ACE3/addons/medical_ai/functions/fnc_healUnit.sqf
johnb432 cd678c5b90
Medical AI - Add tourniquet support (#10158)
Add tourniquet support for Medical AI
2024-08-05 02:39:01 -07:00

66 lines
2.0 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: BaerMitUmlaut
* Makes a medic heal the next unit that needs treatment.
*
* Arguments:
* Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* cursorObject call ace_medical_ai_fnc_healUnit
*
* Public: No
*/
// Player will have to do this manually of course
if ([_this] call EFUNC(common,isPlayer)) exitWith {};
// Can't heal other units when unconscious
if IS_UNCONSCIOUS(_this) exitWith {
_this setVariable [QGVAR(currentTreatment), nil];
};
// Find next unit to treat
private _healQueue = _this getVariable [QGVAR(healQueue), []];
private _target = _healQueue param [0, objNull];
// If unit died or was healed, be lazy and wait for the next tick
if (!alive _target || {!(_target call FUNC(isInjured))}) exitWith {
_this forceSpeed -1;
_target forceSpeed -1;
_healQueue deleteAt 0;
_this setVariable [QGVAR(healQueue), _healQueue];
// return to formation instead of going where the injured unit was if it healed itself in the mean time
_this doFollow leader _this;
_this setVariable [QGVAR(nextMoveOrder), nil];
_this setVariable [QGVAR(currentTreatment), nil];
#ifdef DEBUG_MODE_FULL
systemChat format ["%1 finished healing %2", _this, _target];
#endif
};
// Move to target...
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];
#endif
};
};
// ...and make sure medic and target don't move
_this forceSpeed 0;
_target forceSpeed 0;
[_this, _target] call FUNC(healingLogic);