Merge branch 'master' into jgrpp

# Conflicts:
#	config.lib
#	projects/openttd_vs140.vcxproj
#	projects/openttd_vs140.vcxproj.filters
#	projects/openttd_vs141.vcxproj
#	projects/openttd_vs141.vcxproj.filters
#	projects/openttd_vs142.vcxproj
#	projects/openttd_vs142.vcxproj.filters
#	src/aircraft_cmd.cpp
#	src/base_station_base.h
#	src/core/pool_type.hpp
#	src/disaster_vehicle.cpp
#	src/economy.cpp
#	src/engine.cpp
#	src/group.h
#	src/group_cmd.cpp
#	src/group_gui.cpp
#	src/lang/english.txt
#	src/lang/german.txt
#	src/linkgraph/linkgraph_gui.cpp
#	src/network/network_command.cpp
#	src/network/network_server.cpp
#	src/openttd.cpp
#	src/order_cmd.cpp
#	src/road_cmd.cpp
#	src/saveload/afterload.cpp
#	src/saveload/cargopacket_sl.cpp
#	src/saveload/linkgraph_sl.cpp
#	src/saveload/order_sl.cpp
#	src/saveload/station_sl.cpp
#	src/saveload/town_sl.cpp
#	src/saveload/vehicle_sl.cpp
#	src/screenshot.cpp
#	src/screenshot.h
#	src/settings_gui.cpp
#	src/settings_type.h
#	src/smallmap_gui.cpp
#	src/station.cpp
#	src/station_cmd.cpp
#	src/table/settings.ini
#	src/toolbar_gui.cpp
#	src/town_cmd.cpp
#	src/train.h
#	src/train_cmd.cpp
#	src/train_gui.cpp
#	src/vehicle.cpp
#	src/vehicle_base.h
#	src/vehiclelist.cpp
#	src/window_type.h
This commit is contained in:
Jonathan G Rennison
2020-01-06 18:45:51 +00:00
281 changed files with 2714 additions and 2467 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -26,9 +26,7 @@ static const SaveLoad _engine_renew_desc[] = {
static void Save_ERNW()
{
EngineRenew *er;
FOR_ALL_ENGINE_RENEWS(er) {
for (EngineRenew *er : EngineRenew::Iterate()) {
SlSetArrayIndex(er->index);
SlObject(er, _engine_renew_desc);
}
@@ -53,9 +51,7 @@ static void Load_ERNW()
static void Ptrs_ERNW()
{
EngineRenew *er;
FOR_ALL_ENGINE_RENEWS(er) {
for (EngineRenew *er : EngineRenew::Iterate()) {
SlObject(er, _engine_renew_desc);
}
}

View File

@@ -25,14 +25,13 @@ extern btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
/* 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;
@@ -46,8 +45,7 @@ extern btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
* 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];
@@ -63,8 +61,7 @@ extern btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
if (IsSavegameVersionBefore(SLV_120)) {
/* CargoPacket's source should be either INVALID_STATION or a valid station */
CargoPacket *cp;
FOR_ALL_CARGOPACKETS(cp) {
for (CargoPacket *cp : CargoPacket::Iterate()) {
if (!Station::IsValidID(cp->source)) cp->source = INVALID_STATION;
}
}
@@ -73,18 +70,15 @@ extern btree::btree_map<uint64, Money> _cargo_packet_deferred_payments;
/* 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();
Station *st;
FOR_ALL_STATIONS(st) {
for (Station *st : Station::Iterate()) {
for (CargoID c = 0; c < NUM_CARGO; c++) st->goods[c].cargo.InvalidateCache();
}
}
if (IsSavegameVersionBefore(SLV_181)) {
Vehicle *v;
FOR_ALL_VEHICLES(v) v->cargo.KeepAll();
for (Vehicle *v : Vehicle::Iterate()) v->cargo.KeepAll();
}
}
@@ -140,8 +134,7 @@ const SaveLoad *GetCargoPacketDesc()
static void Save_CAPA()
{
std::vector<SaveLoad> filtered_packet_desc = SlFilterObject(GetCargoPacketDesc());
CargoPacket *cp;
FOR_ALL_CARGOPACKETS(cp) {
for (CargoPacket *cp : CargoPacket::Iterate()) {
SlSetArrayIndex(cp->index);
SlObjectSaveFiltered(cp, filtered_packet_desc.data());
}

View File

@@ -95,17 +95,16 @@ CompanyManagerFace ConvertFromOldCompanyManagerFace(uint32 face)
void AfterLoadCompanyStats()
{
/* Reset infrastructure statistics to zero. */
Company *c;
FOR_ALL_COMPANIES(c) MemSetT(&c->infrastructure, 0);
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++;
}
}
Company *c;
for (TileIndex tile = 0; tile < MapSize(); tile++) {
switch (GetTileType(tile)) {
case MP_RAILWAY:
@@ -488,8 +487,7 @@ static void SaveLoad_PLYR(Company *c)
static void Save_PLYR()
{
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
SlSetArrayIndex(c->index);
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
}
@@ -545,8 +543,7 @@ static void Check_PLYR()
static void Ptrs_PLYR()
{
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
SlObject(c, _company_settings_desc);
}
}

View File

@@ -31,9 +31,7 @@ static const SaveLoad _depot_desc[] = {
static void Save_DEPT()
{
Depot *depot;
FOR_ALL_DEPOTS(depot) {
for (Depot *depot : Depot::Iterate()) {
SlSetArrayIndex(depot->index);
SlObject(depot, _depot_desc);
}
@@ -54,9 +52,7 @@ static void Load_DEPT()
static void Ptrs_DEPT()
{
Depot *depot;
FOR_ALL_DEPOTS(depot) {
for (Depot *depot : Depot::Iterate()) {
SlObject(depot, _depot_desc);
if (IsSavegameVersionBefore(SLV_141)) depot->town = Town::Get((size_t)depot->town);
}

View File

@@ -73,8 +73,7 @@ static const SaveLoad _cargopayment_desc[] = {
static void Save_CAPY()
{
CargoPayment *cp;
FOR_ALL_CARGO_PAYMENTS(cp) {
for (CargoPayment *cp : CargoPayment::Iterate()) {
SlSetArrayIndex(cp->index);
SlObject(cp, _cargopayment_desc);
}
@@ -92,8 +91,7 @@ static void Load_CAPY()
static void Ptrs_CAPY()
{
CargoPayment *cp;
FOR_ALL_CARGO_PAYMENTS(cp) {
for (CargoPayment *cp : CargoPayment::Iterate()) {
SlObject(cp, _cargopayment_desc);
}
}

View File

@@ -86,8 +86,7 @@ Engine *GetTempDataEngine(EngineID index)
static void Save_ENGN()
{
Engine *e;
FOR_ALL_ENGINES(e) {
for (Engine *e : Engine::Iterate()) {
SlSetArrayIndex(e->index);
SlObject(e, _engine_desc);
}
@@ -118,8 +117,7 @@ static void Load_ENGN()
*/
void CopyTempEngineData()
{
Engine *e;
FOR_ALL_ENGINES(e) {
for (Engine *e : Engine::Iterate()) {
if (e->index >= _temp_engine.size()) break;
const Engine *se = GetTempDataEngine(e->index);

View File

@@ -26,8 +26,7 @@ static const SaveLoad _goals_desc[] = {
static void Save_GOAL()
{
Goal *s;
FOR_ALL_GOALS(s) {
for (Goal *s : Goal::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _goals_desc);
}

View File

@@ -31,9 +31,7 @@ static const SaveLoad _group_desc[] = {
static void Save_GRPS()
{
Group *g;
FOR_ALL_GROUPS(g) {
for (Group *g : Group::Iterate()) {
SlSetArrayIndex(g->index);
SlObject(g, _group_desc);
}

View File

@@ -77,10 +77,8 @@ static const SaveLoad _industry_desc[] = {
static void Save_INDY()
{
Industry *ind;
/* Write the industries */
FOR_ALL_INDUSTRIES(ind) {
for (Industry *ind : Industry::Iterate()) {
SlSetArrayIndex(ind->index);
SlObject(ind, _industry_desc);
}
@@ -129,9 +127,7 @@ static void Load_TIDS()
static void Ptrs_INDY()
{
Industry *i;
FOR_ALL_INDUSTRIES(i) {
for (Industry *i : Industry::Iterate()) {
SlObject(i, _industry_desc);
}
}

View File

@@ -269,17 +269,15 @@ static void Load_LGRS()
void AfterLoadLinkGraphs()
{
if (IsSavegameVersionBefore(SLV_191)) {
LinkGraph *lg;
FOR_ALL_LINK_GRAPHS(lg) {
for (LinkGraph *lg : LinkGraph::Iterate()) {
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
}
}
LinkGraphJob *lgj;
FOR_ALL_LINK_GRAPH_JOBS(lgj) {
lg = &(const_cast<LinkGraph &>(lgj->Graph()));
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
LinkGraph *lg = &(const_cast<LinkGraph &>(lgj->Graph()));
for (NodeID node_id = 0; node_id < lg->Size(); ++node_id) {
const Station *st = Station::GetIfValid((*lg)[node_id].Station());
if (st != nullptr) (*lg)[node_id].UpdateLocation(st->xy);
@@ -296,8 +294,7 @@ void AfterLoadLinkGraphs()
static void Save_LGRP()
{
FilterDescs();
LinkGraph *lg;
FOR_ALL_LINK_GRAPHS(lg) {
for (LinkGraph *lg : LinkGraph::Iterate()) {
SlSetArrayIndex(lg->index);
SlAutolength((AutolengthProc*)DoSave_LGRP, lg);
}
@@ -309,8 +306,7 @@ static void Save_LGRP()
static void Save_LGRJ()
{
FilterDescs();
LinkGraphJob *lgj;
FOR_ALL_LINK_GRAPH_JOBS(lgj) {
for (LinkGraphJob *lgj : LinkGraphJob::Iterate()) {
SlSetArrayIndex(lgj->index);
SlAutolength((AutolengthProc*)DoSave_LGRJ, lgj);
}

View File

@@ -31,10 +31,8 @@ static const SaveLoad _object_desc[] = {
static void Save_OBJS()
{
Object *o;
/* Write the objects */
FOR_ALL_OBJECTS(o) {
for (Object *o : Object::Iterate()) {
SlSetArrayIndex(o->index);
SlObject(o, _object_desc);
}
@@ -51,8 +49,7 @@ static void Load_OBJS()
static void Ptrs_OBJS()
{
Object *o;
FOR_ALL_OBJECTS(o) {
for (Object *o : Object::Iterate()) {
SlObject(o, _object_desc);
if (IsSavegameVersionBefore(SLV_148) && !IsTileType(o->location.tile, MP_OBJECT)) {
/* Due to a small bug stale objects could remain. */

View File

@@ -109,8 +109,7 @@ static void FixTTDMapArray()
static void FixTTDDepots()
{
const Depot *d;
FOR_ALL_DEPOTS_FROM(d, 252) {
for (const Depot *d : Depot::Iterate(252)) {
if (!IsDepotTile(d->xy) || GetDepotIndex(d->xy) != d->index) {
/** Workaround for SVXConverter bug, depots 252-255 could be invalid */
delete d;
@@ -153,10 +152,8 @@ static uint32 RemapOldTownName(uint32 townnameparts, byte old_town_name_type)
static void FixOldTowns()
{
Town *town;
/* Convert town-names if needed */
FOR_ALL_TOWNS(town) {
for (Town *town : Town::Iterate()) {
if (IsInsideMM(town->townnametype, 0x20C1, 0x20C3)) {
town->townnametype = SPECSTR_TOWNNAME_ENGLISH + _settings_game.game_creation.town_name;
town->townnameparts = RemapOldTownName(town->townnameparts, _settings_game.game_creation.town_name);
@@ -173,9 +170,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 {
@@ -385,8 +380,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];
}
@@ -459,8 +453,7 @@ static bool FixTTOEngines()
static void FixTTOCompanies()
{
Company *c;
FOR_ALL_COMPANIES(c) {
for (Company *c : Company::Iterate()) {
c->cur_economy.company_value = CalculateCompanyValue(c); // company value history is zeroed
}
}

View File

@@ -132,9 +132,7 @@ const SaveLoad *GetOrderDescription()
static void Save_ORDR()
{
Order *order;
FOR_ALL_ORDERS(order) {
for (Order *order : Order::Iterate()) {
SlSetArrayIndex(order->index);
SlObject(order, GetOrderDescription());
}
@@ -175,8 +173,8 @@ static void Load_ORDR()
}
/* Update all the next pointer */
Order *o;
FOR_ALL_ORDERS(o) {
for (Order *o : Order::Iterate()) {
size_t order_index = o->index;
/* Delete invalid orders */
if (o->IsType(OT_NOTHING)) {
delete o;
@@ -193,12 +191,6 @@ static void Load_ORDR()
while ((index = SlIterateArray()) != -1) {
Order *order = new (index) Order();
SlObject(order, GetOrderDescription());
if (IsSavegameVersionBefore(SLV_190)) {
order->SetTravelTimetabled(order->GetTravelTime() > 0);
order->SetWaitTimetabled(order->GetWaitTime() > 0);
} else if (order->IsType(OT_CONDITIONAL) && SlXvIsFeatureMissing(XSLFI_TIMETABLE_EXTRA)) {
order->SetWaitTimetabled(order->GetWaitTime() > 0);
}
}
}
}
@@ -218,9 +210,7 @@ const SaveLoad *GetOrderExtraInfoDescription()
void Save_ORDX()
{
Order *order;
FOR_ALL_ORDERS(order) {
for (Order *order : Order::Iterate()) {
if (order->extra) {
SlSetArrayIndex(order->index);
SlObject(order->extra.get(), GetOrderExtraInfoDescription());
@@ -244,9 +234,7 @@ static void Ptrs_ORDR()
/* Orders from old savegames have pointers corrected in Load_ORDR */
if (IsSavegameVersionBefore(SLV_5, 2)) return;
Order *o;
FOR_ALL_ORDERS(o) {
for (Order *o : Order::Iterate()) {
SlObject(o, GetOrderDescription());
}
}
@@ -271,9 +259,7 @@ const SaveLoad *GetOrderListDescription()
static void Save_ORDL()
{
OrderList *list;
FOR_ALL_ORDER_LISTS(list) {
for (OrderList *list : OrderList::Iterate()) {
SlSetArrayIndex(list->index);
SlObject(list, GetOrderListDescription());
}
@@ -302,9 +288,7 @@ static void Load_ORDL()
void Ptrs_ORDL()
{
OrderList *list;
FOR_ALL_ORDER_LISTS(list) {
for (OrderList *list : OrderList::Iterate()) {
SlObject(list, GetOrderListDescription());
list->ReindexOrderList();
}
@@ -349,8 +333,7 @@ static void Save_BKOR()
* normal games this information isn't needed. */
if (!_networking || !_network_server) return;
OrderBackup *ob;
FOR_ALL_ORDER_BACKUPS(ob) {
for (OrderBackup *ob : OrderBackup::Iterate()) {
SlSetArrayIndex(ob->index);
SlObject(ob, GetOrderBackupDescription());
}
@@ -369,8 +352,7 @@ void Load_BKOR()
static void Ptrs_BKOR()
{
OrderBackup *ob;
FOR_ALL_ORDER_BACKUPS(ob) {
for (OrderBackup *ob : OrderBackup::Iterate()) {
SlObject(ob, GetOrderBackupDescription());
}
}

View File

@@ -38,8 +38,7 @@ static void RealSave_PLAN(Plan *p)
/** Save all plans. */
static void Save_PLAN()
{
Plan *p;
FOR_ALL_PLANS(p) {
for (Plan *p : Plan::Iterate()) {
SlSetArrayIndex(p->index);
SlAutolength((AutolengthProc*) RealSave_PLAN, p);
}
@@ -82,8 +81,7 @@ static void Load_PLANLINE()
SlArray(&pl->tiles[0], plsz, SLE_UINT32);
}
Plan *p;
FOR_ALL_PLANS(p) {
for (Plan *p : Plan::Iterate()) {
p->SetVisibility(false);
}
}

View File

@@ -3413,8 +3413,7 @@ void GenerateDefaultSaveName(char *buf, const char *last)
* 'Spectator' as "company" name. */
CompanyID cid = _local_company;
if (!Company::IsValidID(cid)) {
const Company *c;
FOR_ALL_COMPANIES(c) {
for (const Company *c : Company::Iterate()) {
cid = c->index;
break;
}

View File

@@ -305,6 +305,7 @@ enum SaveLoadVersion : uint16 {
SLV_SCRIPT_MEMLIMIT, ///< 215 PR#7516 Limit on AI/GS memory consumption.
SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station.
SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age.
SLV_ENDING_YEAR, ///< 218 PR#7747 Configurable ending year.
SL_MAX_VERSION, ///< Highest possible saveload version

View File

@@ -32,9 +32,7 @@ static const SaveLoad _sign_desc[] = {
/** Save all signs */
static void Save_SIGN()
{
Sign *si;
FOR_ALL_SIGNS(si) {
for (Sign *si : Sign::Iterate()) {
SlSetArrayIndex(si->index);
SlObject(si, _sign_desc);
}

View File

@@ -43,16 +43,14 @@ static void UpdateWaypointOrder(Order *o)
void MoveBuoysToWaypoints()
{
/* Buoy orders become waypoint orders */
OrderList *ol;
FOR_ALL_ORDER_LISTS(ol) {
for (OrderList *ol : OrderList::Iterate()) {
VehicleType vt = ol->GetFirstSharedVehicle()->type;
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
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;
@@ -60,8 +58,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;
@@ -112,8 +109,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;
@@ -136,12 +132,11 @@ void AfterLoadStations()
void AfterLoadRoadStops()
{
/* First construct the drive through entries */
RoadStop *rs;
FOR_ALL_ROADSTOPS(rs) {
for (RoadStop *rs : RoadStop::Iterate()) {
if (IsDriveThroughStopTile(rs->xy)) rs->MakeDriveThrough();
}
/* And then rebuild the data in those entries */
FOR_ALL_ROADSTOPS(rs) {
for (RoadStop *rs : RoadStop::Iterate()) {
if (!HasBit(rs->status, RoadStop::RSSFB_BASE_ENTRY)) continue;
rs->GetEntry(DIAGDIR_NE)->Rebuild(rs);
@@ -387,8 +382,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];
@@ -564,9 +558,8 @@ static void Save_STNN()
{
SetupDescs_STNN();
BaseStation *st;
/* Write the stations */
FOR_ALL_BASE_STATIONS(st) {
for (BaseStation *st : BaseStation::Iterate()) {
SlSetArrayIndex(st->index);
SlAutolength((AutolengthProc*)RealSave_STNN, st);
}
@@ -687,8 +680,7 @@ static void Ptrs_STNN()
}
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) && SlXvIsFeatureMissing(XSLFI_CHILLPP)) {
@@ -705,8 +697,7 @@ static void Ptrs_STNN()
SlObjectPtrOrNullFiltered(st, _filtered_station_desc.data());
}
Waypoint *wp;
FOR_ALL_WAYPOINTS(wp) {
for (Waypoint *wp : Waypoint::Iterate()) {
SlObjectPtrOrNullFiltered(wp, _filtered_waypoint_desc.data());
}
}
@@ -714,8 +705,7 @@ static void Ptrs_STNN()
static void Save_ROADSTOP()
{
SetupDescs_ROADSTOP();
RoadStop *rs;
FOR_ALL_ROADSTOPS(rs) {
for (RoadStop *rs : RoadStop::Iterate()) {
SlSetArrayIndex(rs->index);
SlObjectSaveFiltered(rs, _filtered_roadstop_desc.data());
}
@@ -735,8 +725,7 @@ static void Load_ROADSTOP()
static void Ptrs_ROADSTOP()
{
SetupDescs_ROADSTOP();
RoadStop *rs;
FOR_ALL_ROADSTOPS(rs) {
for (RoadStop *rs : RoadStop::Iterate()) {
SlObjectPtrOrNullFiltered(rs, _filtered_roadstop_desc.data());
}
}

View File

@@ -36,10 +36,8 @@ static void Load_PSAC()
/** Save persistent storage data. */
static void Save_PSAC()
{
PersistentStorage *ps;
/* Write the industries */
FOR_ALL_STORAGES(ps) {
for (PersistentStorage *ps : PersistentStorage::Iterate()) {
ps->ClearChanges();
SlSetArrayIndex(ps->index);
SlObject(ps, _storage_desc);

View File

@@ -39,8 +39,7 @@ static const SaveLoad _story_page_elements_desc[] = {
static void Save_STORY_PAGE_ELEMENT()
{
StoryPageElement *s;
FOR_ALL_STORY_PAGE_ELEMENTS(s) {
for (StoryPageElement *s : StoryPageElement::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _story_page_elements_desc);
}
@@ -75,8 +74,7 @@ static const SaveLoad _story_pages_desc[] = {
static void Save_STORY_PAGE()
{
StoryPage *s;
FOR_ALL_STORY_PAGES(s) {
for (StoryPage *s : StoryPage::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _story_pages_desc);
}

View File

@@ -29,8 +29,7 @@ static const SaveLoad _subsidies_desc[] = {
static void Save_SUBS()
{
Subsidy *s;
FOR_ALL_SUBSIDIES(s) {
for (Subsidy *s : Subsidy::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _subsidies_desc);
}

View File

@@ -12,9 +12,7 @@ static const SaveLoad _template_replacement_desc[] = {
static void Save_TMPL_RPLS()
{
TemplateReplacement *tr;
FOR_ALL_TEMPLATE_REPLACEMENTS(tr) {
for (TemplateReplacement *tr : TemplateReplacement::Iterate()) {
SlSetArrayIndex(tr->index);
SlObject(tr, _template_replacement_desc);
}

View File

@@ -58,9 +58,7 @@ const SaveLoad* GTD() {
static void Save_TMPLS()
{
TemplateVehicle *tv;
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
SlSetArrayIndex(tv->index);
SlObject(tv, GTD());
}
@@ -78,22 +76,19 @@ static void Load_TMPLS()
static void Ptrs_TMPLS()
{
TemplateVehicle *tv;
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
SlObject(tv, GTD());
}
}
void AfterLoadTemplateVehicles()
{
TemplateVehicle *tv;
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
/* Reinstate the previous pointer */
if (tv->next != nullptr) tv->next->previous = tv;
tv->first = nullptr;
}
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
/* Fill the first pointers */
if (tv->previous == nullptr) {
for (TemplateVehicle *u = tv; u != nullptr; u = u->Next()) {
@@ -105,13 +100,11 @@ void AfterLoadTemplateVehicles()
void AfterLoadTemplateVehiclesUpdateImage()
{
TemplateVehicle *tv;
SavedRandomSeeds saved_seeds;
SaveRandomSeeds(&saved_seeds);
if (!SlXvIsFeaturePresent(XSLFI_TEMPLATE_REPLACEMENT, 3)) {
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
if (tv->Prev() == nullptr && !Company::IsValidID(tv->owner)) {
// clean up leftover template vehicles which no longer have a valid owner
delete tv;
@@ -119,7 +112,7 @@ void AfterLoadTemplateVehiclesUpdateImage()
}
}
FOR_ALL_TEMPLATES(tv) {
for (TemplateVehicle *tv : TemplateVehicle::Iterate()) {
if (tv->Prev() == nullptr) {
Backup<CompanyID> cur_company(_current_company, tv->owner, FILE_LINE);
StringID err;

View File

@@ -24,12 +24,11 @@
*/
void RebuildTownCaches(bool cargo_update_required)
{
Town *town;
InitializeBuildingCounts();
RebuildTownKdtree();
/* Reset town population and num_houses */
FOR_ALL_TOWNS(town) {
for (Town *town : Town::Iterate()) {
town->cache.population = 0;
town->cache.num_houses = 0;
}
@@ -38,7 +37,7 @@ void RebuildTownCaches(bool cargo_update_required)
if (!IsTileType(t, MP_HOUSE)) continue;
HouseID house_id = GetHouseType(t);
town = Town::GetByTile(t);
Town *town = Town::GetByTile(t);
IncreaseBuildingCount(town, house_id);
if (IsHouseCompleted(t)) town->cache.population += HouseSpec::Get(house_id)->population;
@@ -47,7 +46,7 @@ void RebuildTownCaches(bool cargo_update_required)
}
/* Update the population and num_house dependent values */
FOR_ALL_TOWNS(town) {
for (Town *town : Town::Iterate()) {
UpdateTownRadius(town);
if (cargo_update_required) {
UpdateTownCargoes(town);
@@ -307,8 +306,7 @@ static void RealSave_Town(Town *t)
static void Save_TOWN()
{
SetupDescs_TOWN();
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
SlSetArrayIndex(t->index);
SlAutolength((AutolengthProc*)RealSave_Town, t);
}
@@ -369,8 +367,7 @@ static void Ptrs_TOWN()
if (IsSavegameVersionBefore(SLV_161)) return;
SetupDescs_TOWN();
Town *t;
FOR_ALL_TOWNS(t) {
for (Town *t : Town::Iterate()) {
SlObjectPtrOrNullFiltered(t, _filtered_town_desc.data());
}
}

View File

@@ -107,9 +107,7 @@ static void RealSave_TRRP(TraceRestrictProgram *prog)
*/
static void Save_TRRP()
{
TraceRestrictProgram *prog;
FOR_ALL_TRACE_RESTRICT_PROGRAMS(prog) {
for (TraceRestrictProgram *prog : TraceRestrictProgram::Iterate()) {
SlSetArrayIndex(prog->index);
SlAutolength((AutolengthProc*) RealSave_TRRP, prog);
}
@@ -166,9 +164,7 @@ static void RealSave_TRRS(TraceRestrictSlot *slot)
*/
static void Save_TRRS()
{
TraceRestrictSlot *slot;
FOR_ALL_TRACE_RESTRICT_SLOTS(slot) {
for (TraceRestrictSlot *slot : TraceRestrictSlot::Iterate()) {
SlSetArrayIndex(slot->index);
SlAutolength((AutolengthProc*) RealSave_TRRS, slot);
}

View File

@@ -25,9 +25,7 @@ static const SaveLoad _tunnel_desc[] = {
static void Save_TUNN()
{
Tunnel *tunnel;
FOR_ALL_TUNNELS(tunnel) {
for (Tunnel *tunnel : Tunnel::Iterate()) {
SlSetArrayIndex(tunnel->index);
SlObject(tunnel, _tunnel_desc);
}

View File

@@ -33,13 +33,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 <..>..<..>..<..>..
@@ -113,10 +111,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);
@@ -167,13 +164,11 @@ 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
}
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()) {
@@ -218,14 +213,12 @@ static void CheckValidVehicles()
size_t total_engines = Engine::GetPoolSize();
EngineID first_engine[4] = { INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE, INVALID_ENGINE };
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_TRAIN) { first_engine[VEH_TRAIN] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) { first_engine[VEH_ROAD] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_SHIP) { first_engine[VEH_SHIP] = e->index; break; }
FOR_ALL_ENGINES_OF_TYPE(e, VEH_AIRCRAFT) { first_engine[VEH_AIRCRAFT] = e->index; break; }
for (const Engine *e : Engine::IterateType(VEH_TRAIN)) { first_engine[VEH_TRAIN] = e->index; break; }
for (const Engine *e : Engine::IterateType(VEH_ROAD)) { first_engine[VEH_ROAD] = e->index; break; }
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:
@@ -248,9 +241,10 @@ extern byte _age_cargo_skip_counter; // From misc_sl.cpp
/** Called after load to update coordinates */
void AfterLoadVehicles(bool part_of_load)
{
Vehicle *v = nullptr;
SCOPE_INFO_FMT([&v], "AfterLoadVehicles: %s", scope_dumper().VehicleInfo(v));
FOR_ALL_VEHICLES(v) {
const Vehicle *si_v = nullptr;
SCOPE_INFO_FMT([&si_v], "AfterLoadVehicles: %s", scope_dumper().VehicleInfo(si_v));
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
/* Reinstate the previous pointer */
if (v->Next() != nullptr) {
v->Next()->previous = v;
@@ -276,7 +270,8 @@ void AfterLoadVehicles(bool part_of_load)
*/
std::map<Order*, OrderList*> mapping;
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
if (v->orders.old != nullptr) {
if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
if (mapping[v->orders.old] == nullptr) {
@@ -303,7 +298,8 @@ void AfterLoadVehicles(bool part_of_load)
}
}
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
/* Fill the first pointers */
if (v->Previous() == nullptr) {
for (Vehicle *u = v; u != nullptr; u = u->Next()) {
@@ -315,7 +311,8 @@ 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()) {
si_v = v;
if (v->First() != v || v->orders.list != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
/* As above, allocating OrderList here is safe. */
@@ -329,9 +326,8 @@ 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) {
v = rv;
for (RoadVehicle *rv : RoadVehicle::Iterate()) {
si_v = rv;
if (rv->subtype == 0) {
/* The road vehicle is at the front. */
rv->SetFrontEngine();
@@ -347,7 +343,8 @@ 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()) {
si_v = v;
if (!v->IsPrimaryVehicle() && v->type != VEH_DISASTER) {
v->current_order.Free();
v->unitnumber = 0;
@@ -357,14 +354,16 @@ 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()) {
si_v = v;
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()) {
si_v = v;
if (!v->IsPrimaryVehicle()) continue;
const Company *c = Company::Get(v->owner);
@@ -377,13 +376,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
@@ -395,19 +392,20 @@ void AfterLoadVehicles(bool part_of_load)
}
if (SlXvIsFeaturePresent(XSLFI_TEMPLATE_REPLACEMENT) && (_network_server || !_networking)) {
Train *t;
FOR_ALL_TRAINS(t) {
for (Train *t : Train::Iterate()) {
si_v = t;
if (t->IsVirtual() && t->First() == t) {
delete t;
}
}
}
}
v = nullptr;
si_v = nullptr;
CheckValidVehicles();
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
assert(v->first != nullptr);
v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
@@ -452,7 +450,8 @@ 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()) {
si_v = v;
if (v->type == VEH_TRAIN) {
Train *t = Train::From(v);
if (!t->IsFrontEngine()) {
@@ -470,7 +469,8 @@ void AfterLoadVehicles(bool part_of_load)
}
}
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
si_v = v;
switch (v->type) {
case VEH_ROAD:
case VEH_TRAIN:
@@ -519,8 +519,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
@@ -991,9 +990,8 @@ static void SetupDescs_VEHS()
static void Save_VEHS()
{
SetupDescs_VEHS();
Vehicle *v;
/* Write the vehicles */
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
SlSetArrayIndex(v->index);
SlObjectSaveFiltered(v, GetVehicleDescriptionFiltered(v->type));
}
@@ -1062,8 +1060,7 @@ static void Ptrs_VEHS()
{
SetupDescs_VEHS();
Vehicle *v;
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
if (SlXvIsFeaturePresent(XSLFI_CHILLPP)) _cpp_packets = std::move(_veh_cpp_packets[v->index]);
SlObjectPtrOrNullFiltered(v, GetVehicleDescriptionFiltered(v->type));
if (SlXvIsFeaturePresent(XSLFI_CHILLPP)) _veh_cpp_packets[v->index] = std::move(_cpp_packets);
@@ -1075,8 +1072,7 @@ const SaveLoad *GetOrderExtraInfoDescription();
void Save_VEOX()
{
/* save extended order info for vehicle current order */
Vehicle *v;
FOR_ALL_VEHICLES(v) {
for (Vehicle *v : Vehicle::Iterate()) {
if (v->current_order.extra) {
SlSetArrayIndex(v->index);
SlObject(v->current_order.extra.get(), GetOrderExtraInfoDescription());
@@ -1111,8 +1107,7 @@ const SaveLoad *GetVehicleSpeedRestrictionDescription()
void Save_VESR()
{
Train *t;
FOR_ALL_TRAINS(t) {
for (Train *t : Train::Iterate()) {
if (HasBit(t->flags, VRF_PENDING_SPEED_RESTRICTION)) {
auto range = pending_speed_restriction_change_map.equal_range(t->index);
for (auto it = range.first; it != range.second; ++it) {

View File

@@ -9,6 +9,7 @@
#include "../stdafx.h"
#include "../waypoint_base.h"
#include "../debug.h"
#include "../newgrf_station.h"
#include "../vehicle_base.h"
#include "../town.h"
@@ -98,47 +99,57 @@ void MoveWaypointsToBaseStations()
/* All saveload conversions have been done. Create the new waypoints! */
for (OldWaypoint &wp : _old_waypoints) {
Waypoint *new_wp = new Waypoint(wp.xy);
TileIndex t = wp.xy;
/* Sometimes waypoint (sign) locations became disconnected from their actual location in
* the map array. If this is the case, try to locate the actual location in the map array */
if (!IsTileType(t, MP_RAILWAY) || GetRailTileType(t) != 2 /* RAIL_TILE_WAYPOINT */ || _m[t].m2 != wp.index) {
DEBUG(sl, 0, "Found waypoint tile %u with invalid position", t);
for (t = 0; t < MapSize(); t++) {
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp.index) {
DEBUG(sl, 0, "Found actual waypoint position at %u", t);
break;
}
}
}
if (t == MapSize()) {
SlErrorCorrupt("Waypoint with invalid tile");
}
Waypoint *new_wp = new Waypoint(t);
new_wp->town = wp.town;
new_wp->town_cn = wp.town_cn;
new_wp->name = wp.name;
new_wp->delete_ctr = 0; // Just reset delete counter for once.
new_wp->build_date = wp.build_date;
new_wp->owner = wp.owner;
new_wp->string_id = STR_SV_STNAME_WAYPOINT;
new_wp->string_id = STR_SV_STNAME_WAYPOINT;
/* The tile might've been reserved! */
bool reserved = !IsSavegameVersionBefore(SLV_100) && HasBit(_m[t].m5, 4);
TileIndex t = wp.xy;
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp.index) {
/* The tile might've been reserved! */
bool reserved = !IsSavegameVersionBefore(SLV_100) && HasBit(_m[t].m5, 4);
/* The tile really has our waypoint, so reassign the map array */
MakeRailWaypoint(t, GetTileOwner(t), new_wp->index, (Axis)GB(_m[t].m5, 0, 1), 0, GetRailType(t));
new_wp->facilities |= FACIL_TRAIN;
new_wp->owner = GetTileOwner(t);
/* The tile really has our waypoint, so reassign the map array */
MakeRailWaypoint(t, GetTileOwner(t), new_wp->index, (Axis)GB(_m[t].m5, 0, 1), 0, GetRailType(t));
new_wp->facilities |= FACIL_TRAIN;
new_wp->owner = GetTileOwner(t);
SetRailStationReservation(t, reserved);
SetRailStationReservation(t, reserved);
if (wp.spec != nullptr) {
SetCustomStationSpecIndex(t, AllocateSpecToStation(wp.spec, new_wp, true));
}
new_wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
if (wp.spec != nullptr) {
SetCustomStationSpecIndex(t, AllocateSpecToStation(wp.spec, new_wp, true));
}
new_wp->rect.BeforeAddTile(t, StationRect::ADD_FORCE);
wp.new_index = new_wp->index;
}
/* Update the orders of vehicles */
OrderList *ol;
FOR_ALL_ORDER_LISTS(ol) {
for (OrderList *ol : OrderList::Iterate()) {
if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue;
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);