diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -745,9 +745,9 @@ static void Disaster_Airplane_Init() { if (!Vehicle::CanAllocateItem(2)) return; - Industry *i, *found = nullptr; + Industry *found = nullptr; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_AIRPLANE_ATTACKS) && (found == nullptr || Chance16(1, 2))) { found = i; @@ -771,9 +771,9 @@ static void Disaster_Helicopter_Init() { if (!Vehicle::CanAllocateItem(3)) return; - Industry *i, *found = nullptr; + Industry *found = nullptr; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CHOPPER_ATTACKS) && (found == nullptr || Chance16(1, 2))) { found = i; @@ -858,9 +858,7 @@ static void Disaster_CoalMine_Init() uint m; for (m = 0; m < 15; m++) { - const Industry *i; - - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { if ((GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_CAN_SUBSIDENCE) && --index < 0) { SetDParam(0, i->town->index); AddTileNewsItem(STR_NEWS_DISASTER_COAL_MINE_SUBSIDENCE, NT_ACCIDENT, i->location.tile + TileDiffXY(1, 1)); // keep the news, even when the mine closes diff --git a/src/industry.h b/src/industry.h --- a/src/industry.h +++ b/src/industry.h @@ -167,9 +167,6 @@ void ReleaseDisastersTargetingIndustry(I bool IsTileForestIndustry(TileIndex tile); -#define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start) -#define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0) - /** Data for managing the number of industries of a single industry type. */ struct IndustryTypeBuildData { uint32 probability; ///< Relative probability of building this industry. diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1203,8 +1203,7 @@ void OnTick_Industry() if (_game_mode == GM_EDITOR) return; - Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { ProduceIndustryGoods(i); } } @@ -1391,8 +1390,7 @@ static CommandCost FindTownForIndustry(T if (_settings_game.economy.multiple_industry_per_town) return CommandCost(); - const Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { if (i->type == (byte)type && i->town == *t) { *t = nullptr; return_cmd_error(STR_ERROR_ONLY_ONE_ALLOWED_PER_TOWN); @@ -1629,11 +1627,11 @@ static bool CheckIfCanLevelIndustryPlatf static CommandCost CheckIfFarEnoughFromConflictingIndustry(TileIndex tile, int type) { const IndustrySpec *indspec = GetIndustrySpec(type); - const Industry *i = nullptr; /* On a large map with many industries, it may be faster to check an area. */ static const int dmax = 14; 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) { if (GetTileType(atile) == MP_INDUSTRY) { @@ -1651,7 +1649,7 @@ static CommandCost CheckIfFarEnoughFromC return CommandCost(); } - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { /* Within 14 tiles from another industry is considered close */ if (DistanceMax(tile, i->location.tile) > 14) continue; @@ -2833,8 +2831,7 @@ void IndustryMonthlyLoop() _industry_builder.MonthlyLoop(); - Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { UpdateIndustryStatistics(i); if (i->prod_level == PRODLEVEL_CLOSURE) { delete i; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1203,8 +1203,7 @@ protected: if (this->industries.NeedRebuild()) { this->industries.clear(); - const Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { this->industries.push_back(i); } diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -91,8 +91,7 @@ uint32 GetIndustryIDAtOffset(TileIndex t static uint32 GetClosestIndustry(TileIndex tile, IndustryType type, const Industry *current) { uint32 best_dist = UINT32_MAX; - const Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { if (i->type != type || i == current) continue; best_dist = min(best_dist, DistanceManhattan(tile, i->location.tile)); @@ -145,8 +144,7 @@ static uint32 GetCountAndDistanceOfClose } else { /* Count only those who match the same industry type and layout filter * Unfortunately, we have to do it manually */ - const Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { if (i->type == ind_index && i != current && (i->selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->town == current->town)) { closest_dist = min(closest_dist, DistanceManhattan(current->location.tile, i->location.tile)); count++; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -259,8 +259,7 @@ static void InitializeWindowsAndCaches() } /* Identify owners of persistent storage arrays */ - Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { if (i->psa != nullptr) { i->psa->feature = GSF_INDUSTRIES; i->psa->tile = i->location.tile; @@ -1413,7 +1412,6 @@ bool AfterLoadGame() /* Time starts at 0 instead of 1920. * Account for this in older games by adding an offset */ if (IsSavegameVersionBefore(SLV_31)) { - Industry *i; Vehicle *v; _date += DAYS_TILL_ORIGINAL_BASE_YEAR; @@ -1423,7 +1421,7 @@ bool AfterLoadGame() for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR; for (Engine *e : Engine::Iterate()) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR; for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR; - FOR_ALL_INDUSTRIES(i) i->last_prod_year += ORIGINAL_BASE_YEAR; + for (Industry *i : Industry::Iterate()) i->last_prod_year += ORIGINAL_BASE_YEAR; FOR_ALL_VEHICLES(v) { v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR; @@ -1435,8 +1433,6 @@ bool AfterLoadGame() * To give this prettiness to old savegames, we remove all farmfields and * plant new ones. */ if (IsSavegameVersionBefore(SLV_32)) { - Industry *i; - for (TileIndex t = 0; t < map_size; t++) { if (IsTileType(t, MP_CLEAR) && IsClearGround(t, CLEAR_FIELDS)) { /* remove fields */ @@ -1444,7 +1440,7 @@ bool AfterLoadGame() } } - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { uint j; if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) { @@ -1660,8 +1656,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_70)) { /* Added variables to support newindustries */ - Industry *i; - FOR_ALL_INDUSTRIES(i) i->founder = OWNER_NONE; + for (Industry *i : Industry::Iterate()) i->founder = OWNER_NONE; } /* From version 82, old style canals (above sealevel (0), WATER owner) are no longer supported. @@ -1701,9 +1696,8 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_78)) { - Industry *i; uint j; - FOR_ALL_INDUSTRIES(i) { + for (Industry * i : Industry::Iterate()) { const IndustrySpec *indsp = GetIndustrySpec(i->type); for (j = 0; j < lengthof(i->produced_cargo); j++) { i->produced_cargo[j] = indsp->produced_cargo[j]; @@ -2760,8 +2754,7 @@ bool AfterLoadGame() /* Before savegame version 161, persistent storages were not stored in a pool. */ if (!IsSavegameVersionBefore(SLV_76)) { - Industry *ind; - FOR_ALL_INDUSTRIES(ind) { + for (Industry *ind : Industry::Iterate()) { assert(ind->psa != nullptr); /* Check if the old storage was empty. */ @@ -3044,8 +3037,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) { /* Make sure added industry cargo slots are cleared */ - Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { for (size_t ci = 2; ci < lengthof(i->produced_cargo); ci++) { i->produced_cargo[ci] = CT_INVALID; i->produced_cargo_waiting[ci] = 0; @@ -3127,8 +3119,7 @@ bool AfterLoadGame() } } else { /* Link neutral station back to industry, as this is not saved. */ - Industry *ind; - FOR_ALL_INDUSTRIES(ind) if (ind->neutral_station != nullptr) ind->neutral_station->industry = ind; + for (Industry *ind : Industry::Iterate()) if (ind->neutral_station != nullptr) ind->neutral_station->industry = ind; } if (IsSavegameVersionBefore(SLV_TREES_WATER_CLASS)) { diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -77,10 +77,8 @@ static const SaveLoad _industry_desc[] = static void Save_INDY() { - Industry *ind; - /* Write the industries */ - FOR_ALL_INDUSTRIES(ind) { + for (Industry *ind : Industry::Iterate()) { SlSetArrayIndex(ind->index); SlObject(ind, _industry_desc); } @@ -129,9 +127,7 @@ static void Load_TIDS() static void Ptrs_INDY() { - Industry *i; - - FOR_ALL_INDUSTRIES(i) { + for (Industry *i : Industry::Iterate()) { SlObject(i, _industry_desc); } } diff --git a/src/script/api/script_industrylist.cpp b/src/script/api/script_industrylist.cpp --- a/src/script/api/script_industrylist.cpp +++ b/src/script/api/script_industrylist.cpp @@ -15,17 +15,14 @@ ScriptIndustryList::ScriptIndustryList() { - Industry *i; - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { this->AddItem(i->index); } } ScriptIndustryList_CargoAccepting::ScriptIndustryList_CargoAccepting(CargoID cargo_id) { - const Industry *i; - - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { for (byte j = 0; j < lengthof(i->accepts_cargo); j++) { if (i->accepts_cargo[j] == cargo_id) this->AddItem(i->index); } @@ -34,9 +31,7 @@ ScriptIndustryList_CargoAccepting::Scrip ScriptIndustryList_CargoProducing::ScriptIndustryList_CargoProducing(CargoID cargo_id) { - const Industry *i; - - FOR_ALL_INDUSTRIES(i) { + for (const Industry *i : Industry::Iterate()) { for (byte j = 0; j < lengthof(i->produced_cargo); j++) { if (i->produced_cargo[j] == cargo_id) this->AddItem(i->index); } diff --git a/src/station.cpp b/src/station.cpp --- a/src/station.cpp +++ b/src/station.cpp @@ -385,8 +385,7 @@ void Station::RemoveFromAllNearbyLists() { Town *t; FOR_ALL_TOWNS(t) { t->stations_near.erase(this); } - Industry *i; - FOR_ALL_INDUSTRIES(i) { i->stations_near.erase(this); } + for (Industry *i : Industry::Iterate()) { i->stations_near.erase(this); } } /** diff --git a/src/subsidy.cpp b/src/subsidy.cpp --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -133,8 +133,7 @@ void RebuildSubsidisedSourceAndDestinati Town *t; FOR_ALL_TOWNS(t) t->cache.part_of_subsidy = POS_NONE; - Industry *i; - FOR_ALL_INDUSTRIES(i) i->part_of_subsidy = POS_NONE; + for (Industry *i : Industry::Iterate()) i->part_of_subsidy = POS_NONE; const Subsidy *s; FOR_ALL_SUBSIDIES(s) { diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -112,8 +112,7 @@ Town::~Town() DeleteWindowById(WC_TOWN_VIEW, this->index); /* Check no industry is related to us. */ - const Industry *i; - FOR_ALL_INDUSTRIES(i) assert(i->town != this); + for (const Industry *i : Industry::Iterate()) assert(i->town != this); /* ... and no object is related to us. */ const Object *o;