# newgrf_commons.h

Go to the documentation of this file.

    00001 /* $Id: newgrf_commons.h 12086 2008-02-08 16:56:52Z glx $ */
    00002
    00007 #ifndef NEWGRF_COMMONS_H
    00008 #define NEWGRF_COMMONS_H
    00009
    00022 struct EntityIDMapping {
    00023   uint32 grfid;
    00024   uint8  entity_id;
    00025   uint8  substitute_id;
    00026 };
    00027
    00028 class OverrideManagerBase {
    00029 protected:
    00030   uint16 *entity_overrides;
    00031   uint32 *grfid_overrides;
    00032
    00033   uint16 max_offset;
    00034   uint16 max_new_entities;
    00035
    00036   uint16 invalid_ID;
    00037   virtual bool CheckValidNewID(uint16 testid) { return true; }
    00038
    00039 public:
    00040   EntityIDMapping *mapping_ID;
    00041
    00042   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
    00043   virtual ~OverrideManagerBase();
    00044
    00045   void ResetOverride();
    00046   void ResetMapping();
    00047
    00048   void Add(uint8 local_id, uint32 grfid, uint entity_type);
    00049   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00050
    00051   uint16 GetSubstituteID(byte entity_id);
    00052   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00053
    00054   inline uint16 GetMaxMapping() { return max_new_entities; }
    00055   inline uint16 GetMaxOffset() { return max_offset; }
    00056 };
    00057
    00058
    00059 struct HouseSpec;
    00060 class HouseOverrideManager : public OverrideManagerBase {
    00061 public:
    00062   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00063       OverrideManagerBase(offset, maximum, invalid) {}
    00064   void SetEntitySpec(const HouseSpec *hs);
    00065 };
    00066
    00067
    00068 struct IndustrySpec;
    00069 class IndustryOverrideManager : public OverrideManagerBase {
    00070 public:
    00071   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00072       OverrideManagerBase(offset, maximum, invalid) {}
    00073
    00074   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00075   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00076   void SetEntitySpec(IndustrySpec *inds);
    00077 };
    00078
    00079
    00080 struct IndustryTileSpec;
    00081 class IndustryTileOverrideManager : public OverrideManagerBase {
    00082 protected:
    00083   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
    00084 public:
    00085   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00086       OverrideManagerBase(offset, maximum, invalid) {}
    00087
    00088   void SetEntitySpec(const IndustryTileSpec *indts);
    00089 };
    00090
    00091 extern HouseOverrideManager _house_mngr;
    00092 extern IndustryOverrideManager _industry_mngr;
    00093 extern IndustryTileOverrideManager _industile_mngr;
    00094
    00095 uint32 GetTerrainType(TileIndex tile);
    00096 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
    00097 uint32 GetNearbyTileInformation(TileIndex tile);
    00098
    00099 #endif /* NEWGRF_COMMONS_H */