summaryrefslogtreecommitdiff
path: root/bridge_map.h
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-07 19:35:21 +0000
committertron <tron@openttd.org>2006-06-07 19:35:21 +0000
commitbe88e269b918b365695e84cfa962e8d21b98e759 (patch)
tree5a6fb4aa93546ad194301d231de10ba5370ccc6f /bridge_map.h
parentace071529e2116f92aeec50d3bac0f95953b129b (diff)
downloadopenttd-be88e269b918b365695e84cfa962e8d21b98e759.tar.xz
(svn r5155) - Remove the bridge branch merge (revision r5070)
Diffstat (limited to 'bridge_map.h')
-rw-r--r--bridge_map.h154
1 files changed, 108 insertions, 46 deletions
diff --git a/bridge_map.h b/bridge_map.h
index 40113471b..525547e0f 100644
--- a/bridge_map.h
+++ b/bridge_map.h
@@ -11,9 +11,6 @@
#include "tile.h"
-void DrawBridgeMiddle(const TileInfo* ti); // XXX
-
-
static inline bool IsBridge(TileIndex t)
{
assert(IsTileType(t, MP_TUNNELBRIDGE));
@@ -26,38 +23,28 @@ static inline bool IsBridgeTile(TileIndex t)
}
-static inline bool MayHaveBridgeAbove(TileIndex t)
+static inline bool IsBridgeRamp(TileIndex t)
{
- return
- IsTileType(t, MP_CLEAR) ||
- IsTileType(t, MP_RAILWAY) ||
- IsTileType(t, MP_STREET) ||
- IsTileType(t, MP_WATER) ||
- IsTileType(t, MP_TUNNELBRIDGE);
+ assert(IsBridgeTile(t));
+ return !HASBIT(_m[t].m5, 6);
}
-
-static inline bool IsXBridgeAbove(TileIndex t)
+static inline bool IsBridgeMiddle(TileIndex t)
{
- assert(MayHaveBridgeAbove(t));
- return GB(_m[t].extra, 6, 1) != 0;
+ assert(IsBridgeTile(t));
+ return HASBIT(_m[t].m5, 6);
}
-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);
-}
-
-static inline bool IsBridgeAbove(TileIndex 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)
{
- return (IsXBridgeAbove(t) || IsYBridgeAbove(t));
+ assert(IsBridgeMiddle(t));
+ return GB(_m[t].m2, 0, 4);
}
@@ -78,15 +65,15 @@ static inline uint GetBridgeType(TileIndex t)
*/
static inline DiagDirection GetBridgeRampDirection(TileIndex t)
{
+ assert(IsBridgeRamp(t));
return ReverseDiagDir(XYNSToDiagDir((Axis)GB(_m[t].m5, 0, 1), GB(_m[t].m5, 5, 1)));
}
static inline Axis GetBridgeAxis(TileIndex t)
{
- static const Axis BridgeAxis[] = {AXIS_END, AXIS_X, AXIS_Y, AXIS_END};
- assert(IsBridgeAbove(t));
- return BridgeAxis[GB(_m[t].extra, 6, 2)];
+ assert(IsBridgeMiddle(t));
+ return (Axis)GB(_m[t].m5, 0, 1);
}
@@ -97,17 +84,50 @@ 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);
@@ -118,26 +138,46 @@ TileIndex GetSouthernBridgeEnd(TileIndex t);
*/
TileIndex GetOtherBridgeEnd(TileIndex);
-uint GetBridgeHeight(TileIndex tile, Axis a);
-uint GetBridgeFoundation(Slope tileh, Axis axis);
+uint GetBridgeHeight(TileIndex t);
-static inline void ClearSingleBridgeMiddle(TileIndex t, Axis a)
+static inline void SetClearUnderBridge(TileIndex t)
{
- assert(MayHaveBridgeAbove(t));
- CLRBIT(_m[t].extra, 6 + a);
+ assert(IsBridgeMiddle(t));
+ SetTileOwner(t, OWNER_NONE);
+ SB(_m[t].m5, 3, 3, 0 << 2 | 0);
+ SB(_m[t].m3, 0, 4, 0);
}
+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 ClearBridgeMiddle(TileIndex t)
+static inline void SetCanalUnderBridge(TileIndex t, Owner o)
{
- ClearSingleBridgeMiddle(t, AXIS_X);
- ClearSingleBridgeMiddle(t, AXIS_Y);
+ assert(IsBridgeMiddle(t));
+ SetTileOwner(t, o);
+ 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)
+{
+ assert(IsBridgeMiddle(t));
+ SetTileOwner(t, o);
+ SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
+ SB(_m[t].m3, 0, 4, r);
}
-static inline void SetBridgeMiddle(TileIndex t, Axis a)
+static inline void SetRoadUnderBridge(TileIndex t, Owner o)
{
- assert(MayHaveBridgeAbove(t));
- SETBIT(_m[t].extra, 6 + a);
+ assert(IsBridgeMiddle(t));
+ SetTileOwner(t, o);
+ SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
+ SB(_m[t].m3, 0, 4, 0);
}
@@ -165,4 +205,26 @@ 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