From da5e9525b4743631d6a3bc243116e65948364509 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Sun, 20 Oct 2019 11:14:31 -0500 Subject: [PATCH] Medical - Make some constants variables (#7236) * Medical - Make some constants variables * Add comments about varNames, calc k/l at runtime --- .../functions/fnc_determineIfFatal.sqf | 5 +--- addons/medical_engine/XEH_preInit.sqf | 22 ++++++++++++++ .../medical_engine/script_macros_medical.hpp | 30 +++++++++++++------ 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/addons/medical_damage/functions/fnc_determineIfFatal.sqf b/addons/medical_damage/functions/fnc_determineIfFatal.sqf index fc674cf75b..e20238f054 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 18bc483c55..de60e5f7f9 100644 --- a/addons/medical_engine/XEH_preInit.sqf +++ b/addons/medical_engine/XEH_preInit.sqf @@ -6,6 +6,28 @@ PREP_RECOMPILE_START; #include "XEH_PREP.hpp" PREP_RECOMPILE_END; +// 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 // 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 7f50866f0e..fcc6e2df36 100644 --- a/addons/medical_engine/script_macros_medical.hpp +++ b/addons/medical_engine/script_macros_medical.hpp @@ -14,12 +14,18 @@ #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 (values are calcualted at runtime in preInit) +#define FATAL_SUM_DAMAGE_WEIBULL_K EGVAR(medical,const_fatalSumDamageWeibull_K) +#define FATAL_SUM_DAMAGE_WEIBULL_L EGVAR(medical,const_fatalSumDamageWeibull_L) // 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 +59,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 +73,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 +88,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