mirror of
https://github.com/FWGS/hlsdk-xash3d
synced 2024-11-22 01:47:45 +01:00
Change weapon switch rules.
This commit is contained in:
parent
d438dbfe33
commit
b37078f019
@ -166,7 +166,7 @@ public:
|
||||
};
|
||||
|
||||
extern CGameRules *InstallGameRules( void );
|
||||
|
||||
BOOL HLGetNextBestWeapon( CBasePlayer *pPlayer, CBasePlayerItem *pCurrentWeapon );
|
||||
|
||||
//=========================================================
|
||||
// CHalfLifeRules - rules for the single player Half-Life
|
||||
|
@ -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 );
|
||||
}
|
||||
|
||||
//=========================================================
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user