Skip to content

Commit

Permalink
Field Rations - Use hashmap for water sources (#10616)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnb432 authored Jan 4, 2025
1 parent e493eb3 commit 847e2ad
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
6 changes: 1 addition & 5 deletions addons/field_rations/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ PREP_RECOMPILE_END;
GVAR(thirstModifiers) = [];
GVAR(hungerModifiers) = [];

private _cache = call (uiNamespace getVariable [QGVAR(cacheP3Ds), {ERROR("no cache")}]); // cache built at preStart
// List of p3d water sources (case sensitive) for objects that report `typeOf == ""`
GVAR(waterSourceP3Ds) = _cache select 0;
// List of refill action offsets corresponding to the p3ds in the array above
GVAR(waterSourceOffsets) = _cache select 1;
GVAR(cacheP3Ds) = +(uiNamespace getVariable QGVAR(cacheP3Ds)); // cache built at preStart

// Custom Arsenal Tab
if (["ace_arsenal"] call EFUNC(common,isModLoaded)) then {
Expand Down
19 changes: 6 additions & 13 deletions addons/field_rations/XEH_preStart.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@

#include "XEH_PREP.hpp"

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

// List of refill action offsets corresponding to the p3ds in the array above
private _waterSourceOffsets = [
[0, 0, 0]
private _waterSourceData = createHashMapFromArray [
["misc_wellpump.p3d", [0, 0, 0]] // [11899, 9150, 0] on Chernarus
];

// Fill water source arrays from CfgVehicles
Expand All @@ -22,13 +16,12 @@ private _waterSourceOffsets = [
_string = _string + ".p3d"
};

private _index = _waterSourceP3Ds pushBackUnique _string;
if (_index != -1) then {
_waterSourceOffsets pushBack ([_x >> QXGVAR(offset), "ARRAY", [0, 0, 0]] call CBA_fnc_getConfigEntry);
if !(_string in _waterSourceData) then {
_waterSourceData set [_string, [_x >> QXGVAR(offset), "ARRAY", [0, 0, 0]] call CBA_fnc_getConfigEntry];
};
} forEach (QUOTE(isNumber (_x >> 'XGVAR(waterSupply)') && {(getNumber (_x >> 'XGVAR(waterSupply)')) != REFILL_WATER_DISABLED}) configClasses (configFile >> "CfgVehicles"));

uiNamespace setVariable [QGVAR(cacheP3Ds), compileFinal str [_waterSourceP3Ds, _waterSourceOffsets]];
TRACE_1("compiled",count _waterSourceP3Ds);
uiNamespace setVariable [QGVAR(cacheP3Ds), compileFinal _waterSourceData];
TRACE_1("compiled",count _waterSourceData);

call FUNC(scanFieldRations);
2 changes: 1 addition & 1 deletion addons/field_rations/functions/fnc_getActionOffset.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ params ["_object"];
private _configOf = configOf _object;
if (isNull _configOf) then {
// Check for offset corresponding to p3d list
GVAR(waterSourceOffsets) param [GVAR(waterSourceP3ds) find (getModelInfo _object select 0), [0, 0, 0], [[]]];
GVAR(cacheP3Ds) getOrDefault [getModelInfo _object select 0, [0, 0, 0]]
} else {
// Check for offset in config since we have valid typeOf
private _offset = getArray (_configOf >> QXGVAR(offset));
Expand Down
2 changes: 1 addition & 1 deletion addons/field_rations/functions/fnc_getRemainingWater.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (isNil "_water") then {
private _configOf = configOf _source;
if (isNull _configOf) then {
// Check the p3d name against list
_water = if ((getModelInfo _source select 0) in GVAR(waterSourceP3ds)) then {REFILL_WATER_INFINITE} else {REFILL_WATER_DISABLED};
_water = [REFILL_WATER_DISABLED, REFILL_WATER_INFINITE] select ((getModelInfo _source select 0) in GVAR(cacheP3Ds));
} else {
// Check for waterSupply entry since we have valid typeOf
_water = getNumber (_configOf >> QXGVAR(waterSupply));
Expand Down

0 comments on commit 847e2ad

Please sign in to comment.