850c503b6ac3ee8e51294e23f1ab408e898a4cc3
[lordsawar] / src / maptile.h
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
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 #ifndef MAPTILE_H
21 #define MAPTILE_H
22
23 #include <list>
24 #include "Tile.h"
25 #include "SmallTile.h"
26 #include "tileset.h"
27 #include "Item.h"
28 class MapBackpack;
29 class StackTile;
30
31 //! A single tile on the game map.
32 /** 
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.
36  *
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.
42  *
43  * The GameMap contains on Maptile object for every cell of the map.
44  *
45  */
46 class Maptile
47 {
48     public:
49         //! Enumeration of all possible constructed objects on the maptile.
50         /**
51          * Each member in the enumeration refers to a class that inherits 
52          * the Location class.
53          */
54         enum Building {
55           //! Bupkiss.  Nothing built here.
56           NONE=0, 
57           //! A City is built here.
58           CITY=1, 
59           //! A Ruin is built here.
60           RUIN=2, 
61           //! A Temple is built here.
62           TEMPLE=3, 
63           //! A Signpost is built here.
64           SIGNPOST=4, 
65           //! A Road is built here.
66           ROAD=6, 
67           //! A Port is built here.
68           PORT=7, 
69           //! A Bridge is built here.
70           BRIDGE=8
71         };
72
73         //! Default constructor.
74         /** 
75          * Make a new Maptile.
76          *
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.
82          */
83         Maptile(Tileset* tileSet, int x, int y, guint32 type, 
84                 TileStyle *tileStyle);
85
86         //! Slower constructor.
87         /** 
88          * Make a new Maptile, but this time using the Tile::Type.
89          *
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.
95          */
96         Maptile(Tileset* tileSet, int x, int y, Tile::Type type, 
97                 TileStyle *tileStyle);
98
99         //! Destructor.
100         ~Maptile();
101
102         //! Set the type of the terrain (type is an index in the tileset).
103         void setType(guint32 index){d_index = index;}
104
105         //! Set which kind of building is on this maptile.
106         void setBuilding(Building building){d_building = building;}
107
108         //! Get the index of the tile type in the tileset.
109         guint32 getType() const {return d_index;}
110
111         //! Get which building is on the maptile.
112         Building getBuilding() const {return d_building;}
113
114         //! Get the number of moves needed to cross this maptile.
115         /**
116          * This method refers to the Tile::getMoves method, but then also 
117          * takes into account the buildings on the tile.
118          * 
119          * @return The number of movement points required to cross this 
120          *         Maptile.
121          */
122         guint32 getMoves() const;
123
124         //! Get the smallmap color of this maptile.
125         Gdk::Color getColor() const
126           {return (*d_tileSet)[d_index]->getSmallTile()->getColor();}
127
128         //! Get the pattern of this maptile on the smallmap.
129        SmallTile::Pattern getPattern() const
130           {return (*d_tileSet)[d_index]->getSmallTile()->getPattern();}
131
132         //! Get the associated colour with the pattern.
133        Gdk::Color getSecondColor() const
134           {return (*d_tileSet)[d_index]->getSmallTile()->getSecondColor();}
135
136         //! Get the associated colour with the pattern.
137        Gdk::Color getThirdColor() const
138           {return (*d_tileSet)[d_index]->getSmallTile()->getThirdColor();}
139
140         //! Get the tile type (the type of the underlying terrain).
141         Tile::Type getMaptileType() const
142           {return (*d_tileSet)[d_index]->getType();}
143
144         //! Get the list of Item objects on this maptile.
145         MapBackpack *getBackpack() const {return d_backpack;};
146
147         //! Get the list of Stack objects on this maptile.
148         StackTile *getStacks() const {return d_stacktile;};
149         
150         //! Whether or not this map tile considered to be "open terrain".
151         /**
152          *
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.
156          */
157         bool isOpenTerrain();
158
159         //! Whether or not this map tile is considered to be "hilly terrain".
160         /**
161          *
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.
165          */
166         bool isHillyTerrain();
167
168         //! Whether or not this map tile is considered to be "city terrain".
169         /**
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.
173          */
174         bool isCityTerrain();
175
176         //! Prints some debug information about this maptile.
177         void printDebugInfo() const;
178                 
179         bool d_blocked[8];
180
181         //! Get the TileStyle associated with this Maptile.
182         TileStyle * getTileStyle() const {return d_tileStyle;}
183
184         //! Set the TileStyle associated with this Maptile.
185         void setTileStyle(TileStyle *style) {d_tileStyle = style;}
186
187         static Maptile::Building buildingFromString(const std::string str);
188         static std::string buildingToString(const Maptile::Building bldg);
189     private:
190         //! The index of the Tile within the Tileset (Maptile::d_tileSet).
191         /**
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.
194          */
195         guint32 d_index;
196         //! The Tileset of the Tile referred to by Maptile::d_index.
197         Tileset* d_tileSet;
198         //! The look of the maptile.
199         TileStyle *d_tileStyle;
200         //! The type of constructed object on this maptile.
201         Building d_building;
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;
206 };
207
208 #endif // MAPTILE_H
209
210 // End of file