Skip to content

Commit

Permalink
MCLOS - Add support for AI (#10701)
Browse files Browse the repository at this point in the history
* MCLOS - Add support for AI

* Move `hasMCLOSControl` config to weapon
  • Loading branch information
PabstMirror authored Feb 14, 2025
1 parent b582cc6 commit a6288e3
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 22 deletions.
16 changes: 16 additions & 0 deletions addons/common/CfgSounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,20 @@ class CfgSounds {
sound[] = {QPATHTOF(sounds\ACE_click.wav), 1, 1, 200};
titles[] = {};
};
class ACE_Sound_Click_10db {
sound[] = {QPATHTOF(sounds\ACE_click.wav), "db-10", 1, 200};
titles[] = {};
};
class ACE_Sound_Click_20db {
sound[] = {QPATHTOF(sounds\ACE_click.wav), "db-20", 1, 200};
titles[] = {};
};
class ACE_Sound_Click_30db {
sound[] = {QPATHTOF(sounds\ACE_click.wav), "db-30", 1, 200};
titles[] = {};
};
class ACE_Sound_Click_40db {
sound[] = {QPATHTOF(sounds\ACE_click.wav), "db-40", 1, 200};
titles[] = {};
};
};
4 changes: 4 additions & 0 deletions addons/missileguidance/CfgAmmo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,8 @@ class CfgAmmo {
enabled = 1;
};
};

#ifdef CREATE_MOCK_PLATFORMS
#include "dev\mock_ammo.hpp"
#endif
};
4 changes: 4 additions & 0 deletions addons/missileguidance/CfgMagazines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ class CfgMagazines {
count = 24;
pylonWeapon = QGVAR(dagr);
};

#ifdef CREATE_MOCK_PLATFORMS
#include "dev\mock_magazines.hpp"
#endif
};
4 changes: 4 additions & 0 deletions addons/missileguidance/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ class CfgWeapons {
lockingTargetSound[] = {"",0,1};
lockedTargetSound[] = {"",0,1};
};

#ifdef CREATE_MOCK_PLATFORMS
#include "dev\mock_weapons.hpp"
#endif
};
4 changes: 4 additions & 0 deletions addons/missileguidance/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ class CfgPatches {
#include "CfgAmmo.hpp"
#include "CfgMagazines.hpp"
#include "CfgWeapons.hpp"
#ifdef CREATE_MOCK_PLATFORMS
#include "dev\mock_vehicles.hpp"
#endif

15 changes: 15 additions & 0 deletions addons/missileguidance/dev/mock_ammo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class M_Titan_AA_static;
class GVAR(mock_a_Malyutka): M_Titan_AA_static {
aiAmmoUsageFlags="64 + 128 + 256 + 512";
weaponLockSystem = 0;
airLock = 0;
lockType = 0;
manualControl = 0;
thrust = 80;
maxSpeed = 100;
airFriction = 0.5;
sideairfriction = 0.14;
class ADDON: GVAR(type_Malyutka) {
enabled = 1;
};
};
4 changes: 4 additions & 0 deletions addons/missileguidance/dev/mock_magazines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class 1Rnd_GAA_missiles;
class GVAR(mock_m_Malyutka): 1Rnd_GAA_missiles {
ammo = QGVAR(mock_a_Malyutka);
};
22 changes: 22 additions & 0 deletions addons/missileguidance/dev/mock_vehicles.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CfgVehicles {
class Car_F;
class LSV_02_base_F: Car_F {
class Turrets;
};
class LSV_02_AT_base_F: LSV_02_base_F {
class Turrets: Turrets {
class MainTurret;
};
};
class O_LSV_02_AT_F: LSV_02_AT_base_F {};
class GVAR(mock_lsv_Malyutka): O_LSV_02_AT_F {
scope = 1;
displayName = "[ACE] Test Malyutka LSV";
class Turrets: Turrets {
class MainTurret: MainTurret {
weapons[] = { QGVAR(mock_w_Malyutka) };
magazines[] = { QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka), QGVAR(mock_m_Malyutka) };
};
};
};
};
7 changes: 7 additions & 0 deletions addons/missileguidance/dev/mock_weapons.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class MissileLauncher;
class GVAR(mock_w_Malyutka): MissileLauncher {
displayName = "Test Malyutka";
GVAR(hasMCLOSControl) = 1;
magazineReloadTime=1;
magazines[] = { QGVAR(mock_m_Malyutka) };
};
36 changes: 19 additions & 17 deletions addons/missileguidance/functions/fnc_MCLOS_buttonPressed.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@

params ["_accelerationDirection", "_player"];

private _inMclosControlled = false;

