summaryrefslogtreecommitdiff
path: root/bridge_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'bridge_map.h')
-rw-r--r--bridge_map.h146
1 files changed, 46 insertions, 100 deletions
diff --git a/bridge_map.h b/bridge_map.h
index f2b5d4ee4..9470204e0 100644
--- a/bridge_map.h
+++ b/bridge_map.h
@@ -11,6 +11,9 @@
#include "tile.h"
+void DrawBridgeMiddle(const TileInfo* ti); // XXX
+
+
static inline bool IsBridge(TileIndex t)
{
assert(IsTileType(t, MP_TUNNELBRIDGE));
@@ -23,28 +26,38 @@ static inline bool IsBridgeTile(TileIndex t)
}
-static inline bool IsBridgeRamp(TileIndex t)
+static inline bool MayHaveBridgeAbove(TileIndex t)
{
- assert(IsBridgeTile(t));
- return !HASBIT(_m[t].m5, 6);
+ return
+ IsTileType(t, MP_CLEAR) ||
+ IsTileType(t, MP_RAILWAY) ||
+ IsTileType(t, MP_STREET) ||
+ IsTileType(t, MP_WATER) ||
+ IsTileType(t, MP_TUNNELBRIDGE);
}
-static inline bool IsBridgeMiddle(TileIndex t)
+
+static inline bool IsXBridgeAbove(TileIndex t)
{
- assert(IsBridgeTile(t));
- return HASBIT(_m[t].m5, 6);
+ 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;
}
+static inline bool IsBridgeOfAxis(TileIndex t, Axis a)
+{
+ if (a == AXIS_X) return IsXBridgeAbove(t);
+ return IsYBridgeAbove(t);
+}
-/**
- * Determines which piece of a bridge is contained in the current tile
- * @param tile The tile to analyze
- * @return the piece
- */
-static inline uint GetBridgePiece(TileIndex t)
+static inline bool IsBridgeAbove(TileIndex t)
{
- assert(IsBridgeMiddle(t));
- return GB(_m[t].m2, 0, 4);
+ return (IsXBridgeAbove(t) || IsYBridgeAbove(t));
}
@@ -65,7 +78,6 @@ static inline uint GetBridgeType(TileIndex t)
*/
static inline DiagDirection GetBridgeRampDirection(TileIndex t)
{
- assert(IsBridgeRamp(t));
/* Heavy wizardry to convert the X/Y (bit 0) + N/S (bit 5) encoding of
* bridges to a DiagDirection
*/
@@ -75,8 +87,9 @@ static inline DiagDirection GetBridgeRampDirection(TileIndex t)
static inline Axis GetBridgeAxis(TileIndex t)
{
- assert(IsBridgeMiddle(t));
- return (Axis)GB(_m[t].m5, 0, 1);
+ static const Axis BridgeAxis[] = {AXIS_END, AXIS_X, AXIS_Y, AXIS_END};
+ assert(IsBridgeAbove(t));
+ return BridgeAxis[GB(_m[t].extra, 6, 2)];
}
@@ -87,50 +100,17 @@ static inline TransportType GetBridgeTransportType(TileIndex t)
}
-static inline bool IsClearUnderBridge(TileIndex t)
-{
- assert(IsBridgeMiddle(t));
- return GB(_m[t].m5, 3, 3) == 0;
-}
-
-static inline bool IsWaterUnderBridge(TileIndex t)
-{
- assert(IsBridgeMiddle(t));
- return GB(_m[t].m5, 3, 3) == 1;
-}
-
-
-static inline bool IsTransportUnderBridge(TileIndex t)
-{
- assert(IsBridgeMiddle(t));
- return HASBIT(_m[t].m5, 5);
-}
-
-static inline TransportType GetTransportTypeUnderBridge(TileIndex t)
-{
- assert(IsTransportUnderBridge(t));
- return (TransportType)GB(_m[t].m5, 3, 2);
-}
-
-static inline RoadBits GetRoadBitsUnderBridge(TileIndex t)
-{
- assert(GetTransportTypeUnderBridge(t) == TRANSPORT_ROAD);
- return GetBridgeAxis(t) == AXIS_X ? ROAD_Y : ROAD_X;
-}
-
-static inline TrackBits GetRailBitsUnderBridge(TileIndex t)
-{
- assert(GetTransportTypeUnderBridge(t) == TRANSPORT_RAIL);
- return GetBridgeAxis(t) == AXIS_X ? TRACK_BIT_Y : TRACK_BIT_X;
-}
-
-
/**
* Finds the end of a bridge in the specified direction starting at a middle tile
*/
TileIndex GetBridgeEnd(TileIndex, DiagDirection);
/**
+ * Finds the northern end of a bridge starting at a middle tile
+ */
+TileIndex GetNorthernBridgeEnd(TileIndex t);
+
+/**
* Finds the southern end of a bridge starting at a middle tile
*/
TileIndex GetSouthernBridgeEnd(TileIndex t);
@@ -141,38 +121,26 @@ TileIndex GetSouthernBridgeEnd(TileIndex t);
*/
TileIndex GetOtherBridgeEnd(TileIndex);
-uint GetBridgeHeight(TileIndex t);
+uint GetBridgeHeight(TileIndex tile, Axis a);
+uint GetBridgeFoundation(Slope tileh, Axis axis);
-static inline void SetClearUnderBridge(TileIndex t)
+static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
{
- assert(IsBridgeMiddle(t));
- SetTileOwner(t, OWNER_NONE);
- SB(_m[t].m5, 3, 3, 0 << 2 | 0);
- SB(_m[t].m3, 0, 4, 0);
+ assert(MayHaveBridgeAbove(t));
+ CLRBIT(_m[t].extra, 6 + a);
}
-static inline void SetWaterUnderBridge(TileIndex t)
-{
- assert(IsBridgeMiddle(t));
- SetTileOwner(t, OWNER_WATER);
- SB(_m[t].m5, 3, 3, 0 << 2 | 1);
- SB(_m[t].m3, 0, 4, 0);
-}
-static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
+static inline void ClearBridgeMiddle(TileIndex t)
{
- assert(IsBridgeMiddle(t));
- SetTileOwner(t, o);
- SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
- SB(_m[t].m3, 0, 4, r);
+ ClearSingleBridgeMiddle(t, AXIS_X);
+ ClearSingleBridgeMiddle(t, AXIS_Y);
}
-static inline void SetRoadUnderBridge(TileIndex t, Owner o)
+static inline void SetBridgeMiddle(TileIndex t, Axis a)
{
- assert(IsBridgeMiddle(t));
- SetTileOwner(t, o);
- SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
- SB(_m[t].m3, 0, 4, 0);
+ assert(MayHaveBridgeAbove(t));
+ SETBIT(_m[t].extra, 6 + a);
}
@@ -200,26 +168,4 @@ static inline void MakeRailBridgeRamp(TileIndex t, Owner o, uint bridgetype, Dia
}
-static inline void MakeBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, TransportType tt)
-{
- SetTileType(t, MP_TUNNELBRIDGE);
- SetTileOwner(t, OWNER_NONE);
- _m[t].m2 = bridgetype << 4 | piece;
- _m[t].m3 = 0;
- _m[t].m4 = 0;
- _m[t].m5 = 1 << 7 | 1 << 6 | 0 << 5 | 0 << 3 | tt << 1 | a;
-}
-
-static inline void MakeRoadBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a)
-{
- MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_ROAD);
-}
-
-static inline void MakeRailBridgeMiddle(TileIndex t, uint bridgetype, uint piece, Axis a, RailType r)
-{
- MakeBridgeMiddle(t, bridgetype, piece, a, TRANSPORT_RAIL);
- SB(_m[t].m3, 4, 4, r);
-}
-
-
#endif