From 688b5b4b37362060defb1eb094912be7e8511e5f Mon Sep 17 00:00:00 2001 From: Alan Shen Date: Mon, 9 Nov 2026 20:24:51 -0700 Subject: [PATCH] Add Supa-7 slug input rules With sv_neo_reload_experimental on, a Supa-7 reload loads shells or slugs, and the player picks which while it runs: - A round's type is set when it enters the tube, so an input during its insert decides it. - Alt-fire during a reload makes the rest of the load slugs; with no reload running it starts one that loads slugs. - Reload during a slug load makes the rest of it shells. - Any number of slugs; a slug load ends when the slugs run out. - In freeze time, alt-fire loads the whole gun with slugs and reload with shells. The choice is saved in cl_neo_supa7_prefer_slugs and applied to the gun in later freeze times. - The HUD fire-mode letter shows the type a reload is loading, otherwise the chambered round's type. The player's freeze-time alt-fire exception is a type check plus the public sv_neo_reload_experimental rule check, as for the Tachi, and the HUD keeps master's SlugLoaded() call, so CWeaponSupa7 gains no public member. With the flag off the Supa-7 behaves as on master. --- src/game/client/c_baseplayer.cpp | 5 +- src/game/server/neo/neo_player.cpp | 1 + src/game/server/player.cpp | 5 +- src/game/shared/neo/weapons/weapon_supa7.cpp | 203 +++++++++++++++++-- src/game/shared/neo/weapons/weapon_supa7.h | 10 + 5 files changed, 201 insertions(+), 23 deletions(-) diff --git a/src/game/client/c_baseplayer.cpp b/src/game/client/c_baseplayer.cpp index 21e5f5170f..b378a90219 100644 --- a/src/game/client/c_baseplayer.cpp +++ b/src/game/client/c_baseplayer.cpp @@ -64,6 +64,7 @@ #ifdef NEO #include "c_neo_player.h" #include "weapon_tachi.h" +#include "weapon_supa7.h" #include "ivieweffects.h" #endif @@ -2611,7 +2612,9 @@ void C_BasePlayer::PhysicsSimulate( void ) ctx->cmd.buttons &= ~(IN_ATTACK | IN_JUMP | IN_SPEED | IN_ALT1 | IN_ALT2 | IN_BACK | IN_FORWARD | IN_MOVELEFT | IN_MOVERIGHT | IN_RUN); const bool isTachi = (dynamic_cast(GetActiveWeapon()) != NULL); - if (!isTachi) + const bool isSupa7 = (dynamic_cast(GetActiveWeapon()) != NULL); + // with the experimental reloads, the Supa-7's freeze-time alt-fire picks slugs for the load + if (!isTachi && !(isSupa7 && NEORules()->IsReloadExperimental())) { ctx->cmd.buttons &= ~IN_ATTACK2; } diff --git a/src/game/server/neo/neo_player.cpp b/src/game/server/neo/neo_player.cpp index 6e038c727f..b3d76c9be2 100644 --- a/src/game/server/neo/neo_player.cpp +++ b/src/game/server/neo/neo_player.cpp @@ -640,6 +640,7 @@ CNEO_Player::CNEO_Player() } convars[] = { { "cl_neo_pvs_cull_roaming_observer", "0" }, { "cl_neo_streamermode", "0" }, + { "cl_neo_supa7_prefer_slugs", "0" }, { "cl_neo_tachi_prefer_auto", "1" }, { "cl_neo_taking_damage_sounds", "0" }, { "cl_onlysteamnick", "0" }, diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp index 58d549330f..4cab3f1745 100644 --- a/src/game/server/player.cpp +++ b/src/game/server/player.cpp @@ -86,6 +86,7 @@ #include "../../common/neo/bit_cast.h" #include "neo_player.h" #include "weapon_tachi.h" +#include "weapon_supa7.h" #include "neo_gamerules.h" #include "tier1/convar_serverbounded.h" #endif @@ -4019,7 +4020,9 @@ void CBasePlayer::PlayerRunCommand(CUserCmd *ucmd, IMoveHelper *moveHelper) ucmd->buttons &= ~(IN_ATTACK | IN_JUMP | IN_SPEED | IN_ALT1 | IN_ALT2 | IN_BACK | IN_FORWARD | IN_MOVELEFT | IN_MOVERIGHT | IN_RUN); const bool isTachi = (dynamic_cast(GetActiveWeapon()) != NULL); - if (!isTachi) + const bool isSupa7 = (dynamic_cast(GetActiveWeapon()) != NULL); + // with the experimental reloads, the Supa-7's freeze-time alt-fire picks slugs for the load + if (!isTachi && !(isSupa7 && NEORules()->IsReloadExperimental())) { ucmd->buttons &= ~IN_ATTACK2; } diff --git a/src/game/shared/neo/weapons/weapon_supa7.cpp b/src/game/shared/neo/weapons/weapon_supa7.cpp index 875857112c..d65f0ab02a 100644 --- a/src/game/shared/neo/weapons/weapon_supa7.cpp +++ b/src/game/shared/neo/weapons/weapon_supa7.cpp @@ -1,6 +1,9 @@ #include "cbase.h" #include "weapon_supa7.h" #include "neo_gamerules.h" +#ifdef CLIENT_DLL +#include "prediction.h" +#endif // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" @@ -19,6 +22,7 @@ BEGIN_NETWORK_TABLE(CWeaponSupa7, DT_WeaponSupa7) RecvPropInt(RECVINFO(m_nInsert)), RecvPropTime(RECVINFO(m_flInsertCreditTime)), RecvPropTime(RECVINFO(m_flRackFeedTime)), + RecvPropBool(RECVINFO(m_bSlugLoad)), #else SendPropBool(SENDINFO(m_bSlugDelayed)), SendPropBool(SENDINFO(m_bSlugLoaded)), @@ -31,6 +35,7 @@ BEGIN_NETWORK_TABLE(CWeaponSupa7, DT_WeaponSupa7) SendPropInt(SENDINFO(m_nInsert), 2, SPROP_UNSIGNED), SendPropTime(SENDINFO(m_flInsertCreditTime)), SendPropTime(SENDINFO(m_flRackFeedTime)), + SendPropBool(SENDINFO(m_bSlugLoad)), #endif END_NETWORK_TABLE() @@ -47,6 +52,7 @@ BEGIN_PREDICTION_DATA(CWeaponSupa7) DEFINE_PRED_FIELD(m_nInsert, FIELD_INTEGER, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_flInsertCreditTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), DEFINE_PRED_FIELD(m_flRackFeedTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_bSlugLoad, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -54,6 +60,11 @@ LINK_ENTITY_TO_CLASS(weapon_supa7, CWeaponSupa7); PRECACHE_WEAPON_REGISTER(weapon_supa7); +#ifdef CLIENT_DLL +ConVar cl_neo_supa7_prefer_slugs("cl_neo_supa7_prefer_slugs", "0", FCVAR_ARCHIVE | FCVAR_USERINFO, + "Whether the Supa-7 starts a round loaded with slugs. Set by the freeze-time alt-fire and reload presses.", true, false, true, true); +#endif + #ifdef GAME_DLL BEGIN_DATADESC(CWeaponSupa7) DEFINE_FIELD(m_bSlugDelayed, FIELD_BOOLEAN), @@ -67,6 +78,7 @@ BEGIN_DATADESC(CWeaponSupa7) DEFINE_FIELD(m_nInsert, FIELD_INTEGER), DEFINE_FIELD(m_flInsertCreditTime, FIELD_TIME), DEFINE_FIELD(m_flRackFeedTime, FIELD_TIME), + DEFINE_FIELD(m_bSlugLoad, FIELD_BOOLEAN), END_DATADESC() #endif @@ -116,6 +128,7 @@ CWeaponSupa7::CWeaponSupa7(void) m_nInsert = SUPA7_INSERT_NONE; m_flInsertCreditTime = 0.0f; m_flRackFeedTime = 0.0f; + m_bSlugLoad = false; m_fMinRange1 = 0.0; m_fMaxRange1 = 500; @@ -154,7 +167,7 @@ bool CWeaponSupa7::StartReload(void) } } - if (m_iPrimaryAmmoCount <= 0) + if (m_iPrimaryAmmoCount <= 0 && !IsSlugLoadActive()) return false; if (m_iClip1 >= GetMaxClip1()) @@ -180,6 +193,11 @@ bool CWeaponSupa7::StartReload(void) // Purpose: Start loading a slug, avoid overriding the default reload functionality due to secondary ammo bool CWeaponSupa7::StartReloadSlug(void) { + if (IsTubeEnabled()) + { + return TubePhasesOnStartSlug(); + } + if (m_bSlugLoaded) return false; @@ -196,11 +214,6 @@ bool CWeaponSupa7::StartReloadSlug(void) if (m_iClip1 >= GetMaxClip1()) return false; - if (!TubePhasesOnStartSlug()) - { - return false; - } - if (!m_bInReload) { SendWeaponAnim(ACT_SHOTGUN_RELOAD_START); @@ -233,7 +246,7 @@ bool CWeaponSupa7::Reload(void) if (pOwner == NULL) return false; - if (m_iPrimaryAmmoCount <= 0) + if (m_iPrimaryAmmoCount <= 0 && !IsSlugLoadActive()) return false; if (m_iClip1 >= GetMaxClip1()) @@ -248,7 +261,7 @@ bool CWeaponSupa7::Reload(void) WeaponSound(SPECIAL1); SendWeaponAnim(ACT_VM_RELOAD); pOwner->DoAnimationEvent(PLAYERANIMEVENT_RELOAD); - StartInsert(SUPA7_INSERT_SHELL); + StartInsert(IsSlugLoadActive() ? SUPA7_INSERT_SLUG : SUPA7_INSERT_SHELL); pOwner->m_flNextAttack = gpGlobals->curtime; constexpr float TIME_BETWEEN_SHELLS_LOADED = 0.5f; @@ -513,9 +526,12 @@ void CWeaponSupa7::ItemPostFrame(void) } ProcessAnimationEvents(); TubePhasesOnFrame(); + TubePhasesOnFreezeTime(); if (m_bInReload) { + TubePhasesOnLoadInput(); + // If I'm primary firing and have one round stop reloading if ((pOwner->m_nButtons & IN_ATTACK) && (m_iClip1 >= 1) && !IsRackPending()) { @@ -632,6 +648,13 @@ void CWeaponSupa7::ItemPostFrame(void) } } +// The draw at spawn keeps the gun busy; the freeze-time load choice applies during it +void CWeaponSupa7::ItemBusyFrame(void) +{ + TubePhasesOnFreezeTime(); + BaseClass::ItemBusyFrame(); +} + bool CWeaponSupa7::IsTubeEnabled() const { return NEORules() && NEORules()->IsReloadExperimental(); @@ -660,21 +683,97 @@ bool CWeaponSupa7::TubePhasesOnStart() return true; } -// One slug per request: a held alt-fire neither queues another nor delays the shot +// Alt-fire with no reload running starts one that loads slugs bool CWeaponSupa7::TubePhasesOnStartSlug() { - if (!IsTubeEnabled()) + if (m_bInReload || m_iSecondaryAmmoCount <= 0 || IsInFreezeTime()) { - return true; + return false; } - if (m_bSlugDelayed || m_nInsert == SUPA7_INSERT_SLUG) + m_bSlugLoad = true; + if (!StartReload()) { + m_bSlugLoad = false; return false; } + return true; +} - SyncTube(); - return !IsTubeFull(); +// Alt-fire makes the rest of the load slugs, from the round in the hand on; a reload press makes it shells again +void CWeaponSupa7::TubePhasesOnLoadInput() +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + if (!IsTubeEnabled() || !pOwner) + { + return; + } + + if ((pOwner->m_nButtons & IN_ATTACK2) && m_iSecondaryAmmoCount > 0) + { + m_bSlugLoad = true; + } + else if ((pOwner->m_afButtonPressed & IN_RELOAD) && m_iPrimaryAmmoCount > 0) + { + m_bSlugLoad = false; + } +} + +// Freeze time: alt-fire loads the gun with slugs, a reload press with shells, and the client keeps the choice for +// later freeze times +void CWeaponSupa7::TubePhasesOnFreezeTime() +{ + CBasePlayer *pOwner = ToBasePlayer(GetOwner()); + if (!IsTubeEnabled() || !pOwner) + { + return; + } + +#ifdef GAME_DLL + if (!IsInFreezeTime()) + { + m_bFreezePreferenceApplied = false; + return; + } + + if (!m_bFreezePreferenceApplied) + { + m_bFreezePreferenceApplied = true; + const char *pszPrefer = engine->GetClientConVarValue(pOwner->entindex(), "cl_neo_supa7_prefer_slugs"); + if (pszPrefer && *pszPrefer && V_atoi(pszPrefer) != 0) + { + ConvertLoad(SUPA7_INSERT_SLUG); + } + } +#else + if (!IsInFreezeTime()) + { + return; + } +#endif + + Supa7Insert_t load = SUPA7_INSERT_NONE; + if (pOwner->m_afButtonPressed & IN_ATTACK2) + { + load = SUPA7_INSERT_SLUG; + } + else if (pOwner->m_afButtonPressed & IN_RELOAD) + { + load = SUPA7_INSERT_SHELL; + } + + if (load == SUPA7_INSERT_NONE) + { + return; + } + + ConvertLoad(load); +#ifdef CLIENT_DLL + if (pOwner->IsLocalPlayer() && prediction->IsFirstTimePredicted()) + { + cl_neo_supa7_prefer_slugs.SetValue(load == SUPA7_INSERT_SLUG); + } +#endif } // A round still in the hand goes back to the reserve; an empty chamber is racked before the next shot. @@ -688,6 +787,7 @@ bool CWeaponSupa7::TubePhasesOnFinish() } CancelInsert(); + m_bSlugLoad = false; SyncTube(); if (!IsChamberLive() && m_nTubeCount > 0) { @@ -740,6 +840,7 @@ void CWeaponSupa7::TubePhasesOnDrop() CancelInsert(); m_flRackFeedTime = 0.0f; + m_bSlugLoad = false; } void CWeaponSupa7::TubePhasesOnFrame() @@ -754,7 +855,7 @@ void CWeaponSupa7::TubePhasesOnFrame() RunRack(); } -// The next shell of a reload; a slug insert ends the reload, as it does without the tube. +// The next round of a reload; the reload ends when the reserve of the type it loads runs out. // Returns whether the tube handled the step bool CWeaponSupa7::TubePhasesOnNextInsert() { @@ -763,16 +864,15 @@ bool CWeaponSupa7::TubePhasesOnNextInsert() return false; } - const bool bSlugInserted = (m_nInsert == SUPA7_INSERT_SLUG); m_nInsert = SUPA7_INSERT_NONE; - // a slug ends the reload with the shipped rack, as it does without the pump - if (!IsChamberLive() && m_nTubeCount > 0 && !bSlugInserted && UsesPumpAfterInsert()) + if (!IsChamberLive() && m_nTubeCount > 0 && UsesPumpAfterInsert()) { StartPumpAfterInsert(); return true; } - if (m_iPrimaryAmmoCount <= 0 || bSlugInserted || IsTubeFull() || !Reload()) + const int iReserve = m_bSlugLoad ? m_iSecondaryAmmoCount : m_iPrimaryAmmoCount; + if (iReserve <= 0 || IsTubeFull() || !Reload()) { FinishReload(); } @@ -811,6 +911,7 @@ void CWeaponSupa7::TubePhasesOnHolster() CancelInsert(); m_flRackFeedTime = 0.0f; m_bSlugDelayed = false; + m_bSlugLoad = false; } // Rebuild the tube from the clip count when something set the count directly (a new or picked-up gun, a give): @@ -903,18 +1004,73 @@ void CWeaponSupa7::RunInsert() return; } - if (m_nInsert == SUPA7_INSERT_SLUG && m_iSecondaryAmmoCount > 0) + // the round's type is set as it enters the tube, so an input during the insert decides it + if (m_nInsert == SUPA7_INSERT_NONE) + { + return; + } + + if (m_bSlugLoad && m_iSecondaryAmmoCount > 0) { TubePush(SUPA7_INSERT_SLUG); m_iSecondaryAmmoCount -= 1; } - else if (m_nInsert == SUPA7_INSERT_SHELL && m_iPrimaryAmmoCount > 0) + else if (!m_bSlugLoad && m_iPrimaryAmmoCount > 0) { TubePush(SUPA7_INSERT_SHELL); m_iPrimaryAmmoCount -= 1; } } +bool CWeaponSupa7::IsInFreezeTime() const +{ + auto pOwner = static_cast(GetOwner()); + return pOwner && (pOwner->GetNeoFlags() & NEO_FL_FREEZETIME); +} + +// Sets the type of the rounds in the gun, the chamber first, then the tube in fire order, while the reserve of that +// type lasts; each replaced round goes back to its reserve +void CWeaponSupa7::ConvertLoad(Supa7Insert_t round) +{ + const bool bToSlug = (round == SUPA7_INSERT_SLUG); + auto swapWithReserve = [this, bToSlug]() + { + int &iTakeFrom = bToSlug ? m_iSecondaryAmmoCount.GetForModify() : m_iPrimaryAmmoCount.GetForModify(); + if (iTakeFrom <= 0) + { + return false; + } + + iTakeFrom -= 1; + int &iGiveTo = bToSlug ? m_iPrimaryAmmoCount.GetForModify() : m_iSecondaryAmmoCount.GetForModify(); + iGiveTo += 1; + return true; + }; + + SyncTube(); + if (IsChamberLive() && (m_nChamber == SUPA7_CHAMBER_SLUG) != bToSlug && swapWithReserve()) + { + m_nChamber = bToSlug ? SUPA7_CHAMBER_SLUG : SUPA7_CHAMBER_SHELL; + } + + for (int i = m_nTubeCount - 1; i >= 0; --i) + { + const int iBit = (1 << i); + if (((m_nTubeSlugs & iBit) != 0) == bToSlug) + { + continue; + } + + if (!swapWithReserve()) + { + break; + } + + m_nTubeSlugs = bToSlug ? (m_nTubeSlugs | iBit) : (m_nTubeSlugs & ~iBit); + } + UpdateClipFromTube(); +} + void CWeaponSupa7::CancelInsert() { m_nInsert = SUPA7_INSERT_NONE; @@ -1060,8 +1216,13 @@ const WeaponSpreadInfo_t &CWeaponSupa7::GetSpreadInfo() return m_weaponHandling.spreadInfo[m_bSlugLoaded]; } +// For the fire-mode letter: the type a reload is loading, otherwise the chambered round's bool CWeaponSupa7::SlugLoaded() const { + if (IsTubeEnabled() && m_bInReload) + { + return m_bSlugLoad; + } return m_bSlugLoaded; } diff --git a/src/game/shared/neo/weapons/weapon_supa7.h b/src/game/shared/neo/weapons/weapon_supa7.h index 9ab4c17738..f65ae87c5f 100644 --- a/src/game/shared/neo/weapons/weapon_supa7.h +++ b/src/game/shared/neo/weapons/weapon_supa7.h @@ -55,6 +55,7 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon void FillClipSlug(void); void FinishReload(void); void ItemPostFrame(void); + void ItemBusyFrame(void) OVERRIDE; void PrimaryAttack(void); void SecondaryAttack(void); @@ -107,6 +108,8 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon // Tube phases (sv_neo_reload_experimental); each hook does nothing with the flag off bool TubePhasesOnStart(); bool TubePhasesOnStartSlug(); + void TubePhasesOnLoadInput(); + void TubePhasesOnFreezeTime(); bool TubePhasesOnFinish(); bool TubePhasesCanFire(); void TubePhasesOnShot(); @@ -122,6 +125,9 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon int TubeCapacity() const { return GetMaxClip1() - SUPA7_CHAMBER_ROUNDS; } void SyncTube(); void TubePush(Supa7Insert_t round); + bool IsSlugLoadActive() const { return IsTubeEnabled() && m_bSlugLoad; } + bool IsInFreezeTime() const; + void ConvertLoad(Supa7Insert_t round); void FeedChamber(); void UpdateClipFromTube(); void StartInsert(Supa7Insert_t round); @@ -159,6 +165,10 @@ class CWeaponSupa7 : public CNEOBaseCombatWeapon CNetworkVar(int, m_nInsert); // Supa7Insert_t CNetworkVar(float, m_flInsertCreditTime); // when the inserted round enters the tube, 0 none CNetworkVar(float, m_flRackFeedTime); // when the rack's pump is home with the next round, 0 none + CNetworkVar(bool, m_bSlugLoad); // the reload loads slugs, each round typed when it is credited +#ifdef GAME_DLL + bool m_bFreezePreferenceApplied = false; // the owner's saved freeze-time load type, once per freeze time +#endif private: CWeaponSupa7(const CWeaponSupa7 &other);