Skip to content

Commit

Permalink
Handle empty FAK
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueTheKing committed Oct 9, 2023
1 parent 1180164 commit 150d6f6
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 51 deletions.
30 changes: 30 additions & 0 deletions addons/misc/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ PREP_RECOMPILE_END;
2
] call CBA_fnc_addSetting;

// Remove IFAK when empty
[
QGVAR(IFAK_RemoveWhenEmpty),
"CHECKBOX",
LLSTRING(SETTING_FAK_RemoveWhenEmpty),
[CBA_SETTINGS_CAT, LSTRING(SubCategory_IFAK)],
[true],
true
] call CBA_fnc_addSetting;

//IFAK First Slot Item
[
QGVAR(IFAKFirstSlotItem),
Expand Down Expand Up @@ -231,6 +241,16 @@ PREP_RECOMPILE_END;
2
] call CBA_fnc_addSetting;

// Remove AFAK when empty
[
QGVAR(AFAK_RemoveWhenEmpty),
"CHECKBOX",
LLSTRING(SETTING_FAK_RemoveWhenEmpty),
[CBA_SETTINGS_CAT, LSTRING(SubCategory_AFAK)],
[true],
true
] call CBA_fnc_addSetting;

//AFAK First Slot Item
[
QGVAR(AFAKFirstSlotItem),
Expand Down Expand Up @@ -337,6 +357,16 @@ PREP_RECOMPILE_END;
2
] call CBA_fnc_addSetting;

// Remove MFAK when empty
[
QGVAR(MFAK_RemoveWhenEmpty),
"CHECKBOX",
LLSTRING(SETTING_FAK_RemoveWhenEmpty),
[CBA_SETTINGS_CAT, LSTRING(SubCategory_MFAK)],
[true],
true
] call CBA_fnc_addSetting;

