src/water_map.h
branchcustombridgeheads
changeset 5643 3778051e8095
parent 4666 850b5b6e4bac
child 6285 187e3ef04cc9
equal deleted inserted replaced
5642:bfa6074e2833 5643:3778051e8095
       
     1 /* $Id$ */
       
     2 
       
     3 #ifndef WATER_MAP_H
       
     4 #define WATER_MAP_H
       
     5 
       
     6 typedef enum WaterTileType {
       
     7 	WATER_CLEAR,
       
     8 	WATER_COAST,
       
     9 	WATER_LOCK,
       
    10 	WATER_DEPOT,
       
    11 } WaterTileType;
       
    12 
       
    13 typedef enum DepotPart {
       
    14 	DEPOT_NORTH = 0x80,
       
    15 	DEPOT_SOUTH = 0x81,
       
    16 	DEPOT_END   = 0x84,
       
    17 } DepotPart;
       
    18 
       
    19 typedef enum LockPart {
       
    20 	LOCK_MIDDLE = 0x10,
       
    21 	LOCK_LOWER  = 0x14,
       
    22 	LOCK_UPPER  = 0x18,
       
    23 	LOCK_END    = 0x1C
       
    24 } LockPart;
       
    25 
       
    26 static inline WaterTileType GetWaterTileType(TileIndex t)
       
    27 {
       
    28 	if (_m[t].m5 == 0) return WATER_CLEAR;
       
    29 	if (_m[t].m5 == 1) return WATER_COAST;
       
    30 	if (IS_INT_INSIDE(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_LOCK;
       
    31 
       
    32 	assert(IS_INT_INSIDE(_m[t].m5, DEPOT_NORTH, DEPOT_END));
       
    33 	return WATER_DEPOT;
       
    34 }
       
    35 
       
    36 static inline bool IsWater(TileIndex t)
       
    37 {
       
    38 	return GetWaterTileType(t) == WATER_CLEAR;
       
    39 }
       
    40 
       
    41 static inline bool IsCoast(TileIndex t)
       
    42 {
       
    43 	return GetWaterTileType(t) == WATER_COAST;
       
    44 }
       
    45 
       
    46 static inline bool IsClearWaterTile(TileIndex t)
       
    47 {
       
    48 	return IsTileType(t, MP_WATER) && IsWater(t) && GetTileSlope(t, NULL) == SLOPE_FLAT;
       
    49 }
       
    50 
       
    51 static inline TileIndex GetOtherShipDepotTile(TileIndex t)
       
    52 {
       
    53 	return t + (HASBIT(_m[t].m5, 0) ? -1 : 1) * (HASBIT(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
       
    54 }
       
    55 
       
    56 static inline TileIndex IsShipDepot(TileIndex t)
       
    57 {
       
    58 	return IS_INT_INSIDE(_m[t].m5, DEPOT_NORTH, DEPOT_END);
       
    59 }
       
    60 
       
    61 static inline Axis GetShipDepotAxis(TileIndex t)
       
    62 {
       
    63 	return (Axis)GB(_m[t].m5, 1, 1);
       
    64 }
       
    65 
       
    66 static inline DiagDirection GetShipDepotDirection(TileIndex t)
       
    67 {
       
    68 	return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
       
    69 }
       
    70 
       
    71 static inline DiagDirection GetLockDirection(TileIndex t)
       
    72 {
       
    73 	return (DiagDirection)GB(_m[t].m5, 0, 2);
       
    74 }
       
    75 
       
    76 static inline byte GetSection(TileIndex t)
       
    77 {
       
    78 	assert(GetWaterTileType(t) == WATER_LOCK || GetWaterTileType(t) == WATER_DEPOT);
       
    79 	return GB(_m[t].m5, 0, 4);
       
    80 }
       
    81 
       
    82 
       
    83 static inline void MakeWater(TileIndex t)
       
    84 {
       
    85 	SetTileType(t, MP_WATER);
       
    86 	SetTileOwner(t, OWNER_WATER);
       
    87 	_m[t].m2 = 0;
       
    88 	_m[t].m3 = 0;
       
    89 	_m[t].m4 = 0;
       
    90 	_m[t].m5 = 0;
       
    91 }
       
    92 
       
    93 static inline void MakeShore(TileIndex t)
       
    94 {
       
    95 	SetTileType(t, MP_WATER);
       
    96 	SetTileOwner(t, OWNER_WATER);
       
    97 	_m[t].m2 = 0;
       
    98 	_m[t].m3 = 0;
       
    99 	_m[t].m4 = 0;
       
   100 	_m[t].m5 = 1;
       
   101 }
       
   102 
       
   103 static inline void MakeCanal(TileIndex t, Owner o)
       
   104 {
       
   105 	SetTileType(t, MP_WATER);
       
   106 	SetTileOwner(t, o);
       
   107 	_m[t].m2 = 0;
       
   108 	_m[t].m3 = 0;
       
   109 	_m[t].m4 = 0;
       
   110 	_m[t].m5 = 0;
       
   111 }
       
   112 
       
   113 static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a)
       
   114 {
       
   115 	SetTileType(t, MP_WATER);
       
   116 	SetTileOwner(t, o);
       
   117 	_m[t].m2 = 0;
       
   118 	_m[t].m3 = 0;
       
   119 	_m[t].m4 = 0;
       
   120 	_m[t].m5 = base + a * 2;
       
   121 }
       
   122 
       
   123 static inline void MakeLockTile(TileIndex t, Owner o, byte section)
       
   124 {
       
   125 	SetTileType(t, MP_WATER);
       
   126 	SetTileOwner(t, o);
       
   127 	_m[t].m2 = 0;
       
   128 	_m[t].m3 = 0;
       
   129 	_m[t].m4 = 0;
       
   130 	_m[t].m5 = section;
       
   131 }
       
   132 
       
   133 static inline void MakeLock(TileIndex t, Owner o, DiagDirection d)
       
   134 {
       
   135 	TileIndexDiff delta = TileOffsByDiagDir(d);
       
   136 
       
   137 	MakeLockTile(t, o, LOCK_MIDDLE + d);
       
   138 	MakeLockTile(t - delta, o, LOCK_LOWER + d);
       
   139 	MakeLockTile(t + delta, o, LOCK_UPPER + d);
       
   140 }
       
   141 
       
   142 #endif /* WATER_MAP_H */