Skip to content

Commit

Permalink
Medical Damage - Improve custom wound handling (#9310)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 authored Aug 11, 2024
1 parent be23ae7 commit c8e7b63
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 12 deletions.
6 changes: 6 additions & 0 deletions addons/medical_damage/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};

class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
4 changes: 4 additions & 0 deletions addons/medical_damage/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "script_component.hpp"

// Reload configs (handle functions being compiled after medical_damage's preInit)
call FUNC(parseConfigForInjuries);
2 changes: 2 additions & 0 deletions addons/medical_damage/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ PREP_RECOMPILE_END;

call FUNC(parseConfigForInjuries);

/*
addMissionEventHandler ["Loaded",{
INFO("Mission Loaded - Reloading medical configs for extension");
// Reload configs into extension (handle full game restart)
call FUNC(parseConfigForInjuries);
}];
*/

[QEGVAR(medical,woundReceived), LINKFUNC(woundReceived)] call CBA_fnc_addEventHandler;

Expand Down
39 changes: 29 additions & 10 deletions addons/medical_damage/functions/fnc_parseWoundHandlersCfg.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "..\script_component.hpp"
/*
* Author: Pterolatypus
* Read a list of wound handler entries from config, accounting for inheritance
* Read a list of wound handler entries from config, accounting for inheritance.
*
* Arguments:
* 0: The config class containing the entries <CONFIG>
Expand All @@ -10,24 +10,43 @@
* None
*
* Example:
* [configFile >> "ace_medical_injuries" >> "damageTypes"] call ace_medical_damage_fnc_parseWoundHandlersCfg
* [configFile >> "ace_medical_injuries" >> "damageTypes" >> "woundHandlers"] call ace_medical_damage_fnc_parseWoundHandlersCfg
*
* Public: No
*/

params ["_config"];

// read all valid entries from config and store
// Read all valid entries from config and store
private _entries = [];

{
private _entryResult = call compile getText _x;
if !(isNil "_entryResult") then {
_entries pushBack _entryResult;
}
private _entryResult = getText _x;

if (_entryResult != "") then {
if (ADDON) then {
// Runs in postInit
_entryResult = call compile _entryResult;

if (!isNil "_entryResult") then {
if (_entryResult isEqualType {}) then {
_entries pushBack _entryResult;
} else {
ERROR_2("Wound handler '%1' needs to be a function, but is of type %2.",configName _x,toLowerANSI typeName _entryResult);
};
};
} else {
// Runs in preInit
// In case function doesn't exist yet, wrap in extra layer
_entries pushBack (compile format ["call %1", _entryResult]);
};
};
} forEach configProperties [_config, "isText _x", false];

private _parent = inheritsFrom _config;

if (isNull _parent) exitWith {_entries};

// recursive call for parent
// can't use configProperties for inheritance since it returns entries in the wrong order
([_parent] call FUNC(parseWoundHandlersCfg)) + _entries;
// Recursive call for parent
// Can't use configProperties for inheritance since it returns entries in the wrong order
([_parent] call FUNC(parseWoundHandlersCfg)) + _entries // return
9 changes: 7 additions & 2 deletions addons/medical_damage/functions/fnc_woundReceived.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,23 @@
*
* Public: No
*/

params ["_unit", "_allDamages", "_shooter", "_ammo"];

private _typeOfDamage = _ammo call FUNC(getTypeOfDamage);

if (_typeOfDamage in GVAR(damageTypeDetails)) then {
(GVAR(damageTypeDetails) get _typeOfDamage) params ["", "", "_woundHandlers"];

private _damageData = [_unit, _allDamages, _typeOfDamage];

{
_damageData = _damageData call _x;
TRACE_1("Wound handler returned",_damageData);
if !(_damageData isEqualType [] && {(count _damageData) >= 3}) exitWith {
TRACE_1("Return invalid, terminating wound handling",_damageData);

// If invalid return, exit
if (isNil "_damageData" || {!(_damageData isEqualType [])} || {(count _damageData) < 3}) exitWith {
TRACE_1("Return invalid, skipping wound handling",_damageData);
};
} forEach _woundHandlers;
};

0 comments on commit c8e7b63

Please sign in to comment.