ACE3/addons/missileguidance/functions/fnc_guidancePFH.sqf

97 lines
3.8 KiB
Plaintext
Raw Normal View History

//#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
private["_args", "_stateParams", "_launchParams", "_targetLaunchParams", "_config", "_flightParams", "_seekerParams", "_seekerTargetPos"];
private["_lastRunTime", "_runtimeDelta", "_profileAdjustedTargetPos", "_targetVectorSeeker", "_targetVector"];
private["_minDeflection", "_maxDeflection", "_incDeflection"];
private["_yVec", "_zVec", "_xVec"];
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);
_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-08 15:01:39 +00:00
_config = configFile >> "CfgAmmo" >> _ammo >> "ACE_MissileGuidance";
if(!alive _projectile || isNull _projectile || isNull _shooter) exitWith {
[(_this select 1)] call cba_fnc_removePerFrameHandler;
};
// TODO: placeholder for "last seek target position"
_seekerTargetPos = [ [0,0,0], _args] call FUNC(doSeekerSearch);
2015-04-08 15:01:39 +00:00
if(!isNil "_seekerTargetPos") then {
_profileAdjustedTargetPos = [_seekerTargetPos,_args] call FUNC(doAttackProfile);
2015-04-08 15:01:39 +00:00
_minDeflection = _flightParams select 0;
_maxDeflection = _flightParams select 1;
2015-04-08 18:27:30 +00:00
_incDeflection = _flightParams select 2;
2015-04-08 15:01:39 +00:00
_yVec = vectorDir _projectile;
_zVec = vectorUp _projectile;
_xVec = vectorNormalized (_yVec vectorCrossProduct _zVec);
_projectilePos = getPosASL _projectile;
_targetVectorSeeker = [_projectile, [_xVec, _yVec, _zVec], _profileAdjustedTargetPos] call EFUNC(common,translateToWeaponSpace);
2015-04-08 15:01:39 +00:00
_targetVector = [0,0,0] vectorFromTo _targetVectorSeeker;
TRACE_1("", _targetVectorSeeker, _targetVector);
private["_yaw", "_pitch"];
2015-04-08 15:01:39 +00:00
_yaw = 0;
_pitch = 0;
if((_targetVectorSeeker select 0) < 0) then {
2015-04-08 18:27:30 +00:00
_yaw = - ( (_minDeflection max (abs(_targetVector select 0) min _maxDeflection) ) );
2015-04-08 15:01:39 +00:00
} else {
if((_targetVectorSeeker select 0) > 0) then {
_yaw = ( (_minDeflection max ((_targetVector select 0) min _maxDeflection) ) );
};
};
if((_targetVectorSeeker select 2) < 0) then {
2015-04-08 18:27:30 +00:00
_pitch = - ( (_minDeflection max (abs(_targetVector select 2) min _maxDeflection) ) );
2015-04-08 15:01:39 +00:00
} else {
if((_targetVectorSeeker select 2) > 0) then {
_pitch = ( (_minDeflection max ((_targetVector select 2) min _maxDeflection) ) );
};
};
#ifdef DEBUG_MODE_FULL
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]];
#endif
if(accTime > 0) then {
private["_adjustTime", "_outVector", "_vectorTo"];
2015-04-08 22:34:59 +00:00
_adjustTime = 1/accTime;
2015-04-09 23:43:05 +00:00
_adjustTime = _adjustTime * (_runtimeDelta / TIMESTEP_FACTOR);
TRACE_4("Adjust timing", 1/accTime, _adjustTime, _runtimeDelta, (_runtimeDelta / TIMESTEP_FACTOR) );
2015-04-09 23:31:14 +00:00
// @TODO: Apply velocity multiplier to yaw/pitch. Basically, it can adjust faster at lower speeds
//_adjustDeflection = (vectorMagnitude velocity _projectile);
_outVector = [_projectile, [_xVec, _yVec, _zVec], [_yaw, _adjustTime, _pitch]] call EFUNC(common,translateToModelSpace);
2015-04-08 15:01:39 +00:00
_vectorTo = _projectilePos vectorFromTo _outVector;
_projectile setVectorDirAndUp [_vectorTo, vectorUp _projectile];
};
#ifdef DEBUG_MODE_FULL
hintSilent format["d: %1", _distanceToTarget];
#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];