diff --git a/src/newgrf_commons.cpp b/src/newgrf_commons.cpp index cd718ec792..296100a09b 100644 --- a/src/newgrf_commons.cpp +++ b/src/newgrf_commons.cpp @@ -59,7 +59,7 @@ OverrideManagerBase::OverrideManagerBase(uint16 offset, uint16 maximum, uint16 i * @param grfid ID of the grf file * @param entity_type original entity type */ -void OverrideManagerBase::Add(uint8 local_id, uint32 grfid, uint entity_type) +void OverrideManagerBase::Add(uint16 local_id, uint32 grfid, uint entity_type) { assert(entity_type < this->max_offset); /* An override can be set only once */ @@ -87,7 +87,7 @@ void OverrideManagerBase::ResetOverride() * @param grfid ID of the grf file * @return the ID of the candidate, of the Invalid flag item ID */ -uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const +uint16 OverrideManagerBase::GetID(uint16 grf_local_id, uint32 grfid) const { for (uint16 id = 0; id < this->max_entities; id++) { const EntityIDMapping *map = &this->mappings[id]; @@ -106,7 +106,7 @@ uint16 OverrideManagerBase::GetID(uint8 grf_local_id, uint32 grfid) const * @param substitute_id is the original entity from which data is copied for the new one * @return the proper usable slot id, or invalid marker if none is found */ -uint16 OverrideManagerBase::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) +uint16 OverrideManagerBase::AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id) { uint16 id = this->GetID(grf_local_id, grfid); @@ -185,7 +185,7 @@ void HouseOverrideManager::SetEntitySpec(const HouseSpec *hs) * @param grfid ID of the grf file * @return the ID of the candidate, of the Invalid flag item ID */ -uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const +uint16 IndustryOverrideManager::GetID(uint16 grf_local_id, uint32 grfid) const { uint16 id = OverrideManagerBase::GetID(grf_local_id, grfid); if (id != this->invalid_id) return id; @@ -205,7 +205,7 @@ uint16 IndustryOverrideManager::GetID(uint8 grf_local_id, uint32 grfid) const * @param substitute_id industry from which data has been copied * @return a free entity id (slotid) if ever one has been found, or Invalid_ID marker otherwise */ -uint16 IndustryOverrideManager::AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) +uint16 IndustryOverrideManager::AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id) { /* This entity hasn't been defined before, so give it an ID now. */ for (uint16 id = 0; id < this->max_entities; id++) { diff --git a/src/newgrf_commons.h b/src/newgrf_commons.h index 8d0a5bfed8..76daa10f86 100644 --- a/src/newgrf_commons.h +++ b/src/newgrf_commons.h @@ -185,8 +185,8 @@ private: */ struct EntityIDMapping { uint32 grfid; ///< The GRF ID of the file the entity belongs to - uint8 entity_id; ///< The entity ID within the GRF file - uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available + uint16 entity_id; ///< The entity ID within the GRF file + uint16 substitute_id; ///< The (original) entity ID to use if this GRF is not available }; class OverrideManagerBase { @@ -209,12 +209,12 @@ public: void ResetOverride(); void ResetMapping(); - void Add(uint8 local_id, uint32 grfid, uint entity_type); - virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); + void Add(uint16 local_id, uint32 grfid, uint entity_type); + virtual uint16 AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id); uint32 GetGRFID(uint16 entity_id) const; uint16 GetSubstituteID(uint16 entity_id) const; - virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const; + virtual uint16 GetID(uint16 grf_local_id, uint32 grfid) const; inline uint16 GetMaxMapping() const { return this->max_entities; } inline uint16 GetMaxOffset() const { return this->max_offset; } @@ -237,8 +237,8 @@ public: IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : OverrideManagerBase(offset, maximum, invalid) {} - uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) override; - uint16 GetID(uint8 grf_local_id, uint32 grfid) const override; + uint16 AddEntityID(uint16 grf_local_id, uint32 grfid, uint16 substitute_id) override; + uint16 GetID(uint16 grf_local_id, uint32 grfid) const override; void SetEntitySpec(IndustrySpec *inds); }; diff --git a/src/saveload/extended_ver_sl.cpp b/src/saveload/extended_ver_sl.cpp index 0a9f5a2fe1..8c7c46c60d 100644 --- a/src/saveload/extended_ver_sl.cpp +++ b/src/saveload/extended_ver_sl.cpp @@ -178,6 +178,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = { { XSLFI_TOWN_SETTING_OVERRIDE, XSCF_NULL, 1, 1, "town_setting_override", nullptr, nullptr, nullptr }, { XSLFI_LINKGRAPH_SPARSE_EDGES, XSCF_NULL, 1, 1, "linkgraph_sparse_edges", nullptr, nullptr, nullptr }, { XSLFI_AUX_TILE_LOOP, XSCF_NULL, 1, 1, "aux_tile_loop", nullptr, nullptr, nullptr }, + { XSLFI_NEWGRF_ENTITY_EXTRA, XSCF_NULL, 1, 1, "newgrf_entity_extra", nullptr, nullptr, nullptr }, { XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr }, { XSLFI_U64_TICK_COUNTER, XSCF_NULL, 1, 1, "u64_tick_counter", nullptr, nullptr, nullptr }, { XSLFI_LINKGRAPH_TRAVEL_TIME, XSCF_NULL, 1, 1, "linkgraph_travel_time", nullptr, nullptr, nullptr }, diff --git a/src/saveload/extended_ver_sl.h b/src/saveload/extended_ver_sl.h index 3ff95bf7ff..d63dd9a702 100644 --- a/src/saveload/extended_ver_sl.h +++ b/src/saveload/extended_ver_sl.h @@ -131,6 +131,7 @@ enum SlXvFeatureIndex { XSLFI_TOWN_SETTING_OVERRIDE, ///< Town setting overrides XSLFI_LINKGRAPH_SPARSE_EDGES, ///< Link graph edge matrix is stored in sparse format, and saved in order XSLFI_AUX_TILE_LOOP, ///< Auxiliary tile loop + XSLFI_NEWGRF_ENTITY_EXTRA, ///< NewGRF entity mappings are 16 bit XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64 XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER diff --git a/src/saveload/newgrf_sl.cpp b/src/saveload/newgrf_sl.cpp index b469e1d8e9..47244353bf 100644 --- a/src/saveload/newgrf_sl.cpp +++ b/src/saveload/newgrf_sl.cpp @@ -17,10 +17,15 @@ #include "../safeguards.h" /** Save and load the mapping between a spec and the NewGRF it came from. */ -static const SaveLoad _newgrf_mapping_desc[] = { +static const SaveLoad _newgrf_mapping_desc_old[] = { SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), - SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), - SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), + SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16), + SLE_VAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16), +}; +static const SaveLoad _newgrf_mapping_desc_new[] = { + SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), + SLE_VAR(EntityIDMapping, entity_id, SLE_UINT16), + SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT16), }; /** @@ -33,8 +38,8 @@ void Save_NewGRFMapping(const OverrideManagerBase &mapping) if (mapping.mappings[i].grfid == 0 && mapping.mappings[i].entity_id == 0) continue; SlSetArrayIndex(i); - SlSetLength(4 + 1 + 1); - SlObjectSaveFiltered(const_cast(&mapping.mappings[i]), _newgrf_mapping_desc); // _newgrf_mapping_desc has no conditionals + SlSetLength(4 + 2 + 2); + SlObjectSaveFiltered(const_cast(&mapping.mappings[i]), _newgrf_mapping_desc_new); // _newgrf_mapping_desc_new has no conditionals } } @@ -50,10 +55,12 @@ void Load_NewGRFMapping(OverrideManagerBase &mapping) uint max_id = mapping.GetMaxMapping(); + SaveLoadTable slt = SlXvIsFeaturePresent(XSLFI_NEWGRF_ENTITY_EXTRA) ? SaveLoadTable(_newgrf_mapping_desc_new) : SaveLoadTable(_newgrf_mapping_desc_old); + int index; while ((index = SlIterateArray()) != -1) { if (unlikely((uint)index >= max_id)) SlErrorCorrupt("Too many NewGRF entity mappings"); - SlObjectLoadFiltered(&mapping.mappings[index], _newgrf_mapping_desc); // _newgrf_mapping_desc has no conditionals + SlObjectLoadFiltered(&mapping.mappings[index], slt); // _newgrf_mapping_desc_old/_newgrf_mapping_desc_new has no conditionals } } diff --git a/src/saveload/upstream/newgrf_sl.cpp b/src/saveload/upstream/newgrf_sl.cpp index 4643ad9718..9a85dd9bfe 100644 --- a/src/saveload/upstream/newgrf_sl.cpp +++ b/src/saveload/upstream/newgrf_sl.cpp @@ -22,8 +22,8 @@ namespace upstream_sl { /** Save and load the mapping between a spec and the NewGRF it came from. */ static const SaveLoad _newgrf_mapping_desc[] = { SLE_VAR(EntityIDMapping, grfid, SLE_UINT32), - SLE_VAR(EntityIDMapping, entity_id, SLE_UINT8), - SLE_VAR(EntityIDMapping, substitute_id, SLE_UINT8), + SLE_VAR(EntityIDMapping, entity_id, SLE_FILE_U8 | SLE_VAR_U16), + SLE_VAR(EntityIDMapping, substitute_id, SLE_FILE_U8 | SLE_VAR_U16), }; /** @@ -31,14 +31,8 @@ static const SaveLoad _newgrf_mapping_desc[] = { */ void NewGRFMappingChunkHandler::Save() const { - SlTableHeader(_newgrf_mapping_desc); - - for (uint i = 0; i < this->mapping.GetMaxMapping(); i++) { - if (this->mapping.mappings[i].grfid == 0 && - this->mapping.mappings[i].entity_id == 0) continue; - SlSetArrayIndex(i); - SlObject(&this->mapping.mappings[i], _newgrf_mapping_desc); - } + // removed + NOT_REACHED(); } /**