Changeset - r19467:47fa1346a132
[Not reviewed]
master
0 14 0
frosch - 12 years ago 2012-07-07 15:39:46
frosch@openttd.org
(svn r24384) -Fix [FS#5188-ish]: Make IsInDepot() functions behave consistent across vehicle types and add IsChainInDepot instead, if that is what shall be checked.
14 files changed with 55 insertions and 63 deletions:
0 comments (0 inline, 0 general)
src/aircraft.h
Show inline comments
 
@@ -78,7 +78,13 @@ struct Aircraft FINAL : public Specializ
 
	int GetSpeedOldUnits() const   { return this->vcache.cached_max_speed * 10 / 128; }
 
	int GetCurrentMaxSpeed() const { return this->GetSpeedOldUnits(); }
 
	Money GetRunningCost() const;
 
	bool IsInDepot() const { return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile); }
 

	
 
	bool IsInDepot() const
 
	{
 
		assert(this->IsPrimaryVehicle());
 
		return (this->vehstatus & VS_HIDDEN) != 0 && IsHangarTile(this->tile);
 
	}
 

	
 
	bool Tick();
 
	void OnNewDay();
 
	uint Crash(bool flooded = false);
src/aircraft_cmd.cpp
Show inline comments
 
@@ -365,7 +365,7 @@ bool Aircraft::FindClosestDepot(TileInde
 
static void CheckIfAircraftNeedsService(Aircraft *v)
 
{
 
	if (Company::Get(v->owner)->settings.vehicle.servint_aircraft == 0 || !v->NeedsAutomaticServicing()) return;
 
	if (v->IsInDepot()) {
 
	if (v->IsChainInDepot()) {
 
		VehicleServiceInDepot(v);
 
		return;
 
	}
src/autoreplace_cmd.cpp
Show inline comments
 
@@ -665,7 +665,7 @@ CommandCost CmdAutoreplaceVehicle(TileIn
 
	CommandCost ret = CheckOwnership(v->owner);
 
	if (ret.Failed()) return ret;
 

	
 
	if (!v->IsInDepot()) return CMD_ERROR;
 
	if (!v->IsChainInDepot()) return CMD_ERROR;
 
	if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
 

	
 
	bool free_wagon = false;
src/ground_vehicle.cpp
Show inline comments
 
@@ -12,6 +12,7 @@
 
#include "stdafx.h"
 
#include "train.h"
 
#include "roadveh.h"
 
#include "depot_map.h"
 

	
 
/**
 
 * Recalculates the cached total power of a vehicle. Should be called when the consist is changed.
 
@@ -164,6 +165,27 @@ int GroundVehicle<T, Type>::GetAccelerat
 
	}
 
}
 

	
 
/**
 
 * Check whether the whole vehicle chain is in the depot.
 
 * @return true if and only if the whole chain is in the depot.
 
 */
 
template <class T, VehicleType Type>
 
bool GroundVehicle<T, Type>::IsChainInDepot() const
 
{
 
	const T *v = this->First();
 
	/* Is the front engine stationary in the depot? */
 
	assert_compile((int)TRANSPORT_RAIL == (int)VEH_TRAIN);
 
	assert_compile((int)TRANSPORT_ROAD == (int)VEH_ROAD);
 
	if (!IsDepotTypeTile(v->tile, (TransportType)Type) || v->cur_speed != 0) return false;
 

	
 
	/* Check whether the rest is also already trying to enter the depot. */
 
	for (; v != NULL; v = v->Next()) {
 
		if (!v->T::IsInDepot() || v->tile != this->tile) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/* Instantiation for Train */
 
template struct GroundVehicle<Train, VEH_TRAIN>;
 
/* Instantiation for RoadVehicle */
src/ground_vehicle.hpp
Show inline comments
 
@@ -92,6 +92,7 @@ struct GroundVehicle : public Specialize
 
	void PowerChanged();
 
	void CargoChanged();
 
	int GetAcceleration() const;
 
	bool IsChainInDepot() const;
 

	
 
	/**
 
	 * Common code executed for crashed ground vehicles
src/roadveh.h
Show inline comments
 
@@ -113,7 +113,6 @@ struct RoadVehicle FINAL : public Ground
 
	Money GetRunningCost() const;
 
	int GetDisplayImageWidth(Point *offset = NULL) const;
 
	bool IsInDepot() const { return this->state == RVSB_IN_DEPOT; }
 
	bool IsStoppedInDepot() const;
 
	bool Tick();
 
	void OnNewDay();
 
	uint Crash(bool flooded = false);
src/roadveh_cmd.cpp
Show inline comments
 
@@ -306,19 +306,6 @@ CommandCost CmdBuildRoadVehicle(TileInde
 
	return CommandCost();
 
}
 

	
 
bool RoadVehicle::IsStoppedInDepot() const
 
{
 
	TileIndex tile = this->tile;
 

	
 
	if (!IsRoadDepotTile(tile)) return false;
 
	if (this->IsFrontEngine() && !(this->vehstatus & VS_STOPPED)) return false;
 

	
 
	for (const RoadVehicle *v = this; v != NULL; v = v->Next()) {
 
		if (v->state != RVSB_IN_DEPOT || v->tile != tile) return false;
 
	}
 
	return true;
 
}
 

	
 
static FindDepotData FindClosestRoadDepot(const RoadVehicle *v, int max_distance)
 
{
 
	if (IsRoadDepotTile(v->tile)) return FindDepotData(v->tile, 0);
 
@@ -1582,7 +1569,7 @@ static void CheckIfRoadVehNeedsService(R
 
{
 
	/* If we already got a slot at a stop, use that FIRST, and go to a depot later */
 
	if (Company::Get(v->owner)->settings.vehicle.servint_roadveh == 0 || !v->NeedsAutomaticServicing()) return;
 
	if (v->IsInDepot()) {
 
	if (v->IsChainInDepot()) {
 
		VehicleServiceInDepot(v);
 
		return;
 
	}
src/script/api/script_vehicle.cpp
Show inline comments
 
@@ -182,7 +182,7 @@
 
/* static */ bool ScriptVehicle::IsInDepot(VehicleID vehicle_id)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return false;
 
	return ::Vehicle::Get(vehicle_id)->IsInDepot();
 
	return ::Vehicle::Get(vehicle_id)->IsChainInDepot();
 
}
 

	
 
/* static */ bool ScriptVehicle::IsStoppedInDepot(VehicleID vehicle_id)
src/ship_cmd.cpp
Show inline comments
 
@@ -142,7 +142,7 @@ static const Depot *FindClosestShipDepot
 
static void CheckIfShipNeedsService(Vehicle *v)
 
{
 
	if (Company::Get(v->owner)->settings.vehicle.servint_ships == 0 || !v->NeedsAutomaticServicing()) return;
 
	if (v->IsInDepot()) {
 
	if (v->IsChainInDepot()) {
 
		VehicleServiceInDepot(v);
 
		return;
 
	}
 
@@ -298,7 +298,7 @@ static const TileIndexDiffC _ship_leave_
 

	
 
static bool CheckShipLeaveDepot(Ship *v)
 
{
 
	if (!v->IsInDepot()) return false;
 
	if (!v->IsChainInDepot()) return false;
 

	
 
	/* We are leaving a depot, but have to go to the exact same one; re-enter */
 
	if (v->current_order.IsType(OT_GOTO_DEPOT) &&
src/train.h
Show inline comments
 
@@ -101,8 +101,7 @@ struct Train FINAL : public GroundVehicl
 
	int GetDisplayMaxSpeed() const { return this->vcache.cached_max_speed; }
 
	Money GetRunningCost() const;
 
	int GetDisplayImageWidth(Point *offset = NULL) const;
 
	bool IsInDepot() const;
 
	bool IsStoppedInDepot() const;
 
	bool IsInDepot() const { return this->track == TRACK_BIT_DEPOT; }
 
	bool Tick();
 
	void OnNewDay();
 
	uint Crash(bool flooded = false);
src/train_cmd.cpp
Show inline comments
 
@@ -732,34 +732,6 @@ CommandCost CmdBuildRailVehicle(TileInde
 
	return CommandCost();
 
}
 

	
 
/**
 
 * Is the whole consist the in a depot?
 
 * @return \c true iff all vehicles of the train are in a depot.
 
 */
 
bool Train::IsInDepot() const
 
{
 
	/* Is the front engine stationary in the depot? */
 
	if (!IsRailDepotTile(this->tile) || this->cur_speed != 0) return false;
 

	
 
	/* Check whether the rest is also already trying to enter the depot. */
 
	for (const Train *v = this; v != NULL; v = v->Next()) {
 
		if (v->track != TRACK_BIT_DEPOT || v->tile != this->tile) return false;
 
	}
 

	
 
	return true;
 
}
 

	
 
/**
 
 * Is the train stopped in a depot?
 
 * @return True if the train is stopped in a depot, else false.
 
 */
 
bool Train::IsStoppedInDepot() const
 
{
 
	/* Are we stopped? Of course wagons don't really care... */
 
	if (this->IsFrontEngine() && !(this->vehstatus & VS_STOPPED)) return false;
 
	return this->IsInDepot();
 
}
 

	
 
static Train *FindGoodVehiclePos(const Train *src)
 
{
 
	EngineID eng = src->engine_type;
 
@@ -1946,7 +1918,7 @@ CommandCost CmdForceTrainProceed(TileInd
 
		 * to proceed to the next signal. In the other cases we
 
		 * would like to pass the signal at danger and run till the
 
		 * next signal we encounter. */
 
		t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsInDepot() ? TFP_STUCK : TFP_SIGNAL;
 
		t->force_proceed = t->force_proceed == TFP_SIGNAL ? TFP_NONE : HasBit(t->flags, VRF_TRAIN_STUCK) || t->IsChainInDepot() ? TFP_STUCK : TFP_SIGNAL;
 
		SetWindowDirty(WC_VEHICLE_VIEW, t->index);
 
	}
 

	
 
@@ -3897,7 +3869,7 @@ bool Train::Tick()
 
static void CheckIfTrainNeedsService(Train *v)
 
{
 
	if (Company::Get(v->owner)->settings.vehicle.servint_trains == 0 || !v->NeedsAutomaticServicing()) return;
 
	if (v->IsInDepot()) {
 
	if (v->IsChainInDepot()) {
 
		VehicleServiceInDepot(v);
 
		return;
 
	}
src/vehicle_base.h
Show inline comments
 
@@ -417,10 +417,22 @@ public:
 
	virtual bool IsInDepot() const { return false; }
 

	
 
	/**
 
	 * Check whether the whole vehicle chain is in the depot.
 
	 * @return true if and only if the whole chain is in the depot.
 
	 */
 
	virtual bool IsChainInDepot() const { return this->IsInDepot(); }
 

	
 
	/**
 
	 * Check whether the vehicle is in the depot *and* stopped.
 
	 * @return true if and only if the vehicle is in the depot and stopped.
 
	 */
 
	virtual bool IsStoppedInDepot() const { return this->IsInDepot() && (this->vehstatus & VS_STOPPED) != 0; }
 
	bool IsStoppedInDepot() const
 
	{
 
		assert(this == this->First());
 
		/* Free wagons have no VS_STOPPED state */
 
		if (this->IsPrimaryVehicle() && !(this->vehstatus & VS_STOPPED)) return false;
 
		return this->IsChainInDepot();
 
	}
 

	
 
	/**
 
	 * Calls the tick handler of the vehicle
src/vehicle_cmd.cpp
Show inline comments
 
@@ -601,13 +601,7 @@ CommandCost CmdMassStartStopVehicle(Tile
 

	
 
		if (!!(v->vehstatus & VS_STOPPED) != do_start) continue;
 

	
 
		if (!vehicle_list_window) {
 
			if (vli.vtype == VEH_TRAIN) {
 
				if (!Train::From(v)->IsInDepot()) continue;
 
			} else {
 
				if (!(v->vehstatus & VS_HIDDEN)) continue;
 
			}
 
		}
 
		if (!vehicle_list_window && !v->IsChainInDepot()) continue;
 

	
 
		/* Just try and don't care if some vehicle's can't be stopped. */
 
		DoCommand(tile, v->index, 0, flags, CMD_START_STOP_VEHICLE);
 
@@ -679,7 +673,7 @@ CommandCost CmdDepotMassAutoReplace(Tile
 
		const Vehicle *v = list[i];
 

	
 
		/* Ensure that the vehicle completely in the depot */
 
		if (!v->IsInDepot()) continue;
 
		if (!v->IsChainInDepot()) continue;
 

	
 
		CommandCost ret = DoCommand(0, v->index, 0, flags, CMD_AUTOREPLACE_VEHICLE);
 

	
src/vehicle_gui.cpp
Show inline comments
 
@@ -1292,7 +1292,7 @@ void BaseVehicleListWindow::DrawVehicleL
 

	
 
		if (show_orderlist) DrawSmallOrderList(v, orderlist_left, orderlist_right, y, v->cur_real_order_index);
 

	
 
		if (v->IsInDepot()) {
 
		if (v->IsChainInDepot()) {
 
			str = STR_BLUE_COMMA;
 
		} else {
 
			str = (v->age > v->max_age - DAYS_IN_LEAP_YEAR) ? STR_RED_COMMA : STR_BLACK_COMMA;
0 comments (0 inline, 0 general)