Update to 1.10.0-beta2

This commit is contained in:
dP
2020-01-06 18:49:34 +03:00
parent 599ccf0c2b
commit c7c3966eec
1366 changed files with 2926 additions and 5639 deletions

View File

@@ -1,5 +1,3 @@
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
@@ -171,9 +169,7 @@ static void ConvertTownOwner()
/* since savegame version 4.1, exclusive transport rights are stored at towns */
static void UpdateExclusiveRights()
{
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
t->exclusivity = INVALID_COMPANY;
}
@@ -245,8 +241,7 @@ static void InitializeWindowsAndCaches()
UpdateAllVirtCoords();
ResetViewportAfterLoadGame();
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
/* For each company, verify (while loading a scenario) that the inauguration date is the current year and set it
* accordingly if it is not the case. No need to set it on companies that are not been used already,
* thus the MIN_YEAR (which is really nothing more than Zero, initialized value) test */
@@ -256,35 +251,30 @@ static void InitializeWindowsAndCaches()
}
/* Count number of objects per type */
Object *o;
FOR_ALL_OBJECTS(o) {
for (Object *o : Object::Iterate()) {
Object::IncTypeCount(o->type);
}
/* 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;
}
}
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;
}
}
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
for (std::list<PersistentStorage *>::iterator it = t->psa_list.begin(); it != t->psa_list.end(); ++it) {
(*it)->feature = GSF_FAKE_TOWNS;
(*it)->tile = t->xy;
}
}
RoadVehicle *rv;
FOR_ALL_ROADVEHICLES(rv) {
for (RoadVehicle *rv : RoadVehicle::Iterate()) {
if (rv->IsFrontEngine()) {
rv->CargoChanged();
}
@@ -441,8 +431,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;
@@ -590,14 +580,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);
@@ -646,23 +635,20 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_84)) {
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->name = CopyFromOldName(c->name_1);
if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
c->president_name = CopyFromOldName(c->president_name_1);
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;
}
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
t->name = CopyFromOldName(t->townnametype);
if (t->name != nullptr) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
}
@@ -673,15 +659,13 @@ 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;
}
/* the same applies to Company::location_of_HQ */
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
if (c->location_of_HQ == 0 || (IsSavegameVersionBefore(SLV_4) && c->location_of_HQ == 0xFFFF)) {
c->location_of_HQ = INVALID_TILE;
}
@@ -789,8 +773,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;
}
@@ -802,8 +785,7 @@ bool AfterLoadGame()
/* Make sure there is an AI attached to an AI company */
{
Company *c;
FOR_ALL_COMPANIES(c) {
for (const Company *c : Company::Iterate()) {
if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
}
}
@@ -833,8 +815,7 @@ bool AfterLoadGame()
}
/* Fix the cache for cargo payments. */
CargoPayment *cp;
FOR_ALL_CARGO_PAYMENTS(cp) {
for (CargoPayment *cp : CargoPayment::Iterate()) {
cp->front->cargo_payment = cp;
cp->current_station = cp->front->last_station_visited;
}
@@ -995,15 +976,13 @@ bool AfterLoadGame()
/* From version 9.0, we update the max passengers of a town (was sometimes negative
* before that. */
if (IsSavegameVersionBefore(SLV_9)) {
Town *t;
FOR_ALL_TOWNS(t) UpdateTownMaxPass(t);
for (Town *t : Town::Iterate()) UpdateTownMaxPass(t);
}
/* From version 16.0, we included autorenew on engines, which are now saved, but
* of course, we do need to initialize them for older savegames. */
if (IsSavegameVersionBefore(SLV_16)) {
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->engine_renew_list = nullptr;
c->settings.engine_renew = false;
c->settings.engine_renew_months = 6;
@@ -1016,7 +995,7 @@ bool AfterLoadGame()
* becomes company 0, unless we are in the scenario editor where all the
* companies are 'invalid'.
*/
c = Company::GetIfValid(COMPANY_FIRST);
Company *c = Company::GetIfValid(COMPANY_FIRST);
if (!_network_dedicated && c != nullptr) {
c->settings = _settings_client.company;
}
@@ -1189,8 +1168,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)) {
@@ -1244,7 +1221,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);
@@ -1303,8 +1280,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;
@@ -1341,7 +1317,7 @@ bool AfterLoadGame()
}
}
FOR_ALL_TRAINS(v) {
for (Train *v : Train::Iterate()) {
if (v->IsFrontEngine() || v->IsFreeWagon()) v->ConsistChanged(CCF_TRACK);
}
@@ -1351,8 +1327,7 @@ bool AfterLoadGame()
* replaced, shall keep their old length. In all prior versions, just default
* to false */
if (IsSavegameVersionBefore(SLV_16, 1)) {
Company *c;
FOR_ALL_COMPANIES(c) c->settings.renew_keep_length = false;
for (Company *c : Company::Iterate()) c->settings.renew_keep_length = false;
}
if (IsSavegameVersionBefore(SLV_123)) {
@@ -1399,15 +1374,13 @@ bool AfterLoadGame()
}
if (IsSavegameVersionBefore(SLV_25)) {
RoadVehicle *rv;
FOR_ALL_ROADVEHICLES(rv) {
for (RoadVehicle *rv : RoadVehicle::Iterate()) {
rv->vehstatus &= ~0x40;
}
}
if (IsSavegameVersionBefore(SLV_26)) {
Station *st;
FOR_ALL_STATIONS(st) {
for (Station *st : Station::Iterate()) {
st->last_vehicle_type = VEH_INVALID;
}
}
@@ -1415,12 +1388,10 @@ bool AfterLoadGame()
YapfNotifyTrackLayoutChange(INVALID_TILE, INVALID_TRACK);
if (IsSavegameVersionBefore(SLV_34)) {
Company *c;
FOR_ALL_COMPANIES(c) ResetCompanyLivery(c);
for (Company *c : Company::Iterate()) ResetCompanyLivery(c);
}
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->avail_railtypes = GetCompanyRailtypes(c->index);
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
}
@@ -1430,22 +1401,16 @@ 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;
_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_ALL_ENGINES(e) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
FOR_ALL_COMPANIES(c) c->inaugurated_year += ORIGINAL_BASE_YEAR;
FOR_ALL_INDUSTRIES(i) i->last_prod_year += 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 (Engine *e : Engine::Iterate()) e->intro_date += DAYS_TILL_ORIGINAL_BASE_YEAR;
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;
}
@@ -1455,8 +1420,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 */
@@ -1464,7 +1427,7 @@ bool AfterLoadGame()
}
}
FOR_ALL_INDUSTRIES(i) {
for (Industry *i : Industry::Iterate()) {
uint j;
if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
@@ -1475,14 +1438,11 @@ bool AfterLoadGame()
/* Setting no refit flags to all orders in savegames from before refit in orders were added */
if (IsSavegameVersionBefore(SLV_36)) {
Order *order;
Vehicle *v;
FOR_ALL_ORDERS(order) {
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);
}
}
@@ -1561,13 +1521,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);
}
}
@@ -1575,16 +1534,14 @@ 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);
}
}
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;
@@ -1594,7 +1551,7 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(SLV_49)) FOR_ALL_COMPANIES(c) c->face = ConvertFromOldCompanyManagerFace(c->face);
if (IsSavegameVersionBefore(SLV_49)) for (Company *c : Company::Iterate()) c->face = ConvertFromOldCompanyManagerFace(c->face);
if (IsSavegameVersionBefore(SLV_52)) {
for (TileIndex t = 0; t < map_size; t++) {
@@ -1608,9 +1565,7 @@ bool AfterLoadGame()
* fast was added in version 54. From version 56 this is now saved in the
* town as cities can be built specifically in the scenario editor. */
if (IsSavegameVersionBefore(SLV_56)) {
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
if (_settings_game.economy.larger_towns != 0 && (t->index % _settings_game.economy.larger_towns) == 0) {
t->larger_town = true;
}
@@ -1618,9 +1573,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
@@ -1634,8 +1588,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;
@@ -1672,8 +1625,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);
}
@@ -1682,8 +1634,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.
@@ -1714,8 +1665,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);
@@ -1724,9 +1674,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];
@@ -1753,11 +1702,9 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_93)) {
/* Rework of orders. */
Order *order;
FOR_ALL_ORDERS(order) order->ConvertFromOldSavegame();
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;
@@ -1765,21 +1712,20 @@ bool AfterLoadGame()
v->current_order.ConvertFromOldSavegame();
if (v->type == VEH_ROAD && v->IsPrimaryVehicle() && v->FirstShared() == v) {
Order* order;
FOR_VEHICLE_ORDERS(v, order) order->SetNonStopType(ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
}
}
} else if (IsSavegameVersionBefore(SLV_94)) {
/* Unload and transfer are now mutual exclusive. */
Order *order;
FOR_ALL_ORDERS(order) {
for (Order *order : Order::Iterate()) {
if ((order->GetUnloadType() & (OUFB_UNLOAD | OUFB_TRANSFER)) == (OUFB_UNLOAD | OUFB_TRANSFER)) {
order->SetUnloadType(OUFB_TRANSFER);
order->SetLoadType(OLFB_NO_LOAD);
}
}
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);
@@ -1794,7 +1740,7 @@ bool AfterLoadGame()
* *really* old revisions of OTTD; else it is already set in InitializeCompanies())
* 2) shares that are owned by inactive companies or self
* (caused by cheating clients in earlier revisions) */
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
for (uint i = 0; i < 4; i++) {
CompanyID company = c->share_owners[i];
if (company == INVALID_COMPANY) continue;
@@ -1928,8 +1874,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;
@@ -1950,8 +1895,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;
@@ -2022,8 +1966,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();
}
}
@@ -2040,22 +1983,19 @@ bool AfterLoadGame()
UpdateNearestTownForRoadTiles(false);
/* signs with invalid owner left from older savegames */
Sign *si;
FOR_ALL_SIGNS(si) {
for (Sign *si : Sign::Iterate()) {
if (si->owner != OWNER_NONE && !Company::IsValidID(si->owner)) si->owner = OWNER_NONE;
}
/* 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;
}
}
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;
@@ -2063,18 +2003,15 @@ bool AfterLoadGame()
}
/* More companies ... */
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
if (c->bankrupt_asked == 0xFF) c->bankrupt_asked = 0xFFFF;
}
Engine *e;
FOR_ALL_ENGINES(e) {
for (Engine *e : Engine::Iterate()) {
if (e->company_avail == 0xFF) e->company_avail = 0xFFFF;
}
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
if (t->have_ratings == 0xFF) t->have_ratings = 0xFFFF;
for (uint i = 8; i != MAX_COMPANIES; i++) t->ratings[i] = RATING_INITIAL;
}
@@ -2163,8 +2100,7 @@ bool AfterLoadGame()
/* Initialize layout of all towns. Older versions were using different
* generator for random town layout, use it if needed. */
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
if (_settings_game.economy.town_layout != TL_RANDOM) {
t->layout = _settings_game.economy.town_layout;
continue;
@@ -2185,32 +2121,28 @@ 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;
}
}
/* Trains could now stop in a specific location. */
if (IsSavegameVersionBefore(SLV_117)) {
Order *o;
FOR_ALL_ORDERS(o) {
for (Order *o : Order::Iterate()) {
if (o->IsType(OT_GOTO_STATION)) o->SetStopLocation(OSL_PLATFORM_FAR_END);
}
}
if (IsSavegameVersionBefore(SLV_120)) {
extern VehicleDefaultSettings _old_vds;
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->settings.vehicle = _old_vds;
}
}
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()) {
@@ -2225,8 +2157,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
@@ -2264,8 +2195,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;
@@ -2280,8 +2210,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_125)) {
/* Convert old subsidies */
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
for (Subsidy *s : Subsidy::Iterate()) {
if (s->remaining < 12) {
/* Converting nonawarded subsidy */
s->remaining = 12 - s->remaining; // convert "age" to "remaining"
@@ -2357,8 +2286,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)) {
@@ -2375,8 +2303,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;
}
@@ -2406,13 +2333,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;
}
}
@@ -2455,8 +2380,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;
@@ -2473,15 +2397,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 (Depot *d : Depot::Iterate()) d->town_cn = UINT16_MAX;
FOR_ALL_DEPOTS(d) MakeDefaultName(d);
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
@@ -2490,8 +2412,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) {
@@ -2541,8 +2462,7 @@ bool AfterLoadGame()
/* Add (random) colour to all objects. */
if (IsSavegameVersionBefore(SLV_148)) {
Object *o;
FOR_ALL_OBJECTS(o) {
for (Object *o : Object::Iterate()) {
Owner owner = GetTileOwner(o->location.tile);
o->colour = (owner == OWNER_NONE) ? Random() & 0xF : Company::Get(owner)->livery->colour1;
}
@@ -2560,12 +2480,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);
}
}
@@ -2576,8 +2495,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;
@@ -2640,8 +2558,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);
@@ -2656,8 +2573,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);
@@ -2665,16 +2581,14 @@ bool AfterLoadGame()
}
/* Introduced terraform/clear limits. */
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->terraform_limit = _settings_game.construction.terraform_frame_burst << 16;
c->clear_limit = _settings_game.construction.clear_frame_burst << 16;
}
}
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);
@@ -2758,7 +2672,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 */
@@ -2778,8 +2692,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));
}
}
@@ -2796,8 +2709,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. */
@@ -2819,8 +2731,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);
@@ -2871,9 +2782,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_164)) FixupTrainLengths();
if (IsSavegameVersionBefore(SLV_165)) {
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
/* Set the default cargo requirement for town growth */
switch (_settings_game.game_creation.landscape) {
case LT_ARCTIC:
@@ -2907,8 +2816,7 @@ bool AfterLoadGame()
Town::Get(GetTownIndex(t))->cargo_accepted.Add(t);
}
Town *town;
FOR_ALL_TOWNS(town) {
for (Town *town : Town::Iterate()) {
UpdateTownCargoes(town);
}
}
@@ -2925,8 +2833,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_175)) {
/* Introduced tree planting limit. */
Company *c;
FOR_ALL_COMPANIES(c) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
for (Company *c : Company::Iterate()) c->tree_limit = _settings_game.construction.tree_frame_burst << 16;
}
if (IsSavegameVersionBefore(SLV_177)) {
@@ -2935,7 +2842,7 @@ bool AfterLoadGame()
if (_economy.inflation_payment > MAX_INFLATION) _economy.inflation_payment = MAX_INFLATION;
/* We have to convert the quarters of bankruptcy into months of bankruptcy */
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->months_of_bankruptcy = 3 * c->months_of_bankruptcy;
}
}
@@ -2947,9 +2854,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;
@@ -2993,10 +2899,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;
@@ -3059,8 +2964,7 @@ bool AfterLoadGame()
#ifndef DEBUG_DUMP_COMMANDS
/* Note: We cannot use CleanPool since that skips part of the destructor
* and then leaks un-reachable Orders in the order pool. */
OrderBackup *ob;
FOR_ALL_ORDER_BACKUPS(ob) {
for (OrderBackup *ob : OrderBackup::Iterate()) {
delete ob;
}
#endif
@@ -3068,8 +2972,7 @@ bool AfterLoadGame()
if (IsSavegameVersionBefore(SLV_198)) {
/* Convert towns growth_rate and grow_counter to ticks */
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
/* 0x8000 = TOWN_GROWTH_RATE_CUSTOM previously */
if (t->growth_rate & 0x8000) SetBit(t->flags, TOWN_CUSTOM_GROWTH);
if (t->growth_rate != TOWN_GROWTH_RATE_NONE) {
@@ -3082,8 +2985,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;
@@ -3112,8 +3014,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;
@@ -3156,8 +3057,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));
@@ -3166,8 +3066,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)) {
@@ -3192,8 +3091,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);
}
}
@@ -3203,8 +3101,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 */