Skip to content
Closed
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
29 changes: 29 additions & 0 deletions game/neo/scripts/game_sounds_weapons.txt
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,35 @@
"wave" "weapons/srs/srs_reload.wav"
}

// SRS reload in per-step pieces (sv_neo_reload_experimental).

"weapon_srs.reload_unload"
{
"channel" "CHAN_ITEM"
"soundlevel" "SNDLVL_NORM"
"volume" "1.0"
"pitch" "PITCH_NORM"
"wave" ")weapons/srs/srs_reload_unload.wav"
}

"weapon_srs.reload_load"
{
"channel" "CHAN_ITEM"
"soundlevel" "SNDLVL_NORM"
"volume" "1.0"
"pitch" "PITCH_NORM"
"wave" ")weapons/srs/srs_reload_load.wav"
}

"weapon_srs.reload_cycle"
{
"channel" "CHAN_ITEM"
"soundlevel" "SNDLVL_NORM"
"volume" "1.0"
"pitch" "PITCH_NORM"
"wave" ")weapons/srs/srs_reload_cycle.wav"
}

//-------------------

"weapon_srs.npc_reload"
Expand Down
7 changes: 7 additions & 0 deletions game/neo/scripts/weapon_srs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#base "weapon_srs_reload_phases.txt"

// SRS

WeaponData
Expand All @@ -16,6 +18,11 @@ WeaponData
"Penetration" "65.0"
"CycleTime" "1.4"
"ReloadReadyBeforeEnd" "0.583" // the reload is done at the last reload click, this long before its animation ends

// Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers
"ReloadPhases" {}
// Chamber capacity is gameplay data; the phase timing comes from neoAssets.
"ChamberedRound" "1"

"TPMuzzleFlashScale" "0.25"

Expand Down
8 changes: 4 additions & 4 deletions src/game/shared/neo/weapons/weapon_neobasecombatweapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,10 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon
bool IsReloadPastUnload() const;

// Clip1 includes the chambered round; the magazine can hold GetMaxClip1() more.
bool HasChamberSlot() const;
bool IsRoundChambered() const;
int RoundsInMagazine() const;
int MagazineCapacity() const;
virtual bool HasChamberSlot() const;
virtual bool IsRoundChambered() const;
virtual int RoundsInMagazine() const;
virtual int MagazineCapacity() const;

protected:
bool IsReloadPhaseSystemEnabled() const;
Expand Down
148 changes: 146 additions & 2 deletions src/game/shared/neo/weapons/weapon_srs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,21 @@ BEGIN_NETWORK_TABLE(CWeaponSRS, DT_WeaponSRS)
DEFINE_NEO_BASE_WEP_NETWORK_TABLE
#ifdef CLIENT_DLL
RecvPropBool(RECVINFO(m_bNeedsBolting)),
RecvPropTime(RECVINFO(m_flBoltHomeTime)),
RecvPropTime(RECVINFO(m_flBoltStartTime)),
#else
SendPropBool(SENDINFO(m_bNeedsBolting)),
SendPropTime(SENDINFO(m_flBoltHomeTime)),
SendPropTime(SENDINFO(m_flBoltStartTime)),
#endif
END_NETWORK_TABLE()

#ifdef CLIENT_DLL
BEGIN_PREDICTION_DATA(CWeaponSRS)
DEFINE_NEO_BASE_WEP_PREDICTION
DEFINE_PRED_FIELD(m_bNeedsBolting, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE),
DEFINE_PRED_FIELD(m_flBoltHomeTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE),
DEFINE_PRED_FIELD(m_flBoltStartTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE),
END_PREDICTION_DATA()
#endif

Expand All @@ -28,13 +34,18 @@ LINK_ENTITY_TO_CLASS(weapon_srs, CWeaponSRS);

PRECACHE_WEAPON_REGISTER(weapon_srs);

