Medical Damage - Improve custom wound handling (#9310)

This commit is contained in:
johnb432 2024-08-12 01:28:51 +02:00 committed by GitHub
parent be23ae7ecd
commit c8e7b6396b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 12 deletions

View File

@ -9,3 +9,9 @@ class Extended_PreInit_EventHandlers {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit)); init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
}; };
}; };
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};

View File

@ -0,0 +1,4 @@
#include "script_component.hpp"
// Reload configs (handle functions being compiled after medical_damage's preInit)
call FUNC(parseConfigForInjuries);

View File

@ -10,11 +10,13 @@ PREP_RECOMPILE_END;
call FUNC(parseConfigForInjuries); call FUNC(parseConfigForInjuries);
/*
addMissionEventHandler ["Loaded",{ addMissionEventHandler ["Loaded",{
INFO("Mission Loaded - Reloading medical configs for extension"); INFO("Mission Loaded - Reloading medical configs for extension");
// Reload configs into extension (handle full game restart) // Reload configs into extension (handle full game restart)
call FUNC(parseConfigForInjuries); call FUNC(parseConfigForInjuries);
}]; }];
*/
[QEGVAR(medical,woundReceived), LINKFUNC(woundReceived)] call CBA_fnc_addEventHandler; [QEGVAR(medical,woundReceived), LINKFUNC(woundReceived)] call CBA_fnc_addEventHandler;

View File

@ -1,7 +1,7 @@
#include "..\script_component.hpp" #include "..\script_component.hpp"
/* /*
* Author: Pterolatypus * 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: * Arguments:
* 0: The config class containing the entries <CONFIG> * 0: The config class containing the entries <CONFIG>
@ -10,24 +10,43 @@
* None * None
* *
* Example: * 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 * Public: No
*/ */
params ["_config"]; params ["_config"];
// read all valid entries from config and store // Read all valid entries from config and store
private _entries = []; private _entries = [];
{ {
private _entryResult = call compile getText _x; private _entryResult = getText _x;
if !(isNil "_entryResult") then {
if (_entryResult != "") then {
if (ADDON) then {
// Runs in postInit
_entryResult = call compile _entryResult;
if (!isNil "_entryResult") then {
if (_entryResult isEqualType {}) then {
_entries pushBack _entryResult; _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]; } forEach configProperties [_config, "isText _x", false];
private _parent = inheritsFrom _config; private _parent = inheritsFrom _config;
if (isNull _parent) exitWith {_entries}; if (isNull _parent) exitWith {_entries};
// recursive call for parent // Recursive call for parent
// can't use configProperties for inheritance since it returns entries in the wrong order // Can't use configProperties for inheritance since it returns entries in the wrong order
([_parent] call FUNC(parseWoundHandlersCfg)) + _entries; ([_parent] call FUNC(parseWoundHandlersCfg)) + _entries // return

View File

@ -17,18 +17,23 @@
* *
* Public: No * Public: No
*/ */
params ["_unit", "_allDamages", "_shooter", "_ammo"]; params ["_unit", "_allDamages", "_shooter", "_ammo"];
private _typeOfDamage = _ammo call FUNC(getTypeOfDamage); private _typeOfDamage = _ammo call FUNC(getTypeOfDamage);
if (_typeOfDamage in GVAR(damageTypeDetails)) then { if (_typeOfDamage in GVAR(damageTypeDetails)) then {
(GVAR(damageTypeDetails) get _typeOfDamage) params ["", "", "_woundHandlers"]; (GVAR(damageTypeDetails) get _typeOfDamage) params ["", "", "_woundHandlers"];
private _damageData = [_unit, _allDamages, _typeOfDamage]; private _damageData = [_unit, _allDamages, _typeOfDamage];
{ {
_damageData = _damageData call _x; _damageData = _damageData call _x;
TRACE_1("Wound handler returned",_damageData); 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; } forEach _woundHandlers;
}; };