-
Notifications
You must be signed in to change notification settings - Fork 738
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
base: master
Are you sure you want to change the base?
Manpad - Add stinger locking #10830
Changes from 2 commits
7e357ad
0f608a8
84b4c4e
e455235
ec647ca
416f953
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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)); | ||
}; | ||
}; |
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[] = {}; | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
PREP(eachFrame); | ||
PREP(weaponChanged); |
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? | ||
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 | ||
PabstMirror marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[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 |
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; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "script_component.hpp" | ||
|
||
#include "XEH_PREP.hpp" |
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]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]; | ||
}; |
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]; | ||
}; |
There was a problem hiding this comment.
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