Skip to content

Commit

Permalink
Fixed bug with satchels: when all satchel deployed and standing on ne…
Browse files Browse the repository at this point in the history
…w ones, explode and after pickup you can't select satchels because satchels weapon is delayed stripped from player.

Fixed bug with packing more then 20 weapons in one weaponbox.
  • Loading branch information
LevShisterov committed Jun 20, 2012
1 parent 8668d11 commit 68c9b7c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 57 deletions.
3 changes: 1 addition & 2 deletions dlls/handgrenade.cpp
Expand Up @@ -103,8 +103,7 @@ void CHandGrenade::Holster( int skiplocal /* = 0 */ )
{
// no more grenades!
m_pPlayer->pev->weapons &= ~(1<<WEAPON_HANDGRENADE);
SetThink( &CHandGrenade::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
DestroyItem();
}

EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);
Expand Down
32 changes: 17 additions & 15 deletions dlls/player.cpp
Expand Up @@ -687,8 +687,8 @@ void CBasePlayer::PackDeadPlayerItems( void )
int iWeaponRules;
int iAmmoRules;
int i;
CBasePlayerWeapon *rgpPackWeapons[ 20 ];// 20 hardcoded for now. How to determine exactly how many weapons we have?
int iPackAmmo[ MAX_AMMO_SLOTS + 1];
CBasePlayerWeapon *rgpPackWeapons[ MAX_WEAPONS ];
int iPackAmmo[ MAX_AMMO_SLOTS ];
int iPW = 0;// index into packweapons array
int iPA = 0;// index into packammo array

Expand All @@ -697,7 +697,7 @@ void CBasePlayer::PackDeadPlayerItems( void )

// get the game rules
iWeaponRules = g_pGameRules->DeadPlayerWeapons( this );
iAmmoRules = g_pGameRules->DeadPlayerAmmo( this );
iAmmoRules = g_pGameRules->DeadPlayerAmmo( this );

if ( iWeaponRules == GR_PLR_DROP_GUN_NO && iAmmoRules == GR_PLR_DROP_AMMO_NO )
{
Expand All @@ -706,15 +706,15 @@ void CBasePlayer::PackDeadPlayerItems( void )
return;
}

