glx@9624: /* $Id$ */ glx@9624: glx@9624: /** @file newgrf_commons.h This file simplyfies and embeds a common mechanism of glx@9624: * loading/saving and mapping of grf entities. glx@9624: */ glx@9624: glx@9624: #ifndef NEWGRF_COMMONS_H glx@9624: #define NEWGRF_COMMONS_H glx@9624: glx@9624: /** glx@9624: * Maps an entity id stored on the map to a GRF file. glx@9624: * Entities are objects used ingame (houses, industries, industry tiles) for glx@9624: * which we need to correlate the ids from the grf files with the ones in the glx@9624: * the savegames themselves. glx@9624: * An array of EntityIDMapping structs is saved with the savegame so glx@9624: * that those GRFs can be loaded in a different order, or removed safely. The glx@9624: * index in the array is the entity's ID stored on the map. glx@9624: * glx@9624: * The substitute ID is the ID of an original entity that should be used instead glx@9624: * if the GRF containing the new entity is not available. glx@9624: */ glx@9624: struct EntityIDMapping { glx@9624: uint32 grfid; ///< The GRF ID of the file the entity belongs to glx@9624: uint8 entity_id; ///< The entity ID within the GRF file glx@9624: uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available glx@9624: }; glx@9624: rubidium@9694: class OverrideManagerBase { glx@9624: protected: glx@9624: uint16 *entity_overrides; rubidium@9722: uint32 *grfid_overrides; glx@9624: glx@9624: uint16 max_offset; ///< what is the length of the original entity's array of specs glx@9624: uint16 max_new_entities; ///< what is the amount of entities, old and new summed glx@9624: glx@9624: uint16 invalid_ID; ///< ID used to dected invalid entities; glx@9704: virtual bool CheckValidNewID(uint16 testid) { return true; } glx@9624: glx@9624: public: glx@9624: EntityIDMapping *mapping_ID; ///< mapping of ids from grf files. Public out of convenience glx@9624: glx@9624: OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid); glx@9624: virtual ~OverrideManagerBase(); glx@9624: glx@9624: void ResetOverride(); glx@9624: void ResetMapping(); glx@9624: rubidium@9722: void Add(uint8 local_id, uint32 grfid, uint entity_type); glx@9626: virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); glx@9624: glx@9624: uint16 GetSubstituteID(byte entity_id); glx@9732: virtual uint16 GetID(uint8 grf_local_id, uint32 grfid); glx@9624: rubidium@9694: inline uint16 GetMaxMapping() { return max_new_entities; } rubidium@9694: inline uint16 GetMaxOffset() { return max_offset; } glx@9624: }; glx@9624: glx@9624: glx@9624: struct HouseSpec; rubidium@9694: class HouseOverrideManager : public OverrideManagerBase { glx@9624: public: glx@9626: HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : rubidium@9694: OverrideManagerBase(offset, maximum, invalid) {} glx@9624: void SetEntitySpec(const HouseSpec *hs); glx@9624: }; glx@9624: glx@9624: glx@9626: struct IndustrySpec; rubidium@9694: class IndustryOverrideManager : public OverrideManagerBase { rubidium@9694: public: rubidium@9694: IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : rubidium@9694: OverrideManagerBase(offset, maximum, invalid) {} glx@9626: rubidium@9694: virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id); glx@9732: virtual uint16 GetID(uint8 grf_local_id, uint32 grfid); glx@9704: void SetEntitySpec(IndustrySpec *inds); glx@9626: }; glx@9626: glx@9629: glx@9629: struct IndustryTileSpec; rubidium@9694: class IndustryTileOverrideManager : public OverrideManagerBase { glx@9704: protected: glx@9704: virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; } rubidium@9694: public: rubidium@9694: IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) : rubidium@9694: OverrideManagerBase(offset, maximum, invalid) {} rubidium@9694: rubidium@9694: void SetEntitySpec(const IndustryTileSpec *indts); glx@9629: }; glx@9629: glx@9624: extern HouseOverrideManager _house_mngr; glx@9626: extern IndustryOverrideManager _industry_mngr; glx@9629: extern IndustryTileOverrideManager _industile_mngr; glx@9626: glx@9626: uint32 GetTerrainType(TileIndex tile); glx@9626: TileIndex GetNearbyTile(byte parameter, TileIndex tile); rubidium@9724: uint32 GetNearbyTileInformation(TileIndex tile); glx@9624: glx@9624: #endif /* NEWGRF_COMMONS_H */