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