2006-03-06 20:55:24 +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 tunnel_map.h Map accessors for tunnels. */
|
2007-04-04 03:21:14 +00:00
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
#ifndef TUNNEL_MAP_H
|
|
|
|
#define TUNNEL_MAP_H
|
|
|
|
|
2009-03-02 22:57:47 +00:00
|
|
|
#include "road_map.h"
|
2006-03-06 20:55:24 +00:00
|
|
|
|
2017-03-04 23:49:55 +00:00
|
|
|
typedef uint32 TunnelID; ///< Type for the unique identifier of tunnels.
|
|
|
|
|
|
|
|
static const TunnelID TUNNEL_ID_MAP_LOOKUP = 0xFFFF; ///< Sentinel ID value to store in m2 to indiciate that the ID should be looked up instead
|
2007-12-16 15:38:51 +00:00
|
|
|
|
2007-04-27 21:29:36 +00:00
|
|
|
/**
|
|
|
|
* Is this a tunnel (entrance)?
|
|
|
|
* @param t the tile that might be a tunnel
|
|
|
|
* @pre IsTileType(t, MP_TUNNELBRIDGE)
|
|
|
|
* @return true if and only if this tile is a tunnel (entrance)
|
|
|
|
*/
|
2006-03-12 15:04:03 +00:00
|
|
|
static inline bool IsTunnel(TileIndex t)
|
|
|
|
{
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsTileType(t, MP_TUNNELBRIDGE), t);
|
2007-11-19 21:02:30 +00:00
|
|
|
return !HasBit(_m[t].m5, 7);
|
2006-03-12 15:04:03 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:29:36 +00:00
|
|
|
/**
|
|
|
|
* Is this a tunnel (entrance)?
|
|
|
|
* @param t the tile that might be a tunnel
|
|
|
|
* @return true if and only if this tile is a tunnel (entrance)
|
|
|
|
*/
|
2006-03-12 15:04:03 +00:00
|
|
|
static inline bool IsTunnelTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_TUNNELBRIDGE) && IsTunnel(t);
|
|
|
|
}
|
|
|
|
|
2017-03-04 11:43:45 +00:00
|
|
|
/**
|
|
|
|
* Get the index of tunnel tile.
|
|
|
|
* @param t the tile
|
|
|
|
* @pre IsTunnelTile(t)
|
|
|
|
* @return TunnelID
|
|
|
|
*/
|
|
|
|
static inline TunnelID GetTunnelIndex(TileIndex t)
|
|
|
|
{
|
2017-03-04 23:49:55 +00:00
|
|
|
extern TunnelID GetTunnelIndexByLookup(TileIndex t);
|
|
|
|
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsTunnelTile(t), t);
|
2017-03-04 23:49:55 +00:00
|
|
|
TunnelID map_id = _m[t].m2;
|
|
|
|
return map_id == TUNNEL_ID_MAP_LOOKUP ? GetTunnelIndexByLookup(t) : map_id;
|
2017-03-04 11:43:45 +00:00
|
|
|
}
|
|
|
|
|
2018-07-03 18:09:10 +00:00
|
|
|
/**
|
|
|
|
* Checks if this tile is a rail tunnel
|
|
|
|
* @param t the tile that might be a rail tunnel
|
|
|
|
* @return true if it is a rail tunnel
|
|
|
|
*/
|
|
|
|
static inline bool IsRailTunnelTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTunnelTile(t) && (TransportType)GB(_m[t].m5, 2, 2) == TRANSPORT_RAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the reservation state of the rail tunnel
|
|
|
|
* @pre IsRailTunnelTile(t)
|
|
|
|
* @param t the tile
|
|
|
|
* @return reservation state
|
|
|
|
*/
|
|
|
|
static inline bool HasTunnelReservation(TileIndex t)
|
|
|
|
{
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsRailTunnelTile(t), t);
|
2018-07-03 18:09:10 +00:00
|
|
|
return HasBit(_m[t].m5, 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the reservation state of the rail tunnel
|
|
|
|
* @pre IsRailTunnelTile(t)
|
|
|
|
* @param t the tile
|
|
|
|
* @param b the reservation state
|
|
|
|
*/
|
|
|
|
static inline void SetTunnelReservation(TileIndex t, bool b)
|
|
|
|
{
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsRailTunnelTile(t), t);
|
2018-07-03 18:09:10 +00:00
|
|
|
SB(_m[t].m5, 4, 1, b ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2006-03-06 20:55:24 +00:00
|
|
|
TileIndex GetOtherTunnelEnd(TileIndex);
|
2017-03-05 19:13:42 +00:00
|
|
|
|
|
|
|
/** Flags for miscellaneous industry tile specialities */
|
|
|
|
enum IsTunnelInWayFlags {
|
|
|
|
ITIWF_NONE = 0,
|
|
|
|
ITIWF_IGNORE_CHUNNEL = 1 << 0, ///< Chunnel mid-parts are ignored, used when terraforming.
|
|
|
|
ITIWF_CHUNNEL_ONLY = 1 << 1, ///< Only check for chunnels
|
|
|
|
};
|
|
|
|
DECLARE_ENUM_AS_BIT_SET(IsTunnelInWayFlags)
|
|
|
|
|
|
|
|
bool IsTunnelInWay(TileIndex, int z, IsTunnelInWayFlags flags = ITIWF_NONE);
|
2006-03-06 20:55:24 +00:00
|
|
|
|
2017-03-05 14:06:34 +00:00
|
|
|
/**
|
|
|
|
* Set the index of tunnel tile.
|
|
|
|
* @param t the tile
|
|
|
|
* @param id the tunnel ID
|
|
|
|
* @pre IsTunnelTile(t)
|
|
|
|
*/
|
|
|
|
static inline void SetTunnelIndex(TileIndex t, TunnelID id)
|
|
|
|
{
|
2018-07-26 18:13:35 +00:00
|
|
|
assert_tile(IsTunnelTile(t), t);
|
2017-03-05 14:06:34 +00:00
|
|
|
_m[t].m2 = (id >= TUNNEL_ID_MAP_LOOKUP) ? TUNNEL_ID_MAP_LOOKUP : id;
|
|
|
|
}
|
|
|
|
|
2007-04-27 21:29:36 +00:00
|
|
|
/**
|
|
|
|
* Makes a road tunnel entrance
|
|
|
|
* @param t the entrance of the tunnel
|
|
|
|
* @param o the owner of the entrance
|
2017-03-04 12:43:48 +00:00
|
|
|
* @param id the tunnel ID
|
2007-04-27 21:29:36 +00:00
|
|
|
* @param d the direction facing out of the tunnel
|
2007-05-20 19:14:08 +00:00
|
|
|
* @param r the road type used in the tunnel
|
2007-04-27 21:29:36 +00:00
|
|
|
*/
|
2017-03-04 11:43:45 +00:00
|
|
|
static inline void MakeRoadTunnel(TileIndex t, Owner o, TunnelID id, DiagDirection d, RoadTypes r)
|
2006-03-06 20:55:24 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_TUNNELBRIDGE);
|
|
|
|
SetTileOwner(t, o);
|
2018-07-26 19:54:13 +00:00
|
|
|
SetTunnelIndex(t, id);
|
2009-03-02 22:57:47 +00:00
|
|
|
_m[t].m3 = 0;
|
2006-03-06 20:55:24 +00:00
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = TRANSPORT_ROAD << 2 | d;
|
2014-09-21 11:23:33 +00:00
|
|
|
SB(_me[t].m6, 2, 4, 0);
|
2009-03-08 16:10:39 +00:00
|
|
|
_me[t].m7 = 0;
|
2018-07-22 22:47:15 +00:00
|
|
|
_me[t].m8 = 0;
|
2009-03-02 22:57:47 +00:00
|
|
|
SetRoadOwner(t, ROADTYPE_ROAD, o);
|
|
|
|
if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
|
|
|
|
SetRoadTypes(t, r);
|
2006-03-06 20:55:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-27 21:29:36 +00:00
|
|
|
/**
|
|
|
|
* Makes a rail tunnel entrance
|
|
|
|
* @param t the entrance of the tunnel
|
|
|
|
* @param o the owner of the entrance
|
2017-03-04 12:43:48 +00:00
|
|
|
* @param id the tunnel ID
|
2007-04-27 21:29:36 +00:00
|
|
|
* @param d the direction facing out of the tunnel
|
|
|
|
* @param r the rail type used in the tunnel
|
|
|
|
*/
|
2017-03-04 12:43:48 +00:00
|
|
|
static inline void MakeRailTunnel(TileIndex t, Owner o, TunnelID id, DiagDirection d, RailType r)
|
2006-03-06 20:55:24 +00:00
|
|
|
{
|
|
|
|
SetTileType(t, MP_TUNNELBRIDGE);
|
|
|
|
SetTileOwner(t, o);
|
2018-07-26 19:54:13 +00:00
|
|
|
SetTunnelIndex(t, id);
|
2018-07-22 22:47:15 +00:00
|
|
|
_m[t].m3 = 0;
|
2006-03-06 20:55:24 +00:00
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = TRANSPORT_RAIL << 2 | d;
|
2014-09-21 11:23:33 +00:00
|
|
|
SB(_me[t].m6, 2, 4, 0);
|
2009-03-08 16:10:39 +00:00
|
|
|
_me[t].m7 = 0;
|
2018-07-22 22:47:15 +00:00
|
|
|
_me[t].m8 = r;
|
2006-03-06 20:55:24 +00:00
|
|
|
}
|
|
|
|
|
2006-09-28 18:42:35 +00:00
|
|
|
#endif /* TUNNEL_MAP_H */
|