2006-03-01 22:00:44 +01:00
|
|
|
/* $Id$ */
|
|
|
|
|
2008-05-06 17:11:33 +02:00
|
|
|
/** @file water_map.h Map accessors for water tiles. */
|
2007-04-06 06:10:19 +02:00
|
|
|
|
2006-03-01 22:00:44 +01:00
|
|
|
#ifndef WATER_MAP_H
|
|
|
|
#define WATER_MAP_H
|
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
enum WaterTileType {
|
2007-03-01 14:27:51 +01:00
|
|
|
WATER_TILE_CLEAR,
|
|
|
|
WATER_TILE_COAST,
|
|
|
|
WATER_TILE_LOCK,
|
|
|
|
WATER_TILE_DEPOT,
|
2008-02-02 10:28:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
enum WaterClass {
|
|
|
|
WATER_CLASS_SEA,
|
|
|
|
WATER_CLASS_CANAL,
|
|
|
|
WATER_CLASS_RIVER,
|
2008-07-26 18:14:10 +02:00
|
|
|
WATER_CLASS_INVALID, ///< Used for industry tiles on land (also for oilrig if newgrf says so)
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2006-03-31 20:36:13 +02:00
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
enum DepotPart {
|
2006-03-30 13:11:35 +02:00
|
|
|
DEPOT_NORTH = 0x80,
|
2006-03-30 13:21:36 +02:00
|
|
|
DEPOT_SOUTH = 0x81,
|
|
|
|
DEPOT_END = 0x84,
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2006-03-30 13:11:35 +02:00
|
|
|
|
2007-03-07 13:11:48 +01:00
|
|
|
enum LockPart {
|
2006-03-30 13:11:35 +02:00
|
|
|
LOCK_MIDDLE = 0x10,
|
|
|
|
LOCK_LOWER = 0x14,
|
2006-03-31 20:36:13 +02:00
|
|
|
LOCK_UPPER = 0x18,
|
|
|
|
LOCK_END = 0x1C
|
2007-03-07 13:11:48 +01:00
|
|
|
};
|
2006-03-30 13:11:35 +02:00
|
|
|
|
2006-03-31 20:36:13 +02:00
|
|
|
static inline WaterTileType GetWaterTileType(TileIndex t)
|
|
|
|
{
|
2007-10-16 21:48:58 +02:00
|
|
|
assert(IsTileType(t, MP_WATER));
|
|
|
|
|
2007-03-01 14:27:51 +01:00
|
|
|
if (_m[t].m5 == 0) return WATER_TILE_CLEAR;
|
|
|
|
if (_m[t].m5 == 1) return WATER_TILE_COAST;
|
2007-11-24 11:38:43 +01:00
|
|
|
if (IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END)) return WATER_TILE_LOCK;
|
2006-03-31 20:36:13 +02:00
|
|
|
|
2007-11-24 11:38:43 +01:00
|
|
|
assert(IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END));
|
2007-03-01 14:27:51 +01:00
|
|
|
return WATER_TILE_DEPOT;
|
2006-03-31 20:36:13 +02:00
|
|
|
}
|
|
|
|
|
2008-02-02 10:28:43 +01:00
|
|
|
static inline WaterClass GetWaterClass(TileIndex t)
|
|
|
|
{
|
2008-07-26 18:14:10 +02: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 10:28:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void SetWaterClass(TileIndex t, WaterClass wc)
|
|
|
|
{
|
2008-07-26 18:14:10 +02: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 10:28:43 +01:00
|
|
|
}
|
|
|
|
|
2007-10-16 21:48:58 +02:00
|
|
|
/** IsWater return true if any type of clear water like ocean, river, canal */
|
2006-03-31 20:36:13 +02:00
|
|
|
static inline bool IsWater(TileIndex t)
|
|
|
|
{
|
2007-03-01 14:27:51 +01:00
|
|
|
return GetWaterTileType(t) == WATER_TILE_CLEAR;
|
2006-03-31 20:36:13 +02:00
|
|
|
}
|
|
|
|
|
2007-10-16 21:48:58 +02:00
|
|
|
static inline bool IsSea(TileIndex t)
|
|
|
|
{
|
2008-02-02 10:28:43 +01:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_SEA;
|
2006-04-03 12:28:16 +02:00
|
|
|
}
|
|
|
|
|
2007-06-19 23:15:14 +02:00
|
|
|
static inline bool IsCanal(TileIndex t)
|
|
|
|
{
|
2008-02-02 10:28:43 +01:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_CANAL;
|
2007-06-19 23:15:14 +02:00
|
|
|
}
|
|
|
|
|
2008-01-19 18:00:54 +01:00
|
|
|
static inline bool IsRiver(TileIndex t)
|
|
|
|
{
|
2008-02-02 10:28:43 +01:00
|
|
|
return IsWater(t) && GetWaterClass(t) == WATER_CLASS_RIVER;
|
2008-01-19 18:00:54 +01:00
|
|
|
}
|
|
|
|
|
2007-10-16 21:48:58 +02:00
|
|
|
static inline bool IsWaterTile(TileIndex t)
|
2006-03-30 13:21:36 +02:00
|
|
|
{
|
2007-10-16 21:48:58 +02:00
|
|
|
return IsTileType(t, MP_WATER) && IsWater(t);
|
2006-03-30 13:21:36 +02:00
|
|
|
}
|
|
|
|
|
2008-02-02 10:28:43 +01:00
|
|
|
static inline bool IsCoast(TileIndex t)
|
2008-01-22 23:17:28 +01:00
|
|
|
{
|
2008-02-02 10:28:43 +01:00
|
|
|
return GetWaterTileType(t) == WATER_TILE_COAST;
|
2008-01-22 23:17:28 +01:00
|
|
|
}
|
|
|
|
|
2006-03-30 13:21:36 +02:00
|
|
|
static inline TileIndex GetOtherShipDepotTile(TileIndex t)
|
|
|
|
{
|
2007-11-19 22:02:30 +01:00
|
|
|
return t + (HasBit(_m[t].m5, 0) ? -1 : 1) * (HasBit(_m[t].m5, 1) ? TileDiffXY(0, 1) : TileDiffXY(1, 0));
|
2006-03-30 13:21:36 +02:00
|
|
|
}
|
|
|
|
|
2008-04-18 03:35:17 +02:00
|
|
|
static inline bool IsShipDepot(TileIndex t)
|
2006-03-30 13:21:36 +02:00
|
|
|
{
|
2007-11-24 11:38:43 +01:00
|
|
|
return IsInsideMM(_m[t].m5, DEPOT_NORTH, DEPOT_END);
|
2006-03-30 13:21:36 +02:00
|
|
|
}
|
|
|
|
|
2008-04-18 03:35:17 +02:00
|
|
|
static inline bool IsShipDepotTile(TileIndex t)
|
2008-04-17 02:44:20 +02:00
|
|
|
{
|
|
|
|
return IsTileType(t, MP_WATER) && IsShipDepot(t);
|
|
|
|
}
|
|
|
|
|
2006-04-03 12:28:16 +02:00
|
|
|
static inline Axis GetShipDepotAxis(TileIndex t)
|
|
|
|
{
|
|
|
|
return (Axis)GB(_m[t].m5, 1, 1);
|
|
|
|
}
|
|
|
|
|
2006-06-04 18:04:15 +02:00
|
|
|
static inline DiagDirection GetShipDepotDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
return XYNSToDiagDir(GetShipDepotAxis(t), GB(_m[t].m5, 0, 1));
|
|
|
|
}
|
|
|
|
|
2008-02-06 16:32:06 +01:00
|
|
|
static inline bool IsLock(TileIndex t)
|
2007-12-07 22:14:54 +01:00
|
|
|
{
|
2008-02-06 16:32:06 +01:00
|
|
|
return IsInsideMM(_m[t].m5, LOCK_MIDDLE, LOCK_END);
|
2007-12-07 22:14:54 +01:00
|
|
|
}
|
|
|
|
|
2006-03-30 13:21:36 +02:00
|
|
|
static inline DiagDirection GetLockDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
return (DiagDirection)GB(_m[t].m5, 0, 2);
|
|
|
|
}
|
|
|
|
|
2006-04-03 12:50:54 +02:00
|
|
|
static inline byte GetSection(TileIndex t)
|
|
|
|
{
|
2007-03-01 14:27:51 +01:00
|
|
|
assert(GetWaterTileType(t) == WATER_TILE_LOCK || GetWaterTileType(t) == WATER_TILE_DEPOT);
|
2006-04-03 12:50:54 +02:00
|
|
|
return GB(_m[t].m5, 0, 4);
|
|
|
|
}
|
|
|
|
|
2008-01-20 19:30:53 +01:00
|
|
|
static inline byte GetWaterTileRandomBits(TileIndex t)
|
|
|
|
{
|
|
|
|
return _m[t].m4;
|
|
|
|
}
|
|
|
|
|
2006-03-30 13:21:36 +02:00
|
|
|
|
2006-03-01 22:00:44 +01:00
|
|
|
static inline void MakeWater(TileIndex t)
|
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
_m[t].m2 = 0;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m3 = WATER_CLASS_SEA;
|
2006-03-01 22:00:44 +01: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 19:30:53 +01:00
|
|
|
static inline void MakeRiver(TileIndex t, uint8 random_bits)
|
2008-01-19 18:00:54 +01:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, OWNER_WATER);
|
|
|
|
_m[t].m2 = 0;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m3 = WATER_CLASS_RIVER;
|
2008-01-20 19:30:53 +01:00
|
|
|
_m[t].m4 = random_bits;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m5 = 0;
|
2008-01-19 18:00:54 +01:00
|
|
|
}
|
|
|
|
|
2008-01-20 19:30:53 +01:00
|
|
|
static inline void MakeCanal(TileIndex t, Owner o, uint8 random_bits)
|
2006-06-03 17:10:39 +02:00
|
|
|
{
|
2007-10-16 21:48:58 +02:00
|
|
|
assert(o != OWNER_WATER);
|
2006-06-03 17:10:39 +02:00
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m3 = WATER_CLASS_CANAL;
|
2008-01-20 19:30:53 +01:00
|
|
|
_m[t].m4 = random_bits;
|
2006-06-03 17:10:39 +02:00
|
|
|
_m[t].m5 = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-06 16:32:06 +01:00
|
|
|
static inline void MakeShipDepot(TileIndex t, Owner o, DepotPart base, Axis a, WaterClass original_water_class)
|
2006-03-30 13:11:35 +02:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = 0;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m3 = original_water_class;
|
2008-02-06 16:32:06 +01:00
|
|
|
_m[t].m4 = 0;
|
2006-03-30 13:11:35 +02:00
|
|
|
_m[t].m5 = base + a * 2;
|
|
|
|
}
|
|
|
|
|
2008-02-02 10:28:43 +01:00
|
|
|
static inline void MakeLockTile(TileIndex t, Owner o, byte section, WaterClass original_water_class)
|
2006-03-30 13:11:35 +02:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
2006-06-03 17:10:39 +02:00
|
|
|
SetTileOwner(t, o);
|
2006-03-30 13:11:35 +02:00
|
|
|
_m[t].m2 = 0;
|
2008-02-02 10:28:43 +01:00
|
|
|
_m[t].m3 = original_water_class;
|
2006-03-30 13:11:35 +02:00
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = section;
|
|
|
|
}
|
|
|
|
|
2008-02-02 10:28:43 +01:00
|
|
|
static inline void MakeLock(TileIndex t, Owner o, DiagDirection d, WaterClass wc_lower, WaterClass wc_upper)
|
2006-03-30 13:11:35 +02:00
|
|
|
{
|
2006-09-06 01:21:41 +02:00
|
|
|
TileIndexDiff delta = TileOffsByDiagDir(d);
|
2006-03-30 13:11:35 +02:00
|
|
|
|
2008-02-02 10:28:43 +01: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 13:11:35 +02:00
|
|
|
}
|
|
|
|
|
2006-09-28 20:42:35 +02:00
|
|
|
#endif /* WATER_MAP_H */
|