Esempio n. 1
0
void GunMount::UpdatePreFiring( )
{
	// Once the prefire is done, go to firing.
	if( IsAnimationComplete( ))
	{
		StartFiring( );
		return;
	}

	SetNextUpdate( UPDATE_NEXT_FRAME );
}
void CASW_Sentry_Top_Flamer::CheckFiring()
{
	bool bShouldFire = false;

	if ( HasAmmo() && m_hEnemy.IsValid() && m_hEnemy.Get())
	{
		float flDist = fabs(m_fGoalYaw - m_fCurrentYaw);
		if (flDist > 180)
			flDist = 360 - flDist;	
		// use some hysteresis
		if (flDist < (IsFiring() ? ASW_SENTRY_FIRE_ANGLE_THRESHOLD * 1.1f : ASW_SENTRY_FIRE_ANGLE_THRESHOLD) )
		{
			bShouldFire = true;
		}
	}

	if ( bShouldFire )
	{
		m_flFireHysteresisTime = gpGlobals->curtime + 0.5f;
	}
	else
	{
		bShouldFire = gpGlobals->curtime < m_flFireHysteresisTime ;
	}
	
	// turn firing on or off as appropriate
	if ( IsFiring() != bShouldFire )
	{
		if ( bShouldFire )
			StartFiring();
		else
			StopFiring();
	}
	Assert( IsFiring() == bShouldFire );

	if ( bShouldFire )
	{
		Fire();
	}
}
Esempio n. 3
0
// ----------------------------------------------------------------------- //
//
//	ROUTINE:	GunMount::StartPreFiring
//
//	PURPOSE:	Starts the prefiring state.
//
// ----------------------------------------------------------------------- //
bool GunMount::StartPreFiring( )
{
	CWeapon* pWeapon = m_Arsenal.GetCurWeapon( );
	if( !pWeapon )
		return false;

	// Get the prefire animation.
	HMODELANIM hAnim = pWeapon->GetPreFireAni( );

	// If they don't have a prefire, just go to firing.
	if( hAnim == INVALID_ANI )
	{
		return StartFiring( );
	}

	// Begin prefire animation.
	pWeapon->PlayAnimation( hAnim, true, false );

	SetNextUpdate( UPDATE_NEXT_FRAME );

	m_eFiringState = ePreFiring;

	return true;
}
Esempio n. 4
0
	virtual void OnOutOfAmmo(IWeapon *pWeapon, IEntityClass* pAmmoType)
	{ 
		ReplenishAmmo( pWeapon );
		StartFiring( &m_actInfo, pWeapon );
	}
Esempio n. 5
0
	void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo )
	{     
		IWeapon* pWeapon = GetWeapon(pActInfo);

		if (!pWeapon) 
			return;
			
		switch (event)
		{
			case eFE_Initialize:
			{
				m_isFiring = false;   
				m_numShots = GetPortInt( pActInfo, IN_NUMBEROFSHOTS );
				m_actInfo = *pActInfo;
				m_numShotsDone = 0;

				pWeapon->StopFire();

				if (pActInfo->pEntity->GetId() != m_weapId)
					RemoveListener(m_weapId, this);

				m_weapId = pActInfo->pEntity->GetId();
				pWeapon->AddEventListener(this, __FUNCTION__);

#ifdef DEBUG_NODEFIREWEAPON
				pActInfo->pGraph->SetRegularlyUpdated( pActInfo->myID, true );
#endif
				break;
			}
		
			case eFE_Activate:
			{ 
				m_actInfo = *pActInfo;
				if (IsPortActive(pActInfo, IN_NUMBEROFSHOTS))
					m_numShots = GetPortBool( pActInfo, IN_NUMBEROFSHOTS );
				
				if (IsPortActive(pActInfo, IN_STOPFIRE))
				{
					StopFiring( pActInfo, pWeapon );
				}
				if (IsPortActive(pActInfo, IN_STARTFIRE))
				{
					m_numShotsDone = 0;
					ReplenishAmmo( pWeapon );
					pWeapon->StopFire();
					StartFiring( pActInfo, pWeapon );
				}
				break;
			}
			
			case eFE_Update:
			{
				// this fixes the problem when the entity is being externally moved/rotated, in the interval of time between when the weapon is aimed an the actual shot happens
				if (m_isFiring && GetPortBool( pActInfo, IN_ALIGNTOTARGET ))
					if (pActInfo->pEntity->GetWorldPos()!=m_lastPos || pActInfo->pEntity->GetWorldRotation()!=m_lastRotation)
						CalcFiringPosition( pActInfo, pWeapon );
			
#ifdef DEBUG_NODEFIREWEAPON
				ColorB colorRed( 255,0,0 );
				ColorB colorGreen( 0,255,0 );
				gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posOrig, colorRed, posTarget, colorRed );
				gEnv->pRenderer->GetIRenderAuxGeom()->DrawLine( posTarget, colorGreen, posShot, colorGreen );
#endif
				break;
			}
		}
	}