Merge branch 'cpp-11' into save_ext
# Conflicts: # config.lib # src/saveload/saveload.cpp
This commit is contained in:
@@ -1214,6 +1214,38 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
/* Railtype moved from m3 to m8 in version 200. */
|
||||
if (IsSavegameVersionBefore(200)) {
|
||||
for (TileIndex t = 0; t < map_size; t++) {
|
||||
switch (GetTileType(t)) {
|
||||
case MP_RAILWAY:
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
break;
|
||||
|
||||
case MP_ROAD:
|
||||
if (IsLevelCrossing(t)) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_STATION:
|
||||
if (HasStationRail(t)) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
case MP_TUNNELBRIDGE:
|
||||
if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) {
|
||||
SetRailType(t, (RailType)GB(_m[t].m3, 0, 4));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Elrails got added in rev 24 */
|
||||
if (IsSavegameVersionBefore(24)) {
|
||||
RailType min_rail = RAILTYPE_ELECTRIC;
|
||||
@@ -2983,6 +3015,36 @@ bool AfterLoadGame()
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(202)) {
|
||||
/* Make sure added industry cargo slots are cleared */
|
||||
Industry *i;
|
||||
FOR_ALL_INDUSTRIES(i) {
|
||||
for (size_t ci = 2; ci < lengthof(i->produced_cargo); ci++) {
|
||||
i->produced_cargo[ci] = CT_INVALID;
|
||||
i->produced_cargo_waiting[ci] = 0;
|
||||
i->production_rate[ci] = 0;
|
||||
i->last_month_production[ci] = 0;
|
||||
i->last_month_transported[ci] = 0;
|
||||
i->last_month_pct_transported[ci] = 0;
|
||||
i->this_month_production[ci] = 0;
|
||||
i->this_month_transported[ci] = 0;
|
||||
}
|
||||
for (size_t ci = 3; ci < lengthof(i->accepts_cargo); ci++) {
|
||||
i->accepts_cargo[ci] = CT_INVALID;
|
||||
i->incoming_cargo_waiting[ci] = 0;
|
||||
}
|
||||
/* Make sure last_cargo_accepted_at is copied to elements for every valid input cargo.
|
||||
* The loading routine should put the original singular value into the first array element. */
|
||||
for (size_t ci = 0; ci < lengthof(i->accepts_cargo); ci++) {
|
||||
if (i->accepts_cargo[ci] != CT_INVALID) {
|
||||
i->last_cargo_accepted_at[ci] = i->last_cargo_accepted_at[0];
|
||||
} else {
|
||||
i->last_cargo_accepted_at[ci] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Station acceptance is some kind of cache */
|
||||
if (IsSavegameVersionBefore(127)) {
|
||||
Station *st;
|
||||
|
@@ -26,18 +26,28 @@ static const SaveLoad _industry_desc[] = {
|
||||
SLE_VAR(Industry, location.h, SLE_FILE_U8 | SLE_VAR_U16),
|
||||
SLE_REF(Industry, town, REF_TOWN),
|
||||
SLE_CONDNULL( 2, 0, 60), ///< used to be industry's produced_cargo
|
||||
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, SL_MAX_VERSION),
|
||||
SLE_ARR(Industry, produced_cargo_waiting, SLE_UINT16, 2),
|
||||
SLE_ARR(Industry, production_rate, SLE_UINT8, 2),
|
||||
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 2, 78, 201),
|
||||
SLE_CONDARR(Industry, produced_cargo, SLE_UINT8, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 3, 70, 201),
|
||||
SLE_CONDARR(Industry, incoming_cargo_waiting, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, produced_cargo_waiting, SLE_UINT16, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, produced_cargo_waiting, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, production_rate, SLE_UINT8, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, production_rate, SLE_UINT8, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDNULL( 3, 0, 60), ///< used to be industry's accepts_cargo
|
||||
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, 78, 201),
|
||||
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 16, 202, SL_MAX_VERSION),
|
||||
SLE_VAR(Industry, prod_level, SLE_UINT8),
|
||||
SLE_ARR(Industry, this_month_production, SLE_UINT16, 2),
|
||||
SLE_ARR(Industry, this_month_transported, SLE_UINT16, 2),
|
||||
SLE_ARR(Industry, last_month_pct_transported, SLE_UINT8, 2),
|
||||
SLE_ARR(Industry, last_month_production, SLE_UINT16, 2),
|
||||
SLE_ARR(Industry, last_month_transported, SLE_UINT16, 2),
|
||||
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 2, 0, 201),
|
||||
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 16, 202, SL_MAX_VERSION),
|
||||
|
||||
SLE_VAR(Industry, counter, SLE_UINT16),
|
||||
|
||||
@@ -51,7 +61,8 @@ static const SaveLoad _industry_desc[] = {
|
||||
SLE_CONDVAR(Industry, founder, SLE_UINT8, 70, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Industry, construction_date, SLE_INT32, 70, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Industry, construction_type, SLE_UINT8, 70, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Industry, last_cargo_accepted_at, SLE_INT32, 70, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Industry, last_cargo_accepted_at[0], SLE_INT32, 70, 201),
|
||||
SLE_CONDARR(Industry, last_cargo_accepted_at, SLE_INT32, 16, 202, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Industry, selected_layout, SLE_UINT8, 73, SL_MAX_VERSION),
|
||||
|
||||
SLEG_CONDARR(_old_ind_persistent_storage.storage, SLE_UINT32, 16, 76, 160),
|
||||
@@ -101,7 +112,7 @@ static void Load_INDY()
|
||||
/* Store the old persistent storage. The GRFID will be added later. */
|
||||
assert(PersistentStorage::CanAllocateItem());
|
||||
i->psa = new PersistentStorage(0, 0, 0);
|
||||
memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(i->psa->storage));
|
||||
memcpy(i->psa->storage, _old_ind_persistent_storage.storage, sizeof(_old_ind_persistent_storage.storage));
|
||||
}
|
||||
Industry::IncIndustryTypeCount(i->type);
|
||||
}
|
||||
|
@@ -132,7 +132,7 @@ static const SaveLoad _edge_desc[] = {
|
||||
|
||||
/**
|
||||
* Save/load a link graph.
|
||||
* @param comp Link graph to be saved or loaded.
|
||||
* @param lg Link graph to be saved or loaded.
|
||||
*/
|
||||
void SaveLoad_LinkGraph(LinkGraph &lg)
|
||||
{
|
||||
|
@@ -272,6 +272,30 @@ static void Save_MAP7()
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_MAP8()
|
||||
{
|
||||
SmallStackSafeStackAlloc<uint16, MAP_SL_BUF_SIZE> buf;
|
||||
TileIndex size = MapSize();
|
||||
|
||||
for (TileIndex i = 0; i != size;) {
|
||||
SlArray(buf, 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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 },
|
||||
@@ -282,5 +306,6 @@ extern const ChunkHandler _map_chunk_handlers[] = {
|
||||
{ '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 | CH_LAST },
|
||||
{ 'MAP7', Save_MAP7, Load_MAP7, NULL, NULL, CH_RIFF },
|
||||
{ 'MAP8', Save_MAP8, Load_MAP8, NULL, NULL, CH_RIFF | CH_LAST },
|
||||
};
|
||||
|
@@ -265,7 +265,7 @@ static SavegameType DetermineOldSavegameType(FILE *f, char *title, const char *l
|
||||
case SGT_TTD: title = strecpy(title, "(TTD) ", last); break;
|
||||
default: title = strecpy(title, "(broken) ", last); break;
|
||||
}
|
||||
title = strecpy(title, temp, last);
|
||||
strecpy(title, temp, last);
|
||||
}
|
||||
|
||||
return type;
|
||||
|
@@ -273,8 +273,11 @@
|
||||
* 197 27978 1.8.x
|
||||
* 198
|
||||
* 199
|
||||
* 200 #6805 Extend railtypes to 64, adding uint16 to map array.
|
||||
* 201 #6885 Extend NewGRF persistant storages.
|
||||
* 202 #6867 Increase industry cargo slots to 16 in, 16 out
|
||||
*/
|
||||
extern const uint16 SAVEGAME_VERSION = 199; ///< Current savegame version of OpenTTD.
|
||||
extern const uint16 SAVEGAME_VERSION = 202; ///< Current savegame version of OpenTTD.
|
||||
const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask
|
||||
|
||||
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||
@@ -3045,7 +3048,7 @@ SaveOrLoadResult LoadWithFilter(LoadFilter *reader)
|
||||
* Main Save or Load function where the high-level saveload functions are
|
||||
* handled. It opens the savegame, selects format and checks versions
|
||||
* @param filename The name of the savegame being created/loaded
|
||||
* @param mode Save or load mode. Load can also be a TTD(Patch) game. Use #SL_LOAD, #SL_OLD_LOAD, #SL_LOAD_CHECK, or #SL_SAVE.
|
||||
* @param fop Save or load mode. Load can also be a TTD(Patch) game.
|
||||
* @param sb The sub directory to save the savegame in
|
||||
* @param threaded True when threaded saving is allowed
|
||||
* @return Return the result of the action. #SL_OK, #SL_ERROR, or #SL_REINIT ("unload" the game)
|
||||
|
@@ -638,7 +638,7 @@ static inline bool SlIsObjectCurrentlyValid(uint16 version_from, uint16 version_
|
||||
* Get the NumberType of a setting. This describes the integer type
|
||||
* as it is represented in memory
|
||||
* @param type VarType holding information about the variable-type
|
||||
* @return return the SLE_VAR_* part of a variable-type description
|
||||
* @return the SLE_VAR_* part of a variable-type description
|
||||
*/
|
||||
static inline VarType GetVarMemType(VarType type)
|
||||
{
|
||||
@@ -646,10 +646,10 @@ static inline VarType GetVarMemType(VarType type)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the #FileType of a setting. This describes the integer type
|
||||
* Get the FileType of a setting. This describes the integer type
|
||||
* as it is represented in a savegame/file
|
||||
* @param type VarType holding information about the file-type
|
||||
* @param return the SLE_FILE_* part of a variable-type description
|
||||
* @return the SLE_FILE_* part of a variable-type description
|
||||
*/
|
||||
static inline VarType GetVarFileType(VarType type)
|
||||
{
|
||||
|
@@ -538,7 +538,7 @@ static void Load_STNN()
|
||||
/* Store the old persistent storage. The GRFID will be added later. */
|
||||
assert(PersistentStorage::CanAllocateItem());
|
||||
st->airport.psa = new PersistentStorage(0, 0, 0);
|
||||
memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(st->airport.psa->storage));
|
||||
memcpy(st->airport.psa->storage, _old_st_persistent_storage.storage, sizeof(_old_st_persistent_storage.storage));
|
||||
}
|
||||
|
||||
for (CargoID i = 0; i < num_cargo; i++) {
|
||||
|
@@ -18,7 +18,8 @@
|
||||
/** Description of the data to save and load in #PersistentStorage. */
|
||||
static const SaveLoad _storage_desc[] = {
|
||||
SLE_CONDVAR(PersistentStorage, grfid, SLE_UINT32, 6, SL_MAX_VERSION),
|
||||
SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, 161, SL_MAX_VERSION),
|
||||
SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 16, 161, 200),
|
||||
SLE_CONDARR(PersistentStorage, storage, SLE_UINT32, 256, 201, SL_MAX_VERSION),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user