Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo - Improve various aspects #9617

Merged
merged 18 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addons/cargo/CfgEden.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Cfg3DEN {
property = QGVAR(customName);
control = "Edit";

expression = QUOTE(_this setVariable [ARR_3(QQGVAR(customName),_value,true)];);
expression = QUOTE(_this setVariable [ARR_3(QQGVAR(customName),_value,true)]);
defaultValue = "''";

condition = "objectHasInventoryCargo - objectVehicle";
Expand Down
1 change: 0 additions & 1 deletion addons/cargo/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
Expand Down
9 changes: 5 additions & 4 deletions addons/cargo/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class CfgVehicles {
};


// misc. vehicles
// Misc. vehicles
class Quadbike_01_base_F: Car_F {
GVAR(space) = 0;
GVAR(hasCargo) = 0;
Expand All @@ -184,7 +184,7 @@ class CfgVehicles {
GVAR(hasCargo) = 0;
};

// helicopters
// Helicopters
class Air;
class Helicopter: Air {
GVAR(space) = 8;
Expand Down Expand Up @@ -224,7 +224,7 @@ class CfgVehicles {
};

class Heli_Transport_04_base_F: Helicopter_Base_H {
// note the double brackets are because loadmasterTurrets is an array of arrays / turret paths
// Note the double brackets are because loadmasterTurrets is an array of arrays / turret paths
GVAR(loadmasterTurrets)[] = {{1}};
GVAR(space) = 0;
GVAR(hasCargo) = 0;
Expand Down Expand Up @@ -363,8 +363,9 @@ class CfgVehicles {
GVAR(size) = 6;
};

// Slingload pallets
class Slingload_base_F: ReammoBox_F {};
class CargoNet_01_base_F: Slingload_base_F { //Slingload pallets
class CargoNet_01_base_F: Slingload_base_F {
GVAR(size) = 6;
};

Expand Down
2 changes: 0 additions & 2 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ PREP(canUnloadItem);
PREP(getCargoSpaceLeft);
PREP(getNameItem);
PREP(getSizeItem);
PREP(handleDeleted);
PREP(handleDestroyed);
PREP(initObject);
PREP(initVehicle);
Expand All @@ -21,4 +20,3 @@ PREP(startLoadIn);
PREP(startUnload);
PREP(unloadCarryItem);
PREP(unloadItem);
PREP(validateCargoSpace);
97 changes: 51 additions & 46 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -1,49 +1,33 @@
#include "script_component.hpp"

["ace_addCargo", {_this call FUNC(addCargoItem)}] call CBA_fnc_addEventHandler;
[QGVAR(paradropItem), {
params ["_item", "_vehicle", ["_showHint", true]];

private _unloaded = [_item, _vehicle, _showHint] call FUNC(paradropItem);

if (_unloaded && {GVAR(openAfterUnload) in [2, 3]}) then {
GVAR(interactionVehicle) = _vehicle;
GVAR(interactionParadrop) = true;
createDialog QGVAR(menu);
};
}] call CBA_fnc_addEventHandler;
["ace_addCargo", LINKFUNC(addCargoItem)] call CBA_fnc_addEventHandler;

["ace_loadCargo", {
params ["_item", "_vehicle"];
TRACE_2("LoadCargo EH",_item,_vehicle);

private _loaded = [_item, _vehicle] call FUNC(loadItem);
private _loaded = [_item, _vehicle] call FUNC(loadItem); // returns true if successful

// Show hint as feedback
private _hint = [LSTRING(LoadingFailed), LSTRING(LoadedItem)] select _loaded;
private _hint = [LSTRING(loadingFailed), LSTRING(loadedItem)] select _loaded;
private _itemName = [_item, true] call FUNC(getNameItem);
private _vehicleName = getText (configOf _vehicle >> "displayName");

[[_hint, _itemName, _vehicleName], 3.0] call EFUNC(common,displayTextStructured);

if (_loaded) then {
// Invoke listenable event
["ace_cargoLoaded", [_item, _vehicle]] call CBA_fnc_globalEvent;
};
[[_hint, _itemName, _vehicleName], 3] call EFUNC(common,displayTextStructured);
}] call CBA_fnc_addEventHandler;

["ace_unloadCargo", {
params ["_item", "_vehicle", ["_unloader", objNull]];
TRACE_3("UnloadCargo EH",_item,_vehicle,_unloader);

private _unloaded = [_item, _vehicle, _unloader] call FUNC(unloadItem); //returns true if sucessful
private _unloaded = [_item, _vehicle, _unloader] call FUNC(unloadItem); // returns true if successful

// Show hint as feedback
private _hint = [LSTRING(UnloadingFailed), LSTRING(UnloadedItem)] select _unloaded;
private _hint = [LSTRING(unloadingFailed), LSTRING(unloadedItem)] select _unloaded;
private _itemName = [_item, true] call FUNC(getNameItem);
private _vehicleName = getText (configOf _vehicle >> "displayName");

[[_hint, _itemName, _vehicleName], 3.0] call EFUNC(common,displayTextStructured);
[[_hint, _itemName, _vehicleName], 3] call EFUNC(common,displayTextStructured);

if (_unloaded && {GVAR(openAfterUnload) in [1, 3]}) then {
GVAR(interactionVehicle) = _vehicle;
Expand All @@ -58,16 +42,27 @@
_item hideObjectGlobal false;
_item setPosASL (AGLtoASL _emptyPosAGL);

[_item, "blockDamage", "ACE_cargo", false] call EFUNC(common,statusEffect_set);
[_item, "blockDamage", QUOTE(ADDON), false] call EFUNC(common,statusEffect_set);
}] call CBA_fnc_addEventHandler;

// Private events to handle adding actions globally via public functions
[QGVAR(initObject), DFUNC(initObject)] call CBA_fnc_addEventHandler;
[QGVAR(initVehicle), DFUNC(initVehicle)] call CBA_fnc_addEventHandler;
[QGVAR(paradropItem), {
params ["_item", "_vehicle", ["_showHint", true]];

private _unloaded = [_item, _vehicle, _showHint] call FUNC(paradropItem);

if (_unloaded && {GVAR(openAfterUnload) in [2, 3]}) then {
GVAR(interactionVehicle) = _vehicle;
GVAR(interactionParadrop) = true;
createDialog QGVAR(menu);
};
}] call CBA_fnc_addEventHandler;

// Private events to handle adding actions globally via public functions
[QGVAR(initObject), LINKFUNC(initObject)] call CBA_fnc_addEventHandler;
[QGVAR(initVehicle), LINKFUNC(initVehicle)] call CBA_fnc_addEventHandler;

GVAR(vehicleAction) = [
QGVAR(openMenu), localize LSTRING(openMenu), "",
QGVAR(openMenu), LLSTRING(openMenu), "",
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(interactionVehicle) = _target;
Expand All @@ -77,17 +72,17 @@ GVAR(vehicleAction) = [
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{(_target getVariable [QGVAR(hasCargo), getNumber (configOf _target >> QGVAR(hasCargo)) == 1])} &&
{locked _target < 2} &&
{([_player, _target] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE} &&
{alive _target} &&
{locked _target < 2} &&
{(_target getVariable [QGVAR(hasCargo), getNumber (configOf _target >> QGVAR(hasCargo)) == 1])} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)}
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)} &&
{([_player, _target] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE}
}
] call EFUNC(interact_menu,createAction);

GVAR(objectActions) = [
[QGVAR(renameObject), LELSTRING(common,rename), "", //TODO: add icon, maybe a pencil couldn't find it before.
[QGVAR(renameObject), LELSTRING(common,rename), "\a3\Modules_F_Curator\Data\iconMissionName_ca.paa",
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(interactionVehicle) = _target;
Expand All @@ -97,67 +92,77 @@ GVAR(objectActions) = [
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{GVAR(enableRename)} &&
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{alive _target} &&
{_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad)) == 1]} &&
{!(_target getVariable [QGVAR(noRename), getNumber (configOf _target >> QGVAR(noRename)) == 1])} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)} &&
{(_target getVariable [QGVAR(noRename), getNumber (configOf _target >> QGVAR(noRename))]) in [false, 0]}
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)}
}
] call EFUNC(interact_menu,createAction),
[QGVAR(load), localize LSTRING(loadObject), "a3\ui_f\data\IGUI\Cfg\Actions\loadVehicle_ca.paa",
[QGVAR(load), LLSTRING(loadObject), "a3\ui_f\data\IGUI\Cfg\Actions\loadVehicle_ca.paa",
{
params ["_target", "_player"];
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
},
{
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{(_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad))]) in [true, 1]} &&
{locked _target < 2} &&
{alive _target} &&
{locked _target < 2} &&
{_target getVariable [QGVAR(canLoad), getNumber (configOf _target >> QGVAR(canLoad)) == 1]} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)} &&
{[_player, _target] call EFUNC(interaction,canInteractWithVehicleCrew)} &&
{((nearestObjects [_target, GVAR(cargoHolderTypes), (MAX_LOAD_DISTANCE + 10)]) findIf {
private _hasCargoConfig = 1 == getNumber (configOf _x >> QGVAR(hasCargo));
private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false];
(_hasCargoConfig || {_hasCargoPublic}) && {_x != _target} && {alive _x} && {locked _x < 2} &&
{((nearestObjects [_target, GVAR(cargoHolderTypes), MAX_LOAD_DISTANCE + 10]) findIf {
_x != _target &&
{alive _x} &&
{locked _x < 2} &&
{_x getVariable [QGVAR(hasCargo), getNumber (configOf _x >> QGVAR(hasCargo)) == 1]} &&
{([_target, _x] call EFUNC(interaction,getInteractionDistance)) < MAX_LOAD_DISTANCE}
}) > -1}
}) != -1}
},
LINKFUNC(addCargoVehiclesActions)
] call EFUNC(interact_menu,createAction)
];

