Skip to content

Commit

Permalink
Advanced Throwing - Cleanup (#10495)
Browse files Browse the repository at this point in the history
* Fix adv. throwing for multiple round grenades

* Cleanup adv. throwing

* Minor optimisation and cleanup
  • Loading branch information
johnb432 authored Nov 22, 2024
1 parent c3a6e28 commit defbf33
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 54 deletions.
1 change: 0 additions & 1 deletion addons/advanced_throwing/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PREP(canThrow);
PREP(drawArc);
PREP(drawThrowable);
PREP(exitThrowMode);
PREP(getMuzzle);
PREP(moduleInit);
PREP(onKeyDown);
PREP(onMouseButtonDown);
Expand Down
6 changes: 3 additions & 3 deletions addons/advanced_throwing/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!hasInterface) exitWith {};
GVAR(tempWindInfo) = false;

// Add keybinds
["ACE3 Weapons", QGVAR(prepare), localize LSTRING(Prepare), {
["ACE3 Weapons", QGVAR(prepare), LLSTRING(Prepare), {
// Condition
if !([ACE_player] call FUNC(canPrepare)) exitWith {false};
if (EGVAR(common,isReloading)) exitWith {true};
Expand All @@ -22,7 +22,7 @@ GVAR(tempWindInfo) = false;
true
}, {false}, [34, [true, false, false]], false] call CBA_fnc_addKeybind; // Shift + G

["ACE3 Weapons", QGVAR(dropModeToggle), localize LSTRING(DropModeToggle), {
["ACE3 Weapons", QGVAR(dropModeToggle), LLSTRING(DropModeToggle), {
// Condition
if (!(ACE_player getVariable [QGVAR(inHand), false]) || {underwater ACE_player}) exitWith {false};

Expand All @@ -35,7 +35,7 @@ GVAR(tempWindInfo) = false;
true
}, {false}, [34, [false, true, false]], false] call CBA_fnc_addKeybind; // Ctrl + G

["ACE3 Weapons", QGVAR(dropModeHold), localize LSTRING(DropModeHold), {
["ACE3 Weapons", QGVAR(dropModeHold), LLSTRING(DropModeHold), {
// Condition
if !(ACE_player getVariable [QGVAR(inHand), false]) exitWith {false};

Expand Down
6 changes: 4 additions & 2 deletions addons/advanced_throwing/functions/fnc_canThrow.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ params ["_unit"];

if !(_unit getVariable [QGVAR(inHand), false]) exitWith {false};

if (!isNull objectParent _unit) exitWith {
private _vehicle = objectParent _unit;

if (!isNull _vehicle) exitWith {
private _startPos = eyePos _unit;
private _aimLinePos = AGLToASL (positionCameraToWorld [0, 0, 1]);
private _intersections = lineIntersectsSurfaces [_startPos, _aimLinePos, _unit, objNull, false];
//TRACE_1("Intersections",_intersections);

(_intersections select {(vehicle _unit) in (_x select 3)}) isEqualTo []
_intersections findIf {_vehicle in (_x select 3)} == -1
};

true
18 changes: 8 additions & 10 deletions addons/advanced_throwing/functions/fnc_drawThrowable.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@ private _primed = ACE_player getVariable [QGVAR(primed), false];
private _activeThrowable = ACE_player getVariable [QGVAR(activeThrowable), objNull];

// Exit if throwable died primed in hand
if (isNull _activeThrowable && {_primed}) exitWith {
if (_primed && {isNull _activeThrowable}) exitWith {
[ACE_player, "Throwable died primed in hand"] call FUNC(exitThrowMode);
};

private _throwable = currentThrowable ACE_player;

// Inventory check
if (_throwable isEqualTo [] && {!_primed}) exitWith {
if (!_primed && {_throwable isEqualTo []}) exitWith {
[ACE_player, "No valid throwables"] call FUNC(exitThrowMode);
};

private _throwableMag = _throwable param [0, "#none"];
_throwable params ["_throwableMag", "_muzzle"];

// If not primed, double check we actually have the magazine in inventory
if ((!_primed) && {!((_throwableMag in (uniformItems ACE_player)) || {_throwableMag in (vestItems ACE_player)} || {_throwableMag in (backpackItems ACE_player)})}) exitWith {
// Can't use ace_common_fnc_hasMagazine, as it doesn't account for empty mags (grenade is emptied so that it can't be thrown via vanilla keybind)
if (!_primed && {!(_throwableMag in (magazines [ACE_player, true]))}) exitWith {
[ACE_player, "No valid throwable (glitched currentThrowable)"] call FUNC(exitThrowMode);
};

Expand All @@ -64,21 +65,19 @@ _phi = [_phi, 360 - _phi] select (_phi > 180);
private _power = linearConversion [0, 180, _phi - 30, 1, 0.3, true];
ACE_player setVariable [QGVAR(throwSpeed), _throwSpeed * _power];

#ifdef DEBUG_MODE_FULL
hintSilent format ["Heading: %1\nPower: %2\nSpeed: %3\nThrowMag: %4\nMuzzle & ammo: %5", _phi, _power, _throwSpeed * _power, _throwableMag, ACE_player getVariable [QGVAR(activeMuzzle), ["", -1]]];
#endif
TRACE_5("",_phi,_power,_throwSpeed * _power,_throwableMag,ACE_player getVariable ARR_2([QGVAR(activeMuzzle),ARR_2(["",-1])]));

private _throwableType = getText (configFile >> "CfgMagazines" >> _throwableMag >> "ammo");

if (!([ACE_player] call FUNC(canThrow)) && {!_primed}) exitWith {
if (!_primed && {!([ACE_player] call FUNC(canThrow))}) exitWith {
if (!isNull _activeThrowable) then {
deleteVehicle _activeThrowable;
// Restore muzzle ammo (setAmmo has no impact if no applicable throwable in inventory)
ACE_player setAmmo (ACE_player getVariable [QGVAR(activeMuzzle), ["", -1]]);
};
};

if (isNull _activeThrowable || {(_throwableType != typeOf _activeThrowable) && {!_primed}}) then {
if (isNull _activeThrowable || {!_primed && {_throwableType != typeOf _activeThrowable}}) then {
if (!isNull _activeThrowable) then {
deleteVehicle _activeThrowable;
// Restore muzzle ammo (setAmmo has no impact if no applicable throwable in inventory)
Expand All @@ -89,7 +88,6 @@ if (isNull _activeThrowable || {(_throwableType != typeOf _activeThrowable) && {
ACE_player setVariable [QGVAR(activeThrowable), _activeThrowable];

// Set muzzle ammo to 0 to block vanilla throwing
private _muzzle = _throwableMag call FUNC(getMuzzle);
ACE_player setVariable [QGVAR(activeMuzzle), [_muzzle, ACE_player ammo _muzzle]];
ACE_player setAmmo [_muzzle, 0];
};
Expand Down
4 changes: 1 addition & 3 deletions addons/advanced_throwing/functions/fnc_exitThrowMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ TRACE_2("params",_unit,_reason);

if !(_unit getVariable [QGVAR(inHand), false]) exitWith {};

#ifdef DEBUG_MODE_FULL
systemChat format ["Exit Throw Mode: %1", _reason];
#endif
TRACE_1("Exit Throw Mode",_reason);

private _activeThrowable = _unit getVariable [QGVAR(activeThrowable), objNull];
if !(_unit getVariable [QGVAR(primed), false]) then {
Expand Down
25 changes: 0 additions & 25 deletions addons/advanced_throwing/functions/fnc_getMuzzle.sqf

This file was deleted.

8 changes: 4 additions & 4 deletions addons/advanced_throwing/functions/fnc_prime.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ if (_ammoCount == 1) then {
_unit setAmmo [_muzzle, 0];

private _throwableType = getText (_config >> "ammo");
private _ammoConfig = configFile >> "CfgAmmo" >> _throwableType;

// Handle weird scripted grenades (RHS) which could cause unexpected behaviour
private _nonInheritedCfg = configProperties [configFile >> "CfgAmmo" >> _throwableType, 'configName _x == QGVAR(replaceWith)', false];
if ((count _nonInheritedCfg) == 1) then {
_throwableType = getText (_nonInheritedCfg select 0);
if (inheritsFrom (_ammoConfig >> QGVAR(replaceWith)) isEqualTo _ammoConfig) then {
_throwableType = getText (_ammoConfig >> QGVAR(replaceWith));
};

// Create actual throwable globally
Expand Down Expand Up @@ -76,7 +76,7 @@ if (_showHint) then {
private _displayNameShort = getText (_config >> "displayNameShort");
private _picture = getText (_config >> "picture");

[[_displayNameShort, localize LSTRING(Primed)] joinString " ", _picture] call EFUNC(common,displayTextPicture);
[[_displayNameShort, LLSTRING(Primed)] joinString " ", _picture] call EFUNC(common,displayTextPicture);

// Change controls hint for RMB
call FUNC(updateControlsHint);
Expand Down
2 changes: 1 addition & 1 deletion addons/advanced_throwing/functions/fnc_throw.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if !(_unit getVariable [QGVAR(primed), false]) then {
};

// Calculate torque of thrown grenade
private _config = configFile >> "CfgAmmo" >> typeOf _activeThrowable;
private _config = configOf _activeThrowable;
private _torqueDir = getArray (_config >> QGVAR(torqueDirection));
_torqueDir = if (_torqueDir isEqualTypeArray [0,0,0]) then { vectorNormalized _torqueDir } else { [0,0,0] };
private _torqueMag = getNumber (_config >> QGVAR(torqueMagnitude));
Expand Down
1 change: 1 addition & 0 deletions addons/advanced_throwing/functions/fnc_throwFiredXEH.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
*
* Public: No
*/

params ["_unit", "", "_muzzle", "", "_ammo"];
TRACE_1("Fired",_this);

Expand Down
8 changes: 4 additions & 4 deletions addons/advanced_throwing/functions/fnc_updateControlsHint.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ if (!GVAR(showMouseControls)) exitWith {};

private _primed = ACE_player getVariable [QGVAR(primed), false];

private _mmb = [localize LSTRING(ChangeMode), localize LSTRING(Extend)] select (ACE_player getVariable [QGVAR(dropMode), false]);
private _mmb = [LLSTRING(ChangeMode), LLSTRING(Extend)] select (ACE_player getVariable [QGVAR(dropMode), false]);

if (!_primed) then {
_mmb = [_mmb, localize LSTRING(Cook)] joinString " / ";
_mmb = [_mmb, LLSTRING(Cook)] joinString " / ";
};

[
localize LSTRING(Throw),
[localize ELSTRING(common,Cancel), ""] select _primed,
LLSTRING(Throw),
[LELSTRING(common,Cancel), ""] select _primed,
_mmb
] call EFUNC(interaction,showMouseHint);
2 changes: 1 addition & 1 deletion addons/advanced_throwing/initSettings.inc.sqf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
private _category = format ["ACE %1", localize LSTRING(Category)];
private _category = format ["ACE %1", LLSTRING(Category)];
[
QGVAR(enabled),
"CHECKBOX",
Expand Down

0 comments on commit defbf33

Please sign in to comment.