Translations update
[openttd/fttd.git] / src / map / water.h
blobf2f525bbfa1021833b25e216d35004c8437e7db8
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 map/water.h Map tile accessors for water tiles. */
10 #ifndef MAP_WATER_H
11 #define MAP_WATER_H
13 #include "../stdafx.h"
14 #include "../tile/common.h"
15 #include "../tile/water.h"
16 #include "map.h"
17 #include "coord.h"
18 #include "common.h"
19 #include "../direction_type.h"
20 #include "../direction_func.h"
21 #include "../company_type.h"
23 /**
24 * Get the water tile type at a tile.
25 * @param t Water tile to query.
26 * @return Water tile type at the tile.
28 static inline WaterTileType GetWaterTileType(TileIndex t)
30 return tile_get_water_type(&_mc[t]);
33 /**
34 * Is it a plain water tile?
35 * @param t Water tile to query.
36 * @return \c true if any type of clear water like ocean, river, or canal.
37 * @pre IsWaterTile(t)
39 static inline bool IsPlainWater(TileIndex t)
41 return tile_water_is_clear(&_mc[t]);
44 /**
45 * Is it a coast tile?
46 * @param t Water tile to query.
47 * @return \c true if it is a sea water tile.
48 * @pre IsWaterTile(t)
50 static inline bool IsCoast(TileIndex t)
52 return tile_water_is_coast(&_mc[t]);
55 /**
56 * Is it a water tile with a ship depot on it?
57 * @param t Water tile to query.
58 * @return \c true if it is a ship depot tile.
59 * @pre IsWaterTile(t)
61 static inline bool IsShipDepot(TileIndex t)
63 return tile_water_is_depot(&_mc[t]);
66 /**
67 * Is there a lock on a given water tile?
68 * @param t Water tile to query.
69 * @return \c true if it is a water lock tile.
70 * @pre IsWaterTile(t)
72 static inline bool IsLock(TileIndex t)
74 return tile_water_is_lock(&_mc[t]);
77 /**
78 * Is it a water tile with plain water?
79 * @param t Tile to query.
80 * @return \c true if it is a plain water tile.
82 static inline bool IsPlainWaterTile(TileIndex t)
84 return tile_is_clear_water(&_mc[t]);
87 /**
88 * Is it a coast tile
89 * @param t Tile to query.
90 * @return \c true if it is a coast.
92 static inline bool IsCoastTile(TileIndex t)
94 return tile_is_coast(&_mc[t]);
97 /**
98 * Is it a ship depot tile?
99 * @param t Tile to query.
100 * @return \c true if it is a ship depot tile.
102 static inline bool IsShipDepotTile(TileIndex t)
104 return tile_is_ship_depot(&_mc[t]);
108 * Is it a lock tile?
109 * @param t Tile to query.
110 * @return \c true if it is a lock tile.
112 static inline bool IsLockTile(TileIndex t)
114 return tile_is_lock(&_mc[t]);
119 * Checks whether the tile has an waterclass associated.
120 * You can then subsequently call GetWaterClass().
121 * @param t Tile to query.
122 * @return True if the tiletype has a waterclass.
124 static inline bool HasTileWaterClass(TileIndex t)
126 return tile_has_water_class(&_mc[t]);
130 * Get the water class at a tile.
131 * @param t Water tile to query.
132 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
133 * @return Water class at the tile.
135 static inline WaterClass GetWaterClass(TileIndex t)
137 return tile_get_water_class(&_mc[t]);
141 * Set the water class at a tile.
142 * @param t Water tile to change.
143 * @param wc New water class.
144 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
146 static inline void SetWaterClass(TileIndex t, WaterClass wc)
148 tile_set_water_class(&_mc[t], wc);
152 * Tests if the tile was built on water.
153 * @param t the tile to check
154 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
155 * @return true iff on water
157 static inline bool IsTileOnWater(TileIndex t)
159 return tile_is_on_water(&_mc[t]);
164 * Is it a sea water tile?
165 * @param t Water tile to query.
166 * @return \c true if it is a sea water tile.
167 * @pre IsWaterTile(t)
169 static inline bool IsSea(TileIndex t)
171 return tile_water_is_sea(&_mc[t]);
175 * Is it a canal tile?
176 * @param t Water tile to query.
177 * @return \c true if it is a canal tile.
178 * @pre IsWaterTile(t)
180 static inline bool IsCanal(TileIndex t)
182 return tile_water_is_canal(&_mc[t]);
186 * Is it a river water tile?
187 * @param t Water tile to query.
188 * @return \c true if it is a river water tile.
189 * @pre IsWaterTile(t)
191 static inline bool IsRiver(TileIndex t)
193 return tile_water_is_river(&_mc[t]);
198 * Get the direction of the ship depot.
199 * @param t Water tile to query.
200 * @return Direction of the depot.
201 * @pre IsShipDepotTile(t)
203 static inline DiagDirection GetShipDepotDirection(TileIndex t)
205 return tile_get_ship_depot_direction(&_mc[t]);
209 * Get the other tile of the ship depot.
210 * @param t Tile to query, containing one section of a ship depot.
211 * @return Tile containing the other section of the depot.
212 * @pre IsShipDepotTile(t)
214 static inline TileIndex GetOtherShipDepotTile(TileIndex t)
216 return t - TileOffsByDiagDir(GetShipDepotDirection(t));
220 * Get the most northern tile of a ship depot.
221 * @param t One of the tiles of the ship depot.
222 * @return The northern tile of the depot.
223 * @pre IsShipDepotTile(t)
225 static inline TileIndex GetShipDepotNorthTile(TileIndex t)
227 assert(IsShipDepot(t));
228 TileIndex tile2 = GetOtherShipDepotTile(t);
230 return t < tile2 ? t : tile2;
235 * Get the direction of the water lock.
236 * @param t Water tile to query.
237 * @return Direction of the lock.
238 * @pre IsWaterTile(t) && IsLock(t)
240 static inline DiagDirection GetLockDirection(TileIndex t)
242 return tile_get_lock_direction(&_mc[t]);
247 * Get the random bits of the water tile.
248 * @param t Water tile to query.
249 * @return Random bits of the tile.
250 * @pre IsWaterTile(t)
252 static inline byte GetWaterTileRandomBits(TileIndex t)
254 assert(IsWaterTile(t));
255 return tile_get_random_bits(&_mc[t]);
260 * Checks whether the tile has water at the ground.
261 * That is, it is either some plain water tile, or a object/industry/station/... with water under it.
262 * @return true iff the tile has water at the ground.
263 * @note Coast tiles are not considered waterish, even if there is water on a halftile.
265 static inline bool HasTileWaterGround(TileIndex t)
267 return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t);
272 * Helper function for making a watery tile.
273 * @param t The tile to change into water
274 * @param o The owner of the water
275 * @param wc The class of water the tile has to be
276 * @param random_bits Eventual random bits to be set for this tile
278 static inline void MakeWater(TileIndex t, Owner o, WaterClass wc, uint8 random_bits)
280 tile_make_water(&_mc[t], o, wc, random_bits);
284 * Make a sea tile.
285 * @param t The tile to change into sea
287 static inline void MakeSea(TileIndex t)
289 tile_make_sea(&_mc[t]);
293 * Make a canal tile
294 * @param t The tile to change into canal
295 * @param o The owner of the canal
296 * @param random_bits Random bits to be set for this tile
298 static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
300 tile_make_canal(&_mc[t], o, random_bits);
304 * Make a river tile
305 * @param t The tile to change into river
306 * @param random_bits Random bits to be set for this tile
308 static inline void MakeRiver(TileIndex t, uint8 random_bits)
310 tile_make_river(&_mc[t], random_bits);
314 * Helper function to make a coast tile.
315 * @param t The tile to change into water
317 static inline void MakeShore(TileIndex t)
319 tile_make_shore(&_mc[t]);
323 * Make a ship depot section.
324 * @param t Tile to place the ship depot section.
325 * @param o Owner of the depot.
326 * @param did Depot ID.
327 * @param dir Direction of the depot.
328 * @param original_water_class Original water class.
330 static inline void MakeShipDepot(TileIndex t, Owner o, uint did, DiagDirection dir, WaterClass original_water_class)
332 tile_make_ship_depot(&_mc[t], o, did, dir, original_water_class);
336 * Make a lock section.
337 * @param t Tile to place the water lock section.
338 * @param o Owner of the lock.
339 * @param part Part to place.
340 * @param dir Lock orientation
341 * @param original_water_class Original water class.
342 * @see MakeLock
344 static inline void MakeLockTile(TileIndex t, Owner o, WaterTileType part, DiagDirection dir, WaterClass original_water_class)
346 tile_make_lock(&_mc[t], o, part, dir, original_water_class);
350 * Make a water lock.
351 * @param t Tile to place the water lock section.
352 * @param o Owner of the lock.
353 * @param d Direction of the water lock.
354 * @param wc_lower Original water class of the lower part.
355 * @param wc_upper Original water class of the upper part.
356 * @param wc_middle Original water class of the middle part.
358 static inline void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper, WaterClass wc_middle)
360 TileIndexDiff delta = TileOffsByDiagDir(d);
362 /* Keep the current waterclass and owner for the tiles.
363 * It allows to restore them after the lock is deleted */
364 MakeLockTile(t, o, WATER_TILE_LOCK_MIDDLE, d, wc_middle);
365 MakeLockTile(t - delta, IsPlainWaterTile(t - delta) ? GetTileOwner(t - delta) : o, WATER_TILE_LOCK_LOWER, d, wc_lower);
366 MakeLockTile(t + delta, IsPlainWaterTile(t + delta) ? GetTileOwner(t + delta) : o, WATER_TILE_LOCK_UPPER, d, wc_upper);
369 #endif /* MAP_WATER_H */