diff options
author | smatz <smatz@openttd.org> | 2009-07-01 23:49:13 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-07-01 23:49:13 +0000 |
commit | ecfaa0564d9588b9f6826b1033d93b827751f410 (patch) | |
tree | f04dff76baabb0dcc7e952f9d81b70828398a740 | |
parent | adc5363202629aa07c762f459d7e9f5bc78efa34 (diff) | |
download | openttd-ecfaa0564d9588b9f6826b1033d93b827751f410.tar.xz |
(svn r16718) -Codechange: make IsFreeWagon() member of Train
-rw-r--r-- | src/ai/api/ai_vehicle.cpp | 2 | ||||
-rw-r--r-- | src/group_cmd.cpp | 2 | ||||
-rw-r--r-- | src/newgrf_engine.cpp | 2 | ||||
-rw-r--r-- | src/saveload/afterload.cpp | 2 | ||||
-rw-r--r-- | src/saveload/vehicle_sl.cpp | 2 | ||||
-rw-r--r-- | src/train.h | 11 | ||||
-rw-r--r-- | src/train_cmd.cpp | 8 | ||||
-rw-r--r-- | src/vehiclelist.cpp | 12 |
8 files changed, 24 insertions, 17 deletions
diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp index b1e4e0ad7..45e50ca4d 100644 --- a/src/ai/api/ai_vehicle.cpp +++ b/src/ai/api/ai_vehicle.cpp @@ -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) diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index cc07395e2..bd4905268 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -368,7 +368,7 @@ void SetTrainGroupID(Train *v, GroupID new_g) */ 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()) { diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index ce7e7e6ea..ecf69a9eb 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -135,7 +135,7 @@ 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; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 7defed1e6..e33e234a1 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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); } } diff --git a/src/saveload/vehicle_sl.cpp b/src/saveload/vehicle_sl.cpp index 3525d2591..2f9c1e330 100644 --- a/src/saveload/vehicle_sl.cpp +++ b/src/saveload/vehicle_sl.cpp @@ -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 ..<..<..>..<..>..>.. diff --git a/src/train.h b/src/train.h index 21e1995ea..02f73ffe6 100644 --- a/src/train.h +++ b/src/train.h @@ -327,11 +327,16 @@ struct Train : public SpecializedVehicle<Train, VEH_TRAIN> { 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) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index a3e3179ee..dc7723f88 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -217,7 +217,7 @@ 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; @@ -752,7 +752,7 @@ 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))) @@ -1030,7 +1030,7 @@ static void AddWagonToConsist(Train *v, Train *dest) */ 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; diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 25e66ec90..efd1f8093 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -27,14 +27,16 @@ void BuildDepotVehicleList(VehicleType type, TileIndex tile, VehicleList *engine 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; |