Merge branch 'save_ext' into improved_breakdowns
This commit is contained in:
@@ -718,12 +718,14 @@ bool AfterLoadGame()
|
||||
if (IsSavegameVersionBefore(95)) _settings_game.vehicle.dynamic_engines = 0;
|
||||
if (IsSavegameVersionBefore(96)) _settings_game.economy.station_noise_level = false;
|
||||
if (IsSavegameVersionBefore(133)) {
|
||||
_settings_game.vehicle.roadveh_acceleration_model = 0;
|
||||
_settings_game.vehicle.train_slope_steepness = 3;
|
||||
}
|
||||
if (IsSavegameVersionBefore(134)) _settings_game.economy.feeder_payment_share = 75;
|
||||
if (IsSavegameVersionBefore(138)) _settings_game.vehicle.plane_crashes = 2;
|
||||
if (IsSavegameVersionBefore(139)) _settings_game.vehicle.roadveh_slope_steepness = 7;
|
||||
if (IsSavegameVersionBefore(139)) {
|
||||
_settings_game.vehicle.roadveh_acceleration_model = 0;
|
||||
_settings_game.vehicle.roadveh_slope_steepness = 7;
|
||||
}
|
||||
if (IsSavegameVersionBefore(143)) _settings_game.economy.allow_town_level_crossings = true;
|
||||
if (IsSavegameVersionBefore(159)) {
|
||||
_settings_game.vehicle.max_train_length = 50;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include "../tunnelbridge_map.h"
|
||||
#include "../tunnelbridge.h"
|
||||
#include "../station_base.h"
|
||||
#include "../strings_func.h"
|
||||
#include "../settings_func.h"
|
||||
|
||||
#include "saveload.h"
|
||||
@@ -244,7 +245,7 @@ static const SaveLoad _company_desc[] = {
|
||||
SLE_VAR(CompanyProperties, name_1, SLE_STRINGID),
|
||||
SLE_CONDSTR(CompanyProperties, name, SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
|
||||
|
||||
SLE_VAR(CompanyProperties, president_name_1, SLE_UINT16),
|
||||
SLE_VAR(CompanyProperties, president_name_1, SLE_STRINGID),
|
||||
SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
|
||||
SLE_CONDSTR(CompanyProperties, president_name, SLE_STR | SLF_ALLOW_CONTROL, 0, 84, SL_MAX_VERSION),
|
||||
|
||||
@@ -503,11 +504,11 @@ static void Check_PLYR()
|
||||
|
||||
/* We do not load old custom names */
|
||||
if (IsSavegameVersionBefore(84)) {
|
||||
if (GB(cprops->name_1, 11, 5) == 15) {
|
||||
if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (GB(cprops->president_name_1, 11, 5) == 15) {
|
||||
if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
@@ -108,6 +108,7 @@ void SlXvResetState()
|
||||
{
|
||||
_sl_is_ext_version = false;
|
||||
_sl_is_faked_ext = false;
|
||||
_sl_xv_discardable_chunk_ids.clear();
|
||||
memset(_sl_xv_feature_versions, 0, sizeof(_sl_xv_feature_versions));
|
||||
}
|
||||
|
||||
|
@@ -96,8 +96,16 @@ static void Load_NGRF()
|
||||
{
|
||||
Load_NGRF_common(_grfconfig);
|
||||
|
||||
/* Append static NewGRF configuration, but only if there are some NewGRFs. */
|
||||
if (_game_mode != GM_MENU || _all_grfs != NULL) AppendStaticGRFConfigs(&_grfconfig);
|
||||
if (_game_mode == GM_MENU) {
|
||||
/* Intro game must not have NewGRF. */
|
||||
if (_grfconfig != NULL) SlErrorCorrupt("The intro game must not use NewGRF");
|
||||
|
||||
/* Activate intro NewGRFs (townnames) */
|
||||
ResetGRFConfig(false);
|
||||
} else {
|
||||
/* Append static NewGRF configuration */
|
||||
AppendStaticGRFConfigs(&_grfconfig);
|
||||
}
|
||||
}
|
||||
|
||||
static void Check_NGRF()
|
||||
|
@@ -41,6 +41,7 @@
|
||||
#include "../fileio_func.h"
|
||||
#include "../gamelog.h"
|
||||
#include "../string_func.h"
|
||||
#include "../string_func_extra.h"
|
||||
#include "../fios.h"
|
||||
#include "../error.h"
|
||||
|
||||
@@ -267,8 +268,9 @@
|
||||
* 193 26802
|
||||
* 194 26881 1.5.x, 1.6.0
|
||||
* 195 27572 1.6.x
|
||||
* 196 27778 1.7.x
|
||||
*/
|
||||
extern const uint16 SAVEGAME_VERSION = 195; ///< Current savegame version of OpenTTD.
|
||||
extern const uint16 SAVEGAME_VERSION = 196; ///< Current savegame version of OpenTTD.
|
||||
const uint16 SAVEGAME_VERSION_EXT = 0x8000; ///< Savegame extension indicator mask
|
||||
|
||||
SavegameType _savegame_type; ///< type of savegame we are loading
|
||||
@@ -1077,6 +1079,18 @@ static inline size_t SlCalcNetStringLen(const char *ptr, size_t length)
|
||||
return min(strlen(ptr), length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the gross length of the std::string that it
|
||||
* will occupy in the savegame. This includes the real length,
|
||||
* and the length that the index will occupy.
|
||||
* @param str reference to the std::string
|
||||
* @return return the gross length of the string
|
||||
*/
|
||||
static inline size_t SlCalcStdStrLen(const std::string &str)
|
||||
{
|
||||
return str.size() + SlGetArrayLength(str.size()); // also include the length of the index
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the gross length of the string that it
|
||||
* will occupy in the savegame. This includes the real length, returned
|
||||
@@ -1188,6 +1202,41 @@ static void SlString(void *ptr, size_t length, VarType conv)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save/Load a std::string.
|
||||
* @param ptr the std::string being manipulated
|
||||
* @param conv must be SLE_FILE_STRING
|
||||
*/
|
||||
static void SlStdString(std::string &str, VarType conv)
|
||||
{
|
||||
switch (_sl.action) {
|
||||
case SLA_SAVE: {
|
||||
SlWriteArrayLength(str.size());
|
||||
SlCopyBytes(const_cast<char *>(str.data()), str.size());
|
||||
break;
|
||||
}
|
||||
case SLA_LOAD_CHECK:
|
||||
case SLA_LOAD: {
|
||||
size_t len = SlReadArrayLength();
|
||||
str.resize(len);
|
||||
SlCopyBytes(const_cast<char *>(str.c_str()), len);
|
||||
|
||||
StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK;
|
||||
if ((conv & SLF_ALLOW_CONTROL) != 0) {
|
||||
settings = settings | SVS_ALLOW_CONTROL_CODE;
|
||||
}
|
||||
if ((conv & SLF_ALLOW_NEWLINE) != 0) {
|
||||
settings = settings | SVS_ALLOW_NEWLINE;
|
||||
}
|
||||
str_validate(str, settings);
|
||||
break;
|
||||
}
|
||||
case SLA_PTRS: break;
|
||||
case SLA_NULL: break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the size in bytes of a certain type of atomic array
|
||||
* @param length The length of the array counted in elements
|
||||
@@ -1490,6 +1539,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
|
||||
case SL_LST:
|
||||
case SL_DEQ:
|
||||
case SL_VEC:
|
||||
case SL_STDSTR:
|
||||
/* CONDITIONAL saveload types depend on the savegame version */
|
||||
if (!SlIsObjectValidInSavegame(sld)) break;
|
||||
|
||||
@@ -1501,6 +1551,7 @@ size_t SlCalcObjMemberLength(const void *object, const SaveLoad *sld)
|
||||
case SL_LST: return SlCalcListLen<std::list<void *>>(GetVariableAddress(object, sld));
|
||||
case SL_DEQ: return SlCalcListLen<std::deque<void *>>(GetVariableAddress(object, sld));
|
||||
case SL_VEC: return SlCalcListLen<std::vector<void *>>(GetVariableAddress(object, sld));
|
||||
case SL_STDSTR: return SlCalcStdStrLen(*static_cast<std::string *>(GetVariableAddress(object, sld)));
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -1549,6 +1600,9 @@ static bool IsVariableSizeRight(const SaveLoad *sld)
|
||||
/* These should be pointer sized, or fixed array. */
|
||||
return sld->size == sizeof(void *) || sld->size == sld->length;
|
||||
|
||||
case SL_STDSTR:
|
||||
return sld->size == sizeof(std::string);
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
@@ -1571,6 +1625,7 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
case SL_LST:
|
||||
case SL_DEQ:
|
||||
case SL_VEC:
|
||||
case SL_STDSTR:
|
||||
/* CONDITIONAL saveload types depend on the savegame version */
|
||||
if (!SlIsObjectValidInSavegame(sld)) return false;
|
||||
if (SlSkipVariableOnLoad(sld)) return false;
|
||||
@@ -1600,6 +1655,7 @@ bool SlObjectMember(void *ptr, const SaveLoad *sld)
|
||||
case SL_LST: SlList<std::list<void *>>(ptr, (SLRefType)conv); break;
|
||||
case SL_DEQ: SlList<std::deque<void *>>(ptr, (SLRefType)conv); break;
|
||||
case SL_VEC: SlList<std::vector<void *>>(ptr, (SLRefType)conv); break;
|
||||
case SL_STDSTR: SlStdString(*static_cast<std::string *>(ptr), sld->conv); break;
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
break;
|
||||
@@ -2081,7 +2137,7 @@ struct LZOLoadFilter : LoadFilter {
|
||||
byte out[LZO_BUFFER_SIZE + LZO_BUFFER_SIZE / 16 + 64 + 3 + sizeof(uint32) * 2];
|
||||
uint32 tmp[2];
|
||||
uint32 size;
|
||||
lzo_uint len;
|
||||
lzo_uint len = ssize;
|
||||
|
||||
/* Read header*/
|
||||
if (this->chain->Read((byte*)tmp, sizeof(tmp)) != sizeof(tmp)) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE, "File read failed");
|
||||
@@ -2103,7 +2159,8 @@ struct LZOLoadFilter : LoadFilter {
|
||||
if (tmp[0] != lzo_adler32(0, out, size + sizeof(uint32))) SlErrorCorrupt("Bad checksum");
|
||||
|
||||
/* Decompress */
|
||||
lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, NULL);
|
||||
int ret = lzo1x_decompress_safe(out + sizeof(uint32) * 1, size, buf, &len, NULL);
|
||||
if (ret != LZO_E_OK) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
|
||||
return len;
|
||||
}
|
||||
};
|
||||
|
@@ -52,7 +52,7 @@ enum SavegameType {
|
||||
extern FileToSaveLoad _file_to_saveload;
|
||||
|
||||
void GenerateDefaultSaveName(char *buf, const char *last);
|
||||
void SetSaveLoadError(uint16 str);
|
||||
void SetSaveLoadError(StringID str);
|
||||
const char *GetSaveLoadErrorString();
|
||||
SaveOrLoadResult SaveOrLoad(const char *filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded = true);
|
||||
void WaitTillSaved();
|
||||
@@ -171,7 +171,7 @@ enum VarTypes {
|
||||
SLE_INT64 = SLE_FILE_I64 | SLE_VAR_I64,
|
||||
SLE_UINT64 = SLE_FILE_U64 | SLE_VAR_U64,
|
||||
SLE_CHAR = SLE_FILE_I8 | SLE_VAR_CHAR,
|
||||
SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U16,
|
||||
SLE_STRINGID = SLE_FILE_STRINGID | SLE_VAR_U32,
|
||||
SLE_STRINGBUF = SLE_FILE_STRING | SLE_VAR_STRB,
|
||||
SLE_STRINGBQUOTE = SLE_FILE_STRING | SLE_VAR_STRBQ,
|
||||
SLE_STRING = SLE_FILE_STRING | SLE_VAR_STR,
|
||||
@@ -207,6 +207,7 @@ enum SaveLoadTypes {
|
||||
SL_LST = 4, ///< Save/load a list.
|
||||
SL_DEQ = 5, ///< Save/load a deque.
|
||||
SL_VEC = 6, ///< Save/load a vector.
|
||||
SL_STDSTR = 7, ///< Save/load a std::string.
|
||||
/* non-normal save-load types */
|
||||
SL_WRITEBYTE = 8,
|
||||
SL_VEH_INCLUDE = 9,
|
||||
@@ -300,6 +301,18 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
#define SLE_CONDSTR_X(base, variable, type, length, from, to, extver) SLE_GENERAL_X(SL_STR, base, variable, type, length, from, to, extver)
|
||||
#define SLE_CONDSTR(base, variable, type, length, from, to) SLE_CONDSTR_X(base, variable, type, length, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a std::string in some savegame versions.
|
||||
* @param base Name of the class or struct containing the string.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
* @param from First savegame version that has the string.
|
||||
* @param to Last savegame version that has the string.
|
||||
* @param extver SlXvFeatureTest to test (along with from and to) which savegames have the field
|
||||
*/
|
||||
#define SLE_CONDSTDSTR_X(base, variable, type, from, to, extver) SLE_GENERAL_X(SL_STDSTR, base, variable, type, 0, from, to, extver)
|
||||
#define SLE_CONDSTDSTR(base, variable, type, from, to) SLE_CONDSTDSTR_X(base, variable, type, from, to, SlXvFeatureTest())
|
||||
|
||||
/**
|
||||
* Storage of a list in some savegame versions.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
@@ -370,6 +383,14 @@ typedef SaveLoad SaveLoadGlobVarList;
|
||||
*/
|
||||
#define SLE_STR(base, variable, type, length) SLE_CONDSTR(base, variable, type, length, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a std::string in every savegame version.
|
||||
* @param base Name of the class or struct containing the string.
|
||||
* @param variable Name of the variable in the class or struct referenced by \a base.
|
||||
* @param type Storage of the data in memory and in the savegame.
|
||||
*/
|
||||
#define SLE_STDSTR(base, variable, type) SLE_CONDSTDSTR(base, variable, type, 0, SL_MAX_VERSION)
|
||||
|
||||
/**
|
||||
* Storage of a list in every savegame version.
|
||||
* @param base Name of the class or struct containing the list.
|
||||
|
@@ -325,6 +325,10 @@ static void SwapPackets(GoodsEntry *ge)
|
||||
|
||||
static void Load_STNS()
|
||||
{
|
||||
_cargo_source_xy = 0;
|
||||
_cargo_days = 0;
|
||||
_cargo_feeder_share = 0;
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Station *st = new (index) Station();
|
||||
@@ -514,8 +518,9 @@ static void Save_STNN()
|
||||
|
||||
static void Load_STNN()
|
||||
{
|
||||
int index;
|
||||
_num_flows = 0;
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
bool waypoint = (SlReadByte() & FACIL_WAYPOINT) != 0;
|
||||
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
#include "../stdafx.h"
|
||||
#include "../string_func.h"
|
||||
#include "../strings_func.h"
|
||||
#include "saveload_internal.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
@@ -60,7 +61,7 @@ char *_old_name_array = NULL;
|
||||
char *CopyFromOldName(StringID id)
|
||||
{
|
||||
/* Is this name an (old) custom name? */
|
||||
if (GB(id, 11, 5) != 15) return NULL;
|
||||
if (GetStringTab(id) != TEXT_TAB_OLD_CUSTOM) return NULL;
|
||||
|
||||
if (IsSavegameVersionBefore(37)) {
|
||||
/* Allow for expansion when converted to UTF-8. */
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "../town.h"
|
||||
#include "../landscape.h"
|
||||
#include "../subsidy_func.h"
|
||||
#include "../strings_func.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "newgrf_sl.h"
|
||||
@@ -285,7 +286,7 @@ static void Load_TOWN()
|
||||
SlObject(&t->received[i], _town_received_desc);
|
||||
}
|
||||
|
||||
if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1) && GB(t->townnametype, 11, 5) != 15) {
|
||||
if (t->townnamegrfid == 0 && !IsInsideMM(t->townnametype, SPECSTR_TOWNNAME_START, SPECSTR_TOWNNAME_LAST + 1) && GetStringTab(t->townnametype) != TEXT_TAB_OLD_CUSTOM) {
|
||||
SlErrorCorrupt("Invalid town name generator");
|
||||
}
|
||||
|
||||
|
@@ -375,6 +375,8 @@ void AfterLoadVehicles(bool part_of_load)
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
assert(v->first != NULL);
|
||||
|
||||
v->trip_occupancy = CalcPercentVehicleFilled(v, NULL);
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN: {
|
||||
Train *t = Train::From(v);
|
||||
|
Reference in New Issue
Block a user