| 931 | } |
| 932 | |
| 933 | void Agent::die(GameState &state, bool silent) |
| 934 | { |
| 935 | auto thisRef = StateRef<Agent>{&state, shared_from_this()}; |
| 936 | |
| 937 | // Set health to zero so agent will die on next update |
| 938 | modified_stats.health = 0; |
| 939 | |
| 940 | // Remove from vehicle |
| 941 | if (currentVehicle) |
| 942 | { |
| 943 | currentVehicle->currentAgents.erase(thisRef); |
| 944 | } |
| 945 | |
| 946 | // Remove from lab |
| 947 | if (assigned_to_lab) |
| 948 | { |
| 949 | for (auto &fac : homeBuilding->base->facilities) |
| 950 | { |
| 951 | if (!fac->lab) |
| 952 | { |
| 953 | continue; |
| 954 | } |
| 955 | auto it = std::find(fac->lab->assigned_agents.begin(), fac->lab->assigned_agents.end(), |
| 956 | thisRef); |
| 957 | if (it != fac->lab->assigned_agents.end()) |
| 958 | { |
| 959 | fac->lab->assigned_agents.erase(it); |
| 960 | assigned_to_lab = false; |
| 961 | break; |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | // In city (if not died in a vehicle) we make an event |
| 967 | if (!silent && !state.current_battle && owner == state.getPlayer()) |
| 968 | { |
| 969 | fw().pushEvent( |
| 970 | new GameSomethingDiedEvent(GameEventType::AgentDiedCity, name, "", position)); |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | bool Agent::isDead() const { return getHealth() <= 0; } |
| 975 | |