Files @ r17613:a9b2554a5d79
Branch filter:

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

rubidium
(svn r22387) -Fix-ish [FS#4601]: Windows' recv seems to return "graceful closed" before having passed the remaining buffer which causes OpenTTD to think all connections are "incorrectly" terminated, i.e. without the "I'm leaving" packet from the client. So let the client wait a tiny bit after sending the "I'm leaving" packet and before gracefully closing the connection
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r12768:980ae0491352
r6418:8a4b147a8f33
r6123:049e9624d068
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r8532:0c31796f7b70
r5475:3f5cd13d1b63
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r7928:a80e7e05d6c5
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r16537:b136370bd3c2
r16537:b136370bd3c2
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6416:1409210e5613
r6416:1409210e5613
r6416:1409210e5613
r6418:8a4b147a8f33
r6416:1409210e5613
r6416:1409210e5613
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5596:84985796bbd9
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6416:1409210e5613
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r8532:0c31796f7b70
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r11247:c15ef8b37f5e
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5596:84985796bbd9
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r7929:67846e70abf8
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r7931:4c17a74c399e
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6661:a60bd28b4b57
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r8532:0c31796f7b70
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r11247:c15ef8b37f5e
r6661:a60bd28b4b57
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r11247:c15ef8b37f5e
r11289:7e06e1b4e52d
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6661:a60bd28b4b57
r6418:8a4b147a8f33
r8532:0c31796f7b70
r5475:3f5cd13d1b63
r11247:c15ef8b37f5e
r11247:c15ef8b37f5e
r11247:c15ef8b37f5e
r11247:c15ef8b37f5e
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r6418:8a4b147a8f33
r8532:0c31796f7b70
r5475:3f5cd13d1b63
r6661:a60bd28b4b57
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r9490:5cf190d39c21
r5475:3f5cd13d1b63
r5475:3f5cd13d1b63
/* $Id$ */

/*
 * 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 bridge_map.h Map accessor functions for bridges. */

#ifndef BRIDGE_MAP_H
#define BRIDGE_MAP_H

#include "road_map.h"
#include "bridge.h"

/**
 * Checks if this is a bridge, instead of a tunnel
 * @param t The tile to analyze
 * @pre IsTileType(t, MP_TUNNELBRIDGE)
 * @return true if the structure is a bridge one
 */
static inline bool IsBridge(TileIndex t)
{
	assert(IsTileType(t, MP_TUNNELBRIDGE));
	return HasBit(_m[t].m5, 7);
}

/**
 * checks if there is a bridge on this tile
 * @param t The tile to analyze
 * @return true if a bridge is present
 */
static inline bool IsBridgeTile(TileIndex t)
{
	return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
}

/**
 * checks for the possibility that a bridge may be on this tile
 * These are in fact all the tile types on which a bridge can be found
 * @param t The tile to analyze
 * @return true if a bridge migh be present
 */
static inline bool MayHaveBridgeAbove(TileIndex t)
{
	return IsTileType(t, MP_CLEAR) || IsTileType(t, MP_RAILWAY) || IsTileType(t, MP_ROAD) ||
			IsTileType(t, MP_WATER) || IsTileType(t, MP_TUNNELBRIDGE) || IsTileType(t, MP_OBJECT);
}

/**
 * checks if a bridge is set above the ground of this tile
 * @param t The tile to analyze
 * @pre MayHaveBridgeAbove(t)
 * @return true if a bridge is detected above
 */
static inline bool IsBridgeAbove(TileIndex t)
{
	assert(MayHaveBridgeAbove(t));
	return GB(_m[t].m6, 6, 2) != 0;
}

/**
 * Determines the type of bridge on a tile
 * @param t The tile to analyze
 * @pre IsBridgeTile(t)
 * @return The bridge type
 */
static inline BridgeType GetBridgeType(TileIndex t)
{
	assert(IsBridgeTile(t));
	return GB(_m[t].m6, 2, 4);
}

/**
 * Get the axis of the bridge that goes over the tile. Not the axis or the ramp.
 * @param t The tile to analyze
 * @pre IsBridgeAbove(t)
 * @return the above mentioned axis
 */
static inline Axis GetBridgeAxis(TileIndex t)
{
	assert(IsBridgeAbove(t));
	return (Axis)(GB(_m[t].m6, 6, 2) - 1);
}

TileIndex GetNorthernBridgeEnd(TileIndex t);
TileIndex GetSouthernBridgeEnd(TileIndex t);
TileIndex GetOtherBridgeEnd(TileIndex t);

uint GetBridgeHeight(TileIndex tile);

/**
 * Remove the bridge over the given axis.
 * @param t the tile to remove the bridge from
 * @param a the axis of the bridge to remove
 * @pre MayHaveBridgeAbove(t)
 */
static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
{
	assert(MayHaveBridgeAbove(t));
	ClrBit(_m[t].m6, 6 + a);
}

/**
 * Removes bridges from the given, that is bridges along the X and Y axis.
 * @param t the tile to remove the bridge from
 * @pre MayHaveBridgeAbove(t)
 */
static inline void ClearBridgeMiddle(TileIndex t)
{
	ClearSingleBridgeMiddle(t, AXIS_X);
	ClearSingleBridgeMiddle(t, AXIS_Y);
}

/**
 * Set that there is a bridge over the given axis.
 * @param t the tile to add the bridge to
 * @param a the axis of the bridge to add
 * @pre MayHaveBridgeAbove(t)
 */
static inline void SetBridgeMiddle(TileIndex t, Axis a)
{
	assert(MayHaveBridgeAbove(t));
	SetBit(_m[t].m6, 6 + a);
}

/**
 * Generic part to make a bridge ramp for both roads and rails.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param bridgetype the type of bridge this bridge ramp belongs to
 * @param d          the direction this ramp must be facing
 * @param tt         the transport type of the bridge
 * @param rt         the road or rail type
 * @note this function should not be called directly.
 */
static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt)
{
	SetTileType(t, MP_TUNNELBRIDGE);
	SetTileOwner(t, o);
	_m[t].m2 = 0;
	_m[t].m3 = rt;
	_m[t].m4 = 0;
	_m[t].m5 = 1 << 7 | tt << 2 | d;
	SB(_m[t].m6, 2, 4, bridgetype);
	_me[t].m7 = 0;
}

/**
 * Make a bridge ramp for roads.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param bridgetype the type of bridge this bridge ramp belongs to
 * @param d          the direction this ramp must be facing
 * @param r          the road type of the bridge
 */
static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RoadTypes r)
{
	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0);
	SetRoadOwner(t, ROADTYPE_ROAD, o);
	if (o != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, o);
	SetRoadTypes(t, r);
}

/**
 * Make a bridge ramp for rails.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param bridgetype the type of bridge this bridge ramp belongs to
 * @param d          the direction this ramp must be facing
 * @param r          the rail type of the bridge
 */
static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r)
{
	MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r);
}

/**
 * Make a bridge ramp for aqueducts.
 * @param t          the tile to make a bridge ramp
 * @param o          the new owner of the bridge ramp
 * @param d          the direction this ramp must be facing
 */
static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d)
{
	MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0);
}

#endif /* BRIDGE_MAP_H */