Field Rations - Basic CfgMagazines support (#9008)

* Add basic CfgMagazines support for field_rations

* Update headers

* Fix CBA context menu

* Add backward compatiblity to fnc_consumeItem

* Fix item refill not finishing

Whoopsie.

* Revert "Add backward compatiblity to fnc_consumeItem"

In hindsight it's not necessary, this is not public function.
This commit is contained in:
Filip Maciejewski 2022-09-06 13:21:45 +02:00 committed by GitHub
parent 508e669e05
commit f734fa9e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 46 deletions

View File

@ -89,7 +89,8 @@ if !(hasInterface) exitWith {};
], ],
{ {
params ["_unit", "", "_item"]; params ["_unit", "", "_item"];
[objNull, _unit, _item] call FUNC(consumeItem); private _itemConfig = configFile >> "CfgWeapons" >> _item;
[objNull, _unit, [_item, _itemConfig, false]] call FUNC(consumeItem);
false false
} }
] call CBA_fnc_addItemContextMenuOption; ] call CBA_fnc_addItemContextMenuOption;

View File

@ -6,23 +6,30 @@
* Arguments: * Arguments:
* 0: Water source <OBJECT> * 0: Water source <OBJECT>
* 1: Player <OBJECT> * 1: Player <OBJECT>
* 2: Item classname <STRING> * 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
* *
* Return Value: * Return Value:
* Can refill item <BOOL> * Can refill item <BOOL>
* *
* Example: * Example:
* [_source, _player, "ACE_WaterBottle_Empty"] call ace_field_rations_fnc_canRefillItem * [_source, _player, ["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_canRefillItem
* *
* Public: No * Public: No
*/ */
params ["_source", "_player", "_item"]; params ["_source", "_player", "_itemData"];
_itemData params ["_item", "_itemConfig", "_isMagazine"];
alive _source alive _source
&& {XGVAR(waterSourceActions) != 0} && {XGVAR(waterSourceActions) != 0}
&& {_item in (_player call EFUNC(common,uniqueItems))} && {
(_isMagazine && {_item in magazines _player})
|| {_item in (_player call EFUNC(common,uniqueItems))}
}
&& { && {
private _water = _source call FUNC(getRemainingWater); private _water = _source call FUNC(getRemainingWater);
_water == REFILL_WATER_INFINITE || {_water >= getNumber (configFile >> "CfgWeapons" >> _item >> QXGVAR(refillAmount))} _water == REFILL_WATER_INFINITE || {_water >= getNumber (_itemConfig >> QXGVAR(refillAmount))}
} }

View File

@ -6,21 +6,23 @@
* Arguments: * Arguments:
* 0: Target (not used) <OBJECT> * 0: Target (not used) <OBJECT>
* 1: Player <OBJECT> * 1: Player <OBJECT>
* 2: Item classname <STRING> * 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [objNull, ACE_player, "ACE_WaterBottle"] call ace_field_rations_fnc_consumeItem * [objNull, ACE_player, "["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_consumeItem
* *
* Public: No * Public: No
*/ */
params ["", "_player", "_consumeItem"]; params ["", "_player", "_consumeData"];
TRACE_2("Consume item started",_player,_consumeItem); _consumeData params ["_consumeItem", "_config", "_isMagazine"];
TRACE_3("Consume item started",_player,_consumeItem,_config);
private _config = configFile >> "CfgWeapons" >> _consumeItem;
// Get consume time for item // Get consume time for item
private _consumeTime = getNumber (_config >> QXGVAR(consumeTime)); private _consumeTime = getNumber (_config >> QXGVAR(consumeTime));
@ -70,11 +72,15 @@ private _soundPlayed = if (_consumeAnim != "" && {vehicle _player == _player &&
private _fnc_onSuccess = { private _fnc_onSuccess = {
params ["_args"]; params ["_args"];
_args params ["_player", "_consumeItem", "_replacementItem", "_thirstQuenched", "_hungerSatiated"]; _args params ["_player", "_consumeItem", "_replacementItem", "_thirstQuenched", "_hungerSatiated", "", "", "", "_isMagazine"];
TRACE_1("Consume item successful",_args); TRACE_1("Consume item successful",_args);
// Remove consumed item // Remove consumed item
if (_isMagazine) then {
_player removeMagazineGlobal _consumeItem;
} else {
_player removeItem _consumeItem; _player removeItem _consumeItem;
};
// Add replacement item if needed // Add replacement item if needed
if (_replacementItem != "") then { if (_replacementItem != "") then {
@ -92,7 +98,7 @@ private _fnc_onSuccess = {
_player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) max 0]; _player setVariable [QXGVAR(hunger), (_hunger - _hungerSatiated) max 0];
}; };
["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated]] call CBA_fnc_localEvent; ["acex_rationConsumed", [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine]] call CBA_fnc_localEvent;
_player setVariable [QGVAR(previousAnim), nil]; _player setVariable [QGVAR(previousAnim), nil];
}; };
@ -115,7 +121,7 @@ private _fnc_onFailure = {
private _fnc_condition = { private _fnc_condition = {
params ["_args"]; params ["_args"];
_args params ["_player", "_consumeItem", "", "", "", "_consumeAnim", "_consumeSound", "_soundPlayed"]; _args params ["_player", "_consumeItem", "", "", "", "_consumeAnim", "_consumeSound", "_soundPlayed", "_isMagazine"];
// Attempt to sync sound with animation start // Attempt to sync sound with animation start
if (!_soundPlayed && {_consumeSound != "" && {_consumeAnim == "" || {animationState _player == _consumeAnim}}}) then { if (!_soundPlayed && {_consumeSound != "" && {_consumeAnim == "" || {animationState _player == _consumeAnim}}}) then {
@ -123,7 +129,10 @@ private _fnc_condition = {
_args set [7, true]; _args set [7, true];
}; };
_consumeItem in (_player call EFUNC(common,uniqueItems)) if (_isMagazine) exitWith {
_consumeItem in magazines _player // return
};
_consumeItem in (_player call EFUNC(common,uniqueItems)) // return
}; };
[ [
@ -136,7 +145,8 @@ private _fnc_condition = {
_hungerSatiated, _hungerSatiated,
_consumeAnim, _consumeAnim,
_consumeSound, _consumeSound,
_soundPlayed _soundPlayed,
_isMagazine
], ],
_fnc_onSuccess, _fnc_onSuccess,
_fnc_onFailure, _fnc_onFailure,

View File

@ -22,18 +22,26 @@ private _fnc_getActions = {
private _actions = []; private _actions = [];
private _cfgWeapons = configFile >> "CfgWeapons"; private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
{ {
private _config = _cfgWeapons >> _x; _x params ["_config", "_items"];
if (getNumber (_config >> QXGVAR(thirstQuenched)) > 0 || {getNumber (_config >> QXGVAR(hungerSatiated)) > 0}) then { private _isMagazine = _config == _cfgMagazines;
private _displayName = getText (_config >> "displayName"); {
private _picture = getText (_config >> "picture"); private _itemConfig = _config >> _x;
if (getNumber (_itemConfig >> QXGVAR(thirstQuenched)) > 0 || {getNumber (_itemConfig >> QXGVAR(hungerSatiated)) > 0}) then {
private _displayName = getText (_itemConfig >> "displayName");
private _picture = getText (_itemConfig >> "picture");
// Exec next frame so closing interaction menu doesn't block progressBar // Exec next frame so closing interaction menu doesn't block progressBar
private _action = [_x, _displayName, _picture, {[FUNC(consumeItem), _this] call CBA_fnc_execNextFrame}, {true}, {}, _x] call EFUNC(interact_menu,createAction); private _action = [_x, _displayName, _picture, {[FUNC(consumeItem), _this] call CBA_fnc_execNextFrame}, {true}, {}, [_x, _itemConfig, _isMagazine]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _player]; _actions pushBack [_action, [], _player];
}; };
} forEach (_player call EFUNC(common,uniqueItems)); } forEach _items;
} forEach [
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
];
_actions _actions
}; };

View File

@ -24,15 +24,23 @@ if (_water == 0 || {_water == REFILL_WATER_DISABLED}) exitWith {[]};
private _actions = []; private _actions = [];
private _cfgWeapons = configFile >> "CfgWeapons"; private _cfgWeapons = configFile >> "CfgWeapons";
private _cfgMagazines = configFile >> "CfgMagazines";
{ {
private _config = _cfgWeapons >> _x; _x params ["_config", "_items"];
if (getText (_config >> QXGVAR(refillItem)) != "" && {_water == REFILL_WATER_INFINITE || {getNumber (_config >> QXGVAR(refillAmount)) <= _water}}) then { private _isMagazine = _config == _cfgMagazines;
private _displayName = format ["%1: %2", LLSTRING(Refill), getText (_config >> "displayName")]; {
private _picture = getText (_config >> "picture"); private _itemConfig = _config >> _x;
private _action = [_x, _displayName, _picture, FUNC(refillItem), FUNC(canRefillItem), {}, _x] call EFUNC(interact_menu,createAction); if (getText (_itemConfig >> QXGVAR(refillItem)) != "" && {_water == REFILL_WATER_INFINITE || {getNumber (_itemConfig >> QXGVAR(refillAmount)) <= _water}}) then {
private _displayName = format ["%1: %2", LLSTRING(Refill), getText (_itemConfig >> "displayName")];
private _picture = getText (_itemConfig >> "picture");
private _action = [_x, _displayName, _picture, FUNC(refillItem), FUNC(canRefillItem), {}, [_x, _itemConfig, _isMagazine]] call EFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _source]; _actions pushBack [_action, [], _source];
}; };
} forEach (_player call EFUNC(common,uniqueItems)); } forEach _items;
} forEach [
[_cfgWeapons, _player call EFUNC(common,uniqueItems)],
[_cfgMagazines, [magazines _player] call EFUNC(common,uniqueElements)]
];
_actions _actions

View File

@ -6,22 +6,24 @@
* Arguments: * Arguments:
* 0: Water source <OBJECT> * 0: Water source <OBJECT>
* 1: Player <OBJECT> * 1: Player <OBJECT>
* 2: Item classname <STRING> * 2: Item data <ARRAY>
* 0: Item classname <STRING>
* 1: Item config <CONFIG>
* 2: Is item magazine <BOOL>
* *
* Return Value: * Return Value:
* None * None
* *
* Example: * Example:
* [_source, _player, "ACE_WaterBottle_Empty"] call ace_field_rations_fnc_refillItem * [_source, _player, ["ACE_WaterBottle_Empty", configFile >> "CfgWeapons" >> "ACE_WaterBottle_Empty", false]] call ace_field_rations_fnc_refillItem
* *
* Public: No * Public: No
*/ */
params ["_source", "_player", "_item"]; params ["_source", "_player", "_itemData"];
_itemData params ["_item", "_config", "_isMagazine"];
TRACE_3("Item refill started",_source,_player,_item); TRACE_3("Item refill started",_source,_player,_item);
private _config = configFile >> "CfgWeapons" >> _item;
// Get config values for refill // Get config values for refill
private _refillItem = getText (_config >> QXGVAR(refillItem)); private _refillItem = getText (_config >> QXGVAR(refillItem));
private _refillAmount = getNumber (_config >> QXGVAR(refillAmount)); private _refillAmount = getNumber (_config >> QXGVAR(refillAmount));
@ -29,11 +31,16 @@ private _refillTime = getNumber (_config >> QXGVAR(refillTime));
private _fnc_onSuccess = { private _fnc_onSuccess = {
params ["_args"]; params ["_args"];
_args params ["_source", "_player", "_item", "_refillItem", "_refillAmount"]; _args params ["_source", "_player", "_itemData", "_refillItem", "_refillAmount", "_itemData"];
_itemData params ["_item", "", "_isMagazine"];
TRACE_1("Refill item successful",_args); TRACE_1("Refill item successful",_args);
// Replace item with refilled one // Replace item with refilled one
if (_isMagazine) then {
_player removeMagazineGlobal _item;
} else {
_player removeItem _item; _player removeItem _item;
};
[_player, _refillItem] call EFUNC(common,addToInventory); [_player, _refillItem] call EFUNC(common,addToInventory);
// Update remaining water in source // Update remaining water in source
@ -43,7 +50,7 @@ private _fnc_onSuccess = {
[_source, _waterInSource] call FUNC(setRemainingWater); [_source, _waterInSource] call FUNC(setRemainingWater);
}; };
["acex_rationRefilled", [_source, _player, _item, _refillItem, _refillAmount]] call CBA_fnc_localEvent; ["acex_rationRefilled", [_source, _player, _item, _refillItem, _refillAmount, _isMagazine]] call CBA_fnc_localEvent;
// Show refilled item hint // Show refilled item hint
private _picture = getText (configFile >> "CfgWeapons" >> _refillItem >> "picture"); private _picture = getText (configFile >> "CfgWeapons" >> _refillItem >> "picture");
@ -64,7 +71,7 @@ private _fnc_condition = {
[ [
_source, _source,
_player, _player,
_item, _itemData,
_refillItem, _refillItem,
_refillAmount _refillAmount
], ],

View File

@ -45,8 +45,8 @@ Config Name | Type | Description
Event Name | Passed Parameter(s) | Locality | Description Event Name | Passed Parameter(s) | Locality | Description
---------- | ------------------- | -------- | ----------- ---------- | ------------------- | -------- | -----------
`acex_rationConsumed` | [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated] | Local | Item consumed `acex_rationConsumed` | [_player, _consumeItem, _replacementItem, _thirstQuenched, _hungerSatiated, _isMagazine] | Local | Item consumed
`acex_rationRefilled` | [_source, _player, _item, _refillItem, _refillAmount] | Local | Item refilled `acex_rationRefilled` | [_source, _player, _item, _refillItem, _refillAmount, _isMagazine] | Local | Item refilled
## 3. Scripting ## 3. Scripting