diff options
author | glx <glx@openttd.org> | 2019-12-17 03:37:43 +0100 |
---|---|---|
committer | Niels Martin Hansen <nielsm@indvikleren.dk> | 2019-12-21 20:13:03 +0100 |
commit | d8a1be48cd60c690235de175e9a044b95f92ea28 (patch) | |
tree | 2e1481aa11661c28df49f0d62f56fbf730577152 /src/saveload | |
parent | 9892d90b26db4dfe97ec7baeb89e43acb53a178e (diff) | |
download | openttd-d8a1be48cd60c690235de175e9a044b95f92ea28.tar.xz |
Codechange: Replace vehicle related FOR_ALL with range-based for loops
Diffstat (limited to 'src/saveload')
-rw-r--r-- | src/saveload/afterload.cpp | 98 | ||||
-rw-r--r-- | src/saveload/cargopacket_sl.cpp | 9 | ||||
-rw-r--r-- | src/saveload/oldloader_sl.cpp | 7 | ||||
-rw-r--r-- | src/saveload/station_sl.cpp | 3 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 57 | ||||
-rw-r--r-- | src/saveload/waypoint_sl.cpp | 3 |
6 files changed, 62 insertions, 115 deletions
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 39ee5b845..8df01bc58 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -278,8 +278,7 @@ static void InitializeWindowsAndCaches() (*it)->tile = t->xy; } } - RoadVehicle *rv; - FOR_ALL_ROADVEHICLES(rv) { + for (RoadVehicle *rv : RoadVehicle::Iterate()) { if (rv->IsFrontEngine()) { rv->CargoChanged(); } @@ -436,8 +435,8 @@ static void FixOwnerOfRailTrack(TileIndex t) assert(!Company::IsValidID(GetTileOwner(t)) && (IsLevelCrossingTile(t) || IsPlainRailTile(t))); /* remove leftover rail piece from crossing (from very old savegames) */ - Train *v = nullptr, *w; - FOR_ALL_TRAINS(w) { + Train *v = nullptr; + for (Train *w : Train::Iterate()) { if (w->tile == t) { v = w; break; @@ -1175,8 +1174,6 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_42)) { - Vehicle *v; - for (TileIndex t = 0; t < map_size; t++) { if (MayHaveBridgeAbove(t)) ClearBridgeMiddle(t); if (IsBridgeTile(t)) { @@ -1230,7 +1227,7 @@ bool AfterLoadGame() } } - FOR_ALL_VEHICLES(v) { + for (Vehicle* v : Vehicle::Iterate()) { if (!v->IsGroundVehicle()) continue; if (IsBridgeTile(v->tile)) { DiagDirection dir = GetTunnelBridgeDirection(v->tile); @@ -1289,8 +1286,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_24)) { RailType min_rail = RAILTYPE_ELECTRIC; - Train *v; - FOR_ALL_TRAINS(v) { + for (Train *v : Train::Iterate()) { RailType rt = RailVehInfo(v->engine_type)->railtype; v->railtype = rt; @@ -1327,7 +1323,7 @@ bool AfterLoadGame() } } - FOR_ALL_TRAINS(v) { + for (Train *v : Train::Iterate()) { if (v->IsFrontEngine() || v->IsFreeWagon()) v->ConsistChanged(CCF_TRACK); } @@ -1384,8 +1380,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_25)) { - RoadVehicle *rv; - FOR_ALL_ROADVEHICLES(rv) { + for (RoadVehicle *rv : RoadVehicle::Iterate()) { rv->vehstatus &= ~0x40; } } @@ -1412,8 +1407,6 @@ bool AfterLoadGame() /* Time starts at 0 instead of 1920. * Account for this in older games by adding an offset */ if (IsSavegameVersionBefore(SLV_31)) { - Vehicle *v; - _date += DAYS_TILL_ORIGINAL_BASE_YEAR; _cur_year += ORIGINAL_BASE_YEAR; @@ -1423,7 +1416,7 @@ bool AfterLoadGame() for (Company *c : Company::Iterate()) c->inaugurated_year += ORIGINAL_BASE_YEAR; for (Industry *i : Industry::Iterate()) i->last_prod_year += ORIGINAL_BASE_YEAR; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { v->date_of_last_service += DAYS_TILL_ORIGINAL_BASE_YEAR; v->build_year += ORIGINAL_BASE_YEAR; } @@ -1451,13 +1444,11 @@ bool AfterLoadGame() /* Setting no refit flags to all orders in savegames from before refit in orders were added */ if (IsSavegameVersionBefore(SLV_36)) { - Vehicle *v; - for (Order *order : Order::Iterate()) { order->SetRefit(CT_NO_REFIT); } - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { v->current_order.SetRefit(CT_NO_REFIT); } } @@ -1536,13 +1527,12 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_45)) { - Vehicle *v; /* Originally just the fact that some cargo had been paid for was * stored to stop people cheating and cashing in several times. This * wasn't enough though as it was cleared when the vehicle started * loading again, even if it didn't actually load anything, so now the * amount that has been paid is stored. */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { ClrBit(v->vehicle_flags, 2); } } @@ -1556,9 +1546,8 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_50)) { - Aircraft *v; /* Aircraft units changed from 8 mph to 1 km-ish/h */ - FOR_ALL_AIRCRAFT(v) { + for (Aircraft *v : Aircraft::Iterate()) { if (v->subtype <= AIR_AIRCRAFT) { const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); v->cur_speed *= 128; @@ -1592,9 +1581,8 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_57)) { - Vehicle *v; /* Added a FIFO queue of vehicles loading at stations */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if ((v->type != VEH_TRAIN || Train::From(v)->IsFrontEngine()) && // for all locs !(v->vehstatus & (VS_STOPPED | VS_CRASHED)) && // not stopped or crashed v->current_order.IsType(OT_LOADING)) { // loading @@ -1645,8 +1633,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_69)) { /* In some old savegames a bit was cleared when it should not be cleared */ - RoadVehicle *rv; - FOR_ALL_ROADVEHICLES(rv) { + for (RoadVehicle *rv : RoadVehicle::Iterate()) { if (rv->state == 250 || rv->state == 251) { SetBit(rv->state, 2); } @@ -1725,8 +1712,7 @@ bool AfterLoadGame() /* Rework of orders. */ for (Order *order : Order::Iterate()) order->ConvertFromOldSavegame(); - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->orders.list != nullptr && v->orders.list->GetFirstOrder() != nullptr && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) { v->orders.list->FreeChain(); v->orders.list = nullptr; @@ -1747,8 +1733,7 @@ bool AfterLoadGame() } } - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if ((v->current_order.GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) { v->current_order.SetUnloadType(OUFB_TRANSFER); v->current_order.SetLoadType(OLFB_NO_LOAD); @@ -1897,8 +1882,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_88)) { /* Profits are now with 8 bit fract */ - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { v->profit_this_year <<= 8; v->profit_last_year <<= 8; v->running_ticks = 0; @@ -1919,8 +1903,7 @@ bool AfterLoadGame() GroupStatistics::UpdateAfterLoad(); // Ensure statistics pool is initialised before trying to delete vehicles /* Remove all trams from savegames without tram support. * There would be trams without tram track under causing crashes sooner or later. */ - RoadVehicle *v; - FOR_ALL_ROADVEHICLES(v) { + for (RoadVehicle *v : RoadVehicle::Iterate()) { if (v->First() == v && HasBit(EngInfo(v->engine_type)->misc_flags, EF_ROAD_TRAM)) { ShowErrorMessage(STR_WARNING_LOADGAME_REMOVED_TRAMS, INVALID_STRING_ID, WL_CRITICAL); delete v; @@ -1991,8 +1974,7 @@ bool AfterLoadGame() /* Reserve all tracks trains are currently on. */ if (IsSavegameVersionBefore(SLV_101)) { - const Train *t; - FOR_ALL_TRAINS(t) { + for (const Train *t : Train::Iterate()) { if (t->First() == t) t->ReserveTrackUnderConsist(); } } @@ -2022,8 +2004,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_104)) { - Aircraft *a; - FOR_ALL_AIRCRAFT(a) { + for (Aircraft *a : Aircraft::Iterate()) { /* Set engine_type of shadow and rotor */ if (!a->IsNormalAircraft()) { a->engine_type = a->First()->engine_type; @@ -2172,8 +2153,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_121)) { /* Delete small ufos heading for non-existing vehicles */ - Vehicle *v; - FOR_ALL_DISASTERVEHICLES(v) { + for (Vehicle *v : DisasterVehicle::Iterate()) { if (v->subtype == 2 /* ST_SMALL_UFO */ && v->current_order.GetDestination() != 0) { const Vehicle *u = Vehicle::GetIfValid(v->dest_tile); if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) { @@ -2335,8 +2315,7 @@ bool AfterLoadGame() /* The behaviour of force_proceed has been changed. Now * it counts signals instead of some random time out. */ if (IsSavegameVersionBefore(SLV_131)) { - Train *t; - FOR_ALL_TRAINS(t) { + for (Train *t : Train::Iterate()) { if (t->force_proceed != TFP_NONE) { t->force_proceed = TFP_STUCK; } @@ -2366,13 +2345,11 @@ bool AfterLoadGame() /* Wait counter and load/unload ticks got split. */ if (IsSavegameVersionBefore(SLV_136)) { - Aircraft *a; - FOR_ALL_AIRCRAFT(a) { + for (Aircraft *a : Aircraft::Iterate()) { a->turn_counter = a->current_order.IsType(OT_LOADING) ? 0 : a->load_unload_ticks; } - Train *t; - FOR_ALL_TRAINS(t) { + for (Train *t : Train::Iterate()) { t->wait_counter = t->current_order.IsType(OT_LOADING) ? 0 : t->load_unload_ticks; } } @@ -2447,8 +2424,7 @@ bool AfterLoadGame() * For old savegames with such aircraft we just throw them in the air and * treat the aircraft like they were flying already. */ if (IsSavegameVersionBefore(SLV_146)) { - Aircraft *v; - FOR_ALL_AIRCRAFT(v) { + for (Aircraft *v : Aircraft::Iterate()) { if (!v->IsNormalAircraft()) continue; Station *st = GetTargetAirportIfValid(v); if (st == nullptr && v->state != FLYING) { @@ -2532,8 +2508,7 @@ bool AfterLoadGame() /* The moment vehicles go from hidden to visible changed. This means * that vehicles don't always get visible anymore causing things to * get messed up just after loading the savegame. This fixes that. */ - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { /* Not all vehicle types can be inside a tunnel. Furthermore, * testing IsTunnelTile() for invalid tiles causes a crash. */ if (!v->IsGroundVehicle()) continue; @@ -2596,8 +2571,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_153)) { - RoadVehicle *rv; - FOR_ALL_ROADVEHICLES(rv) { + for (RoadVehicle *rv : RoadVehicle::Iterate()) { if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) continue; bool loading = rv->current_order.IsType(OT_LOADING) || rv->current_order.IsType(OT_LEAVESTATION); @@ -2612,8 +2586,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_156)) { /* The train's pathfinder lost flag got moved. */ - Train *t; - FOR_ALL_TRAINS(t) { + for (Train *t : Train::Iterate()) { if (!HasBit(t->flags, 5)) continue; ClrBit(t->flags, 5); @@ -2628,8 +2601,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_158)) { - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { switch (v->type) { case VEH_TRAIN: { Train *t = Train::From(v); @@ -2713,7 +2685,7 @@ bool AfterLoadGame() } /* Fill Vehicle::cur_real_order_index */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (!v->IsPrimaryVehicle()) continue; /* Older versions are less strict with indices being in range and fix them on the fly */ @@ -2733,8 +2705,7 @@ bool AfterLoadGame() * will keep reversing disabled, otherwise it'll be turned on. */ _settings_game.pf.reverse_at_signals = IsSavegameVersionBefore(SLV_100) || (_settings_game.pf.wait_oneway_signal != 255 && _settings_game.pf.wait_twoway_signal != 255 && _settings_game.pf.wait_for_pbs_path != 255); - Train *t; - FOR_ALL_TRAINS(t) { + for (Train *t : Train::Iterate()) { _settings_game.vehicle.max_train_length = max<uint8>(_settings_game.vehicle.max_train_length, CeilDiv(t->gcache.cached_total_length, TILE_SIZE)); } } @@ -2899,9 +2870,8 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_182)) { - Aircraft *v; /* Aircraft acceleration variable was bonkers */ - FOR_ALL_AIRCRAFT(v) { + for (Aircraft *v : Aircraft::Iterate()) { if (v->subtype <= AIR_AIRCRAFT) { const AircraftVehicleInfo *avi = AircraftVehInfo(v->engine_type); v->acceleration = avi->acceleration; @@ -2945,10 +2915,9 @@ bool AfterLoadGame() * Now they have the same length, but that means that trailing articulated parts will * take longer to go through the curve than the parts in front which already left the courve. * So, make articulated parts catch up. */ - RoadVehicle *v; bool roadside = _settings_game.vehicle.road_side == 1; std::vector<uint> skip_frames; - FOR_ALL_ROADVEHICLES(v) { + for (RoadVehicle *v : RoadVehicle::Iterate()) { if (!v->IsFrontEngine()) continue; skip_frames.clear(); TileIndex prev_tile = v->tile; @@ -3062,8 +3031,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_SHIPS_STOP_IN_LOCKS)) { /* Move ships from lock slope to upper or lower position. */ - Ship *s; - FOR_ALL_SHIPS(s) { + for (Ship *s : Ship::Iterate()) { /* Suitable tile? */ if (!IsTileType(s->tile, MP_WATER) || !IsLock(s->tile) || GetLockPart(s->tile) != LOCK_PART_MIDDLE) continue; diff --git a/src/saveload/cargopacket_sl.cpp b/src/saveload/cargopacket_sl.cpp index bb44c663f..e9476fd4b 100644 --- a/src/saveload/cargopacket_sl.cpp +++ b/src/saveload/cargopacket_sl.cpp @@ -21,14 +21,13 @@ /* static */ void CargoPacket::AfterLoad() { if (IsSavegameVersionBefore(SLV_44)) { - Vehicle *v; /* If we remove a station while cargo from it is still en route, payment calculation will assume * 0, 0 to be the source of the cargo, resulting in very high payments usually. v->source_xy * stores the coordinates, preserving them even if the station is removed. However, if a game is loaded * where this situation exists, the cargo-source information is lost. in this case, we set the source * to the current tile of the vehicle to prevent excessive profits */ - FOR_ALL_VEHICLES(v) { + for (const Vehicle *v : Vehicle::Iterate()) { const CargoPacketList *packets = v->cargo.Packets(); for (VehicleCargoList::ConstIterator it(packets->begin()); it != packets->end(); it++) { CargoPacket *cp = *it; @@ -67,8 +66,7 @@ /* Only since version 68 we have cargo packets. Savegames from before used * 'new CargoPacket' + cargolist.Append so their caches are already * correct and do not need rebuilding. */ - Vehicle *v; - FOR_ALL_VEHICLES(v) v->cargo.InvalidateCache(); + for (Vehicle *v : Vehicle::Iterate()) v->cargo.InvalidateCache(); for (Station *st : Station::Iterate()) { for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache(); @@ -76,8 +74,7 @@ } if (IsSavegameVersionBefore(SLV_181)) { - Vehicle *v; - FOR_ALL_VEHICLES(v) v->cargo.KeepAll(); + for (Vehicle *v : Vehicle::Iterate()) v->cargo.KeepAll(); } } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index d2befa84d..830d300b6 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -172,9 +172,7 @@ static StringID *_old_vehicle_names; */ void FixOldVehicles() { - Vehicle *v; - - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if ((size_t)v->next == 0xFFFF) { v->next = nullptr; } else { @@ -384,8 +382,7 @@ static bool FixTTOEngines() 233, 234, 235, 236, 237, 238, 253 }; - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->engine_type >= lengthof(tto_to_ttd)) return false; v->engine_type = tto_to_ttd[v->engine_type]; } diff --git a/src/saveload/station_sl.cpp b/src/saveload/station_sl.cpp index 08fc07157..2df8d8167 100644 --- a/src/saveload/station_sl.cpp +++ b/src/saveload/station_sl.cpp @@ -47,8 +47,7 @@ void MoveBuoysToWaypoints() for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o); } - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { VehicleType vt = v->type; if (vt != VEH_SHIP && vt != VEH_TRAIN) continue; diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 74a01616b..3569507c7 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -31,13 +31,11 @@ */ void ConnectMultiheadedTrains() { - Train *v; - - FOR_ALL_TRAINS(v) { + for (Train *v : Train::Iterate()) { v->other_multiheaded_part = nullptr; } - FOR_ALL_TRAINS(v) { + for (Train *v : Train::Iterate()) { if (v->IsFrontEngine() || v->IsFreeWagon()) { /* Two ways to associate multiheaded parts to each other: * sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>.. @@ -111,10 +109,9 @@ void ConnectMultiheadedTrains() */ void ConvertOldMultiheadToNew() { - Train *t; - FOR_ALL_TRAINS(t) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop + for (Train *t : Train::Iterate()) SetBit(t->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop - FOR_ALL_TRAINS(t) { + for (Train *t : Train::Iterate()) { if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) { for (Train *u = t; u != nullptr; u = u->Next()) { const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); @@ -169,8 +166,7 @@ void UpdateOldAircraft() st->airport.flags = 0; // reset airport } - Aircraft *a; - FOR_ALL_AIRCRAFT(a) { + for (Aircraft *a : Aircraft::Iterate()) { /* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) * skip those */ if (a->IsNormalAircraft()) { @@ -220,8 +216,7 @@ static void CheckValidVehicles() for (const Engine *e : Engine::IterateType(VEH_SHIP)) { first_engine[VEH_SHIP] = e->index; break; } for (const Engine *e : Engine::IterateType(VEH_AIRCRAFT)) { first_engine[VEH_AIRCRAFT] = e->index; break; } - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { /* Test if engine types match */ switch (v->type) { case VEH_TRAIN: @@ -244,9 +239,7 @@ extern byte _age_cargo_skip_counter; // From misc_sl.cpp /** Called after load to update coordinates */ void AfterLoadVehicles(bool part_of_load) { - Vehicle *v; - - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { /* Reinstate the previous pointer */ if (v->Next() != nullptr) v->Next()->previous = v; if (v->NextShared() != nullptr) v->NextShared()->previous_shared = v; @@ -267,7 +260,7 @@ void AfterLoadVehicles(bool part_of_load) */ std::map<Order*, OrderList*> mapping; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->orders.old != nullptr) { if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList if (mapping[v->orders.old] == nullptr) { @@ -294,7 +287,7 @@ void AfterLoadVehicles(bool part_of_load) } } - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { /* Fill the first pointers */ if (v->Previous() == nullptr) { for (Vehicle *u = v; u != nullptr; u = u->Next()) { @@ -306,7 +299,7 @@ void AfterLoadVehicles(bool part_of_load) if (part_of_load) { if (IsSavegameVersionBefore(SLV_105)) { /* Before 105 there was no order for shared orders, thus it messed up horribly */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->First() != v || v->orders.list != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue; /* As above, allocating OrderList here is safe. */ @@ -320,8 +313,7 @@ void AfterLoadVehicles(bool part_of_load) if (IsSavegameVersionBefore(SLV_157)) { /* The road vehicle subtype was converted to a flag. */ - RoadVehicle *rv; - FOR_ALL_ROADVEHICLES(rv) { + for (RoadVehicle *rv : RoadVehicle::Iterate()) { if (rv->subtype == 0) { /* The road vehicle is at the front. */ rv->SetFrontEngine(); @@ -337,7 +329,7 @@ void AfterLoadVehicles(bool part_of_load) if (IsSavegameVersionBefore(SLV_160)) { /* In some old savegames there might be some "crap" stored. */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) { v->current_order.Free(); v->unitnumber = 0; @@ -347,14 +339,14 @@ void AfterLoadVehicles(bool part_of_load) if (IsSavegameVersionBefore(SLV_162)) { /* Set the vehicle-local cargo age counter from the old global counter. */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { v->cargo_age_counter = _age_cargo_skip_counter; } } if (IsSavegameVersionBefore(SLV_180)) { /* Set service interval flags */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (!v->IsPrimaryVehicle()) continue; const Company *c = Company::Get(v->owner); @@ -367,13 +359,11 @@ void AfterLoadVehicles(bool part_of_load) if (IsSavegameVersionBefore(SLV_SHIP_ROTATION)) { /* Ship rotation added */ - Ship *s; - FOR_ALL_SHIPS(s) { + for (Ship *s : Ship::Iterate()) { s->rotation = s->direction; } } else { - Ship *s; - FOR_ALL_SHIPS(s) { + for (Ship *s : Ship::Iterate()) { if (s->rotation == s->direction) continue; /* In case we are rotating on gameload, set the rotation position to * the current position, otherwise the applied workaround offset would @@ -387,7 +377,7 @@ void AfterLoadVehicles(bool part_of_load) CheckValidVehicles(); - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { assert(v->first != nullptr); v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr); @@ -432,7 +422,7 @@ void AfterLoadVehicles(bool part_of_load) /* Stop non-front engines */ if (part_of_load && IsSavegameVersionBefore(SLV_112)) { - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->type == VEH_TRAIN) { Train *t = Train::From(v); if (!t->IsFrontEngine()) { @@ -450,7 +440,7 @@ void AfterLoadVehicles(bool part_of_load) } } - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { switch (v->type) { case VEH_ROAD: case VEH_TRAIN: @@ -494,8 +484,7 @@ void FixupTrainLengths() { /* Vehicle center was moved from 4 units behind the front to half the length * behind the front. Move vehicles so they end up on the same spot. */ - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) { /* The vehicle center is now more to the front depending on vehicle length, * so we need to move all vehicles forward to cover the difference to the @@ -892,9 +881,8 @@ const SaveLoad *GetVehicleDescription(VehicleType vt) /** Will be called when the vehicles need to be saved. */ static void Save_VEHS() { - Vehicle *v; /* Write the vehicles */ - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { SlSetArrayIndex(v->index); SlObject(v, GetVehicleDescription(v->type)); } @@ -951,8 +939,7 @@ void Load_VEHS() static void Ptrs_VEHS() { - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { SlObject(v, GetVehicleDescription(v->type)); } } diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index ddb11082e..c0570f81d 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -136,8 +136,7 @@ void MoveWaypointsToBaseStations() for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o); } - Vehicle *v; - FOR_ALL_VEHICLES(v) { + for (Vehicle *v : Vehicle::Iterate()) { if (v->type != VEH_TRAIN) continue; UpdateWaypointOrder(&v->current_order); |