ACE3/addons/missileguidance/functions/fnc_guidancePFH.sqf

168 lines
7.1 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", "_pidData"];
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
2021-03-27 05:15:29 +00:00
private _projectilePos = getPosASLVisual _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
Implement M47 Dragon (#6773) * abc * Revert "abc" This reverts commit bcb4214bd99bba3fec692efa4dca950323da582d. * Update to current commit * Ports over NouberNou's dragon guidance * Add Dragon model * Make the Dragon CSW capable * Fix bugs regarding argument order * Add Dragon Attack Profile. Change how missileGuidance guidance_pfh works in order to allow for different types of missiles besides continious thrust * Fix bug regarding missile direction. Add official US Army training manual for the dragon for reference purposes * Adjust model to reflect real-life one * Add attackProfile and guidanceProfile onFired functions * Change Dragon "onFired" to reflect missileGuidance changes * Only implementing the Super-Dragon. Remove Tabs. Add new lines to all files. Add string-table. Tweak missile flight dynamics * Add sight description * Fix inheritance issues. Missile damage values tweaked. Fix String Table. Add backblast area. * Add feature wiki page. * Fix picture issues * Remove Dragon manual * add missing semi-colon * Tweak damage values. Fix formatting. Add lazy evaluation where applicable * Disable the ability to switch to the unusable launcher. Convert rvmat numbers to equivalent but more readable numbers. Multiple code fixes. ace_csw required. Formatting fixes. TGA -> PAA. Remove unused comments in missile guidance code * Dragon flight dynamics tweaked. Now assuming there is a booster angle creating wobble. Add a slight delay when the wire breaks to fire all of the service charges * hpp newline fixes. Case sensitivity for model and rvmat references * Update Wiki dependencies * Revert "Update Wiki dependencies" This reverts commit efc298c481d10fc0db32e08ada376f04ac9b3fd5. * fix dependency component * Changed inheritance structure to be more rigid. Remove un-needed config values. Fix script issues regarding positioning and the launchers aliveness * get rid of the optic for the base dragon. fucking bi configs not making sense * Lock non-useable dragon on initialization * Add model.cfg for animations * Fix formatting. Fix M47 Dragon Optic zoom * Change LOD selection names * Revert indentation, keep parenthesis. "Start, stop, start stop! Jesus! I'm starting to think Mattis is just a big cock tease" * Re-update indentation of model.cfg * Path fix. Whitespace fix * Sight attach/detach on same vehicle * If the sight gets detached, make sure the dragon goes dumb. Remove resetting of resting position when gunner gets out - looks stupid, but when the dragon is fired weird stuff happens * disable debug * Add EOF * Maybe finally fix EOF problem
2019-06-08 04:48:37 +00:00
// If there is no deflection on the missile, this cannot change and therefore is redundant. Avoid calculations for missiles without any deflection
if ((_minDeflection != 0 || {_maxDeflection != 0}) && {_profileAdjustedTargetPos isNotEqualTo [0,0,0]}) then {
// Get a commanded acceleration via proportional navigation (https://youtu.be/Osb7anMm1AY)
// Use a simple PID controller to get the desired pitch, yaw, and roll
// Simulate moving servos by moving in each DOF by a fixed amount per frame
// Then setVectorDirAndUp to allow ARMA to translate the velocity to whatever PhysX says
2016-05-30 16:37:03 +00:00
2021-03-27 05:15:29 +00:00
private _rollDegreesPerSecond = 30;
private _yawDegreesPerSecond = 30;
private _pitchDegreesPerSecond = 30;
2016-10-12 22:35:24 +00:00
2021-03-27 05:15:29 +00:00
private _proportionalGain = 1;
private _integralGain = 0;
private _derivativeGain = 0;
2016-10-12 22:35:24 +00:00
2021-03-27 05:15:29 +00:00
_pidData params ["_pid", "_lastTargetDetails", "_lastLineOfSight", "_currentPitchYawRoll"];
_currentPitchYawRoll params ["_pitch", "_yaw", "_roll"];
2021-03-27 05:15:29 +00:00
_lastTargetDetails params ["_lastTargetPosition", "_lastTargetVelocity"];
private _navigationGain = 3;
2021-03-27 05:15:29 +00:00
private _targetVelocity = (_seekerTargetPos vectorDiff _lastTargetPosition) vectorMultiply (1 / TIMESTEP_FACTOR);
private _targetAcceleration = (_targetVelocity vectorDiff _lastTargetVelocity) vectorMultiply (1 / TIMESTEP_FACTOR);
2021-03-27 05:15:29 +00:00
private _lineOfSight = _projectile vectorWorldToModelVisual vectorNormalized (_profileAdjustedTargetPos vectorDiff _projectilePos);
private _losNormal = [(_lineOfSight#2), -(_lineOfSight#0), 0];
2021-03-27 05:15:29 +00:00
private _deltaLOS = _lineOfSight vectorDiff _lastLineOfSight;
private _rotationRate = vectorMagnitude _deltaLOS;
private _closingVelocity = -_rotationRate;
2021-03-27 05:15:29 +00:00
private _lateralAcceleration = _navigationGain * _rotationRate * _closingVelocity;
private _commandedAcceleration = _losNormal vectorMultiply _lateralAcceleration;
//_commandedAcceleration = _commandedAcceleration vectorAdd (_losNormal vectorMultiply (_navigationGain * 0.5 * TIMESTEP_FACTOR * (9.81 + 150)));
2021-03-27 05:15:29 +00:00
//systemChat str vectorMagnitude _targetAcceleration;
TRACE_5("PN", CBA_missionTime, _lineOfSight, _lastLineOfSight, _rotationRate, _deltaLOS);
private _acceleration = [0, 0];
{
(_pid select _forEachIndex) params ["", "_lastDerivative", "_integral"];
// think about this in xz plane where x = yaw, z = pitch
private _commandedAccelerationAxis = _commandedAcceleration select _forEachIndex;
2016-10-12 22:35:24 +00:00
private _proportional = _commandedAccelerationAxis * _proportionalGain;
private _d0 = _commandedAccelerationAxis * _derivativeGain;
2021-03-27 05:15:29 +00:00
private _derivative = (_d0 - _lastDerivative) / TIMESTEP_FACTOR;
2021-03-27 05:15:29 +00:00
_integral = _integral + (_d0 * TIMESTEP_FACTOR * _integralGain);
private _pidSum = _proportional + _integral + _derivative;
(_pid select _forEachIndex) set [1, _d0];
(_pid select _forEachIndex) set [2, _integral];
_acceleration set [_forEachIndex, _pidSum];
} forEach _acceleration;
2016-05-30 16:37:03 +00:00
2021-03-19 05:43:07 +00:00
#ifdef DRAW_GUIDANCE_INFO
TRACE_1("",_acceleration);
private _projectilePosAGL = ASLToAGL _projectilePos;
private _debugAcceleration = [_acceleration#0, 0, _acceleration#1];
2021-03-27 05:15:29 +00:00
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd (_lineOfSight vectorMultiply 15), [1, 0, 0, 1]];
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd (_lastLineOfSight vectorMultiply 5), [0, 1, 0, 1]];
drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd ([_lineOfSight#2, -(_lineOfSight#0), 0] vectorMultiply 5), [0, 0, 1, 1]];
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], [0, 0, 4] vectorAdd ASLtoAGL _projectilePos, 0.75, 0.75, 0, str _rotationRate, 1, 0.025, "TahomaB"];
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], [0, 0, 3] vectorAdd ASLtoAGL _projectilePos, 0.75, 0.75, 0, str vectorMagnitude _targetAcceleration, 1, 0.025, "TahomaB"];
2021-03-19 05:43:07 +00:00
#endif
if (!isGamePaused && accTime > 0) then {
_acceleration params ["_pitchChange", "_yawChange"];
private _clampedPitch = (-_pitchChange min _pitchDegreesPerSecond) max -_pitchDegreesPerSecond;
private _clampedYaw = (_yawChange min _yawDegreesPerSecond) max -_yawDegreesPerSecond;
2021-03-27 05:15:29 +00:00
_pitch = _pitch + _clampedPitch * TIMESTEP_FACTOR;
_yaw = _yaw + _clampedYaw * TIMESTEP_FACTOR;
[_projectile, _pitch, _yaw, 0] call FUNC(changeMissileDirection);
_currentPitchYawRoll set [0, _pitch];
_currentPitchYawRoll set [1, _yaw];
2016-10-12 22:35:24 +00:00
};
_pidData set [0, _pid];
2021-03-27 05:15:29 +00:00
if (accTime > 0) then {
_pidData set [1, [_seekerTargetPos, _targetVelocity]];
};
_pidData set [2, _lineOfSight];
_pidData set [3, _currentPitchYawRoll];
_stateParams set [4, _pidData];
2021-03-27 05:15:29 +00:00
_args set [4, _stateParams];
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 1.0;
2016-05-30 16:37:03 +00:00
#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);