Skip to content

Commit

Permalink
Add cargo eden attributes (#4780)
Browse files Browse the repository at this point in the history
- Add a ace_cargo_space attribute to vehicles to alter how much cargo they can carry.
- Add an ace_cargo_size attribute to objects to alter how much cargo space they consume.
- Add two public functions `fnc_setSize.sqf` and `fnc_setSpace.sqf` to update the cargo size/space respectively of any given object.
- Deprecate cargo makeLoadable module and public function.
- Added some macros to get the space/size of a config, making code more readable in places.
  • Loading branch information
kymckay authored May 31, 2017
1 parent cbe06e5 commit fea2326
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 99 deletions.
37 changes: 37 additions & 0 deletions addons/cargo/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Cfg3DEN {
class Object {
class AttributeCategories {
class ace_attributes {
class Attributes {
class GVAR(space) {
displayName = CSTRING(space_edenName);
tooltip = CSTRING(space_edenDesc);
property = QGVAR(space);
control = "Edit";

expression = QUOTE([ARR_2(_this,_value)] call DFUNC(setSpace););
defaultValue = QUOTE(GET_NUMBER(configFile >> 'CfgVehicles' >> typeOf _this >> QQGVAR(space),0));

validate = "number";
condition = "objectHasInventoryCargo";
typeName = "NUMBER";
};
class GVAR(size) {
displayName = CSTRING(size_edenName);
tooltip = CSTRING(size_edenDesc);
property = QGVAR(size);
control = "Edit";

// Expression only runs on the server, must handle actions for all machines and future JIPs (Why BI?!)
expression = QUOTE([ARR_2(_this,_value)] call DFUNC(setSize););
defaultValue = QUOTE(GET_NUMBER(configFile >> 'CfgVehicles' >> typeOf _this >> QQGVAR(size),-1));

validate = "number";
condition = "1-objectBrain";
typeName = "NUMBER";
};
};
};
};
};
};
49 changes: 0 additions & 49 deletions addons/cargo/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,3 @@ class Extended_Killed_EventHandlers {
};
};
};

//Need initPost or we have problems with setVariable with 'ACE_Cargo'
class Extended_InitPost_EventHandlers {
class ThingX {
class ADDON {
init = QUOTE(_this call DFUNC(initObject); _this call DFUNC(initVehicle));
};
};
class Land_PaperBox_closed_F {
class ADDON {
init = QUOTE(_this call DFUNC(initObject); _this call DFUNC(initVehicle));
};
};
class PlasticCase_01_base_F {
class ADDON {
init = QUOTE(_this call DFUNC(initObject); _this call DFUNC(initVehicle));
};
};
class LandVehicle {
class ADDON {
init = QUOTE(_this call DFUNC(initVehicle));
};
};
class Air {
class ADDON {
init = QUOTE(_this call DFUNC(initVehicle));
};
};
class Ship_F {
class ADDON {
init = QUOTE(_this call DFUNC(initVehicle));
};
};
class ACE_ConcertinaWireCoil {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
};
};
class Land_PortableLight_single_F {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
};
};
class StaticWeapon {
class ADDON {
init = QUOTE(_this call DFUNC(initObject));
};
};
};
4 changes: 2 additions & 2 deletions addons/cargo/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class CfgVehicles {
GVAR(space) = 4;
GVAR(hasCargo) = 1;
};

// autonomus
class UAV_01_base_F: Helicopter_Base_F {
GVAR(space) = 0;
Expand Down Expand Up @@ -346,7 +346,7 @@ class CfgVehicles {
GVAR(space) = 8;
GVAR(hasCargo) = 1;
};

class StaticMortar;
class Mortar_01_base_F: StaticMortar {
GVAR(size) = 2; // 1 = small, 2 = large
Expand Down
2 changes: 2 additions & 0 deletions addons/cargo/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ PREP(moduleMakeLoadable);
PREP(moduleSettings);
PREP(onMenuOpen);
PREP(paradropItem);
PREP(setSize);
PREP(setSpace);
PREP(startLoadIn);
PREP(startUnload);
PREP(unloadItem);
Expand Down
25 changes: 25 additions & 0 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,28 @@
_item hideObjectGlobal false;
_item setPosASL (AGLtoASL _emptyPosAGL);
}] 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;

