summaryrefslogtreecommitdiff
path: root/src/saveload
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 /src/saveload
parent3a14cea068d130e11b5d9dde11d4451dd7dec453 (diff)
downloadopenttd-ddabfed1cd3efa9ee229214207a60fc7cb3e0641.tar.xz
Codechange: Replace station related FOR_ALL with range-based for loops
Diffstat (limited to 'src/saveload')
-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
5 files changed, 33 insertions, 64 deletions
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
}