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 - Adjust healing logic for rewrite #6902

Merged
merged 17 commits into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from 13 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
6 changes: 5 additions & 1 deletion addons/medical/dev/debugDisplay.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@

if (!isNull cursorTarget && {cursorTarget isKindOf "CAManBase"}) then {
private _targetState = [cursorTarget, EGVAR(medical,STATE_MACHINE)] call CBA_statemachine_fnc_getCurrentState;
drawIcon3D ["", [0.6, 0, 0, 1], cursorTarget modelToWorldVisual (cursorTarget selectionPosition "pelvis"), 0, 0, 0, format ["State: %1", _targetState], 2, 40 * pixelH, "RobotoCondensed"];
private _targetStateAI = "";
if (!isNil QEGVAR(medical_ai,stateMachine)) then {
_targetStateAI = [cursorTarget, EGVAR(medical_ai,stateMachine)] call CBA_statemachine_fnc_getCurrentState;
};
drawIcon3D ["", [0.6, 0, 0, 1], cursorTarget modelToWorldVisual (cursorTarget selectionPosition "pelvis"), 0, 0, 0, format ["State: %1 / %2", _targetState,_targetStateAI], 2, 40 * pixelH, "RobotoCondensed"];
};
}, 0 ,[]] call CBA_fnc_addPerFrameHandler;
}, []] call CBA_fnc_waitUntilAndExecute;
86 changes: 0 additions & 86 deletions addons/medical_ai/StateMachine.hpp

This file was deleted.

1 change: 1 addition & 0 deletions addons/medical_ai/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PREP(canRequestMedic);
PREP(healingLogic);
PREP(healSelf);
PREP(healUnit);
PREP(isInjured);
Expand Down
27 changes: 3 additions & 24 deletions addons/medical_ai/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,35 +1,14 @@
#include "script_component.hpp"

/*["ace_settingsInitialized", {
["ace_settingsInitialized", {
TRACE_1("settingsInitialized", GVAR(enabledFor));
if (GVAR(enabledFor) == 0) exitWith {}; // 0: disabled
if ((GVAR(enabledFor) == 1) && {!isServer} && {hasInterface}) exitWith {}; // 1: Don't Run on non-hc Clients

// Only run for AI that does not have to deal with advanced medical
if (EGVAR(medical,enableFor) == 1 || {hasInterface}) exitWith {};

["ace_firedNonPlayer", {
_unit setVariable [QGVAR(lastFired), CBA_missionTime];
}] call CBA_fnc_addEventHandler;

if (hasInterface) then {
["ace_unconscious", {
params ["_unit", "_unconscious"];
if (!_unconscious || {_unit != ACE_player}) exitWith {};

private _medic = objNull;
{
if ((!isPlayer _x) && {[_x] call EFUNC(medical_treatment,isMedic)}) exitWith {
_medic = _x;
};
} forEach (units _unit);
if (isNull _medic) exitWith {};

private _healQueue = _medic getVariable [QGVAR(healQueue), []];
_healQueue pushBack _unit;
_medic setVariable [QGVAR(healQueue), _healQueue];
}] call CBA_fnc_addEventHandler;
};
#include "stateMachine.sqf"
}] call CBA_fnc_addEventHandler;

GVAR(statemachine) = [configFile >> "ACE_Medical_AI_StateMachine"] call CBA_statemachine_fnc_createFromConfig;
}] call CBA_fnc_addEventHandler;*/
1 change: 0 additions & 1 deletion addons/medical_ai/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ class CfgPatches {

#include "ACE_Settings.hpp"
#include "CfgEventHandlers.hpp"
#include "StateMachine.hpp"
16 changes: 10 additions & 6 deletions addons/medical_ai/functions/fnc_canRequestMedic.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Can request medic <BOOL>
*
* Example:
* call ACE_medical_ai_fnc_canRequestMedic
* player call ACE_medical_ai_fnc_canRequestMedic
*
* Public: No
*/
Expand All @@ -21,10 +21,14 @@

if ([_this] call EFUNC(medical_treatment,isMedic) || {vehicle _this != _this}) exitWith {false};

// Search for a medic, prioritize unitReady
private _medic = objNull;
{
if ([_x] call EFUNC(medical_treatment,isMedic) && {!([_x] call EFUNC(common,isPlayer))}) exitWith {
_this setVariable [QGVAR(assignedMedic), _x];
true
};
false
if ([_x] call EFUNC(medical_treatment,isMedic) && {!([_x] call EFUNC(common,isPlayer))} && {
_medic = _x;
(unitReady _medic)
}) exitWith {};
} forEach (units _this);

_this setVariable [QGVAR(assignedMedic), _medic];
!isNull _medic
41 changes: 4 additions & 37 deletions addons/medical_ai/functions/fnc_healSelf.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,8 @@
// Player will have to do this manually of course
if ([_this] call EFUNC(common,isPlayer)) exitWith {};
// Can't heal self when unconscious
if IS_UNCONSCIOUS(_this) exitWith {};
// Check if we're still treating
if ((_this getVariable [QGVAR(treatmentOverAt), CBA_missionTime]) > CBA_missionTime) exitWith {};

private _needsBandaging = GET_BLOOD_LOSS(_this) > 0;
private _needsMorphine = GET_PAIN(_this) > 0.2;

switch (true) do {
case _needsBandaging: {
// Select first wound and bandage it
private _openWounds = _this getVariable [QEGVAR(medical,openWounds), []];
private _partIndex = {
_x params ["", "", "_index", "_amount", "_percentage"];
if (_amount * _percentage > 0) exitWith {
_index
};
} forEach _openWounds;
private _selection = ALL_BODY_PARTS select _partIndex;
[_this, "BasicBandage", _selection] call EFUNC(medical_treatment,treatmentBandageLocal);

#ifdef DEBUG_MODE_FULL
systemChat format ["%1 is bandaging selection %2", _this, _selection];
#endif

// Play animation
[_this, true, true] call FUNC(playTreatmentAnim);
_this setVariable [QGVAR(treatmentOverAt), CBA_missionTime + 5];
};
case _needsMorphine: {
[_this, "Morphine", 2] call EFUNC(medical_treatment,treatmentMedicationLocal);
[_this, false, true] call FUNC(playTreatmentAnim);
_this setVariable [QGVAR(treatmentOverAt), CBA_missionTime + 2];

#ifdef DEBUG_MODE_FULL
systemChat format ["%1 is giving himself morphine", _this];
#endif
};
if IS_UNCONSCIOUS(_this) exitWith {
_this setVariable [QGVAR(currentTreatment), nil];
};

[_this, _this] call FUNC(healingLogic);
75 changes: 18 additions & 57 deletions addons/medical_ai/functions/fnc_healUnit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,86 +14,47 @@
*
* 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 {};
// Check if we're still treating
if ((_this getVariable [QGVAR(treatmentOverAt), CBA_missionTime]) > CBA_missionTime) exitWith {};
if IS_UNCONSCIOUS(_this) exitWith {
_this setVariable [QGVAR(currentTreatment), nil];
};

// Find next unit to treat
private _healQueue = _this getVariable [QGVAR(healQueue), []];
private _target = _healQueue select 0;

// If unit died or was healed, be lazy and wait for the next tick
if (isNull _target || {!alive _target} || {!(_target call FUNC(isInjured))}) exitWith {
_this forceSpeed -1;
_target forceSpeed -1;
_healQueue deleteAt 0;
_this getVariable [QGVAR(healQueue), _healQueue];
_this forceSpeed -1;
_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(movingToInjured), false];
_this setVariable [QGVAR(nextMoveOrder), nil];
_this setVariable [QGVAR(currentTreatment), nil];

#ifdef DEBUG_MODE_FULL
systemChat format ["%1 finished healing %2", _this, _target];
systemChat format ["%1 finished healing %2", _this, _target];
#endif
};

// Move to target...
if (_this distance _target > 2) exitWith {
if !(_this getVariable [QGVAR(movingToInjured), false]) then {
_this setVariable [QGVAR(movingToInjured), true];
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];
_this doMove getPosATL _target;
#ifdef DEBUG_MODE_FULL
systemChat format ["%1 moving to %2", _this, _target];
#endif
};
};
_this setVariable [QGVAR(movingToInjured), false];

