//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponShieldGrenade::PrimaryAttack( void )
{
	CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
	if ( !pPlayer )
		return;

	if ( !ComputeEMPFireState() )
		return;

	if ( !GetPrimaryAmmo() )
		return;

	// player "shoot" animation
	PlayAttackAnimation( ACT_VM_THROW );

	ThrowGrenade();

	// Setup for refire
	m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
	CheckRemoveDisguise();

	// If I'm now out of ammo, switch away
	if ( !HasPrimaryAmmo() )
	{
		g_pGameRules->GetNextBestWeapon( pPlayer, NULL );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pEvent - 
//			*pOperator - 
//-----------------------------------------------------------------------------
void CWeaponFrag::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	switch( pEvent->event )
	{
		case EVENT_WEAPON_THROW:
			ThrowGrenade( pOwner );
			DecrementAmmo( pOwner );
			break;

		case EVENT_WEAPON_THROW2:
			RollGrenade( pOwner );
			DecrementAmmo( pOwner );
			break;

		case EVENT_WEAPON_THROW3:
			LobGrenade( pOwner );
			DecrementAmmo( pOwner );
			break;

		default:
			BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
			break;
	}
}
Example #3
0
//=========================================================
// HandleAnimEvent - catches the monster-specific messages
// that occur when tagged animation frames are played.
//=========================================================
void COgre :: HandleAnimEvent( MonsterEvent_t *pEvent )
{
	switch( pEvent->event )
	{
	case OGRE_DROP_BACKPACK:
		ammo_rockets = 2;
		CWeaponBox::DropBackpack( this, 0 );
		break;
	case OGRE_IDLE_SOUND:
		if( RANDOM_FLOAT( 0.0f, 1.0f ) < 0.1f )
			EMIT_SOUND( edict(), CHAN_VOICE, "ogre/ogidle.wav", 1.0, ATTN_IDLE );
		break;
	case OGRE_IDLE_SOUND2:
		if( RANDOM_FLOAT( 0.0f, 1.0f ) < 0.1f )
			EMIT_SOUND( edict(), CHAN_VOICE, "ogre/ogidle2.wav", 1.0, ATTN_IDLE );
		break;
	case OGRE_DRAG_SOUND:
		if( RANDOM_FLOAT( 0.0f, 1.0f ) < 0.05f )
			EMIT_SOUND( edict(), CHAN_VOICE, "ogre/ogdrag.wav", 1.0, ATTN_IDLE );
		break;
	case OGRE_SHOOT_GRENADE:
		ThrowGrenade ();
		break;
	case OGRE_CHAINSAW:
		ChainSaw( atof( pEvent->options ));
		break;
	case OGRE_CHAINSAW_SOUND:
		EMIT_SOUND( edict(), CHAN_WEAPON, "ogre/ogsawatk.wav", 1.0, ATTN_NORM );
		break;
	default:
		CQuakeMonster::HandleAnimEvent( pEvent );
		break;
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pEvent - 
//			*pOperator - 
//-----------------------------------------------------------------------------
void CWeaponFrag::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	bool fThrewGrenade = false;

	switch( pEvent->event )
	{
		case EVENT_WEAPON_SEQUENCE_FINISHED:
			m_fDrawbackFinished = true;
			break;

		case EVENT_WEAPON_THROW:
			ThrowGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		case EVENT_WEAPON_THROW2:
			RollGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		case EVENT_WEAPON_THROW3:
			LobGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		default:
			BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
			break;
	}

#define RETHROW_DELAY	0.5
	if( fThrewGrenade )
	{
		m_flNextPrimaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flNextSecondaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flTimeWeaponIdle = FLT_MAX; //NOTE: This is set once the animation has finished up!
#ifdef SecobMod__Enable_Fixed_Multiplayer_AI		
		// Make a sound designed to scare snipers back into their holes!
		CBaseCombatCharacter *pOwner = GetOwner();

		if( pOwner )
		{
			Vector vecSrc = pOwner->Weapon_ShootPosition();
			Vector	vecDir;

			AngleVectors( pOwner->EyeAngles(), &vecDir );

			trace_t tr;

			UTIL_TraceLine( vecSrc, vecSrc + vecDir * 1024, MASK_SOLID_BRUSHONLY, pOwner, COLLISION_GROUP_NONE, &tr );

			CSoundEnt::InsertSound( SOUND_DANGER_SNIPERONLY, tr.endpos, 384, 0.2, pOwner );
		}
#endif //SecobMod__Enable_Fixed_Multiplayer_AI
	}
}
void CGEWeaponGrenade::PreOwnerDeath()
{
	// Throw the grenade if the player was about to before they died.
	if (m_bSpawnWait || m_bPreThrow)
		ThrowGrenade(GE_GRENADE_THROW_FORCE/5);

	BaseClass::PreOwnerDeath();
}
Example #6
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseSDKGrenade::ItemPostFrame()
{
	CSDKPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
	if ( !vm )
		return;

	// If they let go of the fire button, they want to throw the grenade.
	if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) 
	{
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
//		if (m_bSecondary)
//			DropGrenade();
//		else
			ThrowGrenade();
		
		DecrementAmmo( pPlayer );
	
		m_bPinPulled = false;
		SendWeaponAnim( ACT_VM_THROW );	
		SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() );

		m_bPinPulled = false;
//		m_bSecondary = false;
	}
	else if( m_bRedraw )
	{
		// Has the throw animation finished playing
		if( m_flTimeWeaponIdle < gpGlobals->curtime )
		{
			// if we're officially out of grenades, ditch this weapon
			if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
#ifdef GAME_DLL
				pPlayer->Weapon_Drop( this, NULL, NULL );
				UTIL_Remove(this);
#endif
				pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs!
			}
			else
			{
				m_bRedraw = false;
				m_flNextPrimaryAttack = gpGlobals->curtime + 1.2;
				m_flNextSecondaryAttack = gpGlobals->curtime + 1.2;
				SendWeaponAnim( GetDeployActivity() );			
			}
			return;	//don't animate this grenade any more!
		}	
	}
	else if( !m_bRedraw )
	{
		BaseClass::ItemPostFrame();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseSDKGrenade::ItemPostFrame()
{
	CSDKPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
	if ( !vm )
		return;

	// If they let go of the fire button, they want to throw the grenade.
	if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) 
	{
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_THROW_GRENADE );

		StartGrenadeThrow();
		
		DecrementAmmo( pPlayer );
	
		m_bPinPulled = false;
		SendWeaponAnim( ACT_VM_THROW );	
		SetWeaponIdleTime( gpGlobals->curtime + SequenceDuration() );
	}
	else if ((m_fThrowTime > 0) && (m_fThrowTime < gpGlobals->curtime))
	{
		ThrowGrenade();
	}
	else if( m_bRedraw )
	{
		// Has the throw animation finished playing
		if( m_flTimeWeaponIdle < gpGlobals->curtime )
		{
#ifdef GAME_DLL
			// if we're officially out of grenades, ditch this weapon
			if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
				pPlayer->Weapon_Drop( this, NULL, NULL );
				UTIL_Remove(this);
			}
			else
			{
				pPlayer->SwitchToNextBestWeapon( this );
			}
#endif
			return;	//don't animate this grenade any more!
		}	
	}
	else if( !m_bRedraw )
	{
		BaseClass::ItemPostFrame();
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pEvent - 
//			*pOperator - 
//-----------------------------------------------------------------------------
void CWeaponBugBait::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	switch( pEvent->event )
	{
		case EVENT_WEAPON_SEQUENCE_FINISHED:
			m_bDrawBackFinished = true;
			break;

		case EVENT_WEAPON_THROW:
			ThrowGrenade( pOwner );
			break;

		default:
			BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
			break;
	}
}
//-----------------------------------------------------------------------------
// Purpose: Checks to see two things...
//			1. Did the player release the throw button (if so throw a grenade!)
//			2. Did the grenade's fuse run out? (if so explode!)
//-----------------------------------------------------------------------------
void CGEWeaponGrenade::ItemPostFrame( void )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

	if( m_bPreThrow )
	{
		// Wait until we are fully drawn back before releasing
		if ( pOwner && m_flNextReleaseTime < gpGlobals->curtime )
		{
			// The player released the attack button, initiate the throwing
			if( !(pOwner->m_nButtons & IN_ATTACK) )
			{
				// Since we are going to be showing the grenade being thrown we 
				// have to wait for the anim to play to that point
				SendWeaponAnim( ACT_VM_GRENADE_THROW1 );
				m_flGrenadeSpawnTime = gpGlobals->curtime + GE_GRENADE_SPAWN_DELAY;
				m_bSpawnWait = true;
				m_bPreThrow = false;
			}
			else if ( gpGlobals->curtime > m_flPrimedTime + GE_GRENADE_FUSE_TIME )
			{
				ExplodeInHand();
				m_bSpawnWait = false;
				m_bPreThrow = false;
			}
		}
	}
	else if ( m_bSpawnWait )
	{
		if ( m_flGrenadeSpawnTime < gpGlobals->curtime )
		{
			ThrowGrenade(GE_GRENADE_THROW_FORCE);

			// player "shoot" animation
			pOwner->SetAnimation( PLAYER_ATTACK1 );
			ToGEPlayer(pOwner)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );

			m_bSpawnWait = false;
		}
	}

	BaseClass::ItemPostFrame();
}
Example #10
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : *pEvent - 
//			*pOperator - 
//-----------------------------------------------------------------------------
void CWeaponFrag::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )
{
	CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
	bool fThrewGrenade = false;

	switch( pEvent->event )
	{
		case EVENT_WEAPON_SEQUENCE_FINISHED:
			m_fDrawbackFinished = true;
			break;

		case EVENT_WEAPON_THROW:
			ThrowGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		case EVENT_WEAPON_THROW2:
			RollGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		case EVENT_WEAPON_THROW3:
			LobGrenade( pOwner );
			DecrementAmmo( pOwner );
			fThrewGrenade = true;
			break;

		default:
			BaseClass::Operator_HandleAnimEvent( pEvent, pOperator );
			break;
	}

#define RETHROW_DELAY	0.5
	if( fThrewGrenade )
	{
		m_flNextPrimaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flNextSecondaryAttack	= gpGlobals->curtime + RETHROW_DELAY;
		m_flTimeWeaponIdle = FLT_MAX; //NOTE: This is set once the animation has finished up!
	}
}
void CWeaponGrenade::PrimaryAttackThrow( void ) {
    CBaseCombatCharacter *pOwner  = GetOwner();
    if ( pOwner == NULL )
        return;

    CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );;
    if ( !pPlayer )
        return;

    SendWeaponAnim( ACT_VM_THROW );
    m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration();

    ThrowGrenade(pPlayer);
    DecrementAmmo(pOwner);

    m_bAttackPaused = false;

    if(!HasPrimaryAmmo())
        pPlayer->SwitchToNextBestWeapon( this );
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponHarpoon::PrimaryAttack( void )
{
	CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>( GetOwner() );
	if ( !pPlayer )
		return;

	if ( !ComputeEMPFireState() )
		return;

	ThrowGrenade();

	// Setup for refire
	m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
	CheckRemoveDisguise();

	// If I'm now out of ammo, switch away
	if ( !HasPrimaryAmmo() )
	{
		pPlayer->SelectLastItem();
	}
}
Example #13
0
		void Player::Update(float dt) {
			SPADES_MARK_FUNCTION();
			auto* listener = world->GetListener();
			
			MovePlayer(dt);
			
			if(!IsAlive()) {
				// do death cleanup
				blockCursorDragging = false;
			}
			
			if(tool == ToolSpade){
				if(weapInput.primary){
					if(world->GetTime() > nextSpadeTime){
						UseSpade();
						nextSpadeTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else if(weapInput.secondary){
					if(world->GetTime() > nextDigTime){
						DigWithSpade();
						nextDigTime = world->GetTime() + GetToolSecondaryDelay();
						firstDig = false;
					}
				}
			}else if(tool == ToolBlock && IsLocalPlayer()){
				GameMap::RayCastResult result;
				auto *map = GetWorld()->GetMap();
				result = map->CastRay2(GetEye(), GetFront(), 12);
				canPending = false;
				
				if(blockCursorDragging) {
					// check the starting point is not floating
					auto start = blockCursorDragPos;
					if(map->IsSolidWrapped(start.x-1, start.y, start.z) ||
					   map->IsSolidWrapped(start.x, start.y-1, start.z) ||
					   map->IsSolidWrapped(start.x, start.y, start.z-1) ||
					   map->IsSolidWrapped(start.x+1, start.y, start.z) ||
					   map->IsSolidWrapped(start.x, start.y+1, start.z) ||
					   map->IsSolidWrapped(start.x, start.y, start.z+1)) {
						// still okay
					}else{
						// cannot build; floating
						if(listener &&
						   this == world->GetLocalPlayer()) {
							listener->
							LocalPlayerBuildError(BuildFailureReason::InvalidPosition);
						}
						blockCursorDragging = false;
					}
				}
				
				if(result.hit &&
				   (result.hitBlock + result.normal).z < 62 &&
				   (!OverlapsWithOneBlock(result.hitBlock + result.normal)) &&
				   BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f &&
				   !pendingPlaceBlock){
					
					// Building is possible, and there's no delayed block placement.
					blockCursorActive = true;
					blockCursorPos = result.hitBlock + result.normal;
					
				}else if(pendingPlaceBlock){
					
					// Delayed Block Placement: When player attempts to place a block while jumping and
					// placing block is currently impossible, building will be delayed until it becomes
					// possible, as long as player is airborne.
					if(airborne == false || blockStocks <= 0){
						// player is no longer airborne, or doesn't have a block to place.
						pendingPlaceBlock = false;
						lastSingleBlockBuildSeqDone = true;
						if(blockStocks > 0) {
							// cannot build; invalid position.
						}
					}else if((!OverlapsWithOneBlock(pendingPlaceBlockPos)) &&
							 BoxDistanceToBlock(pendingPlaceBlockPos) < 3.f){
						// now building became possible.
						SPAssert(this == world->GetLocalPlayer());
						
						if(GetWorld()->GetListener())
							GetWorld()->GetListener()->LocalPlayerBlockAction(pendingPlaceBlockPos, BlockActionCreate);
						
						pendingPlaceBlock = false;
						lastSingleBlockBuildSeqDone = true;
						// blockStocks--; decrease when created
						
						nextBlockTime = world->GetTime() + GetToolPrimaryDelay();
					}
					
				}else{
					// Delayed Block Placement can be activated only when the only reason making placement
					// impossible is that block to be placed overlaps with the player's hitbox.
					canPending = result.hit &&
								 (result.hitBlock + result.normal).z < 62 &&
								 BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f;
					
					blockCursorActive = false;
					int dist = 11;
					for(; dist >= 1 &&
						BoxDistanceToBlock(result.hitBlock + result.normal) > 3.f ; dist--) {
						result = GetWorld()->GetMap()->CastRay2(GetEye(),
																GetFront(),
																dist);
					}
					for(; dist < 12 &&
						BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f ; dist++) {
						result = GetWorld()->GetMap()->CastRay2(GetEye(),
																GetFront(),
																dist);
					}
					
					blockCursorPos = result.hitBlock + result.normal;
				}
				
			}else if(tool == ToolWeapon){
			}else if(tool == ToolGrenade){
				if(holdingGrenade){
					if(world->GetTime() - grenadeTime > 2.9f){
						ThrowGrenade();
					}
				}
			}
		
			if(tool != ToolWeapon)
				weapon->SetShooting(false);
			if(weapon->FrameNext(dt)){
				FireWeapon();
			}
			
			if(weapon->IsReloading()) {
				lastReloadingTime = world->GetTime();
			}else if(reloadingServerSide) {
				// for some reason a server didn't return
				// WeaponReload packet.
				if(world->GetTime() + lastReloadingTime + .8f) {
					reloadingServerSide = false;
					weapon->ForceReloadDone();
				}
			}
		}
Example #14
0
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CWeaponFrag::ItemPostFrame( void )
{
    if( m_fDrawbackFinished )
    {
        CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

        if (pOwner)
        {
            switch( m_AttackPaused )
            {
            case GRENADE_PAUSED_PRIMARY:
                if( !(pOwner->m_nButtons & IN_ATTACK) )
                {
                    SendWeaponAnim( ACT_VM_THROW );
                    ToHL2MPPlayer(pOwner)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );

                    //Tony; fire the sequence
                    m_fDrawbackFinished = false;
                }
                //We are still holding attack...
                else
                {
                    if ( flExplodeTime <= gpGlobals->curtime )
                    {
                        //DHL: Skip the animations and go boom immediately if we've been holding it too long
                        ThrowGrenade( pOwner, true ); //Make it invisible as to maintain the illusion of going off in the player's hand
                        DecrementAmmo( pOwner );

                        //Make absolutely certain that if the grenade goes off in a player's hand, they die.
#ifndef CLIENT_DLL
                        CTakeDamageInfo GrenadeInfo( this, pOwner, 100.0f, DMG_BURN, 0 );
                        pOwner->TakeDamage( GrenadeInfo );
#endif

                    }
                }
                break;

            case GRENADE_PAUSED_SECONDARY:
                if( !(pOwner->m_nButtons & IN_ATTACK2) )
                {
                    //See if we're ducking
                    if ( pOwner->m_nButtons & IN_DUCK )
                    {
                        //Send the weapon animation
                        SendWeaponAnim( ACT_VM_SECONDARYATTACK );
                    }
                    else
                    {
                        //Send the weapon animation
                        SendWeaponAnim( ACT_VM_HAULBACK );
                    }
                    //Tony; the grenade really should have a secondary anim. but it doesn't on the player.
                    ToHL2MPPlayer(pOwner)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );

                    m_fDrawbackFinished = false;
                }
                break;

            default:
                break;
            }
        }
    }

    BaseClass::ItemPostFrame();

    if ( m_bRedraw )
    {
        if ( IsViewModelSequenceFinished() )
        {
            Reload();
        }
    }
}
//------------------------------------------------------------------------
void CThrow::Update(float frameTime, uint32 frameId)
{
	CSingle::Update(frameTime, frameId);

	if (m_firing)
	{
		if (!m_pulling && !m_throwing && !m_thrown)
		{
			if(m_hold_timer > 0.0f)
			{
				m_hold_timer -= frameTime;

				if (m_hold_timer < 0.0f)
				{
					m_hold_timer = 0.0f;
				}
			}
		}
		else if (m_throwing && m_throw_time <= 0.0f)
		{
			CActor *pOwner = m_pWeapon->GetOwnerActor();
			m_pWeapon->HideItem(true);

			if (m_throwableId)
			{
				IEntity *pEntity = gEnv->pEntitySystem->GetEntity(m_throwableId);

				if (pEntity)
				{
					if (m_throwableAction)
					{
						m_throwableAction->execute(m_pWeapon);
					}

					IPhysicalEntity *pPE = pEntity->GetPhysics();

					if (pPE && (pPE->GetType() == PE_RIGID || pPE->GetType() == PE_PARTICLE))
					{
						ThrowObject(pEntity, pPE);
					}
					else if (pPE && (pPE->GetType() == PE_LIVING || pPE->GetType() == PE_ARTICULATED))
					{
						ThrowLivingEntity(pEntity, pPE);
					}
				}
			}
			else if (!m_netfiring)
			{
				ThrowGrenade();
			}

			m_throwing = false;
		}
		else if (m_thrown && m_throw_time <= 0.0f)
		{
			m_pWeapon->SetBusy(false);
			m_pWeapon->HideItem(false);
			int ammoCount = m_pWeapon->GetAmmoCount(m_pShared->fireparams.ammo_type_class);

			if (ammoCount > 0)
			{
				m_pWeapon->PlayAction(m_pShared->throwactions.next);
			}
			else if (m_pShared->throwparams.auto_select_last)
			{
				static_cast<CPlayer *>(m_pWeapon->GetOwnerActor())->SelectLastItem(true);
			}

			m_firing = false;
			m_throwing = false;
			m_thrown = false;
		}

		m_throw_time -= frameTime;

		if (m_throw_time < 0.0f)
		{
			m_throw_time = 0.0f;
		}

		m_pWeapon->RequireUpdate(eIUS_FireMode);
	}
}
Example #16
0
		void Player::Update(float dt) {
			SPADES_MARK_FUNCTION();
			
			MovePlayer(dt);
			if(tool == ToolSpade){
				if(weapInput.primary){
					if(world->GetTime() > nextSpadeTime){
						UseSpade();
						nextSpadeTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else if(weapInput.secondary){
					if(world->GetTime() > nextDigTime){
						DigWithSpade();
						nextDigTime = world->GetTime() + GetToolSecondaryDelay();
						firstDig = false;
					}
				}
			}else if(tool == ToolBlock){
				GameMap::RayCastResult result;
				result = GetWorld()->GetMap()->CastRay2(GetEye(),
														GetFront(),
														12);
				canPending = false;
				if(result.hit && (result.hitBlock + result.normal).z < 62 &&
				   (!OverlapsWithOneBlock(result.hitBlock + result.normal)) &&
				   BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f &&
				   !pendingPlaceBlock){
					blockCursorActive = true;
					blockCursorPos = result.hitBlock + result.normal;
				}else if(pendingPlaceBlock){
					if(airborne == false || blockStocks <= 0){
						pendingPlaceBlock = false;
					}else if((!OverlapsWithOneBlock(pendingPlaceBlockPos)) &&
							 BoxDistanceToBlock(pendingPlaceBlockPos) < 3.f){
						SPAssert(this == world->GetLocalPlayer());
						
						if(GetWorld()->GetListener())
							GetWorld()->GetListener()->LocalPlayerBlockAction(pendingPlaceBlockPos, BlockActionCreate);
						
						pendingPlaceBlock = false;
						// blockStocks--; decrease when created
						
						nextBlockTime = world->GetTime() + GetToolPrimaryDelay();
					}
				}else{
					canPending = result.hit && (result.hitBlock + result.normal).z < 62 &&
					BoxDistanceToBlock(result.hitBlock + result.normal) < 3.f;
					blockCursorActive = false;
					blockCursorPos = result.hitBlock + result.normal;
				}
			}else if(tool == ToolWeapon){
			}else if(tool == ToolGrenade){
				if(holdingGrenade){
					if(world->GetTime() - grenadeTime > 2.9f){
						ThrowGrenade();
					}
				}
			}
		
			if(tool != ToolWeapon)
				weapon->SetShooting(false);
			if(weapon->FrameNext(dt)){
				FireWeapon();
			}
			
			if(weapon->IsReloading()) {
				lastReloadingTime = world->GetTime();
			}else if(reloadingServerSide) {
				// for some reason a server didn't return
				// WeaponReload packet.
				if(world->GetTime() + lastReloadingTime + .8f) {
					reloadingServerSide = false;
					weapon->ForceReloadDone();
				}
			}
		}
Example #17
0
void Protagonist::Update( HGE*engine, float ftime )    
{ 
	MainAnimation->Update( ftime );

	if( Player::IsDead() ) return;
	
	if( eCURRENTSTANCE != JUMPING  && eCURRENTSTANCE != DEAD )
	if(engine->Input_GetKeyState(HGEK_ALT) )
	{
		if( ThrowGrenade() )
		{ 
			ChangeStance( THROW_GRENADE);	
		}
	}
	else
	if (engine->Input_GetKeyState(HGEK_SHIFT) )
	{
		ChangeStance( MELEE );
	}
 	else
	if( ( engine->Input_KeyUp(HGEK_DOWN) ) && eCURRENTSTANCE == DUCK /* && eCURRENTSTANCE != THROW_GRENADE */)
	{
			ChangeStance( DUCK );
			MainAnimation->SetMode(HGEANIM_REV);
			Play(); 
	
	}
	else
	if( ( engine->Input_KeyUp(HGEK_UP) )  && eCURRENTSTANCE == LOOKUP && eCURRENTSTANCE != THROW_GRENADE )
	{
		ChangeStance( LOOKUP );
		MainAnimation->SetMode(HGEANIM_REV);
		Play();
	}
	else     ///////////////////////
		if ( !MainAnimation->IsPlaying()  || eCURRENTSTANCE == RUNNING || eCURRENTSTANCE == LOWMOVE || eCURRENTSTANCE == MOVE_BACK )
	    {	
		if ( engine->Input_KeyUp(HGEK_DOWN) /*&& eCURRENTSTANCE != LOOKUP*/ )
		{
			ChangeStance( DUCK );
			MainAnimation->SetMode(HGEANIM_REV);
			Play();
		}
		else
		if (engine->Input_GetKeyState(HGEK_UP) )
		{
			ChangeStance( LOOKUP );	
		}
		else
		if (engine->Input_GetKeyState(HGEK_DOWN) )
		{
				if( engine->Input_GetKeyState(HGEK_RIGHT)  ) // Stealth Move Right
				{
					if( eCURRENTSTANCE == LOWMOVE && !MainAnimation->IsPlaying() ) eCURRENTSTANCE = IDLE;
					ChangeStance( LOWMOVE ); 
					SetFacing( FACERIGHT,false );
					vDirection.x = +1;
				}
				else 
				if( engine->Input_GetKeyState(HGEK_LEFT)  )  // Stealth Move Left
				{
					if( eCURRENTSTANCE == LOWMOVE && !MainAnimation->IsPlaying() ) eCURRENTSTANCE = IDLE;
					ChangeStance( LOWMOVE );
					SetFacing( FACELEFT,true );
					vDirection.x = -1;
				}
				else if(eCURRENTSTANCE == LOWMOVE)   // Stealth Move
				{ 
					ChangeStance( DUCK );  MainAnimation->SetFrame(1);  
				}
 				else
				{ 
					ChangeStance( DUCK ); 
					vDirection.x = ( eFACING == FACERIGHT ) ? 1 : -1;
				}
		}
		else
		if (engine->Input_GetKeyState(HGEK_LEFT) )     // move left
		{
			if ( engine->Input_GetKeyState( HGEK_CTRL ) && eFACING == FACERIGHT )
			{
				if(eCURRENTSTANCE == MOVE_BACK && !MainAnimation->IsPlaying() ) ChangeStance(IDLE);
				ChangeStance(MOVE_BACK);		
				vDirection.x = -1;
			}
			else
			{
				if(eCURRENTSTANCE==RUNNING && !MainAnimation->IsPlaying()) eCURRENTSTANCE = IDLE;
				SetFacing( FACELEFT,true );
				ChangeStance( RUNNING ); 
				vDirection.x = -1;
			}
		}
		else
		if (engine->Input_GetKeyState(HGEK_RIGHT) )  // move right
		{
			if ( engine->Input_GetKeyState( HGEK_CTRL ) && eFACING == FACELEFT )
			{
				if(eCURRENTSTANCE == MOVE_BACK && !MainAnimation->IsPlaying() ) ChangeStance(IDLE);
				ChangeStance(MOVE_BACK);		vDirection.x = 1;
			}
			else
			{
				if(eCURRENTSTANCE==RUNNING && !MainAnimation->IsPlaying()) eCURRENTSTANCE = IDLE;
				SetFacing( FACERIGHT,false );
				ChangeStance( RUNNING );	
				vDirection.x = +1;
			}
		}
		else
		{
			ChangeStance( IDLE );
		}

	}
		/*
		if( eCURRENTSTANCE == MOVE_BACK )
		vDirection.x = ( eFACING == FACERIGHT ) ? -1 :  1;
		else
		vDirection.x = ( eFACING == FACERIGHT ) ?  1 : -1;
		*/
}	
void CGEWeaponGrenade::FireNPCPrimaryAttack( CBaseCombatCharacter *pOperator, bool bUseWeaponAngles )
{
	m_flPrimedTime = gpGlobals->curtime;
	ThrowGrenade(GE_GRENADE_THROW_FORCE);
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseSDKGrenade::ItemPostFrame()
{
	CSDKPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	CBaseViewModel *vm = pPlayer->GetViewModel( m_nViewModelIndex );
	if ( !vm )
		return;

	// If they let go of the fire button, they want to throw the grenade.
	if ( m_bPinPulled && !(pPlayer->m_nButtons & IN_ATTACK) ) 
	{
		pPlayer->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );
//		if (m_bSecondary)
//			DropGrenade();
//		else
			ThrowGrenade();

		if (!pPlayer->IsStyleSkillActive(SKILL_TROLL))
			DecrementAmmo( pPlayer );

		m_bPinPulled = false;
		SendWeaponAnim( ACT_VM_THROW );	
		SetWeaponIdleTime( GetCurrentTime() + SequenceDuration() );

		m_bPinPulled = false;
//		m_bSecondary = false;
	}
	else if( m_bRedraw )
	{
		// Has the throw animation finished playing
		if( m_flTimeWeaponIdle < GetCurrentTime() )
		{
			// if we're officially out of grenades, ditch this weapon
			if( pPlayer->GetAmmoCount(m_iPrimaryAmmoType) <= 0 )
			{
#ifdef GAME_DLL
				pPlayer->Weapon_Drop( this, NULL, NULL );
				UTIL_Remove(this);
#endif
				pPlayer->SwitchToNextBestWeapon( NULL ); //Tony; now switch! cuz we rans outs!
			}
			else if (pPlayer->IsStyleSkillActive(SKILL_TROLL))
			{
				m_bRedraw = false;
				m_flNextPrimaryAttack = GetCurrentTime() + 1.2;
				m_flNextSecondaryAttack = GetCurrentTime() + 1.2;
				SendWeaponAnim( GetDeployActivity() );	
			}
			else
			{
				m_bRedraw = false;

				// Only switch to the next best weapon if the next best weapon is not brawl.
				CBaseCombatWeapon *pNewWeapon = g_pGameRules->GetNextBestWeapon(pPlayer, this);
				CWeaponSDKBase* pSDKNewWeapon = dynamic_cast<CWeaponSDKBase*>(pNewWeapon);

				bool bSwitch = true;

				if (!pSDKNewWeapon)
					bSwitch = false;

				// If I'm going to switch to brawl but I have more grenades, don't switch.
				else if (pSDKNewWeapon && pSDKNewWeapon->GetWeaponID() == SDK_WEAPON_BRAWL && pPlayer->GetAmmoCount(m_iPrimaryAmmoType) > 0)
					bSwitch = false;

				if (bSwitch)
					pPlayer->SwitchToNextBestWeapon( this );
			}
			return;	//don't animate this grenade any more!
		}	
	}
	else if( !m_bRedraw )
	{
		BaseClass::ItemPostFrame();
	}
}