From b6eae578783ee12892ecda0e70370d802a4d3f12 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 16:02:23 -0400 Subject: [PATCH 01/26] Added Projectiles modules --- addons/modules/CfgFactionClasses.hpp | 5 + addons/modules/CfgVehicles.hpp | 54 +++++ addons/modules/config.cpp | 9 + .../functions/fnc_moduleFireLauncher.sqf | 50 +++++ addons/modules/functions/fnc_moduleGLFrag.sqf | 75 +++++++ .../functions/fnc_moduleThrowBottle.sqf | 46 +++++ .../modules/functions/fnc_moduleThrowCan.sqf | 46 +++++ .../modules/functions/fnc_moduleThrowFrag.sqf | 42 ++++ .../modules/functions/fnc_moduleThrowMini.sqf | 42 ++++ .../functions/fnc_moduleThrowSmoke.sqf | 42 ++++ .../functions/fnc_moduleThrowStone.sqf | 42 ++++ .../fnc_moduleToggleThrowTrajectory.sqf | 25 +++ .../functions/fnc_projectiles_unit.sqf | 184 ++++++++++++++++++ .../functions/fnc_projectiles_zeus.sqf | 46 +++++ addons/modules/stringtable.xml | 30 +++ 15 files changed, 738 insertions(+) create mode 100644 addons/modules/functions/fnc_moduleFireLauncher.sqf create mode 100644 addons/modules/functions/fnc_moduleGLFrag.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowBottle.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowCan.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowFrag.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowMini.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowSmoke.sqf create mode 100644 addons/modules/functions/fnc_moduleThrowStone.sqf create mode 100644 addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf create mode 100644 addons/modules/functions/fnc_projectiles_unit.sqf create mode 100644 addons/modules/functions/fnc_projectiles_zeus.sqf diff --git a/addons/modules/CfgFactionClasses.hpp b/addons/modules/CfgFactionClasses.hpp index 748b38b2c..360b86fc7 100644 --- a/addons/modules/CfgFactionClasses.hpp +++ b/addons/modules/CfgFactionClasses.hpp @@ -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; diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 7247d45cc..c42741973 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -317,6 +317,60 @@ class CfgVehicles { displayName = CSTRING(ModulePatrolArea); function = QFUNC(modulePatrolArea); }; + class GVAR(moduleToggleThrowTrajectory): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleToggleThrowTrajectory); + function = QFUNC(moduleToggleThrowTrajectory); + }; + class GVAR(moduleThrowFrag): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowFrag); + function = QFUNC(moduleThrowFrag); + }; + class GVAR(moduleThrowMini): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowMini); + function = QFUNC(moduleThrowMini); + }; + class GVAR(moduleThrowSmoke): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowSmoke); + function = QFUNC(moduleThrowSmoke); + }; + class GVAR(moduleThrowStone): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowStone); + function = QFUNC(moduleThrowStone); + }; + class GVAR(moduleThrowCan): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowCan); + function = QFUNC(moduleThrowCan); + }; + class GVAR(moduleThrowBottle): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleThrowBottle); + function = QFUNC(moduleThrowBottle); + }; + class GVAR(moduleGLFrag): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleGLFrag); + function = QFUNC(moduleGLFrag); + }; + class GVAR(moduleFireLauncher): GVAR(moduleBase) { + curatorCanAttach = 1; + category = CSTRING(Projectiles); + displayName = CSTRING(moduleFireLauncher); + function = QFUNC(moduleFireLauncher); + }; class GVAR(moduleRemoveArsenal): GVAR(moduleBase) { curatorCanAttach = 1; category = GVAR(Inventory); diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index 7fb016182..a41497366 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -48,6 +48,15 @@ class CfgPatches { QGVAR(moduleMakeInvincible), QGVAR(moduleNuke), QGVAR(modulePatrolArea), + QGVAR(moduleToggleThrowTrajectory), + QGVAR(moduleThrowFrag), + QGVAR(moduleThrowMini), + QGVAR(moduleThrowSmoke), + QGVAR(moduleThrowStone), + QGVAR(moduleThrowCan), + QGVAR(moduleThrowBottle), + QGVAR(moduleGLFrag), + QGVAR(moduleFireLauncher), QGVAR(moduleRemoveArsenal), QGVAR(moduleRotateObject), QGVAR(moduleSearchBuilding), diff --git a/addons/modules/functions/fnc_moduleFireLauncher.sqf b/addons/modules/functions/fnc_moduleFireLauncher.sqf new file mode 100644 index 000000000..293c5b317 --- /dev/null +++ b/addons/modules/functions/fnc_moduleFireLauncher.sqf @@ -0,0 +1,50 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit fire unguided rocket launcher. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleGLFrag + * + * 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"]; + 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(GLFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleGLFrag.sqf b/addons/modules/functions/fnc_moduleGLFrag.sqf new file mode 100644 index 000000000..db07cd99d --- /dev/null +++ b/addons/modules/functions/fnc_moduleGLFrag.sqf @@ -0,0 +1,75 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit use GL to fire a HE 40mm. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleGLFrag + * + * 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"]; + 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(GLFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowBottle.sqf b/addons/modules/functions/fnc_moduleThrowBottle.sqf new file mode 100644 index 000000000..554a5aa67 --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowBottle.sqf @@ -0,0 +1,46 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a water bottle (ALiVE). + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowBottle + * + * 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); +}; + +if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Bottle")) exitWith { + ["ALiVE mod must be loaded"] call EFUNC(common,showMessage); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "ALiVE_HandGrenade_Bottle"; + private _muzzle = "ALiVE_Handgrenade_BottleMuzzle"; + private _firemode = "ALiVE_Handgrenade_BottleMuzzle"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowBottle)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowCan.sqf b/addons/modules/functions/fnc_moduleThrowCan.sqf new file mode 100644 index 000000000..beb8a4baa --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowCan.sqf @@ -0,0 +1,46 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a can (ALiVE). + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowCan + * + * 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); +}; + +if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Can")) exitWith { + ["ALiVE mod must be loaded"] call EFUNC(common,showMessage); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "ALiVE_HandGrenade_Can"; + private _muzzle = "ALiVE_Handgrenade_canMuzzle"; + private _firemode = "ALiVE_Handgrenade_canMuzzle"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowCan)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowFrag.sqf b/addons/modules/functions/fnc_moduleThrowFrag.sqf new file mode 100644 index 000000000..56a5ea8ac --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowFrag.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a frag grenade. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowFrag + * + * 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); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "HandGrenade"; + private _muzzle = "HandGrenadeMuzzle"; + private _firemode = "HandGrenadeMuzzle"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowMini.sqf b/addons/modules/functions/fnc_moduleThrowMini.sqf new file mode 100644 index 000000000..315ae7ee0 --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowMini.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a mini grenade. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowMini + * + * 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); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "MiniGrenade"; + private _muzzle = "MiniGrenadeMuzzle"; + private _firemode = "MiniGrenadeMuzzle"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowMini)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowSmoke.sqf b/addons/modules/functions/fnc_moduleThrowSmoke.sqf new file mode 100644 index 000000000..7b6ba25fb --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowSmoke.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a smoke grenade. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowSmoke + * + * 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); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "SmokeShell"; + private _muzzle = "SmokeShellMuzzle"; + private _firemode = "SmokeShellMuzzle"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowSmoke)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowStone.sqf b/addons/modules/functions/fnc_moduleThrowStone.sqf new file mode 100644 index 000000000..32ae8655e --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowStone.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to make unit throw a stone. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleThrowStone + * + * 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); +}; + +// Get target position +[_unit, { + params ["_successful", "_unit", "_mousePosASL"]; + private _magazine = "HandGrenade_Stone"; + private _muzzle = "HandGrenade_Stone"; + private _firemode = "HandGrenade_Stone"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; +}, [], LSTRING(ThrowStone)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf b/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf new file mode 100644 index 000000000..bc2fb2b10 --- /dev/null +++ b/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf @@ -0,0 +1,25 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to toggle the ballistic trajectory of projectile modules. + * + * Arguments: + * 0: Logic + * + * Return Value: + * None + * + * Example: + * [LOGIC] call zen_modules_fnc_moduleToggleThrowTrajectory + * + * Public: No + */ + +params ["_logic"]; + +deleteVehicle _logic; + +private _throwFlatTrajectory = profileNamespace getVariable ["amp_projectiles_throwFlatTrajectory", true]; +_throwFlatTrajectory = !_throwFlatTrajectory; +profileNamespace setVariable ["amp_projectiles_throwFlatTrajectory", _throwFlatTrajectory]; +[format ["Throw Trajectory: %1", ["High", "Flat"] select _throwFlatTrajectory]] call EFUNC(common,showMessage); \ No newline at end of file diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf new file mode 100644 index 000000000..785849128 --- /dev/null +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -0,0 +1,184 @@ +/* + Author: Ampers + Makes unit throw the specified magazine to the specified location. + + * Arguments: + * 0: Unit + * 1: Magazine + * 2: Muzzle + * 3: Fire Mode + * 4: Target Pos ASL + * 5: Trajectory + * + * Return Value: + * Exit position + + * Example: + * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call tft_zeus_fnc_unitProjectile; + * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["tft_zeus_fnc_unitProjectile", _unit]; +*/ + +params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; +if !(local _unit) exitWith {}; + +_unit setVariable ["amp_projectiles_throwParams", [_targetPos, _throwFlatTrajectory]]; + +_unit disableAI "PATH"; +_unit setBehaviour "COMBAT"; +private _stance = stance _unit; +if (_stance isEqualTo "STAND") then {_unit setUnitPosWeak "UP";}; +if (_stance isEqualTo "CROUCH") then {_unit setUnitPosWeak "Middle";}; +if (_stance isEqualTo "PRONE") then {_unit setUnitPosWeak "DOWN";}; + +_unit doWatch ASLToAGL _targetPos; + +_unit addEventHandler ["Fired", { + params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; + + private _throwParams = _unit getVariable ["amp_projectiles_throwParams", []]; + if (_throwParams isEqualTo []) exitWith {}; + + _throwParams params ["_targetPos", "_throwFlatTrajectory"]; + private _projectilePosASL = getPosASL _projectile; + private _distance = _projectilePosASL distance2D _targetPos; + private _height = _projectilePosASL # 2 - _targetPos # 2; + private _g = 9.8066; + //private _speed = 10 + _distance / 2 - _height / 2; + private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); + + private _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; + + if !(_angle isEqualType 0) then { + /* boost speed + systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; + while {_speed < 20 && {!(_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; + */ + _angle = 45; + }; + + if (_angle < 0) then { + _angle = _angle + 90; + }; + + if (_angle > 45) then { + //_angle = 90 - _angle; + }; + //systemChat format ["IA:%1",_angle]; + + 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; + + _projectile setVectorDirAndUp [ + _vectorFinal, + _vectorUp + ]; + + // + _projectile setVelocity _vectorFinal; + + // clean up + _unit removeEventHandler ["Fired", _thisEventHandler]; + _unit setVariable ["amp_projectiles_thrown", true]; + _unit enableAI "PATH"; + + // draw testing lines + + amp_projectiles_unit = _unit; + amp_projectiles_projectile = _projectile; + amp_projectiles_projectilePos = getPos _projectile; + amp_projectiles_pos = ASLToAGL _targetPos; + amp_projectiles_velocity = _vectorFinal; + onEachFrame { + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_pos, [0,1,0,1]]; + drawLine3D [amp_projectiles_pos, amp_projectiles_pos vectorAdd [0,0,10], [0,1,0,1]]; + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_projectilePos vectorAdd amp_projectiles_velocity, [0,0,1,1]]; + }; + + //systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; + +}]; + +_unit setVariable ["amp_projectiles_thrown", false]; +_unit setVariable ["amp_projectiles_time", diag_tickTime]; + +_this spawn { + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + + private _uniformItems = []; + private _canAdd = _unit canAdd _magazine; + if !_canAdd then { + { + while {!(_unit canAdd _magazine)} do { + _unit removeItemFromUniform _x; + _uniformItems pushBack _x; + }; + } forEach uniformItems _unit; + }; + _unit addMagazineGlobal _magazine; + + waitUntil { + if (_unit getVariable ["amp_projectiles_thrown", false]) exitWith { + //systemChat "Success."; + true + }; + if (diag_tickTime - (_unit getVariable ["amp_projectiles_time", 0]) > 15) exitWith { + //systemChat "Timed out."; + true + }; + sleep 0.01; + + private _dirUnit = getDir _unit; + private _dirTarget = _unit getDir _targetPos; + private _dirDiff = _dirTarget - _dirUnit; + if (abs _dirDiff > 180) then {_dirDiff = abs _dirDiff - 360}; + if (abs _dirDiff < 35) then { + if (abs _dirDiff > 5) then { _unit setDir _dirTarget;}; + _unit forceWeaponFire [_muzzle, _firemode]; + }; + false + }; + + _unit setVariable ["amp_projectiles_thrown", nil]; + _unit enableAI "PATH"; + + if !_canAdd then { + { + _unit addItemToUniform _x; + } forEach _uniformItems; + }; +}; \ No newline at end of file diff --git a/addons/modules/functions/fnc_projectiles_zeus.sqf b/addons/modules/functions/fnc_projectiles_zeus.sqf new file mode 100644 index 000000000..e2dbcc48d --- /dev/null +++ b/addons/modules/functions/fnc_projectiles_zeus.sqf @@ -0,0 +1,46 @@ +/* + Author: Ampers + Check if projectile can reach target, then remote executes on the unit. + + * Arguments: + * 0: Unit + * 1: Magazine + * 2: Muzzle + * 3: Fire Mode + * 4: Target Pos ASL + * + * Return Value: + * Exit position + + * Example: + * [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call tft_zeus_fnc_zeusProjectile; + */ + +params ["_unit", "_magazine", "_muzzle", "_firemode", "_mousePosASL"]; + +// get location of target in zeus cam view +private _position0 = positionCameraToWorld [0, 0, 0]; +private _intersections = lineIntersectsSurfaces [AGLToASL _position0, _mousePosASL, cameraOn, objNull, true, 1, "GEOM"]; + +private _targetPos = _mousePosASL; +if !(_intersections isEqualTo []) then { + _targetPos = _intersections # 0 # 0; + //systemChat str _targetPos; +}; + +// check if can reach +private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +private _eyePos = eyePos _unit; +private _distance = _eyePos distance2D _targetPos; +private _height = _eyePos # 2 - _targetPos # 2; +private _g = 9.8066; +private _angle = (acos((_g * _distance^2/_initSpeed^2-_height)/(_eyePos distance _targetPos)) + atan (_distance / _height)) / 2; + +if !(_angle isEqualType 0) then { + // if can't reach, notify zeus. Will try to throw as far as possible + [objNull, format ["Can't reach target! D:%1 H:%2", _distance, _height]] call bis_fnc_showCuratorFeedbackMessage; +}; + +private _throwFlatTrajectory = profileNamespace getVariable ["amp_projectiles_throwFlatTrajectory", 1]; + +[_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; \ No newline at end of file diff --git a/addons/modules/stringtable.xml b/addons/modules/stringtable.xml index a18621302..8a969a93a 100644 --- a/addons/modules/stringtable.xml +++ b/addons/modules/stringtable.xml @@ -994,6 +994,36 @@ Zmieni zachowanie, prędkość i formację grupy. グループの移動速度や陣形といった挙動を変更できます。 + + Projectiles + + + Toggle Throw Trajectory + + + Throw Frag + + + Throw Mini + + + Throw Smoke + + + Throw Stone + + + Throw Can + + + Throw Bottle + + + GL Frag + + + Fire Launcher + Side Relations Отношения сторон From 143da4777abb2bfcc2b12c7258c26b5e1fa310df Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 16:07:36 -0400 Subject: [PATCH 02/26] Update Authors --- AUTHORS.txt | 1 + addons/modules/config.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 9d23d9f29..099f01c05 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -34,3 +34,4 @@ PabstMirror SilentSpike Tuupertunut veteran29 +Ampersand \ No newline at end of file diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index a41497366..cfb831546 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -83,7 +83,7 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"zen_attributes"}; author = ECSTRING(main,Author); - authors[] = {"mharis001"}; + authors[] = {"mharis001", "Ampersand"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; From 8674ad2c424acd0aa344efa758bd303972f7b471 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 16:28:23 -0400 Subject: [PATCH 03/26] Sort names --- AUTHORS.txt | 2 +- addons/modules/XEH_PREP.hpp | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 099f01c05..84eee7071 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -15,6 +15,7 @@ NeilZar 3Mydlo3 654wak654 Alganthe +Ampersand BaerMitUmlaut Beaumont Brett @@ -34,4 +35,3 @@ PabstMirror SilentSpike Tuupertunut veteran29 -Ampersand \ No newline at end of file diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index 6306638ed..b604d03cf 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -51,9 +51,11 @@ PREP(moduleEffectFire); PREP(moduleEffectFireLocal); PREP(moduleEquipWithECM); PREP(moduleExportMissionSQF); +PREP(moduleFireLauncher); PREP(moduleFireMission); PREP(moduleFlyHeight); PREP(moduleFunctionsViewer); +PREP(moduleGLFrag); PREP(moduleGarrison); PREP(moduleGlobalAISkill); PREP(moduleGroupSide); @@ -77,9 +79,15 @@ PREP(moduleSpawnDestroyer); PREP(moduleSpawnReinforcements); PREP(moduleSuicideBomber); PREP(moduleTeleportPlayers); +PREP(moduleThrowBottle); +PREP(moduleThrowCan); +PREP(moduleThrowFrag); +PREP(moduleThrowSmoke); +PREP(moduleThrowStone); PREP(moduleToggleFlashlights); PREP(moduleToggleIRLasers); PREP(moduleToggleLamps); +PREP(moduleToggleThrowTrajectory); PREP(moduleTurretOptics); PREP(moduleUnGarrison); PREP(moduleVisibility); From f5f0c80f8a866cc5d5c52ae9b7bf524ce917468a Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 16:37:23 -0400 Subject: [PATCH 04/26] Toggle module doesn't need to attach --- addons/modules/CfgVehicles.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index c42741973..3a9487b86 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -318,7 +318,6 @@ class CfgVehicles { function = QFUNC(modulePatrolArea); }; class GVAR(moduleToggleThrowTrajectory): GVAR(moduleBase) { - curatorCanAttach = 1; category = CSTRING(Projectiles); displayName = CSTRING(moduleToggleThrowTrajectory); function = QFUNC(moduleToggleThrowTrajectory); From 3fb03aae41a47dbe2c09c9f5f199e98f83f17b75 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 18:25:05 -0400 Subject: [PATCH 05/26] Getting functions registered --- addons/modules/CfgVehicles.hpp | 18 +++--- addons/modules/XEH_PREP.hpp | 4 ++ .../functions/fnc_moduleFireLauncher.sqf | 5 +- addons/modules/functions/fnc_moduleGLFrag.sqf | 2 +- .../functions/fnc_moduleThrowBottle.sqf | 2 +- .../modules/functions/fnc_moduleThrowCan.sqf | 2 +- .../modules/functions/fnc_moduleThrowFrag.sqf | 2 +- .../modules/functions/fnc_moduleThrowMini.sqf | 2 +- .../functions/fnc_moduleThrowSmoke.sqf | 2 +- .../functions/fnc_moduleThrowStone.sqf | 2 +- .../fnc_moduleToggleThrowTrajectory.sqf | 7 +-- .../functions/fnc_projectiles_unit.sqf | 58 ++++++++----------- .../functions/fnc_projectiles_zeus.sqf | 7 ++- addons/modules/stringtable.xml | 20 +++---- 14 files changed, 64 insertions(+), 69 deletions(-) diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 3a9487b86..932ca0911 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -318,55 +318,55 @@ class CfgVehicles { function = QFUNC(modulePatrolArea); }; class GVAR(moduleToggleThrowTrajectory): GVAR(moduleBase) { - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleToggleThrowTrajectory); function = QFUNC(moduleToggleThrowTrajectory); }; class GVAR(moduleThrowFrag): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowFrag); function = QFUNC(moduleThrowFrag); }; class GVAR(moduleThrowMini): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowMini); function = QFUNC(moduleThrowMini); }; class GVAR(moduleThrowSmoke): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowSmoke); function = QFUNC(moduleThrowSmoke); }; class GVAR(moduleThrowStone): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowStone); function = QFUNC(moduleThrowStone); }; class GVAR(moduleThrowCan): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowCan); function = QFUNC(moduleThrowCan); }; class GVAR(moduleThrowBottle): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleThrowBottle); function = QFUNC(moduleThrowBottle); }; class GVAR(moduleGLFrag): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleGLFrag); function = QFUNC(moduleGLFrag); }; class GVAR(moduleFireLauncher): GVAR(moduleBase) { curatorCanAttach = 1; - category = CSTRING(Projectiles); + category = QGVAR(Projectiles); displayName = CSTRING(moduleFireLauncher); function = QFUNC(moduleFireLauncher); }; diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index b604d03cf..cfdc6b7e7 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -82,6 +82,7 @@ PREP(moduleTeleportPlayers); PREP(moduleThrowBottle); PREP(moduleThrowCan); PREP(moduleThrowFrag); +PREP(moduleThrowMini); PREP(moduleThrowSmoke); PREP(moduleThrowStone); PREP(moduleToggleFlashlights); @@ -92,3 +93,6 @@ PREP(moduleTurretOptics); PREP(moduleUnGarrison); PREP(moduleVisibility); PREP(moduleWeather); +PREP(projectiles_unit); +PREP(projectiles_zeus); +PREP(moduleWeather); diff --git a/addons/modules/functions/fnc_moduleFireLauncher.sqf b/addons/modules/functions/fnc_moduleFireLauncher.sqf index 293c5b317..4cc1032f7 100644 --- a/addons/modules/functions/fnc_moduleFireLauncher.sqf +++ b/addons/modules/functions/fnc_moduleFireLauncher.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [LOGIC] call zen_modules_fnc_moduleGLFrag + * [LOGIC] call zen_modules_fnc_moduleFireLauncher * * Public: No */ @@ -44,7 +44,8 @@ if (_launcher isEqualTo "") exitWith { 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(GLFrag)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleFireLauncher)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleGLFrag.sqf b/addons/modules/functions/fnc_moduleGLFrag.sqf index db07cd99d..0113e0622 100644 --- a/addons/modules/functions/fnc_moduleGLFrag.sqf +++ b/addons/modules/functions/fnc_moduleGLFrag.sqf @@ -72,4 +72,4 @@ if (_glMuzzles isEqualTo []) exitWith { private _muzzle = _glMuzzles # 0 # 1; private _firemode = "Single"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(GLFrag)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleGLFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowBottle.sqf b/addons/modules/functions/fnc_moduleThrowBottle.sqf index 554a5aa67..944f4ac11 100644 --- a/addons/modules/functions/fnc_moduleThrowBottle.sqf +++ b/addons/modules/functions/fnc_moduleThrowBottle.sqf @@ -43,4 +43,4 @@ if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Bottle")) exitW private _muzzle = "ALiVE_Handgrenade_BottleMuzzle"; private _firemode = "ALiVE_Handgrenade_BottleMuzzle"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowBottle)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowBottle)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowCan.sqf b/addons/modules/functions/fnc_moduleThrowCan.sqf index beb8a4baa..cb7b1ad2e 100644 --- a/addons/modules/functions/fnc_moduleThrowCan.sqf +++ b/addons/modules/functions/fnc_moduleThrowCan.sqf @@ -43,4 +43,4 @@ if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Can")) exitWith private _muzzle = "ALiVE_Handgrenade_canMuzzle"; private _firemode = "ALiVE_Handgrenade_canMuzzle"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowCan)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowCan)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowFrag.sqf b/addons/modules/functions/fnc_moduleThrowFrag.sqf index 56a5ea8ac..a0c803d59 100644 --- a/addons/modules/functions/fnc_moduleThrowFrag.sqf +++ b/addons/modules/functions/fnc_moduleThrowFrag.sqf @@ -39,4 +39,4 @@ if !(alive _unit) exitWith { private _muzzle = "HandGrenadeMuzzle"; private _firemode = "HandGrenadeMuzzle"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowFrag)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowMini.sqf b/addons/modules/functions/fnc_moduleThrowMini.sqf index 315ae7ee0..c6745056b 100644 --- a/addons/modules/functions/fnc_moduleThrowMini.sqf +++ b/addons/modules/functions/fnc_moduleThrowMini.sqf @@ -39,4 +39,4 @@ if !(alive _unit) exitWith { private _muzzle = "MiniGrenadeMuzzle"; private _firemode = "MiniGrenadeMuzzle"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowMini)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowMini)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowSmoke.sqf b/addons/modules/functions/fnc_moduleThrowSmoke.sqf index 7b6ba25fb..3f3eae912 100644 --- a/addons/modules/functions/fnc_moduleThrowSmoke.sqf +++ b/addons/modules/functions/fnc_moduleThrowSmoke.sqf @@ -39,4 +39,4 @@ if !(alive _unit) exitWith { private _muzzle = "SmokeShellMuzzle"; private _firemode = "SmokeShellMuzzle"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowSmoke)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowSmoke)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowStone.sqf b/addons/modules/functions/fnc_moduleThrowStone.sqf index 32ae8655e..d33932799 100644 --- a/addons/modules/functions/fnc_moduleThrowStone.sqf +++ b/addons/modules/functions/fnc_moduleThrowStone.sqf @@ -39,4 +39,4 @@ if !(alive _unit) exitWith { private _muzzle = "HandGrenade_Stone"; private _firemode = "HandGrenade_Stone"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ThrowStone)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleThrowStone)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf b/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf index bc2fb2b10..9091d002c 100644 --- a/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf +++ b/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf @@ -19,7 +19,6 @@ params ["_logic"]; deleteVehicle _logic; -private _throwFlatTrajectory = profileNamespace getVariable ["amp_projectiles_throwFlatTrajectory", true]; -_throwFlatTrajectory = !_throwFlatTrajectory; -profileNamespace setVariable ["amp_projectiles_throwFlatTrajectory", _throwFlatTrajectory]; -[format ["Throw Trajectory: %1", ["High", "Flat"] select _throwFlatTrajectory]] call EFUNC(common,showMessage); \ No newline at end of file +if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlatTrajectory = true;}; +zen_projectiles_throwFlatTrajectory = !zen_projectiles_throwFlatTrajectory; +[format ["Throw Trajectory: %1", ["High", "Flat"] select zen_projectiles_throwFlatTrajectory]] call EFUNC(common,showMessage); \ No newline at end of file diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index 785849128..45229e278 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -11,7 +11,7 @@ * 5: Trajectory * * Return Value: - * Exit position + * NONE * Example: * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call tft_zeus_fnc_unitProjectile; @@ -21,7 +21,7 @@ params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; if !(local _unit) exitWith {}; -_unit setVariable ["amp_projectiles_throwParams", [_targetPos, _throwFlatTrajectory]]; +_unit setVariable ["zen_projectiles_throwParams", [_targetPos, _throwFlatTrajectory]]; _unit disableAI "PATH"; _unit setBehaviour "COMBAT"; @@ -35,7 +35,7 @@ _unit doWatch ASLToAGL _targetPos; _unit addEventHandler ["Fired", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; - private _throwParams = _unit getVariable ["amp_projectiles_throwParams", []]; + private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; if (_throwParams isEqualTo []) exitWith {}; _throwParams params ["_targetPos", "_throwFlatTrajectory"]; @@ -45,7 +45,7 @@ _unit addEventHandler ["Fired", { private _g = 9.8066; //private _speed = 10 + _distance / 2 - _height / 2; private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); - + private _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; if !(_angle isEqualType 0) then { @@ -113,50 +113,40 @@ _unit addEventHandler ["Fired", { // clean up _unit removeEventHandler ["Fired", _thisEventHandler]; - _unit setVariable ["amp_projectiles_thrown", true]; + _unit setVariable ["zen_projectiles_thrown", true]; _unit enableAI "PATH"; - // draw testing lines - - amp_projectiles_unit = _unit; - amp_projectiles_projectile = _projectile; - amp_projectiles_projectilePos = getPos _projectile; - amp_projectiles_pos = ASLToAGL _targetPos; - amp_projectiles_velocity = _vectorFinal; - onEachFrame { - drawLine3D [amp_projectiles_projectilePos, amp_projectiles_pos, [0,1,0,1]]; - drawLine3D [amp_projectiles_pos, amp_projectiles_pos vectorAdd [0,0,10], [0,1,0,1]]; - drawLine3D [amp_projectiles_projectilePos, amp_projectiles_projectilePos vectorAdd amp_projectiles_velocity, [0,0,1,1]]; - }; - - //systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; - }]; -_unit setVariable ["amp_projectiles_thrown", false]; -_unit setVariable ["amp_projectiles_time", diag_tickTime]; +_unit setVariable ["zen_projectiles_thrown", false]; +_unit setVariable ["zen_projectiles_time", diag_tickTime]; _this spawn { params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - private _uniformItems = []; private _canAdd = _unit canAdd _magazine; + private _removedItems = []; if !_canAdd then { - { - while {!(_unit canAdd _magazine)} do { - _unit removeItemFromUniform _x; - _uniformItems pushBack _x; - }; - } forEach uniformItems _unit; + private _backpackContainer = backpackContainer _unit; + if (_backpackContainer isEqualTo objNull) then { + _unit addBackpackGlobal "B_TacticalPack_blk"; + _backpackContainer = backpackContainer _unit; + }; + + while {!(_unit canAddItemToBackpack _magazine)} do { + private _item = (backpackItems _unit) # 0; + _unit removeItemFromBackpack _item; + _removedItems pushBack _item; + }; }; _unit addMagazineGlobal _magazine; waitUntil { - if (_unit getVariable ["amp_projectiles_thrown", false]) exitWith { + if (_unit getVariable ["zen_projectiles_thrown", false]) exitWith { //systemChat "Success."; true }; - if (diag_tickTime - (_unit getVariable ["amp_projectiles_time", 0]) > 15) exitWith { + if (diag_tickTime - (_unit getVariable ["zen_projectiles_time", 0]) > 15) exitWith { //systemChat "Timed out."; true }; @@ -173,12 +163,12 @@ _this spawn { false }; - _unit setVariable ["amp_projectiles_thrown", nil]; + _unit setVariable ["zen_projectiles_thrown", nil]; _unit enableAI "PATH"; if !_canAdd then { { - _unit addItemToUniform _x; - } forEach _uniformItems; + _unit addItemToBackpack _x; + } forEach _removedItems; }; }; \ No newline at end of file diff --git a/addons/modules/functions/fnc_projectiles_zeus.sqf b/addons/modules/functions/fnc_projectiles_zeus.sqf index e2dbcc48d..38c6653be 100644 --- a/addons/modules/functions/fnc_projectiles_zeus.sqf +++ b/addons/modules/functions/fnc_projectiles_zeus.sqf @@ -10,7 +10,7 @@ * 4: Target Pos ASL * * Return Value: - * Exit position + * NONE * Example: * [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call tft_zeus_fnc_zeusProjectile; @@ -41,6 +41,7 @@ if !(_angle isEqualType 0) then { [objNull, format ["Can't reach target! D:%1 H:%2", _distance, _height]] call bis_fnc_showCuratorFeedbackMessage; }; -private _throwFlatTrajectory = profileNamespace getVariable ["amp_projectiles_throwFlatTrajectory", 1]; +if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlatTrajectory = true;}; + +[_unit, _magazine, _muzzle, _firemode, _targetPos, zen_projectiles_throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; -[_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; \ No newline at end of file diff --git a/addons/modules/stringtable.xml b/addons/modules/stringtable.xml index 8a969a93a..4d8d3967c 100644 --- a/addons/modules/stringtable.xml +++ b/addons/modules/stringtable.xml @@ -994,34 +994,34 @@ Zmieni zachowanie, prędkość i formację grupy. グループの移動速度や陣形といった挙動を変更できます。 - + Projectiles - + Toggle Throw Trajectory - + Throw Frag - + Throw Mini - + Throw Smoke - + Throw Stone - + Throw Can - + Throw Bottle - + GL Frag - + Fire Launcher From 4c73e020d65ba1a2a4c5468332957f210675ff76 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 20:19:42 -0400 Subject: [PATCH 06/26] Fixed dup line --- addons/modules/XEH_PREP.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index cfdc6b7e7..527104b0f 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -95,4 +95,3 @@ PREP(moduleVisibility); PREP(moduleWeather); PREP(projectiles_unit); PREP(projectiles_zeus); -PREP(moduleWeather); From f64a4c1a873040720c8e7b941766cfe35757abbd Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 7 May 2020 20:41:45 -0400 Subject: [PATCH 07/26] Remove ALiVE until dependent on mod loaded --- addons/modules/CfgVehicles.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 932ca0911..a55405c50 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -346,6 +346,7 @@ class CfgVehicles { displayName = CSTRING(moduleThrowStone); function = QFUNC(moduleThrowStone); }; + /* class GVAR(moduleThrowCan): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); @@ -358,6 +359,7 @@ class CfgVehicles { displayName = CSTRING(moduleThrowBottle); function = QFUNC(moduleThrowBottle); }; + */ class GVAR(moduleGLFrag): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); From 7ebd6a5d5528908385f9042f31579b0065ae469f Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 00:35:06 -0400 Subject: [PATCH 08/26] Add module for Throw Select Choose from unit's available throwables in context menu. Issue: actions not removed if context menu is closed. --- addons/modules/CfgVehicles.hpp | 6 ++ addons/modules/XEH_PREP.hpp | 1 + addons/modules/config.cpp | 1 + .../functions/fnc_moduleThrowSelect.sqf | 84 +++++++++++++++++++ addons/modules/stringtable.xml | 3 + 5 files changed, 95 insertions(+) create mode 100644 addons/modules/functions/fnc_moduleThrowSelect.sqf diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index a55405c50..0a875a134 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -334,6 +334,12 @@ class CfgVehicles { displayName = CSTRING(moduleThrowMini); function = QFUNC(moduleThrowMini); }; + class GVAR(moduleThrowSelect): GVAR(moduleBase) { + curatorCanAttach = 1; + category = QGVAR(Projectiles); + displayName = CSTRING(moduleThrowSelect); + function = QFUNC(moduleThrowSelect); + }; class GVAR(moduleThrowSmoke): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index 527104b0f..cac76e403 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -83,6 +83,7 @@ PREP(moduleThrowBottle); PREP(moduleThrowCan); PREP(moduleThrowFrag); PREP(moduleThrowMini); +PREP(moduleThrowSelect); PREP(moduleThrowSmoke); PREP(moduleThrowStone); PREP(moduleToggleFlashlights); diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index cfb831546..24c43535c 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -51,6 +51,7 @@ class CfgPatches { QGVAR(moduleToggleThrowTrajectory), QGVAR(moduleThrowFrag), QGVAR(moduleThrowMini), + QGVAR(moduleThrowSelect), QGVAR(moduleThrowSmoke), QGVAR(moduleThrowStone), QGVAR(moduleThrowCan), diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf new file mode 100644 index 000000000..d96741eff --- /dev/null +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -0,0 +1,84 @@ +#include "script_component.hpp" +/* + * Author: Ampersand + * Zeus module function to choose a throwable and make unit throw it. + * + * Arguments: + * 0: Logic + * + * 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", "_throwables"]; + _throwables apply {[_x] call zen_context_menu_fnc_removeAction}; + // Get target position + [_unit, { + params ["_successful", "_unit", "_mousePosASL", "_arguments"]; + _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, _throwables] + ] call EFUNC(context_menu,createAction); + [_action, [], 0] call EFUNC(context_menu,addAction); +} forEach _throwables; +[] call EFUNC(context_menu,openMenu); + + + + + + + + + + + + + + + + + + + + + + diff --git a/addons/modules/stringtable.xml b/addons/modules/stringtable.xml index 4d8d3967c..202a10da5 100644 --- a/addons/modules/stringtable.xml +++ b/addons/modules/stringtable.xml @@ -1006,6 +1006,9 @@ Throw Mini + + Throw Select + Throw Smoke From 093fb91e6d800f07c87e51eb1871486b58adc4e9 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 12:37:35 -0400 Subject: [PATCH 09/26] Reliability and performance Repalced spawn and waitUntil with CBA Use AnimChanged EH to re-fire launcher as needed Added comments and test code --- .../functions/fnc_projectiles_unit.sqf | 162 +++++++++++------- 1 file changed, 101 insertions(+), 61 deletions(-) diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index 45229e278..dff7090bd 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -16,12 +16,30 @@ * Example: * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call tft_zeus_fnc_unitProjectile; * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["tft_zeus_fnc_unitProjectile", _unit]; -*/ + +// Zeus selected unit throw a thing at mouse position +private _unit = (curatorSelected # 0 # 0); +(currentThrowable _unit) params ["_magazine", "_muzzle"]; +private _firemode = _muzzle; +private _targetPos = AGLToASL screenToWorld getMousePosition; +[_unit, _magazine, _muzzle, _firemode, _targetPos, true] execVM "fnc_projectiles_unit.sqf" + +// Zeus selected unit fire launcher at mouse position +private _unit = (curatorSelected # 0 # 0); +private _targetPos = AGLToASL screenToWorld getMousePosition; +private _weapon = secondaryWeapon _unit; +private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; +private _muzzle = _weapon; +private _firemode = "Single"; +[_unit, _magazine, _muzzle, _firemode, _targetPos, true] execVM "fnc_projectiles_unit.sqf" + + */ params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; if !(local _unit) exitWith {}; -_unit setVariable ["zen_projectiles_throwParams", [_targetPos, _throwFlatTrajectory]]; +_unit setVariable ["zen_projectiles_throwParams", _this]; +//_unit setVariable ["zen_projectiles_throwParams", [_targetPos, _throwFlatTrajectory]]; _unit disableAI "PATH"; _unit setBehaviour "COMBAT"; @@ -32,13 +50,32 @@ if (_stance isEqualTo "PRONE") then {_unit setUnitPosWeak "DOWN";}; _unit doWatch ASLToAGL _targetPos; +// Launcher needs timely command of forceWeaponFire +_unit addEventHandler ["AnimChanged", { + params ["_unit", "_anim"]; + if !(_unit getVariable ["zen_projectiles_thrown", false]) then { + // haven't fired yet + private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; + if (_throwParams isEqualTo []) exitWith {}; + _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + + // fire again + _unit forceWeaponFire [_muzzle, _firemode]; + + } else { + // fired, clean up + _unit removeEventHandler ["AnimChanged", _thisEventHandler]; + }; +}]; + +// set the projectile initial velocity _unit addEventHandler ["Fired", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; if (_throwParams isEqualTo []) exitWith {}; - - _throwParams params ["_targetPos", "_throwFlatTrajectory"]; + _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + private _projectilePosASL = getPosASL _projectile; private _distance = _projectilePosASL distance2D _targetPos; private _height = _projectilePosASL # 2 - _targetPos # 2; @@ -46,8 +83,10 @@ _unit addEventHandler ["Fired", { //private _speed = 10 + _distance / 2 - _height / 2; private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); + // physics private _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 { /* boost speed systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; @@ -58,17 +97,11 @@ _unit addEventHandler ["Fired", { _speed = _speed + 2; _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; */ + // just go as far as possible _angle = 45; }; - if (_angle < 0) then { - _angle = _angle + 90; - }; - - if (_angle > 45) then { - //_angle = 90 - _angle; - }; - //systemChat format ["IA:%1",_angle]; + if (_angle < 0) then { _angle = _angle + 90; }; private _speedY = _speed * sin _angle; private _speedx = _speed * cos _angle; @@ -108,7 +141,7 @@ _unit addEventHandler ["Fired", { _vectorUp ]; - // + // set velocity _projectile setVelocity _vectorFinal; // clean up @@ -116,59 +149,66 @@ _unit addEventHandler ["Fired", { _unit setVariable ["zen_projectiles_thrown", true]; _unit enableAI "PATH"; + /* test draw sight and aim lines + amp_projectiles_unit = _unit; + amp_projectiles_projectile = _projectile; + amp_projectiles_projectilePos = getPos _projectile; + amp_projectiles_targetPos = ASLToAGL _targetPos; + amp_projectiles_velocity = _vectorFinal; + onEachFrame { + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_targetPos, [0,1,0,1]]; // sight line + drawLine3D [amp_projectiles_targetPos, amp_projectiles_targetPos vectorAdd [0,0,10], [0,1,0,1]]; // vertical goal post + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_projectilePos vectorAdd amp_projectiles_velocity, [0,0,1,1]]; // aim line, initial angle + }; + */ }]; _unit setVariable ["zen_projectiles_thrown", false]; _unit setVariable ["zen_projectiles_time", diag_tickTime]; -_this spawn { - params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - - private _canAdd = _unit canAdd _magazine; - private _removedItems = []; - if !_canAdd then { - private _backpackContainer = backpackContainer _unit; - if (_backpackContainer isEqualTo objNull) then { - _unit addBackpackGlobal "B_TacticalPack_blk"; - _backpackContainer = backpackContainer _unit; - }; - - while {!(_unit canAddItemToBackpack _magazine)} do { - private _item = (backpackItems _unit) # 0; - _unit removeItemFromBackpack _item; - _removedItems pushBack _item; - }; - }; - _unit addMagazineGlobal _magazine; - - waitUntil { - if (_unit getVariable ["zen_projectiles_thrown", false]) exitWith { - //systemChat "Success."; - true - }; - if (diag_tickTime - (_unit getVariable ["zen_projectiles_time", 0]) > 15) exitWith { - //systemChat "Timed out."; - true - }; - sleep 0.01; - - private _dirUnit = getDir _unit; - private _dirTarget = _unit getDir _targetPos; - private _dirDiff = _dirTarget - _dirUnit; - if (abs _dirDiff > 180) then {_dirDiff = abs _dirDiff - 360}; - if (abs _dirDiff < 35) then { - if (abs _dirDiff > 5) then { _unit setDir _dirTarget;}; - _unit forceWeaponFire [_muzzle, _firemode]; - }; - false +private _canAdd = _unit canAdd _magazine; +private _removedItems = []; +if !_canAdd then { + private _backpackContainer = backpackContainer _unit; + if (_backpackContainer isEqualTo objNull) then { + _unit addBackpackGlobal "B_TacticalPack_blk"; + _backpackContainer = backpackContainer _unit; }; - - _unit setVariable ["zen_projectiles_thrown", nil]; - _unit enableAI "PATH"; - if !_canAdd then { - { - _unit addItemToBackpack _x; - } forEach _removedItems; + while {!(_unit canAddItemToBackpack _magazine)} do { + private _item = (backpackItems _unit) # 0; + _unit removeItemFromBackpack _item; + _removedItems pushBack _item; }; -}; \ No newline at end of file +}; +_unit addMagazineGlobal _magazine; + +[{ + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + // make unit turn towards target + private _dirUnit = getDir _unit; + private _dirTarget = _unit getDir _targetPos; + private _dirDiff = _dirTarget - _dirUnit; + if (abs _dirDiff > 180) then {_dirDiff = abs _dirDiff - 360}; + (abs _dirDiff < 35) +},{ + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + // close enough, make unit face target + private _dirUnit = getDir _unit; + private _dirTarget = _unit getDir _targetPos; + private _dirDiff = _dirTarget - _dirUnit; + if (abs _dirDiff > 5) then { _unit setDir _dirTarget;}; + [{ + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + _unit forceWeaponFire [_muzzle, _firemode]; + }, _this, 0.1] call CBA_fnc_waitAndExecute; +}, _this, 15, {}] call CBA_fnc_waitUntilAndExecute; + +_unit setVariable ["zen_projectiles_thrown", nil]; +_unit enableAI "PATH"; + +if !_canAdd then { + { + _unit addItemToBackpack _x; + } forEach _removedItems; +}; From 5692c7b011c77bd06de0887de3e1cad7a2c35470 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 12:40:55 -0400 Subject: [PATCH 10/26] Corrected example code --- addons/modules/functions/fnc_projectiles_unit.sqf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index dff7090bd..1c4ffe77f 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -14,15 +14,15 @@ * NONE * Example: - * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call tft_zeus_fnc_unitProjectile; - * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["tft_zeus_fnc_unitProjectile", _unit]; + * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call zen_modules_fnc_projectiles_unit; + * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; // Zeus selected unit throw a thing at mouse position private _unit = (curatorSelected # 0 # 0); (currentThrowable _unit) params ["_magazine", "_muzzle"]; private _firemode = _muzzle; private _targetPos = AGLToASL screenToWorld getMousePosition; -[_unit, _magazine, _muzzle, _firemode, _targetPos, true] execVM "fnc_projectiles_unit.sqf" +[_unit, _magazine, _muzzle, _firemode, _targetPos, true] call zen_modules_fnc_projectiles_unit // Zeus selected unit fire launcher at mouse position private _unit = (curatorSelected # 0 # 0); @@ -31,7 +31,7 @@ private _weapon = secondaryWeapon _unit; private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; private _muzzle = _weapon; private _firemode = "Single"; -[_unit, _magazine, _muzzle, _firemode, _targetPos, true] execVM "fnc_projectiles_unit.sqf" +[_unit, _magazine, _muzzle, _firemode, _targetPos, true] call zen_modules_fnc_projectiles_unit */ From 44b69dce38450533ffb03f0e408e662c73f054e2 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 13:32:58 -0400 Subject: [PATCH 11/26] Separate ballistics function --- addons/modules/XEH_PREP.hpp | 1 + .../fnc_projectiles_ballisticVector.sqf | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 addons/modules/functions/fnc_projectiles_ballisticVector.sqf diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index cac76e403..951d9ab19 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -96,3 +96,4 @@ PREP(moduleVisibility); PREP(moduleWeather); PREP(projectiles_unit); PREP(projectiles_zeus); +PREP(projectiles_ballisticVector); diff --git a/addons/modules/functions/fnc_projectiles_ballisticVector.sqf b/addons/modules/functions/fnc_projectiles_ballisticVector.sqf new file mode 100644 index 000000000..af1494fe4 --- /dev/null +++ b/addons/modules/functions/fnc_projectiles_ballisticVector.sqf @@ -0,0 +1,94 @@ +/* + Author: Ampersand + Find the + + * Arguments: + * 0: Projectile + * 1: Target Pos ASL + * 2: Speed + * 3: useFlatTrajectory + * + * Return Value: + * 0: VectorDirAndUp + * + * 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] From 117923ef6c91d20e4ecce248408fe19793607f42 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 13:33:07 -0400 Subject: [PATCH 12/26] Name fix --- addons/modules/functions/fnc_projectiles_unit.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index 1c4ffe77f..a4fe771ff 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -1,5 +1,5 @@ /* - Author: Ampers + Author: Ampersand Makes unit throw the specified magazine to the specified location. * Arguments: From fb5d8b8f25d661cc7da74a0611410c3197e8c2c5 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 8 May 2020 14:05:43 -0400 Subject: [PATCH 13/26] Clear grenade actions on context menu close --- .../functions/fnc_moduleThrowSelect.sqf | 32 +++++-------------- 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf index d96741eff..fe1b10465 100644 --- a/addons/modules/functions/fnc_moduleThrowSelect.sqf +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -42,8 +42,7 @@ private _action = []; getText (configFile >> "CfgMagazines" >> _x >> "displayName"), getText (configFile >> "CfgMagazines" >> _x >> "picture"), { - (_this # 6) params ["_unit", "_magazine", "_throwables"]; - _throwables apply {[_x] call zen_context_menu_fnc_removeAction}; + (_this # 6) params ["_unit", "_magazine"]; // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL", "_arguments"]; @@ -55,30 +54,15 @@ private _action = []; }, {true}, - [_unit, _x, _throwables] + [_unit, _x] ] call EFUNC(context_menu,createAction); [_action, [], 0] call EFUNC(context_menu,addAction); } forEach _throwables; [] call EFUNC(context_menu,openMenu); - - - - - - - - - - - - - - - - - - - - - +// 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; From cd243ffe30b60238b91d67ddd937e1653a3ff285 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Tue, 12 May 2020 11:34:35 -0400 Subject: [PATCH 14/26] Removed and renamed movdules --- addons/modules/CfgVehicles.hpp | 53 ++----------------- addons/modules/XEH_PREP.hpp | 9 +--- addons/modules/config.cpp | 10 +--- ..._moduleGLFrag.sqf => fnc_moduleFireGL.sqf} | 4 +- .../functions/fnc_moduleThrowBottle.sqf | 46 ---------------- .../modules/functions/fnc_moduleThrowCan.sqf | 46 ---------------- .../modules/functions/fnc_moduleThrowFrag.sqf | 42 --------------- .../modules/functions/fnc_moduleThrowMini.sqf | 42 --------------- .../functions/fnc_moduleThrowSmoke.sqf | 42 --------------- .../functions/fnc_moduleThrowStone.sqf | 42 --------------- .../fnc_moduleToggleThrowTrajectory.sqf | 24 --------- addons/modules/stringtable.xml | 25 +-------- 12 files changed, 12 insertions(+), 373 deletions(-) rename addons/modules/functions/{fnc_moduleGLFrag.sqf => fnc_moduleFireGL.sqf} (94%) delete mode 100644 addons/modules/functions/fnc_moduleThrowBottle.sqf delete mode 100644 addons/modules/functions/fnc_moduleThrowCan.sqf delete mode 100644 addons/modules/functions/fnc_moduleThrowFrag.sqf delete mode 100644 addons/modules/functions/fnc_moduleThrowMini.sqf delete mode 100644 addons/modules/functions/fnc_moduleThrowSmoke.sqf delete mode 100644 addons/modules/functions/fnc_moduleThrowStone.sqf delete mode 100644 addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 0a875a134..512326c94 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -317,65 +317,22 @@ class CfgVehicles { displayName = CSTRING(ModulePatrolArea); function = QFUNC(modulePatrolArea); }; - class GVAR(moduleToggleThrowTrajectory): GVAR(moduleBase) { - category = QGVAR(Projectiles); - displayName = CSTRING(moduleToggleThrowTrajectory); - function = QFUNC(moduleToggleThrowTrajectory); - }; - class GVAR(moduleThrowFrag): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowFrag); - function = QFUNC(moduleThrowFrag); - }; - class GVAR(moduleThrowMini): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowMini); - function = QFUNC(moduleThrowMini); - }; class GVAR(moduleThrowSelect): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowSelect); + displayName = CSTRING(moduleThrowSelect); function = QFUNC(moduleThrowSelect); }; - class GVAR(moduleThrowSmoke): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowSmoke); - function = QFUNC(moduleThrowSmoke); - }; - class GVAR(moduleThrowStone): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowStone); - function = QFUNC(moduleThrowStone); - }; - /* - class GVAR(moduleThrowCan): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowCan); - function = QFUNC(moduleThrowCan); - }; - class GVAR(moduleThrowBottle): GVAR(moduleBase) { - curatorCanAttach = 1; - category = QGVAR(Projectiles); - displayName = CSTRING(moduleThrowBottle); - function = QFUNC(moduleThrowBottle); - }; - */ - class GVAR(moduleGLFrag): GVAR(moduleBase) { + class GVAR(moduleFireGL): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); - displayName = CSTRING(moduleGLFrag); - function = QFUNC(moduleGLFrag); + displayName = CSTRING(moduleFireGL); + function = QFUNC(moduleFireGL); }; class GVAR(moduleFireLauncher): GVAR(moduleBase) { curatorCanAttach = 1; category = QGVAR(Projectiles); - displayName = CSTRING(moduleFireLauncher); + displayName = CSTRING(moduleFireLauncher); function = QFUNC(moduleFireLauncher); }; class GVAR(moduleRemoveArsenal): GVAR(moduleBase) { diff --git a/addons/modules/XEH_PREP.hpp b/addons/modules/XEH_PREP.hpp index 951d9ab19..900d0a66f 100644 --- a/addons/modules/XEH_PREP.hpp +++ b/addons/modules/XEH_PREP.hpp @@ -51,11 +51,11 @@ PREP(moduleEffectFire); PREP(moduleEffectFireLocal); PREP(moduleEquipWithECM); PREP(moduleExportMissionSQF); +PREP(moduleFireGL); PREP(moduleFireLauncher); PREP(moduleFireMission); PREP(moduleFlyHeight); PREP(moduleFunctionsViewer); -PREP(moduleGLFrag); PREP(moduleGarrison); PREP(moduleGlobalAISkill); PREP(moduleGroupSide); @@ -79,17 +79,10 @@ PREP(moduleSpawnDestroyer); PREP(moduleSpawnReinforcements); PREP(moduleSuicideBomber); PREP(moduleTeleportPlayers); -PREP(moduleThrowBottle); -PREP(moduleThrowCan); -PREP(moduleThrowFrag); -PREP(moduleThrowMini); PREP(moduleThrowSelect); -PREP(moduleThrowSmoke); -PREP(moduleThrowStone); PREP(moduleToggleFlashlights); PREP(moduleToggleIRLasers); PREP(moduleToggleLamps); -PREP(moduleToggleThrowTrajectory); PREP(moduleTurretOptics); PREP(moduleUnGarrison); PREP(moduleVisibility); diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index 24c43535c..3782a0db3 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -35,6 +35,8 @@ class CfgPatches { QGVAR(moduleEquipWithECM), QGVAR(moduleExportMissionSQF), QGVAR(moduleExecuteCode), + QGVAR(moduleFireGL), + QGVAR(moduleFireLauncher), QGVAR(moduleFireMission), QGVAR(moduleFlyHeight), QGVAR(moduleFunctionsViewer), @@ -48,16 +50,8 @@ class CfgPatches { QGVAR(moduleMakeInvincible), QGVAR(moduleNuke), QGVAR(modulePatrolArea), - QGVAR(moduleToggleThrowTrajectory), - QGVAR(moduleThrowFrag), - QGVAR(moduleThrowMini), QGVAR(moduleThrowSelect), - QGVAR(moduleThrowSmoke), - QGVAR(moduleThrowStone), - QGVAR(moduleThrowCan), QGVAR(moduleThrowBottle), - QGVAR(moduleGLFrag), - QGVAR(moduleFireLauncher), QGVAR(moduleRemoveArsenal), QGVAR(moduleRotateObject), QGVAR(moduleSearchBuilding), diff --git a/addons/modules/functions/fnc_moduleGLFrag.sqf b/addons/modules/functions/fnc_moduleFireGL.sqf similarity index 94% rename from addons/modules/functions/fnc_moduleGLFrag.sqf rename to addons/modules/functions/fnc_moduleFireGL.sqf index 0113e0622..5c3794773 100644 --- a/addons/modules/functions/fnc_moduleGLFrag.sqf +++ b/addons/modules/functions/fnc_moduleFireGL.sqf @@ -10,7 +10,7 @@ * None * * Example: - * [LOGIC] call zen_modules_fnc_moduleGLFrag + * [LOGIC] call zen_modules_fnc_moduleFireGL * * Public: No */ @@ -72,4 +72,4 @@ if (_glMuzzles isEqualTo []) exitWith { private _muzzle = _glMuzzles # 0 # 1; private _firemode = "Single"; [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleGLFrag)] call EFUNC(common,selectPosition); +}, [], LSTRING(ModuleFireGL)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowBottle.sqf b/addons/modules/functions/fnc_moduleThrowBottle.sqf deleted file mode 100644 index 944f4ac11..000000000 --- a/addons/modules/functions/fnc_moduleThrowBottle.sqf +++ /dev/null @@ -1,46 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a water bottle (ALiVE). - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowBottle - * - * 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); -}; - -if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Bottle")) exitWith { - ["ALiVE mod must be loaded"] call EFUNC(common,showMessage); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "ALiVE_HandGrenade_Bottle"; - private _muzzle = "ALiVE_Handgrenade_BottleMuzzle"; - private _firemode = "ALiVE_Handgrenade_BottleMuzzle"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowBottle)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowCan.sqf b/addons/modules/functions/fnc_moduleThrowCan.sqf deleted file mode 100644 index cb7b1ad2e..000000000 --- a/addons/modules/functions/fnc_moduleThrowCan.sqf +++ /dev/null @@ -1,46 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a can (ALiVE). - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowCan - * - * 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); -}; - -if !(isClass (ConfigFile >> "CfgMagazines" >> "ALiVE_HandGrenade_Can")) exitWith { - ["ALiVE mod must be loaded"] call EFUNC(common,showMessage); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "ALiVE_HandGrenade_Can"; - private _muzzle = "ALiVE_Handgrenade_canMuzzle"; - private _firemode = "ALiVE_Handgrenade_canMuzzle"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowCan)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowFrag.sqf b/addons/modules/functions/fnc_moduleThrowFrag.sqf deleted file mode 100644 index a0c803d59..000000000 --- a/addons/modules/functions/fnc_moduleThrowFrag.sqf +++ /dev/null @@ -1,42 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a frag grenade. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowFrag - * - * 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); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "HandGrenade"; - private _muzzle = "HandGrenadeMuzzle"; - private _firemode = "HandGrenadeMuzzle"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowFrag)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowMini.sqf b/addons/modules/functions/fnc_moduleThrowMini.sqf deleted file mode 100644 index c6745056b..000000000 --- a/addons/modules/functions/fnc_moduleThrowMini.sqf +++ /dev/null @@ -1,42 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a mini grenade. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowMini - * - * 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); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "MiniGrenade"; - private _muzzle = "MiniGrenadeMuzzle"; - private _firemode = "MiniGrenadeMuzzle"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowMini)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowSmoke.sqf b/addons/modules/functions/fnc_moduleThrowSmoke.sqf deleted file mode 100644 index 3f3eae912..000000000 --- a/addons/modules/functions/fnc_moduleThrowSmoke.sqf +++ /dev/null @@ -1,42 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a smoke grenade. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowSmoke - * - * 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); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "SmokeShell"; - private _muzzle = "SmokeShellMuzzle"; - private _firemode = "SmokeShellMuzzle"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowSmoke)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowStone.sqf b/addons/modules/functions/fnc_moduleThrowStone.sqf deleted file mode 100644 index d33932799..000000000 --- a/addons/modules/functions/fnc_moduleThrowStone.sqf +++ /dev/null @@ -1,42 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to make unit throw a stone. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleThrowStone - * - * 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); -}; - -// Get target position -[_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - private _magazine = "HandGrenade_Stone"; - private _muzzle = "HandGrenade_Stone"; - private _firemode = "HandGrenade_Stone"; - [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; -}, [], LSTRING(ModuleThrowStone)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf b/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf deleted file mode 100644 index 9091d002c..000000000 --- a/addons/modules/functions/fnc_moduleToggleThrowTrajectory.sqf +++ /dev/null @@ -1,24 +0,0 @@ -#include "script_component.hpp" -/* - * Author: Ampersand - * Zeus module function to toggle the ballistic trajectory of projectile modules. - * - * Arguments: - * 0: Logic - * - * Return Value: - * None - * - * Example: - * [LOGIC] call zen_modules_fnc_moduleToggleThrowTrajectory - * - * Public: No - */ - -params ["_logic"]; - -deleteVehicle _logic; - -if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlatTrajectory = true;}; -zen_projectiles_throwFlatTrajectory = !zen_projectiles_throwFlatTrajectory; -[format ["Throw Trajectory: %1", ["High", "Flat"] select zen_projectiles_throwFlatTrajectory]] call EFUNC(common,showMessage); \ No newline at end of file diff --git a/addons/modules/stringtable.xml b/addons/modules/stringtable.xml index 202a10da5..589893d97 100644 --- a/addons/modules/stringtable.xml +++ b/addons/modules/stringtable.xml @@ -997,32 +997,11 @@ Projectiles - - Toggle Throw Trajectory - - - Throw Frag - - - Throw Mini - Throw Select - - Throw Smoke - - - Throw Stone - - - Throw Can - - - Throw Bottle - - - GL Frag + + Fire GL Fire Launcher From 7ab17faecb913477dec16bcd0de7beed69e71ed9 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 14 May 2020 11:55:07 -0400 Subject: [PATCH 15/26] Tabs to spaces --- addons/modules/functions/fnc_moduleFireGL.sqf | 56 ++-- .../functions/fnc_moduleFireLauncher.sqf | 16 +- .../functions/fnc_moduleThrowSelect.sqf | 44 +-- .../functions/fnc_projectiles_unit.sqf | 280 +++++++++--------- .../functions/fnc_projectiles_zeus.sqf | 12 +- 5 files changed, 204 insertions(+), 204 deletions(-) diff --git a/addons/modules/functions/fnc_moduleFireGL.sqf b/addons/modules/functions/fnc_moduleFireGL.sqf index 5c3794773..e169cfbce 100644 --- a/addons/modules/functions/fnc_moduleFireGL.sqf +++ b/addons/modules/functions/fnc_moduleFireGL.sqf @@ -36,13 +36,13 @@ if !(alive _unit) exitWith { 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"); + 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 { @@ -51,25 +51,25 @@ if (_glMuzzles isEqualTo []) exitWith { // Get target position [_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - 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; + params ["_successful", "_unit", "_mousePosASL"]; + 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); diff --git a/addons/modules/functions/fnc_moduleFireLauncher.sqf b/addons/modules/functions/fnc_moduleFireLauncher.sqf index 4cc1032f7..c4a235755 100644 --- a/addons/modules/functions/fnc_moduleFireLauncher.sqf +++ b/addons/modules/functions/fnc_moduleFireLauncher.sqf @@ -40,12 +40,12 @@ if (_launcher isEqualTo "") exitWith { // Get target position [_unit, { - params ["_successful", "_unit", "_mousePosASL"]; - 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; + params ["_successful", "_unit", "_mousePosASL"]; + 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); diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf index fe1b10465..e021815bb 100644 --- a/addons/modules/functions/fnc_moduleThrowSelect.sqf +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -37,32 +37,32 @@ private _throwables = (_mags arrayIntersect _mags) select {_x call BIS_fnc_isThr 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"]; - _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); + _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"]; + _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,openMenu); // remove actions on menu close [{ - EGVAR(context_menu,contextGroups) isEqualTo [] + EGVAR(context_menu,contextGroups) isEqualTo [] },{ - _this apply {[_x] call zen_context_menu_fnc_removeAction}; + _this apply {[_x] call zen_context_menu_fnc_removeAction}; }, _throwables, 15, {}] call CBA_fnc_waitUntilAndExecute; diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index a4fe771ff..0027e4b25 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -16,7 +16,7 @@ * Example: * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] call zen_modules_fnc_projectiles_unit; * [_unit, _magazine, _muzzle, _firemode, _targetPos, _throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; - + // Zeus selected unit throw a thing at mouse position private _unit = (curatorSelected # 0 # 0); (currentThrowable _unit) params ["_magazine", "_muzzle"]; @@ -27,9 +27,9 @@ private _targetPos = AGLToASL screenToWorld getMousePosition; // Zeus selected unit fire launcher at mouse position private _unit = (curatorSelected # 0 # 0); private _targetPos = AGLToASL screenToWorld getMousePosition; -private _weapon = secondaryWeapon _unit; -private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; -private _muzzle = _weapon; +private _weapon = secondaryWeapon _unit; +private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; +private _muzzle = _weapon; private _firemode = "Single"; [_unit, _magazine, _muzzle, _firemode, _targetPos, true] call zen_modules_fnc_projectiles_unit @@ -52,115 +52,115 @@ _unit doWatch ASLToAGL _targetPos; // Launcher needs timely command of forceWeaponFire _unit addEventHandler ["AnimChanged", { - params ["_unit", "_anim"]; - if !(_unit getVariable ["zen_projectiles_thrown", false]) then { - // haven't fired yet - private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; - if (_throwParams isEqualTo []) exitWith {}; - _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - - // fire again - _unit forceWeaponFire [_muzzle, _firemode]; - - } else { - // fired, clean up - _unit removeEventHandler ["AnimChanged", _thisEventHandler]; - }; + params ["_unit", "_anim"]; + if !(_unit getVariable ["zen_projectiles_thrown", false]) then { + // haven't fired yet + private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; + if (_throwParams isEqualTo []) exitWith {}; + _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + + // fire again + _unit forceWeaponFire [_muzzle, _firemode]; + + } else { + // fired, clean up + _unit removeEventHandler ["AnimChanged", _thisEventHandler]; + }; }]; // set the projectile initial velocity _unit addEventHandler ["Fired", { - params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; - - private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; - if (_throwParams isEqualTo []) exitWith {}; - _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - - private _projectilePosASL = getPosASL _projectile; - private _distance = _projectilePosASL distance2D _targetPos; - private _height = _projectilePosASL # 2 - _targetPos # 2; - private _g = 9.8066; - //private _speed = 10 + _distance / 2 - _height / 2; - private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); - - // physics - private _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 { - /* boost speed - systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; - while {_speed < 20 && {!(_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; - */ - // just go as far as possible - _angle = 45; - }; - - 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; - - _projectile setVectorDirAndUp [ - _vectorFinal, - _vectorUp - ]; - - // set velocity - _projectile setVelocity _vectorFinal; - - // clean up - _unit removeEventHandler ["Fired", _thisEventHandler]; - _unit setVariable ["zen_projectiles_thrown", true]; - _unit enableAI "PATH"; - - /* test draw sight and aim lines - amp_projectiles_unit = _unit; - amp_projectiles_projectile = _projectile; - amp_projectiles_projectilePos = getPos _projectile; - amp_projectiles_targetPos = ASLToAGL _targetPos; - amp_projectiles_velocity = _vectorFinal; - onEachFrame { - drawLine3D [amp_projectiles_projectilePos, amp_projectiles_targetPos, [0,1,0,1]]; // sight line - drawLine3D [amp_projectiles_targetPos, amp_projectiles_targetPos vectorAdd [0,0,10], [0,1,0,1]]; // vertical goal post - drawLine3D [amp_projectiles_projectilePos, amp_projectiles_projectilePos vectorAdd amp_projectiles_velocity, [0,0,1,1]]; // aim line, initial angle - }; - */ + params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; + + private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; + if (_throwParams isEqualTo []) exitWith {}; + _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + + private _projectilePosASL = getPosASL _projectile; + private _distance = _projectilePosASL distance2D _targetPos; + private _height = _projectilePosASL # 2 - _targetPos # 2; + private _g = 9.8066; + //private _speed = 10 + _distance / 2 - _height / 2; + private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); + + // physics + private _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 { + /* boost speed + systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; + while {_speed < 20 && {!(_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; + */ + // just go as far as possible + _angle = 45; + }; + + 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; + + _projectile setVectorDirAndUp [ + _vectorFinal, + _vectorUp + ]; + + // set velocity + _projectile setVelocity _vectorFinal; + + // clean up + _unit removeEventHandler ["Fired", _thisEventHandler]; + _unit setVariable ["zen_projectiles_thrown", true]; + _unit enableAI "PATH"; + + /* test draw sight and aim lines + amp_projectiles_unit = _unit; + amp_projectiles_projectile = _projectile; + amp_projectiles_projectilePos = getPos _projectile; + amp_projectiles_targetPos = ASLToAGL _targetPos; + amp_projectiles_velocity = _vectorFinal; + onEachFrame { + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_targetPos, [0,1,0,1]]; // sight line + drawLine3D [amp_projectiles_targetPos, amp_projectiles_targetPos vectorAdd [0,0,10], [0,1,0,1]]; // vertical goal post + drawLine3D [amp_projectiles_projectilePos, amp_projectiles_projectilePos vectorAdd amp_projectiles_velocity, [0,0,1,1]]; // aim line, initial angle + }; + */ }]; _unit setVariable ["zen_projectiles_thrown", false]; @@ -169,46 +169,46 @@ _unit setVariable ["zen_projectiles_time", diag_tickTime]; private _canAdd = _unit canAdd _magazine; private _removedItems = []; if !_canAdd then { - private _backpackContainer = backpackContainer _unit; - if (_backpackContainer isEqualTo objNull) then { - _unit addBackpackGlobal "B_TacticalPack_blk"; - _backpackContainer = backpackContainer _unit; - }; - - while {!(_unit canAddItemToBackpack _magazine)} do { - private _item = (backpackItems _unit) # 0; - _unit removeItemFromBackpack _item; - _removedItems pushBack _item; - }; + private _backpackContainer = backpackContainer _unit; + if (_backpackContainer isEqualTo objNull) then { + _unit addBackpackGlobal "B_TacticalPack_blk"; + _backpackContainer = backpackContainer _unit; + }; + + while {!(_unit canAddItemToBackpack _magazine)} do { + private _item = (backpackItems _unit) # 0; + _unit removeItemFromBackpack _item; + _removedItems pushBack _item; + }; }; _unit addMagazineGlobal _magazine; [{ - params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - // make unit turn towards target - private _dirUnit = getDir _unit; - private _dirTarget = _unit getDir _targetPos; - private _dirDiff = _dirTarget - _dirUnit; - if (abs _dirDiff > 180) then {_dirDiff = abs _dirDiff - 360}; - (abs _dirDiff < 35) + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + // make unit turn towards target + private _dirUnit = getDir _unit; + private _dirTarget = _unit getDir _targetPos; + private _dirDiff = _dirTarget - _dirUnit; + if (abs _dirDiff > 180) then {_dirDiff = abs _dirDiff - 360}; + (abs _dirDiff < 35) },{ - params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - // close enough, make unit face target - private _dirUnit = getDir _unit; - private _dirTarget = _unit getDir _targetPos; - private _dirDiff = _dirTarget - _dirUnit; - if (abs _dirDiff > 5) then { _unit setDir _dirTarget;}; - [{ - params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; - _unit forceWeaponFire [_muzzle, _firemode]; - }, _this, 0.1] call CBA_fnc_waitAndExecute; + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + // close enough, make unit face target + private _dirUnit = getDir _unit; + private _dirTarget = _unit getDir _targetPos; + private _dirDiff = _dirTarget - _dirUnit; + if (abs _dirDiff > 5) then { _unit setDir _dirTarget;}; + [{ + params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + _unit forceWeaponFire [_muzzle, _firemode]; + }, _this, 0.1] call CBA_fnc_waitAndExecute; }, _this, 15, {}] call CBA_fnc_waitUntilAndExecute; _unit setVariable ["zen_projectiles_thrown", nil]; _unit enableAI "PATH"; if !_canAdd then { - { - _unit addItemToBackpack _x; - } forEach _removedItems; + { + _unit addItemToBackpack _x; + } forEach _removedItems; }; diff --git a/addons/modules/functions/fnc_projectiles_zeus.sqf b/addons/modules/functions/fnc_projectiles_zeus.sqf index 38c6653be..6a7c60a30 100644 --- a/addons/modules/functions/fnc_projectiles_zeus.sqf +++ b/addons/modules/functions/fnc_projectiles_zeus.sqf @@ -1,6 +1,6 @@ /* Author: Ampers - Check if projectile can reach target, then remote executes on the unit. + Check if projectile can reach target, then remote executes on the unit. * Arguments: * 0: Unit @@ -11,7 +11,7 @@ * * Return Value: * NONE - + * Example: * [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call tft_zeus_fnc_zeusProjectile; */ @@ -24,8 +24,8 @@ private _intersections = lineIntersectsSurfaces [AGLToASL _position0, _mousePosA private _targetPos = _mousePosASL; if !(_intersections isEqualTo []) then { - _targetPos = _intersections # 0 # 0; - //systemChat str _targetPos; + _targetPos = _intersections # 0 # 0; + //systemChat str _targetPos; }; // check if can reach @@ -37,8 +37,8 @@ private _g = 9.8066; private _angle = (acos((_g * _distance^2/_initSpeed^2-_height)/(_eyePos distance _targetPos)) + atan (_distance / _height)) / 2; if !(_angle isEqualType 0) then { - // if can't reach, notify zeus. Will try to throw as far as possible - [objNull, format ["Can't reach target! D:%1 H:%2", _distance, _height]] call bis_fnc_showCuratorFeedbackMessage; + // if can't reach, notify zeus. Will try to throw as far as possible + [objNull, format ["Can't reach target! D:%1 H:%2", _distance, _height]] call bis_fnc_showCuratorFeedbackMessage; }; if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlatTrajectory = true;}; From 90bda128056b1cc055a2677e7551cd3fee632a3a Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 14 May 2020 11:58:42 -0400 Subject: [PATCH 16/26] Tabs to spaces --- .../fnc_projectiles_ballisticVector.sqf | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/addons/modules/functions/fnc_projectiles_ballisticVector.sqf b/addons/modules/functions/fnc_projectiles_ballisticVector.sqf index af1494fe4..2ada16bb8 100644 --- a/addons/modules/functions/fnc_projectiles_ballisticVector.sqf +++ b/addons/modules/functions/fnc_projectiles_ballisticVector.sqf @@ -1,6 +1,6 @@ /* Author: Ampersand - Find the + Find the * Arguments: * 0: Projectile @@ -15,7 +15,7 @@ * * 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; @@ -34,24 +34,24 @@ private _angle = ""; // physics if (_speed > 0) then { - _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; -}; + _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 (_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; }; @@ -66,23 +66,23 @@ private _vectorLaunch = vectorNormalized (_vectorDir vectorAdd [0,0,_speedY/_spe // 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 _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; From eb9dd683630fafd13f0d2125060d35c97dff8dd7 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Thu, 14 May 2020 13:11:44 -0400 Subject: [PATCH 17/26] Nicer Icons --- addons/modules/CfgVehicles.hpp | 3 +++ addons/modules/ui/ugl_shell_ca.paa | Bin 0 -> 5625 bytes 2 files changed, 3 insertions(+) create mode 100644 addons/modules/ui/ugl_shell_ca.paa diff --git a/addons/modules/CfgVehicles.hpp b/addons/modules/CfgVehicles.hpp index 512326c94..acac5de5e 100644 --- a/addons/modules/CfgVehicles.hpp +++ b/addons/modules/CfgVehicles.hpp @@ -322,18 +322,21 @@ class CfgVehicles { 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; diff --git a/addons/modules/ui/ugl_shell_ca.paa b/addons/modules/ui/ugl_shell_ca.paa new file mode 100644 index 0000000000000000000000000000000000000000..6651ae1619759827a11674bf4259de0525a8ea8c GIT binary patch literal 5625 zcmeHLL1+^}6#ctoX(KcSH5goj0V@h(Bp|u;kO@L!KrzrAt)S4>a~tsBE!K*di!l%o z>O~J8yv9qA97HIzLQ9V!xDpQrdNj8-kh=aqn@!?c4}z;ryPw(Jyv)x0`EO?bzFEac zr4riZ)QyA(0NU;L34x~)*9aSEgj0#DNx~8ygeQ~9>kNNC#3Szqcyv%u9)D&G z7y$O*n#+L8fMX2EkS>jSnOcY8<@m*i{HivsE1pCh2qEX z_f7oO+QE!pjjm)n8%5*JH;SLuJ+1bE^>4#!G@q*%cb3ihXH48Y#3w_Q{D8$UsjG_!Vi&x7$}_yh5qO!WEa{&M5rzw>|Q;LU$9x}9xS zX7n89KU4r5RDAKLWh)Qzpup35clGmNG=8#<5{WQlnn(%5`}DgbcNy5*41^&JKwlV4 z3**I-=Jd~A#YdlFj;PF?rZj=uDrsbraH!tJJ=yHk_Glnzl7Qki%FE6uOG#9IyYv zzt~pw{1XFxbIQMOeJu;P Date: Mon, 8 Jun 2020 12:21:01 -0400 Subject: [PATCH 18/26] Update config.cpp --- addons/modules/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index 3782a0db3..e6512d05b 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -78,7 +78,7 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"zen_attributes"}; author = ECSTRING(main,Author); - authors[] = {"mharis001", "Ampersand"}; + authors[] = {"mharis001"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; From 76120e62dee45513b659277dc1036d23ff75eaa2 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Wed, 24 Jun 2020 10:22:52 -0400 Subject: [PATCH 19/26] Revert "Update config.cpp" This reverts commit 07aefb106cf8c2ed07138f7263351598004fd585. --- addons/modules/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index e6512d05b..3782a0db3 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -78,7 +78,7 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"zen_attributes"}; author = ECSTRING(main,Author); - authors[] = {"mharis001"}; + authors[] = {"mharis001", "Ampersand"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; From 296f069f5c0e81fad200be8a85070d08e6a112fc Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Wed, 24 Jun 2020 10:28:21 -0400 Subject: [PATCH 20/26] Authors --- addons/modules/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/modules/config.cpp b/addons/modules/config.cpp index 3782a0db3..e6512d05b 100644 --- a/addons/modules/config.cpp +++ b/addons/modules/config.cpp @@ -78,7 +78,7 @@ class CfgPatches { requiredVersion = REQUIRED_VERSION; requiredAddons[] = {"zen_attributes"}; author = ECSTRING(main,Author); - authors[] = {"mharis001", "Ampersand"}; + authors[] = {"mharis001"}; url = ECSTRING(main,URL); VERSION_CONFIG; }; From 78f397b382197ac39b64c0ab086f32b0d3bd3867 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 26 Jun 2020 11:14:47 -0400 Subject: [PATCH 21/26] add return --- addons/modules/functions/fnc_projectiles_zeus.sqf | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/modules/functions/fnc_projectiles_zeus.sqf b/addons/modules/functions/fnc_projectiles_zeus.sqf index 6a7c60a30..8c70865f8 100644 --- a/addons/modules/functions/fnc_projectiles_zeus.sqf +++ b/addons/modules/functions/fnc_projectiles_zeus.sqf @@ -45,3 +45,4 @@ if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlat [_unit, _magazine, _muzzle, _firemode, _targetPos, zen_projectiles_throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; +true From a4d9a18179d6a43d35fcd1b010dd89a99cddd6f9 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 26 Jun 2020 13:08:11 -0400 Subject: [PATCH 22/26] Soft launch --- .../functions/fnc_projectiles_unit.sqf | 114 ++++++++++-------- .../functions/fnc_projectiles_zeus.sqf | 13 +- 2 files changed, 76 insertions(+), 51 deletions(-) diff --git a/addons/modules/functions/fnc_projectiles_unit.sqf b/addons/modules/functions/fnc_projectiles_unit.sqf index 0027e4b25..9e65796e9 100644 --- a/addons/modules/functions/fnc_projectiles_unit.sqf +++ b/addons/modules/functions/fnc_projectiles_unit.sqf @@ -72,62 +72,82 @@ _unit addEventHandler ["AnimChanged", { _unit addEventHandler ["Fired", { params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"]; + // clean up + _unit removeEventHandler ["Fired", _thisEventHandler]; + _unit setVariable ["zen_projectiles_thrown", true]; + _unit enableAI "PATH"; + private _throwParams = _unit getVariable ["zen_projectiles_throwParams", []]; if (_throwParams isEqualTo []) exitWith {}; _throwParams params ["_unit", "_magazine", "_muzzle", "_firemode", "_targetPos", "_throwFlatTrajectory"]; + // SACLOS + if ( + isNumber (configfile >> "CfgAmmo" >> _ammo >> "manualControl") && + {1 == (getNumber (configfile >> "CfgAmmo" >> _ammo >> "manualControl"))} + ) then { + _projectile setMissileTargetPos (ASLToAGL _targetPos); + }; + private _projectilePosASL = getPosASL _projectile; private _distance = _projectilePosASL distance2D _targetPos; private _height = _projectilePosASL # 2 - _targetPos # 2; private _g = 9.8066; - //private _speed = 10 + _distance / 2 - _height / 2; - private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); - - // physics - private _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 { - /* boost speed - systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; - while {_speed < 20 && {!(_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; - */ - // just go as far as possible - _angle = 45; - }; - - 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]; + private _speed = getNumber (configFile >> "CfgAmmo" >> _ammo >> "maxSpeed"); + if (_speed == 0) then { + _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); + }; - if (_angleLOS_Launch > (_angleLOS_Vert / 2)) then { - if (_angleLOS_Vert > 90) then { - _angleHORZ_LOS = -1 * _angleHORZ_LOS; + _maneuvrability = getNumber (configFile >> "CfgAmmo" >> _ammo >> "maneuvrability"); + private _vectorLaunch = _projectilePosASL vectorFromTo _targetPos; + if (_maneuvrability <= 1) then { + // physics + private _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 { + /* boost speed + systemChat format ["d:%1, h:%2, s:%3, a:%4",_distance, _height, _speed, _angle]; + while {_speed < 20 && {!(_angle isEqualType 0)}} do { + _speed = _speed + 1; + _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; }; - _angle = _angleLaunch_Vert + _angleHORZ_LOS; - //systemChat format ["FA:%1",_angle]; + _speed = _speed + 2; + _angle = (acos((_g * _distance^2/_speed^2-_height)/(_projectilePosASL distance _targetPos)) + atan (_distance / _height)) / 2; + */ + // just go as far as possible + _angle = 45; + }; - _speedY = _speed * sin _angle; - _speedx = _speed * cos _angle; - _vectorLaunch = vectorNormalized (_vectorDir vectorAdd [0,0,_speedY/_speedX]); + 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]; + _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]); + }; }; }; @@ -144,11 +164,6 @@ _unit addEventHandler ["Fired", { // set velocity _projectile setVelocity _vectorFinal; - // clean up - _unit removeEventHandler ["Fired", _thisEventHandler]; - _unit setVariable ["zen_projectiles_thrown", true]; - _unit enableAI "PATH"; - /* test draw sight and aim lines amp_projectiles_unit = _unit; amp_projectiles_projectile = _projectile; @@ -166,6 +181,7 @@ _unit addEventHandler ["Fired", { _unit setVariable ["zen_projectiles_thrown", false]; _unit setVariable ["zen_projectiles_time", diag_tickTime]; +// add ammo to unit private _canAdd = _unit canAdd _magazine; private _removedItems = []; if !_canAdd then { diff --git a/addons/modules/functions/fnc_projectiles_zeus.sqf b/addons/modules/functions/fnc_projectiles_zeus.sqf index 8c70865f8..a3d73370b 100644 --- a/addons/modules/functions/fnc_projectiles_zeus.sqf +++ b/addons/modules/functions/fnc_projectiles_zeus.sqf @@ -29,12 +29,17 @@ if !(_intersections isEqualTo []) then { }; // check if can reach -private _initSpeed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +private _speed = getNumber (configFile >> "CfgAmmo" >> (getText (configFile >> "CfgMagazines" >> _magazine >> "ammo")) >> "maxSpeed"); +if (_speed == 0) then { + _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); +}; + +private _speed = getNumber (configFile >> "CfgMagazines" >> _magazine >> "initSpeed"); private _eyePos = eyePos _unit; private _distance = _eyePos distance2D _targetPos; private _height = _eyePos # 2 - _targetPos # 2; private _g = 9.8066; -private _angle = (acos((_g * _distance^2/_initSpeed^2-_height)/(_eyePos distance _targetPos)) + atan (_distance / _height)) / 2; +private _angle = (acos((_g * _distance^2/_speed^2-_height)/(_eyePos distance _targetPos)) + atan (_distance / _height)) / 2; if !(_angle isEqualType 0) then { // if can't reach, notify zeus. Will try to throw as far as possible @@ -43,6 +48,10 @@ if !(_angle isEqualType 0) then { if (isNil "zen_projectiles_throwFlatTrajectory") then {zen_projectiles_throwFlatTrajectory = true;}; +// trace bullet +//BIS_tracedShooter = nil; +//[_unit, 1] call BIS_fnc_traceBullets; + [_unit, _magazine, _muzzle, _firemode, _targetPos, zen_projectiles_throwFlatTrajectory] remoteExecCall ["zen_modules_fnc_projectiles_unit", _unit]; true From 622fc7e3b40c3f0612a4401f992d0f92659e0c0a Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Fri, 26 Jun 2020 13:08:33 -0400 Subject: [PATCH 23/26] Don't run if position selection is cancelled --- addons/modules/functions/fnc_moduleFireGL.sqf | 36 ++++++++++--------- .../functions/fnc_moduleFireLauncher.sqf | 12 ++++--- .../functions/fnc_moduleThrowSelect.sqf | 10 +++--- 3 files changed, 32 insertions(+), 26 deletions(-) diff --git a/addons/modules/functions/fnc_moduleFireGL.sqf b/addons/modules/functions/fnc_moduleFireGL.sqf index e169cfbce..5bdfd09e8 100644 --- a/addons/modules/functions/fnc_moduleFireGL.sqf +++ b/addons/modules/functions/fnc_moduleFireGL.sqf @@ -52,24 +52,26 @@ if (_glMuzzles isEqualTo []) exitWith { // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL"]; - private _weapons = weapons _unit; - private _glMuzzles = []; - { - private _weapon = _x; + if _successful then { + private _weapons = weapons _unit; + private _glMuzzles = []; { - 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; + 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; - }; + 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; + 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); diff --git a/addons/modules/functions/fnc_moduleFireLauncher.sqf b/addons/modules/functions/fnc_moduleFireLauncher.sqf index c4a235755..b4789aee4 100644 --- a/addons/modules/functions/fnc_moduleFireLauncher.sqf +++ b/addons/modules/functions/fnc_moduleFireLauncher.sqf @@ -41,11 +41,13 @@ if (_launcher isEqualTo "") exitWith { // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL"]; - private _weapon = secondaryWeapon _unit; + if _successful then { + private _weapon = secondaryWeapon _unit; - private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; + 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; + private _muzzle = _weapon; + private _firemode = "Single"; + [_unit, _magazine, _muzzle, _firemode, _mousePosASL] call zen_modules_fnc_projectiles_zeus; + }; }, [], LSTRING(ModuleFireLauncher)] call EFUNC(common,selectPosition); diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf index e021815bb..f55120a5d 100644 --- a/addons/modules/functions/fnc_moduleThrowSelect.sqf +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -46,10 +46,12 @@ private _action = []; // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL", "_arguments"]; - _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); + 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); }, From 669c7137949bca64a57fcabebbecc6eabc62118d Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Mon, 29 Jun 2020 11:49:27 -0400 Subject: [PATCH 24/26] if condition parens --- addons/modules/functions/fnc_moduleFireGL.sqf | 2 +- addons/modules/functions/fnc_moduleFireLauncher.sqf | 2 +- addons/modules/functions/fnc_moduleThrowSelect.sqf | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/addons/modules/functions/fnc_moduleFireGL.sqf b/addons/modules/functions/fnc_moduleFireGL.sqf index 5bdfd09e8..1088a13df 100644 --- a/addons/modules/functions/fnc_moduleFireGL.sqf +++ b/addons/modules/functions/fnc_moduleFireGL.sqf @@ -52,7 +52,7 @@ if (_glMuzzles isEqualTo []) exitWith { // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL"]; - if _successful then { + if (_successful) then { private _weapons = weapons _unit; private _glMuzzles = []; { diff --git a/addons/modules/functions/fnc_moduleFireLauncher.sqf b/addons/modules/functions/fnc_moduleFireLauncher.sqf index b4789aee4..a49ac0830 100644 --- a/addons/modules/functions/fnc_moduleFireLauncher.sqf +++ b/addons/modules/functions/fnc_moduleFireLauncher.sqf @@ -41,7 +41,7 @@ if (_launcher isEqualTo "") exitWith { // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL"]; - if _successful then { + if (_successful) then { private _weapon = secondaryWeapon _unit; private _magazine = getArray (configFile >> "CfgWeapons" >> _weapon >> "Magazines") # 0; diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf index f55120a5d..46fcf014c 100644 --- a/addons/modules/functions/fnc_moduleThrowSelect.sqf +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -46,7 +46,7 @@ private _action = []; // Get target position [_unit, { params ["_successful", "_unit", "_mousePosASL", "_arguments"]; - if _successful then { + if (_successful) then { _arguments params ["_magazine"]; private _muzzle = configName (("_magazine in (getArray (_x >> 'magazines'))" configClasses (configFile >> "CfgWeapons" >> "Throw")) # 0); private _firemode = _muzzle; From 1185850de47f1cc0f50793e1ced330005e3d989b Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Tue, 11 Aug 2020 12:37:50 -0400 Subject: [PATCH 25/26] Module List documentation --- docs/user_guide/modules_list.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/user_guide/modules_list.md b/docs/user_guide/modules_list.md index 7933b1c16..cc4abdd1f 100644 --- a/docs/user_guide/modules_list.md +++ b/docs/user_guide/modules_list.md @@ -147,6 +147,14 @@ When used in JIP mode, the module can be deleted to stop execution on new JIP cl Outputs SQF code that can be executed to restore the current mission. +## Fire GL + +Orders AI with UGL to fire the currently loaded round at the target position. + +## Fire Launcher + +Orders AI with launcher to fire the currently loaded round at the target position. + ## Fly Height Sets the flying altitude of the attached aircraft relative to the ground. @@ -245,6 +253,10 @@ The range of Auto Seek is based on the unit's spot distance skill with a minimum Teleports players from the selected side, group(s), or individual player(s) to the module's position. If the module is placed on a vehicle, players will be teleported into the vehicle. +## Throw Select + +Orders AI to throw the selected throwable from its inventory at the target position. + ## Toggle Flashlights Toggles the flashlights of all AI units of the given side (or group, when placed on a unit) to the selected state. From 1318549deb8b7e7d8537e51a96ce7fa6ba1b1db7 Mon Sep 17 00:00:00 2001 From: ampersand38 Date: Mon, 31 Aug 2020 12:42:00 -0400 Subject: [PATCH 26/26] zen_context_menu_fnc_open --- addons/modules/functions/fnc_moduleThrowSelect.sqf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/modules/functions/fnc_moduleThrowSelect.sqf b/addons/modules/functions/fnc_moduleThrowSelect.sqf index 46fcf014c..27bf6c651 100644 --- a/addons/modules/functions/fnc_moduleThrowSelect.sqf +++ b/addons/modules/functions/fnc_moduleThrowSelect.sqf @@ -60,7 +60,7 @@ private _action = []; ] call EFUNC(context_menu,createAction); [_action, [], 0] call EFUNC(context_menu,addAction); } forEach _throwables; -[] call EFUNC(context_menu,openMenu); +[] call EFUNC(context_menu,open); // remove actions on menu close [{