// ...and make sure medic and target don't move
_this forceSpeed 0;
_target forceSpeed 0;

private _needsBandaging = GET_BLOOD_LOSS(_target) > 0;
private _needsMorphine = GET_PAIN(_target) > 0.2;
private _needsEpinephrine = IS_UNCONSCIOUS(_target);

switch (true) do {
case _needsBandaging: {
// Select first wound and bandage it
private _openWounds = _target getVariable [QEGVAR(medical,openWounds), []];
private _partIndex = {
_x params ["", "", "_index", "_amount", "_percentage"];
if (_amount * _percentage > 0) exitWith {
_index
};
} forEach _openWounds;
private _selection = ALL_BODY_PARTS select _partIndex;
[_target, "BasicBandage", _selection] call EFUNC(medical_treatment,treatmentBandageLocal);

#ifdef DEBUG_MODE_FULL
systemChat format ["%1 is bandaging selection %2 on %3", _this, _selection, _target];
#endif

// Play animation
[_this, true, false] call FUNC(playTreatmentAnim);
_this setVariable [QGVAR(treatmentOverAt), CBA_missionTime + 5];
};
case _needsMorphine: {
[_this, "Morphine", 2] call EFUNC(medical_treatment,treatmentMedicationLocal);
[_this, false, false] call FUNC(playTreatmentAnim);
_this setVariable [QGVAR(treatmentOverAt), CBA_missionTime + 2];

#ifdef DEBUG_MODE_FULL
systemChat format ["%1 is giving %2 morphine", _this, _target];
#endif
};
//ToDo - Figure out how to connect to new medical
// case _needsEpinephrine: {
// [_this, _target] call EFUNC(medical,treatmentBasic_epipen);
// [_this, false, false] call FUNC(playTreatmentAnim);
// _this setVariable [QGVAR(treatmentOverAt), CBA_missionTime + 2];

// #ifdef DEBUG_MODE_FULL
// systemChat format ["%1 is using an epipen on %2", _this, _target];
// #endif
// };
};
[_this, _target] call FUNC(healingLogic);
Loading