diff --git a/src/ai/api/ai_vehicle.cpp b/src/ai/api/ai_vehicle.cpp --- 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 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -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()) { diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -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; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp --- 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 --- 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 --- a/src/train.h +++ b/src/train.h @@ -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) diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -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; diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -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;