private _shooter = vehicle _player;
if (getNumber ((configOf _shooter) >> QGVAR(hasMCLOSControl)) == 1) then {
playSound "ACE_Sound_Click";
if (_player == _shooter) exitWith {};
private _turret = _shooter unitTurret _player;

if (((_shooter weaponsTurret _turret) findIf {
(getNumber (configFile >> "CfgWeapons" >> _x >> QGVAR(hasMCLOSControl))) == 1
}) == -1) exitWith { false };


private _currentDirection = _shooter getVariable [QGVAR(MCLOS_direction), [0, 0, 0]];
// Send data across network for handling non-local projectiles
// This is the case in a wanted development for a proper Malyutka implementation where projectiles will
// have their locality change via script
_shooter setVariable [QGVAR(MCLOS_direction), _currentDirection vectorAdd _accelerationDirection, true];
playSound "ACE_Sound_Click_20db";

// Shouldn't have too many projectiles sent across the network. Planned max is 4 at a time
private _controlled = _shooter getVariable [QGVAR(mclos_projectiles), []];
_controlled = _controlled select { !isNull _x };
_shooter setVariable [QGVAR(mclos_projectiles), _controlled, true];
private _currentDirection = _shooter getVariable [QGVAR(MCLOS_direction), [0, 0, 0]];
// Send data across network for handling non-local projectiles
// This is the case in a wanted development for a proper Malyutka implementation where projectiles will
// have their locality change via script
_shooter setVariable [QGVAR(MCLOS_direction), _currentDirection vectorAdd _accelerationDirection, true];

// if we are controlling missiles, we want the input to be captured
_inMclosControlled = _controlled isNotEqualTo [];
};
// Shouldn't have too many projectiles sent across the network. Planned max is 4 at a time
private _controlled = _shooter getVariable [QGVAR(mclos_projectiles), []];
_controlled = _controlled select { !isNull _x };
_shooter setVariable [QGVAR(mclos_projectiles), _controlled, true];

_inMclosControlled
// if we are controlling missiles, we want the input to be captured
_controlled isNotEqualTo []
8 changes: 6 additions & 2 deletions addons/missileguidance/functions/fnc_MCLOS_onFired.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
* Public: No
*/
params ["_firedEH", "", "", "", "_stateParams"];
_firedEH params ["_shooter","_weapon","","","","","_projectile"];
_stateParams params ["", "_seekerStateParams"];
_firedEH params ["_shooter","_weapon","","","","","_projectile", "_gunner"];

if !(_gunner call EFUNC(common,isPlayer)) then {
// AI shot - save shot info (ToDo: Handle offset for optics/launch dir?)
// _stateParams params ["", "_seekerStateParams"];
_stateParams set [1, [getPosASLVisual _projectile, vectorNormalized velocity _projectile]];
};
private _source = vehicle _shooter;

private _controlled = _source getVariable [QGVAR(mclos_projectiles), []];
Expand Down
28 changes: 25 additions & 3 deletions addons/missileguidance/functions/fnc_seekerType_MCLOS.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,38 @@
* Public: No
*/
params ["", "_args"];
_args params ["_firedEH", "", "_flightParams"];
_firedEH params ["","","","","","","_projectile","_gunner"];
_args params ["_firedEH", "", "_flightParams", "", "_stateParams"];
_firedEH params ["_shooter","","","","","","_projectile","_gunner"];
_flightParams params ["_pitchRate", "_yawRate"];
_stateParams params ["", "_seekerStateParams"];

private _projectilePos = getPosASLVisual _projectile;
private _source = _projectile getVariable [QGVAR(source), _projectile];
private _mclosInput = (_source getVariable [QGVAR(MCLOS_direction), [0, 0, 0]]);

private _accelerationDirection = _projectile vectorModelToWorldVisual (_source getVariable [QGVAR(MCLOS_direction), [0, 0, 0]]);
if (_seekerStateParams isNotEqualTo []) then { // Handle AI
_seekerStateParams params ["_launchPos", "_launchVec"];
if (!(alive _shooter && {alive _gunner} && {(vehicle _gunner) == _shooter} && {_gunner call EFUNC(common,isAwake)})) exitWith {};

private _distance = _launchPos vectorDistance _projectilePos;
private _projectedPath = _launchPos vectorAdd (_launchVec vectorMultiply _distance);

private _hOffset = (_projectilePos # 2) - (_projectedPath # 2);
private _vv = (velocity _projectile) # 2;
_mclosInput = switch (true) do {
case (_hOffset < 0): { [0, 0, 1] }; // gross h adjust
case (_hOffset > 50): { [0, 0, -1] };
case ((_hOffset + 2 * _vv) < 0): { [0, 0, 1] }; // gross v adjust
case ((_hOffset + 2 * _vv) > 10): { [0, 0, -1] };
case ((_hOffset + _vv) > 5): { [0, 0, -1] }; // fine v adjust
default { [0, 0, 0] };
};
};

private _accelerationDirection = _projectile vectorModelToWorldVisual _mclosInput;
private _returnPos = _projectilePos vectorAdd (_accelerationDirection vectorMultiply (_pitchRate max _yawRate));

//IGNORE_PRIVATE_WARNING["_targetData"]
_targetData set [0, _projectilePos vectorFromTo _returnPos];
_targetData set [2, _returnPos distance _projectilePos];

Expand Down
1 change: 1 addition & 0 deletions addons/missileguidance/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS
// #define CREATE_MOCK_PLATFORMS

#ifdef DEBUG_ENABLED_MISSILEGUIDANCE
#define DEBUG_MODE_FULL
Expand Down

0 comments on commit a6288e3

Please sign in to comment.