From b37078f019a83da9dc6e0cc5ef29668725b2f25f Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Sun, 4 Feb 2024 01:15:33 +0500 Subject: [PATCH] Change weapon switch rules. --- dlls/gamerules.h | 2 +- dlls/multiplay_gamerules.cpp | 65 ++----------------------------- dlls/rpg.cpp | 2 +- dlls/singleplay_gamerules.cpp | 73 +++++++++++++++++++++++++++++++++++ dlls/weapons.h | 1 + 5 files changed, 79 insertions(+), 64 deletions(-) diff --git a/dlls/gamerules.h b/dlls/gamerules.h index 0d86ce02..adbbaa31 100644 --- a/dlls/gamerules.h +++ b/dlls/gamerules.h @@ -166,7 +166,7 @@ public: }; extern CGameRules *InstallGameRules( void ); - +BOOL HLGetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ); //========================================================= // CHalfLifeRules - rules for the single player Half-Life diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index 1578ec13..ef2db2d5 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -345,70 +345,11 @@ BOOL CHalfLifeMultiplay::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerI return FALSE; } +//========================================================= +//========================================================= BOOL CHalfLifeMultiplay::GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ) { - CBasePlayerItem *pCheck; - CBasePlayerItem *pBest;// this will be used in the event that we don't find a weapon in the same category. - int iBestWeight; - int i; - - iBestWeight = -1;// no weapon lower than -1 can be autoswitched to - pBest = NULL; - - if( !pCurrentWeapon->CanHolster() ) - { - // can't put this gun away right now, so can't switch. - return FALSE; - } - - for( i = 0; i < MAX_ITEM_TYPES; i++ ) - { - pCheck = pPlayer->m_rgpPlayerItems[i]; - - while( pCheck ) - { - if( pCheck->iWeight() > -1 && pCheck->iWeight() == pCurrentWeapon->iWeight() && pCheck != pCurrentWeapon ) - { - // this weapon is from the same category. - if ( pCheck->CanDeploy() ) - { - if ( pPlayer->SwitchWeapon( pCheck ) ) - { - return TRUE; - } - } - } - else if( pCheck->iWeight() > iBestWeight && pCheck != pCurrentWeapon )// don't reselect the weapon we're trying to get rid of - { - //ALERT ( at_console, "Considering %s\n", STRING( pCheck->pev->classname ) ); - // we keep updating the 'best' weapon just in case we can't find a weapon of the same weight - // that the player was using. This will end up leaving the player with his heaviest-weighted - // weapon. - if( pCheck->CanDeploy() ) - { - // if this weapon is useable, flag it as the best - iBestWeight = pCheck->iWeight(); - pBest = pCheck; - } - } - - pCheck = pCheck->m_pNext; - } - } - - // if we make it here, we've checked all the weapons and found no useable - // weapon in the same catagory as the current weapon. - - // if pBest is null, we didn't find ANYTHING. Shouldn't be possible- should always - // at least get the crowbar, but ya never know. - if( !pBest ) - { - return FALSE; - } - - pPlayer->SwitchWeapon( pBest ); - - return TRUE; + return HLGetNextBestWeapon( pPlayer, pCurrentWeapon ); } //========================================================= diff --git a/dlls/rpg.cpp b/dlls/rpg.cpp index 271a9d7c..4e39ec2c 100644 --- a/dlls/rpg.cpp +++ b/dlls/rpg.cpp @@ -400,7 +400,7 @@ int CRpg::GetItemInfo( ItemInfo *p ) p->iSlot = 3; p->iPosition = 0; p->iId = m_iId = WEAPON_RPG; - p->iFlags = 0; + p->iFlags = ITEM_FLAG_NOCHOICE; p->iWeight = RPG_WEIGHT; return 1; diff --git a/dlls/singleplay_gamerules.cpp b/dlls/singleplay_gamerules.cpp index 59f43fa2..06ad417c 100644 --- a/dlls/singleplay_gamerules.cpp +++ b/dlls/singleplay_gamerules.cpp @@ -95,10 +95,83 @@ BOOL CHalfLifeRules::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem return TRUE; } +//========================================================= +//========================================================= +BOOL HLGetNextBestWeapon(CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ) +{ + CBasePlayerItem *pCheck; + CBasePlayerItem *pBest;// this will be used in the event that we don't find a weapon in the same category. + int iBestWeight; + int i; + + iBestWeight = -1;// no weapon lower than -1 can be autoswitched to + pBest = NULL; + + if( !pCurrentWeapon->CanHolster() ) + { + // can't put this gun away right now, so can't switch. + return FALSE; + } + + for( i = 0; i < MAX_ITEM_TYPES; i++ ) + { + pCheck = pPlayer->m_rgpPlayerItems[i]; + + while( pCheck ) + { + if( !FBitSet( pCheck->iFlags(), ITEM_FLAG_NOCHOICE )) + { + if( pCheck->iWeight() > -1 && pCheck->iWeight() == pCurrentWeapon->iWeight() && pCheck != pCurrentWeapon ) + { + // this weapon is from the same category. + if ( pCheck->CanDeploy() ) + { + if ( pPlayer->SwitchWeapon( pCheck ) ) + { + return TRUE; + } + } + } + else if( pCheck->iWeight() > iBestWeight && pCheck != pCurrentWeapon )// don't reselect the weapon we're trying to get rid of + { + //ALERT ( at_console, "Considering %s\n", STRING( pCheck->pev->classname ) ); + // we keep updating the 'best' weapon just in case we can't find a weapon of the same weight + // that the player was using. This will end up leaving the player with his heaviest-weighted + // weapon. + if( pCheck->CanDeploy() ) + { + // if this weapon is useable, flag it as the best + iBestWeight = pCheck->iWeight(); + pBest = pCheck; + } + } + } + + pCheck = pCheck->m_pNext; + } + } + + // if we make it here, we've checked all the weapons and found no useable + // weapon in the same catagory as the current weapon. + + // if pBest is null, we didn't find ANYTHING. Shouldn't be possible- should always + // at least get the crowbar, but ya never know. + if( !pBest ) + { + return FALSE; + } + + pPlayer->SwitchWeapon( pBest ); + + return TRUE; +} + //========================================================= //========================================================= BOOL CHalfLifeRules::GetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon ) { + if( pCurrentWeapon && FBitSet( pCurrentWeapon->iFlags(), ITEM_FLAG_EXHAUSTIBLE )) + return HLGetNextBestWeapon( pPlayer, pCurrentWeapon ); return FALSE; } diff --git a/dlls/weapons.h b/dlls/weapons.h index f0ba783c..4db8381f 100644 --- a/dlls/weapons.h +++ b/dlls/weapons.h @@ -183,6 +183,7 @@ typedef enum #define ITEM_FLAG_NOAUTOSWITCHEMPTY 4 #define ITEM_FLAG_LIMITINWORLD 8 #define ITEM_FLAG_EXHAUSTIBLE 16 // A player can totally exhaust their ammo supply and lose this weapon +#define ITEM_FLAG_NOCHOICE 32 #define WEAPON_IS_ONTARGET 0x40