diff --git a/addons/missileguidance/ACE_GuidanceConfig.hpp b/addons/missileguidance/ACE_GuidanceConfig.hpp index 3628c9eec0..131beee339 100644 --- a/addons/missileguidance/ACE_GuidanceConfig.hpp +++ b/addons/missileguidance/ACE_GuidanceConfig.hpp @@ -6,6 +6,11 @@ class GVAR(AttackProfiles) { functionName = QFUNC(attackProfile_LIN); }; + // empty classes for backwards compat + class MID: LIN { + }; + class HI: LIN { + }; class DIR { name = ""; visualName = ""; @@ -13,21 +18,14 @@ class GVAR(AttackProfiles) { functionName = QFUNC(attackProfile_DIR); }; - class MID { + class LOFT { name = ""; visualName = ""; description = ""; - functionName = QFUNC(attackProfile_MID); + functionName = QFUNC(attackProfile_LOFT); }; - class HI { - name = ""; - visualName = ""; - description = ""; - - functionName = QFUNC(attackProfile_HI); - }; - class JAV_DIR { + class JAV_DIR { name = ""; visualName = ""; description = ""; @@ -82,12 +80,39 @@ class GVAR(SeekerTypes) { functionName = QFUNC(seekerType_SACLOS); onFired = QFUNC(SACLOS_onFired); }; - class ARH { + class MillimeterWaveRadar { name = ""; visualName = ""; description = ""; - functionName = QFUNC(seekerType_ARH); - onFired = QFUNC(ahr_onFired); + functionName = QFUNC(seekerType_MWR); + onFired = QFUNC(mwr_onFired); + }; +}; + +class GVAR(NavigationTypes) { + class Direct { + functionName = QFUNC(navigationType_direct); + onFired = ""; + }; + class Line { + functionName = QFUNC(navigationType_line); + onFired = QFUNC(line_onFired); + }; + class LineOfSight { + functionName = QFUNC(navigationType_lineOfSight); + onFired = QFUNC(proNav_onFired); + }; + class ProportionalNavigation { + functionName = QFUNC(navigationType_proNav); + onFired = QFUNC(proNav_onFired); + }; + class AugmentedProportionalNavigation { + functionName = QFUNC(navigationType_augmentedProNav); + onFired = QFUNC(proNav_onFired); + }; + class ZeroEffortMiss { + functionName = QFUNC(navigationType_zeroEffortMiss); + onFired = QFUNC(proNav_onFired); }; }; diff --git a/addons/missileguidance/XEH_PREP.hpp b/addons/missileguidance/XEH_PREP.hpp index 075f2f03c5..d0c6b0af11 100644 --- a/addons/missileguidance/XEH_PREP.hpp +++ b/addons/missileguidance/XEH_PREP.hpp @@ -6,6 +6,8 @@ PREP(changeMissileDirection); PREP(checkSeekerAngle); PREP(checkLos); +PREP(dev_ProjectileCamera); + PREP(onFired); PREP(onIncomingMissile); @@ -16,28 +18,44 @@ PREP(doSeekerSearch); PREP(doHandoff); PREP(handleHandoff); +//re-enable after feature merge - PREP(shouldFilterRadarHit); + // Attack Profiles PREP(attackProfile_AIR); PREP(attackProfile_DIR); -PREP(attackProfile_HI); PREP(attackProfile_LIN); -PREP(attackProfile_MID); +PREP(attackProfile_LOFT); PREP(attackProfile_WIRE); PREP(attackProfile_BEAM); +//re-enable after feature merge - PREP(attackProfile_JDAM); // Javelin profiles PREP(attackProfile_JAV_DIR); PREP(attackProfile_JAV_TOP); +// Navigation Profiles +PREP(navigationType_zeroEffortMiss); +PREP(navigationType_augmentedProNav); +PREP(navigationType_proNav); +PREP(navigationType_lineOfSight); +PREP(navigationType_line); +PREP(navigationType_direct); + // Seeker search functions PREP(seekerType_SALH); PREP(seekerType_Optic); PREP(seekerType_SACLOS); -PREP(seekerType_ARH); +//re-enable after feature merge - PREP(seekerType_Doppler); +PREP(seekerType_MWR); // Attack Profiles OnFired PREP(wire_onFired); // Seeker OnFired PREP(SACLOS_onFired); -PREP(ahr_onFired); +PREP(mwr_onFired); + +// Navigation OnFired +PREP(proNav_onFired); +PREP(line_onFired); + diff --git a/addons/missileguidance/XEH_postInit.sqf b/addons/missileguidance/XEH_postInit.sqf index eb0fb60abf..e0fc98ba1b 100644 --- a/addons/missileguidance/XEH_postInit.sqf +++ b/addons/missileguidance/XEH_postInit.sqf @@ -2,12 +2,10 @@ [QGVAR(handoff), LINKFUNC(handleHandoff)] call CBA_fnc_addEventHandler; -["ACE3 Weapons", QGVAR(cycleFireMode), localize LSTRING(CycleFireMode), -{ +["ACE3 Weapons", QGVAR(cycleFireMode), localize LSTRING(CycleFireMode), { [] call FUNC(cycleAttackProfileKeyDown); false -}, -{ +}, { false }, [15, [false, true, false]], false] call CBA_fnc_addKeybind; //Ctrl+Tab Key diff --git a/addons/missileguidance/XEH_preInit.sqf b/addons/missileguidance/XEH_preInit.sqf index 0798fed2e4..9b1a85e37c 100644 --- a/addons/missileguidance/XEH_preInit.sqf +++ b/addons/missileguidance/XEH_preInit.sqf @@ -11,4 +11,15 @@ PREP_RECOMPILE_END; // As weapons take config changes, there is little point in being able to disable guidance if (isNil QGVAR(enabled)) then { GVAR(enabled) = 2; }; +GVAR(debug_enableMissileCamera) = false; +GVAR(debug_drawGuidanceInfo) = false; + +#ifdef DRAW_GUIDANCE_INFO +GVAR(debug_drawGuidanceInfo) = true; +#endif + +#ifdef ENABLE_PROJECTILE_CAMERA +GVAR(debug_enableMissileCamera) = true; +#endif + ADDON = true; diff --git a/addons/missileguidance/dev/getAmmoProperties.sqf b/addons/missileguidance/dev/getAmmoProperties.sqf new file mode 100644 index 0000000000..9c416c228f --- /dev/null +++ b/addons/missileguidance/dev/getAmmoProperties.sqf @@ -0,0 +1,26 @@ +#include "..\script_component.hpp" + +private _configs = configProperties [configFile >> "CfgAmmo", QUOTE((isClass _x) && { isClass (_x >> QUOTE(QUOTE(ADDON)))})]; + +private _seekerTypes = createHashMap; +private _navigationTypes = createHashMap; +private _attackProfiles = createHashMap; +{ + private _seekerType = getText (_x >> QUOTE(ADDON) >> "defaultSeekerType"); + private _navigationType = getText (_x >> QUOTE(ADDON) >> "defaultNavigationType"); + private _attackProfile = getText (_x >> QUOTE(ADDON) >> "defaultAttackProfile"); + + private _seekers = _seekerTypes getOrDefault [_seekerType, []]; + private _navigations = _navigationTypes getOrDefault [_navigationType, []]; + private _attacks = _attackProfiles getOrDefault [_attackProfile, []]; + + _seekers pushBack configName _x; + _navigations pushBack configName _x; + _attacks pushBack configName _x; + + _seekerTypes set [_seekerType, _seekers]; + _navigationTypes set [_navigationType, _navigations]; + _attackProfiles set [_attackProfile, _attacks]; +} forEach _configs; + +[_seekerTypes, _navigationTypes, _attackProfiles] diff --git a/addons/missileguidance/functions/fnc_SACLOS_onFired.sqf b/addons/missileguidance/functions/fnc_SACLOS_onFired.sqf index 299ec6f236..f48b4a9571 100644 --- a/addons/missileguidance/functions/fnc_SACLOS_onFired.sqf +++ b/addons/missileguidance/functions/fnc_SACLOS_onFired.sqf @@ -32,4 +32,3 @@ _seekerStateParams set [2, _animationSourceGun]; _seekerStateParams set [3, _usePilotCamera || { (_shooter isKindOf "Plane") && hasPilotCamera _shooter }]; if ((_shooter isKindOf "Plane") && !hasPilotCamera _shooter) then { WARNING("SACLOS fired from planes without pilot camera unsupported!"); }; - diff --git a/addons/missileguidance/functions/fnc_attackProfile_BEAM.sqf b/addons/missileguidance/functions/fnc_attackProfile_BEAM.sqf index 5aaff9d7f8..fd86b57104 100644 --- a/addons/missileguidance/functions/fnc_attackProfile_BEAM.sqf +++ b/addons/missileguidance/functions/fnc_attackProfile_BEAM.sqf @@ -17,31 +17,26 @@ * Public: No */ params ["_seekerTargetPos", "_args", "_attackProfileStateParams"]; -_args params ["_firedEH"]; +_args params ["_firedEH", "", "", "", "", "_targetData"]; _firedEH params ["_shooter","","","","","","_projectile"]; -_attackProfileStateParams params["_maxCorrectableDistance", "_wireCut", "_randomVector", "_crosshairOffset", "_seekerMaxRangeSqr", "_seekerMinRangeSqr", "_wireCutSource", "_distanceAheadOfMissile"]; +_attackProfileStateParams params ["_maxCorrectableDistance", "_wireCut", "_lastInput", "_crosshairOffset", "_seekerMaxRangeSqr", "_seekerMinRangeSqr", "_wireCutSource", "_distanceAheadOfMissile"]; private _projectilePos = getPosASL _projectile; private _shooterPos = getPosASL _shooter; -private _shooterDir = vectorNormalized(_seekerTargetPos vectorDiff _shooterPos); private _distanceToProjectile = _shooterPos vectorDistanceSqr _projectilePos; -if (_distanceToProjectile > _seekerMaxRangeSqr || { _seekerTargetPos isEqualTo [0, 0, 0] } || { _distanceToProjectile < _seekerMinRangeSqr }) exitWith { - // return position 50m infront of projectile - _projectilePos vectorAdd (_projectile vectorModelToWorld [0, 50, 0]) +if ((_distanceToProjectile > _seekerMaxRangeSqr) || { _wireCut }) exitWith { + // wire snap, random direction + if !(_wireCut) then { + _attackProfileStateParams set [1, true]; + }; + _lastInput }; -private _relativeCorrection = _projectile vectorWorldToModel (_projectilePos vectorDiff _seekerTargetPos); -_relativeCorrection = _relativeCorrection vectorDiff _crosshairOffset; +private _final = _seekerTargetPos vectorAdd _crosshairOffset; +_attackProfileStateParams set [2, _final]; -private _magnitude = vectorMagnitude [_relativeCorrection select 0, 0, _relativeCorrection select 2]; -private _fovImpulse = 1 min (_magnitude / _maxCorrectableDistance); // the simulated impulse for the missile being close to the center of the crosshair +_targetData set [0, _projectilePos vectorFromTo _final]; -// Adjust the impulse due to near-zero values creating wobbly missiles? -private _correction = _fovImpulse; - - -_relativeCorrection = (vectorNormalized _relativeCorrection) vectorMultiply _correction; -private _returnPos = _projectilePos vectorDiff (_projectile vectorModelToWorld _relativeCorrection); -_returnPos vectorAdd (_shooterDir vectorMultiply _distanceAheadOfMissile) +_final diff --git a/addons/missileguidance/functions/fnc_attackProfile_DIR.sqf b/addons/missileguidance/functions/fnc_attackProfile_DIR.sqf index 80499a85da..d2a2c0616c 100644 --- a/addons/missileguidance/functions/fnc_attackProfile_DIR.sqf +++ b/addons/missileguidance/functions/fnc_attackProfile_DIR.sqf @@ -1,8 +1,8 @@ #include "..\script_component.hpp" /* - * Author: jaynus / nou + * Author: tcvm * Attack profile: DIR - * TODO: falls back to Linear + * Returns target position with no modifications * * Arguments: * 0: Seeker Target PosASL @@ -18,4 +18,5 @@ * Public: No */ -_this call FUNC(attackProfile_LIN); +params ["_seekerTargetPos"]; +_seekerTargetPos diff --git a/addons/missileguidance/functions/fnc_attackProfile_HI.sqf b/addons/missileguidance/functions/fnc_attackProfile_HI.sqf deleted file mode 100644 index 92413f59d0..0000000000 --- a/addons/missileguidance/functions/fnc_attackProfile_HI.sqf +++ /dev/null @@ -1,21 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: jaynus / nou - * Attack profile: HI - * TODO: falls back to Linear - * - * Arguments: - * 0: Seeker Target PosASL - * 1: Guidance Arg Array - * 2: Attack Profile State - * - * Return Value: - * Missile Aim PosASL - * - * Example: - * [[1,2,3], [], []] call ace_missileguidance_fnc_attackProfile_HI; - * - * Public: No - */ - -_this call FUNC(attackProfile_LIN); diff --git a/addons/missileguidance/functions/fnc_attackProfile_LIN.sqf b/addons/missileguidance/functions/fnc_attackProfile_LIN.sqf index e346b16eb6..5462a80a75 100644 --- a/addons/missileguidance/functions/fnc_attackProfile_LIN.sqf +++ b/addons/missileguidance/functions/fnc_attackProfile_LIN.sqf @@ -18,8 +18,10 @@ */ params ["_seekerTargetPos", "_args"]; -_args params ["_firedEH"]; +_args params ["_firedEH", "_launchParams"]; _firedEH params ["_shooter","","","","","","_projectile"]; +_launchParams params ["","_targetLaunchParams"]; +_targetLaunchParams params ["", "", "_launchPos"]; if (_seekerTargetPos isEqualTo [0,0,0]) exitWith {_seekerTargetPos}; @@ -30,27 +32,29 @@ private _distanceToTarget = _projectilePos vectorDistance _seekerTargetPos; private _distanceToShooter = _projectilePos vectorDistance _shooterPos; private _distanceShooterToTarget = _shooterPos vectorDistance _seekerTargetPos; +private _ttgo = _distanceToTarget / (vectorMagnitude velocity _projectile); + TRACE_2("",_distanceToTarget,_distanceToShooter); // Add height depending on distance for compensate private _addHeight = [0,0,0]; -// Always climb an arc on initial launch if we are close to the round -if ((((ASLtoAGL _projectilePos) select 2) < 5) && {_distanceToShooter < 15}) then { - _addHeight = _addHeight vectorAdd [0,0,_distanceToTarget]; - TRACE_1("climb - near shooter",_addHeight); -} else { - // If we are below the target, increase the climbing arc - if (((_projectilePos select 2) < (_seekerTargetPos select 2)) && {_distanceToTarget > 100}) then { - _addHeight = _addHeight vectorAdd [0,0, ((_seekerTargetPos select 2) - (_projectilePos select 2))]; - TRACE_1("climb - below target and far",_addHeight); - }; -}; +private _2dDistance = (800 + (_projectilePos distance2D _launchPos)) / (_projectilePos distance2D _seekerTargetPos); -// Projectile above target -if ((_projectilePos select 2) > (_seekerTargetPos select 2)) then { - TRACE_1("above - far",_addHeight); - _addHeight = _addHeight vectorAdd [0,0, _distanceToTarget / 50]; +if (_2dDistance <= 1) then { + _addHeight = [0, 0, (_projectilePos#2) + 8]; +} else { + // Always climb an arc on initial launch if we are close to the round + if ((((ASLtoAGL _projectilePos) select 2) < 5) && {_distanceToShooter < 15}) then { + _addHeight = _addHeight vectorAdd [0,0,_distanceToTarget]; + TRACE_1("climb - near shooter",_addHeight); + } else { + // If we are below the target, increase the climbing arc + if (((_projectilePos select 2) < (_seekerTargetPos select 2)) && {_distanceToTarget > 100}) then { + _addHeight = _addHeight vectorAdd [0,0, ((_seekerTargetPos select 2) - (_projectilePos select 2))]; + TRACE_1("climb - below target and far",_addHeight); + }; + }; }; private _returnTargetPos = _seekerTargetPos vectorAdd _addHeight; diff --git a/addons/missileguidance/functions/fnc_attackProfile_LOFT.sqf b/addons/missileguidance/functions/fnc_attackProfile_LOFT.sqf new file mode 100644 index 0000000000..1fff2ef8c5 --- /dev/null +++ b/addons/missileguidance/functions/fnc_attackProfile_LOFT.sqf @@ -0,0 +1,53 @@ +#include "..\script_component.hpp" +/* + * Author: jaynus / nou + * Attack profile: AIR + * TODO: falls back to Linear + * + * Arguments: + * 0: Seeker Target PosASL + * 1: Guidance Arg Array + * 2: Seeker State + * + * Return Value: + * Missile Aim PosASL + * + * Example: + * [[1,2,3], [], []] call ace_missileguidance_fnc_attackProfile_AIR; + * + * Public: No + */ + +params ["_seekerTargetPos", "_args"]; +_args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"]; +_firedEH params ["_shooter","","","","_ammo","","_projectile"]; +_launchParams params ["_shooter","_targetLaunchParams","_seekerType","_attackProfile","_lockMode","_laserInfo","_navigationType"]; +_targetLaunchParams params ["_target", "_targetPos", "_launchPos", "_launchDir", "_launchTime"]; +_flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance"]; +_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState","_navigationParams"]; +_seekerParams params ["_seekerAngle", "_seekerAccuracy", "_seekerMaxRange", "_seekerMinRange"]; + +if (_seekerTargetPos isEqualTo [0, 0, 0]) exitWith { + _seekerTargetPos +}; + +private _projectilePos = getPosASLVisual _projectile; +private _distanceToTarget2d = _projectilePos distance2d _seekerTargetPos; + +private _closingRate = vectorMagnitude velocity _projectile; +private _timeToGo = (_projectilePos distance _seekerTargetPos) / _closingRate; + +// we could do stuff like desired attack angle, but I'm not going that far today +private _los = vectorNormalized (_seekerTargetPos vectorDiff _projectilePos); + +private _angleToTarget = acos ((vectorDir _projectile) vectorCos _los); +private _atMinRotationAngle = _angleToTarget >= (0.5 * _pitchRate * _timeToGo); + +private _returnTargetPos = _seekerTargetPos; + +if (!_atMinRotationAngle && _distanceToTarget2d >= 500 && _timeToGo >= 10) then { + // 10 degree pitch up + _returnTargetPos = _seekerTargetPos vectorAdd [0, 0, (_projectilePos distance _seekerTargetPos) * sin 10]; +}; + +_returnTargetPos diff --git a/addons/missileguidance/functions/fnc_attackProfile_MID.sqf b/addons/missileguidance/functions/fnc_attackProfile_MID.sqf deleted file mode 100644 index 2ca9eef77f..0000000000 --- a/addons/missileguidance/functions/fnc_attackProfile_MID.sqf +++ /dev/null @@ -1,21 +0,0 @@ -#include "..\script_component.hpp" -/* - * Author: jaynus / nou - * Attack profile: MID - * TODO: falls back to Linear - * - * Arguments: - * 0: Seeker Target PosASL - * 1: Guidance Arg Array - * 2: Attack Profile State - * - * Return Value: - * Missile Aim PosASL - * - * Example: - * [[1,2,3], [], []] call ace_missileguidance_fnc_attackProfile_MID; - * - * Public: No - */ - -_this call FUNC(attackProfile_LIN); diff --git a/addons/missileguidance/functions/fnc_attackProfile_WIRE.sqf b/addons/missileguidance/functions/fnc_attackProfile_WIRE.sqf index 443fe1bb97..361b0d8fcf 100644 --- a/addons/missileguidance/functions/fnc_attackProfile_WIRE.sqf +++ b/addons/missileguidance/functions/fnc_attackProfile_WIRE.sqf @@ -17,47 +17,27 @@ * Public: No */ params ["_seekerTargetPos", "_args", "_attackProfileStateParams"]; -_args params ["_firedEH"]; +_args params ["_firedEH", "", "", "", "", "_targetData"]; _firedEH params ["_shooter","","","","","","_projectile"]; -_attackProfileStateParams params["_maxCorrectableDistance", "_wireCut", "_randomVector", "_crosshairOffset", "_seekerMaxRangeSqr", "_seekerMinRangeSqr", "_wireCutSource", "_distanceAheadOfMissile"]; +_attackProfileStateParams params ["_maxCorrectableDistance", "_wireCut", "_lastInput", "_crosshairOffset", "_seekerMaxRangeSqr", "_seekerMinRangeSqr", "_wireCutSource", "_distanceAheadOfMissile"]; private _projectilePos = getPosASL _projectile; private _shooterPos = getPosASL _shooter; -private _shooterDir = vectorNormalized(_seekerTargetPos vectorDiff _shooterPos); private _distanceToProjectile = _shooterPos vectorDistanceSqr _projectilePos; if ((_distanceToProjectile > _seekerMaxRangeSqr) || { _wireCut }) exitWith { // wire snap, random direction - if (_randomVector isEqualTo [0, 0, 0]) then { - _randomVector = RANDOM_VECTOR_3D vectorMultiply 300; + if !(_wireCut) then { _attackProfileStateParams set [1, true]; - _attackProfileStateParams set [2, _randomVector]; - playSound3D ["a3\sounds_f\air\sfx\SL_rope_break.wss", objNull, false, AGLtoASL (_shooter modelToWorld _wireCutSource), 5, 1, 150]; }; - _projectilePos vectorAdd _randomVector + _lastInput }; -if (_seekerTargetPos isEqualTo [0, 0, 0] || { _distanceToProjectile < _seekerMinRangeSqr }) exitWith { - // cut wire if its caught on terrain - /*if (lineIntersectsSurfaces [getPosASL _shooter, _projectilePos, _shooter] isNotEqualTo []) then { - _attackProfileStateParams set [1, true]; - };*/ - // return position 50m infront of projectile - _projectilePos vectorAdd (_projectile vectorModelToWorld [0, 50, 0]) -}; +private _final = _seekerTargetPos vectorAdd _crosshairOffset; +_attackProfileStateParams set [2, _final]; -private _relativeCorrection = _projectile vectorWorldToModel (_projectilePos vectorDiff _seekerTargetPos); -_relativeCorrection = _relativeCorrection vectorDiff _crosshairOffset; +_targetData set [0, _projectilePos vectorFromTo _final]; -private _magnitude = vectorMagnitude [_relativeCorrection select 0, 0, _relativeCorrection select 2]; -private _fovImpulse = 1 min (_magnitude / _maxCorrectableDistance); // the simulated impulse for the missile being close to the center of the crosshair - -// Adjust the impulse due to near-zero values creating wobbly missiles? -private _correction = _fovImpulse; - - -_relativeCorrection = (vectorNormalized _relativeCorrection) vectorMultiply _correction; -private _returnPos = _projectilePos vectorDiff (_projectile vectorModelToWorld _relativeCorrection); -_returnPos vectorAdd (_shooterDir vectorMultiply _distanceAheadOfMissile) +_final diff --git a/addons/missileguidance/functions/fnc_changeMissileDirection.sqf b/addons/missileguidance/functions/fnc_changeMissileDirection.sqf index 21884c1693..f9a2493955 100644 --- a/addons/missileguidance/functions/fnc_changeMissileDirection.sqf +++ b/addons/missileguidance/functions/fnc_changeMissileDirection.sqf @@ -16,10 +16,9 @@ * Public: No */ -params ["_projectile", "_v"]; +params ["_projectile", "_pitch", "_yaw", "_roll"]; -private _l = sqrt ((_v select 0) ^ 2 + (_v select 1) ^ 2); -private _r = -(_v select 2) / _l; +private _dir = [sin _yaw * cos _pitch, cos _yaw * cos _pitch, sin _pitch]; +private _up = [[sin _roll, -sin _pitch, cos _roll * cos _pitch], -_yaw] call BIS_fnc_rotateVector2D; -_projectile setVectorDirAndUp [ _v, [(_v select 0) * _r,(_v select 1) * _r, _l] ]; -_projectile setVelocity (_v vectorMultiply (vectorMagnitude (velocity _projectile))); +_projectile setVectorDirAndUp [_dir, _up]; diff --git a/addons/missileguidance/functions/fnc_checkLos.sqf b/addons/missileguidance/functions/fnc_checkLos.sqf index 1fadc5510e..4ec1ebac10 100644 --- a/addons/missileguidance/functions/fnc_checkLos.sqf +++ b/addons/missileguidance/functions/fnc_checkLos.sqf @@ -43,4 +43,3 @@ if (!((terrainIntersectASL [_seekerPos, _targetPos]) && {terrainIntersectASL [_s }; _return - diff --git a/addons/missileguidance/functions/fnc_cycleAttackProfileKeyDown.sqf b/addons/missileguidance/functions/fnc_cycleAttackProfileKeyDown.sqf index 2263716724..f8494e474c 100644 --- a/addons/missileguidance/functions/fnc_cycleAttackProfileKeyDown.sqf +++ b/addons/missileguidance/functions/fnc_cycleAttackProfileKeyDown.sqf @@ -76,7 +76,7 @@ private _nextFireMode = _attackProfiles select _index; TRACE_4("",_currentFireMode,_nextFireMode,_index,_attackProfiles); -private _currentFireMode = if (_useModeForAttackProfile) then { +if (_useModeForAttackProfile) then { TRACE_2("setting fire mode",_weaponStateToken,_nextFireMode); { _x params ["_xIndex", "", "_xWeapon", "", "_xMode"]; diff --git a/addons/missileguidance/functions/fnc_dev_ProjectileCamera.sqf b/addons/missileguidance/functions/fnc_dev_ProjectileCamera.sqf new file mode 100644 index 0000000000..5073709a27 --- /dev/null +++ b/addons/missileguidance/functions/fnc_dev_ProjectileCamera.sqf @@ -0,0 +1,61 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * tracks a projectile until it explodes + * + * Arguments: + * None + * + * Return Value: + * None + * + * Public: No + */ +params ["_projectile"]; + +private _camera = "camera" camCreate getPosATL _projectile; +_camera camPrepareFOV 0.7; +_camera cameraEffect ["internal", "back"]; + +_camera camCommitPrepared 0; + +GVAR(debug_camera_close) = false; +private _displayEH = (findDisplay 46) displayAddEventHandler ["KeyDown", { + params ["_displayorcontrol", "_key", "_shift", "_ctrl", "_alt"]; + GVAR(debug_camera_close) = (_key == 1); + true +}]; + +[{ + params ["_args", "_pfh"]; + _args params ["_projectile", "_camera", "_projectilePos", "_displayEH"]; + if (!alive _projectile || GVAR(debug_camera_close)) exitWith { + private _delay = 1.5; + if (GVAR(debug_camera_close)) then { + _delay = 0; + }; + + (findDisplay 46) displayRemoveEventHandler ["KeyDown", _displayEH]; + + [{ + params ["_camera"]; + + _camera cameraEffect ["terminate", "back"]; + _camera camCommitPrepared 0; + camDestroy _camera; + }, [_camera], _delay] call CBA_fnc_waitAndExecute; + + _camera camPrepareTarget _projectilePos; + _camera camCommitPrepared 0; + + [_pfh] call CBA_fnc_removePerFrameHandler; + }; + + private _currentProjectilePos = getPosATLVisual _projectile; + + _camera camPrepareTarget _projectile; + _camera camPrepareRelPos [0, -5, 1]; + _camera camCommitPrepared 0; + + _args set [2, getPosATL _projectile]; +}, 0, [_projectile, _camera, getPosATL _projectile, _displayEH]] call CBA_fnc_addPerFrameHandler; diff --git a/addons/missileguidance/functions/fnc_doAttackProfile.sqf b/addons/missileguidance/functions/fnc_doAttackProfile.sqf index cafbadf69c..731d18d18d 100644 --- a/addons/missileguidance/functions/fnc_doAttackProfile.sqf +++ b/addons/missileguidance/functions/fnc_doAttackProfile.sqf @@ -22,7 +22,6 @@ _args params ["", "_launchParams"]; _launchParams params ["", "", "", "_attackProfileName"]; private _attackProfileFunction = getText (configFile >> QGVAR(AttackProfiles) >> _attackProfileName >> "functionName"); - private _attackProfilePos = _this call (missionNamespace getVariable _attackProfileFunction); if ((isNil "_attackProfilePos") || {_attackProfilePos isEqualTo [0,0,0]}) exitWith { @@ -30,10 +29,10 @@ if ((isNil "_attackProfilePos") || {_attackProfilePos isEqualTo [0,0,0]}) exitWi [0,0,0] }; -#ifdef DRAW_GUIDANCE_INFO -drawLine3D [(ASLtoAGL _attackProfilePos), (ASLtoAGL _seekerTargetPos), [0,1,1,1]]; -drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0,0,1,1], ASLtoAGL _attackProfilePos, 0.5, 0.5, 0, _attackProfileName, 1, 0.025, "TahomaB"]; -#endif +if (GVAR(debug_drawGuidanceInfo)) then { + drawLine3D [(ASLtoAGL _attackProfilePos), (ASLtoAGL _seekerTargetPos), [0,1,1,1]]; + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0,0,1,1], ASLtoAGL _attackProfilePos, 0.5, 0.5, 0, _attackProfileName, 1, 0.025, "TahomaB"]; +}; TRACE_2("return",_attackProfilePos,_attackProfileName); _attackProfilePos; diff --git a/addons/missileguidance/functions/fnc_doSeekerSearch.sqf b/addons/missileguidance/functions/fnc_doSeekerSearch.sqf index 6008725b4c..b6fd158ce0 100644 --- a/addons/missileguidance/functions/fnc_doSeekerSearch.sqf +++ b/addons/missileguidance/functions/fnc_doSeekerSearch.sqf @@ -30,9 +30,9 @@ if ((isNil "_seekerTargetPos") || {_seekerTargetPos isEqualTo [0,0,0]}) then { / if (_seekLastTargetPos && {_lastKnownPos isNotEqualTo [0,0,0]}) then { // if enabled for the ammo, use last known position if we have one stored TRACE_2("seeker returned bad pos - using last known",_seekLastTargetPos,_lastKnownPos); _seekerTargetPos = _lastKnownPos; - #ifdef DRAW_GUIDANCE_INFO - drawIcon3D ["\A3\ui_f\data\map\markers\military\unknown_CA.paa", [1,1,0,1], ASLtoAGL _lastKnownPos, 0.25, 0.25, 0, "LastKnownPos", 1, 0.02, "TahomaB"]; - #endif + if (GVAR(debug_drawGuidanceInfo)) then { + drawIcon3D ["\A3\ui_f\data\map\markers\military\unknown_CA.paa", [1,1,0,1], ASLtoAGL _lastKnownPos, 0.25, 0.25, 0, "LastKnownPos", 1, 0.02, "TahomaB"]; + }; } else { TRACE_1("seeker returned no pos",_seekerTargetPos); _seekerTargetPos = [0,0,0]; @@ -44,9 +44,9 @@ if ((isNil "_seekerTargetPos") || {_seekerTargetPos isEqualTo [0,0,0]}) then { / }; }; -#ifdef DRAW_GUIDANCE_INFO -drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0,1,0,1], ASLtoAGL _seekerTargetPos, 0.5, 0.5, 0, _seekerTypeName, 1, 0.025, "TahomaB"]; -#endif +if (GVAR(debug_drawGuidanceInfo)) then { + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0,1,0,1], ASLtoAGL _seekerTargetPos, 0.5, 0.5, 0, _seekerTypeName, 1, 0.025, "TahomaB"]; +}; TRACE_2("return",_seekerTargetPos,_seekerTypeName); _seekerTargetPos; diff --git a/addons/missileguidance/functions/fnc_guidancePFH.sqf b/addons/missileguidance/functions/fnc_guidancePFH.sqf index 0620e9e3c0..3c67b4b126 100644 --- a/addons/missileguidance/functions/fnc_guidancePFH.sqf +++ b/addons/missileguidance/functions/fnc_guidancePFH.sqf @@ -15,100 +15,215 @@ * * Public: No */ +#define TRAIL_COLOUR(multiplier) [1 * multiplier, 1 * multiplier, 0.3 * multiplier, 0.7 * multiplier] BEGIN_COUNTER(guidancePFH); -#define TIMESTEP_FACTOR 0.01 - params ["_args", "_pfID"]; -_args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"]; +_args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams", "_targetData", "_navigationStateParams"]; _firedEH params ["_shooter","","","","_ammo","","_projectile"]; -_launchParams params ["","_targetLaunchParams"]; -_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState"]; +_launchParams params ["","_targetLaunchParams","","","","","_navigationType"]; +_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState", "_navigationParameters", "_guidanceParameters"]; +_navigationStateParams params ["_currentState", "_navigationStateData"]; +_flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance", "_stabilityCoefficient", "_showTrail"]; if (!alive _projectile || isNull _projectile || isNull _shooter) exitWith { [_pfID] call CBA_fnc_removePerFrameHandler; END_COUNTER(guidancePFH); }; -private _runtimeDelta = diag_tickTime - _lastRunTime; -private _adjustTime = 1; - -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; +if (_showTrail) then { + drop [ + "\a3\data_f\kouleSvetlo", "", "Billboard", + 100, + 0.03, + _projectile modelToWorld [0, 0, 0], + [0, 0, 0], + 0, + 1.25, + 1, + 0.05, + [0.5], + [TRAIL_COLOUR(1)], + [0], + 0, + 0, + "", + "", + "", + 0, + false, + -1, + [TRAIL_COLOUR(10000)] + ]; }; -private _minDeflection = ((_flightParams select 0) - ((_flightParams select 0) * _adjustTime)) max 0; -private _maxDeflection = (_flightParams select 1) * _adjustTime; -// private _incDeflection = _flightParams select 2; // todo - -private _projectilePos = getPosASL _projectile; +private _timestep = diag_deltaTime * accTime; // Run seeker function: -private _seekerTargetPos = [[0,0,0], _args, _seekerStateParams, _lastKnownPosState] call FUNC(doSeekerSearch); - +private _seekerTargetPos = [[0,0,0], _args, _seekerStateParams, _lastKnownPosState, _timestep] call FUNC(doSeekerSearch); // Run attack profile function: -private _profileAdjustedTargetPos = [_seekerTargetPos, _args, _attackProfileStateParams] call FUNC(doAttackProfile); +_seekerTargetPos = AGLtoASL ASLToAGL _seekerTargetPos; +private _profileAdjustedTargetPos = [_seekerTargetPos, _args, _attackProfileStateParams, _timestep] call FUNC(doAttackProfile); + +private _projectilePos = getPosASLVisual _projectile; +_targetData set [1, _projectilePos vectorFromTo _profileAdjustedTargetPos]; // If we have no seeker target, then do not change anything // 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 { - - 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) ) ); +if ((_pitchRate != 0 || {_yawRate != 0})) then { + private _navigationFunction = getText (configFile >> QGVAR(NavigationTypes) >> _navigationType >> "functionName"); + if (_navigationStateData isNotEqualTo []) then { + (_navigationStateData select _currentState) params ["_transitionCondition"]; + private _transition = (_args call (missionNamespace getVariable [_transitionCondition, { false }])); + if (_transition) then { + _currentState = _currentState + 1; + _navigationStateParams set [0, _currentState]; }; - }; - if (_adjustVectorY < 0) then { - _roll = - ( (_minDeflection max ((abs _adjustVectorY) min _maxDeflection) ) ); - } else { - if (_adjustVectorY > 0) then { - _roll = ( (_minDeflection max (_adjustVectorY min _maxDeflection) ) ); - }; - }; - if (_adjustVectorZ < 0) then { - _pitch = - ( (_minDeflection max ((abs _adjustVectorZ) min _maxDeflection) ) ); - } else { - if (_adjustVectorZ > 0) then { - _pitch = ( (_minDeflection max (_adjustVectorZ min _maxDeflection) ) ); - }; - }; - private _finalAdjustVector = [_yaw, _roll, _pitch]; - TRACE_3("",_pitch,_yaw,_roll); - TRACE_3("",_targetVector,_adjustVector,_finalAdjustVector); + _navigationType = (_navigationStateData select _currentState) select 1; + _navigationFunction = getText (configFile >> QGVAR(NavigationTypes) >> _navigationType >> "functionName"); - if (accTime > 0) then { - private _changeVector = (vectorDir _projectile) vectorAdd _finalAdjustVector; - TRACE_2("",_projectile,_changeVector); - [_projectile, _changeVector] call FUNC(changeMissileDirection); + _navigationParameters = (_navigationStateData select _currentState) select 2; + _stateParams set [4, _navigationParameters]; }; + private _commandedAcceleration = [_args, _timestep, _seekerTargetPos, _profileAdjustedTargetPos, _targetData, _navigationParameters] call (missionNamespace getVariable _navigationFunction); + + if (isNil "_commandedAcceleration") exitWith { + systemChat format ["Error in %1 Missile Type %2 Seeker Pos %3", _navigationFunction, typeOf _projectile, _seekerTargetPos]; + ERROR_MSG_3("_commandedAcceleration is nil! Guidance cancelled [%1 %2 %3]",_navigationFunction,typeOf _projectile,_seekerTargetPos); + }; + + if (GVAR(debug_drawGuidanceInfo)) then { + private _projectilePosAGL = ASLToAGL _projectilePos; + private _cmdAccelLocal = _projectile vectorWorldToModelVisual _commandedAcceleration; + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], _projectilePosAGL vectorAdd [0, 0, 1], 0.75, 0.75, 0, format ["cmdPitch: %1 cmdYaw %2", _cmdAccelLocal#2, _cmdAccelLocal#0], 1, 0.025, "TahomaB"]; + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,1,0,1], _projectilePosAGL vectorAdd [0, 0, 2], 0.75, 0.75, 0, _navigationType, 1, 0.025, "TahomaB"]; + drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd _commandedAcceleration, [1, 0, 1, 1]]; + }; + + // activate missile servos and change direction + if (!isGamePaused && accTime > 0) then { + _guidanceParameters params ["_yaw", "_roll", "_pitch"]; + + _commandedAcceleration = _projectile vectorWorldToModelVisual _commandedAcceleration; + _commandedAcceleration params ["_yawChange", "", "_pitchChange"]; + + if (isNil "_yawChange") then { + _yawChange = 0; + }; + if (isNil "_pitchChange") then { + _pitchChange = 0; + }; + + private _clampedPitch = (_pitchChange min _pitchRate) max -_pitchRate; + private _clampedYaw = (_yawChange min _yawRate) max -_yawRate; + + // controls are either on or off, no proportional + if (_isBangBangGuidance) then { + private _pitchSign = if (_clampedPitch == 0) then { + 0 + } else { + _clampedPitch / abs _clampedPitch + }; + private _yawSign = if (_clampedYaw == 0) then { + 0 + } else { + _clampedYaw / abs _clampedYaw + }; + _clampedPitch = _pitchSign * _pitchRate; + _clampedYaw = _yawSign * _yawRate; + }; + + TRACE_9("pitch/yaw/roll",_pitch,_yaw,_roll,_yawChange,_pitchChange,_pitchRate,_yawRate,_clampedPitch,_clampedYaw); + // directional stability + private _localVelocity = _projectile vectorWorldToModelVisual (velocity _projectile); + + private _velocityAngleYaw = (_localVelocity#0) atan2 (_localVelocity#1); + private _velocityAnglePitch = (_localVelocity#2) atan2 (_localVelocity#1); + + // bastardized version of direction stability https://en.wikipedia.org/wiki/Directional_stability#Steering_forces + private _forceYaw = _stabilityCoefficient * _velocityAngleYaw + _clampedYaw; + private _forcePitch = _stabilityCoefficient * _velocityAnglePitch + _clampedPitch; + + _pitch = _pitch + _forcePitch * _timestep; + _yaw = _yaw + _forceYaw * _timestep; + + TRACE_3("new pitch/yaw/roll",_pitch,_yaw,_roll); + + private _multiplyQuat = { + params ["_qLHS", "_qRHS"]; + _qLHS params ["_lhsX", "_lhsY", "_lhsZ", "_lhsW"]; + _qRHS params ["_rhsX", "_rhsY", "_rhsZ", "_rhsW"]; + + private _lhsImaginary = [_lhsX, _lhsY, _lhsZ]; + private _rhsImaginary = [_rhsX, _rhsY, _rhsZ]; + + private _scalar = _lhsW * _rhsW - (_lhsImaginary vectorDotProduct _rhsImaginary); + private _imginary = (_rhsImaginary vectorMultiply _lhsW) vectorAdd (_lhsImaginary vectorMultiply _rhsW) vectorAdd (_lhsImaginary vectorCrossProduct _rhsImaginary); + + _imginary + [_scalar] + }; + + private _multiplyVector = { + params ["_quaternion", "_vector"]; + + private _real = _quaternion#3; + private _imaginary = [ + _quaternion#0, + _quaternion#1, + _quaternion#2 + ]; + + private _vectorReturn = _vector vectorAdd (( + _imaginary vectorCrossProduct ( + (_imaginary vectorCrossProduct _vector) vectorAdd ( + _vector vectorMultiply _real + ) + ) + ) vectorMultiply 2); + + _vectorReturn + }; + + private _quaternion = [0, 0, 0, 1]; + + private _temp = [0, 0, sin (-_yaw / 2), cos (-_yaw / 2)]; + _quaternion = [_quaternion, _temp] call _multiplyQuat; + + _temp = [sin (_pitch / 2), 0, 0, cos (_pitch / 2)]; + _quaternion = [_quaternion, _temp] call _multiplyQuat; + + private _dir = [_quaternion, [0, 1, 0]] call _multiplyVector; + private _up = [_quaternion, [0, 0, 1]] call _multiplyVector; + + _projectile setVectorDirAndUp [_dir, _up]; + + //[_projectile, _pitch, _yaw, 0] call FUNC(changeMissileDirection); + + _guidanceParameters set [0, _yaw]; + _guidanceParameters set [2, _pitch]; + + _stateParams set [5, _guidanceParameters]; + }; + + _stateParams set [4, _navigationParameters]; + _args set [4, _stateParams]; }; -#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"]; +if (GVAR(debug_drawGuidanceInfo)) then { + 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"]; -private _ps = "#particlesource" createVehicleLocal (ASLtoAGL _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; -#endif + if (!isGamePaused && accTime > 0) then { + private _ps = "#particlesource" createVehicleLocal (ASLtoAGL _projectilePos); + _PS setParticleParams [["\A3\Data_f\cl_basic", 8, 3, 1], "", "Billboard", 1, 3.0141, [0, 0, 0], [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; + }; + + drawLine3D [ASLtoAGL _projectilePos, (ASLtoAGL _projectilePos) vectorAdd velocity _projectile, [1, 1, 1, 1]]; +}; _stateParams set [0, diag_tickTime]; END_COUNTER(guidancePFH); - diff --git a/addons/missileguidance/functions/fnc_line_onFired.sqf b/addons/missileguidance/functions/fnc_line_onFired.sqf new file mode 100644 index 0000000000..6093dc2738 --- /dev/null +++ b/addons/missileguidance/functions/fnc_line_onFired.sqf @@ -0,0 +1,35 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Sets up line state arrays (called from missileGuidance's onFired). + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * None + * + * Example: + * [] call ace_missileguidance_fnc_line_onFired + * + * Public: No + */ +params ["_firedEH", "", "", "", "_stateParams"]; +_firedEH params ["","","","","","","_projectile"]; + +private _ammoConfig = configOf _projectile; +private _p = getNumber (_ammoConfig >> QUOTE(ADDON) >> "lineGainP"); +private _d = getNumber (_ammoConfig >> QUOTE(ADDON) >> "lineGainD"); +private _correctionDistance = getNumber (_ammoConfig >> QUOTE(ADDON) >> "correctionDistance"); + +if (_correctionDistance == 0) then { + _correctionDistance = 1; +}; + +private _navigationParams = [ + _p, 0, _d, + 0, + 0, + _correctionDistance +]; +_navigationParams diff --git a/addons/missileguidance/functions/fnc_ahr_onFired.sqf b/addons/missileguidance/functions/fnc_mwr_onFired.sqf similarity index 92% rename from addons/missileguidance/functions/fnc_ahr_onFired.sqf rename to addons/missileguidance/functions/fnc_mwr_onFired.sqf index 0618c046ad..845b81cda6 100644 --- a/addons/missileguidance/functions/fnc_ahr_onFired.sqf +++ b/addons/missileguidance/functions/fnc_mwr_onFired.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [] call ace_missileguidance_fnc_ahr_onFired + * [] call ace_missileguidance_fnc_mwr_onFired * * Public: No */ @@ -38,6 +38,8 @@ private _activeRadarDistance = [_config >> "activeRadarEngageDistance", "NUMBER" private _projectileThrust = [_projectileConfig >> "thrust", "NUMBER", 0] call CBA_fnc_getConfigEntry; private _projectileThrustTime = [_projectileConfig >> "thrustTime", "NUMBER", 0] call CBA_fnc_getConfigEntry; +private _lockTypes = [_config >> "lockableTypes", "ARRAY", ["Air", "LandVehicle", "Ship"]] call CBA_fnc_getConfigEntry; + private _velocityAtImpact = _projectileThrust * _projectileThrustTime; private _timeToActive = 0; if (!isNil "_target" && _velocityAtImpact > 0) then { @@ -70,4 +72,4 @@ _seekerStateParams set [6, false]; _seekerStateParams set [7, [0, 0, 0]]; _seekerStateParams set [8, CBA_missionTime]; _seekerStateParams set [9, isNull _target]; - +_seekerStateParams set [10, _lockTypes]; diff --git a/addons/missileguidance/functions/fnc_navigationType_augmentedProNav.sqf b/addons/missileguidance/functions/fnc_navigationType_augmentedProNav.sqf new file mode 100644 index 0000000000..f8f1e6c0f4 --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_augmentedProNav.sqf @@ -0,0 +1,50 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Determine path for projectile to take in accordance to proportional navigation, takes target acceleration into account + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_augmentedProNav + * + * Public: No + */ +params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos"]; +_args params ["_firedEH", "", "", "", "_stateParams", "_targetData"]; +_firedEH params ["","","","","","","_projectile"]; +_stateParams params ["", "", "", "","_navigationParams"]; +_navigationParams params ["_lastMissileFrame", "_navigationGain"]; +_lastMissileFrame params ["_lastLineOfSight"]; +_targetData params ["_targetDirection", "_attackProfileDirection", "", "_targetVelocity", "_targetAcceleration"]; + +// Proportional navigation implemented via "Fundamentals of proportional navigation" by Stephen Murtaugh and Harry Criel +private _closingVelocity = _targetVelocity vectorDiff velocity _projectile; + +private _targetAccelerationProjected = _attackProfileDirection vectorMultiply (_targetAcceleration vectorDotProduct _attackProfileDirection); +_targetAcceleration = _targetAcceleration vectorDiff _targetAccelerationProjected; + +private _losDelta = (vectorNormalized _attackProfileDirection) vectorDiff (vectorNormalized _lastLineOfSight); +private _losRate = if (_timestep == 0) then { + 0 +} else { + 1 * (vectorMagnitude _losDelta) / _timestep; +}; + +private _lateralAcceleration = _navigationGain * _losRate; +private _commandedAcceleration = _closingVelocity vectorMultiply _lateralAcceleration; +_commandedAcceleration = _commandedAcceleration vectorAdd (_losDelta vectorMultiply (0.5 * _navigationGain * vectorMagnitude _targetAcceleration)); + +// we need acceleration normal to our LOS +private _commandedAccelerationProjected = _attackProfileDirection vectorMultiply (_commandedAcceleration vectorDotProduct _attackProfileDirection); +_commandedAcceleration = _commandedAcceleration vectorDiff _commandedAccelerationProjected; + +if (accTime > 0) then { + _navigationParams set [0, [_seekerTargetPos, _targetVelocity, _attackProfileDirection]]; +}; + +_commandedAcceleration vectorMultiply _timestep diff --git a/addons/missileguidance/functions/fnc_navigationType_direct.sqf b/addons/missileguidance/functions/fnc_navigationType_direct.sqf new file mode 100644 index 0000000000..7b4763b44e --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_direct.sqf @@ -0,0 +1,21 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Points directly toward attack profile positon + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_direct + * + * Public: No + */ +params ["_args", "", "", "_profileAdjustedTargetPos"]; +_args params ["_firedEH"]; +_firedEH params ["","","","","","","_projectile"]; + +_profileAdjustedTargetPos vectorDiff getPosASLVisual _projectile diff --git a/addons/missileguidance/functions/fnc_navigationType_line.sqf b/addons/missileguidance/functions/fnc_navigationType_line.sqf new file mode 100644 index 0000000000..c9a3870c58 --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_line.sqf @@ -0,0 +1,52 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Assumes targetDir is pointing toward line we want to stay on + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_line + * + * Public: No + */ +params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos", "_targetData", "_navigationParams"]; +_args params ["", "", "_flightParams"]; +_targetData params ["", "_targetDir", "_distance"]; +_flightParams params ["_pitchRate", "_yawRate"]; + +_navigationParams params ["_proportionalGain", "", "_derivativeGain", "_lastErrorX", "_lastErrorY", "_correctionDistance"]; +private _relativeTargetDirection = [0, (velocityModelSpace _projectile) select 1, 0] vectorAdd (_projectile vectorWorldToModelVisual (_targetDir vectorMultiply _distance)); + +private _angleX = ((_relativeTargetDirection select 0) atan2 (_relativeTargetDirection select 1)); +private _angleY = ((_relativeTargetDirection select 2) atan2 (_relativeTargetDirection select 1)); + +private _pX = _proportionalGain * _angleX; +private _dX = 0; +if (_timestep > 0) then { + _dX = _derivativeGain * (_angleX - _lastErrorX) / _timestep; +}; + +private _pY = _proportionalGain * _angleY; +private _dY = 0; +if (_timestep > 0) then { + _dY = _derivativeGain * (_angleY - _lastErrorY) / _timestep; +}; + +private _accelerationX = _pX + _dX; +private _accelerationY = _pY + _dY; + +private _commandedAcceleration = [ + _accelerationX, + 0, + _accelerationY +]; + +_navigationParams set [3, _angleX]; +_navigationParams set [4, _angleY]; + +_projectile vectorModelToWorldVisual _commandedAcceleration; diff --git a/addons/missileguidance/functions/fnc_navigationType_lineOfSight.sqf b/addons/missileguidance/functions/fnc_navigationType_lineOfSight.sqf new file mode 100644 index 0000000000..5056d83722 --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_lineOfSight.sqf @@ -0,0 +1,48 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Accelerates toward LOS + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_lineOfSight + * + * Public: No + */ +params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos"]; +_args params ["_firedEH", "", "", "", "_stateParams", "_targetData"]; +_firedEH params ["","","","","","","_projectile"]; +_stateParams params ["", "", "", "","_navigationParams"]; +_navigationParams params ["_onLaunch"]; +_onLaunch params ["_lastLineOfSight"]; +_targetData params ["_targetDirection", "_attackProfileDirection", "", "_targetVelocity", ""]; + +// Semi-proportional navigation implemented via "Fundamentals of proportional navigation" by Stephen Murtaugh and Harry Criel + +// the los rate is tiny, so we multiply by a constant of a power of ten to get more aggressive acceleration +// this is just due to how we measure our LOS delta, the vectors involved are _tiny_ +private _losDelta = _attackProfileDirection vectorDiff _lastLineOfSight; +private _losRate = if (_timestep == 0) then { + 0 +} else { + 10 * (vectorMagnitude _losDelta) / _timestep; +}; + +private _closingVelocity = _targetVelocity vectorDiff (velocity _projectile); + +private _commandedAcceleration = _closingVelocity vectorMultiply _losRate; + +// we need acceleration normal to our LOS +private _commandedAccelerationProjected = _attackProfileDirection vectorMultiply (_commandedAcceleration vectorDotProduct _attackProfileDirection); +_commandedAcceleration = _commandedAcceleration vectorDiff _commandedAccelerationProjected; + +if (accTime > 0) then { + _navigationParams set [0, [_attackProfileDirection]]; +}; + +_targetDirection diff --git a/addons/missileguidance/functions/fnc_navigationType_proNav.sqf b/addons/missileguidance/functions/fnc_navigationType_proNav.sqf new file mode 100644 index 0000000000..45052689b0 --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_proNav.sqf @@ -0,0 +1,46 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Determine path for projectile to take in accordance to proportional navigation + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_proNav + * + * Public: No + */ +params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos"]; +_args params ["_firedEH", "", "", "", "_stateParams", "_targetData"]; +_firedEH params ["","","","","","","_projectile"]; +_stateParams params ["", "", "", "","_navigationParams"]; +_navigationParams params ["_lastMissileFrame", "_navigationGain"]; +_lastMissileFrame params ["_lastLineOfSight"]; +_targetData params ["_targetDirection", "_attackProfileDirection", "", "_targetVelocity", ""]; + +// Proportional navigation implemented via "Fundamentals of proportional navigation" by Stephen Murtaugh and Harry Criel +private _closingVelocity = _targetVelocity vectorDiff velocity _projectile; + +private _losDelta = (vectorNormalized _attackProfileDirection) vectorDiff (vectorNormalized _lastLineOfSight); +private _losRate = if (_timestep == 0) then { + 0 +} else { + 1 * (vectorMagnitude _losDelta) / _timestep; +}; + +private _lateralAcceleration = _navigationGain * _losRate; +private _commandedAcceleration = _closingVelocity vectorMultiply _lateralAcceleration; + +// we need acceleration normal to our LOS +private _commandedAccelerationProjected = _attackProfileDirection vectorMultiply (_commandedAcceleration vectorDotProduct _attackProfileDirection); +_commandedAcceleration = _commandedAcceleration vectorDiff _commandedAccelerationProjected; + +if (accTime > 0) then { + _navigationParams set [0, [_seekerTargetPos, _targetVelocity, _attackProfileDirection]]; +}; + +_commandedAcceleration vectorMultiply _timestep diff --git a/addons/missileguidance/functions/fnc_navigationType_zeroEffortMiss.sqf b/addons/missileguidance/functions/fnc_navigationType_zeroEffortMiss.sqf new file mode 100644 index 0000000000..293bede8bf --- /dev/null +++ b/addons/missileguidance/functions/fnc_navigationType_zeroEffortMiss.sqf @@ -0,0 +1,38 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Determine path for projectile to take in accordance to zero-effort miss pro-nav, takes target acceleration into account. Super deadly + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * Commanded acceleration normal to LOS in world space + * + * Example: + * [] call ace_missileguidance_fnc_navigationType_zeroEffortMiss + * + * Public: No + */ +params ["_args", "_timestep", "_seekerTargetPos", "_profileAdjustedTargetPos"]; +_args params ["_firedEH", "", "", "", "_stateParams", "_targetData"]; +_firedEH params ["","","","","","","_projectile"]; +_stateParams params ["", "", "", "","_navigationParams"]; +_navigationParams params ["", "_navigationGain"]; +_targetData params ["_targetDirection", "_attackProfileDirection", "_targetRange", "_targetVelocity", "_targetAcceleration"]; + +private _vectorToTarget = _attackProfileDirection vectorMultiply _targetRange; +private _closingVelocity = _targetVelocity vectorDiff velocity _projectile; +private _timeToGo = _targetRange / vectorMagnitude _closingVelocity; + +if (_timeToGo == 0) then { + _timeToGo = 0.001; +}; + +private _zeroEffortMiss = _vectorToTarget vectorAdd (_closingVelocity vectorMultiply _timeToGo); +private _zeroEffortMissProjectiled = _attackProfileDirection vectorMultiply (_zeroEffortMiss vectorDotProduct _attackProfileDirection); +private _zeroEffortMissNormal = _zeroEffortMiss vectorDiff _zeroEffortMissProjectiled; + +private _commandedAcceleration = _zeroEffortMissNormal vectorMultiply (_navigationGain / (_timeToGo * _timeToGo)); + +_commandedAcceleration diff --git a/addons/missileguidance/functions/fnc_onFired.sqf b/addons/missileguidance/functions/fnc_onFired.sqf index 1d63d120a9..9cc91f300a 100644 --- a/addons/missileguidance/functions/fnc_onFired.sqf +++ b/addons/missileguidance/functions/fnc_onFired.sqf @@ -19,9 +19,6 @@ params ["_shooter","_weapon","","_mode","_ammo","","_projectile"]; -// Bail on not missile -if !(_ammo isKindOf "MissileBase") exitWith {}; - // Bail if guidance is disabled for this ammo if ((getNumber (configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON) >> "enabled")) != 1) exitWith {}; @@ -44,6 +41,7 @@ private _target = _shooter getVariable [QGVAR(target), nil]; private _targetPos = _shooter getVariable [QGVAR(targetPosition), nil]; private _seekerType = _shooter getVariable [QGVAR(seekerType), nil]; private _attackProfile = _shooter getVariable [QGVAR(attackProfile), nil]; +private _navigationType = _shooter getVariable [QGVAR(navigationType), nil]; if ((getNumber (configFile >> "CfgAmmo" >> _ammo >> QUOTE(ADDON) >> "useModeForAttackProfile")) == 1) then { _attackProfile = getText (configFile >> "CfgWeapons" >> _weapon >> _mode >> QGVAR(attackProfile)) }; @@ -52,7 +50,7 @@ private _lockMode = _shooter getVariable [QGVAR(lockMode), nil]; private _laserCode = _shooter getVariable [QEGVAR(laser,code), ACE_DEFAULT_LASER_CODE]; private _laserInfo = [_laserCode, ACE_DEFAULT_LASER_WAVELENGTH, ACE_DEFAULT_LASER_WAVELENGTH]; -TRACE_6("getVars",_target,_targetPos,_seekerType,_attackProfile,_lockMode,_laserCode); +TRACE_7("getVars",_target,_targetPos,_seekerType,_attackProfile,_lockMode,_laserCode,_navigationType); private _launchPos = getPosASL (vehicle _shooter); @@ -65,6 +63,14 @@ if (isNil "_attackProfile" || {!(_attackProfile in (getArray (_config >> "attack if (isNil "_lockMode" || {!(_lockMode in (getArray (_config >> "seekerLockModes")))}) then { _lockMode = getText (_config >> "defaultSeekerLockMode"); }; +if (isNil "_navigationType" || {!(_navigationType in (getArray (_config >> "navigationTypes")))}) then { + _navigationType = getText (_config >> "defaultNavigationType"); +}; + +if (isNil "_navigationType" || _navigationType isEqualTo "") then { + // most missiles use ProNav by default + _navigationType = "ProportionalNavigation"; +}; // If we didn't get a target, try to fall back on tab locking if (isNil "_target") then { @@ -76,7 +82,7 @@ if (isNil "_target") then { private _canUseLock = getNumber (_config >> "canVanillaLock"); // @TODO: Get vanilla target if (_canUseLock > 0 || difficulty < 1) then { - private _vanillaTarget = cursorTarget; + private _vanillaTarget = missileTarget _projectile; TRACE_1("Using Vanilla Locking",_vanillaTarget); if (!isNil "_vanillaTarget") then { @@ -85,6 +91,7 @@ if (isNil "_target") then { }; }; }; +_targetPos = getPosASLVisual _target; // Array for seek last target position private _seekLastTargetPos = (getNumber ( _config >> "seekLastTargetPos")) == 1; @@ -95,19 +102,66 @@ if (_seekLastTargetPos && {!isNil "_target"}) then { _lastKnownPosState set [1, [0,0,0]]; }; -TRACE_4("Beginning ACE guidance system",_target,_ammo,_seekerType,_attackProfile); +private _navigationParameters = [ + // set up in navigation type onFired function +]; + +// default config values to make sure there is backwards compat +private _pitchRate = 30; +private _yawRate = 30; +private _bangBang = false; +if (isNumber (_config >> "pitchRate")) then { + _pitchRate = getNumber ( _config >> "pitchRate" ); + _yawRate = getNumber ( _config >> "yawRate" ); + _bangBang = (1 == getNumber (_config >> "bangBangGuidance")); +}; + +// How much this projectile likes to stay toward current velocity +private _stabilityCoefficient = getNumber (_config >> "stabilityCoefficient"); + +// show a light trail in flight +private _showTrail = (1 == getNumber (_config >> "showTrail")); + +private _navigationStateSubclass = _config >> "navigationStates"; +private _states = getArray (_navigationStateSubclass >> "states"); + +private _navigationStateData = []; +private _initialState = ""; + +if (_states isNotEqualTo []) then { + _initialState = _states select 0; + { + private _stateClass = _navigationStateSubclass >> _x; + _navigationStateData pushBack [ + getText (_stateClass >> "transitionCondition"), + getText (_stateClass >> "navigationType"), + [] + ]; + } forEach _states; +}; + +private _initialRoll = getNumber (_config >> "initialRoll"); +private _initialYaw = getNumber (_config >> "initialYaw"); +private _initialPitch = getNumber (_config >> "initialPitch"); + +private _yawRollPitch = (vectorDir _projectile) call CBA_fnc_vect2Polar; + +TRACE_5("Beginning ACE guidance system",_target,_ammo,_seekerType,_attackProfile,_navigationType); private _args = [_this, [ _shooter, - [_target, _targetPos, _launchPos], + [_target, _targetPos, _launchPos, vectorDirVisual vehicle _shooter, CBA_missionTime], _seekerType, _attackProfile, _lockMode, - _laserInfo + _laserInfo, + _navigationType ], [ - getNumber ( _config >> "minDeflection" ), - getNumber ( _config >> "maxDeflection" ), - getNumber ( _config >> "incDeflection" ) + _pitchRate, + _yawRate, + _bangBang, + _stabilityCoefficient, + _showTrail ], [ getNumber ( _config >> "seekerAngle" ), @@ -115,37 +169,70 @@ private _args = [_this, getNumber ( _config >> "seekerMaxRange" ), getNumber ( _config >> "seekerMinRange" ) ], - [ diag_tickTime, [], [], _lastKnownPosState] + [ diag_tickTime, [], [], _lastKnownPosState, _navigationParameters, [_initialYaw + (_yawRollPitch select 1), _initialRoll, _initialPitch + (_yawRollPitch select 2)]], + [ + // target data from missile. Must be filled by seeker for navigation to work + [0, 0, 0], // direction to target + [0, 0, 0], // direction to attack profile + 0, // range to target + [0, 0, 0], // target velocity + [0, 0, 0] // target acceleration + ], + [0, _navigationStateData] ]; private _onFiredFunc = getText (configFile >> QGVAR(SeekerTypes) >> _seekerType >> "onFired"); -TRACE_1("",_onFiredFunc); +TRACE_1("seeker on fired",_onFiredFunc); if (_onFiredFunc != "") then { _args call (missionNamespace getVariable _onFiredFunc); }; _onFiredFunc = getText (configFile >> QGVAR(AttackProfiles) >> _attackProfile >> "onFired"); -TRACE_1("",_onFiredFunc); +TRACE_1("attack on fired",_onFiredFunc); if (_onFiredFunc != "") then { _args call (missionNamespace getVariable _onFiredFunc); }; +if (_states isEqualTo []) then { + _onFiredFunc = getText (configFile >> QGVAR(NavigationTypes) >> _navigationType >> "onFired"); + TRACE_1("navigation on fired",_onFiredFunc); + if (_onFiredFunc != "") then { + private _navState = (_args call (missionNamespace getVariable _onFiredFunc)); + (_args select 4) set [4, _navState]; + }; +} else { + { + _onFiredFunc = getText (configFile >> QGVAR(NavigationTypes) >> _x >> "onFired"); + TRACE_1("navigation on fired",_onFiredFunc); + if (_onFiredFunc != "") then { + private _navState = (_args call (missionNamespace getVariable _onFiredFunc)); + (_navigationStateData select _forEachIndex) set [2, _navState]; + }; + } forEach getArray (_config >> "navigationTypes"); +}; + // Run the "onFired" function passing the full guidance args array _onFiredFunc = getText (_config >> "onFired"); -TRACE_1("",_onFiredFunc); +TRACE_1("general on fired",_onFiredFunc); if (_onFiredFunc != "") then { _args call (missionNamespace getVariable _onFiredFunc); }; // Reverse: -// _args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams"]; +// _args params ["_firedEH", "_launchParams", "_flightParams", "_seekerParams", "_stateParams", "_targetData", "_navigationStateData"]; // _firedEH params ["_shooter","","","","_ammo","","_projectile"]; -// _launchParams params ["_shooter","_targetLaunchParams","_seekerType","_attackProfile","_lockMode","_laserInfo"]; -// _targetLaunchParams params ["_target", "_targetPos", "_launchPos"]; -// _stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState"]; +// _launchParams params ["_shooter","_targetLaunchParams","_seekerType","_attackProfile","_lockMode","_laserInfo","_navigationType"]; +// _targetLaunchParams params ["_target", "_targetPos", "_launchPos", "_launchDir", "_launchTime"]; +// _flightParams params ["_pitchRate", "_yawRate", "_isBangBangGuidance"]; +// _stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState", "_navigationParams", "_guidanceParameters"]; // _seekerParams params ["_seekerAngle", "_seekerAccuracy", "_seekerMaxRange", "_seekerMinRange"]; +// _targetData params ["_targetDirection", "_attackProfileDirection", "_targetRange", "_targetVelocity", "_targetAcceleration"]; -[LINKFUNC(guidancePFH), 0, _args ] call CBA_fnc_addPerFrameHandler; +[LINKFUNC(guidancePFH),0, _args ] call CBA_fnc_addPerFrameHandler; + +if (GVAR(debug_enableMissileCamera)) then { + [_projectile] call FUNC(dev_ProjectileCamera); +}; /* Clears locking settings diff --git a/addons/missileguidance/functions/fnc_proNav_onFired.sqf b/addons/missileguidance/functions/fnc_proNav_onFired.sqf new file mode 100644 index 0000000000..c297d3ce59 --- /dev/null +++ b/addons/missileguidance/functions/fnc_proNav_onFired.sqf @@ -0,0 +1,36 @@ +#include "..\script_component.hpp" +/* + * Author: tcvm + * Sets up proportional navigation state arrays (called from missileGuidance's onFired). + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * None + * + * Example: + * [] call ace_missileguidance_fnc_proNav_onFired + * + * Public: No + */ +params ["_firedEH", "", "", "", "_stateParams"]; +_firedEH params ["_shooter","","","","_ammo","","_projectile"]; +_launchParams params ["_shooter","_targetLaunchParams","_seekerType","_attackProfile","_lockMode","_laserInfo","_navigationType"]; +_targetLaunchParams params ["_target", "_targetPos", "_launchPos"]; +_stateParams params ["_lastRunTime", "_seekerStateParams", "_attackProfileStateParams", "_lastKnownPosState"]; +_seekerParams params ["_seekerAngle", "_seekerAccuracy", "_seekerMaxRange", "_seekerMinRange"]; + +private _ammoConfig = configOf _projectile; +private _navigationGain = getNumber (_ammoConfig >> QUOTE(ADDON) >> "navigationGain"); +if (_navigationGain == 0) then { + _navigationGain = 3; +}; + +private _navigationParams = [ + [ // Last Missile Frame + [0, 0, 0] // Last line of sight + ], + _navigationGain // navigation gain of missile. Set in the navigation onFired function +]; +_navigationParams diff --git a/addons/missileguidance/functions/fnc_seekerType_ARH.sqf b/addons/missileguidance/functions/fnc_seekerType_MWR.sqf similarity index 82% rename from addons/missileguidance/functions/fnc_seekerType_ARH.sqf rename to addons/missileguidance/functions/fnc_seekerType_MWR.sqf index 54e487a9a0..df51acdd8c 100644 --- a/addons/missileguidance/functions/fnc_seekerType_ARH.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_MWR.sqf @@ -11,16 +11,16 @@ * Seeker Pos * * Example: - * [] call call ace_missileguidance_fnc_seekerType_ARH; + * [] call call ace_missileguidance_fnc_seekerType_MWR; * * Public: No */ -params ["", "_args", "_seekerStateParams"]; -_args params ["_firedEH", "_launchParams", "", "_seekerParams", "_stateParams"]; +params ["", "_args", "_seekerStateParams", "", "_timestep"]; +_args params ["_firedEH", "_launchParams", "", "_seekerParams", "_stateParams", "_targetData"]; _firedEH params ["_shooter","","","","","","_projectile"]; _launchParams params ["_target","","","",""]; _seekerParams params ["_seekerAngle", "", "_seekerMaxRange"]; -_seekerStateParams params ["_isActive", "_activeRadarEngageDistance", "_timeWhenActive", "_expectedTargetPos", "_lastTargetPollTime", "_shooterHasRadar", "_wasActive", "_lastKnownVelocity", "_lastTimeSeen", "_doesntHaveTarget"]; +_seekerStateParams params ["_isActive", "_activeRadarEngageDistance", "_timeWhenActive", "_expectedTargetPos", "_lastTargetPollTime", "_shooterHasRadar", "_wasActive", "_lastKnownVelocity", "_lastTimeSeen", "_doesntHaveTarget", "_lockTypes"]; if (_isActive || { CBA_missionTime >= _timeWhenActive }) then { if !(_isActive) then { @@ -60,8 +60,7 @@ if (_isActive || { CBA_missionTime >= _timeWhenActive }) then { _seekerBaseRadiusAdjusted = _seekerBaseRadiusAtGround; }; // Look in front of seeker for any targets - private _nearestObjects = nearestObjects [ASLtoAGL _searchPos, ["Air", "LandVehicle", "Ship"], _seekerBaseRadiusAdjusted, false]; - + private _nearestObjects = nearestObjects [ASLtoAGL _searchPos, _lockTypes, _seekerBaseRadiusAdjusted, false]; _nearestObjects = _nearestObjects apply { // I check both Line of Sight versions to make sure that a single bush doesnt make the target lock dissapear but at the same time ensure that this can see through smoke. Should work 80% of the time if ([_projectile, getPosASL _x, _seekerAngle] call FUNC(checkSeekerAngle) && { ([_projectile, _x, true] call FUNC(checkLOS)) || { ([_projectile, _x, false] call FUNC(checkLOS)) } }) then { @@ -74,6 +73,7 @@ if (_isActive || { CBA_missionTime >= _timeWhenActive }) then { // Select closest object to the expected position to be the current radar target if (_nearestObjects isEqualTo []) exitWith { _projectile setMissileTarget objNull; + _seekerStateParams set [3, _searchPos]; _searchPos }; private _closestDistance = _seekerBaseRadiusAtGround; @@ -89,9 +89,9 @@ if (_isActive || { CBA_missionTime >= _timeWhenActive }) then { _projectile setMissileTarget _target; } else { - #ifdef DRAW_GUIDANCE_INFO - _seekerTypeName = "AHR - EXT"; - #endif + if (GVAR(debug_drawGuidanceInfo)) then { + _seekerTypeName = "MWR - EXT"; + }; // External radar homing // if the target is in the remote targets for the side, whoever the donor is will "datalink" the target for the hellfire. private _remoteTargets = listRemoteTargets side _shooter; @@ -104,16 +104,30 @@ if (_isActive || { CBA_missionTime >= _timeWhenActive }) then { }; }; +if (GVAR(debug_drawGuidanceInfo)) then { + drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [1,0,0,1], ASLtoAGL _expectedTargetPos, 0.75, 0.75, 0, "expected target pos", 1, 0.025, "TahomaB"]; +}; + if !(isNull _target) then { private _centerOfObject = getCenterOfMass _target; - private _targetAdjustedPos = _target modelToWorldWorld _centerOfObject; + private _targetAdjustedPos = _target modelToWorldVisualWorld _centerOfObject; _expectedTargetPos = _targetAdjustedPos; - _seekerStateParams set [3, _expectedTargetPos]; _seekerStateParams set [7, velocity _target]; _seekerStateParams set [8, CBA_missionTime]; _seekerStateParams set [9, false]; + + _targetData set [2, _projectile distance _target]; + _targetData set [3, velocity _target]; + + if (_timestep != 0) then { + private _acceleration = ((velocity _target) vectorDiff _lastKnownVelocity) vectorMultiply (1 / _timestep); + _targetData set [4, _acceleration]; + }; }; +_targetData set [0, (getPosASLVisual _projectile) vectorFromTo _expectedTargetPos]; + +_seekerStateParams set [3, _expectedTargetPos]; _launchParams set [0, _target]; _expectedTargetPos diff --git a/addons/missileguidance/functions/fnc_seekerType_Optic.sqf b/addons/missileguidance/functions/fnc_seekerType_Optic.sqf index bac01d05b4..0507bc2c11 100644 --- a/addons/missileguidance/functions/fnc_seekerType_Optic.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_Optic.sqf @@ -17,7 +17,7 @@ */ params ["", "_args"]; -_args params ["_firedEH", "_launchParams", "", "_seekerParams", "_stateParams"]; +_args params ["_firedEH", "_launchParams", "", "_seekerParams", "_stateParams", "_targetData"]; _firedEH params ["","","","","","","_projectile"]; _launchParams params ["", "_targetParams"]; _targetParams params ["_target"]; @@ -25,7 +25,7 @@ _seekerParams params ["_seekerAngle", "", "_seekerMaxRange"]; if (isNil "_target") exitWith {[0,0,0]}; -private _foundTargetPos = aimPos _target; +private _foundTargetPos = _target modelToWorldVisualWorld getCenterOfMass _target; // @TODO: This is seeker LOS and angle checks for LOAL only; LOBL does not need visual private _angleOkay = [_projectile, _foundTargetPos, _seekerAngle] call FUNC(checkSeekerAngle); @@ -40,14 +40,11 @@ TRACE_2("",_angleOkay,_losOkay); if (!_angleOkay || !_losOkay) exitWith {[0,0,0]}; TRACE_2("",_target,_foundTargetPos); -// @TODO: Configurable lead for seekers -private _projectileSpeed = (vectorMagnitude velocity _projectile); private _distanceToTarget = (getPosASL _projectile) vectorDistance _foundTargetPos; -private _eta = _distanceToTarget / _projectileSpeed; -private _adjustDistance = (velocity _target) vectorMultiply _eta; -TRACE_3("leading target",_distanceToTarget,_eta,_adjustDistance); -_foundTargetPos = _foundTargetPos vectorAdd _adjustDistance; +_targetData set [0, (getPosASL _projectile) vectorFromTo _foundTargetPos]; +_targetData set [2, _distanceToTarget]; +_targetData set [3, velocity _target]; TRACE_2("return",_foundTargetPos,(aimPos _target) distance _foundTargetPos); _foundTargetPos; diff --git a/addons/missileguidance/functions/fnc_seekerType_SACLOS.sqf b/addons/missileguidance/functions/fnc_seekerType_SACLOS.sqf index da9549c3ae..1641ff4a7d 100644 --- a/addons/missileguidance/functions/fnc_seekerType_SACLOS.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_SACLOS.sqf @@ -16,13 +16,13 @@ * Public: No */ params ["", "_args"]; -_args params ["_firedEH", "", "", "_seekerParams", "_stateParams"]; +_args params ["_firedEH", "", "", "_seekerParams", "_stateParams", "_targetData"]; _firedEH params ["_shooter","_weapon","","","","","_projectile"]; _seekerParams params ["_seekerAngle"]; _stateParams params ["", "_seekerStateParams"]; _seekerStateParams params ["_memoryPointGunnerOptics", "_animationSourceBody", "_animationSourceGun", "_usePilotCamera"]; -private _shooterPos = AGLToASL (_shooter modelToWorld(_shooter selectionPosition _memoryPointGunnerOptics)); +private _shooterPos = AGLToASL (_shooter modelToWorldVisual (_shooter selectionPosition _memoryPointGunnerOptics)); private _projPos = getPosASL _projectile; private _lookDirection = if !(_shooter isKindOf "CAManBase" || {_shooter isKindOf "StaticWeapon"}) then { @@ -37,8 +37,9 @@ private _lookDirection = if !(_shooter isKindOf "CAManBase" || {_shooter isKindO _shooter vectorModelToWorldVisual getPilotCameraDirection _shooter; }; } else { - private _gBody = -deg(_shooter animationPhase _animationSourceBody); - private _gGun = deg(_shooter animationPhase _animationSourceGun); + // use animationSourcePhase + private _gBody = -deg(_shooter animationSourcePhase _animationSourceBody); + private _gGun = deg(_shooter animationSourcePhase _animationSourceGun); _shooter vectorModelToWorldVisual ([1, _gBody, _gGun] call CBA_fnc_polar2vect); }; _finalLookDirection @@ -58,5 +59,9 @@ if ((_testDotProduct < (cos _seekerAngle)) || {_testIntersections isNotEqualTo [ [0, 0, 0] }; -_shooterPos vectorAdd (_lookDirection vectorMultiply _distanceToProj); +private _returnPos = _shooterPos vectorAdd (_lookDirection vectorMultiply _distanceToProj); +_targetData set [0, _projPos vectorFromTo _returnPos]; +_targetData set [2, _returnPos vectorDistance getPosASLVisual _projectile]; + +_returnPos diff --git a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf index a16c58ce5f..8772d73178 100644 --- a/addons/missileguidance/functions/fnc_seekerType_SALH.sqf +++ b/addons/missileguidance/functions/fnc_seekerType_SALH.sqf @@ -16,17 +16,58 @@ * * Public: No */ +#define MAX_AVERAGES 15 +#define MINIMUM_DISTANCE_UNTIL_NEW_POS 1 -params ["", "_args"]; -_args params ["_firedEH", "_launchParams", "", "_seekerParams"]; +params ["", "_args", "", "", "_timestep"]; +_args params ["_firedEH", "_launchParams", "", "_seekerParams", "", "_targetData"]; _firedEH params ["","","","","","","_projectile"]; _launchParams params ["","","","","","_laserParams"]; -_seekerParams params ["_seekerAngle", "", "_seekerMaxRange"]; +_seekerParams params ["_seekerAngle", "", "_seekerMaxRange", "", ["_lastPositions", []], ["_lastPositionIndex", 0], ["_lastPositionSum", [0, 0, 0]]]; _laserParams params ["_code", "_wavelengthMin", "_wavelengthMax"]; - private _laserResult = [(getPosASL _projectile), (velocity _projectile), _seekerAngle, _seekerMaxRange, [_wavelengthMin, _wavelengthMax], _code, _projectile] call EFUNC(laser,seekerFindLaserSpot); private _foundTargetPos = _laserResult select 0; TRACE_1("Search",_laserResult); -_foundTargetPos; +if (isNil "_foundTargetPos") exitWith { + [0, 0, 0] +}; + +// average out any error from laser jump +private _positionSum = [0, 0, 0]; +{ + _positionSum = _positionSum vectorAdd _x; +} forEach _lastPositions; + +if (_foundTargetPos isNotEqualTo [0, 0, 0]) then { + _lastPositions set [_lastPositionIndex % MAX_AVERAGES, _foundTargetPos]; + _seekerParams set [4, _lastPositions]; + _seekerParams set [5, _lastPositionIndex + 1]; +}; + +private _aproximateVelocity = [0, 0, 0]; +_positionSum = _positionSum vectorAdd _foundTargetPos; +if (MAX_AVERAGES == count _lastPositions) then { + _positionSum = _positionSum vectorMultiply (1 / (1 + count _lastPositions)); + + // if we are within a meter of the previous average, just use the previous average + if (_positionSum distanceSqr _lastPositionSum < MINIMUM_DISTANCE_UNTIL_NEW_POS * MINIMUM_DISTANCE_UNTIL_NEW_POS) then { + _positionSum = _lastPositionSum; + }; + + if (_timestep != 0) then { + _aproximateVelocity = (_positionSum vectorDiff _lastPositionSum) vectorMultiply (1 / _timestep); + }; +} else { + _positionSum = _positionSum vectorMultiply (1 / count _lastPositions); +}; + +_seekerParams set [6, _positionSum]; + +_targetData set [0, (getPosASL _projectile) vectorFromTo _positionSum]; +_targetData set [3, _aproximateVelocity]; + +TRACE_3("laser target found",_foundTargetPos,_positionSum,count _lastPositions); + +_positionSum diff --git a/addons/missileguidance/functions/fnc_wire_onFired.sqf b/addons/missileguidance/functions/fnc_wire_onFired.sqf index 0cfa90ff99..870754c509 100644 --- a/addons/missileguidance/functions/fnc_wire_onFired.sqf +++ b/addons/missileguidance/functions/fnc_wire_onFired.sqf @@ -45,4 +45,3 @@ _attackProfileStateParams set [4, _maxDistanceSqr]; // max distance squared used _attackProfileStateParams set [5, _minDistanceSqr]; _attackProfileStateParams set [6, _wireCutSource]; _attackProfileStateParams set [7, _distanceAheadOfMissile]; - diff --git a/addons/missileguidance/script_component.hpp b/addons/missileguidance/script_component.hpp index 2b43be42f3..2ffb589e77 100644 --- a/addons/missileguidance/script_component.hpp +++ b/addons/missileguidance/script_component.hpp @@ -3,8 +3,9 @@ #include "\z\ace\addons\main\script_mod.hpp" // #define DRAW_GUIDANCE_INFO +// #define ENABLE_PROJECTILE_CAMERA // #define DEBUG_MODE_FULL -// #define DISABLE_COMPILE_CACHE + #define DISABLE_COMPILE_CACHE // #define ENABLE_PERFORMANCE_COUNTERS #ifdef DEBUG_ENABLED_MISSILEGUIDANCE @@ -28,4 +29,3 @@ #define DEFAULT_LEAD_DISTANCE 5 #define ACTIVE_RADAR_POLL_FREQUENCY (1 / 7) #define ACTIVE_RADAR_MINIMUM_SCAN_AREA 30 - diff --git a/docs/wiki/framework/missile-guidance-framework.md b/docs/wiki/framework/missile-guidance-framework.md index ff6859d735..df83559996 100644 --- a/docs/wiki/framework/missile-guidance-framework.md +++ b/docs/wiki/framework/missile-guidance-framework.md @@ -27,10 +27,10 @@ Finally, flight profiles and mechanics for realistic missile simulations are als ## 2. Components -The framework is broken up into 3 major components: Locking Types, Seeker Types and Attack Profiles. In combination, these components build out the entire process of launching, locking and going terminal flight against targets. +The framework is broken up into 3 major components: Navigation Types, Seeker Types and Attack Profiles. In combination, these components build out the entire process of launching, locking and going terminal flight against targets. -#### 2.1 Locking Types -Locking types provide the basic functionality of targeting which will be based to a seeker type, providing target acquisition for seekers. This provides the basic functionality for providing pre-determined targets for a seeker, or allowing the seeker to perform its own target acquisition and locking. Additionally, the seeker may reference back into the locking type in order to re-perform target acquisition. +#### 2.1 Navigation Types +Navigation types define how the missile flies to the designated target. ACE 3 implements the most common ones in use, Proportional Navigation, Augmented Proportional Navigation, and Zero-Effort Miss. These navigation types give an acceleration command to the missile who attempts to satisfy the command by adjusting its pitch and yaw to fly to the target. #### 2.2 Seeker Types Each seeker is generally assumed to be the logic for the seeker head unit within any given munition. Seekers within this framework provide the basic targeting functionality for the entire framework. The locking type will provide a generic target to the seeker, or the seeker may aquire a target on its own. The seeker then provides a target, either an object or a ASL position, which is then passed further into the framework. This target (or position) should be the actual current target position for the missiles flight. Seekers are required to perform all limitations and checks within their systems, although various limitations have been provided in this framework such as LOS FOV, laser guidance, etc. @@ -42,9 +42,9 @@ An attack profile adjusts the current target flight location to create the actua ## 3. How it all ties together -The system is executed in a linear series of calls to each step of the process, and feeding back the return from that step to the next step. Execution is conducted using Locking -> Seeker -> Profile, iteratively every frame of execution. Flight times are adjusted to `accTime` values and FPS lag, giving consistent flight. +The system is executed in a linear series of calls to each step of the process, and feeding back the return from that step to the next step. Execution is conducted using Seeker -> Profile -> Navigation, iteratively every frame of execution. Flight times are adjusted to `accTime` values and FPS lag, giving consistent flight. -On each step of execution, a target specification array `[targetObj, targetPos]` is passed to the locking type, which then will return a possible modified target array. Next, this modified data is passed to the seeker type - which then, in turn, returns a position vector to the current "seeked" target position (ASL). Last, this target position is passed to the attack profile, which then returns an "adjusted attack position" (ASL), which is the location the missile should *currently* be homing on for flight. +On each step of execution, the seeker finds and returns the position of its target (ASL) and, optionally, sets target data specifying the target's direction from the missile, range, velocity and acceleration (if able). Then, this data is passed to the attack profile, which then returns an "adjusted attack position" (ASL), which is the location the missile should *currently* be homing on for flight. Finally, the navigation system processes the seeker's data about the target and returns a "Commanded Acceleration" vector which the missile attempts to satisfy. In the simplest sense, the entire system provides the flight trajectory of the missile homing directly on the "adjusted attack position"; thus, an attack profile would ajust this position to direct the missile. For example, top down attacks return the adjusted attack position high above the target, until entering their terminal stages, which then changes the position to be directly on top of the target - thus "walking the missile" along its flight path and to the impact. @@ -60,28 +60,47 @@ class CfgAmmo { // Begin ACE guidance Configs class ace_missileguidance { - enabled = 1; // Enable missile guidance (0-disabled, 1-enabled) + enabled = 1; // Explicit enabling of the system - minDeflection = 0.00025; // Minimum flap deflection for guidance - maxDeflection = 0.001; // Maximum flap deflection for guidance - incDeflection = 0.0005; // The increment in which deflection adjusts + pitchRate = 30; // How many degrees/second the missile can pitch + yawRate = 30; // How many degrees/second this missile can yaw - canVanillaLock = 0; // Enable vanilla lock, only applicable to non-cadet modes, 'recruit' always uses vanilla locking (0-disabled, 1-enabled) + canVanillaLock = 0; // Can this default vanilla lock? Only applicable to non-cadet mode - defaultSeekerType = "SALH"; // Default seeker type - seekerTypes[] = {"SALH", "LIDAR", "SARH", "Optic", "Thermal", "GPS", "SACLOS", "MCLOS"}; // Seeker types available + // Guidance type for munitions + defaultSeekerType = "SALH"; // Default seeker type + seekerTypes[] = { "SALH", "LIDAR", "SARH", "Optic", "Thermal", "GPS", "SACLOS", "MCLOS" }; - defaultSeekerLockMode = "LOAL"; // Default seeker lock mode - seekerLockModes[] = {"LOAL", "LOBL"}; // Seeker lock modes available + defaultSeekerLockMode = "LOAL"; // Default lock mode + seekerLockModes[] = { "LOAL", "LOBL" }; - seekerAngle = 90; // Angle in front of the missile which can be searched - seekerAccuracy = 1; // Seeker accuracy multiplier + defaultNavigationType = "Direct"; // Default navigation type + navigationTypes[] = { "Direct", "ZeroEffortMiss" }; // Navigation types this missile can use - seekerMinRange = 1; // Minimum range from the missile which the seeker can visually search - seekerMaxRange = 2500; // Maximum from the missile which the seeker can visually search + seekLastTargetPos = 1; // seek last target position [if seeker loses LOS of target, continue to last known pos] + seekerAngle = 70; // Angle in front of the missile which can be searched + seekerAccuracy = 1; // seeker accuracy multiplier - defaultAttackProfile = "LIN"; // Default attack profile - attackProfiles[] = {"LIN", "DIR", "MID", "HI"}; // Attack profiles available + seekerMinRange = 1; // Minimum range from the missile which the seeker can visually search + seekerMaxRange = 8000; // Maximum range from the missile which the seeker can visually search + + // Attack profile type selection + defaultAttackProfile = "hellfire"; // Default attack profile + attackProfiles[] = {"hellfire", "hellfire_hi", "hellfire_lo"}; // Possible attack profiles + + // State machine defining what navigation type to use in this missiles phase + class navigationStates { + class initial { + transitionCondition = "my_fnc_navigationTransition"; // Condition needed to transition to next state + navigationType = "Direct"; // Navigation type to use in this state + }; + class terminal { + transitionCondition = ""; + navigationType = "ZeroEffortMiss"; + }; + // transitions from initial -> termimal + states[] = {"initial", "terminal"}; + }; }; ``` @@ -95,6 +114,7 @@ class ace_missileguidance_seekerTypes { description = ""; // Description functionName = "my_fnc_doSeekerType"; // Function that handles the seeker type + onFired = "my_fnc_onFired"; // Function that runs when the missile is fired using this seeker }; }; ``` @@ -109,6 +129,17 @@ class ace_missileguidance_attackProfiles { description = ""; // Description functionName = "my_fnc_doAttackProfile"; // Function that handles the attack profile + onFired = "my_fnc_onFired"; // Function that runs when missile is fired using this attack profile + }; +}; +``` + +### 4.4 Custom Navigation Type +```cpp +class ace_missileguidance_navigationTypes { + class MyNavigationProfile { + functionName = "my_fnc_navigation"; // Function to run for navigation + onFired = "my_fnc_onFired"; // Function to run when the missile is fired with this navigation type }; }; ```