From 90d63475d584db875bccda151351597015463547 Mon Sep 17 00:00:00 2001 From: Brett Date: Thu, 17 Feb 2022 11:14:39 -0600 Subject: [PATCH] Medical Treatment - Add preferred seats for loading patients (#8789) * Medical Treatment - Add preferred seats for loading patients * load patients in reverse order * add option for reverse fill * Update addons/medical_treatment/functions/fnc_loadUnit.sqf Co-authored-by: Filip Maciejewski * Update docs/wiki/framework/medical-treatment-framework.md Co-authored-by: PabstMirror Co-authored-by: Filip Maciejewski Co-authored-by: PabstMirror --- addons/common/functions/fnc_loadPerson.sqf | 10 +++-- .../common/functions/fnc_loadPersonLocal.sqf | 31 +++++++++++--- addons/medical_treatment/CfgVehicles.hpp | 10 +++++ .../functions/fnc_loadUnit.sqf | 8 +++- .../framework/medical-treatment-framework.md | 40 +++++++++++++++++++ 5 files changed, 89 insertions(+), 10 deletions(-) create mode 100644 docs/wiki/framework/medical-treatment-framework.md diff --git a/addons/common/functions/fnc_loadPerson.sqf b/addons/common/functions/fnc_loadPerson.sqf index 160344258b..5e872768d3 100644 --- a/addons/common/functions/fnc_loadPerson.sqf +++ b/addons/common/functions/fnc_loadPerson.sqf @@ -7,6 +7,8 @@ * 0: Unit that will load * 1: Unit to be loaded * 2: Vehicle that the unit will be loaded in (default: objNull) + * 3: Preferred seats + * 4: Reverse fill * * Return Value: * Vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed @@ -19,8 +21,8 @@ #define GROUP_SWITCH_ID QFUNC(loadPerson) -params ["_caller", "_unit", ["_vehicle", objNull]]; -TRACE_3("loadPerson",_caller,_unit,_vehicle); +params ["_caller", "_unit", ["_vehicle", objNull], ["_preferredSeats", []], ["_reverseFill", false]]; +TRACE_5("loadPerson",_caller,_unit,_vehicle,_preferredSeats,_reverseFill); if (!([_caller, _unit, ["isNotDragging", "isNotCarrying", "isNotSwimming"]] call FUNC(canInteractWith)) || {_caller == _unit}) exitWith { objNull }; @@ -39,8 +41,8 @@ if (!isNull _vehicle) then { }; }; - TRACE_3("sending ace_loadPersonEvent",_unit,_vehicle,_caller); - ["ace_loadPersonEvent", [_unit, _vehicle, _caller], _unit] call CBA_fnc_targetEvent; + TRACE_5("sending ace_loadPersonEvent",_unit,_vehicle,_caller,_preferredSeats,_reverseFill); + ["ace_loadPersonEvent", [_unit, _vehicle, _caller, _preferredSeats, _reverseFill], _unit] call CBA_fnc_targetEvent; }; _vehicle diff --git a/addons/common/functions/fnc_loadPersonLocal.sqf b/addons/common/functions/fnc_loadPersonLocal.sqf index 8490bf70e9..0c0fdab22c 100644 --- a/addons/common/functions/fnc_loadPersonLocal.sqf +++ b/addons/common/functions/fnc_loadPersonLocal.sqf @@ -7,6 +7,8 @@ * 0: unit to be loaded * 1: vehicle that will beloaded * 2: caller that will load + * 3: preferred seats + * 4: reverse fill * * Return Value: * None @@ -17,14 +19,33 @@ * Public: Yes */ -params ["_unit", "_vehicle", ["_caller", objNull]]; -TRACE_3("loadPersonLocal",_unit,_vehicle,_caller); +params ["_unit", "_vehicle", ["_caller", objNull], ["_preferredSeats", []], ["_reverseFill", false]]; +TRACE_5("loadPersonLocal",_unit,_vehicle,_caller,_preferredSeats,_reverseFill); private _slotsOpen = false; if ((_vehicle emptyPositions "cargo" > 0) && {!(_unit getVariable ['ACE_isUnconscious', false]) || {(getNumber (configOf _vehicle >> "ejectDeadCargo")) == 0}}) then { - _unit moveInCargo _vehicle; - TRACE_1("moveInCargo",_vehicle); - _slotsOpen = true; + if (_preferredSeats isNotEqualTo []) then { + private _taken = []; + { + _taken pushBackUnique (_vehicle getCargoIndex _x); + } forEach crew _vehicle; + private _preferredSeats = _preferredSeats - _taken; + if (count _preferredSeats > 0) then { + _unit moveInCargo [_vehicle, _preferredSeats select 0]; + TRACE_2("moveInCargo",_vehicle,_preferredSeats select 0); + _slotsOpen = true; + }; + }; + if (!_slotsOpen) then { + private _cargoSeats = fullCrew [_vehicle, "cargo", true]; + if (_reverseFill) then { + reverse _cargoSeats; + }; + private _index = _cargoSeats findIf {isNull (_x select 0)}; + _unit moveInCargo [_vehicle, (_cargoSeats select _index) select 2]; + TRACE_2("moveInCargo",_vehicle,_index); + _slotsOpen = true; + }; } else { // Check if an empty turret is available // This already excludes FFV seats, which count as cargo positions diff --git a/addons/medical_treatment/CfgVehicles.hpp b/addons/medical_treatment/CfgVehicles.hpp index 876078d484..5036750fab 100644 --- a/addons/medical_treatment/CfgVehicles.hpp +++ b/addons/medical_treatment/CfgVehicles.hpp @@ -328,4 +328,14 @@ class CfgVehicles { MACRO_ADDITEM(ACE_bodyBag,5); }; }; + + class Van_02_base_F; + class Van_02_medevac_base_F: Van_02_base_F { + GVAR(patientSeats)[] = {3,4}; + }; + + class Heli_Transport_04_base_F; + class O_Heli_Transport_04_medevac_F: Heli_Transport_04_base_F { + GVAR(patientSeats)[] = {0,1,2}; + }; }; diff --git a/addons/medical_treatment/functions/fnc_loadUnit.sqf b/addons/medical_treatment/functions/fnc_loadUnit.sqf index 8b556014e1..91656c3c19 100644 --- a/addons/medical_treatment/functions/fnc_loadUnit.sqf +++ b/addons/medical_treatment/functions/fnc_loadUnit.sqf @@ -32,7 +32,13 @@ if (_patient call EFUNC(medical_status,isBeingDragged)) then { [_medic, _patient] call EFUNC(dragging,dropObject); }; -private _vehicle = [_medic, _patient, _vehicle] call EFUNC(common,loadPerson); +private _vehicle = [ + _medic, + _patient, + _vehicle, + getArray (configOf _vehicle >> QGVAR(patientSeats)), + ([configOf _vehicle >> QGVAR(patientReverseFill), "NUMBER", 1] call CBA_fnc_getConfigEntry) > 0 +] call EFUNC(common,loadPerson); if (isNull _vehicle) exitWith { TRACE_1("no vehicle found",_vehicle); }; diff --git a/docs/wiki/framework/medical-treatment-framework.md b/docs/wiki/framework/medical-treatment-framework.md new file mode 100644 index 0000000000..a3f5d04de1 --- /dev/null +++ b/docs/wiki/framework/medical-treatment-framework.md @@ -0,0 +1,40 @@ +--- +layout: wiki +title: Medical Treatment Framework +description: Explains extending the treatment system for developers. +group: framework +order: 5 +parent: wiki +mod: ace +version: + major: 3 + minor: 14 + patch: 2 +--- + +## 1. Config Values + +### 1.1 Vehicle Patient Seats + +Defines the seats that will be prioritized when loading patients into vehicles. Uses `moveInCargo` indexes. + +```cpp +class CfgVehicles { + class MyCar { + ace_medical_treatment_patientSeats[] = {3,4}; + }; +}; +``` + +### 1.2 Patient Reverse Fill + +When no patient seats are available, by default patients will be filled from the highest cargo index to the lowest. +This can be changed to fill from the lowest to the highest. + +```cpp +class CfgVehicles { + class MyCar { + ace_medical_treatment_patientReverseFill = 0; + }; +}; +```