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 4 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
63 changes: 63 additions & 0 deletions addons/common/functions/fnc_adjustMagazineAmmo.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "..\script_component.hpp"
/*
* Author: Katalam, Blue, Brett Mayson
johnb432 marked this conversation as resolved.
Show resolved Hide resolved
* Handle adjusting a magazine's ammo
*
* Arguments:
* 0: Vehicle or Unit <OBJECT>
* 1: Item <STRING>
* 2: Count <NUMBER>
*
* Return Value:
* Empty mag <BOOLEAN> - true if the magazine is empty after the ammo is consumed
*
* Example:
* [player, "30Rnd_556x45_Stanag", 1] call ace_commone_fnc_adjustMagazineAmmo;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
*
* Public: No
*/

params ["_unit", "_item", ["_count", -1]];

private _lowestCount = 999;
private _lowestIndex = 0;

if (_unit isKindOf "CAManBase") then {
private _magazines = [];
{
_x params ["_class", "_ammo", "_loaded", "", "_location"];
if (_class == _item && !_loaded) then {
_magazines pushBack _x;
if (_ammo < _lowestCount) then {
_lowestCount = _ammo;
_lowestIndex = count _magazines - 1;
};
};
} forEach (magazinesAmmoFull _unit);
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
if (_magazines isEqualTo []) exitWith {};
_unit removeMagazines _item;
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
(_magazines select _lowestIndex) params ["_class", "_ammo", "_loaded", "", "_location"];
_magazines set [_lowestIndex, [_class, _ammo + _count, _loaded, "", /* tolower _location - no command, will always go to first empty container */ ""]];
{
_x params ["_class", "_ammo", "_loaded", "", "_location"];
if (_ammo > 0) then {
[_unit, _class, _location, _ammo] call FUNC(addToInventory);
};
} forEach _magazines;
_ammo + _count <= 0
} else {
private _cargoMags = magazinesAmmoCargo _unit;
private _itemIndex = _cargoMags findIf {_x select 0 isEqualTo _item};
if (_itemIndex == -1) exitWith {};
clearMagazineCargoGlobal _unit;
{
if (_forEachIndex == _itemIndex) then {
if (((_x select 1) + _count) > 0) then {
_unit addMagazineAmmoCargo [_x select 0, 1, ((_x select 1) + _count)];
};
} else {
_unit addMagazineAmmoCargo [_x select 0, 1, _x select 1];
};
} forEach _cargoMags;
((_cargoMags select _itemIndex) select 1) + _count <= 0
};
23 changes: 16 additions & 7 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 @@ -20,12 +20,21 @@
params ["_unit", "_itemType"];

private _countItemsInContainer = {
(getItemCargo _this) params ["_itemTypes", "_itemCounts"];
params ["_itemType", "_container"];

private _index = _itemTypes find _itemType;
_itemCounts param [_index, 0]
if ((_itemType call BIS_fnc_itemType) select 0 isEqualTo "Magazine") then {
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
(getMagazineCargo _container) params ["_itemTypes", "_itemCounts"];

private _index = _itemTypes find _itemType;
_itemCounts param [_index, 0]
} else {
(getItemCargo _container) params ["_itemTypes", "_itemCounts"];

private _index = _itemTypes find _itemType;
_itemCounts param [_index, 0]
};
};

((uniformContainer _unit) call _countItemsInContainer) +
((vestContainer _unit) call _countItemsInContainer) +
((backpackContainer _unit) call _countItemsInContainer)
([_itemType, uniformContainer _unit] call _countItemsInContainer) +
([_itemType, vestContainer _unit] call _countItemsInContainer) +
([_itemType, backpackContainer _unit] call _countItemsInContainer)
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 ((_x call BIS_fnc_itemType) select 0 isEqualTo "Magazine") 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 ((magazinesAmmoCargo _unitVehicle) apply { _x select 0 });
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};
_items findIf {_x in _unitItems} != -1
};
Expand Down
3 changes: 2 additions & 1 deletion addons/medical_treatment/functions/fnc_medication.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 (_usedItem call BIS_fnc_itemType select 0 isEqualTo "Magazine");
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
[_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;
6 changes: 5 additions & 1 deletion addons/medical_treatment/functions/fnc_treatmentFailure.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 !(((_usedItem call BIS_fnc_itemType) select 0) isEqualTo "Magazine") then {
[_itemUser, _usedItem] call EFUNC(common,addToInventory);
} else {
[_itemUser, _usedItem, 1] call EFUNC(common,adjustMagazineAmmo);
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};
BrettMayson marked this conversation as resolved.
Show resolved Hide resolved
};

// Switch medic to end animation immediately
Expand Down
Loading