Changeset - r14695:1c04f0d9ca0f
[Not reviewed]
master
0 1 0
alberth - 15 years ago 2010-02-28 10:47:46
alberth@openttd.org
(svn r19289) -Codechange: Move _error_message assignment from check routine to caller.
1 file changed with 17 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/vehicle.cpp
Show inline comments
 
@@ -400,47 +400,59 @@ static Vehicle *EnsureNoVehicleProcZ(Veh
 
{
 
	byte z = *(byte*)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;
 
}
 

	
 
/* Ensure there is no vehicle at the ground at the given position.
 
 * @param tile Position to examine.
 
 * @return A vehicle has been found.
 
 */
 
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 */
 
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;
 
}
 

	
 
/**
 
 * Finds vehicle in tunnel / bridge
 
 * @param tile first end
 
 * @param endtile second end
 
 * @param ignore Ignore this vehicle when searching
 
 * @return true if the bridge has a vehicle
 
 */
 
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;
 
}
 

	
 

	
 
static void UpdateNewVehiclePosHash(Vehicle *v, bool remove)
 
{
 
	Vehicle **old_hash = v->old_new_hash;
0 comments (0 inline, 0 general)