00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef WATER_MAP_H
00013 #define WATER_MAP_H
00014
00015 #include "depot_type.h"
00016 #include "tile_map.h"
00017
00019 enum WaterTileType {
00020 WATER_TILE_CLEAR,
00021 WATER_TILE_COAST,
00022 WATER_TILE_LOCK,
00023 WATER_TILE_DEPOT,
00024 };
00025
00027 enum WaterClass {
00028 WATER_CLASS_SEA,
00029 WATER_CLASS_CANAL,
00030 WATER_CLASS_RIVER,
00031 WATER_CLASS_INVALID,
00032 };
00034 template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
00035
00037 enum DepotPart {
00038 DEPOT_NORTH = 0x80,
00039 DEPOT_SOUTH = 0x81,
00040 DEPOT_END = 0x84,
00041 };
00042
00044 enum LockPart {
00045 LOCK_MIDDLE = 0x10,
00046 LOCK_LOWER = 0x14,
00047 LOCK_UPPER = 0x18,
00048 LOCK_END = 0x1C
00049 };
00050
00056 static inline WaterTileType GetWaterTileType(TileIndex t)
00057 {
00058 assert(IsTileType(t, MP_WATER));
00059
00060 if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
00061 if (_m[t].m5 == 1) return WATER_TILE_COAST;
00062 if (IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
00063
00064 assert(IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END));
00065 return WATER_TILE_DEPOT;
00066 }
00067
00074 static inline bool HasTileWaterClass(TileIndex t)
00075 {
00076 return IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT);
00077 }
00078
00085 static inline WaterClass GetWaterClass(TileIndex t)
00086 {
00087 assert(HasTileWaterClass(t));
00088 return (WaterClass)GB(_m[t].m1, 5, 2);
00089 }
00090
00097 static inline void SetWaterClass(TileIndex t, WaterClass wc)
00098 {
00099 assert(HasTileWaterClass(t));
00100 SB(_m[t].m1, 5, 2, wc);
00101 }
00102
00109 static inline bool IsTileOnWater(TileIndex t)
00110 {
00111 return (GetWaterClass(t) != WATER_CLASS_INVALID);
00112 }
00113
00119 static inline bool IsWater(TileIndex t)
00120 {
00121 return GetWaterTileType(t) == WATER_TILE_CLEAR;
00122 }
00123
00129 static inline bool IsSea(TileIndex t)
00130 {
00131 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_SEA;
00132 }
00133
00139 static inline bool IsCanal(TileIndex t)
00140 {
00141 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_CANAL;
00142 }
00143
00149 static inline bool IsRiver(TileIndex t)
00150 {
00151 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_RIVER;
00152 }
00153
00159 static inline bool IsWaterTile(TileIndex t)
00160 {
00161 return IsTileType(t, MP_WATER) && IsWater(t);
00162 }
00163
00169 static inline bool IsCoast(TileIndex t)
00170 {
00171 return GetWaterTileType(t) == WATER_TILE_COAST;
00172 }
00173
00179 static inline bool IsCoastTile(TileIndex t)
00180 {
00181 return IsTileType(t, MP_WATER) && IsCoast(t);
00182 }
00183
00189 static inline TileIndex GetOtherShipDepotTile(TileIndex t)
00190 {
00191 return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
00192 }
00193
00199 static inline bool IsShipDepot(TileIndex t)
00200 {
00201 return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END);
00202 }
00203
00209 static inline bool IsShipDepotTile(TileIndex t)
00210 {
00211 return IsTileType(t, MP_WATER) && IsShipDepot(t);
00212 }
00213
00219 static inline Axis GetShipDepotAxis(TileIndex t)
00220 {
00221 return (Axis)GB(_m[t].m5, 1, 1);
00222 }
00223
00229 static inline DiagDirection GetShipDepotDirection(TileIndex t)
00230 {
00231 return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
00232 }
00233
00239 static inline TileIndex GetShipDepotNorthTile(TileIndex t)
00240 {
00241 assert(IsShipDepot(t));
00242 TileIndex tile2 = GetOtherShipDepotTile(t);
00243
00244 return t < tile2 ? t : tile2;
00245 }
00246
00252 static inline bool IsLock(TileIndex t)
00253 {
00254 return IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END);
00255 }
00256
00262 static inline DiagDirection GetLockDirection(TileIndex t)
00263 {
00264 return (DiagDirection)GB(_m[t].m5, 0, 2);
00265 }
00266
00272 static inline byte GetSection(TileIndex t)
00273 {
00274 assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT);
00275 return GB(_m[t].m5, 0, 4);
00276 }
00277
00283 static inline byte GetWaterTileRandomBits(TileIndex t)
00284 {
00285 return _m[t].m4;
00286 }
00287
00294 static inline bool HasTileWaterGround(TileIndex t)
00295 {
00296 return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t);
00297 }
00298
00299
00304 static inline void MakeShore(TileIndex t)
00305 {
00306 SetTileType(t, MP_WATER);
00307 SetTileOwner(t, OWNER_WATER);
00308 SetWaterClass(t, WATER_CLASS_SEA);
00309 _m[t].m2 = 0;
00310 _m[t].m3 = 0;
00311 _m[t].m4 = 0;
00312 _m[t].m5 = 1;
00313 SB(_m[t].m6, 2, 4, 0);
00314 _me[t].m7 = 0;
00315 }
00316
00324 static inline void MakeWater(TileIndex t, Owner o, WaterClass wc, uint8 random_bits)
00325 {
00326 SetTileType(t, MP_WATER);
00327 SetTileOwner(t, o);
00328 SetWaterClass(t, wc);
00329 _m[t].m2 = 0;
00330 _m[t].m3 = 0;
00331 _m[t].m4 = random_bits;
00332 _m[t].m5 = 0;
00333 SB(_m[t].m6, 2, 4, 0);
00334 _me[t].m7 = 0;
00335 }
00336
00341 static inline void MakeSea(TileIndex t)
00342 {
00343 MakeWater(t, OWNER_WATER, WATER_CLASS_SEA, 0);
00344 }
00345
00351 static inline void MakeRiver(TileIndex t, uint8 random_bits)
00352 {
00353 MakeWater(t, OWNER_WATER, WATER_CLASS_RIVER, random_bits);
00354 }
00355
00362 static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
00363 {
00364 assert(o != OWNER_WATER);
00365 MakeWater(t, o, WATER_CLASS_CANAL, random_bits);
00366 }
00367
00377 static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
00378 {
00379 SetTileType(t, MP_WATER);
00380 SetTileOwner(t, o);
00381 SetWaterClass(t, original_water_class);
00382 _m[t].m2 = did;
00383 _m[t].m3 = 0;
00384 _m[t].m4 = 0;
00385 _m[t].m5 = base + a * 2;
00386 SB(_m[t].m6, 2, 4, 0);
00387 _me[t].m7 = 0;
00388 }
00389
00398 static inline void MakeLockTile(TileIndex t, Owner o, byte section, WaterClass original_water_class)
00399 {
00400 SetTileType(t, MP_WATER);
00401 SetTileOwner(t, o);
00402 SetWaterClass(t, original_water_class);
00403 _m[t].m2 = 0;
00404 _m[t].m3 = 0;
00405 _m[t].m4 = 0;
00406 _m[t].m5 = section;
00407 SB(_m[t].m6, 2, 4, 0);
00408 _me[t].m7 = 0;
00409 }
00410
00419 static inline void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper)
00420 {
00421 TileIndexDiff delta = TileOffsByDiagDir(d);
00422
00423 MakeLockTile(t, o, LOCK_MIDDLE + d, WATER_CLASS_CANAL);
00424 MakeLockTile(t - delta, o, LOCK_LOWER + d, wc_lower);
00425 MakeLockTile(t + delta, o, LOCK_UPPER + d, wc_upper);
00426 }
00427
00428 #endif