Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Field Rations - Add ability to drink from source #204

Merged
merged 3 commits into from
Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
20 changes: 20 additions & 0 deletions addons/field_rations/CfgMoves.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,25 @@ class CfgMovesMaleSdr: CfgMovesBasic {
file = QPATHTOF(anim\drink_prone_can.rtm);
speed = 1/9;
};
class GVAR(drinkFromSource): GVAR(drinkStand) {
file = QPATHTOF(anim\drink_source.rtm);
speed = 1/8;
};
class GVAR(drinkFromSourceHigh): GVAR(drinkFromSource) {
file = QPATHTOF(anim\drink_source_high.rtm);
};
class GVAR(drinkFromSourceLow): GVAR(drinkFromSource) {
file = QPATHTOF(anim\drink_source_low.rtm);
};
class GVAR(drinkFromSourceSquat): GVAR(drinkFromSource) {
file = QPATHTOF(anim\drink_source_squat.rtm);
interpolateFrom[] = {"AmovPercMstpSnonWnonDnon", 0.1, "AmovPknlMstpSnonWnonDnon", 0.1};
};
class GVAR(drinkFromSourceSquatHigh): GVAR(drinkFromSourceSquat) {
file = QPATHTOF(anim\drink_source_squat_high.rtm);
};
class GVAR(drinkFromSourceSquatLow): GVAR(drinkFromSourceSquat) {
file = QPATHTOF(anim\drink_source_squat_low.rtm);
};
};
};
2 changes: 1 addition & 1 deletion addons/field_rations/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CfgVehicles {
class NonStrategic;
class Land_Water_source_F: NonStrategic {
GVAR(waterSupply) = REFILL_WATER_INFINITE;
GVAR(offset)[] = {0, 0, -0.2};
GVAR(offset)[] = {0, -0.12, -0.25};
};

class Land_WaterPump_01_F;
Expand Down
3 changes: 3 additions & 0 deletions addons/field_rations/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
PREP(addStatusModifier);
PREP(addWaterSourceInteractions);
PREP(canDrinkFromSource);
PREP(canRefillItem);
PREP(checkWater);
PREP(consumeItem);
PREP(drinkFromSource);
PREP(getActionOffset);
PREP(getConsumableChildren);
PREP(getDrinkAnimation);
PREP(getRefillChildren);
PREP(getRemainingWater);
PREP(handleEffects);
Expand Down
24 changes: 16 additions & 8 deletions addons/field_rations/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ if !(hasInterface) exitWith {};
{true},
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];

alive _waterSource
&& {GVAR(waterSourceActions) != 0}
&& {_waterSource call FUNC(getRemainingWater) != REFILL_WATER_DISABLED}
&& {[_player, _waterSource] call ACEFUNC(common,canInteractWith)}
},
Expand All @@ -49,16 +51,20 @@ if !(hasInterface) exitWith {};
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
(_waterSource call FUNC(getRemainingWater)) != REFILL_WATER_INFINITE
}
] call ACEFUNC(interact_menu,createAction)
/*
] call ACEFUNC(interact_menu,createAction),
[
QGVAR(drinkDirectly),
localize LSTRING(DrinkDirectly),
QGVAR(drinkFromSource),
localize LSTRING(DrinkFromSource),
QPATHTOF(ui\icon_water_tap.paa),
{systemChat "x"},
{true}
] call ACEFUNC(interact_menu,createAction),
*/
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
[_player, _waterSource] call FUNC(drinkFromSource);
},
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
[_player, _waterSource] call FUNC(canDrinkFromSource);
}
] call ACEFUNC(interact_menu,createAction)
];

// Add water source actions to helper
Expand All @@ -79,11 +85,13 @@ if !(hasInterface) exitWith {};
-1 * count (_this getVariable [QACEGVAR(medical,ivBags), []]);
}] call FUNC(addStatusModifier);
};

if (["ace_weather"] call ACEFUNC(common,isModLoaded)) then {
[0, {
linearConversion [40, 60, missionNamespace getVariable [QACEGVAR(weather,currentTemperature), 25], 0, 1.5, true];
}] call FUNC(addStatusModifier);
};

if (["ace_dragging"] call ACEFUNC(common,isModLoaded)) then {
[2, {
if (_this getVariable [QACEGVAR(dragging,isDragging), false] || {_this getVariable [QACEGVAR(dragging,isCarrying), false]}) exitWith {
Expand Down
Binary file added addons/field_rations/anim/drink_source.rtm
Binary file not shown.
Binary file added addons/field_rations/anim/drink_source_high.rtm
Binary file not shown.
Binary file added addons/field_rations/anim/drink_source_low.rtm
Binary file not shown.
Binary file added addons/field_rations/anim/drink_source_squat.rtm
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 12 additions & 6 deletions addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@

params ["_interactionType"];

// Ignore self-interaction menu or mounted vehicle interaction
if (_interactionType != 0 || {vehicle ACE_player != ACE_player}) exitWith {};
// Ignore when self-interaction, mounted vehicle interaction, or water source actions are disabled
if (
_interactionType != 0
|| {vehicle ACE_player != ACE_player}
|| {GVAR(waterSourceActions) == 0}
) exitWith {};
TRACE_1("Starting interact PFH",_interactionType);

[{
Expand All @@ -39,15 +43,17 @@ TRACE_1("Starting interact PFH",_interactionType);
if (getPosASL ACE_player distanceSqr _setPosition > 25) then {
BEGIN_COUNTER(updatePosition);
{
if !(_x in _sourcesHelped) then {
if (!(_x in _sourcesHelped) && {GVAR(terrainObjectActions) || {!(_x call CBA_fnc_isTerrainObject)}} ) then {
private _waterRemaining = [_x] call FUNC(getRemainingWater);

if (_waterRemaining != REFILL_WATER_DISABLED) then {
_sourcesHelped pushBack _x;
private _helper = QGVAR(helper) createVehicleLocal [0, 0, 0];
_helper setVariable [QGVAR(waterSource), _x];
private _offset = [_x] call FUNC(getActionOffset);
private _helper = QGVAR(helper) createVehicleLocal [0, 0, 0];
_helper setPosASL AGLtoASL (_x modelToWorld _offset);
_helper setVariable [QGVAR(waterSource), _x];

_addedHelpers pushBack _helper;
_sourcesHelped pushBack _x;
TRACE_3("Added interaction helper",_x,typeOf _x,_waterRemaining);
};
};
Expand Down
24 changes: 24 additions & 0 deletions addons/field_rations/functions/fnc_canDrinkFromSource.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Checks if the player can drink directly from the given water source.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Water Source <OBJECT>
*
* Return Value:
* Can Drink From Source <BOOL>
*
* Example:
* [_player, _source] call acex_field_rations_canDrinkFromSource
*
* Public: No
*/

params ["_player", "_source"];

GVAR(waterSourceActions) == 2 && {
private _water = _source call FUNC(getRemainingWater);
_water == REFILL_WATER_INFINITE || {_source call FUNC(getRemainingWater) >= DRINK_FROM_SOURCE_AMOUNT}
}
11 changes: 7 additions & 4 deletions addons/field_rations/functions/fnc_canRefillItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@

params ["_source", "_player", "_item"];

if !(alive _source && {_item in (_player call ACEFUNC(common,uniqueItems))}) exitWith {false};

private _water = _source call FUNC(getRemainingWater);
_water == REFILL_WATER_INFINITE || {_water >= getNumber (configFile >> "CfgWeapons" >> _item >> QGVAR(refillAmount))}
alive _source
&& {GVAR(waterSourceActions) != 0}
&& {_item in (_player call ACEFUNC(common,uniqueItems))}
&& {
private _water = _source call FUNC(getRemainingWater);
_water == REFILL_WATER_INFINITE || {_water >= getNumber (configFile >> "CfgWeapons" >> _item >> QGVAR(refillAmount))}
}
2 changes: 1 addition & 1 deletion addons/field_rations/functions/fnc_consumeItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private _fnc_condition = {
_args set [7, true];
};

_consumeItem in (_player call ACEFUNC(common,uniqueItems));
_consumeItem in (_player call ACEFUNC(common,uniqueItems))
};

[
Expand Down
80 changes: 80 additions & 0 deletions addons/field_rations/functions/fnc_drinkFromSource.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Makes the player drink directly from the given water source.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Water Source <OBJECT>
*
* Return Value:
* None
*
* Example:
* [_player, _source] call acex_field_rations_drinkFromSource
*
* Public: No
*/

params ["_player", "_source"];

// Store current animation for resetting
_player setVariable [QGVAR(previousAnim), animationState _player];

private _animation = [_player, _source] call FUNC(getDrinkAnimation);
[_player, _animation, 1] call ACEFUNC(common,doAnimation);

private _fnc_onSuccess = {
params ["_args"];
_args params ["_player", "_source"];

// Reduce player thirst
private _thirst = _player getVariable [QGVAR(thirst), 0];
_player setVariable [QGVAR(thirst), (_thirst - DRINK_FROM_SOURCE_QUENCHED) max 0];
_player setVariable [QGVAR(previousAnim), nil];

// Update remaining water in source
private _waterInSource = _source call FUNC(getRemainingWater);

if (_waterInSource != REFILL_WATER_INFINITE) then {
[_source, (_waterInSource - DRINK_FROM_SOURCE_AMOUNT) max 0] call FUNC(setRemainingWater);
};
};

private _fnc_onFailure = {
params ["_args"];
_args params ["_player"];

// Reset animation if needed
if (vehicle _player == _player && {!(_player call ACEFUNC(common,isSwimming))}) then {
private _previousAnim = _player getVariable [QGVAR(previousAnim), ""];
if (_previousAnim != "") then {
[_player, _previousAnim, 2] call ACEFUNC(common,doAnimation);
};
};

_player setVariable [QGVAR(previousAnim), nil];
};

private _fnc_condition = {
params ["_args"];
_args params ["_player", "_source"];

[_player, _source] call FUNC(canDrinkFromSource)
};

private _sourceType = typeOf _source;
private _progressText = if (_sourceType == "") then {
localize LSTRING(DrinkingFromSource)
} else {
format [localize LSTRING(DrinkingFromX), getText (configFile >> "CfgVehicles" >> _sourceType >> "displayName")]
};

[
DRINK_FROM_SOURCE_TIME,
[_player, _source],
_fnc_onSuccess,
_fnc_onFailure,
_progressText,
_fnc_condition
] call ACEFUNC(common,progressBar);
35 changes: 35 additions & 0 deletions addons/field_rations/functions/fnc_getDrinkAnimation.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "script_component.hpp"
/*
* Author: mharis001
* Returns an appropriate animation for drinking directly from the given water source.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Water Source <OBJECT>
*
* Return Value:
* Animation <STRING>
*
* Example:
* [_player, _source] call acex_field_rations_getDrinkAnimation
*
* Public: No
*/

params ["_player", "_source"];

private _offset = _source call FUNC(getActionOffset);
private _actionPos = _source modelToWorld _offset;
private _playerPos = _player modelToWorld [0, 0, 0];

private _difference = (_actionPos vectorDiff _playerPos) select 2;

// Experimentally determined values to try to match height difference to different animations
switch (true) do {
case (_difference < 0.1): {QGVAR(drinkFromSourceSquatLow)};
case (_difference < 0.4): {QGVAR(drinkFromSourceSquat)};
case (_difference < 0.8): {QGVAR(drinkFromSourceSquatHigh)};
case (_difference < 1.2): {QGVAR(drinkFromSourceLow)};
case (_difference < 1.4): {QGVAR(drinkFromSource)};
default {QGVAR(drinkFromSourceHigh)};
};
18 changes: 18 additions & 0 deletions addons/field_rations/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@
true
] call CBA_settings_fnc_init;

[
QGVAR(waterSourceActions),
"LIST",
[LSTRING(WaterSourceActions_DisplayName), LSTRING(WaterSourceActions_Description)],
LSTRING(DisplayName),
[[0, 1, 2], [ACELSTRING(common,Disabled), LSTRING(RefillOnly), ACELSTRING(common,Enabled)], 2],
true
] call CBA_settings_fnc_init;

[
QGVAR(terrainObjectActions),
"CHECKBOX",
[LSTRING(TerrainObjectActions_DisplayName), LSTRING(TerrainObjectActions_Description)],
LSTRING(DisplayName),
true,
true
] call CBA_settings_fnc_init;

[
QGVAR(affectAdvancedFatigue),
"CHECKBOX",
Expand Down
3 changes: 3 additions & 0 deletions addons/field_rations/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#define REFILL_WATER_INFINITE -10
#define REFILL_WATER_DISABLED -1
#define CHECK_WATER_TIME 2
#define DRINK_FROM_SOURCE_AMOUNT 1
#define DRINK_FROM_SOURCE_QUENCHED 10
#define DRINK_FROM_SOURCE_TIME 10

#define IDC_COLORED_HUD_THIRST 6740
#define IDC_COLORED_HUD_HUNGER 6750
Expand Down
Loading