Skip to content

Commit

Permalink
Extend KickBack functionalities
Browse files Browse the repository at this point in the history
  • Loading branch information
dystopm committed Aug 1, 2024
1 parent 576e967 commit 0ba5031
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 0 deletions.
36 changes: 36 additions & 0 deletions regamedll/dlls/weapons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,41 @@ LINK_HOOK_CLASS_VOID_CHAIN(CBasePlayerWeapon, KickBack, (float up_base, float la

void EXT_FUNC CBasePlayerWeapon::__API_HOOK(KickBack)(float up_base, float lateral_base, float up_modifier, float lateral_modifier, float up_max, float lateral_max, int direction_change)
{
#ifdef REGAMEDLL_ADD
real_t flKickUp = up_base;
float flKickLateral = lateral_base;

if (m_iShotsFired > 1) // consider == 0 case
{
flKickUp += m_iShotsFired * up_modifier;
flKickLateral += m_iShotsFired * lateral_modifier;
}

if (up_max == 0.0f) // boundaryless vertical kick
{
m_pPlayer->pev->punchangle.x -= flKickUp;
}
else if (m_pPlayer->pev->punchangle.x > -up_max) // do not kick when already out of boundaries
{
m_pPlayer->pev->punchangle.x = Q_max<real_t>(m_pPlayer->pev->punchangle.x - flKickUp, -up_max);
}

if (lateral_max == 0.0f) // boundaryless horizontal kick
{
m_pPlayer->pev->punchangle.y += flKickLateral * (m_iDirection * 2 - 1);
}
else if (Q_fabs(m_pPlayer->pev->punchangle.y) < lateral_max) // do not kick when already out of boundaries
{
m_pPlayer->pev->punchangle.y = (m_iDirection == 1) ?
Q_min(m_pPlayer->pev->punchangle.y + flKickLateral, lateral_max) :
Q_max(m_pPlayer->pev->punchangle.y - flKickLateral, -lateral_max);
}

if (direction_change > 0 && !RANDOM_LONG(0, direction_change)) // be sure to not waste RNG consumption
{
m_iDirection = !m_iDirection;
}
#else
real_t flKickUp;
float flKickLateral;

Expand Down Expand Up @@ -752,6 +787,7 @@ void EXT_FUNC CBasePlayerWeapon::__API_HOOK(KickBack)(float up_base, float later
{
m_iDirection = !m_iDirection;
}
#endif
}

void CBasePlayerWeapon::FireRemaining(int &shotsFired, float &shootTime, BOOL bIsGlock)
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_awp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,11 @@ void CAWP::AWPFire(float flSpread, float flCycleTime, BOOL fUseAutoAim)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CAWP::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_deagle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,11 @@ void CDEAGLE::DEAGLEFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2;
#endif
ResetPlayerShieldAnim();
}

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_elite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ void CELITE::ELITEFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CELITE::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_fiveseven.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ void CFiveSeven::FiveSevenFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_g3sg1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,15 @@ void CG3SG1::G3SG1Fire(float flSpread, float flCycleTime, BOOL fUseAutoAim)

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;

#ifdef REGAMEDLL_ADD
m_iDirection = 1; // force positive Y addition
KickBack(UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25f,
UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75),
0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25f;
m_pPlayer->pev->punchangle.y += UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75);
#endif
}

void CG3SG1::Reload()
Expand Down
3 changes: 3 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_glock18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,9 @@ void CGLOCK18::GLOCK18Fire(float flSpread, float flCycleTime, BOOL bFireBurst)
m_flGlock18Shoot = gpGlobals->time + 0.1f;
}

#ifdef REGAMEDLL_ADD
KickBack(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0); // dummy call, API useful
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_m3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ void CM3::PrimaryAttack()

m_fInSpecialReload = 0;

#ifdef REGAMEDLL_ADD
if (m_pPlayer->pev->flags & FL_ONGROUND)
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 4, 6), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
else
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 8, 11), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
if (m_pPlayer->pev->flags & FL_ONGROUND)
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 4, 6);
else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 8, 11);
#endif

m_pPlayer->m_flEjectBrass = gpGlobals->time + 0.45f;
}
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_p228.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ void CP228::P228Fire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2;
#endif
ResetPlayerShieldAnim();
}

Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_scout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,11 @@ void CSCOUT::SCOUTFire(float flSpread, float flCycleTime, BOOL fUseAutoAim)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
}

void CSCOUT::Reload()
Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_sg550.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,15 @@ void CSG550::SG550Fire(float flSpread, float flCycleTime, BOOL fUseAutoAim)

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.8f;

#ifdef REGAMEDLL_ADD
m_iDirection = 1; // force positive Y addition
KickBack(UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.75) + m_pPlayer->pev->punchangle.x * 0.25,
UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75),
0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomFloat(m_pPlayer->random_seed + 4, 0.75, 1.25) + m_pPlayer->pev->punchangle.x * 0.25;
m_pPlayer->pev->punchangle.y += UTIL_SharedRandomFloat(m_pPlayer->random_seed + 5, -0.75, 0.75);
#endif
}

void CSG550::Reload()
Expand Down
4 changes: 4 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_usp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ void CUSP::USPFire(float flSpread, float flCycleTime, BOOL fUseSemi)
}

m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 2.0f;
#ifdef REGAMEDLL_ADD
KickBack(2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
m_pPlayer->pev->punchangle.x -= 2.0f;
#endif
ResetPlayerShieldAnim();
}

Expand Down
7 changes: 7 additions & 0 deletions regamedll/dlls/wpn_shared/wpn_xm1014.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,17 @@ void CXM1014::PrimaryAttack()

m_fInSpecialReload = 0;

#ifdef REGAMEDLL_ADD
if (m_pPlayer->pev->flags & FL_ONGROUND)
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 3, 5), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
else
KickBack(UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 7, 10), 0.0, 0.0, 0.0, 0.0, 0.0, 0);
#else
if (m_pPlayer->pev->flags & FL_ONGROUND)
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 3, 5);
else
m_pPlayer->pev->punchangle.x -= UTIL_SharedRandomLong(m_pPlayer->random_seed + 1, 7, 10);
#endif
}

void CXM1014::Reload()
Expand Down

0 comments on commit 0ba5031

Please sign in to comment.