File diff r8082:9d654f9b59ea → r8083:8cd2123a0c7c
src/road_cmd.cpp
Show inline comments
 
@@ -31,12 +31,14 @@
 
#include "newgrf.h"
 
#include "station_map.h"
 
#include "tunnel_map.h"
 
#include "misc/autoptr.hpp"
 
#include "autoslope.h"
 
#include "transparency.h"
 
#include "tunnelbridge_map.h"
 

	
 

	
 
#define M(x) (1 << (x))
 
/* Level crossings may only be built on these slopes */
 
static const uint32 VALID_LEVEL_CROSSING_SLOPES = (M(SLOPE_SEN) | M(SLOPE_ENW) | M(SLOPE_NWS) | M(SLOPE_NS) | M(SLOPE_WSE) | M(SLOPE_EW) | M(SLOPE_FLAT));
 
#undef M
 

	
 
@@ -130,16 +132,16 @@ CommandCost CmdRemoveRoad(TileIndex tile
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			{
 
				TileIndex endtile;
 
				if (IsTunnel(tile)) {
 
					if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					endtile = GetOtherTunnelEnd(tile);
 
				} else {
 
					if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					endtile = GetOtherBridgeEnd(tile);
 
				}
 

	
 
				if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
 
			} break;
 

	
 
@@ -172,13 +174,13 @@ CommandCost CmdRemoveRoad(TileIndex tile
 
				SetRoadTypes(tile, GetRoadTypes(tile) & ~RoadTypeToRoadTypes(rt));
 

	
 
				/* Mark tiles diry that have been repaved */
 
				MarkTileDirtyByTile(tile);
 
				MarkTileDirtyByTile(other_end);
 
				if (IsBridge(tile)) {
 
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
 
					TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
 

	
 
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
 
				}
 
			}
 
		} else {
 
			cost.AddCost(_price.remove_road);
 
@@ -511,16 +513,16 @@ CommandCost CmdBuildRoad(TileIndex tile,
 
			break;
 

	
 
		case MP_TUNNELBRIDGE:
 
			{
 
				TileIndex endtile;
 
				if (IsTunnel(tile)) {
 
					if (GetTunnelTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					endtile = GetOtherTunnelEnd(tile);
 
				} else {
 
					if (GetBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
 
					endtile = GetOtherBridgeEnd(tile);
 
				}
 
				if (HasBit(GetRoadTypes(tile), rt)) return_cmd_error(STR_1007_ALREADY_BUILT);
 
				/* Don't allow "upgrading" the bridge/tunnel when vehicles are already driving on it */
 
				if (GetVehicleTunnelBridge(tile, endtile) != NULL) return CMD_ERROR;
 
			} break;
 
@@ -573,13 +575,13 @@ do_clear:;
 
				SetRoadTypes(tile, GetRoadTypes(tile) | RoadTypeToRoadTypes(rt));
 

	
 
				/* Mark tiles diry that have been repaved */
 
				MarkTileDirtyByTile(other_end);
 
				MarkTileDirtyByTile(tile);
 
				if (IsBridge(tile)) {
 
					TileIndexDiff delta = TileOffsByDiagDir(GetBridgeRampDirection(tile));
 
					TileIndexDiff delta = TileOffsByDiagDir(GetTunnelBridgeDirection(tile));
 

	
 
					for (TileIndex t = tile + delta; t != other_end; t += delta) MarkTileDirtyByTile(t);
 
				}
 
			} break;
 

	
 
			case MP_STATION:
 
@@ -688,18 +690,18 @@ CommandCost CmdBuildLongRoad(TileIndex e
 
			_error_message = INVALID_STRING_ID;
 
		} else {
 
			had_success = true;
 
			/* Only pay for the upgrade on one side of the bridges and tunnels */
 
			if (IsTileType(tile, MP_TUNNELBRIDGE)) {
 
				if (IsBridge(tile)) {
 
					if ((!had_bridge || GetBridgeRampDirection(tile) == DIAGDIR_SE || GetBridgeRampDirection(tile) == DIAGDIR_SW)) {
 
					if ((!had_bridge || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
 
						cost.AddCost(ret);
 
					}
 
					had_bridge = true;
 
				} else {
 
					if ((!had_tunnel || GetTunnelDirection(tile) == DIAGDIR_SE || GetTunnelDirection(tile) == DIAGDIR_SW)) {
 
					if ((!had_tunnel || GetTunnelBridgeDirection(tile) == DIAGDIR_SE || GetTunnelBridgeDirection(tile) == DIAGDIR_SW)) {
 
						cost.AddCost(ret);
 
					}
 
					had_tunnel = true;
 
				}
 
			} else {
 
				cost.AddCost(ret);