Skip to content

Commit 9a764b2

Browse files
authored
Field Rations - Support negative thirst and hunger values (#10949)
* Support negative thirst and hunger values & minor optimisations * More minor optimisations
1 parent f255375 commit 9a764b2

8 files changed

Lines changed: 21 additions & 21 deletions

addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ TRACE_1("Starting interact PFH",_interactionType);
8181
};
8282
};
8383
END_COUNTER(interactEH);
84-
}, 0.5, [getPosASL ACE_player vectorAdd [-100, 0, 0], [], []]] call CBA_fnc_addPerFrameHandler;
84+
}, 0.5, [[0, 0, -100], [], []]] call CBA_fnc_addPerFrameHandler;

addons/field_rations/functions/fnc_canRefillItem.sqf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ _itemData params ["_item", "_itemConfig", "_isMagazine"];
2626
alive _source
2727
&& {XGVAR(waterSourceActions) != 0}
2828
&& {
29-
(_isMagazine && {_item in magazines _player})
30-
|| {_item in (_player call EFUNC(common,uniqueItems))}
29+
(_isMagazine && {_item in ([_player, 2] call EFUNC(common,uniqueItems))})
30+
|| {!_isMagazine && {_item in (_player call EFUNC(common,uniqueItems))}}
3131
}
3232
&& {
3333
private _water = _source call FUNC(getRemainingWater);

addons/field_rations/functions/fnc_consumeItem.sqf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private _displayName = getText (_config >> "displayName");
3737
private _consumeText = getText (_config >> QXGVAR(consumeText));
3838

3939
if (_consumeText == "") then {
40-
_consumeText = if (_hungerSatiated > 0) then {
40+
_consumeText = if (_hungerSatiated != 0) then {
4141
LLSTRING(EatingX);
4242
} else {
4343
LLSTRING(DrinkingX);
@@ -88,14 +88,14 @@ private _fnc_onSuccess = {
8888
};
8989

9090
// Handle thirst and hunger values
91-
if (_thirstQuenched > 0) then {
91+
if (_thirstQuenched != 0) then {
9292
private _thirst = _player getVariable [QXGVAR(thirst), 0];
93-
_player setVariable [QXGVAR(thirst), (_thirst - _thirstQuenched) max 0];
93+
_player setVariable [QXGVAR(thirst), (_thirst - _thirstQuenched) min 100 max 0];
9494
};
9595

96-
if (_hungerSatiated > 0) then {
96+
if (_hungerSatiated != 0) then {
9797
private _hunger = _player getVariable [QXGVAR(hunger), 0];
98-
_player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) max 0];
98+
_player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) min 100 max 0];
9999
};
100100

101101
["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine]] call CBA_fnc_localEvent;
@@ -130,7 +130,7 @@ private _fnc_condition = {
130130
};
131131

132132
if (_isMagazine) exitWith {
133-
_consumeItem in magazines _player // return
133+
_consumeItem in ([_player, 2] call EFUNC(common,uniqueItems)) // return
134134
};
135135
_consumeItem in (_player call EFUNC(common,uniqueItems)) // return
136136
};

addons/field_rations/functions/fnc_getConsumableChildren.sqf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ private _fnc_getActions = {
2929
private _isMagazine = _config == _cfgMagazines;
3030
{
3131
private _itemConfig = _config >> _x;
32-
if (getNumber (_itemConfig >> QXGVAR(thirstQuenched)) > 0 || {getNumber (_itemConfig >> QXGVAR(hungerSatiated)) > 0}) then {
32+
if (getNumber (_itemConfig >> QXGVAR(thirstQuenched)) != 0 || {getNumber (_itemConfig >> QXGVAR(hungerSatiated)) != 0}) then {
3333
private _displayName = getText (_itemConfig >> "displayName");
3434
private _picture = getText (_itemConfig >> "picture");
3535

@@ -40,7 +40,7 @@ private _fnc_getActions = {
4040
} forEach _items;
4141
} forEach [
4242
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
43-
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
43+
[_cfgMagazines, [_player, 2] call EFUNC(common,uniqueItems)]
4444
];
4545

4646
_actions

addons/field_rations/functions/fnc_getRefillChildren.sqf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private _cfgMagazines = configFile >> "CfgMagazines";
4040
} forEach _items;
4141
} forEach [
4242
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
43-
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
43+
[_cfgMagazines, [_player, 2] call EFUNC(common,uniqueItems)]
4444
];
4545

4646
_actions

addons/field_rations/functions/fnc_handleEffects.sqf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@ if !(_player call EFUNC(common,isAwake)) exitWith {};
2929

3030
// Make unit moan from high hunger/thirst
3131
if (
32-
GETEGVAR(medical,enabled,false) &&
33-
{(_thirst > CONSEQ_THRESHOLD_LIGHT) || {_hunger > CONSEQ_THRESHOLD_LIGHT}} &&
32+
GETEGVAR(medical,enabled,false) &&
33+
{(_thirst > CONSEQ_THRESHOLD_LIGHT) || {_hunger > CONSEQ_THRESHOLD_LIGHT}} &&
3434
{random 1 < linearConversion [CONSEQ_THRESHOLD_LIGHT, 100, (_thirst max _hunger), 0.05, 0.2, true]}
3535
) then {
36-
[ACE_Player, "moan", round (linearConversion [CONSEQ_THRESHOLD_LIGHT, 90, (_thirst max _hunger), 0, 2, true])] call EFUNC(medical_feedback,playInjuredSound);
36+
[_player, "moan", round (linearConversion [CONSEQ_THRESHOLD_LIGHT, 90, (_thirst max _hunger), 0, 2, true])] call EFUNC(medical_feedback,playInjuredSound);
3737
};
3838

3939
// Trigger high thirst/hunger consequence (chance based on how high thirst/hunger are)
4040
if (
41-
GETEGVAR(medical,enabled,false) &&
42-
{(_thirst > CONSEQ_THRESHOLD_SEVERE || {_hunger > CONSEQ_THRESHOLD_SEVERE}) &&
41+
GETEGVAR(medical,enabled,false) &&
42+
{(_thirst > CONSEQ_THRESHOLD_SEVERE || {_hunger > CONSEQ_THRESHOLD_SEVERE}) &&
4343
{random 1 < linearConversion [CONSEQ_THRESHOLD_SEVERE, 100, _thirst max _hunger, 0.05, 0.1, true]}}
4444
) exitWith {
4545
if (XGVAR(nearDepletedConsequence) == 1) then { // Set unit unconscious with a 45s cooldown
@@ -48,8 +48,8 @@ if (
4848
[_player, true, 5, true] call EFUNC(medical,setUnconscious);
4949
};
5050
} else { // Add pain
51-
if (ACE_Player getVariable [QEGVAR(medical,pain), 0] < 0.1) then {
52-
[ACE_Player, 0.1] call EFUNC(medical,adjustPainLevel);
51+
if (_player getVariable [QEGVAR(medical,pain), 0] < 0.1) then {
52+
[_player, 0.1] call EFUNC(medical,adjustPainLevel);
5353
};
5454
};
5555
};

addons/field_rations/functions/fnc_scanFieldRations.sqf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ private _cfgWeapons = configFile >> "CfgWeapons";
2020
private _cfgMagazines = configFile >> "CfgMagazines";
2121

2222
private _fnc_isFieldRationItem = toString {
23-
(getNumber (_x >> "ACE_isFieldRationItem") isEqualTo 1) || {(getNumber (_x >> QXGVAR(thirstQuenched))) > 0} || {(getNumber (_x >> QXGVAR(hungerSatiated))) > 0} || {(getText (_x >> QXGVAR(refillItem))) isNotEqualTo ""}
23+
(getNumber (_x >> "ACE_isFieldRationItem") isEqualTo 1) || {(getNumber (_x >> QXGVAR(thirstQuenched))) != 0} || {(getNumber (_x >> QXGVAR(hungerSatiated))) != 0} || {(getText (_x >> QXGVAR(refillItem))) isNotEqualTo ""}
2424
};
2525

2626
{

docs/wiki/framework/field-rations-framework.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ redirect_from: "/wiki/frameworkx/field-rations-framework.html"
3131
| `ACE_isFieldRationItem` | Number | Force adds the item to the ACE Field Rations category in ACE Arsenal (OPTIONAL) |
3232

3333

34-
_* Value range is 0 to 100 and can be modified by the corresponding coefficient setting._
34+
_* Value range is -100 to 100 and can be modified by the corresponding coefficient setting._
3535

3636
_** Array is in format: STAND, CROUCH, PRONE. If player is in vehicle, the first element is used._
3737

0 commit comments

Comments
 (0)