MCPcopy Create free account
hub / github.com/OpenApoc/OpenApoc / die

Method die

game/state/shared/agent.cpp:933–972  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

931}
932
933void 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
974bool Agent::isDead() const { return getHealth() <= 0; }
975

Callers 4

loadAmmoMethod · 0.45
updateMethod · 0.45
updateHirableAgentsMethod · 0.45
executeMethod · 0.45

Calls 4

endMethod · 0.80
getPlayerMethod · 0.80
pushEventMethod · 0.80
beginMethod · 0.45

Tested by

no test coverage detected