2006-03-01 21:00:44 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
|
|
2009-05-22 15:13:50 +00:00
|
|
|
#include "core/math_func.hpp"
|
2009-09-10 14:33:07 +00:00
|
|
|
#include "depot_type.h"
|
2010-01-15 16:41:15 +00:00
|
|
|
#include "tile_map.h"
|
2009-05-22 15:13:50 +00:00
|
|
|
|
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 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;
|
2009-03-08 16:10:39 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = 0;
|
2006-03-01 21:00:44 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 12:31:11 +00:00
|
|
|
/**
|
|
|
|
* Helper function for making a watery tile.
|
|
|
|
* @param t The tile to change into water
|
|
|
|
* @param o The owner of the water
|
|
|
|
* @param wc The class of water the tile has to be
|
|
|
|
* @param random_bits Eventual random bits to be set for this tile
|
|
|
|
*/
|
|
|
|
static inline void MakeWater(TileIndex t, Owner o, WaterClass wc, uint8 random_bits)
|
2008-01-19 17:00:54 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
2009-10-20 12:31:11 +00:00
|
|
|
SetTileOwner(t, o);
|
2008-01-19 17:00:54 +00:00
|
|
|
_m[t].m2 = 0;
|
2009-10-20 12:31:11 +00:00
|
|
|
_m[t].m3 = wc;
|
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;
|
2009-03-08 16:10:39 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = 0;
|
2008-01-19 17:00:54 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 12:31:11 +00:00
|
|
|
/**
|
|
|
|
* Make a sea tile.
|
|
|
|
* @param t The tile to change into sea
|
|
|
|
*/
|
|
|
|
static inline void MakeSea(TileIndex t)
|
|
|
|
{
|
|
|
|
MakeWater(t, OWNER_WATER, WATER_CLASS_SEA, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a river tile
|
|
|
|
* @param t The tile to change into river
|
|
|
|
* @param random_bits Random bits to be set for this tile
|
|
|
|
*/
|
|
|
|
static inline void MakeRiver(TileIndex t, uint8 random_bits)
|
|
|
|
{
|
|
|
|
MakeWater(t, OWNER_WATER, WATER_CLASS_RIVER, random_bits);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make a canal tile
|
|
|
|
* @param t The tile to change into canal
|
|
|
|
* @param o The owner of the canal
|
|
|
|
* @param random_bits Random bits to be set for this tile
|
|
|
|
*/
|
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);
|
2009-10-20 12:31:11 +00:00
|
|
|
MakeWater(t, o, WATER_CLASS_CANAL, random_bits);
|
2006-06-03 15:10:39 +00:00
|
|
|
}
|
|
|
|
|
2009-09-10 14:33:07 +00:00
|
|
|
static inline void MakeShipDepot(TileIndex t, Owner o, DepotID did, DepotPart base, Axis a, WaterClass original_water_class)
|
2006-03-30 11:11:35 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_WATER);
|
|
|
|
SetTileOwner(t, o);
|
2009-09-10 14:33:07 +00:00
|
|
|
_m[t].m2 = did;
|
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;
|
2009-03-08 16:10:39 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = 0;
|
2006-03-30 11:11:35 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2009-03-08 16:10:39 +00:00
|
|
|
SB(_m[t].m6, 2, 4, 0);
|
|
|
|
_me[t].m7 = 0;
|
2006-03-30 11:11:35 +00:00
|
|
|
}
|
|
|
|
|
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 */
|