ACE3/addons/cargo/functions/fnc_initVehicle.sqf
jokoho482 7c3713a03f Remove Old Cargo Menu
Update to match Old Cargo Menu
Fix some Merge issues that happend
2024-04-21 01:01:55 +02:00

143 lines
5.3 KiB
Plaintext

#include "..\script_component.hpp"
/*
* Author: Glowbal
* Initializes vehicle, adds open cargo menu action if available.
*
* Arguments:
* 0: Vehicle <OBJECT>
*
* Return Value:
* None
*
* Example:
* cursorObject call ace_cargo_fnc_initVehicle
*
* Public: No
*/
params ["_vehicle"];
TRACE_1("params",_vehicle);
private _type = typeOf _vehicle;
private _config = configOf _vehicle;
// If vehicle had space given to it via eden/public, then override config hasCargo setting
private _hasCargoPublic = _vehicle getVariable QGVAR(hasCargo);
private _hasCargoPublicDefined = !isNil "_canLoadPublic";
if (_hasCargoPublicDefined && {!(_hasCargoPublic isEqualType false)}) then {
WARNING_4("%1[%2] - Variable %3 is %4 - Should be bool",_vehicle,_type,QGVAR(hasCargo),_hasCargoPublic);
};
private _hasCargoConfig = getNumber (_config >> QGVAR(hasCargo)) == 1;
// Nothing to do here if vehicle has no cargo space
if !((_hasCargoPublicDefined && {_hasCargoPublic in [true, 1]}) || {!_hasCargoPublicDefined && {_hasCargoConfig}}) exitWith {};
// Check if cargo is in cargo holder types (checked when trying to search for loadable objects)
private _addCargoType = GVAR(cargoHolderTypes) findIf {_type isKindOf _x} == -1;
TRACE_2("",_addCargoType,_type);
if (_addCargoType) then {
GVAR(cargoHolderTypes) pushBack _type;
};
// If already initialised (both actions and cargo), then skip
if (_vehicle getVariable [QGVAR(initVehicle), false]) exitWith {};
// Vehicles can have default ace cargo in their config
if (isServer) then {
_vehicle setVariable [QGVAR(initVehicle), true];
private _cargoClassname = "";
private _cargoCount = 0;
{
_cargoClassname = getText (_x >> "type");
_cargoCount = getNumber (_x >> "amount");
TRACE_3("adding ACE_Cargo",configName _x,_cargoClassname,_cargoCount);
["ace_addCargo", [_cargoClassname, _vehicle, _cargoCount]] call CBA_fnc_localEvent;
} forEach ("true" configClasses (_config >> QUOTE(ADDON) >> "cargo"));
};
// Servers and HCs do not require action menus (beyond this point)
if (!hasInterface) exitWith {};
if (_vehicle getVariable [QGVAR(initVehicle),false]) exitWith {};
private _tb = getNumber (_config >> "transportmaxbackpacks");
private _tm = getNumber (_config >> "transportmaxmagazines");
private _tw = getNumber (_config >> "transportmaxweapons");
private _hasInventory = (_tb > 0 || _tm > 0 || _tw > 0);
_vehicle setVariable [QGVAR(hasInventory), _hasInventory];
// This is a Hack to add the Gear Action and thus the Cargo UI to vehicles/Objects that dont naturally have a Gear Action
if (!_hasInventory) then {
private _cfgAction = configFile >> "CfgActions" >> "Gear";
private _title = getText (_cfgAction >> "text");
private _hideOnUse = getNumber (_cfgAction >> "hideOnUse") == 1;
private _showWindow = getNumber (_cfgAction >> "showWindow") == 1;
private _textDefault = getText (_cfgAction >> "textDefault");
private _shortcut = getText (_cfgAction >> "shortcut");
private _id = _vehicle addAction [_title, {
ACE_Player action ["Gear", objNull];
}, nil, 5.1, _showWindow, _hideOnUse, _shortcut, "!(lockedInventory _target)"];
_vehicle setUserActionText [_id, _title, _textDefault];
};
// Unnecessary to add actions to a vehicle class that's already got them
if (_type in GVAR(initializedVehicleClasses)) exitWith {};
if (_vehicle getVariable [QGVAR(initVehicle),false]) exitWith {};
// Vehicles given cargo via eden have their actions added to the object
// So this function may run for multiple of the same class in that case
if (_hasCargoConfig) then {
GVAR(initializedVehicleClasses) pushBack _type;
TRACE_1("Adding unload cargo action to class",_type);
[_type, 0, ["ACE_MainActions"], GVAR(vehicleAction)] call EFUNC(interact_menu,addActionToClass);
} else {
_vehicle setVariable [QGVAR(initVehicle), true];
TRACE_1("Adding unload cargo action to object",_vehicle);
[_vehicle, 0, ["ACE_MainActions"], GVAR(vehicleAction)] call EFUNC(interact_menu,addActionToObject);
};
// Add the paradrop self interaction for planes and helicopters
if (_vehicle isKindOf "Air") then {
private _condition = {
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{[_player, _target, []] call EFUNC(common,canInteractWith)} && {
private _turretPath = _target unitTurret _player;
(_player == currentPilot _target) || // Pilot/Co-pilot
{(getNumber ([_target, _turretPath] call CBA_fnc_getTurret >> "isCopilot")) == 1} || // Co-pilot
{_turretPath in (getArray (configOf _target >> QGVAR(loadmasterTurrets)))}
}
};
private _statement = {
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(interactionVehicle) = _target;
GVAR(interactionParadrop) = true;
ACE_Player action ["Gear", _target];
};
private _text = LLSTRING(openMenu);
private _icon = "";
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
// Self action on the vehicle
if (_hasCargoConfig) then {
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass);
} else {
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
};
};