// The bolt cycle after a shot; the 3_cycle row of its phase table gives when the bolt is home with the next round
static constexpr const char *VM_SEQ_CHARGE = "charge";

CWeaponSRS::CWeaponSRS()
{
m_flSoonestAttack = gpGlobals->curtime;
m_flAccuracyPenalty = 0;

m_nNumShotsFired = 0;
m_bNeedsBolting = false;
m_flBoltHomeTime = 0.0f;
m_flBoltStartTime = 0.0f;

m_weaponSeeds = {
"srspx",
Expand All @@ -52,6 +63,11 @@ void CWeaponSRS::PrimaryAttack()
return BaseClass::PrimaryAttack();
}

if (BoltPhasesBlockShot())
{
return;
}

const bool tryingToShootTooFast =
(gpGlobals->curtime < m_flLastAttackTime + GetFireRate());
if (tryingToShootTooFast)
Expand All @@ -60,6 +76,7 @@ void CWeaponSRS::PrimaryAttack()
}

m_bNeedsBolting = true;
BoltPhasesOnShot();
BaseClass::PrimaryAttack();
}

Expand All @@ -70,6 +87,11 @@ void CWeaponSRS::ItemPreFrame()
return BaseClass::ItemPreFrame();
}

if (BoltPhasesDelayCycle())
{
return BaseClass::ItemPreFrame();
}

