2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2015-08-10 21:07:47 +00:00
|
|
|
/*
|
|
|
|
* Author: Glowbal
|
2015-08-18 21:59:01 +00:00
|
|
|
* Initializes vehicle, adds open cargo menu action if available.
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
|
|
|
* Arguments:
|
2015-08-16 20:41:35 +00:00
|
|
|
* 0: Vehicle <OBJECT>
|
2015-08-10 21:07:47 +00:00
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* None
|
|
|
|
*
|
2015-08-16 20:41:35 +00:00
|
|
|
* Example:
|
|
|
|
* [vehicle] call ace_cargo_fnc_initVehicle
|
|
|
|
*
|
2015-08-10 21:07:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_vehicle"];
|
|
|
|
TRACE_1("params", _vehicle);
|
|
|
|
|
2016-01-19 03:53:48 +00:00
|
|
|
private _type = typeOf _vehicle;
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// If vehicle had space given to it via eden/public then override config hasCargo setting
|
|
|
|
private _hasCargoPublic = _vehicle getVariable [QGVAR(hasCargo), false];
|
|
|
|
private _hasCargoConfig = getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) == 1;
|
2016-04-03 12:17:16 +00:00
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// Nothing to do here if vehicle has no cargo space
|
|
|
|
if !(_hasCargoConfig || _hasCargoPublic) exitWith {};
|
|
|
|
|
2017-06-14 13:36:23 +00:00
|
|
|
// Check if cargo is in cargo holder types (checked when trying to search for loadable objects)
|
|
|
|
private _addCargoType = true;
|
|
|
|
{
|
|
|
|
if (_type isKindOf _x) exitWith {_addCargoType = false};
|
|
|
|
} forEach GVAR(cargoHolderTypes);
|
|
|
|
TRACE_2("",_addCargoType,_type);
|
|
|
|
if (_addCargoType) then {
|
|
|
|
GVAR(cargoHolderTypes) pushBack _type;
|
|
|
|
};
|
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// Vehicle can have default ace cargo in its config
|
2015-08-11 21:18:01 +00:00
|
|
|
if (isServer) then {
|
|
|
|
{
|
|
|
|
if (isClass _x) then {
|
2016-09-04 14:44:22 +00:00
|
|
|
private _cargoClassname = getText (_x >> "type");
|
|
|
|
private _cargoCount = getNumber (_x >> "amount");
|
2015-09-20 15:05:34 +00:00
|
|
|
TRACE_3("adding ACE_Cargo", (configName _x), _cargoClassname, _cargoCount);
|
2016-06-24 15:12:19 +00:00
|
|
|
["ace_addCargo", [_cargoClassname, _vehicle, _cargoCount]] call CBA_fnc_localEvent;
|
2015-08-11 21:18:01 +00:00
|
|
|
};
|
2015-08-14 16:07:31 +00:00
|
|
|
} count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo"));
|
2015-08-11 21:18:01 +00:00
|
|
|
};
|
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// Servers and HCs do not require action menus (beyond this point)
|
|
|
|
if !(hasInterface) exitWith {};
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// 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 {};
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2017-05-31 22:54:57 +00:00
|
|
|
// 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);
|
2018-02-24 18:39:03 +00:00
|
|
|
[_type, 0, ["ACE_MainActions"], GVAR(vehicleAction)] call EFUNC(interact_menu,addActionToClass);
|
2017-05-31 22:54:57 +00:00
|
|
|
} else {
|
|
|
|
_vehicle setVariable [QGVAR(initVehicle),true];
|
|
|
|
TRACE_1("Adding unload cargo action to object", _vehicle);
|
2018-02-24 18:39:03 +00:00
|
|
|
[_vehicle, 0, ["ACE_MainActions"], GVAR(vehicleAction)] call EFUNC(interact_menu,addActionToObject);
|
2017-05-31 22:54:57 +00:00
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
|
|
|
|
// Add the paradrop self interaction for planes and helicopters
|
|
|
|
if (_vehicle isKindOf "Air") then {
|
|
|
|
private _condition = {
|
2017-05-31 21:09:36 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
|
2016-08-27 08:14:54 +00:00
|
|
|
GVAR(enable) && {[_player, _target, []] call EFUNC(common,canInteractWith)} && {
|
|
|
|
private _turretPath = _player call CBA_fnc_turretPath;
|
|
|
|
(_player == (driver _target)) || // pilot
|
|
|
|
{(getNumber (([_target, _turretPath] call CBA_fnc_getTurret) >> "isCopilot")) == 1} || // coPilot
|
2021-02-18 18:58:08 +00:00
|
|
|
{_turretPath in (getArray (configOf _target >> QGVAR(loadmasterTurrets)))}} // loadMaster turret from config
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|
|
|
|
private _statement = {
|
2017-05-31 21:09:36 +00:00
|
|
|
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
|
2016-08-27 08:14:54 +00:00
|
|
|
GVAR(interactionVehicle) = _target;
|
|
|
|
GVAR(interactionParadrop) = true;
|
|
|
|
createDialog QGVAR(menu);
|
|
|
|
};
|
|
|
|
private _text = localize LSTRING(openMenu);
|
|
|
|
private _icon = "";
|
|
|
|
|
|
|
|
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
|
2017-05-31 22:54:57 +00:00
|
|
|
if (_hasCargoConfig) then {
|
|
|
|
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); // self action on the vehicle
|
|
|
|
} else {
|
|
|
|
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|