Update to 12.0-beta1
This commit is contained in:
+265
-238
@@ -8,6 +8,10 @@
|
||||
/** @file company_sl.cpp Code handling saving and loading of company data */
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "compat/company_sl_compat.h"
|
||||
|
||||
#include "../company_func.h"
|
||||
#include "../company_manager_face.h"
|
||||
#include "../fios.h"
|
||||
@@ -16,8 +20,6 @@
|
||||
#include "../station_base.h"
|
||||
#include "../strings_func.h"
|
||||
|
||||
#include "saveload.h"
|
||||
|
||||
#include "table/strings.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
@@ -128,7 +130,7 @@ void AfterLoadCompanyStats()
|
||||
}
|
||||
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
for (RoadTramType rtt : _roadtramtypes) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(IsRoadDepot(tile) ? GetTileOwner(tile) : GetRoadOwner(tile, rtt));
|
||||
@@ -151,7 +153,7 @@ void AfterLoadCompanyStats()
|
||||
case STATION_BUS:
|
||||
case STATION_TRUCK: {
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
for (RoadTramType rtt : _roadtramtypes) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rtt));
|
||||
@@ -209,7 +211,7 @@ void AfterLoadCompanyStats()
|
||||
|
||||
case TRANSPORT_ROAD: {
|
||||
/* Iterate all present road types as each can have a different owner. */
|
||||
FOR_ALL_ROADTRAMTYPES(rtt) {
|
||||
for (RoadTramType rtt : _roadtramtypes) {
|
||||
RoadType rt = GetRoadType(tile, rtt);
|
||||
if (rt == INVALID_ROADTYPE) continue;
|
||||
c = Company::GetIfValid(GetRoadOwner(tile, rtt));
|
||||
@@ -236,7 +238,207 @@ void AfterLoadCompanyStats()
|
||||
}
|
||||
}
|
||||
|
||||
/* We do need to read this single value, as the bigger it gets, the more data is stored */
|
||||
struct CompanyOldAI {
|
||||
uint8 num_build_rec;
|
||||
};
|
||||
|
||||
class SlCompanyOldAIBuildRec : public DefaultSaveLoadHandler<SlCompanyOldAIBuildRec, CompanyOldAI> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {{}}; // Needed to keep DefaultSaveLoadHandler happy.
|
||||
inline const static SaveLoadCompatTable compat_description = _company_old_ai_buildrec_compat;
|
||||
|
||||
SaveLoadTable GetDescription() const override { return {}; }
|
||||
|
||||
void Load(CompanyOldAI *old_ai) const override
|
||||
{
|
||||
for (int i = 0; i != old_ai->num_build_rec; i++) {
|
||||
SlObject(nullptr, this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyOldAI *old_ai) const override { this->Load(old_ai); }
|
||||
};
|
||||
|
||||
class SlCompanyOldAI : public DefaultSaveLoadHandler<SlCompanyOldAI, CompanyProperties> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107),
|
||||
SLEG_STRUCTLIST("buildrec", SlCompanyOldAIBuildRec),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _company_old_ai_compat;
|
||||
|
||||
void Load(CompanyProperties *c) const override
|
||||
{
|
||||
if (!c->is_ai) return;
|
||||
|
||||
CompanyOldAI old_ai;
|
||||
SlObject(&old_ai, this->GetLoadDescription());
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
|
||||
};
|
||||
|
||||
class SlCompanySettings : public DefaultSaveLoadHandler<SlCompanySettings, CompanyProperties> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
/* Engine renewal settings */
|
||||
SLE_CONDREF(CompanyProperties, engine_renew_list, REF_ENGINE_RENEWS, SLV_19, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.engine_renew_money, SLE_UINT32, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.renew_keep_length, SLE_BOOL, SLV_2, SL_MAX_VERSION),
|
||||
|
||||
/* Default vehicle settings */
|
||||
SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ispercent, SLE_BOOL, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_trains, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _company_settings_compat;
|
||||
|
||||
void Save(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(c, this->GetDescription());
|
||||
}
|
||||
|
||||
void Load(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(c, this->GetLoadDescription());
|
||||
}
|
||||
|
||||
void FixPointers(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(c, this->GetDescription());
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
|
||||
};
|
||||
|
||||
class SlCompanyEconomy : public DefaultSaveLoadHandler<SlCompanyEconomy, CompanyProperties> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
|
||||
SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, SL_MIN_VERSION, SLV_170),
|
||||
SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, SLV_170, SLV_EXTEND_CARGOTYPES),
|
||||
SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
|
||||
SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _company_economy_compat;
|
||||
|
||||
void Save(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(&c->cur_economy, this->GetDescription());
|
||||
}
|
||||
|
||||
void Load(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(&c->cur_economy, this->GetLoadDescription());
|
||||
}
|
||||
|
||||
void FixPointers(CompanyProperties *c) const override
|
||||
{
|
||||
SlObject(&c->cur_economy, this->GetDescription());
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
|
||||
};
|
||||
|
||||
class SlCompanyOldEconomy : public SlCompanyEconomy {
|
||||
public:
|
||||
void Save(CompanyProperties *c) const override
|
||||
{
|
||||
SlSetStructListLength(c->num_valid_stat_ent);
|
||||
for (int i = 0; i < c->num_valid_stat_ent; i++) {
|
||||
SlObject(&c->old_economy[i], this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(CompanyProperties *c) const override
|
||||
{
|
||||
if (!IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) {
|
||||
c->num_valid_stat_ent = (uint8)SlGetStructListLength(UINT8_MAX);
|
||||
}
|
||||
if (c->num_valid_stat_ent > lengthof(c->old_economy)) SlErrorCorrupt("Too many old economy entries");
|
||||
|
||||
for (int i = 0; i < c->num_valid_stat_ent; i++) {
|
||||
SlObject(&c->old_economy[i], this->GetLoadDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
|
||||
};
|
||||
|
||||
class SlCompanyLiveries : public DefaultSaveLoadHandler<SlCompanyLiveries, CompanyProperties> {
|
||||
public:
|
||||
inline static const SaveLoad description[] = {
|
||||
SLE_CONDVAR(Livery, in_use, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
};
|
||||
inline const static SaveLoadCompatTable compat_description = _company_liveries_compat;
|
||||
|
||||
/**
|
||||
* Get the number of liveries used by this savegame version.
|
||||
* @return The number of liveries used by this savegame version.
|
||||
*/
|
||||
size_t GetNumLiveries() const
|
||||
{
|
||||
if (IsSavegameVersionBefore(SLV_63)) return LS_END - 4;
|
||||
if (IsSavegameVersionBefore(SLV_85)) return LS_END - 2;
|
||||
if (IsSavegameVersionBefore(SLV_SAVELOAD_LIST_LENGTH)) return LS_END;
|
||||
/* Read from the savegame how long the list is. */
|
||||
return SlGetStructListLength(LS_END);
|
||||
}
|
||||
|
||||
void Save(CompanyProperties *c) const override
|
||||
{
|
||||
SlSetStructListLength(LS_END);
|
||||
for (int i = 0; i < LS_END; i++) {
|
||||
SlObject(&c->livery[i], this->GetDescription());
|
||||
}
|
||||
}
|
||||
|
||||
void Load(CompanyProperties *c) const override
|
||||
{
|
||||
size_t num_liveries = this->GetNumLiveries();
|
||||
bool update_in_use = IsSavegameVersionBefore(SLV_GROUP_LIVERIES);
|
||||
|
||||
for (size_t i = 0; i < num_liveries; i++) {
|
||||
SlObject(&c->livery[i], this->GetLoadDescription());
|
||||
if (update_in_use && i != LS_DEFAULT) {
|
||||
if (c->livery[i].in_use == 0) {
|
||||
c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
|
||||
c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
|
||||
} else {
|
||||
c->livery[i].in_use = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_85)) {
|
||||
/* 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]));
|
||||
c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
|
||||
c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_63)) {
|
||||
/* Copy bus/truck liveries over to trams */
|
||||
c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
|
||||
c->livery[LS_FREIGHT_TRAM] = c->livery[LS_TRUCK];
|
||||
}
|
||||
}
|
||||
|
||||
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
|
||||
};
|
||||
|
||||
/* Save/load of companies */
|
||||
static const SaveLoad _company_desc[] = {
|
||||
@@ -259,11 +461,8 @@ static const SaveLoad _company_desc[] = {
|
||||
|
||||
SLE_VAR(CompanyProperties, colour, SLE_UINT8),
|
||||
SLE_VAR(CompanyProperties, money_fraction, SLE_UINT8),
|
||||
SLE_CONDNULL(1, SL_MIN_VERSION, SLV_58), ///< avail_railtypes
|
||||
SLE_VAR(CompanyProperties, block_preview, SLE_UINT8),
|
||||
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_94), ///< cargo_types
|
||||
SLE_CONDNULL(4, SLV_94, SLV_170), ///< cargo_types
|
||||
SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDVAR(CompanyProperties, location_of_HQ, SLE_UINT32, SLV_6, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, last_build_coordinate, SLE_FILE_U16 | SLE_VAR_U32, SL_MIN_VERSION, SLV_6),
|
||||
@@ -273,7 +472,7 @@ static const SaveLoad _company_desc[] = {
|
||||
|
||||
SLE_ARR(CompanyProperties, share_owners, SLE_UINT8, 4),
|
||||
|
||||
SLE_VAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8),
|
||||
SLE_CONDVAR(CompanyProperties, num_valid_stat_ent, SLE_UINT8, SL_MIN_VERSION, SLV_SAVELOAD_LIST_LENGTH),
|
||||
|
||||
SLE_VAR(CompanyProperties, months_of_bankruptcy, SLE_UINT8),
|
||||
SLE_CONDVAR(CompanyProperties, bankrupt_asked, SLE_FILE_U8 | SLE_VAR_U16, SL_MIN_VERSION, SLV_104),
|
||||
@@ -287,257 +486,85 @@ static const SaveLoad _company_desc[] = {
|
||||
SLE_CONDARR(CompanyProperties, yearly_expenses, SLE_INT64, 3 * 13, SLV_2, SL_MAX_VERSION),
|
||||
|
||||
SLE_CONDVAR(CompanyProperties, is_ai, SLE_BOOL, SLV_2, SL_MAX_VERSION),
|
||||
SLE_CONDNULL(1, SLV_107, SLV_112), ///< is_noai
|
||||
SLE_CONDNULL(1, SLV_4, SLV_100),
|
||||
|
||||
SLE_CONDVAR(CompanyProperties, terraform_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, clear_limit, SLE_UINT32, SLV_156, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyProperties, tree_limit, SLE_UINT32, SLV_175, SL_MAX_VERSION),
|
||||
|
||||
SLE_END()
|
||||
SLEG_STRUCT("settings", SlCompanySettings),
|
||||
SLEG_CONDSTRUCT("old_ai", SlCompanyOldAI, SL_MIN_VERSION, SLV_107),
|
||||
SLEG_STRUCT("cur_economy", SlCompanyEconomy),
|
||||
SLEG_STRUCTLIST("old_economy", SlCompanyOldEconomy),
|
||||
SLEG_CONDSTRUCTLIST("liveries", SlCompanyLiveries, SLV_34, SL_MAX_VERSION),
|
||||
};
|
||||
|
||||
static const SaveLoad _company_settings_desc[] = {
|
||||
/* Engine renewal settings */
|
||||
SLE_CONDNULL(512, SLV_16, SLV_19),
|
||||
SLE_CONDREF(Company, engine_renew_list, REF_ENGINE_RENEWS, SLV_19, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.engine_renew, SLE_BOOL, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.engine_renew_months, SLE_INT16, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.engine_renew_money, SLE_UINT32, SLV_16, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.renew_keep_length, SLE_BOOL, SLV_2, SL_MAX_VERSION),
|
||||
struct PLYRChunkHandler : ChunkHandler {
|
||||
PLYRChunkHandler() : ChunkHandler('PLYR', CH_TABLE) {}
|
||||
|
||||
/* Default vehicle settings */
|
||||
SLE_CONDVAR(Company, settings.vehicle.servint_ispercent, SLE_BOOL, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.vehicle.servint_trains, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.vehicle.servint_roadveh, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.vehicle.servint_aircraft, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Company, settings.vehicle.servint_ships, SLE_UINT16, SLV_120, SL_MAX_VERSION),
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(_company_desc);
|
||||
|
||||
SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad _company_settings_skip_desc[] = {
|
||||
/* Engine renewal settings */
|
||||
SLE_CONDNULL(512, SLV_16, SLV_19),
|
||||
SLE_CONDNULL(2, SLV_19, SLV_69), // engine_renew_list
|
||||
SLE_CONDNULL(4, SLV_69, SL_MAX_VERSION), // engine_renew_list
|
||||
SLE_CONDNULL(1, SLV_16, SL_MAX_VERSION), // settings.engine_renew
|
||||
SLE_CONDNULL(2, SLV_16, SL_MAX_VERSION), // settings.engine_renew_months
|
||||
SLE_CONDNULL(4, SLV_16, SL_MAX_VERSION), // settings.engine_renew_money
|
||||
SLE_CONDNULL(1, SLV_2, SL_MAX_VERSION), // settings.renew_keep_length
|
||||
|
||||
/* Default vehicle settings */
|
||||
SLE_CONDNULL(1, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_ispercent
|
||||
SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_trains
|
||||
SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_roadveh
|
||||
SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_aircraft
|
||||
SLE_CONDNULL(2, SLV_120, SL_MAX_VERSION), // settings.vehicle.servint_ships
|
||||
|
||||
SLE_CONDNULL(63, SLV_2, SLV_144), // old reserved space
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad _company_economy_desc[] = {
|
||||
/* these were changed to 64-bit in savegame format 2 */
|
||||
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, income, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, expenses, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_FILE_I32 | SLE_VAR_I64, SL_MIN_VERSION, SLV_2),
|
||||
SLE_CONDVAR(CompanyEconomyEntry, company_value, SLE_INT64, SLV_2, SL_MAX_VERSION),
|
||||
|
||||
SLE_CONDVAR(CompanyEconomyEntry, delivered_cargo[NUM_CARGO - 1], SLE_INT32, SL_MIN_VERSION, SLV_170),
|
||||
SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, 32, SLV_170, SLV_EXTEND_CARGOTYPES),
|
||||
SLE_CONDARR(CompanyEconomyEntry, delivered_cargo, SLE_UINT32, NUM_CARGO, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION),
|
||||
SLE_VAR(CompanyEconomyEntry, performance_history, SLE_INT32),
|
||||
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
/* We do need to read this single value, as the bigger it gets, the more data is stored */
|
||||
struct CompanyOldAI {
|
||||
uint8 num_build_rec;
|
||||
};
|
||||
|
||||
static const SaveLoad _company_ai_desc[] = {
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_13),
|
||||
SLE_CONDNULL(4, SLV_13, SLV_107),
|
||||
SLE_CONDNULL(8, SL_MIN_VERSION, SLV_107),
|
||||
SLE_CONDVAR(CompanyOldAI, num_build_rec, SLE_UINT8, SL_MIN_VERSION, SLV_107),
|
||||
SLE_CONDNULL(3, SL_MIN_VERSION, SLV_107),
|
||||
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107),
|
||||
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_107),
|
||||
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_69),
|
||||
SLE_CONDNULL(4, SLV_69, SLV_107),
|
||||
|
||||
SLE_CONDNULL(18, SL_MIN_VERSION, SLV_107),
|
||||
SLE_CONDNULL(20, SL_MIN_VERSION, SLV_107),
|
||||
SLE_CONDNULL(32, SL_MIN_VERSION, SLV_107),
|
||||
|
||||
SLE_CONDNULL(64, SLV_2, SLV_107),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad _company_ai_build_rec_desc[] = {
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(2, SL_MIN_VERSION, SLV_6),
|
||||
SLE_CONDNULL(4, SLV_6, SLV_107),
|
||||
SLE_CONDNULL(8, SL_MIN_VERSION, SLV_107),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static const SaveLoad _company_livery_desc[] = {
|
||||
SLE_CONDVAR(Livery, in_use, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Livery, colour1, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
SLE_CONDVAR(Livery, colour2, SLE_UINT8, SLV_34, SL_MAX_VERSION),
|
||||
SLE_END()
|
||||
};
|
||||
|
||||
static void SaveLoad_PLYR_common(Company *c, CompanyProperties *cprops)
|
||||
{
|
||||
int i;
|
||||
|
||||
SlObject(cprops, _company_desc);
|
||||
if (c != nullptr) {
|
||||
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 */
|
||||
if (IsSavegameVersionBefore(SLV_107) && cprops->is_ai) {
|
||||
CompanyOldAI old_ai;
|
||||
char nothing;
|
||||
|
||||
SlObject(&old_ai, _company_ai_desc);
|
||||
for (i = 0; i != old_ai.num_build_rec; i++) {
|
||||
SlObject(¬hing, _company_ai_build_rec_desc);
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlSetArrayIndex(c->index);
|
||||
SlObject(c, _company_desc);
|
||||
}
|
||||
}
|
||||
|
||||
/* Write economy */
|
||||
SlObject(&cprops->cur_economy, _company_economy_desc);
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
|
||||
|
||||
/* Write old economy entries. */
|
||||
if (cprops->num_valid_stat_ent > lengthof(cprops->old_economy)) SlErrorCorrupt("Too many old economy entries");
|
||||
for (i = 0; i < cprops->num_valid_stat_ent; i++) {
|
||||
SlObject(&cprops->old_economy[i], _company_economy_desc);
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Company *c = new (index) Company();
|
||||
SlObject(c, slt);
|
||||
_company_colours[index] = (Colours)c->colour;
|
||||
}
|
||||
}
|
||||
|
||||
/* 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 != nullptr) {
|
||||
for (i = 0; i < num_liveries; i++) {
|
||||
SlObject(&c->livery[i], _company_livery_desc);
|
||||
if (update_in_use && i != LS_DEFAULT) {
|
||||
if (c->livery[i].in_use == 0) {
|
||||
c->livery[i].colour1 = c->livery[LS_DEFAULT].colour1;
|
||||
c->livery[i].colour2 = c->livery[LS_DEFAULT].colour2;
|
||||
} else {
|
||||
c->livery[i].in_use = 3;
|
||||
|
||||
void LoadCheck(size_t) const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlCompatTableHeader(_company_desc, _company_sl_compat);
|
||||
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
CompanyProperties *cprops = new CompanyProperties();
|
||||
SlObject(cprops, slt);
|
||||
|
||||
/* We do not load old custom names */
|
||||
if (IsSavegameVersionBefore(SLV_84)) {
|
||||
if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (num_liveries < LS_END) {
|
||||
/* 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]));
|
||||
c->livery[LS_PASSENGER_WAGON_MONORAIL] = c->livery[LS_MONORAIL];
|
||||
c->livery[LS_PASSENGER_WAGON_MAGLEV] = c->livery[LS_MAGLEV];
|
||||
}
|
||||
|
||||
if (num_liveries == LS_END - 4) {
|
||||
/* Copy bus/truck liveries over to trams */
|
||||
c->livery[LS_PASSENGER_TRAM] = c->livery[LS_BUS];
|
||||
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()
|
||||
{
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlSetArrayIndex(c->index);
|
||||
SlAutolength((AutolengthProc*)SaveLoad_PLYR, c);
|
||||
}
|
||||
}
|
||||
|
||||
static void Load_PLYR()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
Company *c = new (index) Company();
|
||||
SaveLoad_PLYR(c);
|
||||
_company_colours[index] = (Colours)c->colour;
|
||||
}
|
||||
}
|
||||
|
||||
static void Check_PLYR()
|
||||
{
|
||||
int index;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
CompanyProperties *cprops = new CompanyProperties();
|
||||
SaveLoad_PLYR_common(nullptr, cprops);
|
||||
|
||||
/* We do not load old custom names */
|
||||
if (IsSavegameVersionBefore(SLV_84)) {
|
||||
if (GetStringTab(cprops->name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (GetStringTab(cprops->president_name_1) == TEXT_TAB_OLD_CUSTOM) {
|
||||
cprops->president_name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
}
|
||||
|
||||
if (cprops->name.empty() && !IsInsideMM(cprops->name_1, SPECSTR_COMPANY_NAME_START, SPECSTR_COMPANY_NAME_LAST + 1) &&
|
||||
if (cprops->name.empty() && !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) {
|
||||
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
cprops->name_1 = STR_GAME_SAVELOAD_NOT_AVAILABLE;
|
||||
}
|
||||
|
||||
if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
|
||||
}
|
||||
|
||||
if (!_load_check_data.companies.Insert(index, cprops)) delete cprops;
|
||||
}
|
||||
}
|
||||
|
||||
static void Ptrs_PLYR()
|
||||
{
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlObject(c, _company_settings_desc);
|
||||
void FixPointers() const override
|
||||
{
|
||||
for (Company *c : Company::Iterate()) {
|
||||
SlObject(c, _company_desc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern const ChunkHandler _company_chunk_handlers[] = {
|
||||
{ 'PLYR', Save_PLYR, Load_PLYR, Ptrs_PLYR, Check_PLYR, CH_ARRAY | CH_LAST},
|
||||
};
|
||||
|
||||
static const PLYRChunkHandler PLYR;
|
||||
static const ChunkHandlerRef company_chunk_handlers[] = {
|
||||
PLYR,
|
||||
};
|
||||
|
||||
extern const ChunkHandlerTable _company_chunk_handlers(company_chunk_handlers);
|
||||
|
||||
Reference in New Issue
Block a user