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

Add cargo eden attributes #4780

Merged
merged 14 commits into from
May 31, 2017
Merged
39 changes: 39 additions & 0 deletions addons/cargo/CfgEden.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#define GET_NUMBER(config,default) (if (isNumber (config)) then {getNumber (config)} else {default})

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(_this setVariable [ARR_3('%s',_value,true)];);
defaultValue = QUOTE(GET_NUMBER(configFile >> 'CfgVehicles' >> typeOf _this >> QQGVAR(space),-1));

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(_this setVariable [ARR_3('%s',_value,true)]; [QQGVAR(EdenObjectInit),_this] call CBA_fnc_globalEventJIP;);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realised there's a missing ARR_2 here that I must have added on my local version after committing. Rest assured, that's not what was making the initObject call fail to work.

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));
};
};
};
24 changes: 24 additions & 0 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,27 @@
_item hideObjectGlobal false;
_item setPosASL (AGLtoASL _emptyPosAGL);
}] call CBA_fnc_addEventHandler;

// Eden runs object attribute expressions on the server only (Why?!)
[QGVAR(EdenObjectInit), DFUNC(initObject)] 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"
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: 21 additions & 5 deletions addons/cargo/functions/fnc_initObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ 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 then override config canLoad setting
private _canLoadEden = _object getVariable [QGVAR(size), -1] >= 0;
private _canLoadConfig = _object getVariable [QGVAR(canLoad), 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 || _canLoadEden) 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;

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);
};

private _condition = {
GVAR(enable) &&
Expand All @@ -42,5 +54,9 @@ private _text = localize LSTRING(loadObject);
private _icon = QPATHTOF(UI\Icon_load.paa);

private _action = [QGVAR(load), _text, _icon, _statement, _condition] 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);
};

36 changes: 27 additions & 9 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 then override config hasCargo setting
private _hasEdenCargo = _vehicle getVariable [QGVAR(space), -1] > 0;
private _hasConfigCargo = getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) == 1;

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

// Vehicle can have default ace cargo in its config
if (isServer) then {
{
if (isClass _x) then {
Expand All @@ -33,14 +39,18 @@ 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 {};

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 (_hasConfigCargo) then {
GVAR(initializedVehicleClasses) pushBack _type;
TRACE_1("Adding unload cargo action to class", _type);
};

private _condition = {
GVAR(enable) && {locked _target < 2} && {alive _target} && {[_player, _target, ["isNotSwimming"]] call EFUNC(common,canInteractWith)}
Expand All @@ -54,7 +64,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 (_hasConfigCargo) 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 @@ -74,5 +88,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 (_hasConfigCargo) 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);
};
};
14 changes: 13 additions & 1 deletion addons/cargo/stringtable.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="Cargo">
<Key ID="STR_ACE_Cargo_loadObject">
Expand Down Expand Up @@ -219,6 +219,18 @@
<Russian>Размер объекта</Russian>
<Japanese>オブジェクトの大きさ</Japanese>
</Key>
<Key ID="STR_ACE_Cargo_space_edenName">
<English>Cargo Space</English>
</Key>
<Key ID="STR_ACE_Cargo_space_edenDesc">
<English>The cargo space available in this vehicle/container</English>
</Key>
<Key ID="STR_ACE_Cargo_size_edenName">
<English>Cargo Size</English>
</Key>
<Key ID="STR_ACE_Cargo_size_edenDesc">
<English>The cargo space required to hold this object (-1 for unloadable)</English>
</Key>
<Key ID="STR_ACE_Cargo_paradropButton">
<English>Airdrop</English>
<German>Türlast</German>
Expand Down