newgrf_commons.h

Go to the documentation of this file.
00001 /* $Id: newgrf_commons.h 21047 2010-10-27 20:15:18Z rubidium $ */
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 
00014 #ifndef NEWGRF_COMMONS_H
00015 #define NEWGRF_COMMONS_H
00016 
00017 #include "tile_cmd.h"
00018 
00020 enum TileContext {
00021   TCX_NORMAL,         
00022   TCX_UPPER_HALFTILE, 
00023   TCX_ON_BRIDGE,      
00024 };
00025 
00038 struct EntityIDMapping {
00039   uint32 grfid;          
00040   uint8  entity_id;      
00041   uint8  substitute_id;  
00042 };
00043 
00044 class OverrideManagerBase {
00045 protected:
00046   uint16 *entity_overrides;
00047   uint32 *grfid_overrides;
00048 
00049   uint16 max_offset;       
00050   uint16 max_new_entities; 
00051 
00052   uint16 invalid_ID;       
00053   virtual bool CheckValidNewID(uint16 testid) { return true; }
00054 
00055 public:
00056   EntityIDMapping *mapping_ID; 
00057 
00058   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
00059   virtual ~OverrideManagerBase();
00060 
00061   void ResetOverride();
00062   void ResetMapping();
00063 
00064   void Add(uint8 local_id, uint32 grfid, uint entity_type);
00065   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00066 
00067   uint16 GetSubstituteID(uint16 entity_id);
00068   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
00069 
00070   inline uint16 GetMaxMapping() { return max_new_entities; }
00071   inline uint16 GetMaxOffset() { return max_offset; }
00072 };
00073 
00074 
00075 struct HouseSpec;
00076 class HouseOverrideManager : public OverrideManagerBase {
00077 public:
00078   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00079       OverrideManagerBase(offset, maximum, invalid) {}
00080   void SetEntitySpec(const HouseSpec *hs);
00081 };
00082 
00083 
00084 struct IndustrySpec;
00085 class IndustryOverrideManager : public OverrideManagerBase {
00086 public:
00087   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00088       OverrideManagerBase(offset, maximum, invalid) {}
00089 
00090   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00091   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
00092   void SetEntitySpec(IndustrySpec *inds);
00093 };
00094 
00095 
00096 struct IndustryTileSpec;
00097 class IndustryTileOverrideManager : public OverrideManagerBase {
00098 protected:
00099   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
00100 public:
00101   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00102       OverrideManagerBase(offset, maximum, invalid) {}
00103 
00104   void SetEntitySpec(const IndustryTileSpec *indts);
00105 };
00106 
00107 extern HouseOverrideManager _house_mngr;
00108 extern IndustryOverrideManager _industry_mngr;
00109 extern IndustryTileOverrideManager _industile_mngr;
00110 
00111 uint32 GetTerrainType(TileIndex tile, TileContext context = TCX_NORMAL);
00112 TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets = true);
00113 uint32 GetNearbyTileInformation(TileIndex tile);
00114 
00115 #endif /* NEWGRF_COMMONS_H */

Generated on Sun Nov 14 14:41:53 2010 for OpenTTD by  doxygen 1.6.1