Files @ r28486:aff297ed5a05
Branch filter:

Location: cpp/openttd-patchpack/source/src/tunnelbridge_map.h - annotation

Peter Nelson
Codechange: Allow constexpr NWidgetPart construction.
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8197:5f087672abf6
r8197:5f087672abf6
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8481:eb333f15ccd8
r8481:eb333f15ccd8
r8481:eb333f15ccd8
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r19944:25a78576fb5e
r8083:8cd2123a0c7c
r28410:d9c73d685bbc
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r26931:7d5bce03e821
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r28410:d9c73d685bbc
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r26931:7d5bce03e821
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r28410:d9c73d685bbc
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r26931:7d5bce03e821
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r28410:d9c73d685bbc
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r26931:7d5bce03e821
r8083:8cd2123a0c7c
r8083:8cd2123a0c7c
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r28410:d9c73d685bbc
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r8197:5f087672abf6
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r28410:d9c73d685bbc
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r26931:7d5bce03e821
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r28410:d9c73d685bbc
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r26931:7d5bce03e821
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r28410:d9c73d685bbc
r9784:d6ecb2e78057
r12460:1f2d22685cf3
r9784:d6ecb2e78057
r9784:d6ecb2e78057
r8083:8cd2123a0c7c
/*
 * 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/>.
 */

/** @file tunnelbridge_map.h Functions that have tunnels and bridges in common */

#ifndef TUNNELBRIDGE_MAP_H
#define TUNNELBRIDGE_MAP_H

#include "bridge_map.h"
#include "tunnel_map.h"


/**
 * Get the direction pointing to the other end.
 *
 * Tunnel: Get the direction facing into the tunnel
 * Bridge: Get the direction pointing onto the bridge
 * @param t The tile to analyze
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 * @return the above mentioned direction
 */
inline DiagDirection GetTunnelBridgeDirection(Tile t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	return (DiagDirection)GB(t.m5(), 0, 2);
}

/**
 * Tunnel: Get the transport type of the tunnel (road or rail)
 * Bridge: Get the transport type of the bridge's ramp
 * @param t The tile to analyze
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 * @return the transport type in the tunnel/bridge
 */
inline TransportType GetTunnelBridgeTransportType(Tile t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	return (TransportType)GB(t.m5(), 2, 2);
}

/**
 * Tunnel: Is this tunnel entrance in a snowy or desert area?
 * Bridge: Does the bridge ramp lie in a snow or desert area?
 * @param t The tile to analyze
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 * @return true if and only if the tile is in a snowy/desert area
 */
inline bool HasTunnelBridgeSnowOrDesert(Tile t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	return HasBit(t.m7(), 5);
}

/**
 * Tunnel: Places this tunnel entrance in a snowy or desert area, or takes it out of there.
 * Bridge: Sets whether the bridge ramp lies in a snow or desert area.
 * @param t the tunnel entrance / bridge ramp tile
 * @param snow_or_desert is the entrance/ramp in snow or desert (true), when
 *                       not in snow and not in desert false
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 */
inline void SetTunnelBridgeSnowOrDesert(Tile t, bool snow_or_desert)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	SB(t.m7(), 5, 1, snow_or_desert);
}

/**
 * Determines type of the wormhole and returns its other end
 * @param t one end
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 * @return other end
 */
inline TileIndex GetOtherTunnelBridgeEnd(Tile t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
}


/**
 * Get the reservation state of the rail tunnel/bridge
 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
 * @param t the tile
 * @return reservation state
 */
inline bool HasTunnelBridgeReservation(Tile t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
	return HasBit(t.m5(), 4);
}

/**
 * Set the reservation state of the rail tunnel/bridge
 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
 * @param t the tile
 * @param b the reservation state
 */
inline void SetTunnelBridgeReservation(Tile t, bool b)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	assert(GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL);
	SB(t.m5(), 4, 1, b ? 1 : 0);
}

/**
 * Get the reserved track bits for a rail tunnel/bridge
 * @pre IsTileType(t, MP_TUNNELBRIDGE) && GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL
 * @param t the tile
 * @return reserved track bits
 */
inline TrackBits GetTunnelBridgeReservationTrackBits(Tile t)
{
	return HasTunnelBridgeReservation(t) ? DiagDirToDiagTrackBits(GetTunnelBridgeDirection(t)) : TRACK_BIT_NONE;
}

#endif /* TUNNELBRIDGE_MAP_H */