// Add all the vehicle init EHs (require initPost for set/get variables)
["LandVehicle", "initPost", DFUNC(initVehicle), nil, nil, true] call CBA_fnc_addClassEventHandler;
["Air", "initPost", DFUNC(initVehicle), nil, nil, true] call CBA_fnc_addClassEventHandler;
["Ship_F", "initPost", DFUNC(initVehicle), nil, nil, true] call CBA_fnc_addClassEventHandler;

// Add all the object init EHs
["StaticWeapon", "initPost", DFUNC(initObject), nil, nil, true] call CBA_fnc_addClassEventHandler;
["Land_PortableLight_single_F", "initPost", DFUNC(initObject), nil, nil, true] call CBA_fnc_addClassEventHandler;
["ACE_ConcertinaWireCoil", "initPost", DFUNC(initObject), nil, nil, true] call CBA_fnc_addClassEventHandler;

// Add all the vehicle/object init EHs
["ThingX", "initPost", {
_this call DFUNC(initObject); _this call DFUNC(initVehicle);
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
["Land_PaperBox_closed_F", "initPost", {
_this call DFUNC(initObject); _this call DFUNC(initVehicle);
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
["PlasticCase_01_base_F", "initPost", {
_this call DFUNC(initObject); _this call DFUNC(initVehicle);
}, nil, nil, true] call CBA_fnc_addClassEventHandler;
1 change: 1 addition & 0 deletions addons/cargo/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class CfgPatches {
};

#include "ACE_Settings.hpp"
#include "CfgEden.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "menu.hpp"
9 changes: 5 additions & 4 deletions addons/cargo/functions/fnc_addCargoVehiclesActions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
#include "script_component.hpp"

params ["_target", "_player"];

private _statement = {
params ["_target", "_player", "_params"];
_params params ["_vehicle"];
Expand All @@ -26,10 +28,9 @@ private _actions = [];

{
private _config = configFile >> "CfgVehicles" >> typeOf _x;
if (
1 == getNumber (_config >> QGVAR(hasCargo)) &&
{_x != _target}
) then {
private _hasCargoPublic = _x getVariable [QGVAR(hasCargo), false];
private _hasCargoConfig = getNumber (_config >> QGVAR(hasCargo)) == 1;
if ((_hasCargoPublic || _hasCargoConfig) && {_x != _target}) then {
private _name = getText (_config >> "displayName");
private _ownerName = [_x, true] call EFUNC(common,getName);
if ("" != _ownerName) then {
Expand Down
2 changes: 1 addition & 1 deletion addons/cargo/functions/fnc_getCargoSpaceLeft.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
params ["_object"];
// TRACE_1("params",_object);

_object getVariable [QGVAR(space), getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(space))]
(_object getVariable [QGVAR(space), getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(space))]) max 0
26 changes: 8 additions & 18 deletions addons/cargo/functions/fnc_getSizeItem.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Author: Glowbal
* Author: Glowbal, SilentSpike
* Get the cargo size of an object.
*
* Arguments:
Expand All @@ -17,23 +17,13 @@

params ["_item"];

scopeName "return";

private _isVirtual = (_item isEqualType "");
private _itemClass = if (_isVirtual) then {_item} else {typeOf _item};
private _config = (configFile >> "CfgVehicles" >> _itemClass >> QGVAR(size));

if (_isVirtual) then {
if (isNumber _config) then {
(getNumber _config) breakOut "return";
};
// Virtual items are much easier to deal with
if (_item isEqualType "") then {
CARGO_SIZE(_item)
} else {
if (!isNil {_item getVariable QGVAR(size)}) then {
(_item getVariable QGVAR(size)) breakOut "return";
};
if (isNumber _config) then {
(getNumber _config) breakOut "return";
if (isNil {_item getVariable QGVAR(size)}) then {
CARGO_SIZE(typeOf _item)
} else {
_item getVariable QGVAR(size)
};
};

-1
42 changes: 33 additions & 9 deletions addons/cargo/functions/fnc_initObject.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Author: Glowbal
* Author: Glowbal, SilentSpike
* Initializes variables for loadable objects. Called from init EH.
*
* Arguments:
Expand All @@ -19,32 +19,56 @@ params ["_object"];
private _type = typeOf _object;
TRACE_2("params",_object,_type);

if ((_object getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(canLoad))]) != 1) exitWith {};
// If object had size given to it via eden/public then override config canLoad setting
private _canLoadPublic = _object getVariable [QGVAR(canLoad), false];
private _canLoadConfig = getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(canLoad)) == 1;

// do nothing if the class is already initialized
// Nothing to do here if object can't be loaded
if !(_canLoadConfig || _canLoadPublic) exitWith {};

// Servers and HCs do not require action menus (beyond this point)
if !(hasInterface) exitWith {};

// Unnecessary to add actions to an object class that's already got them
if (_type in GVAR(initializedItemClasses)) exitWith {};
GVAR(initializedItemClasses) pushBack _type;
if (_object getVariable [QGVAR(initObject),false]) exitWith {};

TRACE_1("Adding load cargo action to class", _type);
// Objects given size via eden have their actions added to the object
// So this function may run for multiple of the same class in that case
if (_canLoadConfig) then {
GVAR(initializedItemClasses) pushBack _type;
TRACE_1("Adding load cargo action to class", _type);
} else {
_object setVariable [QGVAR(initObject),true];
TRACE_1("Adding load cargo action to object", _object);
};

// Vehicles with passengers inside are prevented from being loaded in `fnc_canLoadItemIn`
private _condition = {
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) &&
{(_target getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(canLoad))]) == 1} &&
{(_target getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(canLoad)) == 1])} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, []] call EFUNC(common,canInteractWith)} &&
{0 < {
1 == getNumber (configFile >> "CfgVehicles" >> typeOf _x >> QGVAR(hasCargo)) &&
{_x != _target}
private _type = typeOf _x;
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])}
};
private _statement = {
params ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
};
private _text = localize LSTRING(loadObject);
private _icon = QPATHTOF(UI\Icon_load.paa);

