forked from acemod/ACE3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Medical - Support Magazine Treatment Items (acemod#9816)
* count treatment items * getCountofItem Co-Authored-By: Blue <[email protected]> * getCountofItem fix Co-Authored-By: Blue <[email protected]> * convert painkillers to magazine * use isclass Co-Authored-By: johnb432 <[email protected]> * forget to change variable * Update addons/medical_treatment/functions/fnc_hasItem.sqf Co-authored-by: Grim <[email protected]> * better magazine adjustment * Update addons/common/functions/fnc_adjustMagazineAmmo.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_treatment/functions/fnc_medication.sqf Co-authored-by: johnb432 <[email protected]> * Update addons/medical_treatment/functions/fnc_treatmentFailure.sqf Co-authored-by: johnb432 <[email protected]> * Update docs/wiki/framework/arsenal-framework.md Co-authored-by: Jouni Järvinen <[email protected]> * Update addons/common/functions/fnc_adjustMagazineAmmo.sqf Co-authored-by: johnb432 <[email protected]> * 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 <[email protected]> * only check adding to mags that are not full Co-Authored-By: LinkIsGrim <[email protected]> * 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 <[email protected]> Co-authored-by: johnb432 <[email protected]> Co-authored-by: Grim <[email protected]> Co-authored-by: Jouni Järvinen <[email protected]> Co-authored-by: LinkIsGrim <[email protected]>
- Loading branch information
1 parent
50978ef
commit 3c5b46c
Showing
16 changed files
with
261 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_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 | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.