Update to 1.10.0-beta1
This commit is contained in:
+188
-83
@@ -19,6 +19,7 @@
|
||||
#include "../network/network_func.h"
|
||||
#include "../gfxinit.h"
|
||||
#include "../viewport_func.h"
|
||||
#include "../viewport_kdtree.h"
|
||||
#include "../industry.h"
|
||||
#include "../clear_map.h"
|
||||
#include "../vehicle_func.h"
|
||||
@@ -56,6 +57,7 @@
|
||||
#include "../error.h"
|
||||
#include "../disaster_vehicle.h"
|
||||
#include "../ship.h"
|
||||
#include "../water.h"
|
||||
|
||||
|
||||
#include "saveload_internal.h"
|
||||
@@ -221,6 +223,7 @@ void UpdateAllVirtCoords()
|
||||
UpdateAllStationVirtCoords();
|
||||
UpdateAllSignVirtCoords();
|
||||
UpdateAllTownVirtCoords();
|
||||
RebuildViewportKdtree();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +231,7 @@ void UpdateAllVirtCoords()
|
||||
* This is not done directly in AfterLoadGame because these
|
||||
* functions require that all saveload conversions have been
|
||||
* done. As people tend to add savegame conversion stuff after
|
||||
* the intialization of the windows and caches quite some bugs
|
||||
* the initialization of the windows and caches quite some bugs
|
||||
* had been made.
|
||||
* Moving this out of there is both cleaner and less bug-prone.
|
||||
*/
|
||||
@@ -261,14 +264,14 @@ static void InitializeWindowsAndCaches()
|
||||
/* Identify owners of persistent storage arrays */
|
||||
Industry *i;
|
||||
FOR_ALL_INDUSTRIES(i) {
|
||||
if (i->psa != NULL) {
|
||||
if (i->psa != nullptr) {
|
||||
i->psa->feature = GSF_INDUSTRIES;
|
||||
i->psa->tile = i->location.tile;
|
||||
}
|
||||
}
|
||||
Station *s;
|
||||
FOR_ALL_STATIONS(s) {
|
||||
if (s->airport.psa != NULL) {
|
||||
if (s->airport.psa != nullptr) {
|
||||
s->airport.psa->feature = GSF_AIRPORTS;
|
||||
s->airport.psa->tile = s->airport.tile;
|
||||
}
|
||||
@@ -280,12 +283,17 @@ static void InitializeWindowsAndCaches()
|
||||
(*it)->tile = t->xy;
|
||||
}
|
||||
}
|
||||
RoadVehicle *rv;
|
||||
FOR_ALL_ROADVEHICLES(rv) {
|
||||
if (rv->IsFrontEngine()) {
|
||||
rv->CargoChanged();
|
||||
}
|
||||
}
|
||||
|
||||
RecomputePrices();
|
||||
|
||||
GroupStatistics::UpdateAfterLoad();
|
||||
|
||||
Station::RecomputeIndustriesNearForAll();
|
||||
RebuildSubsidisedSourceAndDestinationCache();
|
||||
|
||||
/* Towns have a noise controlled number of airports system
|
||||
@@ -302,9 +310,9 @@ static void InitializeWindowsAndCaches()
|
||||
}
|
||||
|
||||
typedef void (CDECL *SignalHandlerPointer)(int);
|
||||
static SignalHandlerPointer _prev_segfault = NULL;
|
||||
static SignalHandlerPointer _prev_abort = NULL;
|
||||
static SignalHandlerPointer _prev_fpe = NULL;
|
||||
static SignalHandlerPointer _prev_segfault = nullptr;
|
||||
static SignalHandlerPointer _prev_abort = nullptr;
|
||||
static SignalHandlerPointer _prev_fpe = nullptr;
|
||||
|
||||
static void CDECL HandleSavegameLoadCrash(int signum);
|
||||
|
||||
@@ -374,7 +382,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||
char *p = buffer;
|
||||
p += seprintf(p, lastof(buffer), "Loading your savegame caused OpenTTD to crash.\n");
|
||||
|
||||
for (const GRFConfig *c = _grfconfig; !_saveload_crash_with_missing_newgrfs && c != NULL; c = c->next) {
|
||||
for (const GRFConfig *c = _grfconfig; !_saveload_crash_with_missing_newgrfs && c != nullptr; c = c->next) {
|
||||
_saveload_crash_with_missing_newgrfs = HasBit(c->flags, GCF_COMPATIBLE) || c->status == GCS_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -392,7 +400,7 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||
"Please load the savegame with the appropriate NewGRFs installed.\n"
|
||||
"The missing/compatible NewGRFs are:\n");
|
||||
|
||||
for (const GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
||||
for (const GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
|
||||
if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
||||
const GRFIdentifier *replaced = GetOverriddenIdentifier(c);
|
||||
char buf[40];
|
||||
@@ -413,14 +421,14 @@ static void CDECL HandleSavegameLoadCrash(int signum)
|
||||
|
||||
ShowInfo(buffer);
|
||||
|
||||
SignalHandlerPointer call = NULL;
|
||||
SignalHandlerPointer call = nullptr;
|
||||
switch (signum) {
|
||||
case SIGSEGV: call = _prev_segfault; break;
|
||||
case SIGABRT: call = _prev_abort; break;
|
||||
case SIGFPE: call = _prev_fpe; break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
if (call != NULL) call(signum);
|
||||
if (call != nullptr) call(signum);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -433,7 +441,7 @@ 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 = NULL, *w;
|
||||
Train *v = nullptr, *w;
|
||||
FOR_ALL_TRAINS(w) {
|
||||
if (w->tile == t) {
|
||||
v = w;
|
||||
@@ -441,7 +449,7 @@ static void FixOwnerOfRailTrack(TileIndex t)
|
||||
}
|
||||
}
|
||||
|
||||
if (v != NULL) {
|
||||
if (v != nullptr) {
|
||||
/* when there is a train on crossing (it could happen in TTD), set owner of crossing to train owner */
|
||||
SetTileOwner(t, v->owner);
|
||||
return;
|
||||
@@ -460,8 +468,19 @@ static void FixOwnerOfRailTrack(TileIndex t)
|
||||
|
||||
if (IsLevelCrossingTile(t)) {
|
||||
/* else change the crossing to normal road (road vehicles won't care) */
|
||||
MakeRoadNormal(t, GetCrossingRoadBits(t), GetRoadTypes(t), GetTownIndex(t),
|
||||
GetRoadOwner(t, ROADTYPE_ROAD), GetRoadOwner(t, ROADTYPE_TRAM));
|
||||
Owner road = GetRoadOwner(t, RTT_ROAD);
|
||||
Owner tram = GetRoadOwner(t, RTT_TRAM);
|
||||
RoadBits bits = GetCrossingRoadBits(t);
|
||||
bool hasroad = HasBit(_me[t].m7, 6);
|
||||
bool hastram = HasBit(_me[t].m7, 7);
|
||||
|
||||
/* MakeRoadNormal */
|
||||
SetTileType(t, MP_ROAD);
|
||||
SetTileOwner(t, road);
|
||||
_m[t].m3 = (hasroad ? bits : 0);
|
||||
_m[t].m5 = (hastram ? bits : 0) | ROAD_TILE_NORMAL << 6;
|
||||
SB(_me[t].m6, 2, 4, 0);
|
||||
SetRoadOwner(t, RTT_TRAM, tram);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -537,6 +556,12 @@ bool AfterLoadGame()
|
||||
GamelogTestRevision();
|
||||
GamelogTestMode();
|
||||
|
||||
RebuildTownKdtree();
|
||||
RebuildStationKdtree();
|
||||
/* This needs to be done even before conversion, because some conversions will destroy objects
|
||||
* that otherwise won't exist in the tree. */
|
||||
RebuildViewportKdtree();
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_98)) GamelogGRFAddList(_grfconfig);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_119)) {
|
||||
@@ -624,22 +649,22 @@ bool AfterLoadGame()
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->name = CopyFromOldName(c->name_1);
|
||||
if (c->name != NULL) c->name_1 = STR_SV_UNNAMED;
|
||||
if (c->name != nullptr) c->name_1 = STR_SV_UNNAMED;
|
||||
c->president_name = CopyFromOldName(c->president_name_1);
|
||||
if (c->president_name != NULL) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
|
||||
if (c->president_name != nullptr) c->president_name_1 = SPECSTR_PRESIDENT_NAME;
|
||||
}
|
||||
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
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 != NULL) st->string_id = STR_SV_STNAME_FALLBACK;
|
||||
if (st->name != nullptr) st->string_id = STR_SV_STNAME_FALLBACK;
|
||||
}
|
||||
|
||||
Town *t;
|
||||
FOR_ALL_TOWNS(t) {
|
||||
t->name = CopyFromOldName(t->townnametype);
|
||||
if (t->name != NULL) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
|
||||
if (t->name != nullptr) t->townnametype = SPECSTR_TOWNNAME_START + _settings_game.game_creation.town_name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -651,7 +676,6 @@ bool AfterLoadGame()
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
if (st->airport.tile == 0) st->airport.tile = INVALID_TILE;
|
||||
if (st->dock_tile == 0) st->dock_tile = INVALID_TILE;
|
||||
if (st->train_station.tile == 0) st->train_station.tile = INVALID_TILE;
|
||||
}
|
||||
|
||||
@@ -669,7 +693,7 @@ bool AfterLoadGame()
|
||||
|
||||
/* Check if all NewGRFs are present, we are very strict in MP mode */
|
||||
GRFListCompatibility gcf_res = IsGoodGRFConfigList(_grfconfig);
|
||||
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
||||
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
|
||||
if (c->status == GCS_NOT_FOUND) {
|
||||
GamelogGRFRemove(c->ident.grfid);
|
||||
} else if (HasBit(c->flags, GCF_COMPATIBLE)) {
|
||||
@@ -780,7 +804,7 @@ bool AfterLoadGame()
|
||||
{
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
if (c->is_ai && c->ai_instance == NULL) AI::StartNew(c->index);
|
||||
if (c->is_ai && c->ai_instance == nullptr) AI::StartNew(c->index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -980,7 +1004,7 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(SLV_16)) {
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->engine_renew_list = NULL;
|
||||
c->engine_renew_list = nullptr;
|
||||
c->settings.engine_renew = false;
|
||||
c->settings.engine_renew_months = 6;
|
||||
c->settings.engine_renew_money = 100000;
|
||||
@@ -993,7 +1017,7 @@ bool AfterLoadGame()
|
||||
* companies are 'invalid'.
|
||||
*/
|
||||
c = Company::GetIfValid(COMPANY_FIRST);
|
||||
if (!_network_dedicated && c != NULL) {
|
||||
if (!_network_dedicated && c != nullptr) {
|
||||
c->settings = _settings_client.company;
|
||||
}
|
||||
}
|
||||
@@ -1045,18 +1069,18 @@ bool AfterLoadGame()
|
||||
break;
|
||||
case ROAD_TILE_DEPOT: break;
|
||||
}
|
||||
SetRoadTypes(t, ROADTYPES_ROAD);
|
||||
SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
if (IsRoadStop(t)) SetRoadTypes(t, ROADTYPES_ROAD);
|
||||
if (IsRoadStop(t)) SB(_me[t].m7, 6, 2, 1);
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
/* Middle part of "old" bridges */
|
||||
if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
|
||||
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
||||
SetRoadTypes(t, ROADTYPES_ROAD);
|
||||
SB(_me[t].m7, 6, 2, 1); // Set pre-NRT road type bits for conversion later.
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1072,7 +1096,7 @@ bool AfterLoadGame()
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_me[t].m7, 5, 3));
|
||||
if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_me[t].m7, 5, 3));
|
||||
SB(_me[t].m7, 5, 1, GB(_m[t].m3, 7, 1)); // snow/desert
|
||||
switch (GetRoadTileType(t)) {
|
||||
default: SlErrorCorrupt("Invalid road tile type");
|
||||
@@ -1097,7 +1121,7 @@ bool AfterLoadGame()
|
||||
}
|
||||
if (!IsRoadDepot(t) && !HasTownOwnedRoad(t)) {
|
||||
const Town *town = CalcClosestTownFromTile(t);
|
||||
if (town != NULL) SetTownIndex(t, town->index);
|
||||
if (town != nullptr) SetTownIndex(t, town->index);
|
||||
}
|
||||
_m[t].m4 = 0;
|
||||
break;
|
||||
@@ -1105,7 +1129,7 @@ bool AfterLoadGame()
|
||||
case MP_STATION:
|
||||
if (!IsRoadStop(t)) break;
|
||||
|
||||
if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
|
||||
if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
|
||||
SB(_me[t].m7, 0, 5, HasBit(_me[t].m6, 2) ? OWNER_TOWN : GetTileOwner(t));
|
||||
SB(_m[t].m3, 4, 4, _m[t].m1);
|
||||
_m[t].m4 = 0;
|
||||
@@ -1114,7 +1138,7 @@ bool AfterLoadGame()
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (old_bridge && IsBridge(t) && HasBit(_m[t].m5, 6)) break;
|
||||
if (((old_bridge && IsBridge(t)) ? (TransportType)GB(_m[t].m5, 1, 2) : GetTunnelBridgeTransportType(t)) == TRANSPORT_ROAD) {
|
||||
if (fix_roadtypes) SetRoadTypes(t, (RoadTypes)GB(_m[t].m3, 0, 3));
|
||||
if (fix_roadtypes) SB(_me[t].m7, 6, 2, (RoadTypes)GB(_m[t].m3, 0, 3));
|
||||
|
||||
Owner o = GetTileOwner(t);
|
||||
SB(_me[t].m7, 0, 5, o); // road owner
|
||||
@@ -1184,13 +1208,14 @@ bool AfterLoadGame()
|
||||
} else {
|
||||
TownID town = IsTileOwner(t, OWNER_TOWN) ? ClosestTownFromTile(t, UINT_MAX)->index : 0;
|
||||
|
||||
MakeRoadNormal(
|
||||
t,
|
||||
axis == AXIS_X ? ROAD_Y : ROAD_X,
|
||||
ROADTYPES_ROAD,
|
||||
town,
|
||||
GetTileOwner(t), OWNER_NONE
|
||||
);
|
||||
/* MakeRoadNormal */
|
||||
SetTileType(t, MP_ROAD);
|
||||
_m[t].m2 = town;
|
||||
_m[t].m3 = 0;
|
||||
_m[t].m5 = (axis == AXIS_X ? ROAD_Y : ROAD_X) | ROAD_TILE_NORMAL << 6;
|
||||
SB(_me[t].m6, 2, 4, 0);
|
||||
_me[t].m7 = 1 << 6;
|
||||
SetRoadOwner(t, RTT_TRAM, OWNER_NONE);
|
||||
}
|
||||
} else {
|
||||
if (GB(_m[t].m5, 3, 2) == 0) {
|
||||
@@ -1245,6 +1270,35 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_ROAD_TYPES)) {
|
||||
/* Add road subtypes */
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
bool has_road = false;
|
||||
switch (GetTileType(t)) {
|
||||
case MP_ROAD:
|
||||
has_road = true;
|
||||
break;
|
||||
case MP_STATION:
|
||||
has_road = IsRoadStop(t);
|
||||
break;
|
||||
case MP_TUNNELBRIDGE:
|
||||
has_road = GetTunnelBridgeTransportType(t) == TRANSPORT_ROAD;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (has_road) {
|
||||
RoadType road_rt = HasBit(_me[t].m7, 6) ? ROADTYPE_ROAD : INVALID_ROADTYPE;
|
||||
RoadType tram_rt = HasBit(_me[t].m7, 7) ? ROADTYPE_TRAM : INVALID_ROADTYPE;
|
||||
|
||||
assert(road_rt != INVALID_ROADTYPE || tram_rt != INVALID_ROADTYPE);
|
||||
SetRoadTypes(t, road_rt, tram_rt);
|
||||
SB(_me[t].m7, 6, 2, 0); // Clear pre-NRT road type bits.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Elrails got added in rev 24 */
|
||||
if (IsSavegameVersionBefore(SLV_24)) {
|
||||
RailType min_rail = RAILTYPE_ELECTRIC;
|
||||
@@ -1368,7 +1422,7 @@ bool AfterLoadGame()
|
||||
Company *c;
|
||||
FOR_ALL_COMPANIES(c) {
|
||||
c->avail_railtypes = GetCompanyRailtypes(c->index);
|
||||
c->avail_roadtypes = GetCompanyRoadtypes(c->index);
|
||||
c->avail_roadtypes = GetCompanyRoadTypes(c->index);
|
||||
}
|
||||
|
||||
if (!IsSavegameVersionBefore(SLV_27)) AfterLoadStations();
|
||||
@@ -1704,9 +1758,9 @@ bool AfterLoadGame()
|
||||
|
||||
Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->orders.list != NULL && v->orders.list->GetFirstOrder() != NULL && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) {
|
||||
if (v->orders.list != nullptr && v->orders.list->GetFirstOrder() != nullptr && v->orders.list->GetFirstOrder()->IsType(OT_NOTHING)) {
|
||||
v->orders.list->FreeChain();
|
||||
v->orders.list = NULL;
|
||||
v->orders.list = nullptr;
|
||||
}
|
||||
|
||||
v->current_order.ConvertFromOldSavegame();
|
||||
@@ -1828,7 +1882,7 @@ bool AfterLoadGame()
|
||||
if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) {
|
||||
Owner o = GetTileOwner(t);
|
||||
if (o < MAX_COMPANIES && !Company::IsValidID(o)) {
|
||||
Backup<CompanyByte> cur_company(_current_company, o, FILE_LINE);
|
||||
Backup<CompanyID> cur_company(_current_company, o, FILE_LINE);
|
||||
ChangeTileOwner(t, o, INVALID_OWNER);
|
||||
cur_company.Restore();
|
||||
}
|
||||
@@ -1839,10 +1893,10 @@ bool AfterLoadGame()
|
||||
}
|
||||
} else if (IsTileType(t, MP_ROAD)) {
|
||||
/* works for all RoadTileType */
|
||||
for (RoadType rt = ROADTYPE_ROAD; rt < ROADTYPE_END; rt++) {
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
/* update even non-existing road types to update tile owner too */
|
||||
Owner o = GetRoadOwner(t, rt);
|
||||
if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rt, OWNER_NONE);
|
||||
Owner o = GetRoadOwner(t, rtt);
|
||||
if (o < MAX_COMPANIES && !Company::IsValidID(o)) SetRoadOwner(t, rtt, OWNER_NONE);
|
||||
}
|
||||
if (IsLevelCrossing(t)) {
|
||||
if (!Company::IsValidID(GetTileOwner(t))) FixOwnerOfRailTrack(t);
|
||||
@@ -1868,7 +1922,7 @@ bool AfterLoadGame()
|
||||
if (_settings_game.pf.yapf.ship_use_yapf) {
|
||||
_settings_game.pf.pathfinder_for_ships = VPF_YAPF;
|
||||
} else {
|
||||
_settings_game.pf.pathfinder_for_ships = (_settings_game.pf.new_pathfinding_all ? VPF_NPF : VPF_OPF);
|
||||
_settings_game.pf.pathfinder_for_ships = VPF_NPF;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2104,7 +2158,7 @@ bool AfterLoadGame()
|
||||
_settings_game.economy.town_layout = TL_BETTER_ROADS;
|
||||
} else {
|
||||
_settings_game.economy.allow_town_roads = true;
|
||||
_settings_game.economy.town_layout = _settings_game.economy.town_layout - 1;
|
||||
_settings_game.economy.town_layout = static_cast<TownLayout>(_settings_game.economy.town_layout - 1);
|
||||
}
|
||||
|
||||
/* Initialize layout of all towns. Older versions were using different
|
||||
@@ -2123,7 +2177,7 @@ bool AfterLoadGame()
|
||||
case 5: layout = 1; break;
|
||||
case 0: layout = 2; break;
|
||||
}
|
||||
t->layout = layout - 1;
|
||||
t->layout = static_cast<TownLayout>(layout - 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2159,7 +2213,7 @@ bool AfterLoadGame()
|
||||
FOR_ALL_DISASTERVEHICLES(v) {
|
||||
if (v->subtype == 2 /* ST_SMALL_UFO */ && v->current_order.GetDestination() != 0) {
|
||||
const Vehicle *u = Vehicle::GetIfValid(v->dest_tile);
|
||||
if (u == NULL || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
|
||||
if (u == nullptr || u->type != VEH_ROAD || !RoadVehicle::From(u)->IsFrontEngine()) {
|
||||
delete v;
|
||||
}
|
||||
}
|
||||
@@ -2180,7 +2234,7 @@ bool AfterLoadGame()
|
||||
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
|
||||
assert(CargoPayment::CanAllocateItem());
|
||||
Vehicle *v = *iter;
|
||||
if (v->cargo_payment == NULL) v->cargo_payment = new CargoPayment(v);
|
||||
if (v->cargo_payment == nullptr) v->cargo_payment = new CargoPayment(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2189,14 +2243,14 @@ bool AfterLoadGame()
|
||||
/* Animated tiles would sometimes not be actually animated or
|
||||
* in case of old savegames duplicate. */
|
||||
|
||||
extern SmallVector<TileIndex, 256> _animated_tiles;
|
||||
extern std::vector<TileIndex> _animated_tiles;
|
||||
|
||||
for (TileIndex *tile = _animated_tiles.Begin(); tile < _animated_tiles.End(); /* Nothing */) {
|
||||
for (auto tile = _animated_tiles.begin(); tile < _animated_tiles.end(); /* Nothing */) {
|
||||
/* Remove if tile is not animated */
|
||||
bool remove = _tile_type_procs[GetTileType(*tile)]->animate_tile_proc == NULL;
|
||||
bool remove = _tile_type_procs[GetTileType(*tile)]->animate_tile_proc == nullptr;
|
||||
|
||||
/* and remove if duplicate */
|
||||
for (TileIndex *j = _animated_tiles.Begin(); !remove && j < tile; j++) {
|
||||
for (auto j = _animated_tiles.begin(); !remove && j < tile; j++) {
|
||||
remove = *tile == *j;
|
||||
}
|
||||
|
||||
@@ -2265,7 +2319,7 @@ bool AfterLoadGame()
|
||||
/* Town -> Town */
|
||||
const Station *ss = Station::GetIfValid(s->src);
|
||||
const Station *sd = Station::GetIfValid(s->dst);
|
||||
if (ss != NULL && sd != NULL && ss->owner == sd->owner &&
|
||||
if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
|
||||
Company::IsValidID(ss->owner)) {
|
||||
s->src_type = s->dst_type = ST_TOWN;
|
||||
s->src = ss->town->index;
|
||||
@@ -2440,13 +2494,13 @@ bool AfterLoadGame()
|
||||
FOR_ALL_AIRCRAFT(v) {
|
||||
if (!v->IsNormalAircraft()) continue;
|
||||
Station *st = GetTargetAirportIfValid(v);
|
||||
if (st == NULL && v->state != FLYING) {
|
||||
if (st == nullptr && v->state != FLYING) {
|
||||
v->state = FLYING;
|
||||
UpdateAircraftCache(v);
|
||||
AircraftNextAirportPos_and_Order(v);
|
||||
/* get aircraft back on running altitude */
|
||||
if ((v->vehstatus & VS_CRASHED) == 0) {
|
||||
GetAircraftFlightLevelBounds(v, &v->z_pos, NULL);
|
||||
GetAircraftFlightLevelBounds(v, &v->z_pos, nullptr);
|
||||
SetAircraftPosition(v, v->x_pos, v->y_pos, GetAircraftFlightLevel(v));
|
||||
}
|
||||
}
|
||||
@@ -2508,11 +2562,11 @@ bool AfterLoadGame()
|
||||
* order they have in the pool. */
|
||||
Waypoint *wp;
|
||||
FOR_ALL_WAYPOINTS(wp) {
|
||||
if (wp->name != NULL) wp->town_cn = UINT16_MAX;
|
||||
if (wp->name != nullptr) wp->town_cn = UINT16_MAX;
|
||||
}
|
||||
|
||||
FOR_ALL_WAYPOINTS(wp) {
|
||||
if (wp->name != NULL) MakeDefaultName(wp);
|
||||
if (wp->name != nullptr) MakeDefaultName(wp);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2655,7 +2709,7 @@ bool AfterLoadGame()
|
||||
|
||||
if (rv->state == RVSB_IN_DEPOT || rv->state == RVSB_WORMHOLE) break;
|
||||
|
||||
TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, rv->compatible_roadtypes);
|
||||
TrackStatus ts = GetTileTrackStatus(rv->tile, TRANSPORT_ROAD, GetRoadTramType(rv->roadtype));
|
||||
TrackBits trackbits = TrackStatusToTrackBits(ts);
|
||||
|
||||
/* Only X/Y tracks can be sloped. */
|
||||
@@ -2744,7 +2798,7 @@ bool AfterLoadGame()
|
||||
if (!IsSavegameVersionBefore(SLV_76)) {
|
||||
Industry *ind;
|
||||
FOR_ALL_INDUSTRIES(ind) {
|
||||
assert(ind->psa != NULL);
|
||||
assert(ind->psa != nullptr);
|
||||
|
||||
/* Check if the old storage was empty. */
|
||||
bool is_empty = true;
|
||||
@@ -2759,7 +2813,7 @@ bool AfterLoadGame()
|
||||
ind->psa->grfid = _industry_mngr.GetGRFID(ind->type);
|
||||
} else {
|
||||
delete ind->psa;
|
||||
ind->psa = NULL;
|
||||
ind->psa = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2768,7 +2822,7 @@ bool AfterLoadGame()
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
if (!(st->facilities & FACIL_AIRPORT)) continue;
|
||||
assert(st->airport.psa != NULL);
|
||||
assert(st->airport.psa != nullptr);
|
||||
|
||||
/* Check if the old storage was empty. */
|
||||
bool is_empty = true;
|
||||
@@ -2783,7 +2837,7 @@ bool AfterLoadGame()
|
||||
st->airport.psa->grfid = _airport_mngr.GetGRFID(st->airport.type);
|
||||
} else {
|
||||
delete st->airport.psa;
|
||||
st->airport.psa = NULL;
|
||||
st->airport.psa = nullptr;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2823,12 +2877,12 @@ bool AfterLoadGame()
|
||||
/* Set the default cargo requirement for town growth */
|
||||
switch (_settings_game.game_creation.landscape) {
|
||||
case LT_ARCTIC:
|
||||
if (FindFirstCargoWithTownEffect(TE_FOOD) != NULL) t->goal[TE_FOOD] = TOWN_GROWTH_WINTER;
|
||||
if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_WINTER;
|
||||
break;
|
||||
|
||||
case LT_TROPIC:
|
||||
if (FindFirstCargoWithTownEffect(TE_FOOD) != NULL) t->goal[TE_FOOD] = TOWN_GROWTH_DESERT;
|
||||
if (FindFirstCargoWithTownEffect(TE_WATER) != NULL) t->goal[TE_WATER] = TOWN_GROWTH_DESERT;
|
||||
if (FindFirstCargoWithTownEffect(TE_FOOD) != nullptr) t->goal[TE_FOOD] = TOWN_GROWTH_DESERT;
|
||||
if (FindFirstCargoWithTownEffect(TE_WATER) != nullptr) t->goal[TE_WATER] = TOWN_GROWTH_DESERT;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2836,7 +2890,7 @@ bool AfterLoadGame()
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_165)) {
|
||||
/* Adjust zoom level to account for new levels */
|
||||
_saved_scrollpos_zoom = _saved_scrollpos_zoom + ZOOM_LVL_SHIFT;
|
||||
_saved_scrollpos_zoom = static_cast<ZoomLevel>(_saved_scrollpos_zoom + ZOOM_LVL_SHIFT);
|
||||
_saved_scrollpos_x *= ZOOM_LVL_BASE;
|
||||
_saved_scrollpos_y *= ZOOM_LVL_BASE;
|
||||
}
|
||||
@@ -2864,8 +2918,8 @@ bool AfterLoadGame()
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
if (!IsStandardRoadStopTile(t)) continue;
|
||||
Owner o = GetTileOwner(t);
|
||||
SetRoadOwner(t, ROADTYPE_ROAD, o);
|
||||
SetRoadOwner(t, ROADTYPE_TRAM, o);
|
||||
SetRoadOwner(t, RTT_ROAD, o);
|
||||
SetRoadOwner(t, RTT_TRAM, o);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2941,14 +2995,14 @@ bool AfterLoadGame()
|
||||
* So, make articulated parts catch up. */
|
||||
RoadVehicle *v;
|
||||
bool roadside = _settings_game.vehicle.road_side == 1;
|
||||
SmallVector<uint, 16> skip_frames;
|
||||
std::vector<uint> skip_frames;
|
||||
FOR_ALL_ROADVEHICLES(v) {
|
||||
if (!v->IsFrontEngine()) continue;
|
||||
skip_frames.Clear();
|
||||
skip_frames.clear();
|
||||
TileIndex prev_tile = v->tile;
|
||||
uint prev_tile_skip = 0;
|
||||
uint cur_skip = 0;
|
||||
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
|
||||
for (RoadVehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
if (u->tile != prev_tile) {
|
||||
prev_tile_skip = cur_skip;
|
||||
prev_tile = u->tile;
|
||||
@@ -2956,24 +3010,24 @@ bool AfterLoadGame()
|
||||
cur_skip = prev_tile_skip;
|
||||
}
|
||||
|
||||
uint *this_skip = skip_frames.Append();
|
||||
*this_skip = prev_tile_skip;
|
||||
/*C++17: uint &this_skip = */ skip_frames.push_back(prev_tile_skip);
|
||||
uint &this_skip = skip_frames.back();
|
||||
|
||||
/* The following 3 curves now take longer than before */
|
||||
switch (u->state) {
|
||||
case 2:
|
||||
cur_skip++;
|
||||
if (u->frame <= (roadside ? 9 : 5)) *this_skip = cur_skip;
|
||||
if (u->frame <= (roadside ? 9 : 5)) this_skip = cur_skip;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
cur_skip++;
|
||||
if (u->frame <= (roadside ? 5 : 9)) *this_skip = cur_skip;
|
||||
if (u->frame <= (roadside ? 5 : 9)) this_skip = cur_skip;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
cur_skip++;
|
||||
if (u->frame <= (roadside ? 4 : 2)) *this_skip = cur_skip;
|
||||
if (u->frame <= (roadside ? 4 : 2)) this_skip = cur_skip;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -2982,10 +3036,13 @@ bool AfterLoadGame()
|
||||
}
|
||||
while (cur_skip > skip_frames[0]) {
|
||||
RoadVehicle *u = v;
|
||||
RoadVehicle *prev = NULL;
|
||||
for (uint *it = skip_frames.Begin(); it != skip_frames.End(); ++it, prev = u, u = u->Next()) {
|
||||
RoadVehicle *prev = nullptr;
|
||||
for (uint sf : skip_frames) {
|
||||
extern bool IndividualRoadVehicleController(RoadVehicle *v, const RoadVehicle *prev);
|
||||
if (*it >= cur_skip) IndividualRoadVehicleController(u, prev);
|
||||
if (sf >= cur_skip) IndividualRoadVehicleController(u, prev);
|
||||
|
||||
prev = u;
|
||||
u = u->Next();
|
||||
}
|
||||
cur_skip--;
|
||||
}
|
||||
@@ -3089,13 +3146,61 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* Update water class for trees for all current savegame versions. */
|
||||
if (IsSavegameVersionBefore(SLV_TOWN_CARGOGEN)) {
|
||||
/* Ensure the original cargo generation mode is used */
|
||||
_settings_game.economy.town_cargogen_mode = TCGM_ORIGINAL;
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_SERVE_NEUTRAL_INDUSTRIES)) {
|
||||
/* Ensure the original neutral industry/station behaviour is used */
|
||||
_settings_game.station.serve_neutral_industries = true;
|
||||
|
||||
/* Link oil rigs to their industry and back. */
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
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));
|
||||
st->industry->neutral_station = st;
|
||||
}
|
||||
}
|
||||
} 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;
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_TREES_WATER_CLASS)) {
|
||||
/* Update water class for trees. */
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
if (IsTileType(t, MP_TREES)) SetWaterClass(t, GetTreeGround(t) == TREE_GROUND_SHORE ? WATER_CLASS_SEA : WATER_CLASS_INVALID);
|
||||
}
|
||||
}
|
||||
|
||||
/* Update structures for multitile docks */
|
||||
if (IsSavegameVersionBefore(SLV_MULTITILE_DOCKS)) {
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
/* Clear docking tile flag from relevant tiles as it
|
||||
* was not previously cleared. */
|
||||
if (IsTileType(t, MP_WATER) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_STATION) || IsTileType(t, MP_TUNNELBRIDGE)) {
|
||||
SetDockingTile(t, false);
|
||||
}
|
||||
/* Add docks and oilrigs to Station::ship_station. */
|
||||
if (IsTileType(t, MP_STATION)) {
|
||||
if (IsDock(t) || IsOilRig(t)) Station::GetByTile(t)->ship_station.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
/* Scan for docking tiles */
|
||||
Station *st;
|
||||
FOR_ALL_STATIONS(st) {
|
||||
if (st->ship_station.tile != INVALID_TILE) UpdateStationDockingTiles(st);
|
||||
}
|
||||
}
|
||||
|
||||
/* Compute station catchment areas. This is needed here in case UpdateStationAcceptance is called below. */
|
||||
Station::RecomputeCatchmentForAll();
|
||||
|
||||
/* Station acceptance is some kind of cache */
|
||||
if (IsSavegameVersionBefore(SLV_127)) {
|
||||
Station *st;
|
||||
|
||||
@@ -53,7 +53,7 @@ static void SaveReal_AIPL(int *index_ptr)
|
||||
_ai_saveload_settings[0] = '\0';
|
||||
config->SettingsToString(_ai_saveload_settings, lastof(_ai_saveload_settings));
|
||||
|
||||
SlObject(NULL, _ai_company);
|
||||
SlObject(nullptr, _ai_company);
|
||||
/* If the AI was active, store his data too */
|
||||
if (Company::IsValidAiID(index)) AI::Save(index);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static void Load_AIPL()
|
||||
{
|
||||
/* Free all current data */
|
||||
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
|
||||
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(NULL);
|
||||
AIConfig::GetConfig(c, AIConfig::SSS_FORCE_GAME)->Change(nullptr);
|
||||
}
|
||||
|
||||
CompanyID index;
|
||||
@@ -71,7 +71,7 @@ static void Load_AIPL()
|
||||
|
||||
_ai_saveload_is_random = 0;
|
||||
_ai_saveload_version = -1;
|
||||
SlObject(NULL, _ai_company);
|
||||
SlObject(nullptr, _ai_company);
|
||||
|
||||
if (_networking && !_network_server) {
|
||||
if (Company::IsValidAiID(index)) AIInstance::LoadEmpty();
|
||||
@@ -81,7 +81,7 @@ static void Load_AIPL()
|
||||
AIConfig *config = AIConfig::GetConfig(index, AIConfig::SSS_FORCE_GAME);
|
||||
if (StrEmpty(_ai_saveload_name)) {
|
||||
/* A random AI. */
|
||||
config->Change(NULL, -1, false, true);
|
||||
config->Change(nullptr, -1, false, true);
|
||||
} else {
|
||||
config->Change(_ai_saveload_name, _ai_saveload_version, false, _ai_saveload_is_random);
|
||||
if (!config->HasScript()) {
|
||||
@@ -125,5 +125,5 @@ static void Save_AIPL()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _ai_chunk_handlers[] = {
|
||||
{ 'AIPL', Save_AIPL, Load_AIPL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'AIPL', Save_AIPL, Load_AIPL, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -37,6 +37,6 @@ static void Load_ATID()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _airport_chunk_handlers[] = {
|
||||
{ 'ATID', Save_ATID, Load_ATID, NULL, NULL, CH_ARRAY },
|
||||
{ 'APID', Save_APID, Load_APID, NULL, NULL, CH_ARRAY | CH_LAST },
|
||||
{ 'ATID', Save_ATID, Load_ATID, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'APID', Save_APID, Load_APID, nullptr, nullptr, CH_ARRAY | CH_LAST },
|
||||
};
|
||||
|
||||
@@ -18,15 +18,15 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
extern SmallVector<TileIndex, 256> _animated_tiles;
|
||||
extern std::vector<TileIndex> _animated_tiles;
|
||||
|
||||
/**
|
||||
* Save the ANIT chunk.
|
||||
*/
|
||||
static void Save_ANIT()
|
||||
{
|
||||
SlSetLength(_animated_tiles.Length() * sizeof(*_animated_tiles.Begin()));
|
||||
SlArray(_animated_tiles.Begin(), _animated_tiles.Length(), SLE_UINT32);
|
||||
SlSetLength(_animated_tiles.size() * sizeof(_animated_tiles.front()));
|
||||
SlArray(_animated_tiles.data(), _animated_tiles.size(), SLE_UINT32);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,15 +42,15 @@ static void Load_ANIT()
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (anim_list[i] == 0) break;
|
||||
*_animated_tiles.Append() = anim_list[i];
|
||||
_animated_tiles.push_back(anim_list[i]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
uint count = (uint)SlGetFieldLength() / sizeof(*_animated_tiles.Begin());
|
||||
_animated_tiles.Clear();
|
||||
_animated_tiles.Append(count);
|
||||
SlArray(_animated_tiles.Begin(), count, SLE_UINT32);
|
||||
uint count = (uint)SlGetFieldLength() / sizeof(_animated_tiles.front());
|
||||
_animated_tiles.clear();
|
||||
_animated_tiles.resize(_animated_tiles.size() + count);
|
||||
SlArray(_animated_tiles.data(), count, SLE_UINT32);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,5 +58,5 @@ static void Load_ANIT()
|
||||
* the animated tile table.
|
||||
*/
|
||||
extern const ChunkHandler _animated_tile_chunk_handlers[] = {
|
||||
{ 'ANIT', Save_ANIT, Load_ANIT, NULL, NULL, CH_RIFF | CH_LAST},
|
||||
{ 'ANIT', Save_ANIT, Load_ANIT, nullptr, nullptr, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -63,5 +63,5 @@ static void Ptrs_ERNW()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _autoreplace_chunk_handlers[] = {
|
||||
{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'ERNW', Save_ERNW, Load_ERNW, Ptrs_ERNW, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -121,6 +121,6 @@ static void LoadPickup()
|
||||
|
||||
/** Chunk definition of the cargomonitoring maps. */
|
||||
extern const ChunkHandler _cargomonitor_chunk_handlers[] = {
|
||||
{ 'CMDL', SaveDelivery, LoadDelivery, NULL, NULL, CH_ARRAY},
|
||||
{ 'CMPU', SavePickup, LoadPickup, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'CMDL', SaveDelivery, LoadDelivery, nullptr, nullptr, CH_ARRAY},
|
||||
{ 'CMPU', SavePickup, LoadPickup, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -139,5 +139,5 @@ static void Load_CAPA()
|
||||
|
||||
/** Chunk handlers related to cargo packets. */
|
||||
extern const ChunkHandler _cargopacket_chunk_handlers[] = {
|
||||
{ 'CAPA', Save_CAPA, Load_CAPA, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'CAPA', Save_CAPA, Load_CAPA, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -51,5 +51,5 @@ static void Load_CHTS()
|
||||
|
||||
/** Chunk handlers related to cheats. */
|
||||
extern const ChunkHandler _cheat_chunk_handlers[] = {
|
||||
{ 'CHTS', Save_CHTS, Load_CHTS, NULL, NULL, CH_RIFF | CH_LAST},
|
||||
{ 'CHTS', Save_CHTS, Load_CHTS, nullptr, nullptr, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
||||
+28
-25
@@ -111,7 +111,7 @@ void AfterLoadCompanyStats()
|
||||
switch (GetTileType(tile)) {
|
||||
case MP_RAILWAY:
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) {
|
||||
if (c != nullptr) {
|
||||
uint pieces = 1;
|
||||
if (IsPlainRail(tile)) {
|
||||
TrackBits bits = GetTrackBits(tile);
|
||||
@@ -127,36 +127,38 @@ void AfterLoadCompanyStats()
|
||||
case MP_ROAD: {
|
||||
if (IsLevelCrossing(tile)) {
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
|
||||
if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += LEVELCROSSING_TRACKBIT_FACTOR;
|
||||
}
|
||||
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
|
||||
c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rt));
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
|
||||
/* A level crossings and depots have two road bits. */
|
||||
if (c != NULL) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rt)) : 2;
|
||||
if (c != nullptr) c->infrastructure.road[rt] += IsNormalRoad(tile) ? CountBits(GetRoadBits(tile, rtt)) : 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MP_STATION:
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL && GetStationType(tile) != STATION_AIRPORT && !IsBuoy(tile)) c->infrastructure.station++;
|
||||
if (c != nullptr && GetStationType(tile) != STATION_AIRPORT && !IsBuoy(tile)) c->infrastructure.station++;
|
||||
|
||||
switch (GetStationType(tile)) {
|
||||
case STATION_RAIL:
|
||||
case STATION_WAYPOINT:
|
||||
if (c != NULL && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
|
||||
if (c != nullptr && !IsStationTileBlocked(tile)) c->infrastructure.rail[GetRailType(tile)]++;
|
||||
break;
|
||||
|
||||
case STATION_BUS:
|
||||
case STATION_TRUCK: {
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rt));
|
||||
if (c != NULL) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rtt));
|
||||
if (c != nullptr) c->infrastructure.road[rt] += 2; // A road stop has two road bits.
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -164,7 +166,7 @@ void AfterLoadCompanyStats()
|
||||
case STATION_DOCK:
|
||||
case STATION_BUOY:
|
||||
if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
|
||||
if (c != NULL) c->infrastructure.water++;
|
||||
if (c != nullptr) c->infrastructure.water++;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -176,7 +178,7 @@ void AfterLoadCompanyStats()
|
||||
case MP_WATER:
|
||||
if (IsShipDepot(tile) || IsLock(tile)) {
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) {
|
||||
if (c != nullptr) {
|
||||
if (IsShipDepot(tile)) c->infrastructure.water += LOCK_DEPOT_TILE_FACTOR;
|
||||
if (IsLock(tile) && GetLockPart(tile) == LOCK_PART_MIDDLE) {
|
||||
/* The middle tile specifies the owner of the lock. */
|
||||
@@ -190,7 +192,7 @@ void AfterLoadCompanyStats()
|
||||
case MP_OBJECT:
|
||||
if (GetWaterClass(tile) == WATER_CLASS_CANAL) {
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) c->infrastructure.water++;
|
||||
if (c != nullptr) c->infrastructure.water++;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -205,22 +207,23 @@ void AfterLoadCompanyStats()
|
||||
switch (GetTunnelBridgeTransportType(tile)) {
|
||||
case TRANSPORT_RAIL:
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) c->infrastructure.rail[GetRailType(tile)] += len;
|
||||
if (c != nullptr) c->infrastructure.rail[GetRailType(tile)] += len;
|
||||
break;
|
||||
|
||||
case TRANSPORT_ROAD: {
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
RoadType rt;
|
||||
FOR_EACH_SET_ROADTYPE(rt, GetRoadTypes(tile)) {
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rt));
|
||||
if (c != NULL) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rtt));
|
||||
if (c != nullptr) c->infrastructure.road[rt] += len * 2; // A full diagonal road has two road bits.
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case TRANSPORT_WATER:
|
||||
c = Company::GetIfValid(GetTileOwner(tile));
|
||||
if (c != NULL) c->infrastructure.water += len;
|
||||
if (c != nullptr) c->infrastructure.water += len;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -414,7 +417,7 @@ static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
|
||||
int i;
|
||||
|
||||
SlObject(cprops, _company_desc);
|
||||
if (c != NULL) {
|
||||
if (c != nullptr) {
|
||||
SlObject(c, _company_settings_desc);
|
||||
} else {
|
||||
char nothing;
|
||||
@@ -444,7 +447,7 @@ static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
|
||||
/* Write each livery entry. */
|
||||
int num_liveries = IsSavegameVersionBefore(SLV_63) ? LS_END - 4 : (IsSavegameVersionBefore(SLV_85) ? LS_END - 2: LS_END);
|
||||
bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES);
|
||||
if (c != NULL) {
|
||||
if (c != nullptr) {
|
||||
for (i = 0; i < num_liveries; i++) {
|
||||
SlObject(&c->livery[i], _company_livery_desc);
|
||||
if (update_in_use && i != LS_DEFAULT) {
|
||||
@@ -507,7 +510,7 @@ static void Check_PLYR()
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
CompanyProperties *cprops = new CompanyProperties();
|
||||
SaveLoad_PLYR_common(NULL, cprops);
|
||||
SaveLoad_PLYR_common(nullptr, cprops);
|
||||
|
||||
/* We do not load old custom names */
|
||||
if (IsSavegameVersionBefore(SLV_84)) {
|
||||
@@ -520,7 +523,7 @@ static void Check_PLYR()
|
||||
}
|
||||
}
|
||||
|
||||
if (cprops->name == NULL && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
|
||||
if (cprops->name == nullptr && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
|
||||
cprops->name_1 != STR_GAME_SAVELOAD_NOT_AVAILABLE && cprops->name_1 != STR_SV_UNNAMED &&
|
||||
cprops->name_1 != SPECSTR_ANDCO_NAME && cprops->name_1 != SPECSTR_PRESIDENT_NAME &&
|
||||
cprops->name_1 != SPECSTR_SILLY_NAME) {
|
||||
|
||||
@@ -64,5 +64,5 @@ static void Ptrs_DEPT()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _depot_chunk_handlers[] = {
|
||||
{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'DEPT', Save_DEPT, Load_DEPT, Ptrs_DEPT, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -22,8 +22,8 @@ static void Load_PRIC()
|
||||
{
|
||||
/* Old games store 49 base prices, very old games store them as int32 */
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlArray(NULL, 49, vt | SLE_VAR_NULL);
|
||||
SlArray(NULL, 49, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
SlArray(nullptr, 49, vt | SLE_VAR_NULL);
|
||||
SlArray(nullptr, 49, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
|
||||
/** Cargo payment rates in pre 126 savegames */
|
||||
@@ -31,8 +31,8 @@ static void Load_CAPR()
|
||||
{
|
||||
uint num_cargo = IsSavegameVersionBefore(SLV_55) ? 12 : IsSavegameVersionBefore(SLV_EXTEND_CARGOTYPES) ? 32 : NUM_CARGO;
|
||||
int vt = IsSavegameVersionBefore(SLV_65) ? SLE_FILE_I32 : SLE_FILE_I64;
|
||||
SlArray(NULL, num_cargo, vt | SLE_VAR_NULL);
|
||||
SlArray(NULL, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
SlArray(nullptr, num_cargo, vt | SLE_VAR_NULL);
|
||||
SlArray(nullptr, num_cargo, SLE_FILE_U16 | SLE_VAR_NULL);
|
||||
}
|
||||
|
||||
static const SaveLoad _economy_desc[] = {
|
||||
@@ -101,8 +101,8 @@ static void Ptrs_CAPY()
|
||||
|
||||
|
||||
extern const ChunkHandler _economy_chunk_handlers[] = {
|
||||
{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, NULL, CH_ARRAY},
|
||||
{ 'PRIC', NULL, Load_PRIC, NULL, NULL, CH_RIFF | CH_AUTO_LENGTH},
|
||||
{ 'CAPR', NULL, Load_CAPR, NULL, NULL, CH_RIFF | CH_AUTO_LENGTH},
|
||||
{ 'ECMY', Save_ECMY, Load_ECMY, NULL, NULL, CH_RIFF | CH_LAST},
|
||||
{ 'CAPY', Save_CAPY, Load_CAPY, Ptrs_CAPY, nullptr, CH_ARRAY},
|
||||
{ 'PRIC', nullptr, Load_PRIC, nullptr, nullptr, CH_RIFF | CH_AUTO_LENGTH},
|
||||
{ 'CAPR', nullptr, Load_CAPR, nullptr, nullptr, CH_RIFF | CH_AUTO_LENGTH},
|
||||
{ 'ECMY', Save_ECMY, Load_ECMY, nullptr, nullptr, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
||||
+11
-10
@@ -68,7 +68,7 @@ static Engine* CallocEngine()
|
||||
*/
|
||||
static void FreeEngine(Engine *e)
|
||||
{
|
||||
if (e != NULL) {
|
||||
if (e != nullptr) {
|
||||
e->~Engine();
|
||||
free(e);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ void CopyTempEngineData()
|
||||
e->preview_wait = se->preview_wait;
|
||||
e->company_avail = se->company_avail;
|
||||
e->company_hidden = se->company_hidden;
|
||||
if (se->name != NULL) e->name = stredup(se->name);
|
||||
if (se->name != nullptr) e->name = stredup(se->name);
|
||||
}
|
||||
|
||||
/* Get rid of temporary data */
|
||||
@@ -177,26 +177,27 @@ static const SaveLoad _engine_id_mapping_desc[] = {
|
||||
|
||||
static void Save_EIDS()
|
||||
{
|
||||
const EngineIDMapping *end = _engine_mngr.End();
|
||||
uint index = 0;
|
||||
for (EngineIDMapping *eid = _engine_mngr.Begin(); eid != end; eid++, index++) {
|
||||
for (EngineIDMapping &eid : _engine_mngr) {
|
||||
SlSetArrayIndex(index);
|
||||
SlObject(eid, _engine_id_mapping_desc);
|
||||
SlObject(&eid, _engine_id_mapping_desc);
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_EIDS()
|
||||
{
|
||||
_engine_mngr.Clear();
|
||||
_engine_mngr.clear();
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
EngineIDMapping *eid = _engine_mngr.Append();
|
||||
/*C++17: EngineIDMapping *eid = &*/ _engine_mngr.emplace_back();
|
||||
EngineIDMapping *eid = &_engine_mngr.back();
|
||||
SlObject(eid, _engine_id_mapping_desc);
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _engine_chunk_handlers[] = {
|
||||
{ 'EIDS', Save_EIDS, Load_EIDS, NULL, NULL, CH_ARRAY },
|
||||
{ 'ENGN', Save_ENGN, Load_ENGN, NULL, NULL, CH_ARRAY },
|
||||
{ 'ENGS', NULL, Load_ENGS, NULL, NULL, CH_RIFF | CH_LAST },
|
||||
{ 'EIDS', Save_EIDS, Load_EIDS, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'ENGN', Save_ENGN, Load_ENGN, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'ENGS', nullptr, Load_ENGS, nullptr, nullptr, CH_RIFF | CH_LAST },
|
||||
};
|
||||
|
||||
+24
-24
@@ -52,19 +52,19 @@ static void SaveReal_GSDT(int *index_ptr)
|
||||
_game_saveload_settings[0] = '\0';
|
||||
config->SettingsToString(_game_saveload_settings, lastof(_game_saveload_settings));
|
||||
|
||||
SlObject(NULL, _game_script);
|
||||
SlObject(nullptr, _game_script);
|
||||
Game::Save();
|
||||
}
|
||||
|
||||
static void Load_GSDT()
|
||||
{
|
||||
/* Free all current data */
|
||||
GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME)->Change(NULL);
|
||||
GameConfig::GetConfig(GameConfig::SSS_FORCE_GAME)->Change(nullptr);
|
||||
|
||||
if ((CompanyID)SlIterateArray() == (CompanyID)-1) return;
|
||||
|
||||
_game_saveload_version = -1;
|
||||
SlObject(NULL, _game_script);
|
||||
SlObject(nullptr, _game_script);
|
||||
|
||||
if (_networking && !_network_server) {
|
||||
GameInstance::LoadEmpty();
|
||||
@@ -110,7 +110,7 @@ static void Load_GSDT()
|
||||
static void Save_GSDT()
|
||||
{
|
||||
SlSetArrayIndex(0);
|
||||
SlAutolength((AutolengthProc *)SaveReal_GSDT, NULL);
|
||||
SlAutolength((AutolengthProc *)SaveReal_GSDT, nullptr);
|
||||
}
|
||||
|
||||
extern GameStrings *_current_data;
|
||||
@@ -129,15 +129,15 @@ static const SaveLoad _game_language_string[] = {
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void SaveReal_GSTR(LanguageStrings *ls)
|
||||
static void SaveReal_GSTR(const LanguageStrings *ls)
|
||||
{
|
||||
_game_saveload_string = ls->language;
|
||||
_game_saveload_strings = ls->lines.Length();
|
||||
_game_saveload_strings = (uint)ls->lines.size();
|
||||
|
||||
SlObject(NULL, _game_language_header);
|
||||
for (uint i = 0; i < _game_saveload_strings; i++) {
|
||||
_game_saveload_string = ls->lines[i];
|
||||
SlObject(NULL, _game_language_string);
|
||||
SlObject(nullptr, _game_language_header);
|
||||
for (const auto &i : ls->lines) {
|
||||
_game_saveload_string = i.c_str();
|
||||
SlObject(nullptr, _game_language_string);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,22 +147,22 @@ static void Load_GSTR()
|
||||
_current_data = new GameStrings();
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
_game_saveload_string = NULL;
|
||||
SlObject(NULL, _game_language_header);
|
||||
_game_saveload_string = nullptr;
|
||||
SlObject(nullptr, _game_language_header);
|
||||
|
||||
LanguageStrings *ls = new LanguageStrings(_game_saveload_string != NULL ? _game_saveload_string : "");
|
||||
std::unique_ptr<LanguageStrings> ls(new LanguageStrings(_game_saveload_string != nullptr ? _game_saveload_string : ""));
|
||||
for (uint i = 0; i < _game_saveload_strings; i++) {
|
||||
SlObject(NULL, _game_language_string);
|
||||
*ls->lines.Append() = stredup(_game_saveload_string != NULL ? _game_saveload_string : "");
|
||||
SlObject(nullptr, _game_language_string);
|
||||
ls->lines.emplace_back(_game_saveload_string != nullptr ? _game_saveload_string : "");
|
||||
}
|
||||
|
||||
*_current_data->raw_strings.Append() = ls;
|
||||
_current_data->raw_strings.push_back(std::move(ls));
|
||||
}
|
||||
|
||||
/* If there were no strings in the savegame, set GameStrings to NULL */
|
||||
if (_current_data->raw_strings.Length() == 0) {
|
||||
/* If there were no strings in the savegame, set GameStrings to nullptr */
|
||||
if (_current_data->raw_strings.size() == 0) {
|
||||
delete _current_data;
|
||||
_current_data = NULL;
|
||||
_current_data = nullptr;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -172,15 +172,15 @@ static void Load_GSTR()
|
||||
|
||||
static void Save_GSTR()
|
||||
{
|
||||
if (_current_data == NULL) return;
|
||||
if (_current_data == nullptr) return;
|
||||
|
||||
for (uint i = 0; i < _current_data->raw_strings.Length(); i++) {
|
||||
for (uint i = 0; i < _current_data->raw_strings.size(); i++) {
|
||||
SlSetArrayIndex(i);
|
||||
SlAutolength((AutolengthProc *)SaveReal_GSTR, _current_data->raw_strings[i]);
|
||||
SlAutolength((AutolengthProc *)SaveReal_GSTR, _current_data->raw_strings[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _game_chunk_handlers[] = {
|
||||
{ 'GSTR', Save_GSTR, Load_GSTR, NULL, NULL, CH_ARRAY },
|
||||
{ 'GSDT', Save_GSDT, Load_GSDT, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'GSTR', Save_GSTR, Load_GSTR, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'GSDT', Save_GSDT, Load_GSDT, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -106,7 +106,7 @@ assert_compile(lengthof(_glog_desc) == GLCT_END);
|
||||
|
||||
static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_actions)
|
||||
{
|
||||
assert(gamelog_action == NULL);
|
||||
assert(gamelog_action == nullptr);
|
||||
assert(gamelog_actions == 0);
|
||||
|
||||
GamelogActionType at;
|
||||
@@ -117,7 +117,7 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action
|
||||
la->at = at;
|
||||
|
||||
SlObject(la, _glog_action_desc); // has to be saved after 'DATE'!
|
||||
la->change = NULL;
|
||||
la->change = nullptr;
|
||||
la->changes = 0;
|
||||
|
||||
GamelogChangeType ct;
|
||||
@@ -125,7 +125,7 @@ static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_action
|
||||
la->change = ReallocT(la->change, la->changes + 1);
|
||||
|
||||
LoggedChange *lc = &la->change[la->changes++];
|
||||
/* for SLE_STR, pointer has to be valid! so make it NULL */
|
||||
/* for SLE_STR, pointer has to be valid! so make it nullptr */
|
||||
memset(lc, 0, sizeof(*lc));
|
||||
lc->ct = ct;
|
||||
|
||||
@@ -179,5 +179,5 @@ static void Check_GLOG()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _gamelog_chunk_handlers[] = {
|
||||
{ 'GLOG', Save_GLOG, Load_GLOG, NULL, Check_GLOG, CH_RIFF | CH_LAST }
|
||||
{ 'GLOG', Save_GLOG, Load_GLOG, nullptr, Check_GLOG, CH_RIFF | CH_LAST }
|
||||
};
|
||||
|
||||
@@ -45,5 +45,5 @@ static void Load_GOAL()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _goal_chunk_handlers[] = {
|
||||
{ 'GOAL', Save_GOAL, Load_GOAL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'GOAL', Save_GOAL, Load_GOAL, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -61,5 +61,5 @@ static void Load_GRPS()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _group_chunk_handlers[] = {
|
||||
{ 'GRPS', Save_GRPS, Load_GRPS, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'GRPS', Save_GRPS, Load_GRPS, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -25,6 +25,7 @@ static const SaveLoad _industry_desc[] = {
|
||||
SLE_VAR(Industry, location.w, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_VAR(Industry, location.h, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_REF(Industry, town, REF_TOWN),
|
||||
SLE_CONDREF(Industry, neutral_station, REF_STATION, SLV_SERVE_NEUTRAL_INDUSTRIES, SL_MAX_VERSION),
|
||||
SLE_CONDNULL( 2, SL_MIN_VERSION, SLV_61), ///< used to be industry's produced_cargo
|
||||
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
|
||||
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
|
||||
@@ -182,9 +183,9 @@ static void Load_ITBL()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _industry_chunk_handlers[] = {
|
||||
{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, NULL, CH_ARRAY},
|
||||
{ 'IIDS', Save_IIDS, Load_IIDS, NULL, NULL, CH_ARRAY},
|
||||
{ 'TIDS', Save_TIDS, Load_TIDS, NULL, NULL, CH_ARRAY},
|
||||
{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, NULL, NULL, CH_RIFF},
|
||||
{ 'ITBL', Save_ITBL, Load_ITBL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'INDY', Save_INDY, Load_INDY, Ptrs_INDY, nullptr, CH_ARRAY},
|
||||
{ 'IIDS', Save_IIDS, Load_IIDS, nullptr, nullptr, CH_ARRAY},
|
||||
{ 'TIDS', Save_TIDS, Load_TIDS, nullptr, nullptr, CH_ARRAY},
|
||||
{ 'IBLD', LoadSave_IBLD, LoadSave_IBLD, nullptr, nullptr, CH_RIFF},
|
||||
{ 'ITBL', Save_ITBL, Load_ITBL, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
static SmallVector<RailTypeLabel, RAILTYPE_END> _railtype_list;
|
||||
static std::vector<RailTypeLabel> _railtype_list;
|
||||
|
||||
/**
|
||||
* Test if any saved rail type labels are different to the currently loaded
|
||||
@@ -26,7 +26,7 @@ static SmallVector<RailTypeLabel, RAILTYPE_END> _railtype_list;
|
||||
*/
|
||||
static bool NeedRailTypeConversion()
|
||||
{
|
||||
for (uint i = 0; i < _railtype_list.Length(); i++) {
|
||||
for (uint i = 0; i < _railtype_list.size(); i++) {
|
||||
if ((RailType)i < RAILTYPE_END) {
|
||||
const RailtypeInfo *rti = GetRailTypeInfo((RailType)i);
|
||||
if (rti->label != _railtype_list[i]) return true;
|
||||
@@ -42,13 +42,13 @@ static bool NeedRailTypeConversion()
|
||||
void AfterLoadLabelMaps()
|
||||
{
|
||||
if (NeedRailTypeConversion()) {
|
||||
SmallVector<RailType, RAILTYPE_END> railtype_conversion_map;
|
||||
std::vector<RailType> railtype_conversion_map;
|
||||
|
||||
for (uint i = 0; i < _railtype_list.Length(); i++) {
|
||||
for (uint i = 0; i < _railtype_list.size(); i++) {
|
||||
RailType r = GetRailTypeByLabel(_railtype_list[i]);
|
||||
if (r == INVALID_RAILTYPE) r = RAILTYPE_BEGIN;
|
||||
|
||||
*railtype_conversion_map.Append() = r;
|
||||
railtype_conversion_map.push_back(r);
|
||||
}
|
||||
|
||||
for (TileIndex t = 0; t < MapSize(); t++) {
|
||||
@@ -81,7 +81,7 @@ void AfterLoadLabelMaps()
|
||||
}
|
||||
}
|
||||
|
||||
_railtype_list.Clear();
|
||||
_railtype_list.clear();
|
||||
}
|
||||
|
||||
/** Container for a label for SaveLoad system */
|
||||
@@ -108,17 +108,17 @@ static void Save_RAIL()
|
||||
|
||||
static void Load_RAIL()
|
||||
{
|
||||
_railtype_list.Clear();
|
||||
_railtype_list.clear();
|
||||
|
||||
LabelObject lo;
|
||||
|
||||
while (SlIterateArray() != -1) {
|
||||
SlObject(&lo, _label_object_desc);
|
||||
*_railtype_list.Append() = (RailTypeLabel)lo.label;
|
||||
_railtype_list.push_back((RailTypeLabel)lo.label);
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _labelmaps_chunk_handlers[] = {
|
||||
{ 'RAIL', Save_RAIL, Load_RAIL, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'RAIL', Save_RAIL, Load_RAIL, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
|
||||
@@ -51,11 +51,11 @@ const SaveLoad *GetLinkGraphDesc()
|
||||
*/
|
||||
const SaveLoad *GetLinkGraphJobDesc()
|
||||
{
|
||||
static SmallVector<SaveLoad, 16> saveloads;
|
||||
static std::vector<SaveLoad> saveloads;
|
||||
static const char *prefix = "linkgraph.";
|
||||
|
||||
/* Build the SaveLoad array on first call and don't touch it later on */
|
||||
if (saveloads.Length() == 0) {
|
||||
if (saveloads.size() == 0) {
|
||||
size_t offset_gamesettings = cpp_offsetof(GameSettings, linkgraph);
|
||||
size_t offset_component = cpp_offsetof(LinkGraphJob, settings);
|
||||
|
||||
@@ -64,12 +64,12 @@ const SaveLoad *GetLinkGraphJobDesc()
|
||||
int setting = 0;
|
||||
const SettingDesc *desc = GetSettingDescription(setting);
|
||||
while (desc->save.cmd != SL_END) {
|
||||
if (desc->desc.name != NULL && strncmp(desc->desc.name, prefix, prefixlen) == 0) {
|
||||
if (desc->desc.name != nullptr && strncmp(desc->desc.name, prefix, prefixlen) == 0) {
|
||||
SaveLoad sl = desc->save;
|
||||
char *&address = reinterpret_cast<char *&>(sl.address);
|
||||
address -= offset_gamesettings;
|
||||
address += offset_component;
|
||||
*(saveloads.Append()) = sl;
|
||||
saveloads.push_back(sl);
|
||||
}
|
||||
desc = GetSettingDescription(++setting);
|
||||
}
|
||||
@@ -82,8 +82,8 @@ const SaveLoad *GetLinkGraphJobDesc()
|
||||
|
||||
int i = 0;
|
||||
do {
|
||||
*(saveloads.Append()) = job_desc[i++];
|
||||
} while (saveloads[saveloads.Length() - 1].cmd != SL_END);
|
||||
saveloads.push_back(job_desc[i++]);
|
||||
} while (saveloads[saveloads.size() - 1].cmd != SL_END);
|
||||
}
|
||||
|
||||
return &saveloads[0];
|
||||
@@ -292,7 +292,7 @@ static void Ptrs_LGRS()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _linkgraph_chunk_handlers[] = {
|
||||
{ 'LGRP', Save_LGRP, Load_LGRP, NULL, NULL, CH_ARRAY },
|
||||
{ 'LGRJ', Save_LGRJ, Load_LGRJ, NULL, NULL, CH_ARRAY },
|
||||
{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, NULL, CH_LAST }
|
||||
{ 'LGRP', Save_LGRP, Load_LGRP, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'LGRJ', Save_LGRJ, Load_LGRJ, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'LGRS', Save_LGRS, Load_LGRS, Ptrs_LGRS, nullptr, CH_LAST }
|
||||
};
|
||||
|
||||
+53
-52
@@ -13,6 +13,7 @@
|
||||
#include "../map_func.h"
|
||||
#include "../core/bitmath_func.hpp"
|
||||
#include "../fios.h"
|
||||
#include <array>
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
@@ -51,80 +52,80 @@ static const uint MAP_SL_BUF_SIZE = 4096;
|
||||
|
||||
static void Load_MAPT()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAPT()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAPH()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].height = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAPH()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].height;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP1()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP1()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m1;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP2()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE,
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE,
|
||||
/* In those versions the m2 was 8 bits */
|
||||
IsSavegameVersionBefore(SLV_5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
|
||||
);
|
||||
@@ -134,94 +135,94 @@ static void Load_MAP2()
|
||||
|
||||
static void Save_MAP2()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size * sizeof(uint16));
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m2;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP3()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP3()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m3;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP4()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP4()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m4;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP5()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP5()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m5;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP6()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_42)) {
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
/* 1024, otherwise we overflow on 64x64 maps! */
|
||||
SlArray(buf, 1024, SLE_UINT8);
|
||||
SlArray(buf.data(), 1024, SLE_UINT8);
|
||||
for (uint j = 0; j != 1024; j++) {
|
||||
_me[i++].m6 = GB(buf[j], 0, 2);
|
||||
_me[i++].m6 = GB(buf[j], 2, 2);
|
||||
@@ -231,7 +232,7 @@ static void Load_MAP6()
|
||||
}
|
||||
} else {
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m6 = buf[j];
|
||||
}
|
||||
}
|
||||
@@ -239,73 +240,73 @@ static void Load_MAP6()
|
||||
|
||||
static void Save_MAP6()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m6;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP7()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP7()
|
||||
{
|
||||
SmallStackSafeStackAlloc<byte, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<byte, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size);
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m7;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT8);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP8()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m8 = buf[j];
|
||||
}
|
||||
}
|
||||
|
||||
static void Save_MAP8()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
std::array<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
SlSetLength(size * sizeof(uint16));
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m8;
|
||||
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
SlArray(buf.data(), MAP_SL_BUF_SIZE, SLE_UINT16);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern const ChunkHandler _map_chunk_handlers[] = {
|
||||
{ 'MAPS', Save_MAPS, Load_MAPS, NULL, Check_MAPS, CH_RIFF },
|
||||
{ 'MAPT', Save_MAPT, Load_MAPT, NULL, NULL, CH_RIFF },
|
||||
{ 'MAPH', Save_MAPH, Load_MAPH, NULL, NULL, CH_RIFF },
|
||||
{ 'MAPO', Save_MAP1, Load_MAP1, NULL, NULL, CH_RIFF },
|
||||
{ 'MAP2', Save_MAP2, Load_MAP2, NULL, NULL, CH_RIFF },
|
||||
{ 'M3LO', Save_MAP3, Load_MAP3, NULL, NULL, CH_RIFF },
|
||||
{ 'M3HI', Save_MAP4, Load_MAP4, NULL, NULL, CH_RIFF },
|
||||
{ 'MAP5', Save_MAP5, Load_MAP5, NULL, NULL, CH_RIFF },
|
||||
{ 'MAPE', Save_MAP6, Load_MAP6, NULL, NULL, CH_RIFF },
|
||||
{ 'MAP7', Save_MAP7, Load_MAP7, NULL, NULL, CH_RIFF },
|
||||
{ 'MAP8', Save_MAP8, Load_MAP8, NULL, NULL, CH_RIFF | CH_LAST },
|
||||
{ 'MAPS', Save_MAPS, Load_MAPS, nullptr, Check_MAPS, CH_RIFF },
|
||||
{ 'MAPT', Save_MAPT, Load_MAPT, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAPH', Save_MAPH, Load_MAPH, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAPO', Save_MAP1, Load_MAP1, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAP2', Save_MAP2, Load_MAP2, nullptr, nullptr, CH_RIFF },
|
||||
{ 'M3LO', Save_MAP3, Load_MAP3, nullptr, nullptr, CH_RIFF },
|
||||
{ 'M3HI', Save_MAP4, Load_MAP4, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAP5', Save_MAP5, Load_MAP5, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAPE', Save_MAP6, Load_MAP6, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAP7', Save_MAP7, Load_MAP7, nullptr, nullptr, CH_RIFF },
|
||||
{ 'MAP8', Save_MAP8, Load_MAP8, nullptr, nullptr, CH_RIFF | CH_LAST },
|
||||
};
|
||||
|
||||
@@ -30,13 +30,13 @@ extern byte _trees_tick_ctr;
|
||||
/* Keep track of current game position */
|
||||
int _saved_scrollpos_x;
|
||||
int _saved_scrollpos_y;
|
||||
ZoomLevelByte _saved_scrollpos_zoom;
|
||||
ZoomLevel _saved_scrollpos_zoom;
|
||||
|
||||
void SaveViewportBeforeSaveGame()
|
||||
{
|
||||
const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||
|
||||
if (w != NULL) {
|
||||
if (w != nullptr) {
|
||||
_saved_scrollpos_x = w->viewport->scrollpos_x;
|
||||
_saved_scrollpos_y = w->viewport->scrollpos_y;
|
||||
_saved_scrollpos_zoom = w->viewport->zoom;
|
||||
@@ -151,6 +151,6 @@ static void SaveLoad_VIEW()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _misc_chunk_handlers[] = {
|
||||
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, NULL, Check_DATE, CH_RIFF},
|
||||
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, NULL, NULL, CH_RIFF | CH_LAST},
|
||||
{ 'DATE', SaveLoad_DATE, SaveLoad_DATE, nullptr, Check_DATE, CH_RIFF},
|
||||
{ 'VIEW', SaveLoad_VIEW, SaveLoad_VIEW, nullptr, nullptr, CH_RIFF | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -73,7 +73,7 @@ static void Save_NGRF()
|
||||
{
|
||||
int index = 0;
|
||||
|
||||
for (GRFConfig *c = _grfconfig; c != NULL; c = c->next) {
|
||||
for (GRFConfig *c = _grfconfig; c != nullptr; c = c->next) {
|
||||
if (HasBit(c->flags, GCF_STATIC)) continue;
|
||||
SlSetArrayIndex(index++);
|
||||
SlObject(c, _grfconfig_desc);
|
||||
@@ -98,7 +98,7 @@ static void Load_NGRF()
|
||||
|
||||
if (_game_mode == GM_MENU) {
|
||||
/* Intro game must not have NewGRF. */
|
||||
if (_grfconfig != NULL) SlErrorCorrupt("The intro game must not use NewGRF");
|
||||
if (_grfconfig != nullptr) SlErrorCorrupt("The intro game must not use NewGRF");
|
||||
|
||||
/* Activate intro NewGRFs (townnames) */
|
||||
ResetGRFConfig(false);
|
||||
@@ -114,5 +114,5 @@ static void Check_NGRF()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _newgrf_chunk_handlers[] = {
|
||||
{ 'NGRF', Save_NGRF, Load_NGRF, NULL, Check_NGRF, CH_ARRAY | CH_LAST }
|
||||
{ 'NGRF', Save_NGRF, Load_NGRF, nullptr, Check_NGRF, CH_ARRAY | CH_LAST }
|
||||
};
|
||||
|
||||
@@ -74,6 +74,6 @@ static void Load_OBID()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _object_chunk_handlers[] = {
|
||||
{ 'OBID', Save_OBID, Load_OBID, NULL, NULL, CH_ARRAY },
|
||||
{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'OBID', Save_OBID, Load_OBID, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'OBJS', Save_OBJS, Load_OBJS, Ptrs_OBJS, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
+11
-11
@@ -154,11 +154,11 @@ bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
/* When both pointers are NULL, we are just skipping data */
|
||||
if (base_ptr == NULL && chunk->ptr == NULL) continue;
|
||||
/* When both pointers are nullptr, we are just skipping data */
|
||||
if (base_ptr == nullptr && chunk->ptr == nullptr) continue;
|
||||
|
||||
/* Writing to the var: bits 8 to 15 have the VAR type */
|
||||
if (chunk->ptr == NULL) ptr = base_ptr + chunk->offset;
|
||||
if (chunk->ptr == nullptr) ptr = base_ptr + chunk->offset;
|
||||
|
||||
/* Write the data */
|
||||
switch (GetOldChunkVarType(chunk->type)) {
|
||||
@@ -174,7 +174,7 @@ bool LoadChunk(LoadgameState *ls, void *base, const OldChunks *chunks)
|
||||
}
|
||||
|
||||
/* Increase pointer base for arrays when looping */
|
||||
if (chunk->amount > 1 && chunk->ptr != NULL) ptr += CalcOldVarLen(chunk->type);
|
||||
if (chunk->amount > 1 && chunk->ptr != nullptr) ptr += CalcOldVarLen(chunk->type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -259,7 +259,7 @@ static SavegameType DetermineOldSavegameType(FILE *f, char *title, const char *l
|
||||
}
|
||||
}
|
||||
|
||||
if (title != NULL) {
|
||||
if (title != nullptr) {
|
||||
switch (type) {
|
||||
case SGT_TTO: title = strecpy(title, "(TTO) ", last); break;
|
||||
case SGT_TTD: title = strecpy(title, "(TTD) ", last); break;
|
||||
@@ -284,14 +284,14 @@ bool LoadOldSaveGame(const char *file)
|
||||
/* Open file */
|
||||
ls.file = FioFOpenFile(file, "rb", NO_DIRECTORY);
|
||||
|
||||
if (ls.file == NULL) {
|
||||
if (ls.file == nullptr) {
|
||||
DEBUG(oldloader, 0, "Cannot open file '%s'", file);
|
||||
return false;
|
||||
}
|
||||
|
||||
SavegameType type = DetermineOldSavegameType(ls.file, NULL, NULL);
|
||||
SavegameType type = DetermineOldSavegameType(ls.file, nullptr, nullptr);
|
||||
|
||||
LoadOldMainProc *proc = NULL;
|
||||
LoadOldMainProc *proc = nullptr;
|
||||
|
||||
switch (type) {
|
||||
case SGT_TTO: proc = &LoadTTOMain; break;
|
||||
@@ -303,7 +303,7 @@ bool LoadOldSaveGame(const char *file)
|
||||
|
||||
bool game_loaded;
|
||||
try {
|
||||
game_loaded = proc != NULL && proc(&ls);
|
||||
game_loaded = proc != nullptr && proc(&ls);
|
||||
} catch (...) {
|
||||
game_loaded = false;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ bool LoadOldSaveGame(const char *file)
|
||||
return false;
|
||||
}
|
||||
|
||||
_pause_mode = 2;
|
||||
_pause_mode = PM_PAUSED_SAVELOAD;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -323,7 +323,7 @@ void GetOldSaveGameName(const char *file, char *title, const char *last)
|
||||
{
|
||||
FILE *f = FioFOpenFile(file, "rb", NO_DIRECTORY);
|
||||
|
||||
if (f == NULL) {
|
||||
if (f == nullptr) {
|
||||
*title = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ struct OldChunks {
|
||||
uint32 amount; ///< Amount of fields
|
||||
|
||||
void *ptr; ///< Pointer where to save the data (may only be set if offset is 0)
|
||||
uint offset; ///< Offset from basepointer (may only be set if ptr is NULL)
|
||||
uint offset; ///< Offset from basepointer (may only be set if ptr is nullptr)
|
||||
OldChunkProc *proc; ///< Pointer to function that is called with OC_CHUNK
|
||||
};
|
||||
|
||||
@@ -125,12 +125,12 @@ static inline uint32 ReadUint32(LoadgameState *ls)
|
||||
* - OCL_CHUNK: load another proc to load a part of the savegame, 'amount' times
|
||||
* - OCL_ASSERT: to check if we are really at the place we expect to be.. because old savegames are too binary to be sure ;)
|
||||
*/
|
||||
#define OCL_SVAR(type, base, offset) { type, 1, NULL, (uint)cpp_offsetof(base, offset), NULL }
|
||||
#define OCL_VAR(type, amount, pointer) { type, amount, pointer, 0, NULL }
|
||||
#define OCL_END() { OC_END, 0, NULL, 0, NULL }
|
||||
#define OCL_CNULL(type, amount) { OC_NULL | type, amount, NULL, 0, NULL }
|
||||
#define OCL_CCHUNK(type, amount, proc) { OC_CHUNK | type, amount, NULL, 0, proc }
|
||||
#define OCL_ASSERT(type, size) { OC_ASSERT | type, 1, NULL, size, NULL }
|
||||
#define OCL_SVAR(type, base, offset) { type, 1, nullptr, (uint)cpp_offsetof(base, offset), nullptr }
|
||||
#define OCL_VAR(type, amount, pointer) { type, amount, pointer, 0, nullptr }
|
||||
#define OCL_END() { OC_END, 0, nullptr, 0, nullptr }
|
||||
#define OCL_CNULL(type, amount) { OC_NULL | type, amount, nullptr, 0, nullptr }
|
||||
#define OCL_CCHUNK(type, amount, proc) { OC_CHUNK | type, amount, nullptr, 0, proc }
|
||||
#define OCL_ASSERT(type, size) { OC_ASSERT | type, 1, nullptr, size, nullptr }
|
||||
#define OCL_NULL(amount) OCL_CNULL((OldChunkType)0, amount)
|
||||
#define OCL_CHUNK(amount, proc) OCL_CCHUNK((OldChunkType)0, amount, proc)
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "../core/smallvec_type.hpp"
|
||||
#include "saveload_internal.h"
|
||||
#include "oldloader.h"
|
||||
#include <array>
|
||||
|
||||
#include "table/strings.h"
|
||||
#include "../table/engines.h"
|
||||
@@ -178,7 +179,7 @@ void FixOldVehicles()
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if ((size_t)v->next == 0xFFFF) {
|
||||
v->next = NULL;
|
||||
v->next = nullptr;
|
||||
} else {
|
||||
v->next = Vehicle::GetIfValid((size_t)v->next);
|
||||
}
|
||||
@@ -452,7 +453,7 @@ static bool FixTTOEngines()
|
||||
e->preview_company = INVALID_COMPANY;
|
||||
e->preview_asked = (CompanyMask)-1;
|
||||
e->preview_wait = 0;
|
||||
e->name = NULL;
|
||||
e->name = nullptr;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -491,7 +492,7 @@ static inline uint RemapOrderIndex(uint x)
|
||||
return _savegame_type == SGT_TTO ? (x - 0x1AC4) / 2 : (x - 0x1C18) / 2;
|
||||
}
|
||||
|
||||
extern SmallVector<TileIndex, 256> _animated_tiles;
|
||||
extern std::vector<TileIndex> _animated_tiles;
|
||||
extern char *_old_name_array;
|
||||
|
||||
static uint32 _old_town_index;
|
||||
@@ -621,7 +622,7 @@ static const OldChunks order_chunk[] = {
|
||||
|
||||
static bool LoadOldOrder(LoadgameState *ls, int num)
|
||||
{
|
||||
if (!LoadChunk(ls, NULL, order_chunk)) return false;
|
||||
if (!LoadChunk(ls, nullptr, order_chunk)) return false;
|
||||
|
||||
Order *o = new (num) Order();
|
||||
o->AssignOrder(UnpackOldOrder(_old_order));
|
||||
@@ -632,7 +633,7 @@ static bool LoadOldOrder(LoadgameState *ls, int num)
|
||||
/* Relink the orders to each other (in the orders for one vehicle are behind each other,
|
||||
* with an invalid order (OT_NOTHING) as indication that it is the last order */
|
||||
Order *prev = Order::GetIfValid(num - 1);
|
||||
if (prev != NULL) prev->next = o;
|
||||
if (prev != nullptr) prev->next = o;
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -646,12 +647,12 @@ static bool LoadOldAnimTileList(LoadgameState *ls, int num)
|
||||
OCL_END ()
|
||||
};
|
||||
|
||||
if (!LoadChunk(ls, NULL, anim_chunk)) return false;
|
||||
if (!LoadChunk(ls, nullptr, anim_chunk)) return false;
|
||||
|
||||
/* The first zero in the loaded array indicates the end of the list. */
|
||||
for (int i = 0; i < 256; i++) {
|
||||
if (anim_list[i] == 0) break;
|
||||
*_animated_tiles.Append() = anim_list[i];
|
||||
_animated_tiles.push_back(anim_list[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -671,7 +672,7 @@ static bool LoadOldDepot(LoadgameState *ls, int num)
|
||||
if (d->xy != 0) {
|
||||
/* In some cases, there could be depots referencing invalid town. */
|
||||
Town *t = Town::GetIfValid(RemapTownIndex(_old_town_index));
|
||||
if (t == NULL) t = Town::GetRandom();
|
||||
if (t == nullptr) t = Town::GetRandom();
|
||||
d->town = t;
|
||||
} else {
|
||||
delete d;
|
||||
@@ -724,7 +725,7 @@ static const OldChunks station_chunk[] = {
|
||||
OCL_NULL( 4 ), ///< bus/lorry tile
|
||||
OCL_SVAR( OC_TILE, Station, train_station.tile ),
|
||||
OCL_SVAR( OC_TILE, Station, airport.tile ),
|
||||
OCL_SVAR( OC_TILE, Station, dock_tile ),
|
||||
OCL_NULL( 4 ), ///< dock tile
|
||||
OCL_SVAR( OC_FILE_U8 | OC_VAR_U16, Station, train_station.w ),
|
||||
|
||||
OCL_NULL( 1 ), ///< sort-index, no longer in use
|
||||
@@ -876,7 +877,7 @@ static bool LoadOldCompanyYearly(LoadgameState *ls, int num)
|
||||
if (_savegame_type == SGT_TTO && i == 6) {
|
||||
_old_yearly = 0; // property maintenance
|
||||
} else {
|
||||
if (!LoadChunk(ls, NULL, _company_yearly_chunk)) return false;
|
||||
if (!LoadChunk(ls, nullptr, _company_yearly_chunk)) return false;
|
||||
}
|
||||
|
||||
c->yearly_expenses[num][i] = _old_yearly;
|
||||
@@ -1106,8 +1107,8 @@ static bool LoadOldVehicleUnion(LoadgameState *ls, int num)
|
||||
uint temp = ls->total_read;
|
||||
bool res;
|
||||
|
||||
if (v == NULL) {
|
||||
res = LoadChunk(ls, NULL, vehicle_empty_chunk);
|
||||
if (v == nullptr) {
|
||||
res = LoadChunk(ls, nullptr, vehicle_empty_chunk);
|
||||
} else {
|
||||
switch (v->type) {
|
||||
default: SlErrorCorrupt("Invalid vehicle type");
|
||||
@@ -1240,7 +1241,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
uint type = ReadByte(ls);
|
||||
switch (type) {
|
||||
default: return false;
|
||||
case 0x00 /* VEH_INVALID */: v = NULL; break;
|
||||
case 0x00 /* VEH_INVALID */: v = nullptr; break;
|
||||
case 0x25 /* MONORAIL */:
|
||||
case 0x20 /* VEH_TRAIN */: v = new (_current_vehicle_id) Train(); break;
|
||||
case 0x21 /* VEH_ROAD */: v = new (_current_vehicle_id) RoadVehicle(); break;
|
||||
@@ -1251,7 +1252,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
}
|
||||
|
||||
if (!LoadChunk(ls, v, vehicle_chunk)) return false;
|
||||
if (v == NULL) continue;
|
||||
if (v == nullptr) continue;
|
||||
v->refit_cap = v->cargo_cap;
|
||||
|
||||
SpriteID sprite = v->sprite_seq.seq[0].sprite;
|
||||
@@ -1276,7 +1277,8 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
};
|
||||
if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false;
|
||||
v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset
|
||||
Train::From(v)->railtype = type == 0x25 ? 1 : 0; // monorail / rail
|
||||
/* Should be the original values for monorail / rail, can't use RailType constants */
|
||||
Train::From(v)->railtype = static_cast<RailType>(type == 0x25 ? 1 : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1318,7 +1320,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
/* Read the vehicle type and allocate the right vehicle */
|
||||
switch (ReadByte(ls)) {
|
||||
default: SlErrorCorrupt("Invalid vehicle type");
|
||||
case 0x00 /* VEH_INVALID */: v = NULL; break;
|
||||
case 0x00 /* VEH_INVALID */: v = nullptr; break;
|
||||
case 0x10 /* VEH_TRAIN */: v = new (_current_vehicle_id) Train(); break;
|
||||
case 0x11 /* VEH_ROAD */: v = new (_current_vehicle_id) RoadVehicle(); break;
|
||||
case 0x12 /* VEH_SHIP */: v = new (_current_vehicle_id) Ship(); break;
|
||||
@@ -1328,7 +1330,7 @@ bool LoadOldVehicle(LoadgameState *ls, int num)
|
||||
}
|
||||
|
||||
if (!LoadChunk(ls, v, vehicle_chunk)) return false;
|
||||
if (v == NULL) continue;
|
||||
if (v == nullptr) continue;
|
||||
|
||||
_old_vehicle_names[_current_vehicle_id] = RemapOldStringID(_old_string_id);
|
||||
|
||||
@@ -1754,11 +1756,11 @@ bool LoadTTDMain(LoadgameState *ls)
|
||||
_read_ttdpatch_flags = false;
|
||||
|
||||
/* Load the biggest chunk */
|
||||
SmallStackSafeStackAlloc<byte, OLD_MAP_SIZE * 2> map3;
|
||||
_old_map3 = map3.data;
|
||||
_old_vehicle_names = NULL;
|
||||
std::array<byte, OLD_MAP_SIZE * 2> map3;
|
||||
_old_map3 = map3.data();
|
||||
_old_vehicle_names = nullptr;
|
||||
try {
|
||||
if (!LoadChunk(ls, NULL, main_chunk)) {
|
||||
if (!LoadChunk(ls, nullptr, main_chunk)) {
|
||||
DEBUG(oldloader, 0, "Loading failed");
|
||||
free(_old_vehicle_names);
|
||||
return false;
|
||||
@@ -1797,13 +1799,13 @@ bool LoadTTOMain(LoadgameState *ls)
|
||||
|
||||
_read_ttdpatch_flags = false;
|
||||
|
||||
SmallStackSafeStackAlloc<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
|
||||
_old_engines = (Engine *)engines.data;
|
||||
SmallStackSafeStackAlloc<StringID, 800> vehnames;
|
||||
_old_vehicle_names = vehnames.data;
|
||||
std::array<byte, 103 * sizeof(Engine)> engines; // we don't want to call Engine constructor here
|
||||
_old_engines = (Engine *)engines.data();
|
||||
std::array<StringID, 800> vehnames;
|
||||
_old_vehicle_names = vehnames.data();
|
||||
|
||||
/* Load the biggest chunk */
|
||||
if (!LoadChunk(ls, NULL, main_chunk)) {
|
||||
if (!LoadChunk(ls, nullptr, main_chunk)) {
|
||||
DEBUG(oldloader, 0, "Loading failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ static void Load_ORDR()
|
||||
/* The orders were built like this:
|
||||
* While the order is valid, set the previous will get its next pointer set */
|
||||
Order *prev = Order::GetIfValid(order_index - 1);
|
||||
if (prev != NULL) prev->next = o;
|
||||
if (prev != nullptr) prev->next = o;
|
||||
}
|
||||
} else {
|
||||
int index;
|
||||
@@ -306,7 +306,7 @@ static void Ptrs_BKOR()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _order_chunk_handlers[] = {
|
||||
{ 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, NULL, CH_ARRAY},
|
||||
{ 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, NULL, CH_ARRAY},
|
||||
{ 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'BKOR', Save_BKOR, Load_BKOR, Ptrs_BKOR, nullptr, CH_ARRAY},
|
||||
{ 'ORDR', Save_ORDR, Load_ORDR, Ptrs_ORDR, nullptr, CH_ARRAY},
|
||||
{ 'ORDL', Save_ORDL, Load_ORDL, Ptrs_ORDL, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
+104
-106
@@ -26,7 +26,7 @@
|
||||
#include "../stdafx.h"
|
||||
#include "../debug.h"
|
||||
#include "../station_base.h"
|
||||
#include "../thread/thread.h"
|
||||
#include "../thread.h"
|
||||
#include "../town.h"
|
||||
#include "../network/network.h"
|
||||
#include "../window_func.h"
|
||||
@@ -45,6 +45,7 @@
|
||||
#include "../string_func.h"
|
||||
#include "../fios.h"
|
||||
#include "../error.h"
|
||||
#include <atomic>
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
@@ -94,7 +95,7 @@ struct ReadBuffer {
|
||||
* Initialise our variables.
|
||||
* @param reader The filter to actually read data.
|
||||
*/
|
||||
ReadBuffer(LoadFilter *reader) : bufp(NULL), bufe(NULL), reader(reader), read(0)
|
||||
ReadBuffer(LoadFilter *reader) : bufp(nullptr), bufe(nullptr), reader(reader), read(0)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -125,15 +126,22 @@ struct ReadBuffer {
|
||||
|
||||
/** Container for dumping the savegame (quickly) to memory. */
|
||||
struct MemoryDumper {
|
||||
AutoFreeSmallVector<byte *, 16> blocks; ///< Buffer with blocks of allocated memory.
|
||||
byte *buf; ///< Buffer we're going to write to.
|
||||
byte *bufe; ///< End of the buffer we write to.
|
||||
std::vector<byte *> blocks; ///< Buffer with blocks of allocated memory.
|
||||
byte *buf; ///< Buffer we're going to write to.
|
||||
byte *bufe; ///< End of the buffer we write to.
|
||||
|
||||
/** Initialise our variables. */
|
||||
MemoryDumper() : buf(NULL), bufe(NULL)
|
||||
MemoryDumper() : buf(nullptr), bufe(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~MemoryDumper()
|
||||
{
|
||||
for (auto p : this->blocks) {
|
||||
free(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a single byte into the dumper.
|
||||
* @param b The byte to write.
|
||||
@@ -143,7 +151,7 @@ struct MemoryDumper {
|
||||
/* Are we at the end of this chunk? */
|
||||
if (this->buf == this->bufe) {
|
||||
this->buf = CallocT<byte>(MEMORY_CHUNK_SIZE);
|
||||
*this->blocks.Append() = this->buf;
|
||||
this->blocks.push_back(this->buf);
|
||||
this->bufe = this->buf + MEMORY_CHUNK_SIZE;
|
||||
}
|
||||
|
||||
@@ -175,7 +183,7 @@ struct MemoryDumper {
|
||||
*/
|
||||
size_t GetSize() const
|
||||
{
|
||||
return this->blocks.Length() * MEMORY_CHUNK_SIZE - (this->bufe - this->buf);
|
||||
return this->blocks.size() * MEMORY_CHUNK_SIZE - (this->bufe - this->buf);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -239,7 +247,7 @@ extern const ChunkHandler _airport_chunk_handlers[];
|
||||
extern const ChunkHandler _object_chunk_handlers[];
|
||||
extern const ChunkHandler _persistent_storage_chunk_handlers[];
|
||||
|
||||
/** Array of all chunks in a savegame, \c NULL terminated. */
|
||||
/** Array of all chunks in a savegame, \c nullptr terminated. */
|
||||
static const ChunkHandler * const _chunk_handlers[] = {
|
||||
_gamelog_chunk_handlers,
|
||||
_map_chunk_handlers,
|
||||
@@ -274,7 +282,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
||||
_airport_chunk_handlers,
|
||||
_object_chunk_handlers,
|
||||
_persistent_storage_chunk_handlers,
|
||||
NULL,
|
||||
nullptr,
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -282,10 +290,10 @@ static const ChunkHandler * const _chunk_handlers[] = {
|
||||
* @param ch the chunk handler iterator
|
||||
*/
|
||||
#define FOR_ALL_CHUNK_HANDLERS(ch) \
|
||||
for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != NULL; chsc++) \
|
||||
for (const ChunkHandler *ch = *chsc; ch != NULL; ch = (ch->flags & CH_LAST) ? NULL : ch + 1)
|
||||
for (const ChunkHandler * const *chsc = _chunk_handlers; *chsc != nullptr; chsc++) \
|
||||
for (const ChunkHandler *ch = *chsc; ch != nullptr; ch = (ch->flags & CH_LAST) ? nullptr : ch + 1)
|
||||
|
||||
/** Null all pointers (convert index -> NULL) */
|
||||
/** Null all pointers (convert index -> nullptr) */
|
||||
static void SlNullPointers()
|
||||
{
|
||||
_sl.action = SLA_NULL;
|
||||
@@ -298,7 +306,7 @@ static void SlNullPointers()
|
||||
DEBUG(sl, 1, "Nulling pointers");
|
||||
|
||||
FOR_ALL_CHUNK_HANDLERS(ch) {
|
||||
if (ch->ptrs_proc != NULL) {
|
||||
if (ch->ptrs_proc != nullptr) {
|
||||
DEBUG(sl, 2, "Nulling pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
||||
ch->ptrs_proc();
|
||||
}
|
||||
@@ -323,14 +331,14 @@ void NORETURN SlError(StringID string, const char *extra_msg)
|
||||
if (_sl.action == SLA_LOAD_CHECK) {
|
||||
_load_check_data.error = string;
|
||||
free(_load_check_data.error_data);
|
||||
_load_check_data.error_data = (extra_msg == NULL) ? NULL : stredup(extra_msg);
|
||||
_load_check_data.error_data = (extra_msg == nullptr) ? nullptr : stredup(extra_msg);
|
||||
} else {
|
||||
_sl.error_str = string;
|
||||
free(_sl.extra_msg);
|
||||
_sl.extra_msg = (extra_msg == NULL) ? NULL : stredup(extra_msg);
|
||||
_sl.extra_msg = (extra_msg == nullptr) ? nullptr : stredup(extra_msg);
|
||||
}
|
||||
|
||||
/* We have to NULL all pointers here; we might be in a state where
|
||||
/* We have to nullptr all pointers here; we might be in a state where
|
||||
* the pointers are actually filled with indices, which means that
|
||||
* when we access them during cleaning the pool dereferences of
|
||||
* those indices will be made with segmentation faults as result. */
|
||||
@@ -370,9 +378,9 @@ void NORETURN SlErrorCorruptFmt(const char *format, ...)
|
||||
}
|
||||
|
||||
|
||||
typedef void (*AsyncSaveFinishProc)(); ///< Callback for when the savegame loading is finished.
|
||||
static AsyncSaveFinishProc _async_save_finish = NULL; ///< Callback to call when the savegame loading is finished.
|
||||
static ThreadObject *_save_thread; ///< The thread we're using to compress and write a savegame
|
||||
typedef void (*AsyncSaveFinishProc)(); ///< Callback for when the savegame loading is finished.
|
||||
static std::atomic<AsyncSaveFinishProc> _async_save_finish; ///< Callback to call when the savegame loading is finished.
|
||||
static std::thread _save_thread; ///< The thread we're using to compress and write a savegame
|
||||
|
||||
/**
|
||||
* Called by save thread to tell we finished saving.
|
||||
@@ -381,9 +389,9 @@ static ThreadObject *_save_thread; ///< The thread we're usin
|
||||
static void SetAsyncSaveFinish(AsyncSaveFinishProc proc)
|
||||
{
|
||||
if (_exit_game) return;
|
||||
while (_async_save_finish != NULL) CSleep(10);
|
||||
while (_async_save_finish.load(std::memory_order_acquire) != nullptr) CSleep(10);
|
||||
|
||||
_async_save_finish = proc;
|
||||
_async_save_finish.store(proc, std::memory_order_release);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,16 +399,13 @@ static void SetAsyncSaveFinish(AsyncSaveFinishProc proc)
|
||||
*/
|
||||
void ProcessAsyncSaveFinish()
|
||||
{
|
||||
if (_async_save_finish == NULL) return;
|
||||
AsyncSaveFinishProc proc = _async_save_finish.exchange(nullptr, std::memory_order_acq_rel);
|
||||
if (proc == nullptr) return;
|
||||
|
||||
_async_save_finish();
|
||||
proc();
|
||||
|
||||
_async_save_finish = NULL;
|
||||
|
||||
if (_save_thread != NULL) {
|
||||
_save_thread->Join();
|
||||
delete _save_thread;
|
||||
_save_thread = NULL;
|
||||
if (_save_thread.joinable()) {
|
||||
_save_thread.join();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,7 +863,7 @@ static void SlSaveLoadConv(void *ptr, VarType conv)
|
||||
*/
|
||||
static inline size_t SlCalcNetStringLen(const char *ptr, size_t length)
|
||||
{
|
||||
if (ptr == NULL) return 0;
|
||||
if (ptr == nullptr) return 0;
|
||||
return min(strlen(ptr), length - 1);
|
||||
}
|
||||
|
||||
@@ -943,7 +948,7 @@ static void SlString(void *ptr, size_t length, VarType conv)
|
||||
case SLE_VAR_STRQ: // Malloc'd string, free previous incarnation, and allocate
|
||||
free(*(char **)ptr);
|
||||
if (len == 0) {
|
||||
*(char **)ptr = NULL;
|
||||
*(char **)ptr = nullptr;
|
||||
return;
|
||||
} else {
|
||||
*(char **)ptr = MallocT<char>(len + 1); // terminating '\0'
|
||||
@@ -1038,7 +1043,7 @@ void SlArray(void *array, size_t length, VarType conv)
|
||||
* Pointers cannot be saved to a savegame, so this functions gets
|
||||
* the index of the item, and if not available, it hussles with
|
||||
* pointers (looks really bad :()
|
||||
* Remember that a NULL item has value 0, and all
|
||||
* Remember that a nullptr item has value 0, and all
|
||||
* indices have +1, so vehicle 0 is saved as index 1.
|
||||
* @param obj The object that we want to get the index of
|
||||
* @param rt SLRefType type of the object the index is being sought of
|
||||
@@ -1048,7 +1053,7 @@ static size_t ReferenceToInt(const void *obj, SLRefType rt)
|
||||
{
|
||||
assert(_sl.action == SLA_SAVE);
|
||||
|
||||
if (obj == NULL) return 0;
|
||||
if (obj == nullptr) return 0;
|
||||
|
||||
switch (rt) {
|
||||
case REF_VEHICLE_OLD: // Old vehicles we save as new ones
|
||||
@@ -1071,7 +1076,7 @@ static size_t ReferenceToInt(const void *obj, SLRefType rt)
|
||||
* Pointers cannot be loaded from a savegame, so this function
|
||||
* gets the index from the savegame and returns the appropriate
|
||||
* pointer from the already loaded base.
|
||||
* Remember that an index of 0 is a NULL pointer so all indices
|
||||
* Remember that an index of 0 is a nullptr pointer so all indices
|
||||
* are +1 so vehicle 0 is saved as 1.
|
||||
* @param index The index that is being converted to a pointer
|
||||
* @param rt SLRefType type of the object the pointer is sought of
|
||||
@@ -1089,8 +1094,8 @@ static void *IntToReference(size_t index, SLRefType rt)
|
||||
rt = REF_VEHICLE;
|
||||
}
|
||||
|
||||
/* No need to look up NULL pointers, just return immediately */
|
||||
if (index == (rt == REF_VEHICLE_OLD ? 0xFFFF : 0)) return NULL;
|
||||
/* No need to look up nullptr pointers, just return immediately */
|
||||
if (index == (rt == REF_VEHICLE_OLD ? 0xFFFF : 0)) return nullptr;
|
||||
|
||||
/* Correct index. Old vehicles were saved differently:
|
||||
* invalid vehicle was 0xFFFF, now we use 0x0000 for everything invalid. */
|
||||
@@ -1104,7 +1109,7 @@ static void *IntToReference(size_t index, SLRefType rt)
|
||||
case REF_ORDER:
|
||||
if (Order::IsValidID(index)) return Order::Get(index);
|
||||
/* in old versions, invalid order was used to mark end of order list */
|
||||
if (IsSavegameVersionBefore(SLV_5, 2)) return NULL;
|
||||
if (IsSavegameVersionBefore(SLV_5, 2)) return nullptr;
|
||||
SlErrorCorrupt("Referencing invalid Order");
|
||||
|
||||
case REF_VEHICLE_OLD:
|
||||
@@ -1494,7 +1499,7 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
*(void **)ptr = IntToReference(*(size_t *)ptr, (SLRefType)conv);
|
||||
break;
|
||||
case SLA_NULL:
|
||||
*(void **)ptr = NULL;
|
||||
*(void **)ptr = nullptr;
|
||||
break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
@@ -1508,7 +1513,7 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
break;
|
||||
|
||||
/* SL_WRITEBYTE writes a value to the savegame to identify the type of an object.
|
||||
* When loading, the value is read explictly with SlReadByte() to determine which
|
||||
* When loading, the value is read explicitly with SlReadByte() to determine which
|
||||
* object description to use. */
|
||||
case SL_WRITEBYTE:
|
||||
switch (_sl.action) {
|
||||
@@ -1560,7 +1565,7 @@ void SlObject(void *object, const SaveLoad *sld)
|
||||
*/
|
||||
void SlGlobList(const SaveLoadGlobVarList *sldg)
|
||||
{
|
||||
SlObject(NULL, (const SaveLoad*)sldg);
|
||||
SlObject(nullptr, (const SaveLoad*)sldg);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1632,7 +1637,7 @@ static void SlLoadChunk(const ChunkHandler *ch)
|
||||
|
||||
/**
|
||||
* Load a chunk of data for checking savegames.
|
||||
* If the chunkhandler is NULL, the chunk is skipped.
|
||||
* If the chunkhandler is nullptr, the chunk is skipped.
|
||||
* @param ch The chunkhandler that will be used for the operation
|
||||
*/
|
||||
static void SlLoadCheckChunk(const ChunkHandler *ch)
|
||||
@@ -1703,7 +1708,7 @@ static inline void SlStubSaveProc2(void *arg)
|
||||
*/
|
||||
static void SlStubSaveProc()
|
||||
{
|
||||
SlAutolength(SlStubSaveProc2, NULL);
|
||||
SlAutolength(SlStubSaveProc2, nullptr);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1716,7 +1721,7 @@ static void SlSaveChunk(const ChunkHandler *ch)
|
||||
ChunkSaveLoadProc *proc = ch->save_proc;
|
||||
|
||||
/* Don't save any chunk information if there is no save handler. */
|
||||
if (proc == NULL) return;
|
||||
if (proc == nullptr) return;
|
||||
|
||||
SlWriteUint32(ch->id);
|
||||
DEBUG(sl, 2, "Saving chunk %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
||||
@@ -1768,7 +1773,7 @@ static void SlSaveChunks()
|
||||
static const ChunkHandler *SlFindChunkHandler(uint32 id)
|
||||
{
|
||||
FOR_ALL_CHUNK_HANDLERS(ch) if (ch->id == id) return ch;
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/** Load all chunks */
|
||||
@@ -1781,7 +1786,7 @@ static void SlLoadChunks()
|
||||
DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
|
||||
|
||||
ch = SlFindChunkHandler(id);
|
||||
if (ch == NULL) SlErrorCorrupt("Unknown chunk type");
|
||||
if (ch == nullptr) SlErrorCorrupt("Unknown chunk type");
|
||||
SlLoadChunk(ch);
|
||||
}
|
||||
}
|
||||
@@ -1796,7 +1801,7 @@ static void SlLoadCheckChunks()
|
||||
DEBUG(sl, 2, "Loading chunk %c%c%c%c", id >> 24, id >> 16, id >> 8, id);
|
||||
|
||||
ch = SlFindChunkHandler(id);
|
||||
if (ch == NULL) SlErrorCorrupt("Unknown chunk type");
|
||||
if (ch == nullptr) SlErrorCorrupt("Unknown chunk type");
|
||||
SlLoadCheckChunk(ch);
|
||||
}
|
||||
}
|
||||
@@ -1809,7 +1814,7 @@ static void SlFixPointers()
|
||||
DEBUG(sl, 1, "Fixing pointers");
|
||||
|
||||
FOR_ALL_CHUNK_HANDLERS(ch) {
|
||||
if (ch->ptrs_proc != NULL) {
|
||||
if (ch->ptrs_proc != nullptr) {
|
||||
DEBUG(sl, 2, "Fixing pointers for %c%c%c%c", ch->id >> 24, ch->id >> 16, ch->id >> 8, ch->id);
|
||||
ch->ptrs_proc();
|
||||
}
|
||||
@@ -1830,29 +1835,29 @@ struct FileReader : LoadFilter {
|
||||
* Create the file reader, so it reads from a specific file.
|
||||
* @param file The file to read from.
|
||||
*/
|
||||
FileReader(FILE *file) : LoadFilter(NULL), file(file), begin(ftell(file))
|
||||
FileReader(FILE *file) : LoadFilter(nullptr), file(file), begin(ftell(file))
|
||||
{
|
||||
}
|
||||
|
||||
/** Make sure everything is cleaned up. */
|
||||
~FileReader()
|
||||
{
|
||||
if (this->file != NULL) fclose(this->file);
|
||||
this->file = NULL;
|
||||
if (this->file != nullptr) fclose(this->file);
|
||||
this->file = nullptr;
|
||||
|
||||
/* Make sure we don't double free. */
|
||||
_sl.sf = NULL;
|
||||
_sl.sf = nullptr;
|
||||
}
|
||||
|
||||
/* virtual */ size_t Read(byte *buf, size_t size)
|
||||
size_t Read(byte *buf, size_t size) override
|
||||
{
|
||||
/* We're in the process of shutting down, i.e. in "failure" mode. */
|
||||
if (this->file == NULL) return 0;
|
||||
if (this->file == nullptr) return 0;
|
||||
|
||||
return fread(buf, 1, size, this->file);
|
||||
}
|
||||
|
||||
/* virtual */ void Reset()
|
||||
void Reset() override
|
||||
{
|
||||
clearerr(this->file);
|
||||
if (fseek(this->file, this->begin, SEEK_SET)) {
|
||||
@@ -1869,7 +1874,7 @@ struct FileWriter : SaveFilter {
|
||||
* Create the file writer, so it writes to a specific file.
|
||||
* @param file The file to write to.
|
||||
*/
|
||||
FileWriter(FILE *file) : SaveFilter(NULL), file(file)
|
||||
FileWriter(FILE *file) : SaveFilter(nullptr), file(file)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1879,21 +1884,21 @@ struct FileWriter : SaveFilter {
|
||||
this->Finish();
|
||||
|
||||
/* Make sure we don't double free. */
|
||||
_sl.sf = NULL;
|
||||
_sl.sf = nullptr;
|
||||
}
|
||||
|
||||
/* virtual */ void Write(byte *buf, size_t size)
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
/* We're in the process of shutting down, i.e. in "failure" mode. */
|
||||
if (this->file == NULL) return;
|
||||
if (this->file == nullptr) return;
|
||||
|
||||
if (fwrite(buf, 1, size, this->file) != size) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE);
|
||||
}
|
||||
|
||||
/* virtual */ void Finish()
|
||||
void Finish() override
|
||||
{
|
||||
if (this->file != NULL) fclose(this->file);
|
||||
this->file = NULL;
|
||||
if (this->file != nullptr) fclose(this->file);
|
||||
this->file = nullptr;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1918,7 +1923,7 @@ struct LZOLoadFilter : LoadFilter {
|
||||
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize decompressor");
|
||||
}
|
||||
|
||||
/* virtual */ size_t Read(byte *buf, size_t ssize)
|
||||
size_t Read(byte *buf, size_t ssize) override
|
||||
{
|
||||
assert(ssize >= LZO_BUFFER_SIZE);
|
||||
|
||||
@@ -1948,7 +1953,7 @@ struct LZOLoadFilter : LoadFilter {
|
||||
if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlErrorCorrupt("Bad checksum");
|
||||
|
||||
/* Decompress */
|
||||
int ret = lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, NULL);
|
||||
int ret = lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, nullptr);
|
||||
if (ret != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||
return len;
|
||||
}
|
||||
@@ -1966,7 +1971,7 @@ struct LZOSaveFilter : SaveFilter {
|
||||
if (lzo_init() != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
|
||||
}
|
||||
|
||||
/* virtual */ void Write(byte *buf, size_t size)
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
const lzo_bytep in = buf;
|
||||
/* Buffer size is from the LZO docs plus the chunk header size. */
|
||||
@@ -2005,7 +2010,7 @@ struct NoCompLoadFilter : LoadFilter {
|
||||
{
|
||||
}
|
||||
|
||||
/* virtual */ size_t Read(byte *buf, size_t size)
|
||||
size_t Read(byte *buf, size_t size) override
|
||||
{
|
||||
return this->chain->Read(buf, size);
|
||||
}
|
||||
@@ -2022,7 +2027,7 @@ struct NoCompSaveFilter : SaveFilter {
|
||||
{
|
||||
}
|
||||
|
||||
/* virtual */ void Write(byte *buf, size_t size)
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
this->chain->Write(buf, size);
|
||||
}
|
||||
@@ -2056,7 +2061,7 @@ struct ZlibLoadFilter : LoadFilter {
|
||||
inflateEnd(&this->z);
|
||||
}
|
||||
|
||||
/* virtual */ size_t Read(byte *buf, size_t size)
|
||||
size_t Read(byte *buf, size_t size) override
|
||||
{
|
||||
this->z.next_out = buf;
|
||||
this->z.avail_out = (uint)size;
|
||||
@@ -2135,14 +2140,14 @@ struct ZlibSaveFilter : SaveFilter {
|
||||
} while (this->z.avail_in || !this->z.avail_out);
|
||||
}
|
||||
|
||||
/* virtual */ void Write(byte *buf, size_t size)
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
this->WriteLoop(buf, size, 0);
|
||||
}
|
||||
|
||||
/* virtual */ void Finish()
|
||||
void Finish() override
|
||||
{
|
||||
this->WriteLoop(NULL, 0, Z_FINISH);
|
||||
this->WriteLoop(nullptr, 0, Z_FINISH);
|
||||
this->chain->Finish();
|
||||
}
|
||||
};
|
||||
@@ -2153,7 +2158,7 @@ struct ZlibSaveFilter : SaveFilter {
|
||||
********** START OF LZMA CODE **************
|
||||
********************************************/
|
||||
|
||||
#if defined(WITH_LZMA)
|
||||
#if defined(WITH_LIBLZMA)
|
||||
#include <lzma.h>
|
||||
|
||||
/**
|
||||
@@ -2185,7 +2190,7 @@ struct LZMALoadFilter : LoadFilter {
|
||||
lzma_end(&this->lzma);
|
||||
}
|
||||
|
||||
/* virtual */ size_t Read(byte *buf, size_t size)
|
||||
size_t Read(byte *buf, size_t size) override
|
||||
{
|
||||
this->lzma.next_out = buf;
|
||||
this->lzma.avail_out = size;
|
||||
@@ -2254,19 +2259,19 @@ struct LZMASaveFilter : SaveFilter {
|
||||
} while (this->lzma.avail_in || !this->lzma.avail_out);
|
||||
}
|
||||
|
||||
/* virtual */ void Write(byte *buf, size_t size)
|
||||
void Write(byte *buf, size_t size) override
|
||||
{
|
||||
this->WriteLoop(buf, size, LZMA_RUN);
|
||||
}
|
||||
|
||||
/* virtual */ void Finish()
|
||||
void Finish() override
|
||||
{
|
||||
this->WriteLoop(NULL, 0, LZMA_FINISH);
|
||||
this->WriteLoop(nullptr, 0, LZMA_FINISH);
|
||||
this->chain->Finish();
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* WITH_LZMA */
|
||||
#endif /* WITH_LIBLZMA */
|
||||
|
||||
/*******************************************
|
||||
************* END OF CODE *****************
|
||||
@@ -2291,7 +2296,7 @@ static const SaveLoadFormat _saveload_formats[] = {
|
||||
/* Roughly 75% larger than zlib level 6 at only ~7% of the CPU usage. */
|
||||
{"lzo", TO_BE32X('OTTD'), CreateLoadFilter<LZOLoadFilter>, CreateSaveFilter<LZOSaveFilter>, 0, 0, 0},
|
||||
#else
|
||||
{"lzo", TO_BE32X('OTTD'), NULL, NULL, 0, 0, 0},
|
||||
{"lzo", TO_BE32X('OTTD'), nullptr, nullptr, 0, 0, 0},
|
||||
#endif
|
||||
/* Roughly 5 times larger at only 1% of the CPU usage over zlib level 6. */
|
||||
{"none", TO_BE32X('OTTN'), CreateLoadFilter<NoCompLoadFilter>, CreateSaveFilter<NoCompSaveFilter>, 0, 0, 0},
|
||||
@@ -2301,9 +2306,9 @@ static const SaveLoadFormat _saveload_formats[] = {
|
||||
* 1 is "only" 3 times as fast. Level 0 results in uncompressed savegames at about 8 times the cost of "none". */
|
||||
{"zlib", TO_BE32X('OTTZ'), CreateLoadFilter<ZlibLoadFilter>, CreateSaveFilter<ZlibSaveFilter>, 0, 6, 9},
|
||||
#else
|
||||
{"zlib", TO_BE32X('OTTZ'), NULL, NULL, 0, 0, 0},
|
||||
{"zlib", TO_BE32X('OTTZ'), nullptr, nullptr, 0, 0, 0},
|
||||
#endif
|
||||
#if defined(WITH_LZMA)
|
||||
#if defined(WITH_LIBLZMA)
|
||||
/* Level 2 compression is speed wise as fast as zlib level 6 compression (old default), but results in ~10% smaller saves.
|
||||
* Higher compression levels are possible, and might improve savegame size by up to 25%, but are also up to 10 times slower.
|
||||
* The next significant reduction in file size is at level 4, but that is already 4 times slower. Level 3 is primarily 50%
|
||||
@@ -2311,14 +2316,14 @@ static const SaveLoadFormat _saveload_formats[] = {
|
||||
* It's OTTX and not e.g. OTTL because liblzma is part of xz-utils and .tar.xz is preferred over .tar.lzma. */
|
||||
{"lzma", TO_BE32X('OTTX'), CreateLoadFilter<LZMALoadFilter>, CreateSaveFilter<LZMASaveFilter>, 0, 2, 9},
|
||||
#else
|
||||
{"lzma", TO_BE32X('OTTX'), NULL, NULL, 0, 0, 0},
|
||||
{"lzma", TO_BE32X('OTTX'), nullptr, nullptr, 0, 0, 0},
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the savegameformat of the game. Whether it was created with ZLIB compression
|
||||
* uncompressed, or another type
|
||||
* @param s Name of the savegame format. If NULL it picks the first available one
|
||||
* @param s Name of the savegame format. If nullptr it picks the first available one
|
||||
* @param compression_level Output for telling what compression level we want.
|
||||
* @return Pointer to SaveLoadFormat struct giving all characteristics of this type of savegame
|
||||
*/
|
||||
@@ -2332,12 +2337,12 @@ static const SaveLoadFormat *GetSavegameFormat(char *s, byte *compression_level)
|
||||
if (!StrEmpty(s)) {
|
||||
/* Get the ":..." of the compression level out of the way */
|
||||
char *complevel = strrchr(s, ':');
|
||||
if (complevel != NULL) *complevel = '\0';
|
||||
if (complevel != nullptr) *complevel = '\0';
|
||||
|
||||
for (const SaveLoadFormat *slf = &_saveload_formats[0]; slf != endof(_saveload_formats); slf++) {
|
||||
if (slf->init_write != NULL && strcmp(s, slf->name) == 0) {
|
||||
if (slf->init_write != nullptr && strcmp(s, slf->name) == 0) {
|
||||
*compression_level = slf->default_compression;
|
||||
if (complevel != NULL) {
|
||||
if (complevel != nullptr) {
|
||||
/* There is a compression level in the string.
|
||||
* First restore the : we removed to do proper name matching,
|
||||
* then move the the begin of the actual version. */
|
||||
@@ -2363,7 +2368,7 @@ static const SaveLoadFormat *GetSavegameFormat(char *s, byte *compression_level)
|
||||
ShowErrorMessage(STR_CONFIG_ERROR, STR_CONFIG_ERROR_INVALID_SAVEGAME_COMPRESSION_ALGORITHM, WL_CRITICAL);
|
||||
|
||||
/* Restore the string by adding the : back */
|
||||
if (complevel != NULL) *complevel = ':';
|
||||
if (complevel != nullptr) *complevel = ':';
|
||||
}
|
||||
*compression_level = def->default_compression;
|
||||
return def;
|
||||
@@ -2380,16 +2385,16 @@ extern bool LoadOldSaveGame(const char *file);
|
||||
static inline void ClearSaveLoadState()
|
||||
{
|
||||
delete _sl.dumper;
|
||||
_sl.dumper = NULL;
|
||||
_sl.dumper = nullptr;
|
||||
|
||||
delete _sl.sf;
|
||||
_sl.sf = NULL;
|
||||
_sl.sf = nullptr;
|
||||
|
||||
delete _sl.reader;
|
||||
_sl.reader = NULL;
|
||||
_sl.reader = nullptr;
|
||||
|
||||
delete _sl.lf;
|
||||
_sl.lf = NULL;
|
||||
_sl.lf = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2486,19 +2491,11 @@ static SaveOrLoadResult SaveFileToDisk(bool threaded)
|
||||
}
|
||||
}
|
||||
|
||||
/** Thread run function for saving the file to disk. */
|
||||
static void SaveFileToDiskThread(void *arg)
|
||||
{
|
||||
SaveFileToDisk(true);
|
||||
}
|
||||
|
||||
void WaitTillSaved()
|
||||
{
|
||||
if (_save_thread == NULL) return;
|
||||
if (!_save_thread.joinable()) return;
|
||||
|
||||
_save_thread->Join();
|
||||
delete _save_thread;
|
||||
_save_thread = NULL;
|
||||
_save_thread.join();
|
||||
|
||||
/* Make sure every other state is handled properly as well. */
|
||||
ProcessAsyncSaveFinish();
|
||||
@@ -2525,7 +2522,8 @@ static SaveOrLoadResult DoSave(SaveFilter *writer, bool threaded)
|
||||
SlSaveChunks();
|
||||
|
||||
SaveFileStart();
|
||||
if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread, "ottd:savegame")) {
|
||||
|
||||
if (!threaded || !StartNewThread(&_save_thread, "ottd:savegame", &SaveFileToDisk, true)) {
|
||||
if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
|
||||
|
||||
SaveOrLoadResult result = SaveFileToDisk(false);
|
||||
@@ -2616,7 +2614,7 @@ static SaveOrLoadResult DoLoad(LoadFilter *reader, bool load_check)
|
||||
}
|
||||
|
||||
/* loader for this savegame type is not implemented? */
|
||||
if (fmt->init_load == NULL) {
|
||||
if (fmt->init_load == nullptr) {
|
||||
char err_str[64];
|
||||
seprintf(err_str, lastof(err_str), "Loader for '%s' is not available.", fmt->name);
|
||||
SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, err_str);
|
||||
@@ -2771,11 +2769,11 @@ SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, Detaile
|
||||
FILE *fh = (fop == SLO_SAVE) ? FioFOpenFile(filename, "wb", sb) : FioFOpenFile(filename, "rb", sb);
|
||||
|
||||
/* Make it a little easier to load savegames from the console */
|
||||
if (fh == NULL && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
|
||||
if (fh == NULL && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
|
||||
if (fh == NULL && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
|
||||
if (fh == nullptr && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", SAVE_DIR);
|
||||
if (fh == nullptr && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", BASE_DIR);
|
||||
if (fh == nullptr && fop != SLO_SAVE) fh = FioFOpenFile(filename, "rb", SCENARIO_DIR);
|
||||
|
||||
if (fh == NULL) {
|
||||
if (fh == nullptr) {
|
||||
SlError(fop == SLO_SAVE ? STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE : STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||
}
|
||||
|
||||
|
||||
+24
-12
@@ -266,8 +266,8 @@ enum SaveLoadVersion : uint16 {
|
||||
SLV_185, ///< 185 25620 Storybooks
|
||||
SLV_186, ///< 186 25833 Objects storage
|
||||
SLV_187, ///< 187 25899 Linkgraph - restricted flows
|
||||
SLV_188, ///< 188 26169 FS#5831 Unify RV travel time
|
||||
SLV_189, ///< 189 26450 Heirarchical vehicle subgroups
|
||||
SLV_188, ///< 188 26169 v1.4 FS#5831 Unify RV travel time
|
||||
SLV_189, ///< 189 26450 Hierarchical vehicle subgroups
|
||||
|
||||
SLV_190, ///< 190 26547 Separate order travel and wait times
|
||||
SLV_191, ///< 191 26636 FS#6026 Fix disaster vehicle storage (No bump)
|
||||
@@ -283,14 +283,26 @@ enum SaveLoadVersion : uint16 {
|
||||
SLV_EXTEND_CARGOTYPES, ///< 199 PR#6802 Extend cargotypes to 64
|
||||
|
||||
SLV_EXTEND_RAILTYPES, ///< 200 PR#6805 Extend railtypes to 64, adding uint16 to map array.
|
||||
SLV_EXTEND_PERSISTENT_STORAGE, ///< 201 PR#6885 Extend NewGRF persistant storages.
|
||||
SLV_EXTEND_PERSISTENT_STORAGE, ///< 201 PR#6885 Extend NewGRF persistent storages.
|
||||
SLV_EXTEND_INDUSTRY_CARGO_SLOTS, ///< 202 PR#6867 Increase industry cargo slots to 16 in, 16 out
|
||||
SLV_SHIP_PATH_CACHE, ///< 203 PR#7072 Add path cache for ships
|
||||
SLV_SHIP_ROTATION, ///< 204 PR#7065 Add extra rotation stages for ships.
|
||||
|
||||
SLV_GROUP_LIVERIES, ///< 205 PR#7108 Livery storage change and group liveries.
|
||||
SLV_SHIPS_STOP_IN_LOCKS, ///< 206 PR#7150 Ship/lock movement changes.
|
||||
SLV_FIX_CARGO_MONITOR, ///< 207 PR#7175 Cargo monitor data packing fix to support 64 cargotypes.
|
||||
SLV_FIX_CARGO_MONITOR, ///< 207 PR#7175 v1.9 Cargo monitor data packing fix to support 64 cargotypes.
|
||||
SLV_TOWN_CARGOGEN, ///< 208 PR#6965 New algorithms for town building cargo generation.
|
||||
SLV_SHIP_CURVE_PENALTY, ///< 209 PR#7289 Configurable ship curve penalties.
|
||||
|
||||
SLV_SERVE_NEUTRAL_INDUSTRIES, ///< 210 PR#7234 Company stations can serve industries with attached neutral stations.
|
||||
SLV_ROADVEH_PATH_CACHE, ///< 211 PR#7261 Add path cache for road vehicles.
|
||||
SLV_REMOVE_OPF, ///< 212 PR#7245 Remove OPF.
|
||||
SLV_TREES_WATER_CLASS, ///< 213 PR#7405 WaterClass update for tree tiles.
|
||||
SLV_ROAD_TYPES, ///< 214 PR#6811 NewGRF road types.
|
||||
|
||||
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.
|
||||
|
||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||
};
|
||||
@@ -634,11 +646,11 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
/** Translate values ingame to different values in the savegame and vv. */
|
||||
#define SLE_WRITEBYTE(base, variable) SLE_GENERAL(SL_WRITEBYTE, base, variable, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION)
|
||||
|
||||
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, NULL, 0}
|
||||
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, NULL, 0}
|
||||
#define SLE_VEH_INCLUDE() {false, SL_VEH_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0}
|
||||
#define SLE_ST_INCLUDE() {false, SL_ST_INCLUDE, 0, 0, SL_MIN_VERSION, SL_MAX_VERSION, nullptr, 0}
|
||||
|
||||
/** End marker of a struct/class save or load. */
|
||||
#define SLE_END() {false, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, NULL, 0}
|
||||
#define SLE_END() {false, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, nullptr, 0}
|
||||
|
||||
/**
|
||||
* Storage of global simple variables, references (pointers), and arrays.
|
||||
@@ -739,10 +751,10 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
* @param from First savegame version that has the empty space.
|
||||
* @param to Last savegame version that has the empty space.
|
||||
*/
|
||||
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)NULL}
|
||||
#define SLEG_CONDNULL(length, from, to) {true, SL_ARR, SLE_FILE_U8 | SLE_VAR_NULL | SLF_NOT_IN_CONFIG, length, from, to, (void*)nullptr}
|
||||
|
||||
/** End marker of global variables save or load. */
|
||||
#define SLEG_END() {true, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, NULL, 0}
|
||||
#define SLEG_END() {true, SL_END, 0, 0, SL_MIN_VERSION, SL_MIN_VERSION, nullptr, 0}
|
||||
|
||||
/**
|
||||
* Checks whether the savegame is below \a major.\a minor.
|
||||
@@ -806,13 +818,13 @@ static inline bool IsNumericType(VarType conv)
|
||||
|
||||
/**
|
||||
* Get the address of the variable. Which one to pick depends on the object
|
||||
* pointer. If it is NULL we are dealing with global variables so the address
|
||||
* pointer. If it is nullptr we are dealing with global variables so the address
|
||||
* is taken. If non-null only the offset is stored in the union and we need
|
||||
* to add this to the address of the object
|
||||
*/
|
||||
static inline void *GetVariableAddress(const void *object, const SaveLoad *sld)
|
||||
{
|
||||
return const_cast<byte *>((const byte*)(sld->global ? NULL : object) + (ptrdiff_t)sld->address);
|
||||
return const_cast<byte *>((const byte*)(sld->global ? nullptr : object) + (ptrdiff_t)sld->address);
|
||||
}
|
||||
|
||||
int64 ReadValue(const void *ptr, VarType conv);
|
||||
@@ -834,7 +846,7 @@ void SlGlobList(const SaveLoadGlobVarList *sldg);
|
||||
void SlArray(void *array, size_t length, VarType conv);
|
||||
void SlObject(void *object, const SaveLoad *sld);
|
||||
bool SlObjectMember(void *object, const SaveLoad *sld);
|
||||
void NORETURN SlError(StringID string, const char *extra_msg = NULL);
|
||||
void NORETURN SlError(StringID string, const char *extra_msg = nullptr);
|
||||
void NORETURN SlErrorCorrupt(const char *msg);
|
||||
void NORETURN SlErrorCorruptFmt(const char *format, ...);
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ struct SaveFilter {
|
||||
*/
|
||||
virtual void Finish()
|
||||
{
|
||||
if (this->chain != NULL) this->chain->Finish();
|
||||
if (this->chain != nullptr) this->chain->Finish();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ void CopyTempEngineData();
|
||||
|
||||
extern int32 _saved_scrollpos_x;
|
||||
extern int32 _saved_scrollpos_y;
|
||||
extern ZoomLevelByte _saved_scrollpos_zoom;
|
||||
extern ZoomLevel _saved_scrollpos_zoom;
|
||||
|
||||
extern SavegameType _savegame_type;
|
||||
extern uint32 _ttdp_version;
|
||||
|
||||
@@ -68,5 +68,5 @@ static void Load_SIGN()
|
||||
|
||||
/** Chunk handlers related to signs. */
|
||||
extern const ChunkHandler _sign_chunk_handlers[] = {
|
||||
{ 'SIGN', Save_SIGN, Load_SIGN, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'SIGN', Save_SIGN, Load_SIGN, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
+19
-13
@@ -47,7 +47,7 @@ void MoveBuoysToWaypoints()
|
||||
VehicleType vt = ol->GetFirstSharedVehicle()->type;
|
||||
if (vt != VEH_SHIP && vt != VEH_TRAIN) continue;
|
||||
|
||||
for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
|
||||
for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o);
|
||||
}
|
||||
|
||||
Vehicle *v;
|
||||
@@ -68,7 +68,7 @@ void MoveBuoysToWaypoints()
|
||||
Town *town = st->town;
|
||||
StringID string_id = st->string_id;
|
||||
char *name = st->name;
|
||||
st->name = NULL;
|
||||
st->name = nullptr;
|
||||
Date build_date = st->build_date;
|
||||
/* TTDPatch could use "buoys with rail station" for rail waypoints */
|
||||
bool train = st->train_station.tile != INVALID_TILE;
|
||||
@@ -116,13 +116,13 @@ void AfterLoadStations()
|
||||
for (uint i = 0; i < st->num_specs; i++) {
|
||||
if (st->speclist[i].grfid == 0) continue;
|
||||
|
||||
st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx, NULL);
|
||||
st->speclist[i].spec = StationClass::GetByGrf(st->speclist[i].grfid, st->speclist[i].localidx, nullptr);
|
||||
}
|
||||
|
||||
if (Station::IsExpected(st)) {
|
||||
Station *sta = Station::From(st);
|
||||
for (const RoadStop *rs = sta->bus_stops; rs != NULL; rs = rs->next) sta->bus_station.Add(rs->xy);
|
||||
for (const RoadStop *rs = sta->truck_stops; rs != NULL; rs = rs->next) sta->truck_station.Add(rs->xy);
|
||||
for (const RoadStop *rs = sta->bus_stops; rs != nullptr; rs = rs->next) sta->bus_station.Add(rs->xy);
|
||||
for (const RoadStop *rs = sta->truck_stops; rs != nullptr; rs = rs->next) sta->truck_station.Add(rs->xy);
|
||||
}
|
||||
|
||||
StationUpdateCachedTriggers(st);
|
||||
@@ -174,8 +174,8 @@ static const SaveLoad _old_station_desc[] = {
|
||||
SLE_CONDVAR(Station, train_station.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, airport.tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDVAR(Station, airport.tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, dock_tile, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDVAR(Station, dock_tile, SLE_UINT32, SLV_6, SL_MAX_VERSION),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_MULTITILE_DOCKS),
|
||||
SLE_REF(Station, town, REF_TOWN),
|
||||
SLE_VAR(Station, train_station.w, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_CONDVAR(Station, train_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_2, SL_MAX_VERSION),
|
||||
@@ -423,7 +423,13 @@ static const SaveLoad _station_desc[] = {
|
||||
|
||||
SLE_REF(Station, bus_stops, REF_ROADSTOPS),
|
||||
SLE_REF(Station, truck_stops, REF_ROADSTOPS),
|
||||
SLE_VAR(Station, dock_tile, SLE_UINT32),
|
||||
SLE_CONDNULL(4, SL_MIN_VERSION, SLV_MULTITILE_DOCKS),
|
||||
SLE_CONDVAR(Station, ship_station.tile, SLE_UINT32, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, ship_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, ship_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, docking_station.tile, SLE_UINT32, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, docking_station.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, docking_station.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_MULTITILE_DOCKS, SL_MAX_VERSION),
|
||||
SLE_VAR(Station, airport.tile, SLE_UINT32),
|
||||
SLE_CONDVAR(Station, airport.w, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Station, airport.h, SLE_FILE_U8 | SLE_VAR_U16, SLV_140, SL_MAX_VERSION),
|
||||
@@ -544,11 +550,11 @@ static void Load_STNN()
|
||||
for (CargoID i = 0; i < num_cargo; i++) {
|
||||
SlObject(&st->goods[i], GetGoodsDesc());
|
||||
FlowSaveLoad flow;
|
||||
FlowStat *fs = NULL;
|
||||
FlowStat *fs = nullptr;
|
||||
StationID prev_source = INVALID_STATION;
|
||||
for (uint32 j = 0; j < _num_flows; ++j) {
|
||||
SlObject(&flow, _flow_desc);
|
||||
if (fs == NULL || prev_source != flow.source) {
|
||||
if (fs == nullptr || prev_source != flow.source) {
|
||||
fs = &(st->goods[i].flows.insert(std::make_pair(flow.source, FlowStat(flow.via, flow.share, flow.restricted))).first->second);
|
||||
} else {
|
||||
fs->AppendShare(flow.via, flow.share, flow.restricted);
|
||||
@@ -638,7 +644,7 @@ static void Ptrs_ROADSTOP()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _station_chunk_handlers[] = {
|
||||
{ 'STNS', NULL, Load_STNS, Ptrs_STNS, NULL, CH_ARRAY },
|
||||
{ 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, NULL, CH_ARRAY },
|
||||
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'STNS', nullptr, Load_STNS, Ptrs_STNS, nullptr, CH_ARRAY },
|
||||
{ 'STNN', Save_STNN, Load_STNN, Ptrs_STNN, nullptr, CH_ARRAY },
|
||||
{ 'ROAD', Save_ROADSTOP, Load_ROADSTOP, Ptrs_ROADSTOP, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -50,5 +50,5 @@ static void Save_PSAC()
|
||||
|
||||
/** Chunk handler for persistent storages. */
|
||||
extern const ChunkHandler _persistent_storage_chunk_handlers[] = {
|
||||
{ 'PSAC', Save_PSAC, Load_PSAC, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'PSAC', Save_PSAC, Load_PSAC, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -102,6 +102,6 @@ static void Load_STORY_PAGE()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _story_page_chunk_handlers[] = {
|
||||
{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, NULL, NULL, CH_ARRAY},
|
||||
{ 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'STPE', Save_STORY_PAGE_ELEMENT, Load_STORY_PAGE_ELEMENT, nullptr, nullptr, CH_ARRAY},
|
||||
{ 'STPA', Save_STORY_PAGE, Load_STORY_PAGE, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -49,7 +49,7 @@ StringID RemapOldStringID(StringID s)
|
||||
}
|
||||
|
||||
/** Location to load the old names to. */
|
||||
char *_old_name_array = NULL;
|
||||
char *_old_name_array = nullptr;
|
||||
|
||||
/**
|
||||
* Copy and convert old custom names to UTF-8.
|
||||
@@ -61,7 +61,7 @@ char *_old_name_array = NULL;
|
||||
char *CopyFromOldName(StringID id)
|
||||
{
|
||||
/* Is this name an (old) custom name? */
|
||||
if (GetStringTab(id) != TEXT_TAB_OLD_CUSTOM) return NULL;
|
||||
if (GetStringTab(id) != TEXT_TAB_OLD_CUSTOM) return nullptr;
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_37)) {
|
||||
/* Allow for expansion when converted to UTF-8. */
|
||||
@@ -82,7 +82,7 @@ char *CopyFromOldName(StringID id)
|
||||
case 0xB8: c = 0x017E; break; // z with caron
|
||||
case 0xBC: c = 0x0152; break; // OE ligature
|
||||
case 0xBD: c = 0x0153; break; // oe ligature
|
||||
case 0xBE: c = 0x0178; break; // Y with diaresis
|
||||
case 0xBE: c = 0x0178; break; // Y with diaeresis
|
||||
default: break;
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ char *CopyFromOldName(StringID id)
|
||||
void ResetOldNames()
|
||||
{
|
||||
free(_old_name_array);
|
||||
_old_name_array = NULL;
|
||||
_old_name_array = nullptr;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -140,5 +140,5 @@ static void Load_NAME()
|
||||
|
||||
/** Chunk handlers related to strings. */
|
||||
extern const ChunkHandler _name_chunk_handlers[] = {
|
||||
{ 'NAME', NULL, Load_NAME, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'NAME', nullptr, Load_NAME, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -48,5 +48,5 @@ static void Load_SUBS()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _subsidy_chunk_handlers[] = {
|
||||
{ 'SUBS', Save_SUBS, Load_SUBS, NULL, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'SUBS', Save_SUBS, Load_SUBS, nullptr, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -28,6 +28,7 @@ void RebuildTownCaches()
|
||||
{
|
||||
Town *town;
|
||||
InitializeBuildingCounts();
|
||||
RebuildTownKdtree();
|
||||
|
||||
/* Reset town population and num_houses */
|
||||
FOR_ALL_TOWNS(town) {
|
||||
@@ -320,6 +321,6 @@ static void Ptrs_TOWN()
|
||||
|
||||
/** Chunk handler for towns. */
|
||||
extern const ChunkHandler _town_chunk_handlers[] = {
|
||||
{ 'HIDS', Save_HIDS, Load_HIDS, NULL, NULL, CH_ARRAY },
|
||||
{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'HIDS', Save_HIDS, Load_HIDS, nullptr, nullptr, CH_ARRAY },
|
||||
{ 'CITY', Save_TOWN, Load_TOWN, Ptrs_TOWN, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
+55
-51
@@ -36,7 +36,7 @@ void ConnectMultiheadedTrains()
|
||||
Train *v;
|
||||
|
||||
FOR_ALL_TRAINS(v) {
|
||||
v->other_multiheaded_part = NULL;
|
||||
v->other_multiheaded_part = nullptr;
|
||||
}
|
||||
|
||||
FOR_ALL_TRAINS(v) {
|
||||
@@ -56,8 +56,8 @@ void ConnectMultiheadedTrains()
|
||||
|
||||
bool sequential_matching = v->IsFrontEngine();
|
||||
|
||||
for (Train *u = v; u != NULL; u = u->GetNextVehicle()) {
|
||||
if (u->other_multiheaded_part != NULL) continue; // we already linked this one
|
||||
for (Train *u = v; u != nullptr; u = u->GetNextVehicle()) {
|
||||
if (u->other_multiheaded_part != nullptr) continue; // we already linked this one
|
||||
|
||||
if (u->IsMultiheaded()) {
|
||||
if (!u->IsEngine()) {
|
||||
@@ -70,8 +70,8 @@ void ConnectMultiheadedTrains()
|
||||
EngineID eid = u->engine_type;
|
||||
Train *w;
|
||||
if (sequential_matching) {
|
||||
for (w = u->GetNextVehicle(); w != NULL; w = w->GetNextVehicle()) {
|
||||
if (w->engine_type != eid || w->other_multiheaded_part != NULL || !w->IsMultiheaded()) continue;
|
||||
for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
|
||||
if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
|
||||
|
||||
/* we found a car to partner with this engine. Now we will make sure it face the right way */
|
||||
if (w->IsEngine()) {
|
||||
@@ -82,8 +82,8 @@ void ConnectMultiheadedTrains()
|
||||
}
|
||||
} else {
|
||||
uint stack_pos = 0;
|
||||
for (w = u->GetNextVehicle(); w != NULL; w = w->GetNextVehicle()) {
|
||||
if (w->engine_type != eid || w->other_multiheaded_part != NULL || !w->IsMultiheaded()) continue;
|
||||
for (w = u->GetNextVehicle(); w != nullptr; w = w->GetNextVehicle()) {
|
||||
if (w->engine_type != eid || w->other_multiheaded_part != nullptr || !w->IsMultiheaded()) continue;
|
||||
|
||||
if (w->IsEngine()) {
|
||||
stack_pos++;
|
||||
@@ -94,7 +94,7 @@ void ConnectMultiheadedTrains()
|
||||
}
|
||||
}
|
||||
|
||||
if (w != NULL) {
|
||||
if (w != nullptr) {
|
||||
w->other_multiheaded_part = u;
|
||||
u->other_multiheaded_part = w;
|
||||
} else {
|
||||
@@ -118,7 +118,7 @@ void ConvertOldMultiheadToNew()
|
||||
|
||||
FOR_ALL_TRAINS(t) {
|
||||
if (HasBit(t->subtype, 7) && ((t->subtype & ~0x80) == 0 || (t->subtype & ~0x80) == 4)) {
|
||||
for (Train *u = t; u != NULL; u = u->Next()) {
|
||||
for (Train *u = t; u != nullptr; u = u->Next()) {
|
||||
const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
|
||||
|
||||
ClrBit(u->subtype, 7);
|
||||
@@ -200,7 +200,7 @@ void UpdateOldAircraft()
|
||||
if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32;
|
||||
|
||||
/* set new position x,y,z */
|
||||
GetAircraftFlightLevelBounds(a, &a->z_pos, NULL);
|
||||
GetAircraftFlightLevelBounds(a, &a->z_pos, nullptr);
|
||||
SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlightLevel(a));
|
||||
}
|
||||
}
|
||||
@@ -252,11 +252,11 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
/* Reinstate the previous pointer */
|
||||
if (v->Next() != NULL) v->Next()->previous = v;
|
||||
if (v->NextShared() != NULL) v->NextShared()->previous_shared = v;
|
||||
if (v->Next() != nullptr) v->Next()->previous = v;
|
||||
if (v->NextShared() != nullptr) v->NextShared()->previous_shared = v;
|
||||
|
||||
if (part_of_load) v->fill_percent_te_id = INVALID_TE_ID;
|
||||
v->first = NULL;
|
||||
v->first = nullptr;
|
||||
if (v->IsGroundVehicle()) v->GetGroundVehicleCache()->first_engine = INVALID_ENGINE;
|
||||
}
|
||||
|
||||
@@ -272,9 +272,9 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
std::map<Order*, OrderList*> mapping;
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->orders.old != NULL) {
|
||||
if (v->orders.old != nullptr) {
|
||||
if (IsSavegameVersionBefore(SLV_105)) { // Pre-105 didn't save an OrderList
|
||||
if (mapping[v->orders.old] == NULL) {
|
||||
if (mapping[v->orders.old] == nullptr) {
|
||||
/* This adds the whole shared vehicle chain for case b */
|
||||
|
||||
/* Creating an OrderList here is safe because the number of vehicles
|
||||
@@ -290,7 +290,7 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
}
|
||||
}
|
||||
} else { // OrderList was saved as such, only recalculate not saved values
|
||||
if (v->PreviousShared() == NULL) {
|
||||
if (v->PreviousShared() == nullptr) {
|
||||
v->orders.list->Initialize(v->orders.list->first, v);
|
||||
}
|
||||
}
|
||||
@@ -300,8 +300,8 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
/* Fill the first pointers */
|
||||
if (v->Previous() == NULL) {
|
||||
for (Vehicle *u = v; u != NULL; u = u->Next()) {
|
||||
if (v->Previous() == nullptr) {
|
||||
for (Vehicle *u = v; u != nullptr; u = u->Next()) {
|
||||
u->first = v;
|
||||
}
|
||||
}
|
||||
@@ -311,12 +311,12 @@ void AfterLoadVehicles(bool 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) {
|
||||
if (v->First() != v || v->orders.list != NULL || v->previous_shared != NULL || v->next_shared == NULL) continue;
|
||||
if (v->First() != v || v->orders.list != nullptr || v->previous_shared != nullptr || v->next_shared == nullptr) continue;
|
||||
|
||||
/* As above, allocating OrderList here is safe. */
|
||||
assert(OrderList::CanAllocateItem());
|
||||
v->orders.list = new OrderList(NULL, v);
|
||||
for (Vehicle *u = v; u != NULL; u = u->next_shared) {
|
||||
v->orders.list = new OrderList(nullptr, v);
|
||||
for (Vehicle *u = v; u != nullptr; u = u->next_shared) {
|
||||
u->orders.list = v->orders.list;
|
||||
}
|
||||
}
|
||||
@@ -392,9 +392,9 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
CheckValidVehicles();
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
assert(v->first != NULL);
|
||||
assert(v->first != nullptr);
|
||||
|
||||
v->trip_occupancy = CalcPercentVehicleFilled(v, NULL);
|
||||
v->trip_occupancy = CalcPercentVehicleFilled(v, nullptr);
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: {
|
||||
@@ -410,6 +410,14 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
RoadVehicle *rv = RoadVehicle::From(v);
|
||||
if (rv->IsFrontEngine()) {
|
||||
rv->gcache.last_speed = rv->cur_speed; // update displayed road vehicle speed
|
||||
|
||||
rv->roadtype = Engine::Get(rv->engine_type)->u.road.roadtype;
|
||||
rv->compatible_roadtypes = GetRoadTypeInfo(rv->roadtype)->powered_roadtypes;
|
||||
for (RoadVehicle *u = rv; u != nullptr; u = u->Next()) {
|
||||
u->roadtype = rv->roadtype;
|
||||
u->compatible_roadtypes = rv->compatible_roadtypes;
|
||||
}
|
||||
|
||||
RoadVehUpdateCache(rv);
|
||||
if (_settings_game.vehicle.roadveh_acceleration_model != AM_ORIGINAL) {
|
||||
rv->CargoChanged();
|
||||
@@ -448,13 +456,7 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
switch (v->type) {
|
||||
case VEH_ROAD: {
|
||||
RoadVehicle *rv = RoadVehicle::From(v);
|
||||
rv->roadtype = HasBit(EngInfo(v->First()->engine_type)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD;
|
||||
rv->compatible_roadtypes = RoadTypeToRoadTypes(rv->roadtype);
|
||||
FALLTHROUGH;
|
||||
}
|
||||
|
||||
case VEH_ROAD:
|
||||
case VEH_TRAIN:
|
||||
case VEH_SHIP:
|
||||
v->GetImage(v->direction, EIT_ON_MAP, &v->sprite_seq);
|
||||
@@ -502,7 +504,7 @@ void FixupTrainLengths()
|
||||
/* 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
|
||||
* old center, otherwise wagon spacing in trains would be broken upon load. */
|
||||
for (Train *u = Train::From(v); u != NULL; u = u->Next()) {
|
||||
for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
|
||||
if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
|
||||
|
||||
Train *next = u->Next();
|
||||
@@ -514,7 +516,7 @@ void FixupTrainLengths()
|
||||
if (!TrainController(u, next, false)) break;
|
||||
}
|
||||
|
||||
if (next != NULL && done < diff && u->IsFrontEngine()) {
|
||||
if (next != nullptr && done < diff && u->IsFrontEngine()) {
|
||||
/* Pulling the front vehicle forwards failed, we either encountered a dead-end
|
||||
* or a red signal. To fix this, we try to move the whole train the required
|
||||
* space backwards and re-do the fix up of the front vehicle. */
|
||||
@@ -530,14 +532,14 @@ void FixupTrainLengths()
|
||||
|
||||
/* We moved the first vehicle which is now the last. Move it back to the
|
||||
* original position as we will fix up the last vehicle later in the loop. */
|
||||
for (int i = 0; i < done; i++) TrainController(u->Last(), NULL);
|
||||
for (int i = 0; i < done; i++) TrainController(u->Last(), nullptr);
|
||||
|
||||
/* Move the train backwards to get space for the first vehicle. As the stopping
|
||||
* distance from a line end is rounded up, move the train one unit more to cater
|
||||
* for front vehicles with odd lengths. */
|
||||
int moved;
|
||||
for (moved = 0; moved < diff + 1; moved++) {
|
||||
if (!TrainController(u, NULL, false)) break;
|
||||
if (!TrainController(u, nullptr, false)) break;
|
||||
}
|
||||
|
||||
/* Swap start<>end, start+1<>end-1, ... again. */
|
||||
@@ -556,17 +558,17 @@ void FixupTrainLengths()
|
||||
|
||||
/* We moved one unit more backwards than needed for even-length front vehicles,
|
||||
* try to move that unit forward again. We don't care if this step fails. */
|
||||
TrainController(u, NULL, false);
|
||||
TrainController(u, nullptr, false);
|
||||
}
|
||||
|
||||
/* If the next wagon is still in a depot, check if it shouldn't be outside already. */
|
||||
if (next != NULL && next->track == TRACK_BIT_DEPOT) {
|
||||
if (next != nullptr && next->track == TRACK_BIT_DEPOT) {
|
||||
int d = TicksToLeaveDepot(u);
|
||||
if (d <= 0) {
|
||||
/* Next vehicle should have left the depot already, show it and pull forward. */
|
||||
next->vehstatus &= ~VS_HIDDEN;
|
||||
next->track = TrackToTrackBits(GetRailDepotTrack(next->tile));
|
||||
for (int i = 0; i >= d; i--) TrainController(next, NULL);
|
||||
for (int i = 0; i >= d; i--) TrainController(next, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -752,21 +754,23 @@ const SaveLoad *GetVehicleDescription(VehicleType vt)
|
||||
static const SaveLoad _roadveh_desc[] = {
|
||||
SLE_WRITEBYTE(Vehicle, type),
|
||||
SLE_VEH_INCLUDE(),
|
||||
SLE_VAR(RoadVehicle, state, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, frame, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
|
||||
SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
|
||||
SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, state, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, frame, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, blocked_ctr, SLE_UINT16),
|
||||
SLE_VAR(RoadVehicle, overtaking, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, overtaking_ctr, SLE_UINT8),
|
||||
SLE_VAR(RoadVehicle, crashed_ctr, SLE_UINT16),
|
||||
SLE_VAR(RoadVehicle, reverse_ctr, SLE_UINT8),
|
||||
SLE_CONDDEQUE(RoadVehicle, path.td, SLE_UINT8, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
|
||||
SLE_CONDDEQUE(RoadVehicle, path.tile, SLE_UINT32, SLV_ROADVEH_PATH_CACHE, SL_MAX_VERSION),
|
||||
|
||||
SLE_CONDNULL(2, SLV_6, SLV_69),
|
||||
SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
|
||||
SLE_CONDNULL(4, SLV_69, SLV_131),
|
||||
SLE_CONDNULL(2, SLV_6, SLV_131),
|
||||
SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
|
||||
SLE_CONDNULL(2, SLV_6, SLV_69),
|
||||
SLE_CONDVAR(RoadVehicle, gv_flags, SLE_UINT16, SLV_139, SL_MAX_VERSION),
|
||||
SLE_CONDNULL(4, SLV_69, SLV_131),
|
||||
SLE_CONDNULL(2, SLV_6, SLV_131),
|
||||
SLE_CONDNULL(16, SLV_2, SLV_144), // old reserved space
|
||||
|
||||
SLE_END()
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad _ship_desc[] = {
|
||||
@@ -958,5 +962,5 @@ static void Ptrs_VEHS()
|
||||
}
|
||||
|
||||
extern const ChunkHandler _veh_chunk_handlers[] = {
|
||||
{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, NULL, CH_SPARSE_ARRAY | CH_LAST},
|
||||
{ 'VEHS', Save_VEHS, Load_VEHS, Ptrs_VEHS, nullptr, CH_SPARSE_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
@@ -36,13 +36,13 @@ struct OldWaypoint {
|
||||
uint8 localidx;
|
||||
uint32 grfid;
|
||||
const StationSpec *spec;
|
||||
OwnerByte owner;
|
||||
Owner owner;
|
||||
|
||||
size_t new_index;
|
||||
};
|
||||
|
||||
/** Temporary array with old waypoints. */
|
||||
static SmallVector<OldWaypoint, 16> _old_waypoints;
|
||||
static std::vector<OldWaypoint> _old_waypoints;
|
||||
|
||||
/**
|
||||
* Update the waypoint orders to get the new waypoint ID.
|
||||
@@ -52,10 +52,10 @@ static void UpdateWaypointOrder(Order *o)
|
||||
{
|
||||
if (!o->IsType(OT_GOTO_WAYPOINT)) return;
|
||||
|
||||
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
|
||||
if (wp->index != o->GetDestination()) continue;
|
||||
for (OldWaypoint &wp : _old_waypoints) {
|
||||
if (wp.index != o->GetDestination()) continue;
|
||||
|
||||
o->SetDestination((DestinationID)wp->new_index);
|
||||
o->SetDestination((DestinationID)wp.new_index);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -71,47 +71,47 @@ void MoveWaypointsToBaseStations()
|
||||
* id which was stored in m4 is now saved as a grf/id reference in the
|
||||
* waypoint struct. */
|
||||
if (IsSavegameVersionBefore(SLV_17)) {
|
||||
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
|
||||
if (wp->delete_ctr != 0) continue; // The waypoint was deleted
|
||||
for (OldWaypoint &wp : _old_waypoints) {
|
||||
if (wp.delete_ctr != 0) continue; // The waypoint was deleted
|
||||
|
||||
/* Waypoint indices were not added to the map prior to this. */
|
||||
_m[wp->xy].m2 = (StationID)wp->index;
|
||||
_m[wp.xy].m2 = (StationID)wp.index;
|
||||
|
||||
if (HasBit(_m[wp->xy].m3, 4)) {
|
||||
wp->spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(_m[wp->xy].m4 + 1);
|
||||
if (HasBit(_m[wp.xy].m3, 4)) {
|
||||
wp.spec = StationClass::Get(STAT_CLASS_WAYP)->GetSpec(_m[wp.xy].m4 + 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* As of version 17, we recalculate the custom graphic ID of waypoints
|
||||
* from the GRF ID / station index. */
|
||||
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
|
||||
for (OldWaypoint &wp : _old_waypoints) {
|
||||
StationClass* stclass = StationClass::Get(STAT_CLASS_WAYP);
|
||||
for (uint i = 0; i < stclass->GetSpecCount(); i++) {
|
||||
const StationSpec *statspec = stclass->GetSpec(i);
|
||||
if (statspec != NULL && statspec->grf_prop.grffile->grfid == wp->grfid && statspec->grf_prop.local_id == wp->localidx) {
|
||||
wp->spec = statspec;
|
||||
if (statspec != nullptr && statspec->grf_prop.grffile->grfid == wp.grfid && statspec->grf_prop.local_id == wp.localidx) {
|
||||
wp.spec = statspec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!Waypoint::CanAllocateItem(_old_waypoints.Length())) SlError(STR_ERROR_TOO_MANY_STATIONS_LOADING);
|
||||
if (!Waypoint::CanAllocateItem(_old_waypoints.size())) SlError(STR_ERROR_TOO_MANY_STATIONS_LOADING);
|
||||
|
||||
/* All saveload conversions have been done. Create the new waypoints! */
|
||||
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
|
||||
Waypoint *new_wp = new Waypoint(wp->xy);
|
||||
new_wp->town = wp->town;
|
||||
new_wp->town_cn = wp->town_cn;
|
||||
new_wp->name = wp->name;
|
||||
for (OldWaypoint &wp : _old_waypoints) {
|
||||
Waypoint *new_wp = new Waypoint(wp.xy);
|
||||
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->build_date = wp.build_date;
|
||||
new_wp->owner = wp.owner;
|
||||
|
||||
new_wp->string_id = STR_SV_STNAME_WAYPOINT;
|
||||
|
||||
TileIndex t = wp->xy;
|
||||
if (IsTileType(t, MP_RAILWAY) && GetRailTileType(t) == 2 /* RAIL_TILE_WAYPOINT */ && _m[t].m2 == wp->index) {
|
||||
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);
|
||||
|
||||
@@ -122,13 +122,13 @@ void MoveWaypointsToBaseStations()
|
||||
|
||||
SetRailStationReservation(t, reserved);
|
||||
|
||||
if (wp->spec != NULL) {
|
||||
SetCustomStationSpecIndex(t, AllocateSpecToStation(wp->spec, new_wp, true));
|
||||
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;
|
||||
wp.new_index = new_wp->index;
|
||||
}
|
||||
|
||||
/* Update the orders of vehicles */
|
||||
@@ -136,7 +136,7 @@ void MoveWaypointsToBaseStations()
|
||||
FOR_ALL_ORDER_LISTS(ol) {
|
||||
if (ol->GetFirstSharedVehicle()->type != VEH_TRAIN) continue;
|
||||
|
||||
for (Order *o = ol->GetFirstOrder(); o != NULL; o = o->next) UpdateWaypointOrder(o);
|
||||
for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o);
|
||||
}
|
||||
|
||||
Vehicle *v;
|
||||
@@ -146,7 +146,8 @@ void MoveWaypointsToBaseStations()
|
||||
UpdateWaypointOrder(&v->current_order);
|
||||
}
|
||||
|
||||
_old_waypoints.Reset();
|
||||
_old_waypoints.clear();
|
||||
_old_waypoints.shrink_to_fit();
|
||||
}
|
||||
|
||||
static const SaveLoad _old_waypoint_desc[] = {
|
||||
@@ -172,12 +173,13 @@ static const SaveLoad _old_waypoint_desc[] = {
|
||||
static void Load_WAYP()
|
||||
{
|
||||
/* Precaution for when loading failed and it didn't get cleared */
|
||||
_old_waypoints.Clear();
|
||||
_old_waypoints.clear();
|
||||
|
||||
int index;
|
||||
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
OldWaypoint *wp = _old_waypoints.Append();
|
||||
/*C++17: OldWaypoint *wp = &*/ _old_waypoints.emplace_back();
|
||||
OldWaypoint *wp = &_old_waypoints.back();
|
||||
memset(wp, 0, sizeof(*wp));
|
||||
|
||||
wp->index = index;
|
||||
@@ -187,31 +189,31 @@ static void Load_WAYP()
|
||||
|
||||
static void Ptrs_WAYP()
|
||||
{
|
||||
for (OldWaypoint *wp = _old_waypoints.Begin(); wp != _old_waypoints.End(); wp++) {
|
||||
SlObject(wp, _old_waypoint_desc);
|
||||
for (OldWaypoint &wp : _old_waypoints) {
|
||||
SlObject(&wp, _old_waypoint_desc);
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_12)) {
|
||||
wp->town_cn = (wp->string_id & 0xC000) == 0xC000 ? (wp->string_id >> 8) & 0x3F : 0;
|
||||
wp->town = ClosestTownFromTile(wp->xy, UINT_MAX);
|
||||
wp.town_cn = (wp.string_id & 0xC000) == 0xC000 ? (wp.string_id >> 8) & 0x3F : 0;
|
||||
wp.town = ClosestTownFromTile(wp.xy, UINT_MAX);
|
||||
} else if (IsSavegameVersionBefore(SLV_122)) {
|
||||
/* Only for versions 12 .. 122 */
|
||||
if (!Town::IsValidID(wp->town_index)) {
|
||||
if (!Town::IsValidID(wp.town_index)) {
|
||||
/* Upon a corrupted waypoint we'll likely get here. The next step will be to
|
||||
* loop over all Ptrs procs to NULL the pointers. However, we don't know
|
||||
* whether we're in the NULL or "normal" Ptrs proc. So just clear the list
|
||||
* loop over all Ptrs procs to nullptr the pointers. However, we don't know
|
||||
* whether we're in the nullptr or "normal" Ptrs proc. So just clear the list
|
||||
* of old waypoints we constructed and then this waypoint (and the other
|
||||
* possibly corrupt ones) will not be queried in the NULL Ptrs proc run. */
|
||||
_old_waypoints.Clear();
|
||||
* possibly corrupt ones) will not be queried in the nullptr Ptrs proc run. */
|
||||
_old_waypoints.clear();
|
||||
SlErrorCorrupt("Referencing invalid Town");
|
||||
}
|
||||
wp->town = Town::Get(wp->town_index);
|
||||
wp.town = Town::Get(wp.town_index);
|
||||
}
|
||||
if (IsSavegameVersionBefore(SLV_84)) {
|
||||
wp->name = CopyFromOldName(wp->string_id);
|
||||
wp.name = CopyFromOldName(wp.string_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern const ChunkHandler _waypoint_chunk_handlers[] = {
|
||||
{ 'CHKP', NULL, Load_WAYP, Ptrs_WAYP, NULL, CH_ARRAY | CH_LAST},
|
||||
{ 'CHKP', nullptr, Load_WAYP, Ptrs_WAYP, nullptr, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user