summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-03-13 12:55:20 +0000
committertron <tron@openttd.org>2006-03-13 12:55:20 +0000
commit26815f74051f7f6e6053b63ccf4f08cbadfa7847 (patch)
treebaf83f0489b844b1906cfa75044bb1f224a71618
parent3e932a0a4fbe5f38b4d946fc6e58aef896fd118f (diff)
downloadopenttd-26815f74051f7f6e6053b63ccf4f08cbadfa7847.tar.xz
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
-rw-r--r--bridge_map.h37
-rw-r--r--rail_cmd.c10
-rw-r--r--road_cmd.c10
-rw-r--r--tunnelbridge_cmd.c22
-rw-r--r--water_cmd.c21
5 files changed, 67 insertions, 33 deletions
diff --git a/bridge_map.h b/bridge_map.h
new file mode 100644
index 000000000..ba8e71d50
--- /dev/null
+++ b/bridge_map.h
@@ -0,0 +1,37 @@
+/* $Id$ */
+
+#ifndef BRIDGE_MAP_H
+#define BRIDGE_MAP_H
+
+#include "macros.h"
+#include "map.h"
+#include "rail.h"
+#include "tile.h"
+
+
+static inline void SetClearUnderBridge(TileIndex t)
+{
+ SetTileOwner(t, OWNER_NONE);
+ SB(_m[t].m5, 3, 3, 0 << 2 | 0);
+}
+
+static inline void SetWaterUnderBridge(TileIndex t)
+{
+ SetTileOwner(t, OWNER_WATER);
+ SB(_m[t].m5, 3, 3, 0 << 2 | 1);
+}
+
+static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
+{
+ SetTileOwner(t, o);
+ SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
+ SB(_m[t].m3, 0, 4, r);
+}
+
+static inline void SetRoadUnderBridge(TileIndex t, Owner o)
+{
+ SetTileOwner(t, o);
+ SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
+}
+
+#endif
diff --git a/rail_cmd.c b/rail_cmd.c
index 034a8ad10..73c687041 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -2,6 +2,7 @@
#include "stdafx.h"
#include "openttd.h"
+#include "bridge_map.h"
#include "debug.h"
#include "functions.h"
#include "rail_map.h"
@@ -299,11 +300,7 @@ int32 CmdBuildSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (CmdFailed(ret)) return ret;
cost += ret;
- if (flags & DC_EXEC) {
- SetTileOwner(tile, _current_player);
- SB(_m[tile].m3, 0, 4, p1);
- _m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge
- }
+ if (flags & DC_EXEC) SetRailUnderBridge(tile, _current_player, p1);
break;
case 0x20: // rail already there
@@ -426,8 +423,7 @@ int32 CmdRemoveSingleRail(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (!(flags & DC_EXEC))
return _price.remove_rail;
- SetTileOwner(tile, OWNER_NONE);
- _m[tile].m5 = _m[tile].m5 & 0xC7;
+ SetClearUnderBridge(tile);
break;
case MP_STREET: {
diff --git a/road_cmd.c b/road_cmd.c
index 55556553e..2b50cf6ff 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -2,6 +2,7 @@
#include "stdafx.h"
#include "openttd.h"
+#include "bridge_map.h"
#include "rail_map.h"
#include "road_map.h"
#include "table/sprites.h"
@@ -140,8 +141,7 @@ int32 CmdRemoveRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
- _m[tile].m5 = ti.map5 & 0xC7;
- SetTileOwner(tile, OWNER_NONE);
+ SetClearUnderBridge(tile);
MarkTileDirtyByTile(tile);
}
return cost;
@@ -375,10 +375,8 @@ int32 CmdBuildRoad(int x, int y, uint32 flags, uint32 p1, uint32 p2)
/* all checked, can build road now! */
cost = _price.build_road * 2;
if (flags & DC_EXEC) {
- ModifyTile(tile,
- MP_MAPOWNER_CURRENT | MP_MAP5,
- (ti.map5 & 0xC7) | 0x28 // map5
- );
+ SetRoadUnderBridge(tile, _current_player);
+ MarkTileDirtyByTile(tile);
}
return cost;
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 8e65f2248..219dc82d3 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -7,6 +7,7 @@
#include "stdafx.h"
#include "openttd.h"
+#include "bridge_map.h"
#include "rail_map.h"
#include "road_map.h"
#include "table/sprites.h"
@@ -334,6 +335,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
for (i = 0; i != bridge_len; i++) {
TransportType transport_under;
+ Owner owner_under = OWNER_NONE;
+ RailType rail_under = INVALID_RAILTYPE;
uint z;
tile += delta;
@@ -354,6 +357,8 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
goto not_valid_below;
}
transport_under = TRANSPORT_RAIL;
+ owner_under = GetTileOwner(tile);
+ rail_under = GB(_m[tile].m3, 0, 4);
break;
case MP_STREET:
@@ -362,6 +367,7 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2)
goto not_valid_below;
}
transport_under = TRANSPORT_ROAD;
+ owner_under = GetTileOwner(tile);
break;
default:
@@ -408,10 +414,10 @@ not_valid_below:;
_m[tile].m2 = (bridge_type << 4) | piece;
SB(_m[tile].m3, 4, 4, railtype);
switch (transport_under) {
- case TRANSPORT_RAIL: _m[tile].m5 = 0xE0 | TRANSPORT_RAIL << 3 | transport << 1 | direction; break; // rail
- case TRANSPORT_ROAD: _m[tile].m5 = 0xE0 | TRANSPORT_ROAD << 3 | transport << 1 | direction; break; // road
- case TRANSPORT_WATER: _m[tile].m5 = 0xC0 | 1 << 3 | transport << 1 | direction; break; // water
- default: _m[tile].m5 = 0xC0 | 0 << 3 | transport << 1 | direction; break; // grass
+ case TRANSPORT_RAIL: SetRailUnderBridge(tile, owner_under, rail_under); break;
+ case TRANSPORT_ROAD: SetRoadUnderBridge(tile, owner_under); break;
+ case TRANSPORT_WATER: SetWaterUnderBridge(tile); break;
+ default: SetClearUnderBridge(tile); break;
}
MarkTileDirtyByTile(tile);
@@ -644,8 +650,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail;
if (flags & DC_EXEC) {
- _m[tile].m5 = _m[tile].m5 & ~0x38;
- SetTileOwner(tile, OWNER_NONE);
+ SetClearUnderBridge(tile);
MarkTileDirtyByTile(tile);
}
return cost;
@@ -658,8 +663,7 @@ static int32 DoClearBridge(TileIndex tile, uint32 flags)
if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
cost = _price.clear_water;
if (flags & DC_EXEC) {
- _m[tile].m5 = _m[tile].m5 & ~0x38;
- SetTileOwner(tile, OWNER_NONE);
+ SetClearUnderBridge(tile);
MarkTileDirtyByTile(tile);
}
return cost;
@@ -1355,7 +1359,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, PlayerID old_player, Pl
// the stuff BELOW the middle part is owned by the deleted player.
if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) {
// convert railway into grass.
- _m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
+ SetClearUnderBridge(tile);
} else {
// for road, change the owner of the road to local authority
SetTileOwner(tile, OWNER_NONE);
diff --git a/water_cmd.c b/water_cmd.c
index 24a08db03..23bd8b537 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -2,6 +2,7 @@
#include "stdafx.h"
#include "openttd.h"
+#include "bridge_map.h"
#include "table/sprites.h"
#include "table/strings.h"
#include "functions.h"
@@ -248,10 +249,7 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return_cmd_error(STR_1007_ALREADY_BUILT);
}
- if (flags & DC_EXEC) {
- // change owner to OWNER_WATER and set land under bridge bit to water
- ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
- }
+ if (flags & DC_EXEC) SetWaterUnderBridge(tile);
} else {
/* no bridge, try to clear it. */
int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
@@ -259,13 +257,13 @@ int32 CmdBuildCanal(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (CmdFailed(ret)) return ret;
cost += ret;
- if (flags & DC_EXEC) {
- MakeWater(tile);
- MarkTileDirtyByTile(tile);
- }
+ if (flags & DC_EXEC) MakeWater(tile);
}
- if (flags & DC_EXEC) MarkTilesAroundDirty(tile);
+ if (flags & DC_EXEC) {
+ MarkTileDirtyByTile(tile);
+ MarkTilesAroundDirty(tile);
+ }
cost += _price.clear_water;
} END_TILE_LOOP(tile, size_x, size_y, 0);
@@ -546,7 +544,7 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
case MP_TUNNELBRIDGE:
// Middle part of bridge with clear land below?
if ((_m[target].m5 & 0xF8) == 0xC0) {
- _m[target].m5 |= 0x08;
+ SetWaterUnderBridge(target);
MarkTileDirtyByTile(target);
}
break;
@@ -560,7 +558,8 @@ static void TileLoopWaterHelper(TileIndex tile, const TileIndexDiffC *offs)
if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0) return;
if ((m5 & 0xC0) == 0xC0) {
- ModifyTile(target, MP_MAPOWNER | MP_MAP5, OWNER_WATER, (m5 & ~0x38) | 0x8);
+ SetWaterUnderBridge(target);
+ MarkTileDirtyByTile(target);
return;
}
}