From 72c18a6cb1eb3e644df8d75ace9b382e4cae873f Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:16:48 +0200 Subject: [PATCH 1/3] Add AI command menu for healing --- addons/medical_ai/XEH_postInit.sqf | 66 ++++++++++++++++++++ addons/medical_ai/functions/fnc_healUnit.sqf | 4 ++ 2 files changed, 70 insertions(+) diff --git a/addons/medical_ai/XEH_postInit.sqf b/addons/medical_ai/XEH_postInit.sqf index 248c6341569..e9a29b39b0d 100644 --- a/addons/medical_ai/XEH_postInit.sqf +++ b/addons/medical_ai/XEH_postInit.sqf @@ -20,6 +20,72 @@ _unit setVariable [QGVAR(lastSuppressed), CBA_missionTime]; }] call CBA_fnc_addClassEventHandler; + // Add command actions to command AI medics to treat other units + if (hasInterface && {GVAR(requireItems) > 0}) then { + private _action = [QGVAR(heal), "Command Healing", "", {}, {_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, + [_x, false, true] call EFUNC(common,getName), + "", + {}, + {true}, + { + (_this select 2) params ["_healer", "_units"]; + + (_units select {_x call FUNC(isInjured)}) apply { + [ + [ + QGVAR(healUnit_) + str _x, + format ["%1: %2", "Heal", [_x, false, true] call EFUNC(common,getName)], + "", + { + (_this select 2) params ["_healer", "_target"]; + + private _assignedMedic = _target getVariable [QGVAR(assignedMedic), objNull]; + + // Remove from previous medic's queue + if (!isNull _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); + }; + if (GVAR(requireItems) == 2) then { ["CAManBase", "InitPost", { [{ diff --git a/addons/medical_ai/functions/fnc_healUnit.sqf b/addons/medical_ai/functions/fnc_healUnit.sqf index 3635088820e..319d5533b16 100644 --- a/addons/medical_ai/functions/fnc_healUnit.sqf +++ b/addons/medical_ai/functions/fnc_healUnit.sqf @@ -47,6 +47,10 @@ if (_this distance _target > 2.5) exitWith { _this setVariable [QGVAR(currentTreatment), nil]; if (CBA_missionTime >= (_this getVariable [QGVAR(nextMoveOrder), CBA_missionTime])) then { _this setVariable [QGVAR(nextMoveOrder), CBA_missionTime + 10]; + + // Medic, when doing a lot of treatment, moves away from injured over time (because of animations) + // Need to allow the medic to move back to the injured again + _this forceSpeed -1; _this doMove getPosATL _target; #ifdef DEBUG_MODE_FULL systemChat format ["%1 moving to %2", _this, _target]; From f14eb0de93a29056301023903575850878d35bd3 Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 4 Aug 2024 16:58:40 +0200 Subject: [PATCH 2/3] Moved actions to separate function --- addons/medical_ai/XEH_PREP.hpp | 1 + addons/medical_ai/XEH_postInit.sqf | 65 +------------- .../fnc_addHealingCommandActions.sqf | 86 +++++++++++++++++++ 3 files changed, 89 insertions(+), 63 deletions(-) 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 de4ac3c38a3..3cf2b3e2441 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 e9a29b39b0d..9684247c67f 100644 --- a/addons/medical_ai/XEH_postInit.sqf +++ b/addons/medical_ai/XEH_postInit.sqf @@ -21,69 +21,8 @@ }] call CBA_fnc_addClassEventHandler; // Add command actions to command AI medics to treat other units - if (hasInterface && {GVAR(requireItems) > 0}) then { - private _action = [QGVAR(heal), "Command Healing", "", {}, {_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, - [_x, false, true] call EFUNC(common,getName), - "", - {}, - {true}, - { - (_this select 2) params ["_healer", "_units"]; - - (_units select {_x call FUNC(isInjured)}) apply { - [ - [ - QGVAR(healUnit_) + str _x, - format ["%1: %2", "Heal", [_x, false, true] call EFUNC(common,getName)], - "", - { - (_this select 2) params ["_healer", "_target"]; - - private _assignedMedic = _target getVariable [QGVAR(assignedMedic), objNull]; - - // Remove from previous medic's queue - if (!isNull _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); + if (hasInterface) then { + call FUNC(addHealingCommandActions); }; if (GVAR(requireItems) == 2) then { diff --git a/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf b/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf new file mode 100644 index 00000000000..150cb76ec04 --- /dev/null +++ b/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf @@ -0,0 +1,86 @@ +#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: + * player call ace_medical_ai_fnc_addHealingCommandActions + * + * Public: No + */ + +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); From ac0e0c5eda4fc9c4698c481f0da5a88afaf4c4af Mon Sep 17 00:00:00 2001 From: johnb432 <58661205+johnb432@users.noreply.github.com> Date: Sun, 4 Aug 2024 17:00:58 +0200 Subject: [PATCH 3/3] Minor cleanup --- addons/medical_ai/XEH_postInit.sqf | 4 +--- addons/medical_ai/functions/fnc_addHealingCommandActions.sqf | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/medical_ai/XEH_postInit.sqf b/addons/medical_ai/XEH_postInit.sqf index 9684247c67f..9ddd8273fdf 100644 --- a/addons/medical_ai/XEH_postInit.sqf +++ b/addons/medical_ai/XEH_postInit.sqf @@ -21,9 +21,7 @@ }] call CBA_fnc_addClassEventHandler; // Add command actions to command AI medics to treat other units - if (hasInterface) then { - call FUNC(addHealingCommandActions); - }; + 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 index 150cb76ec04..cc91ca7eb3c 100644 --- a/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf +++ b/addons/medical_ai/functions/fnc_addHealingCommandActions.sqf @@ -10,11 +10,13 @@ * None * * Example: - * player call ace_medical_ai_fnc_addHealingCommandActions + * call ace_medical_ai_fnc_addHealingCommandActions * * Public: No */ +if (!hasInterface) exitWith {}; + private _action = [ QGVAR(heal), localize "STR_A3_Task180_name",