summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-15 07:10:41 +0000
committertron <tron@openttd.org>2006-03-15 07:10:41 +0000
commitc515c34008f458df019230461d1cee38f39b97b5 (patch)
treec4c8fbce340b1303c9e47db7434fd1b78a01c132
parent3fd42fab5db59e2d76470f8dce6b0f6238a98501 (diff)
downloadopenttd-c515c34008f458df019230461d1cee38f39b97b5.tar.xz
(svn r3877) Add functions to turn a tile into a rail/road bridge ramp/middle part
-rw-r--r--bridge_map.h47
-rw-r--r--direction.h10
-rw-r--r--tunnelbridge_cmd.c39
3 files changed, 73 insertions, 23 deletions
diff --git a/bridge_map.h b/bridge_map.h
index f1e12db59..6b2c92cdf 100644
--- a/bridge_map.h
+++ b/bridge_map.h
@@ -47,4 +47,51 @@ static inline void SetRoadUnderBridge(TileIndex t, Owner o)
SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
}
+
+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;
+}
+
+
+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
diff --git a/direction.h b/direction.h
index 8f29bdd6c..c7a8498f6 100644
--- a/direction.h
+++ b/direction.h
@@ -102,4 +102,14 @@ static inline Axis DiagDirToAxis(DiagDirection d)
return (Axis)(d & 1);
}
+
+/*
+ * Converts an Axis to a DiagDirection
+ * Points always in the positive direction, i.e. S[EW]
+ */
+static inline DiagDirection AxisToDiagDir(Axis a)
+{
+ return (DiagDirection)(2 - a);
+}
+
#endif
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 795c59477..85eb50d62 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -309,23 +309,17 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* do the drill? */
if (flags & DC_EXEC) {
- /* build the start tile */
- ModifyTile(ti_start.tile,
- MP_SETTYPE(MP_TUNNELBRIDGE) |
- MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
- (bridge_type << 4), /* map2 */
- railtype, /* map3_lo */
- 0x80 | direction | transport << 1 /* map5 */
- );
-
- /* build the end tile */
- ModifyTile(ti_end.tile,
- MP_SETTYPE(MP_TUNNELBRIDGE) |
- MP_MAP2 | MP_MAP3LO | MP_MAPOWNER_CURRENT | MP_MAP5,
- (bridge_type << 4), /* map2 */
- railtype, /* map3_lo */
- 0x80 | 0x20 | direction | transport << 1 /* map5 */
- );
+ DiagDirection dir = AxisToDiagDir(direction);
+
+ if (transport == TRANSPORT_RAIL) {
+ MakeRailBridgeRamp(ti_start.tile, _current_player, bridge_type, dir, railtype);
+ MakeRailBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir), railtype);
+ } else {
+ MakeRoadBridgeRamp(ti_start.tile, _current_player, bridge_type, dir);
+ MakeRoadBridgeRamp(ti_end.tile, _current_player, bridge_type, ReverseDiagDir(dir));
+ }
+ MarkTileDirtyByTile(ti_start.tile);
+ MarkTileDirtyByTile(ti_end.tile);
}
// position of middle part of the odd bridge (larger than MAX(i) otherwise)
@@ -380,12 +374,9 @@ not_valid_below:;
break;
}
- /* do middle part of bridge */
if (flags & DC_EXEC) {
uint piece;
- SetTileType(tile, MP_TUNNELBRIDGE);
-
//bridges pieces sequence (middle parts)
// bridge len 1: 0
// bridge len 2: 0 1
@@ -411,9 +402,11 @@ not_valid_below:;
piece = 2 + ((i % 2 == 0) ^ (i > odd_middle_part));
}
- _m[tile].m2 = (bridge_type << 4) | piece;
- SB(_m[tile].m3, 4, 4, railtype);
- _m[tile].m5 = 0xC0 | transport << 1 | direction;
+ if (transport == TRANSPORT_RAIL) {
+ MakeRailBridgeMiddle(tile, bridge_type, piece, direction, railtype);
+ } else {
+ MakeRoadBridgeMiddle(tile, bridge_type, piece, direction);
+ }
switch (transport_under) {
case TRANSPORT_RAIL: SetRailUnderBridge(tile, owner_under, rail_under); break;
case TRANSPORT_ROAD: SetRoadUnderBridge(tile, owner_under); break;