From c31ef9e16b7e6f7122ea9535498d5c374d9929f0 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Mon, 5 Aug 2024 11:39:35 +0200 Subject: [PATCH] Medical AI - Add command actions to heal injured units (#10164) * Add AI command menu for healing * Moved actions to separate function * Minor cleanup --- addons/medical_ai/XEH_PREP.hpp | 1 + addons/medical_ai/XEH_postInit.sqf | 3 + .../fnc_addHealingCommandActions.sqf | 88 +++++++++++++++++++ 3 files changed, 92 insertions(+) create mode 100644 addons/medical_ai/functions/fnc_addHealingCommandActions.sqf diff --git a/addons/medical_ai/XEH_PREP.hpp b/addons/medical_ai/XEH_PREP.hpp index de4ac3c38a..3cf2b3e244 100644 --- a/addons/medical_ai/XEH_PREP.hpp +++ b/addons/medical_ai/XEH_PREP.hpp @@ -1,3 +1,4 @@ +PREP(addHealingCommandActions); PREP(canRequestMedic); PREP(healingLogic); PREP(healSelf); diff --git a/addons/medical_ai/XEH_postInit.sqf b/addons/medical_ai/XEH_postInit.sqf index 248c634156..9ddd8273fd 100644 --- a/addons/medical_ai/XEH_postInit.sqf +++ b/addons/medical_ai/XEH_postInit.sqf @@ -20,6 +20,9 @@ _unit setVariable [QGVAR(lastSuppressed), CBA_missionTime]; }] call CBA_fnc_addClassEventHandler; + // Add command actions to command AI medics to treat other units + call FUNC(addHealingCommandActions); + if (GVAR(requireItems) == 2) then { ["CAManBase", "InitPost", { [{ diff --git a/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf b/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf new file mode 100644 index 0000000000..cc91ca7eb3 --- /dev/null +++ b/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf @@ -0,0 +1,88 @@ +#include "..\script_component.hpp" +/* + * Author: johnb43 + * Adds ACE actions for the player to command medics to heal injured units. + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * call ace_medical_ai_fnc_addHealingCommandActions + * + * Public: No + */ + +if (!hasInterface) exitWith {}; + +private _action = [ + QGVAR(heal), + localize "STR_A3_Task180_name", + "", + {}, + {_player == leader _player}, + { + private _units = units _player; + + (_units select {_x call EFUNC(common,isAwake) && {_x call EFUNC(medical_treatment,isMedic)} && {!(_x call EFUNC(common,isPlayer))}}) apply { + [ + [ + QGVAR(medicHeal_) + str _x, + format ["%1: (%2)", [_x, false, true] call EFUNC(common,getName), groupID _x], + "", + {}, + {true}, + { + (_this select 2) params ["_healer", "_units"]; + + (_units select {_x call FUNC(isInjured)}) apply { + [ + [ + QGVAR(healUnit_) + str _x, + format [localize "str_action_heal_soldier", ([_x, false, true] call EFUNC(common,getName)) + " (" + str groupID _x + ")"], + "", + { + (_this select 2) params ["_healer", "_target"]; + + private _assignedMedic = _target getVariable [QGVAR(assignedMedic), objNull]; + + // Remove from previous medic's queue + if (!isNull _assignedMedic && {_healer != _assignedMedic}) then { + private _healQueue = _assignedMedic getVariable [QGVAR(healQueue), []]; + + _healQueue deleteAt (_healQueue find _target); + + _assignedMedic setVariable [QGVAR(healQueue), _healQueue]; + }; + + _target setVariable [QGVAR(assignedMedic), _healer]; + + // Add to new medic + private _healQueue = _healer getVariable [QGVAR(healQueue), []]; + + _healQueue deleteAt (_healQueue find _target); + _healQueue insert [0, [_target]]; + + _healer setVariable [QGVAR(healQueue), _healQueue]; + }, + {true}, + {}, + [_healer, _x] + ] call EFUNC(interact_menu,createAction), + [], + _x + ] + }; + }, + [_x, _units] + ] call EFUNC(interact_menu,createAction), + [], + _x + ] + }; + } +] call EFUNC(interact_menu,createAction); + +["CAManBase", 1, ["ACE_SelfActions"], _action, true] call EFUNC(interact_menu,addActionToClass);