From c016d01414a23a2549b146db32a12f551aa63025 Mon Sep 17 00:00:00 2001 From: Glowbal Date: Mon, 10 Aug 2015 23:07:47 +0200 Subject: [PATCH] Initial load in cargo module --- addons/cargo/CfgEventHandlers.hpp | 48 ++++++++ addons/cargo/CfgVehicles.hpp | 63 +++++++++++ addons/cargo/XEH_preInit.sqf | 21 +++- addons/cargo/config.cpp | 8 +- addons/cargo/functions/fnc_canLoad.sqf | 23 ++++ addons/cargo/functions/fnc_canLoadItemIn.sqf | 23 ++++ addons/cargo/functions/fnc_canUnloadItem.sqf | 39 +++++++ addons/cargo/functions/fnc_empty.sqf | 3 - .../functions/fnc_findNearestVehicle.sqf | 31 ++++++ .../cargo/functions/fnc_getCargoSpaceLeft.sqf | 17 +++ addons/cargo/functions/fnc_getSizeItem.sqf | 20 ++++ .../cargo/functions/fnc_handleDestroyed.sqf | 27 +++++ addons/cargo/functions/fnc_initObject.sqf | 28 +++++ addons/cargo/functions/fnc_initVehicle.sqf | 39 +++++++ addons/cargo/functions/fnc_loadItem.sqf | 34 ++++++ addons/cargo/functions/fnc_onMenuOpen.sqf | 44 ++++++++ addons/cargo/functions/fnc_startLoadIn.sqf | 22 ++++ addons/cargo/functions/fnc_startUnload.sqf | 31 ++++++ addons/cargo/functions/fnc_unloadItem.sqf | 63 +++++++++++ .../functions/fnc_validateCargoSpace.sqf | 31 ++++++ addons/cargo/menu.hpp | 104 ++++++++++++++++++ addons/cargo/script_component.hpp | 4 +- addons/cargo/stringtable.xml | 20 ++++ 23 files changed, 735 insertions(+), 8 deletions(-) create mode 100644 addons/cargo/CfgVehicles.hpp create mode 100644 addons/cargo/functions/fnc_canLoad.sqf create mode 100644 addons/cargo/functions/fnc_canLoadItemIn.sqf create mode 100644 addons/cargo/functions/fnc_canUnloadItem.sqf delete mode 100644 addons/cargo/functions/fnc_empty.sqf create mode 100644 addons/cargo/functions/fnc_findNearestVehicle.sqf create mode 100644 addons/cargo/functions/fnc_getCargoSpaceLeft.sqf create mode 100644 addons/cargo/functions/fnc_getSizeItem.sqf create mode 100644 addons/cargo/functions/fnc_handleDestroyed.sqf create mode 100644 addons/cargo/functions/fnc_initObject.sqf create mode 100644 addons/cargo/functions/fnc_initVehicle.sqf create mode 100644 addons/cargo/functions/fnc_loadItem.sqf create mode 100644 addons/cargo/functions/fnc_onMenuOpen.sqf create mode 100644 addons/cargo/functions/fnc_startLoadIn.sqf create mode 100644 addons/cargo/functions/fnc_startUnload.sqf create mode 100644 addons/cargo/functions/fnc_unloadItem.sqf create mode 100644 addons/cargo/functions/fnc_validateCargoSpace.sqf create mode 100644 addons/cargo/menu.hpp create mode 100644 addons/cargo/stringtable.xml diff --git a/addons/cargo/CfgEventHandlers.hpp b/addons/cargo/CfgEventHandlers.hpp index f0a9f14d91..603e156c50 100644 --- a/addons/cargo/CfgEventHandlers.hpp +++ b/addons/cargo/CfgEventHandlers.hpp @@ -4,3 +4,51 @@ class Extended_PreInit_EventHandlers { init = QUOTE(call COMPILE_FILE(XEH_preInit)); }; }; + +class Extended_Killed_EventHandlers { + class All { + init = QUOTE(call FUNC(handleDestroyed)); + }; +}; + +class Extended_Init_EventHandlers { + class StaticWeapon { + class ADDON { + init = QUOTE(_this call DFUNC(initObject)); + }; + }; + class ReammoBox_F { + class ADDON { + init = QUOTE(_this call DFUNC(initObject)); + }; + }; + class Car { + class ADDON { + init = QUOTE(_this call DFUNC(initVehicle)); + }; + }; + + class Tank { + class ADDON { + init = QUOTE(_this call DFUNC(initVehicle)); + }; + }; + + class Helicopter { + class ADDON { + init = QUOTE(_this call DFUNC(initVehicle)); + }; + }; + + class Plane { + class ADDON { + init = QUOTE(_this call DFUNC(initVehicle)); + }; + }; + + class Ship_F { + class ADDON { + init = QUOTE(_this call DFUNC(initVehicle)); + }; + }; +}; diff --git a/addons/cargo/CfgVehicles.hpp b/addons/cargo/CfgVehicles.hpp new file mode 100644 index 0000000000..d9113bd295 --- /dev/null +++ b/addons/cargo/CfgVehicles.hpp @@ -0,0 +1,63 @@ + +class CfgVehicles { + class LandVehicle; + class Car: LandVehicle { + GVAR(space) = 4; + GVAR(hasCargo) = 1; + }; + + class Tank: LandVehicle { + GVAR(space) = 4; + GVAR(hasCargo) = 1; + }; + class Car_F; + class Truck_F: Car_F { + GVAR(space) = 8; + GVAR(hasCargo) = 1; + }; + + class Air; + // Repair helicopters + class Helicopter: Air { + GVAR(space) = 8; + GVAR(hasCargo) = 1; + }; + + class Heli_Transport_02_base_F; + class I_Heli_Transport_02_F : Heli_Transport_02_base_F { + GVAR(space) = 20; + GVAR(hasCargo) = 1; + }; + + // Repair fixed wing aircraft + class Plane: Air { + GVAR(space) = 4; + GVAR(hasCargo) = 1; + }; + + // boats + class Ship; + class Ship_F: Ship { + GVAR(space) = 4; + GVAR(hasCargo) = 1; + }; + + // Static weapons + class StaticWeapon: LandVehicle { + GVAR(size) = 2; // 1 = small, 2 = large + GVAR(canLoad) = 1; + }; + + class StaticMortar; + class Mortar_01_base_F: StaticMortar { + GVAR(size) = 2; // 1 = small, 2 = large + GVAR(canLoad) = 1; + }; + + // Ammo boxes + class ThingX; + class ReammoBox_F: ThingX { + GVAR(size) = 2; // 1 = small, 2 = large + GVAR(canLoad) = 1; + }; +}; diff --git a/addons/cargo/XEH_preInit.sqf b/addons/cargo/XEH_preInit.sqf index 69abb46fa9..067d131717 100644 --- a/addons/cargo/XEH_preInit.sqf +++ b/addons/cargo/XEH_preInit.sqf @@ -2,6 +2,25 @@ ADDON = false; -PREP(empty); +PREP(canLoadItemIn); +PREP(canUnloadItem); +PREP(canLoad); +PREP(findNearestVehicle); +PREP(getCargoSpaceLeft); +PREP(GetSizeItem); +PREP(initObject); +PREP(initVehicle); +PREP(handleDestroyed); +PREP(loadItem); +PREP(onMenuOpen); +PREP(unloadItem); +PREP(validateCargoSpace); +PREP(startLoadIn); +PREP(startUnload); +GVAR(initializedItemClasses) = []; + +if (isServer) then { + ["cargo_hideItem", {(_this select 0) hideObjectGlobal (_this select 1);}] call EFUNC(common,addEventHandler); +}; ADDON = true; diff --git a/addons/cargo/config.cpp b/addons/cargo/config.cpp index 7e6cb24ff2..3f1438a2f2 100644 --- a/addons/cargo/config.cpp +++ b/addons/cargo/config.cpp @@ -5,11 +5,13 @@ class CfgPatches { units[] = {}; weapons[] = {}; requiredVersion = REQUIRED_VERSION; - requiredAddons[] = {"ace_common","ace_interaction","ace_interact_menu"}; - author[] = {"commy2"}; - authorUrl = "https://github.com/commy2"; + requiredAddons[] = {"ace_interaction"}; + author[] = {"commy2", "Glowbal"}; + authorUrl = "https://ace3mod.com/"; VERSION_CONFIG; }; }; #include "CfgEventHandlers.hpp" +#include "CfgVehicles.hpp" +#include "menu.hpp" \ No newline at end of file diff --git a/addons/cargo/functions/fnc_canLoad.sqf b/addons/cargo/functions/fnc_canLoad.sqf new file mode 100644 index 0000000000..1b6488da6b --- /dev/null +++ b/addons/cargo/functions/fnc_canLoad.sqf @@ -0,0 +1,23 @@ +/* + * Author: Glowbal + * Check if player can load item into the nearest vehicle + * + * Arguments: + * 0: Player + * 1: Object to load + * + * Return value: + * Can load + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_player", "_object"]; + +private ["_nearestVehicle"]; +_nearestVehicle = [_player] call FUNC(findNearestVehicle); +if (isNull _nearestVehicle) exitwith {false}; + +[_object, _nearestVehicle] call FUNC(canLoadItemIn); diff --git a/addons/cargo/functions/fnc_canLoadItemIn.sqf b/addons/cargo/functions/fnc_canLoadItemIn.sqf new file mode 100644 index 0000000000..e777e2dd53 --- /dev/null +++ b/addons/cargo/functions/fnc_canLoadItemIn.sqf @@ -0,0 +1,23 @@ +/* + * Author: Glowbal + * Check if item can be loaded into other Object + * + * Arguments: + * 0: Any object + * 1: Object + * + * Return value: + * Can load in + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_item", "_vehicle"]; + +if (speed _vehicle > 1 || (((getPos _vehicle) select 2) > 3)) exitwith {false}; + +private "_itemSize"; +_itemSize = ([_item] call FUNC(getSizeItem)); +_itemSize > 0 && {alive _item && alive _vehicle} && {(_item distance _vehicle <= MAX_LOAD_DISTANCE)} && {_itemSize <= ([_vehicle] call FUNC(getCargoSpaceLeft))}; diff --git a/addons/cargo/functions/fnc_canUnloadItem.sqf b/addons/cargo/functions/fnc_canUnloadItem.sqf new file mode 100644 index 0000000000..2770528a63 --- /dev/null +++ b/addons/cargo/functions/fnc_canUnloadItem.sqf @@ -0,0 +1,39 @@ +/* + * Author: Glowbal, ViperMaul + * Check if item can be unloaded + * + * Arguments: + * 0: loaded object + * 1: Object + * + * Return value: + * Can be unloaded + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_loaded", "_position", "_validVehiclestate", "_emptyPos"]; +params ["_item", "_vehicle"]; +_loaded = _vehicle getvariable [QGVAR(loaded), []]; +if !(_item in _loaded) exitwith {false}; + +_validVehiclestate = true; +_emptyPos = []; +if (_vehicle isKindOf "Ship" ) then { + if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false}; + _emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 15, typeOf _item]); // TODO: if spot is underwater pick another spot. +} else { + if (_vehicle isKindOf "Air" ) then { + if !(speed _vehicle <1 && {isTouchingGround _vehicle}) then {_validVehiclestate = false}; + _emptyPos = (getPosASL _vehicle) call EFUNC(common,ASLtoPosition); + _emptyPos = [(_emptyPos select 0) + random(5), (_emptyPos select 1) + random(5), _emptyPos select 2 ]; + } else { + if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false}; + _emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 15, typeOf _item]); + }; +}; + +if (!_validVehiclestate) exitwith { false }; +(count _emptyPos != 0); diff --git a/addons/cargo/functions/fnc_empty.sqf b/addons/cargo/functions/fnc_empty.sqf deleted file mode 100644 index c60a82b2d8..0000000000 --- a/addons/cargo/functions/fnc_empty.sqf +++ /dev/null @@ -1,3 +0,0 @@ -#include "script_component.hpp" - -diag_log text format["This is here as an example!!!"]; diff --git a/addons/cargo/functions/fnc_findNearestVehicle.sqf b/addons/cargo/functions/fnc_findNearestVehicle.sqf new file mode 100644 index 0000000000..7828eca8a9 --- /dev/null +++ b/addons/cargo/functions/fnc_findNearestVehicle.sqf @@ -0,0 +1,31 @@ +/* + * Author: Glowbal + * Get nearest vehicle, priority car, air, tank, ship + * + * Arguments: + * 0: Object + * + * Return value: + * Can load + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_vehicle"]; +params ["_unit"]; + +_vehicle = nearestObject [_unit, "car"]; +if (_unit distance _vehicle <= MAX_LOAD_DISTANCE) exitwith {_vehicle}; + +_loadhelicopter = nearestObject [_unit, "air"]; +if (_unit distance _vehicle <= MAX_LOAD_DISTANCE) exitwith {_vehicle}; + +_loadtank = nearestObject [_unit, "tank"]; +if (_unit distance _vehicle <= MAX_LOAD_DISTANCE) exitwith {_vehicle}; + +_loadtank = nearestObject [_unit, "ship"]; +if (_unit distance _vehicle <= MAX_LOAD_DISTANCE) exitwith {_vehicle}; + +objNull; diff --git a/addons/cargo/functions/fnc_getCargoSpaceLeft.sqf b/addons/cargo/functions/fnc_getCargoSpaceLeft.sqf new file mode 100644 index 0000000000..3c50e24ad3 --- /dev/null +++ b/addons/cargo/functions/fnc_getCargoSpaceLeft.sqf @@ -0,0 +1,17 @@ +/* + * Author: Glowbal + * Get the cargo space left on object + * + * Arguments: + * 0: Object + * + * Return value: + * Cargo space left + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_vehicle"]; +_vehicle getvariable [QGVAR(space), getNumber (configFile >> "CfgVehicles" >> typeof _vehicle >> QGVAR(space))]; diff --git a/addons/cargo/functions/fnc_getSizeItem.sqf b/addons/cargo/functions/fnc_getSizeItem.sqf new file mode 100644 index 0000000000..3d079d6b3a --- /dev/null +++ b/addons/cargo/functions/fnc_getSizeItem.sqf @@ -0,0 +1,20 @@ +/* + * Author: Glowbal + * Get the cargo size of an object + * + * Arguments: + * 0: Object + * + * Return value: + * Cargo size. -1 is not a size defined + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_item"]; +if (isNumber (configFile >> "CfgVehicles" >> typeof _item >> QGVAR(size))) exitwith { + _item getvariable [QGVAR(size), getNumber (configFile >> "CfgVehicles" >> typeof _item >> QGVAR(size))]; +}; +-1; diff --git a/addons/cargo/functions/fnc_handleDestroyed.sqf b/addons/cargo/functions/fnc_handleDestroyed.sqf new file mode 100644 index 0000000000..54d4f1103b --- /dev/null +++ b/addons/cargo/functions/fnc_handleDestroyed.sqf @@ -0,0 +1,27 @@ +/* + * Author: Glowbal + * Handle object being destroyed + * + * Arguments: + * 0: Object + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_vehicle"]; + +_loaded = _vehicle getvariable [QGVAR(loaded), []]; +if (count _loaded == 0) exitwith {}; + +{ + // TODO deleteVehicle or just delete vehicle? Do we want to be able to recover destroyed equipment? + deleteVehicle _x; + //_x setDamage 1; +}foreach _loaded; + +[_vehicle] call FUNC(validateCargoSpace); diff --git a/addons/cargo/functions/fnc_initObject.sqf b/addons/cargo/functions/fnc_initObject.sqf new file mode 100644 index 0000000000..98aeb5afea --- /dev/null +++ b/addons/cargo/functions/fnc_initObject.sqf @@ -0,0 +1,28 @@ +/* + * Author: Glowbal + * Initialize variables for loadable objects. Called from init EH. + * + * Arguments: + * 0: Any object + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_object"]; + +if (getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(canLoad)) != 1) exitwith {}; + +private ["_type", "_action"]; +_type = typeOf _object; + +// do nothing if the class is already initialized +if (_type in GVAR(initializedItemClasses)) exitWith {}; +GVAR(initializedItemClasses) pushBack _type; + +_action = [QGVAR(load), localize LSTRING(loadObject), "", {[_player, _target] call FUNC(startLoadIn)}, {[_player, _target] call FUNC(canLoad)}] call EFUNC(interact_menu,createAction); +[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass); diff --git a/addons/cargo/functions/fnc_initVehicle.sqf b/addons/cargo/functions/fnc_initVehicle.sqf new file mode 100644 index 0000000000..241b23eb83 --- /dev/null +++ b/addons/cargo/functions/fnc_initVehicle.sqf @@ -0,0 +1,39 @@ +/* + * Author: Glowbal + * initalize vehicle. Adds open caro menu action if available + * + * Arguments: + * 0: vehicle + * + * Return Value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_vehicle"]; +TRACE_1("params", _vehicle); + +private ["_type", "_initializedClasses"]; + +_type = typeOf _vehicle; +_initializedClasses = GETMVAR(GVAR(initializedClasses),[]); + +// do nothing if the class is already initialized +if (_type in _initializedClasses) exitWith {}; +// set class as initialized +_initializedClasses pushBack _type; +SETMVAR(GVAR(initializedClasses),_initializedClasses); + +if (getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) != 1) exitwith {}; + +private ["_text", "_condition", "_statement", "_icon", "_action"]; +_text = localize "STR_ACE_Cargo_openMenu"; +_condition = {true}; +_statement = {diag_log format["_target %1", _target];GVAR(interactionVehicle) = _target; createDialog QGVAR(menu);}; +_icon = ""; + +_action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction); +[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass); diff --git a/addons/cargo/functions/fnc_loadItem.sqf b/addons/cargo/functions/fnc_loadItem.sqf new file mode 100644 index 0000000000..0abebdd43c --- /dev/null +++ b/addons/cargo/functions/fnc_loadItem.sqf @@ -0,0 +1,34 @@ +/* + * Author: Glowbal + * Load object into vehicle + * + * Arguments: + * 0: Object + * 1: Vehicle + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_loaded", "_space", "_itemSize"]; +params ["_item", "_vehicle"]; + +if !([_item, _vehicle] call FUNC(canLoadItemIn)) exitwith {false}; + +_loaded = _vehicle getvariable [QGVAR(loaded), []]; +_loaded pushback _item; +_vehicle setvariable [QGVAR(loaded), _loaded, true]; + +_space = [_vehicle] call FUNC(getCargoSpaceLeft); +_itemSize = [_item] call FUNC(getSizeItem); +_vehicle setvariable [QGVAR(space), _space - _itemSize, true]; + +detach _item; +_item attachTo [_vehicle,[0,0,100]]; +["cargo_hideItem", [_item, true]] call EFUNC(common,serverEvent); + +true; diff --git a/addons/cargo/functions/fnc_onMenuOpen.sqf b/addons/cargo/functions/fnc_onMenuOpen.sqf new file mode 100644 index 0000000000..e51e6ee2e8 --- /dev/null +++ b/addons/cargo/functions/fnc_onMenuOpen.sqf @@ -0,0 +1,44 @@ +/* + * Author: Glowbal + * Handle the UI data display + * + * Arguments: + * 0: display + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +disableSerialization; +params["_display"]; + +uiNamespace setvariable [QGVAR(menuDisplay), _display]; + +[{ + private ["_display","_loaded", "_ctrl", "_label"]; + disableSerialization; + _display = uiNamespace getvariable QGVAR(menuDisplay); + if (isnil "_display") exitwith { + [_this select 1] call CBA_fnc_removePerFrameHandler; + }; + + if (isNull GVAR(interactionVehicle) || ACE_player distance GVAR(interactionVehicle) >= 10) exitwith { + closeDialog 0; + [_this select 1] call CBA_fnc_removePerFrameHandler; + }; + + _loaded = GVAR(interactionVehicle) getvariable [QGVAR(loaded), []]; + _ctrl = _display displayCtrl 100; + _label = _display displayCtrl 2; + + lbClear _ctrl; + { + _ctrl lbAdd (getText(configfile >> "CfgVehicles" >> typeOf _x >> "displayName")); + }foreach _loaded; + + _label ctrlSetText format[localize "STR_ACE_Cargo_labelSpace", [GVAR(interactionVehicle)] call DFUNC(getCargoSpaceLeft)]; +}, 0, []] call CBA_fnc_addPerFrameHandler; diff --git a/addons/cargo/functions/fnc_startLoadIn.sqf b/addons/cargo/functions/fnc_startLoadIn.sqf new file mode 100644 index 0000000000..ae6a5ec934 --- /dev/null +++ b/addons/cargo/functions/fnc_startLoadIn.sqf @@ -0,0 +1,22 @@ +/* + * Author: Glowbal + * Start load item + * + * Arguments: + * 0: Any object + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +params ["_player", "_object"]; + +private ["_nearestVehicle"]; +_nearestVehicle = [_player] call FUNC(findNearestVehicle); + +if (isNull _nearestVehicle) exitwith {false}; +[_object, _nearestVehicle] call FUNC(loadItem); diff --git a/addons/cargo/functions/fnc_startUnload.sqf b/addons/cargo/functions/fnc_startUnload.sqf new file mode 100644 index 0000000000..03bad9299b --- /dev/null +++ b/addons/cargo/functions/fnc_startUnload.sqf @@ -0,0 +1,31 @@ +/* + * Author: Glowbal + * Start unload action + * + * Arguments: + * None + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_display", "_loaded", "_ctrl", "_selected", "_item"]; +disableSerialization; +_display = uiNamespace getvariable QGVAR(menuDisplay); +if (isnil "_display") exitwith {}; + +_loaded = GVAR(interactionVehicle) getvariable [QGVAR(loaded), []]; +if (count _loaded == 0) exitwith {}; + +_ctrl = _display displayCtrl 100; + +_selected = (lbCurSel _ctrl) max 0; + +if (count _loaded <= _selected) exitwith {systemChat format["count: %1 %2", count _loaded, _selected]}; +_item = _loaded select _selected; + +[_item, GVAR(interactionVehicle)] call FUNC(unloadItem); diff --git a/addons/cargo/functions/fnc_unloadItem.sqf b/addons/cargo/functions/fnc_unloadItem.sqf new file mode 100644 index 0000000000..fcc2a07796 --- /dev/null +++ b/addons/cargo/functions/fnc_unloadItem.sqf @@ -0,0 +1,63 @@ +/* + * Author: Glowbal, ViperMaul + * Unload object from vehicle + * + * Arguments: + * 0: Object + * 1: Vehicle + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_loaded", "_space", "_itemSize", "_emptyPos", "_validVehiclestate"]; +params ["_item", "_vehicle"]; + +if !([_item, _vehicle] call FUNC(canUnloadItem)) exitwith { + systemChat format["Can not unload item"]; + false +}; + +_validVehiclestate = true; +_emptyPos = []; +if (_vehicle isKindOf "Ship" ) then { + if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false}; + TRACE_1("SHIP Ground Check", getPosATL _vehicle ); + _emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 15, typeOf _item]); // TODO: if spot is underwater pick another spot. +} else { + if (_vehicle isKindOf "Air" ) then { + if !(speed _vehicle <1 && {isTouchingGround _vehicle}) then {_validVehiclestate = false}; + TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle); + _emptyPos = (getPosASL _vehicle) call EFUNC(common,ASLtoPosition); + _emptyPos = [(_emptyPos select 0) + random(5), (_emptyPos select 1) + random(5), _emptyPos select 2 ]; + } else { + if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false}; + TRACE_1("Vehicle Ground Check", isTouchingGround _vehicle); + _emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 13, typeOf _item]); + }; +}; + +TRACE_1("getPosASL Vehicle Check", getPosASL _vehicle); +if (!_validVehiclestate) exitwith { false }; + +if (count _emptyPos == 0) exitwith { false}; //consider displaying text saying there are no safe places to exit the vehicle + +_loaded = _vehicle getvariable [QGVAR(loaded), []]; +_loaded = _loaded - [_item]; +_vehicle setvariable [QGVAR(loaded), _loaded, true]; + +_space = [_vehicle] call FUNC(getCargoSpaceLeft); +_itemSize = [_item] call FUNC(getSizeItem); +_vehicle setvariable [QGVAR(space), _space + _itemSize, true]; + +detach _item; +_item setPosASL (_emptyPos call EFUNC(common,PositiontoASL)); +["cargo_hideItem", [_item, false]] call EFUNC(common,serverEvent); + +// TOOO maybe drag/carry the unloaded item? + +true; diff --git a/addons/cargo/functions/fnc_validateCargoSpace.sqf b/addons/cargo/functions/fnc_validateCargoSpace.sqf new file mode 100644 index 0000000000..34ac1ef981 --- /dev/null +++ b/addons/cargo/functions/fnc_validateCargoSpace.sqf @@ -0,0 +1,31 @@ +/* + * Author: Glowbal + * Validate the vehicle cargo space + * + * Arguments: + * 0: Object + * + * Return value: + * None + * + * Public: No + */ + +#include "script_component.hpp" + +private ["_loaded", "_newLoaded", "_totalSpaceOccupied"]; +params ["_vehicle"]; +_loaded = _vehicle getvariable [QGVAR(loaded), []]; +_newLoaded = []; +_totalSpaceOccupied = 0; +{ + if !(isNull _x) then { + _newLoaded pushback _x; + _totalSpaceOccupied = _totalSpaceOccupied + ([_x] call FUNC(getSizeItem)); + }; +}foreach _loaded; + +if (count _loaded != count _newLoaded) then { + _vehicle setvariable [QGVAR(loaded), _newLoaded, true]; +}; +_vehicle setvariable [QGVAR(space), getNumber (configFile >> "CfgVehicles" >> typeof _vehicle >> QGVAR(space)) - _totalSpaceOccupied, true]; diff --git a/addons/cargo/menu.hpp b/addons/cargo/menu.hpp new file mode 100644 index 0000000000..35976d19ad --- /dev/null +++ b/addons/cargo/menu.hpp @@ -0,0 +1,104 @@ + +#include "\z\ace\addons\common\define.hpp" + +class GVAR(menu) { + idd = 314614; + movingEnable = true; + onLoad = QUOTE([_this select 0] call FUNC(onMenuOpen)); + onUnload = QUOTE(uiNamespace setvariable [ARR_2(QUOTE(QGVAR(menuDisplay)),nil)];); + class controlsBackground { + class HeaderBackground: ACE_gui_backgroundBase{ + idc = -1; + SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)"; + x = "13 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + y = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + w = "13 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + text = "#(argb,8,8,3)color(0,0,0,0)"; + }; + class CenterBackground: HeaderBackground { + y = "2.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + h = "14 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + text = "#(argb,8,8,3)color(0,0,0,0.8)"; + colorText[] = {0, 0, 0, "(profilenamespace getvariable ['GUI_BCG_RGB_A',0.9])"}; + colorBackground[] = {0,0,0,"(profilenamespace getvariable ['GUI_BCG_RGB_A',0.9])"}; + }; + }; + + class controls { + class HeaderName { + idc = 1; + type = CT_STATIC; + x = "13 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + y = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + w = "13 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + style = ST_LEFT + ST_SHADOW; + font = "PuristaMedium"; + SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)"; + colorText[] = {0.95, 0.95, 0.95, 0.75}; + colorBackground[] = {"(profilenamespace getvariable ['GUI_BCG_RGB_R',0.69])","(profilenamespace getvariable ['GUI_BCG_RGB_G',0.75])","(profilenamespace getvariable ['GUI_BCG_RGB_B',0.5])", "(profilenamespace getvariable ['GUI_BCG_RGB_A',0.9])"}; + text = CSTRING(cargoMenu); + }; + class SubHeader: HeaderName { + idc = 2; + x = "13 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + y = "2.5 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + w = "13 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + style = ST_CENTER; + colorText[] = {1, 1, 1.0, 0.9}; + colorBackground[] = {0,0,0,0}; + SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1.2)"; + text = ""; + }; + class cargoList: ACE_gui_listBoxBase { + idc = 100; + x = "13.1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + y = "4 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + w = "12.8 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "10 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 0.7)"; + rowHeight = 0.03; + colorBackground[] = {0, 0, 0, 0.2}; + colorText[] = {1, 1, 1, 1.0}; + colorScrollbar[] = {0.95, 0.95, 0.95, 1}; + colorSelect[] = {1, 1, 1, 1.0}; + colorSelect2[] = {1, 1, 1, 1.0}; + colorSelectBackground[] = {0.3, 0.3, 0.3, 1.0}; + colorSelectBackground2[] = {0.3, 0.3, 0.3, 1.0}; + }; + class btnUnload: ACE_gui_buttonBase { + text = "Cancel"; + idc = 11; + x = "13.1 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + y = "14.1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2)"; + w = "5 * (((safezoneW / safezoneH) min 1.2) / 40)"; + h = "1 * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25)"; + size = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 1)"; + SizeEx = "(((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) * 0.7)"; + animTextureNormal = "#(argb,8,8,3)color(0,0,0,0.9)"; + animTextureDisabled = "#(argb,8,8,3)color(0,0,0,0.8)"; + animTextureOver = "#(argb,8,8,3)color(1,1,1,1)"; + animTextureFocused = "#(argb,8,8,3)color(1,1,1,1)"; + animTexturePressed = "#(argb,8,8,3)color(1,1,1,1)"; + animTextureDefault = "#(argb,8,8,3)color(1,1,1,1)"; + color[] = {1, 1, 1, 1}; + color2[] = {0,0,0, 1}; + colorBackgroundFocused[] = {1,1,1,1}; + colorBackground[] = {1,1,1,1}; + colorbackground2[] = {1,1,1,1}; + colorDisabled[] = {1,1,1,1}; + colorFocused[] = {0,0,0,1}; + periodFocus = 1; + periodOver = 1; + action = QUOTE(closeDialog 0); + }; + class btnCancel: btnUnload { + text = CSTRING(unloadObject); + idc = 12; + x = "20.9 * (((safezoneW / safezoneH) min 1.2) / 40) + (safezoneX + (safezoneW - ((safezoneW / safezoneH) min 1.2))/2)"; + action = QUOTE([] call FUNC(startUnload);); + }; + }; +}; \ No newline at end of file diff --git a/addons/cargo/script_component.hpp b/addons/cargo/script_component.hpp index fea5a6601b..9716d7a536 100644 --- a/addons/cargo/script_component.hpp +++ b/addons/cargo/script_component.hpp @@ -9,4 +9,6 @@ #define DEBUG_SETTINGS DEBUG_ENABLED_CARGO #endif -#include "\z\ace\addons\main\script_macros.hpp" \ No newline at end of file +#include "\z\ace\addons\main\script_macros.hpp" + +#define MAX_LOAD_DISTANCE 10 diff --git a/addons/cargo/stringtable.xml b/addons/cargo/stringtable.xml new file mode 100644 index 0000000000..e547ae9553 --- /dev/null +++ b/addons/cargo/stringtable.xml @@ -0,0 +1,20 @@ + + + + + Load object + + + Unload object + + + Cargo Menu + + + Cargo Menu + + + Cargo space left: %1 + + +