1
0
Fork 0

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.
pull/10548/head
SamuXarick 2024-01-02 14:18:07 +00:00
parent 1f4ca2ed07
commit fe3c0f3203
1 changed files with 18 additions and 12 deletions

View File

@ -93,11 +93,6 @@ Station::~Station()
this->loading_vehicles.front()->LeaveStation(); 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) { for (CargoID c = 0; c < NUM_CARGO; ++c) {
LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph); LinkGraph *lg = LinkGraph::GetIfValid(this->goods[c].link_graph);
if (lg == nullptr) continue; if (lg == nullptr) continue;
@ -117,13 +112,24 @@ Station::~Station()
} }
} }
for (Vehicle *v : Vehicle::Iterate()) { for (const Company *c : Company::Iterate()) {
/* Forget about this station if this station is removed */ if (this->owner != c->index && this->owner != OWNER_NONE) continue;
if (v->last_station_visited == this->index) { for (VehicleType type = VEH_BEGIN; type < VEH_COMPANY_END; type++) {
v->last_station_visited = INVALID_STATION; const VehicleList &vehicle_list = c->group_all[type].vehicle_list;
} for (const Vehicle *vehicle : vehicle_list) {
if (v->last_loading_station == this->index) { Vehicle *v = Vehicle::Get(vehicle->index);
v->last_loading_station = INVALID_STATION; 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;
}
}
} }
} }