From b9eb48c64d4d9bf549bbe428f523b62fa5aeeb39 Mon Sep 17 00:00:00 2001 From: Vdauphin Date: Fri, 6 Nov 2020 22:16:13 +0100 Subject: [PATCH] Overwrite BI unload all vehicles Use ACE own interraction to unload all vehicles as BI action unload all vehicles do. --- addons/cargo/CfgActions.hpp | 6 +++++ addons/cargo/XEH_PREP.hpp | 2 ++ addons/cargo/XEH_postInit.sqf | 16 ++++++++++++ addons/cargo/config.cpp | 1 + .../fnc_canShowUnloadAllVehicles.sqf | 26 +++++++++++++++++++ .../cargo/functions/fnc_unloadAllVehicles.sqf | 26 +++++++++++++++++++ 6 files changed, 77 insertions(+) create mode 100644 addons/cargo/CfgActions.hpp create mode 100644 addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf create mode 100644 addons/cargo/functions/fnc_unloadAllVehicles.sqf diff --git a/addons/cargo/CfgActions.hpp b/addons/cargo/CfgActions.hpp new file mode 100644 index 0000000000..6ab5949419 --- /dev/null +++ b/addons/cargo/CfgActions.hpp @@ -0,0 +1,6 @@ +class CfgActions { + class None; + class UnloadAllVehicles: None { + show = 0; + }; +}; diff --git a/addons/cargo/XEH_PREP.hpp b/addons/cargo/XEH_PREP.hpp index ad22d5116f..1fbea404a7 100644 --- a/addons/cargo/XEH_PREP.hpp +++ b/addons/cargo/XEH_PREP.hpp @@ -1,6 +1,7 @@ PREP(addCargoItem); PREP(addCargoVehiclesActions); PREP(canLoadItemIn); +PREP(canShowUnloadAllVehicles); PREP(canUnloadItem); PREP(getCargoSpaceLeft); PREP(getSizeItem); @@ -17,5 +18,6 @@ PREP(setSize); PREP(setSpace); PREP(startLoadIn); PREP(startUnload); +PREP(unloadAllVehicles); PREP(unloadItem); PREP(validateCargoSpace); diff --git a/addons/cargo/XEH_postInit.sqf b/addons/cargo/XEH_postInit.sqf index 7ea978dc73..5289185151 100644 --- a/addons/cargo/XEH_postInit.sqf +++ b/addons/cargo/XEH_postInit.sqf @@ -78,6 +78,18 @@ GVAR(vehicleAction) = [ } ] call EFUNC(interact_menu,createAction); +GVAR(unloadAllVehiclesAction) = [ + QGVAR(unloadAllvehicles), localize "STR_A3_ACTION_UNLOAD_ALL_VEHICLES", "\A3\Ui_f\data\IGUI\Cfg\Actions\unloadAllVehicles_ca.paa", + { + params ["_target"]; + [_target] call FUNC(unloadAllVehicles); + }, + { + params ["_target", "_player"]; + [_target, _player] call FUNC(canShowUnloadAllVehicles); + } +] call EFUNC(interact_menu,createAction); + GVAR(objectAction) = [ QGVAR(load), localize LSTRING(loadObject), "a3\ui_f\data\IGUI\Cfg\Actions\loadVehicle_ca.paa", { @@ -101,6 +113,10 @@ GVAR(objectAction) = [ LINKFUNC(addCargoVehiclesActions) ] call EFUNC(interact_menu,createAction); +{ + [_x, 1, ["ACE_SelfActions"], GVAR(unloadAllVehiclesAction), true] call EFUNC(interact_menu,addActionToClass); +} forEach ["LandVehicle", "Ship", "Air"]; + // find all remaining configured classes and init them, see XEH_preStart.sqf private _vehicleClassesAddAction = call (uiNamespace getVariable [QGVAR(initializedVehicleClasses), {[]}]); { diff --git a/addons/cargo/config.cpp b/addons/cargo/config.cpp index 31f01ffd72..3692d2dc29 100644 --- a/addons/cargo/config.cpp +++ b/addons/cargo/config.cpp @@ -19,3 +19,4 @@ class CfgPatches { #include "CfgEventHandlers.hpp" #include "CfgVehicles.hpp" #include "menu.hpp" +#include "CfgActions.hpp" diff --git a/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf b/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf new file mode 100644 index 0000000000..2aa594230e --- /dev/null +++ b/addons/cargo/functions/fnc_canShowUnloadAllVehicles.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Vdauphin + * Checks if unload all vehicles interaction can be show. + * + * Arguments: + * 0: Vehicle + * 1: Unit + * + * Return Value: + * Can show menu + * + * Example: + * [vehicle player, player] call ace_cargo_fnc_canShowUnloadAllVehicles + * + * Public: No + */ + +params [ + "_vehicle", + ["_unit", player, [objNull]] +]; + +driver _vehicle isEqualTo _unit && +{isClass (configfile >> "CfgVehicles" >> typeOf _vehicle >> "VehicleTransport" >> "Carrier")} && +{!(getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []]) isEqualTo [])} diff --git a/addons/cargo/functions/fnc_unloadAllVehicles.sqf b/addons/cargo/functions/fnc_unloadAllVehicles.sqf new file mode 100644 index 0000000000..fcfe808445 --- /dev/null +++ b/addons/cargo/functions/fnc_unloadAllVehicles.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Vdauphin + * Unload all vehicles but not ACE Cargo. + * + * Arguments: + * 0: Vehicle + * + * Return Value: + * Loaded vehiclesnot part of ACE Cargo + * + * Example: + * [vehicle player] call ace_cargo_fnc_unloadAllVehicles + * + * Public: No + */ + +params ["_vehicle"]; + +private _loadedVehicles = getVehicleCargo _vehicle - (_vehicle getVariable [QGVAR(loaded), []]); +private _unloadingInterval = getNumber (configfile >> "CfgVehicles" >> typeOf _vehicle >> "VehicleTransport" >> "Carrier" >> "unloadingInterval"); +{ + [{objnull setVehicleCargo _this}, _x, _forEachIndex * _unloadingInterval] call CBA_fnc_waitAndExecute; +} forEach _loadedVehicles; + +_loadedVehicles