// find all remaining configured classes and init them, see XEH_preStart.sqf
// Find all remaining configured classes and init them, see XEH_preStart.sqf
private _vehicleClassesAddAction = call (uiNamespace getVariable [QGVAR(initializedVehicleClasses), {[]}]);

{
[_x, 0, ["ACE_MainActions"], GVAR(vehicleAction)] call EFUNC(interact_menu,addActionToClass);
} forEach _vehicleClassesAddAction;

GVAR(initializedVehicleClasses) append _vehicleClassesAddAction;

private _objectClassesAddAction = call (uiNamespace getVariable [QGVAR(initializedItemClasses), {[]}]);

{
private _objectClass = _x;

{
[_objectClass, 0, ["ACE_MainActions"], _x] call EFUNC(interact_menu,addActionToClass);
} forEach GVAR(objectActions);
} forEach _objectClassesAddAction;

GVAR(initializedItemClasses) append _objectClassesAddAction;

private _vehicleClassesAddClassEH = call (uiNamespace getVariable [QGVAR(vehicleClasses_classEH), {[]}]);

{
[_x, "initPost", DFUNC(initVehicle), nil, nil, true] call CBA_fnc_addClassEventHandler;
} forEach _vehicleClassesAddClassEH;

private _objectClassesAddClassEH = call (uiNamespace getVariable [QGVAR(objectClasses_classEH), {[]}]);

