newgrf_commons.h

Go to the documentation of this file.
00001 /* $Id: newgrf_commons.h 17248 2009-08-21 20:21:05Z 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 "core/bitmath_func.hpp"
00018 
00019 #include "table/sprites.h"
00020 
00033 struct EntityIDMapping {
00034   uint32 grfid;          
00035   uint8  entity_id;      
00036   uint8  substitute_id;  
00037 };
00038 
00039 class OverrideManagerBase {
00040 protected:
00041   uint16 *entity_overrides;
00042   uint32 *grfid_overrides;
00043 
00044   uint16 max_offset;       
00045   uint16 max_new_entities; 
00046 
00047   uint16 invalid_ID;       
00048   virtual bool CheckValidNewID(uint16 testid) { return true; }
00049 
00050 public:
00051   EntityIDMapping *mapping_ID; 
00052 
00053   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
00054   virtual ~OverrideManagerBase();
00055 
00056   void ResetOverride();
00057   void ResetMapping();
00058 
00059   void Add(uint8 local_id, uint32 grfid, uint entity_type);
00060   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00061 
00062   uint16 GetSubstituteID(byte entity_id);
00063   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
00064 
00065   inline uint16 GetMaxMapping() { return max_new_entities; }
00066   inline uint16 GetMaxOffset() { return max_offset; }
00067 };
00068 
00069 
00070 struct HouseSpec;
00071 class HouseOverrideManager : public OverrideManagerBase {
00072 public:
00073   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00074       OverrideManagerBase(offset, maximum, invalid) {}
00075   void SetEntitySpec(const HouseSpec *hs);
00076 };
00077 
00078 
00079 struct IndustrySpec;
00080 class IndustryOverrideManager : public OverrideManagerBase {
00081 public:
00082   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00083       OverrideManagerBase(offset, maximum, invalid) {}
00084 
00085   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
00086   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
00087   void SetEntitySpec(IndustrySpec *inds);
00088 };
00089 
00090 
00091 struct IndustryTileSpec;
00092 class IndustryTileOverrideManager : public OverrideManagerBase {
00093 protected:
00094   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
00095 public:
00096   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
00097       OverrideManagerBase(offset, maximum, invalid) {}
00098 
00099   void SetEntitySpec(const IndustryTileSpec *indts);
00100 };
00101 
00102 extern HouseOverrideManager _house_mngr;
00103 extern IndustryOverrideManager _industry_mngr;
00104 extern IndustryTileOverrideManager _industile_mngr;
00105 
00106 uint32 GetTerrainType(TileIndex tile);
00107 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
00108 uint32 GetNearbyTileInformation(TileIndex tile);
00109 
00121 static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
00122 {
00123   if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00124     return (pal != 0 ? pal : default_pal);
00125   } else {
00126     return PAL_NONE;
00127   }
00128 }
00129 
00140 static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
00141 {
00142   if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00143     return (pal != 0 ? pal : default_pal);
00144   } else {
00145     return PAL_NONE;
00146   }
00147 }
00148 
00149 #endif /* NEWGRF_COMMONS_H */

Generated on Tue Jan 5 21:02:56 2010 for OpenTTD by  doxygen 1.5.6