mirror of
https://github.com/acemod/ACE3.git
synced 2024-08-30 18:23:18 +00:00
Cargo load menu overhaul (#4871)
* Add submenu with vehicles to cargo load menu * replace private ARRAY with keyword * fix ace function macro using * filter vehicles without cargo * add Load condition, clean params, fix param reusing * replace nearEntities with nearestObjects, add macro * optimize, del magic, replace count with forEach * del unused functions * del useless _this parameter
This commit is contained in:
parent
5dc8859984
commit
9f291c86d8
@ -1,9 +1,8 @@
|
||||
|
||||
PREP(addCargoItem);
|
||||
PREP(canLoad);
|
||||
PREP(addCargoVehiclesActions);
|
||||
PREP(canLoadItemIn);
|
||||
PREP(canUnloadItem);
|
||||
PREP(findNearestVehicle);
|
||||
PREP(getCargoSpaceLeft);
|
||||
PREP(getSizeItem);
|
||||
PREP(handleDestroyed);
|
||||
|
44
addons/cargo/functions/fnc_addCargoVehiclesActions.sqf
Normal file
44
addons/cargo/functions/fnc_addCargoVehiclesActions.sqf
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Author: Dystopian
|
||||
* Create actions for nearest vehicles with cargo.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Target <OBJECT>
|
||||
* 1: Player <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Children actions <ARRAY>
|
||||
*
|
||||
* Example:
|
||||
* [target, player] call ace_cargo_fnc_addCargoVehiclesActions
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
private _statement = {
|
||||
params ["_target", "_player", "_params"];
|
||||
_params params ["_vehicle"];
|
||||
[_player, _target, _vehicle] call FUNC(startLoadIn);
|
||||
};
|
||||
|
||||
private _actions = [];
|
||||
|
||||
{
|
||||
private _config = configFile >> "CfgVehicles" >> typeOf _x;
|
||||
if (
|
||||
1 == getNumber (_config >> QGVAR(hasCargo)) &&
|
||||
{_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, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE]);
|
||||
|
||||
_actions
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Check if player can load an item into the nearest vehicle.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Player <OBJECT>
|
||||
* 1: Object to load <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Can load <BOOL>
|
||||
*
|
||||
* Example:
|
||||
* [player, object] call ace_cargo_fnc_canLoad
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_player", "_object"];
|
||||
TRACE_2("params",_player,_object);
|
||||
|
||||
if (!([_player, _object, []] call EFUNC(common,canInteractWith))) exitWith {false};
|
||||
|
||||
private _nearestVehicle = [_player, _object] call FUNC(findNearestVehicle);
|
||||
|
||||
if (_nearestVehicle isKindOf "Cargo_Base_F" || isNull _nearestVehicle) then {
|
||||
{
|
||||
if ([_object, _x] call FUNC(canLoadItemIn)) exitWith {_nearestVehicle = _x};
|
||||
} forEach (nearestObjects [_player, ["Cargo_base_F", "Land_PaperBox_closed_F"], MAX_LOAD_DISTANCE]);
|
||||
};
|
||||
|
||||
if (isNull _nearestVehicle) exitWith {false};
|
||||
|
||||
if ((locked _nearestVehicle) >= 2) exitWith {false};
|
||||
|
||||
[_object, _nearestVehicle] call FUNC(canLoadItemIn)
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Author: Glowbal
|
||||
* Get nearest vehicle from unit that is not excluded, priority: Car-Air-Tank-Ship.
|
||||
*
|
||||
* Arguments:
|
||||
* 0: Unit <OBJECT>
|
||||
* 1: Object to exclude <OBJECT>
|
||||
*
|
||||
* Return Value:
|
||||
* Vehicle in Distance <OBJECT>
|
||||
*
|
||||
* Example:
|
||||
* [unit, object] call ace_cargo_fnc_findNearestVehicle
|
||||
*
|
||||
* Public: No
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_unit","_object"];
|
||||
|
||||
private _loadCar = nearestObjects [_unit, ["car"], MAX_LOAD_DISTANCE];
|
||||
_loadCar deleteAt (_loadCar find _object);
|
||||
if !(_loadCar isEqualTo []) exitWith {_loadCar select 0};
|
||||
|
||||
private _loadHelicopter = nearestObjects [_unit, ["air"], MAX_LOAD_DISTANCE];
|
||||
_loadHelicopter deleteAt (_loadHelicopter find _object);
|
||||
if !(_loadHelicopter isEqualTo []) exitWith {_loadHelicopter select 0};
|
||||
|
||||
private _loadTank = nearestObjects [_unit, ["tank"], MAX_LOAD_DISTANCE];
|
||||
_loadTank deleteAt (_loadTank find _object);
|
||||
if !(_loadTank isEqualTo []) exitWith {_loadTank select 0};
|
||||
|
||||
private _loadShip = nearestObjects [_unit, ["ship"], MAX_LOAD_DISTANCE];
|
||||
_loadShip deleteAt (_loadShip find _object);;
|
||||
if !(_loadShip isEqualTo []) exitWith {_loadShip select 0};
|
||||
|
||||
private _loadContainer = nearestObjects [_unit, ["Cargo_base_F"], MAX_LOAD_DISTANCE];
|
||||
_loadContainer deleteAt (_loadContainer find _object);
|
||||
if !(_loadContainer isEqualTo []) exitWith {_loadContainer select 0};
|
||||
|
||||
objNull
|
@ -32,15 +32,18 @@ private _condition = {
|
||||
{(_target getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(canLoad))]) == 1} &&
|
||||
{locked _target < 2} &&
|
||||
{alive _target} &&
|
||||
{[_player, _target, []] call EFUNC(common,canInteractWith)}
|
||||
{[_player, _target, []] call EFUNC(common,canInteractWith)} &&
|
||||
{0 < {
|
||||
1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)) &&
|
||||
{_x != _target}
|
||||
} count (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE])}
|
||||
};
|
||||
private _statement = {
|
||||
params ["_target", "_player"];
|
||||
[_player, _target] call FUNC(startLoadIn);
|
||||
};
|
||||
private _text = localize LSTRING(loadObject);
|
||||
private _icon = QPATHTOF(UI\Icon_load.paa);
|
||||
|
||||
private _action = [QGVAR(load), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
|
||||
private _action = [QGVAR(load), _text, _icon, _statement, _condition, {call FUNC(addCargoVehiclesActions)}] call EFUNC(interact_menu,createAction);
|
||||
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Arguments:
|
||||
* 0: Player <OBJECT>
|
||||
* 1: Object <OBJECT>
|
||||
* 2: Vehicle <OBJECT> (Optional)
|
||||
*
|
||||
* Return Value:
|
||||
* Load ProgressBar Started <BOOL>
|
||||
@ -16,15 +17,14 @@
|
||||
*/
|
||||
#include "script_component.hpp"
|
||||
|
||||
params ["_player", "_object"];
|
||||
TRACE_2("params",_player,_object);
|
||||
params ["_player", "_object", ["_cargoVehicle", objNull]];
|
||||
TRACE_3("params",_player,_object,_cargoVehicle);
|
||||
|
||||
private _vehicle = [_player, _object] call FUNC(findNearestVehicle);
|
||||
|
||||
if ((isNull _vehicle) || {_vehicle isKindOf "Cargo_Base_F"}) then {
|
||||
private _vehicle = _cargoVehicle;
|
||||
if (isNull _vehicle) then {
|
||||
{
|
||||
if ([_object, _x] call FUNC(canLoadItemIn)) exitWith {_vehicle = _x};
|
||||
} forEach (nearestObjects [_player, ["Cargo_base_F", "Land_PaperBox_closed_F"], MAX_LOAD_DISTANCE]);
|
||||
} forEach (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE]);
|
||||
};
|
||||
|
||||
if (isNull _vehicle) exitWith {
|
||||
|
@ -17,3 +17,4 @@
|
||||
#include "\z\ace\addons\main\script_macros.hpp"
|
||||
|
||||
#define MAX_LOAD_DISTANCE 10
|
||||
#define CARGO_VEHICLE_CLASSES ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"]
|
||||
|
Loading…
Reference in New Issue
Block a user