From ef926c17cebeb5b4d7192e3669f1a5a7c1563a4a Mon Sep 17 00:00:00 2001 From: jokoho482 Date: Tue, 14 May 2024 22:23:46 +0200 Subject: [PATCH 1/3] Simplifications and correct usage of aiAmmoUsageFlags in fnc_getLauncherUnits.sqf Add AI_AMMO_USAGE_FLAG_X --- addons/danger/functions/fnc_tacticsAssess.sqf | 2 +- addons/danger/functions/fnc_tacticsHide.sqf | 4 +-- .../main/functions/UnitAction/fnc_doSmoke.sqf | 2 +- .../main/functions/fnc_getLauncherUnits.sqf | 27 +++++-------------- addons/main/script_macros.hpp | 12 +++++++++ addons/wp/functions/fnc_taskRush.sqf | 2 +- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/addons/danger/functions/fnc_tacticsAssess.sqf b/addons/danger/functions/fnc_tacticsAssess.sqf index 39ee143b..1116fb62 100644 --- a/addons/danger/functions/fnc_tacticsAssess.sqf +++ b/addons/danger/functions/fnc_tacticsAssess.sqf @@ -86,7 +86,7 @@ if !(_enemies isEqualTo [] || {_unitCount < random 4}) then { }; // soft vehicle response - private _hasAT = ([_group, false, true, false, true] call EFUNC(main,getLauncherUnits)) isNotEqualTo []; + private _hasAT = ([_group, AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_ARMOUR] call EFUNC(main,getLauncherUnits)) isNotEqualTo []; private _vehicleTarget = _enemies findIf { _hasAT && {_unit distance2D _x < RANGE_NEAR} diff --git a/addons/danger/functions/fnc_tacticsHide.sqf b/addons/danger/functions/fnc_tacticsHide.sqf index 8eaaa907..1c4c53da 100644 --- a/addons/danger/functions/fnc_tacticsHide.sqf +++ b/addons/danger/functions/fnc_tacticsHide.sqf @@ -101,8 +101,8 @@ _units doWatch objNull; [_units, _target, _cover] call EFUNC(main,doGroupHide); // find launcher units -private _launchersAT = [_group, false, true, false, true] call EFUNC(main,getLauncherUnits); -private _launchersAA = [_group, false, false, true, false] call EFUNC(main,getLauncherUnits); +private _launchersAA = [_group, AI_AMMO_USAGE_FLAG_AIR, true] call EFUNC(main,getLauncherUnits); +private _launchersAT = [_group, AI_AMMO_USAGE_FLAG_ARMOUR] call EFUNC(main,getLauncherUnits); // find enemy vehicles private _enemies = _unit targets [true, 600, [], 0, _target]; diff --git a/addons/main/functions/UnitAction/fnc_doSmoke.sqf b/addons/main/functions/UnitAction/fnc_doSmoke.sqf index a9567a71..85078c83 100644 --- a/addons/main/functions/UnitAction/fnc_doSmoke.sqf +++ b/addons/main/functions/UnitAction/fnc_doSmoke.sqf @@ -20,7 +20,7 @@ params [ ["_unit", objNull, [grpNull, objNull, []]], ["_pos", [], [[]]], - ["_type", 4, [0]] + ["_type", AI_AMMO_USAGE_FLAG_CONCEALMENT, [0]] ]; // single unit diff --git a/addons/main/functions/fnc_getLauncherUnits.sqf b/addons/main/functions/fnc_getLauncherUnits.sqf index 88128c74..9705e315 100644 --- a/addons/main/functions/fnc_getLauncherUnits.sqf +++ b/addons/main/functions/fnc_getLauncherUnits.sqf @@ -13,7 +13,8 @@ * * Arguments: * 0: Group to search in - * 1: Check through submunitions + * 1: Flags to check Against + * 2: Check through submunitions * * Return Value: * Array - units with launchers @@ -24,23 +25,12 @@ * Public: Yes */ -#define LIGHT_VEHICLE 128 -#define AIR_VEHICLE 256 -#define HEAVY_VEHICLE 512 - params [ ["_group", grpNull, [grpNull]], - ["_checkSubmunition", false, [false]], - ["_offensiveVeh", true, [true]], - ["_offensiveAir", true, [true]], - ["_offensiveArmor", true, [true]] + ["_flags", 896, [0]], // 896 == AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR + ["_checkSubmunition", false, [false]] ]; -private _flags = 0; -if (_offensiveVeh) then {_flags = _flags + LIGHT_VEHICLE}; -if (_offensiveArmor) then {_flags = _flags + HEAVY_VEHICLE}; -if (_offensiveAir) then {_flags = _flags + AIR_VEHICLE}; - private _suitableUnits = []; { if ((secondaryWeapon _x) isEqualTo "") then {continue}; @@ -55,17 +45,12 @@ private _suitableUnits = []; // Optionally go through submunitions. More info in header. if !(_checkSubmunition) then {continue}; // Invert & continue to reduce indentation - // Can't use checkMagazineAiUsageFlags for submunitions private _mainAmmo = getText (configFile >> "cfgMagazines" >> _x >> "ammo"); private _submunition = getText (configFile >> "cfgAmmo" >> _mainAmmo >> "submunitionAmmo"); if (_submunition isEqualTo "") then {continue}; - private _submunitionFlags = getText (configFile >> "cfgAmmo" >> _submunition >> "aiAmmoUsageFlags"); + private _submunitionFlags = getNumber(configFile >> "cfgAmmo" >> _submunition >> "aiAmmoUsageFlags"); - if ( - (_offensiveVeh && (QUOTE(LIGHT_VEHICLE) in _submunitionFlags)) - || {_offensiveAir && (QUOTE(AIR_VEHICLE) in _submunitionFlags)} - || {_offensiveArmor && (QUOTE(HEAVY_VEHICLE) in _submunitionFlags)} - ) exitWith {_suitableUnits pushBackUnique _currentUnit}; + if ([_submunitionFlags, _flags] call BIS_fnc_bitflagsCheck) exitWith {_suitableUnits pushBackUnique _currentUnit}; } forEachReversed _unitsMagazines; // We iterate back to front for performance, because _unitsMagazines is structured - // as follows: uniform magazines -> vest magazines -> backpack magazines, and - diff --git a/addons/main/script_macros.hpp b/addons/main/script_macros.hpp index ea33845c..305ad6ef 100644 --- a/addons/main/script_macros.hpp +++ b/addons/main/script_macros.hpp @@ -1,7 +1,19 @@ #include "\x\cba\addons\main\script_macros_common.hpp" + #define DFUNC(var1) TRIPLES(ADDON,fnc,var1) #define RND(var) random 1 > var +#define AI_AMMO_USAGE_FLAG_LIGHT 1 +#define AI_AMMO_USAGE_FLAG_MARKING 2 +#define AI_AMMO_USAGE_FLAG_CONCEALMENT 4 +#define AI_AMMO_USAGE_FLAG_COUNTERMEASURES 8 +#define AI_AMMO_USAGE_FLAG_MINE 16 +#define AI_AMMO_USAGE_FLAG_UNDERWATER 32 +#define AI_AMMO_USAGE_FLAG_INFATRY 64 +#define AI_AMMO_USAGE_FLAG_VEHICLE 128 +#define AI_AMMO_USAGE_FLAG_AIR 256 +#define AI_AMMO_USAGE_FLAG_ARMOUR 512 + #define GET_CURATOR_GRP_UNDER_CURSOR call { \ private _group = grpNull; \ private _mouseOver = missionNamespace getVariable ["BIS_fnc_curatorObjectPlaced_mouseOver", [""]]; \ diff --git a/addons/wp/functions/fnc_taskRush.sqf b/addons/wp/functions/fnc_taskRush.sqf index 59051d9f..50f48ebb 100644 --- a/addons/wp/functions/fnc_taskRush.sqf +++ b/addons/wp/functions/fnc_taskRush.sqf @@ -48,7 +48,7 @@ private _fnc_rushOrders = { }; // Tank -- hide or ready AT - private _launcherUnits = [_group, false] call EFUNC(main,getLauncherUnits); + private _launcherUnits = [_group] call EFUNC(main,getLauncherUnits); if ((_distance < 80) && {(vehicle _target) isKindOf "Tank"}) exitWith { { if (_x in _launcherUnits) then { From 93640d72d96b4624e15ae64d45c12411db6b3dc0 Mon Sep 17 00:00:00 2001 From: jokoho482 Date: Wed, 15 May 2024 22:15:53 +0200 Subject: [PATCH 2/3] Fix TacticsHide use full group and not prefiltered Group Add Units Array support for getLauncherUnits --- addons/danger/functions/fnc_tacticsHide.sqf | 4 ++-- addons/main/functions/fnc_getLauncherUnits.sqf | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/danger/functions/fnc_tacticsHide.sqf b/addons/danger/functions/fnc_tacticsHide.sqf index 1c4c53da..9ce31eb0 100644 --- a/addons/danger/functions/fnc_tacticsHide.sqf +++ b/addons/danger/functions/fnc_tacticsHide.sqf @@ -101,8 +101,8 @@ _units doWatch objNull; [_units, _target, _cover] call EFUNC(main,doGroupHide); // find launcher units -private _launchersAA = [_group, AI_AMMO_USAGE_FLAG_AIR, true] call EFUNC(main,getLauncherUnits); -private _launchersAT = [_group, AI_AMMO_USAGE_FLAG_ARMOUR] call EFUNC(main,getLauncherUnits); +private _launchersAA = [_units, AI_AMMO_USAGE_FLAG_AIR, true] call EFUNC(main,getLauncherUnits); +private _launchersAT = [_units, AI_AMMO_USAGE_FLAG_ARMOUR] call EFUNC(main,getLauncherUnits); // find enemy vehicles private _enemies = _unit targets [true, 600, [], 0, _target]; diff --git a/addons/main/functions/fnc_getLauncherUnits.sqf b/addons/main/functions/fnc_getLauncherUnits.sqf index 9705e315..00d954c6 100644 --- a/addons/main/functions/fnc_getLauncherUnits.sqf +++ b/addons/main/functions/fnc_getLauncherUnits.sqf @@ -12,7 +12,7 @@ * Disposable launchers get mostly ignored, AI doesn't seem to even use them. * * Arguments: - * 0: Group to search in + * 0: Group to search in > * 1: Flags to check Against * 2: Check through submunitions * @@ -26,11 +26,14 @@ */ params [ - ["_group", grpNull, [grpNull]], + ["_group", [], [grpNull, []]], ["_flags", 896, [0]], // 896 == AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR ["_checkSubmunition", false, [false]] ]; +if (_group isEqualType grpNull) then { + _group = units _group; +}; private _suitableUnits = []; { if ((secondaryWeapon _x) isEqualTo "") then {continue}; @@ -55,6 +58,6 @@ private _suitableUnits = []; // We iterate back to front for performance, because _unitsMagazines is structured - // as follows: uniform magazines -> vest magazines -> backpack magazines, and - // launcher ammo is usually in the backpack. This is a ~3-4x speedup. -} forEach (units _group); +} forEach _group; _suitableUnits From d57a8674776385250fe8591012c4c1063bd74daf Mon Sep 17 00:00:00 2001 From: jokoho482 Date: Sun, 7 Jul 2024 15:29:04 +0200 Subject: [PATCH 3/3] remove precalculated value and use macros for getLauncherUnits --- addons/main/functions/fnc_getLauncherUnits.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/main/functions/fnc_getLauncherUnits.sqf b/addons/main/functions/fnc_getLauncherUnits.sqf index 00d954c6..d3265bde 100644 --- a/addons/main/functions/fnc_getLauncherUnits.sqf +++ b/addons/main/functions/fnc_getLauncherUnits.sqf @@ -27,7 +27,7 @@ params [ ["_group", [], [grpNull, []]], - ["_flags", 896, [0]], // 896 == AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR + ["_flags", AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR, [0]], ["_checkSubmunition", false, [false]] ];