ACE3/addons/missileguidance/functions/fnc_attackProfile_JAV_TOP.sqf

90 lines
3.0 KiB
Plaintext
Raw Normal View History

2016-10-12 22:35:24 +00:00
/*
* Author: jaynus / nou
* Attack profile: Javelin Top
*
* 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_missileguidance_fnc_attackProfile_JAV_TOP;
*
* Public: No
*/
// #define DEBUG_MODE_FULL
2016-05-30 16:37:03 +00:00
#include "script_component.hpp"
#define STAGE_LAUNCH 1
#define STAGE_CLIMB 2
#define STAGE_COAST 3
#define STAGE_TERMINAL 4
2016-10-12 22:35:24 +00:00
params ["_seekerTargetPos", "_args", "_attackProfileStateParams"];
_args params ["_firedEH"];
_firedEH params ["_shooter","","","","","","_projectile"];
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
if (_attackProfileStateParams isEqualTo []) then {
_attackProfileStateParams set [0, STAGE_LAUNCH];
2016-05-30 16:37:03 +00:00
};
2016-10-12 22:35:24 +00:00
private _shooterPos = getPosASL _shooter;
private _projectilePos = getPosASL _projectile;
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
private _distanceToTarget = _projectilePos vectorDistance _seekerTargetPos;
private _distanceToShooter = _projectilePos vectorDistance _shooterPos;
private _distanceShooterToTarget = _shooterPos vectorDistance _seekerTargetPos;
2016-05-30 16:37:03 +00:00
TRACE_2("", _distanceToTarget, _distanceToShooter);
// Add height depending on distance for compensate
2016-10-12 22:35:24 +00:00
private _returnTargetPos = _seekerTargetPos;
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
switch( (_attackProfileStateParams select 0) ) do {
2016-05-30 16:37:03 +00:00
case STAGE_LAUNCH: {
TRACE_1("STAGE_LAUNCH","");
2016-10-12 22:35:24 +00:00
if (_distanceToShooter < 10) then {
_returnTargetPos = _seekerTargetPos vectorAdd [0,0,_distanceToTarget*2];
2016-05-30 16:37:03 +00:00
} else {
2016-10-12 22:35:24 +00:00
_attackProfileStateParams set [0, STAGE_CLIMB];
2016-05-30 16:37:03 +00:00
};
};
case STAGE_CLIMB: {
TRACE_1("STAGE_CLIMB","");
_cruisAlt = 140;
2016-10-12 22:35:24 +00:00
if (_distanceShooterToTarget < 1250) then {
private _cruisAlt = 140 * (_distanceShooterToTarget/1250);
2016-05-30 16:37:03 +00:00
TRACE_1("_cruisAlt", _cruisAlt);
};
2016-10-12 22:35:24 +00:00
if ( ((ASLToAGL _projectilePos) select 2) - ((ASLToAGL _seekerTargetPos) select 2) >= _cruisAlt) then {
if (_cruisAlt < 140) then {
_attackProfileStateParams set [0, STAGE_TERMINAL];
2016-05-30 16:37:03 +00:00
} else {
2016-10-12 22:35:24 +00:00
_attackProfileStateParams set [0, STAGE_COAST];
2016-05-30 16:37:03 +00:00
};
} else {
_returnTargetPos = _seekerTargetPos vectorAdd [0,0,_distanceToTarget*1.5];
2016-05-30 16:37:03 +00:00
};
};
case STAGE_COAST: {
TRACE_1("STAGE_COAST","");
TRACE_1("", ((ASLToAGL _projectilePos) select 2) - (( ASLToAGL _seekerTargetPos) select 2) );
2016-10-12 22:35:24 +00:00
if (_distanceToTarget < ( ((ASLToAGL _projectilePos) select 2) - (( ASLToAGL _seekerTargetPos) select 2) ) * 2) then {
_attackProfileStateParams set [0, STAGE_TERMINAL];
2016-05-30 16:37:03 +00:00
} else {
_returnTargetPos = _seekerTargetPos vectorAdd [0,0,(_projectilePos select 2)];
2016-05-30 16:37:03 +00:00
};
};
case STAGE_TERMINAL: {
TRACE_1("STAGE_TERMINAL","");
//_returnTargetPos = _seekerTargetPos vectorAdd [0,0,_distanceToTarget * 0.02];
2016-05-30 16:37:03 +00:00
_returnTargetPos = _seekerTargetPos;
};
};
TRACE_1("Adjusted target position", _returnTargetPos);
_returnTargetPos;