Add: INR currency (#8136)
[openttd-github.git] / src / clear_map.h
blob159f5c6a40add7a84cd315f5cea24b796b6fc9bf
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file clear_map.h Map accessors for 'clear' tiles */
10 #ifndef CLEAR_MAP_H
11 #define CLEAR_MAP_H
13 #include "bridge_map.h"
14 #include "industry_type.h"
16 /**
17 * Ground types. Valid densities in comments after the enum.
19 enum ClearGround {
20 CLEAR_GRASS = 0, ///< 0-3
21 CLEAR_ROUGH = 1, ///< 3
22 CLEAR_ROCKS = 2, ///< 3
23 CLEAR_FIELDS = 3, ///< 3
24 CLEAR_SNOW = 4, ///< 0-3
25 CLEAR_DESERT = 5, ///< 1,3
29 /**
30 * Test if a tile is covered with snow.
31 * @param t the tile to check
32 * @pre IsTileType(t, MP_CLEAR)
33 * @return whether the tile is covered with snow.
35 static inline bool IsSnowTile(TileIndex t)
37 assert(IsTileType(t, MP_CLEAR));
38 return HasBit(_m[t].m3, 4);
41 /**
42 * Get the type of clear tile but never return CLEAR_SNOW.
43 * @param t the tile to get the clear ground type of
44 * @pre IsTileType(t, MP_CLEAR)
45 * @return the ground type
47 static inline ClearGround GetRawClearGround(TileIndex t)
49 assert(IsTileType(t, MP_CLEAR));
50 return (ClearGround)GB(_m[t].m5, 2, 3);
53 /**
54 * Get the type of clear tile.
55 * @param t the tile to get the clear ground type of
56 * @pre IsTileType(t, MP_CLEAR)
57 * @return the ground type
59 static inline ClearGround GetClearGround(TileIndex t)
61 if (IsSnowTile(t)) return CLEAR_SNOW;
62 return GetRawClearGround(t);
65 /**
66 * Set the type of clear tile.
67 * @param t the tile to set the clear ground type of
68 * @param ct the ground type
69 * @pre IsTileType(t, MP_CLEAR)
71 static inline bool IsClearGround(TileIndex t, ClearGround ct)
73 return GetClearGround(t) == ct;
77 /**
78 * Get the density of a non-field clear tile.
79 * @param t the tile to get the density of
80 * @pre IsTileType(t, MP_CLEAR)
81 * @return the density
83 static inline uint GetClearDensity(TileIndex t)
85 assert(IsTileType(t, MP_CLEAR));
86 return GB(_m[t].m5, 0, 2);
89 /**
90 * Increment the density of a non-field clear tile.
91 * @param t the tile to increment the density of
92 * @param d the amount to increment the density with
93 * @pre IsTileType(t, MP_CLEAR)
95 static inline void AddClearDensity(TileIndex t, int d)
97 assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
98 _m[t].m5 += d;
102 * Set the density of a non-field clear tile.
103 * @param t the tile to set the density of
104 * @param d the new density
105 * @pre IsTileType(t, MP_CLEAR)
107 static inline void SetClearDensity(TileIndex t, uint d)
109 assert(IsTileType(t, MP_CLEAR));
110 SB(_m[t].m5, 0, 2, d);
115 * Get the counter used to advance to the next clear density/field type.
116 * @param t the tile to get the counter of
117 * @pre IsTileType(t, MP_CLEAR)
118 * @return the value of the counter
120 static inline uint GetClearCounter(TileIndex t)
122 assert(IsTileType(t, MP_CLEAR));
123 return GB(_m[t].m5, 5, 3);
127 * Increments the counter used to advance to the next clear density/field type.
128 * @param t the tile to increment the counter of
129 * @param c the amount to increment the counter with
130 * @pre IsTileType(t, MP_CLEAR)
132 static inline void AddClearCounter(TileIndex t, int c)
134 assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
135 _m[t].m5 += c << 5;
139 * Sets the counter used to advance to the next clear density/field type.
140 * @param t the tile to set the counter of
141 * @param c the amount to set the counter to
142 * @pre IsTileType(t, MP_CLEAR)
144 static inline void SetClearCounter(TileIndex t, uint c)
146 assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
147 SB(_m[t].m5, 5, 3, c);
152 * Sets ground type and density in one go, also sets the counter to 0
153 * @param t the tile to set the ground type and density for
154 * @param type the new ground type of the tile
155 * @param density the density of the ground tile
156 * @pre IsTileType(t, MP_CLEAR)
158 static inline void SetClearGroundDensity(TileIndex t, ClearGround type, uint density)
160 assert(IsTileType(t, MP_CLEAR)); // XXX incomplete
161 _m[t].m5 = 0 << 5 | type << 2 | density;
166 * Get the field type (production stage) of the field
167 * @param t the field to get the type of
168 * @pre GetClearGround(t) == CLEAR_FIELDS
169 * @return the field type
171 static inline uint GetFieldType(TileIndex t)
173 assert(GetClearGround(t) == CLEAR_FIELDS);
174 return GB(_m[t].m3, 0, 4);
178 * Set the field type (production stage) of the field
179 * @param t the field to get the type of
180 * @param f the field type
181 * @pre GetClearGround(t) == CLEAR_FIELDS
183 static inline void SetFieldType(TileIndex t, uint f)
185 assert(GetClearGround(t) == CLEAR_FIELDS); // XXX incomplete
186 SB(_m[t].m3, 0, 4, f);
190 * Get the industry (farm) that made the field
191 * @param t the field to get creating industry of
192 * @pre GetClearGround(t) == CLEAR_FIELDS
193 * @return the industry that made the field
195 static inline IndustryID GetIndustryIndexOfField(TileIndex t)
197 assert(GetClearGround(t) == CLEAR_FIELDS);
198 return(IndustryID) _m[t].m2;
202 * Set the industry (farm) that made the field
203 * @param t the field to get creating industry of
204 * @param i the industry that made the field
205 * @pre GetClearGround(t) == CLEAR_FIELDS
207 static inline void SetIndustryIndexOfField(TileIndex t, IndustryID i)
209 assert(GetClearGround(t) == CLEAR_FIELDS);
210 _m[t].m2 = i;
215 * Is there a fence at the given border?
216 * @param t the tile to check for fences
217 * @param side the border to check
218 * @pre IsClearGround(t, CLEAR_FIELDS)
219 * @return 0 if there is no fence, otherwise the fence type
221 static inline uint GetFence(TileIndex t, DiagDirection side)
223 assert(IsClearGround(t, CLEAR_FIELDS));
224 switch (side) {
225 default: NOT_REACHED();
226 case DIAGDIR_SE: return GB(_m[t].m4, 2, 3);
227 case DIAGDIR_SW: return GB(_m[t].m4, 5, 3);
228 case DIAGDIR_NE: return GB(_m[t].m3, 5, 3);
229 case DIAGDIR_NW: return GB(_me[t].m6, 2, 3);
234 * Sets the type of fence (and whether there is one) for the given border.
235 * @param t the tile to check for fences
236 * @param side the border to check
237 * @param h 0 if there is no fence, otherwise the fence type
238 * @pre IsClearGround(t, CLEAR_FIELDS)
240 static inline void SetFence(TileIndex t, DiagDirection side, uint h)
242 assert(IsClearGround(t, CLEAR_FIELDS));
243 switch (side) {
244 default: NOT_REACHED();
245 case DIAGDIR_SE: SB(_m[t].m4, 2, 3, h); break;
246 case DIAGDIR_SW: SB(_m[t].m4, 5, 3, h); break;
247 case DIAGDIR_NE: SB(_m[t].m3, 5, 3, h); break;
248 case DIAGDIR_NW: SB(_me[t].m6, 2, 3, h); break;
254 * Make a clear tile.
255 * @param t the tile to make a clear tile
256 * @param g the type of ground
257 * @param density the density of the grass/snow/desert etc
259 static inline void MakeClear(TileIndex t, ClearGround g, uint density)
261 SetTileType(t, MP_CLEAR);
262 _m[t].m1 = 0;
263 SetTileOwner(t, OWNER_NONE);
264 _m[t].m2 = 0;
265 _m[t].m3 = 0;
266 _m[t].m4 = 0 << 5 | 0 << 2;
267 SetClearGroundDensity(t, g, density); // Sets m5
268 _me[t].m6 = 0;
269 _me[t].m7 = 0;
270 _me[t].m8 = 0;
275 * Make a (farm) field tile.
276 * @param t the tile to make a farm field
277 * @param field_type the 'growth' level of the field
278 * @param industry the industry this tile belongs to
280 static inline void MakeField(TileIndex t, uint field_type, IndustryID industry)
282 SetTileType(t, MP_CLEAR);
283 _m[t].m1 = 0;
284 SetTileOwner(t, OWNER_NONE);
285 _m[t].m2 = industry;
286 _m[t].m3 = field_type;
287 _m[t].m4 = 0 << 5 | 0 << 2;
288 SetClearGroundDensity(t, CLEAR_FIELDS, 3);
289 SB(_me[t].m6, 2, 4, 0);
290 _me[t].m7 = 0;
291 _me[t].m8 = 0;
295 * Make a snow tile.
296 * @param t the tile to make snowy
297 * @param density The density of snowiness.
298 * @pre GetClearGround(t) != CLEAR_SNOW
300 static inline void MakeSnow(TileIndex t, uint density = 0)
302 assert(GetClearGround(t) != CLEAR_SNOW);
303 SetBit(_m[t].m3, 4);
304 if (GetRawClearGround(t) == CLEAR_FIELDS) {
305 SetClearGroundDensity(t, CLEAR_GRASS, density);
306 } else {
307 SetClearDensity(t, density);
312 * Clear the snow from a tile and return it to its previous type.
313 * @param t the tile to clear of snow
314 * @pre GetClearGround(t) == CLEAR_SNOW
316 static inline void ClearSnow(TileIndex t)
318 assert(GetClearGround(t) == CLEAR_SNOW);
319 ClrBit(_m[t].m3, 4);
320 SetClearDensity(t, 3);
323 #endif /* CLEAR_MAP_H */