# newgrf_commons.h

Go to the documentation of this file.

    00001 /* $Id: newgrf_commons.h 15428 2009-02-09 02:57:15Z rubidium $ */
    00002
    00007 #ifndef NEWGRF_COMMONS_H
    00008 #define NEWGRF_COMMONS_H
    00009
    00010 #include "core/bitmath_func.hpp"
    00011
    00012 #include "table/sprites.h"
    00013
    00026 struct EntityIDMapping {
    00027   uint32 grfid;
    00028   uint8  entity_id;
    00029   uint8  substitute_id;
    00030 };
    00031
    00032 class OverrideManagerBase {
    00033 protected:
    00034   uint16 *entity_overrides;
    00035   uint32 *grfid_overrides;
    00036
    00037   uint16 max_offset;
    00038   uint16 max_new_entities;
    00039
    00040   uint16 invalid_ID;
    00041   virtual bool CheckValidNewID(uint16 testid) { return true; }
    00042
    00043 public:
    00044   EntityIDMapping *mapping_ID;
    00045
    00046   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
    00047   virtual ~OverrideManagerBase();
    00048
    00049   void ResetOverride();
    00050   void ResetMapping();
    00051
    00052   void Add(uint8 local_id, uint32 grfid, uint entity_type);
    00053   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00054
    00055   uint16 GetSubstituteID(byte entity_id);
    00056   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00057
    00058   inline uint16 GetMaxMapping() { return max_new_entities; }
    00059   inline uint16 GetMaxOffset() { return max_offset; }
    00060 };
    00061
    00062
    00063 struct HouseSpec;
    00064 class HouseOverrideManager : public OverrideManagerBase {
    00065 public:
    00066   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00067       OverrideManagerBase(offset, maximum, invalid) {}
    00068   void SetEntitySpec(const HouseSpec *hs);
    00069 };
    00070
    00071
    00072 struct IndustrySpec;
    00073 class IndustryOverrideManager : public OverrideManagerBase {
    00074 public:
    00075   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00076       OverrideManagerBase(offset, maximum, invalid) {}
    00077
    00078   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00079   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00080   void SetEntitySpec(IndustrySpec *inds);
    00081 };
    00082
    00083
    00084 struct IndustryTileSpec;
    00085 class IndustryTileOverrideManager : public OverrideManagerBase {
    00086 protected:
    00087   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
    00088 public:
    00089   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00090       OverrideManagerBase(offset, maximum, invalid) {}
    00091
    00092   void SetEntitySpec(const IndustryTileSpec *indts);
    00093 };
    00094
    00095 extern HouseOverrideManager _house_mngr;
    00096 extern IndustryOverrideManager _industry_mngr;
    00097 extern IndustryTileOverrideManager _industile_mngr;
    00098
    00099 uint32 GetTerrainType(TileIndex tile);
    00100 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
    00101 uint32 GetNearbyTileInformation(TileIndex tile);
    00102
    00114 static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
    00115 {
    00116   if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
    00117     return (pal != 0 ? pal : default_pal);
    00118   } else {
    00119     return PAL_NONE;
    00120   }
    00121 }
    00122
    00133 static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
    00134 {
    00135   if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
    00136     return (pal != 0 ? pal : default_pal);
    00137   } else {
    00138     return PAL_NONE;
    00139   }
    00140 }
    00141
    00142 #endif /* NEWGRF_COMMONS_H */