# newgrf_commons.h

Go to the documentation of this file.

    00001 /* $Id: newgrf_commons.h 19439 2010-03-16 20:54:26Z 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
    00031 struct EntityIDMapping {
    00032   uint32 grfid;
    00033   uint8  entity_id;
    00034   uint8  substitute_id;
    00035 };
    00036
    00037 class OverrideManagerBase {
    00038 protected:
    00039   uint16 *entity_overrides;
    00040   uint32 *grfid_overrides;
    00041
    00042   uint16 max_offset;
    00043   uint16 max_new_entities;
    00044
    00045   uint16 invalid_ID;
    00046   virtual bool CheckValidNewID(uint16 testid) { return true; }
    00047
    00048 public:
    00049   EntityIDMapping *mapping_ID;
    00050
    00051   OverrideManagerBase(uint16 offset, uint16 maximum, uint16 invalid);
    00052   virtual ~OverrideManagerBase();
    00053
    00054   void ResetOverride();
    00055   void ResetMapping();
    00056
    00057   void Add(uint8 local_id, uint32 grfid, uint entity_type);
    00058   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00059
    00060   uint16 GetSubstituteID(uint16 entity_id);
    00061   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00062
    00063   inline uint16 GetMaxMapping() { return max_new_entities; }
    00064   inline uint16 GetMaxOffset() { return max_offset; }
    00065 };
    00066
    00067
    00068 struct HouseSpec;
    00069 class HouseOverrideManager : public OverrideManagerBase {
    00070 public:
    00071   HouseOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00072       OverrideManagerBase(offset, maximum, invalid) {}
    00073   void SetEntitySpec(const HouseSpec *hs);
    00074 };
    00075
    00076
    00077 struct IndustrySpec;
    00078 class IndustryOverrideManager : public OverrideManagerBase {
    00079 public:
    00080   IndustryOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00081       OverrideManagerBase(offset, maximum, invalid) {}
    00082
    00083   virtual uint16 AddEntityID(byte grf_local_id, uint32 grfid, byte substitute_id);
    00084   virtual uint16 GetID(uint8 grf_local_id, uint32 grfid);
    00085   void SetEntitySpec(IndustrySpec *inds);
    00086 };
    00087
    00088
    00089 struct IndustryTileSpec;
    00090 class IndustryTileOverrideManager : public OverrideManagerBase {
    00091 protected:
    00092   virtual bool CheckValidNewID(uint16 testid) { return testid != 0xFF; }
    00093 public:
    00094   IndustryTileOverrideManager(uint16 offset, uint16 maximum, uint16 invalid) :
    00095       OverrideManagerBase(offset, maximum, invalid) {}
    00096
    00097   void SetEntitySpec(const IndustryTileSpec *indts);
    00098 };
    00099
    00100 extern HouseOverrideManager _house_mngr;
    00101 extern IndustryOverrideManager _industry_mngr;
    00102 extern IndustryTileOverrideManager _industile_mngr;
    00103
    00104 uint32 GetTerrainType(TileIndex tile);
    00105 TileIndex GetNearbyTile(byte parameter, TileIndex tile);
    00106 uint32 GetNearbyTileInformation(TileIndex tile);
    00107
    00108 #endif /* NEWGRF_COMMONS_H */