2006-03-13 12:55:20 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
#ifndef BRIDGE_MAP_H
|
|
|
|
#define BRIDGE_MAP_H
|
|
|
|
|
2006-03-14 12:00:11 +00:00
|
|
|
#include "direction.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "macros.h"
|
|
|
|
#include "map.h"
|
|
|
|
#include "rail.h"
|
2006-03-16 15:16:27 +00:00
|
|
|
#include "road_map.h"
|
2006-03-13 12:55:20 +00:00
|
|
|
#include "tile.h"
|
|
|
|
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
void DrawBridgeMiddle(const TileInfo* ti); // XXX
|
|
|
|
|
|
|
|
|
2006-03-16 15:16:27 +00:00
|
|
|
static inline bool IsBridge(TileIndex t)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsTileType(t, MP_TUNNELBRIDGE));
|
2006-03-16 15:16:27 +00:00
|
|
|
return HASBIT(_m[t].m5, 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsBridgeTile(TileIndex t)
|
|
|
|
{
|
|
|
|
return IsTileType(t, MP_TUNNELBRIDGE) && IsBridge(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline bool MayHaveBridgeAbove(TileIndex t)
|
2006-03-15 16:44:50 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
return
|
|
|
|
IsTileType(t, MP_CLEAR) ||
|
|
|
|
IsTileType(t, MP_RAILWAY) ||
|
|
|
|
IsTileType(t, MP_STREET) ||
|
|
|
|
IsTileType(t, MP_WATER) ||
|
|
|
|
IsTileType(t, MP_TUNNELBRIDGE);
|
2006-03-15 16:44:50 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
|
|
|
|
static inline bool IsXBridgeAbove(TileIndex t)
|
2006-03-16 05:28:15 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
|
|
|
return GB(_m[t].extra, 6, 1) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsYBridgeAbove(TileIndex t)
|
|
|
|
{
|
|
|
|
assert(MayHaveBridgeAbove(t));
|
|
|
|
return GB(_m[t].extra, 7, 1) != 0;
|
2006-03-16 05:28:15 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline bool IsBridgeOfAxis(TileIndex t, Axis a)
|
|
|
|
{
|
|
|
|
if (a == AXIS_X) return IsXBridgeAbove(t);
|
|
|
|
return IsYBridgeAbove(t);
|
|
|
|
}
|
2006-03-16 05:28:15 +00:00
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline bool IsBridgeAbove(TileIndex t)
|
2006-03-16 10:00:50 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
return (IsXBridgeAbove(t) || IsYBridgeAbove(t));
|
2006-03-16 10:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines the type of bridge on a tile
|
|
|
|
* @param tile The tile to analyze
|
|
|
|
* @return The bridge type
|
|
|
|
*/
|
2006-03-30 09:29:01 +00:00
|
|
|
static inline uint GetBridgeType(TileIndex t)
|
2006-03-16 10:00:50 +00:00
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsBridgeTile(t));
|
|
|
|
return GB(_m[t].m2, 4, 4);
|
2006-03-16 10:00:50 +00:00
|
|
|
}
|
|
|
|
|
2006-03-15 16:44:50 +00:00
|
|
|
|
2006-03-14 12:00:11 +00:00
|
|
|
/**
|
|
|
|
* Get the direction pointing onto the bridge
|
|
|
|
*/
|
|
|
|
static inline DiagDirection GetBridgeRampDirection(TileIndex t)
|
|
|
|
{
|
|
|
|
/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
|
|
|
|
* bridges to a DiagDirection
|
|
|
|
*/
|
|
|
|
return (DiagDirection)((6 - (_m[t].m5 >> 4 & 2) - (_m[t].m5 & 1)) % 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-16 05:28:15 +00:00
|
|
|
static inline Axis GetBridgeAxis(TileIndex t)
|
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
static const Axis BridgeAxis[] = {AXIS_END, AXIS_X, AXIS_Y, AXIS_END};
|
|
|
|
assert(IsBridgeAbove(t));
|
|
|
|
return BridgeAxis[GB(_m[t].extra, 6, 2)];
|
2006-03-16 05:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-16 15:16:27 +00:00
|
|
|
static inline TransportType GetBridgeTransportType(TileIndex t)
|
|
|
|
{
|
2006-03-30 09:29:01 +00:00
|
|
|
assert(IsBridgeTile(t));
|
2006-03-16 15:16:27 +00:00
|
|
|
return (TransportType)GB(_m[t].m5, 1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-16 05:28:15 +00:00
|
|
|
/**
|
|
|
|
* Finds the end of a bridge in the specified direction starting at a middle tile
|
|
|
|
*/
|
|
|
|
TileIndex GetBridgeEnd(TileIndex, DiagDirection);
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
/**
|
|
|
|
* Finds the northern end of a bridge starting at a middle tile
|
|
|
|
*/
|
|
|
|
TileIndex GetNorthernBridgeEnd(TileIndex t);
|
|
|
|
|
2006-03-16 05:28:15 +00:00
|
|
|
/**
|
|
|
|
* Finds the southern end of a bridge starting at a middle tile
|
|
|
|
*/
|
|
|
|
TileIndex GetSouthernBridgeEnd(TileIndex t);
|
|
|
|
|
|
|
|
|
2006-03-15 16:44:50 +00:00
|
|
|
/**
|
|
|
|
* Starting at one bridge end finds the other bridge end
|
|
|
|
*/
|
|
|
|
TileIndex GetOtherBridgeEnd(TileIndex);
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
uint GetBridgeHeight(TileIndex tile, Axis a);
|
|
|
|
uint GetBridgeFoundation(Slope tileh, Axis axis);
|
2006-03-15 16:44:50 +00:00
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
|
2006-03-13 12:55:20 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
|
|
|
CLRBIT(_m[t].extra, 6 + a);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline void ClearBridgeMiddle(TileIndex t)
|
2006-03-13 12:55:20 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
ClearSingleBridgeMiddle(t, AXIS_X);
|
|
|
|
ClearSingleBridgeMiddle(t, AXIS_Y);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
2006-06-02 13:05:41 +00:00
|
|
|
static inline void SetBridgeMiddle(TileIndex t, Axis a)
|
2006-03-13 12:55:20 +00:00
|
|
|
{
|
2006-06-02 13:05:41 +00:00
|
|
|
assert(MayHaveBridgeAbove(t));
|
|
|
|
SETBIT(_m[t].extra, 6 + a);
|
2006-03-13 12:55:20 +00:00
|
|
|
}
|
|
|
|
|
2006-03-15 07:10:41 +00:00
|
|
|
|
|
|
|
static inline void MakeBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, TransportType tt)
|
|
|
|
{
|
|
|
|
uint northsouth = (d == DIAGDIR_NE || d == DIAGDIR_NW);
|
|
|
|
|
|
|
|
SetTileType(t, MP_TUNNELBRIDGE);
|
|
|
|
SetTileOwner(t, o);
|
|
|
|
_m[t].m2 = bridgetype << 4;
|
|
|
|
_m[t].m4 = 0;
|
|
|
|
_m[t].m5 = 1 << 7 | 0 << 6 | northsouth << 5 | tt << 1 | DiagDirToAxis(d);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d)
|
|
|
|
{
|
|
|
|
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD);
|
|
|
|
_m[t].m3 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, DiagDirection d, RailType r)
|
|
|
|
{
|
|
|
|
MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL);
|
|
|
|
_m[t].m3 = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-13 12:55:20 +00:00
|
|
|
#endif
|