Skip to content

Commit

Permalink
Pike - Laser guided 40mm grenade (acemod#6731)
Browse files Browse the repository at this point in the history
Co-authored-by: Jouni Järvinen <[email protected]>
  • Loading branch information
2 people authored and PlayerBotPro committed Jan 14, 2025
1 parent 8168c85 commit f8c7bdb
Show file tree
Hide file tree
Showing 27 changed files with 689 additions and 204 deletions.
3 changes: 3 additions & 0 deletions addons/artillerytables/functions/fnc_firedEH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ if (_newMuzzleVelocityCoefficent != 1) then {

if (_airFriction > 0) exitWith {}; // positive value indicates it has vanilla airFriction, so we can just exit

// For compatiblity with other addons
_projectile setVariable [QGVAR(kFactor), _kFactor];

[{
params ["_projectile", "_kFactor", "_time"];

Expand Down
1 change: 1 addition & 0 deletions addons/missile_clgp/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\ace\addons\missile_clgp
Empty file.
89 changes: 89 additions & 0 deletions addons/missile_clgp/CfgAmmo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
class CfgAmmo {
class SubmunitionBase;



class GVAR(pike_launch): SubmunitionBase {
model = QPATHTOF(data\ace_pike_ammo.p3d);
submunitionAmmo = QGVAR(pike_guidance);
submunitionCount = 1;
submunitionConeAngle = 0;
triggerTime = 0.1;
class Eventhandlers {
fired = QUOTE(call FUNC(submunition_ammoFired));
};
};

class MissileBase;
class GVAR(pike_guidance): MissileBase {
irLock = 0;
laserLock = 0;
airLock = 0;
manualControl = 0;
timeToLive = 22;

model = QPATHTOF(data\ace_pike_ammo.p3d);
maxSpeed = 150; // ~2km in 15sec
thrust = 19;
thrustTime = 14;
initTime = 0;
airFriction = 0.1;
sideAirFriction = 0.1;

hit = 120;
indirectHit = 10;
indirectHitRange = 10;
warheadName = "HE";

EGVAR(frag,enabled) = 1;
EGVAR(frag,force) = 1;
EGVAR(frag,classes)[] = {QEGVAR(frag,tiny_HD)};
EGVAR(frag,metal) = 200;
EGVAR(frag,charge) = 270; // ~8x a normal 40mm
EGVAR(frag,gurney_c) = 2700;
EGVAR(frag,gurney_k) = "1/2";

CraterEffects="ExploAmmoCrater";
explosionEffects="ExploAmmoExplosion";
effectsMissileInit = "";
effectsMissile = "missile2";

SoundSetExplosion[] = {"GrenadeHe_Exp_SoundSet", "GrenadeHe_Tail_SoundSet", "Explosion_Debris_SoundSet"};
soundHit1[] = { "A3\Sounds_F\arsenal\explosives\Grenades\Explosion_gng_grenades_01", 3.1622777, 1, 1500};
soundHit2[] = { "A3\Sounds_F\arsenal\explosives\Grenades\Explosion_gng_grenades_02", 3.1622777, 1, 1500};
soundHit3[] = { "A3\Sounds_F\arsenal\explosives\Grenades\Explosion_gng_grenades_03", 3.1622777, 1, 1500};
soundHit4[] = { "A3\Sounds_F\arsenal\explosives\Grenades\Explosion_gng_grenades_04", 3.1622777, 1, 1500};
multiSoundHit[] = {"soundHit1", 0.25, "soundHit2", 0.25, "soundHit3", 0.25, "soundHit4", 0.25};
whistleDist=16;

// Begin ACE guidance Configs
class ace_missileguidance {
enabled = 2;

pitchRate = 15;
yawRate = 20;

canVanillaLock = 0; // Can this default vanilla lock? Only applicable to non-cadet mode

// Guidance type for munitions
defaultSeekerType = "SALH";
seekerTypes[] = {"SALH"};

defaultSeekerLockMode = "LOAL";
seekerLockModes[] = {"LOAL"};

defaultNavigationType = "Direct";
navigationTypes[] = { "Direct" };

seekerAngle = 90; // Angle in front of the missile which can be searched
seekerAccuracy = 1; // seeker accuracy multiplier

seekerMinRange = 1;
seekerMaxRange = 3000; // Range from the missile which the seeker can visually search

// Attack profile type selection
defaultAttackProfile = "LIN";
attackProfiles[] = {"LIN"};
};
};
};
15 changes: 15 additions & 0 deletions addons/missile_clgp/CfgEventhandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
5 changes: 5 additions & 0 deletions addons/missile_clgp/CfgMagazineWells.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class CfgMagazineWells {
class CBA_40mm_EGLM { // for longer grenades that can only fit side breech-loading
ADDON[] = {"ACE_40mm_Pike"};
};
};
15 changes: 15 additions & 0 deletions addons/missile_clgp/CfgMagazines.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class CfgMagazines {
class 1Rnd_HE_Grenade_shell;
class ACE_40mm_Pike: 1Rnd_HE_Grenade_shell {
author = ECSTRING(common,ACETeam);
displayName = CSTRING(pike_magazine_displayName);
displayNameShort = CSTRING(pike_magazine_displayNameShort);
descriptionShort = CSTRING(pike_magazine_descriptionShort);
picture = QPATHTOF(ui\gear_pike_ca.paa);
ammo = QGVAR(pike_launch);
count = 1;
// model = QPATHTOF(data\ace_pike_ammo.p3d); // just use default pouch
initSpeed = 50;
mass = 12; // ~1.7 Pounds, but high density
};
};
Empty file.
Empty file added addons/missile_clgp/GUI.hpp
Empty file.
4 changes: 4 additions & 0 deletions addons/missile_clgp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ace_missile_clgp
===================

Cannon Launched Guided Projectiles
5 changes: 5 additions & 0 deletions addons/missile_clgp/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
LOG("prep");

PREP(submunition_ammoFired);
PREP(submunition_applyDrag);
PREP(submunition_submunitionCreated);
5 changes: 5 additions & 0 deletions addons/missile_clgp/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "script_component.hpp"

#ifdef ENABLE_QUICK_TESTING
call compileScript [QPATHTOF(dev\quickTesting.sqf)];
#endif
9 changes: 9 additions & 0 deletions addons/missile_clgp/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "script_component.hpp"

ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

ADDON = true;
3 changes: 3 additions & 0 deletions addons/missile_clgp/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.hpp"
22 changes: 22 additions & 0 deletions addons/missile_clgp/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_missileguidance"};
author = ECSTRING(common,ACETeam);
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};

#include "ACE_GuidanceConfig.hpp"
#include "CfgAmmo.hpp"
#include "CfgEventhandlers.hpp"
#include "CfgMagazines.hpp"
#include "CfgMagazineWells.hpp"
#include "CfgWeapons.hpp"
#include "GUI.hpp"
Binary file added addons/missile_clgp/data/ace_pike_ammo.p3d
Binary file not shown.
77 changes: 77 additions & 0 deletions addons/missile_clgp/dev/quickTesting.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "..\script_component.hpp"

["recompile", "recompile", "recompile", {
private _start = diag_tickTime;
[] call ACE_PREP_RECOMPILE;
[] call ace_common_fnc_dumpPerformanceCounters;
private _end = diag_tickTime;
systemChat format ["recompile took [%1 ms]", (1000 * (_end - _start)) toFixed 1];

if (productVersion #4 == "Diag") then {
call compile "diag_mergeConfigFile ['P:\z\ace\addons\missile_clgp\config.cpp']";
};
false
}, {false}, [59, [false, false, false]], false] call CBA_fnc_addKeybind; // F1 Key

DFUNC(dev_trackShell) = {
params ["_projectile"];
[{
params ["_projectile", "_time", "_lastVel"];
if (isNull _projectile) exitWith { true };

private _ammo = typeOf _projectile;
if (_ammo isKindOf "SubmunitionBase") then {
private _projectilePos = getPosASL _projectile;
private _forwardPosition = _projectilePos vectorAdd ((vectorNormalized (velocity _projectile)) vectorMultiply 15);
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"];
drawIcon3D ["\a3\ui_f\data\IGUI\Cfg\Cursors\selectover_ca.paa", [0.5,0,1,1], ASLToAGL _forwardPosition, 0.75, 0.75, 0,
format ["V: %1 (%2)", round vectorMagnitude velocity _projectile, round ((velocity _projectile) # 2)], 1, 0.025, "TahomaB"];
drawLine3D [ASLToAGL _projectilePos, ASLToAGL _forwardPosition, [0.5,0,1,1]];
};

private _deltaT = CBA_missionTime - _time;
if (_deltaT < 0.25) exitWith { false };

private _curVelocity = velocity _projectile;
private _avgSpeed = 0.5 * vectorMagnitude (_curVelocity vectorAdd _lastVel);
systemChat format ["Vel %1 (%2)", _curVelocity, _avgSpeed];

private _diff = _curVelocity vectorDiff _lastVel;
_diff = _diff vectorMultiply (1/_deltaT);
_diff = _diff vectorAdd [0,0,GRAVITY];
private _drag = (vectorMagnitude _diff) / ((_avgSpeed max 1) ^ 2);
systemChat format ["Drag %1", (100000 * _drag) toFixed 2];

// systemChat format ["E %1", (GRAVITY * ((getposasl _projectile) # 2)) + (_avgSpeed ^2)];

_this set[1, CBA_missionTime];
_this set[2, _curVelocity];
false
}, {}, [_projectile, CBA_missionTime, velocity _projectile]] call CBA_fnc_waitUntilAndExecute;
};


// ["turret", {
// params ["_player", "_turret"];
// private _veh = vehicle _player;
// if (currentWeapon _veh == "mortar_155mm_AMOS" && {_veh getVariable [QGVAR(needSetup), true]}) then {
// _veh setVariable [QGVAR(needSetup), false];
// systemChat "Setting up...";
// for "_i" from 0 to 9 do { _veh addMagazineTurret ["ace_1rnd_155mm_m712", [0], 1]; };
// _veh loadMagazine [[0], "mortar_155mm_AMOS", "ace_1rnd_155mm_m712"];
// };
// }, true] call CBA_fnc_addPlayerEventHandler;

{
_x addEventHandler ["Fired", {
params ["", "", "", "", "", "", "_projectile"];
_projectile call FUNC(dev_trackShell);
_projectile addEventHandler ["SubmunitionCreated", {
params ["_projectile", "_submunitionProjectile"];
hint format ["sub\n%1\n=%2 %3\n\n%4\n%5 %6",
velocity _projectile, vectorMagnitude velocity _projectile, local _projectile,
velocity _submunitionProjectile, vectorMagnitude velocity _submunitionProjectile, local _submunitionProjectile];
_submunitionProjectile call FUNC(dev_trackShell);
}];
}];
} forEach (vehicles + [player]);
49 changes: 49 additions & 0 deletions addons/missile_clgp/functions/fnc_submunition_ammoFired.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Generic handler for firing a clgp submuntion ammo. Called from the ammo's fired EH.
*
* Arguments:
* FiredEH
*
* Return Value:
* Nothing
*
* Example:
* [] call ace_missile_clgp_fnc_submunition_ammoFired
*
* Public: No
*/

params ["_unit", "", "", "", "_ammo", "", "_projectile", "_gunner"];
if (!local _gunner) exitWith {};
if (isNull _projectile) exitWith {};
TRACE_4("ammoFired local",typeOf _unit,_ammo,_projectile,_gunner);
private _ammoCfg = configOf _projectile;

// Get MissileGuidance args now
private _firedEH = +_this;
// Inject the submunition ammo into guidance args
_firedEH set [4, getText (_ammoCfg >> "submunitionAmmo")];
private _guidanceArgs = _firedEH call EFUNC(missileguidance,onFiredGetArgs);
if (_guidanceArgs isEqualTo []) then { WARNING_1("no args %1",_projectile); };
_projectile setVariable [QGVAR(guidanceArgs), _guidanceArgs];

// On missile deploy start guidance
_projectile addEventHandler ["SubmunitionCreated", LINKFUNC(submunition_submunitionCreated)];

// Trigger ammo when conditions are met
private _deployCondition = getText (_ammoCfg >> QGVAR(deployCondition));
if (_deployCondition != "") then {
_deployCondition = missionNamespace getVariable [_deployCondition, { ERROR("bad func"); true} ];
[{
params ["_projectile", "", "_deployCondition"];
if (isNull _projectile) exitWith { true };
_this call _deployCondition
}, {
params ["_projectile"];
if (isNull _projectile) exitWith { TRACE_1("null at trigger condition %1",_projectile); };
TRACE_1("triggerAmmo",_projectile);
triggerAmmo _projectile;
}, [_projectile, _guidanceArgs, _deployCondition]] call CBA_fnc_waitUntilAndExecute;
};
39 changes: 39 additions & 0 deletions addons/missile_clgp/functions/fnc_submunition_applyDrag.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "..\script_component.hpp"
/*
* Author: PabstMirror
* Applies drag to a missile (based on ace_artillerytables_fnc_firedEH)
*
* Arguments:
* 0: Projectile <OBJECT>
* 1: Drag <NUMBER>
* 2: Last time ran (modified via _this array) <NUMBER>
*
* Return Value:
* None
*
* Example:
* [x, 2, 2] call ace_missile_clgp_fnc_submunition_applyDrag
*
* Public: No
*/

params ["_projectile", "_kFactor", "_time"];

private _bulletVelocity = velocity _projectile;
private _deltaT = CBA_missionTime - _time;
_this set [2, CBA_missionTime];

if (_kFactor != 0) then {
private _trueVelocity = _bulletVelocity vectorDiff wind;
private _trueSpeed = vectorMagnitude _trueVelocity;

private _drag = _deltaT * _kFactor * _trueSpeed;
private _accel = _trueVelocity vectorMultiply _drag;
_bulletVelocity = _bulletVelocity vectorAdd _accel;

_projectile setVelocity _bulletVelocity;
};

private _dir = vectorNormalized _bulletVelocity;
_projectile setVectorDirAndUp [_dir, _dir vectorCrossProduct vectorSide _projectile];
TRACE_2("setVectorDirAndUp",_projectile,_dir);
Loading

0 comments on commit f8c7bdb

Please sign in to comment.