From dac4a4dc42dfa221f6df9bfaff7455b443b02687 Mon Sep 17 00:00:00 2001
From: BaerMitUmlaut <BaerMitUmlaut@users.noreply.github.com>
Date: Wed, 9 Nov 2016 19:01:55 +0100
Subject: [PATCH] Merged instant death and execution into one setting

---
 addons/medical/ACE_Medical_StateMachine.hpp   | 12 +++++------
 addons/medical/XEH_preInit.sqf                | 21 +++++++------------
 ...qf => fnc_conditionCardiacArrestTimer.sqf} |  2 +-
 .../functions/fnc_conditionExecutionDeath.sqf |  2 +-
 ...ted.sqf => fnc_transitionSecondChance.sqf} |  2 +-
 5 files changed, 17 insertions(+), 22 deletions(-)
 rename addons/medical/functions/{fnc_conditionCardiacArrestDeath.sqf => fnc_conditionCardiacArrestTimer.sqf} (87%)
 rename addons/medical/functions/{fnc_transitionInstantDeathPrevented.sqf => fnc_transitionSecondChance.sqf} (82%)

diff --git a/addons/medical/ACE_Medical_StateMachine.hpp b/addons/medical/ACE_Medical_StateMachine.hpp
index 94bf48bff2..82ef3b6c29 100644
--- a/addons/medical/ACE_Medical_StateMachine.hpp
+++ b/addons/medical/ACE_Medical_StateMachine.hpp
@@ -64,13 +64,13 @@ class ACE_Medical_StateMachine {
         // Transition state for handling instant death
         // This state raises the next transition in the same frame
         onStateEntered = QUOTE(DFUNC(enteredStateFatalInjury));
-        class InstantDeathPrevented {
+        class SecondChance {
             events[] = {QGVAR(FatalInjuryInstantTransition)};
             targetState = "CardiacArrest";
-            condition = QUOTE(!GVAR(enableInstantDeath));
-            onTransition = QUOTE(DFUNC(transitionInstantDeathPrevented));
+            condition = QUOTE(GVAR(allowDeathMode) > 0);
+            onTransition = QUOTE(DFUNC(transitionSecondChance));
         };
-        class InstantDeath {
+        class Death {
             events[] = {QGVAR(FatalInjuryInstantTransition)};
             targetState = "Dead";
             condition = "true";
@@ -79,9 +79,9 @@ class ACE_Medical_StateMachine {
     class CardiacArrest {
         onStateEntered = QUOTE(DFUNC(enteredStateCardiacArrest));
         onStateLeaving = '_this setVariable [QGVAR(cardiacArrestStart), nil]';
-        class Death {
+        class TimerRanOut {
             targetState = "Dead";
-            condition = QUOTE(DFUNC(conditionCardiacArrestDeath));
+            condition = QUOTE(DFUNC(conditionCardiacArrestTimer));
         };
         class Reanimated {
             targetState = "Unconscious";
diff --git a/addons/medical/XEH_preInit.sqf b/addons/medical/XEH_preInit.sqf
index 1540e538bc..f300d1cd70 100644
--- a/addons/medical/XEH_preInit.sqf
+++ b/addons/medical/XEH_preInit.sqf
@@ -38,20 +38,15 @@ GVAR(STATE_MACHINE) = (configFile >> "ACE_Medical_StateMachine") call CBA_statem
 ] call CBA_Settings_fnc_init;
 
 [
-    QGVAR(enableInstantDeath),
-    "CHECKBOX",
-    ["Enable Instant Death", "Enables units instantly dying without entering cardiac arrest first."], //@todo
+    QGVAR(allowDeathMode),
+    "LIST",
+    ["Kill unit after", ""], //@todo
     "ACE Medical", // @todo
-    true,
-    true
-] call CBA_Settings_fnc_init;
-
-[
-    QGVAR(enableExecutions),
-    "CHECKBOX",
-    ["Enable Executions", "Enables killing units that are in cardiac arrest. Only matters when instant death is disabled."], //@todo
-    "ACE Medical", // @todo
-    true,
+    [
+        [0, 1, 2],
+        ["Fatal wound", "Second chance after fatal wound", "Only cardiac arrest time expiration"],
+        0
+    ],
     true
 ] call CBA_Settings_fnc_init;
 
diff --git a/addons/medical/functions/fnc_conditionCardiacArrestDeath.sqf b/addons/medical/functions/fnc_conditionCardiacArrestTimer.sqf
similarity index 87%
rename from addons/medical/functions/fnc_conditionCardiacArrestDeath.sqf
rename to addons/medical/functions/fnc_conditionCardiacArrestTimer.sqf
index fd7348f4bc..79a3263d58 100644
--- a/addons/medical/functions/fnc_conditionCardiacArrestDeath.sqf
+++ b/addons/medical/functions/fnc_conditionCardiacArrestTimer.sqf
@@ -1,6 +1,6 @@
 /*
  * Author: BaerMitUmlaut
- * Handles a unit entering cardiac arrest.
+ * Checks if the cardiac arrest timer ran out.
  *
  * Arguments:
  * 0: The Unit <OBJECT>
diff --git a/addons/medical/functions/fnc_conditionExecutionDeath.sqf b/addons/medical/functions/fnc_conditionExecutionDeath.sqf
index 3c9a1cdf8e..1fc870a3a4 100644
--- a/addons/medical/functions/fnc_conditionExecutionDeath.sqf
+++ b/addons/medical/functions/fnc_conditionExecutionDeath.sqf
@@ -13,4 +13,4 @@
 #include "script_component.hpp"
 params ["_unit"];
 
-GVAR(enableInstantDeath) || {GVAR(enableExecutions) && {!(_unit getVariable [QGVAR(deathBlocked), false])}}
+(GVAR(allowDeathMode) < 2) && {!(_unit getVariable [QGVAR(deathBlocked), false])}}
diff --git a/addons/medical/functions/fnc_transitionInstantDeathPrevented.sqf b/addons/medical/functions/fnc_transitionSecondChance.sqf
similarity index 82%
rename from addons/medical/functions/fnc_transitionInstantDeathPrevented.sqf
rename to addons/medical/functions/fnc_transitionSecondChance.sqf
index 87d9548fbc..6fcfd0ac08 100644
--- a/addons/medical/functions/fnc_transitionInstantDeathPrevented.sqf
+++ b/addons/medical/functions/fnc_transitionSecondChance.sqf
@@ -1,6 +1,6 @@
 /*
  * Author: BaerMitUmlaut
- * Prevents instant death for 1 second.
+ * Gives the unit a second chance and prevents death for 1 second.
  *
  * Arguments:
  * 0: The Unit <OBJECT>