Skip to content

Manpad - Add stinger locking #10830

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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
13 changes: 13 additions & 0 deletions addons/compat_cup_weapons/compat_cup_missileguidance/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ class CfgPatches {

#include "\z\ace\addons\missileguidance\script_missileBases.hpp"
#include "CfgAmmo.hpp"

class CfgWeapons { //todo
class Launcher_Base_F;
class CUP_launch_FIM92Stinger_Loaded: Launcher_Base_F {
canLock = 0;
EGVAR(missile_manpad,enabled) = 1;
EGVAR(missile_manpad,lockAngle) = 3;
EGVAR(missile_manpad,lockingTimeMin) = 2;
EGVAR(missile_manpad,lockingTimeMax) = 4;
EGVAR(missile_manpad,lockingSound) = QEGVAR(missile_manpad,stinger_locking);
EGVAR(missile_manpad,lockedSound) = QEGVAR(missile_manpad,stinger_locked);
};
};
16 changes: 16 additions & 0 deletions addons/missile_manpad/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};

class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
clientInit = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
10 changes: 10 additions & 0 deletions addons/missile_manpad/CfgSounds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CfgSounds {
class GVAR(stinger_locked) {
sound[] = {QPATHTOF(sounds\stinger_locked.ogg), 1, 1, 30};
titles[] = {};
};
class GVAR(stinger_locking) {
sound[] = {QPATHTOF(sounds\stinger_locking.ogg), 1, 1, 30};
titles[] = {};
};
};
16 changes: 16 additions & 0 deletions addons/missile_manpad/CfgWeapons.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,21 @@ class CfgWeapons {
class launch_Titan_base: Launcher_Base_F {
magazines[] = {QGVAR(stinger_man)};
};

#ifdef CREATE_MOCK_PLATFORMS
class launch_RPG7_F;
class GVAR(mockStinger): launch_RPG7_F {
displayName = "Test Stinger";
canLock = 0;
magazineWell[] = {};
magazines[] = {QGVAR(stinger_man)};
GVAR(enabled) = 1;
GVAR(lockAngle) = 3;
GVAR(lockingTimeMin) = 2;
GVAR(lockingTimeMax) = 4;
GVAR(lockingSound) = QGVAR(stinger_locking);
GVAR(lockedSound) = QGVAR(stinger_locked);
};
#endif
};

2 changes: 2 additions & 0 deletions addons/missile_manpad/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREP(eachFrame);
PREP(weaponChanged);
45 changes: 45 additions & 0 deletions addons/missile_manpad/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "script_component.hpp"

if (!hasInterface) exitWith {};

// Add keybind - todo: move to missile_guidance-common-binds?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i like this idea. javelin, spike, and now this will have the lock key bound but all unique binds; i think its beneficial to have some common ones

GVAR(isLockKeyDown) = false;
["ACE3 Weapons", QGVAR(trackTarget), "Lock Target (Hold) [stinger]", {
GVAR(isLockKeyDown) = true;
}, {
GVAR(isLockKeyDown) = false;
}, [15, [false, false, false]], false] call CBA_fnc_addKeybind; //Tab Key


GVAR(running) = [];
["weapon", LINKFUNC(weaponChanged)] call CBA_fnc_addPlayerEventHandler;
["unit", LINKFUNC(weaponChanged), true] call CBA_fnc_addPlayerEventHandler;

// todo move to CBA on it's next release https://github.com/CBATeam/CBA_A3/pull/1751
[QGVAR(soundEffect), {
params ["_unit", "_sound"];
TRACE_2("soundEffect",_unit,_sound);
private _old = _unit getVariable [QGVAR(soundEffect), objNull];
if (!isNull _old) then {
deleteVehicle _old;
};
if (_sound != "") then {
private _new = _unit say3D _sound;
_unit setVariable [QGVAR(soundEffect), _new];
};
}] call CBA_fnc_addEventHandler;


