Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Medical AI - Add command actions to heal injured units #10164

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/medical_ai/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(addHealingCommandActions);
PREP(canRequestMedic);
PREP(healingLogic);
PREP(healSelf);
Expand Down
3 changes: 3 additions & 0 deletions addons/medical_ai/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
[{
Expand Down
88 changes: 88 additions & 0 deletions addons/medical_ai/functions/fnc_addHealingCommandActions.sqf
Original file line number Diff line number Diff line change
@@ -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);
4 changes: 4 additions & 0 deletions addons/medical_ai/functions/fnc_healUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down