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

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 <string>
41 #include <vector>
42 
43 struct lua_State;
44 
45 // Not used until now:
46 #define MapFieldSpeedMask 0x0003
47 
48 #define MapFieldOpaque 0x0004
49 
50 #define MapFieldHuman 0x0008
51 
52 #define MapFieldLandAllowed 0x0010
53 #define MapFieldCoastAllowed 0x0020
54 #define MapFieldWaterAllowed 0x0040
55 #define MapFieldNoBuilding 0x0080
56 
57 #define MapFieldUnpassable 0x0100
58 #define MapFieldWall 0x0200
59 #define MapFieldRocks 0x0400
60 #define MapFieldForest 0x0800
61 
62 #define MapFieldLandUnit 0x1000
63 #define MapFieldAirUnit 0x2000
64 #define MapFieldSeaUnit 0x4000
65 #define MapFieldBuilding 0x8000
66 
67 #define MapFieldDecorative 0x10000
68 #define MapFieldCost4 (0x20000 | MapFieldForest)
69 #define MapFieldCost5 (0x40000 | MapFieldForest)
70 #define MapFieldCost6 (0x80000 | MapFieldForest)
71 
72 
79 enum TileType {
87 };
88 
90 struct CTileInfo {
91 public:
93  {}
94  CTileInfo(unsigned char base, unsigned char mix) : BaseTerrain(base), MixTerrain(mix)
95  {}
96 
97  bool operator ==(const CTileInfo &rhs) const
98  {
99  return BaseTerrain == rhs.BaseTerrain && MixTerrain == rhs.MixTerrain;
100  }
101  bool operator !=(const CTileInfo &rhs) const { return !(*this == rhs); }
102 
103 public:
104  unsigned char BaseTerrain;
105  unsigned char MixTerrain;
106 };
107 
110  std::string TerrainName;
111  // TODO: When drawing with the editor add some kind fo probabilities for every tile.
112 };
113 
114 class CTile
115 {
116 public:
117  CTile() : tile(0), flag(0) {}
118 
119 public:
120  unsigned short tile;
121  unsigned int flag;
123 };
124 
126 class CTileset
127 {
128 public:
129  void clear();
130 
131  unsigned int getTileCount() const { return tiles.size(); }
132 
133  unsigned int getDefaultTileIndex() const;
134  unsigned int getDefaultWoodTileIndex() const;
135 
136  bool isAWallTile(unsigned tile) const;
137  bool isARaceWallTile(unsigned tile, bool human) const;
138  bool isAWoodTile(unsigned tile) const;
139  bool isARockTile(unsigned tile) const;
140 
141  const PixelSize &getPixelTileSize() const { return pixelTileSize; }
142 
143  unsigned getRemovedRockTile() const { return removedRockTile; }
144  unsigned getRemovedTreeTile() const { return removedTreeTile; }
145  unsigned getBottomOneTreeTile() const { return botOneTreeTile; }
146  unsigned getTopOneTreeTile() const { return topOneTreeTile; }
147  unsigned getMidOneTreeTile() const { return midOneTreeTile; }
148 
149  unsigned getWallDirection(int tileIndex, bool human) const;
150 
151  unsigned getHumanWallTileIndex(int dirFlag) const;
152  unsigned getOrcWallTileIndex(int dirFlag) const;
153  unsigned getHumanWallTileIndex_broken(int dirFlag) const;
154  unsigned getOrcWallTileIndex_broken(int dirFlag) const;
155  unsigned getHumanWallTileIndex_destroyed(int dirFlag) const;
156  unsigned getOrcWallTileIndex_destroyed(int dirFlag) const;
157 
158  unsigned int getSolidTerrainCount() const;
159 
160  const std::string &getTerrainName(int solidTerrainIndex) const;
161 
162  int findTileIndexByTile(unsigned int tile) const;
163  unsigned int getTileNumber(int basic, bool random, bool filler) const;
164  void fillSolidTiles(std::vector<unsigned int> *solidTiles) const;
165 
166  unsigned getQuadFromTile(unsigned int tile) const;
167  int getTileBySurrounding(unsigned short type,
168  int up, int right,
169  int bottom, int left) const;
170  int tileFromQuad(unsigned fixed, unsigned quad) const;
171  bool isEquivalentTile(unsigned int tile1, unsigned int tile2) const;
172 
173  void parse(lua_State *l);
174  void buildTable(lua_State *l);
175  int parseTilesetTileFlags(lua_State *l, int *back, int *j);
176  int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain = 0) const;
177 
178 private:
179  unsigned int getOrAddSolidTileIndexByName(const std::string &name);
180  int getTileIndex(unsigned char baseTerrain, unsigned char mixTerrain, unsigned int quad) const;
181  void buildWallReplacementTable();
182  void parseSlots(lua_State *l, int t);
183  void parseSpecial(lua_State *l);
184  void parseSolid(lua_State *l);
185  void parseMixed(lua_State *l);
186  int findTilePath(int base, int goal, int length, std::vector<char> &marks, int *tileIndex) const;
187 public:
188  std::string Name;
189  std::string ImageFile;
190 
191 public:
192  std::vector<CTile> tiles;
193 
194  // TODO: currently hardcoded
195  std::vector<unsigned char> TileTypeTable;
196 private:
197  PixelSize pixelTileSize;
198  std::vector<SolidTerrainInfo> solidTerrainTypes;
199 #if 1
200  std::vector<int> mixedLookupTable;
201  unsigned topOneTreeTile;
202  unsigned midOneTreeTile;
203  unsigned botOneTreeTile;
204  unsigned removedTreeTile;
205  int woodTable[20];
206  unsigned topOneRockTile;
207  unsigned midOneRockTile;
208  unsigned botOneRockTile;
209  unsigned removedRockTile;
210  int rockTable[20];
211  unsigned humanWallTable[16];
212  unsigned orcWallTable[16];
213 #endif
214 };
215 
216 /*----------------------------------------------------------------------------
217 -- Functions
218 ----------------------------------------------------------------------------*/
219 
220 extern void ParseTilesetTileFlags(lua_State *l, int *back, int *j);
221 
223 
224 #endif // !TILESET_H
CTileset::getOrcWallTileIndex_destroyed
unsigned getOrcWallTileIndex_destroyed(int dirFlag) const
Definition: tileset.cpp:747
TileTypeWood
@ TileTypeWood
Unknown tile type.
Definition: tileset.h:81
CTileset::isAWallTile
bool isAWallTile(unsigned tile) const
Definition: tileset.cpp:270
CTileset::getTileBySurrounding
int getTileBySurrounding(unsigned short type, int up, int right, int bottom, int left) const
Definition: tileset.cpp:512
CTileset::findTileIndex
int findTileIndex(unsigned char baseTerrain, unsigned char mixTerrain=0) const
Definition: tileset.cpp:331
CTileset::getRemovedTreeTile
unsigned getRemovedTreeTile() const
Definition: tileset.h:144
TileTypeRock
@ TileTypeRock
Any wood tile.
Definition: tileset.h:82
CTileset::getPixelTileSize
const PixelSize & getPixelTileSize() const
Definition: tileset.h:141
CTile::tileinfo
CTileInfo tileinfo
Flag.
Definition: tileset.h:122
TileTypeUnknown
@ TileTypeUnknown
Definition: tileset.h:80
vec2i.h
CTileset::getHumanWallTileIndex
unsigned getHumanWallTileIndex(int dirFlag) const
Definition: tileset.cpp:705
CTileInfo::MixTerrain
unsigned char MixTerrain
Basic terrain of the tile.
Definition: tileset.h:105
CTileset::getOrcWallTileIndex
unsigned getOrcWallTileIndex(int dirFlag) const
Definition: tileset.cpp:709
CTileset::tiles
std::vector< CTile > tiles
File containing image data.
Definition: tileset.h:192
CTileset::getBottomOneTreeTile
unsigned getBottomOneTreeTile() const
Definition: tileset.h:145
CTileset::tileFromQuad
int tileFromQuad(unsigned fixed, unsigned quad) const
Definition: tileset.cpp:430
TileTypeWater
@ TileTypeWater
Any orc wall tile.
Definition: tileset.h:86
Vec2T< int >
TileTypeCoast
@ TileTypeCoast
Any rock tile.
Definition: tileset.h:83
CTileInfo
Single tile definition.
Definition: tileset.h:90
CTileset::parse
void parse(lua_State *l)
Definition: script_tileset.cpp:336
CTileInfo::operator!=
bool operator!=(const CTileInfo &rhs) const
Definition: tileset.h:101
CTileset::isARaceWallTile
bool isARaceWallTile(unsigned tile, bool human) const
Definition: tileset.cpp:279
CTileInfo::CTileInfo
CTileInfo(unsigned char base, unsigned char mix)
Definition: tileset.h:94
CTileInfo::BaseTerrain
unsigned char BaseTerrain
Definition: tileset.h:104
CTileset::parseTilesetTileFlags
int parseTilesetTileFlags(lua_State *l, int *back, int *j)
Definition: script_tileset.cpp:108
CTileset::getSolidTerrainCount
unsigned int getSolidTerrainCount() const
Definition: tileset.cpp:326
CTileset::getRemovedRockTile
unsigned getRemovedRockTile() const
Definition: tileset.h:143
CTileset::getDefaultTileIndex
unsigned int getDefaultTileIndex() const
Definition: tileset.cpp:228
CTileInfo::CTileInfo
CTileInfo()
Definition: tileset.h:92
CTileset::clear
void clear()
Definition: tileset.cpp:205
SolidTerrainInfo
Definition for a terrain type.
Definition: tileset.h:109
CTileset::TileTypeTable
std::vector< unsigned char > TileTypeTable
Definition: tileset.h:195
CTileset::getTopOneTreeTile
unsigned getTopOneTreeTile() const
Definition: tileset.h:146
CTileset::isARockTile
bool isARockTile(unsigned tile) const
Definition: tileset.cpp:299
CTileset::buildTable
void buildTable(lua_State *l)
Definition: script_tileset.cpp:365
TileTypeOrcWall
@ TileTypeOrcWall
Any human wall tile.
Definition: tileset.h:85
CTileset::getDefaultWoodTileIndex
unsigned int getDefaultWoodTileIndex() const
Definition: tileset.cpp:249
CTile::flag
unsigned int flag
graphical pos
Definition: tileset.h:121
CTile::tile
unsigned short tile
Definition: tileset.h:120
CTileset::findTileIndexByTile
int findTileIndexByTile(unsigned int tile) const
Definition: tileset.cpp:573
CTileset::getTileNumber
unsigned int getTileNumber(int basic, bool random, bool filler) const
Definition: tileset.cpp:594
CTileset::Name
std::string Name
Definition: tileset.h:188
CTileset::ImageFile
std::string ImageFile
Nice name to display.
Definition: tileset.h:189
CTileset::getTileCount
unsigned int getTileCount() const
Definition: tileset.h:131
CTile
Definition: tileset.h:114
CTileset::isEquivalentTile
bool isEquivalentTile(unsigned int tile1, unsigned int tile2) const
Definition: tileset.cpp:566
CTileset::getTerrainName
const std::string & getTerrainName(int solidTerrainIndex) const
Definition: tileset.cpp:321
CTileset::getHumanWallTileIndex_destroyed
unsigned getHumanWallTileIndex_destroyed(int dirFlag) const
Definition: tileset.cpp:739
CTile::CTile
CTile()
Definition: tileset.h:117
CTileset::getMidOneTreeTile
unsigned getMidOneTreeTile() const
Definition: tileset.h:147
CTileset::getOrcWallTileIndex_broken
unsigned getOrcWallTileIndex_broken(int dirFlag) const
Definition: tileset.cpp:732
SolidTerrainInfo::TerrainName
std::string TerrainName
Definition: tileset.h:110
CTileset::getQuadFromTile
unsigned getQuadFromTile(unsigned int tile) const
Definition: tileset.cpp:646
CTileset::getWallDirection
unsigned getWallDirection(int tileIndex, bool human) const
Definition: tileset.cpp:694
TileType
TileType
Definition: tileset.h:79
CTileset::isAWoodTile
bool isAWoodTile(unsigned tile) const
Definition: tileset.cpp:292
CTileset::getHumanWallTileIndex_broken
unsigned getHumanWallTileIndex_broken(int dirFlag) const
Definition: tileset.cpp:725
CTileset
Tileset definition.
Definition: tileset.h:126
CTileset::fillSolidTiles
void fillSolidTiles(std::vector< unsigned int > *solidTiles) const
Definition: tileset.cpp:678
CTileInfo::operator==
bool operator==(const CTileInfo &rhs) const
Definition: tileset.h:97
TileTypeHumanWall
@ TileTypeHumanWall
Any coast tile.
Definition: tileset.h:84
ParseTilesetTileFlags
void ParseTilesetTileFlags(lua_State *l, int *back, int *j)
(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.