コード例 #1
0
ファイル: weapon_combatknife.cpp プロジェクト: dreckard/dhl2
void CWeaponCombatKnife::SecondaryAttack( void )
{
	CBasePlayer* pOwner = ToBasePlayer( GetOwner() );
	Assert( pOwner );

	//Can't throw last knife
	if ( pOwner->GetAmmoCount(GetPrimaryAmmoType()) <= 0 )
	{
		m_flNextSecondaryAttack = gpGlobals->curtime + 0.1f;
		return;
	}

	#ifndef CLIENT_DLL
		CDHLProjectile* pKnife = (CDHLProjectile*)(CreateEntityByName( "dhl_projectile" ));
		Assert( pKnife );
		pKnife->SetOwnerEntity( pOwner );
		pKnife->Spawn();

		//This is just an easy way of getting an eye vector, there isn't really any autoaim in MP
		Vector vecDir = pOwner->GetAutoaimVector( AUTOAIM_SCALE_DEFAULT );
		//HACK - move it forward so it doesn't appear to spawn inside the player's face
		Vector vecSrc = pOwner->Weapon_ShootPosition() + ( vecDir * 6.0f );

		pKnife->Fire( vecSrc, vecDir * 1232.0f /*70mph*/, GetHL2MPWpnData().m_iPlayerDamage, this, pOwner, -1 );
		
		if ( dhl_flamingknives.GetBool() )
			pKnife->Ignite( 30.0f, false );
		
	#endif

		//Make sure this is done after the call to Fire()
		int iAmmo = pOwner->GetAmmoCount(GetPrimaryAmmoType());
		pOwner->RemoveAmmo( 1, GetPrimaryAmmoType() );
		if ( iAmmo <= 0 )
		{
			AddEffects( EF_NODRAW );
			#ifndef CLIENT_DLL
				pOwner->Weapon_Drop( this, NULL, NULL );
				Remove();
			#endif
		}
		else
		{
			SendWeaponAnim( ACT_VM_THROW ); //Need to be able to predict this

			pOwner->SetAnimation( PLAYER_ATTACK1 ); //Use the primary attack anim for now
			ToHL2MPPlayer(pOwner)->DoAnimationEvent( PLAYERANIMEVENT_ATTACK_PRIMARY );

			m_flNextSecondaryAttack = gpGlobals->curtime + GetFireRate();
		}

		/*IPhysicsObject* pPhysObj = VPhysicsGetObject();
		if ( pPhysObj )
		{
			pPhysObj->Sleep();
			pPhysObj->EnableMotion( false );
			pPhysObj->EnableCollisions( false );
		}
		m_bAllowPickup = false;*/
}
コード例 #2
0
ファイル: weapon_shotgun.cpp プロジェクト: NEITMod/HL2BM2
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWeaponShotgun::ItemHolsterFrame( void )
{
	// Must be player held
	if ( GetOwner() && GetOwner()->IsPlayer() == false )
		return;

	// We can't be active
	if ( GetOwner()->GetActiveWeapon() == this )
		return;

	// If it's been longer than three seconds, reload
	if ( ( gpGlobals->curtime - m_flHolsterTime ) > sk_auto_reload_time.GetFloat() )
	{
		// Reset the timer
		m_flHolsterTime = gpGlobals->curtime;
	
		if ( GetOwner() == NULL )
			return;

		if ( m_iClip1 == GetMaxClip1() )
			return;

		// Just load the clip with no animations
		int ammoFill = MIN( (GetMaxClip1() - m_iClip1), GetOwner()->GetAmmoCount( GetPrimaryAmmoType() ) );
		
		GetOwner()->RemoveAmmo( ammoFill, GetPrimaryAmmoType() );
		m_iClip1 += ammoFill;
	}
}
コード例 #3
0
bool CDODBaseRocketWeapon::Reload( void )
{
	CDODPlayer *pPlayer = GetDODPlayerOwner();

	if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
	{
		CDODPlayer *pDODPlayer = ToDODPlayer( pPlayer );
		pDODPlayer->HintMessage( HINT_AMMO_EXHAUSTED );
		return false;
	}

	Activity actReload;

	if( IsDeployed() )
		actReload = ACT_VM_RELOAD_DEPLOYED;
	else
		actReload = ACT_VM_RELOAD;

	int iResult = DefaultReload( GetMaxClip1(), GetMaxClip2(), actReload );
	if ( !iResult )
		return false;

	pPlayer->SetAnimation( PLAYER_RELOAD );

	// if we don't want the auto-rezoom, undeploy here
	if ( !pPlayer->ShouldAutoRezoom() )
	{
		m_bDeployed = false;
		pPlayer->SetBazookaDeployed( m_bDeployed );
	}

	return true;
}
コード例 #4
0
bool CCombatWeapon::MyTouch( CPlayer *pPlayer )
{
	if ( !pPlayer->IsAllowedToPickupWeapons() )
		return false;

	if(pPlayer->HaveThisWeaponType(this))
	{
		// give sound
		int nCount = GetMaxClip1();
		if(nCount == -1)
			nCount = 1;
		bool ret = pPlayer->GiveAmmo(nCount, GetPrimaryAmmoType());
		if(ret)
		{
			CPASAttenuationFilter filter( pPlayer, "BaseCombatCharacter.AmmoPickup" );
			EmitSound( filter, pPlayer->entindex(), "BaseCombatCharacter.AmmoPickup" );
		}
		return ret;
	}

	CCombatWeapon *pWeapon = (CCombatWeapon *)CEntity::Instance(pPlayer->Weapon_GetSlot(GetSlot()));
	if(pWeapon)
		return false;

	//give sound
	pWeapon = (CCombatWeapon *)CEntity::Instance(pPlayer->GiveNamedItem(GetClassname()));
	if(pWeapon)
	{
		pWeapon->m_bRemoveOnDrop = true;
	}

	return true;
}
コード例 #5
0
ファイル: weapon_base_gun.cpp プロジェクト: bonjorno7/GAME
bool CWeaponBaseGun::Reload()
{
    CMomentumPlayer *pPlayer = GetPlayerOwner();
    if (!pPlayer)
        return false;

    if (pPlayer->GetAmmoCount(GetPrimaryAmmoType()) <= 0)
        return false;

    int iResult = DefaultReload(GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD);
    if (!iResult)
        return false;

    pPlayer->SetAnimation(PLAYER_RELOAD);

#ifndef CLIENT_DLL
    if ((iResult) && (pPlayer->GetFOV() != pPlayer->GetDefaultFOV()))
    {
        pPlayer->SetFOV(pPlayer, pPlayer->GetDefaultFOV());
    }
#endif

    m_flAccuracy = 0.2;
    pPlayer->m_iShotsFired = 0;
    m_bDelayFire = false;

    return true;
}
コード例 #6
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CTFCompoundBow::WeaponIdle( void )
{
	CTFPlayer *pOwner = GetTFPlayerOwner();

	if ( m_flChargeBeginTime > 0 && pOwner->GetAmmoCount( GetPrimaryAmmoType() ) > 0 )
	{
		FireArrow();
	}
	else
	{
		BaseClass::WeaponIdle();
	}
}
コード例 #7
0
bool CDEagle::Reload()
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	if ( pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
		return false;

	if ( !DefaultReload( 7, DEAGLE_RELOAD, 2.2 ) )
		return false;

	//m_pPlayer->SetAnimation( PLAYER_RELOAD );
	m_flAccuracy = 0.9;
	return true;
}
コード例 #8
0
bool CWeaponUSP::Reload()
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
		return true;

	int iResult = DefaultReload( 12, 0, ACT_VM_RELOAD );
	if (!iResult)
		return true;

	pPlayer->SetAnimation( PLAYER_RELOAD );
	m_flAccuracy = 0.92;
	return true;
}
コード例 #9
0
bool CWeaponDODBase::IsUseable()
{
	CBasePlayer *pPlayer = GetPlayerOwner();

	if ( Clip1() <= 0 )
	{
		if ( pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 && GetMaxClip1() != -1 )			
		{
			// clip is empty (or nonexistant) and the player has no more ammo of this type. 
			return false;
		}
	}

	return true;
}
コード例 #10
0
bool CWeaponMP5::Reload( )
{
	CSDKPlayer *pPlayer = GetPlayerOwner();

	if (pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
		return false;

	int iResult = DefaultReload( GetMaxClip1(), GetMaxClip2(), ACT_VM_RELOAD );
	if ( !iResult )
		return false;

	pPlayer->SetAnimation( PLAYER_RELOAD );

#ifndef CLIENT_DLL
	if ((iResult) && (pPlayer->GetFOV() != pPlayer->GetDefaultFOV()))
	{
		pPlayer->SetFOV( pPlayer, pPlayer->GetDefaultFOV() );
	}
#endif

	pPlayer->m_iShotsFired = 0;

	return true;
}
コード例 #11
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CWarsWeapon::PrimaryAttack( void )
{
	VPROF_BUDGET( "CWarsWeapon::PrimaryAttack", VPROF_BUDGETGROUP_UNITS );

	CUnitBase *pOwner = GetOwner()  ? GetOwner()->MyUnitPointer() : NULL;
	if( !pOwner )
		return;

#ifndef CLIENT_DLL
	if( m_bEnableBurst )
	{
		// Auto reset burst shots next time we fire
		if( m_nBurstShotsRemaining <= 0 )
		{
			m_nBurstShotsRemaining = GetRandomBurst();
		}
	}
#endif // CLIENT_DLL

	pOwner->DoMuzzleFlash();
	
	SendWeaponAnim( GetPrimaryAttackActivity() );

	Vector vecShootOrigin, vecShootDir;
	GetShootOriginAndDirection(vecShootOrigin, vecShootDir);

    int shots = 0;

	// Assume still firing if gpGlobals.curtime-nextprimaryattack falss within this range
	// In the other case reset nextprimaryattack, so we only fire one shot
	if( (gpGlobals->curtime - m_flNextPrimaryAttack) > m_fFireTimeOut )
		m_flNextPrimaryAttack = gpGlobals->curtime;

	//WeaponSound(SINGLE, m_flNextPrimaryAttack);
	while( m_flNextPrimaryAttack <= gpGlobals->curtime )
	{
#ifdef CLIENT_DLL
		// MUST call sound before removing a round from the clip of a CMachineGun
		WeaponSound(SINGLE, m_flNextPrimaryAttack);
#endif // CLIENT_DLL
		m_flNextPrimaryAttack = m_flNextPrimaryAttack + m_fFireRate;
		shots += 1;
		if( !m_fFireRate )
			break;
	}
    
	// Fill in bullets info
	FireBulletsInfo_t info;
	info.m_vecSrc = vecShootOrigin;
	info.m_vecDirShooting = vecShootDir;
	info.m_iShots = shots;
	info.m_flDistance = m_fMaxBulletRange;
	info.m_iAmmoType = GetPrimaryAmmoType();
	info.m_iTracerFreq = 2;
	info.m_vecSpread = m_vBulletSpread;
	info.m_flDamage = m_fOverrideAmmoDamage;

	pOwner->FireBullets( info );

#ifndef CLIENT_DLL
	if( m_bEnableBurst )
	{
		m_nBurstShotsRemaining -= shots;
		// Dispatch burst finished event if we have no shots left
		// It's up to the AI to rest
		if( m_nBurstShotsRemaining <= 0 )
		{
			pOwner->DispatchBurstFinished();
		}
	}
#endif // CLIENT_DLL

	// Add our view kick in
	AddViewKick();
}
コード例 #12
0
void CWeaponUSP::USPFire( float flSpread )
{
	CCSPlayer *pPlayer = GetPlayerOwner();
	if ( !pPlayer )
		return;

	float flCycleTime =  GetCSWpnData().m_flCycleTime;

	pPlayer->m_iShotsFired++;
	
	if (pPlayer->m_iShotsFired > 1)
		return;
	
	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	m_flAccuracy -= (0.275)*(0.3 - (gpGlobals->curtime - m_flLastFire));

	if (m_flAccuracy > 0.92)
		m_flAccuracy = 0.92;
	else if (m_flAccuracy < 0.6)
		m_flAccuracy = 0.6;

	m_flLastFire = gpGlobals->curtime;

	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime;

	m_iClip1--;

	SendWeaponAnim( ACT_VM_PRIMARYATTACK );

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	
	if ( !m_bSilencerOn )
	{
		pPlayer->DoMuzzleFlash();
	}
	
	FX_FireBullets(
		pPlayer->entindex(),
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + 2.0f * pPlayer->GetPunchAngle(),
		GetWeaponID(),
		m_bSilencerOn?Secondary_Mode:Primary_Mode,
		CBaseEntity::GetPredictionRandomSeed() & 255,
		flSpread );

	if (!m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}
 
	SetWeaponIdleTime( gpGlobals->curtime + 2 );

	QAngle angle = pPlayer->GetPunchAngle();
	angle.x -= 2;
	pPlayer->SetPunchAngle( angle );
}
コード例 #13
0
	void ItemPostFrame()
	{
		CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>(GetOwner());
		if( !pPlayer )
			return;

		if ( pPlayer->m_afButtonReleased & IN_ATTACK )
		{
			CancelPrimaryAttack();
		}
					
		trace_t tr;
		Vector eyePos, eyeForward;
		pPlayer->EyePositionAndVectors( &eyePos, &eyeForward, NULL, NULL );

		CTraceFilterSkipTwoEntities traceFilter( pPlayer, this, COLLISION_GROUP_NONE );
		UTIL_TraceLine( eyePos, eyePos + eyeForward * MAX_TRACE_LENGTH, MASK_SHOT, &traceFilter, &tr );

		if( !m_hBeam )
		{
			if ( gpGlobals->curtime >= m_flBeamTime )
			{
#ifndef CLIENT_DLL
				m_hBeam = CREATE_ENTITY( CBeam, "env_beam" );

				if ( m_hBeam )
				{
					m_hBeam->BeamInit( "sprites/lgtning.vmt", 6.5f );
					m_hBeam->PointEntInit( tr.endpos, pPlayer->GetViewModel(0) );
					m_hBeam->SetScrollRate( -10.f );
					m_hBeam->SetNoise( 1 );
					m_hBeam->SetEndAttachment( LookupAttachment("muzzle") );
					m_hBeam->Spawn();
				}
#endif
				SendWeaponAnim( ACT_VM_PRIMARYATTACK );
			}
			
			if ( m_flBeamTime == FLT_MAX )
				BaseClass::ItemPostFrame();
		}
		else
		{
			if ( gpGlobals->curtime >= m_flDamageTime )
			{
				GetOwner()->RemoveAmmo( 1, GetPrimaryAmmoType() );
#ifndef CLIENT_DLL					
				if( tr.fraction != 1.0 && tr.m_pEnt )
				{
					ClearMultiDamage();
					Vector dir = tr.endpos - m_hBeam->GetAbsEndPos();
					VectorNormalize( dir );
	
					const float flDamage = BEAM_DAMAGE;

					CTakeDamageInfo info( m_hBeam, GetOwner(), flDamage, DMG_SHOCK );
					CalculateMeleeDamageForce( &info, dir, tr.endpos );
					tr.m_pEnt->DispatchTraceAttack( info, dir, &tr );
					ApplyMultiDamage();

					RadiusDamage( CTakeDamageInfo( m_hBeam, GetOwner(), flDamage * 0.25f, DMG_SHOCK ), tr.endpos, 16.0f, CLASS_NONE, NULL );
				}
#endif

				if ( !HasPrimaryAmmo() )
					CancelPrimaryAttack();

				m_flDamageTime = gpGlobals->curtime + DAMAGE_TICK;
			}

			m_hBeam->SetStartPos( tr.endpos );
		}
	}
コード例 #14
0
void CDODBaseRocketWeapon::PrimaryAttack()
{
	Assert( m_pWeaponInfo );

	CDODPlayer *pPlayer = ToDODPlayer( GetPlayerOwner() );
	
	// Out of ammo?
	if ( m_iClip1 <= 0 )
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	if( pPlayer->GetWaterLevel() > 2 )
	{
		PlayEmptySound();
		m_flNextPrimaryAttack = gpGlobals->curtime + 1.0;
		return;
	}

	if( IsDeployed() )
	{
		// player "shoot" animation
		pPlayer->SetAnimation( PLAYER_ATTACK1 );

		SendWeaponAnim( ACT_VM_PRIMARYATTACK );
		
		FireRocket();

		DoFireEffects();

		m_iClip1--; 

#ifdef CLIENT_DLL
		if ( prediction->IsFirstTimePredicted() )
			pPlayer->DoRecoil( GetWeaponID(), m_pWeaponInfo->m_flRecoil );
#endif

		if ( m_iClip1 <= 0 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
		{
			Lower();
		}

		m_flNextPrimaryAttack = gpGlobals->curtime + SequenceDuration() + 0.5;
		m_flTimeWeaponIdle = gpGlobals->curtime + SequenceDuration() + 0.5;	//length of the fire anim!

#ifndef CLIENT_DLL
		IGameEvent * event = gameeventmanager->CreateEvent( "dod_stats_weapon_attack" );
		if ( event )
		{
			event->SetInt( "attacker", pPlayer->GetUserID() );
			event->SetInt( "weapon", GetStatsWeaponID() );

			gameeventmanager->FireEvent( event );
		}
#endif	//CLIENT_DLL
	}
	else
	{
#ifdef CLIENT_DLL
		pPlayer->HintMessage( HINT_SHOULDER_WEAPON, true );
#endif

		m_flNextPrimaryAttack = gpGlobals->curtime + 2.0f;
	}
}
コード例 #15
0
void CDEagle::DEAGLEFire( float flSpread, float flCycleTime, bool fUseSemi )
{
	CCSPlayer *pPlayer = GetPlayerOwner();


	flCycleTime -= 0.075;
	m_iShotsFired++;

	if (m_iShotsFired > 1)
		return;

	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	if ( m_flLastFire == 0 )
	{
		m_flLastFire = gpGlobals->curtime;
	}
	else 
	{
		m_flAccuracy -= (0.35)*(0.4 - ( gpGlobals->curtime - m_flLastFire ) );

		if (m_flAccuracy > 0.9)
			m_flAccuracy = 0.9;
		else if (m_flAccuracy < 0.55)
			m_flAccuracy = 0.55;

		m_flLastFire = gpGlobals->curtime;
	}


	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_iClip1--;

	pPlayer->m_fEffects |= EF_MUZZLEFLASH;

	//SetPlayerShieldAnim();
	
	// player "shoot" animation
	//m_pPlayer->SetAnimation( PLAYER_ATTACK1 );

	//pPlayer->m_iWeaponVolume = BIG_EXPLOSION_VOLUME;
	//pPlayer->m_iWeaponFlash = BRIGHT_GUN_FLASH;

	Vector vecSrc = pPlayer->Weapon_ShootPosition();
	Vector vecDir = pPlayer->FireBullets3( 
		vecSrc, 
		pPlayer->EyeAngles() + pPlayer->GetPunchAngle(), 
		flSpread, 
		4096, 
		2, 
		GetPrimaryAmmoType(), 
		54, 
		0.81, 
		pPlayer );

	WeaponSound( SINGLE );

	/*
	#if defined( CLIENT_WEAPONS )
		int flag = FEV_NOTHOST;
	#else
		int flag = 0;
	#endif
	
	PLAYBACK_EVENT_FULL( flag, m_pPlayer->edict(), m_usFireDeagle,
		0.0, (float *)&g_vecZero, (float *)&g_vecZero, 
		vecDir.x,
		vecDir.y,
		m_pPlayer->pev->punchangle.x * 100,
		m_pPlayer->pev->punchangle.y * 100, 
		m_iClip1 ? 0 : 1, 0 );
	*/

	m_flNextPrimaryAttack = gpGlobals->curtime + flCycleTime;

	if ( !m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0 )
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}

	m_flTimeWeaponIdle = gpGlobals->curtime + 1.8;

	QAngle punchAngle = pPlayer->GetPunchAngle();
	punchAngle.x -= 2;
	pPlayer->SetPunchAngle( punchAngle );

	//ResetPlayerShieldAnim();
}
コード例 #16
0
void CWeaponDODBase::ItemPostFrame()
{
	if ( m_flSmackTime > 0 && gpGlobals->curtime > m_flSmackTime )
	{
		Smack();
		m_flSmackTime = -1;
	}

	CBasePlayer *pPlayer = GetPlayerOwner();

	if ( !pPlayer )
		return;

#ifdef _DEBUG
	CDODGameRules *mp = DODGameRules();
#endif

	assert( mp );

	if ((m_bInReload) && (pPlayer->m_flNextAttack <= gpGlobals->curtime))
	{
		// complete the reload. 
		int j = min( GetMaxClip1() - m_iClip1, pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) );	

		// Add them to the clip
		m_iClip1 += j;
		pPlayer->RemoveAmmo( j, m_iPrimaryAmmoType );

		m_bInReload = false;

		FinishReload();
	}

	if ((pPlayer->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
	{
		if ( m_iClip2 != -1 && !pPlayer->GetAmmoCount( GetSecondaryAmmoType() ) )
		{
			m_bFireOnEmpty = TRUE;
		}

		SecondaryAttack();

		pPlayer->m_nButtons &= ~IN_ATTACK2;
	}
	else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime ) && !m_bInAttack )
	{
		if ( (m_iClip1 == 0/* && pszAmmo1()*/) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) ) )
		{
			m_bFireOnEmpty = TRUE;
		}

		if( CanAttack() )
			PrimaryAttack();
	}
	else if ( pPlayer->m_nButtons & IN_RELOAD && GetMaxClip1() != WEAPON_NOCLIP && !m_bInReload && m_flNextPrimaryAttack < gpGlobals->curtime) 
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.		
		Reload();	
	}
	else if ( !(pPlayer->m_nButtons & (IN_ATTACK|IN_ATTACK2) ) )
	{
		// no fire buttons down

		m_bFireOnEmpty = false;

		m_bInAttack = false;	//reset semi-auto

		if ( !IsUseable() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
		{
			// Intentionally blank -- used to switch weapons here
		}
		else if( ShouldAutoReload() )
		{
			// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
			if ( m_iClip1 == 0 && !(GetWeaponFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				Reload();
				return;
			}
		}

		WeaponIdle( );
		return;
	}
}
コード例 #17
0
void CWeaponCSBase::ItemPostFrame()
{
	CCSPlayer *pPlayer = GetPlayerOwner();


	//GOOSEMAN : Return zoom level back to previous zoom level before we fired a shot. This is used only for the AWP.
	if ( (m_flNextPrimaryAttack <= gpGlobals->curtime) && (pPlayer->m_bResumeZoom == TRUE) )
	{
		#ifndef CLIENT_DLL
			pPlayer->SetFOV( pPlayer->m_iLastZoom );

			if ( pPlayer->GetFOV() == pPlayer->m_iLastZoom )
			{
				// return the fade level in zoom.
				pPlayer->m_bResumeZoom = false;
			}
		#endif
	}

	//GOOSEMAN : Delayed shell ejection code..
	if ( (pPlayer->m_flEjectBrass != 0.0) && (pPlayer->m_flEjectBrass <= gpGlobals->curtime ) )
	{
		pPlayer->m_flEjectBrass = 0.0;
		EjectBrassLate();
	}


	if ((m_bInReload) && (pPlayer->m_flNextAttack <= gpGlobals->curtime))
	{
		// complete the reload. 
		int j = min( GetMaxClip1() - m_iClip1, pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) );	

		// Add them to the clip
		m_iClip1 += j;
		pPlayer->RemoveAmmo( j, m_iPrimaryAmmoType );

		m_bInReload = false;
	}

	if ((pPlayer->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
	{
		if ( m_iClip2 != -1 && !pPlayer->GetAmmoCount( GetSecondaryAmmoType() ) )
		{
			m_bFireOnEmpty = TRUE;
		}
		SecondaryAttack();
		pPlayer->m_nButtons &= ~IN_ATTACK2;
	}
	else if ((pPlayer->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime ))
	{
		if ( (m_iClip1 == 0/* && pszAmmo1()*/) || (GetMaxClip1() == -1 && !pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) ) )
		{
			m_bFireOnEmpty = TRUE;
		}

		// Can't shoot during the freeze period
		// Ken: Always allow firing in single player
		//---
		if ( !CSGameRules()->IsFreezePeriod() && 
			!pPlayer->m_bIsDefusing &&
			pPlayer->State_Get() == STATE_JOINED
			)
		{
			PrimaryAttack();
		}
		//---
	}
	else if ( pPlayer->m_nButtons & IN_RELOAD && GetMaxClip1() != WEAPON_NOCLIP && !m_bInReload && m_flNextPrimaryAttack < gpGlobals->curtime) 
	{
		// reload when reload is pressed, or if no buttons are down and weapon is empty.
		
		//MIKETODO: add code for shields...
		//if ( !FBitSet( m_iWeaponState, WPNSTATE_SHIELD_DRAWN ) )
			  Reload();	
	}
	else if ( !(pPlayer->m_nButtons & (IN_ATTACK|IN_ATTACK2) ) )
	{
		// no fire buttons down

		// The following code prevents the player from tapping the firebutton repeatedly 
		// to simulate full auto and retaining the single shot accuracy of single fire
		if (m_bDelayFire == TRUE)
		{
			m_bDelayFire = FALSE;
			if (m_iShotsFired > 15)
				m_iShotsFired = 15;
			m_flDecreaseShotsFired = gpGlobals->curtime + 0.4;
		}

		m_bFireOnEmpty = FALSE;

		// if it's a pistol then set the shots fired to 0 after the player releases a button
		if ( IsPistol() )
		{
			m_iShotsFired = 0;
		}
		else
		{
			if ( (m_iShotsFired > 0) && (m_flDecreaseShotsFired < gpGlobals->curtime)	)
			{
				m_flDecreaseShotsFired = gpGlobals->curtime + 0.0225;
				m_iShotsFired--;
			}
		}

		#ifndef CLIENT_DLL
			if ( !IsUseable() && m_flNextPrimaryAttack < gpGlobals->curtime ) 
			{
				// Intentionally blank -- used to switch weapons here
			}
			else
		#endif
		{
			// weapon is useable. Reload if empty and weapon has waited as long as it has to after firing
			if ( m_iClip1 == 0 && !(GetFlags() & ITEM_FLAG_NOAUTORELOAD) && m_flNextPrimaryAttack < gpGlobals->curtime )
			{
				Reload();
				return;
			}
		}

		WeaponIdle( );
		return;
	}
}
コード例 #18
0
void CWeaponUSP::USPFire( float flSpread, float flCycleTime, bool fUseSemi )
{
	CCSPlayer *pPlayer = GetPlayerOwner();

	flCycleTime -= 0.075;
	m_iShotsFired++;

	if (m_iShotsFired > 1)
		return;
	
	// Mark the time of this shot and determine the accuracy modifier based on the last shot fired...
	if (m_flLastFire == 0)
		m_flLastFire = gpGlobals->curtime;
	else 
	{
		m_flAccuracy -= (0.275)*(0.3 - (gpGlobals->curtime - m_flLastFire));

		if (m_flAccuracy > 0.92)
			m_flAccuracy = 0.92;
		else if (m_flAccuracy < 0.6)
			m_flAccuracy = 0.6;

		m_flLastFire = gpGlobals->curtime;
	}

	if (m_iClip1 <= 0)
	{
		if (m_bFireOnEmpty)
		{
			PlayEmptySound();
			m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
		}

		return;
	}

	m_flNextPrimaryAttack = m_flNextSecondaryAttack = gpGlobals->curtime + flCycleTime;

	m_iClip1--;

	// player "shoot" animation
	pPlayer->SetAnimation( PLAYER_ATTACK1 );

	
	int damageAmt;
	if ( m_bSilencerOn )
	{
		WeaponSound( SPECIAL1 );
		damageAmt = 30;
	}
	else
	{
		WeaponSound( SINGLE );
		damageAmt = 34;
		pPlayer->m_fEffects |= EF_MUZZLEFLASH;
	}
	
	Vector vecDir = pPlayer->FireBullets3( 
		pPlayer->Weapon_ShootPosition(),
		pPlayer->EyeAngles() + pPlayer->GetPunchAngle(),
		flSpread, 
		4096, 
		1, 
		GetPrimaryAmmoType(), 
		damageAmt, 
		0.79, 
		pPlayer );


	/*
	pPlayer->m_iWeaponVolume = BIG_EXPLOSION_VOLUME;
	pPlayer->m_iWeaponFlash = DIM_GUN_FLASH;

	int flag;
	#if defined( CLIENT_WEAPONS )
		flag = FEV_NOTHOST;
	#else
		flag = 0;
	#endif

	PLAYBACK_EVENT_FULL( flag, pPlayer->edict(), m_usFireUSP,
	0.0, (float *)&g_vecZero, (float *)&g_vecZero, 
	vecDir.x,
	vecDir.y,
	pPlayer->pev->punchangle.x * 100, 0, m_iClip1 ? 0 : 1, (m_iWeaponState & WPNSTATE_USP_SILENCER_ON) ? 1 : 0 );
	*/

	if (!m_iClip1 && pPlayer->GetAmmoCount( GetPrimaryAmmoType() ) <= 0)
	{
		// HEV suit - indicate out of ammo condition
		pPlayer->SetSuitUpdate("!HEV_AMO0", false, 0);
	}
 
	m_flTimeWeaponIdle = gpGlobals->curtime + 2;

	QAngle angle = pPlayer->GetPunchAngle();
	angle.x -= 2;
	pPlayer->SetPunchAngle( angle );
}