Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projectiles #371

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b6eae57
Added Projectiles modules
ampersand38 May 7, 2020
143da47
Update Authors
ampersand38 May 7, 2020
8674ad2
Sort names
ampersand38 May 7, 2020
f5f0c80
Toggle module doesn't need to attach
ampersand38 May 7, 2020
3fb03aa
Getting functions registered
ampersand38 May 7, 2020
4c73e02
Fixed dup line
ampersand38 May 8, 2020
f64a4c1
Remove ALiVE until dependent on mod loaded
ampersand38 May 8, 2020
7ebd6a5
Add module for Throw Select
ampersand38 May 8, 2020
093fb91
Reliability and performance
ampersand38 May 8, 2020
5692c7b
Corrected example code
ampersand38 May 8, 2020
44b69dc
Separate ballistics function
ampersand38 May 8, 2020
117923e
Name fix
ampersand38 May 8, 2020
fb5d8b8
Clear grenade actions on context menu close
ampersand38 May 8, 2020
cd243ff
Removed and renamed movdules
ampersand38 May 12, 2020
7ab17fa
Tabs to spaces
ampersand38 May 14, 2020
90bda12
Tabs to spaces
ampersand38 May 14, 2020
eb9dd68
Nicer Icons
ampersand38 May 14, 2020
139dd9a
Update config.cpp
ampersand38 Jun 8, 2020
76120e6
Revert "Update config.cpp"
ampersand38 Jun 24, 2020
296f069
Authors
ampersand38 Jun 24, 2020
78f397b
add return
ampersand38 Jun 26, 2020
a4d9a18
Soft launch
ampersand38 Jun 26, 2020
622fc7e
Don't run if position selection is cancelled
ampersand38 Jun 26, 2020
669c713
if condition parens
ampersand38 Jun 29, 2020
1185850
Module List documentation
ampersand38 Aug 11, 2020
1318549
zen_context_menu_fnc_open
ampersand38 Aug 31, 2020
27abc1d
Merge branch 'master' into projectiles
ampersand38 Jul 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Ampersand
3Mydlo3
654wak654
Alganthe
Ampersand
BaerMitUmlaut
Beaumont
Brett
Expand Down
5 changes: 5 additions & 0 deletions addons/modules/CfgFactionClasses.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class CfgFactionClasses {
priority = 2;
side = 7;
};
class GVAR(Projectiles) {
displayName = CSTRING(Projectiles);
priority = 2;
side = 7;
};
class GVAR(Spawn) {
displayName = CSTRING(Spawn);
priority = 2;
Expand Down
21 changes: 21 additions & 0 deletions addons/modules/CfgVehicles.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,27 @@ class CfgVehicles {
displayName = CSTRING(ModulePatrolArea);
function = QFUNC(modulePatrolArea);
};
class GVAR(moduleThrowSelect): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Projectiles);
displayName = CSTRING(moduleThrowSelect);
function = QFUNC(moduleThrowSelect);
icon = "\a3\ui_f\data\gui\rsc\rscdisplayarsenal\cargothrow_ca.paa";
};
class GVAR(moduleFireGL): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Projectiles);
displayName = CSTRING(moduleFireGL);
function = QFUNC(moduleFireGL);
icon = QPATHTOF(ui\ugl_shell_ca.paa);
};
class GVAR(moduleFireLauncher): GVAR(moduleBase) {
curatorCanAttach = 1;
category = QGVAR(Projectiles);
displayName = CSTRING(moduleFireLauncher);
function = QFUNC(moduleFireLauncher);
icon = "\a3\ui_f\data\gui\rsc\rscdisplayarsenal\secondaryweapon_ca.paa";
};
class GVAR(moduleRemoveArsenal): GVAR(moduleBase) {
curatorCanAttach = 1;
category = GVAR(Inventory);
Expand Down
6 changes: 6 additions & 0 deletions addons/modules/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ PREP(moduleEffectFire);
PREP(moduleEffectFireLocal);
PREP(moduleEquipWithECM);
PREP(moduleExportMissionSQF);
PREP(moduleFireGL);
PREP(moduleFireLauncher);
PREP(moduleFireMission);
PREP(moduleFlyHeight);
PREP(moduleFunctionsViewer);
Expand Down Expand Up @@ -81,6 +83,7 @@ PREP(moduleSpawnDestroyer);
PREP(moduleSpawnReinforcements);
PREP(moduleSuicideBomber);
PREP(moduleTeleportPlayers);
PREP(moduleThrowSelect);
PREP(moduleToggleFlashlights);
PREP(moduleToggleIRLasers);
PREP(moduleToggleLamps);
Expand All @@ -89,3 +92,6 @@ PREP(moduleTurretOptics);
PREP(moduleUnGarrison);
PREP(moduleVisibility);
PREP(moduleWeather);
PREP(projectiles_unit);
PREP(projectiles_zeus);
PREP(projectiles_ballisticVector);
4 changes: 4 additions & 0 deletions addons/modules/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class CfgPatches {
QGVAR(moduleEquipWithECM),
QGVAR(moduleExportMissionSQF),
QGVAR(moduleExecuteCode),
QGVAR(moduleFireGL),
QGVAR(moduleFireLauncher),
QGVAR(moduleFireMission),
QGVAR(moduleFlyHeight),
QGVAR(moduleFunctionsViewer),
Expand All @@ -50,6 +52,8 @@ class CfgPatches {
QGVAR(moduleMakeInvincible),
QGVAR(moduleNuke),
QGVAR(modulePatrolArea),
QGVAR(moduleThrowSelect),
QGVAR(moduleThrowBottle),
QGVAR(moduleRemoveArsenal),
QGVAR(moduleRotateObject),
QGVAR(moduleSearchBuilding),
Expand Down
77 changes: 77 additions & 0 deletions addons/modules/functions/fnc_moduleFireGL.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Zeus module function to make unit use GL to fire a HE 40mm.
*
* Arguments:
* 0: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [LOGIC] call zen_modules_fnc_moduleFireGL
*
* Public: No
*/

params ["_logic"];

private _unit = attachedTo _logic;
deleteVehicle _logic;

if (isNull _unit) exitWith {
[LSTRING(NoObjectSelected)] call EFUNC(common,showMessage);
};

if !(_unit isKindOf "Man") exitWith {
[LSTRING(OnlyInfantry)] call EFUNC(common,showMessage);
};

if !(alive _unit) exitWith {
[LSTRING(OnlyAlive)] call EFUNC(common,showMessage);
};

// Check if unit has GL
private _weapons = weapons _unit;
private _glMuzzles = [];
{
private _weapon = _x;
{
private _muzzle = _x;
if (configName inheritsFrom (configFile >> "CfgWeapons" >> _weapon >> _muzzle) isEqualTo "UGL_F") then {
_glMuzzles pushBack [_weapon, _muzzle];
};
} forEach getArray(configFile >> "cfgWeapons" >> _weapon >> "muzzles");
} forEach _weapons;

if (_glMuzzles isEqualTo []) exitWith {
["Unit must have GL"] call EFUNC(common,showMessage);
};

// Get target position
[_unit, {
params ["_successful", "_unit", "_mousePosASL"];
if (_successful) then {
private _weapons = weapons _unit;
private _glMuzzles = [];
{
private _weapon = _x;
{
private _muzzle = _x;
if (configName inheritsFrom (configFile >> "CfgWeapons" >> _weapon >> _muzzle) isEqualTo "UGL_F") then {
_glMuzzles pushBack [_weapon, _muzzle];
};
} forEach getArray(configFile >> "cfgWeapons" >> _weapon >> "muzzles");
} forEach _weapons;

if (_glMuzzles isEqualTo []) exitWith {
[objNull, format ["Unit has no GL: %1", _unit]] call bis_fnc_showCuratorFeedbackMessage;
};

private _magazine = "1Rnd_HE_Grenade_shell";
private _muzzle = _glMuzzles # 0 # 1;
private _firemode = "Single";
[_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus;
};
}, [], LSTRING(ModuleFireGL)] call EFUNC(common,selectPosition);
53 changes: 53 additions & 0 deletions addons/modules/functions/fnc_moduleFireLauncher.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Zeus module function to make unit fire unguided rocket launcher.
*
* Arguments:
* 0: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [LOGIC] call zen_modules_fnc_moduleFireLauncher
*
* Public: No
*/

params ["_logic"];

private _unit = attachedTo _logic;
deleteVehicle _logic;

if (isNull _unit) exitWith {
[LSTRING(NoObjectSelected)] call EFUNC(common,showMessage);
};

if !(_unit isKindOf "Man") exitWith {
[LSTRING(OnlyInfantry)] call EFUNC(common,showMessage);
};

if !(alive _unit) exitWith {
[LSTRING(OnlyAlive)] call EFUNC(common,showMessage);
};

// Check if unit has launcher
private _launcher = secondaryWeapon _unit;
if (_launcher isEqualTo "") exitWith {
["Unit must have launcher"] call EFUNC(common,showMessage);
};

// Get target position
[_unit, {
params ["_successful", "_unit", "_mousePosASL"];
if (_successful) then {
private _weapon = secondaryWeapon _unit;

private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0;

private _muzzle = _weapon;
private _firemode = "Single";
[_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus;
};
}, [], LSTRING(ModuleFireLauncher)] call EFUNC(common,selectPosition);
70 changes: 70 additions & 0 deletions addons/modules/functions/fnc_moduleThrowSelect.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include "script_component.hpp"
/*
* Author: Ampersand
* Zeus module function to choose a throwable and make unit throw it.
*
* Arguments:
* 0: Logic <OBJECT>
*
* Return Value:
* None
*
* Example:
* [LOGIC] call zen_modules_fnc_moduleThrowSelect
*
* Public: No
*/

params ["_logic"];

private _unit = attachedTo _logic;
deleteVehicle _logic;

if (isNull _unit) exitWith {
[LSTRING(NoObjectSelected)] call EFUNC(common,showMessage);
};

if !(_unit isKindOf "Man") exitWith {
[LSTRING(OnlyInfantry)] call EFUNC(common,showMessage);
};

if !(alive _unit) exitWith {
[LSTRING(OnlyAlive)] call EFUNC(common,showMessage);
};

private _mags = magazines _unit;
private _throwables = (_mags arrayIntersect _mags) select {_x call BIS_fnc_isThrowable};

private _action = [];
{
_action = [
_x,
getText (configFile >> "CfgMagazines" >> _x >> "displayName"),
getText (configFile >> "CfgMagazines" >> _x >> "picture"),
{
(_this # 6) params ["_unit", "_magazine"];
// Get target position
[_unit, {
params ["_successful", "_unit", "_mousePosASL", "_arguments"];
if (_successful) then {
_arguments params ["_magazine"];
private _muzzle = configName (("_magazine in (getArray (_x >> 'magazines'))" configClasses (configFile >> "CfgWeapons" >> "Throw")) # 0);
private _firemode = _muzzle;
[_unit, _magazine, _muzzle, _firemode, _mousePosASL] call FUNC(projectiles_zeus);
};
}, [_magazine], LSTRING(ModuleThrowSelect)] call EFUNC(common,selectPosition);

},
{true},
[_unit, _x]
] call EFUNC(context_menu,createAction);
[_action, [], 0] call EFUNC(context_menu,addAction);
} forEach _throwables;
[] call EFUNC(context_menu,open);

// remove actions on menu close
[{
EGVAR(context_menu,contextGroups) isEqualTo []
},{
_this apply {[_x] call zen_context_menu_fnc_removeAction};
}, _throwables, 15, {}] call CBA_fnc_waitUntilAndExecute;
94 changes: 94 additions & 0 deletions addons/modules/functions/fnc_projectiles_ballisticVector.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
Author: Ampersand
Find the

* Arguments:
* 0: Projectile <OBJECT>
* 1: Target Pos ASL <ARRAY>
* 2: Speed <NUMBER><OPTIONAL>
* 3: useFlatTrajectory <BOOLEAN><OPTIONAL>
*
* Return Value:
* 0: VectorDirAndUp <ARRAY>
*
* Speed <= 0 will boost speed to whatever is necessary to reach target pos.
*
* Example:
* [_projectile, _targetPos, _throwFlatTrajectory] call zen_modules_fnc_projectiles_ballisticVector;

// Launch Zeus selection at mouse position
private _projectile = (curatorSelected # 0 # 0);
private _targetPos = AGLToASL screenToWorld getMousePosition;
private _vector = [_projectile, _targetPos] execVM "fnc_projectiles_ballisticVector.sqf";
_projectile setVelocity = _vector;

*/

params ["_projectile", "_targetPos", ["_speed", 0, [0]], ["_throwFlatTrajectory", true, [true]]];

private _projectilePosASL = getPosASL _projectile;
private _distance = _projectilePosASL distance2D _targetPos;
private _height = _projectilePosASL # 2 - _targetPos # 2;
private _g = 9.8066;
private _angle = "";

// physics
if (_speed > 0) then {
_angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2;
};

// initSpeed too low to reach target
if !(_angle isEqualType 0) then {

if (_speed > 0) then {
// just go as far as possible
_angle = 45;
} else {
// boost speed
while {_speed < 10000 && {!(_angle isEqualType 0)}} do {
_speed = _speed + 1;
_angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2;
};
_speed = _speed + 2;
_angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2;
};
};

if (_angle < 0) then { _angle = _angle + 90; };

private _speedY = _speed * sin _angle;
private _speedx = _speed * cos _angle;

private _vectorLOS = _projectilePosASL vectorFromTo _targetPos;
private _vectorDir = [_projectilePosASL # 0,_projectilePosASL # 1, 0] vectorFromTo [_targetPos # 0, _targetPos # 1, 0];
private _vectorLaunch = vectorNormalized (_vectorDir vectorAdd [0,0,_speedY/_speedX]);


// check if using high angle
if _throwFlatTrajectory then {
private _angleLOS_Vert = acos (_vectorLOS vectorCos [0,0,1]);
private _angleHORZ_LOS = acos (_vectorDir vectorCos _vectorLOS);
private _angleLOS_Launch = acos (_vectorLOS vectorCos _vectorLaunch);
private _angleLaunch_Vert = acos (_vectorLaunch vectorCos [0,0,1]);
//systemChat format ["LV:%1, HL:%2, LA:%3, AV:%4",_angleLOS_Vert, _angleHORZ_LOS, _angleLOS_Launch, _angleLaunch_Vert];

if (_angleLOS_Launch > (_angleLOS_Vert / 2)) then {
if (_angleLOS_Vert > 90) then {
_angleHORZ_LOS = -1 * _angleHORZ_LOS;
};
_angle = _angleLaunch_Vert + _angleHORZ_LOS;
//systemChat format ["FA:%1",_angle];

_speedY = _speed * sin _angle;
_speedx = _speed * cos _angle;
_vectorLaunch = vectorNormalized (_vectorDir vectorAdd [0,0,_speedY/_speedX]);
};
};

private _vectorFinal = _vectorLaunch vectorMultiply _speed;

// projectile orientation
private _vectorSide = _vectorFinal vectorCrossProduct [0,0,-1];
private _vectorUp = _vectorFinal vectorCrossProduct _vectorSide;

[_vectorFinal,_vectorUp]
Loading