Fix #12901: Savegame format of company allow lists

(cherry picked from commit c277ff121e71dcf8c2fff1e88b84d9f78fb539a6)

# Conflicts:
#	src/saveload/saveload.h
pull/737/merge
Jonathan G Rennison 1 month ago
parent 3ec25ffc9a
commit 05b55fd12f

@ -231,6 +231,38 @@ public:
void LoadCheck(CompanyProperties *c) const override { this->Load(c); }
};
class SlAllowListData : public DefaultSaveLoadHandler<SlAllowListData, CompanyProperties> {
public:
struct KeyWrapper {
std::string key;
};
inline static const SaveLoad description[] = {
SLE_SSTR(KeyWrapper, key, SLE_STR),
};
inline const static SaveLoadCompatTable compat_description = {};
void Save(CompanyProperties *cprops) const override
{
SlSetStructListLength(cprops->allow_list.size());
for (std::string &str : cprops->allow_list) {
SlObject(&str, this->GetDescription());
}
}
void Load(CompanyProperties *cprops) const override
{
size_t num_keys = SlGetStructListLength(UINT32_MAX);
cprops->allow_list.clear();
cprops->allow_list.resize(num_keys);
for (std::string &str : cprops->allow_list) {
SlObject(&str, this->GetLoadDescription());
}
}
void LoadCheck(CompanyProperties *cprops) const override { this->Load(cprops); }
};
/* Save/load of companies */
static const SaveLoad _company_desc[] = {
SLE_VAR(CompanyProperties, name_2, SLE_UINT32),
@ -241,7 +273,8 @@ static const SaveLoad _company_desc[] = {
SLE_VAR(CompanyProperties, president_name_2, SLE_UINT32),
SLE_CONDSSTR(CompanyProperties, president_name, SLE_STR | SLF_ALLOW_CONTROL, SLV_84, SL_MAX_VERSION),
SLE_CONDVECTOR(CompanyProperties, allow_list, SLE_STR, SLV_COMPANY_ALLOW_LIST, SL_MAX_VERSION),
SLE_CONDVECTOR(CompanyProperties, allow_list, SLE_STR, SLV_COMPANY_ALLOW_LIST, SLV_COMPANY_ALLOW_LIST_V2),
SLEG_CONDSTRUCTLIST("allow_list", SlAllowListData, SLV_COMPANY_ALLOW_LIST_V2, SL_MAX_VERSION),
SLE_VAR(CompanyProperties, face, SLE_UINT32),

@ -400,6 +400,7 @@ enum SaveLoadVersion : uint16_t {
SLV_COMPANY_INAUGURATED_PERIOD, ///< 339 PR#12798 Companies show the period inaugurated in wallclock mode.
SLV_ROAD_STOP_TILE_DATA, ///< 340 PR#12883 Move storage of road stop tile data, also save for road waypoints.
SLV_COMPANY_ALLOW_LIST_V2, ///< 341 PR#12908 Fixed savegame format for saving of list of client keys that are allowed to join this company.
SL_MAX_VERSION, ///< Highest possible saveload version

Loading…
Cancel
Save