// go through all of the weapons and make a list of the ones to pack
for ( i = 0 ; i < MAX_ITEM_TYPES ; i++ )
// go through all of the weapons and make a list of the ones to pack
for ( i = 0 ; i < MAX_ITEM_TYPES && iPW < MAX_WEAPONS ; i++ )
{
if ( m_rgpPlayerItems[ i ] )
{
// there's a weapon here. Should I pack it?
CBasePlayerItem *pPlayerItem = m_rgpPlayerItems[ i ];

while ( pPlayerItem )
while ( pPlayerItem && iPW < MAX_WEAPONS )
{
switch( iWeaponRules )
{
Expand All @@ -739,7 +739,7 @@ void CBasePlayer::PackDeadPlayerItems( void )
}
}

// now go through ammo and make a list of which types to pack.
// now go through ammo and make a list of which types to pack.
if ( iAmmoRules != GR_PLR_DROP_AMMO_NO )
{
for ( i = 0 ; i < MAX_AMMO_SLOTS ; i++ )
Expand Down Expand Up @@ -773,7 +773,7 @@ void CBasePlayer::PackDeadPlayerItems( void )
}
}

// create a box to pack the stuff into.
// create a box to pack the stuff into.
CWeaponBox *pWeaponBox = (CWeaponBox *)CBaseEntity::Create( "weaponbox", pev->origin, pev->angles, edict() );

pWeaponBox->pev->angles.x = 0;// don't let weaponbox tilt.
Expand All @@ -782,18 +782,18 @@ void CBasePlayer::PackDeadPlayerItems( void )
pWeaponBox->SetThink( &CWeaponBox::Kill );
pWeaponBox->pev->nextthink = gpGlobals->time + 120;

// back these two lists up to their first elements
// back these two lists up to their first elements
iPA = 0;
iPW = 0;

// pack the ammo
// pack the ammo
while ( iPackAmmo[ iPA ] != -1 )
{
pWeaponBox->PackAmmo( MAKE_STRING( CBasePlayerItem::AmmoInfoArray[ iPackAmmo[ iPA ] ].pszName ), m_rgAmmo[ iPackAmmo[ iPA ] ] );
iPA++;
}

// now pack all of the items in the lists
// now pack all of the items in the lists
while ( rgpPackWeapons[ iPW ] )
{
// weapon unhooked from the player. Pack it into der box.
Expand Down Expand Up @@ -3660,14 +3660,16 @@ int CBasePlayer::AddPlayerItem( CBasePlayerItem *pItem )



int CBasePlayer::RemovePlayerItem( CBasePlayerItem *pItem )
int CBasePlayer::RemovePlayerItem( CBasePlayerItem *pItem, bool bCallHolster )
{
pItem->pev->nextthink = 0;// crowbar may be trying to swing again, etc.
pItem->SetThink( NULL );

if (m_pActiveItem == pItem)
{
ResetAutoaim( );
pItem->Holster( );
pItem->pev->nextthink = 0;// crowbar may be trying to swing again, etc.
pItem->SetThink( NULL );
if ( bCallHolster )
pItem->Holster( );
m_pActiveItem = NULL;
pev->viewmodel = 0;
pev->weaponmodel = 0;
Expand Down
2 changes: 1 addition & 1 deletion dlls/player.h
Expand Up @@ -248,7 +248,7 @@ class CBasePlayer : public CBaseMonster
void AddPoints( int score, BOOL bAllowNegativeScore );
void AddPointsToTeam( int score, BOOL bAllowNegativeScore );
BOOL AddPlayerItem( CBasePlayerItem *pItem );
BOOL RemovePlayerItem( CBasePlayerItem *pItem );
BOOL RemovePlayerItem( CBasePlayerItem *pItem, bool bCallHoster );
void DropPlayerItem ( char *pszItemName );
BOOL HasPlayerItem( CBasePlayerItem *pCheckItem );
BOOL HasNamedPlayerItem( const char *pszItemName );
Expand Down
54 changes: 23 additions & 31 deletions dlls/satchel.cpp
Expand Up @@ -23,6 +23,12 @@
#include "player.h"
#include "gamerules.h"

enum satchel_state {
SATCHEL_IDLE = 0,
SATCHEL_READY,
SATCHEL_RELOAD,
};

enum satchel_e {
SATCHEL_IDLE1 = 0,
SATCHEL_FIDGET1,
Expand Down Expand Up @@ -194,7 +200,7 @@ int CSatchel::AddDuplicate( CBasePlayerItem *pOriginal )
{
pSatchel = (CSatchel *)pOriginal;

if ( pSatchel->m_chargeReady != 0 )
if ( pSatchel->m_chargeReady != SATCHEL_IDLE )
{
// player has some satchels deployed. Refuse to add more.
return FALSE;
Expand All @@ -211,7 +217,7 @@ int CSatchel::AddToPlayer( CBasePlayer *pPlayer )
int bResult = CBasePlayerItem::AddToPlayer( pPlayer );

pPlayer->pev->weapons |= (1<<m_iId);
m_chargeReady = 0;// this satchel charge weapon now forgets that any satchels are deployed by it.
m_chargeReady = SATCHEL_IDLE; // this satchel charge weapon now forgets that any satchels are deployed by it.

if ( bResult )
{
Expand Down Expand Up @@ -265,19 +271,7 @@ int CSatchel::GetItemInfo(ItemInfo *p)
//=========================================================
BOOL CSatchel::IsUseable( void )
{
if ( m_pPlayer->m_rgAmmo[ PrimaryAmmoIndex() ] > 0 )
{
// player is carrying some satchels
return TRUE;
}

if ( m_chargeReady != 0 )
{
// player isn't carrying any satchels, but has some out
return TRUE;
}

return FALSE;
return CanDeploy();
}

BOOL CSatchel::CanDeploy( void )
Expand All @@ -288,7 +282,7 @@ BOOL CSatchel::CanDeploy( void )
return TRUE;
}

if ( m_chargeReady != 0 )
if ( m_chargeReady != SATCHEL_IDLE )
{
// player isn't carrying any satchels, but has some out
return TRUE;
Expand Down Expand Up @@ -327,11 +321,10 @@ void CSatchel::Holster( int skiplocal /* = 0 */ )
}
EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM);

if ( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] && !m_chargeReady )
if ( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] && m_chargeReady != SATCHEL_READY )
{
m_pPlayer->pev->weapons &= ~(1<<WEAPON_SATCHEL);
SetThink( &CSatchel::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
DestroyItem();
}
}

Expand All @@ -341,12 +334,12 @@ void CSatchel::PrimaryAttack()
{
switch (m_chargeReady)
{
case 0:
case SATCHEL_IDLE:
{
Throw( );
}
break;
case 1:
case SATCHEL_READY:
{
SendWeaponAnim( SATCHEL_RADIO_FIRE );

Expand All @@ -361,19 +354,18 @@ void CSatchel::PrimaryAttack()
if (pSatchel->pev->owner == pPlayer)
{
pSatchel->Use( m_pPlayer, m_pPlayer, USE_ON, 0 );
m_chargeReady = 2;
}
}
}

m_chargeReady = 2;
m_chargeReady = SATCHEL_RELOAD;
m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 0.5;
break;
}

case 2:
case SATCHEL_RELOAD:
// we're reloading, don't allow fire
{
}
Expand All @@ -384,7 +376,7 @@ void CSatchel::PrimaryAttack()

void CSatchel::SecondaryAttack( void )
{
if ( m_chargeReady != 2 )
if ( m_chargeReady != SATCHEL_RELOAD )
{
Throw( );
}
Expand Down Expand Up @@ -415,7 +407,7 @@ void CSatchel::Throw( void )
// player "shoot" animation
m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

m_chargeReady = 1;
m_chargeReady = SATCHEL_READY;

m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--;

Expand All @@ -432,21 +424,21 @@ void CSatchel::WeaponIdle( void )

switch( m_chargeReady )
{
case 0:
case SATCHEL_IDLE:
SendWeaponAnim( SATCHEL_FIDGET1 );
// use tripmine animations
strcpy( m_pPlayer->m_szAnimExtention, "trip" );
break;
case 1:
case SATCHEL_READY:
SendWeaponAnim( SATCHEL_RADIO_FIDGET1 );
// use hivehand animations
strcpy( m_pPlayer->m_szAnimExtention, "hive" );
break;
case 2:
case SATCHEL_RELOAD:
if ( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] )
{
m_chargeReady = 0;
RetireWeapon();
m_chargeReady = SATCHEL_IDLE;
return;
}

Expand All @@ -464,7 +456,7 @@ void CSatchel::WeaponIdle( void )

m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 0.5;
m_chargeReady = 0;
m_chargeReady = SATCHEL_IDLE;
break;
}
m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + UTIL_SharedRandomFloat( m_pPlayer->random_seed, 10, 15 );// how long till we do this again.
Expand Down
3 changes: 1 addition & 2 deletions dlls/squeakgrenade.cpp
Expand Up @@ -483,8 +483,7 @@ void CSqueak::Holster( int skiplocal /* = 0 */ )
if ( !m_pPlayer->m_rgAmmo[ m_iPrimaryAmmoType ] )
{
m_pPlayer->pev->weapons &= ~(1<<WEAPON_SNARK);
SetThink( &CSqueak::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
DestroyItem();
return;
}

Expand Down
3 changes: 1 addition & 2 deletions dlls/tripmine.cpp
Expand Up @@ -420,8 +420,7 @@ void CTripmine::Holster( int skiplocal /* = 0 */ )
{
// out of mines
m_pPlayer->pev->weapons &= ~(1<<WEAPON_TRIPMINE);
SetThink( &CTripmine::DestroyItem );
pev->nextthink = gpGlobals->time + 0.1;
DestroyItem();
}

SendWeaponAnim( TRIPMINE_HOLSTER );
Expand Down
18 changes: 14 additions & 4 deletions dlls/weapons.cpp
Expand Up @@ -721,8 +721,8 @@ void CBasePlayerItem::DestroyItem( void )
{
if ( m_pPlayer )
{
// if attached to a player, remove.
m_pPlayer->RemovePlayerItem( this );
// if attached to a player, remove.
m_pPlayer->RemovePlayerItem( this, false );
}

Kill( );
Expand Down Expand Up @@ -1181,7 +1181,17 @@ void CBasePlayerWeapon::RetireWeapon( void )
m_pPlayer->pev->weaponmodel = iStringNull;
//m_pPlayer->pev->viewmodelindex = NULL;

g_pGameRules->GetNextBestWeapon( m_pPlayer, this );
if (!g_pGameRules->GetNextBestWeapon( m_pPlayer, this ))
{
// Another weapon wasn't selected. Get rid of current one
if (m_pPlayer->m_pActiveItem == this)
{
m_pPlayer->ResetAutoaim();
m_pPlayer->m_pActiveItem->Holster();
m_pPlayer->m_pLastItem = NULL;
m_pPlayer->m_pActiveItem = NULL;
}
}
}

//*********************************************************
Expand Down Expand Up @@ -1351,7 +1361,7 @@ BOOL CWeaponBox::PackWeapon( CBasePlayerItem *pWeapon )

if ( pWeapon->m_pPlayer )
{
if ( !pWeapon->m_pPlayer->RemovePlayerItem( pWeapon ) )
if ( !pWeapon->m_pPlayer->RemovePlayerItem( pWeapon, true ) )
{
// failed to unhook the weapon from the player!
return FALSE;
Expand Down

0 comments on commit 68c9b7c

Please sign in to comment.