Skip to content

Commit

Permalink
Improve GetLauncherUnits (#395)
Browse files Browse the repository at this point in the history
* Simplifications and correct usage of aiAmmoUsageFlags in fnc_getLauncherUnits.sqf

Add AI_AMMO_USAGE_FLAG_X

* Fix TacticsHide use full group and not prefiltered Group

Add Units Array support for getLauncherUnits

* remove precalculated value and use macros for getLauncherUnits
  • Loading branch information
jokoho48 authored Jul 7, 2024
1 parent 75d2671 commit 080a61d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion addons/danger/functions/fnc_tacticsAssess.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions addons/danger/functions/fnc_tacticsHide.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [_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];
Expand Down
2 changes: 1 addition & 1 deletion addons/main/functions/UnitAction/fnc_doSmoke.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
params [
["_unit", objNull, [grpNull, objNull, []]],
["_pos", [], [[]]],
["_type", 4, [0]]
["_type", AI_AMMO_USAGE_FLAG_CONCEALMENT, [0]]
];

// single unit
Expand Down
36 changes: 12 additions & 24 deletions addons/main/functions/fnc_getLauncherUnits.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
* Disposable launchers get mostly ignored, AI doesn't seem to even use them.
*
* Arguments:
* 0: Group to search in <GROUP>
* 1: Check through submunitions <BOOLEAN>
* 0: Group to search in <GROUP, ARRAY<OBJECT>>
* 1: Flags to check Against <NUMBER>
* 2: Check through submunitions <BOOLEAN>
*
* Return Value:
* Array - units with launchers
Expand All @@ -24,23 +25,15 @@
* 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]]
["_group", [], [grpNull, []]],
["_flags", AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR, [0]],
["_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};

if (_group isEqualType grpNull) then {
_group = units _group;
};
private _suitableUnits = [];
{
if ((secondaryWeapon _x) isEqualTo "") then {continue};
Expand All @@ -55,21 +48,16 @@ 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 -
// launcher ammo is usually in the backpack. This is a ~3-4x speedup.
} forEach (units _group);
} forEach _group;

_suitableUnits
12 changes: 12 additions & 0 deletions addons/main/script_macros.hpp
Original file line number Diff line number Diff line change
@@ -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", [""]]; \
Expand Down
2 changes: 1 addition & 1 deletion addons/wp/functions/fnc_taskRush.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 080a61d

Please sign in to comment.