mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r19291) -Codechange: Rename HasVehicleOnTunnelBridge() to TunnelBridgeIsFree() and return a CommandCost status.
This commit is contained in:
parent
986d15ef73
commit
63dd6ce6b0
|
@ -1466,7 +1466,7 @@ CommandCost CmdConvertRail(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
||||||
|
|
||||||
/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
|
/* When not coverting rail <-> el. rail, any vehicle cannot be in tunnel/bridge */
|
||||||
if (!IsCompatibleRail(GetRailType(tile), totype) &&
|
if (!IsCompatibleRail(GetRailType(tile), totype) &&
|
||||||
HasVehicleOnTunnelBridge(tile, endtile)) continue;
|
TunnelBridgeIsFree(tile, endtile).Failed()) continue;
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
|
Track track = DiagDirToDiagTrack(GetTunnelBridgeDirection(tile));
|
||||||
|
|
|
@ -192,10 +192,12 @@ static CommandCost RemoveRoad(TileIndex tile, DoCommandFlag flags, RoadBits piec
|
||||||
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE: {
|
||||||
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) return CMD_ERROR;
|
||||||
if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR;
|
CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile));
|
||||||
break;
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
} break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return CMD_ERROR;
|
return CMD_ERROR;
|
||||||
|
@ -573,13 +575,15 @@ CommandCost CmdBuildRoad(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
|
||||||
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case MP_TUNNELBRIDGE:
|
case MP_TUNNELBRIDGE: {
|
||||||
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) goto do_clear;
|
if (GetTunnelBridgeTransportType(tile) != TRANSPORT_ROAD) goto do_clear;
|
||||||
if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
|
if (MirrorRoadBits(DiagDirToRoadBits(GetTunnelBridgeDirection(tile))) != pieces) goto do_clear;
|
||||||
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
if (HasTileRoadType(tile, rt)) return_cmd_error(STR_ERROR_ALREADY_BUILT);
|
||||||
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
|
/* Don't allow adding roadtype to the bridge/tunnel when vehicles are already driving on it */
|
||||||
if (HasVehicleOnTunnelBridge(tile, GetOtherTunnelBridgeEnd(tile))) return CMD_ERROR;
|
CommandCost ret = TunnelBridgeIsFree(tile, GetOtherTunnelBridgeEnd(tile));
|
||||||
break;
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
do_clear:;
|
do_clear:;
|
||||||
|
|
|
@ -2342,7 +2342,7 @@ static void ClearPathReservation(const Train *v, TileIndex tile, Trackdir track_
|
||||||
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(dir)) {
|
if (GetTunnelBridgeDirection(tile) == ReverseDiagDir(dir)) {
|
||||||
TileIndex end = GetOtherTunnelBridgeEnd(tile);
|
TileIndex end = GetOtherTunnelBridgeEnd(tile);
|
||||||
|
|
||||||
if (!HasVehicleOnTunnelBridge(tile, end, v)) {
|
if (TunnelBridgeIsFree(tile, end, v).Succeeded()) {
|
||||||
/* Free the reservation only if no other train is on the tiles. */
|
/* Free the reservation only if no other train is on the tiles. */
|
||||||
SetTunnelBridgeReservation(tile, false);
|
SetTunnelBridgeReservation(tile, false);
|
||||||
SetTunnelBridgeReservation(end, false);
|
SetTunnelBridgeReservation(end, false);
|
||||||
|
|
|
@ -611,7 +611,9 @@ static CommandCost DoClearTunnel(TileIndex tile, DoCommandFlag flags)
|
||||||
|
|
||||||
endtile = GetOtherTunnelEnd(tile);
|
endtile = GetOtherTunnelEnd(tile);
|
||||||
|
|
||||||
if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
|
CommandCost ret = TunnelBridgeIsFree(tile, endtile);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
_build_tunnel_endtile = endtile;
|
_build_tunnel_endtile = endtile;
|
||||||
|
|
||||||
|
@ -676,7 +678,9 @@ static CommandCost DoClearBridge(TileIndex tile, DoCommandFlag flags)
|
||||||
|
|
||||||
endtile = GetOtherBridgeEnd(tile);
|
endtile = GetOtherBridgeEnd(tile);
|
||||||
|
|
||||||
if (HasVehicleOnTunnelBridge(tile, endtile)) return CMD_ERROR;
|
CommandCost ret = TunnelBridgeIsFree(tile, endtile);
|
||||||
|
ret.SetGlobalErrorMessage();
|
||||||
|
if (ret.Failed()) return ret;
|
||||||
|
|
||||||
direction = GetTunnelBridgeDirection(tile);
|
direction = GetTunnelBridgeDirection(tile);
|
||||||
delta = TileOffsByDiagDir(direction);
|
delta = TileOffsByDiagDir(direction);
|
||||||
|
|
|
@ -437,9 +437,9 @@ static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data)
|
||||||
* @param tile first end
|
* @param tile first end
|
||||||
* @param endtile second end
|
* @param endtile second end
|
||||||
* @param ignore Ignore this vehicle when searching
|
* @param ignore Ignore this vehicle when searching
|
||||||
* @return true if the bridge has a vehicle
|
* @return Succeeded command (if tunnel/bridge is free) or failed command (if a vehicle is using the tunnel/bridge).
|
||||||
*/
|
*/
|
||||||
bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
|
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore)
|
||||||
{
|
{
|
||||||
/* Value v is not safe in MP games, however, it is used to generate a local
|
/* Value v is not safe in MP games, however, it is used to generate a local
|
||||||
* error message only (which may be different for different machines).
|
* error message only (which may be different for different machines).
|
||||||
|
@ -448,8 +448,8 @@ bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *
|
||||||
Vehicle *v = VehicleFromPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc, true);
|
Vehicle *v = VehicleFromPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc, true);
|
||||||
if (v == NULL) v = VehicleFromPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc, true);
|
if (v == NULL) v = VehicleFromPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc, true);
|
||||||
|
|
||||||
if (v != NULL) _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type;
|
if (v != NULL) return_cmd_error(STR_ERROR_TRAIN_IN_THE_WAY + v->type);
|
||||||
return v != NULL;
|
return CommandCost();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ CommandCost RefitVehicle(Vehicle *v, bool only_this, CargoID new_cid, byte new_s
|
||||||
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
void ViewportAddVehicles(DrawPixelInfo *dpi);
|
||||||
|
|
||||||
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
|
void ShowNewGrfVehicleError(EngineID engine, StringID part1, StringID part2, GRFBugs bug_type, bool critical);
|
||||||
bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
|
CommandCost TunnelBridgeIsFree(TileIndex tile, TileIndex endtile, const Vehicle *ignore = NULL);
|
||||||
|
|
||||||
void DecreaseVehicleValue(Vehicle *v);
|
void DecreaseVehicleValue(Vehicle *v);
|
||||||
void CheckVehicleBreakdown(Vehicle *v);
|
void CheckVehicleBreakdown(Vehicle *v);
|
||||||
|
|
Loading…
Reference in New Issue