2023-09-12 18:58:10 +00:00
|
|
|
#include "..\script_component.hpp"
|
2017-06-02 21:51:38 +00:00
|
|
|
/*
|
|
|
|
* Author: PabstMirror
|
|
|
|
* Hellfire attack profile. Handles all 4 modes LOBL, LOAL-DIR, LOAL-HI, LOAL-LO
|
|
|
|
*
|
|
|
|
* Arguments:
|
|
|
|
* 0: Seeker Target PosASL <ARRAY>
|
|
|
|
* 1: Guidance Arg Array <ARRAY>
|
|
|
|
* 2: Attack Profile State <ARRAY>
|
|
|
|
*
|
|
|
|
* Return Value:
|
|
|
|
* Missile Aim PosASL <ARRAY>
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* [[1,2,3], [], []] call ace_hellfire_fnc_attackProfile
|
|
|
|
*
|
|
|
|
* Public: No
|
|
|
|
*/
|
|
|
|
|
|
|
|
params ["_seekerTargetPos", "_args", "_attackProfileStateParams"];
|
2019-12-30 18:29:08 +00:00
|
|
|
_args params ["_firedEH", "_launchParams", "", "", "_stateParams"];
|
|
|
|
_stateParams params ["", "_seekerStateParams"];
|
|
|
|
_launchParams params ["","_targetLaunchParams","_seekerType"];
|
|
|
|
|
2017-06-02 21:51:38 +00:00
|
|
|
_targetLaunchParams params ["", "", "_launchPos"];
|
|
|
|
_firedEH params ["","","","","","","_projectile"];
|
|
|
|
|
|
|
|
// Get state params:
|
|
|
|
if (_attackProfileStateParams isEqualTo []) then {
|
|
|
|
_this call FUNC(getAttackProfileSettings);
|
|
|
|
};
|
|
|
|
_attackProfileStateParams params ["_attackStage", "_configLaunchHeightClear"];
|
|
|
|
|
|
|
|
|
|
|
|
private _projectilePos = getPosASL _projectile;
|
|
|
|
private _distanceFromLaunch2d = _launchPos distance2d _projectilePos;
|
|
|
|
private _heightAboveLaunch = (_projectilePos select 2) - (_launchPos select 2);
|
|
|
|
|
|
|
|
// Add height depending on distance for compensate
|
|
|
|
private _returnTargetPos = nil;
|
|
|
|
|
|
|
|
switch (_attackStage) do {
|
|
|
|
case STAGE_LAUNCH: { // Gain height quickly to pass terrain mask
|
|
|
|
_returnTargetPos = _projectilePos getPos [100, getDir _projectile];
|
|
|
|
_returnTargetPos set [2, (_projectilePos select 2) + 36.4]; // 100 and 36.4 gives a 20 deg angle
|
|
|
|
|
|
|
|
if (_heightAboveLaunch > _configLaunchHeightClear) then {
|
|
|
|
_attackProfileStateParams set [0, STAGE_SEEK_CRUISE];
|
|
|
|
TRACE_2("New Stage: STAGE_SEEK_CRUISE",_distanceFromLaunch2d,_heightAboveLaunch);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case STAGE_SEEK_CRUISE: { // Slowly gain altitude while searching for target
|
|
|
|
// Before 4000 cruise at 5.7 degrees up, then level out
|
|
|
|
private _cruiseHeight = linearConversion [3000, 5000, _distanceFromLaunch2d, 10, 0, true];
|
|
|
|
|
|
|
|
_returnTargetPos = _projectilePos getPos [100, getDir _projectile];
|
|
|
|
_returnTargetPos set [2, (_projectilePos select 2) + _cruiseHeight];
|
|
|
|
|
2021-02-27 17:05:05 +00:00
|
|
|
if (_seekerTargetPos isNotEqualTo [0,0,0]) then {
|
2017-06-02 21:51:38 +00:00
|
|
|
_attackProfileStateParams set [0, STAGE_ATTACK_CRUISE];
|
|
|
|
TRACE_1("New Stage: STAGE_ATTACK_CRUISE",_distanceFromLaunch2d);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case STAGE_ATTACK_CRUISE: {
|
|
|
|
private _currentHeightOverTarget = (_projectilePos select 2) - (_seekerTargetPos select 2);
|
|
|
|
private _distanceToTarget2d = _seekerTargetPos distance2d _projectilePos;
|
|
|
|
private _distToGoRatio = _distanceToTarget2d / (_launchPos distance2d _seekerTargetPos);
|
|
|
|
|
|
|
|
// arcing up at 7 degrees to start until 50% left, then smooth curve to a downward attack
|
2021-02-27 17:05:05 +00:00
|
|
|
private _gainSlope = linearConversion [0.5, 0.1, _distToGoRatio, 7, -7, true];
|
2017-06-02 21:51:38 +00:00
|
|
|
_returnTargetPos = +_seekerTargetPos;
|
|
|
|
_returnTargetPos set [2, ((_projectilePos select 2) + (_distanceToTarget2d * sin _gainSlope)) max (_seekerTargetPos select 2)];
|
2019-12-30 18:29:08 +00:00
|
|
|
|
2017-06-02 21:51:38 +00:00
|
|
|
if ((_distanceToTarget2d < 500) || {(_currentHeightOverTarget atan2 _distanceToTarget2d) > 15}) then { // Wait until we can come down at a sharp angle
|
|
|
|
_attackProfileStateParams set [0, STAGE_ATTACK_TERMINAL];
|
|
|
|
TRACE_2("New Stage: STAGE_ATTACK_TERMINAL",_distanceToTarget2d,_currentHeightOverTarget);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
case STAGE_ATTACK_TERMINAL: {
|
|
|
|
private _distanceToTarget2d = _seekerTargetPos distance2d _projectilePos;
|
|
|
|
_returnTargetPos = _seekerTargetPos vectorAdd [0, 0, _distanceToTarget2d * 0.02];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-12-30 18:29:08 +00:00
|
|
|
// Special radar case. Adjust target position such that we are leading it
|
|
|
|
if (_attackStage >= 3 && { _seekerType isEqualTo "ARH" }) then {
|
|
|
|
_seekerStateParams params ["", "", "", "", "", "", "", "_lastKnownVelocity"];
|
|
|
|
private _projectileVelocity = velocity _projectile;
|
|
|
|
if (_projectileVelocity#2 < 0) then {
|
|
|
|
private _projectileSpeed = vectorMagnitude _projectileVelocity; // this gives a precise impact time versus using speed _projectile. Dont change
|
|
|
|
private _timeUntilImpact = (_seekerTargetPos distance _projectilePos) / _projectileSpeed;
|
|
|
|
_returnTargetPos = _returnTargetPos vectorAdd (_lastKnownVelocity vectorMultiply _timeUntilImpact);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-02-05 17:04:24 +00:00
|
|
|
// TRACE_1("Adjusted target position",_returnTargetPos);
|
2017-06-02 21:51:38 +00:00
|
|
|
_returnTargetPos;
|