ACE3/addons/missileguidance/functions/fnc_guidancePFH.sqf

114 lines
3.9 KiB
Plaintext
Raw Normal View History

#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:
* 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
#define TIMESTEP_FACTOR 0.01
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"];
_launchParams params ["","_targetLaunchParams"];
_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState"];
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
};
2016-10-12 22:35:24 +00:00
private _runtimeDelta = diag_tickTime - _lastRunTime;
private _adjustTime = 1;
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
if (accTime > 0) then {
2016-05-30 16:37:03 +00:00
_adjustTime = 1/accTime;
_adjustTime = _adjustTime * (_runtimeDelta / TIMESTEP_FACTOR);
TRACE_4("Adjust timing", 1/accTime, _adjustTime, _runtimeDelta, (_runtimeDelta / TIMESTEP_FACTOR) );
} else {
_adjustTime = 0;
};
2016-10-12 22:35:24 +00:00
private _minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0;
private _maxDeflection = (_flightParams select 1) * _adjustTime;
// private _incDeflection = _flightParams select 2; // todo
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
private _projectilePos = getPosASL _projectile;
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-05-30 16:37:03 +00:00
2016-11-15 02:19:24 +00:00
// Run attack profile function:
private _profileAdjustedTargetPos = [_seekerTargetPos, _args, _attackProfileStateParams] call FUNC(doAttackProfile);
2016-10-12 22:35:24 +00:00
// If we have no seeker target, then do not change anything
2016-11-15 02:19:24 +00:00
if (!(_profileAdjustedTargetPos isEqualTo [0,0,0])) then {
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
private _targetVector = _projectilePos vectorFromTo _profileAdjustedTargetPos;
private _adjustVector = _targetVector vectorDiff (vectorDir _projectile);
_adjustVector params ["_adjustVectorX", "_adjustVectorY", "_adjustVectorZ"];
private _yaw = 0;
private _pitch = 0;
private _roll = 0;
if (_adjustVectorX < 0) then {
_yaw = - ( (_minDeflection max ((abs _adjustVectorX) min _maxDeflection) ) );
} else {
if (_adjustVectorX > 0) then {
_yaw = ( (_minDeflection max (_adjustVectorX min _maxDeflection) ) );
};
2016-05-30 16:37:03 +00:00
};
2016-10-12 22:35:24 +00:00
if (_adjustVectorY < 0) then {
_roll = - ( (_minDeflection max ((abs _adjustVectorY) min _maxDeflection) ) );
} else {
if (_adjustVectorY > 0) then {
_roll = ( (_minDeflection max (_adjustVectorY min _maxDeflection) ) );
};
2016-05-30 16:37:03 +00:00
};
2016-10-12 22:35:24 +00:00
if (_adjustVectorZ < 0) then {
_pitch = - ( (_minDeflection max ((abs _adjustVectorZ) min _maxDeflection) ) );
} else {
if (_adjustVectorZ > 0) then {
_pitch = ( (_minDeflection max (_adjustVectorZ min _maxDeflection) ) );
};
2016-05-30 16:37:03 +00:00
};
2016-10-12 22:35:24 +00:00
private _finalAdjustVector = [_yaw, _roll, _pitch];
TRACE_3("", _pitch, _yaw, _roll);
TRACE_3("", _targetVector, _adjustVector, _finalAdjustVector);
2016-05-30 16:37:03 +00:00
2016-10-12 22:35:24 +00:00
if (accTime > 0) then {
private _changeVector = (vectorDir _projectile) vectorAdd _finalAdjustVector;
TRACE_2("",_projectile,_changeVector);
[_projectile, _changeVector] call FUNC(changeMissileDirection);
};
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
2016-10-12 22:35:24 +00:00
private _ps = "#particlesource" createVehicleLocal (ASLtoAGL _projectilePos);
2016-05-30 16:37:03 +00:00
_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;
#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);