private _action = [QGVAR(load), _text, _icon, _statement, _condition, {call FUNC(addCargoVehiclesActions)}] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
if (_canLoadConfig) then {
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
} else {
[_object, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToObject);
};

46 changes: 36 additions & 10 deletions addons/cargo/functions/fnc_initVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ TRACE_1("params", _vehicle);

private _type = typeOf _vehicle;

if (getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) != 1) exitWith {};
// If vehicle had space given to it via eden/public then override config hasCargo setting
private _hasCargoPublic = _vehicle getVariable [QGVAR(hasCargo), false];
private _hasCargoConfig = getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) == 1;

// Nothing to do here if vehicle has no cargo space
if !(_hasCargoConfig || _hasCargoPublic) exitWith {};

// Vehicle can have default ace cargo in its config
if (isServer) then {
{
if (isClass _x) then {
Expand All @@ -33,18 +39,30 @@ if (isServer) then {
} count ("true" configClasses (configFile >> "CfgVehicles" >> _type >> "ACE_Cargo" >> "Cargo"));
};

// do nothing if the class is already initialized
if (_type in GVAR(initializedVehicleClasses)) exitWith {};
// set class as initialized
GVAR(initializedVehicleClasses) pushBack _type;
// Servers and HCs do not require action menus (beyond this point)
if !(hasInterface) exitWith {};

if (!hasInterface) exitWith {};
// Unnecessary to add actions to a vehicle class that's already got them
if (_type in GVAR(initializedVehicleClasses)) exitWith {};
if (_vehicle getVariable [QGVAR(initVehicle),false]) exitWith {};

TRACE_1("Adding unload cargo action to class", _type);
// 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;
TRACE_1("Adding unload cargo action to class", _type);
} else {
_vehicle setVariable [QGVAR(initVehicle),true];
TRACE_1("Adding unload cargo action to object", _vehicle);
};

private _condition = {
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
GVAR(enable) && {locked _target < 2} && {alive _target} && {[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
GVAR(enable) &&
{(_target getVariable [QGVAR(hasCargo), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(hasCargo)) == 1])} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
};
private _statement = {
//IGNORE_PRIVATE_WARNING ["_target", "_player"];
Expand All @@ -56,7 +74,11 @@ private _text = localize LSTRING(openMenu);
private _icon = "";

private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
if (_hasCargoConfig) then {
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
} else {
[_vehicle, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToObject);
};

// Add the paradrop self interaction for planes and helicopters
if (_vehicle isKindOf "Air") then {
Expand All @@ -78,5 +100,9 @@ if (_vehicle isKindOf "Air") then {
private _icon = "";

private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); // self action on the vehicle
if (_hasCargoConfig) then {
[_type, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToClass); // self action on the vehicle
} else {
[_vehicle, 1, ["ACE_SelfActions"], _action] call EFUNC(interact_menu,addActionToObject);
};
};
Loading

0 comments on commit fea2326

Please sign in to comment.