diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index f07bfa6586..b8b6f6689f 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -762,6 +762,15 @@ // ZR68 reload in per-step pieces (sv_neo_reload_experimental), named reload_; a step's later sounds add _part2, _part3. // Each file starts just before its first transient +"weapon_zr68.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/zr68/zr68_reload_unload.wav" +} + "weapon_zr68.reload_load" { "channel" "CHAN_ITEM" diff --git a/game/neo/scripts/weapon_zr68c.txt b/game/neo/scripts/weapon_zr68c.txt index d7f86f9791..d6dbc3b052 100644 --- a/game/neo/scripts/weapon_zr68c.txt +++ b/game/neo/scripts/weapon_zr68c.txt @@ -21,6 +21,8 @@ WeaponData // 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.5" diff --git a/src/game/client/neo/ui/neo_hud_ammo.cpp b/src/game/client/neo/ui/neo_hud_ammo.cpp index 771efb2554..55d355b076 100644 --- a/src/game/client/neo/ui/neo_hud_ammo.cpp +++ b/src/game/client/neo/ui/neo_hud_ammo.cpp @@ -6,6 +6,9 @@ #include "iclientmode.h" #include #include +#include +#include "VGuiMatSurface/IMatSystemSurface.h" +#include "cdll_client_int.h" #include #include #include @@ -160,16 +163,20 @@ void CNEOHud_Ammo::DrawAmmo() const } const char* ammoChar = nullptr; + int fireModeWidth = 0, fireModeHeight = 0; int magSizeMax = 0; int magSizeCurrent = 0; + // NEO TODO: client tests for the 30+1/30 row and the chamber glyph (fresh, after tactical reload, after drop). + // a gun with a chamber counts the magazine in the row, and the round icon of the fire-mode glyph shows the chamber + const bool hasChamber = activeWep->HasChamberSlot(); if ((activeWep->UsesClipsForAmmo1() && !(activeWep->GetNeoWepBits() & NEO_WEP_THROWABLE)) || (activeWep->GetNeoWepBits() & NEO_WEP_BALC)) { char fireModeText[2]{ '\0' }; ammoChar = activeWep->GetNEOWpnData().szBulletCharacter; - magSizeMax = activeWep->GetMaxClip1(); - magSizeCurrent = activeWep->Clip1(); + magSizeMax = hasChamber ? activeWep->MagazineCapacity() : activeWep->GetMaxClip1(); + magSizeCurrent = hasChamber ? activeWep->RoundsInMagazine() : activeWep->Clip1(); if(activeWep) { @@ -188,8 +195,16 @@ void CNEOHud_Ammo::DrawAmmo() const g_pVGuiLocalize->ConvertANSIToUnicode(fireModeText, unicodeFireModeText, sizeof(unicodeFireModeText)); surface()->DrawSetTextFont(m_hFireModeFont); - surface()->DrawSetTextPos(icon_xpos + xpos, icon_ypos + ypos); - surface()->DrawPrintText(unicodeFireModeText, V_wcslen(unicodeFireModeText)); + if (hasChamber) + { + surface()->GetTextSize(m_hFireModeFont, unicodeFireModeText, fireModeWidth, fireModeHeight); + DrawFireModeWithChamber(unicodeFireModeText, fireModeHeight, activeWep->IsRoundChambered()); + } + else + { + surface()->DrawSetTextPos(icon_xpos + xpos, icon_ypos + ypos); + surface()->DrawPrintText(unicodeFireModeText, V_wcslen(unicodeFireModeText)); + } } } else { @@ -216,8 +231,16 @@ void CNEOHud_Ammo::DrawAmmo() const surface()->DrawSetTextFont(m_hBulletFont); surface()->DrawSetTextPos(digit_xpos + xpos, digit_ypos + ypos); wchar_t bullets[22]; - V_swprintf_safe(bullets, L"%i/%i", magSizeCurrent, magSizeMax); - surface()->DrawPrintText(bullets, (int)(magSizeCurrent == 0 ? 1 : log10(magSizeCurrent) + 1) + (int)(log10(magSizeMax) + 1) + 1); + if (hasChamber && activeWep->IsRoundChambered()) + { + V_swprintf_safe(bullets, L"%i+1/%i", magSizeCurrent, magSizeMax); + surface()->DrawPrintText(bullets, V_wcslen(bullets)); + } + else + { + V_swprintf_safe(bullets, L"%i/%i", magSizeCurrent, magSizeMax); + surface()->DrawPrintText(bullets, (int)(magSizeCurrent == 0 ? 1 : log10(magSizeCurrent) + 1) + (int)(log10(magSizeMax) + 1) + 1); + } return; } @@ -290,6 +313,36 @@ void CNEOHud_Ammo::DrawAmmo() const } } +// The fire-mode glyph's top rows are a round icon (bullet or shell), its letter sits below them +static constexpr float FIRE_MODE_ROUND_ICON_HEIGHT = 0.184f; + +// Draw the fire-mode glyph with its round icon lit while a round is chambered, in the empty color otherwise; +// the letter keeps the text color. Two passes, each clipped to its part of the glyph +void CNEOHud_Ammo::DrawFireModeWithChamber(const wchar_t *pszGlyph, int iGlyphTall, bool bChambered) const +{ + const int iX = icon_xpos + xpos; + const int iY = icon_ypos + ypos; + int iScreenX = 0, iScreenY = 0; + vgui::ipanel()->GetAbsPos(GetVPanel(), iScreenX, iScreenY); + const int iSplitY = iScreenY + iY + static_cast(iGlyphTall * FIRE_MODE_ROUND_ICON_HEIGHT + 0.5f); + + int iLeft, iTop, iRight, iBottom; + bool bClippingDisabled; + g_pMatSystemSurface->GetClippingRect(iLeft, iTop, iRight, iBottom, bClippingDisabled); + + g_pMatSystemSurface->SetClippingRect(iLeft, iTop, iRight, Min(iBottom, iSplitY)); + surface()->DrawSetTextColor(bChambered ? ammo_color : emptied_ammo_color); + surface()->DrawSetTextPos(iX, iY); + surface()->DrawPrintText(pszGlyph, V_wcslen(pszGlyph)); + + g_pMatSystemSurface->SetClippingRect(iLeft, Max(iTop, iSplitY), iRight, iBottom); + surface()->DrawSetTextColor(ammo_text_color); + surface()->DrawSetTextPos(iX, iY); + surface()->DrawPrintText(pszGlyph, V_wcslen(pszGlyph)); + + g_pMatSystemSurface->SetClippingRect(iLeft, iTop, iRight, iBottom); +} + void CNEOHud_Ammo::DrawNeoHudElement() { auto *localPlayer = C_NEO_Player::GetLocalNEOPlayer(); diff --git a/src/game/client/neo/ui/neo_hud_ammo.h b/src/game/client/neo/ui/neo_hud_ammo.h index 069561e11c..637d663457 100644 --- a/src/game/client/neo/ui/neo_hud_ammo.h +++ b/src/game/client/neo/ui/neo_hud_ammo.h @@ -27,6 +27,7 @@ class CNEOHud_Ammo : public CNEOHud_ChildElement, public CHudElement, public vgu private: void DrawAmmo() const; + void DrawFireModeWithChamber(const wchar_t *pszGlyph, int iGlyphTall, bool bChambered) const; void DrawHeatMeter(C_NEOBaseCombatWeapon* activeWep) const; private: diff --git a/src/game/server/neo/bot/neo_bot.cpp b/src/game/server/neo/bot/neo_bot.cpp index 7d1c1e2ef8..8f9036fb00 100644 --- a/src/game/server/neo/bot/neo_bot.cpp +++ b/src/game/server/neo/bot/neo_bot.cpp @@ -1628,6 +1628,13 @@ void CNEOBot::EquipBestWeaponForThreat(const CKnownEntity* threat, const bool bN if (EquipRequiredWeapon()) return; + // A switch would only delay the reload that is about to refill the clip + auto *pActiveWeapon = static_cast(GetActiveWeapon()); + if (pActiveWeapon && pActiveWeapon->IsReloadPastUnload()) + { + return; + } + // ------------------------------------------------------------------------------- CNEOBaseCombatWeapon* primaryWeapon = static_cast(Weapon_GetSlot(0)); @@ -1813,6 +1820,8 @@ void CNEOBot::ReloadIfLowClip(bool bForceReload) return; } + // NEO TODO: with a chamber slot 30 of 31 counts as full here, and 29+1 (clip 30) never reloads by bot + // logic. Accepted for now; revisit the threshold later. if (myWeapon->Clip1() >= myWeapon->GetMaxClip1()) { return; diff --git a/src/game/shared/neo/weapons/neo_weapon_parse.cpp b/src/game/shared/neo/weapons/neo_weapon_parse.cpp index eee8e991f1..b3050775c8 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_bChamberedRound = false; m_flVMFov = m_flVMAimFov = 0.f; m_vecVMPosOffset = m_vecVMAimPosOffset = vec3_origin; @@ -114,6 +115,7 @@ void CNEOWeaponInfo::Parse( KeyValues *pKeyValuesData, const char *szWeaponName m_flCycleTime = pKeyValuesData->GetFloat( "CycleTime", 0.15 ); m_flReloadReadyBeforeEnd = pKeyValuesData->GetFloat( "ReloadReadyBeforeEnd", 0.0f ); ParseReloadPhases(pKeyValuesData->FindKey("ReloadPhases")); + m_bChamberedRound = pKeyValuesData->GetBool("ChamberedRound", false); 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 8decaa120e..abdf2e86f9 100644 --- a/src/game/shared/neo/weapons/neo_weapon_parse.h +++ b/src/game/shared/neo/weapons/neo_weapon_parse.h @@ -74,6 +74,8 @@ class CNEOWeaponInfo : public CHL2MPSWeaponInfo int m_iBullets; float m_flCycleTime; float m_flReloadReadyBeforeEnd; + // A closed-bolt weapon retains a chambered round when reloading with rounds left. + bool m_bChamberedRound; // Empty: the weapon reloads without phases. Allocated only for scripts with a ReloadPhases block. CUtlVector m_reloadTables; char szViewModel2[MAX_WEAPON_STRING]; // Team 2 (NSF) wep vm diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index f54388a35e..1cb03f6d4b 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -46,6 +46,7 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) RecvPropInt(RECVINFO(m_nReloadTable)), RecvPropTime(RECVINFO(m_flReloadStart)), RecvPropInt(RECVINFO(m_nReloadSoundsDone)), + RecvPropBool(RECVINFO(m_bChamberEmpty)), RecvPropInt(RECVINFO(m_spawnflags)), #else SendPropTime(SENDINFO(m_flSoonestAttack)), @@ -58,6 +59,7 @@ BEGIN_NETWORK_TABLE( CNEOBaseCombatWeapon, DT_NEOBaseCombatWeapon ) 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), + SendPropBool(SENDINFO(m_bChamberEmpty)), SendPropInt(SENDINFO(m_spawnflags)), SendPropExclude("DT_BaseAnimating", "m_nSequence"), #endif @@ -75,6 +77,7 @@ BEGIN_PREDICTION_DATA(CNEOBaseCombatWeapon) 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), + DEFINE_PRED_FIELD(m_bChamberEmpty, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -92,6 +95,7 @@ BEGIN_DATADESC( CNEOBaseCombatWeapon ) DEFINE_FIELD(m_nReloadTable, FIELD_INTEGER), DEFINE_FIELD(m_flReloadStart, FIELD_TIME), DEFINE_FIELD(m_nReloadSoundsDone, FIELD_INTEGER), + DEFINE_FIELD(m_bChamberEmpty, FIELD_BOOLEAN), END_DATADESC() #endif @@ -258,6 +262,8 @@ CNEOBaseCombatWeapon::CNEOBaseCombatWeapon( void ) m_nReloadTable = -1; m_flReloadStart = 0.0f; m_nReloadSoundsDone = 0; + // Spawn ammo includes the chambered round; only a tactical reload adds an extra round. + m_bChamberEmpty = false; } const CNEOWeaponInfo &CNEOBaseCombatWeapon::GetNEOWpnData() const @@ -445,6 +451,12 @@ void CNEOBaseCombatWeapon::Equip(CBaseCombatCharacter* pOwner) bool CNEOBaseCombatWeapon::Reload( void ) { + const ReloadRequest_t request = ReloadPhasesOnRequest(); + if (request != RELOAD_REQUEST_DEFAULT) + { + return request == RELOAD_REQUEST_STARTED; + } + const bool bEmptyReload = UsesClipsForAmmo1() && m_iClip1 <= 0 && SelectWeightedSequence(ACT_VM_RELOAD_EMPTY) != ACTIVITY_NOT_AVAILABLE; @@ -506,6 +518,44 @@ bool CNEOBaseCombatWeapon::IsReloadPhaseSystemEnabled() const return NEORules() && NEORules()->IsReloadExperimental() && !GetNEOWpnData().m_reloadTables.IsEmpty(); } +CNEOBaseCombatWeapon::ReloadRequest_t CNEOBaseCombatWeapon::ReloadPhasesOnRequest() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return RELOAD_REQUEST_DEFAULT; + } + + // The phase paths below bypass DefaultReload, so a call during a reload must not restart it. + if (m_bInReload) + { + return RELOAD_REQUEST_REFUSED; + } + + // A lost resume must still allow chambering the loaded magazine, even without spare ammo. + if (HasChamberSlot() && m_bChamberEmpty && m_iClip1 > 0) + { + static constexpr const char *VM_SEQ_RELOAD_DRY = "reload"; + const int iTable = GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD_DRY); + if (iTable < 0 || !PlayReloadSequence(VM_SEQ_RELOAD_DRY, iTable, RELOAD_GESTURE_KEEP_START)) + { + return RELOAD_REQUEST_REFUSED; + } + + // Keep the loaded magazine's ammo; only the cycle phase still needs credit. + m_nReloadPhase = RELOAD_PHASE_LOADED; + CBaseCombatWeapon::WeaponSound(RELOAD_NPC); + return RELOAD_REQUEST_STARTED; + } + + if (HasChamberSlot() && RoundsInMagazine() >= MagazineCapacity()) + { + return RELOAD_REQUEST_REFUSED; + } + + // The tactical sequence omits the bolt cycle and retains the chambered round. + return StartPartialReload() ? RELOAD_REQUEST_STARTED : RELOAD_REQUEST_DEFAULT; +} + // The phases are those of the sequence the reload plays, such as reload or reloadempty void CNEOBaseCombatWeapon::ReloadPhasesOnReload() { @@ -519,15 +569,17 @@ void CNEOBaseCombatWeapon::ReloadPhasesOnReload() StartReloadPhases(pVM ? GetNEOWpnData().FindReloadTable(pVM->GetSequenceName(pVM->GetSequence())) : -1); } -// The magazine is in: the phases up to the load are done; a switch from here resumes only where the table names a resume -void CNEOBaseCombatWeapon::ReloadPhasesOnFinish() +// The magazine is in: the phases up to the load are done; a switch from here resumes only where the table names a resume. +// Returns the rounds the chamber keeps through the magazine change +int CNEOBaseCombatWeapon::ReloadPhasesOnFinish() { if (!IsReloadPhaseSystemEnabled()) { - return; + return 0; } m_nReloadPhase = Max(static_cast(m_nReloadPhase.Get()), RELOAD_PHASE_LOADED); + return IsRoundChambered() ? 1 : 0; } // A reload interrupted by a switch goes on in the draw; returns whether it resumed @@ -544,6 +596,7 @@ bool CNEOBaseCombatWeapon::ReloadPhasesOnDeploy() // Only a phase that a sequence resumes from outlasts the switch, with the table that names the resume void CNEOBaseCombatWeapon::ReloadPhasesOnHolster() { + // NEO TODO: Decide whether RELOAD_END should stop the gesture on a switch. if (!IsReloadPhaseSystemEnabled()) { return; @@ -647,14 +700,23 @@ void CNEOBaseCombatWeapon::RunReloadPhases() void CNEOBaseCombatWeapon::FinishReloadPhase(ReloadPhase_t phase) { - // 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_LOADED) + // The old magazine's rounds go with it, as a reload without phases discards them at the load (FinishReload); + // a chambered round stays + if (phase == RELOAD_PHASE_UNLOADED) + { + m_iClip1 = IsRoundChambered() ? 1 : 0; + } + else if (phase == RELOAD_PHASE_LOADED) { // the magazine loads now, as at a reload's ready time (ItemBusyFrame) m_flReloadReadyTime = gpGlobals->curtime; } + if (phase == RELOAD_PHASE_CYCLED) + { + m_bChamberEmpty = false; + } + m_nReloadPhase = phase; } @@ -664,19 +726,55 @@ bool CNEOBaseCombatWeapon::ResumeReload() { const char *pszName = FindResumeSequence(); const int iTable = pszName ? GetNEOWpnData().FindReloadTable(pszName) : -1; - const int iSequence = (iTable >= 0) ? LookupReloadSequence(pszName) : -1; - if (iSequence < 0) + if (iTable < 0 || LookupReloadSequence(pszName) < 0) { m_nReloadPhase = RELOAD_PHASE_NONE; m_nReloadTable = -1; return false; } - // After the unload the old magazine and its rounds are gone, as when a reload loads at its ready time. + // After the unload the old magazine and its rounds are gone, but a chambered round stays. // After the load the fresh magazine is already in. if (m_nReloadPhase == RELOAD_PHASE_UNLOADED) { - m_iClip1 = 0; + m_iClip1 = IsRoundChambered() ? 1 : 0; + } + + return PlayReloadSequence(pszName, iTable, RELOAD_GESTURE_KEEP_END); +} + +// The tactical sequence has no activity; ACT_VM_RELOAD selects the dry reload. +bool CNEOBaseCombatWeapon::StartPartialReload() +{ + static constexpr const char *VM_SEQ_RELOAD_PARTIAL = "reload_skipcycle"; + if (!IsReloadPhaseSystemEnabled() || !IsRoundChambered()) + { + return false; + } + + if (!UsesClipsForAmmo1() || RoundsInMagazine() >= MagazineCapacity() || m_iPrimaryAmmoCount <= 0) + { + return false; + } + + const int iTable = GetNEOWpnData().FindReloadTable(VM_SEQ_RELOAD_PARTIAL); + if (iTable < 0 || LookupReloadSequence(VM_SEQ_RELOAD_PARTIAL) < 0) + { + return false; + } + + m_nReloadPhase = RELOAD_PHASE_NONE; + return PlayReloadSequence(VM_SEQ_RELOAD_PARTIAL, iTable, RELOAD_GESTURE_KEEP_START); +} + +// Named sequences carry no activity, so time their reload phases and gesture explicitly. +bool CNEOBaseCombatWeapon::PlayReloadSequence(const char *pszName, int iTable, ReloadGestureFit_t gestureFit) +{ + auto *pOwner = ToHL2MPPlayer(GetOwner()); + const int iSequence = LookupReloadSequence(pszName); + if (!pOwner || iSequence < 0) + { + return false; } // The weapon entity draws its world model in third person, which has none of the viewmodel's sequences @@ -687,11 +785,11 @@ bool CNEOBaseCombatWeapon::ResumeReload() } SendViewModelAnim(iSequence); - // the third-person reload gesture lasts no longer than the resume + // the third-person reload gesture lasts no longer than this sequence const float flDuration = ReloadViewModel()->SequenceDuration(iSequence); - ToHL2MPPlayer(GetOwner())->DoAnimationEvent(PLAYERANIMEVENT_RELOAD, - CHL2MPPlayerAnimState::PackReloadGestureData(RELOAD_GESTURE_KEEP_END, flDuration)); + pOwner->DoAnimationEvent(PLAYERANIMEVENT_RELOAD, CHL2MPPlayerAnimState::PackReloadGestureData(gestureFit, flDuration)); + // the clip end is the fire point: no ReloadReadyBeforeEnd on this path const float flEnd = gpGlobals->curtime + flDuration; GetOwner()->SetNextAttack(flEnd); m_flNextPrimaryAttack = m_flNextSecondaryAttack = flEnd; @@ -704,6 +802,33 @@ bool CNEOBaseCombatWeapon::ResumeReload() return true; } +// The old magazine is out and the fresh one not yet in: the reload is about to refill the clip +bool CNEOBaseCombatWeapon::IsReloadPastUnload() const +{ + return IsReloadPhaseSystemEnabled() && m_bInReload && m_nReloadPhase == RELOAD_PHASE_UNLOADED; +} + +bool CNEOBaseCombatWeapon::HasChamberSlot() const +{ + return IsReloadPhaseSystemEnabled() && GetNEOWpnData().m_bChamberedRound; +} + +// The clip counts the chambered round; the chamber is empty after the last shot until a 3_cycle +bool CNEOBaseCombatWeapon::IsRoundChambered() const +{ + return HasChamberSlot() && m_iClip1 > 0 && !m_bChamberEmpty; +} + +int CNEOBaseCombatWeapon::RoundsInMagazine() const +{ + return m_iClip1 - (IsRoundChambered() ? 1 : 0); +} + +int CNEOBaseCombatWeapon::MagazineCapacity() const +{ + return GetMaxClip1(); +} + // 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 @@ -743,7 +868,6 @@ void CNEOBaseCombatWeapon::StopReloadSoundPieces() } } -// A dropped weapon cancels its reload: the next owner does not resume it void CNEOBaseCombatWeapon::StopReloadOnDrop() { if (!IsReloadPhaseSystemEnabled()) @@ -752,6 +876,14 @@ void CNEOBaseCombatWeapon::StopReloadOnDrop() } StopReloadSoundPieces(); + + // Preserve a pending bolt cycle for the next owner's draw. + // NEO TODO: Should a drop after 1_unload also resume for the next owner? + if (m_nReloadPhase >= RELOAD_PHASE_LOADED && FindResumeSequence()) + { + return; + } + m_nReloadPhase = RELOAD_PHASE_NONE; m_nReloadTable = -1; } @@ -791,7 +923,7 @@ void CNEOBaseCombatWeapon::FinishReload(void) } m_flReloadReadyTime = 0.0f; - ReloadPhasesOnFinish(); + const int iChambered = ReloadPhasesOnFinish(); CBaseCombatCharacter* pOwner = GetOwner(); @@ -801,7 +933,7 @@ void CNEOBaseCombatWeapon::FinishReload(void) if (UsesClipsForAmmo1()) { int primary = MIN(GetMaxClip1(), m_iPrimaryAmmoCount); - m_iClip1 = primary; + m_iClip1 = iChambered + primary; m_iPrimaryAmmoCount -= primary; } @@ -1331,6 +1463,13 @@ void CNEOBaseCombatWeapon::PrimaryAttack(void) return; } + // A loaded magazine cannot fire until a reload cycle chambers a round. + else if (HasChamberSlot() && m_bChamberEmpty && m_iClip1 > 0) + { + CheckReload(); + return; + } + else if (m_iClip1 == 0) { if (!m_bFireOnEmpty) @@ -1433,6 +1572,12 @@ void CNEOBaseCombatWeapon::PrimaryAttack(void) { info.m_iShots = MIN(info.m_iShots, m_iClip1); m_iClip1 -= info.m_iShots; + + // The last shot requires a bolt cycle on the next reload. + if (HasChamberSlot() && m_iClip1 <= 0) + { + m_bChamberEmpty = true; + } } else { diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index a197043f2e..469bbab87c 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -302,6 +302,13 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon // Each hook checks IsReloadPhaseSystemEnabled itself, so with the flag off a hook call does nothing public: void StopReloadOnDrop(); + 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; protected: bool IsReloadPhaseSystemEnabled() const; @@ -314,10 +321,21 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon CNetworkVar(float, m_flReloadStart); // the sound pieces of the playing sequence already started, one bit per piece CNetworkVar(int, m_nReloadSoundsDone); + // Only a reload cycle chambers a round after the last shot. + CNetworkVar(bool, m_bChamberEmpty); private: + // What a reload request does before the default reload: run it, or answer for the phases + enum ReloadRequest_t + { + RELOAD_REQUEST_DEFAULT, // the default reload runs + RELOAD_REQUEST_STARTED, // the phases started their own reload + RELOAD_REQUEST_REFUSED, // no reload starts + }; + + ReloadRequest_t ReloadPhasesOnRequest(); void ReloadPhasesOnReload(); - void ReloadPhasesOnFinish(); + int ReloadPhasesOnFinish(); bool ReloadPhasesOnDeploy(); void ReloadPhasesOnHolster(); void ReloadPhasesOnBusyFrame(); @@ -327,6 +345,8 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon void FinishReloadPhase(ReloadPhase_t phase); const char *FindResumeSequence() const; bool ResumeReload(); + bool PlayReloadSequence(const char *pszName, int iTable, ReloadGestureFit_t gestureFit); + bool StartPartialReload(); void StopReloadSoundPieces(); void EmitReloadSoundPiece(const char *pszSound); CBaseViewModel *ReloadViewModel() const;