From 5e16bfad7073cc26e01495778b16a7c98e5acd9f Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 10 Oct 2019 22:56:35 -0500 Subject: [PATCH 1/2] Medical - Make some constants variables --- .../functions/fnc_determineIfFatal.sqf | 5 +-- addons/medical_engine/XEH_preInit.sqf | 13 ++++++++ .../medical_engine/script_macros_medical.hpp | 32 +++++++++++++------ 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/addons/medical_damage/functions/fnc_determineIfFatal.sqf b/addons/medical_damage/functions/fnc_determineIfFatal.sqf index fc674cf75b4..e20238f0548 100644 --- a/addons/medical_damage/functions/fnc_determineIfFatal.sqf +++ b/addons/medical_damage/functions/fnc_determineIfFatal.sqf @@ -18,9 +18,6 @@ * Public: No */ -#define WEIBULL_K 6.5625 -#define WEIBULL_L 0.704523 - params ["_unit", "_part", "_bodyPartDamage", "_woundDamage"]; if (_part > 1) exitWith { false }; @@ -49,7 +46,7 @@ if (EGVAR(medical,fatalDamageSource) in [1, 2]) then { _bodyPartDamage params ["_headDamage", "_bodyDamage"]; private _vitalDamage = ((_headDamage - _headThreshhold) max 0) + ((_bodyDamage - _bodyThreshhold) max 0); - private _chanceFatal = 1 - exp -((_vitalDamage/WEIBULL_L)^WEIBULL_K); + private _chanceFatal = 1 - exp -((_vitalDamage/FATAL_SUM_DAMAGE_WEIBULL_L)^FATAL_SUM_DAMAGE_WEIBULL_K); TRACE_3("",_bodyPartDamage,_vitalDamage,_chanceFatal); if (_chanceFatal > random 1) exitWith { diff --git a/addons/medical_engine/XEH_preInit.sqf b/addons/medical_engine/XEH_preInit.sqf index 18bc483c550..252c36b0f95 100644 --- a/addons/medical_engine/XEH_preInit.sqf +++ b/addons/medical_engine/XEH_preInit.sqf @@ -6,6 +6,19 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +// Define "Constants" variables +HEAD_DAMAGE_THRESHOLD = HEAD_DAMAGE_THRESHOLD_DEFAULT; +ORGAN_DAMAGE_THRESHOLD = ORGAN_DAMAGE_THRESHOLD_DEFAULT; +FATAL_SUM_DAMAGE_WEIBULL_K = FATAL_SUM_DAMAGE_WEIBULL_K_DEFAULT; +FATAL_SUM_DAMAGE_WEIBULL_L = FATAL_SUM_DAMAGE_WEIBULL_L_DEFAULT; +HEART_HIT_CHANCE = HEART_HIT_CHANCE_DEFAULT; +PENETRATION_THRESHOLD = PENETRATION_THRESHOLD_DEFAULT; +BLOOD_LOSS_KNOCK_OUT_THRESHOLD = BLOOD_LOSS_KNOCK_OUT_THRESHOLD_DEFAULT; +PAIN_UNCONSCIOUS = PAIN_UNCONSCIOUS_DEFAULT; +PAIN_FADE_TIME = PAIN_FADE_TIME_DEFAULT; +LIMPING_DAMAGE_THRESHOLD = LIMPING_DAMAGE_THRESHOLD_DEFAULT; +FRACTURE_DAMAGE_THRESHOLD = FRACTURE_DAMAGE_THRESHOLD_DEFAULT; + // Hack for #3168 (units in static weapons do not take any damage): // Doing a manual pre-load with a small distance seems to fix the LOD problems // with handle damage not returning full results. diff --git a/addons/medical_engine/script_macros_medical.hpp b/addons/medical_engine/script_macros_medical.hpp index 7f50866f0ec..86578e84b1b 100644 --- a/addons/medical_engine/script_macros_medical.hpp +++ b/addons/medical_engine/script_macros_medical.hpp @@ -14,12 +14,20 @@ #define HITPOINT_INDEX_RLEG 5 // Damage threshold above which fatal organ damage can occur -#define HEAD_DAMAGE_THRESHOLD 1 -#define ORGAN_DAMAGE_THRESHOLD 0.6 +#define HEAD_DAMAGE_THRESHOLD EGVAR(medical,const_headDamageThreshold) +#define HEAD_DAMAGE_THRESHOLD_DEFAULT 1 +#define ORGAN_DAMAGE_THRESHOLD EGVAR(medical,const_organDamageThreshold) +#define ORGAN_DAMAGE_THRESHOLD_DEFAULT 0.6 +// Consts for determineIfFatal: sum of damage +#define FATAL_SUM_DAMAGE_WEIBULL_K EGVAR(medical,const_fatalSumDamageWeibull_K) +#define FATAL_SUM_DAMAGE_WEIBULL_K_DEFAULT 6.5625 +#define FATAL_SUM_DAMAGE_WEIBULL_L EGVAR(medical,const_fatalSumDamageWeibull_L) +#define FATAL_SUM_DAMAGE_WEIBULL_L_DEFAULT 0.704523 // Chance to hit heart based on ratio of 70kg (approx. 70L) body to 70mL stroke volume of heart // Assuming torso is 50% of the body volume (35L) -#define HEART_HIT_CHANCE 0.05 +#define HEART_HIT_CHANCE EGVAR(medical,const_heartHitChance) +#define HEART_HIT_CHANCE_DEFAULT 0.05 #define MEDICAL_ACTION_DISTANCE 1.75 @@ -53,10 +61,12 @@ #define IV_CHANGE_PER_SECOND 4.1667 // in milliliters per second // Minimum amount of damage required for penetrating wounds (also minDamage for velocity wounds) -#define PENETRATION_THRESHOLD 0.35 +#define PENETRATION_THRESHOLD EGVAR(medical,const_penetrationThreshold) +#define PENETRATION_THRESHOLD_DEFAULT 0.35 // To be replaced by a proper blood pressure calculation -#define BLOOD_LOSS_KNOCK_OUT_THRESHOLD 0.5 // 50% of cardiac output +#define BLOOD_LOSS_KNOCK_OUT_THRESHOLD EGVAR(medical,const_bloodLossKnockOutThreshold) +#define BLOOD_LOSS_KNOCK_OUT_THRESHOLD_DEFAULT 0.5 // 50% of cardiac output // Used to color interaction icons and body image selections #define BLOOD_LOSS_RED_THRESHOLD 0.5 @@ -65,10 +75,12 @@ #define DAMAGE_TOTAL_COLORS 10 // --- pain -#define PAIN_UNCONSCIOUS 0.5 +#define PAIN_UNCONSCIOUS EGVAR(medical,const_painUnconscious) +#define PAIN_UNCONSCIOUS_DEFAULT 0.5 // Pain fade out time (time it takes until pain is guaranteed to be completly gone) -#define PAIN_FADE_TIME 900 +#define PAIN_FADE_TIME EGVAR(medical,const_painFadeTime) +#define PAIN_FADE_TIME_DEFAULT 900 // Only relevant when advanced medication is disabled // Morphine pain suppression fade out time (time it takes until pain suppression is guaranteed to be completly gone) @@ -78,10 +90,12 @@ #define SPONTANEOUS_WAKE_UP_INTERVAL 15 // Minimum leg damage required for limping -#define LIMPING_DAMAGE_THRESHOLD 0.30 +#define LIMPING_DAMAGE_THRESHOLD EGVAR(medical,const_limpingDamageThreshold) +#define LIMPING_DAMAGE_THRESHOLD_DEFAULT 0.30 // Minimum limb damage required for fracture -#define FRACTURE_DAMAGE_THRESHOLD 0.50 +#define FRACTURE_DAMAGE_THRESHOLD EGVAR(medical,const_fractureDamageThreshold) +#define FRACTURE_DAMAGE_THRESHOLD_DEFAULT 0.50 // Minimum body part damage required for blood effect on uniform #define VISUAL_BODY_DAMAGE_THRESHOLD 0.35 From f1b2f2f2c4c38ff775139c9fb074752e80f8475d Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Tue, 15 Oct 2019 10:36:07 -0500 Subject: [PATCH 2/2] Add comments about varNames, calc k/l at runtime --- addons/medical_engine/XEH_preInit.sqf | 33 ++++++++++++------- .../medical_engine/script_macros_medical.hpp | 4 +-- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/addons/medical_engine/XEH_preInit.sqf b/addons/medical_engine/XEH_preInit.sqf index 252c36b0f95..de60e5f7f93 100644 --- a/addons/medical_engine/XEH_preInit.sqf +++ b/addons/medical_engine/XEH_preInit.sqf @@ -6,18 +6,27 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; -// Define "Constants" variables -HEAD_DAMAGE_THRESHOLD = HEAD_DAMAGE_THRESHOLD_DEFAULT; -ORGAN_DAMAGE_THRESHOLD = ORGAN_DAMAGE_THRESHOLD_DEFAULT; -FATAL_SUM_DAMAGE_WEIBULL_K = FATAL_SUM_DAMAGE_WEIBULL_K_DEFAULT; -FATAL_SUM_DAMAGE_WEIBULL_L = FATAL_SUM_DAMAGE_WEIBULL_L_DEFAULT; -HEART_HIT_CHANCE = HEART_HIT_CHANCE_DEFAULT; -PENETRATION_THRESHOLD = PENETRATION_THRESHOLD_DEFAULT; -BLOOD_LOSS_KNOCK_OUT_THRESHOLD = BLOOD_LOSS_KNOCK_OUT_THRESHOLD_DEFAULT; -PAIN_UNCONSCIOUS = PAIN_UNCONSCIOUS_DEFAULT; -PAIN_FADE_TIME = PAIN_FADE_TIME_DEFAULT; -LIMPING_DAMAGE_THRESHOLD = LIMPING_DAMAGE_THRESHOLD_DEFAULT; -FRACTURE_DAMAGE_THRESHOLD = FRACTURE_DAMAGE_THRESHOLD_DEFAULT; +// Define "Constants" variables (both are macros defined in script_macros_medical.hpp, look there for actual variable names) +if (isNil QUOTE(HEAD_DAMAGE_THRESHOLD)) then {HEAD_DAMAGE_THRESHOLD = HEAD_DAMAGE_THRESHOLD_DEFAULT}; +if (isNil QUOTE(ORGAN_DAMAGE_THRESHOLD)) then {ORGAN_DAMAGE_THRESHOLD = ORGAN_DAMAGE_THRESHOLD_DEFAULT}; +if (isNil QUOTE(HEART_HIT_CHANCE)) then {HEART_HIT_CHANCE = HEART_HIT_CHANCE_DEFAULT}; +if (isNil QUOTE(PENETRATION_THRESHOLD)) then {PENETRATION_THRESHOLD = PENETRATION_THRESHOLD_DEFAULT}; +if (isNil QUOTE(BLOOD_LOSS_KNOCK_OUT_THRESHOLD)) then {BLOOD_LOSS_KNOCK_OUT_THRESHOLD = BLOOD_LOSS_KNOCK_OUT_THRESHOLD_DEFAULT}; +if (isNil QUOTE(PAIN_UNCONSCIOUS)) then {PAIN_UNCONSCIOUS = PAIN_UNCONSCIOUS_DEFAULT}; +if (isNil QUOTE(PAIN_FADE_TIME)) then {PAIN_FADE_TIME = PAIN_FADE_TIME_DEFAULT}; +if (isNil QUOTE(LIMPING_DAMAGE_THRESHOLD)) then {LIMPING_DAMAGE_THRESHOLD = LIMPING_DAMAGE_THRESHOLD_DEFAULT}; +if (isNil QUOTE(FRACTURE_DAMAGE_THRESHOLD)) then {FRACTURE_DAMAGE_THRESHOLD = FRACTURE_DAMAGE_THRESHOLD_DEFAULT}; +// Derive the alternate fatal damage coefficents +if (isNil QUOTE(FATAL_SUM_DAMAGE_WEIBULL_K) || isNil QUOTE(FATAL_SUM_DAMAGE_WEIBULL_L)) then { + private _x1 = 0.5; + private _y1 = 0.1; + private _x2 = 0.8; + private _y2 = 0.9; + private _b1 = -ln (1-_y1); + private _b2 = -ln (1-_y2); + FATAL_SUM_DAMAGE_WEIBULL_K = ln(_b1/_b2) / ln(_x1/_x2); + FATAL_SUM_DAMAGE_WEIBULL_L = _x1 / _b1^(1/FATAL_SUM_DAMAGE_WEIBULL_K); +}; // Hack for #3168 (units in static weapons do not take any damage): // Doing a manual pre-load with a small distance seems to fix the LOD problems diff --git a/addons/medical_engine/script_macros_medical.hpp b/addons/medical_engine/script_macros_medical.hpp index 86578e84b1b..fcc6e2df36a 100644 --- a/addons/medical_engine/script_macros_medical.hpp +++ b/addons/medical_engine/script_macros_medical.hpp @@ -18,11 +18,9 @@ #define HEAD_DAMAGE_THRESHOLD_DEFAULT 1 #define ORGAN_DAMAGE_THRESHOLD EGVAR(medical,const_organDamageThreshold) #define ORGAN_DAMAGE_THRESHOLD_DEFAULT 0.6 -// Consts for determineIfFatal: sum of damage +// Consts for determineIfFatal: sum of damage (values are calcualted at runtime in preInit) #define FATAL_SUM_DAMAGE_WEIBULL_K EGVAR(medical,const_fatalSumDamageWeibull_K) -#define FATAL_SUM_DAMAGE_WEIBULL_K_DEFAULT 6.5625 #define FATAL_SUM_DAMAGE_WEIBULL_L EGVAR(medical,const_fatalSumDamageWeibull_L) -#define FATAL_SUM_DAMAGE_WEIBULL_L_DEFAULT 0.704523 // Chance to hit heart based on ratio of 70kg (approx. 70L) body to 70mL stroke volume of heart // Assuming torso is 50% of the body volume (35L)