Changeset - r13938:79b6be1ab675
[Not reviewed]
master
0 2 0
rubidium - 14 years ago 2009-12-13 17:13:20
rubidium@openttd.org
(svn r18484) -Codechange: simplify the Is(Stopped)InDepot functions for trains
2 files changed with 17 insertions and 24 deletions:
0 comments (0 inline, 0 general)
src/train.h
Show inline comments
 
@@ -49,7 +49,6 @@ void CcBuildWagon(bool success, TileInde
 

	
 
byte FreightWagonMult(CargoID cargo);
 

	
 
int CheckTrainInDepot(const Train *v, bool needs_to_be_stopped);
 
void UpdateTrainAcceleration(Train *v);
 
void CheckTrainsLengths();
 

	
 
@@ -131,8 +130,8 @@ struct Train : public SpecializedVehicle
 
	int GetDisplayMaxSpeed() const { return this->tcache.cached_max_speed; }
 
	Money GetRunningCost() const;
 
	int GetDisplayImageWidth(Point *offset = NULL) const;
 
	bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
 
	bool IsStoppedInDepot() const { return CheckTrainInDepot(this, true) != -1; }
 
	bool IsInDepot() const;
 
	bool IsStoppedInDepot() const;
 
	bool Tick();
 
	void OnNewDay();
 
	uint Crash(bool flooded = false);
src/train_cmd.cpp
Show inline comments
 
@@ -954,30 +954,24 @@ CommandCost CmdBuildRailVehicle(TileInde
 
}
 

	
 

	
 
/* Check if all the wagons of the given train are in a depot, returns the
 
 * number of cars (including loco) then. If not it returns -1 */
 
int CheckTrainInDepot(const Train *v, bool needs_to_be_stopped)
 
bool Train::IsInDepot() const
 
{
 
	TileIndex tile = v->tile;
 

	
 
	/* check if stopped in a depot */
 
	if (!IsRailDepotTile(tile) || v->cur_speed != 0 ||
 
			(needs_to_be_stopped && v->IsFrontEngine() && !(v->vehstatus & VS_STOPPED))) {
 
		return -1;
 
	/* 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;
 
	}
 

	
 
	int count = 0;
 
	for (; v != NULL; v = v->Next()) {
 
		/* This count is used by the depot code to determine the number of engines
 
		 * in the consist. Exclude articulated parts so that autoreplacing to
 
		 * engines with more articulated parts than before works correctly.
 
		 *
 
		 * Also skip counting rear ends of multiheaded engines */
 
		if (!v->IsArticulatedPart() && !v->IsRearDualheaded()) count++;
 
		if (v->track != TRACK_BIT_DEPOT || v->tile != tile) return -1;
 
	}
 

	
 
	return count;
 
	return true;
 
}
 

	
 
bool Train::IsStoppedInDepot() const
 
{
 
	/* Are we stopped? Ofcourse wagons don't really care... */
 
	if (this->IsFrontEngine() && !(this->vehstatus & VS_STOPPED)) return false;
 
	return this->IsInDepot();
 
}
 

	
 
static Train *FindGoodVehiclePos(const Train *src)
0 comments (0 inline, 0 general)