Index: water_map.h
===================================================================
--- water_map.h (revision 27210)
+++ water_map.h (working copy)
@@ -16,25 +16,26 @@
#include "tile_map.h"
/**
- * Bit field layout of m5 for water tiles.
+ * Bit field layout for water tiles.
*/
enum WaterTileTypeBitLayout {
- WBL_TYPE_BEGIN = 4, ///< Start of the 'type' bitfield.
- WBL_TYPE_COUNT = 4, ///< Length of the 'type' bitfield.
+ WBL_TYPE_BEGIN = 4, ///< First bit for the structure kind, in m5 bitfield.
+ WBL_TYPE_COUNT = 4, ///< Number of bits, for the structure kind, in m5 bitfield.
- WBL_TYPE_NORMAL = 0x0, ///< Clear water or coast ('type' bitfield).
- WBL_TYPE_LOCK = 0x1, ///< Lock ('type' bitfield).
- WBL_TYPE_DEPOT = 0x8, ///< Depot ('type' bitfield).
+ WBL_TYPE_NORMAL = 0x0, ///< Clear water or coast, in m5 (structure kind bitfield).
+ WBL_TYPE_LOCK = 0x1, ///< Lock, in m5 (structure kind bitfield).
+ WBL_TYPE_DEPOT = 0x8, ///< Depot, in m5 (structure kind bitfield).
- WBL_COAST_FLAG = 0, ///< Flag for coast.
+ WBL_COAST_FLAG = 0, ///< Flag for coast, in m5.
+ WBL_RIVER_FLAG = 0, ///< Flag for canal on river, in m6.
- WBL_LOCK_ORIENT_BEGIN = 0, ///< Start of lock orientiation bitfield.
- WBL_LOCK_ORIENT_COUNT = 2, ///< Length of lock orientiation bitfield.
- WBL_LOCK_PART_BEGIN = 2, ///< Start of lock part bitfield.
- WBL_LOCK_PART_COUNT = 2, ///< Length of lock part bitfield.
+ WBL_LOCK_ORIENT_BEGIN = 0, ///< Start of lock orientiation, in m5 bitfield.
+ WBL_LOCK_ORIENT_COUNT = 2, ///< Length of lock orientiation, in m5 bitfield.
+ WBL_LOCK_PART_BEGIN = 2, ///< Start of lock part, in m5 bitfield.
+ WBL_LOCK_PART_COUNT = 2, ///< Length of lock part, in m5 bitfield.
- WBL_DEPOT_PART = 0, ///< Depot part flag.
- WBL_DEPOT_AXIS = 1, ///< Depot axis flag.
+ WBL_DEPOT_PART = 0, ///< Depot part flag, in m5.
+ WBL_DEPOT_AXIS = 1, ///< Depot axis flag, in m5.
};
/** Available water tile types. */
@@ -55,6 +56,12 @@
/** Helper information for extract tool. */
template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
+/** Bases of a canal (for #WATER_CLASS_CANAL class of water). */
+enum CanalBase {
+ WCC_WITHOUT_RIVER = 0, ///< Without a river under it
+ WCC_WITH_RIVER = 1, ///< With a river under it
+};
+
/** Sections of the water depot. */
enum DepotPart {
DEPOT_PART_NORTH = 0, ///< Northern part of a depot.
@@ -122,6 +129,40 @@
}
/**
+ * Get the base of the canal at a tile.
+ * @param t Water tile to query.
+ * @pre GetWaterClass(t) == WATER_CLASS_CANAL
+ * @return Base of the canal at the tile.
+ */
+static inline CanalBase GetCanalBase(TileIndex t)
+{
+ assert(GetWaterClass(t) == WATER_CLASS_CANAL);
+ return (CanalBase)HasBit(_me[t].m6, WBL_RIVER_FLAG) ? WCC_WITH_RIVER : WCC_WITHOUT_RIVER;
+}
+
+/**
+ * Set the base of the canal to indicate there is a river under a tile.
+ * @param t Water tile of water class canal to query.
+ * @pre GetWaterClass(t) == WATER_CLASS_CANAL
+ */
+static inline void SetCanalOnRiver(TileIndex t)
+{
+ assert(GetWaterClass(t) == WATER_CLASS_CANAL);
+ SB(_me[t].m6, 0, WBL_RIVER_FLAG, WCC_WITH_RIVER);
+}
+
+/**
+ * Checks whether the canal at a tile has a river under it.
+ * @param t Water tile of water class canal to query.
+ * @pre GetWaterClass(t) == WATER_CLASS_CANAL
+ * @return true if the canal has a river under it.
+ */
+static inline bool HasTileCanalOnRiver(TileIndex t)
+{
+ return HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL && GetCanalBase(t) == WCC_WITH_RIVER;
+}
+
+/**
* Tests if the tile was built on water.
* @param t the tile to check
* @pre IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT)