From cac223c6ec5d2394d9fddd84c9ad749b8a322997 Mon Sep 17 00:00:00 2001 From: PabstMirror Date: Thu, 9 Feb 2023 13:16:42 -0600 Subject: [PATCH] Common - Use hashmap variable for canDig surfaces (#9147) * Common - Use hashmap variable for canDig surfaces * Update XEH_preInit.sqf * Update fnc_canDig.sqf * Update fnc_canDig.sqf --- addons/common/XEH_preInit.sqf | 10 ++++++++++ addons/common/functions/fnc_canDig.sqf | 20 +++++++++++--------- addons/common/script_component.hpp | 15 --------------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/addons/common/XEH_preInit.sqf b/addons/common/XEH_preInit.sqf index fb42193cef..8daee5c64c 100644 --- a/addons/common/XEH_preInit.sqf +++ b/addons/common/XEH_preInit.sqf @@ -59,6 +59,16 @@ GVAR(hexArray) = [ "F0","F1","F2","F3","F4","F5","F6","F7","F8","F9","FA","FB","FC","FD","FE","FF" ]; +GVAR(canDigSurfaces) = createHashMapFromArray [ + ["int_concrete",false],["int_pavement_exp",false],["int_solidwood_exp",false],["tiling",false],["roof_tiles",false],["stony",false], + ["wavymetal",false],["int_wood",false],["int_tiles",false],["softwood_exp",false],["int_concrete_exp",false],["tiles_int",false], + ["metalplate_exp",false],["int_metalplate_exp",false],["steel_exp",false],["metal",false],["int_lino_exp",false],["metal_int",false], + ["wavymetal_exp",false],["int_metal",false],["asphalt_exp",false],["pavement_exp",false],["gridmetal_exp",false], + ["rooftiles_exp",false],["rock",false],["int_mat_exp",false],["wood_int",false],["concrete_int",false],["tarmac",false],["wood",false], + ["roof_tin",false],["lino_exp",false],["concrete",false],["int_softwood_exp",false], ["concrete_exp",false],["stones_exp",false], + ["forest_exp",true],["snow",true],["grasstall_exp",true],["grass",true] +]; + isHC = !hasInterface && !isDedicated; // deprecated because no tag missionNamespace setVariable ["ACE_isHC", ACE_isHC]; uiNamespace setVariable ["ACE_isHC", ACE_isHC]; diff --git a/addons/common/functions/fnc_canDig.sqf b/addons/common/functions/fnc_canDig.sqf index a75f32b5d4..14e7a0b843 100644 --- a/addons/common/functions/fnc_canDig.sqf +++ b/addons/common/functions/fnc_canDig.sqf @@ -4,34 +4,36 @@ * Checks if the player can dig on the surface below (enough dust). * * Arguments: - * 0: Unit + * 0: Unit or Position (2d/3d) * * Return Value: * Can Dig * * Example: * [ACE_player] call ace_common_fnc_canDig + * [[1000,2000]] call ace_common_fnc_canDig * * Public: No */ -params ["_unit"]; +params ["_input"]; -private _posASL = getPosASL _unit; +private _posASL = _input; -if ((getPosATL _unit) select 2 > 0.05 || // Walking on objects, such as buildings, pavements, etc. +if ((_input isEqualType objNull) && { + _posASL = getPosASL _input; + (getPosATL _unit) select 2 > 0.05 || // Walking on objects, such as buildings, pavements, etc. {surfaceIsWater _posASL} // posATL in low water (not as low to allow awalking) is negative -) exitWith {false}; +}) exitWith {false}; private _surfaceClass = (surfaceType _posASL) select [1]; private _config = configFile >> "CfgSurfaces" >> _surfaceClass; -private _surfaceType = getText (_config >> "soundEnviron"); -private _surfaceDust = getNumber (_config >> "dust"); -TRACE_2("Surface",_surfaceType,_surfaceDust); +TRACE_3("",_surfaceClass,getText (_config >> "soundEnviron"),getNumber (_config >> "dust")); if (isNumber (_config >> "ACE_canDig")) then { (getNumber (_config >> "ACE_canDig")) == 1 // return } else { - !(_surfaceType in DIG_SURFACE_BLACKLIST) && {(_surfaceDust >= 0.1) || {_surfaceType in DIG_SURFACE_WHITELIST}} // return + private _surfaceType = getText (_config >> "soundEnviron"); + GVAR(canDigSurfaces) getOrDefault [_surfaceType, getNumber (_config >> "dust") >= 0.1, true] // return }; diff --git a/addons/common/script_component.hpp b/addons/common/script_component.hpp index b3312e8a18..379d32399c 100644 --- a/addons/common/script_component.hpp +++ b/addons/common/script_component.hpp @@ -15,18 +15,3 @@ #endif #include "\z\ace\addons\main\script_macros.hpp" - - -#define DIG_SURFACE_BLACKLIST [ \ - "concrete", "concrete_exp", "concrete_int", "int_concrete", "int_concrete_exp", \ - "pavement_exp", "int_pavement_exp", \ - "tiling", "tiles_int", "int_tiles", \ - "roof_tin", "roof_tiles", "rooftiles_exp", \ - "tarmac", "asphalt_exp", \ - "stones_exp", "rock", "stony", \ - "metal", "gridmetal_exp", "metalplate_exp", "int_metalplate_exp", "metal_int", "wavymetal", "wavymetal_exp", "int_metal", "steel_exp", \ - "lino_exp", "int_lino_exp", "int_mat_exp", \ - "wood", "wood_int", "int_wood", "softwood_exp", "int_softwood_exp", "int_solidwood_exp" \ -] - -#define DIG_SURFACE_WHITELIST ["grass", "grasstall_exp", "forest_exp", "snow"]