1 // Copyright (C) 2001, 2002, 2003 Michael Bartl
2 // Copyright (C) 2001, 2002, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2007, 2008 Ben Asselstine
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "xmlhelper.h"
28 #include "tilestyleset.h"
32 //! Describes a kind of tile that a Stack can traverse.
34 * Many tiles are put together to form a tileset. Thus, a tile describes a
35 * single terrain type. It keeps the name, movement points, type (grass, water
36 * etc.) and also keeps the images together.
38 * Each tile holds a list of TileStyleSet objects which hold a list of
39 * TileStyle objects. Each TileStyleSet holds a bunch of pictures of
40 * what this tile can look like. A TileStyle is a single picture.
41 * These TileStyle pictures are displayed on the BigMap using the MapRenderer.
43 * Tile objects are held in a Tileset object.
44 * Maptile objects refer to Tile objects.
46 class Tile : public std::list<TileStyleSet*>
49 //! The xml tag of this object in a tileset configuration file.
50 static std::string d_tag;
52 //! Enumerate the kinds of terrain that a Stack can potentially move on.
54 //! Synomymous with GRASS.
56 //! Grassy plain. Flat. Open. Easy to pass through.
58 //! Lake, ocean, river, puddle, moat, or anything else watery.
60 //! Trees in great abundance, also includes shrubberies.
62 //! Hilly terrain, generally passable.
64 //! Very hilly terrain, generally not passable except by flight.
68 //! Terrain that no army units can cross, even when flying.
72 //! Default constructor.
75 //! Loading constructor.
77 * Loads the tileset.tile XML entities in the tileset configuration
80 Tile(XML_Helper* helper);
87 //! Get the number of movement points needed to cross this tile
88 guint32 getMoves() const {return d_moves;}
90 //! Get the type (grass, hill,...) of this tile type.
91 Type getType() const {return d_type;}
93 //! Get the name of this kind of tile (used in the editor).
94 std::string getName() const {return d_name;}
96 int getTypeIndex() {return getTypeIndexForType(d_type);}
98 SmallTile * getSmallTile() {return d_smalltile;};
103 void setType(Type type) {d_type = type;}
105 //! Set the name of this kind of tile (used in the editor).
106 void setName(std::string name) {d_name = name;}
108 void setTypeByIndex(int idx);
110 //! Set the SmallTile object associated with this tile.
111 void setSmallTile(SmallTile *smalltile) {d_smalltile = smalltile;};
114 // Methods the operate on the class data but do not modify the class
116 //! Save a Tile to an opened tile configuration file.
118 * @param The opened XML tile configuration file.
120 bool save(XML_Helper *helper) const;
122 //! Check to see if this tile is suitable for use within the game.
123 bool validate() const;
125 //! Check to see if the tilestylesets only contain simple tilestyles.
126 bool consistsOnlyOfLoneAndOtherStyles() const;
128 //! Lookup a random tile style for this tile.
130 * Scan the TileStyles for this Tile for a TileStyle that matches
131 * the given style. When there is more than one TileStyle to choose
132 * from, randomly pick one from all of the matching TileStyle objects.
134 * @param style The kind of style we're looking for.
136 * @return A pointer to the matching TileStyle object, or NULL if no
137 * TileStyle could be found with that given style.
139 TileStyle *getRandomTileStyle (TileStyle::Type style) const;
141 // Methods the operate on the class data and modify the class
143 //! Destroy the images associated with this tile.
144 void uninstantiateImages();
146 //! Load the images associated with this tile.
147 void instantiateImages(int tilesize, Tileset *ts);
152 //! Convert a Tile::Type enumerated value to a string.
153 static std::string tileTypeToString(const Tile::Type type);
155 //! Convert a string represenation of a Tile::Type to an enum value.
156 static Tile::Type tileTypeFromString(const std::string str);
158 //! If an army unit can move on these kinds of terrains, it is flying.
159 static guint32 isFlying()
160 {return FOREST | HILLS | WATER | SWAMP | MOUNTAIN;};
162 static int getTypeIndexForType(Tile::Type type);
166 //! Check to see if the grass tilestyles are suitable for in-game use.
167 bool validateGrass(std::list<TileStyle::Type> types) const;
169 //! Check to see if the other tilestyles are suitable for in-game use.
170 bool validateFeature(std::list<TileStyle::Type> types) const;
174 //! The name of this kind of a tile.
176 * The name is taken from the tileset configuration file.
177 * This value doesn't change during gameplay.
178 * It used in the scenario editor, but not used in the game.
179 * Equates to the tileset.tile.d_name XML entities in the tileset
180 * configuration file.
184 //! The number of movement points required to cross this tile.
186 * If an Army unit cannot traverse the tile efficiently it pays
187 * this number of movement points to walk over this tile.
188 * This value doesn't change during gameplay.
189 * Equates to the tileset.tile.d_moves XML entities in the tileset
190 * configuration file.
194 //! The kind of terrain tile this instance represents.
196 * Equates to the tileset.tile.d_type XML entities in the tileset
197 * configuration file.
201 //! What this Tile looks like when it's shown on the miniature map.
202 SmallTile *d_smalltile;