| 78 | } |
| 79 | |
| 80 | void Base::die(GameState &state, bool collapse) |
| 81 | { |
| 82 | fw().pushEvent(new GameSomethingDiedEvent( |
| 83 | GameEventType::BaseDestroyed, name, |
| 84 | collapse ? /*by collapsing building*/ "" : "byEnemyForces", building->crewQuarters)); |
| 85 | for (auto &b : building->city->buildings) |
| 86 | { |
| 87 | for (auto &c : b.second->cargo) |
| 88 | { |
| 89 | if (c.destination == building) |
| 90 | { |
| 91 | c.refund(state, {&state, b.first}); |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | for (auto &v : state.vehicles) |
| 96 | { |
| 97 | for (auto &c : v.second->cargo) |
| 98 | { |
| 99 | if (c.destination == building) |
| 100 | { |
| 101 | // This is base transfer in progress |
| 102 | if (c.originalOwner == c.destination->owner) |
| 103 | { |
| 104 | // Re-route to another base |
| 105 | for (auto &b : state.player_bases) |
| 106 | { |
| 107 | if (b.second->building == building) |
| 108 | { |
| 109 | continue; |
| 110 | } |
| 111 | c.destination = b.second->building; |
| 112 | break; |
| 113 | } |
| 114 | } |
| 115 | else |
| 116 | { |
| 117 | c.refund(state, nullptr); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | for (auto a : building->currentAgents) |
| 123 | { |
| 124 | a->die(state, true); |
| 125 | } |
| 126 | for (auto v : building->currentVehicles) |
| 127 | { |
| 128 | v->die(state, true); |
| 129 | } |
| 130 | building->base.clear(); |
| 131 | building->owner = state.getGovernment(); |
| 132 | building->collapse(state); |
| 133 | building.clear(); |
| 134 | |
| 135 | state.player_bases.erase(Base::getId(state, shared_from_this())); |
| 136 | state.current_base.clear(); |
| 137 | if (state.player_bases.empty()) |
no test coverage detected