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

Grenades - Add grenade rolling #10005

Merged
merged 9 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions addons/compat_rhs_afrf3/CfgAmmo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ class CfgAmmo {
EGVAR(frag,force) = 0;
};

class SmokeShell;
class rhs_ammo_rdg2_white: SmokeShell {
EGVAR(grenades,rollVectorDirAndUp)[] = {{0, 1, 0}, {0, 0, 1}};
};

class Sh_125mm_APFSDS;
class Sh_125mm_HE;
Expand Down
7 changes: 7 additions & 0 deletions addons/compat_sog/CfgAmmo/grenades.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ class vn_molotov_grenade_ammo: vn_grenadehand {
EGVAR(frag,enabled) = 0;
};

class vn_t67_grenade_ammo: vn_grenadehand {
EGVAR(grenades,rollVectorDirAndUp)[] = {{-1, 0, 0}, {0, 0, 1}};
};
class vn_chicom_grenade_ammo: vn_grenadehand {
EGVAR(grenades,rollVectorDirAndUp)[] = {{1, 0, 0}, {0, 0, 1}};
};

class SmokeShell;
class vn_m14_grenade_ammo: SmokeShell {
EGVAR(grenades,incendiary) = 1;
Expand Down
24 changes: 24 additions & 0 deletions addons/grenades/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,27 @@ GVAR(flashbangPPEffectCC) ppEffectForceInNVG true;
[] call FUNC(addChangeFuseItemContextMenuOptions);
};
}] call CBA_fnc_addEventHandler;

["vehicle", {
private _currentThrowable = currentThrowable ACE_player;

// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second and player isn't in a vehicle)
if !(
GVAR(currentThrowMode) == 3 &&
{_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) exitWith {};

// If the player can't use throwables, don't change it
if !(ACE_player call CBA_fnc_canUseWeapon) exitWith {};

// Force the user into the normal throw mode
// Next throw mode after roll would be drop, which isn't ideal if the user tries to throw unknowingly...
[format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2] call EFUNC(common,displayTextStructured);

GVAR(currentThrowMode) = 0;
GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
}, true] call CBA_fnc_addPlayerEventHandler;
3 changes: 3 additions & 0 deletions addons/grenades/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;

GVAR(currentThrowMode) = 0;
GVAR(throwModePFEH) = -1;

#include "initSettings.inc.sqf"

ADDON = true;
48 changes: 44 additions & 4 deletions addons/grenades/functions/fnc_nextMode.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,26 @@
* Public: No
*/

private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0];
private _mode = GVAR(currentThrowMode);

if (_mode == 4) then {
_mode = 0;
} else {
_mode = _mode + 1;
};

