(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
This commit is contained in:
smatz 2008-01-04 19:45:29 +00:00
parent 9299f76af4
commit 7302d8c88b
6 changed files with 27 additions and 21 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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));

View File

@ -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;
}

View File

@ -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

View File

@ -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 */