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
This commit is contained in:
Ozan Eğitmen 2017-09-29 23:00:47 +03:00 committed by jonpas
parent 0644ad9ca2
commit 45a66ccfa1
16 changed files with 156 additions and 74 deletions

View File

@ -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);

View File

@ -1,3 +1,4 @@
PREP(addLoadCaptiveActions);
PREP(canApplyHandcuffs);
PREP(canEscortCaptive);
PREP(canFriskPerson);

View File

@ -0,0 +1,25 @@
/*
* Author: 654wak654
* Adds child actions to the "load captive" action for near vehicles.
*
* Arguments:
* 0: Captive <OBJECT>
*
* Return Value:
* Child actions <ARRAY>
*
* 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)

View File

@ -4,20 +4,20 @@
*
* Arguments:
* 0: Unit that wants to load a captive <OBJECT>
* 1: A captive. ObjNull for the first escorted captive (may be null) <OBJECT>
* 2: Vehicle to load the captive into. ObjNull for the nearest vehicle (may be null) <OBJECT>
* 1: A captive. objNull for the first escorted captive <OBJECT>
* 2: Vehicle to load the captive into. objNull for the nearest vehicle <OBJECT>
*
* Return Value:
* The return value <BOOL>
* Can load captive <BOOL>
*
* 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

View File

@ -4,42 +4,37 @@
*
* Arguments:
* 0: Unit that wants to load a captive <OBJECT>
* 1: A captive. ObjNull for the first escorted captive <OBJECT>
* 2: Vehicle to load the captive into. ObjNull for the nearest vehicle <OBJECT>
* 1: A captive. objNull for the first escorted captive <OBJECT>
* 2: Vehicle to load the captive into. objNull for the nearest vehicle <OBJECT>
*
* 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;
};
};

View File

@ -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]);

View File

@ -4,42 +4,28 @@
*
* Arguments:
* 0: Target <OBJECT>
* 1: Player <OBJECT>
*
* Return Value:
* Children actions <ARRAY>
* Child actions <ARRAY>
*
* 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)

View File

@ -116,6 +116,7 @@ PREP(moduleLSDVehicles);
PREP(muteUnit);
PREP(muteUnitHandleInitPost);
PREP(muteUnitHandleRespawn);
PREP(nearestVehiclesFreeSeat);
PREP(numberToDigits);
PREP(numberToDigitsString);
PREP(numberToString);

View File

@ -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 <OBJECT>
* 1: Unit to be loaded <OBJECT>
* 2: Vehicle that the unit will be loaded in <OBJECT> (default: objNull)
*
* Return Value:
* the vehicle that the unitToBeloaded has been loaded in. Returns ObjNull if function failed <OBJECT>
* Vehicle that the unitToBeloaded has been loaded in. Returns objNull if function failed <OBJECT>
*
* 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);

View File

@ -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 <OBJECT>
* 1: Distance <NUMBER>
*
* Return Value:
* Nearest vehicles with a free seat <ARRAY>
*
* 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}}

View File

@ -7,6 +7,7 @@ PREP(compileMenuSelfAction);
PREP(compileMenuZeus);
PREP(collectActiveActionTree);
PREP(createAction);
PREP(createVehiclesActions);
PREP(ctrlSetParsedTextCached);
PREP(findActionNode);
PREP(handleEscapeMenu);

View File

@ -0,0 +1,33 @@
/*
* Author: Dystopian
* Creates child actions for vehicle list.
* Statement gets vehicle as action parameter.
*
* Arguments:
* 0: Vehicle list <ARRAY>
* 1: Statement <CODE>
* 2: Target <OBJECT>
*
* Return Value:
* Array of actions <ARRAY>
*
* 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]
}

View File

@ -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);

View File

@ -11,6 +11,7 @@ PREP(actionLoadUnit);
PREP(actionUnloadUnit);
PREP(addDamageToUnit);
PREP(addHeartRateAdjustment);
PREP(addLoadPatientActions);
PREP(addToLog);
PREP(addToTriageCard);
PREP(addUnconsciousCondition);

View File

@ -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 <OBJECT>
* 1: The patient <OBJECT>
* 2: The vehicle <OBJECT> (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);

View File

@ -0,0 +1,25 @@
/*
* Author: 654wak654
* Adds child actions to the "load patient" action for near vehicles.
*
* Arguments:
* 0: Patient <OBJECT>
*
* Return Value:
* Child actions <ARRAY>
*
* 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)