2006-03-01 21:00:44 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 15:11:33 +00:00
|
|
|
/** @file water_map.h Map accessors for water tiles. */
|
2007-04-06 04:10:19 +00:00
|
|
|
|
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-02-02 09:28:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum WaterClass {
|
|
|
|
WATER_CLASS_SEA,
|
|
|
|
WATER_CLASS_CANAL,
|
|
|
|
WATER_CLASS_RIVER,
|
2008-07-26 16:14:10 +00:00
|
|
|
WATER_CLASS_INVALID, ///< Used for industry tiles on land (also for oilrig if newgrf says so)
|
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;
|
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
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
static inline WaterClass GetWaterClass(TileIndex t)
|
|
|
|
{
|
2008-07-26 16:14:10 +00:00
|
|
|
assert(IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY));
|
|
|
|
return (WaterClass)(IsTileType(t, MP_INDUSTRY) ? GB(_m[t].m1, 5, 2) : GB(_m[t].m3, 0, 2));
|
2008-02-02 09:28:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetWaterClass(TileIndex t, WaterClass wc)
|
|
|
|
{
|
2008-07-26 16:14:10 +00:00
|
|
|
assert(IsTileType(t, MP_WATER) || IsTileType(t, MP_STATION) || IsTileType(t, MP_INDUSTRY));
|
|
|
|
if (IsTileType(t, MP_INDUSTRY)) {
|
|
|
|
SB(_m[t].m1, 5, 2, wc);
|
|
|
|
} else {
|
|
|
|
SB(_m[t].m3, 0, 2, wc);
|
|
|
|
}
|
2008-02-02 09:28:43 +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)
|
|
|
|
{
|
2008-02-02 09:28:43 +00:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_SEA;
|
2006-04-03 10:28:16 +00:00
|
|
|
}
|
|
|
|
|
2007-06-19 21:15:14 +00:00
|
|
|
static inline bool IsCanal(TileIndex t)
|
|
|
|
{
|
2008-02-02 09:28:43 +00:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_CANAL;
|
2007-06-19 21:15:14 +00:00
|
|
|
}
|
|
|
|
|
2008-01-19 17:00:54 +00:00
|
|
|
static inline bool IsRiver(TileIndex t)
|
|
|
|
{
|
2008-02-02 09:28:43 +00:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_RIVER;
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
static inline bool IsCoast(TileIndex t)
|
2008-01-22 22:17:28 +00:00
|
|
|
{
|
2008-02-02 09:28:43 +00:00
|
|
|
return GetWaterTileType(t) == WATER_TILE_COAST;
|
2008-01-22 22:17:28 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2008-04-18 01:35:17 +00:00
|
|
|
static inline bool IsShipDepot(TileIndex t)
|
2006-03-30 11:21:36 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2008-04-18 01:35:17 +00:00
|
|
|
static inline bool IsShipDepotTile(TileIndex t)
|
2008-04-17 00:44:20 +00:00
|
|
|
{
|
|
|
|
return IsTileType(t, MP_WATER) && IsShipDepot(t);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2008-02-06 15:32:06 +00:00
|
|
|
static inline bool IsLock(TileIndex t)
|
2007-12-07 21:14:54 +00:00
|
|
|
{
|
2008-02-06 15:32:06 +00:00
|
|
|
return IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END);
|
2007-12-07 21:14:54 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m3 = WATER_CLASS_SEA;
|
2006-03-01 21:00:44 +00:00
|
|
|
_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;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m3 = WATER_CLASS_RIVER;
|
2008-01-20 18:30:53 +00:00
|
|
|
_m[t].m4 = random_bits;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m5 = 0;
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m3 = WATER_CLASS_CANAL;
|
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;
|
|
|
|
}
|
|
|
|
|
2008-02-06 15:32:06 +00:00
|
|
|
static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class)
|
2006-03-30 11:11:35 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m3 = original_water_class;
|
2008-02-06 15:32:06 +00:00
|
|
|
_m[t].m4 = 0;
|
2006-03-30 11:11:35 +00:00
|
|
|
_m[t].m5 = base + a * 2;
|
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
static inline void MakeLockTile(TileIndex t, Owner o, byte section, WaterClass original_water_class)
|
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;
|
2008-02-02 09:28:43 +00:00
|
|
|
_m[t].m3 = original_water_class;
|
2006-03-30 11:11:35 +00:00
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = section;
|
|
|
|
}
|
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
static inline void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper)
|
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
|
|
|
|
2008-02-02 09:28:43 +00:00
|
|
|
MakeLockTile(t, o, LOCK_MIDDLE + d, WATER_CLASS_CANAL);
|
|
|
|
MakeLockTile(t - delta, o, LOCK_LOWER + d, wc_lower);
|
|
|
|
MakeLockTile(t + delta, o, LOCK_UPPER + d, wc_upper);
|
2006-03-30 11:11:35 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* WATER_MAP_H */
|