Changeset - r9990:11fe53c71e1b
[Not reviewed]
master
0 1 0
frosch - 16 years ago 2008-08-23 22:31:36
frosch@openttd.org
(svn r14147) -Codechange: Allow passing 'const Vehicle *' to GetNextUnit() and GetPrevUnit().
1 file changed with 8 insertions and 8 deletions:
0 comments (0 inline, 0 general)
src/train.h
Show inline comments
 
@@ -220,116 +220,116 @@ static inline Vehicle *GetNextArticPart(
 
static inline Vehicle *GetLastEnginePart(Vehicle *v)
 
{
 
	assert(v->type == VEH_TRAIN);
 
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
 
	return v;
 
}
 

	
 
/** Tell if we are dealing with the rear end of a multiheaded engine.
 
 * @param v Vehicle.
 
 * @return True if the engine is the rear part of a dualheaded engine.
 
 */
 
static inline bool IsRearDualheaded(const Vehicle *v)
 
{
 
	assert(v->type == VEH_TRAIN);
 
	return (IsMultiheaded(v) && !IsTrainEngine(v));
 
}
 

	
 
/** Get the next real (non-articulated part) vehicle in the consist.
 
 * @param v Vehicle.
 
 * @return Next vehicle in the consist.
 
 */
 
static inline Vehicle *GetNextVehicle(const Vehicle *v)
 
{
 
	assert(v->type == VEH_TRAIN);
 
	while (EngineHasArticPart(v)) v = GetNextArticPart(v);
 

	
 
	/* v now contains the last artic part in the engine */
 
	return v->Next();
 
}
 

	
 
/** Get the previous real (non-articulated part) vehicle in the consist.
 
 * @param w Vehicle.
 
 * @return Previous vehicle in the consist.
 
 */
 
static inline Vehicle *GetPrevVehicle(const Vehicle *w)
 
{
 
	assert(w->type == VEH_TRAIN);
 

	
 
	Vehicle *v = w->Previous();
 
	while (v != NULL && IsArticulatedPart(v)) v = v->Previous();
 

	
 
	return v;
 
}
 

	
 
/** Get the next real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
 
 * @param v Vehicle.
 
 * @return Next vehicle in the consist.
 
 */
 
static inline Vehicle *GetNextUnit(Vehicle *v)
 
static inline Vehicle *GetNextUnit(const Vehicle *v)
 
{
 
	assert(v->type == VEH_TRAIN);
 
	v = GetNextVehicle(v);
 
	if (v != NULL && IsRearDualheaded(v)) v = GetNextVehicle(v);
 
	Vehicle *w = GetNextVehicle(v);
 
	if (w != NULL && IsRearDualheaded(w)) w = GetNextVehicle(w);
 

	
 
	return v;
 
	return w;
 
}
 

	
 
/** Get the previous real (non-articulated part and non rear part of dualheaded engine) vehicle in the consist.
 
 * @param v Vehicle.
 
 * @return Previous vehicle in the consist.
 
 */
 
static inline Vehicle *GetPrevUnit(Vehicle *v)
 
static inline Vehicle *GetPrevUnit(const Vehicle *v)
 
{
 
	assert(v->type == VEH_TRAIN);
 
	v = GetPrevVehicle(v);
 
	if (v != NULL && IsRearDualheaded(v)) v = GetPrevVehicle(v);
 
	Vehicle *w = GetPrevVehicle(v);
 
	if (w != NULL && IsRearDualheaded(w)) w = GetPrevVehicle(w);
 

	
 
	return v;
 
	return w;
 
}
 

	
 
void ConvertOldMultiheadToNew();
 
void ConnectMultiheadedTrains();
 

	
 
void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2);
 
void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2);
 

	
 
byte FreightWagonMult(CargoID cargo);
 

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

	
 
void FreeTrainTrackReservation(const Vehicle *v, TileIndex origin = INVALID_TILE, Trackdir orig_td = INVALID_TRACKDIR);
 
bool TryPathReserve(Vehicle *v, bool mark_as_stuck = false, bool first_tile_okay = false);
 

	
 
/**
 
 * This class 'wraps' Vehicle; you do not actually instantiate this class.
 
 * You create a Vehicle using AllocateVehicle, so it is added to the pool
 
 * and you reinitialize that to a Train using:
 
 *   v = new (v) Train();
 
 *
 
 * As side-effect the vehicle type is set correctly.
 
 */
 
struct Train : public Vehicle {
 
	/** Initializes the Vehicle to a train */
 
	Train() { this->type = VEH_TRAIN; }
 

	
 
	/** We want to 'destruct' the right class. */
 
	virtual ~Train() { this->PreDestructor(); }
 

	
 
	const char *GetTypeString() const { return "train"; }
 
	void MarkDirty();
 
	void UpdateDeltaXY(Direction direction);
 
	ExpensesType GetExpenseType(bool income) const { return income ? EXPENSES_TRAIN_INC : EXPENSES_TRAIN_RUN; }
 
	void PlayLeaveStationSound() const;
 
	bool IsPrimaryVehicle() const { return IsFrontEngine(this); }
 
	SpriteID GetImage(Direction direction) const;
 
	int GetDisplaySpeed() const { return this->u.rail.last_speed * 10 / 16; }
 
	int GetDisplayMaxSpeed() const { return this->u.rail.cached_max_speed * 10 / 16; }
 
	Money GetRunningCost() const;
 
	bool IsInDepot() const { return CheckTrainInDepot(this, false) != -1; }
 
	bool IsStoppedInDepot() const { return CheckTrainStoppedInDepot(this) >= 0; }
 
	void Tick();
 
	void OnNewDay();
 
	TileIndex GetOrderStationLocation(StationID station);
0 comments (0 inline, 0 general)