summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-12-15 05:55:59 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-12-21 20:13:03 +0100
commitddabfed1cd3efa9ee229214207a60fc7cb3e0641 (patch)
tree824eddd3155d04363864731a43a6863cd7fbd2a3
parent3a14cea068d130e11b5d9dde11d4451dd7dec453 (diff)
downloadopenttd-ddabfed1cd3efa9ee229214207a60fc7cb3e0641.tar.xz
Codechange: Replace station related FOR_ALL with range-based for loops
-rw-r--r--src/aircraft_cmd.cpp3
-rw-r--r--src/base_station_base.h11
-rw-r--r--src/disaster_vehicle.cpp3
-rw-r--r--src/economy.cpp16
-rw-r--r--src/linkgraph/linkgraph_gui.cpp3
-rw-r--r--src/network/network_server.cpp3
-rw-r--r--src/openttd.cpp3
-rw-r--r--src/saveload/afterload.cpp67
-rw-r--r--src/saveload/cargopacket_sl.cpp6
-rw-r--r--src/saveload/company_sl.cpp3
-rw-r--r--src/saveload/station_sl.cpp18
-rw-r--r--src/saveload/vehicle_sl.cpp3
-rw-r--r--src/script/api/script_depotlist.cpp3
-rw-r--r--src/script/api/script_stationlist.cpp3
-rw-r--r--src/script/api/script_town.cpp3
-rw-r--r--src/script/api/script_waypointlist.cpp3
-rw-r--r--src/settings.cpp3
-rw-r--r--src/station.cpp9
-rw-r--r--src/station_base.h2
-rw-r--r--src/station_cmd.cpp24
-rw-r--r--src/station_gui.cpp6
-rw-r--r--src/terraform_gui.cpp3
-rw-r--r--src/town_cmd.cpp6
-rw-r--r--src/vehicle.cpp3
-rw-r--r--src/viewport.cpp6
-rw-r--r--src/waypoint_base.h6
-rw-r--r--src/waypoint_cmd.cpp8
27 files changed, 76 insertions, 151 deletions
diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp
index fe0ae78b4..262834344 100644
--- a/src/aircraft_cmd.cpp
+++ b/src/aircraft_cmd.cpp
@@ -119,7 +119,6 @@ enum HelicopterRotorStates {
*/
static StationID FindNearestHangar(const Aircraft *v)
{
- const Station *st;
uint best = 0;
StationID index = INVALID_STATION;
TileIndex vtile = TileVirtXY(v->x_pos, v->y_pos);
@@ -140,7 +139,7 @@ static StationID FindNearestHangar(const Aircraft *v)
}
}
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->owner != v->owner || !(st->facilities & FACIL_AIRPORT) || !st->airport.HasHangar()) continue;
const AirportFTAClass *afc = st->airport.GetFTA();
diff --git a/src/base_station_base.h b/src/base_station_base.h
index a23a7bf51..a1c935fce 100644
--- a/src/base_station_base.h
+++ b/src/base_station_base.h
@@ -163,8 +163,6 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> {
static void PostDestructor(size_t index);
};
-#define FOR_ALL_BASE_STATIONS(var) FOR_ALL_ITEMS_FROM(BaseStation, station_index, var, 0)
-
/**
* Class defining several overloaded accessors so we don't
* have to cast base stations that often
@@ -252,8 +250,13 @@ struct SpecializedStation : public BaseStation {
assert(IsExpected(st));
return (const T *)st;
}
-};
-#define FOR_ALL_BASE_STATIONS_OF_TYPE(name, var) FOR_ALL_ITEMS_FROM(name, station_index, var, 0) if (name::IsExpected(var))
+ /**
+ * Returns an iterable ensemble of all valid stations of type T
+ * @param from index of the first station to consider
+ * @return an iterable ensemble of all valid stations of type T
+ */
+ static Pool::IterateWrapper<T> Iterate(size_t from = 0) { return Pool::IterateWrapper<T>(from); }
+};
#endif /* BASE_STATION_BASE_H */
diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp
index 40ac55c89..faf0a9e92 100644
--- a/src/disaster_vehicle.cpp
+++ b/src/disaster_vehicle.cpp
@@ -708,8 +708,7 @@ static void Disaster_Zeppeliner_Init()
/* Pick a random place, unless we find a small airport */
int x = TileX(Random()) * TILE_SIZE + TILE_SIZE / 2;
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->airport.tile != INVALID_TILE && (st->airport.type == AT_SMALL || st->airport.type == AT_LARGE)) {
x = (TileX(st->airport.tile) + 2) * TILE_SIZE;
break;
diff --git a/src/economy.cpp b/src/economy.cpp
index f115cf9c8..468111a8e 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -112,10 +112,9 @@ Money CalculateCompanyValue(const Company *c, bool including_loan)
{
Owner owner = c->index;
- Station *st;
uint num = 0;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->owner == owner) num += CountBits((byte)st->facilities);
}
@@ -188,9 +187,7 @@ int UpdateCompanyRatingAndValue(Company *c, bool update)
/* Count stations */
{
uint num = 0;
- const Station *st;
-
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
/* Only count stations that are actually serviced */
if (st->owner == owner && (st->time_since_load <= 20 || st->time_since_unload <= 20)) num += CountBits((byte)st->facilities);
}
@@ -514,8 +511,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
if (new_owner != INVALID_OWNER) Company::Get(new_owner)->infrastructure.airport += Company::Get(old_owner)->infrastructure.airport;
/* convert owner of stations (including deleted ones, but excluding buoys) */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->owner == old_owner) {
/* if a company goes bankrupt, set owner to OWNER_NONE so the sign doesn't disappear immediately
* also, drawing station window would cause reading invalid company's colour */
@@ -524,8 +520,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
}
/* do the same for waypoints (we need to do this here so deleted waypoints are converted too) */
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
if (wp->owner == old_owner) {
wp->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
}
@@ -663,8 +658,7 @@ static void CompaniesGenStatistics()
Backup<CompanyID> cur_company(_current_company, FILE_LINE);
if (!_settings_game.economy.infrastructure_maintenance) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
cur_company.Change(st->owner);
CommandCost cost(EXPENSES_PROPERTY, _price[PR_STATION_VALUE] >> 1);
SubtractMoneyFromCompany(cost);
diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp
index 6eb1d68b2..b5fbc50ff 100644
--- a/src/linkgraph/linkgraph_gui.cpp
+++ b/src/linkgraph/linkgraph_gui.cpp
@@ -56,8 +56,7 @@ void LinkGraphOverlay::RebuildCache()
DrawPixelInfo dpi;
this->GetWidgetDpi(&dpi);
- const Station *sta;
- FOR_ALL_STATIONS(sta) {
+ for (const Station *sta : Station::Iterate()) {
if (sta->rect.IsEmpty()) continue;
Point pta = this->GetStationMiddle(sta);
diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp
index a8322ff90..7eabf24f5 100644
--- a/src/network/network_server.cpp
+++ b/src/network/network_server.cpp
@@ -1547,7 +1547,6 @@ void NetworkSocketHandler::SendCompanyInformation(Packet *p, const Company *c, c
void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
{
const Vehicle *v;
- const Station *s;
memset(stats, 0, sizeof(*stats) * MAX_COMPANIES);
@@ -1566,7 +1565,7 @@ void NetworkPopulateCompanyStats(NetworkCompanyStats *stats)
}
/* Go through all stations and count the types of stations */
- FOR_ALL_STATIONS(s) {
+ for (const Station *s : Station::Iterate()) {
if (Company::IsValidID(s->owner)) {
NetworkCompanyStats *npi = &stats[s->owner];
diff --git a/src/openttd.cpp b/src/openttd.cpp
index fde01111d..cf79419cc 100644
--- a/src/openttd.cpp
+++ b/src/openttd.cpp
@@ -1313,8 +1313,7 @@ static void CheckCaches()
assert(memcmp(&v->cargo, buff, sizeof(VehicleCargoList)) == 0);
}
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
byte buff[sizeof(StationCargoList)];
memcpy(buff, &st->goods[c].cargo, sizeof(StationCargoList));
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index c10904c8a..d79cd9410 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -266,8 +266,7 @@ static void InitializeWindowsAndCaches()
i->psa->tile = i->location.tile;
}
}
- Station *s;
- FOR_ALL_STATIONS(s) {
+ for (Station *s : Station::Iterate()) {
if (s->airport.psa != nullptr) {
s->airport.psa->feature = GSF_AIRPORTS;
s->airport.psa->tile = s->airport.tile;
@@ -587,14 +586,13 @@ bool AfterLoadGame()
* recompute the width and height. Doing this unconditionally for all old
* savegames simplifies the code. */
if (IsSavegameVersionBefore(SLV_2)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
st->train_station.w = st->train_station.h = 0;
}
for (TileIndex t = 0; t < map_size; t++) {
if (!IsTileType(t, MP_STATION)) continue;
if (_m[t].m5 > 7) continue; // is it a rail station tile?
- st = Station::Get(_m[t].m2);
+ Station *st = Station::Get(_m[t].m2);
assert(st->train_station.tile != 0);
int dx = TileX(t) - TileX(st->train_station.tile);
int dy = TileY(t) - TileY(st->train_station.tile);
@@ -650,8 +648,7 @@ bool AfterLoadGame()
if (c->president_name != nullptr) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
}
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
st->name = CopyFromOldName(st->string_id);
/* generating new name would be too much work for little effect, use the station name fallback */
if (st->name != nullptr) st->string_id = STR_SV_STNAME_FALLBACK;
@@ -669,8 +666,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_106)) {
/* no station is determined by 'tile == INVALID_TILE' now (instead of '0') */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
}
@@ -784,8 +780,7 @@ bool AfterLoadGame()
* here as AfterLoadVehicles can check it indirectly via the newgrf
* code. */
if (IsSavegameVersionBefore(SLV_139)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->airport.tile != INVALID_TILE && st->airport.type == 15) {
st->airport.type = AT_OILRIG;
}
@@ -1398,8 +1393,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_26)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
st->last_vehicle_type = VEH_INVALID;
}
}
@@ -1420,8 +1414,6 @@ bool AfterLoadGame()
/* Time starts at 0 instead of 1920.
* Account for this in older games by adding an offset */
if (IsSavegameVersionBefore(SLV_31)) {
- Station *st;
- Waypoint *wp;
Engine *e;
Industry *i;
Vehicle *v;
@@ -1429,8 +1421,8 @@ bool AfterLoadGame()
_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
_cur_year += ORIGINAL_BASE_YEAR;
- FOR_ALL_STATIONS(st) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
- FOR_ALL_WAYPOINTS(wp) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
+ for (Station *st : Station::Iterate()) st->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
+ for (Waypoint *wp : Waypoint::Iterate()) wp->build_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_ENGINES(e) 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;
@@ -1565,8 +1557,7 @@ bool AfterLoadGame()
/* Buoys do now store the owner of the previous water tile, which can never
* be OWNER_NONE. So replace OWNER_NONE with OWNER_WATER. */
if (IsSavegameVersionBefore(SLV_46)) {
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
if ((wp->facilities & FACIL_DOCK) != 0 && IsTileOwner(wp->xy, OWNER_NONE) && TileHeight(wp->xy) == 0) SetTileOwner(wp->xy, OWNER_WATER);
}
}
@@ -1624,8 +1615,7 @@ bool AfterLoadGame()
} else if (IsSavegameVersionBefore(SLV_59)) {
/* For some reason non-loading vehicles could be in the station's loading vehicle list */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
std::list<Vehicle *>::iterator iter;
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end();) {
Vehicle *v = *iter;
@@ -1704,8 +1694,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_74)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
st->goods[c].last_speed = 0;
if (st->goods[c].cargo.AvailableCount() != 0) SetBit(st->goods[c].status, GoodsEntry::GES_RATING);
@@ -2037,8 +2026,7 @@ bool AfterLoadGame()
/* Station can get named based on an industry type, but the current ones
* are not, so mark them as if they are not named by an industry. */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
st->indtype = IT_INVALID;
}
}
@@ -2174,8 +2162,7 @@ bool AfterLoadGame()
/* There could be (deleted) stations with invalid owner, set owner to OWNER NONE.
* The conversion affects oil rigs and buoys too, but it doesn't matter as
* they have st->owner == OWNER_NONE already. */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (!Company::IsValidID(st->owner)) st->owner = OWNER_NONE;
}
}
@@ -2213,8 +2200,7 @@ bool AfterLoadGame()
* However, some 0.7 versions might have cargo payment. For those we just
* add cargopayment for the vehicles that don't have it.
*/
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
std::list<Vehicle *>::iterator iter;
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
/* There are always as many CargoPayments as Vehicles. We need to make the
@@ -2252,8 +2238,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_124) && !IsSavegameVersionBefore(SLV_1)) {
/* The train station tile area was added, but for really old (TTDPatch) it's already valid. */
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
if (wp->facilities & FACIL_TRAIN) {
wp->train_station.tile = wp->xy;
wp->train_station.w = 1;
@@ -2443,8 +2428,7 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_140)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->airport.tile != INVALID_TILE) {
st->airport.w = st->airport.GetSpec()->size_x;
st->airport.h = st->airport.GetSpec()->size_y;
@@ -2548,12 +2532,11 @@ bool AfterLoadGame()
* renumber those. First set all affected waypoints to the
* highest possible number to get them numbered in the
* order they have in the pool. */
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
if (wp->name != nullptr) wp->town_cn = UINT16_MAX;
}
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint* wp : Waypoint::Iterate()) {
if (wp->name != nullptr) MakeDefaultName(wp);
}
}
@@ -2806,8 +2789,7 @@ bool AfterLoadGame()
}
if (!IsSavegameVersionBefore(SLV_145)) {
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (!(st->facilities & FACIL_AIRPORT)) continue;
assert(st->airport.psa != nullptr);
@@ -3142,8 +3124,7 @@ bool AfterLoadGame()
_settings_game.station.serve_neutral_industries = true;
/* Link oil rigs to their industry and back. */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (IsTileType(st->xy, MP_STATION) && IsOilRig(st->xy)) {
/* Industry tile is always adjacent during construction by TileDiffXY(0, 1) */
st->industry = Industry::GetByTile(st->xy + TileDiffXY(0, 1));
@@ -3178,8 +3159,7 @@ bool AfterLoadGame()
}
/* Scan for docking tiles */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->ship_station.tile != INVALID_TILE) UpdateStationDockingTiles(st);
}
}
@@ -3189,8 +3169,7 @@ bool AfterLoadGame()
/* Station acceptance is some kind of cache */
if (IsSavegameVersionBefore(SLV_127)) {
- Station *st;
- FOR_ALL_STATIONS(st) UpdateStationAcceptance(st, false);
+ for (Station *st : Station::Iterate()) UpdateStationAcceptance(st, false);
}
/* Road stops is 'only' updating some caches */
diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp
index d0797212d..90aa33cf9 100644
--- a/src/saveload/cargopacket_sl.cpp
+++ b/src/saveload/cargopacket_sl.cpp
@@ -42,8 +42,7 @@
* station where the goods came from is already removed, the source
* information is lost. In that case we set it to the position of this
* station */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) {
GoodsEntry *ge = &st->goods[c];
@@ -72,8 +71,7 @@
Vehicle *v;
FOR_ALL_VEHICLES(v) v->cargo.InvalidateCache();
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
}
}
diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp
index e1dc5cdc2..5b9266c7b 100644
--- a/src/saveload/company_sl.cpp
+++ b/src/saveload/company_sl.cpp
@@ -97,8 +97,7 @@ void AfterLoadCompanyStats()
for (Company *c : Company::Iterate()) MemSetT(&c->infrastructure, 0);
/* Collect airport count. */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if ((st->facilities & FACIL_AIRPORT) && Company::IsValidID(st->owner)) {
Company::Get(st->owner)->infrastructure.airport++;
}
diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp
index ac38bb0cf..7b091e2f1 100644
--- a/src/saveload/station_sl.cpp
+++ b/src/saveload/station_sl.cpp
@@ -57,8 +57,7 @@ void MoveBuoysToWaypoints()
}
/* Now make the stations waypoints */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if ((st->had_vehicle_of_type & HVOT_WAYPOINT) == 0) continue;
StationID index = st->index;
@@ -109,8 +108,7 @@ void MoveBuoysToWaypoints()
void AfterLoadStations()
{
/* Update the speclists of all stations to point to the currently loaded custom stations. */
- BaseStation *st;
- FOR_ALL_BASE_STATIONS(st) {
+ for (BaseStation *st : BaseStation::Iterate()) {
for (uint i = 0; i < st->num_specs; i++) {
if (st->speclist[i].grfid == 0) continue;
@@ -376,8 +374,7 @@ static void Ptrs_STNS()
if (!IsSavegameVersionBefore(SLV_123)) return;
uint num_cargo = IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (!IsSavegameVersionBefore(SLV_68)) {
for (CargoID i = 0; i < num_cargo; i++) {
GoodsEntry *ge = &st->goods[i];
@@ -514,9 +511,8 @@ static void RealSave_STNN(BaseStation *bst)
static void Save_STNN()
{
- BaseStation *st;
/* Write the stations */
- FOR_ALL_BASE_STATIONS(st) {
+ for (BaseStation *st : BaseStation::Iterate()) {
SlSetArrayIndex(st->index);
SlAutolength((AutolengthProc*)RealSave_STNN, st);
}
@@ -588,8 +584,7 @@ static void Ptrs_STNN()
if (IsSavegameVersionBefore(SLV_123)) return;
uint num_cargo = IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID i = 0; i < num_cargo; i++) {
GoodsEntry *ge = &st->goods[i];
if (IsSavegameVersionBefore(SLV_183)) {
@@ -606,8 +601,7 @@ static void Ptrs_STNN()
SlObject(st, _station_desc);
}
- Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
SlObject(wp, _waypoint_desc);
}
}
diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp
index a20c51a09..3529c84eb 100644
--- a/src/saveload/vehicle_sl.cpp
+++ b/src/saveload/vehicle_sl.cpp
@@ -165,8 +165,7 @@ void ConvertOldMultiheadToNew()
void UpdateOldAircraft()
{
/* set airport_flags to 0 for all airports just to be sure */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
st->airport.flags = 0; // reset airport
}
diff --git a/src/script/api/script_depotlist.cpp b/src/script/api/script_depotlist.cpp
index be0071473..ab2e09cfd 100644
--- a/src/script/api/script_depotlist.cpp
+++ b/src/script/api/script_depotlist.cpp
@@ -26,8 +26,7 @@ ScriptDepotList::ScriptDepotList(ScriptTile::TransportType transport_type)
case ScriptTile::TRANSPORT_AIR: {
/* Hangars are not seen as real depots by the depot code. */
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) {
for (uint i = 0; i < st->airport.GetNumHangars(); i++) {
this->AddItem(st->airport.GetHangarTile(i));
diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp
index 9c2a56da9..9b9e67e7a 100644
--- a/src/script/api/script_stationlist.cpp
+++ b/src/script/api/script_stationlist.cpp
@@ -18,8 +18,7 @@
ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
{
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if ((st->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY) && (st->facilities & station_type) != 0) this->AddItem(st->index);
}
}
diff --git a/src/script/api/script_town.cpp b/src/script/api/script_town.cpp
index fb5589707..1cb6e32bb 100644
--- a/src/script/api/script_town.cpp
+++ b/src/script/api/script_town.cpp
@@ -346,8 +346,7 @@
}
int num = 0;
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
}
return max(0, 2 - num);
diff --git a/src/script/api/script_waypointlist.cpp b/src/script/api/script_waypointlist.cpp
index 12f5f6bf1..1c0a804d1 100644
--- a/src/script/api/script_waypointlist.cpp
+++ b/src/script/api/script_waypointlist.cpp
@@ -17,8 +17,7 @@
ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)
{
- const Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (const Waypoint *wp : Waypoint::Iterate()) {
if ((wp->facilities & waypoint_type) &&
(wp->owner == ScriptObject::GetCompany() || ScriptObject::GetCompany() == OWNER_DEITY || wp->owner == OWNER_NONE)) this->AddItem(wp->index);
}
diff --git a/src/settings.cpp b/src/settings.cpp
index cc29304df..98c273876 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1233,8 +1233,7 @@ static bool CheckFreeformEdges(int32 p1)
return false;
}
}
- BaseStation *st;
- FOR_ALL_BASE_STATIONS(st) {
+ for (const BaseStation *st : BaseStation::Iterate()) {
/* Check if there is a non-deleted buoy on the northern border. */
if (st->IsInUse() && (TileX(st->xy) == 0 || TileY(st->xy) == 0)) {
ShowErrorMessage(STR_CONFIG_SETTING_EDGES_NOT_EMPTY, INVALID_STRING_ID, WL_ERROR);
diff --git a/src/station.cpp b/src/station.cpp
index 59fee57da..2a343d798 100644
--- a/src/station.cpp
+++ b/src/station.cpp
@@ -42,8 +42,7 @@ StationKdtree _station_kdtree(Kdtree_StationXYFunc);
void RebuildStationKdtree()
{
std::vector<StationID> stids;
- BaseStation *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
stids.push_back(st->index);
}
_station_kdtree.Build(stids.begin(), stids.end());
@@ -480,8 +479,7 @@ void Station::RecomputeCatchment()
*/
/* static */ void Station::RecomputeCatchmentForAll()
{
- Station *st;
- FOR_ALL_STATIONS(st) { st->RecomputeCatchment(); }
+ for (Station *st : Station::Iterate()) { st->RecomputeCatchment(); }
}
/************************************************************************/
@@ -660,8 +658,7 @@ Money AirportMaintenanceCost(Owner owner)
{
Money total_cost = 0;
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->owner == owner && (st->facilities & FACIL_AIRPORT)) {
total_cost += _price[PR_INFRASTRUCTURE_AIRPORT] * st->airport.GetSpec()->maintenance_cost;
}
diff --git a/src/station_base.h b/src/station_base.h
index ca5fd61da..0c33a58ed 100644
--- a/src/station_base.h
+++ b/src/station_base.h
@@ -525,8 +525,6 @@ public:
void GetTileArea(TileArea *ta, StationType type) const override;
};
-#define FOR_ALL_STATIONS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Station, var)
-
/** Iterator to iterate over all tiles belonging to an airport. */
class AirportTileIterator : public OrthogonalTileIterator {
private:
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index aa5afb97c..126e6fd9d 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -251,8 +251,7 @@ static StringID GenerateStationName(Station *st, TileIndex tile, StationNaming n
bool indtypes[NUM_INDUSTRYTYPES];
memset(indtypes, 0, sizeof(indtypes));
- const Station *s;
- FOR_ALL_STATIONS(s) {
+ for (const Station *s : Station::Iterate()) {
if (s != st && s->town == t) {
if (s->indtype != IT_INVALID) {
indtypes[s->indtype] = true;
@@ -449,9 +448,7 @@ void Station::MoveSign(TileIndex new_xy)
/** Update the virtual coords needed to draw the station sign for all stations. */
void UpdateAllStationVirtCoords()
{
- BaseStation *st;
-
- FOR_ALL_BASE_STATIONS(st) {
+ for (BaseStation *st : BaseStation::Iterate()) {
st->UpdateVirtCoord();
}
}
@@ -2212,11 +2209,10 @@ Town *AirportGetNearestTown(const AirportSpec *as, const TileIterator &it, uint
void UpdateAirportsNoise()
{
Town *t;
- const Station *st;
FOR_ALL_TOWNS(t) t->noise_reached = 0;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->airport.tile != INVALID_TILE && st->airport.type != AT_OILRIG) {
const AirportSpec *as = st->airport.GetSpec();
AirportTileIterator it(st);
@@ -2293,8 +2289,7 @@ CommandCost CmdBuildAirport(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
} else {
Town *t = ClosestTownFromTile(tile, UINT_MAX);
uint num = 0;
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->town == t && (st->facilities & FACIL_AIRPORT) && st->airport.type != AT_OILRIG) num++;
}
if (num >= 2) {
@@ -3824,8 +3819,7 @@ void OnTick_Station()
{
if (_game_mode == GM_EDITOR) return;
- BaseStation *st;
- FOR_ALL_BASE_STATIONS(st) {
+ for (BaseStation *st : BaseStation::Iterate()) {
StationHandleSmallTick(st);
/* Clean up the link graph about once a week. */
@@ -3848,9 +3842,7 @@ void OnTick_Station()
/** Monthly loop for stations. */
void StationMonthlyLoop()
{
- Station *st;
-
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
for (CargoID i = 0; i < NUM_CARGO; i++) {
GoodsEntry *ge = &st->goods[i];
SB(ge->status, GoodsEntry::GES_LAST_MONTH, 1, GB(ge->status, GoodsEntry::GES_CURRENT_MONTH, 1));
@@ -3922,9 +3914,7 @@ static uint UpdateStationWaiting(Station *st, CargoID type, uint amount, SourceT
static bool IsUniqueStationName(const char *name)
{
- const Station *st;
-
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->name != nullptr && strcmp(st->name, name) == 0) return false;
}
diff --git a/src/station_gui.cpp b/src/station_gui.cpp
index 17b884e50..a4804528c 100644
--- a/src/station_gui.cpp
+++ b/src/station_gui.cpp
@@ -229,8 +229,7 @@ protected:
this->stations.clear();
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->owner == owner || (st->owner == OWNER_NONE && HasStationInUse(st->index, true, owner))) {
if (this->facilities & st->facilities) { // only stations with selected facilities
int num_waiting_cargo = 0;
@@ -2242,8 +2241,7 @@ static const T *FindStationsNearby(TileArea ta, bool distant_join)
}
/* Look for deleted stations */
- const BaseStation *st;
- FOR_ALL_BASE_STATIONS(st) {
+ for (const BaseStation *st : BaseStation::Iterate()) {
if (T::IsExpected(st) && !st->IsInUse() && st->owner == _local_company) {
/* Include only within station spread (yes, it is strictly less than) */
if (max(DistanceMax(ta.tile, st->xy), DistanceMax(TILE_ADDXY(ta.tile, ta.w - 1, ta.h - 1), st->xy)) < _settings_game.station.station_spread) {
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 2f65bb610..9f727ce72 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -508,8 +508,7 @@ static void ResetLandscapeConfirmationCallback(Window *w, bool confirmed)
_generating_world = false;
/* Delete all station signs */
- BaseStation *st;
- FOR_ALL_BASE_STATIONS(st) {
+ for (BaseStation *st : BaseStation::Iterate()) {
/* There can be buoys, remove them */
if (IsBuoyTile(st->xy)) DoCommand(st->xy, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
if (!st->IsInUse()) delete st;
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 6f907bc3c..2c7393ce5 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -2872,8 +2872,7 @@ CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
if (t == nullptr) return CMD_ERROR;
/* Stations refer to towns. */
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->town == t) {
/* Non-oil rig stations are always a problem. */
if (!(st->facilities & FACIL_AIRPORT) || st->airport.type != AT_OILRIG) return CMD_ERROR;
@@ -3159,8 +3158,7 @@ static CommandCost TownActionBribe(Town *t, DoCommandFlag flags)
t->unwanted[_current_company] = 6;
/* set all close by station ratings to 0 */
- Station *st;
- FOR_ALL_STATIONS(st) {
+ for (Station *st : Station::Iterate()) {
if (st->town == t && st->owner == _current_company) {
for (CargoID i = 0; i < NUM_CARGO; i++) st->goods[i].rating = 0;
}
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 2eaeb38e5..3e14c982e 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -947,8 +947,7 @@ void CallVehicleTicks()
{
PerformanceMeasurer framerate(PFE_GL_ECONOMY);
- Station *st;
- FOR_ALL_STATIONS(st) LoadUnloadStation(st);
+ for (Station *st : Station::Iterate()) LoadUnloadStation(st);
}
PerformanceAccumulator::Reset(PFE_GL_TRAINS);
PerformanceAccumulator::Reset(PFE_GL_ROADVEHS);
diff --git a/src/viewport.cpp b/src/viewport.cpp
index 94245cf6c..27bbdad51 100644
--- a/src/viewport.cpp
+++ b/src/viewport.cpp
@@ -2247,13 +2247,11 @@ void RebuildViewportKdtree()
std::vector<ViewportSignKdtreeItem> items;
items.reserve(BaseStation::GetNumItems() + Town::GetNumItems() + Sign::GetNumItems());
- const Station *st;
- FOR_ALL_STATIONS(st) {
+ for (const Station *st : Station::Iterate()) {
if (st->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeStation(st->index));
}
- const Waypoint *wp;
- FOR_ALL_WAYPOINTS(wp) {
+ for (const Waypoint *wp : Waypoint::Iterate()) {
if (wp->sign.kdtree_valid) items.push_back(ViewportSignKdtreeItem::MakeWaypoint(wp->index));
}
diff --git a/src/waypoint_base.h b/src/waypoint_base.h
index 3ebb649ad..2c7cc530f 100644
--- a/src/waypoint_base.h
+++ b/src/waypoint_base.h
@@ -67,10 +67,4 @@ struct Waypoint FINAL : SpecializedStation<Waypoint, true> {
}
};
-/**
- * Iterate over all waypoints.
- * @param var The variable used for iteration.
- */
-#define FOR_ALL_WAYPOINTS(var) FOR_ALL_BASE_STATIONS_OF_TYPE(Waypoint, var)
-
#endif /* WAYPOINT_BASE_H */
diff --git a/src/waypoint_cmd.cpp b/src/waypoint_cmd.cpp
index d55b1b459..51d791fc2 100644
--- a/src/waypoint_cmd.cpp
+++ b/src/waypoint_cmd.cpp
@@ -70,10 +70,10 @@ void Waypoint::MoveSign(TileIndex new_xy)
*/
static Waypoint *FindDeletedWaypointCloseTo(TileIndex tile, StringID str, CompanyID cid)
{
- Waypoint *wp, *best = nullptr;
+ Waypoint *best = nullptr;
uint thres = 8;
- FOR_ALL_WAYPOINTS(wp) {
+ for (Waypoint *wp : Waypoint::Iterate()) {
if (!wp->IsInUse() && wp->string_id == str && wp->owner == cid) {
uint cur_dist = DistanceManhattan(tile, wp->xy);
@@ -397,9 +397,7 @@ CommandCost RemoveBuoy(TileIndex tile, DoCommandFlag flags)
*/
static bool IsUniqueWaypointName(const char *name)
{
- const Waypoint *wp;
-
- FOR_ALL_WAYPOINTS(wp) {
+ for (const Waypoint *wp : Waypoint::Iterate()) {
if (wp->name != nullptr && strcmp(wp->name, name) == 0) return false;
}