2007-05-15 21:36:58 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/** @file newgrf_commons.h This file simplyfies and embeds a common mechanism of
|
|
|
|
* loading/saving and mapping of grf entities.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NEWGRF_COMMONS_H
|
|
|
|
#define NEWGRF_COMMONS_H
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps an entity id stored on the map to a GRF file.
|
|
|
|
* Entities are objects used ingame (houses, industries, industry tiles) for
|
|
|
|
* which we need to correlate the ids from the grf files with the ones in the
|
|
|
|
* the savegames themselves.
|
|
|
|
* An array of EntityIDMapping structs is saved with the savegame so
|
|
|
|
* that those GRFs can be loaded in a different order, or removed safely. The
|
|
|
|
* index in the array is the entity's ID stored on the map.
|
|
|
|
*
|
|
|
|
* The substitute ID is the ID of an original entity that should be used instead
|
|
|
|
* if the GRF containing the new entity is not available.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2007-07-25 17:18:13 +00:00
|
|
|
class OverrideManagerBase {
|
2007-05-15 21:36:58 +00:00
|
|
|
protected:
|
|
|
|
uint16 *entity_overrides;
|
2007-11-12 20:40:58 +00:00
|
|
|
uint32 *grfid_overrides;
|
2007-05-15 21:36:58 +00:00
|
|
|
|
|
|
|
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 dected invalid entities;
|
2007-09-26 02:15:00 +00:00
|
|
|
virtual bool CheckValidNewID(uint16 testid) { return true; }
|
2007-05-15 21:36:58 +00:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2007-11-12 20:40:58 +00:00
|
|
|
void Add(uint8 local_id, uint32 grfid, uint entity_type);
|
2007-06-09 02:05:51 +00:00
|
|
|
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
|
2007-05-15 21:36:58 +00:00
|
|
|
|
|
|
|
uint16 GetSubstituteID(byte entity_id);
|
2008-02-08 16:56:52 +00:00
|
|
|
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
|
2007-05-15 21:36:58 +00:00
|
|
|
|
2007-07-25 17:18:13 +00:00
|
|
|
inline uint16 GetMaxMapping() { return max_new_entities; }
|
|
|
|
inline uint16 GetMaxOffset() { return max_offset; }
|
2007-05-15 21:36:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct HouseSpec;
|
2007-07-25 17:18:13 +00:00
|
|
|
class HouseOverrideManager : public OverrideManagerBase {
|
2007-05-15 21:36:58 +00:00
|
|
|
public:
|
2007-06-09 02:05:51 +00:00
|
|
|
HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
2007-07-25 17:18:13 +00:00
|
|
|
OverrideManagerBase(offset, maximum, invalid) {}
|
2007-05-15 21:36:58 +00:00
|
|
|
void SetEntitySpec(const HouseSpec *hs);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-06-09 02:05:51 +00:00
|
|
|
struct IndustrySpec;
|
2007-07-25 17:18:13 +00:00
|
|
|
class IndustryOverrideManager : public OverrideManagerBase {
|
|
|
|
public:
|
|
|
|
IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
|
|
|
OverrideManagerBase(offset, maximum, invalid) {}
|
|
|
|
|
|
|
|
virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
|
2008-02-08 16:56:52 +00:00
|
|
|
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
|
2007-10-04 00:59:52 +00:00
|
|
|
void SetEntitySpec(IndustrySpec *inds);
|
2007-06-09 02:05:51 +00:00
|
|
|
};
|
|
|
|
|
2007-06-21 17:09:10 +00:00
|
|
|
|
|
|
|
struct IndustryTileSpec;
|
2007-07-25 17:18:13 +00:00
|
|
|
class IndustryTileOverrideManager : public OverrideManagerBase {
|
2007-09-26 02:15:00 +00:00
|
|
|
protected:
|
|
|
|
virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
|
2007-07-25 17:18:13 +00:00
|
|
|
public:
|
|
|
|
IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
|
|
|
|
OverrideManagerBase(offset, maximum, invalid) {}
|
|
|
|
|
|
|
|
void SetEntitySpec(const IndustryTileSpec *indts);
|
2007-06-21 17:09:10 +00:00
|
|
|
};
|
|
|
|
|
2007-05-15 21:36:58 +00:00
|
|
|
extern HouseOverrideManager _house_mngr;
|
2007-06-09 02:05:51 +00:00
|
|
|
extern IndustryOverrideManager _industry_mngr;
|
2007-06-21 17:09:10 +00:00
|
|
|
extern IndustryTileOverrideManager _industile_mngr;
|
2007-05-15 21:36:58 +00:00
|
|
|
|
2007-06-05 01:49:08 +00:00
|
|
|
uint32 GetTerrainType(TileIndex tile);
|
2007-06-08 17:54:18 +00:00
|
|
|
TileIndex GetNearbyTile(byte parameter, TileIndex tile);
|
2008-01-31 17:46:08 +00:00
|
|
|
uint32 GetNearbyTileInformation(TileIndex tile);
|
2007-06-05 01:49:08 +00:00
|
|
|
|
2007-05-15 21:36:58 +00:00
|
|
|
#endif /* NEWGRF_COMMONS_H */
|