[HL25] Backport satchel charge/radio controls

Those who want the "legacy" behavior can comment the define in
"satchel.cpp" called "MODERN_SATCHEL_CONTROLS".
This commit is contained in:
Joël Troch 2024-08-28 14:21:38 +02:00
parent fd9713612f
commit 1c202f5812
2 changed files with 48 additions and 22 deletions

View file

@ -21,6 +21,10 @@
#include "player.h" #include "player.h"
#include "gamerules.h" #include "gamerules.h"
// If you want the "legacy" controls where primary attack is "throw first charge / detonate" and secondary attack is
// "throw extra" charge, simply comment this define.
#define MODERN_SATCHEL_CONTROLS
class CSatchelCharge : public CGrenade class CSatchelCharge : public CGrenade
{ {
void Spawn() override; void Spawn() override;
@ -333,6 +337,13 @@ void CSatchel::Holster()
void CSatchel::PrimaryAttack() void CSatchel::PrimaryAttack()
{ {
#ifdef MODERN_SATCHEL_CONTROLS
// we're reloading, don't allow fire
if (m_chargeReady != 2)
{
Throw();
}
#else
switch (m_chargeReady) switch (m_chargeReady)
{ {
case 0: case 0:
@ -342,28 +353,7 @@ void CSatchel::PrimaryAttack()
break; break;
case 1: case 1:
{ {
SendWeaponAnim(SATCHEL_RADIO_FIRE); Detonate();
edict_t* pPlayer = m_pPlayer->edict();
CBaseEntity* pSatchel = NULL;
while ((pSatchel = UTIL_FindEntityInSphere(pSatchel, m_pPlayer->pev->origin, 4096)) != NULL)
{
if (FClassnameIs(pSatchel->pev, "monster_satchel"))
{
if (pSatchel->pev->owner == pPlayer)
{
pSatchel->Use(m_pPlayer, m_pPlayer, USE_ON, 0);
m_chargeReady = 2;
}
}
}
m_chargeReady = 2;
m_flNextPrimaryAttack = GetNextAttackDelay(0.5);
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
break; break;
} }
@ -373,15 +363,23 @@ void CSatchel::PrimaryAttack()
} }
break; break;
} }
#endif
} }
void CSatchel::SecondaryAttack() void CSatchel::SecondaryAttack()
{ {
#ifdef MODERN_SATCHEL_CONTROLS
if (m_chargeReady == 1)
{
Detonate();
}
#else
if (m_chargeReady != 2) if (m_chargeReady != 2)
{ {
Throw(); Throw();
} }
#endif
} }
@ -419,6 +417,33 @@ void CSatchel::Throw()
} }
void CSatchel::Detonate()
{
SendWeaponAnim(SATCHEL_RADIO_FIRE);
edict_t* pPlayer = m_pPlayer->edict();
CBaseEntity* pSatchel = NULL;
while ((pSatchel = UTIL_FindEntityInSphere(pSatchel, m_pPlayer->pev->origin, 4096)) != NULL)
{
if (FClassnameIs(pSatchel->pev, "monster_satchel"))
{
if (pSatchel->pev->owner == pPlayer)
{
pSatchel->Use(m_pPlayer, m_pPlayer, USE_ON, 0);
m_chargeReady = 2;
}
}
}
m_chargeReady = 2;
m_flNextPrimaryAttack = GetNextAttackDelay(0.5);
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
}
void CSatchel::WeaponIdle() void CSatchel::WeaponIdle()
{ {
if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase()) if (m_flTimeWeaponIdle > UTIL_WeaponTimeBase())

View file

@ -1129,6 +1129,7 @@ public:
void Holster() override; void Holster() override;
void WeaponIdle() override; void WeaponIdle() override;
void Throw(); void Throw();
void Detonate();
bool UseDecrement() override bool UseDecrement() override
{ {