-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Medical - Add medication dosage support & improve overdose (#10393)
* Initial Commit * Small fix to get all medications * Update launch.toml * Small fix and removal of medication dose variables * Deleted old entries from stringtable * Update addons/medical_treatment/script_component.hpp Co-authored-by: Grim <[email protected]> * Fixed newline * Changes for backwards compatibility * Update addons/medical_status/functions/fnc_addMedicationAdjustment.sqf Co-authored-by: Grim <[email protected]> * Update addons/medical_status/functions/fnc_getAllMedicationCount.sqf Co-authored-by: Grim <[email protected]> * Update addons/medical_status/functions/fnc_getAllMedicationCount.sqf Co-authored-by: Grim <[email protected]> * Fixes, maybe? * Overdose fixes * trailling comma * Update addons/medical_vitals/functions/fnc_handleUnitVitals.sqf * aa * there we go * Update addons/medical_treatment/functions/fnc_onMedicationUsage.sqf Co-authored-by: Jouni Järvinen <[email protected]> * Update addons/medical_treatment/functions/fnc_onMedicationUsage.sqf Co-authored-by: Jouni Järvinen <[email protected]> * Update XEH_PREP.hpp * Update addons/medical_status/functions/fnc_getAllMedicationCount.sqf Co-authored-by: Grim <[email protected]> * Grim Misc Fixes * Remove debug * Small fixes * newline * headers * code cleanup * more headers * drop unneeded _dose * last header * fix getting overdose func/code * whitespace * now the last header * Update addons/medical_treatment/functions/fnc_overDose.sqf Co-authored-by: Grim <[email protected]> * fix compiling nil * Update addons/medical_status/functions/fnc_addMedicationAdjustment.sqf Co-authored-by: johnb432 <[email protected]> * Fixes * Update addons/medical_treatment/functions/fnc_overDose.sqf Co-authored-by: johnb432 <[email protected]> * Update fnc_overDose.sqf * Update addons/medical_status/functions/fnc_addMedicationAdjustment.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_treatment/functions/fnc_overDose.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_treatment/functions/fnc_onMedicationUsage.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_status/functions/fnc_addMedicationAdjustment.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_status/functions/fnc_getMedicationCount.sqf Co-authored-by: johnb432 <[email protected]> * Fixes * Moving med settings to different PR * oopps * Stringtable * Misc fixes & cleanup * Update fnc_onMedicationUsage.sqf * Fix nonsensical code * add API event and doc * Misc fixes * Update ACE_Medical_Treatment.hpp * Update watchVariable.sqf * Update addons/medical_treatment/ACE_Medical_Treatment.hpp Co-authored-by: johnb432 <[email protected]> * Update ACE_Medical_Treatment.hpp --------- Co-authored-by: Grim <[email protected]> Co-authored-by: Jouni Järvinen <[email protected]> Co-authored-by: johnb432 <[email protected]>
- Loading branch information
1 parent
d8b3cda
commit e31aba5
Showing
12 changed files
with
134 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
addons/medical_status/functions/fnc_getAllMedicationCount.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: PabstMirror, Cplhardcore | ||
* Gets effective count of all medications in a unit's system | ||
* (each medication dose is scaled from 0..1 based on time till max effect and max time in system) | ||
* | ||
* Arguments: | ||
* 0: The patient <OBJECT> | ||
* 1: Get raw count (true) or effect ratio (false) <BOOL> (default: true) | ||
* | ||
* Return Value: | ||
* Array of medication counts <ARRAY of ARRAY>: | ||
* 0: Medication Name <String> | ||
* 1: Dose Count <NUMBER> | ||
* 2: Medication effectiveness (0-1) <NUMBER> | ||
* | ||
* Example: | ||
* [player] call ace_medical_status_fnc_getAllMedicationCount | ||
* | ||
* Public: Yes | ||
*/ | ||
|
||
params ["_target", ["_getCount", true]]; | ||
|
||
private _medicationClasses = (_target getVariable [VAR_MEDICATIONS, []]) apply {_x select 0}; | ||
_medicationClasses = _medicationClasses arrayIntersect _medicationClasses; | ||
_medicationClasses apply {[_x] + ([_target, _x, _getCount] call FUNC(getMedicationCount))} // return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 18 additions & 36 deletions
54
addons/medical_treatment/functions/fnc_onMedicationUsage.sqf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,50 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Glowbal | ||
* Author: Glowbal, Cplhardcore | ||
* Handles the medication given to a patient. | ||
* | ||
* Arguments: | ||
* 0: The patient <OBJECT> | ||
* 0: Patient <OBJECT> | ||
* 1: Medication Treatment classname <STRING> | ||
* 2: Max dose (0 to ignore) <NUMBER> | ||
* 3: Max dose deviation <NUMBER> | ||
* 3: Incompatable medication <ARRAY<STRING>> | ||
* 2: Incompatible medication <ARRAY of <STRING, NUMBER>> | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [player, "morphine", 4, 2, [["x", 1]]] call ace_medical_treatment_fnc_onMedicationUsage | ||
* [player, "morphine", [["x", 1]]] call ace_medical_treatment_fnc_onMedicationUsage | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_target", "_className", "_maxDose", "_maxDoseDeviation", "_incompatibleMedication"]; | ||
TRACE_5("onMedicationUsage",_target,_className,_maxDose,_maxDoseDeviation,_incompatibleMedication); | ||
|
||
private _overdosedMedications = []; | ||
params ["_target", "_className", "_incompatibleMedication"]; | ||
TRACE_3("onMedicationUsage",_target,_className,_incompatibleMedication); | ||
|
||
// Check for overdose from current medication | ||
private _defaultConfig = configFile >> QUOTE(ADDON) >> "Medication"; | ||
private _medicationConfig = _defaultConfig >> _classname; | ||
private _maxDose = GET_NUMBER(_medicationConfig >> "maxDose",getNumber (_defaultConfig >> "maxDose")); | ||
|
||
if (_maxDose > 0) then { | ||
private _currentDose = [_target, _className] call EFUNC(medical_status,getMedicationCount); | ||
private _maxDoseDeviation = GET_NUMBER(_medicationConfig >> "maxDoseDeviation",getNumber (_defaultConfig >> "maxDoseDeviation")); | ||
private _currentDose = [_target, _className] call EFUNC(medical_status,getMedicationCount) select 0; | ||
// Because both {floor random 0} and {floor random 1} return 0 | ||
if (_maxDoseDeviation > 0) then { | ||
_maxDoseDeviation = _maxDoseDeviation + 1; | ||
}; | ||
|
||
if (_currentDose > _maxDose + (floor random _maxDoseDeviation)) then { | ||
private _limit = _maxDose + (floor random _maxDoseDeviation); | ||
if (_currentDose > _limit) then { | ||
TRACE_1("exceeded max dose",_currentDose); | ||
_overdosedMedications pushBackUnique _className; | ||
[_target, _classname, _currentDose, _limit, _classname] call FUNC(overDose); | ||
}; | ||
}; | ||
|
||
// Check incompatible medication (format [med,limit]) | ||
{ | ||
_x params ["_xMed", "_xLimit"]; | ||
private _inSystem = [_target, _xMed] call EFUNC(medical_status,getMedicationCount); | ||
if (_inSystem> _xLimit) then { | ||
_overdosedMedications pushBackUnique _xMed; | ||
private _inSystem = ([_target, _xMed] call EFUNC(medical_status,getMedicationCount)) select 0; | ||
if (_inSystem > _xLimit) then { | ||
[_target, _classname, _inSystem, _xLimit, _xMed] call FUNC(overDose); | ||
}; | ||
} forEach _incompatibleMedication; | ||
|
||
if (_overdosedMedications isNotEqualTo []) then { | ||
private _medicationConfig = (configFile >> "ace_medical_treatment" >> "Medication"); | ||
private _onOverDose = getText (_medicationConfig >> "onOverDose"); | ||
if (isClass (_medicationConfig >> _className)) then { | ||
_medicationConfig = (_medicationConfig >> _className); | ||
if (isText (_medicationConfig >> "onOverDose")) then { _onOverDose = getText (_medicationConfig >> "onOverDose"); }; | ||
}; | ||
TRACE_2("overdose",_overdosedMedications,_onOverDose); | ||
if (_onOverDose == "") exitWith { | ||
TRACE_1("CriticalVitals Event",_target); // make unconscious | ||
[QEGVAR(medical,CriticalVitals), _target] call CBA_fnc_localEvent; | ||
}; | ||
if (isNil _onOverDose) then { | ||
_onOverDose = compile _onOverDose; | ||
} else { | ||
_onOverDose = missionNamespace getVariable _onOverDose; | ||
}; | ||
[_target, _className, _overdosedMedications] call _onOverDose; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "..\script_component.hpp" | ||
/* | ||
* Author: Cplhardcore | ||
* Handles the overdose effects of a medication. | ||
* | ||
* Arguments: | ||
* 0: Patient <OBJECT> | ||
* 1: Medication classname <STRING> | ||
* 2: Medication dosage <NUMBER> | ||
* 3: Overdose threshold <NUMBER> | ||
* 4: Incompatible medication that caused overdose (can be the medication itself) <STRING> (default: "") | ||
* | ||
* Return Value: | ||
* None | ||
* | ||
* Example: | ||
* [player, "morphine", 5, 3, "morphine"] call ace_medical_treatment_fnc_overDose | ||
* | ||
* Public: No | ||
*/ | ||
|
||
params ["_unit", "_classname", "_dose", "_limit", "_incompatibleMed"]; | ||
|
||
private _medicationConfig = configFile >> QUOTE(ADDON) >> "Medication"; | ||
private _onOverDose = getText (_medicationConfig >> "onOverDose"); | ||
|
||
if (isClass _medicationConfig) then { | ||
_medicationConfig = _medicationConfig >> _classname; | ||
if (isText (_medicationConfig >> "onOverDose")) then { | ||
_onOverDose = getText (_medicationConfig >> "onOverDose"); | ||
}; | ||
}; | ||
TRACE_2("overdose",_classname,_onOverDose); | ||
|
||
[QEGVAR(medical,overdose), [_unit, _classname, _dose, _limit, _incompatibleMed]] call CBA_fnc_localEvent; | ||
|
||
if (_onOverDose == "") exitWith { | ||
TRACE_1("CriticalVitals Event",_unit); | ||
[QEGVAR(medical,CriticalVitals), _unit] call CBA_fnc_localEvent; | ||
}; | ||
|
||
_onOverDose = if (missionNamespace isNil _onOverDose) then { | ||
compile _onOverDose | ||
} else { | ||
missionNamespace getVariable _onOverDose | ||
}; | ||
|
||
[_unit, _classname, _dose, _limit, _incompatibleMed] call _onOverDose |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters