From feee7f5e1e448c24a7f848f275c770a7c2264aaf Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Wed, 14 Jun 2017 08:36:23 -0500 Subject: [PATCH] Make array of cargo holders dynamic (#5274) --- addons/cargo/XEH_preInit.sqf | 1 + addons/cargo/functions/fnc_addCargoVehiclesActions.sqf | 2 +- addons/cargo/functions/fnc_initObject.sqf | 2 +- addons/cargo/functions/fnc_initVehicle.sqf | 10 ++++++++++ addons/cargo/functions/fnc_startLoadIn.sqf | 2 +- addons/cargo/script_component.hpp | 2 -- 6 files changed, 14 insertions(+), 5 deletions(-) diff --git a/addons/cargo/XEH_preInit.sqf b/addons/cargo/XEH_preInit.sqf index 7784968d3f..5ee6406a7d 100644 --- a/addons/cargo/XEH_preInit.sqf +++ b/addons/cargo/XEH_preInit.sqf @@ -8,5 +8,6 @@ PREP_RECOMPILE_END; GVAR(initializedItemClasses) = []; GVAR(initializedVehicleClasses) = []; +GVAR(cargoHolderTypes) = ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"]; ADDON = true; diff --git a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf index aeace6960b..176b2f31b6 100644 --- a/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf +++ b/addons/cargo/functions/fnc_addCargoVehiclesActions.sqf @@ -40,6 +40,6 @@ private _actions = []; 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]); +} forEach (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]); _actions diff --git a/addons/cargo/functions/fnc_initObject.sqf b/addons/cargo/functions/fnc_initObject.sqf index 3ab2061b0d..d2ce8e5b58 100644 --- a/addons/cargo/functions/fnc_initObject.sqf +++ b/addons/cargo/functions/fnc_initObject.sqf @@ -56,7 +56,7 @@ private _condition = { private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false]; private _hasCargoConfig = getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) == 1; (_hasCargoPublic || _hasCargoConfig) && {_x != _target} - } count (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE])} + } count (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE])} }; private _statement = { params ["_target", "_player"]; diff --git a/addons/cargo/functions/fnc_initVehicle.sqf b/addons/cargo/functions/fnc_initVehicle.sqf index f27f289ad5..6d3709a329 100644 --- a/addons/cargo/functions/fnc_initVehicle.sqf +++ b/addons/cargo/functions/fnc_initVehicle.sqf @@ -27,6 +27,16 @@ private _hasCargoConfig = getNumber (configFile >> "CfgVehicles" >> _type >> QGV // Nothing to do here if vehicle has no cargo space if !(_hasCargoConfig || _hasCargoPublic) exitWith {}; +// 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; +}; + // Vehicle can have default ace cargo in its config if (isServer) then { { diff --git a/addons/cargo/functions/fnc_startLoadIn.sqf b/addons/cargo/functions/fnc_startLoadIn.sqf index 0116a34a73..4fa0401772 100644 --- a/addons/cargo/functions/fnc_startLoadIn.sqf +++ b/addons/cargo/functions/fnc_startLoadIn.sqf @@ -24,7 +24,7 @@ private _vehicle = _cargoVehicle; if (isNull _vehicle) then { { if ([_object, _x] call FUNC(canLoadItemIn)) exitWith {_vehicle = _x}; - } forEach (nearestObjects [_player, CARGO_VEHICLE_CLASSES, MAX_LOAD_DISTANCE]); + } forEach (nearestObjects [_player, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE]); }; if (isNull _vehicle) exitWith { diff --git a/addons/cargo/script_component.hpp b/addons/cargo/script_component.hpp index 885308a3b9..3ae6331f91 100644 --- a/addons/cargo/script_component.hpp +++ b/addons/cargo/script_component.hpp @@ -18,8 +18,6 @@ #define MAX_LOAD_DISTANCE 10 -#define CARGO_VEHICLE_CLASSES ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"] - #define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default}) // Default cargo size is -1 as 0 is a valid size