20
11
#include "tileset.h"
23
/** A single tile on the map
25
* The Maptile class encapsulates all information one may want to get about a
26
* single maptile of the game map. Specifically, it stores the type of and the
27
* buildings on the map tile.
29
* A remark concerning the type. A maptile has two types. First, the type value
30
* is an index in the tileset which says which tile type this maptile has, e.g.
31
* "This maptile is of the sort of the first tile in the tileset". The maptile
32
* type says which terrain type this maptile has, e.g. grass or swamps.
14
//! A single tile on the game map.
16
* The Maptile class encapsulates all information one may want to get about a
17
* single maptile of the game map. Specifically, it stores the type of and the
18
* buildings on the map tile.
20
* A remark concerning the type. A maptile has two types. First, the type
21
* value is an index in the tileset which says which tile type this maptile
22
* has, e.g. "This maptile is of the sort of the first tile in the tileset".
23
* The maptile type says which terrain type this maptile has,
24
* e.g. grass or swamps.
26
* The GameMap contains on Maptile object for every cell of the map.
38
//! Enum of possible buldings on the tile
39
enum Building {NONE=0, CITY=1, RUIN=2, TEMPLE=3, SIGNPOST=4, ROAD=6, PORT=7, BRIDGE=8};
41
/** Default constructor
43
* @param tileSet the tileset to use
44
* @param x the x position of the tile
45
* @param y the y position of the tile
46
* @param type the terrain type (index in the tileset)
47
* @param tileStyle the look of this tile to use
49
Maptile(Tileset* tileSet, int x, int y, Uint32 type, TileStyle *tileStyle);
32
//! Enumeration of all possible constructed objects on the maptile.
34
* Each member in the enumeration refers to a class that inherits
38
//! Bupkiss. Nothing built here.
40
//! A City is built here.
42
//! A Ruin is built here.
44
//! A Temple is built here.
46
//! A Signpost is built here.
48
//! A Road is built here.
50
//! A Port is built here.
52
//! A Bridge is built here.
56
//! Default constructor.
60
* @param tileSet The tileset to use.
61
* @param x The x position of the tile.
62
* @param y The y position of the tile.
63
* @param type The terrain type (index in the tileset).
64
* @param tileStyle The look of this tile to use.
66
Maptile(Tileset* tileSet, int x, int y, Uint32 type,
67
TileStyle *tileStyle);
69
//! Slower constructor.
71
* Make a new Maptile, but this time using the Tile::Type.
73
* @param tileSet The tileset to use.
74
* @param x The x position of the tile.
75
* @param y The y position of the tile.
76
* @param type The terrain type enumeration Tile::Type.
77
* @param tileStyle The look of this tile to use.
79
Maptile(Tileset* tileSet, int x, int y, Tile::Type type,
80
TileStyle *tileStyle);
52
//! Set the type of the terrain (type is an index in the tileset)
85
//! Set the type of the terrain (type is an index in the tileset).
53
86
void setType(Uint32 index){d_index = index;}
55
//! Set which building is on this maptile
88
//! Set which kind of building is on this maptile.
56
89
void setBuilding(Building building){d_building = building;}
59
//! Get the index of the tile type in the tileset
91
//! Get the index of the tile type in the tileset.
60
92
Uint32 getType() const {return d_index;}
62
//! Get which building is on the maptile
94
//! Get which building is on the maptile.
63
95
Building getBuilding() const {return d_building;}
65
//! Get the number of moves needed to cross this maptile
97
//! Get the number of moves needed to cross this maptile.
99
* This method refers to the Tile::getMoves method, but then also
100
* takes into account the buildings on the tile.
102
* @return The number of movement points required to cross this
66
105
Uint32 getMoves() const;
68
//! Get the smallmap color of this maptile
69
SDL_Color getColor() const;
71
//! Get the pattern of this maptile on the smallmap
72
Tile::Pattern getPattern() const;
74
//! Get the associated colour with the pattern
75
SDL_Color getSecondColor() const;
77
//! Get the associated colour with the pattern
78
SDL_Color getThirdColor() const;
80
//! Get the tile type (the type of the underlying terrain)
81
Tile::Type getMaptileType() const;
83
//! Add an item to the maptile at a specific position in the list (<0 => to the end)
84
void addItem(Item*, int position=-1);
86
//! Remove an item from the maptile withut deleting it (!)
107
//! Get the smallmap color of this maptile.
108
SDL_Color getColor() const
109
{return (*d_tileSet)[d_index]->getColor();}
111
//! Get the pattern of this maptile on the smallmap.
112
Tile::Pattern getPattern() const
113
{return (*d_tileSet)[d_index]->getPattern();}
115
//! Get the associated colour with the pattern.
116
SDL_Color getSecondColor() const
117
{return (*d_tileSet)[d_index]->getSecondColor();}
119
//! Get the associated colour with the pattern.
120
SDL_Color getThirdColor() const
121
{return (*d_tileSet)[d_index]->getThirdColor();}
123
//! Get the tile type (the type of the underlying terrain).
124
Tile::Type getMaptileType() const
125
{return (*d_tileSet)[d_index]->getType();}
127
//! Add an Item to the maptile.
129
* Put an Item on this spot. If there are others, specify the
130
* position among the list of other items.
132
* @param item The item to add to the maptile.
133
* @param position Where to add it in the list of items already
134
* here. -1 means add to the end.
136
void addItem(Item*, int position = -1);
138
//! Remove an Item from the maptile without deleting it.
87
139
void removeItem(Item* item);
89
//! Get the items located at this maptile
141
//! Get the list of Item objects on this maptile.
90
142
std::list<Item*> getItems() const;
92
//! is this map tile considered to be "open terrain".
93
//! this is used for bonus calculations
144
//! Whether or not this map tile considered to be "open terrain".
147
* This is used for battle bonus calculations. An Army unit can
148
* potentially have a bonus for being `out in the open' -- and this
149
* method defines if this maptile is `out in the open' or not.
94
151
bool isOpenTerrain();
96
//! is this map tile considered to be "hilly terrain".
97
//! this is used for bonus calculations
153
//! Whether or not this map tile is considered to be "hilly terrain".
156
* This is used for battle bonus calculations. An Army unit can
157
* potentially have a bonus for being `in the hills' -- and this method
158
* defines if this maptile is `in the hills' or not.
98
160
bool isHillyTerrain();
100
//! is this map tile considered to be "city terrain".
101
//! this is used for bonus calculations
162
//! Whether or not this map tile is considered to be "city terrain".
164
* This is used for battle bonus calculations. An Army unit can
165
* potentially have a bonus for being `in a city' -- and this method
166
* defines if this maptile is `in a city' or not.
102
168
bool isCityTerrain();
104
//prints some debug information
170
//! Prints some debug information about this maptile.
105
171
void printDebugInfo() const;
107
173
bool d_blocked[8];
175
//! Get the TileStyle associated with this Maptile.
109
176
TileStyle * getTileStyle() const {return d_tileStyle;}
178
//! Set the TileStyle associated with this Maptile.
111
179
void setTileStyle(TileStyle *style) {d_tileStyle = style;}
182
//! The index of the Tile within the Tileset (Maptile::d_tileSet).
184
* The Maptile has a type, in the form of a Tile. This Tile is
185
* identified by it's index within Maptile::d_tileSet.
188
//! The Tileset of the Tile referred to by Maptile::d_index.
114
189
Tileset* d_tileSet;
190
//! The look of the maptile.
116
191
TileStyle *d_tileStyle;
117
Building d_building; // which building is on this maptile
192
//! The type of constructed object on this maptile.
194
//! The list of pointers to items on this maptile.
118
195
std::list<Item*> d_items;