author | truebrain |
Mon, 30 Jun 2008 21:31:23 +0000 | |
branch | noai |
changeset 11111 | 1b984dab8cec |
parent 9800 | ab08ca2a2018 |
permissions | -rw-r--r-- |
9723 | 1 |
/* $Id$ */ |
2 |
||
3 |
/** @file tile_map.h Map writing/reading functions for tiles. */ |
|
4 |
||
5 |
#ifndef TILE_MAP_H |
|
6 |
#define TILE_MAP_H |
|
7 |
||
8 |
#include "tile_type.h" |
|
9 |
#include "slope_type.h" |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
10 |
#include "player_type.h" |
9723 | 11 |
#include "map_func.h" |
12 |
#include "core/bitmath_func.hpp" |
|
13 |
||
14 |
/** |
|
15 |
* Returns the height of a tile |
|
16 |
* |
|
17 |
* This function returns the height of the northern corner of a tile. |
|
18 |
* This is saved in the global map-array. It does not take affect by |
|
19 |
* any slope-data of the tile. |
|
20 |
* |
|
21 |
* @param tile The tile to get the height from |
|
22 |
* @return the height of the tile |
|
23 |
* @pre tile < MapSize() |
|
24 |
*/ |
|
25 |
static inline uint TileHeight(TileIndex tile) |
|
26 |
{ |
|
27 |
assert(tile < MapSize()); |
|
28 |
return GB(_m[tile].type_height, 0, 4); |
|
29 |
} |
|
30 |
||
31 |
/** |
|
32 |
* Sets the height of a tile. |
|
33 |
* |
|
34 |
* This function sets the height of the northern corner of a tile. |
|
35 |
* |
|
36 |
* @param tile The tile to change the height |
|
37 |
* @param height The new height value of the tile |
|
38 |
* @pre tile < MapSize() |
|
39 |
* @pre heigth <= MAX_TILE_HEIGHT |
|
40 |
*/ |
|
41 |
static inline void SetTileHeight(TileIndex tile, uint height) |
|
42 |
{ |
|
43 |
assert(tile < MapSize()); |
|
44 |
assert(height <= MAX_TILE_HEIGHT); |
|
45 |
SB(_m[tile].type_height, 0, 4, height); |
|
46 |
} |
|
47 |
||
48 |
/** |
|
49 |
* Returns the height of a tile in pixels. |
|
50 |
* |
|
51 |
* This function returns the height of the northern corner of a tile in pixels. |
|
52 |
* |
|
53 |
* @param tile The tile to get the height |
|
54 |
* @return The height of the tile in pixel |
|
55 |
*/ |
|
56 |
static inline uint TilePixelHeight(TileIndex tile) |
|
57 |
{ |
|
58 |
return TileHeight(tile) * TILE_HEIGHT; |
|
59 |
} |
|
60 |
||
61 |
/** |
|
62 |
* Get the tiletype of a given tile. |
|
63 |
* |
|
64 |
* @param tile The tile to get the TileType |
|
65 |
* @return The tiletype of the tile |
|
66 |
* @pre tile < MapSize() |
|
67 |
*/ |
|
68 |
static inline TileType GetTileType(TileIndex tile) |
|
69 |
{ |
|
70 |
assert(tile < MapSize()); |
|
71 |
return (TileType)GB(_m[tile].type_height, 4, 4); |
|
72 |
} |
|
73 |
||
74 |
/** |
|
75 |
* Set the type of a tile |
|
76 |
* |
|
77 |
* This functions sets the type of a tile. If the type |
|
78 |
* MP_VOID is selected the tile must be at the south-west or |
|
79 |
* south-east edges of the map and vice versa. |
|
80 |
* |
|
81 |
* @param tile The tile to save the new type |
|
82 |
* @param type The type to save |
|
83 |
* @pre tile < MapSize() |
|
84 |
* @pre type MP_VOID <=> tile is on the south-east or south-west edge. |
|
85 |
*/ |
|
86 |
static inline void SetTileType(TileIndex tile, TileType type) |
|
87 |
{ |
|
88 |
assert(tile < MapSize()); |
|
89 |
/* VOID tiles (and no others) are exactly allowed at the lower left and right |
|
90 |
* edges of the map */ |
|
91 |
assert((TileX(tile) == MapMaxX() || TileY(tile) == MapMaxY()) == (type == MP_VOID)); |
|
92 |
SB(_m[tile].type_height, 4, 4, type); |
|
93 |
} |
|
94 |
||
95 |
/** |
|
96 |
* Checks if a tile is a give tiletype. |
|
97 |
* |
|
98 |
* This function checks if a tile got the given tiletype. |
|
99 |
* |
|
100 |
* @param tile The tile to check |
|
101 |
* @param type The type to check agains |
|
102 |
* @return true If the type matches agains the type of the tile |
|
103 |
*/ |
|
104 |
static inline bool IsTileType(TileIndex tile, TileType type) |
|
105 |
{ |
|
106 |
return GetTileType(tile) == type; |
|
107 |
} |
|
108 |
||
109 |
/** |
|
9800 | 110 |
* Checks if a tile is valid |
111 |
* |
|
112 |
* @param tile The tile to check |
|
113 |
* @return True if the tile is on the map and not one of MP_VOID. |
|
114 |
*/ |
|
115 |
static inline bool IsValidTile(TileIndex tile) |
|
116 |
{ |
|
117 |
return tile < MapSize() && !IsTileType(tile, MP_VOID); |
|
118 |
} |
|
119 |
||
120 |
/** |
|
9723 | 121 |
* Returns the owner of a tile |
122 |
* |
|
123 |
* This function returns the owner of a tile. This cannot used |
|
124 |
* for tiles which type is one of MP_HOUSE, MP_VOID and MP_INDUSTRY |
|
125 |
* as no player owned any of these buildings. |
|
126 |
* |
|
127 |
* @param tile The tile to check |
|
128 |
* @return The owner of the tile |
|
9800 | 129 |
* @pre IsValidTile(tile) |
130 |
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY |
|
9723 | 131 |
*/ |
132 |
static inline Owner GetTileOwner(TileIndex tile) |
|
133 |
{ |
|
9800 | 134 |
assert(IsValidTile(tile)); |
9723 | 135 |
assert(!IsTileType(tile, MP_HOUSE)); |
136 |
assert(!IsTileType(tile, MP_INDUSTRY)); |
|
137 |
||
138 |
return (Owner)_m[tile].m1; |
|
139 |
} |
|
140 |
||
141 |
/** |
|
142 |
* Sets the owner of a tile |
|
143 |
* |
|
144 |
* This function sets the owner status of a tile. Note that you cannot |
|
145 |
* set a owner for tiles of type MP_HOUSE, MP_VOID and MP_INDUSTRY. |
|
146 |
* |
|
147 |
* @param tile The tile to change the owner status. |
|
148 |
* @param owner The new owner. |
|
9800 | 149 |
* @pre IsValidTile(tile) |
150 |
* @pre The type of the tile must not be MP_HOUSE and MP_INDUSTRY |
|
9723 | 151 |
*/ |
152 |
static inline void SetTileOwner(TileIndex tile, Owner owner) |
|
153 |
{ |
|
9800 | 154 |
assert(IsValidTile(tile)); |
9723 | 155 |
assert(!IsTileType(tile, MP_HOUSE)); |
156 |
assert(!IsTileType(tile, MP_INDUSTRY)); |
|
157 |
||
158 |
_m[tile].m1 = owner; |
|
159 |
} |
|
160 |
||
161 |
/** |
|
162 |
* Checks if a tile belongs to the given owner |
|
163 |
* |
|
164 |
* @param tile The tile to check |
|
165 |
* @param owner The owner to check agains |
|
166 |
* @return True if a tile belongs the the given owner |
|
167 |
*/ |
|
168 |
static inline bool IsTileOwner(TileIndex tile, Owner owner) |
|
169 |
{ |
|
170 |
return GetTileOwner(tile) == owner; |
|
171 |
} |
|
172 |
||
173 |
/** |
|
174 |
* Set the tropic zone |
|
175 |
* @param tile the tile to set the zone of |
|
176 |
* @param type the new type |
|
9800 | 177 |
* @pre tile < MapSize() |
9723 | 178 |
*/ |
179 |
static inline void SetTropicZone(TileIndex tile, TropicZone type) |
|
180 |
{ |
|
181 |
assert(tile < MapSize()); |
|
182 |
SB(_m[tile].m6, 0, 2, type); |
|
183 |
} |
|
184 |
||
185 |
/** |
|
186 |
* Get the tropic zone |
|
187 |
* @param tile the tile to get the zone of |
|
9800 | 188 |
* @pre tile < MapSize() |
9723 | 189 |
* @return the zone type |
190 |
*/ |
|
191 |
static inline TropicZone GetTropicZone(TileIndex tile) |
|
192 |
{ |
|
193 |
assert(tile < MapSize()); |
|
194 |
return (TropicZone)GB(_m[tile].m6, 0, 2); |
|
195 |
} |
|
196 |
||
197 |
Slope GetTileSlope(TileIndex tile, uint *h); |
|
198 |
uint GetTileZ(TileIndex tile); |
|
199 |
uint GetTileMaxZ(TileIndex tile); |
|
200 |
||
201 |
#endif /* TILE_TYPE_H */ |