2018-09-17 19:19:29 +00:00
|
|
|
#include "script_component.hpp"
|
2016-10-12 22:35:24 +00:00
|
|
|
/*
|
|
|
|
* Author: jaynus / nou
|
|
|
|
* Guidance Per Frame Handler
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Guidance Arg Array <ARRAY>
|
|
|
|
* 1: PFID <NUMBER>
|
|
|
|
*
|
|
|
|
* Return Value:
|
2017-06-08 13:31:51 +00:00
|
|
|
* None
|
2016-10-12 22:35:24 +00:00
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[], 0] call ace_missileguidance_fnc_guidancePFH;
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
BEGIN_COUNTER(guidancePFH);
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
params ["_args", "_pfID"];
|
|
|
|
_args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"];
|
|
|
|
_firedEH params ["_shooter","","","","_ammo","","_projectile"];
|
2021-04-11 00:49:47 +00:00
|
|
|
_launchParams params ["","_targetLaunchParams","","","","","_navigationType"];
|
2021-04-12 06:12:16 +00:00
|
|
|
_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState", "_navigationParameters", "_guidanceParameters"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
if (!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
|
|
|
|
[_pfID] call CBA_fnc_removePerFrameHandler;
|
|
|
|
END_COUNTER(guidancePFH);
|
2016-05-30 16:37:03 +00:00
|
|
|
};
|
|
|
|
|
2021-04-12 21:18:01 +00:00
|
|
|
private _timestep = diag_deltaTime * accTime;
|
|
|
|
|
2021-04-11 01:02:31 +00:00
|
|
|
_flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// Run seeker function:
|
|
|
|
private _seekerTargetPos = [[0,0,0], _args, _seekerStateParams, _lastKnownPosState] call FUNC(doSeekerSearch);
|
2016-11-15 02:19:24 +00:00
|
|
|
// Run attack profile function:
|
2021-04-11 00:32:55 +00:00
|
|
|
_seekerTargetPos = AGLtoASL ASLToAGL _seekerTargetPos;
|
2016-11-15 02:19:24 +00:00
|
|
|
private _profileAdjustedTargetPos = [_seekerTargetPos, _args, _attackProfileStateParams] call FUNC(doAttackProfile);
|
2017-06-08 13:31:51 +00:00
|
|
|
|
2021-04-04 03:04:16 +00:00
|
|
|
private _projectilePos = getPosASLVisual _projectile;
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
// If we have no seeker target, then do not change anything
|
2019-06-08 04:48:37 +00:00
|
|
|
// If there is no deflection on the missile, this cannot change and therefore is redundant. Avoid calculations for missiles without any deflection
|
2021-04-10 19:11:20 +00:00
|
|
|
if ((_pitchRate != 0 || {_yawRate != 0}) && {_profileAdjustedTargetPos isNotEqualTo [0,0,0]}) then {
|
2021-04-11 00:49:47 +00:00
|
|
|
private _navigationFunction = getText (configFile >> QGVAR(NavigationTypes) >> _navigationType >> "functionName");
|
2021-04-12 21:18:01 +00:00
|
|
|
private _commandedAcceleration = [_args, _timestep, _seekerTargetPos, _profileAdjustedTargetPos] call (missionNamespace getVariable _navigationFunction);
|
2021-04-02 02:12:49 +00:00
|
|
|
|
2021-04-13 22:21:15 +00:00
|
|
|
if (isNil "_commandedAcceleration") exitWith {
|
|
|
|
ERROR_MSG("_commandedAcceleration is nil! Guidance cancelled");
|
|
|
|
};
|
|
|
|
|
2021-04-04 03:04:16 +00:00
|
|
|
#ifdef DRAW_GUIDANCE_INFO
|
|
|
|
private _projectilePosAGL = ASLToAGL _projectilePos;
|
2021-04-02 02:12:49 +00:00
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], _projectilePosAGL vectorAdd [0, 0, 1], 0.75, 0.75, 0, str _commandedAcceleration, 1, 0.025, "TahomaB"];
|
2021-04-10 17:15:27 +00:00
|
|
|
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd _commandedAcceleration, [1, 0, 1, 1]];
|
2021-03-19 05:43:07 +00:00
|
|
|
#endif
|
|
|
|
|
2021-04-10 19:11:20 +00:00
|
|
|
// activate missile servos and change direction
|
2021-03-19 05:43:07 +00:00
|
|
|
if (!isGamePaused && accTime > 0) then {
|
2021-04-12 06:12:16 +00:00
|
|
|
_guidanceParameters params ["_yaw", "_roll", "_pitch"];
|
2021-04-10 19:11:20 +00:00
|
|
|
|
2021-04-10 17:15:27 +00:00
|
|
|
_commandedAcceleration = _projectile vectorWorldToModelVisual _commandedAcceleration;
|
2021-04-04 03:04:16 +00:00
|
|
|
_commandedAcceleration params ["_yawChange", "", "_pitchChange"];
|
2021-04-12 22:44:59 +00:00
|
|
|
|
|
|
|
if (isNil "_yawChange") then {
|
|
|
|
_yawChange = 0;
|
|
|
|
};
|
|
|
|
if (isNil "_pitchChange") then {
|
|
|
|
_pitchChange = 0;
|
|
|
|
};
|
2021-04-04 03:04:16 +00:00
|
|
|
|
2021-04-10 19:11:20 +00:00
|
|
|
private _clampedPitch = (_pitchChange min _pitchRate) max -_pitchRate;
|
|
|
|
private _clampedYaw = (_yawChange min _yawRate) max -_yawRate;
|
2021-04-12 22:44:59 +00:00
|
|
|
|
2021-04-11 01:02:31 +00:00
|
|
|
// controls are either on or off, no proportional
|
|
|
|
if (_isBangBangGuidance) then {
|
2021-04-11 23:58:44 +00:00
|
|
|
private _pitchSign = if (_clampedPitch == 0) then {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
_clampedPitch / abs _clampedPitch
|
|
|
|
};
|
|
|
|
private _yawSign = if (_clampedYaw == 0) then {
|
|
|
|
0
|
|
|
|
} else {
|
|
|
|
_clampedYaw / abs _clampedYaw
|
|
|
|
};
|
2021-04-12 08:51:02 +00:00
|
|
|
_clampedPitch = _pitchSign * 50;
|
|
|
|
_clampedYaw = _yawSign * 50;
|
2021-04-11 01:02:31 +00:00
|
|
|
};
|
|
|
|
|
2021-04-10 19:11:20 +00:00
|
|
|
TRACE_9("pitch/yaw/roll",_pitch,_yaw,_roll,_yawChange,_pitchChange,_pitchRate,_yawRate,_clampedPitch,_clampedYaw);
|
|
|
|
|
2021-04-12 21:18:01 +00:00
|
|
|
_pitch = _pitch + _clampedPitch * _timestep;
|
|
|
|
_yaw = _yaw + _clampedYaw * _timestep;
|
2021-04-10 19:11:20 +00:00
|
|
|
|
|
|
|
TRACE_3("new pitch/yaw/roll",_pitch,_yaw,_roll);
|
2021-04-04 03:04:16 +00:00
|
|
|
|
2021-03-19 05:28:55 +00:00
|
|
|
[_projectile, _pitch, _yaw, 0] call FUNC(changeMissileDirection);
|
|
|
|
|
2021-04-12 06:12:16 +00:00
|
|
|
_guidanceParameters set [0, _yaw];
|
|
|
|
_guidanceParameters set [2, _pitch];
|
2021-03-19 05:28:55 +00:00
|
|
|
|
2021-04-12 06:12:16 +00:00
|
|
|
_stateParams set [5, _guidanceParameters];
|
2021-03-27 05:15:29 +00:00
|
|
|
};
|
2021-04-10 19:11:20 +00:00
|
|
|
|
|
|
|
_stateParams set [4, _navigationParameters];
|
2021-03-27 05:15:29 +00:00
|
|
|
_args set [4, _stateParams];
|
2016-05-30 16:37:03 +00:00
|
|
|
};
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
#ifdef DRAW_GUIDANCE_INFO
|
|
|
|
TRACE_3("",_projectilePos,_seekerTargetPos,_profileAdjustedTargetPos);
|
|
|
|
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], ASLtoAGL _projectilePos, 0.75, 0.75, 0, _ammo, 1, 0.025, "TahomaB"];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2021-03-31 23:16:00 +00:00
|
|
|
if (!isGamePaused && accTime > 0) then {
|
|
|
|
private _ps = "#particlesource" createVehicleLocal (ASLtoAGL _projectilePos);
|
|
|
|
_PS setParticleParams [["\A3\Data_f\cl_basic", 8, 3, 1], "", "Billboard", 1, 3.0141, [0, 0, 2], [0, 0, 0], 1, 1.275, 1, 0, [1, 1], [[1, 0, 0, 1], [1, 0, 0, 1], [1, 0, 0, 1]], [1], 1, 0, "", "", nil];
|
|
|
|
_PS setDropInterval 1.0;
|
|
|
|
};
|
2016-05-30 16:37:03 +00:00
|
|
|
#endif
|
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
_stateParams set [0, diag_tickTime];
|
2016-05-30 16:37:03 +00:00
|
|
|
|
2016-10-12 22:35:24 +00:00
|
|
|
END_COUNTER(guidancePFH);
|
2017-06-08 13:31:51 +00:00
|
|
|
|