Changeset - r12291:690f4158878e
[Not reviewed]
master
0 8 0
smatz - 15 years ago 2009-07-01 23:49:13
smatz@openttd.org
(svn r16718) -Codechange: make IsFreeWagon() member of Train
8 files changed with 24 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_vehicle.cpp
Show inline comments
 
@@ -17,13 +17,13 @@
 
#include "../../vehicle_func.h"
 
#include "table/strings.h"
 

	
 
/* static */ bool AIVehicle::IsValidVehicle(VehicleID vehicle_id)
 
{
 
	const Vehicle *v = ::Vehicle::GetIfValid(vehicle_id);
 
	return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::IsFreeWagon(v)));
 
	return v != NULL && v->owner == _current_company && (v->IsPrimaryVehicle() || (v->type == VEH_TRAIN && ::Train::From(v)->IsFreeWagon()));
 
}
 

	
 
/* static */ int32 AIVehicle::GetNumWagons(VehicleID vehicle_id)
 
{
 
	if (!IsValidVehicle(vehicle_id)) return -1;
 

	
src/group_cmd.cpp
Show inline comments
 
@@ -365,13 +365,13 @@ void SetTrainGroupID(Train *v, GroupID n
 
 * @note this needs to be called too for 'wagon chains' (in the depot, without an engine)
 
 * @note Called in CmdBuildRailVehicle, CmdBuildRailWagon, CmdMoveRailVehicle, CmdSellRailWagon
 
 * @param v First vehicle of the chain.
 
 */
 
void UpdateTrainGroupID(Train *v)
 
{
 
	assert(v->IsFrontEngine() || IsFreeWagon(v));
 
	assert(v->IsFrontEngine() || v->IsFreeWagon());
 

	
 
	GroupID new_g = v->IsFrontEngine() ? v->group_id : (GroupID)DEFAULT_GROUP;
 
	for (Vehicle *u = v; u != NULL; u = u->Next()) {
 
		if (IsEngineCountable(u)) UpdateNumEngineGroup(u->engine_type, u->group_id, new_g);
 

	
 
		u->group_id = new_g;
src/newgrf_engine.cpp
Show inline comments
 
@@ -132,13 +132,13 @@ uint32 GetEngineGRFID(EngineID engine)
 

	
 
static int MapOldSubType(const Vehicle *v)
 
{
 
	switch (v->type) {
 
		case VEH_TRAIN:
 
			if (IsTrainEngine(v)) return 0;
 
			if (IsFreeWagon(v)) return 4;
 
			if (Train::From(v)->IsFreeWagon()) return 4;
 
			return 2;
 
		case VEH_ROAD:
 
		case VEH_SHIP:     return 0;
 
		case VEH_AIRCRAFT:
 
		case VEH_DISASTER: return v->subtype;
 
		case VEH_EFFECT:   return v->subtype << 1;
src/saveload/afterload.cpp
Show inline comments
 
@@ -982,13 +982,13 @@ bool AfterLoadGame()
 
				default:
 
					break;
 
			}
 
		}
 

	
 
		FOR_ALL_TRAINS(v) {
 
			if (v->IsFrontEngine() || IsFreeWagon(v)) TrainConsistChanged(v, true);
 
			if (v->IsFrontEngine() || v->IsFreeWagon()) TrainConsistChanged(v, true);
 
		}
 

	
 
	}
 

	
 
	/* In version 16.1 of the savegame a company can decide if trains, which get
 
	 * replaced, shall keep their old length. In all prior versions, just default
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -25,13 +25,13 @@ void ConnectMultiheadedTrains()
 

	
 
	FOR_ALL_TRAINS(v) {
 
		v->other_multiheaded_part = NULL;
 
	}
 

	
 
	FOR_ALL_TRAINS(v) {
 
		if (v->IsFrontEngine() || IsFreeWagon(v)) {
 
		if (v->IsFrontEngine() || v->IsFreeWagon()) {
 
			/* Two ways to associate multiheaded parts to each other:
 
			 * sequential-matching: Trains shall be arranged to look like <..>..<..>..<..>..
 
			 * bracket-matching:    Free vehicle chains shall be arranged to look like ..<..<..>..<..>..>..
 
			 *
 
			 * Note: Old savegames might contain chains which do not comply with these rules, e.g.
 
			 *   - the front and read parts have invalid orders
src/train.h
Show inline comments
 
@@ -324,17 +324,22 @@ struct Train : public SpecializedVehicle
 
	void OnNewDay();
 
	Trackdir GetVehicleTrackdir() const;
 
	TileIndex GetOrderStationLocation(StationID station);
 
	bool FindClosestDepot(TileIndex *location, DestinationID *destination, bool *reverse);
 

	
 
	/**
 
	 * Check if a vehicle is front engine
 
	 * @param v vehicle to check
 
	 * @return Returns true if vehicle is a front engine
 
	 * Check if train is a front engine
 
	 * @return Returns true if train is a front engine
 
	 */
 
	FORCEINLINE bool IsFrontEngine() const { return HasBit(this->subtype, TS_FRONT); }
 

	
 
	/**
 
	 * Check if train is a free wagon (got no engine in front of it)
 
	 * @return Returns true if train is a free wagon
 
	 */
 
	FORCEINLINE bool IsFreeWagon() const { return HasBit(this->subtype, TS_FREE_WAGON); }
 
};
 

	
 
#define FOR_ALL_TRAINS(var) FOR_ALL_VEHICLES_OF_TYPE(Train, var)
 

	
 
/**
 
 * Get the next part of a multi-part engine.
src/train_cmd.cpp
Show inline comments
 
@@ -214,13 +214,13 @@ void CheckTrainsLengths()
 
 * @param same_length should length of vehicles stay the same?
 
 */
 
void TrainConsistChanged(Train *v, bool same_length)
 
{
 
	uint16 max_speed = UINT16_MAX;
 

	
 
	assert(v->IsFrontEngine() || IsFreeWagon(v));
 
	assert(v->IsFrontEngine() || v->IsFreeWagon());
 

	
 
	const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type);
 
	EngineID first_engine = v->IsFrontEngine() ? v->engine_type : INVALID_ENGINE;
 
	v->tcache.cached_total_length = 0;
 
	v->compatible_railtypes = RAILTYPES_NONE;
 

	
 
@@ -749,13 +749,13 @@ static CommandCost CmdBuildRailWagon(Eng
 

	
 
/** Move all free vehicles in the depot to the train */
 
static void NormalizeTrainVehInDepot(const Train *u)
 
{
 
	const Train *v;
 
	FOR_ALL_TRAINS(v) {
 
		if (IsFreeWagon(v) && v->tile == u->tile &&
 
		if (v->IsFreeWagon() && v->tile == u->tile &&
 
				v->track == TRACK_BIT_DEPOT) {
 
			if (CmdFailed(DoCommand(0, v->index | (u->index << 16), 1, DC_EXEC,
 
					CMD_MOVE_RAIL_VEHICLE)))
 
				break;
 
		}
 
	}
 
@@ -1027,13 +1027,13 @@ static void AddWagonToConsist(Train *v, 
 
/*
 
 * move around on the train so rear engines are placed correctly according to the other engines
 
 * always call with the front engine
 
 */
 
static void NormaliseTrainConsist(Train *v)
 
{
 
	if (IsFreeWagon(v)) return;
 
	if (v->IsFreeWagon()) return;
 

	
 
	assert(v->IsFrontEngine());
 

	
 
	for (; v != NULL; v = GetNextVehicle(v)) {
 
		if (!IsMultiheaded(v) || !IsTrainEngine(v)) continue;
 

	
 
@@ -4456,13 +4456,13 @@ bool Train::Tick()
 

	
 
		this->current_order_time++;
 

	
 
		if (!TrainLocoHandler(this, false)) return false;
 

	
 
		return TrainLocoHandler(this, true);
 
	} else if (IsFreeWagon(this) && (this->vehstatus & VS_CRASHED)) {
 
	} else if (this->IsFreeWagon() && (this->vehstatus & VS_CRASHED)) {
 
		/* Delete flooded standalone wagon chain */
 
		if (++this->crash_anim_pos >= 4400) {
 
			delete this;
 
			return false;
 
		}
 
	}
src/vehiclelist.cpp
Show inline comments
 
@@ -24,20 +24,22 @@ void BuildDepotVehicleList(VehicleType t
 
	FOR_ALL_VEHICLES(v) {
 
		/* General tests for all vehicle types */
 
		if (v->type != type) continue;
 
		if (v->tile != tile) continue;
 

	
 
		switch (type) {
 
			case VEH_TRAIN:
 
				if (IsArticulatedPart(v) || IsRearDualheaded(v)) continue;
 
				if (Train::From(v)->track != TRACK_BIT_DEPOT) continue;
 
				if (wagons != NULL && IsFreeWagon(v->First())) {
 
					if (individual_wagons || IsFreeWagon(v)) *wagons->Append() = v;
 
			case VEH_TRAIN: {
 
				const Train *t = Train::From(v);
 
				if (IsArticulatedPart(t) || IsRearDualheaded(t)) continue;
 
				if (t->track != TRACK_BIT_DEPOT) continue;
 
				if (wagons != NULL && t->First()->IsFreeWagon()) {
 
					if (individual_wagons || t->IsFreeWagon()) *wagons->Append() = t;
 
					continue;
 
				}
 
				break;
 
			}
 

	
 
			default:
 
				if (!v->IsInDepot()) continue;
 
				break;
 
		}
 

	
0 comments (0 inline, 0 general)