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-2010, 2012, 2014, 2015, 2017 Ben Asselstine
5 //
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.
10 //
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.
15 //
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
19 //  02110-1301, USA.
20 
21 #pragma once
22 #ifndef MAPTILE_H
23 #define MAPTILE_H
24 
25 #include <list>
26 #include "Tile.h"
27 #include "Movable.h"
28 #include "SmallTile.h"
29 #include "MapBackpack.h"
30 class StackTile;
31 
32 //! A single tile on the game map.
33 /**
34  * The Maptile class encapsulates all information one may want to get about a
35  * single maptile of the game map.  Specifically, it stores the type of and the
36  * buildings on the map tile.
37  *
38  * A remark concerning the type.  A maptile has two types. First, the type
39  * value is an index in the tileset which says which tile type this maptile
40  * has, e.g. "This maptile is of the sort of the first tile in the tileset".
41  * The maptile type says which terrain type this maptile has,
42  * e.g. grass or swamps.
43  *
44  * The GameMap contains on Maptile object for every cell of the map.
45  *
46  */
47 class Maptile: public Movable
48 {
49     public:
50         //! Enumeration of all possible constructed objects on the maptile.
51 	/**
52 	 * Each member in the enumeration refers to a class that inherits
53 	 * the Location class.
54 	 */
55         enum Building {
56 	  //! Bupkiss.  Nothing built here.
57 	  NONE=0,
58 	  //! A City is built here.
59 	  CITY=1,
60 	  //! A Ruin is built here.
61 	  RUIN=2,
62 	  //! A Temple is built here.
63 	  TEMPLE=3,
64 	  //! A Signpost is built here.
65 	  SIGNPOST=4,
66 	  //! A Road is built here.
67 	  ROAD=6,
68 	  //! A Port is built here.
69 	  PORT=7,
70 	  //! A Bridge is built here.
71 	  BRIDGE=8,
72 	  //! A Standing stone is built here.
73 	  STONE=9
74 	};
75 
76 	//! Default constructor.
77         Maptile();
78 
79 	//! Default constructor.
80         /**
81 	 * Make a new Maptile.
82 	 *
83          * @param x                The x position of the tile.
84          * @param y                The y position of the tile.
85          * @param type             The terrain type (index in the tileset).
86          *
87          * no tilestyle is set.
88          */
89         Maptile(int x, int y, guint32 type);
90 
91 	//! Slower constructor.
92         /**
93 	 * Make a new Maptile, but this time using the Tile::Type.
94 	 *
95          * @param x                The x position of the tile.
96          * @param y                The y position of the tile.
97          * @param type             The terrain type enumeration Tile::Type.
98          *
99          * no tilestyle is set.
100          */
101         Maptile(int x, int y, Tile::Type type);
102 
103 	//! Destructor.
104         ~Maptile();
105 
106         //! Set the type of the terrain (type is an index in the tileset).
107         void setIndex(guint32 index);
108 
109         //! Set which kind of building is on this maptile.
setBuilding(Building building)110         void setBuilding(Building building){d_building = building;}
111 
112         //! Get the index of the tile type in the tileset.
getIndex()113         guint32 getIndex() const {return d_index;}
114 
115         //! Get which building is on the maptile.
getBuilding()116         inline Building getBuilding() const {return d_building;}
117 
118         //! Get the number of moves needed to cross this maptile.
119 	/**
120 	 * This method refers to the Tile::getMoves method, but then also
121 	 * takes into account the buildings on the tile.
122 	 *
123 	 * @return The number of movement points required to cross this
124 	 *         Maptile.
125 	 */
126         guint32 getMoves() const;
127 
128         //! Get the smalltile color of this maptile.
129 	Gdk::RGBA getColor() const;
130 
131 	//! Get the pattern of this maptile on the smalltile.
132        SmallTile::Pattern getPattern() const;
133 
134 	//! Get the associated colour with the pattern.
135        Gdk::RGBA getSecondColor() const;
136 
137 	//! Get the associated colour with the pattern.
138        Gdk::RGBA getThirdColor() const;
139 
140         //! Get the tile type (the type of the underlying terrain).
141         Tile::Type getType() const;
142 
143         //! Get the list of Item objects on this maptile.
144         MapBackpack *getBackpack();
145 
146 	//! Get the list of Stack objects on this maptile.
147 	StackTile *getStacks();
148 
149         //! Set the backpack for this tile.
setBackpack(MapBackpack * bag)150         void setBackpack(MapBackpack *bag) {if (getBackpack()) delete getBackpack(); d_backpack = bag;};
151 
152 	//! Whether or not this map tile considered to be "open terrain".
153 	/**
154 	 *
155 	 * This is used for battle bonus calculations.  An Army unit can
156 	 * potentially have a bonus for being `out in the open' -- and this
157 	 * method defines if this maptile is `out in the open' or not.
158 	 */
159 	bool isOpenTerrain();
160 
161 	//! Whether or not this map tile is considered to be "hilly terrain".
162 	/**
163 	 *
164 	 * This is used for battle bonus calculations.  An Army unit can
165 	 * potentially have a bonus for being `in the hills' -- and this method
166 	 * defines if this maptile is `in the hills' or not.
167 	 */
168         bool isHillyTerrain();
169 
170 	//! Whether or not this map tile is considered to be "city terrain".
171 	/**
172 	 * This is used for battle bonus calculations.  An Army unit can
173 	 * potentially have a bonus for being `in a city' -- and this method
174 	 * defines if this maptile is `in a city' or not.
175 	 */
176         bool isCityTerrain();
177 
178         //! Whether or not this map tile is considered to be a road.
179         /**
180          * includes roads and bridges.
181          */
182         bool isRoadTerrain();
183 
184         //! Whether or not there is a building on this tile that belongs on land.
185         bool hasLandBuilding() const;
186 
187         //! Whether or not there is a building on this tile that belongs on water.
188         bool hasWaterBuilding() const;
189         //! Prints some debug information about this maptile.
190 
191 	bool d_blocked[8];
192 
193 	//! Get the TileStyle associated with this Maptile.
getTileStyle()194 	TileStyle * getTileStyle() const {return d_tileStyle;}
195 
196 	//! Set the TileStyle associated with this Maptile.
setTileStyle(TileStyle * style)197 	void setTileStyle(TileStyle *style) {d_tileStyle = style;}
198 
199 	static Maptile::Building buildingFromString(const Glib::ustring str);
200 	static Glib::ustring buildingToString(const Maptile::Building bldg);
201         static Glib::ustring buildingToFriendlyName(const guint32 bldg);
202     private:
203 	//! The index of the Tile within the Tileset (GameMap::s_tileset).
204 	/**
205 	 * The Maptile has a type, in the form of a Tile.  This Tile is
206 	 * identified by it's index within GameMap::s_tileset.
207 	 */
208         guint32 d_index;
209 
210 	//! The look of the maptile.
211 	TileStyle *d_tileStyle;
212 
213 	//! The type of constructed object on this maptile.
214         Building d_building;
215 
216 	//! The list of pointers to items on this maptile.
217 	MapBackpack *d_backpack;
218 
219 	//! The list of pointers to stacks on this maptile.
220 	StackTile *d_stacktile;
221 };
222 
223 #endif // MAPTILE_H
224 
225 // End of file
226