1 // Copyright (C) 2003 Michael Bartl
2 // Copyright (C) 2003, 2004, 2005, 2006 Ulf Lorenz
3 // Copyright (C) 2005 Andrea Paternesi
4 // Copyright (C) 2006, 2007, 2008, 2009 Ben Asselstine
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 3 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Library General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "SmallTile.h"
31 //! A single tile on the game map.
33 * The Maptile class encapsulates all information one may want to get about a
34 * single maptile of the game map. Specifically, it stores the type of and the
35 * buildings on the map tile.
37 * A remark concerning the type. A maptile has two types. First, the type
38 * value is an index in the tileset which says which tile type this maptile
39 * has, e.g. "This maptile is of the sort of the first tile in the tileset".
40 * The maptile type says which terrain type this maptile has,
41 * e.g. grass or swamps.
43 * The GameMap contains on Maptile object for every cell of the map.
49 //! Enumeration of all possible constructed objects on the maptile.
51 * Each member in the enumeration refers to a class that inherits
55 //! Bupkiss. Nothing built here.
57 //! A City is built here.
59 //! A Ruin is built here.
61 //! A Temple is built here.
63 //! A Signpost is built here.
65 //! A Road is built here.
67 //! A Port is built here.
69 //! A Bridge is built here.
73 //! Default constructor.
77 * @param tileSet The tileset to use.
78 * @param x The x position of the tile.
79 * @param y The y position of the tile.
80 * @param type The terrain type (index in the tileset).
81 * @param tileStyle The look of this tile to use.
83 Maptile(Tileset* tileSet, int x, int y, guint32 type,
84 TileStyle *tileStyle);
86 //! Slower constructor.
88 * Make a new Maptile, but this time using the Tile::Type.
90 * @param tileSet The tileset to use.
91 * @param x The x position of the tile.
92 * @param y The y position of the tile.
93 * @param type The terrain type enumeration Tile::Type.
94 * @param tileStyle The look of this tile to use.
96 Maptile(Tileset* tileSet, int x, int y, Tile::Type type,
97 TileStyle *tileStyle);
102 //! Set the type of the terrain (type is an index in the tileset).
103 void setType(guint32 index){d_index = index;}
105 //! Set which kind of building is on this maptile.
106 void setBuilding(Building building){d_building = building;}
108 //! Get the index of the tile type in the tileset.
109 guint32 getType() const {return d_index;}
111 //! Get which building is on the maptile.
112 Building getBuilding() const {return d_building;}
114 //! Get the number of moves needed to cross this maptile.
116 * This method refers to the Tile::getMoves method, but then also
117 * takes into account the buildings on the tile.
119 * @return The number of movement points required to cross this
122 guint32 getMoves() const;
124 //! Get the smallmap color of this maptile.
125 Gdk::Color getColor() const
126 {return (*d_tileSet)[d_index]->getSmallTile()->getColor();}
128 //! Get the pattern of this maptile on the smallmap.
129 SmallTile::Pattern getPattern() const
130 {return (*d_tileSet)[d_index]->getSmallTile()->getPattern();}
132 //! Get the associated colour with the pattern.
133 Gdk::Color getSecondColor() const
134 {return (*d_tileSet)[d_index]->getSmallTile()->getSecondColor();}
136 //! Get the associated colour with the pattern.
137 Gdk::Color getThirdColor() const
138 {return (*d_tileSet)[d_index]->getSmallTile()->getThirdColor();}
140 //! Get the tile type (the type of the underlying terrain).
141 Tile::Type getMaptileType() const
142 {return (*d_tileSet)[d_index]->getType();}
144 //! Get the list of Item objects on this maptile.
145 MapBackpack *getBackpack() const {return d_backpack;};
147 //! Get the list of Stack objects on this maptile.
148 StackTile *getStacks() const {return d_stacktile;};
150 //! Whether or not this map tile considered to be "open terrain".
153 * This is used for battle bonus calculations. An Army unit can
154 * potentially have a bonus for being `out in the open' -- and this
155 * method defines if this maptile is `out in the open' or not.
157 bool isOpenTerrain();
159 //! Whether or not this map tile is considered to be "hilly terrain".
162 * This is used for battle bonus calculations. An Army unit can
163 * potentially have a bonus for being `in the hills' -- and this method
164 * defines if this maptile is `in the hills' or not.
166 bool isHillyTerrain();
168 //! Whether or not this map tile is considered to be "city terrain".
170 * This is used for battle bonus calculations. An Army unit can
171 * potentially have a bonus for being `in a city' -- and this method
172 * defines if this maptile is `in a city' or not.
174 bool isCityTerrain();
176 //! Prints some debug information about this maptile.
177 void printDebugInfo() const;
181 //! Get the TileStyle associated with this Maptile.
182 TileStyle * getTileStyle() const {return d_tileStyle;}
184 //! Set the TileStyle associated with this Maptile.
185 void setTileStyle(TileStyle *style) {d_tileStyle = style;}
187 static Maptile::Building buildingFromString(const std::string str);
188 static std::string buildingToString(const Maptile::Building bldg);
190 //! The index of the Tile within the Tileset (Maptile::d_tileSet).
192 * The Maptile has a type, in the form of a Tile. This Tile is
193 * identified by it's index within Maptile::d_tileSet.
196 //! The Tileset of the Tile referred to by Maptile::d_index.
198 //! The look of the maptile.
199 TileStyle *d_tileStyle;
200 //! The type of constructed object on this maptile.
202 //! The list of pointers to items on this maptile.
203 MapBackpack *d_backpack;
204 //! The list of pointers to stacks on this maptile.
205 StackTile *d_stacktile;