diff --git a/addons/arsenal/functions/fnc_addRightPanelButton.sqf b/addons/arsenal/functions/fnc_addRightPanelButton.sqf index 6e1035a86a..a1bdb09d1d 100644 --- a/addons/arsenal/functions/fnc_addRightPanelButton.sqf +++ b/addons/arsenal/functions/fnc_addRightPanelButton.sqf @@ -66,7 +66,8 @@ _items = _items select { _x isKindOf ["CBA_MiscItem", _cfgWeapons] && {getNumber (_configItemInfo >> "type") in [TYPE_MUZZLE, TYPE_OPTICS, TYPE_FLASHLIGHT, TYPE_BIPOD]} || {getNumber (_configItemInfo >> "type") in [TYPE_FIRST_AID_KIT, TYPE_MEDIKIT, TYPE_TOOLKIT]} || {getText (_cfgWeapons >> _x >> "simulation") == "ItemMineDetector"} || - {getNumber (_cfgMagazines >> _x >> "ACE_isUnique") == 1} + {getNumber (_cfgMagazines >> _x >> "ACE_isUnique") == 1} || + {getNumber (_cfgMagazines >> _x >> "ACE_asItem") == 1} }; GVAR(customRightPanelButtons) set [_position, [_items apply {_x call EFUNC(common,getConfigName)}, _picture, _tooltip, _moveOnOverwrite]]; diff --git a/addons/arsenal/functions/fnc_scanConfig.sqf b/addons/arsenal/functions/fnc_scanConfig.sqf index 105eb3479a..fef97e8bd8 100644 --- a/addons/arsenal/functions/fnc_scanConfig.sqf +++ b/addons/arsenal/functions/fnc_scanConfig.sqf @@ -160,7 +160,7 @@ private _magazineMiscItems = createHashMap; { _magazineMiscItems set [configName _x, nil]; -} forEach ((toString {getNumber (_x >> "ACE_isUnique") == 1}) configClasses _cfgMagazines); +} forEach ((toString {getNumber (_x >> "ACE_isUnique") == 1 || getNumber (_x >> "ACE_asItem") == 1}) configClasses _cfgMagazines); // Remove invalid/non-existent entries _grenadeList deleteAt ""; diff --git a/addons/common/XEH_PREP.hpp b/addons/common/XEH_PREP.hpp index ce6ac334ee..fb64d464df 100644 --- a/addons/common/XEH_PREP.hpp +++ b/addons/common/XEH_PREP.hpp @@ -13,6 +13,7 @@ PREP(addLineToDebugDraw); PREP(addSwayFactor); PREP(addToInventory); PREP(addWeapon); +PREP(adjustMagazineAmmo); PREP(assignedItemFix); PREP(assignObjectsInList); PREP(ambientBrightness); diff --git a/addons/common/functions/fnc_adjustMagazineAmmo.sqf b/addons/common/functions/fnc_adjustMagazineAmmo.sqf new file mode 100644 index 0000000000..87d5b9e899 --- /dev/null +++ b/addons/common/functions/fnc_adjustMagazineAmmo.sqf @@ -0,0 +1,107 @@ +#include "..\script_component.hpp" +/* + * Author: Katalam, Blue, Brett Mayson, johnb43 + * Handle adjusting a magazine's ammo + * + * Arguments: + * 0: Vehicle or Unit + * 1: Item + * 2: Ammo to adjust by (default: -1) + * + * Return Value: + * How much the ammo was adjusted by + * + * Example: + * [player, "30Rnd_556x45_Stanag", 1] call ace_common_fnc_adjustMagazineAmmo; + * + * Public: No + */ + +params ["_unit", "_magazine", ["_count", -1]]; + +if (_count == 0) exitWith {0}; + +private _containers = if (_unit isKindOf "CAManBase") then { + [uniformContainer _unit, vestContainer _unit, backpackContainer _unit] +} else { + [_unit] +}; + +scopeName "main"; + +private _originalCount = _count; +private _container = objNull; +private _magazinesContainer = []; +private _newAmmoCount = 0; +private _removeAmmo = _count < 0; +private _maxMagazineAmmo = getNumber (configFile >> "CfgMagazines" >> _magazine >> "count"); + +{ + _container = _x; + + // Get all magazines of _magazine type + _magazinesContainer = (magazinesAmmoCargo _container) select {_x select 0 == _magazine}; + + // Get the ammo count, filter out magazines with 0 ammo + _magazinesContainer = (_magazinesContainer apply {_x select 1}) select {_x != 0}; + + // If there are none, skip to next container + if (_magazinesContainer isEqualTo []) then { + continue; + }; + + // Sort, smallest first when removing, largest first when adding + _magazinesContainer sort _removeAmmo; + + if (_removeAmmo) then { + { + _count = _x + _count; + + _container addMagazineAmmoCargo [_magazine, -1, _x]; + + if (_count >= 0) then { + // Only add magazine back if it's not empty + if (_count != 0) then { + _container addMagazineAmmoCargo [_magazine, 1, _count]; + }; + + _originalCount breakOut "main"; + }; + } forEach _magazinesContainer; + } else { + // This loop only fills up partially filled magazines + { + // Fill the magazine to either its max or until all ammo has been added + _newAmmoCount = (_x + _count) min _maxMagazineAmmo; + + if (_newAmmoCount <= _maxMagazineAmmo) then { + _container addMagazineAmmoCargo [_magazine, -1, _x]; + _container addMagazineAmmoCargo [_magazine, 1, _newAmmoCount]; + }; + + // Remove the ammo that was added + _count = _count - (_newAmmoCount - _x); + + if (_count <= 0) then { + _originalCount breakOut "main"; + }; + } forEach (_magazinesContainer select {_x < _maxMagazineAmmo}); + }; +} forEach _containers; + +// If there is still remaining ammo to add, try add it after having iterated through all containers +if (!_removeAmmo && _count > 0) then { + { + while {_count > 0 && {_x canAdd [_magazine, 1/* 2.18 , true*/]}} do { + _x addMagazineAmmoCargo [_magazine, 1, _count]; + + _count = _count - _maxMagazineAmmo; + }; + } forEach _containers; + + if (_count <= 0) then { + _originalCount breakOut "main"; + }; +}; + +_originalCount - _count diff --git a/addons/common/functions/fnc_getCountOfItem.sqf b/addons/common/functions/fnc_getCountOfItem.sqf index 5667b6c980..5114f375d2 100644 --- a/addons/common/functions/fnc_getCountOfItem.sqf +++ b/addons/common/functions/fnc_getCountOfItem.sqf @@ -1,6 +1,6 @@ #include "..\script_component.hpp" /* - * Author: Dedmen + * Author: Dedmen, Blue, johnb43 * Return how many items of type _itemType the player has in his containers (Uniform, Vest, Backpack) * Doesn't count assignedItems, weapons, weapon attachments, magazines in weapons * @@ -19,13 +19,17 @@ params ["_unit", "_itemType"]; -private _countItemsInContainer = { - (getItemCargo _this) params ["_itemTypes", "_itemCounts"]; +private _count = 0; +private _isMagazine = isClass (configFile >> "CfgMagazines" >> _itemType); - private _index = _itemTypes find _itemType; - _itemCounts param [_index, 0] -}; +{ + (if (_isMagazine) then { + getMagazineCargo _x + } else { + getItemCargo _x + }) params ["_itemTypes", "_itemCounts"]; -((uniformContainer _unit) call _countItemsInContainer) + -((vestContainer _unit) call _countItemsInContainer) + -((backpackContainer _unit) call _countItemsInContainer) + _count = _count + (_itemCounts param [_itemTypes find _itemType, 0]); +} forEach [uniformContainer _unit, vestContainer _unit, backpackContainer _unit]; + +_count diff --git a/addons/common/functions/fnc_uniqueItems.sqf b/addons/common/functions/fnc_uniqueItems.sqf index dc783ebbea..204501ca3f 100644 --- a/addons/common/functions/fnc_uniqueItems.sqf +++ b/addons/common/functions/fnc_uniqueItems.sqf @@ -1,37 +1,84 @@ #include "..\script_component.hpp" /* - * Author: mharis001 - * Returns list of unique items in a unit's inventory. - * Items are cached if unit is ACE_player. + * Author: mharis001, Blue, Brett Mayson + * Returns list of unique items in the target's inventory. * * Arguments: - * 0: Unit + * 0: Target + * 1: Include magazines + * 0: No (default) + * 1: Yes + * 2: Only magazines * * Return Value: * Items * * Example: - * [player] call ace_common_fnc_uniqueItems + * [player, 2] call ace_common_fnc_uniqueItems * * Public: No */ -params ["_unit"]; +params ["_target", ["_includeMagazines", 0]]; private _fnc_getItems = { - private _items = (getItemCargo uniformContainer _unit) select 0; - _items append ((getItemCargo vestContainer _unit) select 0); - _items append ((getItemCargo backpackContainer _unit) select 0); + private _items = []; + + private _inventoryItems = (getItemCargo uniformContainer _target) select 0; + _inventoryItems append ((getItemCargo vestContainer _target) select 0); + _inventoryItems append ((getItemCargo backpackContainer _target) select 0); + + _items set [0, _inventoryItems]; + _items set [1, magazines _target]; _items arrayIntersect _items }; -// Use cached items list if unit is ACE_player -if (_unit isEqualTo ACE_player) then { +// Cache items list if unit is ACE_player +if (_target isEqualTo ACE_player) then { if (isNil QGVAR(uniqueItemsCache)) then { GVAR(uniqueItemsCache) = call _fnc_getItems; }; - +GVAR(uniqueItemsCache) + + switch (_includeMagazines) do { + case 0: { + GVAR(uniqueItemsCache) select 0 + }; + case 1: { + (GVAR(uniqueItemsCache) select 1) + (GVAR(uniqueItemsCache) select 0) + }; + case 2: { + GVAR(uniqueItemsCache) select 1 + }; + }; } else { - call _fnc_getItems; + if (_target isKindOf "CAManBase") then { + private _items = call _fnc_getItems; + + switch (_includeMagazines) do { + case 0: { + _items select 0 + }; + case 1: { + (_items select 1) + (_items select 0) + }; + case 2: { + _items select 1 + }; + }; + } else { + private _items = switch (_includeMagazines) do { + case 0: { + itemCargo _target + }; + case 1: { + (magazineCargo _target) + (itemCargo _target) + }; + case 2: { + magazineCargo _target + }; + }; + + _items arrayIntersect _items + }; }; diff --git a/addons/medical_gui/functions/fnc_countTreatmentItems.sqf b/addons/medical_gui/functions/fnc_countTreatmentItems.sqf index 6e8394c82f..ac7c4857e6 100644 --- a/addons/medical_gui/functions/fnc_countTreatmentItems.sqf +++ b/addons/medical_gui/functions/fnc_countTreatmentItems.sqf @@ -42,12 +42,27 @@ private _vehicle = [_patientVehicle, _medicVehicle] select (!isNull _medicVehicl if (!isNull _vehicle) then { _vehicleCount = 0; - (getItemCargo _vehicle) params ["_itemTypes", "_itemCounts"]; + private _magazineItems = []; + private _itemItems = []; { - private _item = _x; - private _index = _itemTypes find _item; - _vehicleCount = _vehicleCount + (_itemCounts param [_index, 0]); + if (isClass (configFile >> "CfgMagazines" >> _x)) then { + _magazineItems pushBack _x; + } else { + _itemItems pushBack _x; + }; } forEach _items; + if (_magazineItems isNotEqualTo []) then { + (getMagazineCargo _vehicle) params ["_itemTypes", "_itemCounts"]; + { + _vehicleCount = _vehicleCount + (_itemCounts param [_itemTypes find _x, 0]); + } forEach _magazineItems; + }; + if (_itemItems isNotEqualTo []) then { + (getItemCargo _vehicle) params ["_itemTypes", "_itemCounts"]; + { + _vehicleCount = _vehicleCount + (_itemCounts param [_itemTypes find _x, 0]); + } forEach _itemItems; + }; }; [_medicCount, _patientCount, _vehicleCount] diff --git a/addons/medical_treatment/CfgMagazines.hpp b/addons/medical_treatment/CfgMagazines.hpp new file mode 100644 index 0000000000..c4daafab76 --- /dev/null +++ b/addons/medical_treatment/CfgMagazines.hpp @@ -0,0 +1,16 @@ +class CfgMagazines { + class CA_Magazine; + class ACE_painkillers: CA_Magazine { + scope = 2; + author = ECSTRING(common,ACETeam); + displayName = CSTRING(painkillers_Display); + model = "\A3\Structures_F_EPA\Items\Medical\PainKillers_F.p3d"; + picture = QPATHTOF(ui\painkillers_ca.paa); + descriptionShort = CSTRING(painkillers_Desc_Short); + descriptionUse = CSTRING(painkillers_Desc_Use); + ACE_isMedicalItem = 1; + ACE_asItem = 1; + count = 10; + mass = 1; + }; +}; diff --git a/addons/medical_treatment/CfgVehicles.hpp b/addons/medical_treatment/CfgVehicles.hpp index bcecdb155e..4f922eb199 100644 --- a/addons/medical_treatment/CfgVehicles.hpp +++ b/addons/medical_treatment/CfgVehicles.hpp @@ -290,8 +290,8 @@ class CfgVehicles { displayName = CSTRING(painkillers_Display); author = "Alganthe"; vehicleClass = "Items"; - class TransportItems { - MACRO_ADDITEM(ACE_painkillers,1); + class TransportMagazines { + MACRO_ADDMAGAZINE(ACE_painkillers,1); }; }; @@ -313,9 +313,11 @@ class CfgVehicles { model = QPATHTOF(data\ace_medcrate.p3d); editorPreview = QPATHTOF(data\ACE_medicalSupplyCrate.jpg); author = ECSTRING(common,ACETeam); + class TransportMagazines { + MACRO_ADDMAGAZINE(ACE_painkillers,25); + }; class TransportItems { MACRO_ADDITEM(ACE_fieldDressing,50); - MACRO_ADDITEM(ACE_painkillers,25); MACRO_ADDITEM(ACE_morphine,25); MACRO_ADDITEM(ACE_epinephrine,25); MACRO_ADDITEM(ACE_bloodIV,15); @@ -357,13 +359,15 @@ class CfgVehicles { }; class ACE_medicalSupplyCrate_advanced: ACE_medicalSupplyCrate { displayName = CSTRING(medicalSupplyCrate_advanced); + class TransportMagazines { + MACRO_ADDMAGAZINE(ACE_painkillers,15); + }; class TransportItems { MACRO_ADDITEM(ACE_fieldDressing,25); MACRO_ADDITEM(ACE_packingBandage,25); MACRO_ADDITEM(ACE_elasticBandage,25); MACRO_ADDITEM(ACE_tourniquet,15); MACRO_ADDITEM(ACE_splint,15); - MACRO_ADDITEM(ACE_painkillers,15); MACRO_ADDITEM(ACE_morphine,15); MACRO_ADDITEM(ACE_adenosine,15); MACRO_ADDITEM(ACE_epinephrine,15); diff --git a/addons/medical_treatment/CfgWeapons.hpp b/addons/medical_treatment/CfgWeapons.hpp index 31b98bd843..7b31e10bee 100644 --- a/addons/medical_treatment/CfgWeapons.hpp +++ b/addons/medical_treatment/CfgWeapons.hpp @@ -310,17 +310,4 @@ class CfgWeapons { hiddenSelectionsTextures[] = {QPATHTOF(data\bodybagItem_white_co.paa)}; GVAR(bodyBagObject) = "ACE_bodyBagObject_white"; }; - class ACE_painkillers: ACE_ItemCore { - scope = 2; - author = "Alganthe"; - displayName = CSTRING(painkillers_Display); - model = "\A3\Structures_F_EPA\Items\Medical\PainKillers_F.p3d"; - picture = QPATHTOF(ui\painkillers_ca.paa); - descriptionShort = CSTRING(painkillers_Desc_Short); - descriptionUse = CSTRING(painkillers_Desc_Use); - ACE_isMedicalItem = 1; - class ItemInfo: CBA_MiscItem_ItemInfo { - mass = 1; - }; - }; }; diff --git a/addons/medical_treatment/config.cpp b/addons/medical_treatment/config.cpp index 75166a0f0c..3782645019 100644 --- a/addons/medical_treatment/config.cpp +++ b/addons/medical_treatment/config.cpp @@ -30,5 +30,6 @@ class CfgPatches { #include "CfgVehicles.hpp" #include "CfgWeapons.hpp" #include "Cfg3DEN.hpp" +#include "CfgMagazines.hpp" #endif diff --git a/addons/medical_treatment/functions/fnc_hasItem.sqf b/addons/medical_treatment/functions/fnc_hasItem.sqf index e84a79f142..e0ef4c8a4f 100644 --- a/addons/medical_treatment/functions/fnc_hasItem.sqf +++ b/addons/medical_treatment/functions/fnc_hasItem.sqf @@ -25,10 +25,11 @@ params ["_medic", "_patient", "_items"]; private _fnc_checkItems = { params ["_unit"]; - private _unitItems = _unit call EFUNC(common,uniqueItems); + private _unitItems = [_unit, 1] call EFUNC(common,uniqueItems); private _unitVehicle = objectParent _unit; if (!isNull _unitVehicle) then { _unitItems append (itemCargo _unitVehicle); + _unitItems append (magazineCargo _unitVehicle); }; _items findIf {_x in _unitItems} != -1 }; diff --git a/addons/medical_treatment/functions/fnc_medication.sqf b/addons/medical_treatment/functions/fnc_medication.sqf index b69a63e994..dfd08d4de2 100644 --- a/addons/medical_treatment/functions/fnc_medication.sqf +++ b/addons/medical_treatment/functions/fnc_medication.sqf @@ -23,6 +23,7 @@ params ["_medic", "_patient", "_bodyPart", "_classname", "", "_usedItem"]; [_patient, _usedItem] call FUNC(addToTriageCard); -[_patient, "activity", LSTRING(Activity_usedItem), [[_medic, false, true] call EFUNC(common,getName), getText (configFile >> "CfgWeapons" >> _usedItem >> "displayName")]] call FUNC(addToLog); +private _cfg = ["CfgWeapons", "CfgMagazines"] select (isClass (configFile >> "CfgMagazines" >> _usedItem)); +[_patient, "activity", LSTRING(Activity_usedItem), [[_medic, false, true] call EFUNC(common,getName), getText (configFile >> _cfg >> _usedItem >> "displayName")]] call FUNC(addToLog); [QGVAR(medicationLocal), [_patient, _bodyPart, _classname], _patient] call CBA_fnc_targetEvent; diff --git a/addons/medical_treatment/functions/fnc_treatmentFailure.sqf b/addons/medical_treatment/functions/fnc_treatmentFailure.sqf index 64d18fa830..42323922a3 100644 --- a/addons/medical_treatment/functions/fnc_treatmentFailure.sqf +++ b/addons/medical_treatment/functions/fnc_treatmentFailure.sqf @@ -23,7 +23,11 @@ _args params ["_medic", "_patient", "_bodyPart", "_classname", "_itemUser", "_us // Return used item to user (if used) if (!isNull _itemUser) then { - [_itemUser, _usedItem] call EFUNC(common,addToInventory); + if (isClass (configFile >> "CfgMagazines" >> _usedItem)) then { + [_itemUser, _usedItem, 1] call EFUNC(common,adjustMagazineAmmo); + } else { + [_itemUser, _usedItem] call EFUNC(common,addToInventory); + }; }; // Switch medic to end animation immediately diff --git a/addons/medical_treatment/functions/fnc_useItem.sqf b/addons/medical_treatment/functions/fnc_useItem.sqf index 1f1d7c8355..9bba3d1c90 100644 --- a/addons/medical_treatment/functions/fnc_useItem.sqf +++ b/addons/medical_treatment/functions/fnc_useItem.sqf @@ -29,18 +29,31 @@ scopeName "Main"; private _useOrder = [[_patient, _medic], [_medic, _patient], [_medic]] select GVAR(allowSharedEquipment); { - private _unit = _x; + private _unit = _x; private _unitVehicle = objectParent _unit; - private _unitItems = _x call EFUNC(common,uniqueItems); + private _unitItems = [_x, 0] call EFUNC(common,uniqueItems); + private _unitMagazines = [_x, 2] call EFUNC(common,uniqueItems); + private _vehicleItems = itemCargo _unitVehicle; // [] for objNull + private _vehicleMagazines = magazineCargo _unitVehicle; // same { - if (!isNull _unitVehicle && {_x in (itemCargo _unitVehicle)}) then { - _unitVehicle addItemCargoGlobal [_x, -1]; - [_unit, _x] breakOut "Main"; - }; - if (_x in _unitItems) then { - _unit removeItem _x; - [_unit, _x] breakOut "Main"; + switch (true) do { + case (_x in _vehicleItems): { + _unitVehicle addItemCargoGlobal [_x, -1]; + [_unit, _x] breakOut "Main"; + }; + case (_x in _vehicleMagazines): { + [_unitVehicle, _x] call EFUNC(common,adjustMagazineAmmo); + [_unit, _x] breakOut "Main"; + }; + case (_x in _unitItems): { + _unit removeItem _x; + [_unit, _x] breakOut "Main"; + }; + case (_x in _unitMagazines): { + [_unit, _x] call EFUNC(common,adjustMagazineAmmo); + [_unit, _x] breakOut "Main"; + }; }; } forEach _items; } forEach _useOrder; diff --git a/docs/wiki/framework/arsenal-framework.md b/docs/wiki/framework/arsenal-framework.md index 4691483e80..273a70836f 100644 --- a/docs/wiki/framework/arsenal-framework.md +++ b/docs/wiki/framework/arsenal-framework.md @@ -138,6 +138,7 @@ ACE Arsenal uses 2 existing config entries to sort and display items. - `baseWeapon`: Class name that is used to display an item in the arsenal, used for weapon/attachment variants that are not normally shown to the player (AI variants, PIP optics, and so on). This property can be applied to any weapon or weapon attachment in `CfgWeapons`. Items using CBA or RHS' Scripted Optics systems, or CBA Switchable Attachments do not need this property explictly set, and will automatically use their player-accessible class. - `ACE_isUnique`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Misc. Items. Used for items with attached data that needs to be kept track of, such as Notepads or Spare Barrels. +- `ACE_asItem`: Classes in `CfgMagazines` with this property set to `1` will be treated and shown by the Arsenal as Items. Used for magazines that are not meant to be used in a weapon, such as Painkillers. ### 3.2 New config entries @@ -159,7 +160,7 @@ ACE Medical Treatment and ACE Field Rations also add their own sub-categories, i - `ACE_isMedicalItem`: Items with this property set to `1` will be sorted to the ACE Medical Tab. - `ACE_isFieldRationItem`: Items with this property set to `1` will be sorted to the ACE Field Rations Tab. -Only Misc. Items will be checked for these properties. Magazines must have ACE_isUnique property. +Only Misc. Items will be checked for these properties. Magazines must have `ACE_isUnique` or `ACE_asItem` property. ## 4. Default loadouts