From a87fab253c488daab5936903650b23ce407931de Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:50:00 -0700 Subject: [PATCH 01/13] Parse the ReloadPhases weapon-script block A weapon script may list, per viewmodel reload sequence, the reload phases it credits (drop, seat, bolt), when each counts and when each sound piece plays. Weapons without the block parse no tables, which keeps them on the existing reload. --- .../shared/neo/weapons/neo_weapon_parse.cpp | 66 +++++++++++++++++++ .../shared/neo/weapons/neo_weapon_parse.h | 54 +++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index bafe4597b6..71c9469276 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -24,6 +24,7 @@ CNEOWeaponInfo::CNEOWeaponInfo() m_flPenetration = 0.f; m_bDropOnDeath = true; iAimFOV = 0; + m_iNumReloadTables = 0; m_flVMFov = m_flVMAimFov = 0.f; m_vecVMPosOffset = m_vecVMAimPosOffset = vec3_origin; @@ -31,6 +32,70 @@ CNEOWeaponInfo::CNEOWeaponInfo() } +static ReloadPhase_t ReloadPhaseFromName(const char *pszName) +{ + static constexpr const char *PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "drop", "seat", "bolt" }; + for (int i = RELOAD_PHASE_DROPPED; i < RELOAD_PHASE_COUNT; ++i) + { + if (V_stricmp(pszName, PHASE_NAMES[i]) == 0) + { + return static_cast(i); + } + } + return RELOAD_PHASE_NONE; +} + +// "ReloadPhases" { "" { "" { "credit" "s" "sound" "name" "at" "s" } ... } ... } +void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) +{ + m_iNumReloadTables = 0; + if (!pBlock) + { + return; + } + + for (KeyValues *pSeq = pBlock->GetFirstTrueSubKey(); pSeq && m_iNumReloadTables < RELOAD_PHASE_TABLES_MAX; pSeq = pSeq->GetNextTrueSubKey()) + { + ReloadPhaseTable_t &table = m_reloadTables[m_iNumReloadTables++]; + V_strncpy(table.szSequence, pSeq->GetName(), sizeof(table.szSequence)); + table.iNumRows = 0; + + for (KeyValues *pRow = pSeq->GetFirstTrueSubKey(); pRow && table.iNumRows < RELOAD_PHASE_ROWS_MAX; pRow = pRow->GetNextTrueSubKey()) + { + const ReloadPhase_t phase = ReloadPhaseFromName(pRow->GetName()); + if (phase == RELOAD_PHASE_NONE) + { + Warning("%s: unknown reload phase \"%s\" in \"%s\"\n", szClassName, pRow->GetName(), table.szSequence); + continue; + } + + ReloadPhaseRow_t &row = table.rows[table.iNumRows++]; + row.phase = phase; + row.flCredit = pRow->GetFloat("credit"); + static constexpr const char *SOUND_KEYS[RELOAD_SOUNDS_PER_ROW][2] = { + { "sound", "at" }, { "sound2", "at2" }, { "sound3", "at3" } + }; + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + row.sounds[j].flAt = pRow->GetFloat(SOUND_KEYS[j][1]); + V_strncpy(row.sounds[j].szName, pRow->GetString(SOUND_KEYS[j][0]), sizeof(row.sounds[j].szName)); + } + } + } +} + +int CNEOWeaponInfo::FindReloadTable(const char *pszSequence) const +{ + for (int i = 0; i < m_iNumReloadTables; ++i) + { + if (V_stricmp(m_reloadTables[i].szSequence, pszSequence) == 0) + { + return i; + } + } + return -1; +} + void CNEOWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName ) { BaseClass::Parse( pKeyValuesData, szWeaponName ); @@ -39,6 +104,7 @@ void CNEOWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName m_iBullets = pKeyValuesData->GetInt( "Bullets", 1 ); m_flCycleTime = pKeyValuesData->GetFloat( "CycleTime", 0.15 ); m_flReloadReadyBeforeEnd = pKeyValuesData->GetFloat( "ReloadReadyBeforeEnd", 0.0f ); + ParseReloadPhases(pKeyValuesData->FindKey("ReloadPhases")); const char *notFoundStr = "notfound"; Q_strncpy(szViewModel2, pKeyValuesData->GetString("team2viewmodel", notFoundStr), MAX_WEAPON_STRING); diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index 040dc00649..87a12bf85a 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -12,6 +12,53 @@ #include "hl2mp_weapon_parse.h" +// A reload is a linear sequence of phases; a reload sequence credits each phase at a point of its animation +enum ReloadPhase_t +{ + RELOAD_PHASE_NONE = 0, // no reload in progress, or none pending + RELOAD_PHASE_DROPPED, // the old magazine is out + RELOAD_PHASE_SEATED, // the fresh magazine is in + RELOAD_PHASE_BOLTED, // the bolt or charging handle chambered a round + + RELOAD_PHASE_COUNT +}; + +// bits to network a phase +static constexpr int RELOAD_PHASE_BITS = 2; +static_assert((1 << RELOAD_PHASE_BITS) >= RELOAD_PHASE_COUNT, "RELOAD_PHASE_BITS cannot hold every phase"); +static constexpr int RELOAD_PHASE_TABLES_MAX = 12; +// bits to network a table index, signed so that -1 (no table) fits +static constexpr int RELOAD_PHASE_TABLE_BITS = 5; +static_assert((1 << (RELOAD_PHASE_TABLE_BITS - 1)) >= RELOAD_PHASE_TABLES_MAX, "RELOAD_PHASE_TABLE_BITS cannot hold every table index"); +static constexpr int RELOAD_PHASE_ROWS_MAX = RELOAD_PHASE_COUNT - 1; +static constexpr int RELOAD_SOUND_NAME_MAX = 64; +static constexpr int RELOAD_SEQUENCE_NAME_MAX = 32; +// a phase may need more than one sound piece, such as a magazine seat and its slap +static constexpr int RELOAD_SOUNDS_PER_ROW = 3; + +// A sound piece of a phase +struct ReloadSoundPiece_t +{ + float flAt; // when the piece's first transient plays, seconds from the sequence start + char szName[RELOAD_SOUND_NAME_MAX]; +}; + +// One phase of a reload sequence: when it is credited, and the sound pieces that go with it +struct ReloadPhaseRow_t +{ + ReloadPhase_t phase; + float flCredit; // seconds from the sequence start + ReloadSoundPiece_t sounds[RELOAD_SOUNDS_PER_ROW]; +}; + +// The phases one reload sequence carries, in order +struct ReloadPhaseTable_t +{ + char szSequence[RELOAD_SEQUENCE_NAME_MAX]; + int iNumRows; + ReloadPhaseRow_t rows[RELOAD_PHASE_ROWS_MAX]; +}; + //-------------------------------------------------------------------------------------------------------- class CNEOWeaponInfo : public CHL2MPSWeaponInfo { @@ -25,6 +72,10 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo int m_iBullets; float m_flCycleTime; float m_flReloadReadyBeforeEnd; + int m_iNumReloadTables; // 0: the weapon reloads without phases + ReloadPhaseTable_t m_reloadTables[RELOAD_PHASE_TABLES_MAX]; + + int FindReloadTable(const char *pszSequence) const; char szViewModel2[MAX_WEAPON_STRING]; // Team 2 (NSF) wep vm char szBulletCharacter[MAX_BULLET_CHARACTER];// character used to display ammunition in current clip char szDeathIcon[MAX_BULLET_CHARACTER]; @@ -39,6 +90,9 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo float m_flVMAimFov; Vector m_vecVMAimPosOffset; QAngle m_angVMAimAngOffset; + +private: + void ParseReloadPhases(::KeyValues *pBlock); }; From c8a4eb83c872724afd9c19b958d18bcb7bbdce33 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:50:42 -0700 Subject: [PATCH 02/13] Resume a reload after the magazine drop Behind sv_neo_reload_experimental (default 0), a weapon whose script has a ReloadPhases block credits the drop of its old magazine during the reload. A switch after the drop keeps that phase, and the next draw plays the weapon's draw-resume sequence, which seats the fresh magazine and pulls the bolt. A switch before the drop cancels the reload as before. The reload itself, its sound and its ready-time load are unchanged. Weapons without the block, and every weapon with the flag off, run the existing code. --- .../weapons/weapon_neobasecombatweapon.cpp | 231 ++++++++++++++++++ .../neo/weapons/weapon_neobasecombatweapon.h | 22 ++ 2 files changed, 253 insertions(+) diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 979d70f8a7..bf36975d3d 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -42,6 +42,11 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) RecvPropInt(RECVINFO(m_nNumShotsFired)), RecvPropBool(RECVINFO(m_bTriggerReset)), RecvPropTime(RECVINFO(m_flReloadReadyTime)), + RecvPropBool(RECVINFO(m_bReloadExperimentalEnabled)), + RecvPropInt(RECVINFO(m_nReloadPhase)), + RecvPropInt(RECVINFO(m_nReloadTable)), + RecvPropTime(RECVINFO(m_flReloadStart)), + RecvPropInt(RECVINFO(m_nReloadSoundsDone)), RecvPropInt(RECVINFO(m_spawnflags)), #else SendPropTime(SENDINFO(m_flSoonestAttack)), @@ -50,6 +55,11 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) SendPropInt(SENDINFO(m_nNumShotsFired)), SendPropBool(SENDINFO(m_bTriggerReset)), SendPropTime(SENDINFO(m_flReloadReadyTime)), + SendPropBool(SENDINFO(m_bReloadExperimentalEnabled)), + SendPropInt(SENDINFO(m_nReloadPhase), RELOAD_PHASE_BITS, SPROP_UNSIGNED), + SendPropInt(SENDINFO(m_nReloadTable), RELOAD_PHASE_TABLE_BITS), + SendPropTime(SENDINFO(m_flReloadStart)), + SendPropInt(SENDINFO(m_nReloadSoundsDone), RELOAD_PHASE_ROWS_MAX * RELOAD_SOUNDS_PER_ROW, SPROP_UNSIGNED), SendPropInt(SENDINFO(m_spawnflags)), SendPropExclude("DT_BaseAnimating", "m_nSequence"), #endif @@ -63,6 +73,11 @@ BEGIN_PREDICTION_DATA(CNEOBaseCombatWeapon) DEFINE_PRED_FIELD(m_nNumShotsFired, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_bTriggerReset, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_flReloadReadyTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_bReloadExperimentalEnabled, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadPhase, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadTable, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flReloadStart, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_nReloadSoundsDone, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -76,11 +91,18 @@ BEGIN_DATADESC( CNEOBaseCombatWeapon ) DEFINE_FIELD(m_nNumShotsFired, FIELD_INTEGER), DEFINE_FIELD(m_bTriggerReset, FIELD_BOOLEAN), DEFINE_FIELD(m_flReloadReadyTime, FIELD_TIME), + DEFINE_FIELD(m_bReloadExperimentalEnabled, FIELD_BOOLEAN), + DEFINE_FIELD(m_nReloadPhase, FIELD_INTEGER), + DEFINE_FIELD(m_nReloadTable, FIELD_INTEGER), + DEFINE_FIELD(m_flReloadStart, FIELD_TIME), + DEFINE_FIELD(m_nReloadSoundsDone, FIELD_INTEGER), END_DATADESC() #endif ConVar sv_neo_accuracy_penalty_scale("sv_neo_accuracy_penalty_scale", "1.0", FCVAR_REPLICATED, "Scales the accuracy penalty per shot.", true, 0.0f, true, 2.0f); ConVar sv_neo_dynamic_viewkick("sv_neo_dynamic_viewkick", "0", FCVAR_REPLICATED, "Enables view kick scaling based on current inaccuracy.", true, 0.0f, true, 1.0f); +ConVar sv_neo_reload_experimental("sv_neo_reload_experimental", "0", FCVAR_REPLICATED, + "Server reload-phase setting; set before a game starts; mid-game changes are unsupported."); const char *GetWeaponByLoadoutId(int id) { @@ -232,7 +254,12 @@ static const WeaponHandlingInfo_t handlingTable[] = { CNEOBaseCombatWeapon::CNEOBaseCombatWeapon( void ) { + m_bReloadExperimentalEnabled = sv_neo_reload_experimental.GetBool(); m_bTriggerReset = true; + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; + m_flReloadStart = 0.0f; + m_nReloadSoundsDone = 0; } const CNEOWeaponInfo &CNEOBaseCombatWeapon::GetNEOWpnData() const @@ -418,6 +445,9 @@ void CNEOBaseCombatWeapon::Equip(CBaseCombatCharacter* pOwner) } +// The shipped reload sequence +static constexpr const char *VM_SEQ_RELOAD = "reload"; + bool CNEOBaseCombatWeapon::Reload( void ) { const bool bEmptyReload = UsesClipsForAmmo1() && m_iClip1 <= 0 && @@ -441,6 +471,11 @@ bool CNEOBaseCombatWeapon::Reload( void ) // the animation and the wait to fire still run to the end m_flReloadReadyTime = Max(gpGlobals->curtime, m_flNextPrimaryAttack - GetNEOWpnData().m_flReloadReadyBeforeEnd); + if (IsReloadPhaseSystemEnabled()) + { + StartReloadPhases(GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD)); + } + return true; #if(0) @@ -471,6 +506,169 @@ bool CNEOBaseCombatWeapon::Reload( void ) #endif } +// Each reload sound piece's file starts this long before its first transient +static constexpr float RELOAD_SOUND_LEAD = 0.02f; + +// The viewmodel sequence that resumes a reload interrupted after the phase credited last; nullptr: none +// (resume sequences carry no activity, so they are picked by name) +static const char *ResumeSequenceName(int iPhaseDone) +{ + switch (iPhaseDone) + { + case RELOAD_PHASE_DROPPED: + // the magazine is out: the draw itself brings the fresh one up + return "draw_resume_drop_dry"; + default: + return nullptr; + } +} + +bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const +{ + return m_bReloadExperimentalEnabled && GetNEOWpnData().m_iNumReloadTables > 0; +} + +// Credit the phases of a reload sequence that starts now (-1: a sequence without a table credits nothing) +void CNEOBaseCombatWeapon::StartReloadPhases(int iTable) +{ + m_nReloadTable = iTable; + m_flReloadStart = gpGlobals->curtime; + m_nReloadSoundsDone = 0; +} + +void CNEOBaseCombatWeapon::EndReloadPhases() +{ + m_nReloadTable = -1; + m_nReloadPhase = RELOAD_PHASE_NONE; +} + +// Credit every phase of the playing reload sequence whose time has come, and play its sound pieces +void CNEOBaseCombatWeapon::RunReloadPhases() +{ + if (!m_bInReload || m_nReloadTable < 0) + { + return; + } + + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + const float flElapsed = gpGlobals->curtime - m_flReloadStart; + + // Sound pieces play on their own times, before or after their phase's credit + for (int i = 0; i < table.iNumRows; ++i) + { + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + const ReloadSoundPiece_t &piece = table.rows[i].sounds[j]; + const int iBit = 1 << (i * RELOAD_SOUNDS_PER_ROW + j); + if (piece.szName[0] && !(m_nReloadSoundsDone & iBit) && flElapsed >= piece.flAt - RELOAD_SOUND_LEAD) + { + m_nReloadSoundsDone |= iBit; + EmitReloadSoundPiece(piece.szName); + } + } + } + + for (int i = 0; i < table.iNumRows; ++i) + { + const ReloadPhaseRow_t &row = table.rows[i]; + if (row.phase <= m_nReloadPhase) + { + continue; + } + + if (flElapsed < row.flCredit) + { + break; + } + + CreditReloadPhase(row.phase); + } +} + +void CNEOBaseCombatWeapon::CreditReloadPhase(ReloadPhase_t phase) +{ + switch (phase) + { + case RELOAD_PHASE_DROPPED: + // the old magazine and its rounds are gone, as when the reload loads at its ready time + m_iClip1 = 0; + break; + case RELOAD_PHASE_SEATED: + m_iClip1 = Min(GetMaxClip1(), m_iPrimaryAmmoCount.Get()); + m_iPrimaryAmmoCount -= m_iClip1; + break; + default: + break; + } + + m_nReloadPhase = phase; +} + +// Resume, in the draw, a reload interrupted by a switch; a model without the resume sequence reloads afresh +void CNEOBaseCombatWeapon::ResumeReload() +{ + const char *pszName = ResumeSequenceName(m_nReloadPhase); + const int iTable = pszName ? GetNEOWpnData().FindReloadTable(pszName) : -1; + const int iSequence = (iTable >= 0) ? LookupReloadSequence(pszName) : -1; + if (iSequence < 0) + { + m_nReloadPhase = RELOAD_PHASE_NONE; + return; + } + + SetSequence(iSequence); + SendViewModelAnim(iSequence); + + // the draw is part of the motion: the full reload gesture fits the resume + ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); + + const float flEnd = gpGlobals->curtime + ReloadViewModel()->SequenceDuration(iSequence); + GetOwner()->SetNextAttack(flEnd); + m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; + SetWeaponIdleTime(flEnd); + + // the seat credit loads the magazine + m_flReloadReadyTime = 0.0f; + StartReloadPhases(iTable); + m_bInReload = true; +} + +// Reload sequences are looked up on the owner's viewmodel: on the client the weapon entity carries the world model, +// so a lookup there would fail and the client would predict a different sequence than the server plays +CBaseViewModel *CNEOBaseCombatWeapon::ReloadViewModel() const +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + return pOwner ? pOwner->GetViewModel(m_nViewModelIndex) : nullptr; +} + +int CNEOBaseCombatWeapon::LookupReloadSequence(const char *pszName) const +{ + CBaseViewModel *pVM = ReloadViewModel(); + return pVM ? pVM->LookupSequence(pszName) : -1; +} + +// Play a reload sound piece from the owner, as WeaponSound does: predicted for the owner, from the server for the rest +void CNEOBaseCombatWeapon::EmitReloadSoundPiece(const char *pszSound) +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!pOwner) + { + return; + } + + CSoundParameters params; + if (!GetParametersForSound(pszSound, params, NULL)) + { + return; + } + + CPASAttenuationFilter filter(pOwner, params.soundlevel); + if (IsPredicted() && CBaseEntity::GetPredictionPlayer()) + { + filter.UsePredictionRules(); + } + EmitSound(filter, pOwner->entindex(), pszSound); +} //----------------------------------------------------------------------------- // Purpose: Reload has finished. @@ -484,6 +682,12 @@ void CNEOBaseCombatWeapon::FinishReload(void) } m_flReloadReadyTime = 0.0f; + // the magazine is in: nothing is left to credit or resume + if (IsReloadPhaseSystemEnabled()) + { + EndReloadPhases(); + } + CBaseCombatCharacter* pOwner = GetOwner(); if (pOwner) @@ -540,6 +744,12 @@ bool CNEOBaseCombatWeapon::Deploy(void) SendViewModelAnim(iDrawEmpty); } + // A reload interrupted by a switch goes on in the draw + if (IsReloadPhaseSystemEnabled() && m_nReloadPhase != RELOAD_PHASE_NONE) + { + ResumeReload(); + } + #ifdef DEBUG CNEO_Player* pOwner = NULL; if (GetOwner()) @@ -600,6 +810,16 @@ float CNEOBaseCombatWeapon::GetPenetration() const bool CNEOBaseCombatWeapon::Holster(CBaseCombatWeapon* pSwitchingTo) { + // Only a phase that a sequence resumes from outlasts the switch + if (IsReloadPhaseSystemEnabled()) + { + if (!ResumeSequenceName(m_nReloadPhase)) + { + m_nReloadPhase = RELOAD_PHASE_NONE; + } + m_nReloadTable = -1; + } + return BaseClass::Holster(pSwitchingTo); } @@ -611,6 +831,12 @@ void CNEOBaseCombatWeapon::CheckReload(void) } BaseClass::CheckReload(); + + // a reload that ran to its end leaves nothing to resume + if (IsReloadPhaseSystemEnabled() && !m_bInReload && m_nReloadTable >= 0) + { + EndReloadPhases(); + } } float CNEOBaseCombatWeapon::GetAccuracyPenaltyDecay() @@ -655,6 +881,11 @@ void CNEOBaseCombatWeapon::ItemBusyFrame(void) BaseClass::ItemBusyFrame(); UpdateInaccuracy(); + if (IsReloadPhaseSystemEnabled()) + { + RunReloadPhases(); + } + // The owner stays busy until the reload animation ends, but the magazine loads at the reload's ready time if (m_bInReload && m_flReloadReadyTime > 0.0f && gpGlobals->curtime >= m_flReloadReadyTime) { diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index a772edda17..433b63150e 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -282,6 +282,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon virtual float GetMaxAccuracyPenalty() const { return 1.0; } virtual float GetAccuracyPenaltyDecay(); virtual float GetFastestDryRefireTime() const { Assert(false); return 0; } // Should never call this base class; implement in children. + bool IsReloadPhaseSystemEnabled() const; protected: CNetworkVar(float, m_flSoonestAttack); @@ -294,10 +295,31 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon // When the reload in progress loads the magazine, 0 once it is loaded CNetworkVar(float, m_flReloadReadyTime); + // The server's pre-game reload setting, snapshotted for prediction + CNetworkVar(bool, m_bReloadExperimentalEnabled); + + // Reload phases (weapons whose script has a ReloadPhases block): the last phase credited, kept across a switch + CNetworkVar(int, m_nReloadPhase); + // the phase table of the sequence playing, -1 none + CNetworkVar(int, m_nReloadTable); + // when the reload sequence started; phase credits are offsets from it + CNetworkVar(float, m_flReloadStart); + // the sound pieces of the playing sequence already started, one bit per piece + CNetworkVar(int, m_nReloadSoundsDone); + private: CNEOBaseCombatWeapon(const CNEOBaseCombatWeapon &other); bool HasEmptyIdle(); + void StartReloadPhases(int iTable); + void EndReloadPhases(); + void RunReloadPhases(); + void CreditReloadPhase(ReloadPhase_t phase); + void ResumeReload(); + void EmitReloadSoundPiece(const char *pszSound); + CBaseViewModel *ReloadViewModel() const; + int LookupReloadSequence(const char *pszName) const; + }; #endif // WEAPON_NEO_BASECOMBATWEAPON_SHARED_H From e79cdec26c92c40c0b7095760a6d3cf635fa829d Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:51:24 -0700 Subject: [PATCH 03/13] Give the ZR68C a drop-resume reload The ZR68C reload credits the magazine drop at 0.700 s. The draw_resume_drop_dry sequence seats at 1.433 s and bolts at 2.367 s, with the seat, slap and bolt sound pieces at their transients. --- game/neo/scripts/game_sounds_weapons.txt | 29 ++++++++++++++++++++++++ game/neo/scripts/weapon_zr68c.txt | 15 ++++++++++++ 2 files changed, 44 insertions(+) diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index ad9ac75c4f..24d8e65ced 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -759,6 +759,35 @@ "wave" "weapons/zr68/zr68_reload.wav" } +// ZR68 reload in per-phase pieces (sv_neo_reload_experimental): each file starts just before its first transient + +"weapon_zr68.reload_seat" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_seat.wav" +} + +"weapon_zr68.reload_slap" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_slap.wav" +} + +"weapon_zr68.reload_bolt" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_bolt.wav" +} + //------------------- "weapon_zr68.npc_reload" diff --git a/game/neo/scripts/weapon_zr68c.txt b/game/neo/scripts/weapon_zr68c.txt index 38f426b6d0..a5fef48d68 100644 --- a/game/neo/scripts/weapon_zr68c.txt +++ b/game/neo/scripts/weapon_zr68c.txt @@ -16,6 +16,21 @@ WeaponData "Penetration" "28.0" "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.483" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): per viewmodel sequence, when each phase counts ("credit") + // and when each sound piece's first transient plays ("at"), in seconds from the sequence start + "ReloadPhases" + { + "reload" + { + "drop" { "credit" "0.700" } + } + "draw_resume_drop_dry" + { + "seat" { "credit" "1.433" "sound" "weapon_zr68.reload_seat" "at" "1.394" "sound2" "weapon_zr68.reload_slap" "at2" "1.829" } + "bolt" { "credit" "2.367" "sound" "weapon_zr68.reload_bolt" "at" "2.129" } + } + } "TPMuzzleFlashScale" "0.5" From 3d979390976db44dac333b24e4fc76279adeadcd Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:52:06 -0700 Subject: [PATCH 04/13] Keep the clip until a switch interrupts the reload The drop credit no longer empties the clip: an uninterrupted reload shows the clip as master's does, which bots read to tell an empty weapon. The old magazine is lost only when the draw resumes the reload. The seat sets the ready time, so FinishReload loads as on master and the end-of-reload hook goes away. A switch or a drop now stops the sound pieces, as the player stops the single reload sound. A dropped weapon, also on death, cancels its reload, so the next owner does not resume it. The resume no longer sends drawempty in the same deploy. --- src/game/server/neo/neo_player.cpp | 2 + .../weapons/weapon_neobasecombatweapon.cpp | 100 +++++++++++------- .../neo/weapons/weapon_neobasecombatweapon.h | 7 +- 3 files changed, 69 insertions(+), 40 deletions(-) diff --git a/src/game/server/neo/neo_player.cpp b/src/game/server/neo/neo_player.cpp index e09dfbe8b9..0a66c4922f 100644 --- a/src/game/server/neo/neo_player.cpp +++ b/src/game/server/neo/neo_player.cpp @@ -2485,6 +2485,7 @@ void CNEO_Player::Weapon_DropOnDeath(CNEOBaseCombatWeapon* pNeoWeapon, Vector da pNeoWeapon->AddEffects(EF_BONEMERGE); } + pNeoWeapon->StopReloadOnDrop(); Vector playerVelocity = vec3_origin; GetVelocity(&playerVelocity, nullptr); pNeoWeapon->Drop(playerVelocity); @@ -2953,6 +2954,7 @@ void CNEO_Player::Weapon_Drop( CBaseCombatWeapon *pWeapon, return; // Return early to not drop weapon } + neoWeapon->StopReloadOnDrop(); pWeapon->m_bInReload = false; pWeapon->StopWeaponSound(RELOAD_NPC); diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index bf36975d3d..62e60edc25 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -473,6 +473,7 @@ bool CNEOBaseCombatWeapon::Reload( void ) if (IsReloadPhaseSystemEnabled()) { + m_nReloadPhase = RELOAD_PHASE_NONE; StartReloadPhases(GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD)); } @@ -536,12 +537,6 @@ void CNEOBaseCombatWeapon::StartReloadPhases(int iTable) m_nReloadSoundsDone = 0; } -void CNEOBaseCombatWeapon::EndReloadPhases() -{ - m_nReloadTable = -1; - m_nReloadPhase = RELOAD_PHASE_NONE; -} - // Credit every phase of the playing reload sequence whose time has come, and play its sound pieces void CNEOBaseCombatWeapon::RunReloadPhases() { @@ -587,25 +582,20 @@ void CNEOBaseCombatWeapon::RunReloadPhases() void CNEOBaseCombatWeapon::CreditReloadPhase(ReloadPhase_t phase) { - switch (phase) + // The drop takes no rounds: they are lost only if a switch interrupts the reload after it (ResumeReload), + // so an uninterrupted reload shows the clip as master's does + if (phase == RELOAD_PHASE_SEATED) { - case RELOAD_PHASE_DROPPED: - // the old magazine and its rounds are gone, as when the reload loads at its ready time - m_iClip1 = 0; - break; - case RELOAD_PHASE_SEATED: - m_iClip1 = Min(GetMaxClip1(), m_iPrimaryAmmoCount.Get()); - m_iPrimaryAmmoCount -= m_iClip1; - break; - default: - break; + // the magazine loads now, as at a reload's ready time (ItemBusyFrame) + m_flReloadReadyTime = gpGlobals->curtime; } m_nReloadPhase = phase; } -// Resume, in the draw, a reload interrupted by a switch; a model without the resume sequence reloads afresh -void CNEOBaseCombatWeapon::ResumeReload() +// Resume, in the draw, a reload interrupted by a switch. A model without the resume sequence keeps the old magazine, +// as when master cancels a reload; returns whether the reload resumed +bool CNEOBaseCombatWeapon::ResumeReload() { const char *pszName = ResumeSequenceName(m_nReloadPhase); const int iTable = pszName ? GetNEOWpnData().FindReloadTable(pszName) : -1; @@ -613,9 +603,12 @@ void CNEOBaseCombatWeapon::ResumeReload() if (iSequence < 0) { m_nReloadPhase = RELOAD_PHASE_NONE; - return; + return false; } + // the old magazine and its rounds are gone, as when a reload loads at its ready time + m_iClip1 = 0; + SetSequence(iSequence); SendViewModelAnim(iSequence); @@ -631,10 +624,12 @@ void CNEOBaseCombatWeapon::ResumeReload() m_flReloadReadyTime = 0.0f; StartReloadPhases(iTable); m_bInReload = true; + return true; } -// Reload sequences are looked up on the owner's viewmodel: on the client the weapon entity carries the world model, -// so a lookup there would fail and the client would predict a different sequence than the server plays +// Reload sequences are looked up on the owner's viewmodel, the entity that plays them. The weapon entity's model is not +// always that viewmodel on the client: CalcOverrideModelIndex gives it the world model whenever the local player does +// not draw its viewmodel CBaseViewModel *CNEOBaseCombatWeapon::ReloadViewModel() const { CBasePlayer *pOwner = ToBasePlayer(GetOwner()); @@ -647,6 +642,46 @@ int CNEOBaseCombatWeapon::LookupReloadSequence(const char *pszName) const return pVM ? pVM->LookupSequence(pszName) : -1; } +// Sound pieces play on their own channel entries, so a switch or a drop stops them by name, +// as the player stops the single reload sound +void CNEOBaseCombatWeapon::StopReloadSoundPieces() +{ + CBaseCombatCharacter *pOwner = GetOwner(); + if (!pOwner) + { + return; + } + + const CNEOWeaponInfo &info = GetNEOWpnData(); + for (int t = 0; t < info.m_iNumReloadTables; ++t) + { + for (int i = 0; i < info.m_reloadTables[t].iNumRows; ++i) + { + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + { + const char *pszName = info.m_reloadTables[t].rows[i].sounds[j].szName; + if (pszName[0]) + { + StopSound(pOwner->entindex(), pszName); + } + } + } + } +} + +// A dropped weapon cancels its reload as on master: the next owner does not resume it +void CNEOBaseCombatWeapon::StopReloadOnDrop() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + StopReloadSoundPieces(); + m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; +} + // Play a reload sound piece from the owner, as WeaponSound does: predicted for the owner, from the server for the rest void CNEOBaseCombatWeapon::EmitReloadSoundPiece(const char *pszSound) { @@ -682,10 +717,10 @@ void CNEOBaseCombatWeapon::FinishReload(void) } m_flReloadReadyTime = 0.0f; - // the magazine is in: nothing is left to credit or resume + // the magazine is in: the phases up to the seat are done, and a switch from here leaves nothing to resume if (IsReloadPhaseSystemEnabled()) { - EndReloadPhases(); + m_nReloadPhase = Max(m_nReloadPhase.Get(), static_cast(RELOAD_PHASE_SEATED)); } CBaseCombatCharacter* pOwner = GetOwner(); @@ -737,19 +772,15 @@ bool CNEOBaseCombatWeapon::Deploy(void) // An empty weapon draws with its slide held back where the model has that draw, // which carries no activity, so it is picked by name static constexpr const char *VM_SEQ_DRAW_EMPTY = "drawempty"; - const int iDrawEmpty = (UsesClipsForAmmo1() && m_iClip1 <= 0) ? LookupSequence(VM_SEQ_DRAW_EMPTY) : ACTIVITY_NOT_AVAILABLE; + // a reload interrupted by a switch goes on in the draw + const bool bResumed = IsReloadPhaseSystemEnabled() && m_nReloadPhase != RELOAD_PHASE_NONE && ResumeReload(); + const int iDrawEmpty = (!bResumed && UsesClipsForAmmo1() && m_iClip1 <= 0) ? LookupSequence(VM_SEQ_DRAW_EMPTY) : ACTIVITY_NOT_AVAILABLE; if (iDrawEmpty != ACTIVITY_NOT_AVAILABLE) { SetSequence(iDrawEmpty); SendViewModelAnim(iDrawEmpty); } - // A reload interrupted by a switch goes on in the draw - if (IsReloadPhaseSystemEnabled() && m_nReloadPhase != RELOAD_PHASE_NONE) - { - ResumeReload(); - } - #ifdef DEBUG CNEO_Player* pOwner = NULL; if (GetOwner()) @@ -818,6 +849,7 @@ bool CNEOBaseCombatWeapon::Holster(CBaseCombatWeapon* pSwitchingTo) m_nReloadPhase = RELOAD_PHASE_NONE; } m_nReloadTable = -1; + StopReloadSoundPieces(); } return BaseClass::Holster(pSwitchingTo); @@ -831,12 +863,6 @@ void CNEOBaseCombatWeapon::CheckReload(void) } BaseClass::CheckReload(); - - // a reload that ran to its end leaves nothing to resume - if (IsReloadPhaseSystemEnabled() && !m_bInReload && m_nReloadTable >= 0) - { - EndReloadPhases(); - } } float CNEOBaseCombatWeapon::GetAccuracyPenaltyDecay() diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 433b63150e..8ac42df588 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -264,6 +264,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon virtual float GetFireRate() override final; float GetPenetration() const; + void StopReloadOnDrop(); #ifdef CLIENT_DLL float m_flTemperature; int m_spawnflags; @@ -300,7 +301,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon // Reload phases (weapons whose script has a ReloadPhases block): the last phase credited, kept across a switch CNetworkVar(int, m_nReloadPhase); - // the phase table of the sequence playing, -1 none + // the phase table of the reload sequence started last, -1 none CNetworkVar(int, m_nReloadTable); // when the reload sequence started; phase credits are offsets from it CNetworkVar(float, m_flReloadStart); @@ -312,10 +313,10 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon bool HasEmptyIdle(); void StartReloadPhases(int iTable); - void EndReloadPhases(); void RunReloadPhases(); void CreditReloadPhase(ReloadPhase_t phase); - void ResumeReload(); + bool ResumeReload(); + void StopReloadSoundPieces(); void EmitReloadSoundPiece(const char *pszSound); CBaseViewModel *ReloadViewModel() const; int LookupReloadSequence(const char *pszName) const; From 6857c4932e08f2c7f3ed1287a596151d74f71037 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:52:48 -0700 Subject: [PATCH 05/13] Tidy the reload-phase code for review Describe what sv_neo_reload_experimental does in its help text and bound it to 0-1 like the other weapon cvars. Hoist the parser's name tables to file scope, group FindReloadTable with the other methods, and word the comments without reference to the base branch. No behavior change. --- src/game/server/neo/neo_player.cpp | 1 + .../shared/neo/weapons/neo_weapon_parse.cpp | 17 ++++++++++------- src/game/shared/neo/weapons/neo_weapon_parse.h | 4 ++-- .../neo/weapons/weapon_neobasecombatweapon.cpp | 9 +++++---- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/game/server/neo/neo_player.cpp b/src/game/server/neo/neo_player.cpp index 0a66c4922f..6e038c727f 100644 --- a/src/game/server/neo/neo_player.cpp +++ b/src/game/server/neo/neo_player.cpp @@ -2486,6 +2486,7 @@ void CNEO_Player::Weapon_DropOnDeath(CNEOBaseCombatWeapon* pNeoWeapon, Vector da } pNeoWeapon->StopReloadOnDrop(); + Vector playerVelocity = vec3_origin; GetVelocity(&playerVelocity, nullptr); pNeoWeapon->Drop(playerVelocity); diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index 71c9469276..787c490a24 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -32,12 +32,18 @@ CNEOWeaponInfo::CNEOWeaponInfo() } +// Weapon-script names of the reload phases, by ReloadPhase_t +static constexpr const char *RELOAD_PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "drop", "seat", "bolt" }; +// Weapon-script keys of a phase's sound pieces: { sound name, time } +static constexpr const char *RELOAD_SOUND_KEYS[RELOAD_SOUNDS_PER_ROW][2] = { + { "sound", "at" }, { "sound2", "at2" }, { "sound3", "at3" } +}; + static ReloadPhase_t ReloadPhaseFromName(const char *pszName) { - static constexpr const char *PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "drop", "seat", "bolt" }; for (int i = RELOAD_PHASE_DROPPED; i < RELOAD_PHASE_COUNT; ++i) { - if (V_stricmp(pszName, PHASE_NAMES[i]) == 0) + if (V_stricmp(pszName, RELOAD_PHASE_NAMES[i]) == 0) { return static_cast(i); } @@ -72,13 +78,10 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) ReloadPhaseRow_t &row = table.rows[table.iNumRows++]; row.phase = phase; row.flCredit = pRow->GetFloat("credit"); - static constexpr const char *SOUND_KEYS[RELOAD_SOUNDS_PER_ROW][2] = { - { "sound", "at" }, { "sound2", "at2" }, { "sound3", "at3" } - }; for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) { - row.sounds[j].flAt = pRow->GetFloat(SOUND_KEYS[j][1]); - V_strncpy(row.sounds[j].szName, pRow->GetString(SOUND_KEYS[j][0]), sizeof(row.sounds[j].szName)); + row.sounds[j].flAt = pRow->GetFloat(RELOAD_SOUND_KEYS[j][1]); + V_strncpy(row.sounds[j].szName, pRow->GetString(RELOAD_SOUND_KEYS[j][0]), sizeof(row.sounds[j].szName)); } } } diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index 87a12bf85a..7bf2def14f 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -74,8 +74,6 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo float m_flReloadReadyBeforeEnd; int m_iNumReloadTables; // 0: the weapon reloads without phases ReloadPhaseTable_t m_reloadTables[RELOAD_PHASE_TABLES_MAX]; - - int FindReloadTable(const char *pszSequence) const; char szViewModel2[MAX_WEAPON_STRING]; // Team 2 (NSF) wep vm char szBulletCharacter[MAX_BULLET_CHARACTER];// character used to display ammunition in current clip char szDeathIcon[MAX_BULLET_CHARACTER]; @@ -91,6 +89,8 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo Vector m_vecVMAimPosOffset; QAngle m_angVMAimAngOffset; + int FindReloadTable(const char *pszSequence) const; + private: void ParseReloadPhases(::KeyValues *pBlock); }; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 62e60edc25..d667b5e76b 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -102,7 +102,8 @@ END_DATADESC() ConVar sv_neo_accuracy_penalty_scale("sv_neo_accuracy_penalty_scale", "1.0", FCVAR_REPLICATED, "Scales the accuracy penalty per shot.", true, 0.0f, true, 2.0f); ConVar sv_neo_dynamic_viewkick("sv_neo_dynamic_viewkick", "0", FCVAR_REPLICATED, "Enables view kick scaling based on current inaccuracy.", true, 0.0f, true, 1.0f); ConVar sv_neo_reload_experimental("sv_neo_reload_experimental", "0", FCVAR_REPLICATED, - "Server reload-phase setting; set before a game starts; mid-game changes are unsupported."); + "Lets a switch interrupt a reload after the magazine is out, for weapons that define reload phases. Set before the map loads.", + true, 0.0f, true, 1.0f); const char *GetWeaponByLoadoutId(int id) { @@ -583,7 +584,7 @@ void CNEOBaseCombatWeapon::RunReloadPhases() void CNEOBaseCombatWeapon::CreditReloadPhase(ReloadPhase_t phase) { // The drop takes no rounds: they are lost only if a switch interrupts the reload after it (ResumeReload), - // so an uninterrupted reload shows the clip as master's does + // so an uninterrupted reload shows the same clip as without phases if (phase == RELOAD_PHASE_SEATED) { // the magazine loads now, as at a reload's ready time (ItemBusyFrame) @@ -594,7 +595,7 @@ void CNEOBaseCombatWeapon::CreditReloadPhase(ReloadPhase_t phase) } // Resume, in the draw, a reload interrupted by a switch. A model without the resume sequence keeps the old magazine, -// as when master cancels a reload; returns whether the reload resumed +// as a cancelled reload does; returns whether the reload resumed bool CNEOBaseCombatWeapon::ResumeReload() { const char *pszName = ResumeSequenceName(m_nReloadPhase); @@ -669,7 +670,7 @@ void CNEOBaseCombatWeapon::StopReloadSoundPieces() } } -// A dropped weapon cancels its reload as on master: the next owner does not resume it +// A dropped weapon cancels its reload: the next owner does not resume it void CNEOBaseCombatWeapon::StopReloadOnDrop() { if (!IsReloadPhaseSystemEnabled()) From 07bfdb6081cca2ab4c99a4b0f9f0d781bbc69241 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 18:53:36 -0700 Subject: [PATCH 06/13] Take the ZR68C reload phases from neoAssets weapon_zr68c.txt includes its ReloadPhases rows with #base from weapon_zr68c_reload_phases.txt, which neoAssets ships and times from the Blender markers, so the sound and credit times follow the animation. A missing file leaves the block empty; the parser then warns and the weapon reloads without phases, as it does without the flag. The configure copy of neoAssets is ignored by git. --- .gitignore | 3 +++ game/neo/scripts/weapon_zr68c.txt | 18 ++++-------------- .../shared/neo/weapons/neo_weapon_parse.cpp | 6 ++++++ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 3d541782cc..590e093b19 100644 --- a/.gitignore +++ b/.gitignore @@ -49,6 +49,9 @@ out # Match session restore file /game/neo/scripts/match_session_restore_point.txt +# Reload phases copied from neoAssets +/game/neo/scripts/weapon_*_reload_phases.txt + # Shader state debug image dumps /game/neo/*.tga diff --git a/game/neo/scripts/weapon_zr68c.txt b/game/neo/scripts/weapon_zr68c.txt index a5fef48d68..d7f86f9791 100644 --- a/game/neo/scripts/weapon_zr68c.txt +++ b/game/neo/scripts/weapon_zr68c.txt @@ -1,3 +1,5 @@ +#base "weapon_zr68c_reload_phases.txt" + // ZR68S WeaponData @@ -17,20 +19,8 @@ WeaponData "CycleTime" "0.090909" // time between shots "ReloadReadyBeforeEnd" "0.483" // the reload is done at the last reload click, this long before its animation ends - // Reload phases (sv_neo_reload_experimental): per viewmodel sequence, when each phase counts ("credit") - // and when each sound piece's first transient plays ("at"), in seconds from the sequence start - "ReloadPhases" - { - "reload" - { - "drop" { "credit" "0.700" } - } - "draw_resume_drop_dry" - { - "seat" { "credit" "1.433" "sound" "weapon_zr68.reload_seat" "at" "1.394" "sound2" "weapon_zr68.reload_slap" "at2" "1.829" } - "bolt" { "credit" "2.367" "sound" "weapon_zr68.reload_bolt" "at" "2.129" } - } - } + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} "TPMuzzleFlashScale" "0.5" diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index 787c490a24..aa4a736c8e 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -60,6 +60,12 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) return; } + if (!pBlock->GetFirstTrueSubKey()) + { + Warning("%s: \"ReloadPhases\" is empty (is its neoAssets #base file missing?); reloading without phases\n", szClassName); + return; + } + for (KeyValues *pSeq = pBlock->GetFirstTrueSubKey(); pSeq && m_iNumReloadTables < RELOAD_PHASE_TABLES_MAX; pSeq = pSeq->GetNextTrueSubKey()) { ReloadPhaseTable_t &table = m_reloadTables[m_iNumReloadTables++]; From 8f82986a0db79ecf27bfd9b786f36526cce26ed9 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 19:05:30 -0700 Subject: [PATCH 07/13] Name the ZR68C reload steps by number Use the step names neoAssets now ships: phases 1_unload, 2_load and 3_cycle (RELOAD_PHASE_UNLOADED, LOADED, CYCLED), the resume sequence resume_after_1_unload_empty, the row keys ammo, sound and sound2 (sound names under sound_name, sound2_name), and sound entries named after their step. No behavior change. --- game/neo/scripts/game_sounds_weapons.txt | 15 +++++----- .../shared/neo/weapons/neo_weapon_parse.cpp | 10 +++---- .../shared/neo/weapons/neo_weapon_parse.h | 14 +++++----- .../weapons/weapon_neobasecombatweapon.cpp | 28 +++++++++---------- .../neo/weapons/weapon_neobasecombatweapon.h | 6 ++-- 5 files changed, 37 insertions(+), 36 deletions(-) diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index 24d8e65ced..4d0cfc3a15 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -759,33 +759,34 @@ "wave" "weapons/zr68/zr68_reload.wav" } -// ZR68 reload in per-phase pieces (sv_neo_reload_experimental): each file starts just before its first transient +// ZR68 reload in per-step pieces (sv_neo_reload_experimental), named after the step; _2 is a step's second sound. +// Each file starts just before its first transient -"weapon_zr68.reload_seat" +"weapon_zr68.reload_2_load" { "channel" "CHAN_ITEM" "soundlevel" "SNDLVL_NORM" "volume" "1.0" "pitch" "PITCH_NORM" - "wave" ")weapons/zr68/zr68_reload_seat.wav" + "wave" ")weapons/zr68/zr68_reload_2_load.wav" } -"weapon_zr68.reload_slap" +"weapon_zr68.reload_2_load_2" { "channel" "CHAN_ITEM" "soundlevel" "SNDLVL_NORM" "volume" "1.0" "pitch" "PITCH_NORM" - "wave" ")weapons/zr68/zr68_reload_slap.wav" + "wave" ")weapons/zr68/zr68_reload_2_load_2.wav" } -"weapon_zr68.reload_bolt" +"weapon_zr68.reload_3_cycle" { "channel" "CHAN_ITEM" "soundlevel" "SNDLVL_NORM" "volume" "1.0" "pitch" "PITCH_NORM" - "wave" ")weapons/zr68/zr68_reload_bolt.wav" + "wave" ")weapons/zr68/zr68_reload_3_cycle.wav" } //------------------- diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index aa4a736c8e..80223a535d 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -33,15 +33,15 @@ CNEOWeaponInfo::CNEOWeaponInfo() // Weapon-script names of the reload phases, by ReloadPhase_t -static constexpr const char *RELOAD_PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "drop", "seat", "bolt" }; +static constexpr const char *RELOAD_PHASE_NAMES[RELOAD_PHASE_COUNT] = { "", "1_unload", "2_load", "3_cycle" }; // Weapon-script keys of a phase's sound pieces: { sound name, time } static constexpr const char *RELOAD_SOUND_KEYS[RELOAD_SOUNDS_PER_ROW][2] = { - { "sound", "at" }, { "sound2", "at2" }, { "sound3", "at3" } + { "sound_name", "sound" }, { "sound2_name", "sound2" }, { "sound3_name", "sound3" } }; static ReloadPhase_t ReloadPhaseFromName(const char *pszName) { - for (int i = RELOAD_PHASE_DROPPED; i < RELOAD_PHASE_COUNT; ++i) + for (int i = RELOAD_PHASE_UNLOADED; i < RELOAD_PHASE_COUNT; ++i) { if (V_stricmp(pszName, RELOAD_PHASE_NAMES[i]) == 0) { @@ -51,7 +51,7 @@ static ReloadPhase_t ReloadPhaseFromName(const char *pszName) return RELOAD_PHASE_NONE; } -// "ReloadPhases" { "" { "" { "credit" "s" "sound" "name" "at" "s" } ... } ... } +// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { m_iNumReloadTables = 0; @@ -83,7 +83,7 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) ReloadPhaseRow_t &row = table.rows[table.iNumRows++]; row.phase = phase; - row.flCredit = pRow->GetFloat("credit"); + row.flAmmo = pRow->GetFloat("ammo"); for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) { row.sounds[j].flAt = pRow->GetFloat(RELOAD_SOUND_KEYS[j][1]); diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index 7bf2def14f..ea7fc66361 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -12,13 +12,13 @@ #include "hl2mp_weapon_parse.h" -// A reload is a linear sequence of phases; a reload sequence credits each phase at a point of its animation +// A reload is a linear sequence of phases; a reload sequence finishes each phase at a point of its animation enum ReloadPhase_t { RELOAD_PHASE_NONE = 0, // no reload in progress, or none pending - RELOAD_PHASE_DROPPED, // the old magazine is out - RELOAD_PHASE_SEATED, // the fresh magazine is in - RELOAD_PHASE_BOLTED, // the bolt or charging handle chambered a round + RELOAD_PHASE_UNLOADED, // 1_unload: the old magazine is out + RELOAD_PHASE_LOADED, // 2_load: the fresh magazine is in + RELOAD_PHASE_CYCLED, // 3_cycle: the bolt or charging handle chambered a round RELOAD_PHASE_COUNT }; @@ -33,7 +33,7 @@ static_assert((1 << (RELOAD_PHASE_TABLE_BITS - 1)) >= RELOAD_PHASE_TABLES_MAX, " static constexpr int RELOAD_PHASE_ROWS_MAX = RELOAD_PHASE_COUNT - 1; static constexpr int RELOAD_SOUND_NAME_MAX = 64; static constexpr int RELOAD_SEQUENCE_NAME_MAX = 32; -// a phase may need more than one sound piece, such as a magazine seat and its slap +// a phase may need more than one sound piece, such as loading a magazine and the tap after it static constexpr int RELOAD_SOUNDS_PER_ROW = 3; // A sound piece of a phase @@ -43,11 +43,11 @@ struct ReloadSoundPiece_t char szName[RELOAD_SOUND_NAME_MAX]; }; -// One phase of a reload sequence: when it is credited, and the sound pieces that go with it +// One phase of a reload sequence: when its ammo counts, and the sound pieces that go with it struct ReloadPhaseRow_t { ReloadPhase_t phase; - float flCredit; // seconds from the sequence start + float flAmmo; // seconds from the sequence start ReloadSoundPiece_t sounds[RELOAD_SOUNDS_PER_ROW]; }; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index d667b5e76b..566b7df4ad 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -511,15 +511,15 @@ bool CNEOBaseCombatWeapon::Reload( void ) // Each reload sound piece's file starts this long before its first transient static constexpr float RELOAD_SOUND_LEAD = 0.02f; -// The viewmodel sequence that resumes a reload interrupted after the phase credited last; nullptr: none +// The viewmodel sequence that resumes a reload interrupted after the phase finished last; nullptr: none // (resume sequences carry no activity, so they are picked by name) static const char *ResumeSequenceName(int iPhaseDone) { switch (iPhaseDone) { - case RELOAD_PHASE_DROPPED: + case RELOAD_PHASE_UNLOADED: // the magazine is out: the draw itself brings the fresh one up - return "draw_resume_drop_dry"; + return "resume_after_1_unload_empty"; default: return nullptr; } @@ -530,7 +530,7 @@ bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const return m_bReloadExperimentalEnabled && GetNEOWpnData().m_iNumReloadTables > 0; } -// Credit the phases of a reload sequence that starts now (-1: a sequence without a table credits nothing) +// Time the phases of a reload sequence that starts now (-1: a sequence without a table finishes none) void CNEOBaseCombatWeapon::StartReloadPhases(int iTable) { m_nReloadTable = iTable; @@ -538,7 +538,7 @@ void CNEOBaseCombatWeapon::StartReloadPhases(int iTable) m_nReloadSoundsDone = 0; } -// Credit every phase of the playing reload sequence whose time has come, and play its sound pieces +// Finish every phase of the playing reload sequence whose time has come, and play its sound pieces void CNEOBaseCombatWeapon::RunReloadPhases() { if (!m_bInReload || m_nReloadTable < 0) @@ -549,7 +549,7 @@ void CNEOBaseCombatWeapon::RunReloadPhases() const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; const float flElapsed = gpGlobals->curtime - m_flReloadStart; - // Sound pieces play on their own times, before or after their phase's credit + // Sound pieces play on their own times, before or after their phase's ammo time for (int i = 0; i < table.iNumRows; ++i) { for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) @@ -572,20 +572,20 @@ void CNEOBaseCombatWeapon::RunReloadPhases() continue; } - if (flElapsed < row.flCredit) + if (flElapsed < row.flAmmo) { break; } - CreditReloadPhase(row.phase); + FinishReloadPhase(row.phase); } } -void CNEOBaseCombatWeapon::CreditReloadPhase(ReloadPhase_t phase) +void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) { - // The drop takes no rounds: they are lost only if a switch interrupts the reload after it (ResumeReload), + // The unload takes no rounds: they are lost only if a switch interrupts the reload after it (ResumeReload), // so an uninterrupted reload shows the same clip as without phases - if (phase == RELOAD_PHASE_SEATED) + if (phase == RELOAD_PHASE_LOADED) { // the magazine loads now, as at a reload's ready time (ItemBusyFrame) m_flReloadReadyTime = gpGlobals->curtime; @@ -621,7 +621,7 @@ bool CNEOBaseCombatWeapon::ResumeReload() m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; SetWeaponIdleTime(flEnd); - // the seat credit loads the magazine + // the load phase loads the magazine m_flReloadReadyTime = 0.0f; StartReloadPhases(iTable); m_bInReload = true; @@ -718,10 +718,10 @@ void CNEOBaseCombatWeapon::FinishReload(void) } m_flReloadReadyTime = 0.0f; - // the magazine is in: the phases up to the seat are done, and a switch from here leaves nothing to resume + // the magazine is in: the phases up to the load are done, and a switch from here leaves nothing to resume if (IsReloadPhaseSystemEnabled()) { - m_nReloadPhase = Max(m_nReloadPhase.Get(), static_cast(RELOAD_PHASE_SEATED)); + m_nReloadPhase = Max(m_nReloadPhase.Get(), static_cast(RELOAD_PHASE_LOADED)); } CBaseCombatCharacter* pOwner = GetOwner(); diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 8ac42df588..90d2164b16 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -299,11 +299,11 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon // The server's pre-game reload setting, snapshotted for prediction CNetworkVar(bool, m_bReloadExperimentalEnabled); - // Reload phases (weapons whose script has a ReloadPhases block): the last phase credited, kept across a switch + // Reload phases (weapons whose script has a ReloadPhases block): the last phase finished, kept across a switch CNetworkVar(int, m_nReloadPhase); // the phase table of the reload sequence started last, -1 none CNetworkVar(int, m_nReloadTable); - // when the reload sequence started; phase credits are offsets from it + // when the reload sequence started; phase times are offsets from it CNetworkVar(float, m_flReloadStart); // the sound pieces of the playing sequence already started, one bit per piece CNetworkVar(int, m_nReloadSoundsDone); @@ -314,7 +314,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon void StartReloadPhases(int iTable); void RunReloadPhases(); - void CreditReloadPhase(ReloadPhase_t phase); + void FinishReloadPhase(ReloadPhase_t phase); bool ResumeReload(); void StopReloadSoundPieces(); void EmitReloadSoundPiece(const char *pszSound); From 1e047b057fc263097eb3c12248473c3c4f28fc90 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 20:03:41 -0700 Subject: [PATCH 08/13] Allow fire at a resume's ready time A resume sequence's ReloadPhases block may give a 4_ready time: the reload is done and fire is allowed there, and the clip plays on to its end unless a shot interrupts it. Without the key, fire waits for the end of the sequence as before. --- src/game/shared/neo/weapons/neo_weapon_parse.cpp | 3 ++- src/game/shared/neo/weapons/neo_weapon_parse.h | 1 + src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index 80223a535d..8487003102 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -51,7 +51,7 @@ static ReloadPhase_t ReloadPhaseFromName(const char *pszName) return RELOAD_PHASE_NONE; } -// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } +// "ReloadPhases" { "" { "4_ready" "s" "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { m_iNumReloadTables = 0; @@ -70,6 +70,7 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { ReloadPhaseTable_t &table = m_reloadTables[m_iNumReloadTables++]; V_strncpy(table.szSequence, pSeq->GetName(), sizeof(table.szSequence)); + table.flReady = pSeq->GetFloat("4_ready"); table.iNumRows = 0; for (KeyValues *pRow = pSeq->GetFirstTrueSubKey(); pRow && table.iNumRows < RELOAD_PHASE_ROWS_MAX; pRow = pRow->GetNextTrueSubKey()) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index ea7fc66361..0a7384faef 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -55,6 +55,7 @@ struct ReloadPhaseRow_t struct ReloadPhaseTable_t { char szSequence[RELOAD_SEQUENCE_NAME_MAX]; + float flReady; // when the reload is done and fire is allowed, seconds from the sequence start; 0: at its end int iNumRows; ReloadPhaseRow_t rows[RELOAD_PHASE_ROWS_MAX]; }; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 566b7df4ad..0e6facbda6 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -616,9 +616,12 @@ bool CNEOBaseCombatWeapon::ResumeReload() // the draw is part of the motion: the full reload gesture fits the resume ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); + // The reload is done and fire is allowed at the ready time; the clip plays on unless a shot interrupts it const float flEnd = gpGlobals->curtime + ReloadViewModel()->SequenceDuration(iSequence); - GetOwner()->SetNextAttack(flEnd); - m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; + const float flReady = GetNEOWpnData().m_reloadTables[iTable].flReady; + const float flFire = (flReady > 0.0f) ? Min(flEnd, gpGlobals->curtime + flReady) : flEnd; + GetOwner()->SetNextAttack(flFire); + m_flNextPrimaryAttack = m_flNextSecondaryAttack = flFire; SetWeaponIdleTime(flEnd); // the load phase loads the magazine From f39b3c4f66345e24b06f5cd7ba22766efaf9aa3b Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 20:31:05 -0700 Subject: [PATCH 09/13] Finish a resume at its clip end Drop the 4_ready time: the resume clip now ends where the hands are at rest, so the reload finishes and fire is allowed when it ends. --- src/game/shared/neo/weapons/neo_weapon_parse.cpp | 3 +-- src/game/shared/neo/weapons/neo_weapon_parse.h | 1 - src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp | 7 ++----- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index 8487003102..80223a535d 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -51,7 +51,7 @@ static ReloadPhase_t ReloadPhaseFromName(const char *pszName) return RELOAD_PHASE_NONE; } -// "ReloadPhases" { "" { "4_ready" "s" "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } +// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { m_iNumReloadTables = 0; @@ -70,7 +70,6 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { ReloadPhaseTable_t &table = m_reloadTables[m_iNumReloadTables++]; V_strncpy(table.szSequence, pSeq->GetName(), sizeof(table.szSequence)); - table.flReady = pSeq->GetFloat("4_ready"); table.iNumRows = 0; for (KeyValues *pRow = pSeq->GetFirstTrueSubKey(); pRow && table.iNumRows < RELOAD_PHASE_ROWS_MAX; pRow = pRow->GetNextTrueSubKey()) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index 0a7384faef..ea7fc66361 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -55,7 +55,6 @@ struct ReloadPhaseRow_t struct ReloadPhaseTable_t { char szSequence[RELOAD_SEQUENCE_NAME_MAX]; - float flReady; // when the reload is done and fire is allowed, seconds from the sequence start; 0: at its end int iNumRows; ReloadPhaseRow_t rows[RELOAD_PHASE_ROWS_MAX]; }; diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 0e6facbda6..566b7df4ad 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -616,12 +616,9 @@ bool CNEOBaseCombatWeapon::ResumeReload() // the draw is part of the motion: the full reload gesture fits the resume ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); - // The reload is done and fire is allowed at the ready time; the clip plays on unless a shot interrupts it const float flEnd = gpGlobals->curtime + ReloadViewModel()->SequenceDuration(iSequence); - const float flReady = GetNEOWpnData().m_reloadTables[iTable].flReady; - const float flFire = (flReady > 0.0f) ? Min(flEnd, gpGlobals->curtime + flReady) : flEnd; - GetOwner()->SetNextAttack(flFire); - m_flNextPrimaryAttack = m_flNextSecondaryAttack = flFire; + GetOwner()->SetNextAttack(flEnd); + m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; SetWeaponIdleTime(flEnd); // the load phase loads the magazine From 0f56ad40e049e49919edd3ab63f440d11eeffab9 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 21:05:39 -0700 Subject: [PATCH 10/13] Take the resume sequence from the phases file Reload() now times the phases of the sequence the viewmodel plays, not a fixed "reload", so a gun whose empty reload is reloadempty gets that table. A row's "resume" key names the sequence that resumes a reload interrupted after its step; Holster keeps the phase and the table that names it, and a second switch before a resume's first step plays that resume again. This replaces the hardcoded resume name. Sound pieces stop from the playing table only. --- .../shared/neo/weapons/neo_weapon_parse.cpp | 3 +- .../shared/neo/weapons/neo_weapon_parse.h | 1 + .../weapons/weapon_neobasecombatweapon.cpp | 74 +++++++++++-------- .../neo/weapons/weapon_neobasecombatweapon.h | 1 + 4 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index 80223a535d..77872fa0eb 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.cpp +++ b/src/game/shared/neo/weapons/neo_weapon_parse.cpp @@ -51,7 +51,7 @@ static ReloadPhase_t ReloadPhaseFromName(const char *pszName) return RELOAD_PHASE_NONE; } -// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" } ... } ... } +// "ReloadPhases" { "" { "" { "ammo" "s" "sound" "s" "sound_name" "name" "resume" "sequence" } ... } ... } void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) { m_iNumReloadTables = 0; @@ -89,6 +89,7 @@ void CNEOWeaponInfo::ParseReloadPhases(KeyValues *pBlock) row.sounds[j].flAt = pRow->GetFloat(RELOAD_SOUND_KEYS[j][1]); V_strncpy(row.sounds[j].szName, pRow->GetString(RELOAD_SOUND_KEYS[j][0]), sizeof(row.sounds[j].szName)); } + V_strncpy(row.szResume, pRow->GetString("resume"), sizeof(row.szResume)); } } } diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.h b/src/game/shared/neo/weapons/neo_weapon_parse.h index ea7fc66361..dc10c7d7ca 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -49,6 +49,7 @@ struct ReloadPhaseRow_t ReloadPhase_t phase; float flAmmo; // seconds from the sequence start ReloadSoundPiece_t sounds[RELOAD_SOUNDS_PER_ROW]; + char szResume[RELOAD_SEQUENCE_NAME_MAX]; // the sequence that resumes a reload interrupted after this phase, or empty }; // The phases one reload sequence carries, in order diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index 566b7df4ad..a314fde42f 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -446,9 +446,6 @@ void CNEOBaseCombatWeapon::Equip(CBaseCombatCharacter* pOwner) } -// The shipped reload sequence -static constexpr const char *VM_SEQ_RELOAD = "reload"; - bool CNEOBaseCombatWeapon::Reload( void ) { const bool bEmptyReload = UsesClipsForAmmo1() && m_iClip1 <= 0 && @@ -474,8 +471,10 @@ bool CNEOBaseCombatWeapon::Reload( void ) if (IsReloadPhaseSystemEnabled()) { + // the phases are those of the sequence the reload plays, such as reload or reloadempty + CBaseViewModel *pVM = ReloadViewModel(); m_nReloadPhase = RELOAD_PHASE_NONE; - StartReloadPhases(GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD)); + StartReloadPhases(pVM ? GetNEOWpnData().FindReloadTable(pVM->GetSequenceName(pVM->GetSequence())) : -1); } return true; @@ -511,23 +510,36 @@ bool CNEOBaseCombatWeapon::Reload( void ) // Each reload sound piece's file starts this long before its first transient static constexpr float RELOAD_SOUND_LEAD = 0.02f; -// The viewmodel sequence that resumes a reload interrupted after the phase finished last; nullptr: none -// (resume sequences carry no activity, so they are picked by name) -static const char *ResumeSequenceName(int iPhaseDone) +bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const +{ + return m_bReloadExperimentalEnabled && GetNEOWpnData().m_iNumReloadTables > 0; +} + +// The viewmodel sequence that resumes the reload interrupted now, from the phase table of the playing sequence; +// nullptr: none (resume sequences carry no activity, so they are picked by name) +const char *CNEOBaseCombatWeapon::FindResumeSequence() const { - switch (iPhaseDone) + const ReloadPhase_t phase = static_cast(m_nReloadPhase.Get()); + if (phase == RELOAD_PHASE_NONE || m_nReloadTable < 0) { - case RELOAD_PHASE_UNLOADED: - // the magazine is out: the draw itself brings the fresh one up - return "resume_after_1_unload_empty"; - default: return nullptr; } -} -bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const -{ - return m_bReloadExperimentalEnabled && GetNEOWpnData().m_iNumReloadTables > 0; + // a sequence that starts after the phase is itself the resume from it, interrupted again before its first phase + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + if (table.iNumRows > 0 && table.rows[0].phase > phase) + { + return table.szSequence; + } + + for (int i = 0; i < table.iNumRows; ++i) + { + if (table.rows[i].phase == phase) + { + return table.rows[i].szResume[0] ? table.rows[i].szResume : nullptr; + } + } + return nullptr; } // Time the phases of a reload sequence that starts now (-1: a sequence without a table finishes none) @@ -598,12 +610,13 @@ void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) // as a cancelled reload does; returns whether the reload resumed bool CNEOBaseCombatWeapon::ResumeReload() { - const char *pszName = ResumeSequenceName(m_nReloadPhase); + const char *pszName = FindResumeSequence(); const int iTable = pszName ? GetNEOWpnData().FindReloadTable(pszName) : -1; const int iSequence = (iTable >= 0) ? LookupReloadSequence(pszName) : -1; if (iSequence < 0) { m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; return false; } @@ -648,23 +661,20 @@ int CNEOBaseCombatWeapon::LookupReloadSequence(const char *pszName) const void CNEOBaseCombatWeapon::StopReloadSoundPieces() { CBaseCombatCharacter *pOwner = GetOwner(); - if (!pOwner) + if (!pOwner || m_nReloadTable < 0) { return; } - const CNEOWeaponInfo &info = GetNEOWpnData(); - for (int t = 0; t < info.m_iNumReloadTables; ++t) + const ReloadPhaseTable_t &table = GetNEOWpnData().m_reloadTables[m_nReloadTable]; + for (int i = 0; i < table.iNumRows; ++i) { - for (int i = 0; i < info.m_reloadTables[t].iNumRows; ++i) + for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) { - for (int j = 0; j < RELOAD_SOUNDS_PER_ROW; ++j) + const char *pszName = table.rows[i].sounds[j].szName; + if (pszName[0]) { - const char *pszName = info.m_reloadTables[t].rows[i].sounds[j].szName; - if (pszName[0]) - { - StopSound(pOwner->entindex(), pszName); - } + StopSound(pOwner->entindex(), pszName); } } } @@ -721,7 +731,7 @@ void CNEOBaseCombatWeapon::FinishReload(void) // the magazine is in: the phases up to the load are done, and a switch from here leaves nothing to resume if (IsReloadPhaseSystemEnabled()) { - m_nReloadPhase = Max(m_nReloadPhase.Get(), static_cast(RELOAD_PHASE_LOADED)); + m_nReloadPhase = Max(static_cast(m_nReloadPhase.Get()), RELOAD_PHASE_LOADED); } CBaseCombatCharacter* pOwner = GetOwner(); @@ -842,15 +852,15 @@ float CNEOBaseCombatWeapon::GetPenetration() const bool CNEOBaseCombatWeapon::Holster(CBaseCombatWeapon* pSwitchingTo) { - // Only a phase that a sequence resumes from outlasts the switch + // Only a phase that a sequence resumes from outlasts the switch, with the table that names the resume if (IsReloadPhaseSystemEnabled()) { - if (!ResumeSequenceName(m_nReloadPhase)) + StopReloadSoundPieces(); + if (!FindResumeSequence()) { m_nReloadPhase = RELOAD_PHASE_NONE; + m_nReloadTable = -1; } - m_nReloadTable = -1; - StopReloadSoundPieces(); } return BaseClass::Holster(pSwitchingTo); diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 90d2164b16..77efdc22b2 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -315,6 +315,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon void StartReloadPhases(int iTable); void RunReloadPhases(); void FinishReloadPhase(ReloadPhase_t phase); + const char *FindResumeSequence() const; bool ResumeReload(); void StopReloadSoundPieces(); void EmitReloadSoundPiece(const char *pszSound); From 198089376cde64945b6fbc4c11866ea5f6cf57b3 Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 21:19:36 -0700 Subject: [PATCH 11/13] Add the M41 reload phases (sketch) Sketch, not a product. weapon_m41.txt includes the M41 phases from neoAssets, and the three-step reload pieces get sound entries. No C++ change is needed for the resume after the unload. --- game/neo/scripts/game_sounds_weapons.txt | 41 ++++++++++++++++++++++++ game/neo/scripts/weapon_m41.txt | 7 ++++ 2 files changed, 48 insertions(+) diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index 4d0cfc3a15..c02252c2e2 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -586,6 +586,47 @@ "wave" "weapons/m41/m41_reload.wav" } +// M41 reload in per-step pieces (sv_neo_reload_experimental), named after the step; _2 and _3 are a step's second and +// third sounds (seat rattle, tap, slap). The ZR68 entries above use ")" in front of the wave; these do not, as +// weapon_m41.reload does not. NEO TODO (sunzenshen): the wavs are placeholders from the research branch; re-cut from +// m41_reload.wav as the ZR68 pieces were (zr68c-sound-align.md). + +"weapon_m41.reload_2_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" "weapons/m41/m41_reload_2_load.wav" +} + +"weapon_m41.reload_2_load_2" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" "weapons/m41/m41_reload_2_load_2.wav" +} + +"weapon_m41.reload_2_load_3" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" "weapons/m41/m41_reload_2_load_3.wav" +} + +"weapon_m41.reload_3_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" "weapons/m41/m41_reload_3_cycle.wav" +} + //------------------- "weapon_m41.npc_reload" diff --git a/game/neo/scripts/weapon_m41.txt b/game/neo/scripts/weapon_m41.txt index b3d02a4cfb..e11fbfdb50 100644 --- a/game/neo/scripts/weapon_m41.txt +++ b/game/neo/scripts/weapon_m41.txt @@ -1,3 +1,5 @@ +#base "weapon_mosok41_reload_phases.txt" + // M41 WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "32.0" "CycleTime" "0.166666" // time between shots "ReloadReadyBeforeEnd" "0.393" // 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 + // NEO TODO (sunzenshen): with the flag on, the magazine loads at the 2_load ammo time, not at the end minus + // ReloadReadyBeforeEnd above (user decision U1); decide whether the M41's fire point moves with it (U2). + "ReloadPhases" {} "TPMuzzleFlashScale" "0.5" From 30284362b05a4b1fa7b820fde2b27066a525f5ec Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 21:22:14 -0700 Subject: [PATCH 12/13] Add the MilSO reload phases (sketch) Sketch, not a product. weapon_milso.txt includes the pistol phases from neoAssets, and the load step gets a sound entry. No C++ change is needed for tactical and dry resumes after the unload. --- game/neo/scripts/game_sounds_weapons.txt | 12 ++++++++++++ game/neo/scripts/weapon_milso.txt | 10 +++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index c02252c2e2..8c42451719 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -12,6 +12,18 @@ "wave" "weapons/milso/milso_reload.wav" } +// MilSO reload in per-step pieces (sv_neo_reload_experimental): only the load step has a sound; the slide release +// (3_cycle) is silent in the shipped wav. NEO TODO (sunzenshen): placeholder wav from the research branch. +"weapon_milso.reload_2_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "CompatibilityAttenuation" "1.0" + "pitch" "PITCH_NORM" + "wave" "weapons/milso/milso_reload_2_load.wav" +} + //------------------ "weapon_milso.npc_reload" diff --git a/game/neo/scripts/weapon_milso.txt b/game/neo/scripts/weapon_milso.txt index 5e220ac1f1..d814eb9371 100644 --- a/game/neo/scripts/weapon_milso.txt +++ b/game/neo/scripts/weapon_milso.txt @@ -1,3 +1,5 @@ +#base "weapon_milso_reload_phases.txt" + // Milso WeaponData { @@ -14,7 +16,13 @@ WeaponData "Penetration" "12.0" "CycleTime" "0.212121" "ReloadReadyBeforeEnd" "0.467" // 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. + // The pistol ships two reloads (reload, reloadempty); the phases file has a table for each and a resume for each. + // NEO TODO (sunzenshen): the same U1/U2 question as the M41: with the flag on, the magazine loads at the 2_load ammo + // time, not at the end minus ReloadReadyBeforeEnd above. + "ReloadPhases" {} + "TPMuzzleFlashScale" "0.5" "clip_size" "12" From c83c129264255eb0a05a30bb49d6110f82960c3b Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Sat, 7 Nov 2026 21:45:22 -0700 Subject: [PATCH 13/13] Stub the open reload TODOs as comments --- game/neo/scripts/weapon_m41.txt | 2 ++ game/neo/scripts/weapon_milso.txt | 2 ++ src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/game/neo/scripts/weapon_m41.txt b/game/neo/scripts/weapon_m41.txt index e11fbfdb50..dc14b7a9dd 100644 --- a/game/neo/scripts/weapon_m41.txt +++ b/game/neo/scripts/weapon_m41.txt @@ -1,4 +1,6 @@ #base "weapon_mosok41_reload_phases.txt" +// NEO TODO (sunzenshen): M41 (one reload, no 30+1 rule): decide the fire point (clip end or ReloadReadyBeforeEnd) and whether the resume keeps +// the _empty name; resume after 2_load and the 3 sounds in 2_load are not done; see the plan's Open TODO list. // M41 diff --git a/game/neo/scripts/weapon_milso.txt b/game/neo/scripts/weapon_milso.txt index d814eb9371..def71448e7 100644 --- a/game/neo/scripts/weapon_milso.txt +++ b/game/neo/scripts/weapon_milso.txt @@ -1,4 +1,6 @@ #base "weapon_milso_reload_phases.txt" +// NEO TODO (sunzenshen): MilSO: resume after 2_load (dry slide release) needs a resume that keeps the clip; tactical resume must keep the +// chambered round; ReloadReadyBeforeEnd 0.467 s vs the new fire point; see the plan's Open TODO list. // Milso WeaponData diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index a314fde42f..1a1dfe093b 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -446,6 +446,8 @@ void CNEOBaseCombatWeapon::Equip(CBaseCombatCharacter* pOwner) } +// NEO TODO (sunzenshen): Partial reload (chamber live, skip the cycle) and the chamber model are not here; see sketch-zr68c-full. +// Bots: Clip1() >= GetMaxClip1() treats 30 of 31 as full; revisit the threshold later. bool CNEOBaseCombatWeapon::Reload( void ) { const bool bEmptyReload = UsesClipsForAmmo1() && m_iClip1 <= 0 && @@ -593,6 +595,7 @@ void CNEOBaseCombatWeapon::RunReloadPhases() } } +// NEO TODO (sunzenshen): RELOAD_END: stop the third-person reload gesture on a cut-short reload (U5b); not decided. void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) { // The unload takes no rounds: they are lost only if a switch interrupts the reload after it (ResumeReload), @@ -608,6 +611,8 @@ void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) // Resume, in the draw, a reload interrupted by a switch. A model without the resume sequence keeps the old magazine, // as a cancelled reload does; returns whether the reload resumed +// NEO TODO (sunzenshen): Resume after 2_load keeps the loaded magazine; only a resume after 1_unload zeroes the clip. +// A tactical reload also needs the chambered round kept (chamber model). bool CNEOBaseCombatWeapon::ResumeReload() { const char *pszName = FindResumeSequence(); @@ -681,6 +686,8 @@ void CNEOBaseCombatWeapon::StopReloadSoundPieces() } // A dropped weapon cancels its reload: the next owner does not resume it +// NEO TODO (sunzenshen): Gun dropped after the load but before the cycle: the next owner's draw plays the dry resume (U4a). +// Fallback for a lost resume (full magazine, empty chamber): let Reload() play the dry reload. void CNEOBaseCombatWeapon::StopReloadOnDrop() { if (!IsReloadPhaseSystemEnabled())