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 };
00033 template <> struct EnumPropsT<WaterClass> : MakeEnumPropsT<WaterClass, byte, WATER_CLASS_SEA, WATER_CLASS_INVALID, WATER_CLASS_INVALID, 2> {};
00034
00036 enum DepotPart {
00037 DEPOT_NORTH = 0x80,
00038 DEPOT_SOUTH = 0x81,
00039 DEPOT_END = 0x84,
00040 };
00041
00043 enum LockPart {
00044 LOCK_MIDDLE = 0x10,
00045 LOCK_LOWER = 0x14,
00046 LOCK_UPPER = 0x18,
00047 LOCK_END = 0x1C
00048 };
00049
00055 static inline WaterTileType GetWaterTileType(TileIndex t)
00056 {
00057 assert(IsTileType(t, MP_WATER));
00058
00059 if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
00060 if (_m[t].m5 == 1) return WATER_TILE_COAST;
00061 if (IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
00062
00063 assert(IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END));
00064 return WATER_TILE_DEPOT;
00065 }
00066
00073 static inline bool HasTileWaterClass(TileIndex t)
00074 {
00075 return IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY) || IsTileType(t, MP_OBJECT);
00076 }
00077
00084 static inline WaterClass GetWaterClass(TileIndex t)
00085 {
00086 assert(HasTileWaterClass(t));
00087 return (WaterClass)GB(_m[t].m1, 5, 2);
00088 }
00089
00096 static inline void SetWaterClass(TileIndex t, WaterClass wc)
00097 {
00098 assert(HasTileWaterClass(t));
00099 SB(_m[t].m1, 5, 2, wc);
00100 }
00101
00108 static inline bool IsTileOnWater(TileIndex t)
00109 {
00110 return (GetWaterClass(t) != WATER_CLASS_INVALID);
00111 }
00112
00118 static inline bool IsWater(TileIndex t)
00119 {
00120 return GetWaterTileType(t) == WATER_TILE_CLEAR;
00121 }
00122
00128 static inline bool IsSea(TileIndex t)
00129 {
00130 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_SEA;
00131 }
00132
00138 static inline bool IsCanal(TileIndex t)
00139 {
00140 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_CANAL;
00141 }
00142
00148 static inline bool IsRiver(TileIndex t)
00149 {
00150 return IsWater(t) && GetWaterClass(t) == WATER_CLASS_RIVER;
00151 }
00152
00158 static inline bool IsWaterTile(TileIndex t)
00159 {
00160 return IsTileType(t, MP_WATER) && IsWater(t);
00161 }
00162
00168 static inline bool IsCoast(TileIndex t)
00169 {
00170 return GetWaterTileType(t) == WATER_TILE_COAST;
00171 }
00172
00178 static inline bool IsCoastTile(TileIndex t)
00179 {
00180 return IsTileType(t, MP_WATER) && IsCoast(t);
00181 }
00182
00188 static inline TileIndex GetOtherShipDepotTile(TileIndex t)
00189 {
00190 return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
00191 }
00192
00198 static inline bool IsShipDepot(TileIndex t)
00199 {
00200 return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END);
00201 }
00202
00208 static inline bool IsShipDepotTile(TileIndex t)
00209 {
00210 return IsTileType(t, MP_WATER) && IsShipDepot(t);
00211 }
00212
00218 static inline Axis GetShipDepotAxis(TileIndex t)
00219 {
00220 return (Axis)GB(_m[t].m5, 1, 1);
00221 }
00222
00228 static inline DiagDirection GetShipDepotDirection(TileIndex t)
00229 {
00230 return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
00231 }
00232
00238 static inline TileIndex GetShipDepotNorthTile(TileIndex t)
00239 {
00240 assert(IsShipDepot(t));
00241 TileIndex tile2 = GetOtherShipDepotTile(t);
00242
00243 return t < tile2 ? t : tile2;
00244 }
00245
00251 static inline bool IsLock(TileIndex t)
00252 {
00253 return IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END);
00254 }
00255
00261 static inline DiagDirection GetLockDirection(TileIndex t)
00262 {
00263 return (DiagDirection)GB(_m[t].m5, 0, 2);
00264 }
00265
00271 static inline byte GetSection(TileIndex t)
00272 {
00273 assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT);
00274 return GB(_m[t].m5, 0, 4);
00275 }
00276
00282 static inline byte GetWaterTileRandomBits(TileIndex t)
00283 {
00284 return _m[t].m4;
00285 }
00286
00293 static inline bool HasTileWaterGround(TileIndex t)
00294 {
00295 return HasTileWaterClass(t) && IsTileOnWater(t) && !IsCoastTile(t);
00296 }
00297
00298
00303 static inline void MakeShore(TileIndex t)
00304 {
00305 SetTileType(t, MP_WATER);
00306 SetTileOwner(t, OWNER_WATER);
00307 SetWaterClass(t, WATER_CLASS_SEA);
00308 _m[t].m2 = 0;
00309 _m[t].m3 = 0;
00310 _m[t].m4 = 0;
00311 _m[t].m5 = 1;
00312 SB(_m[t].m6, 2, 4, 0);
00313 _me[t].m7 = 0;
00314 }
00315
00323 static inline void MakeWater(TileIndex t, Owner o, WaterClass wc, uint8 random_bits)
00324 {
00325 SetTileType(t, MP_WATER);
00326 SetTileOwner(t, o);
00327 SetWaterClass(t, wc);
00328 _m[t].m2 = 0;
00329 _m[t].m3 = 0;
00330 _m[t].m4 = random_bits;
00331 _m[t].m5 = 0;
00332 SB(_m[t].m6, 2, 4, 0);
00333 _me[t].m7 = 0;
00334 }
00335
00340 static inline void MakeSea(TileIndex t)
00341 {
00342 MakeWater(t, OWNER_WATER, WATER_CLASS_SEA, 0);
00343 }
00344
00350 static inline void MakeRiver(TileIndex t, uint8 random_bits)
00351 {
00352 MakeWater(t, OWNER_WATER, WATER_CLASS_RIVER, random_bits);
00353 }
00354
00361 static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
00362 {
00363 assert(o != OWNER_WATER);
00364 MakeWater(t, o, WATER_CLASS_CANAL, random_bits);
00365 }
00366
00376 static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
00377 {
00378 SetTileType(t, MP_WATER);
00379 SetTileOwner(t, o);
00380 SetWaterClass(t, original_water_class);
00381 _m[t].m2 = did;
00382 _m[t].m3 = 0;
00383 _m[t].m4 = 0;
00384 _m[t].m5 = base + a * 2;
00385 SB(_m[t].m6, 2, 4, 0);
00386 _me[t].m7 = 0;
00387 }
00388
00397 static inline void MakeLockTile(TileIndex t, Owner o, byte section, WaterClass original_water_class)
00398 {
00399 SetTileType(t, MP_WATER);
00400 SetTileOwner(t, o);
00401 SetWaterClass(t, original_water_class);
00402 _m[t].m2 = 0;
00403 _m[t].m3 = 0;
00404 _m[t].m4 = 0;
00405 _m[t].m5 = section;
00406 SB(_m[t].m6, 2, 4, 0);
00407 _me[t].m7 = 0;
00408 }
00409
00418 static inline void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper)
00419 {
00420 TileIndexDiff delta = TileOffsByDiagDir(d);
00421
00422 MakeLockTile(t, o, LOCK_MIDDLE + d, WATER_CLASS_CANAL);
00423 MakeLockTile(t - delta, o, LOCK_LOWER + d, wc_lower);
00424 MakeLockTile(t + delta, o, LOCK_UPPER + d, wc_upper);
00425 }
00426
00427 #endif