Loading

Revision differences

Old revision #pbvghndpaNew revision #pfw0tp5rk
1/**  1Index: water_map.h
2 * Bit field layout of m5 for water tiles.  2===================================================================
3 */  3--- water_map.h    (revision 27210)
4enum WaterTileTypeBitLayout {  4+++ water_map.h    (working copy)
5    WBL_TYPE_BEGIN        = 4,   ///< Start of the 'type' bitfield.  5@@ -16,25 +16,26 @@
6    WBL_TYPE_COUNT        = 4,   ///< Length of the 'type' bitfield.  6 #include "tile_map.h"
7  7 
8    WBL_TYPE_NORMAL       = 0x0, ///< Clear water or coast ('type' bitfield).  8 /**
9    WBL_TYPE_LOCK         = 0x1, ///< Lock ('type' bitfield).  9- * Bit field layout of m5 for water tiles.
10    WBL_TYPE_DEPOT        = 0x8, ///< Depot ('type' bitfield).  10+ * Bit field layout for water tiles.
11  11  */
12    WBL_COAST_FLAG        = 0,   ///< Flag for coast.  12 enum WaterTileTypeBitLayout {
13    WBL_RIVER_FLAG          = 0,   ///< Flag for canal on river.  13-    WBL_TYPE_BEGIN        = 4,   ///< Start of the 'type' bitfield.
14  14-    WBL_TYPE_COUNT        = 4,   ///< Length of the 'type' bitfield.
15    WBL_LOCK_ORIENT_BEGIN = 0,   ///< Start of lock orientiation bitfield.  15+    WBL_TYPE_BEGIN        = 4,   ///< First bit for the structure kind, in m5 bitfield.
16    WBL_LOCK_ORIENT_COUNT = 2,   ///< Length of lock orientiation bitfield.  16+    WBL_TYPE_COUNT        = 4,   ///< Number of bits, for the structure kind, in m5 bitfield.
17    WBL_LOCK_PART_BEGIN   = 2,   ///< Start of lock part bitfield.  17 
18    WBL_LOCK_PART_COUNT   = 2,   ///< Length of lock part bitfield.  18-    WBL_TYPE_NORMAL       = 0x0, ///< Clear water or coast ('type' bitfield).
19  19-    WBL_TYPE_LOCK         = 0x1, ///< Lock ('type' bitfield).
20    WBL_DEPOT_PART        = 0,   ///< Depot part flag.  20-    WBL_TYPE_DEPOT        = 0x8, ///< Depot ('type' bitfield).
21    WBL_DEPOT_AXIS        = 1,   ///< Depot axis flag.  21+    WBL_TYPE_NORMAL       = 0x0, ///< Clear water or coast, in m5 (structure kind bitfield).
22};  22+    WBL_TYPE_LOCK         = 0x1, ///< Lock, in m5 (structure kind bitfield).
23  23+    WBL_TYPE_DEPOT        = 0x8, ///< Depot, in m5 (structure kind bitfield).
24......  24 
25  25-    WBL_COAST_FLAG        = 0,   ///< Flag for coast.
26enum CanalType {  26+    WBL_COAST_FLAG        = 0,   ///< Flag for coast, in m5.
27    CANAL_NOT_RIVER = 0,    ///<  27+    WBL_RIVER_FLAG          = 0,   ///< Flag for canal on river, in m6.
28    CANAL_AND_RIVER = 1,    ///<  28 
29};  29-    WBL_LOCK_ORIENT_BEGIN = 0,   ///< Start of lock orientiation bitfield.
30  30-    WBL_LOCK_ORIENT_COUNT = 2,   ///< Length of lock orientiation bitfield.
31  31-    WBL_LOCK_PART_BEGIN   = 2,   ///< Start of lock part bitfield.
32.....  32-    WBL_LOCK_PART_COUNT   = 2,   ///< Length of lock part bitfield.
33  33+    WBL_LOCK_ORIENT_BEGIN = 0,   ///< Start of lock orientiation, in m5 bitfield.
34static inline CanalType GetCanalType(TileIndex t)  34+    WBL_LOCK_ORIENT_COUNT = 2,   ///< Length of lock orientiation, in m5 bitfield.
35{  35+    WBL_LOCK_PART_BEGIN   = 2,   ///< Start of lock part, in m5 bitfield.
36    assert(HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL);  36+    WBL_LOCK_PART_COUNT   = 2,   ///< Length of lock part, in m5 bitfield.
37    return (CanalType)HasBit(_me[t].m6, WBL_RIVER_FLAG) ? CANAL_AND_RIVER : CANAL_NOT_RIVER;  37 
38}  38-    WBL_DEPOT_PART        = 0,   ///< Depot part flag.
39  39-    WBL_DEPOT_AXIS        = 1,   ///< Depot axis flag.
40static inline bool HasTileCanalOnRiver(TileIndex t)  40+    WBL_DEPOT_PART        = 0,   ///< Depot part flag, in m5.
41{  41+    WBL_DEPOT_AXIS        = 1,   ///< Depot axis flag, in m5.
42    return HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL && GetCanalType(t) == CANAL_AND_RIVER;  42 };
43}  43 
44  44 /** Available water tile types. */
45static inline void SetCanalOnRiver(TileIndex t)  45@@ -55,6 +56,12 @@
46{  46 /** Helper information for extract tool. */
47    assert(HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL);  47 template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
48    SB(_me[t].m6, 0, WBL_RIVER_FLAG, CANAL_AND_RIVER);  48 
49} 49+/** Bases of a canal (for #WATER_CLASS_CANAL class of water). */
   50+enum CanalBase {
   51+    WCC_WITHOUT_RIVER    = 0,    ///< Without a river under it
   52+    WCC_WITH_RIVER        = 1,    ///< With a river under it
   53+};
   54+
   55 /** Sections of the water depot. */
   56 enum DepotPart {
   57     DEPOT_PART_NORTH = 0, ///< Northern part of a depot.
   58@@ -121,6 +128,27 @@
   59     SB(_m[t].m1, 5, 2, wc);
   60 }
   61 
   62+
   63+
   64+static inline CanalBase GetCanalBase(TileIndex t)
   65+{
   66+    assert(HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL);
   67+    return (CanalBase)HasBit(_me[t].m6, WBL_RIVER_FLAG) ? WCC_WITH_RIVER : WCC_WITHOUT_RIVER;
   68+}
   69+
   70+static inline bool HasTileCanalOnRiver(TileIndex t)
   71+{
   72+    return HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL && GetCanalBase(t) == WCC_WITH_RIVER;
   73+}
   74+
   75+static inline void SetCanalOnRiver(TileIndex t)
   76+{
   77+    assert(HasTileWaterClass(t) && GetWaterClass(t) == WATER_CLASS_CANAL);
   78+    SB(_me[t].m6, 0, WBL_RIVER_FLAG, WCC_WITH_RIVER);
   79+}
   80+
   81+
   82+
   83 /**
   84  * Tests if the tile was built on water.
   85  * @param t the tile to check
   86@@ -165,6 +193,12 @@
   87     return IsWater(t) && GetWaterClass(t) == WATER_CLASS_CANAL;
   88 }
   89 
   90+static inline bool IsCanalOnRiver(TileIndex t)
   91+{
   92+    assert(IsCanal(t));
   93+    return HasBit(_me[t].m6, WBL_RIVER_FLAG);
   94+}
   95+
   96 /**
   97  * Is it a river water tile?
   98  * @param t Water tile to query.