mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Replace TILE_AREA_LOOP with range-based for loops
This commit is contained in:
parent
5bd8144853
commit
38c97e1492
|
@ -149,7 +149,7 @@ Industry::~Industry()
|
|||
|
||||
const bool has_neutral_station = this->neutral_station != nullptr;
|
||||
|
||||
TILE_AREA_LOOP(tile_cur, this->location) {
|
||||
for (TileIndex tile_cur : this->location) {
|
||||
if (IsTileType(tile_cur, MP_INDUSTRY)) {
|
||||
if (GetIndustryIndex(tile_cur) == this->index) {
|
||||
DeleteNewGRFInspectWindow(GSF_INDUSTRYTILES, tile_cur);
|
||||
|
@ -164,7 +164,7 @@ Industry::~Industry()
|
|||
|
||||
if (has_neutral_station) {
|
||||
/* Remove possible docking tiles */
|
||||
TILE_AREA_LOOP(tile_cur, this->location) {
|
||||
for (TileIndex tile_cur : this->location) {
|
||||
ClearDockingTilesCheckingNeighbours(tile_cur);
|
||||
}
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ Industry::~Industry()
|
|||
TileArea ta = TileArea(this->location.tile, 0, 0).Expand(21);
|
||||
|
||||
/* Remove the farmland and convert it to regular tiles over time. */
|
||||
TILE_AREA_LOOP(tile_cur, ta) {
|
||||
for (TileIndex tile_cur : ta) {
|
||||
if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
|
||||
GetIndustryIndexOfField(tile_cur) == this->index) {
|
||||
SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
|
||||
|
@ -1041,7 +1041,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry)
|
|||
|
||||
/* check the amount of bad tiles */
|
||||
int count = 0;
|
||||
TILE_AREA_LOOP(cur_tile, ta) {
|
||||
for (TileIndex cur_tile : ta) {
|
||||
assert(cur_tile < MapSize());
|
||||
count += IsSuitableForFarmField(cur_tile, false);
|
||||
}
|
||||
|
@ -1053,7 +1053,7 @@ static void PlantFarmField(TileIndex tile, IndustryID industry)
|
|||
uint field_type = GB(r, 8, 8) * 9 >> 8;
|
||||
|
||||
/* make field */
|
||||
TILE_AREA_LOOP(cur_tile, ta) {
|
||||
for (TileIndex cur_tile : ta) {
|
||||
assert(cur_tile < MapSize());
|
||||
if (IsSuitableForFarmField(cur_tile, true)) {
|
||||
MakeField(cur_tile, field_type, industry);
|
||||
|
@ -1115,7 +1115,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data)
|
|||
static void ChopLumberMillTrees(Industry *i)
|
||||
{
|
||||
/* We only want to cut trees if all tiles are completed. */
|
||||
TILE_AREA_LOOP(tile_cur, i->location) {
|
||||
for (TileIndex tile_cur : i->location) {
|
||||
if (i->TileBelongsToIndustry(tile_cur)) {
|
||||
if (!IsIndustryCompleted(tile_cur)) return;
|
||||
}
|
||||
|
@ -1532,7 +1532,7 @@ static bool CheckCanTerraformSurroundingTiles(TileIndex tile, uint height, int i
|
|||
if (TileX(tile) == 0 || TileY(tile) == 0 || GetTileType(tile) == MP_VOID) return false;
|
||||
|
||||
TileArea ta(tile - TileDiffXY(1, 1), 2, 2);
|
||||
TILE_AREA_LOOP(tile_walk, ta) {
|
||||
for (TileIndex tile_walk : ta) {
|
||||
uint curh = TileHeight(tile_walk);
|
||||
/* Is the tile clear? */
|
||||
if ((GetTileType(tile_walk) != MP_CLEAR) && (GetTileType(tile_walk) != MP_TREES)) return false;
|
||||
|
@ -1587,7 +1587,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
|
|||
* Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */
|
||||
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
|
||||
|
||||
TILE_AREA_LOOP(tile_walk, ta) {
|
||||
for (TileIndex tile_walk : ta) {
|
||||
uint curh = TileHeight(tile_walk);
|
||||
if (curh != h) {
|
||||
/* This tile needs terraforming. Check if we can do that without
|
||||
|
@ -1607,7 +1607,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags,
|
|||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Terraform the land under the industry */
|
||||
TILE_AREA_LOOP(tile_walk, ta) {
|
||||
for (TileIndex tile_walk : ta) {
|
||||
uint curh = TileHeight(tile_walk);
|
||||
while (curh != h) {
|
||||
/* We give the terraforming for free here, because we can't calculate
|
||||
|
@ -1639,7 +1639,7 @@ static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int t
|
|||
if (Industry::GetNumItems() > (size_t) (dmax * dmax * 2)) {
|
||||
const Industry* i = nullptr;
|
||||
TileArea tile_area = TileArea(tile, 1, 1).Expand(dmax);
|
||||
TILE_AREA_LOOP(atile, tile_area) {
|
||||
for (TileIndex atile : tile_area) {
|
||||
if (GetTileType(atile) == MP_INDUSTRY) {
|
||||
const Industry *i2 = Industry::GetByTile(atile);
|
||||
if (i == i2) continue;
|
||||
|
|
|
@ -307,7 +307,7 @@ void AirportAnimationTrigger(Station *st, AirpAnimationTrigger trigger, CargoID
|
|||
{
|
||||
if (st->airport.tile == INVALID_TILE) return;
|
||||
|
||||
TILE_AREA_LOOP(tile, st->airport) {
|
||||
for (TileIndex tile : st->airport) {
|
||||
if (st->TileBelongsToAirport(tile)) AirportTileAnimationTrigger(st, tile, trigger, cargo_type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -287,7 +287,7 @@ bool StartStopIndustryTileAnimation(const Industry *ind, IndustryAnimationTrigge
|
|||
{
|
||||
bool ret = true;
|
||||
uint32 random = Random();
|
||||
TILE_AREA_LOOP(tile, ind->location) {
|
||||
for (TileIndex tile : ind->location) {
|
||||
if (ind->TileBelongsToIndustry(tile)) {
|
||||
if (StartStopIndustryTileAnimation(tile, iat, random)) {
|
||||
SB(random, 0, 16, Random());
|
||||
|
@ -372,7 +372,7 @@ void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
|
|||
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
|
||||
{
|
||||
uint32 reseed_industry = 0;
|
||||
TILE_AREA_LOOP(tile, ind->location) {
|
||||
for (TileIndex tile : ind->location) {
|
||||
if (ind->TileBelongsToIndustry(tile)) {
|
||||
DoTriggerIndustryTile(tile, trigger, ind, reseed_industry);
|
||||
}
|
||||
|
|
|
@ -554,7 +554,7 @@ void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const Obj
|
|||
{
|
||||
if (!HasBit(spec->animation.triggers, trigger)) return;
|
||||
|
||||
TILE_AREA_LOOP(tile, o->location) {
|
||||
for (TileIndex tile : o->location) {
|
||||
TriggerObjectTileAnimation(o, tile, trigger, spec);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -737,7 +737,7 @@ void DeallocateSpecFromStation(BaseStation *st, byte specindex)
|
|||
|
||||
ETileArea area = ETileArea(st, INVALID_TILE, TA_WHOLE);
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
TILE_AREA_LOOP(tile, area) {
|
||||
for (TileIndex tile : area) {
|
||||
if (st->TileBelongsToRailStation(tile) && GetCustomStationSpecIndex(tile) == specindex) {
|
||||
return;
|
||||
}
|
||||
|
@ -939,7 +939,7 @@ void TriggerStationAnimation(BaseStation *st, TileIndex tile, StationAnimationTr
|
|||
ETileArea area = ETileArea(st, tile, tas[trigger]);
|
||||
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
TILE_AREA_LOOP(tile, area) {
|
||||
for (TileIndex tile : area) {
|
||||
if (st->TileBelongsToRailStation(tile)) {
|
||||
const StationSpec *ss = GetStationSpec(tile);
|
||||
if (ss != nullptr && HasBit(ss->animation.triggers, trigger)) {
|
||||
|
@ -995,7 +995,7 @@ void TriggerStationRandomisation(Station *st, TileIndex tile, StationRandomTrigg
|
|||
uint32 used_triggers = 0;
|
||||
|
||||
/* Check all tiles over the station to check if the specindex is still in use */
|
||||
TILE_AREA_LOOP(tile, area) {
|
||||
for (TileIndex tile : area) {
|
||||
if (st->TileBelongsToRailStation(tile)) {
|
||||
const StationSpec *ss = GetStationSpec(tile);
|
||||
if (ss == nullptr) continue;
|
||||
|
|
|
@ -114,7 +114,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
|||
|
||||
assert(o->town != nullptr);
|
||||
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WATER_CLASS_INVALID);
|
||||
/* Update company infrastructure counts for objects build on canals owned by nobody. */
|
||||
if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) {
|
||||
|
@ -136,7 +136,7 @@ void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, u
|
|||
static void IncreaseAnimationStage(TileIndex tile)
|
||||
{
|
||||
TileArea ta = Object::GetByTile(tile)->location;
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
SetAnimationFrame(t, GetAnimationFrame(t) + 1);
|
||||
MarkTileDirtyByTile(t);
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
* some information about the tiles. */
|
||||
bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
|
||||
bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
if (HasTileWaterGround(t)) {
|
||||
if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
|
||||
if (!IsWaterTile(t)) {
|
||||
|
@ -263,7 +263,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
int allowed_z;
|
||||
if (GetTileSlope(tile, &allowed_z) != SLOPE_FLAT) allowed_z++;
|
||||
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
uint16 callback = CALLBACK_FAILED;
|
||||
if (HasBit(spec->callback_mask, CBM_OBJ_SLOPE_CHECK)) {
|
||||
TileIndex diff = t - tile;
|
||||
|
@ -283,7 +283,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
if (flags & DC_EXEC) {
|
||||
/* This is basically a copy of the loop above with the exception that we now
|
||||
* execute the commands and don't check for errors, since that's already done. */
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
if (HasTileWaterGround(t)) {
|
||||
if (!IsWaterTile(t)) {
|
||||
DoCommand(t, 0, 0, (flags & ~DC_NO_WATER) | DC_NO_MODIFY_TOWN_RATING, CMD_LANDSCAPE_CLEAR);
|
||||
|
@ -297,7 +297,7 @@ CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
if (cost.Failed()) return cost;
|
||||
|
||||
/* Finally do a check for bridges. */
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
if (IsBridgeAbove(t) && (
|
||||
!(spec->flags & OBJECT_FLAG_ALLOW_UNDER_BRIDGE) ||
|
||||
(GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
|
||||
|
@ -438,7 +438,7 @@ static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
|
|||
static void ReallyClearObjectTile(Object *o)
|
||||
{
|
||||
Object::DecTypeCount(o->type);
|
||||
TILE_AREA_LOOP(tile_cur, o->location) {
|
||||
for (TileIndex tile_cur : o->location) {
|
||||
DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
|
||||
|
||||
MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
|
||||
|
|
|
@ -1265,7 +1265,7 @@ static void CheckCaches()
|
|||
/* Check docking tiles */
|
||||
TileArea ta;
|
||||
std::map<TileIndex, bool> docking_tiles;
|
||||
TILE_AREA_LOOP(tile, st->docking_station) {
|
||||
for (TileIndex tile : st->docking_station) {
|
||||
ta.Add(tile);
|
||||
docking_tiles[tile] = IsDockingTile(tile);
|
||||
}
|
||||
|
@ -1273,7 +1273,7 @@ static void CheckCaches()
|
|||
if (ta.tile != st->docking_station.tile || ta.w != st->docking_station.w || ta.h != st->docking_station.h) {
|
||||
DEBUG(desync, 2, "station docking mismatch: station %i, company %i", st->index, (int)st->owner);
|
||||
}
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (docking_tiles[tile] != IsDockingTile(tile)) {
|
||||
DEBUG(desync, 2, "docking tile mismatch: tile %i", (int)tile);
|
||||
}
|
||||
|
|
|
@ -163,7 +163,7 @@ void CcRoadStop(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2,
|
|||
if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
|
||||
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
|
||||
TileArea roadstop_area(tile, GB(p1, 0, 8), GB(p1, 8, 8));
|
||||
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
||||
for (TileIndex cur_tile : roadstop_area) {
|
||||
ConnectRoadToStructure(cur_tile, dir);
|
||||
/* For a drive-through road stop build connecting road for other entrance. */
|
||||
if (HasBit(p2, 1)) ConnectRoadToStructure(cur_tile, ReverseDiagDir(dir));
|
||||
|
|
|
@ -86,7 +86,7 @@ void MoveBuoysToWaypoints()
|
|||
|
||||
if (train) {
|
||||
/* When we make a rail waypoint of the station, convert the map as well. */
|
||||
TILE_AREA_LOOP(t, train_st) {
|
||||
for (TileIndex t : train_st) {
|
||||
if (!IsTileType(t, MP_STATION) || GetStationIndex(t) != index) continue;
|
||||
|
||||
SB(_me[t].m6, 3, 3, STATION_WAYPOINT);
|
||||
|
|
|
@ -186,7 +186,7 @@
|
|||
if (!HasHeliport(industry_id)) return INVALID_TILE;
|
||||
|
||||
const Industry *ind = ::Industry::Get(industry_id);
|
||||
TILE_AREA_LOOP(tile_cur, ind->location) {
|
||||
for (TileIndex tile_cur : ind->location) {
|
||||
if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
|
||||
return tile_cur;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@
|
|||
if (!HasDock(industry_id)) return INVALID_TILE;
|
||||
|
||||
const Industry *ind = ::Industry::Get(industry_id);
|
||||
TILE_AREA_LOOP(tile_cur, ind->location) {
|
||||
for (TileIndex tile_cur : ind->location) {
|
||||
if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
|
||||
return tile_cur;
|
||||
}
|
||||
|
|
|
@ -256,11 +256,11 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
case OT_GOTO_STATION: {
|
||||
const Station *st = ::Station::Get(order->GetDestination());
|
||||
if (st->train_station.tile != INVALID_TILE) {
|
||||
TILE_AREA_LOOP(t, st->train_station) {
|
||||
for (TileIndex t : st->train_station) {
|
||||
if (st->TileBelongsToRailStation(t)) return t;
|
||||
}
|
||||
} else if (st->ship_station.tile != INVALID_TILE) {
|
||||
TILE_AREA_LOOP(t, st->ship_station) {
|
||||
for (TileIndex t : st->ship_station) {
|
||||
if (IsTileType(t, MP_STATION) && (IsDock(t) || IsOilRig(t)) && GetStationIndex(t) == st->index) return t;
|
||||
}
|
||||
} else if (st->bus_stops != nullptr) {
|
||||
|
@ -268,7 +268,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
} else if (st->truck_stops != nullptr) {
|
||||
return st->truck_stops->xy;
|
||||
} else if (st->airport.tile != INVALID_TILE) {
|
||||
TILE_AREA_LOOP(tile, st->airport) {
|
||||
for (TileIndex tile : st->airport) {
|
||||
if (st->TileBelongsToAirport(tile) && !::IsHangar(tile)) return tile;
|
||||
}
|
||||
}
|
||||
|
@ -278,7 +278,7 @@ static int ScriptOrderPositionToRealOrderPosition(VehicleID vehicle_id, ScriptOr
|
|||
case OT_GOTO_WAYPOINT: {
|
||||
const Waypoint *wp = ::Waypoint::Get(order->GetDestination());
|
||||
if (wp->train_station.tile != INVALID_TILE) {
|
||||
TILE_AREA_LOOP(t, wp->train_station) {
|
||||
for (TileIndex t : wp->train_station) {
|
||||
if (wp->TileBelongsToRailStation(t)) return t;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ void ScriptTileList::AddRectangle(TileIndex t1, TileIndex t2)
|
|||
if (!::IsValidTile(t2)) return;
|
||||
|
||||
TileArea ta(t1, t2);
|
||||
TILE_AREA_LOOP(t, ta) this->AddItem(t);
|
||||
for (TileIndex t : ta) this->AddItem(t);
|
||||
}
|
||||
|
||||
void ScriptTileList::AddTile(TileIndex tile)
|
||||
|
@ -37,7 +37,7 @@ void ScriptTileList::RemoveRectangle(TileIndex t1, TileIndex t2)
|
|||
if (!::IsValidTile(t2)) return;
|
||||
|
||||
TileArea ta(t1, t2);
|
||||
TILE_AREA_LOOP(t, ta) this->RemoveItem(t);
|
||||
for (TileIndex t : ta) this->RemoveItem(t);
|
||||
}
|
||||
|
||||
void ScriptTileList::RemoveTile(TileIndex tile)
|
||||
|
@ -55,7 +55,7 @@ void ScriptTileList::RemoveTile(TileIndex tile)
|
|||
*/
|
||||
static void FillIndustryCatchment(const Industry *i, int radius, BitmapTileArea &bta)
|
||||
{
|
||||
TILE_AREA_LOOP(cur_tile, i->location) {
|
||||
for (TileIndex cur_tile : i->location) {
|
||||
if (!::IsTileType(cur_tile, MP_INDUSTRY) || ::GetIndustryIndex(cur_tile) != i->index) continue;
|
||||
|
||||
int tx = TileX(cur_tile);
|
||||
|
@ -156,7 +156,7 @@ ScriptTileList_StationType::ScriptTileList_StationType(StationID station_id, Scr
|
|||
if ((station_type & ScriptStation::STATION_DOCK) != 0) station_type_value |= (1 << ::STATION_DOCK) | (1 << ::STATION_OILRIG);
|
||||
|
||||
TileArea ta(::TileXY(rect->left, rect->top), rect->right - rect->left + 1, rect->bottom - rect->top + 1);
|
||||
TILE_AREA_LOOP(cur_tile, ta) {
|
||||
for (TileIndex cur_tile : ta) {
|
||||
if (!::IsTileType(cur_tile, MP_STATION)) continue;
|
||||
if (::GetStationIndex(cur_tile) != station_id) continue;
|
||||
if (!HasBit(station_type_value, ::GetStationType(cur_tile))) continue;
|
||||
|
|
|
@ -750,7 +750,7 @@ inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const
|
|||
TileIndex tile = INVALID_TILE; // Position of the most important tile.
|
||||
TileType et = MP_VOID; // Effective tile type at that position.
|
||||
|
||||
TILE_AREA_LOOP(ti, ta) {
|
||||
for (TileIndex ti : ta) {
|
||||
TileType ttype = GetTileType(ti);
|
||||
|
||||
switch (ttype) {
|
||||
|
|
|
@ -416,7 +416,7 @@ void Station::RecomputeCatchment()
|
|||
if (!_settings_game.station.serve_neutral_industries && this->industry != nullptr) {
|
||||
/* Station is associated with an industry, so we only need to deliver to that industry. */
|
||||
this->catchment_tiles.Initialize(this->industry->location);
|
||||
TILE_AREA_LOOP(tile, this->industry->location) {
|
||||
for (TileIndex tile : this->industry->location) {
|
||||
if (IsTileType(tile, MP_INDUSTRY) && GetIndustryIndex(tile) == this->industry->index) {
|
||||
this->catchment_tiles.SetTile(tile);
|
||||
}
|
||||
|
@ -435,7 +435,7 @@ void Station::RecomputeCatchment()
|
|||
|
||||
/* Loop finding all station tiles */
|
||||
TileArea ta(TileXY(this->rect.left, this->rect.top), TileXY(this->rect.right, this->rect.bottom));
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (!IsTileType(tile, MP_STATION) || GetStationIndex(tile) != this->index) continue;
|
||||
|
||||
uint r = GetTileCatchmentRadius(tile, this);
|
||||
|
@ -443,7 +443,7 @@ void Station::RecomputeCatchment()
|
|||
|
||||
/* This tile sub-loop doesn't need to test any tiles, they are simply added to the catchment set. */
|
||||
TileArea ta2 = TileArea(tile, 1, 1).Expand(r);
|
||||
TILE_AREA_LOOP(tile2, ta2) this->catchment_tiles.SetTile(tile2);
|
||||
for (TileIndex tile2 : ta2) this->catchment_tiles.SetTile(tile2);
|
||||
}
|
||||
|
||||
/* Search catchment tiles for towns and industries */
|
||||
|
@ -567,7 +567,7 @@ CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRect
|
|||
/* static */ bool StationRect::ScanForStationTiles(StationID st_id, int left_a, int top_a, int right_a, int bottom_a)
|
||||
{
|
||||
TileArea ta(TileXY(left_a, top_a), TileXY(right_a, bottom_a));
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsTileType(tile, MP_STATION) && GetStationIndex(tile) == st_id) return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -575,7 +575,7 @@ void ForAllStationsAroundTiles(const TileArea &ta, Func func)
|
|||
* to find the possible nearby stations. */
|
||||
uint max_c = _settings_game.station.modified_catchment ? MAX_CATCHMENT : CA_UNMODIFIED;
|
||||
TileArea ta_ext = TileArea(ta).Expand(max_c);
|
||||
TILE_AREA_LOOP(tile, ta_ext) {
|
||||
for (TileIndex tile : ta_ext) {
|
||||
if (IsTileType(tile, MP_STATION)) seen_stations.insert(GetStationIndex(tile));
|
||||
}
|
||||
|
||||
|
@ -587,7 +587,7 @@ void ForAllStationsAroundTiles(const TileArea &ta, Func func)
|
|||
if (!_settings_game.station.serve_neutral_industries && st->industry != nullptr) continue;
|
||||
|
||||
/* Test if the tile is within the station's catchment */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (st->TileIsInCatchment(tile)) {
|
||||
if (func(st, tile)) break;
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ CommandCost GetStationAround(TileArea ta, StationID closest_station, CompanyID c
|
|||
ta.Expand(1);
|
||||
|
||||
/* check around to see if there are any stations there owned by the company */
|
||||
TILE_AREA_LOOP(tile_cur, ta) {
|
||||
for (TileIndex tile_cur : ta) {
|
||||
if (IsTileType(tile_cur, MP_STATION)) {
|
||||
StationID t = GetStationIndex(tile_cur);
|
||||
if (!T::IsValidID(t) || Station::Get(t)->owner != company) continue;
|
||||
|
@ -511,7 +511,7 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
|
|||
|
||||
/* Loop over all tiles to get the produced cargo of
|
||||
* everything except industries */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
|
||||
AddProducedCargo(tile, produced);
|
||||
}
|
||||
|
@ -549,7 +549,7 @@ CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, Cargo
|
|||
|
||||
TileArea ta = TileArea(tile, w, h).Expand(rad);
|
||||
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
/* Ignore industry if it has a neutral station. */
|
||||
if (!_settings_game.station.serve_neutral_industries && IsTileType(tile, MP_INDUSTRY) && Industry::GetByTile(tile)->neutral_station != nullptr) continue;
|
||||
|
||||
|
@ -872,7 +872,7 @@ static CommandCost CheckFlatLandRailStation(TileArea tile_area, DoCommandFlag fl
|
|||
const StationSpec *statspec = StationClass::Get(spec_class)->GetSpec(spec_index);
|
||||
bool slope_cb = statspec != nullptr && HasBit(statspec->callback_mask, CBM_STATION_SLOPE_CHECK);
|
||||
|
||||
TILE_AREA_LOOP(tile_cur, tile_area) {
|
||||
for (TileIndex tile_cur : tile_area) {
|
||||
CommandCost ret = CheckBuildableTile(tile_cur, invalid_dirs, allowed_z, false);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
|
@ -954,7 +954,7 @@ static CommandCost CheckFlatLandRoadStop(TileArea tile_area, DoCommandFlag flags
|
|||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
int allowed_z = -1;
|
||||
|
||||
TILE_AREA_LOOP(cur_tile, tile_area) {
|
||||
for (TileIndex cur_tile : tile_area) {
|
||||
CommandCost ret = CheckBuildableTile(cur_tile, invalid_dirs, allowed_z, !is_drive_through);
|
||||
if (ret.Failed()) return ret;
|
||||
cost.AddCost(ret);
|
||||
|
@ -1435,7 +1435,7 @@ CommandCost CmdBuildRailStation(TileIndex tile_org, DoCommandFlag flags, uint32
|
|||
update_reservation_area = TileArea(tile_org, numtracks_orig, 1);
|
||||
}
|
||||
|
||||
TILE_AREA_LOOP(tile, update_reservation_area) {
|
||||
for (TileIndex tile : update_reservation_area) {
|
||||
/* Don't even try to make eye candy parts reserved. */
|
||||
if (IsStationTileBlocked(tile)) continue;
|
||||
|
||||
|
@ -1563,7 +1563,7 @@ CommandCost RemoveFromRailBaseStation(TileArea ta, std::vector<T *> &affected_st
|
|||
CommandCost error;
|
||||
|
||||
/* Do the action for every tile into the area */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
/* Make sure the specified tile is a rail station */
|
||||
if (!HasStationTileRail(tile)) continue;
|
||||
|
||||
|
@ -1729,7 +1729,7 @@ CommandCost RemoveRailStation(T *st, DoCommandFlag flags, Money removal_cost)
|
|||
|
||||
CommandCost cost(EXPENSES_CONSTRUCTION);
|
||||
/* clear all areas of the station */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
/* only remove tiles that are actually train station tiles */
|
||||
if (st->TileBelongsToRailStation(tile)) {
|
||||
std::vector<T*> affected_stations; // dummy
|
||||
|
@ -1894,7 +1894,7 @@ CommandCost CmdBuildRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
|
|||
|
||||
if (flags & DC_EXEC) {
|
||||
/* Check every tile in the area. */
|
||||
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
||||
for (TileIndex cur_tile : roadstop_area) {
|
||||
/* Get existing road types and owners before any tile clearing */
|
||||
RoadType road_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_ROAD) : INVALID_ROADTYPE;
|
||||
RoadType tram_rt = MayHaveRoad(cur_tile) ? GetRoadType(cur_tile, RTT_TRAM) : INVALID_ROADTYPE;
|
||||
|
@ -2101,7 +2101,7 @@ CommandCost CmdRemoveRoadStop(TileIndex tile, DoCommandFlag flags, uint32 p1, ui
|
|||
CommandCost last_error(STR_ERROR_THERE_IS_NO_STATION);
|
||||
bool had_success = false;
|
||||
|
||||
TILE_AREA_LOOP(cur_tile, roadstop_area) {
|
||||
for (TileIndex cur_tile : roadstop_area) {
|
||||
/* Make sure the specified tile is a road stop of the correct type */
|
||||
if (!IsTileType(cur_tile, MP_STATION) || !IsRoadStop(cur_tile) || (uint32)GetRoadStopType(cur_tile) != GB(p2, 0, 1)) continue;
|
||||
|
||||
|
@ -2409,7 +2409,7 @@ static CommandCost RemoveAirport(TileIndex tile, DoCommandFlag flags)
|
|||
nearest->noise_reached -= GetAirportNoiseLevelForDistance(as, dist);
|
||||
}
|
||||
|
||||
TILE_AREA_LOOP(tile_cur, st->airport) {
|
||||
for (TileIndex tile_cur : st->airport) {
|
||||
if (!st->TileBelongsToAirport(tile_cur)) continue;
|
||||
|
||||
CommandCost ret = EnsureNoVehicleOnGround(tile_cur);
|
||||
|
@ -4120,7 +4120,7 @@ void UpdateStationDockingTiles(Station *st)
|
|||
int y1 = std::max<int>(y - 1, 0);
|
||||
|
||||
TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1));
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsValidTile(tile) && IsPossibleDockingTile(tile)) CheckForDockingTile(tile);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ static void FindStationsAroundSelection()
|
|||
Station *adjacent = nullptr;
|
||||
|
||||
/* Direct loop instead of ForAllStationsAroundTiles as we are not interested in catchment area */
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) {
|
||||
Station *st = Station::GetByTile(tile);
|
||||
if (st == nullptr) continue;
|
||||
|
@ -2214,7 +2214,7 @@ static const T *FindStationsNearby(TileArea ta, bool distant_join)
|
|||
_deleted_stations_nearby.clear();
|
||||
|
||||
/* Check the inside, to return, if we sit on another station */
|
||||
TILE_AREA_LOOP(t, ta) {
|
||||
for (TileIndex t : ta) {
|
||||
if (t < MapSize() && IsTileType(t, MP_STATION) && T::IsValidID(GetStationIndex(t))) return T::GetByTile(t);
|
||||
}
|
||||
|
||||
|
|
|
@ -329,7 +329,7 @@ bool FindSubsidyTownCargoRoute()
|
|||
/* Calculate the produced cargo of houses around town center. */
|
||||
CargoArray town_cargo_produced;
|
||||
TileArea ta = TileArea(src_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsTileType(tile, MP_HOUSE)) {
|
||||
AddProducedCargo(tile, town_cargo_produced);
|
||||
}
|
||||
|
@ -440,7 +440,7 @@ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src)
|
|||
/* Calculate cargo acceptance of houses around town center. */
|
||||
CargoArray town_cargo_accepted;
|
||||
TileArea ta = TileArea(dst_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS);
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
if (IsTileType(tile, MP_HOUSE)) {
|
||||
AddAcceptedCargo(tile, town_cargo_accepted, nullptr);
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ static void GenerateDesertArea(TileIndex end, TileIndex start)
|
|||
_generating_world = true;
|
||||
|
||||
TileArea ta(start, end);
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
SetTropicZone(tile, (_ctrl_pressed) ? TROPICZONE_NORMAL : TROPICZONE_DESERT);
|
||||
DoCommandP(tile, 0, 0, CMD_LANDSCAPE_CLEAR);
|
||||
MarkTileDirtyByTile(tile);
|
||||
|
@ -74,7 +74,7 @@ static void GenerateRockyArea(TileIndex end, TileIndex start)
|
|||
bool success = false;
|
||||
TileArea ta(start, end);
|
||||
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_TREES:
|
||||
if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue;
|
||||
|
@ -408,18 +408,18 @@ static void CommonRaiseLowerBigLand(TileIndex tile, int mode)
|
|||
if (mode != 0) {
|
||||
/* Raise land */
|
||||
h = MAX_TILE_HEIGHT;
|
||||
TILE_AREA_LOOP(tile2, ta) {
|
||||
for (TileIndex tile2 : ta) {
|
||||
h = std::min(h, TileHeight(tile2));
|
||||
}
|
||||
} else {
|
||||
/* Lower land */
|
||||
h = 0;
|
||||
TILE_AREA_LOOP(tile2, ta) {
|
||||
for (TileIndex tile2 : ta) {
|
||||
h = std::max(h, TileHeight(tile2));
|
||||
}
|
||||
}
|
||||
|
||||
TILE_AREA_LOOP(tile2, ta) {
|
||||
for (TileIndex tile2 : ta) {
|
||||
if (TileHeight(tile2) == h) {
|
||||
DoCommandP(tile2, SLOPE_N, (uint32)mode, CMD_TERRAFORM_LAND);
|
||||
}
|
||||
|
|
|
@ -146,6 +146,24 @@ void OrthogonalTileArea::ClampToMap()
|
|||
this->h = std::min<int>(this->h, MapSizeY() - TileY(this->tile));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator to the beginning of the tile area.
|
||||
* @return The OrthogonalTileIterator.
|
||||
*/
|
||||
OrthogonalTileIterator OrthogonalTileArea::begin() const
|
||||
{
|
||||
return OrthogonalTileIterator(*this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an iterator to the end of the tile area.
|
||||
* @return The OrthogonalTileIterator.
|
||||
*/
|
||||
OrthogonalTileIterator OrthogonalTileArea::end() const
|
||||
{
|
||||
return OrthogonalTileIterator(OrthogonalTileArea());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a diagonal tile area from two corners.
|
||||
* @param start First corner of the area.
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include "map_func.h"
|
||||
|
||||
class OrthogonalTileIterator;
|
||||
|
||||
/** Represents the covered area of e.g. a rail station */
|
||||
struct OrthogonalTileArea {
|
||||
TileIndex tile; ///< The base tile of the area
|
||||
|
@ -58,6 +60,10 @@ struct OrthogonalTileArea {
|
|||
{
|
||||
return TILE_ADDXY(this->tile, this->w / 2, this->h / 2);
|
||||
}
|
||||
|
||||
OrthogonalTileIterator begin() const;
|
||||
|
||||
OrthogonalTileIterator end() const;
|
||||
};
|
||||
|
||||
/** Represents a diagonal tile area. */
|
||||
|
@ -123,6 +129,15 @@ public:
|
|||
return this->tile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tile we are currently at.
|
||||
* @return The tile we are at, or INVALID_TILE when we're done.
|
||||
*/
|
||||
inline TileIndex operator *() const
|
||||
{
|
||||
return this->tile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Move ourselves to the next tile in the rectangle on the map.
|
||||
*/
|
||||
|
@ -223,12 +238,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* A loop which iterates over the tiles of a TileArea.
|
||||
* @param var The name of the variable which contains the current tile.
|
||||
* This variable will be allocated in this \c for of this loop.
|
||||
* @param ta The tile area to search over.
|
||||
*/
|
||||
#define TILE_AREA_LOOP(var, ta) for (OrthogonalTileIterator var(ta); var != INVALID_TILE; ++var)
|
||||
|
||||
#endif /* TILEAREA_TYPE_H */
|
||||
|
|
|
@ -392,7 +392,7 @@ CommandCost CmdPlantTree(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
|||
int limit = (c == nullptr ? INT32_MAX : GB(c->tree_limit, 16, 16));
|
||||
|
||||
TileArea ta(tile, p2);
|
||||
TILE_AREA_LOOP(tile, ta) {
|
||||
for (TileIndex tile : ta) {
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_TREES:
|
||||
/* no more space for trees? */
|
||||
|
|
|
@ -1044,7 +1044,7 @@ static void FloodVehicles(TileIndex tile)
|
|||
|
||||
if (IsAirportTile(tile)) {
|
||||
const Station *st = Station::GetByTile(tile);
|
||||
TILE_AREA_LOOP(tile, st->airport) {
|
||||
for (TileIndex tile : st->airport) {
|
||||
if (st->TileBelongsToAirport(tile)) FindVehicleOnPos(tile, &z, &FloodVehicleProc);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue