Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Advanced Throwing - Cleanup #10495

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 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
30 changes: 14 additions & 16 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,34 +65,31 @@ _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: %5", _phi, _power, _throwSpeed * _power, _throwableMag, ACE_player getVariable [QGVAR(activeMuzzle), ""]];
#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 1 has no impact if no appliccable throwable in inventory)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
// 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 1 has no impact if no appliccable throwable in inventory)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
// Restore muzzle ammo (setAmmo has no impact if no applicable throwable in inventory)
ACE_player setAmmo (ACE_player getVariable [QGVAR(activeMuzzle), ["", -1]]);
};
_activeThrowable = _throwableType createVehicleLocal [0, 0, 0];
_activeThrowable enableSimulation false;
ACE_player setVariable [QGVAR(activeThrowable), _activeThrowable];

// Set muzzle ammo to 0 to block vanilla throwing (can only be 0 or 1)
private _muzzle = _throwableMag call FUNC(getMuzzle);
// Set muzzle ammo to 0 to block vanilla throwing
ACE_player setVariable [QGVAR(activeMuzzle), [_muzzle, ACE_player ammo _muzzle]];
ACE_player setAmmo [_muzzle, 0];
ACE_player setVariable [QGVAR(activeMuzzle), _muzzle];
};

// Exit in case of explosion in hand
Expand Down
10 changes: 4 additions & 6 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 All @@ -38,13 +36,13 @@ if !(_unit getVariable [QGVAR(primed), false]) then {
[QEGVAR(common,setShotParents), [_activeThrowable, _unit, _instigator]] call CBA_fnc_serverEvent;
};

// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
_unit setAmmo [_unit getVariable [QGVAR(activeMuzzle), ""], 1];
// Restore muzzle ammo (setAmmo has no impact if no applicable throwable in inventory)
_unit setAmmo (_unit getVariable [QGVAR(activeMuzzle), ["", -1]]);

_unit setVariable [QGVAR(inHand), false];
_unit setVariable [QGVAR(primed), false];
_unit setVariable [QGVAR(activeThrowable), objNull];
_unit setVariable [QGVAR(activeMuzzle), ""];
_unit setVariable [QGVAR(activeMuzzle), ["", -1]];
_unit setVariable [QGVAR(throwType), THROW_TYPE_DEFAULT];
_unit setVariable [QGVAR(throwSpeed), THROW_SPEED_DEFAULT];
_unit setVariable [QGVAR(dropMode), false];
Expand Down
25 changes: 0 additions & 25 deletions addons/advanced_throwing/functions/fnc_getMuzzle.sqf
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is only used once and we can get the muzzle from currentThrowable.
Does anyone know why this function exists?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, maybe we thought there was a use in getting the muzzle for a grenade not selected
but I don't see any use for it now.

This file was deleted.

4 changes: 2 additions & 2 deletions addons/advanced_throwing/functions/fnc_prepare.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ if (_unit getVariable [QGVAR(inHand), false]) exitWith {
TRACE_1("inHand",_unit);
if !(_unit getVariable [QGVAR(primed), false]) then {
TRACE_1("not primed",_unit);
// Restore muzzle ammo (setAmmo 1 has no impact if no appliccable throwable in inventory)
// Restore muzzle ammo (setAmmo has no impact if no applicable throwable in inventory)
// selectNextGrenade relies on muzzles array (setAmmo 0 removes the muzzle from the array and current can't be found, cycles between 0 and 1 muzzles)
ACE_player setAmmo [ACE_player getVariable [QGVAR(activeMuzzle), ""], 1];
ACE_player setAmmo (ACE_player getVariable [QGVAR(activeMuzzle), ["", -1]]);
[_unit] call EFUNC(weaponselect,selectNextGrenade);
};
};
Expand Down
34 changes: 24 additions & 10 deletions addons/advanced_throwing/functions/fnc_prime.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,32 @@ _unit setVariable [QGVAR(primed), true];

// Remove item before cooking to prevent weaponselect showing more throwables than there actually are in inventory
private _throwableMag = (currentThrowable _unit) select 0;
_unit removeItem _throwableMag;
private _config = configFile >> "CfgMagazines" >> _throwableMag;

private _throwableType = getText (configFile >> "CfgMagazines" >> _throwableMag >> "ammo");
private _muzzle = _unit getVariable [QGVAR(activeMuzzle), ""];
(_unit getVariable [QGVAR(activeMuzzle), ["", -1]]) params ["_muzzle", "_ammoCount"];

// Set muzzle ammo to 0 to block vanilla throwing (can only be 0 or 1), removeItem above resets it
// If there is 1 "round" left in the grenade, remove it from the player's inventory
if (_ammoCount == 1) then {
// Grenade has ammo set to 0, so remove that one specifically
[_unit, _throwableMag, 0] call EFUNC(common,removeSpecificMagazine);

// Get ammo count of new magazine
_unit setVariable [QGVAR(activeMuzzle), [_muzzle, _unit ammo _muzzle]];
} else {
if (_ammoCount > 1 && {getNumber (_config >> "count") > 1}) then {
_unit setVariable [QGVAR(activeMuzzle), [_muzzle, _ammoCount - 1]];
};
};

// Set muzzle ammo to 0 to block vanilla throwing, removing magazine above resets it
_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 All @@ -59,10 +73,10 @@ deleteVehicle _activeThrowableOld;

if (_showHint) then {
// Show primed hint
private _displayNameShort = getText (configFile >> "CfgMagazines" >> _throwableMag >> "displayNameShort");
private _picture = getText (configFile >> "CfgMagazines" >> _throwableMag >> "picture");
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
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