mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19980) -Add: Load some general data from savegames on SL_LOAD_CHECK.
This commit is contained in:
parent
e95518c8e9
commit
16618e6f16
|
@ -14,12 +14,16 @@
|
||||||
|
|
||||||
#include "strings_type.h"
|
#include "strings_type.h"
|
||||||
#include "core/smallvec_type.hpp"
|
#include "core/smallvec_type.hpp"
|
||||||
|
#include "core/smallmap_type.hpp"
|
||||||
#include "core/enum_type.hpp"
|
#include "core/enum_type.hpp"
|
||||||
#include "gfx_type.h"
|
#include "gfx_type.h"
|
||||||
#include "date_type.h"
|
#include "date_type.h"
|
||||||
#include "settings_type.h"
|
#include "settings_type.h"
|
||||||
|
#include "company_base.h"
|
||||||
|
|
||||||
|
|
||||||
|
typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for loading in mode SL_LOAD_CHECK.
|
* Container for loading in mode SL_LOAD_CHECK.
|
||||||
*/
|
*/
|
||||||
|
@ -33,6 +37,8 @@ struct LoadCheckData {
|
||||||
|
|
||||||
GameSettings settings;
|
GameSettings settings;
|
||||||
|
|
||||||
|
CompanyPropertiesMap companies; ///< Company information.
|
||||||
|
|
||||||
LoadCheckData() : error_data(NULL)
|
LoadCheckData() : error_data(NULL)
|
||||||
{
|
{
|
||||||
this->Clear();
|
this->Clear();
|
||||||
|
|
|
@ -48,6 +48,12 @@ void LoadCheckData::Clear()
|
||||||
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
||||||
this->current_date = 0;
|
this->current_date = 0;
|
||||||
memset(&this->settings, 0, sizeof(this->settings));
|
memset(&this->settings, 0, sizeof(this->settings));
|
||||||
|
|
||||||
|
const CompanyPropertiesMap::iterator end = this->companies.End();
|
||||||
|
for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
|
||||||
|
delete it->second;
|
||||||
|
}
|
||||||
|
companies.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3334,6 +3334,7 @@ STR_GAME_SAVELOAD_ERROR_TOO_NEW_SAVEGAME :Savegame is mad
|
||||||
STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE :File not readable
|
STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE :File not readable
|
||||||
STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE :File not writeable
|
STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE :File not writeable
|
||||||
STR_GAME_SAVELOAD_ERROR_DATA_INTEGRITY_CHECK_FAILED :Data integrity check failed
|
STR_GAME_SAVELOAD_ERROR_DATA_INTEGRITY_CHECK_FAILED :Data integrity check failed
|
||||||
|
STR_GAME_SAVELOAD_NOT_AVAILABLE :<not available>
|
||||||
STR_WARNING_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed.
|
STR_WARNING_LOADGAME_REMOVED_TRAMS :{WHITE}Game was saved in version without tram support. All trams have been removed.
|
||||||
|
|
||||||
# Map generation messages
|
# Map generation messages
|
||||||
|
|
|
@ -13,9 +13,12 @@
|
||||||
#include "../company_base.h"
|
#include "../company_base.h"
|
||||||
#include "../company_func.h"
|
#include "../company_func.h"
|
||||||
#include "../company_manager_face.h"
|
#include "../company_manager_face.h"
|
||||||
|
#include "../fios.h"
|
||||||
|
|
||||||
#include "saveload.h"
|
#include "saveload.h"
|
||||||
|
|
||||||
|
#include "table/strings.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an old company manager's face format to the new company manager's face format
|
* Converts an old company manager's face format to the new company manager's face format
|
||||||
*
|
*
|
||||||
|
@ -163,6 +166,29 @@ static const SaveLoad _company_settings_desc[] = {
|
||||||
SLE_END()
|
SLE_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const SaveLoad _company_settings_skip_desc[] = {
|
||||||
|
/* Engine renewal settings */
|
||||||
|
SLE_CONDNULL(512, 16, 18),
|
||||||
|
SLE_CONDNULL(2, 19, 68), // engine_renew_list
|
||||||
|
SLE_CONDNULL(4, 69, SL_MAX_VERSION), // engine_renew_list
|
||||||
|
SLE_CONDNULL(1, 16, SL_MAX_VERSION), // settings.engine_renew
|
||||||
|
SLE_CONDNULL(2, 16, SL_MAX_VERSION), // settings.engine_renew_months
|
||||||
|
SLE_CONDNULL(4, 16, SL_MAX_VERSION), // settings.engine_renew_money
|
||||||
|
SLE_CONDNULL(1, 2, SL_MAX_VERSION), // settings.renew_keep_length
|
||||||
|
|
||||||
|
/* Default vehicle settings */
|
||||||
|
SLE_CONDNULL(1, 120, SL_MAX_VERSION), // settings.vehicle.servint_ispercent
|
||||||
|
SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_trains
|
||||||
|
SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_roadveh
|
||||||
|
SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_aircraft
|
||||||
|
SLE_CONDNULL(2, 120, SL_MAX_VERSION), // settings.vehicle.servint_ships
|
||||||
|
|
||||||
|
/* Reserve extra space in savegame here. (currently 63 bytes) */
|
||||||
|
SLE_CONDNULL(63, 2, SL_MAX_VERSION),
|
||||||
|
|
||||||
|
SLE_END()
|
||||||
|
};
|
||||||
|
|
||||||
static const SaveLoad _company_economy_desc[] = {
|
static const SaveLoad _company_economy_desc[] = {
|
||||||
/* these were changed to 64-bit in savegame format 2 */
|
/* these were changed to 64-bit in savegame format 2 */
|
||||||
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
|
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, 0, 1),
|
||||||
|
@ -230,15 +256,20 @@ static const SaveLoad _company_livery_desc[] = {
|
||||||
SLE_END()
|
SLE_END()
|
||||||
};
|
};
|
||||||
|
|
||||||
static void SaveLoad_PLYR(Company *c)
|
static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
SlObject((CompanyProperties *)c, _company_desc);
|
SlObject(cprops, _company_desc);
|
||||||
SlObject(c, _company_settings_desc);
|
if (c != NULL) {
|
||||||
|
SlObject(c, _company_settings_desc);
|
||||||
|
} else {
|
||||||
|
char nothing;
|
||||||
|
SlObject(¬hing, _company_settings_skip_desc);
|
||||||
|
}
|
||||||
|
|
||||||
/* Keep backwards compatible for savegames, so load the old AI block */
|
/* Keep backwards compatible for savegames, so load the old AI block */
|
||||||
if (CheckSavegameVersion(107) && c->is_ai) {
|
if (CheckSavegameVersion(107) && cprops->is_ai) {
|
||||||
CompanyOldAI old_ai;
|
CompanyOldAI old_ai;
|
||||||
char nothing;
|
char nothing;
|
||||||
|
|
||||||
|
@ -249,33 +280,46 @@ static void SaveLoad_PLYR(Company *c)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write economy */
|
/* Write economy */
|
||||||
SlObject(&c->cur_economy, _company_economy_desc);
|
SlObject(&cprops->cur_economy, _company_economy_desc);
|
||||||
|
|
||||||
/* Write old economy entries. */
|
/* Write old economy entries. */
|
||||||
for (i = 0; i < c->num_valid_stat_ent; i++) {
|
for (i = 0; i < cprops->num_valid_stat_ent; i++) {
|
||||||
SlObject(&c->old_economy[i], _company_economy_desc);
|
SlObject(&cprops->old_economy[i], _company_economy_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write each livery entry. */
|
/* Write each livery entry. */
|
||||||
int num_liveries = CheckSavegameVersion(63) ? LS_END - 4 : (CheckSavegameVersion(85) ? LS_END - 2: LS_END);
|
int num_liveries = CheckSavegameVersion(63) ? LS_END - 4 : (CheckSavegameVersion(85) ? LS_END - 2: LS_END);
|
||||||
for (i = 0; i < num_liveries; i++) {
|
if (c != NULL) {
|
||||||
SlObject(&c->livery[i], _company_livery_desc);
|
for (i = 0; i < num_liveries; i++) {
|
||||||
}
|
SlObject(&c->livery[i], _company_livery_desc);
|
||||||
|
}
|
||||||
|
|
||||||
if (num_liveries < LS_END) {
|
if (num_liveries < LS_END) {
|
||||||
/* We want to insert some liveries somewhere in between. This means some have to be moved. */
|
/* We want to insert some liveries somewhere in between. This means some have to be moved. */
|
||||||
memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
|
memmove(&c->livery[LS_FREIGHT_WAGON], &c->livery[LS_PASSENGER_WAGON_MONORAIL], (LS_END - LS_FREIGHT_WAGON) * sizeof(c->livery[0]));
|
||||||
c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
|
c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
|
||||||
c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
|
c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (num_liveries == LS_END - 4) {
|
if (num_liveries == LS_END - 4) {
|
||||||
/* Copy bus/truck liveries over to trams */
|
/* Copy bus/truck liveries over to trams */
|
||||||
c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
|
c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
|
||||||
c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
|
c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Skip liveries */
|
||||||
|
Livery dummy_livery;
|
||||||
|
for (i = 0; i < num_liveries; i++) {
|
||||||
|
SlObject(&dummy_livery, _company_livery_desc);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SaveLoad_PLYR(Company *c)
|
||||||
|
{
|
||||||
|
SaveLoad_PLYR_common(c, c);
|
||||||
|
}
|
||||||
|
|
||||||
static void Save_PLYR()
|
static void Save_PLYR()
|
||||||
{
|
{
|
||||||
Company *c;
|
Company *c;
|
||||||
|
@ -295,15 +339,38 @@ static void Load_PLYR()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Check_PLYR()
|
||||||
|
{
|
||||||
|
int index;
|
||||||
|
while ((index = SlIterateArray()) != -1) {
|
||||||
|
CompanyProperties *cprops = new CompanyProperties();
|
||||||
|
SaveLoad_PLYR_common(NULL, cprops);
|
||||||
|
|
||||||
|
/* We do not load old custom names */
|
||||||
|
if (CheckSavegameVersion(84))
|
||||||
|
{
|
||||||
|
if (GB(cprops->name_1, 11, 5) == 15) {
|
||||||
|
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (GB(cprops->president_name_1, 11, 5) == 15) {
|
||||||
|
cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void Ptrs_PLYR()
|
static void Ptrs_PLYR()
|
||||||
{
|
{
|
||||||
Company *c;
|
Company *c;
|
||||||
FOR_ALL_COMPANIES(c) {
|
FOR_ALL_COMPANIES(c) {
|
||||||
SlObject(c, _company_desc);
|
SlObject(c, _company_settings_desc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern const ChunkHandler _company_chunk_handlers[] = {
|
extern const ChunkHandler _company_chunk_handlers[] = {
|
||||||
{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, NULL, CH_ARRAY | CH_LAST},
|
{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue