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

Commit

Permalink
Add water actions to map objects
Browse files Browse the repository at this point in the history
  • Loading branch information
PabstMirror committed Nov 4, 2018
1 parent 9500715 commit 5c769a1
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 84 deletions.
39 changes: 7 additions & 32 deletions addons/field_rations/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class CfgVehicles {
};
};

class ACE_LogicDummy;
class GVAR(helper): ACE_LogicDummy {};

class Items_base_F;
class Land_WaterBarrel_F: Items_base_F {
GVAR(waterSupply) = 200;
Expand All @@ -36,39 +39,18 @@ class CfgVehicles {

class Infrastructure_base_F;
class Land_WaterTank_01_F: Infrastructure_base_F {
class ACE_Actions {
class ACE_MainActions {
displayName = ACECSTRING(interaction,MainAction);
condition = "true";
position = "[0, -1.42, -0.78]";
distance = 2;
};
};
// position = "[0, -1.42, -0.78]";
GVAR(waterSupply) = 2400;
};
class Land_WaterTank_02_F: Infrastructure_base_F {
class ACE_Actions {
class ACE_MainActions {
displayName = ACECSTRING(interaction,MainAction);
condition = "true";
position = "[-0.09, -1.45, 0.53]";
distance = 2;
};
};
// position = "[-0.09, -1.45, 0.53]";
GVAR(waterSupply) = 2400;
};
class Land_WaterTank_03_F: Infrastructure_base_F {
GVAR(waterSupply) = 200;
};
class Land_WaterTank_04_F: Infrastructure_base_F {
class ACE_Actions {
class ACE_MainActions {
displayName = ACECSTRING(interaction,MainAction);
condition = "true";
position = "[-0.155, -0.72, 0.37]";
distance = 2;
};
};
// position = "[-0.155, -0.72, 0.37]";
GVAR(waterSupply) = 200;
};

Expand All @@ -79,14 +61,7 @@ class CfgVehicles {

class StorageBladder_base_F;
class Land_StorageBladder_02_F: StorageBladder_base_F {
class ACE_Actions {
class ACE_MainActions {
displayName = ACECSTRING(interaction,MainAction);
condition = "true";
position = "[-2.02, 1.47, -0.02]";
distance = 2;
};
};
// position = "[-2.02, 1.47, -0.02]";
};
class StorageBladder_02_water_forest_F: Land_StorageBladder_02_F {
GVAR(waterSupply) = 10000;
Expand Down
4 changes: 2 additions & 2 deletions addons/field_rations/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CfgWeapons {
};
GVAR(replacementItem) = "ACE_WaterBottle_empty";
GVAR(refillItem) = "ACE_WaterBottle";
GVAR(refillAmount) = 1;
GVAR(refillAmount) = 0.5;
};

class ACE_WaterBottle_empty: ACE_WaterBottle {
Expand Down Expand Up @@ -77,7 +77,7 @@ class CfgWeapons {
GVAR(consumeText) = CSTRING(DrinkFromCanteenHalf);
GVAR(replacementItem) = "ACE_Canteen_empty";
GVAR(refillItem) = "ACE_Canteen";
GVAR(refillAmount) = 1;
GVAR(refillAmount) = 0.5;
};

class ACE_Canteen_empty: ACE_Canteen {
Expand Down
1 change: 1 addition & 0 deletions addons/field_rations/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
PREP(addStatusModifier);
PREP(addWaterSourceInteractions);
PREP(canConsumeItem);
PREP(canRefillItem);
PREP(checkWater);
Expand Down
59 changes: 38 additions & 21 deletions addons/field_rations/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,52 +15,69 @@ if !(hasInterface) exitWith {};
};

// Compile water source actions
GVAR(mainAction) = [
private _mainAction = [
QGVAR(waterSource),
localize LSTRING(WaterSource),
QPATHTOF(ui\icon_water_tap.paa),
{true},
{
alive _target
&& {_target call FUNC(getRemainingWater) != REFILL_WATER_DISABLED}
&& {[_player, _target] call ACEFUNC(common,canInteractWith)}
}
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
alive _waterSource
&& {_waterSource call FUNC(getRemainingWater) != REFILL_WATER_DISABLED}
&& {[_player, _waterSource] call ACEFUNC(common,canInteractWith)}
},
{ // Add refil actions as sub actions to main node?
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
[_waterSource, _player] call FUNC(getRefillChildren);},
[],
{[0, 0, 0]},
5.5,
[false, false, false, false, true]
] call ACEFUNC(interact_menu,createAction);

GVAR(subActions) = [
private _subActions = [
[
QGVAR(checkWater),
localize LSTRING(CheckWater),
QPATHTOF(ui\icon_water_tap.paa),
{[_player, _target] call FUNC(checkWater)},
{_target call FUNC(getRemainingWater) != REFILL_WATER_INFINITE}
] call ACEFUNC(interact_menu,createAction),
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
[_player, _waterSource] call FUNC(checkWater);},
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
(_waterSource call FUNC(getRemainingWater)) != REFILL_WATER_INFINITE
}
] call ACEFUNC(interact_menu,createAction)
/*
[
QGVAR(drinkDirectly),
localize LSTRING(DrinkDirectly),
QPATHTOF(ui\icon_water_tap.paa),
{},
{}
{systemChat "x"},
{true}
] call ACEFUNC(interact_menu,createAction),
[
QGVAR(refill),
localize LSTRING(Refill),
QPATHTOF(ui\icon_water_tap.paa),
{},
{true},
LINKFUNC(getRefillChildren)
{
private _waterSource = _target getVariable [QGVAR(waterSource), objNull];
[_waterSource, _player] call FUNC(getRefillChildren);
}
] call ACEFUNC(interact_menu,createAction)
*/
];

// Add refill water actions to water sources from compiled list
// Add refill water actions
[QGVAR(helper), 0, [], _mainAction] call ACEFUNC(interact_menu,addActionToClass);
{
private _classname = _x;
[_classname, 0, ["ACE_MainActions"], GVAR(mainAction)] call ACEFUNC(interact_menu,addActionToClass);
{
[_classname, 0, ["ACE_MainActions", QGVAR(waterSource)], _x] call ACEFUNC(interact_menu,addActionToClass);
} forEach GVAR(subActions);
LOG_1("Added water source actions to %1 from config",_classname);
} forEach GETUVAR(GVAR(waterSources),[]);
[QGVAR(helper), 0, [QGVAR(waterSource)], _x] call ACEFUNC(interact_menu,addActionToClass);
} forEach _subActions;

// Add water source helpers when interaction menu is opened
["ace_interactMenuOpened", {call FUNC(addWaterSourceInteractions)}] call CBA_fnc_addEventHandler;


// Add status modifiers
if (["ace_medical"] call ACEFUNC(common,isModLoaded)) then {
Expand Down
5 changes: 5 additions & 0 deletions addons/field_rations/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@ PREP_RECOMPILE_END;
GVAR(thirstModifiers) = [];
GVAR(hungerModifiers) = [];

// List of p3d water sources (case sensitive) for objects that report `typeOf == ""`
GVAR(waterSourceP3ds) = [
"misc_wellpump.p3d" // (11899,9150,0] on chenarus
];

ADDON = true;
5 changes: 0 additions & 5 deletions addons/field_rations/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"

// Compile list of water sources from config
private _filter = QUOTE(getNumber (_x >> 'scope') == 2 && {getNumber (_x >> QQGVAR(waterSupply)) > 0 || {getNumber (_x >> QQGVAR(waterSupply)) == REFILL_WATER_INFINITE}});
private _waterSources = (_filter configClasses (configFile >> "CfgVehicles")) apply {configName _x};
SETUVAR(GVAR(waterSources),_waterSources);
63 changes: 63 additions & 0 deletions addons/field_rations/functions/fnc_addWaterSourceInteractions.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Author: PabstMirror, mharis001
* Dynamically adds water actions to nearby water objects when interact_menu is opened.
* Called by the "ace_interactMenuOpened" event.
*
* Arguments:
* Interact Menu Type (0 - World, 1 - Self) <NUMBER>
*
* Return Value:
* None
*
* Example:
* [0] call acex_field_rations_fnc_addWaterSourceInteractions
*
* Public: No
*/
#include "script_component.hpp"

params ["_interactionType"];
TRACE_1("addWaterSourceInteractions",_interactionType);

// Ignore self-interaction menu or mounted vehicle interaction
if (_interactionType != 0 || {vehicle ACE_player != ACE_player}) exitWith {};
TRACE_1("Starting interact PFH",_interactionType);

[{
BEGIN_COUNTER(interactEH);
params ["_args", "_pfhID"];
_args params ["_setPosition", "_addedHelpers", "_fencesHelped"];

if (!ACEGVAR(interact_menu,keyDown)) then {
TRACE_1("Ending interact PFH",_pfhID);
{deleteVehicle _x} forEach _addedHelpers;
[_pfhID] call CBA_fnc_removePerFrameHandler;
} else {
// Prevent rare error when ending mission with interact key down
if (isNull ACE_player) exitWith {};

// Rescan if player has moved more than 5 meters from last position
if (getPosASL ACE_player distanceSqr _setPosition > 25) then {
BEGIN_COUNTER(updatePosition);
{
if (!(_x in _fencesHelped)) then {
private _waterRemaining = [_x] call FUNC(getRemainingWater);
if ((_waterRemaining == REFILL_WATER_INFINITE) || {_waterRemaining > 0}) then {
_fencesHelped pushBack _x;
private _helper = QGVAR(helper) createVehicleLocal [0, 0, 0];
_helper setVariable [QGVAR(waterSource), _x];
// private _offset = getArray (configFile >> "CfgVehicles" >> (typeOf _x) >> QGVAR(offset));
// if (_offset isEqualTo []) then {_offset = [0,0,0]};
_helper setPosASL AGLtoASL (_x modelToWorld [0,0,0]);
_addedHelpers pushBack _helper;
TRACE_3("added interaction helper",_x,typeOf _x,_waterRemaining);
};
};
} forEach nearestObjects [ACE_player, [], 15];

_args set [0, getPosASL ACE_player];
END_COUNTER(updatePosition);
};
};
END_COUNTER(interactEH);
}, 0.5, [getPosASL ACE_player vectorAdd [-100, 0, 0], [], []]] call CBA_fnc_addPerFrameHandler;
8 changes: 4 additions & 4 deletions addons/field_rations/functions/fnc_consumeItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private _onFinish = {

// Add relevant thirst/hunger values
if (_thirstRestored > 0) then {
private _thirstStatus = _player getVariable [QGVAR(thirst), 100];
_player setVariable [QGVAR(thirst), (_thirstStatus + _thirstRestored) min 100];
private _thirstStatus = _player getVariable [QGVAR(thirst), 0];
_player setVariable [QGVAR(thirst), (_thirstStatus - _thirstRestored) max 0];
};
if (_hungerRestored > 0) then {
private _hungerStatus = _player getVariable [QGVAR(hunger), 100];
_player setVariable [QGVAR(hunger), (_hungerStatus + _hungerRestored) min 100];
private _hungerStatus = _player getVariable [QGVAR(hunger), 0];
_player setVariable [QGVAR(hunger), (_hungerStatus - _hungerRestored) max 0];
};
};

Expand Down
2 changes: 1 addition & 1 deletion addons/field_rations/functions/fnc_getRefillChildren.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private _actions = [];
{
private _config = configFile >> "CfgWeapons" >> _x;
if (getText (_config >> QGVAR(refillItem)) != "" && {_water == REFILL_WATER_INFINITE || {getNumber (_config >> QGVAR(refillAmount)) <= _water}}) then {
private _displayName = getText (_config >> "displayName");
private _displayName = format ["%1: %2", localize LSTRING(Refill), getText (_config >> "displayName")];
private _picture = getText (_config >> "picture");
private _action = [_x, _displayName, _picture, FUNC(refillItem), FUNC(canRefillItem), {}, _x] call ACEFUNC(interact_menu,createAction);
_actions pushBack [_action, [], _source];
Expand Down
17 changes: 14 additions & 3 deletions addons/field_rations/functions/fnc_getRemainingWater.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,24 @@

params [["_source", objNull, [objNull]]];

if (isNull _source) exitWith {0};
if (!alive _source) exitWith {0};

private _water = _source getVariable QGVAR(currentWaterSupply);

if (isNil "_water") then {
_water = getNumber (configFile >> "CfgVehicles" >> typeOf _source >> QGVAR(waterSupply));
_source setVariable [QGVAR(currentWaterSupply), _water, true];
private _typeOf = typeOf _source;
if (_typeOf != "") then { // Have type, check config
_water = getNumber (configFile >> "CfgVehicles" >> _typeOf >> QGVAR(waterSupply));
if ((_water != 0) && {_water != REFILL_WATER_DISABLED}) then {
if ([_source] call CBA_fnc_isTerrainObject) then {
_water = REFILL_WATER_INFINITE;
} else {
_source setVariable [QGVAR(currentWaterSupply), _water, true];
};
};
} else { // Check the p3d name against list
_water = if (((getModelInfo _source) select 0) in GVAR(waterSourceP3ds)) then { REFILL_WATER_INFINITE } else { 0 };
};
};

_water
2 changes: 1 addition & 1 deletion addons/field_rations/functions/fnc_handleHUD.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ private _display = GETUVAR(GVAR(hudDisplay),displayNull);
// Create HUD if display is null
if (isNull _display) then {
private _rscType = [QGVAR(hudColoredIcons), QGVAR(hudDrainingIcons)] select GVAR(hudType);
HUD_LAYER cutRsc [_rscType, "PLAIN", -1, false];
QGVAR(hud) cutRsc [_rscType, "PLAIN", -1, false];
_display = GETUVAR(GVAR(hudDisplay),displayNull);
};

Expand Down
10 changes: 2 additions & 8 deletions addons/field_rations/functions/fnc_handleRespawn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,5 @@ TRACE_2("Handle Respawn",_unit,_corpse);

if !(local _unit) exitWith {};

_unit setVariable [QGVAR(thirst), 100];
_unit setVariable [QGVAR(hunger), 100];

// Reset the HUD and variables if the respawning unit is the local player
if ([_unit] call ACEFUNC(common,isPlayer)) then {
GVAR(hudInteractionHover) = false;
[0] call FUNC(showHud);
};
_unit setVariable [QGVAR(thirst), 0];
_unit setVariable [QGVAR(hunger), 0];
6 changes: 3 additions & 3 deletions addons/field_rations/functions/fnc_update.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private _player = ACE_player;
// Handle unit not alive or null
if (!alive _player) exitWith {
[FUNC(update), _nextMpSync, 1] call CBA_fnc_waitAndExecute;
HUD_LAYER cutFadeOut 0.5;
QGVAR(hud) cutFadeOut 0.5;
};

// Get current thirst and hunger
Expand Down Expand Up @@ -63,13 +63,13 @@ _player setVariable [QGVAR(thirst), _thirst, _doSync];
_player setVariable [QGVAR(hunger), _hunger, _doSync];

// Handle any effects/consequences of high thirst or hunger
// [_player, _thirst, _hunger] call FUNC(handleEffects);
[_player, _thirst, _hunger] call FUNC(handleEffects);

// Handle showing/updating or hiding of HUD
if (_thirst > GVAR(hudShowLevel) || {_hunger > GVAR(hudShowLevel)} || {GVAR(hudInteractionHover)}) then {
[_thirst, _hunger] call FUNC(handleHUD);
} else {
HUD_LAYER cutFadeOut 0.5;
QGVAR(hud) cutFadeOut 0.5;
};

[FUNC(update), _nextMpSync, 1] call CBA_fnc_waitAndExecute;
4 changes: 3 additions & 1 deletion addons/field_rations/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
[ACELSTRING(common,Enabled), LSTRING(Enabled_Description)],
LSTRING(DisplayName),
false,
true
true,
{},
true // needRestart
] call CBA_settings_fnc_init;

[
Expand Down
4 changes: 1 addition & 3 deletions addons/field_rations/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@

#include "\a3\ui_f\hpp\defineCommonGrids.inc"

#define MP_SYNC_INTERVAL 60
#define MP_SYNC_INTERVAL 60 + random 60

#define REFILL_WATER_INFINITE -10
#define REFILL_WATER_DISABLED -1
#define DEFAULT_REFILL_TIME 5
#define CHECK_WATER_TIME 1

#define HUD_LAYER (QGVAR(hud) call BIS_fnc_rscLayer)

#define IDC_COLORED_HUD_THIRST 6740
#define IDC_COLORED_HUD_HUNGER 6750
#define IDC_DRAINING_HUD_THIRST_GROUP 7740
Expand Down

0 comments on commit 5c769a1

Please sign in to comment.