summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmatz <smatz@openttd.org>2008-01-04 19:45:29 +0000
committersmatz <smatz@openttd.org>2008-01-04 19:45:29 +0000
commitf02cf9281bbbfd0118269dd8431263e2f95005a1 (patch)
tree9a2deee8e62f246ba97175135518232409950b73
parentaefb86d7feb69b6a484fd0adad92acc54101be09 (diff)
downloadopenttd-f02cf9281bbbfd0118269dd8431263e2f95005a1.tar.xz
(svn r11760) -Codechange: unify the way how other end of a tunnel/bridge is determined at some places
-Fix: adding road/tram to tram/road bridge was cheaper by one tile
-rw-r--r--src/npf.cpp2
-rw-r--r--src/rail_cmd.cpp7
-rw-r--r--src/road_cmd.cpp15
-rw-r--r--src/town_cmd.cpp2
-rw-r--r--src/train_cmd.cpp8
-rw-r--r--src/tunnelbridge_map.h14
6 files changed, 27 insertions, 21 deletions
diff --git a/src/npf.cpp b/src/npf.cpp
index a253fd757..a5d8c7146 100644
--- a/src/npf.cpp
+++ b/src/npf.cpp
@@ -538,7 +538,7 @@ static void NPFFollowTrack(AyStar* aystar, OpenListNode* current)
/* This is a tunnel/bridge. We know this tunnel/bridge is our type,
* otherwise we wouldn't have got here. It is also facing us,
* so we should skip it's body */
- dst_tile = IsTunnel(src_tile) ? GetOtherTunnelEnd(src_tile) : GetOtherBridgeEnd(src_tile);
+ dst_tile = GetOtherTunnelBridgeEnd(src_tile);
override_dst_check = true;
} else if (type != TRANSPORT_WATER && (IsStandardRoadStopTile(src_tile) || IsTileDepotType(src_tile, type))) {
/* This is a road station (non drive-through) or a train or road depot. We can enter and exit
diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp
index d550b311c..810329496 100644
--- a/src/rail_cmd.cpp
+++ b/src/rail_cmd.cpp
@@ -931,7 +931,7 @@ static bool CheckSignalAutoFill(TileIndex &tile, Trackdir &trackdir, int &signal
/* Skip to end of tunnel or bridge
* note that tile is a parameter by reference, so it must be updated */
- tile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
+ tile = GetOtherTunnelBridgeEnd(tile);
signal_ctr += 2 + DistanceMax(orig_tile, tile) * 2;
return true;
@@ -1262,7 +1262,7 @@ CommandCost CmdConvertRail(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
break;
case MP_TUNNELBRIDGE: {
- TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
+ TileIndex endtile = GetOtherTunnelBridgeEnd(tile);
/* If both ends of tunnel/bridge are in the range, do not try to convert twice -
* it would cause assert because of different test and exec runs */
@@ -1938,8 +1938,7 @@ static bool SignalVehicleCheck(TileIndex tile, uint track)
{
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
/* Locate vehicles in tunnels or on bridges */
- TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
- return GetVehicleTunnelBridge(tile, endtile) != NULL;
+ return GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL;
} else {
return VehicleFromPos(tile, &track, &SignalVehicleCheckProc) != NULL;
}
diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp
index 90afac8de..e4c7ad6c4 100644
--- a/src/road_cmd.cpp
+++ b/src/road_cmd.cpp
@@ -133,8 +133,7 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
case MP_TUNNELBRIDGE:
{
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
- TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
- if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
+ if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
} break;
default:
@@ -158,9 +157,9 @@ CommandCost CmdRemoveRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CommandCost cost;
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
- TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
+ TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
/* Pay for *every* tile of the bridge or tunnel */
- cost.AddCost((DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile) + 1) * _price.remove_road);
+ cost.AddCost((DistanceManhattan(other_end, tile) + 1) * _price.remove_road);
if (flags & DC_EXEC) {
SetRoadTypes(other_end, GetRoadTypes(other_end) & ~RoadTypeToRoadTypes(rt));
SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
@@ -509,10 +508,8 @@ CommandCost CmdBuildRoad(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
- TileIndex endtile = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
-
/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
- if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
+ if (GetVehicleTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile)) != NULL) return CMD_ERROR;
} break;
default:
@@ -541,7 +538,7 @@ do_clear:;
cost.AddCost(CountBits(pieces) * _price.build_road);
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
/* Pay for *every* tile of the bridge or tunnel */
- cost.MultiplyCost(DistanceManhattan(IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile), tile));
+ cost.MultiplyCost(DistanceManhattan(GetOtherTunnelBridgeEnd(tile), tile) + 1);
}
if (flags & DC_EXEC) {
@@ -557,7 +554,7 @@ do_clear:;
} break;
case MP_TUNNELBRIDGE: {
- TileIndex other_end = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
+ TileIndex other_end = GetOtherTunnelBridgeEnd(tile);
SetRoadTypes(other_end, GetRoadTypes(other_end) | RoadTypeToRoadTypes(rt));
SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 9abf01875..8d9e6863c 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1062,7 +1062,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t
/* Reached a tunnel/bridge? Then continue at the other side of it. */
if (IsTileType(tile, MP_TUNNELBRIDGE)) {
if (GetTunnelBridgeTransportType(tile) == TRANSPORT_ROAD) {
- *tile_ptr = IsTunnel(tile) ? GetOtherTunnelEnd(tile) : GetOtherBridgeEnd(tile);
+ *tile_ptr = GetOtherTunnelBridgeEnd(tile);
}
return;
}
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index 02fd41069..379c2343a 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -2851,11 +2851,7 @@ static void CheckTrainCollision(Vehicle *v)
/* find colliding vehicles */
if (v->u.rail.track == TRACK_BIT_WORMHOLE) {
VehicleFromPos(v->tile, &tcc, FindTrainCollideEnum);
- if (IsBridgeTile(v->tile)) {
- VehicleFromPos(GetOtherBridgeEnd(v->tile), &tcc, FindTrainCollideEnum);
- } else {
- VehicleFromPos(GetOtherTunnelEnd(v->tile), &tcc, FindTrainCollideEnum);
- }
+ VehicleFromPos(GetOtherTunnelBridgeEnd(v->tile), &tcc, FindTrainCollideEnum);
} else {
VehicleFromPosXY(v->x_pos, v->y_pos, &tcc, FindTrainCollideEnum);
}
@@ -3130,7 +3126,7 @@ static void DeleteLastWagon(Vehicle *v)
DisableTrainCrossing(v->tile);
if (v->u.rail.track == TRACK_BIT_WORMHOLE) { // inside a tunnel / bridge
- TileIndex endtile = IsTunnel(v->tile) ? GetOtherTunnelEnd(v->tile) : GetOtherBridgeEnd(v->tile);
+ TileIndex endtile = GetOtherTunnelBridgeEnd(v->tile);
if (GetVehicleTunnelBridge(v->tile, endtile) != NULL) return; // tunnel / bridge is busy
diff --git a/src/tunnelbridge_map.h b/src/tunnelbridge_map.h
index e9cbe0945..47266442f 100644
--- a/src/tunnelbridge_map.h
+++ b/src/tunnelbridge_map.h
@@ -8,6 +8,8 @@
#include "direction_func.h"
#include "core/bitmath_func.hpp"
#include "tile_map.h"
+#include "bridge_map.h"
+#include "tunnel_map.h"
/**
@@ -63,4 +65,16 @@ static inline void SetTunnelBridgeSnowOrDesert(TileIndex t, bool snow_or_desert)
SB(_m[t].m4, 7, 1, snow_or_desert);
}
+/**
+ * Determines type of the wormhole and returns its other end
+ * @param t one end
+ * @pre IsTileType(t, MP_TUNNELBRIDGE)
+ * @return other end
+ */
+static inline TileIndex GetOtherTunnelBridgeEnd(TileIndex t)
+{
+ assert(IsTileType(t, MP_TUNNELBRIDGE));
+ return IsTunnel(t) ? GetOtherTunnelEnd(t) : GetOtherBridgeEnd(t);
+}
+
#endif /* TUNNELBRIDGE_MAP_H */