tron@3111: /* $Id$ */ tron@3111: belugas@6928: /** @file water_map.h */ belugas@6928: tron@3111: #ifndef WATER_MAP_H tron@3111: #define WATER_MAP_H tron@3111: rubidium@6574: enum WaterTileType { rubidium@6507: WATER_TILE_CLEAR, rubidium@6507: WATER_TILE_COAST, rubidium@6507: WATER_TILE_LOCK, rubidium@6507: WATER_TILE_DEPOT, rubidium@6574: }; celestar@3402: rubidium@6574: enum DepotPart { celestar@3372: DEPOT_NORTH = 0x80, celestar@3373: DEPOT_SOUTH = 0x81, celestar@3373: DEPOT_END = 0x84, rubidium@6574: }; celestar@3372: rubidium@6574: enum LockPart { celestar@3372: LOCK_MIDDLE = 0x10, celestar@3372: LOCK_LOWER = 0x14, celestar@3402: LOCK_UPPER = 0x18, celestar@3402: LOCK_END = 0x1C rubidium@6574: }; celestar@3372: celestar@3402: static inline WaterTileType GetWaterTileType(TileIndex t) celestar@3373: { rubidium@8235: assert(IsTileType(t, MP_WATER)); rubidium@8235: rubidium@6507: if (_m[t].m5 == 0) return WATER_TILE_CLEAR; rubidium@6507: if (_m[t].m5 == 1) return WATER_TILE_COAST; skidd13@8450: if (IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK; celestar@3402: skidd13@8450: assert(IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END)); rubidium@6507: return WATER_TILE_DEPOT; celestar@3402: } celestar@3402: rubidium@8235: /** IsWater return true if any type of clear water like ocean, river, canal */ celestar@3402: static inline bool IsWater(TileIndex t) celestar@3402: { rubidium@6507: return GetWaterTileType(t) == WATER_TILE_CLEAR; celestar@3402: } celestar@3402: rubidium@8235: static inline bool IsSea(TileIndex t) rubidium@8235: { rubidium@8235: if (GetWaterTileType(t) != WATER_TILE_CLEAR) return false; rubidium@8235: if (!IsTileOwner(t, OWNER_WATER)) return false; // 'Human' built water = canal, not sea rubidium@8235: return true; rubidium@8235: } rubidium@8235: celestar@3423: static inline bool IsCoast(TileIndex t) celestar@3423: { rubidium@6507: return GetWaterTileType(t) == WATER_TILE_COAST; celestar@3423: } celestar@3423: rubidium@7470: static inline bool IsCanal(TileIndex t) rubidium@7470: { rubidium@7470: return GetWaterTileType(t) == WATER_TILE_CLEAR && GetTileOwner(t) != OWNER_WATER; rubidium@7470: } rubidium@7470: rubidium@8235: static inline bool IsWaterTile(TileIndex t) celestar@3402: { rubidium@8235: return IsTileType(t, MP_WATER) && IsWater(t); celestar@3373: } celestar@3373: celestar@3373: static inline TileIndex GetOtherShipDepotTile(TileIndex t) celestar@3373: { skidd13@8424: return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0)); celestar@3373: } celestar@3373: celestar@3373: static inline TileIndex IsShipDepot(TileIndex t) celestar@3373: { skidd13@8450: return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END); celestar@3373: } celestar@3373: celestar@3423: static inline Axis GetShipDepotAxis(TileIndex t) celestar@3423: { celestar@3423: return (Axis)GB(_m[t].m5, 1, 1); celestar@3423: } celestar@3423: tron@3953: static inline DiagDirection GetShipDepotDirection(TileIndex t) tron@3953: { tron@3953: return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1)); tron@3953: } tron@3953: rubidium@8525: static inline Owner GetShipDepotWaterOwner(TileIndex t) rubidium@8525: { rubidium@8525: return (Owner)_m[t].m4; rubidium@8525: } rubidium@8525: celestar@3373: static inline DiagDirection GetLockDirection(TileIndex t) celestar@3373: { celestar@3373: return (DiagDirection)GB(_m[t].m5, 0, 2); celestar@3373: } celestar@3373: celestar@3425: static inline byte GetSection(TileIndex t) celestar@3425: { rubidium@6507: assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT); celestar@3425: return GB(_m[t].m5, 0, 4); celestar@3425: } celestar@3425: celestar@3373: tron@3111: static inline void MakeWater(TileIndex t) tron@3111: { tron@3111: SetTileType(t, MP_WATER); tron@3111: SetTileOwner(t, OWNER_WATER); tron@3111: _m[t].m2 = 0; tron@3111: _m[t].m3 = 0; tron@3111: _m[t].m4 = 0; tron@3111: _m[t].m5 = 0; tron@3111: } tron@3111: tron@3111: static inline void MakeShore(TileIndex t) tron@3111: { tron@3111: SetTileType(t, MP_WATER); tron@3111: SetTileOwner(t, OWNER_WATER); tron@3111: _m[t].m2 = 0; tron@3111: _m[t].m3 = 0; tron@3111: _m[t].m4 = 0; tron@3111: _m[t].m5 = 1; tron@3111: } tron@3111: peter1138@3940: static inline void MakeCanal(TileIndex t, Owner o) peter1138@3940: { rubidium@8235: assert(o != OWNER_WATER); peter1138@3940: SetTileType(t, MP_WATER); peter1138@3940: SetTileOwner(t, o); peter1138@3940: _m[t].m2 = 0; peter1138@3940: _m[t].m3 = 0; peter1138@3940: _m[t].m4 = 0; peter1138@3940: _m[t].m5 = 0; peter1138@3940: } peter1138@3940: rubidium@8525: static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, Owner original_owner) celestar@3372: { celestar@3372: SetTileType(t, MP_WATER); celestar@3372: SetTileOwner(t, o); celestar@3372: _m[t].m2 = 0; celestar@3372: _m[t].m3 = 0; rubidium@8525: _m[t].m4 = original_owner; celestar@3372: _m[t].m5 = base + a * 2; celestar@3372: } celestar@3372: peter1138@3940: static inline void MakeLockTile(TileIndex t, Owner o, byte section) celestar@3372: { celestar@3372: SetTileType(t, MP_WATER); peter1138@3940: SetTileOwner(t, o); celestar@3372: _m[t].m2 = 0; celestar@3372: _m[t].m3 = 0; celestar@3372: _m[t].m4 = 0; celestar@3372: _m[t].m5 = section; celestar@3372: } celestar@3372: peter1138@3940: static inline void MakeLock(TileIndex t, Owner o, DiagDirection d) celestar@3372: { Darkvater@4559: TileIndexDiff delta = TileOffsByDiagDir(d); celestar@3372: peter1138@3940: MakeLockTile(t, o, LOCK_MIDDLE + d); peter1138@3940: MakeLockTile(t - delta, o, LOCK_LOWER + d); peter1138@3940: MakeLockTile(t + delta, o, LOCK_UPPER + d); celestar@3372: } celestar@3372: peter1138@4666: #endif /* WATER_MAP_H */