@@ -197,49 +197,48 @@ protected:
uint16 max_offset; ///< what is the length of the original entity's array of specs
uint16 max_new_entities; ///< what is the amount of entities, old and new summed
uint16 invalid_ID; ///< ID used to detected invalid entities;
virtual bool CheckValidNewID(uint16 testid) { return true; }
public:
EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience
OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
virtual ~OverrideManagerBase();
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);
uint32 GetGRFID(uint16 entity_id) const;
uint16 GetSubstituteID(uint16 entity_id) const;
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
inline uint16 GetMaxMapping() const { return max_new_entities; }
inline uint16 GetMaxOffset() const { return max_offset; }
inline bool IsValidID(uint16 entity_id) const { return entity_overrides[entity_id] != invalid_ID; }
};
struct HouseSpec;
class HouseOverrideManager : public OverrideManagerBase {
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
OverrideManagerBase(offset, maximum, invalid) {}
void SetEntitySpec(const HouseSpec *hs);
struct IndustrySpec;
class IndustryOverrideManager : public OverrideManagerBase {
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id) override;
uint16 GetID(uint8 grf_local_id, uint32 grfid) const override;
void SetEntitySpec(IndustrySpec *inds);
@@ -9,49 +9,50 @@
#include "../stdafx.h"
#include "../fios.h"
#include "saveload.h"
#include "newgrf_sl.h"
#include "../safeguards.h"
/** 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_END()
/**
* Save a GRF ID + local id -> OpenTTD's id mapping.
* @param mapping The mapping to save.
*/
void Save_NewGRFMapping(const OverrideManagerBase &mapping)
{
for (uint i = 0; i < mapping.GetMaxMapping(); i++) {
if (!mapping.IsValidID(i)) continue;
if (mapping.mapping_ID[i].grfid == 0 &&
mapping.mapping_ID[i].entity_id == 0) continue;
SlSetArrayIndex(i);
SlObject(&mapping.mapping_ID[i], _newgrf_mapping_desc);
}
* Load a GRF ID + local id -> OpenTTD's id mapping.
* @param mapping The mapping to load.
void Load_NewGRFMapping(OverrideManagerBase &mapping)
/* Clear the current mapping stored.
* This will create the manager if ever it is not yet done */
mapping.ResetMapping();
uint max_id = mapping.GetMaxMapping();
int index;
while ((index = SlIterateArray()) != -1) {
if ((uint)index >= max_id) SlErrorCorrupt("Too many NewGRF entity mappings");
SlObject(&mapping.mapping_ID[index], _newgrf_mapping_desc);
Status change: