diff --git a/src/ai/api/ai_industry.cpp b/src/ai/api/ai_industry.cpp --- a/src/ai/api/ai_industry.cpp +++ b/src/ai/api/ai_industry.cpp @@ -162,7 +162,7 @@ if (!HasHeliport(industry_id)) return INVALID_TILE; const Industry *ind = ::Industry::Get(industry_id); - TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) { + TILE_AREA_LOOP(tile_cur, ind->location) { if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { return tile_cur; } @@ -184,7 +184,7 @@ if (!HasDock(industry_id)) return INVALID_TILE; const Industry *ind = ::Industry::Get(industry_id); - TILE_LOOP(tile_cur, ind->location.w, ind->location.h, ind->location.tile) { + TILE_AREA_LOOP(tile_cur, ind->location) { if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) { return tile_cur; } diff --git a/src/ai/api/ai_tilelist.cpp b/src/ai/api/ai_tilelist.cpp --- a/src/ai/api/ai_tilelist.cpp +++ b/src/ai/api/ai_tilelist.cpp @@ -86,7 +86,7 @@ AITileList_IndustryAccepting::AITileList if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; - TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) { + TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h + radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) { if (!::IsValidTile(cur_tile)) continue; /* Exclude all tiles that belong to this industry */ if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; @@ -123,7 +123,7 @@ AITileList_IndustryProducing::AITileList if (!_settings_game.station.modified_catchment) radius = CA_UNMODIFIED; - TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h+ radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) { + TILE_LOOP(cur_tile, i->location.w + radius * 2, i->location.h + radius * 2, i->location.tile - ::TileDiffXY(radius, radius)) { if (!::IsValidTile(cur_tile)) continue; /* Exclude all tiles that belong to this industry */ if (::IsTileType(cur_tile, MP_INDUSTRY) && ::GetIndustryIndex(cur_tile) == industry_id) continue; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -144,7 +144,7 @@ Industry::~Industry() * This means that we do not have to clear tiles either. */ if (this->location.w == 0) return; - TILE_LOOP(tile_cur, this->location.w, this->location.h, this->location.tile) { + TILE_AREA_LOOP(tile_cur, this->location) { if (IsTileType(tile_cur, MP_INDUSTRY)) { if (GetIndustryIndex(tile_cur) == this->index) { /* MakeWaterKeepingClass() can also handle 'land' */ diff --git a/src/map_func.h b/src/map_func.h --- a/src/map_func.h +++ b/src/map_func.h @@ -348,6 +348,16 @@ uint DistanceFromEdge(TileIndex); ///< s for (uint cur_w = (w); cur_w > 0; --cur_w, var++) /** + * A loop which iterates over the tiles of a TileArea + * + * This macro starts 2 nested loops which iterates over a square of tiles. + * + * @param var The name of the variable which contains the current tile + * @param ta The tile area to search over + */ +#define TILE_AREA_LOOP(var, ta) TILE_LOOP(var, ta.w, ta.h, ta.tile) + +/** * Convert a DiagDirection to a TileIndexDiff * * @param dir The DiagDirection diff --git a/src/newgrf_industrytiles.cpp b/src/newgrf_industrytiles.cpp --- a/src/newgrf_industrytiles.cpp +++ b/src/newgrf_industrytiles.cpp @@ -396,7 +396,7 @@ bool StartStopIndustryTileAnimation(cons { bool ret = true; uint32 random = Random(); - TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) { + TILE_AREA_LOOP(tile, ind->location) { if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { if (StartStopIndustryTileAnimation(tile, iat, random)) { SB(random, 0, 16, Random()); @@ -441,7 +441,7 @@ void TriggerIndustryTile(TileIndex tile, void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger) { - TILE_LOOP(tile, ind->location.w, ind->location.h, ind->location.tile) { + TILE_AREA_LOOP(tile, ind->location) { if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == ind->index) { DoTriggerIndustryTile(tile, trigger, ind); } diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -837,7 +837,7 @@ void DeallocateSpecFromStation(BaseStati ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE); /* Check all tiles over the station to check if the specindex is still in use */ - TILE_LOOP(tile, area.w, area.h, area.tile) { + TILE_AREA_LOOP(tile, area) { if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) { return; } @@ -1076,7 +1076,7 @@ void StationAnimationTrigger(const BaseS ETileArea area = ETileArea(st, tile, tas[trigger]); /* Check all tiles over the station to check if the specindex is still in use */ - TILE_LOOP(tile, area.w, area.h, area.tile) { + TILE_AREA_LOOP(tile, area) { if (st->TileBelongsToRailStation(tile)) { const StationSpec *ss = GetStationSpec(tile); if (ss != NULL && HasBit(ss->anim_triggers, trigger)) { diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -1223,7 +1223,7 @@ CommandCost RemoveFromRailBaseStation(Ti CommandCost total_cost(EXPENSES_CONSTRUCTION); /* Do the action for every tile into the area */ - TILE_LOOP(tile, ta.w, ta.h, ta.tile) { + TILE_AREA_LOOP(tile, ta) { /* Make sure the specified tile is a rail station */ if (!HasStationTileRail(tile)) continue; @@ -1388,7 +1388,7 @@ CommandCost RemoveRailStation(T *st, DoC CommandCost cost(EXPENSES_CONSTRUCTION); /* clear all areas of the station */ - TILE_LOOP(tile, ta.w, ta.h, ta.tile) { + TILE_AREA_LOOP(tile, ta) { /* for nonuniform stations, only remove tiles that are actually train station tiles */ if (!st->TileBelongsToRailStation(tile)) continue; diff --git a/src/station_gui.cpp b/src/station_gui.cpp --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -1211,7 +1211,7 @@ static const T *FindStationsNearby(TileA _deleted_stations_nearby.Clear(); /* Check the inside, to return, if we sit on another station */ - TILE_LOOP(t, ta.w, ta.h, ta.tile) { + TILE_AREA_LOOP(t, ta) { if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t); } diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -761,7 +761,7 @@ static void FloodVehicles(TileIndex tile if (!_settings_game.station.nonuniform_stations && IsTileType(tile, MP_STATION) && GetStationType(tile) == STATION_RAIL) { const Station *st = Station::GetByTile(tile); - TILE_LOOP(t, st->train_station.w, st->train_station.h, st->train_station.tile) { + TILE_AREA_LOOP(t, st->train_station) { if (st->TileBelongsToRailStation(t)) { FindVehicleOnPos(tile, &z, &FloodVehicleProc); }