{
[_x, "initPost", DFUNC(initObject), nil, nil, true] call CBA_fnc_addClassEventHandler;
} forEach _objectClassesAddClassEH;

if (isServer) then {
["ace_placedInBodyBag", {
params ["_target", "_bodyBag", "_isGrave"];

if (_isGrave) exitWith {}; // assume graves aren't cargo

_bodyBag setVariable [QGVAR(customName), [_target, false, true] call EFUNC(common,getName), true];
}] call CBA_fnc_addEventHandler;
};
6 changes: 3 additions & 3 deletions addons/cargo/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ PREP_RECOMPILE_END;

GVAR(initializedItemClasses) = [];
GVAR(initializedVehicleClasses) = [];
GVAR(cargoHolderTypes) = ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"];
GVAR(disableParadropEffectsClasstypes) = ["Car_F"];
GVAR(cargoHolderTypes) = ["Car", "Air", "Tank", "Ship", "Cargo_base_F", "Land_PaperBox_closed_F"] apply {_x call EFUNC(common,getConfigName)}; // make sure they are config case
GVAR(disableParadropEffectsClasstypes) = ["Car_F"] apply {_x call EFUNC(common,getConfigName)};

if (isServer) then {
["All", "Deleted", LINKFUNC(handleDeleted)] call CBA_fnc_addClassEventHandler;
["All", "Deleted", LINKFUNC(handleDestroyed)] call CBA_fnc_addClassEventHandler;
};

