From 993d82b8798a70cdf77141780150a9b1c6bb45bd Mon Sep 17 00:00:00 2001 From: alberth Date: Sun, 28 Feb 2010 10:47:46 +0000 Subject: [PATCH] (svn r19289) -Codechange: Move _error_message assignment from check routine to caller. --- src/vehicle.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e061373428..1a72220a85 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -403,7 +403,6 @@ static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) if (v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW)) return NULL; if (v->z_pos > z) return NULL; - _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; return v; } @@ -414,7 +413,14 @@ static Vehicle *EnsureNoVehicleProcZ(Vehicle *v, void *data) bool EnsureNoVehicleOnGround(TileIndex tile) { byte z = GetTileMaxZ(tile); - return !HasVehicleOnPos(tile, &z, &EnsureNoVehicleProcZ); + + /* 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). + * Such a message does not affect MP synchronisation. + */ + Vehicle *v = VehicleFromPos(tile, &z, &EnsureNoVehicleProcZ, true); + if (v != NULL) _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; + return v == NULL; } /** Procedure called for every vehicle found in tunnel/bridge in the hash map */ @@ -423,7 +429,6 @@ static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) if (v->type != VEH_TRAIN && v->type != VEH_ROAD && v->type != VEH_SHIP) return NULL; if (v == (const Vehicle *)data) return NULL; - _error_message = STR_ERROR_TRAIN_IN_THE_WAY + v->type; return v; } @@ -436,8 +441,15 @@ static Vehicle *GetVehicleTunnelBridgeProc(Vehicle *v, void *data) */ bool HasVehicleOnTunnelBridge(TileIndex tile, TileIndex endtile, const Vehicle *ignore) { - return HasVehicleOnPos(tile, (void *)ignore, &GetVehicleTunnelBridgeProc) || - HasVehicleOnPos(endtile, (void *)ignore, &GetVehicleTunnelBridgeProc); + /* 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). + * Such a message does not affect MP synchronisation. + */ + Vehicle *v = VehicleFromPos(tile, (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; + return v != NULL; }