Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GetLauncherUnits #395

Merged
merged 5 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = ((units _unit) findIf {(secondaryWeapon _x) isNotEqualTo ""}) isNotEqualTo -1;
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
16 changes: 9 additions & 7 deletions addons/danger/functions/fnc_tacticsHide.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,28 @@ _units doWatch objNull;
// disperse and hide unit ~ notice that cover is added as building positions nkenny
[_units, _target, _cover] call EFUNC(main,doGroupHide);

// find launcher and armour
private _launchers = _units select {(secondaryWeapon _x) isNotEqualTo ""};
// find launcher units
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 air/tanks
// find enemy vehicles
private _enemies = _unit targets [true, 600, [], 0, _target];
private _tankAir = _enemies findIf {(vehicle _x) isKindOf "Tank" || {(vehicle _x) isKindOf "Air"}};

if (_antiTank && { _tankAir != -1 } && { _launchers isNotEqualTo [] }) then {
if (_antiTank && { _tankAir != -1 } && { _launchersAT isNotEqualTo [] || (_launchersAA isNotEqualTo []) }) then {
private _targetVehicle = vehicle (_enemies select _tankAir);
{
// launcher units target air/tank
_x setCombatMode "RED";
_x commandTarget (_enemies select _tankAir);
_x commandTarget _targetVehicle;

// extra impetuous to select launcher
_x selectWeapon (secondaryWeapon _x);
_x setUnitPosWeak "MIDDLE";
} forEach _launchers;
} forEach ([_launchersAT, _launchersAA] select (_targetVehicle isKindOf "Air"));

// extra aggression from unit
_unit doFire (_enemies select _tankAir);
_unit doFire _targetVehicle;
};

// debug
Expand Down
1 change: 1 addition & 0 deletions addons/main/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ PREP(doAnimation);
PREP(doCallout);
PREP(doGesture);
PREP(doShareInformation);
PREP(getLauncherUnits);
PREP(getShareInformationParams);
PREP(shouldSuppressPosition);

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
63 changes: 63 additions & 0 deletions addons/main/functions/fnc_getLauncherUnits.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include "script_component.hpp"
/*
* Author: ThomasAngel
* Gets all units from a group that have launchers.
* Things like AP launchers, flares etc will not count, -
* launcher must be capable of destroying at least some vehicle.
*
* Checking through the submunitions might improve mod compatibility,
* but only if the AI actually accounts for submunitions when evaluating -
* whether to engage or not. As of writing, this is unknown.
*
* Disposable launchers get mostly ignored, AI doesn't seem to even use them.
*
* Arguments:
* 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
*
* Example:
* [group bob] call lambs_main_fnc_getLauncherUnits;
*
* Public: Yes
*/

params [
["_group", [], [grpNull, []]],
["_flags", 896, [0]], // 896 == AI_AMMO_USAGE_FLAG_VEHICLE + AI_AMMO_USAGE_FLAG_AIR + AI_AMMO_USAGE_FLAG_ARMOUR
jokoho48 marked this conversation as resolved.
Show resolved Hide resolved
["_checkSubmunition", false, [false]]
];

if (_group isEqualType grpNull) then {
_group = units _group;
};
private _suitableUnits = [];
{
if ((secondaryWeapon _x) isEqualTo "") then {continue};
private _currentUnit = _x;

private _unitsMagazines = (magazines _currentUnit) + (secondaryWeaponMagazine _currentUnit);
jokoho48 marked this conversation as resolved.
Show resolved Hide resolved
{
if ([_x, _flags] call FUNC(checkMagazineAiUsageFlags)) exitWith {
_suitableUnits pushBackUnique _currentUnit
};

// Optionally go through submunitions. More info in header.
if !(_checkSubmunition) then {continue}; // Invert & continue to reduce indentation

private _mainAmmo = getText (configFile >> "cfgMagazines" >> _x >> "ammo");
private _submunition = getText (configFile >> "cfgAmmo" >> _mainAmmo >> "submunitionAmmo");
if (_submunition isEqualTo "") then {continue};
private _submunitionFlags = getNumber(configFile >> "cfgAmmo" >> _submunition >> "aiAmmoUsageFlags");

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 _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
3 changes: 2 additions & 1 deletion addons/wp/functions/fnc_taskRush.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ private _fnc_rushOrders = {
};

// Tank -- hide or ready AT
private _launcherUnits = [_group] call EFUNC(main,getLauncherUnits);
if ((_distance < 80) && {(vehicle _target) isKindOf "Tank"}) exitWith {
{
if ((secondaryWeapon _x) isNotEqualTo "") then {
if (_x in _launcherUnits) then {
_x setUnitPos "MIDDLE";
_x selectWeapon (secondaryWeapon _x);
} else {
Expand Down
Loading