Destroy all stuff that (still) needs the virtual functions to work properly */
| 794 | |
| 795 | /** Destroy all stuff that (still) needs the virtual functions to work properly */ |
| 796 | void Vehicle::PreDestructor() |
| 797 | { |
| 798 | if (CleaningPool()) return; |
| 799 | |
| 800 | if (Station::IsValidID(this->last_station_visited)) { |
| 801 | Station *st = Station::Get(this->last_station_visited); |
| 802 | st->loading_vehicles.remove(this); |
| 803 | |
| 804 | HideFillingPercent(&this->fill_percent_te_id); |
| 805 | this->CancelReservation(StationID::Invalid(), st); |
| 806 | delete this->cargo_payment; |
| 807 | assert(this->cargo_payment == nullptr); // cleared by ~CargoPayment |
| 808 | } |
| 809 | |
| 810 | if (this->IsEngineCountable()) { |
| 811 | GroupStatistics::CountEngine(this, -1); |
| 812 | if (this->IsPrimaryVehicle()) GroupStatistics::CountVehicle(this, -1); |
| 813 | GroupStatistics::UpdateAutoreplace(this->owner); |
| 814 | |
| 815 | if (this->owner == _local_company) InvalidateAutoreplaceWindow(this->engine_type, this->group_id); |
| 816 | DeleteGroupHighlightOfVehicle(this); |
| 817 | } |
| 818 | |
| 819 | Company::Get(this->owner)->freeunits[this->type].ReleaseID(this->unitnumber); |
| 820 | |
| 821 | if (this->type == VEH_AIRCRAFT && this->IsPrimaryVehicle()) { |
| 822 | Aircraft *a = Aircraft::From(this); |
| 823 | Station *st = GetTargetAirportIfValid(a); |
| 824 | if (st != nullptr) { |
| 825 | const auto &layout = st->airport.GetFTA()->layout; |
| 826 | st->airport.blocks.Reset(layout[a->previous_pos].blocks | layout[a->pos].blocks); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | |
| 831 | if (this->type == VEH_ROAD && this->IsPrimaryVehicle()) { |
| 832 | RoadVehicle *v = RoadVehicle::From(this); |
| 833 | if (!v->vehstatus.Test(VehState::Crashed) && IsInsideMM(v->state, RVSB_IN_DT_ROAD_STOP, RVSB_IN_DT_ROAD_STOP_END)) { |
| 834 | /* Leave the drive through roadstop, when you have not already left it. */ |
| 835 | RoadStop::GetByTile(v->tile, GetRoadStopType(v->tile))->Leave(v); |
| 836 | } |
| 837 | |
| 838 | if (v->disaster_vehicle != VehicleID::Invalid()) ReleaseDisasterVehicle(v->disaster_vehicle); |
| 839 | } |
| 840 | |
| 841 | if (this->Previous() == nullptr) { |
| 842 | InvalidateWindowData(WC_VEHICLE_DEPOT, this->tile); |
| 843 | } |
| 844 | |
| 845 | if (this->IsPrimaryVehicle()) { |
| 846 | CloseWindowById(WC_VEHICLE_VIEW, this->index); |
| 847 | CloseWindowById(WC_VEHICLE_ORDERS, this->index); |
| 848 | CloseWindowById(WC_VEHICLE_REFIT, this->index); |
| 849 | CloseWindowById(WC_VEHICLE_DETAILS, this->index); |
| 850 | CloseWindowById(WC_VEHICLE_TIMETABLE, this->index); |
| 851 | SetWindowDirty(WC_COMPANY, this->owner); |
| 852 | OrderBackup::ClearVehicle(this); |
| 853 | } |
no test coverage detected