Medical - Support Magazine Treatment Items (#9816)

* count treatment items

* getCountofItem

Co-Authored-By: Blue <itzblueman@gmail.com>

* getCountofItem fix

Co-Authored-By: Blue <itzblueman@gmail.com>

* convert painkillers to magazine

* use isclass

Co-Authored-By: johnb432 <58661205+johnb432@users.noreply.github.com>

* forget to change variable

* Update addons/medical_treatment/functions/fnc_hasItem.sqf

Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>

* better magazine adjustment

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/medical_treatment/functions/fnc_medication.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update addons/medical_treatment/functions/fnc_treatmentFailure.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Update docs/wiki/framework/arsenal-framework.md

Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com>

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* Header

* use switch statement in fnc_useItem

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>

* only check adding to mags that are not full

Co-Authored-By: LinkIsGrim <salluci.lovi@gmail.com>

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

* Update fnc_getCountOfItem.sqf

* Optimisations & header fix

* Update addons/common/functions/fnc_adjustMagazineAmmo.sqf

* Fixed vehicle implementation

---------

Co-authored-by: Blue <itzblueman@gmail.com>
Co-authored-by: johnb432 <58661205+johnb432@users.noreply.github.com>
Co-authored-by: Grim <69561145+LinkIsGrim@users.noreply.github.com>
Co-authored-by: Jouni Järvinen <rautamiekka@users.noreply.github.com>
Co-authored-by: LinkIsGrim <salluci.lovi@gmail.com>
This commit is contained in:
BrettMayson 2024-03-21 15:56:24 -06:00 committed by GitHub
parent 50978efa46
commit 3c5b46c42d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
16 changed files with 261 additions and 58 deletions

View File

@ -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]];

View File

@ -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 "";

View File

@ -13,6 +13,7 @@ PREP(addLineToDebugDraw);
PREP(addSwayFactor);
PREP(addToInventory);
PREP(addWeapon);
PREP(adjustMagazineAmmo);
PREP(assignedItemFix);
PREP(assignObjectsInList);
PREP(ambientBrightness);

View File

@ -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 <OBJECT>
* 1: Item <STRING>
* 2: Ammo to adjust by <NUMBER> (default: -1)
*
* Return Value:
* How much the ammo was adjusted by <NUMBER>
*
* 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

View File

@ -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

View File

@ -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 <OBJECT>
* 0: Target <OBJECT>
* 1: Include magazines <NUMBER>
* 0: No (default)
* 1: Yes
* 2: Only magazines
*
* Return Value:
* Items <ARRAY>
*
* 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)
} else {
call _fnc_getItems;
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 {
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
};
};

View File

@ -42,12 +42,27 @@ private _vehicle = [_patientVehicle, _medicVehicle] select (!isNull _medicVehicl
if (!isNull _vehicle) then {
_vehicleCount = 0;
private _magazineItems = [];
private _itemItems = [];
{
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"];
{
private _item = _x;
private _index = _itemTypes find _item;
_vehicleCount = _vehicleCount + (_itemCounts param [_index, 0]);
} forEach _items;
_vehicleCount = _vehicleCount + (_itemCounts param [_itemTypes find _x, 0]);
} forEach _itemItems;
};
};
[_medicCount, _patientCount, _vehicleCount]

View File

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

View File

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

View File

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

View File

@ -30,5 +30,6 @@ class CfgPatches {
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "Cfg3DEN.hpp"
#include "CfgMagazines.hpp"
#endif

View File

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

View File

@ -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;

View File

@ -23,8 +23,12 @@ _args params ["_medic", "_patient", "_bodyPart", "_classname", "_itemUser", "_us
// Return used item to user (if used)
if (!isNull _itemUser) then {
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
private _endInAnim = _medic getVariable QGVAR(endInAnim);

View File

@ -31,17 +31,30 @@ private _useOrder = [[_patient, _medic], [_medic, _patient], [_medic]] select GV
{
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 {
switch (true) do {
case (_x in _vehicleItems): {
_unitVehicle addItemCargoGlobal [_x, -1];
[_unit, _x] breakOut "Main";
};
if (_x in _unitItems) then {
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;

View File

@ -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