#ifdef ENABLE_QUICK_TESTING
["recompile", "recompile", "recompile", {
private _start = diag_tickTime;
[] call ACE_PREP_RECOMPILE;
[] call ace_common_fnc_dumpPerformanceCounters;
private _end = diag_tickTime;
systemChat format ["recompile took [%1 ms]", (1000 * (_end - _start)) toFixed 1];
if (productVersion #4 == "Diag") then {
call compile "diag_mergeConfigFile ['P:\z\ace\addons\missile_manpad\config.cpp']";
};
false
}, {false}, [59, [false, false, false]], false] call CBA_fnc_addKeybind; // F1 Key
#endif
9 changes: 9 additions & 0 deletions addons/missile_manpad/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/missile_manpad/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
7 changes: 4 additions & 3 deletions addons/missile_manpad/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common","ace_missileguidance"};
requiredAddons[] = {"ace_missileguidance"};
author = ECSTRING(common,ACETeam);
authors[] = {"Dani (TCVM)"};
authors[] = {"Dani (TCVM)", "PabstMirror"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "CfgAmmo.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgMagazines.hpp"
#include "CfgSounds.hpp"
#include "CfgWeapons.hpp"
#include "CfgVehicles.hpp"

127 changes: 127 additions & 0 deletions addons/missile_manpad/functions/fnc_eachFrame.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Each frame.
*
* Arguments:
* 0: Args <ARRAY>
*
* Return Value:
* None
*
* Example:
* [[]] call ace_missile_manpad_fnc_eachFrame
*
* Public: No
*/
params ["_args"];
_args params ["_unit", "_pfid", "_actionId", "_config", "_lockCanidate", "_lockStartTime", "_haveLock", "_lastSound", "_lastSoundTimeout"];
_config params ["_seekerMaxRange", "_lockAngle", "_uncageAngle", "_lockingTimeMin", "_lockingTimeMax", "_lockingSound", "_lockedSound"];

private _fnc_playSound = {
params ["_sound"];
if ((_lastSound != _sound) || {CBA_missionTime > _lastSoundTimeout}) then {
private _affected = (ASLToAGL eyePos _unit) nearEntities ["CAManBase", 50];
[QGVAR(soundEffect), [_unit, _sound], _affected] call CBA_fnc_targetEvent;
_args set [7, _sound];
_args set [8, CBA_missionTime + 10]; // tiny clipping when re-starting track
};
};

private _fnc_searchTarget = {
params ["_target", "_currentAngleMax"];

private _aimASL = aimPos _target;
private _targetDiff = _aimASL vectorDiff _seekerASL;
private _angle = acos ((_seekerDir vectorCos _targetDiff) min 1 max -1); // vectorCos will sometimes be 1.0001 :(
private _visibility = [_source, "VIEW", _target] checkVisibility [_seekerASL, _aimASL];
private _dist = vectorMagnitude _targetDiff;

if ((_angle > _currentAngleMax) || {_visibility < 0.1} || {_dist > _seekerMaxRange}) exitWith {
if (EGVAR(missileguidance,debug_drawGuidanceInfo)) then {
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [1,0,0,1],
ASLToAGL _aimASL, 1.5, 1.5, 45, format ["a%1 - v%2 - d%3", _angle, _visibility, _dist], 0.5, 0.025, "TahomaB"];
};
0
};

private _ret = _visibility // get a signal strength estimate
* linearConversion [_currentAngleMax/2, _currentAngleMax, _angle, 1, 0.5, true]
* linearConversion [_seekerMaxRange/2, _seekerMaxRange, vectorMagnitude _targetDiff, 1, 0.5, true]
* linearConversion [100, 3000, getMass _target, 0.25, 1, true];

if (EGVAR(missileguidance,debug_drawGuidanceInfo)) then {
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\select_target_ca.paa", [0,1,0,1],
ASLToAGL _aimASL, 1.5, 1.5, 45, format ["a%1 - v%2 - d%3 = %4", _angle, _visibility, _dist, _ret], 0.5, 0.025, "TahomaB"];
};
_ret
};


if (!GVAR(isLockKeyDown) || {(currentMagazine _unit) == ""}) exitWith {
"" call _fnc_playSound;
_unit setVariable [QEGVAR(missileguidance,target), nil];
_args set [4, objNull]; // _lockCanidate = objNull
};

private _source = _unit;
private _seekerASL = eyePos _source;
private _seekerDir = _source weaponDirection currentWeapon _source;

private _lockFeedback = 0;
if (isNull _lockCanidate) then {
// find any target within seeker range
private _potentialTargets = _source nearEntities ["Air", _seekerMaxRange];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flares won't be locked with this, idk if thats desired. it may make more sense to break out the target logic into its own function and call that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering if this should more closely just copy the ir_seeker code

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think it should; i'd want to break the logic into it's own function just because its a but unweidly and if it changes in the future it'd be a pain to update twice

private _bestValue = 0;
private _bestTarget = objNull;
{
private _target = _x;
if (_target isKindOf "ParachuteBase") then { continue };
private _strength = [_x, _lockAngle, _seekerMaxRange] call _fnc_searchTarget;
if (_strength > _bestValue) then {
_bestTarget = _x;
_bestValue = _strength;
};
} forEach _potentialTargets;
if (!isNull _bestTarget) then {
TRACE_1("new target",_bestTarget);
_args set [4, _bestTarget]; // _lockCanidate = _bestTarget;
_args set [5, CBA_missionTime]; // _lockStartTime = CBA_missionTime;
_args set [6, false]; // _haveLock = false;
};
} else {
private _angle = [_lockAngle, _uncageAngle] select CBA_events_control;
private _strength = [_lockCanidate, _angle, _seekerMaxRange] call _fnc_searchTarget;
if (_strength == 0) exitWith {
_haveLock = false;
_args set [4, objNull]; // _lockCanidate = objNull;
};

if (_haveLock) then {
_lockFeedback = 1;
} else {
private _lockTime = CBA_missionTime - _lockStartTime;
private _lockNeeded = linearConversion [1, 0, _strength, _lockingTimeMin, _lockingTimeMax, true];
_lockFeedback = linearConversion [0, _lockNeeded, _lockTime, 0, 1, true];
_haveLock = _lockFeedback >= 1;
if (_haveLock) then {
TRACE_1("new lock",_strength);
_args set [6, true];
};
};

// hintSilent format ["lf %1\nstr %2", _lockFeedback, _strength];
};

