# HG changeset patch # User glx # Date 2019-12-15 16:54:05 # Node ID a76e956cb3587e5a0223142c26cfb0ac7bc807f7 # Parent 102d2d7daf232d0891d1d6d8afb160b1bfa0aedb Codechange: Replace FOR_ALL_DEPOTS with range-based for loops diff --git a/src/depot_base.h b/src/depot_base.h --- a/src/depot_base.h +++ b/src/depot_base.h @@ -44,7 +44,4 @@ struct Depot : DepotPool::PoolItem<&_dep } }; -#define FOR_ALL_DEPOTS_FROM(var, start) FOR_ALL_ITEMS_FROM(Depot, depot_index, var, start) -#define FOR_ALL_DEPOTS(var) FOR_ALL_DEPOTS_FROM(var, 0) - #endif /* DEPOT_BASE_H */ diff --git a/src/depot_cmd.cpp b/src/depot_cmd.cpp --- a/src/depot_cmd.cpp +++ b/src/depot_cmd.cpp @@ -28,9 +28,7 @@ */ static bool IsUniqueDepotName(const char *name) { - const Depot *d; - - FOR_ALL_DEPOTS(d) { + for (const Depot *d : Depot::Iterate()) { if (d->name != nullptr && strcmp(d->name, name) == 0) return false; } diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2330,8 +2330,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_128)) { - const Depot *d; - FOR_ALL_DEPOTS(d) { + for (const Depot *d : Depot::Iterate()) { /* At some point, invalid depots were saved into the game (possibly those removed in the past?) * Remove them here, so they don't cause issues further down the line */ if (!IsDepotTile(d->xy)) { @@ -2445,15 +2444,13 @@ bool AfterLoadGame() /* We need to properly number/name the depots. * The first step is making sure none of the depots uses the * 'default' names, after that we can assign the names. */ - Depot *d; - FOR_ALL_DEPOTS(d) d->town_cn = UINT16_MAX; - - FOR_ALL_DEPOTS(d) MakeDefaultName(d); + for (Depot *d : Depot::Iterate()) d->town_cn = UINT16_MAX; + + for (Depot* d : Depot::Iterate()) MakeDefaultName(d); } if (IsSavegameVersionBefore(SLV_142)) { - Depot *d; - FOR_ALL_DEPOTS(d) d->build_date = _date; + for (Depot *d : Depot::Iterate()) d->build_date = _date; } /* In old versions it was possible to remove an airport while a plane was diff --git a/src/saveload/depot_sl.cpp b/src/saveload/depot_sl.cpp --- a/src/saveload/depot_sl.cpp +++ b/src/saveload/depot_sl.cpp @@ -30,9 +30,7 @@ static const SaveLoad _depot_desc[] = { static void Save_DEPT() { - Depot *depot; - - FOR_ALL_DEPOTS(depot) { + for (Depot *depot : Depot::Iterate()) { SlSetArrayIndex(depot->index); SlObject(depot, _depot_desc); } @@ -53,9 +51,7 @@ static void Load_DEPT() static void Ptrs_DEPT() { - Depot *depot; - - FOR_ALL_DEPOTS(depot) { + for (Depot *depot : Depot::Iterate()) { SlObject(depot, _depot_desc); if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town); } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -109,8 +109,7 @@ static void FixTTDMapArray() static void FixTTDDepots() { - const Depot *d; - FOR_ALL_DEPOTS_FROM(d, 252) { + for (const Depot *d : Depot::Iterate(252)) { if (!IsDepotTile(d->xy) || GetDepotIndex(d->xy) != d->index) { /** Workaround for SVXConverter bug, depots 252-255 could be invalid */ delete d; diff --git a/src/script/api/script_depotlist.cpp b/src/script/api/script_depotlist.cpp --- a/src/script/api/script_depotlist.cpp +++ b/src/script/api/script_depotlist.cpp @@ -38,8 +38,7 @@ ScriptDepotList::ScriptDepotList(ScriptT } /* Handle 'standard' depots. */ - const Depot *depot; - FOR_ALL_DEPOTS(depot) { + for (const Depot *depot : Depot::Iterate()) { if ((::GetTileOwner(depot->xy) == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && ::IsTileType(depot->xy, tile_type)) this->AddItem(depot->xy); } } diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp --- a/src/ship_cmd.cpp +++ b/src/ship_cmd.cpp @@ -144,7 +144,6 @@ void Ship::GetImage(Direction direction, static const Depot *FindClosestShipDepot(const Vehicle *v, uint max_distance) { /* Find the closest depot */ - const Depot *depot; const Depot *best_depot = nullptr; /* If we don't have a maximum distance, i.e. distance = 0, * we want to find any depot so the best distance of no @@ -153,7 +152,7 @@ static const Depot *FindClosestShipDepot * further away than max_distance can safely be ignored. */ uint best_dist = max_distance == 0 ? UINT_MAX : max_distance + 1; - FOR_ALL_DEPOTS(depot) { + for (const Depot *depot : Depot::Iterate()) { TileIndex tile = depot->xy; if (IsShipDepotTile(tile) && IsTileOwner(tile, v->owner)) { uint dist = DistanceManhattan(tile, v->tile); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2883,8 +2883,7 @@ CommandCost CmdDeleteTown(TileIndex tile } /* Depots refer to towns. */ - const Depot *d; - FOR_ALL_DEPOTS(d) { + for (const Depot *d : Depot::Iterate()) { if (d->town == t) return CMD_ERROR; }