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/>.
8 /** @file map/water.h Map tile accessors for water tiles. */
13 #include "../stdafx.h"
14 #include "../tile/common.h"
15 #include "../tile/water.h"
19 #include "../direction_type.h"
20 #include "../direction_func.h"
21 #include "../company_type.h"
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
]);
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.
39 static inline bool IsPlainWater(TileIndex t
)
41 return tile_water_is_clear(&_mc
[t
]);
46 * @param t Water tile to query.
47 * @return \c true if it is a sea water tile.
50 static inline bool IsCoast(TileIndex t
)
52 return tile_water_is_coast(&_mc
[t
]);
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.
61 static inline bool IsShipDepot(TileIndex t
)
63 return tile_water_is_depot(&_mc
[t
]);
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.
72 static inline bool IsLock(TileIndex t
)
74 return tile_water_is_lock(&_mc
[t
]);
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
]);
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
]);
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
]);
109 * Checks whether the tile has an waterclass associated.
110 * You can then subsequently call GetWaterClass().
111 * @param t Tile to query.
112 * @return True if the tiletype has a waterclass.
114 static inline bool HasTileWaterClass(TileIndex t
)
116 return tile_has_water_class(&_mc
[t
]);
120 * Get the water class at a tile.
121 * @param t Water tile to query.
122 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
123 * @return Water class at the tile.
125 static inline WaterClass
GetWaterClass(TileIndex t
)
127 return tile_get_water_class(&_mc
[t
]);
131 * Set the water class at a tile.
132 * @param t Water tile to change.
133 * @param wc New water class.
134 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
136 static inline void SetWaterClass(TileIndex t
, WaterClass wc
)
138 tile_set_water_class(&_mc
[t
], wc
);
142 * Tests if the tile was built on water.
143 * @param t the tile to check
144 * @pre IsWaterTile(t) || IsStationTile(t) || IsIndustryTile(t) || IsObjectTile(t)
145 * @return true iff on water
147 static inline bool IsTileOnWater(TileIndex t
)
149 return tile_is_on_water(&_mc
[t
]);
154 * Is it a sea water tile?
155 * @param t Water tile to query.
156 * @return \c true if it is a sea water tile.
157 * @pre IsWaterTile(t)
159 static inline bool IsSea(TileIndex t
)
161 return tile_water_is_sea(&_mc
[t
]);
165 * Is it a canal tile?
166 * @param t Water tile to query.
167 * @return \c true if it is a canal tile.
168 * @pre IsWaterTile(t)
170 static inline bool IsCanal(TileIndex t
)
172 return tile_water_is_canal(&_mc
[t
]);
176 * Is it a river water tile?
177 * @param t Water tile to query.
178 * @return \c true if it is a river water tile.
179 * @pre IsWaterTile(t)
181 static inline bool IsRiver(TileIndex t
)
183 return tile_water_is_river(&_mc
[t
]);
188 * Get the direction of the ship depot.
189 * @param t Water tile to query.
190 * @return Direction of the depot.
191 * @pre IsShipDepotTile(t)
193 static inline DiagDirection
GetShipDepotDirection(TileIndex t
)
195 return tile_get_ship_depot_direction(&_mc
[t
]);
199 * Get the other tile of the ship depot.
200 * @param t Tile to query, containing one section of a ship depot.
201 * @return Tile containing the other section of the depot.
202 * @pre IsShipDepotTile(t)
204 static inline TileIndex
GetOtherShipDepotTile(TileIndex t
)
206 return t
- TileOffsByDiagDir(GetShipDepotDirection(t
));
210 * Get the most northern tile of a ship depot.
211 * @param t One of the tiles of the ship depot.
212 * @return The northern tile of the depot.
213 * @pre IsShipDepotTile(t)
215 static inline TileIndex
GetShipDepotNorthTile(TileIndex t
)
217 assert(IsShipDepot(t
));
218 TileIndex tile2
= GetOtherShipDepotTile(t
);
220 return t
< tile2
? t
: tile2
;
225 * Get the direction of the water lock.
226 * @param t Water tile to query.
227 * @return Direction of the lock.
228 * @pre IsWaterTile(t) && IsLock(t)
230 static inline DiagDirection
GetLockDirection(TileIndex t
)
232 return tile_get_lock_direction(&_mc
[t
]);
236 * Get the part of a lock.
237 * @param t Water tile to query.
239 * @pre IsWaterTile(t) && IsLock(t)
241 static inline byte
GetLockPart(TileIndex t
)
243 return tile_get_lock_part(&_mc
[t
]);
248 * Get the random bits of the water tile.
249 * @param t Water tile to query.
250 * @return Random bits of the tile.
251 * @pre IsWaterTile(t)
253 static inline byte
GetWaterTileRandomBits(TileIndex t
)
255 assert(IsWaterTile(t
));
256 return tile_get_random_bits(&_mc
[t
]);
261 * Checks whether the tile has water at the ground.
262 * That is, it is either some plain water tile, or a object/industry/station/... with water under it.
263 * @return true iff the tile has water at the ground.
264 * @note Coast tiles are not considered waterish, even if there is water on a halftile.
266 static inline bool HasTileWaterGround(TileIndex t
)
268 return HasTileWaterClass(t
) && IsTileOnWater(t
) && !IsCoastTile(t
);
273 * Helper function for making a watery tile.
274 * @param t The tile to change into water
275 * @param o The owner of the water
276 * @param wc The class of water the tile has to be
277 * @param random_bits Eventual random bits to be set for this tile
279 static inline void MakeWater(TileIndex t
, Owner o
, WaterClass wc
, uint8 random_bits
)
281 tile_make_water(&_mc
[t
], o
, wc
, random_bits
);
286 * @param t The tile to change into sea
288 static inline void MakeSea(TileIndex t
)
290 tile_make_sea(&_mc
[t
]);
295 * @param t The tile to change into canal
296 * @param o The owner of the canal
297 * @param random_bits Random bits to be set for this tile
299 static inline void MakeCanal(TileIndex t
, Owner o
, uint8 random_bits
)
301 tile_make_canal(&_mc
[t
], o
, random_bits
);
306 * @param t The tile to change into river
307 * @param random_bits Random bits to be set for this tile
309 static inline void MakeRiver(TileIndex t
, uint8 random_bits
)
311 tile_make_river(&_mc
[t
], random_bits
);
315 * Helper function to make a coast tile.
316 * @param t The tile to change into water
318 static inline void MakeShore(TileIndex t
)
320 tile_make_shore(&_mc
[t
]);
324 * Make a ship depot section.
325 * @param t Tile to place the ship depot section.
326 * @param o Owner of the depot.
327 * @param did Depot ID.
328 * @param dir Direction of the depot.
329 * @param original_water_class Original water class.
331 static inline void MakeShipDepot(TileIndex t
, Owner o
, uint did
, DiagDirection dir
, WaterClass original_water_class
)
333 tile_make_ship_depot(&_mc
[t
], o
, did
, dir
, original_water_class
);
337 * Make a lock section.
338 * @param t Tile to place the water lock section.
339 * @param o Owner of the lock.
340 * @param part Part to place.
341 * @param dir Lock orientation
342 * @param original_water_class Original water class.
345 static inline void MakeLockTile(TileIndex t
, Owner o
, LockPart part
, DiagDirection dir
, WaterClass original_water_class
)
347 tile_make_lock(&_mc
[t
], o
, part
, dir
, original_water_class
);
352 * @param t Tile to place the water lock section.
353 * @param o Owner of the lock.
354 * @param d Direction of the water lock.
355 * @param wc_lower Original water class of the lower part.
356 * @param wc_upper Original water class of the upper part.
357 * @param wc_middle Original water class of the middle part.
359 static inline void MakeLock(TileIndex t
, Owner o
, DiagDirection d
, WaterClass wc_lower
, WaterClass wc_upper
, WaterClass wc_middle
)
361 TileIndexDiff delta
= TileOffsByDiagDir(d
);
363 /* Keep the current waterclass and owner for the tiles.
364 * It allows to restore them after the lock is deleted */
365 MakeLockTile(t
, o
, LOCK_PART_MIDDLE
, d
, wc_middle
);
366 MakeLockTile(t
- delta
, IsPlainWaterTile(t
- delta
) ? GetTileOwner(t
- delta
) : o
, LOCK_PART_LOWER
, d
, wc_lower
);
367 MakeLockTile(t
+ delta
, IsPlainWaterTile(t
+ delta
) ? GetTileOwner(t
+ delta
) : o
, LOCK_PART_UPPER
, d
, wc_upper
);
370 #endif /* MAP_WATER_H */