switch (true) do {
case (_lockFeedback == 0): { "" call _fnc_playSound };
case (_lockFeedback < 1): { _lockingSound call _fnc_playSound };
case (_lockFeedback >= 1): { _lockedSound call _fnc_playSound };
};


if ((isNull _lockCanidate) || {!_haveLock}) then {
_unit setVariable [QEGVAR(missileguidance,target), nil];
} else {
_unit setVariable [QEGVAR(missileguidance,target), _lockCanidate];
};
55 changes: 55 additions & 0 deletions addons/missile_manpad/functions/fnc_weaponChanged.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Unit or Weapon changed
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [player] call ace_missile_manpad_fnc_weaponChanged
*
* Public: No
*/
params ["_unit"];
private _weapon = currentWeapon _unit;
TRACE_2("weaponChanged",_unit,_weapon);

if (GVAR(running) isNotEqualTo []) then {
TRACE_1("cleanup",GVAR(running));
GVAR(running) params ["_unit", "_pfid", "_actionId"];
_pfid call CBA_fnc_removePerFrameHandler;
[_unit, "DefaultAction", _actionId] call EFUNC(common,removeActionEventHandler);
GVAR(running) = [];
};
if (alive _unit && {_weapon != ""}) then {
private _weapCfg = configFile >> "CfgWeapons" >> _weapon;
if ((getNumber (_weapCfg >> QGVAR(enabled))) != 1) exitWith { TRACE_1("-not enabled",_weapCfg); };
private _mag = (compatibleMagazines _weapon) param [0, ""];
private _ammo = getText (configFile >> "CfgMagazines" >> _mag >> "ammo");
private _ammoCfg = configFile >> "CfgAmmo" >> _ammo;

// _config params ["_seekerMaxRange", "_lockAngle", "_uncageAngle", "_lockingTimeMin", "_lockingTimeMax", "_lockingSound", "_lockedSound"];
private _config = [
[_ammoCfg >> "ace_missileguidance" >> "seekerMaxRange", "NUMBER", 9000] call CBA_fnc_getConfigEntry,
[_weapCfg >> QGVAR(lockAngle), "NUMBER", 3] call CBA_fnc_getConfigEntry,
[_ammoCfg >> "ace_missileguidance" >> "seekerAngle", "NUMBER", 3] call CBA_fnc_getConfigEntry,
[_weapCfg >> QGVAR(lockingTimeMin), "NUMBER", 3] call CBA_fnc_getConfigEntry,
[_weapCfg >> QGVAR(lockingTimeMax), "NUMBER", 3] call CBA_fnc_getConfigEntry,
[_weapCfg >> QGVAR(lockingSound), "STRING", ""] call CBA_fnc_getConfigEntry,
[_weapCfg >> QGVAR(lockedSound), "STRING", ""] call CBA_fnc_getConfigEntry
];
TRACE_3("-enabled",_mag,_ammo,_config);

private _actionId = [_unit, "DefaultAction", {
isNull ((_this select 1) getVariable [QEGVAR(missileguidance,target), objNull])
}, {
TRACE_1("block click",EGVAR(missileguidance,target));
}] call EFUNC(common,addActionEventHandler);
GVAR(running) = [_unit, -1,_actionId, _config, objNull, -1, false, "", -1];
private _pfid = [{call FUNC(eachFrame)}, 0, GVAR(running)] call CBA_fnc_addPerFrameHandler;
GVAR(running) set [1, _pfid];
};
2 changes: 2 additions & 0 deletions addons/missile_manpad/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS
// #define ENABLE_QUICK_TESTING
// #define CREATE_MOCK_PLATFORMS

#ifdef DEBUG_ENABLED_MISSILE_MANPAD
#define DEBUG_MODE_FULL
Expand Down
Binary file added addons/missile_manpad/sounds/stinger_locked.ogg
Binary file not shown.
Binary file added addons/missile_manpad/sounds/stinger_locking.ogg
Binary file not shown.
2 changes: 1 addition & 1 deletion addons/missileguidance/dev/mock_ammo.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class M_Titan_AA_static;
class GVAR(mock_a_Malyutka): M_Titan_AA_static {
aiAmmoUsageFlags="64 + 128 + 256 + 512";
aiAmmoUsageFlags = 64 + 128 + 256 + 512;
weaponLockSystem = 0;
airLock = 0;
lockType = 0;
Expand Down
Loading