From 45a66ccfa17147ab047ffd9c8be09b24dca3bdb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ozan=20E=C4=9Fitmen?= Date: Fri, 29 Sep 2017 23:00:47 +0300 Subject: [PATCH] Medical & Captive Load Menu Overhaul (#5519) * Add load in child actions to medical & captive * Add actions with proper structure * Move vehicles actions code to common function * Simplify code in config, Fix docs * Remove unused vars * Fix header example * Add _distance param to fnc_nearestVehiclesFreeSeat * Change docs * Fix spacing --- addons/captives/CfgVehicles.hpp | 1 + addons/captives/XEH_PREP.hpp | 1 + .../functions/fnc_addLoadCaptiveActions.sqf | 25 ++++++++++++++ .../captives/functions/fnc_canLoadCaptive.sqf | 26 +++++++-------- .../captives/functions/fnc_doLoadCaptive.sqf | 27 +++++++-------- .../fnc_findEmptyNonFFVCargoSeat.sqf | 6 ++-- .../functions/fnc_addCargoVehiclesActions.sqf | 32 +++++------------- addons/common/XEH_PREP.hpp | 1 + addons/common/functions/fnc_loadPerson.sqf | 21 +++++------- .../functions/fnc_nearestVehiclesFreeSeat.sqf | 22 +++++++++++++ addons/interact_menu/XEH_PREP.hpp | 1 + .../functions/fnc_createVehiclesActions.sqf | 33 +++++++++++++++++++ addons/medical/CfgVehicles.hpp | 1 + addons/medical/XEH_PREP.hpp | 1 + .../medical/functions/fnc_actionLoadUnit.sqf | 7 ++-- .../functions/fnc_addLoadPatientActions.sqf | 25 ++++++++++++++ 16 files changed, 156 insertions(+), 74 deletions(-) create mode 100644 addons/captives/functions/fnc_addLoadCaptiveActions.sqf create mode 100644 addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf create mode 100644 addons/interact_menu/functions/fnc_createVehiclesActions.sqf create mode 100644 addons/medical/functions/fnc_addLoadPatientActions.sqf diff --git a/addons/captives/CfgVehicles.hpp b/addons/captives/CfgVehicles.hpp index 6a93d35195..45a3f323e6 100644 --- a/addons/captives/CfgVehicles.hpp +++ b/addons/captives/CfgVehicles.hpp @@ -51,6 +51,7 @@ class CfgVehicles { showDisabled = 0; icon = QPATHTOF(UI\captive_ca.paa); priority = 2.2; + insertChildren = QUOTE(call DFUNC(addLoadCaptiveActions)); }; class GVAR(UnloadCaptive) { displayName = CSTRING(UnloadCaptive); diff --git a/addons/captives/XEH_PREP.hpp b/addons/captives/XEH_PREP.hpp index 9ce78e438a..bf0b06a1db 100644 --- a/addons/captives/XEH_PREP.hpp +++ b/addons/captives/XEH_PREP.hpp @@ -1,3 +1,4 @@ +PREP(addLoadCaptiveActions); PREP(canApplyHandcuffs); PREP(canEscortCaptive); PREP(canFriskPerson); diff --git a/addons/captives/functions/fnc_addLoadCaptiveActions.sqf b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf new file mode 100644 index 0000000000..0c7adbda7a --- /dev/null +++ b/addons/captives/functions/fnc_addLoadCaptiveActions.sqf @@ -0,0 +1,25 @@ +/* + * Author: 654wak654 + * Adds child actions to the "load captive" action for near vehicles. + * + * Arguments: + * 0: Captive + * + * Return Value: + * Child actions + * + * Example: + * [kevin] call ace_medical_fnc_addLoadCaptiveActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_target"]; + +private _statement = { + params ["_target", "_player", "_vehicle"]; + [_player, _target, _vehicle] call FUNC(doLoadCaptive); +}; + +[_target call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions) diff --git a/addons/captives/functions/fnc_canLoadCaptive.sqf b/addons/captives/functions/fnc_canLoadCaptive.sqf index b968f1754a..782661ea1c 100644 --- a/addons/captives/functions/fnc_canLoadCaptive.sqf +++ b/addons/captives/functions/fnc_canLoadCaptive.sqf @@ -4,20 +4,20 @@ * * Arguments: * 0: Unit that wants to load a captive - * 1: A captive. ObjNull for the first escorted captive (may be null) - * 2: Vehicle to load the captive into. ObjNull for the nearest vehicle (may be null) + * 1: A captive. objNull for the first escorted captive + * 2: Vehicle to load the captive into. objNull for the nearest vehicle * * Return Value: - * The return value + * Can load captive * * Example: - * [player, bob, car] call ACE_captives_fnc_canLoadCaptive + * [bob, tom, car] call ace_captives_fnc_canLoadCaptive * * Public: No */ #include "script_component.hpp" -params ["_unit", "_target","_vehicle"]; +params ["_unit", "_target", "_vehicle"]; // Don't show "Load Captive" if unit is unconscious (already has "Load Patient") if (_target getVariable ["ACE_isUnconscious", false]) exitWith {false}; @@ -30,20 +30,16 @@ if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then { }; } forEach (attachedObjects _unit); }; -if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {false}; +if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {false}; if (isNull _vehicle) then { - //Looking at a captive unit, search for nearby vehicles with valid seats: - { - if ((_x emptyPositions "cargo") > 0) exitWith { - _vehicle = _x; - }; - } forEach (nearestObjects [_unit, ["Car", "Tank", "Helicopter", "Plane", "Ship"], 10]); + // Looking at a captive unit, get nearest vehicle with valid seat: + _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { - //We have a vehicle picked, make sure it has empty seats: - if ((_vehicle emptyPositions "cargo") == 0) then { + // We have a vehicle picked, make sure it has empty seats: + if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { _vehicle = objNull; }; }; -(!isNull _vehicle) +!isNull _vehicle diff --git a/addons/captives/functions/fnc_doLoadCaptive.sqf b/addons/captives/functions/fnc_doLoadCaptive.sqf index 82e446b460..c47cc389d4 100644 --- a/addons/captives/functions/fnc_doLoadCaptive.sqf +++ b/addons/captives/functions/fnc_doLoadCaptive.sqf @@ -4,42 +4,37 @@ * * Arguments: * 0: Unit that wants to load a captive - * 1: A captive. ObjNull for the first escorted captive - * 2: Vehicle to load the captive into. ObjNull for the nearest vehicle + * 1: A captive. objNull for the first escorted captive + * 2: Vehicle to load the captive into. objNull for the nearest vehicle * * Return Value: * None * * Example: - * [bob, tom, car] call ACE_captives_fnc_doLoadCaptive + * [bob, tom, car] call ace_captives_fnc_doLoadCaptive * * Public: No */ #include "script_component.hpp" -params ["_unit", "_target","_vehicle"]; +params ["_unit", "_target", "_vehicle"]; -if ((isNull _target) && {_unit getVariable [QGVAR(isEscorting), false]}) then { - //Looking at a vehicle while escorting, get target from attached objects: +if (isNull _target && {_unit getVariable [QGVAR(isEscorting), false]}) then { + // Looking at a vehicle while escorting, get target from attached objects: { if (_x getVariable [QGVAR(isHandcuffed), false]) exitWith { _target = _x; }; } forEach (attachedObjects _unit); }; -if ((isNull _target) || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {WARNING("");}; +if (isNull _target || {(vehicle _target) != _target} || {!(_target getVariable [QGVAR(isHandcuffed), false])}) exitWith {WARNING("");}; if (isNull _vehicle) then { - //Looking at a captive unit, search for nearby vehicles with valid seats: - { - // if (([_x] call FUNC(findEmptyNonFFVCargoSeat)) != -1) exitWith { - if ((_x emptyPositions "cargo") > 0) exitWith { - _vehicle = _x; - }; - } forEach (nearestObjects [_unit, ["Car", "Tank", "Helicopter", "Plane", "Ship"], 10]); + // Looking at a captive unit, get nearest vehicle with valid seat: + _vehicle = (_target call EFUNC(common,nearestVehiclesFreeSeat)) param [0, objNull]; } else { - // if (([_vehicle] call FUNC(findEmptyNonFFVCargoSeat)) == -1) then { - if ((_vehicle emptyPositions "cargo") == 0) then { + // We have a vehicle picked, make sure it has empty seats: + if (_vehicle emptyPositions "cargo" == 0 && {_vehicle emptyPositions "gunner" == 0}) then { _vehicle = objNull; }; }; diff --git a/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf b/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf index 63792a7c55..91bb800c05 100644 --- a/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf +++ b/addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf @@ -18,20 +18,18 @@ params ["_vehicle"]; TRACE_1("params", _vehicle); -private _vehicleConfig = configFile >> "CfgVehicles" >> (typeOf _vehicle); - scopeName "main"; { _x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"]; - if ((isNull _unit) && {_role == "cargo"} && {_cargoIndex > -1} && {!_isPersonTurret}) then { + if (isNull _unit && {_role == "cargo"} && {_cargoIndex > -1} && {!_isPersonTurret}) then { [_cargoIndex, false] breakOut "main"; }; } forEach (fullCrew [_vehicle, "", true]); { _x params ["_unit", "_role", "_cargoIndex", "_turretPath", "_isPersonTurret"]; - if ((isNull _unit) && {_cargoIndex > -1}) then { + if (isNull _unit && {_cargoIndex > -1}) then { [_cargoIndex, true] breakOut "main"; }; } forEach (fullCrew [_vehicle, "", true]); diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index 176b2f31b6..111407e3fe 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -4,42 +4,28 @@ * * Arguments: * 0: Target - * 1: Player * * Return Value: - * Children actions + * Child actions * * Example: - * [target, player] call ace_cargo_fnc_addCargoVehiclesActions + * [cursorObject] call ace_cargo_fnc_addCargoVehiclesActions * * Public: No */ #include "script_component.hpp" -params ["_target", "_player"]; +params ["_target"]; private _statement = { - params ["_target", "_player", "_params"]; - _params params ["_vehicle"]; + params ["_target", "_player", "_vehicle"]; [_player, _target, _vehicle] call FUNC(startLoadIn); }; -private _actions = []; - -{ - private _config = configFile >> "CfgVehicles" >> typeOf _x; +private _vehicles = (nearestObjects [_target, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]) select { + private _hasCargoConfig = 1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)); private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false]; - private _hasCargoConfig = getNumber (_config >> QGVAR(hasCargo)) == 1; - if ((_hasCargoPublic || _hasCargoConfig) && {_x != _target}) then { - private _name = getText (_config >> "displayName"); - private _ownerName = [_x, true] call EFUNC(common,getName); - if ("" != _ownerName) then { - _name = format ["%1 (%2)", _name, _ownerName]; - }; - private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; - private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, [_x]] call EFUNC(interact_menu,createAction); - _actions pushBack [_action, [], _target]; - }; -} forEach (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]); + (_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} +}; -_actions +[_vehicles, _statement, _target] call EFUNC(interact_menu,createVehiclesActions) diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index 959dc896e3..efc92df752 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -116,6 +116,7 @@ PREP(moduleLSDVehicles); PREP(muteUnit); PREP(muteUnitHandleInitPost); PREP(muteUnitHandleRespawn); +PREP(nearestVehiclesFreeSeat); PREP(numberToDigits); PREP(numberToDigitsString); PREP(numberToString); diff --git a/addons/common/functions/fnc_loadPerson.sqf b/addons/common/functions/fnc_loadPerson.sqf index ae762b82be..897ff1f9a8 100644 --- a/addons/common/functions/fnc_loadPerson.sqf +++ b/addons/common/functions/fnc_loadPerson.sqf @@ -1,13 +1,14 @@ /* * Author: Glowbal - * Loads a specified unit into any nearby vehicle + * Loads a specified unit into any nearby vehicle, or _vehicle parameter. * * Arguments: * 0: Unit that will load * 1: Unit to be loaded + * 2: Vehicle that the unit will be loaded in (default: objNull) * * Return Value: - * the vehicle that the unitToBeloaded has been loaded in. Returns ObjNull if function failed + * Vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed * * Example: * [bob, kevin] call ace_common_fnc_loadPerson @@ -18,20 +19,14 @@ #define GROUP_SWITCH_ID QFUNC(loadPerson) -params ["_caller", "_unit"]; - -private _vehicle = objNull; +params ["_caller", "_unit", ["_vehicle", objNull]]; if (!([_caller, _unit, ["isNotDragging", "isNotCarrying"]] call FUNC(canInteractWith)) || {_caller == _unit}) exitWith {_vehicle}; -private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F","Pod_Heli_Transport_04_crewed_base_F"], 10]; - -{ - TRACE_1("",_x); - if ((_x emptyPositions "cargo" > 0) || {_x emptyPositions "gunner" > 0}) exitWith { - _vehicle = _x; - }; -} forEach _nearVehicles; +// Try to use nearest vehicle if a vehicle hasn't been supplied +if (isNull _vehicle) then { + _vehicle = ([_unit] call FUNC(nearestVehiclesFreeSeat)) param [0, objNull]; +}; if (!isNull _vehicle) then { [_unit, true, GROUP_SWITCH_ID, side group _caller] call FUNC(switchToGroupSide); diff --git a/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf new file mode 100644 index 0000000000..080499d9cf --- /dev/null +++ b/addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf @@ -0,0 +1,22 @@ +/* + * Author: 654wak654 + * Returns a list of vehicles near given unit that the unit can be a passenger in. + * + * Arguments: + * 0: Unit + * 1: Distance + * + * Return Value: + * Nearest vehicles with a free seat + * + * Example: + * [bob] call ace_common_fnc_nearestVehiclesFreeSeat + * + * Public: Yes + */ +#include "script_component.hpp" + +params ["_unit", ["_distance", 10]]; + +private _nearVehicles = nearestObjects [_unit, ["Car", "Air", "Tank", "Ship_F", "Pod_Heli_Transport_04_crewed_base_F"], _distance]; +_nearVehicles select {(_x emptyPositions "cargo" > 0) || {_x emptyPositions "gunner" > 0}} diff --git a/addons/interact_menu/XEH_PREP.hpp b/addons/interact_menu/XEH_PREP.hpp index 55c35d54df..7ee668a583 100644 --- a/addons/interact_menu/XEH_PREP.hpp +++ b/addons/interact_menu/XEH_PREP.hpp @@ -7,6 +7,7 @@ PREP(compileMenuSelfAction); PREP(compileMenuZeus); PREP(collectActiveActionTree); PREP(createAction); +PREP(createVehiclesActions); PREP(ctrlSetParsedTextCached); PREP(findActionNode); PREP(handleEscapeMenu); diff --git a/addons/interact_menu/functions/fnc_createVehiclesActions.sqf b/addons/interact_menu/functions/fnc_createVehiclesActions.sqf new file mode 100644 index 0000000000..6bdc941118 --- /dev/null +++ b/addons/interact_menu/functions/fnc_createVehiclesActions.sqf @@ -0,0 +1,33 @@ +/* + * Author: Dystopian + * Creates child actions for vehicle list. + * Statement gets vehicle as action parameter. + * + * Arguments: + * 0: Vehicle list + * 1: Statement + * 2: Target + * + * Return Value: + * Array of actions + * + * Example: + * [nearestObjects [player, ["AllVehicles"], 10], {}, cursorObject] call ace_interact_menu_fnc_createVehiclesActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_vehicles", "_statement", "_target"]; + +_vehicles apply { + private _config = configFile >> "CfgVehicles" >> typeOf _x; + private _name = getText (_config >> "displayName"); + private _ownerName = [_x, true] call EFUNC(common,getName); + if ("" != _ownerName) then { + _name = format ["%1 (%2)", _name, _ownerName]; + }; + private _icon = (getText (_config >> "icon")) call BIS_fnc_textureVehicleIcon; + private _action = [format ["%1", _x], _name, _icon, _statement, {true}, {}, _x] call EFUNC(interact_menu,createAction); + [_action, [], _target] +} diff --git a/addons/medical/CfgVehicles.hpp b/addons/medical/CfgVehicles.hpp index 936ea976ef..4217fb3745 100644 --- a/addons/medical/CfgVehicles.hpp +++ b/addons/medical/CfgVehicles.hpp @@ -551,6 +551,7 @@ class CfgVehicles { priority = 2; icon = QPATHTOF(UI\icons\medical_cross.paa); exceptions[] = {"isNotDragging", "isNotCarrying", "isNotSwimming"}; + insertChildren = QUOTE(call DFUNC(addLoadPatientActions)); }; class GVAR(UnLoadPatient) { displayName = CSTRING(UnloadPatient); diff --git a/addons/medical/XEH_PREP.hpp b/addons/medical/XEH_PREP.hpp index ab80312925..9749bd7efc 100644 --- a/addons/medical/XEH_PREP.hpp +++ b/addons/medical/XEH_PREP.hpp @@ -11,6 +11,7 @@ PREP(actionLoadUnit); PREP(actionUnloadUnit); PREP(addDamageToUnit); PREP(addHeartRateAdjustment); +PREP(addLoadPatientActions); PREP(addToLog); PREP(addToTriageCard); PREP(addUnconsciousCondition); diff --git a/addons/medical/functions/fnc_actionLoadUnit.sqf b/addons/medical/functions/fnc_actionLoadUnit.sqf index 11a875bf2f..264fb72a4b 100644 --- a/addons/medical/functions/fnc_actionLoadUnit.sqf +++ b/addons/medical/functions/fnc_actionLoadUnit.sqf @@ -1,10 +1,11 @@ /* * Author: Glowbal - * Action for loading an unconscious or dead unit in the nearest vechile + * Action for loading an unconscious or dead unit in the nearest vehicle, or _vehicle if given. * * Arguments: * 0: The medic * 1: The patient + * 2: The vehicle (default: objNull) * * Return Value: * None @@ -17,7 +18,7 @@ #include "script_component.hpp" -params ["_caller", "_target"]; +params ["_caller", "_target", ["_vehicle", objNull]]; if ([_target] call EFUNC(common,isAwake)) exitWith { [QEGVAR(common,displayTextStructured), [[LSTRING(CanNotLoaded), [_target] call EFUNC(common,getName)], 1.5, _caller], [_caller]] call CBA_fnc_targetEvent; @@ -29,4 +30,4 @@ if ([_target] call FUNC(isBeingDragged)) then { [_caller, _target] call EFUNC(dragging,dropObject); }; -private _vehicle = [_caller, _target] call EFUNC(common,loadPerson); +[_caller, _target, _vehicle] call EFUNC(common,loadPerson); diff --git a/addons/medical/functions/fnc_addLoadPatientActions.sqf b/addons/medical/functions/fnc_addLoadPatientActions.sqf new file mode 100644 index 0000000000..b00ff72472 --- /dev/null +++ b/addons/medical/functions/fnc_addLoadPatientActions.sqf @@ -0,0 +1,25 @@ +/* + * Author: 654wak654 + * Adds child actions to the "load patient" action for near vehicles. + * + * Arguments: + * 0: Patient + * + * Return Value: + * Child actions + * + * Example: + * [kevin] call ace_medical_fnc_addLoadPatientActions + * + * Public: No + */ +#include "script_component.hpp" + +params ["_target"]; + +private _statement = { + params ["_target", "_player", "_vehicle"]; + [_player, _target, _vehicle] call FUNC(actionLoadUnit); +}; + +[_target call EFUNC(common,nearestVehiclesFreeSeat), _statement, _target] call EFUNC(interact_menu,createVehiclesActions)