2006-03-01 21:00:44 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-06 04:10:19 +00:00
|
|
|
/** @file water_map.h */
|
|
|
|
|
2006-03-01 21:00:44 +00:00
|
|
|
#ifndef WATER_MAP_H
|
|
|
|
#define WATER_MAP_H
|
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum WaterTileType {
|
2007-03-01 13:27:51 +00:00
|
|
|
WATER_TILE_CLEAR,
|
|
|
|
WATER_TILE_COAST,
|
|
|
|
WATER_TILE_LOCK,
|
|
|
|
WATER_TILE_DEPOT,
|
2008-01-19 17:00:54 +00:00
|
|
|
WATER_TILE_RIVER,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-31 18:36:13 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum DepotPart {
|
2006-03-30 11:11:35 +00:00
|
|
|
DEPOT_NORTH = 0x80,
|
2006-03-30 11:21:36 +00:00
|
|
|
DEPOT_SOUTH = 0x81,
|
|
|
|
DEPOT_END = 0x84,
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-30 11:11:35 +00:00
|
|
|
|
2007-03-07 12:11:48 +00:00
|
|
|
enum LockPart {
|
2006-03-30 11:11:35 +00:00
|
|
|
LOCK_MIDDLE = 0x10,
|
|
|
|
LOCK_LOWER = 0x14,
|
2006-03-31 18:36:13 +00:00
|
|
|
LOCK_UPPER = 0x18,
|
|
|
|
LOCK_END = 0x1C
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-03-30 11:11:35 +00:00
|
|
|
|
2006-03-31 18:36:13 +00:00
|
|
|
static inline WaterTileType GetWaterTileType(TileIndex t)
|
|
|
|
{
|
2007-10-16 19:48:58 +00:00
|
|
|
assert(IsTileType(t, MP_WATER));
|
|
|
|
|
2007-03-01 13:27:51 +00:00
|
|
|
if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
|
|
|
|
if (_m[t].m5 == 1) return WATER_TILE_COAST;
|
2008-01-19 17:00:54 +00:00
|
|
|
if (_m[t].m5 == 2) return WATER_TILE_RIVER;
|
2007-11-24 10:38:43 +00:00
|
|
|
if (IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
|
2006-03-31 18:36:13 +00:00
|
|
|
|
2007-11-24 10:38:43 +00:00
|
|
|
assert(IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END));
|
2007-03-01 13:27:51 +00:00
|
|
|
return WATER_TILE_DEPOT;
|
2006-03-31 18:36:13 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 19:48:58 +00:00
|
|
|
/** IsWater return true if any type of clear water like ocean, river, canal */
|
2006-03-31 18:36:13 +00:00
|
|
|
static inline bool IsWater(TileIndex t)
|
|
|
|
{
|
2007-03-01 13:27:51 +00:00
|
|
|
return GetWaterTileType(t) == WATER_TILE_CLEAR;
|
2006-03-31 18:36:13 +00:00
|
|
|
}
|
|
|
|
|
2007-10-16 19:48:58 +00:00
|
|
|
static inline bool IsSea(TileIndex t)
|
|
|
|
{
|
|
|
|
if (GetWaterTileType(t) != WATER_TILE_CLEAR) return false;
|
|
|
|
if (!IsTileOwner(t, OWNER_WATER)) return false; // 'Human' built water = canal, not sea
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-04-03 10:28:16 +00:00
|
|
|
static inline bool IsCoast(TileIndex t)
|
|
|
|
{
|
2007-03-01 13:27:51 +00:00
|
|
|
return GetWaterTileType(t) == WATER_TILE_COAST;
|
2006-04-03 10:28:16 +00:00
|
|
|
}
|
|
|
|
|
2007-06-19 21:15:14 +00:00
|
|
|
static inline bool IsCanal(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetWaterTileType(t) == WATER_TILE_CLEAR && GetTileOwner(t) != OWNER_WATER;
|
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static inline bool IsRiver(TileIndex t)
|
|
|
|
{
|
|
|
|
return GetWaterTileType(t) == WATER_TILE_RIVER;
|
|
|
|
}
|
|
|
|
|
2007-10-16 19:48:58 +00:00
|
|
|
static inline bool IsWaterTile(TileIndex t)
|
2006-03-30 11:21:36 +00:00
|
|
|
{
|
2007-10-16 19:48:58 +00:00
|
|
|
return IsTileType(t, MP_WATER) && IsWater(t);
|
2006-03-30 11:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline TileIndex GetOtherShipDepotTile(TileIndex t)
|
|
|
|
{
|
2007-11-19 21:02:30 +00:00
|
|
|
return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
2006-03-30 11:21:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline TileIndex IsShipDepot(TileIndex t)
|
|
|
|
{
|
2007-11-24 10:38:43 +00:00
|
|
|
return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END);
|
2006-03-30 11:21:36 +00:00
|
|
|
}
|
|
|
|
|
2006-04-03 10:28:16 +00:00
|
|
|
static inline Axis GetShipDepotAxis(TileIndex t)
|
|
|
|
{
|
|
|
|
return (Axis)GB(_m[t].m5, 1, 1);
|
|
|
|
}
|
|
|
|
|
2006-06-04 16:04:15 +00:00
|
|
|
static inline DiagDirection GetShipDepotDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
|
|
|
|
}
|
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
static inline Owner GetShipDepotWaterOwner(TileIndex t)
|
|
|
|
{
|
|
|
|
return (Owner)_m[t].m4;
|
|
|
|
}
|
|
|
|
|
2006-03-30 11:21:36 +00:00
|
|
|
static inline DiagDirection GetLockDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
|
|
|
}
|
|
|
|
|
2006-04-03 10:50:54 +00:00
|
|
|
static inline byte GetSection(TileIndex t)
|
|
|
|
{
|
2007-03-01 13:27:51 +00:00
|
|
|
assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT);
|
2006-04-03 10:50:54 +00:00
|
|
|
return GB(_m[t].m5, 0, 4);
|
|
|
|
}
|
|
|
|
|
2008-01-20 18:30:53 +00:00
|
|
|
static inline byte GetWaterTileRandomBits(TileIndex t)
|
|
|
|
{
|
|
|
|
return _m[t].m4;
|
|
|
|
}
|
|
|
|
|
2006-03-30 11:21:36 +00:00
|
|
|
|
2006-03-01 21:00:44 +00:00
|
|
|
static inline void MakeWater(TileIndex t)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void MakeShore(TileIndex t)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = 1;
|
|
|
|
}
|
|
|
|
|
2008-01-20 18:30:53 +00:00
|
|
|
static inline void MakeRiver(TileIndex t, uint8 random_bits)
|
2008-01-19 17:00:54 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
2008-01-20 18:30:53 +00:00
|
|
|
_m[t].m4 = random_bits;
|
2008-01-19 17:00:54 +00:00
|
|
|
_m[t].m5 = 2;
|
|
|
|
}
|
|
|
|
|
2008-01-20 18:30:53 +00:00
|
|
|
static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
|
2006-06-03 15:10:39 +00:00
|
|
|
{
|
2007-10-16 19:48:58 +00:00
|
|
|
assert(o != OWNER_WATER);
|
2006-06-03 15:10:39 +00:00
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
2008-01-20 18:30:53 +00:00
|
|
|
_m[t].m4 = random_bits;
|
2006-06-03 15:10:39 +00:00
|
|
|
_m[t].m5 = 0;
|
|
|
|
}
|
|
|
|
|
2007-12-07 21:14:54 +00:00
|
|
|
static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, Owner original_owner)
|
2006-03-30 11:11:35 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
2007-12-07 21:14:54 +00:00
|
|
|
_m[t].m4 = original_owner;
|
2006-03-30 11:11:35 +00:00
|
|
|
_m[t].m5 = base + a * 2;
|
|
|
|
}
|
|
|
|
|
2006-06-03 15:10:39 +00:00
|
|
|
static inline void MakeLockTile(TileIndex t, Owner o, byte section)
|
2006-03-30 11:11:35 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
2006-06-03 15:10:39 +00:00
|
|
|
SetTileOwner(t, o);
|
2006-03-30 11:11:35 +00:00
|
|
|
_m[t].m2 = 0;
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = section;
|
|
|
|
}
|
|
|
|
|
2006-06-03 15:10:39 +00:00
|
|
|
static inline void MakeLock(TileIndex t, Owner o, DiagDirection d)
|
2006-03-30 11:11:35 +00:00
|
|
|
{
|
2006-09-05 23:21:41 +00:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(d);
|
2006-03-30 11:11:35 +00:00
|
|
|
|
2006-06-03 15:10:39 +00:00
|
|
|
MakeLockTile(t, o, LOCK_MIDDLE + d);
|
|
|
|
MakeLockTile(t - delta, o, LOCK_LOWER + d);
|
|
|
|
MakeLockTile(t + delta, o, LOCK_UPPER + d);
|
2006-03-30 11:11:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* WATER_MAP_H */
|