if (m_flLastAttackTime + 0.08f <= gpGlobals->curtime)
{ // Primary attack animation finished, begin chambering a round
if (auto* pOwner = ToNEOPlayer(GetOwner())) {
Expand All @@ -83,6 +105,7 @@ void CWeaponSRS::ItemPreFrame()
SendWeaponAnim(ACT_VM_PULLBACK);
WeaponSound(SPECIAL1);
m_bNeedsBolting = false;
BoltPhasesOnCycle();
}

BaseClass::ItemPreFrame();
Expand All @@ -92,20 +115,141 @@ bool CWeaponSRS::Deploy()
{
// This is on purpose; the player is allowed to cancel the bolting animation
// with a quick-switch input.
m_bNeedsBolting = false;
m_bNeedsBolting = BoltPhasesKeepCycle();

return BaseClass::Deploy();
const bool bDeployed = BaseClass::Deploy();
BoltPhasesOnDeploy();
return bDeployed;
}

bool CWeaponSRS::Reload()
{
if (BoltPhasesBlockReload())
{
return false;
}

// The reloading animation already contains the bolting motion;
// we don't want to bolt twice.
m_bNeedsBolting = false;
BoltPhasesOnReload();

return BaseClass::Reload();
}

bool CWeaponSRS::IsBoltPending() const
{
return m_bNeedsBolting || gpGlobals->curtime < m_flBoltHomeTime;
}

bool CWeaponSRS::Holster(CBaseCombatWeapon *pSwitchingTo)
{
BoltPhasesOnHolster();
return BaseClass::Holster(pSwitchingTo);
}

bool CWeaponSRS::IsRoundChambered() const
{
if (HasChamberSlot() && IsBoltPending())
{
return false;
}

return BaseClass::IsRoundChambered();
}

// An unchambered gun completes its bolt cycle before it can fire; the press is ignored
bool CWeaponSRS::BoltPhasesBlockShot() const
{
return HasChamberSlot() && IsBoltPending();
}

// With rounds left, the chamber holds the shot's spent case until the bolt is home. A reload before then would
// count the case as a chambered round, at the unload and as the round kept through the magazine change
bool CWeaponSRS::BoltPhasesBlockReload() const
{
return HasChamberSlot() && IsBoltPending() && m_iClip1 > 0;
}

void CWeaponSRS::BoltPhasesOnShot()
{
if (!IsReloadPhaseSystemEnabled())
{
return;
}

m_flBoltHomeTime = 0.0f;
m_flBoltStartTime = 0.0f;
}

// A bolt cycle resumed by a draw waits for the draw to end
bool CWeaponSRS::BoltPhasesDelayCycle() const
{
return IsReloadPhaseSystemEnabled() && m_flBoltStartTime > gpGlobals->curtime;
}

// The round counts as chambered once the bolt is home
void CWeaponSRS::BoltPhasesOnCycle()
{
if (!IsReloadPhaseSystemEnabled())
{
return;
}

const CNEOWeaponInfo &info = GetNEOWpnData();
const int iTable = info.FindReloadTable(VM_SEQ_CHARGE);
if (iTable >= 0 && info.m_reloadTables[iTable].iNumRows > 0)
{
m_flBoltHomeTime = gpGlobals->curtime + info.m_reloadTables[iTable].rows[0].flAmmo;
}
}

// The round does not count as chambered before the bolt is home, so a cut-short cycle resumes after the draw.
// Returns whether the draw keeps the cycle
bool CWeaponSRS::BoltPhasesKeepCycle()
{
if (!IsReloadPhaseSystemEnabled())
{
return false;
}

m_flBoltHomeTime = 0.0f;
m_flBoltStartTime = 0.0f;
return m_bNeedsBolting;
}

void CWeaponSRS::BoltPhasesOnDeploy()
{
if (!IsReloadPhaseSystemEnabled() || !m_bNeedsBolting)
{
return;
}

m_flBoltStartTime = m_flNextPrimaryAttack;
}

void CWeaponSRS::BoltPhasesOnReload()
{
if (!IsReloadPhaseSystemEnabled())
{
return;
}

m_flBoltHomeTime = 0.0f;
}

// Time passes while holstered, so note that the bolt is not home for the next draw
void CWeaponSRS::BoltPhasesOnHolster()
{
if (!IsReloadPhaseSystemEnabled() || !IsBoltPending())
{
return;
}

m_bNeedsBolting = true;
m_flBoltHomeTime = 0.0f;
}

bool CWeaponSRS::CanBePickedUpByClass(int classId)
{
return classId != NEO_CLASS_JUGGERNAUT;
Expand Down
20 changes: 20 additions & 0 deletions src/game/shared/neo/weapons/weapon_srs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CWeaponSRS : public CNEOBaseCombatWeapon
virtual bool Deploy() override;
virtual void PrimaryAttack() override;
virtual bool Reload(void) OVERRIDE;
virtual bool Holster(CBaseCombatWeapon *pSwitchingTo) OVERRIDE;
bool IsRoundChambered() const OVERRIDE;

NEO_WEP_BITS_UNDERLYING_TYPE WeaponIndex() const override { return NEO_WIDX_SRS; }
virtual NEO_WEP_BITS_UNDERLYING_TYPE GetNeoWepBits(void) const override { return NEO_WEP_SRS | NEO_WEP_SCOPEDWEAPON | NEO_WEP_FIREARM; }
Expand All @@ -53,7 +55,25 @@ class CWeaponSRS : public CNEOBaseCombatWeapon
private:
CWeaponSRS(const CWeaponSRS &other);

// Whether the bolt cycle after a shot has not finished yet
bool IsBoltPending() const;

// Bolt phases (sv_neo_reload_experimental); each hook does nothing with the flag off
bool BoltPhasesBlockShot() const;
bool BoltPhasesBlockReload() const;
void BoltPhasesOnShot();
bool BoltPhasesDelayCycle() const;
void BoltPhasesOnCycle();
bool BoltPhasesKeepCycle();
void BoltPhasesOnDeploy();
void BoltPhasesOnReload();
void BoltPhasesOnHolster();

CNetworkVar(bool, m_bNeedsBolting);
// The bolt is home, and a round chambered, at this time; 0: no bolt cycle is running
CNetworkVar(float, m_flBoltHomeTime);
// A bolt cycle resumed by a draw starts no earlier than this time
CNetworkVar(float, m_flBoltStartTime);
};

#endif // NEO_WEAPON_SRS_H
Loading