// ROLL GRENADE DOESN'T WORK RIGHT NOW
if (_mode == 3) then {
_mode = 4;
private _currentThrowable = currentThrowable ACE_player;

// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second and player isn't in a vehicle)
if (
_mode == 3 &&
{_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) then {
_mode = _mode + 1;
};

private _hint = localize ([
Expand All @@ -38,6 +47,37 @@ private _hint = localize ([

[_hint] call EFUNC(common,displayTextStructured);

GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
GVAR(currentThrowMode) = _mode;

// If in rolling mode, check every frame if current throwable is rollable
if (GVAR(currentThrowMode) == 3) then {
GVAR(currentThrowable) = _currentThrowable;

GVAR(throwModePFEH) = {
private _currentThrowable = currentThrowable ACE_player;

if (GVAR(currentThrowable) isEqualTo _currentThrowable) exitWith {};

GVAR(currentThrowable) = _currentThrowable;

// Make sure grenade can be rolled if in roll mode (detonation time has to be >= 1 second and player isn't in a vehicle)
if !(
GVAR(currentThrowMode) == 3 &&
{_currentThrowable isNotEqualTo []} &&
{
!isNull objectParent ACE_player ||
{getNumber (configFile >> "CfgAmmo" >> getText (configFile >> "CfgMagazines" >> _currentThrowable select 0 >> "ammo") >> "explosionTime") < MIN_EXPLOSION_TIME_FOR_ROLL}
}
) exitWith {};

// Force the user into the normal throw mode
// Next throw mode after roll would be drop, which isn't ideal if the user tries to throw unknowingly...
[format [LLSTRING(RollGrenadeDisabled), LLSTRING(NormalThrow)], 2] call EFUNC(common,displayTextStructured);

GVAR(throwModePFEH) call CBA_fnc_removePerFrameHandler;
GVAR(currentThrowMode) = 0;
} call CBA_fnc_addPerFrameHandler;
};

true
19 changes: 16 additions & 3 deletions addons/grenades/functions/fnc_throwGrenade.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ if (getNumber (_config >> QGVAR(incendiary)) == 1) then {
if (_unit != ACE_player) exitWith {};
if (_unit getVariable [QEGVAR(advanced_throwing,primed), false]) exitWith {LOG("advanced_throwing throw");};

private _mode = missionNamespace getVariable [QGVAR(currentThrowMode), 0];
private _mode = GVAR(currentThrowMode);

if (_mode != 0) then {
private _velocity = velocity _projectile;
Expand All @@ -103,9 +103,22 @@ if (_mode != 0) then {
case 2 : {
_velocity = (_unit weaponDirection _weapon) vectorMultiply (vectorMagnitude _velocity);
};
//roll grande
//roll grenade
case 3 : {
//@todo
private _posASL = getPosASL _projectile;

// getPos is unreliable, as surfaces in some ruins are not recognised as surfaces
private _lisPos = (lineIntersectsSurfaces [_posASL, _posASL vectorAdd [0, 0, -1e11], ACE_player, objNull, true, 1, "ROADWAY", "FIRE"]) select 0;
_projectile setPosASL ((_lisPos select 0) vectorAdd [0, 0, 0.2]);

// Rotate throwables by 90° to the side by default, so cylindrical throwables can be rolled
private _vectorDirAndUp = getArray (_config >> QGVAR(rollVectorDirAndUp));
_vectorDirAndUp params [["_vectorDir", [0, 1, 0], [[]], 3], ["_vectorUp", [1, 0, 0], [[]], 3]];

// Do as if object were facing north
_projectile setVectorDirAndUp ([[_vectorDir, _vectorUp], -(direction _projectile), 0, 0] call BIS_fnc_transformVectorDirAndUp);

_velocity = (vectorDir _unit) vectorMultiply 10;
};
//drop grenade
case 4 : {
Expand Down
2 changes: 2 additions & 0 deletions addons/grenades/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
#define EFFECT_STAGE_DELETELIGHT 1
#define EFFECT_STAGE_PARTIALRECOVERY 2
#define EFFECT_STAGE_FULLRECOVERY 3

#define MIN_EXPLOSION_TIME_FOR_ROLL 1
3 changes: 3 additions & 0 deletions addons/grenades/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@
<Chinese>下丟投擲</Chinese>
<Turkish>Bombayı Yere Bırak</Turkish>
</Key>
<Key ID="STR_ACE_Grenades_RollGrenadeDisabled">
<English>Can't roll this grenade, switched to %1</English>
</Key>
<Key ID="STR_ACE_Grenades_M84_Name">
<English>M84 Stun Grenade</English>
<German>M84 Blendgranate</German>
Expand Down
2 changes: 2 additions & 0 deletions docs/wiki/feature/grenades.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ version:
### 1.1 Throw modes
Provides different modes for throwing grenades (high throw, precision throw and drop mode).

A grenade is only rollable if the fuse time (`explosionTime`) is >= 1 second and the player isn't in a vehicle.

### 1.2 Hand flares
Adds throwable hand flares in the colors white, red, green and yellow. Additionally buffs existing flares by making them brighter and last longer.

Expand Down
6 changes: 6 additions & 0 deletions docs/wiki/framework/grenades-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ If set to zero or left undefined, the grenade is not treated as a flare. If it i

Sets the color of the emitted light. The first 3 values of the array of the color, the last is the light intensity.

### 2.4 Grenade Rolling

#### 2.4.1 ace_grenades_rollVectorDirAndUp

Sets the `setVectorDirAndUp` of the grenade when the grenade is rolled.

## 3. Events

### 3.1 Listenable
Expand Down