Changeset - r8197:5f087672abf6
[Not reviewed]
master
0 6 0
smatz - 17 years ago 2008-01-04 19:45:29
smatz@openttd.org
(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
6 files changed with 27 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/npf.cpp
Show inline comments
 
@@ -538,7 +538,7 @@ static void NPFFollowTrack(AyStar* aysta
 
		/* 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
src/rail_cmd.cpp
Show inline comments
 
@@ -931,7 +931,7 @@ static bool CheckSignalAutoFill(TileInde
 

	
 
			/* 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 til
 
					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
 
{
 
	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;
 
	}
src/road_cmd.cpp
Show inline comments
 
@@ -133,8 +133,7 @@ CommandCost CmdRemoveRoad(TileIndex tile
 
		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
 

	
 
		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,
 
				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));
src/town_cmd.cpp
Show inline comments
 
@@ -1062,7 +1062,7 @@ static void GrowTownInTile(TileIndex *ti
 
		/* 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;
 
		}
src/train_cmd.cpp
Show inline comments
 
@@ -2851,11 +2851,7 @@ static void CheckTrainCollision(Vehicle 
 
	/* 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
 

	
src/tunnelbridge_map.h
Show inline comments
 
@@ -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 SetTunnelBridgeSnowOr
 
	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 */
0 comments (0 inline, 0 general)