2023-09-12 18:58:10 +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:
|
2023-11-17 23:07:28 +00:00
|
|
|
* cursorObject call ace_cargo_fnc_initVehicle
|
2015-08-16 20:41:35 +00:00
|
|
|
*
|
2015-08-10 21:07:47 +00:00
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_vehicle"];
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("params",_vehicle);
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2016-01-19 03:53:48 +00:00
|
|
|
private _type = typeOf _vehicle;
|
2022-03-09 03:41:21 +00:00
|
|
|
private _config = configOf _vehicle;
|
2015-08-10 21:07:47 +00:00
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// If vehicle had space given to it via eden/public, then override config hasCargo setting
|
2024-04-02 20:46:14 +00:00
|
|
|
private _hasCargoPublic = _vehicle getVariable QGVAR(hasCargo);
|
2024-04-23 21:07:16 +00:00
|
|
|
private _hasCargoPublicDefined = !isNil "_hasCargoPublic";
|
2024-02-07 12:16:18 +00:00
|
|
|
|
|
|
|
if (_hasCargoPublicDefined && {!(_hasCargoPublic isEqualType false)}) then {
|
2024-04-02 20:46:14 +00:00
|
|
|
WARNING_4("%1[%2] - Variable %3 is %4 - Should be bool",_vehicle,_type,QGVAR(hasCargo),_hasCargoPublic);
|
2024-02-07 12:16:18 +00:00
|
|
|
};
|
|
|
|
|
2022-03-09 03:41:21 +00:00
|
|
|
private _hasCargoConfig = getNumber (_config >> 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
|
2024-02-07 12:16:18 +00:00
|
|
|
if !((_hasCargoPublicDefined && {_hasCargoPublic in [true, 1]}) || {!_hasCargoPublicDefined && {_hasCargoConfig}}) exitWith {};
|
2017-05-31 22:54:57 +00:00
|
|
|
|
2017-06-14 13:36:23 +00:00
|
|
|
// Check if cargo is in cargo holder types (checked when trying to search for loadable objects)
|
2023-11-17 23:07:28 +00:00
|
|
|
private _addCargoType = GVAR(cargoHolderTypes) findIf {_type isKindOf _x} == -1;
|
|
|
|
|
2017-06-14 13:36:23 +00:00
|
|
|
TRACE_2("",_addCargoType,_type);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2017-06-14 13:36:23 +00:00
|
|
|
if (_addCargoType) then {
|
|
|
|
GVAR(cargoHolderTypes) pushBack _type;
|
|
|
|
};
|
|
|
|
|
2023-11-17 23:07:28 +00:00
|
|
|
// 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
|
2015-08-11 21:18:01 +00:00
|
|
|
if (isServer) then {
|
2023-11-17 23:07:28 +00:00
|
|
|
_vehicle setVariable [QGVAR(initVehicle), true];
|
|
|
|
|
|
|
|
private _cargoClassname = "";
|
|
|
|
private _cargoCount = 0;
|
2024-05-22 06:32:46 +00:00
|
|
|
private _loaded = 0;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2015-08-11 21:18:01 +00:00
|
|
|
{
|
2023-11-17 23:07:28 +00:00
|
|
|
_cargoClassname = getText (_x >> "type");
|
|
|
|
_cargoCount = getNumber (_x >> "amount");
|
|
|
|
|
2024-05-22 06:32:46 +00:00
|
|
|
TRACE_3("adding ace_cargo",configName _x,_cargoClassname,_cargoCount);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2024-05-22 06:32:46 +00:00
|
|
|
// Ignore stability check (distance check is also ignored with this, but it's ignored by default if item is a string)
|
|
|
|
_loaded = [_cargoClassname, _vehicle, _cargoCount, true] call FUNC(addCargoItem);
|
|
|
|
|
|
|
|
// Let loop continue until the end, so that it prints everything into the rpt (there might be smaller items that could still fit in cargo)
|
|
|
|
if (_loaded != _cargoCount) then {
|
|
|
|
WARNING_5("%1 (%2) could not fit %3 %4 inside its cargo, only %5 were loaded.",_vehicle,_type,_cargoCount,_cargoClassname,_loaded);
|
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
} forEach ("true" configClasses (_config >> QUOTE(ADDON) >> "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)
|
2023-11-17 23:07:28 +00:00
|
|
|
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 {};
|
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;
|
2023-11-17 23:07:28 +00:00
|
|
|
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Adding unload cargo action to class",_type);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
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 {
|
2023-11-17 23:07:28 +00:00
|
|
|
_vehicle setVariable [QGVAR(initVehicle), true];
|
|
|
|
|
2024-02-05 17:04:24 +00:00
|
|
|
TRACE_1("Adding unload cargo action to object",_vehicle);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
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"];
|
2023-11-17 23:07:28 +00:00
|
|
|
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)))}
|
|
|
|
}
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
|
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);
|
|
|
|
};
|
2023-11-17 23:07:28 +00:00
|
|
|
|
|
|
|
private _text = LLSTRING(openMenu);
|
2016-08-27 08:14:54 +00:00
|
|
|
private _icon = "";
|
|
|
|
|
|
|
|
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
|
2023-11-17 23:07:28 +00:00
|
|
|
|
|
|
|
// Self action on the vehicle
|
2017-05-31 22:54:57 +00:00
|
|
|
if (_hasCargoConfig) then {
|
2023-11-17 23:07:28 +00:00
|
|
|
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass);
|
2017-05-31 22:54:57 +00:00
|
|
|
} else {
|
|
|
|
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
|
|
|
|
};
|
2016-08-27 08:14:54 +00:00
|
|
|
};
|