| 50 | GameState::GameState() : player(this) { luaGameState.init(*this); } |
| 51 | |
| 52 | GameState::~GameState() |
| 53 | { |
| 54 | if (this->current_battle) |
| 55 | { |
| 56 | Battle::finishBattle(*this); |
| 57 | Battle::exitBattle(*this); |
| 58 | } |
| 59 | for (auto &a : this->agents) |
| 60 | { |
| 61 | a.second->destroy(); |
| 62 | } |
| 63 | for (auto &v : this->vehicles) |
| 64 | { |
| 65 | auto vehicle = v.second; |
| 66 | vehicle->removeFromMap(*this); |
| 67 | // Detach some back-pointers otherwise we get circular sp<> dependencies and leak |
| 68 | // FIXME: This is not a 'good' way of doing this, maybe add a destroyVehicle() function? Or |
| 69 | // make StateRefWeak<> or something? |
| 70 | // |
| 71 | vehicle->city.clear(); |
| 72 | vehicle->homeBuilding.clear(); |
| 73 | vehicle->currentBuilding.clear(); |
| 74 | vehicle->missions.clear(); |
| 75 | vehicle->equipment.clear(); |
| 76 | vehicle->mover = nullptr; |
| 77 | } |
| 78 | for (auto &b : this->player_bases) |
| 79 | { |
| 80 | for (auto &f : b.second->facilities) |
| 81 | { |
| 82 | if (f->lab) |
| 83 | { |
| 84 | f->lab->assigned_agents.clear(); |
| 85 | f->lab->current_project.clear(); |
| 86 | f->lab.clear(); |
| 87 | } |
| 88 | } |
| 89 | b.second->building.clear(); |
| 90 | } |
| 91 | for (auto &org : this->organisations) |
| 92 | { |
| 93 | org.second->current_relations.clear(); |
| 94 | } |
| 95 | for (auto &city : this->cities) |
| 96 | { |
| 97 | for (auto &building : city.second->buildings) |
| 98 | { |
| 99 | auto &bld = building.second; |
| 100 | bld->city.clear(); |
| 101 | bld->function.clear(); |
| 102 | bld->owner.clear(); |
| 103 | bld->base_layout.clear(); |
| 104 | bld->base.clear(); |
| 105 | bld->battle_map.clear(); |
| 106 | bld->preset_crew.clear(); |
| 107 | bld->current_crew.clear(); |
| 108 | bld->currentVehicles.clear(); |
| 109 | bld->currentAgents.clear(); |
nothing calls this directly
no test coverage detected