/** * Clean up a station by clearing vehicle orders, invalidating windows and * removing link stats. * Aircraft-Hangar orders need special treatment here, as the hangars are * actually part of a station (tiletype is STATION), but the order type * is OT_GOTO_DEPOT. */ Station::~Station() { if (CleaningPool()) return; while (!this->loading_vehicles.empty()) { this->loading_vehicles.front()->LeaveStation(); } Aircraft *a; FOR_ALL_AIRCRAFT(a) { if (!a->IsNormalAircraft()) continue; if (a->targetairport == this->index) a->targetairport = INVALID_STATION; } Station *st; FOR_ALL_STATIONS(st) { for (CargoID c = 0; c < NUM_CARGO; ++c) { GoodsEntry &ge = st->goods[c]; ge.link_stats.erase(this->index); DeleteStaleFlows(st->index, c, this->index); ge.cargo.RerouteStalePackets(this->index); } } Vehicle *v; FOR_ALL_VEHICLES(v) { /* 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; } } InvalidateWindowData(WC_STATION_LIST, this->owner, 0); DeleteWindowById(WC_STATION_VIEW, index); /* Now delete all orders that go to the station */ RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index); /* Remove all news items */ DeleteStationNews(this->index); for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.Truncate(0); } CargoPacket::InvalidateAllFrom(this->index); }
/** * Clean up a station by clearing vehicle orders and invalidating windows. * Aircraft-Hangar orders need special treatment here, as the hangars are * actually part of a station (tiletype is STATION), but the order type * is OT_GOTO_DEPOT. */ Station::~Station() { if (CleaningPool()) { for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.OnCleanPool(); } return; } while (!this->loading_vehicles.empty()) { this->loading_vehicles.front()->LeaveStation(); } Aircraft *a; FOR_ALL_AIRCRAFT(a) { if (!a->IsNormalAircraft()) continue; if (a->targetairport == this->index) a->targetairport = INVALID_STATION; } Vehicle *v; FOR_ALL_VEHICLES(v) { /* Forget about this station if this station is removed */ if (v->last_station_visited == this->index) { v->last_station_visited = INVALID_STATION; } } /* Clear the persistent storage. */ delete this->airport.psa; if (this->owner == OWNER_NONE) { /* Invalidate all in case of oil rigs. */ InvalidateWindowClassesData(WC_STATION_LIST, 0); } else { InvalidateWindowData(WC_STATION_LIST, this->owner, 0); } DeleteWindowById(WC_STATION_VIEW, index); /* Now delete all orders that go to the station */ RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index); /* Remove all news items */ DeleteStationNews(this->index); for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.Truncate(0); } CargoPacket::InvalidateAllFrom(this->index); }
/** * Clean up a station by clearing vehicle orders and invalidating windows. * Aircraft-Hangar orders need special treatment here, as the hangars are * actually part of a station (tiletype is STATION), but the order type * is OT_GOTO_DEPOT. */ Station::~Station() { if (CleaningPool()) return; while (!this->loading_vehicles.empty()) { this->loading_vehicles.front()->LeaveStation(); } Aircraft *a; FOR_ALL_AIRCRAFT(a) { if (!a->IsNormalAircraft()) continue; if (a->targetairport == this->index) a->targetairport = INVALID_STATION; } Vehicle *v; FOR_ALL_VEHICLES(v) { /* Forget about this station if this station is removed */ if (v->last_station_visited == this->index) { v->last_station_visited = INVALID_STATION; } } this->sign.MarkDirty(); InvalidateWindowData(WC_STATION_LIST, this->owner, 0); DeleteWindowById(WC_STATION_VIEW, index); WindowNumber wno = (this->index << 16) | VLW_STATION_LIST | this->owner; DeleteWindowById(WC_TRAINS_LIST, wno | (VEH_TRAIN << 11)); DeleteWindowById(WC_ROADVEH_LIST, wno | (VEH_ROAD << 11)); DeleteWindowById(WC_SHIPS_LIST, wno | (VEH_SHIP << 11)); DeleteWindowById(WC_AIRCRAFT_LIST, wno | (VEH_AIRCRAFT << 11)); /* Now delete all orders that go to the station */ RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index); /* Remove all news items */ DeleteStationNews(this->index); for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.Truncate(0); } CargoPacket::InvalidateAllFrom(this->index); }
/** need to be called to load aircraft from old version */ void UpdateOldAircraft() { /* set airport_flags to 0 for all airports just to be sure */ Station *st; FOR_ALL_STATIONS(st) { st->airport.flags = 0; // reset airport } Aircraft *a; FOR_ALL_AIRCRAFT(a) { /* airplane has another vehicle with subtype 4 (shadow), helicopter also has 3 (rotor) * skip those */ if (a->IsNormalAircraft()) { /* airplane in terminal stopped doesn't hurt anyone, so goto next */ if ((a->vehstatus & VS_STOPPED) && a->state == 0) { a->state = HANGAR; continue; } AircraftLeaveHangar(a, a->direction); // make airplane visible if it was in a depot for example a->vehstatus &= ~VS_STOPPED; // make airplane moving UpdateAircraftCache(a); a->cur_speed = a->vcache.cached_max_speed; // so aircraft don't have zero speed while in air if (!a->current_order.IsType(OT_GOTO_STATION) && !a->current_order.IsType(OT_GOTO_DEPOT)) { /* reset current order so aircraft doesn't have invalid "station-only" order */ a->current_order.MakeDummy(); } a->state = FLYING; AircraftNextAirportPos_and_Order(a); // move it to the entry point of the airport GetNewVehiclePosResult gp = GetNewVehiclePos(a); a->tile = 0; // aircraft in air is tile=0 /* correct speed of helicopter-rotors */ if (a->subtype == AIR_HELICOPTER) a->Next()->Next()->cur_speed = 32; /* set new position x,y,z */ SetAircraftPosition(a, gp.x, gp.y, GetAircraftFlyingAltitude(a)); } } }
/** * Clean up a station by clearing vehicle orders, invalidating windows and * removing link stats. * Aircraft-Hangar orders need special treatment here, as the hangars are * actually part of a station (tiletype is STATION), but the order type * is OT_GOTO_DEPOT. */ Station::~Station() { if (CleaningPool()) { for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.OnCleanPool(); } return; } while (!this->loading_vehicles.empty()) { this->loading_vehicles.front()->LeaveStation(); } Aircraft *a; FOR_ALL_AIRCRAFT(a) { 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 == NULL) continue; for (NodeID node = 0; node < lg->Size(); ++node) { Station *st = Station::Get((*lg)[node].Station()); st->goods[c].flows.erase(this->index); if ((*lg)[node][this->goods[c].node].LastUpdate() != INVALID_DATE) { st->goods[c].flows.DeleteFlows(this->index); RerouteCargo(st, c, this->index, st->index); } } lg->RemoveNode(this->goods[c].node); if (lg->Size() == 0) { LinkGraphSchedule::instance.Unqueue(lg); delete lg; } } Vehicle *v; FOR_ALL_VEHICLES(v) { /* 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; } } /* Clear the persistent storage. */ delete this->airport.psa; if (this->owner == OWNER_NONE) { /* Invalidate all in case of oil rigs. */ InvalidateWindowClassesData(WC_STATION_LIST, 0); } else { InvalidateWindowData(WC_STATION_LIST, this->owner, 0); } if (Overlays::Instance()->HasStation(Station::Get(this->index))) { Overlays::Instance()->ToggleStation(Station::Get(this->index)); }; DeleteWindowById(WC_STATION_VIEW, index); /* Now delete all orders that go to the station */ RemoveOrderFromAllVehicles(OT_GOTO_STATION, this->index); /* Remove all news items */ DeleteStationNews(this->index); for (CargoID c = 0; c < NUM_CARGO; c++) { this->goods[c].cargo.Truncate(); } CargoPacket::InvalidateAllFrom(this->index); }