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 Armory simulation for taking and stashing Vanilla gear #202

Merged
merged 3 commits into from
Aug 26, 2016
Merged
Show file tree
Hide file tree
Changes from all 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/armory/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ PREP(init);
PREP(isCompatible);
PREP(moduleInit);
PREP(openArmory);
PREP(sendData);
PREP(processAction);
PREP(subtractData);
15 changes: 5 additions & 10 deletions addons/armory/functions/fnc_addItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 14 additions & 4 deletions addons/armory/functions/fnc_canAddArmory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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])
4 changes: 2 additions & 2 deletions addons/armory/functions/fnc_dialogControl_takestash.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down
99 changes: 12 additions & 87 deletions addons/armory/functions/fnc_getDataVanilla.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 2 additions & 4 deletions addons/armory/functions/fnc_init.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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];
59 changes: 59 additions & 0 deletions addons/armory/functions/fnc_openArmory.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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 <STRING>
Expand All @@ -9,7 +9,7 @@
* None
*
* Example:
* ["type"] call tac_armory_fnc_sendData
* ["type"] call tac_armory_fnc_processAction
*
* Public: No
*/
Expand Down Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions addons/armory/script_component.hpp
Original file line number Diff line number Diff line change
@@ -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
Expand Down