//MFAK First Slot Item
[
QGVAR(MFAKFirstSlotItem),
Expand Down
4 changes: 2 additions & 2 deletions addons/misc/functions/fnc_FAK_checkRepack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

params ["_unit", "_item", "_type", "_slotToCheck"];

if !([_unit, _item] call ACEFUNC(common,hasMagazine)) exitWith {false};
if (!([_unit, _item] call ACEFUNC(common,hasMagazine)) && {(magazinesAmmoFull [_unit, true]) findIf {_x select 0 isEqualTo _item} isEqualTo -1}) exitWith {false};

private _return = true;

Expand Down Expand Up @@ -93,7 +93,7 @@ switch (_type) do {

{
_x params ["_className", "_amount"];

if (((_className call BIS_fnc_itemType) select 0) == "Item") then {
if !([_unit, _className, _amount] call _fnc_getTargetItemCount >= _amount) exitWith {
_return = false;
Expand Down
4 changes: 2 additions & 2 deletions addons/misc/functions/fnc_FAK_checkSlot.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _itemType = _itemType select 0;

if (_itemType == "Item") exitWith {([_unit, _item] call ACEFUNC(common,hasItem));};

if ((_itemType == "Magazine") && !([_unit, _item] call ACEFUNC(common,hasMagazine))) exitWith {false};
if ((_itemType == "Magazine") && !([_unit, _item] call ACEFUNC(common,hasMagazine)) && {(magazinesAmmoFull [_unit, true]) findIf {_x select 0 isEqualTo _item} isEqualTo -1}) exitWith {false};

private _ammoCount = [_unit, _item] call FUNC(getMagazineAmmoCounts);
private _max = 255;
Expand All @@ -38,7 +38,7 @@ switch (_type) do {
};

{
if (_slot == 0 && _x > 0) exitWith {
if (_slot == 0) exitWith {
_return = true;
break;
};
Expand Down
5 changes: 3 additions & 2 deletions addons/misc/functions/fnc_FAK_repack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private _fnc_getContainer = {

private _ammoCount = [_unit, _item] call FUNC(getMagazineAmmoCounts);
private _slotArray = [];
private _highestAmmoCount = 0;
private _highestAmmoCount = -1;

{
private _checkedArray = [_x, _type] call FUNC(FAK_ammoToArray);
Expand All @@ -55,8 +55,9 @@ private _highestAmmoCount = 0;
};
} forEach _ammoCount;

if !(_highestAmmoCount > 0) exitWith {};
if !(_highestAmmoCount > -1) exitWith {};

private _container = "";
private _FAKToAdd = "";
private _itemList = [];
private _max = 0;
Expand Down
83 changes: 39 additions & 44 deletions addons/misc/functions/fnc_FAK_unpack.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -42,36 +42,42 @@ private _fnc_getContainer = {
};
};

// ----- Handling for full item -----

private _itemType = _item call BIS_fnc_itemType;
_itemType = _itemType select 0;

private _container = "";
private _slotArray = [];
private _FAKToAdd = "";
private _itemList = [];
private _removeOnEmptyCondition = false;

if (_itemType == "Item") exitWith {
switch (_type) do {
case 0: { // IFAK
_FAKToAdd = "kat_IFAK_Magazine";
_slotArray = [true,true,true,true,false,false,false,false];
_container = [(missionNamespace getVariable [QGVAR(IFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(IFAKContents), []];
};
case 1: { // AFAK
_FAKToAdd = "kat_AFAK_Magazine";
_slotArray = [true,true,true,true,true,true,false,false];
_container = [(missionNamespace getVariable [QGVAR(AFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(AFAKContents), []];
};
default { // MFAK
_FAKToAdd = "kat_MFAK_Magazine";
_slotArray = [true,true,true,true,true,true,true,true];
_container = [(missionNamespace getVariable [QGVAR(MFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(MFAKContents), []];
};
switch (_type) do {
case 0: { // IFAK
_FAKToAdd = "kat_IFAK_Magazine";
_slotArray = [true,true,true,true,false,false,false,false];
_container = [(missionNamespace getVariable [QGVAR(IFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(IFAKContents), []];
_removeOnEmptyCondition = GVAR(IFAK_RemoveWhenEmpty);
};
case 1: { // AFAK
_FAKToAdd = "kat_AFAK_Magazine";
_slotArray = [true,true,true,true,true,true,false,false];
_container = [(missionNamespace getVariable [QGVAR(AFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(AFAKContents), []];
_removeOnEmptyCondition = GVAR(AFAK_RemoveWhenEmpty);
};
default { // MFAK
_FAKToAdd = "kat_MFAK_Magazine";
_slotArray = [true,true,true,true,true,true,true,true];
_container = [(missionNamespace getVariable [QGVAR(MFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(MFAKContents), []];
_removeOnEmptyCondition = GVAR(MFAK_RemoveWhenEmpty);
};
};

// ----- Handling for full item -----

if (_itemType == "Item") exitWith {
_unit removeItem _item;
if (_slot > 0) then {
_slotArray set [(_slot - 1), false];
Expand All @@ -82,51 +88,36 @@ if (_itemType == "Item") exitWith {
{
[_unit, _x, _container] call _fnc_arrayToInvItem;
} forEach _itemList;

if !(_removeOnEmptyCondition) then {
[_unit, _FAKToAdd, "", 0] call ACEFUNC(common,addToInventory);
};
};
};

// ----- Handling for magazine -----

private _ammoCount = [_unit, _item] call FUNC(getMagazineAmmoCounts);
_unit removeItem _item;
private _lowestAmmoCount = 257;

{
private _checkedArray = [_x, _type] call FUNC(FAK_ammoToArray);

if (_checkedArray select (_slot - 1) && _x < _lowestAmmoCount) then { // Get emptiest FAK
if (_x < _lowestAmmoCount && (_slot == 0 || (_slot > 0 && {_checkedArray select (_slot - 1)}))) then { // Get emptiest FAK
_slotArray = _checkedArray;
_lowestAmmoCount = _x;
};
} forEach _ammoCount;

if !(_lowestAmmoCount < 257) exitWith {};

switch (_type) do {
case 0: {
_FAKToAdd = "kat_IFAK_Magazine";
_container = [(missionNamespace getVariable [QGVAR(IFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(IFAKContents), []];
};
case 1: {
_FAKToAdd = "kat_AFAK_Magazine";
_container = [(missionNamespace getVariable [QGVAR(AFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(AFAKContents), []];
};
default {
_FAKToAdd = "kat_MFAK_Magazine";
_container = [(missionNamespace getVariable [QGVAR(MFAK_Container), 0])] call _fnc_getContainer;
_itemList = missionNameSpace getVariable [QGVAR(MFAKContents), []];
};
};
_unit removeItem _item;

if (_slot > 0) then {
_slotArray set [(_slot - 1), false];
[_unit, (_itemList select (_slot - 1)), _container] call _fnc_arrayToInvItem;

private _remaining = [_slotArray] call FUNC(FAK_arrayToAmmo);

if (_remaining > 0) then {
if (_remaining > 0 || !_removeOnEmptyCondition) then {
[_unit, _FAKToAdd, "", _remaining] call ACEFUNC(common,addToInventory);
};
} else {
Expand All @@ -135,4 +126,8 @@ if (_slot > 0) then {
[_unit, (_itemList select _forEachIndex), _container] call _fnc_arrayToInvItem;
};
} forEach _slotArray;

if !(_removeOnEmptyCondition) then {
[_unit, _FAKToAdd, "", 0] call ACEFUNC(common,addToInventory);
};
};
2 changes: 1 addition & 1 deletion addons/misc/functions/fnc_getMagazineAmmoCounts.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ params ["_unit", "_mag", "_returnLocation"];

private _magAmmo = [];
private _return = _magAmmo;
private _targetMag = magazinesAmmoFull _unit select {_x select 0 == _mag};
private _targetMag = magazinesAmmoFull [_unit, true] select {_x select 0 == _mag};

if (_returnLocation) exitWith {

Expand Down
3 changes: 3 additions & 0 deletions addons/misc/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@
<English>Repack Slot 8</English>
<German>Packe Tasche 8</German>
</Key>
<Key ID="STR_KAT_Misc_SETTING_FAK_RemoveWhenEmpty">
<English>Remove when empty</English>
</Key>
<Key ID="STR_KAT_Misc_CancelCarrying">
<English>Cancel Carrying</English>
<Japanese>担ぐのを止める</Japanese>
Expand Down

0 comments on commit 150d6f6

Please sign in to comment.