ACE3/addons/nlaw/functions/fnc_keyDown.sqf
PabstMirror 49374feb2a NLAW - Predicted Line Of Sight Guidance and Overfly Attack Mode (#4791)
* NLAW Prototype

* Make AI Compatible

* Add Overfly Top Attack Mode

* Limit Max Deflection

* Base prediction on AI skill

* Generic cycle attack profile key for missile guidance

* Add hint for weapons without huds

* Configure for attack cycle key

* Finish OTA ammo effects

* Cleanup

* Arm at 20m

* Disable Debug

* No models for short lived sub-ammos

* Fix Korean strings

* Change AI randomization to use skillFinal

* Add wiki doc for nlaw

* Cleanup

* Cleanup

* Cleanup
2017-06-02 16:51:20 -05:00

82 lines
3.0 KiB
Plaintext

/*
* Author: PabstMirror
* Handles the track key being held down.
* Tracks change in direction of weapon and computes angle change per second.
*
* Arguments:
* None
*
* Return Value:
* None
*
* Example:
* [] call ace_nlaw_fnc_keyDown
*
* Public: No
*/
// #define DEBUG_MODE_FULL
#include "script_component.hpp"
TRACE_1("lock key down",GVAR(isLockKeyDown));
if (!alive ACE_player) exitWith {};
if (!([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith))) exitWith {};
if (!(ACE_player call CBA_fnc_canUseWeapon)) exitWith {};
if ((getNumber (configFile >> "CfgWeapons" >> (currentWeapon ACE_player) >> QGVAR(enabled))) == 0) exitWith {};
if (GVAR(isLockKeyDown)) exitWith {ERROR("already running?");};
GVAR(isLockKeyDown) = true;
playSound "ACE_Sound_Click";
// Get starting weapon dir
((ACE_player weaponDirection (currentWeapon ACE_player)) call CBA_fnc_vect2Polar) params ["", "_yaw", "_pitch"];
[{
params ["_args", "_pfID"];
_args params ["_lastTime", "_lastYaw", "_lastPitch", "_initPhase"];
if ((!alive ACE_player) ||
{!([ACE_player, objNull, ["isNotInside"]] call EFUNC(common,canInteractWith))} ||
{!GVAR(isLockKeyDown)} ||
{!(ACE_player call CBA_fnc_canUseWeapon)} ||
{(getNumber (configFile >> "CfgWeapons" >> (currentWeapon ACE_player) >> QGVAR(enabled))) == 0})
exitWith {
TRACE_1("ending track",_pfID);
[_pfID] call CBA_fnc_removePerFrameHandler;
playSound "ACE_Sound_Click";
[{ // reset gvars after a short delay
TRACE_1("reset vars",_this);
GVAR(yawChange) = 0;
GVAR(pitchChange) = 0;
}, [], 0.5] call CBA_fnc_waitAndExecute;
};
private _deltaT = CBA_missionTime - _lastTime;
if (_deltaT == 0) exitWith {};
if (_initPhase && {_deltaT < 0.75}) exitWith {};
((ACE_player weaponDirection (currentWeapon ACE_player)) call CBA_fnc_vect2Polar) params ["", "_yaw", "_pitch"];
private _yawChange = ([_yaw - _lastYaw] call CBA_fnc_simplifyAngle180) / _deltaT;
private _pitchChange = ([_pitch - _lastPitch] call CBA_fnc_simplifyAngle180) / _deltaT;
if (_initPhase) then { // initial value will use first 0.75 seconds of input
GVAR(yawChange) = _yawChange;
GVAR(pitchChange) = _pitchChange;
_args set [3, false];
} else {
// smoothing factor alpha - higher values will be more responsive to change, but also spike higher on jerky mouse movmeent
private _alpha = _deltaT / 3;
GVAR(yawChange) = (_yawChange * _alpha) + GVAR(yawChange) * (1 - _alpha);
GVAR(pitchChange) = (_pitchChange * _alpha) + GVAR(pitchChange) * (1 - _alpha);
};
_args set [0, CBA_missionTime];
_args set [1, _yaw];
_args set [2, _pitch];
#ifdef DEBUG_MODE_FULL
hintSilent format ["Instantaneous\nYaw: %1\n Pitch: %2\nGVAR\nYaw: %3\nPitch: %4", _yawChange, _pitchChange, GVAR(yawChange), GVAR(pitchChange)];
#endif
}, .25, [CBA_missionTime, _yaw, _pitch, true]] call CBA_fnc_addPerFrameHandler;