newgrf_commons.h

Go to the documentation of this file.
00001 /* $Id$ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00015 #ifndef NEWGRF_COMMONS_H
00016 #define NEWGRF_COMMONS_H
00017 
00018 #include "tile_type.h"
00019 
00021 enum TileContext {
00022   TCX_NORMAL,         
00023   TCX_UPPER_HALFTILE, 
00024   TCX_ON_BRIDGE,      
00025 };
00026 
00039 struct EntityIDMapping {
00040   uint32 grfid;          
00041   uint8  entity_id;      
00042   uint8  substitute_id;  
00043 };
00044 
00045 class OverrideManagerBase {
00046 protected:
00047   uint16 *entity_overrides;
00048   uint32 *grfid_overrides;
00049 
00050   uint16 max_offset;       
00051   uint16 max_new_entities; 
00052 
00053   uint16 invalid_ID;       
00054   virtual bool CheckValidNewID(uint16 testid) { return true; }
00055 
00056 public:
00057   EntityIDMapping *mapping_ID; 
00058 
00059   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
00060   virtual ~OverrideManagerBase();
00061 
00062   void ResetOverride();
00063   void ResetMapping();
00064 
00065   void Add(uint8 local_id, uint32 grfid, uint entity_type);
00066   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00067 
00068   uint16 GetSubstituteID(uint16 entity_id) const;
00069   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
00070 
00071   inline uint16 GetMaxMapping() const { return max_new_entities; }
00072   inline uint16 GetMaxOffset() const { return max_offset; }
00073 };
00074 
00075 
00076 struct HouseSpec;
00077 class HouseOverrideManager : public OverrideManagerBase {
00078 public:
00079   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00080       OverrideManagerBase(offset, maximum, invalid) {}
00081   void SetEntitySpec(const HouseSpec *hs);
00082 };
00083 
00084 
00085 struct IndustrySpec;
00086 class IndustryOverrideManager : public OverrideManagerBase {
00087 public:
00088   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00089       OverrideManagerBase(offset, maximum, invalid) {}
00090 
00091   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00092   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const;
00093   void SetEntitySpec(IndustrySpec *inds);
00094 };
00095 
00096 
00097 struct IndustryTileSpec;
00098 class IndustryTileOverrideManager : public OverrideManagerBase {
00099 protected:
00100   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
00101 public:
00102   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00103       OverrideManagerBase(offset, maximum, invalid) {}
00104 
00105   void SetEntitySpec(const IndustryTileSpec *indts);
00106 };
00107 
00108 struct AirportSpec;
00109 class AirportOverrideManager : public OverrideManagerBase {
00110 public:
00111   AirportOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00112       OverrideManagerBase(offset, maximum, invalid) {}
00113 
00114   void SetEntitySpec(AirportSpec *inds);
00115 };
00116 
00117 struct AirportTileSpec;
00118 class AirportTileOverrideManager : public OverrideManagerBase {
00119 protected:
00120   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
00121 public:
00122   AirportTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00123       OverrideManagerBase(offset, maximum, invalid) {}
00124 
00125   void SetEntitySpec(const AirportTileSpec *ats);
00126 };
00127 
00128 struct ObjectSpec;
00129 class ObjectOverrideManager : public OverrideManagerBase {
00130 protected:
00131   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
00132 public:
00133   ObjectOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00134       OverrideManagerBase(offset, maximum, invalid) {}
00135 
00136   void SetEntitySpec(ObjectSpec *spec);
00137 };
00138 
00139 extern HouseOverrideManager _house_mngr;
00140 extern IndustryOverrideManager _industry_mngr;
00141 extern IndustryTileOverrideManager _industile_mngr;
00142 extern AirportOverrideManager _airport_mngr;
00143 extern AirportTileOverrideManager _airporttile_mngr;
00144 extern ObjectOverrideManager _object_mngr;
00145 
00146 uint32 GetTerrainType(TileIndex tile, TileContext context = TCX_NORMAL);
00147 TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets = true);
00148 uint32 GetNearbyTileInformation(TileIndex tile);
00149 
00154 template <size_t Tcnt>
00155 struct GRFFilePropsBase {
00156   GRFFilePropsBase() : local_id(0), grffile(0)
00157   {
00158     /* The lack of some compilers to provide default constructors complying to the specs
00159      * requires us to zero the stuff ourself. */
00160     memset(spritegroup, 0, sizeof(spritegroup));
00161   }
00162 
00163   uint16 local_id;                             
00164   const struct GRFFile *grffile;               
00165   const struct SpriteGroup *spritegroup[Tcnt]; 
00166 };
00167 
00169 struct GRFFileProps : GRFFilePropsBase<1> {
00171   GRFFileProps(uint16 subst_id) :
00172       GRFFilePropsBase<1>(), subst_id(subst_id), override(subst_id)
00173   {
00174   }
00175 
00177   GRFFileProps() : GRFFilePropsBase<1>() {}
00178   uint16 subst_id;
00179   uint16 override;                      
00180 };
00181 
00182 #endif /* NEWGRF_COMMONS_H */

Generated on Sun May 8 07:30:15 2011 for OpenTTD by  doxygen 1.6.1