ACE3/addons/missileguidance/functions/fnc_guidancePFH.sqf

106 lines
4.3 KiB
Plaintext
Raw Normal View History

2015-04-14 15:24:13 +00:00
//#define DEBUG_MODE_FULL
2015-04-08 15:01:39 +00:00
#include "script_component.hpp"
2015-04-09 23:43:05 +00:00
#define TIMESTEP_FACTOR 0.01
2015-04-14 15:24:13 +00:00
private["_launchParams", "_targetLaunchParams", "_flightParams", "_seekerParams", "_stateParams"];
private["_lastRunTime", "_runtimeDelta", "_adjustTime", "_args", "_seekerTargetPos", "_projectilePos"];
private["_profileAdjustedTargetPos", "_incDeflection", "_minDeflection", "_maxDeflection"];
private["_targetVector", "_adjustVector", "_finalAdjustVector", "_changeVector", "_pitch", "_yaw", "_roll"];
2015-04-18 17:53:21 +00:00
private["_PS", "_distanceToTarget", "_targetRelativeVector", "_vectorTo"];
2015-04-14 15:24:13 +00:00
2015-04-08 15:01:39 +00:00
_args = _this select 0;
EXPLODE_7_PVT((_args select 0),_shooter,_weapon,_muzzle,_mode,_ammo,_magazine,_projectile);
2015-04-14 15:24:13 +00:00
if(!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
2015-04-08 15:01:39 +00:00
_launchParams = _args select 1;
_targetLaunchParams = _launchParams select 1;
_flightParams = _args select 2;
_seekerParams = _args select 3;
2015-04-08 22:34:59 +00:00
_stateParams = _args select 4;
_lastRunTime = _stateParams select 0;
_runtimeDelta = diag_tickTime - _lastRunTime;
2015-04-13 22:34:51 +00:00
_adjustTime = 1;
2015-04-14 15:24:13 +00:00
2015-04-13 22:34:51 +00:00
if(accTime > 0) then {
_adjustTime = 1/accTime;
_adjustTime = _adjustTime * (_runtimeDelta / TIMESTEP_FACTOR);
TRACE_4("Adjust timing", 1/accTime, _adjustTime, _runtimeDelta, (_runtimeDelta / TIMESTEP_FACTOR) );
} else {
_adjustTime = 0;
};
2015-04-08 15:01:39 +00:00
2015-04-14 15:24:13 +00:00
_minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0;
_maxDeflection = (_flightParams select 1) * _adjustTime;
_incDeflection = _flightParams select 2;
_projectilePos = getPosASL _projectile;
2015-04-08 15:01:39 +00:00
2015-04-14 15:24:13 +00:00
// @TODO: placeholder for "last seek target position"
// Last target pos should be optional based on the seeker unit
_seekerTargetPos = [ [0,0,0], _args, (_stateParams select 1)] call FUNC(doSeekerSearch);
2015-04-14 15:24:13 +00:00
if(isNil "_seekerTargetPos") then {
_seekerTargetPos = _seekerTargetPos vectorAdd ((velocity _projectile) vectorMultiply 5);
} else {
if( (vectorMagnitude _seekerTargetPos) == 0) then {
_seekerTargetPos = _seekerTargetPos vectorAdd ((velocity _projectile) vectorMultiply 5);
2015-04-08 15:01:39 +00:00
};
2015-04-14 15:24:13 +00:00
};
_profileAdjustedTargetPos = [_seekerTargetPos,_args, (_stateParams select 2)] call FUNC(doAttackProfile);
_targetVector = _projectilePos vectorFromTo _profileAdjustedTargetPos;
_adjustVector = _targetVector vectorDiff (vectorDir _projectile);
_yaw = 0;
_pitch = 0;
_roll = 0;
if((_adjustVector select 0) < 0) then {
_yaw = - ( (_minDeflection max (abs(_adjustVector select 0) min _maxDeflection) ) );
} else {
if((_adjustVector select 0) > 0) then {
_yaw = ( (_minDeflection max ((_adjustVector select 0) min _maxDeflection) ) );
2015-04-08 15:01:39 +00:00
};
2015-04-14 15:24:13 +00:00
};
if((_adjustVector select 1) < 0) then {
_roll = - ( (_minDeflection max (abs(_adjustVector select 1) min _maxDeflection) ) );
} else {
if((_adjustVector select 1) > 0) then {
_roll = ( (_minDeflection max ((_adjustVector select 1) min _maxDeflection) ) );
};
};
if((_adjustVector select 2) < 0) then {
_pitch = - ( (_minDeflection max (abs(_adjustVector select 2) min _maxDeflection) ) );
} else {
if((_adjustVector select 2) > 0) then {
_pitch = ( (_minDeflection max ((_adjustVector select 2) min _maxDeflection) ) );
2015-04-08 15:01:39 +00:00
};
2015-04-14 15:24:13 +00:00
};
_finalAdjustVector = [_yaw, _roll, _pitch];
TRACE_2("", _pitch, _yaw);
TRACE_4("", _targetVector, _targetRelativeVector, _adjustVector, _finalAdjustVector);
if(accTime > 0) then {
_changeVector = (vectorDir _projectile) vectorAdd _finalAdjustVector;
2015-04-14 16:36:39 +00:00
[_projectile, _changeVector] call FUNC(changeMissileDirection);
2015-04-14 15:24:13 +00:00
};
2015-04-08 15:01:39 +00:00
#ifdef DEBUG_MODE_FULL
2015-04-14 15:24:13 +00:00
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,1,1,1], ASLtoATL _projectilePos, 0.75, 0.75, 0, str _vectorTo, 1, 0.025, "TahomaB"];
drawLine3D [ASLtoATL _projectilePos, ASLtoATL _profileAdjustedTargetPos, [1,0,0,1]];
2015-04-13 23:47:09 +00:00
2015-04-18 16:29:58 +00:00
_ps = "#particlesource" createVehicleLocal (ASLtoATL _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 3.0;
2015-04-14 15:24:13 +00:00
hintSilent format["d: %1", _distanceToTarget];
2015-04-08 15:01:39 +00:00
#endif
2015-04-08 22:34:59 +00:00
2015-04-08 22:41:26 +00:00
_stateParams set[0, diag_tickTime];
2015-04-08 22:34:59 +00:00
_args set[4, _stateParams];
_this set[0, _args];