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
 
@@ -20,7 +20,7 @@
 
/* 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)
src/group_cmd.cpp
Show inline comments
 
@@ -368,7 +368,7 @@ void SetTrainGroupID(Train *v, GroupID n
 
 */
 
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()) {
src/newgrf_engine.cpp
Show inline comments
 
@@ -135,7 +135,7 @@ static int MapOldSubType(const Vehicle *
 
	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;
src/saveload/afterload.cpp
Show inline comments
 
@@ -985,7 +985,7 @@ bool AfterLoadGame()
 
		}
 

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

	
 
	}
src/saveload/vehicle_sl.cpp
Show inline comments
 
@@ -28,7 +28,7 @@ void ConnectMultiheadedTrains()
 
	}
 

	
 
	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 ..<..<..>..<..>..>..
src/train.h
Show inline comments
 
@@ -327,11 +327,16 @@ struct Train : public SpecializedVehicle
 
	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)
src/train_cmd.cpp
Show inline comments
 
@@ -217,7 +217,7 @@ void TrainConsistChanged(Train *v, bool 
 
{
 
	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;
 
@@ -752,7 +752,7 @@ static void NormalizeTrainVehInDepot(con
 
{
 
	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)))
 
@@ -1030,7 +1030,7 @@ static void AddWagonToConsist(Train *v, 
 
 */
 
static void NormaliseTrainConsist(Train *v)
 
{
 
	if (IsFreeWagon(v)) return;
 
	if (v->IsFreeWagon()) return;
 

	
 
	assert(v->IsFrontEngine());
 

	
 
@@ -4459,7 +4459,7 @@ bool Train::Tick()
 
		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;
src/vehiclelist.cpp
Show inline comments
 
@@ -27,14 +27,16 @@ void BuildDepotVehicleList(VehicleType t
 
		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;
0 comments (0 inline, 0 general)