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

Medical - Support Magazine Treatment Items #9816

Merged
merged 23 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
fe4ed52
count treatment items
BrettMayson Mar 1, 2024
e88afa6
getCountofItem
BrettMayson Mar 2, 2024
d05bb52
getCountofItem fix
BrettMayson Mar 2, 2024
41eafbc
convert painkillers to magazine
BrettMayson Mar 3, 2024
936897e
use isclass
BrettMayson Mar 3, 2024
d8cac46
forget to change variable
BrettMayson Mar 3, 2024
5c15384
Update addons/medical_treatment/functions/fnc_hasItem.sqf
BrettMayson Mar 3, 2024
65dfa6b
better magazine adjustment
BrettMayson Mar 4, 2024
ef251a4
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
BrettMayson Mar 4, 2024
5137885
Update addons/medical_treatment/functions/fnc_medication.sqf
BrettMayson Mar 4, 2024
21a6b5b
Update addons/medical_treatment/functions/fnc_treatmentFailure.sqf
BrettMayson Mar 4, 2024
81be584
Update docs/wiki/framework/arsenal-framework.md
BrettMayson Mar 4, 2024
a343b38
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
BrettMayson Mar 6, 2024
ee070a6
Header
LinkIsGrim Mar 6, 2024
8a0d64f
use switch statement in fnc_useItem
LinkIsGrim Mar 6, 2024
601524d
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
johnb432 Mar 7, 2024
e488e13
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
BrettMayson Mar 10, 2024
a701251
only check adding to mags that are not full
BrettMayson Mar 11, 2024
7709779
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
johnb432 Mar 11, 2024
cbed198
Update fnc_getCountOfItem.sqf
johnb432 Mar 13, 2024
c6ebef8
Optimisations & header fix
johnb432 Mar 13, 2024
f53063d
Update addons/common/functions/fnc_adjustMagazineAmmo.sqf
johnb432 Mar 16, 2024
f5dc797
Fixed vehicle implementation
johnb432 Mar 16, 2024
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
3 changes: 2 additions & 1 deletion addons/arsenal/functions/fnc_addRightPanelButton.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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]];
Expand Down
2 changes: 1 addition & 1 deletion addons/arsenal/functions/fnc_scanConfig.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
1 change: 1 addition & 0 deletions addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ PREP(addLineToDebugDraw);
PREP(addSwayFactor);
PREP(addToInventory);
PREP(addWeapon);
PREP(adjustMagazineAmmo);
PREP(assignedItemFix);
PREP(assignObjectsInList);
PREP(ambientBrightness);
Expand Down
107 changes: 107 additions & 0 deletions addons/common/functions/fnc_adjustMagazineAmmo.sqf
Original file line number Diff line number Diff line change
@@ -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 {};
johnb432 marked this conversation as resolved.
Show resolved Hide resolved

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
22 changes: 13 additions & 9 deletions addons/common/functions/fnc_getCountOfItem.sqf
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "..\script_component.hpp"
/*
* Author: Dedmen
* Author: Dedmen, Blue
* 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
*
Expand All @@ -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
73 changes: 60 additions & 13 deletions addons/common/functions/fnc_uniqueItems.sqf
Original file line number Diff line number Diff line change
@@ -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_getUniqueItems
*
* 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 = [];

_inventoryItems append ((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;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};
};
} else {
call _fnc_getItems;
if (_isVehicle) then {
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
private _items = switch (_includeMagazines) do {
case 0: {
itemCargo _target
};
case 1: {
(magazineCargo _target) + (itemCargo _target)
};
case 2: {
magazineCargo _target
};
};
_items arrayIntersect _items
} else {
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;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};
};
};
};
27 changes: 23 additions & 4 deletions addons/medical_gui/functions/fnc_countTreatmentItems.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,31 @@ 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"];
{
private _item = _x;
private _index = _itemTypes find _item;
_vehicleCount = _vehicleCount + (_itemCounts param [_index, 0]);
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
} 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 _itemItems;
};
};

[_medicCount, _patientCount, _vehicleCount]
16 changes: 16 additions & 0 deletions addons/medical_treatment/CfgMagazines.hpp
Original file line number Diff line number Diff line change
@@ -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;
};
};
12 changes: 8 additions & 4 deletions addons/medical_treatment/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
};

Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 0 additions & 13 deletions addons/medical_treatment/CfgWeapons.hpp
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
1 change: 1 addition & 0 deletions addons/medical_treatment/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ class CfgPatches {
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"
#include "Cfg3DEN.hpp"
#include "CfgMagazines.hpp"

#endif
3 changes: 2 additions & 1 deletion addons/medical_treatment/functions/fnc_hasItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down
Loading