From 44b7b874fd7018cff1c09aae3701415237643ada Mon Sep 17 00:00:00 2001 From: Brandon Danyluk Date: Mon, 19 Apr 2021 01:27:49 -0600 Subject: [PATCH] Add SDB and JDAM --- addons/missileguidance/ACE_GuidanceConfig.hpp | 16 +++++ addons/missileguidance/XEH_PREP.hpp | 5 ++ addons/missileguidance/XEH_pre_init.sqf | 18 ++++-- .../functions/fnc_attackProfile_JDAM.sqf | 58 +++++++++++++++++++ .../functions/fnc_gps_attackOnFired.sqf | 23 ++++++++ .../functions/fnc_gps_confirm.sqf | 2 +- .../functions/fnc_gps_getAttackData.sqf | 24 ++++++++ .../functions/fnc_gps_modeSelect.sqf | 4 +- .../functions/fnc_gps_onLoad.sqf | 4 +- .../functions/fnc_gps_seekerOnFired.sqf | 20 +++++++ .../functions/fnc_seekerType_GPS.sqf | 28 +++++++++ addons/missileguidance/script_component.hpp | 2 +- addons/sdb/$PBOPREFIX$ | 1 + addons/sdb/CfgAmmo.hpp | 37 ++++++++++++ addons/sdb/CfgMagazines.hpp | 17 ++++++ addons/sdb/CfgWeapons.hpp | 12 ++++ addons/sdb/README.md | 12 ++++ addons/sdb/config.cpp | 20 +++++++ addons/sdb/script_component.hpp | 18 ++++++ 19 files changed, 310 insertions(+), 11 deletions(-) create mode 100644 addons/missileguidance/functions/fnc_attackProfile_JDAM.sqf create mode 100644 addons/missileguidance/functions/fnc_gps_attackOnFired.sqf create mode 100644 addons/missileguidance/functions/fnc_gps_getAttackData.sqf create mode 100644 addons/missileguidance/functions/fnc_gps_seekerOnFired.sqf create mode 100644 addons/missileguidance/functions/fnc_seekerType_GPS.sqf create mode 100644 addons/sdb/$PBOPREFIX$ create mode 100644 addons/sdb/CfgAmmo.hpp create mode 100644 addons/sdb/CfgMagazines.hpp create mode 100644 addons/sdb/CfgWeapons.hpp create mode 100644 addons/sdb/README.md create mode 100644 addons/sdb/config.cpp create mode 100644 addons/sdb/script_component.hpp diff --git a/addons/missileguidance/ACE_GuidanceConfig.hpp b/addons/missileguidance/ACE_GuidanceConfig.hpp index 0960e7fab2..5fc73110ef 100644 --- a/addons/missileguidance/ACE_GuidanceConfig.hpp +++ b/addons/missileguidance/ACE_GuidanceConfig.hpp @@ -55,6 +55,14 @@ class GVAR(AttackProfiles) { functionName = QFUNC(attackProfile_BEAM); onFired = QFUNC(wire_onFired); // since Beam guidance is pretty much the same as Wire guidance, we can reuse this }; + class JDAM { + name = ""; + visualName = ""; + description = ""; + + functionName = QFUNC(attackProfile_JDAM); + onFired = QFUNC(gps_attackOnFired); + } }; class GVAR(SeekerTypes) { @@ -104,6 +112,14 @@ class GVAR(SeekerTypes) { functionName = QFUNC(seekerType_IR); onFired = QFUNC(IR_onFired); }; + class GPS { + name = ""; + visualName = ""; + description = ""; + + functionName = QFUNC(seekerType_GPS); + onFired = QFUNC(gps_seekerOnFired); + }; }; class GVAR(NavigationTypes) { diff --git a/addons/missileguidance/XEH_PREP.hpp b/addons/missileguidance/XEH_PREP.hpp index 65347b45cc..5ec6f2e6e4 100644 --- a/addons/missileguidance/XEH_PREP.hpp +++ b/addons/missileguidance/XEH_PREP.hpp @@ -25,6 +25,7 @@ PREP(attackProfile_LIN); PREP(attackProfile_LOFT); PREP(attackProfile_WIRE); PREP(attackProfile_BEAM); +PREP(attackProfile_JDAM); // Javelin profiles PREP(attackProfile_JAV_DIR); @@ -43,15 +44,18 @@ PREP(seekerType_SACLOS); PREP(seekerType_Doppler); PREP(seekerType_MWR); PREP(seekerType_IR); +PREP(seekerType_GPS); // Attack Profiles OnFired PREP(wire_onFired); +PREP(gps_attackOnFired); // Seeker OnFired PREP(SACLOS_onFired); PREP(doppler_onFired); PREP(mwr_onFired); PREP(IR_onFired); +PREP(gps_seekerOnFired); // Navigation OnFired PREP(proNav_onFired); @@ -67,4 +71,5 @@ PREP(gps_confirm); PREP(gps_modeSelect); PREP(gps_saveAttackSettings); PREP(gps_loadAttackSettings); +PREP(gps_getAttackData); diff --git a/addons/missileguidance/XEH_pre_init.sqf b/addons/missileguidance/XEH_pre_init.sqf index 3c592d09b2..77c88c7ab0 100644 --- a/addons/missileguidance/XEH_pre_init.sqf +++ b/addons/missileguidance/XEH_pre_init.sqf @@ -12,9 +12,9 @@ PREP_RECOMPILE_END; if (isNil QGVAR(enabled)) then { GVAR(enabled) = 2; }; GVAR(gps_currentSettings) = [ - [0, 0, 0], // attack position - -1, // impact angle - -1 // attack heading + [0, 0, 0], // attack position + -1, // impact angle + -1 // attack heading ]; GVAR(gps_pbMode) = 0; @@ -23,9 +23,17 @@ for "_i" from 0 to MAX_PB_MODES do { GVAR(gps_settings) set [_i, GVAR(currentSettings)]; }; -GVAR(mode) = "pb"; +GVAR(gps_mode) = "pb"; +GVAR(debug_enableMissileCamera) = false; +GVAR(debug_drawGuidanceInfo) = true; + +#ifdef DRAW_GUIDANCE_INFO +GVAR(debug_drawGuidanceInfo) = true; +#endif + +#ifdef ENABLE_PROJECTILE_CAMERA GVAR(debug_enableMissileCamera) = true; -GVAR(debug_drawGuidanceInfo) = false; +#endif ADDON = true; diff --git a/addons/missileguidance/functions/fnc_attackProfile_JDAM.sqf b/addons/missileguidance/functions/fnc_attackProfile_JDAM.sqf new file mode 100644 index 0000000000..11e39b848c --- /dev/null +++ b/addons/missileguidance/functions/fnc_attackProfile_JDAM.sqf @@ -0,0 +1,58 @@ +#include "script_component.hpp" +/* + * Author: Brandon (TCVM) + * Attack profile: JDAM + * Glides until attack angle, and then dives in + * + * 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_jdam; + * + * Public: No + */ +params ["_seekerTargetPos", "_args", "_attackProfileStateParams"]; +_args params ["_firedEH", "", "_flightParams", "", "", "_targetData"]; +_firedEH params ["_shooter","","","","","","_projectile"]; +_attackProfileStateParams params ["_gpsData", "_initialProjectileHeight", "_terminal"]; +_gpsData params ["", "_impactAngle", "_attackDirection"]; +_targetData params ["_directionToTarget", "", "_distanceToTarget"]; +_flightParams params ["_pitchRate", "_yawRate"]; + +if (_impactAngle <= 0) then { + _impactAngle = 360; // immediate pitch over to attack +}; + +if (_attackDirection < 0) then { + _attackDirection = direction _projectile; +}; + +private _targetPos = _seekerTargetPos; +if !(_terminal) then { + _targetPos set [2, (_seekerTargetPos select 2) + 500]; + private _timeToGo = ((getPosASL _projectile) distance _targetPos) / vectorMagnitude velocity _projectile; + + private _pitchTime = 0.5 * _pitchRate * _timeToGo; + + private _atMinRotationAngle = _pitchTime <= _impactAngle; + _attackProfileStateParams set [2, _atMinRotationAngle]; + + if (GVAR(debug_drawGuidanceInfo)) then { + _attackProfileName = format ["JDAM [%1]", _pitchTime]; + }; +}; + +if (GVAR(debug_drawGuidanceInfo)) then { + private _desiredAngle = [5000, 180 + _attackDirection, _impactAngle] call CBA_fnc_polar2vect; + private _projectilePosAGL = ASLtoAGL _seekerTargetPos; + drawLine3D [_projectilePosAGL, _projectilePosAGL vectorAdd _desiredAngle, [1, 0, 0, 1]]; +}; + +_targetPos; + diff --git a/addons/missileguidance/functions/fnc_gps_attackOnFired.sqf b/addons/missileguidance/functions/fnc_gps_attackOnFired.sqf new file mode 100644 index 0000000000..fd633c324d --- /dev/null +++ b/addons/missileguidance/functions/fnc_gps_attackOnFired.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +/* + * Author: Brandon (TCVM) + * Sets up wireGuided state arrays (called from missileGuidance's onFired). + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * None + * + * Example: + * [] call ace_missileguidance_fnc_wire_onFired + * + * Public: No + */ +params ["_firedEH", "", "", "", "_stateParams", "", ""]; +_stateParams params ["", "", "_attackProfileStateParams"]; +_firedEH params ["_shooter","","","","_ammo","","_projectile"]; + +_attackProfileStateParams set [0, [] call FUNC(gps_getAttackData)]; +_attackProfileStateParams set [1, (getPosASL _projectile) select 2]; +_attackProfileStateParams set [2, false]; diff --git a/addons/missileguidance/functions/fnc_gps_confirm.sqf b/addons/missileguidance/functions/fnc_gps_confirm.sqf index f259f7d2c6..afc4665fd6 100644 --- a/addons/missileguidance/functions/fnc_gps_confirm.sqf +++ b/addons/missileguidance/functions/fnc_gps_confirm.sqf @@ -14,7 +14,7 @@ * * Public: No */ -if (GVAR(mode) isEqualTo "pb") then { +if (GVAR(gps_mode) isEqualTo "pb") then { [GVAR(gps_pbMode)] call FUNC(gps_saveAttackSettings); }; closeDialog 0; diff --git a/addons/missileguidance/functions/fnc_gps_getAttackData.sqf b/addons/missileguidance/functions/fnc_gps_getAttackData.sqf new file mode 100644 index 0000000000..247e441982 --- /dev/null +++ b/addons/missileguidance/functions/fnc_gps_getAttackData.sqf @@ -0,0 +1,24 @@ +#include "script_component.hpp" +/* + * Author: Brandon (TCVM) + * Returns attack data for GPS guided bomb + * + * Arguments: + * None + * + * Return Value: + * None + * + * Example: + * [] call ace_missileguidance_fnc_gps_getAttackData + * + * Public: No + */ + +if (GVAR(gps_mode) isEqualTo "too") then { + private _target = getPilotCameraTarget (vehicle ACE_PLAYER); + _target params ["_tracking", "_position", "_object"]; + GVAR(gps_currentSettings) set [0, _position] +}; +GVAR(gps_currentSettings) + diff --git a/addons/missileguidance/functions/fnc_gps_modeSelect.sqf b/addons/missileguidance/functions/fnc_gps_modeSelect.sqf index f723335983..bc620b875d 100644 --- a/addons/missileguidance/functions/fnc_gps_modeSelect.sqf +++ b/addons/missileguidance/functions/fnc_gps_modeSelect.sqf @@ -45,12 +45,12 @@ private _selectedColour = [ ctrlSetFocus (_display displayCtrl _mode); if (_mode == GPS_UI_TOO) then { - GVAR(mode) = "too"; + GVAR(gps_mode) = "too"; if !(_onLoad) then { [GVAR(gps_pbMode)] call FUNC(gps_saveAttackSettings); }; } else { - GVAR(mode) = "pb"; + GVAR(gps_mode) = "pb"; [GVAR(gps_pbMode)] call FUNC(gps_loadAttackSettings); }; diff --git a/addons/missileguidance/functions/fnc_gps_onLoad.sqf b/addons/missileguidance/functions/fnc_gps_onLoad.sqf index 0117c216ba..5edff41e4e 100644 --- a/addons/missileguidance/functions/fnc_gps_onLoad.sqf +++ b/addons/missileguidance/functions/fnc_gps_onLoad.sqf @@ -18,7 +18,7 @@ params ["_display"]; uiNamespace setVariable [QGVAR(gpsAttackOptionDisplay), _display]; - private _mode = if (GVAR(mode) isEqualTo "too") then { + private _mode = if (GVAR(gps_mode) isEqualTo "too") then { GPS_UI_TOO } else { GPS_UI_PB @@ -29,7 +29,7 @@ // update current settings GVAR(gps_uiPerFrameHandler) = [{ - if (GVAR(mode) isEqualTo "too") then { + if (GVAR(gps_mode) isEqualTo "too") then { // update coordinates based on TGP position private _target = getPilotCameraTarget (vehicle ACE_PLAYER); _target params ["_tracking", "_position", "_object"]; diff --git a/addons/missileguidance/functions/fnc_gps_seekerOnFired.sqf b/addons/missileguidance/functions/fnc_gps_seekerOnFired.sqf new file mode 100644 index 0000000000..fa6bd8d167 --- /dev/null +++ b/addons/missileguidance/functions/fnc_gps_seekerOnFired.sqf @@ -0,0 +1,20 @@ +#include "script_component.hpp" +/* + * Author: Brandon (TCVM) + * Sets up wireGuided state arrays (called from missileGuidance's onFired). + * + * Arguments: + * Guidance Arg Array + * + * Return Value: + * None + * + * Example: + * [] call ace_missileguidance_fnc_wire_onFired + * + * Public: No + */ +params ["", "", "", "", "_stateParams", "", ""]; +_stateParams params ["", "_seekerStateParams"]; + +_seekerStateParams set [0, [] call FUNC(gps_getAttackData)]; diff --git a/addons/missileguidance/functions/fnc_seekerType_GPS.sqf b/addons/missileguidance/functions/fnc_seekerType_GPS.sqf new file mode 100644 index 0000000000..00941fc851 --- /dev/null +++ b/addons/missileguidance/functions/fnc_seekerType_GPS.sqf @@ -0,0 +1,28 @@ +#include "script_component.hpp" +/* + * Author: Brandon (TCVM) + * Returns GPS position. That's it. + * + * Arguments: + * 1: Guidance Arg Array + * 2: Seeker State + * + * Return Value: + * Position of wanted missile pos relative to the camera direction + * + * Example: + * [] call ace_missileguidance_fnc_seekerType_gps + * + * Public: No + */ +params ["", "_args", "_seekerStateParams"]; +_args params ["", "", "", "", "", "_targetData"]; +(_seekerStateParams select 0) params ["_attackPosition"]; + +_targetData set [0, (getPosASL _projectile) vectorFromTo _attackPosition]; +_targetData set [2, (getPosASL _projectile) distance _attackPosition]; +_targetData set [3, [0, 0, 0]]; +_targetData set [4, [0, 0, 0]]; + +_attackPosition + diff --git a/addons/missileguidance/script_component.hpp b/addons/missileguidance/script_component.hpp index 061e6c6fcb..70c679a1b9 100644 --- a/addons/missileguidance/script_component.hpp +++ b/addons/missileguidance/script_component.hpp @@ -2,7 +2,7 @@ #define COMPONENT_BEAUTIFIED Missile Guidance #include "\z\ace\addons\main\script_mod.hpp" -// #define DRAW_GUIDANCE_INFO + #define DRAW_GUIDANCE_INFO // #define ENABLE_PROJECTILE_CAMERA // #define DEBUG_MODE_FULL #define DISABLE_COMPILE_CACHE diff --git a/addons/sdb/$PBOPREFIX$ b/addons/sdb/$PBOPREFIX$ new file mode 100644 index 0000000000..beebd4b824 --- /dev/null +++ b/addons/sdb/$PBOPREFIX$ @@ -0,0 +1 @@ +z\ace\addons\sdb \ No newline at end of file diff --git a/addons/sdb/CfgAmmo.hpp b/addons/sdb/CfgAmmo.hpp new file mode 100644 index 0000000000..4bf8c383a5 --- /dev/null +++ b/addons/sdb/CfgAmmo.hpp @@ -0,0 +1,37 @@ +class CfgAmmo { + class ammo_Bomb_SDB; + class GVAR(sdb): ammo_Bomb_SDB { + author = "Brandon (TCVM)"; + maneuvrability = 0; // no maneuvrability so that default guidance doesnt work + class ace_missileguidance { + enabled = 1; + + pitchRate = 15; + yawRate = 5; + + canVanillaLock = 0; // Can this default vanilla lock? Only applicable to non-cadet mode + + // Guidance type for munitions + defaultSeekerType = "GPS"; + seekerTypes[] = { "GPS" }; + + defaultSeekerLockMode = "LOBL"; + seekerLockModes[] = { "LOBL" }; + + defaultNavigationType = "ZeroEffortMiss"; + navigationTypes[] = { "ZeroEffortMiss" }; + + seekLastTargetPos = 0; // seek last target position [if seeker loses LOS of target, continue to last known pos] + seekerAngle = 60; // Angle from the shooter's view that can track the missile + seekerAccuracy = 1; // seeker accuracy multiplier + + seekerMinRange = 5; + seekerMaxRange = 4000; // Range from the missile which the seeker can visually search + + // Attack profile type selection + defaultAttackProfile = "JDAM"; + attackProfiles[] = {"JDAM"}; + }; + }; +}; + diff --git a/addons/sdb/CfgMagazines.hpp b/addons/sdb/CfgMagazines.hpp new file mode 100644 index 0000000000..24f08a67b0 --- /dev/null +++ b/addons/sdb/CfgMagazines.hpp @@ -0,0 +1,17 @@ +class CfgMagazines { + class magazine_Bomb_SDB_x1; + class PylonRack_Bomb_SDB_x4; + class GVAR(magazine_bomb_SDB_x1): magazine_Bomb_SDB_x1 { + displayName = "1x GBU-39 [ACE]"; + author = "Brandon (TCVM)"; + ammo = QGVAR(sdb); + }; + + class GVAR(PylonRack_bomb_SDB_x4): PylonRack_Bomb_SDB_x4 { + displayName = "4x GBU-39 [ACE]"; + author = "Brandon (TCVM)"; + ammo = QGVAR(sdb); + pylonWeapon = QGVAR(sdb); + }; +}; + diff --git a/addons/sdb/CfgWeapons.hpp b/addons/sdb/CfgWeapons.hpp new file mode 100644 index 0000000000..e69a475778 --- /dev/null +++ b/addons/sdb/CfgWeapons.hpp @@ -0,0 +1,12 @@ +class CfgWeapons { + class weapon_SDBLauncher; + class GVAR(sdb): weapon_SDBLauncher { + author = "Brandon (TCVM)"; + displayName = "GBU-39 [ACE]"; + magazines[] = { + QGVAR(magazine_bomb_SDB_x1), + QGVAR(PylonRack_bomb_SDB_x4) + }; + }; +}; + diff --git a/addons/sdb/README.md b/addons/sdb/README.md new file mode 100644 index 0000000000..7803e5d4d3 --- /dev/null +++ b/addons/sdb/README.md @@ -0,0 +1,12 @@ +ace_sdb +=================== + +Adds GBU-39 SDB + + +## Maintainers + +The people responsible for merging changes to this component or answering potential questions. + +- [Brandon-TCVM](https://github.com/TheCandianVendingMachine) + diff --git a/addons/sdb/config.cpp b/addons/sdb/config.cpp new file mode 100644 index 0000000000..c3fa764832 --- /dev/null +++ b/addons/sdb/config.cpp @@ -0,0 +1,20 @@ +#include "script_component.hpp" + +class CfgPatches { + class ADDON { + name = COMPONENT_NAME; + units[] = {}; + weapons[] = {}; + requiredVersion = REQUIRED_VERSION; + requiredAddons[] = {"ace_common","ace_missileguidance"}; + author = ECSTRING(common,ACETeam); + authors[] = {"Brandon (TCVM)"}; + url = ECSTRING(main,URL); + VERSION_CONFIG; + }; +}; + +#include "CfgAmmo.hpp" +#include "CfgMagazines.hpp" +#include "CfgWeapons.hpp" + diff --git a/addons/sdb/script_component.hpp b/addons/sdb/script_component.hpp new file mode 100644 index 0000000000..310911b691 --- /dev/null +++ b/addons/sdb/script_component.hpp @@ -0,0 +1,18 @@ +#define COMPONENT sdb +#define COMPONENT_BEAUTIFIED Small Diameter Bomb +#include "\z\ace\addons\main\script_mod.hpp" + +// #define DEBUG_MODE_FULL +// #define DISABLE_COMPILE_CACHE +// #define ENABLE_PERFORMANCE_COUNTERS + +#ifdef DEBUG_ENABLED_SDB + #define DEBUG_MODE_FULL +#endif + +#ifdef DEBUG_SETTINGS_SDB + #define DEBUG_SETTINGS DEBUG_SETTINGS_SDB +#endif + +#include "\z\ace\addons\main\script_macros.hpp" +