summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-02-28 10:47:46 +0000
committeralberth <alberth@openttd.org>2010-02-28 10:47:46 +0000
commit993d82b8798a70cdf77141780150a9b1c6bb45bd (patch)
treefa57a7729f9fa7dc6f673fecff9217bd8df8c56d
parent8408b42dee5ced6d121e0676e5b27b8419ef6804 (diff)
downloadopenttd-993d82b8798a70cdf77141780150a9b1c6bb45bd.tar.xz
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
-rw-r--r--src/vehicle.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index e06137342..1a72220a8 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;
}