_________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
                   Stratagus - A free fantasy real time strategy game engine

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
tileset.h
Go to the documentation of this file.
1 // _________ __ __
2 // / _____// |_____________ _/ |______ ____ __ __ ______
3 // \_____ \\ __\_ __ \__ \\ __\__ \ / ___\| | \/ ___/
4 // / \| | | | \// __ \| | / __ \_/ /_/ > | /\___ |
5 // /_______ /|__| |__| (____ /__| (____ /\___ /|____//____ >
6 // \/ \/ \//_____/ \/
7 // ______________________ ______________________
8 // T H E W A R B E G I N S
9 // Stratagus - A free fantasy real time strategy game engine
10 //
12 //
13 // (c) Copyright 1998-2005 by Lutz Sammer and Jimmy Salmon
14 //
15 // This program is free software; you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation; only version 2 of the License.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 // 02111-1307, USA.
28 //
29 
30 #ifndef TILESET_H
31 #define TILESET_H
32 
34 
35 /*----------------------------------------------------------------------------
36 -- Declarations
37 ----------------------------------------------------------------------------*/
38 
39 #include "vec2i.h"
40 #include <vector>
41 
42 struct lua_State;
43 
44 // Not used until now:
45 #define MapFieldSpeedMask 0x0007
46 
47 #define MapFieldHuman 0x0008
48 
49 #define MapFieldLandAllowed 0x0010
50 #define MapFieldCoastAllowed 0x0020
51 #define MapFieldWaterAllowed 0x0040
52 #define MapFieldNoBuilding 0x0080
53 
54 #define MapFieldUnpassable 0x0100
55 #define MapFieldWall 0x0200
56 #define MapFieldRocks 0x0400
57 #define MapFieldForest 0x0800
58 
59 #define MapFieldLandUnit 0x1000
60 #define MapFieldAirUnit 0x2000
61 #define MapFieldSeaUnit 0x4000
62 #define MapFieldBuilding 0x8000
63 
64 
71 enum TileType {
79 };
80 
82 struct CTileInfo {
83 public:
85  {}
86  CTileInfo(unsigned char base, unsigned char mix) : BaseTerrain(base), MixTerrain(mix)
87  {}
88 
89  bool operator ==(const CTileInfo &rhs) const
90  {
91  return BaseTerrain == rhs.BaseTerrain && MixTerrain == rhs.MixTerrain;
92  }
93  bool operator !=(const CTileInfo &rhs) const { return !(*this == rhs); }
94 
95 public:
96  unsigned char BaseTerrain;
97  unsigned char MixTerrain;
98 };
99 
102  std::string TerrainName;
103  // TODO: When drawing with the editor add some kind fo probabilities for every tile.
104 };
105 
106 class CTile
107 {
108 public:
109  CTile() : tile(0), flag(0) {}
110 
111 public:
112  unsigned short tile;
113  unsigned short flag;
115 };
116 
118 class CTileset
119 {
120 public:
121  void clear();
122 
123  unsigned int getTileCount() const { return tiles.size(); }
124 
125  unsigned int getDefaultTileIndex() const;
126 
127  bool isAWallTile(unsigned tile) const;
128  bool isARaceWallTile(unsigned tile, bool human) const;
129  bool isAWoodTile(unsigned tile) const;
130  bool isARockTile(unsigned tile) const;
131 
132  const PixelSize &getPixelTileSize() const { return pixelTileSize; }
133 
134  unsigned getRemovedRockTile() const { return removedRockTile; }
135  unsigned getRemovedTreeTile() const { return removedTreeTile; }
136  unsigned getBottomOneTreeTile() const { return botOneTreeTile; }
137  unsigned getTopOneTreeTile() const { return topOneTreeTile; }
138  unsigned getMidOneTreeTile() const { return midOneTreeTile; }
139 
140  unsigned getWallDirection(int tileIndex, bool human) const;
141 
142  unsigned getHumanWallTileIndex(int dirFlag) const;
143  unsigned getOrcWallTileIndex(int dirFlag) const;
144  unsigned getHumanWallTileIndex_broken(int dirFlag) const;
145  unsigned getOrcWallTileIndex_broken(int dirFlag) const;
146  unsigned getHumanWallTileIndex_destroyed(int dirFlag) const;
147  unsigned getOrcWallTileIndex_destroyed(int dirFlag) const;
148 
149  unsigned int getSolidTerrainCount() const;
150 
151  const std::string &getTerrainName(int solidTerrainIndex) const;
152 
153  int findTileIndexByTile(unsigned int tile) const;
154  unsigned int getTileNumber(int basic, bool random, bool filler) const;
155  void fillSolidTiles(std::vector<unsigned int> *solidTiles) const;
156 
157  unsigned getQuadFromTile(unsigned int tile) const;
158  int getTileBySurrounding(unsigned short type,
159  int up, int right,
160  int bottom, int left) const;
161  int tileFromQuad(unsigned fixed, unsigned quad) const;
162  bool isEquivalentTile(unsigned int tile1, unsigned int tile2) const;
163 
164  void parse(lua_State *l);
165  void buildTable(lua_State *l);
166 
167 private:
168  unsigned int getOrAddSolidTileIndexByName(const std::string &name);
169  int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
170  int getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain, unsigned int quad) const;
171  void buildWallReplacementTable();
172  void parseSlots(lua_State *l, int t);
173  void parseSpecial(lua_State *l);
174  void parseSolid(lua_State *l);
175  void parseMixed(lua_State *l);
176  int findTilePath(int base, int goal, int length, std::vector<char> &marks, int *tileIndex) const;
177 public:
178  std::string Name;
179  std::string ImageFile;
180 
181 public:
182  std::vector<CTile> tiles;
183 
184  // TODO: currently hardcoded
185  std::vector<unsigned char> TileTypeTable;
186 private:
187  PixelSize pixelTileSize;
188  std::vector<SolidTerrainInfo> solidTerrainTypes;
189 #if 1
190  std::vector<int> mixedLookupTable;
191  unsigned topOneTreeTile;
192  unsigned midOneTreeTile;
193  unsigned botOneTreeTile;
194  unsigned removedTreeTile;
195  int woodTable[20];
196  unsigned topOneRockTile;
197  unsigned midOneRockTile;
198  unsigned botOneRockTile;
199  unsigned removedRockTile;
200  int rockTable[20];
201  unsigned humanWallTable[16];
202  unsigned orcWallTable[16];
203 #endif
204 };
205 
206 /*----------------------------------------------------------------------------
207 -- Functions
208 ----------------------------------------------------------------------------*/
209 
210 extern void ParseTilesetTileFlags(lua_State *l, int *back, int *j);
211 
213 
214 #endif // !TILESET_H
void ParseTilesetTileFlags(lua_State *l, int *back, int *j)
Definition: script_tileset.cpp:102
CTileInfo tileinfo
Flag.
Definition: tileset.h:114
bool isARockTile(unsigned tile) const
Definition: tileset.cpp:262
Definition: tileset.h:106
unsigned char BaseTerrain
Definition: tileset.h:96
bool isARaceWallTile(unsigned tile, bool human) const
Definition: tileset.cpp:242
bool operator!=(const CTileInfo &rhs) const
Definition: tileset.h:93
unsigned getOrcWallTileIndex_broken(int dirFlag) const
Definition: tileset.cpp:685
Any human wall tile.
Definition: tileset.h:77
unsigned getTopOneTreeTile() const
Definition: tileset.h:137
unsigned getQuadFromTile(unsigned int tile) const
Definition: tileset.cpp:604
unsigned getHumanWallTileIndex_destroyed(int dirFlag) const
Definition: tileset.cpp:692
bool isEquivalentTile(unsigned int tile1, unsigned int tile2) const
Definition: tileset.cpp:525
unsigned int getTileCount() const
Definition: tileset.h:123
bool isAWoodTile(unsigned tile) const
Definition: tileset.cpp:255
std::vector< unsigned char > TileTypeTable
Definition: tileset.h:185
unsigned short flag
graphical pos
Definition: tileset.h:113
unsigned getMidOneTreeTile() const
Definition: tileset.h:138
unsigned getHumanWallTileIndex(int dirFlag) const
Definition: tileset.cpp:658
Tileset definition.
Definition: tileset.h:118
Any coast tile.
Definition: tileset.h:76
unsigned int getDefaultTileIndex() const
Definition: tileset.cpp:227
Definition for a terrain type.
Definition: tileset.h:101
unsigned int getSolidTerrainCount() const
Definition: tileset.cpp:289
Unknown tile type.
Definition: tileset.h:73
void fillSolidTiles(std::vector< unsigned int > *solidTiles) const
Definition: tileset.cpp:636
unsigned char MixTerrain
Basic terrain of the tile.
Definition: tileset.h:97
Any rock tile.
Definition: tileset.h:75
std::string Name
Definition: tileset.h:178
unsigned getHumanWallTileIndex_broken(int dirFlag) const
Definition: tileset.cpp:678
const PixelSize & getPixelTileSize() const
Definition: tileset.h:132
void buildTable(lua_State *l)
Definition: script_tileset.cpp:337
CTileInfo(unsigned char base, unsigned char mix)
Definition: tileset.h:86
Single tile definition.
Definition: tileset.h:82
unsigned getBottomOneTreeTile() const
Definition: tileset.h:136
unsigned getWallDirection(int tileIndex, bool human) const
Definition: tileset.cpp:647
unsigned getOrcWallTileIndex(int dirFlag) const
Definition: tileset.cpp:662
unsigned getOrcWallTileIndex_destroyed(int dirFlag) const
Definition: tileset.cpp:700
TileType
Definition: tileset.h:71
unsigned short tile
Definition: tileset.h:112
Any wood tile.
Definition: tileset.h:74
bool operator==(const CTileInfo &rhs) const
Definition: tileset.h:89
unsigned int getTileNumber(int basic, bool random, bool filler) const
Definition: tileset.cpp:553
unsigned getRemovedRockTile() const
Definition: tileset.h:134
void parse(lua_State *l)
Definition: script_tileset.cpp:308
bool isAWallTile(unsigned tile) const
Definition: tileset.cpp:233
std::string TerrainName
Definition: tileset.h:102
void clear()
Definition: tileset.cpp:204
CTileInfo()
Definition: tileset.h:84
Any orc wall tile.
Definition: tileset.h:78
std::vector< CTile > tiles
File containing image data.
Definition: tileset.h:182
Definition: tileset.h:72
CTile()
Definition: tileset.h:109
int tileFromQuad(unsigned fixed, unsigned quad) const
Definition: tileset.cpp:390
const std::string & getTerrainName(int solidTerrainIndex) const
Definition: tileset.cpp:284
unsigned getRemovedTreeTile() const
Definition: tileset.h:135
std::string ImageFile
Nice name to display.
Definition: tileset.h:179
int findTileIndexByTile(unsigned int tile) const
Definition: tileset.cpp:532
int getTileBySurrounding(unsigned short type, int up, int right, int bottom, int left) const
Definition: tileset.cpp:471
(C) Copyright 1998-2012 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.