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 & Captive Load Menu Overhaul #5519

Merged
merged 12 commits into from
Sep 29, 2017
1 change: 1 addition & 0 deletions addons/captives/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions addons/captives/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PREP(addLoadCaptiveActions);
PREP(canApplyHandcuffs);
PREP(canEscortCaptive);
PREP(canFriskPerson);
Expand Down
25 changes: 25 additions & 0 deletions addons/captives/functions/fnc_addLoadCaptiveActions.sqf
Original file line number Diff line number Diff line change
@@ -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)
26 changes: 11 additions & 15 deletions addons/captives/functions/fnc_canLoadCaptive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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
27 changes: 11 additions & 16 deletions addons/captives/functions/fnc_doLoadCaptive.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
Expand Down
6 changes: 2 additions & 4 deletions addons/captives/functions/fnc_findEmptyNonFFVCargoSeat.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
32 changes: 9 additions & 23 deletions addons/cargo/functions/fnc_addCargoVehiclesActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ PREP(moduleLSDVehicles);
PREP(muteUnit);
PREP(muteUnitHandleInitPost);
PREP(muteUnitHandleRespawn);
PREP(nearestVehiclesFreeSeat);
PREP(numberToDigits);
PREP(numberToDigitsString);
PREP(numberToString);
Expand Down
21 changes: 8 additions & 13 deletions addons/common/functions/fnc_loadPerson.sqf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions addons/common/functions/fnc_nearestVehiclesFreeSeat.sqf
Original file line number Diff line number Diff line change
@@ -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}}
1 change: 1 addition & 0 deletions addons/interact_menu/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ PREP(compileMenuSelfAction);
PREP(compileMenuZeus);
PREP(collectActiveActionTree);
PREP(createAction);
PREP(createVehiclesActions);
PREP(ctrlSetParsedTextCached);
PREP(findActionNode);
PREP(handleEscapeMenu);
Expand Down
33 changes: 33 additions & 0 deletions addons/interact_menu/functions/fnc_createVehiclesActions.sqf
Original file line number Diff line number Diff line change
@@ -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]
}
1 change: 1 addition & 0 deletions addons/medical/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions addons/medical/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PREP(actionLoadUnit);
PREP(actionUnloadUnit);
PREP(addDamageToUnit);
PREP(addHeartRateAdjustment);
PREP(addLoadPatientActions);
PREP(addToLog);
PREP(addToTriageCard);
PREP(addUnconsciousCondition);
Expand Down
7 changes: 4 additions & 3 deletions addons/medical/functions/fnc_actionLoadUnit.sqf
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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);
Loading