diff --git a/addons/armory/XEH_PREP.hpp b/addons/armory/XEH_PREP.hpp index ba276bf1..95a87b8c 100644 --- a/addons/armory/XEH_PREP.hpp +++ b/addons/armory/XEH_PREP.hpp @@ -18,5 +18,5 @@ PREP(init); PREP(isCompatible); PREP(moduleInit); PREP(openArmory); -PREP(sendData); +PREP(processAction); PREP(subtractData); diff --git a/addons/armory/functions/fnc_addItems.sqf b/addons/armory/functions/fnc_addItems.sqf index a5007889..d2c6227f 100644 --- a/addons/armory/functions/fnc_addItems.sqf +++ b/addons/armory/functions/fnc_addItems.sqf @@ -42,16 +42,11 @@ if (_armoryData isEqualTo []) exitWith { }; // Add Armory if not added yet -if !(_object getVariable [QGVAR(armoryEnabled), false]) then { - private _return = true; +[_object] call FUNC(init); - if ([_object] call FUNC(canAddArmory)) then { - [_object] call FUNC(init); - _return = true; - } else { - ACE_LOGERROR_1("Armory cannot be added to an object without inventory: %1",_object); - _return = false; - }; +if (_object getVariable [QGVAR(enabled), false]) exitWith { + _object setVariable [QGVAR(armoryData), _armoryData, true]; + true }; -_object setVariable [QGVAR(armoryData), _armoryData, true]; +false diff --git a/addons/armory/functions/fnc_canAddArmory.sqf b/addons/armory/functions/fnc_canAddArmory.sqf index 58532824..81aee35e 100644 --- a/addons/armory/functions/fnc_canAddArmory.sqf +++ b/addons/armory/functions/fnc_canAddArmory.sqf @@ -17,8 +17,18 @@ params ["_object"]; -private _config = configFile >> "CfgVehicles" >> typeOf _object; +private _objectClass = typeOf _object; +private _config = configFile >> "CfgVehicles" >> _objectClass; -(getNumber (_config >> "transportMaxBackpacks") > 0) && -{getNumber (_config >> "transportMaxMagazines") > 0} && -{getNumber (_config >> "transportMaxWeapons") > 0} +if (getNumber (_config >> "transportMaxBackpacks") == 0 || + {getNumber (_config >> "transportMaxMagazines") == 0} || + {getNumber (_config >> "transportMaxWeapons") == 0} +) exitWith { + ACE_LOGWARNING_1("Armory cannot be added to an object without inventory. Object classname: %1",_objectClass); +}; + +if (isClass (_config >> "ACE_Actions" >> "ACE_MainActions" >> QGVAR(Open))) then { + _object setVariable [QGVAR(enabled), true]; +}; + +!(_object getVariable [QGVAR(enabled), false]) diff --git a/addons/armory/functions/fnc_dialogControl_takestash.sqf b/addons/armory/functions/fnc_dialogControl_takestash.sqf index 4e923491..0802bc21 100644 --- a/addons/armory/functions/fnc_dialogControl_takestash.sqf +++ b/addons/armory/functions/fnc_dialogControl_takestash.sqf @@ -25,12 +25,12 @@ if (lbText [DROPDOWNAMOUNT, lbCurSel CTRL(DROPDOWNAMOUNT)] == "") exitWith { if (GVAR(selectedCategory) == "stash") then { // Stash ctrlSetText [TAKESTASHPIC, QPATHTOF(UI\btnStash.paa)]; - buttonSetAction [TAKESTASHBTN, QUOTE(['stash'] call FUNC(sendData))]; + buttonSetAction [TAKESTASHBTN, QUOTE(['stash'] call FUNC(processAction))]; CTRL(TAKESTASHBTN) ctrlSetTooltip localize LSTRING(BtnStashItemTooltip); } else { // Take ctrlSetText [TAKESTASHPIC, QPATHTOF(UI\btnTake.paa)]; - buttonSetAction [TAKESTASHBTN, QUOTE(['take'] call FUNC(sendData))]; + buttonSetAction [TAKESTASHBTN, QUOTE(['take'] call FUNC(processAction))]; CTRL(TAKESTASHBTN) ctrlSetTooltip localize LSTRING(BtnTakeItemTooltip); }; diff --git a/addons/armory/functions/fnc_getDataVanilla.sqf b/addons/armory/functions/fnc_getDataVanilla.sqf index 56d57834..cf69b41e 100644 --- a/addons/armory/functions/fnc_getDataVanilla.sqf +++ b/addons/armory/functions/fnc_getDataVanilla.sqf @@ -27,94 +27,19 @@ if (isNull _object) exitWith { private _armoryDataVar = _object getVariable [QGVAR(armoryData), []]; private _armoryData = []; -#ifndef DEBUG_MODE_FULL - // Verify armory data - { - _x params [ - ["_category", "", [""]], - ["_className", "", [""]], - ["_subCategory", "", [""]], - ["_description", "", [""]], - ["_quantity", 1, [0]] - ]; +// Verify armory data +{ + _x params [ + ["_category", "", [""]], + ["_className", "", [""]], + ["_subCategory", "", [""]], + ["_description", "", [""]], + ["_quantity", 1, [0]] + ]; - if (_category == _selectedCategory && {_className != ""} && {_subCategory != ""} && {_quantity > 0}) then { - _armoryData pushBack [_className, _subCategory, _description, str _quantity]; - }; - } forEach _armoryDataVar; -#else - // Rifles - if (_selectedCategory == "rifle") then { - _armoryData = [ - // Classname, Subcategory, Description, Quantity - ["arifle_MX_F", "Assault Rifle", "Blabla, this item, blabla", "23"], - ["srifle_DMR_01_F", "Marksman Rifle", "Blabla, this item, blabla", "4"], - ["srifle_EBR_F", "Marksman Rifle", "Blabla, this item, blabla", "5"], - ["arifle_Katiba_GL_F", "Assault Rifle", "Blabla, this item, blabla", "45"], - ["arifle_Mk20C_plain_F", "Assault Rifle", "Blabla, this item, blabla", "18"], - ["arifle_Mk20C_plain_F", "Assault Rifle", "Blabla, this item, blabla", "20"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"], - ["arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", "33"] - ]; + if (_category == _selectedCategory && {_className != ""} && {_subCategory != ""} && {_quantity > 0}) then { + _armoryData pushBack [_className, _subCategory, _description, str _quantity]; }; - if (_selectedCategory == "ammo") then { - _armoryData = [ - // Classname, Subcategory, Description, Quantity - ["30Rnd_65x39_caseless_mag", "Magazine", "Blabla, this item, blabla", "333"], - ["100Rnd_65x39_caseless_mag", "Magazine", "Blabla, this item, blabla", "123"], - ["NLAW_F", "Missile", "Blabla, this item, blabla", "7"], - ["1Rnd_HE_Grenade_shell", "Shell", "Blabla, this item, blabla", "19"], - ["SmokeShellBlue", "Shell", "Blabla, this item, blabla", "15"] - ]; - }; - if (_selectedCategory == "item") then { - _armoryData = [ - // Classname, Subcategory, Description, Quantity - ["NVGoggles", "Headgear", "Blabla, this item, blabla", "23"], - ["Laserdesignator", "Item", "Blabla, this item, blabla", "7"], - ["ItemGPS", "Item", "Blabla, this item, blabla", "5"], - ["MediKit", "Item", "Blabla, this item, blabla", "2"], - ["ToolKit", "Item", "Blabla, this item, blabla", "18"], - ["B_UavTerminal", "Item", "Blabla, this item, blabla", "20"] - ]; - }; - if (_selectedCategory == "attachment") then { - _armoryData = [ - // Classname, Subcategory, Description, Quantity - ["optic_Hamr", "Optic", "Blabla, this item, blabla", "4"], - ["optic_Aco", "Optic", "Blabla, this item, blabla", "45"], - ["optic_DMS", "Optic", "Blabla, this item, blabla", "33"], - ["muzzle_snds_93mmg", "Muzzle", "Blabla, this item, blabla", "6"], - ["muzzle_snds_H", "Muzzle", "Blabla, this item, blabla", "13"], - ["optic_MRD", "Optic", "Blabla, this item, blabla", "1"] - ]; - }; - if (_selectedCategory == "wearable") then { - _armoryData = [ - // Classname, Subcategory, Description, Quantity - ["G_Bandanna_Shades", "Goggles", "Blabla, this item, blabla", "4"] - ]; - }; - if (_selectedCategory == "insignia") then { - private _config = configFile >> "CfgUnitInsignia"; - for "_x" from 0 to (count _config - 1) do { - private _configName = configName (_config select _x); - _armoryData pushBack [_configName, "Insignia", "Insignia", "1"]; - }; - }; -#endif +} forEach _armoryDataVar; _armoryData diff --git a/addons/armory/functions/fnc_init.sqf b/addons/armory/functions/fnc_init.sqf index cd86004c..2de2ef94 100644 --- a/addons/armory/functions/fnc_init.sqf +++ b/addons/armory/functions/fnc_init.sqf @@ -18,9 +18,7 @@ params [["_object", this]]; // Check if object has inventory -if !([_object] call FUNC(canAddArmory)) exitWith { - ACE_LOGWARNING_1("Aborted adding Armory to an object without inventory. Object classname: %1",typeOf _object); -}; +if !([_object] call FUNC(canAddArmory)) exitWith {}; // Add action private _armoryAction = [ @@ -35,4 +33,4 @@ private _armoryAction = [ [_object, 0, ["ACE_MainActions"], _armoryAction] call ACE_Interact_Menu_fnc_addActionToObject; -_object setVariable [QGVAR(armoryEnabled), true]; +_object setVariable [QGVAR(enabled), true]; diff --git a/addons/armory/functions/fnc_openArmory.sqf b/addons/armory/functions/fnc_openArmory.sqf index 46f779aa..c65b8eb9 100644 --- a/addons/armory/functions/fnc_openArmory.sqf +++ b/addons/armory/functions/fnc_openArmory.sqf @@ -26,3 +26,62 @@ ACE_player setVariable [QGVAR(object), _object, true]; // Create display and load main menu createDialog QGVAR(Display); ["main"] call FUNC(dialogControl); + + +#ifdef ADD_DEBUG_ITEMS +if !((_object getVariable [QGVAR(armoryData), []]) isEqualTo []) exitWith {}; + +private _itemsData = [ + // Rifles + ["rifle", "arifle_MX_F", "Assault Rifle", "Blabla, this item, blabla", 23], + ["rifle", "srifle_DMR_01_F", "Marksman Rifle", "Blabla, this item, blabla", 4], + ["rifle", "srifle_EBR_F", "Marksman Rifle", "Blabla, this item, blabla", 5], + ["rifle", "arifle_Katiba_GL_F", "Assault Rifle", "Blabla, this item, blabla", 45], + ["rifle", "arifle_Mk20C_plain_F", "Assault Rifle", "Blabla, this item, blabla", 18], + ["rifle", "arifle_Mk20C_plain_F", "Assault Rifle", "Blabla, this item, blabla", 20], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + ["rifle", "arifle_MXC_F", "Shotgun", "Blabla, this item, blabla", 33], + // Ammo + ["ammo", "30Rnd_65x39_caseless_mag", "Magazine", "Blabla, this item, blabla", 333], + ["ammo", "100Rnd_65x39_caseless_mag", "Magazine", "Blabla, this item, blabla", 123], + ["ammo", "NLAW_F", "Missile", "Blabla, this item, blabla", 7], + ["ammo", "1Rnd_HE_Grenade_shell", "Shell", "Blabla, this item, blabla", 19], + ["ammo", "SmokeShellBlue", "Shell", "Blabla, this item, blabla", 15], + // Items + ["item", "NVGoggles", "Headgear", "Blabla, this item, blabla", 23], + ["item", "Laserdesignator", "Item", "Blabla, this item, blabla", 7], + ["item", "ItemGPS", "Item", "Blabla, this item, blabla", 5], + ["item", "MediKit", "Item", "Blabla, this item, blabla", 2], + ["item", "ToolKit", "Item", "Blabla, this item, blabla", 18], + ["item", "B_UavTerminal", "Item", "Blabla, this item, blabla", 20], + // Attachments + ["attachment", "optic_Hamr", "Optic", "Blabla, this item, blabla", 4], + ["attachment", "optic_Aco", "Optic", "Blabla, this item, blabla", 45], + ["attachment", "optic_DMS", "Optic", "Blabla, this item, blabla", 33], + ["attachment", "muzzle_snds_93mmg", "Muzzle", "Blabla, this item, blabla", 6], + ["attachment", "muzzle_snds_H", "Muzzle", "Blabla, this item, blabla", 13], + ["attachment", "optic_MRD", "Optic", "Blabla, this item, blabla", 1], + // Wearables + ["wearable", "G_Bandanna_Shades", "Goggles", "Blabla, this item, blabla", 4] +]; + +{ + _itemsData pushBack ["insignia", configName _x, "Insignia", "This item is an insignia", 1]; +} forEach ("true" configClasses (configFile >> "CfgUnitInsignia")); + +private _return = [_object, _itemsData] call FUNC(addItems); +TRACE_1("Debug items add",_return); +#endif diff --git a/addons/armory/functions/fnc_sendData.sqf b/addons/armory/functions/fnc_processAction.sqf similarity index 82% rename from addons/armory/functions/fnc_sendData.sqf rename to addons/armory/functions/fnc_processAction.sqf index 1984f15d..8932e42d 100644 --- a/addons/armory/functions/fnc_sendData.sqf +++ b/addons/armory/functions/fnc_processAction.sqf @@ -1,6 +1,6 @@ /* * Author: Jonpas - * Prepares and sends data back to Apollo (Chronos). + * Processes performed action and modifies Vanilla data or sends data back to Apollo (Chronos). * * Arguments: * 0: Take/Stash @@ -9,7 +9,7 @@ * None * * Example: - * ["type"] call tac_armory_fnc_sendData + * ["type"] call tac_armory_fnc_processAction * * Public: No */ @@ -48,6 +48,7 @@ if (_type == "take" && {!(_object canAdd _selectedItem)}) exitWith { }; if (GVAR(system) == 0) then { + // Set box contents private _isBackpack = [_selectedItem] call ACE_Backpacks_fnc_isBackpack; private _itemType = ([_selectedItem] call ACE_Common_fnc_getItemType) select 0; @@ -74,6 +75,20 @@ if (GVAR(system) == 0) then { }; [_object, _selectedItem, parseNumber _selectedAmount] call CBA_fnc_removeItemCargo; //default "item" }; + + // Set Armory contents + private _armoryDataVar = _object getVariable [QGVAR(armoryData), []]; + private _amountChange = [_selectedAmount, format ["-%1", _selectedAmount]] select (_type == "take"); + + _armoryDataVar = _armoryDataVar apply { + if (_x select 1 == _selectedItem) then { + [_x select 0, _x select 1, _x select 2, _x select 3, (_x select 4) + (parseNumber _amountChange)] + } else { + _x + }; + }; + + _object setVariable [QGVAR(armoryData), _armoryDataVar]; }; if (GVAR(system) == 1) then { diff --git a/addons/armory/script_component.hpp b/addons/armory/script_component.hpp index 6ffd8c2b..cd05354c 100644 --- a/addons/armory/script_component.hpp +++ b/addons/armory/script_component.hpp @@ -1,6 +1,7 @@ #define COMPONENT armory #include "\x\tac\addons\main\script_mod.hpp" +// #define ADD_DEBUG_ITEMS // #define DEBUG_MODE_FULL // #define DISABLE_COMPILE_CACHE // #define CBA_DEBUG_SYNCHRONOUS