Skip to content

Commit

Permalink
Update fnc_tacticsReinforce.sqf
Browse files Browse the repository at this point in the history
Adds new features to tacticsReinforce

Adds groups set to reinforce will appropriate vehicles (of their side) to use for transport
Adds groups will take ownership of static weapons (and pack them for their use)
Adds groups will check dead bodies for useful weapon before rienforcing
Improves more reliable packing and deploying of static weapons
Improves more formations used
Fixes "HOLD", "GUARD", and "DISMISS" waypoints not being cancelled

Overall this is a considerable enhancement to how units with the reinforcement flag function.  They will much more reliably collect nearby resources before moving to reinforce, and add considerable dynamic potential to operations
  • Loading branch information
nk3nny committed Mar 4, 2024
1 parent 618424f commit a9493d4
Showing 1 changed file with 48 additions and 14 deletions.
62 changes: 48 additions & 14 deletions addons/danger/functions/fnc_tacticsReinforce.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if (!(_unit call EFUNC(main,isAlive))) exitWith {false};
// free garrisons
private _group = group _unit;
if (EGVAR(main,Loaded_WP) && {!(_unit checkAIFeature "PATH")}) then {
_group = [_group, true] call EFUNC(wp,taskReset);
_group = [_group, true, true] call EFUNC(wp,taskReset);
};

// set new time
Expand All @@ -42,7 +42,7 @@ _group setVariable [QEGVAR(main,currentTactic), "Reinforcing", EGVAR(main,debug_
_group setVariable [QGVAR(isExecutingTactic), true];
_group setVariable [QGVAR(contact), time + _delay];
_group enableAttack false; // gives better fine control of AI - nkenny
_group setBehaviour "AWARE"; // more tractacle speed
_group setBehaviour "AWARE"; // more tractable speed

// reset
[
Expand All @@ -69,41 +69,75 @@ if (_units isEqualTo []) then {
_units = units _unit;
};

// set waiting time for movement order
private _waitForMove = 5;

// get vehicles
private _assignedVehicles = assignedVehicles _group;

// check waypoints -- if none add new?
// commander vehicles? ~ future versions with setting ~ nkenny
private _vehicles = nearestObjects [_unit, ["Landvehicle"], 75];
private _side = getNumber (configFile >> "CfgVehicles" >> (typeOf _unit) >> "side");
_vehicles = _vehicles select {alive _x && canMove _x && simulationEnabled _x && {(crew _x) isEqualTo []} && { !isObjectHidden _x } && { locked _x != 2 } && {(getNumber (configFile >> "CfgVehicles" >> (typeOf _x) >> "side")) isEqualTo _side}};
if (_vehicles isNotEqualTo []) then {
{
_group addVehicle _x;
_waitForMove = _waitForMove + 2;
} forEach _vehicles;
};

// check for unregistered static weapons
private _guns = _units select {(vehicle _x) isKindOf "StaticWeapon"};
if ((_group getVariable [QEGVAR(main,staticWeaponList), []]) isEqualTo []) then {
_group setVariable [QEGVAR(main,staticWeaponList), _guns, true];
_waitForMove = _waitForMove + 1;
};

// check bodies
private _weaponHolders = allDeadMen findIf { (_x distance2D _unit) < 35 };
if (_weaponHolders isNotEqualTo -1) then {
{
[{_this call lambs_main_fnc_doCheckBody;}, [_x, _x getPos [20, random 360], 35], random 2] call CBA_fnc_waitAndExecute;
_waitForMove = _waitForMove + 2;
} forEach _units;
};

// has artillery? ~ if so fire in support?
// is aircraft or tank? Different movement waypoint?

// clear HOLD waypointss
// clear HOLD, GUARD and DISMISS waypoints
private _waypoints = waypoints _group;
private _currentWP = _waypoints select ((currentWaypoint _group) min ((count _waypoints) - 1));
if ((waypointType _currentWP) isEqualTo "HOLD") then {
[_group] call CBA_fnc_clearWaypoints;
if (_waypoints isNotEqualTo []) then {
private _currentWP = _waypoints select ((currentWaypoint _group) min ((count _waypoints) - 1));
if ((waypointType _currentWP) in ["HOLD", "GUARD", "DISMISS"]) then {
[_group] call CBA_fnc_clearWaypoints;
};
};

// formation changes ~ allowed here as Reinforcing units have full autonomy - nkenny
private _distance = _unit distance2D _target;
if (_distance > 500) then {
_unit setFormation "COLUMN";
_group setFormation selectRandom ["COLUMN", "STAG COLUMN"];
if !(isNull objectParent _unit) then {(vehicle _unit) setUnloadInCombat [false, false];};
} else {
if (_distance > 200) then {
_unit setFormation selectRandom ["WEDGE", "VEE", "LINE"];
_group setFormation selectRandom ["WEDGE", "VEE", "LINE"];
};
if (_distance < GVAR(cqbRange)) then {
_unit setFormation "FILE";
[_unit, _target] call FUNC(tacticsAssault);
// _group setFormation "FILE"; ~formation is set in tacticsAssault ~KRM
[_group, _target] call FUNC(tacticsAssault);
};
};

// pack & deploy static weapons
if !(GVAR(disableAIDeployStaticWeapons)) then {
private _intersect = terrainIntersectASL [eyePos _unit, AGLtoASL (_target vectorAdd [0, 0, 10])];
if (_distance > 400 || {_intersect}) then {
_units = [_units] call EFUNC(main,doGroupStaticPack);
_units = [leader _group] call EFUNC(main,doGroupStaticPack);
};
if (!_intersect) then {
_units = [_units, _target] call EFUNC(main,doGroupStaticDeploy);
_units = [leader _group, _target] call EFUNC(main,doGroupStaticDeploy);
};
};

Expand All @@ -119,7 +153,7 @@ if (!(GVAR(disableAutonomousFlares)) && {_unit call EFUNC(main,isNight)}) then {
_group move _target;
},
[_group, _target],
5
_waitForMove
] call CBA_fnc_waitAndExecute;

// debug
Expand All @@ -128,7 +162,7 @@ if (EGVAR(main,debug_functions)) then {
"%1 TACTICS REINFORCING (%2 with %3 units @ %4m)",
side _unit,
name _unit,
count _units,
count units _group,
round (_unit distance2D _target)
] call EFUNC(main,debugLog);
private _m = [_unit, format ["Reinforcing @ %1m", round (_unit distance2D _target)], _unit call EFUNC(main,debugMarkerColor), "hd_warning"] call EFUNC(main,dotMarker);
Expand Down

0 comments on commit a9493d4

Please sign in to comment.