game/server/shit/npc_alien_trooper.cpp
BOOL CSTrooper :: CheckRangeAttack2 ( float flDot, float flDist )
{
	
	// if the grunt isn't moving, it's ok to check.
	if ( m_flGroundSpeed != 0 )
	{
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}

	// assume things haven't changed too much since last time
	if (gpGlobals->time < m_flNextGrenadeCheck )
	{
		return m_fThrowGrenade;
	}

	if ( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == 0 && m_vecEnemyLKP.z > pev->absmax.z  )
	{
		//!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to 
		// be grenaded.
		// don't throw grenades at anything that isn't on the ground!
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}
	
	Vector vecTarget;

	if (FBitSet( pev->weapons, STROOPER_SPOREGRENADE))
	{
		// find feet
		if (RANDOM_LONG(0,1))
		{
			// magically know where they are
			vecTarget = Vector( m_hEnemy->pev->origin.x, m_hEnemy->pev->origin.y, m_hEnemy->pev->absmin.z );
		}
		else
		{
			// toss it to where you last saw them
			vecTarget = m_vecEnemyLKP;
		}
		// vecTarget = m_vecEnemyLKP + (m_hEnemy->BodyTarget( pev->origin ) - m_hEnemy->pev->origin);
		// estimate position
		// vecTarget = vecTarget + m_hEnemy->pev->velocity * 2;
	}
	else
	{
		// find target
		// vecTarget = m_hEnemy->BodyTarget( pev->origin );
		vecTarget = m_vecEnemyLKP + (m_hEnemy->BodyTarget( pev->origin ) - m_hEnemy->pev->origin);
		// estimate position
		if (HasConditions( bits_COND_SEE_ENEMY))
			vecTarget = vecTarget + ((vecTarget - pev->origin).Length() / gSkillData.shocktrooperGrenadeSpeed) * m_hEnemy->pev->velocity;
	}

	// are any of my squad members near the intended grenade impact area?
	if ( InSquad() )
	{
		if (SquadMemberInRange( vecTarget, 256 ))
		{
			// crap, I might blow my own guy up. Don't throw a grenade and don't check again for a while.
			m_flNextGrenadeCheck = gpGlobals->time + 1; // one full second.
			m_fThrowGrenade = FALSE;
		}
	}
	
	if ( ( vecTarget - pev->origin ).Length2D() <= 256 )
	{
		// crap, I don't want to blow myself up
		m_flNextGrenadeCheck = gpGlobals->time + 1; // one full second.
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}

		
	if (FBitSet( pev->weapons, STROOPER_SPOREGRENADE))
	{
		Vector vecToss = VecCheckToss( pev, GetGunPosition(), vecTarget, 0.5 );

		if ( vecToss != g_vecZero )
		{
			m_vecTossVelocity = vecToss;

			// throw a hand grenade
			m_fThrowGrenade = TRUE;
			// don't check again for a while.
			m_flNextGrenadeCheck = gpGlobals->time; // 1/3 second.
		}
		else
		{
			// don't throw
			m_fThrowGrenade = FALSE;
			// don't check again for a while.
			m_flNextGrenadeCheck = gpGlobals->time + 1; // one full second.
		}
	}
	else
	{
		Vector vecToss = VecCheckThrow( pev, GetGunPosition(), vecTarget, gSkillData.shocktrooperGrenadeSpeed, 0.5 );

		if ( vecToss != g_vecZero )
		{
			m_vecTossVelocity = vecToss;

			// throw a hand grenade
			m_fThrowGrenade = TRUE;
			// don't check again for a while.
			m_flNextGrenadeCheck = gpGlobals->time + 0.3; // 1/3 second.
		}
		else
		{
			// don't throw
			m_fThrowGrenade = FALSE;
			// don't check again for a while.
			m_flNextGrenadeCheck = gpGlobals->time + 1; // one full second.
		}
	}

	

	return m_fThrowGrenade;
}
//=========================================================
// CheckRangeAttack2 - this checks the Trooper's grenade
// attack. 
//=========================================================
this checks the Trooper's grenade
attack.
this checks the Trooper ' s grenade attack .
BOOL CSTrooper :: CheckRangeAttack2 ( float flDot, float flDist )
{
	if ( m_flGroundSpeed != 0 )
	{
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}
	if (gpGlobals->time < m_flNextGrenadeCheck )
	{
		return m_fThrowGrenade;
	}
	if ( !FBitSet ( m_hEnemy->pev->flags, FL_ONGROUND ) && m_hEnemy->pev->waterlevel == 0 && m_vecEnemyLKP.z > pev->absmax.z  )
	{
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}
	Vector vecTarget;
	if (FBitSet( pev->weapons, STROOPER_SPOREGRENADE))
	{
		if (RANDOM_LONG(0,1))
		{
			vecTarget = Vector( m_hEnemy->pev->origin.x, m_hEnemy->pev->origin.y, m_hEnemy->pev->absmin.z );
		}
		else
		{
			vecTarget = m_vecEnemyLKP;
		}
	}
	else
	{
		vecTarget = m_vecEnemyLKP + (m_hEnemy->BodyTarget( pev->origin ) - m_hEnemy->pev->origin);
		if (HasConditions( bits_COND_SEE_ENEMY))
			vecTarget = vecTarget + ((vecTarget - pev->origin).Length() / gSkillData.shocktrooperGrenadeSpeed) * m_hEnemy->pev->velocity;
	}
	if ( InSquad() )
	{
		if (SquadMemberInRange( vecTarget, 256 ))
		{
			m_flNextGrenadeCheck = gpGlobals->time + 1; 
			m_fThrowGrenade = FALSE;
		}
	}
	if ( ( vecTarget - pev->origin ).Length2D() <= 256 )
	{
		m_flNextGrenadeCheck = gpGlobals->time + 1; 
		m_fThrowGrenade = FALSE;
		return m_fThrowGrenade;
	}
	if (FBitSet( pev->weapons, STROOPER_SPOREGRENADE))
	{
		Vector vecToss = VecCheckToss( pev, GetGunPosition(), vecTarget, 0.5 );
		if ( vecToss != g_vecZero )
		{
			m_vecTossVelocity = vecToss;
			m_fThrowGrenade = TRUE;
			m_flNextGrenadeCheck = gpGlobals->time; 
		}
		else
		{
			m_fThrowGrenade = FALSE;
			m_flNextGrenadeCheck = gpGlobals->time + 1; 
		}
	}
	else
	{
		Vector vecToss = VecCheckThrow( pev, GetGunPosition(), vecTarget, gSkillData.shocktrooperGrenadeSpeed, 0.5 );
		if ( vecToss != g_vecZero )
		{
			m_vecTossVelocity = vecToss;
			m_fThrowGrenade = TRUE;
			m_flNextGrenadeCheck = gpGlobals->time + 0.3; 
		}
		else
		{
			m_fThrowGrenade = FALSE;
			m_flNextGrenadeCheck = gpGlobals->time + 1; 
		}
	}
	return m_fThrowGrenade;
}
BOOL CSTrooper :: CheckRangeAttack2 ( float flDot , float flDist ) { if ( m_flGroundSpeed != 0 ) { m_fThrowGrenade = FALSE ; return m_fThrowGrenade ; } if ( gpGlobals -> time < m_flNextGrenadeCheck ) { return m_fThrowGrenade ; } if ( ! FBitSet ( m_hEnemy -> pev -> flags , FL_ONGROUND ) && m_hEnemy -> pev -> waterlevel == 0 && m_vecEnemyLKP . z > pev -> absmax . z ) { m_fThrowGrenade = FALSE ; return m_fThrowGrenade ; } Vector vecTarget ; if ( FBitSet ( pev -> weapons , STROOPER_SPOREGRENADE ) ) { if ( RANDOM_LONG ( 0 , 1 ) ) { vecTarget = Vector ( m_hEnemy -> pev -> origin . x , m_hEnemy -> pev -> origin . y , m_hEnemy -> pev -> absmin . z ) ; } else { vecTarget = m_vecEnemyLKP ; } } else { vecTarget = m_vecEnemyLKP + ( m_hEnemy -> BodyTarget ( pev -> origin ) - m_hEnemy -> pev -> origin ) ; if ( HasConditions ( bits_COND_SEE_ENEMY ) ) vecTarget = vecTarget + ( ( vecTarget - pev -> origin ) . Length ( ) / gSkillData . shocktrooperGrenadeSpeed ) * m_hEnemy -> pev -> velocity ; } if ( InSquad ( ) ) { if ( SquadMemberInRange ( vecTarget , 256 ) ) { m_flNextGrenadeCheck = gpGlobals -> time + 1 ; m_fThrowGrenade = FALSE ; } } if ( ( vecTarget - pev -> origin ) . Length2D ( ) <= 256 ) { m_flNextGrenadeCheck = gpGlobals -> time + 1 ; m_fThrowGrenade = FALSE ; return m_fThrowGrenade ; } if ( FBitSet ( pev -> weapons , STROOPER_SPOREGRENADE ) ) { Vector vecToss = VecCheckToss ( pev , GetGunPosition ( ) , vecTarget , 0.5 ) ; if ( vecToss != g_vecZero ) { m_vecTossVelocity = vecToss ; m_fThrowGrenade = TRUE ; m_flNextGrenadeCheck = gpGlobals -> time ; } else { m_fThrowGrenade = FALSE ; m_flNextGrenadeCheck = gpGlobals -> time + 1 ; } } else { Vector vecToss = VecCheckThrow ( pev , GetGunPosition ( ) , vecTarget , gSkillData . shocktrooperGrenadeSpeed , 0.5 ) ; if ( vecToss != g_vecZero ) { m_vecTossVelocity = vecToss ; m_fThrowGrenade = TRUE ; m_flNextGrenadeCheck = gpGlobals -> time + 0.3 ; } else { m_fThrowGrenade = FALSE ; m_flNextGrenadeCheck = gpGlobals -> time + 1 ; } } return m_fThrowGrenade ; }
CheckRangeAttack2 - this checks the Trooper's grenade
attack.
CheckRangeAttack2 - this checks the Trooper ' s grenade attack .
// if the grunt isn't moving, it's ok to check. // assume things haven't changed too much since last time //!!!BUGBUG - we should make this check movetype and make sure it isn't FLY? Players who jump a lot are unlikely to  // be grenaded. // don't throw grenades at anything that isn't on the ground! // find feet // magically know where they are // toss it to where you last saw them // vecTarget = m_vecEnemyLKP + (m_hEnemy->BodyTarget( pev->origin ) - m_hEnemy->pev->origin); // estimate position // vecTarget = vecTarget + m_hEnemy->pev->velocity * 2; // find target // vecTarget = m_hEnemy->BodyTarget( pev->origin ); // estimate position // are any of my squad members near the intended grenade impact area? // crap, I might blow my own guy up. Don't throw a grenade and don't check again for a while. // one full second. // crap, I don't want to blow myself up // one full second. // throw a hand grenade // don't check again for a while. // 1/3 second. // don't throw // don't check again for a while. // one full second. // throw a hand grenade // don't check again for a while. // 1/3 second. // don't throw // don't check again for a while. // one full second.