["All", "Killed", LINKFUNC(handleDestroyed)] call CBA_fnc_addClassEventHandler;
Expand Down
27 changes: 14 additions & 13 deletions addons/cargo/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,38 @@

#include "XEH_PREP.hpp"


//See XEH_postInit.sqf
// See XEH_postInit.sqf
private _vehicleClasses_addClassEH = ["ThingX", "LandVehicle", "Air", "Ship_F"];
private _objectClasses_addClassEH = ["ThingX", "StaticWeapon"];
private _vehicleClasses_addAction = [];
private _itemClasses_addAction = [];
private _class = "";

// find all remaining configured classes and init them
// Find all remaining configured classes and init them
{
private _class = configName _x;
// init vehicle
_class = configName _x;

// Init vehicle
if (
1 == getNumber (_x >> QGVAR(hasCargo))
&& {-1 == _vehicleClasses_addClassEH findIf {_class isKindOf _x}}
getNumber (_x >> QGVAR(hasCargo)) == 1 &&
{_vehicleClasses_addClassEH findIf {_class isKindOf _x} == -1}
) then {
if (_class isKindOf "Static") then {
if (2 == getNumber (_x >> "scope")) then {
if (getNumber (_x >> "scope") == 2) then {
_vehicleClasses_addAction pushBackUnique _class;
};
} else {
_vehicleClasses_addClassEH pushBackUnique _class;
};
};
// init object

// Init object
if (
1 == getNumber (_x >> QGVAR(canLoad))
&& {-1 == _objectClasses_addClassEH findIf {_class isKindOf _x}}
getNumber (_x >> QGVAR(canLoad)) == 1 &&
{_objectClasses_addClassEH findIf {_class isKindOf _x} == -1}
) then {
if (_class isKindOf "Static") then {
if (2 == getNumber (_x >> "scope")) then {
if (getNumber (_x >> "scope") == 2) then {
_itemClasses_addAction pushBackUnique _class;
};
} else {
Expand All @@ -40,7 +42,6 @@ private _itemClasses_addAction = [];
};
} forEach ("true" configClasses (configFile >> "CfgVehicles"));


uiNamespace setVariable [QGVAR(vehicleClasses_classEH), compileFinal str _vehicleClasses_addClassEH];
uiNamespace setVariable [QGVAR(objectClasses_classEH), compileFinal str _objectClasses_addClassEH];
uiNamespace setVariable [QGVAR(initializedVehicleClasses), compileFinal str _vehicleClasses_addAction];
Expand Down
26 changes: 17 additions & 9 deletions addons/cargo/functions/fnc_addCargoItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@
* Adds a cargo item to the vehicle.
*
* Arguments:
* 0: Item Classname <STRING>
* 1: Vehicle <OBJECT>
* 0: Item to be loaded <STRING> or <OBJECT>
* 1: Holder object (vehicle) <OBJECT>
* 2: Amount <NUMBER> (default: 1)
* 3: Show Hint <BOOL> (default: false)
*
* Return Value:
* None
*
* Example:
* ["item", vehicle] call ace_cargo_fnc_addCargoItem
* ["ACE_Wheel", cursorObject] call ace_cargo_fnc_addCargoItem
*
* Public: No
*/

params ["_itemClass", "_vehicle", ["_amount", 1], ["_showHint", false, [false]]];
TRACE_3("params",_itemClass,_vehicle,_amount);
params ["_item", "_vehicle", ["_amount", 1]];
TRACE_3("params",_item,_vehicle,_amount);

for "_i" from 1 to _amount do {
[_itemClass, _vehicle] call FUNC(loadItem);
// Get config sensitive case name
if (_item isEqualType "") then {
_item = _item call EFUNC(common,getConfigName);

for "_i" from 1 to _amount do {
[_item, _vehicle] call FUNC(loadItem);
};
} else {
[_item, _vehicle] call FUNC(loadItem);

_item = typeOf _item;
};

// Invoke listenable event
["ace_cargoAdded", [_itemClass, _vehicle, _amount]] call CBA_fnc_globalEvent;
["ace_cargoAdded", [_item, _vehicle, _amount]] call CBA_fnc_globalEvent;
Loading