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();
}
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,7 +112,16 @@ Station::~Station()
}
}
for (Vehicle *v : Vehicle::Iterate()) {
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;
@ -126,6 +130,8 @@ Station::~Station()
v->last_loading_station = INVALID_STATION;
}
}
}
}
/* Remove station from industries and towns that reference it. */
this->RemoveFromAllNearbyLists();