From fe3c0f32035f3d39d99c3ac202313ee885633897 Mon Sep 17 00:00:00 2001 From: SamuXarick <43006711+SamuXarick@users.noreply.github.com> Date: Tue, 2 Jan 2024 14:18:07 +0000 Subject: [PATCH] Change: Iterate group vehicle lists for Station::~Station As a compromise, the result of this change differs from the original. The VehiclePool was being iterated twice. Do it only once and assume only primary vehicles make use of last_station_visited and last_loading_station. --- src/station.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/station.cpp b/src/station.cpp index 42efef7591..a012afb7c7 100644 --- a/src/station.cpp +++ b/src/station.cpp @@ -93,11 +93,6 @@ Station::~Station() this->loading_vehicles.front()->LeaveStation(); } - for (Aircraft *a : Aircraft::Iterate()) { - if (!a->IsNormalAircraft()) continue; - if (a->targetairport == this->index) a->targetairport = INVALID_STATION; - } - for (CargoID c = 0; c < NUM_CARGO; ++c) { LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph); if (lg == nullptr) continue; @@ -117,13 +112,24 @@ Station::~Station() } } - for (Vehicle *v : Vehicle::Iterate()) { - /* Forget about this station if this station is removed */ - if (v->last_station_visited == this->index) { - v->last_station_visited = INVALID_STATION; - } - if (v->last_loading_station == this->index) { - v->last_loading_station = INVALID_STATION; + for (const Company *c : Company::Iterate()) { + if (this->owner != c->index && this->owner != OWNER_NONE) continue; + for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) { + const VehicleList &vehicle_list = c->group_all[type].vehicle_list; + for (const Vehicle *vehicle : vehicle_list) { + Vehicle *v = Vehicle::Get(vehicle->index); + if (type == VEH_AIRCRAFT) { + Aircraft *a = Aircraft::From(v); + if (a->targetairport == this->index) a->targetairport = INVALID_STATION; + } + /* Forget about this station if this station is removed */ + if (v->last_station_visited == this->index) { + v->last_station_visited = INVALID_STATION; + } + if (v->last_loading_station == this->index) { + v->last_loading_station = INVALID_STATION; + } + } } }