Add wrapper to iterate vehicle pool with vehicle type filter

Without needing to dereference vehicle pointers if using tagged pointers
This commit is contained in:
Jonathan G Rennison
2024-02-25 13:38:49 +00:00
parent be4aea0dad
commit 05e237f8d1
10 changed files with 47 additions and 26 deletions

View File

@@ -595,12 +595,12 @@ void FixupTrainLengths()
{
/* Vehicle center was moved from 4 units behind the front to half the length
* behind the front. Move vehicles so they end up on the same spot. */
for (Vehicle *v : Vehicle::Iterate()) {
if (v->type == VEH_TRAIN && v->IsPrimaryVehicle()) {
for (Train *v : Train::Iterate()) {
if (v->IsPrimaryVehicle()) {
/* The vehicle center is now more to the front depending on vehicle length,
* so we need to move all vehicles forward to cover the difference to the
* old center, otherwise wagon spacing in trains would be broken upon load. */
for (Train *u = Train::From(v); u != nullptr; u = u->Next()) {
for (Train *u = v; u != nullptr; u = u->Next()) {
if (u->track == TRACK_BIT_DEPOT || (u->vehstatus & VS_CRASHED)) continue;
Train *next = u->Next();
@@ -670,7 +670,7 @@ void FixupTrainLengths()
}
/* Update all cached properties after moving the vehicle chain around. */
Train::From(v)->ConsistChanged(CCF_TRACK);
v->ConsistChanged(CCF_TRACK);
}
}
}

View File

@@ -149,9 +149,7 @@ void MoveWaypointsToBaseStations()
for (Order *o = ol->GetFirstOrder(); o != nullptr; o = o->next) UpdateWaypointOrder(o);
}
for (Vehicle *v : Vehicle::Iterate()) {
if (v->type != VEH_TRAIN) continue;
for (Vehicle *v : Vehicle::IterateType(VEH_TRAIN)) {
UpdateWaypointOrder(&v->current_order);
}