From cd6859363d4ac551faf0d5da2d77e8bba9cc3107 Mon Sep 17 00:00:00 2001 From: AdamTadeusz Date: Mon, 13 Nov 2023 10:46:35 +0000 Subject: [PATCH 1/5] Change weapons reload to drop current magazine, disabled reload when weapon is holstered, changed clip display to show total ammo when using supa7, changed bullet icon to correspond to ammo type of weapon. --- mp/src/game/client/neo/ui/neo_hud_ammo.cpp | 50 +++++++++++++------ .../game/shared/basecombatweapon_shared.cpp | 6 +-- .../weapon_hl2mpbasehlmpcombatweapon.cpp | 2 +- 3 files changed, 39 insertions(+), 19 deletions(-) diff --git a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp index cbf13dab6..0a20c6eb7 100644 --- a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp +++ b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp @@ -145,29 +145,49 @@ void CNEOHud_Ammo::DrawAmmo() const { const auto ammo = GetAmmoDef()->GetAmmoOfIndex(activeWep->GetPrimaryAmmoType()); const int ammoCount = activeWep->GetOwner()->GetAmmoCount(ammo->pName); - const int numClips = abs(ammoCount / activeWep->GetMaxClip1()); // abs because grenades return negative values (???) + const int numClips = ceil(abs((float)ammoCount / activeWep->GetMaxClip1())); // abs because grenades return negative values (???) // casting division to float in case we have a half-empty mag, rounding up to show the half mag as one more mag // Render amount of clips remaining. Sort of an approximation, should revisit once unfinished mag "reload dumping" is implemented. - if (numClips != 0) - { - const int maxLen = 4; // support a max of '999' clips, plus '\0' - char clipsText[maxLen]{ '\0' }; - itoa(numClips, clipsText, 10); - textLen = V_strlen(clipsText); - wchar_t unicodeClipsText[maxLen]{ L'\0' }; - g_pVGuiLocalize->ConvertANSIToUnicode(clipsText, unicodeClipsText, sizeof(unicodeClipsText)); - - surface()->DrawSetTextPos(m_resX - fontWidth * 1.5 - margin, ypos + fontHeight * 2.5 - margin); - surface()->DrawPrintText(unicodeClipsText, textLen); - } + + const int maxLen = 4; // support a max of '999' clips, plus '\0' + char clipsText[maxLen]{ '\0' }; + itoa(strcmp(wepName, "MURATA SUPA 7") == 0 ? ammoCount : numClips, clipsText, 10); // If using the Supa7, display total ammo instead of total ammo/size of internal magazine + textLen = V_strlen(clipsText); + wchar_t unicodeClipsText[maxLen]{ L'\0' }; + g_pVGuiLocalize->ConvertANSIToUnicode(clipsText, unicodeClipsText, sizeof(unicodeClipsText)); + + surface()->DrawSetTextPos(m_resX - fontWidth * 1.5 - margin, ypos + fontHeight * 2.5 - margin); + surface()->DrawPrintText(unicodeClipsText, textLen); + // Render the bullet icons representing the amount of bullets in current clip. - if (ammoCount != 0 && activeWep->UsesClipsForAmmo1()) + if (activeWep->UsesClipsForAmmo1()) { + // Get character representation of ammo type + int ammoType = activeWep->GetPrimaryAmmoType(); + char* ammoChar = null; + switch (ammoType) { + case 1: + ammoChar = "a"; + break; + case 3: + ammoChar = "b"; + break; + case 12: + ammoChar = "d"; + break; + case 17: + ammoChar = "c"; + break; + default: + ammoChar = "a"; + break; + } + const int maxBulletsInClip = 63 + 1; char bullets[maxBulletsInClip]{ '\0' }; for (int i = 0, numBulletsInCurClip = activeWep->Clip1(); i < maxBulletsInClip && numBulletsInCurClip != 0; ++i) { - V_strcat_safe(bullets, "a"); + V_strcat_safe(bullets, ammoChar); --numBulletsInCurClip; } wchar_t unicodeBullets[maxBulletsInClip]{ L'\0' }; diff --git a/mp/src/game/shared/basecombatweapon_shared.cpp b/mp/src/game/shared/basecombatweapon_shared.cpp index 683f972e1..888d383f1 100644 --- a/mp/src/game/shared/basecombatweapon_shared.cpp +++ b/mp/src/game/shared/basecombatweapon_shared.cpp @@ -2220,9 +2220,9 @@ void CBaseCombatWeapon::FinishReload( void ) // If I use primary clips, reload primary if ( UsesClipsForAmmo1() ) { - int primary = MIN( GetMaxClip1() - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); - m_iClip1 += primary; - pOwner->RemoveAmmo( primary, m_iPrimaryAmmoType); + int primary = MIN(GetMaxClip1(), pOwner->GetAmmoCount(m_iPrimaryAmmoType)); + m_iClip1 = primary; + pOwner->RemoveAmmo(primary, m_iPrimaryAmmoType); } // If I use secondary clips, reload secondary diff --git a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp index 361a53f14..2b150d2c4 100644 --- a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp +++ b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp @@ -71,7 +71,7 @@ void CBaseHL2MPCombatWeapon::ItemHolsterFrame( void ) if ( ( gpGlobals->curtime - m_flHolsterTime ) > sk_auto_reload_time.GetFloat() ) { // Just load the clip with no animations - FinishReload(); + //FinishReload(); m_flHolsterTime = gpGlobals->curtime; } } From 931a69e03f0b8b86e2fa512e8828456309660ba6 Mon Sep 17 00:00:00 2001 From: AdamTadeusz Date: Mon, 13 Nov 2023 13:30:32 +0000 Subject: [PATCH 2/5] Bullet Character is now obtained from the weapon script. --- mp/src/game/client/neo/ui/neo_hud_ammo.cpp | 20 +------------------- mp/src/game/shared/weapon_parse.cpp | 2 ++ mp/src/game/shared/weapon_parse.h | 2 ++ 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp index 0a20c6eb7..8d92b743e 100644 --- a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp +++ b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp @@ -164,25 +164,7 @@ void CNEOHud_Ammo::DrawAmmo() const if (activeWep->UsesClipsForAmmo1()) { // Get character representation of ammo type - int ammoType = activeWep->GetPrimaryAmmoType(); - char* ammoChar = null; - switch (ammoType) { - case 1: - ammoChar = "a"; - break; - case 3: - ammoChar = "b"; - break; - case 12: - ammoChar = "d"; - break; - case 17: - ammoChar = "c"; - break; - default: - ammoChar = "a"; - break; - } + char* ammoChar = (char*)activeWep->GetWpnData().szBulletCharacter; const int maxBulletsInClip = 63 + 1; char bullets[maxBulletsInClip]{ '\0' }; diff --git a/mp/src/game/shared/weapon_parse.cpp b/mp/src/game/shared/weapon_parse.cpp index bb0b7e431..52456dfde 100644 --- a/mp/src/game/shared/weapon_parse.cpp +++ b/mp/src/game/shared/weapon_parse.cpp @@ -349,6 +349,7 @@ FileWeaponInfo_t::FileWeaponInfo_t() #ifdef NEO vecVmOffset = vec3_origin; + szBulletCharacter[0] = 0; #endif } @@ -425,6 +426,7 @@ void FileWeaponInfo_t::Parse( KeyValues *pKeyValuesData, const char *szWeaponNam const float VMOffsetRight = pKeyValuesData->GetFloat("VMOffsetRight"); const float VMOffsetUp = pKeyValuesData->GetFloat("VMOffsetUp"); vecVmOffset = Vector(VMOffsetForward, VMOffsetRight, VMOffsetUp); + Q_strncpy( szBulletCharacter, pKeyValuesData->GetString("BulletCharacter", "a"), MAX_BULLET_CHARACTER); #endif bShowUsageHint = ( pKeyValuesData->GetInt( "showusagehint", 0 ) != 0 ) ? true : false; diff --git a/mp/src/game/shared/weapon_parse.h b/mp/src/game/shared/weapon_parse.h index 3eff43b74..1a39d8b81 100644 --- a/mp/src/game/shared/weapon_parse.h +++ b/mp/src/game/shared/weapon_parse.h @@ -52,6 +52,7 @@ int GetWeaponSoundFromString( const char *pszString ); #define MAX_WEAPON_STRING 80 #define MAX_WEAPON_PREFIX 16 #define MAX_WEAPON_AMMO_NAME 32 +#define MAX_BULLET_CHARACTER 2 #define WEAPON_PRINTNAME_MISSING "!!! Missing printname on weapon" @@ -104,6 +105,7 @@ class FileWeaponInfo_t #ifdef NEO Vector vecVmOffset; + char szBulletCharacter[MAX_BULLET_CHARACTER];// character used to display ammunition in current clip #endif // Sound blocks From e058af1931060811fbc71fb874e2013760ab3d82 Mon Sep 17 00:00:00 2001 From: AdamTadeusz Date: Mon, 13 Nov 2023 14:06:50 +0000 Subject: [PATCH 3/5] Ammo counter is not displayed when knife is equipped. --- mp/game/neo/scripts/weapon_knife.txt | 1 + mp/src/game/client/neo/ui/neo_hud_ammo.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mp/game/neo/scripts/weapon_knife.txt b/mp/game/neo/scripts/weapon_knife.txt index 88af742de..321fc170d 100644 --- a/mp/game/neo/scripts/weapon_knife.txt +++ b/mp/game/neo/scripts/weapon_knife.txt @@ -14,6 +14,7 @@ WeaponData "clip_size" "-1" "primary_ammo" "None" "secondary_ammo" "None" + "MeleeWeapon" "1" "weight" "0" "item_flags" "0" diff --git a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp index 8d92b743e..c0c352ef8 100644 --- a/mp/src/game/client/neo/ui/neo_hud_ammo.cpp +++ b/mp/src/game/client/neo/ui/neo_hud_ammo.cpp @@ -141,7 +141,7 @@ void CNEOHud_Ammo::DrawAmmo() const surface()->DrawPrintText(unicodeWepName, textLen); const int maxClip = activeWep->GetMaxClip1(); - if (maxClip != 0) + if (maxClip != 0 && !activeWep->IsMeleeWeapon()) { const auto ammo = GetAmmoDef()->GetAmmoOfIndex(activeWep->GetPrimaryAmmoType()); const int ammoCount = activeWep->GetOwner()->GetAmmoCount(ammo->pName); From a493ff49ce8549e53f5e38023c4e87cbe024a3b0 Mon Sep 17 00:00:00 2001 From: AdamTadeusz Date: Sun, 28 Apr 2024 20:08:55 +0100 Subject: [PATCH 4/5] reverted base files to original state --- .../game/shared/basecombatweapon_shared.cpp | 4 +- .../weapon_hl2mpbasehlmpcombatweapon.cpp | 2 +- .../weapons/weapon_neobasecombatweapon.cpp | 38 +++++++++++++++++++ .../neo/weapons/weapon_neobasecombatweapon.h | 2 + 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/mp/src/game/shared/basecombatweapon_shared.cpp b/mp/src/game/shared/basecombatweapon_shared.cpp index 888d383f1..99f1b5dc2 100644 --- a/mp/src/game/shared/basecombatweapon_shared.cpp +++ b/mp/src/game/shared/basecombatweapon_shared.cpp @@ -2220,8 +2220,8 @@ void CBaseCombatWeapon::FinishReload( void ) // If I use primary clips, reload primary if ( UsesClipsForAmmo1() ) { - int primary = MIN(GetMaxClip1(), pOwner->GetAmmoCount(m_iPrimaryAmmoType)); - m_iClip1 = primary; + int primary = MIN(GetMaxClip1() - m_iClip1, pOwner->GetAmmoCount(m_iPrimaryAmmoType)); + m_iClip1 += primary; pOwner->RemoveAmmo(primary, m_iPrimaryAmmoType); } diff --git a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp index 2b150d2c4..361a53f14 100644 --- a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp +++ b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp @@ -71,7 +71,7 @@ void CBaseHL2MPCombatWeapon::ItemHolsterFrame( void ) if ( ( gpGlobals->curtime - m_flHolsterTime ) > sk_auto_reload_time.GetFloat() ) { // Just load the clip with no animations - //FinishReload(); + FinishReload(); m_flHolsterTime = gpGlobals->curtime; } } diff --git a/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp b/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp index c815fe25f..36b0d31c9 100644 --- a/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp +++ b/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.cpp @@ -132,6 +132,39 @@ bool CNEOBaseCombatWeapon::Reload( void ) #endif } + +//----------------------------------------------------------------------------- +// Purpose: Reload has finished. +//----------------------------------------------------------------------------- +void CNEOBaseCombatWeapon::FinishReload(void) +{ + CBaseCombatCharacter* pOwner = GetOwner(); + + if (pOwner) + { + // If I use primary clips, reload primary + if (UsesClipsForAmmo1()) + { + int primary = MIN(GetMaxClip1(), pOwner->GetAmmoCount(m_iPrimaryAmmoType)); + m_iClip1 = primary; + pOwner->RemoveAmmo(primary, m_iPrimaryAmmoType); + } + + // If I use secondary clips, reload secondary + if (UsesClipsForAmmo2()) + { + int secondary = MIN(GetMaxClip2() - m_iClip2, pOwner->GetAmmoCount(m_iSecondaryAmmoType)); + m_iClip2 += secondary; + pOwner->RemoveAmmo(secondary, m_iSecondaryAmmoType); + } + + if (m_bReloadsSingly) + { + m_bInReload = false; + } + } +} + bool CNEOBaseCombatWeapon::CanBeSelected(void) { if (GetWeaponFlags() & ITEM_FLAG_NOAUTOSWITCHEMPTY) @@ -206,6 +239,11 @@ bool CNEOBaseCombatWeapon::Holster(CBaseCombatWeapon* pSwitchingTo) return BaseClass::Holster(pSwitchingTo); } + +void CNEOBaseCombatWeapon::ItemHolsterFrame(void) +{ // Overrides the base class behaviour of reloading the weapon after its been holstered for 3 seconds + return; +} #endif void CNEOBaseCombatWeapon::CheckReload(void) diff --git a/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 48dbedcc6..b8494b026 100644 --- a/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/mp/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -135,6 +135,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon virtual void CheckReload(void); virtual bool Reload( void ); + virtual void FinishReload(void) OVERRIDE; virtual bool CanBeSelected(void); @@ -196,6 +197,7 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon #ifdef CLIENT_DLL virtual bool Holster(CBaseCombatWeapon* pSwitchingTo); + virtual void ItemHolsterFrame() OVERRIDE; #endif virtual bool Deploy(void); From fe5ce4e601b520010eda3e164c465626078ff369 Mon Sep 17 00:00:00 2001 From: AdamTadeusz Date: Sun, 28 Apr 2024 20:47:40 +0100 Subject: [PATCH 5/5] Player PostThink will cast our CNEOBaseWeapon to a CBaseCombatWeapon regardless, so holster reload will occure anyway, need to early return in this function or earlier or rewrite CNEOPlayer postThink to not call baseclass postThink but thats a huge amount of effort I think --- mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp index 361a53f14..650badb0a 100644 --- a/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp +++ b/mp/src/game/shared/hl2mp/weapon_hl2mpbasehlmpcombatweapon.cpp @@ -59,6 +59,9 @@ void CBaseHL2MPCombatWeapon::ItemHolsterFrame( void ) { BaseClass::ItemHolsterFrame(); +#ifdef NEO + return; +#endif // Must be player held if ( GetOwner() && GetOwner()->IsPlayer() == false ) return;