예제 #1
0
파일: sp_ai.c 프로젝트: JosephPecoraro/ktx
void HuntTarget()
{
	vec3_t tmpv;

	self->s.v.goalentity = self->s.v.enemy;
	self->s.v.think = ( func_t ) self->th_run;
	VectorSubtract( PROG_TO_EDICT( self->s.v.enemy )->s.v.origin, self->s.v.origin, tmpv );
	self->s.v.ideal_yaw = vectoyaw( tmpv );
	self->s.v.nextthink = g_globalvars.time + 0.1;
	SUB_AttackFinished( 1 );	// wait a while before first attack
}
예제 #2
0
void Sentry_HuntTarget(  )
{
    vec3_t  vtemp;

    self->s.v.goalentity = self->s.v.enemy;
    if ( self->s.v.weapon == 1 )
        self->s.v.think = ( func_t ) lvl1_sentry_atk1;
    else
    {
        if ( self->s.v.weapon == 2 )
            self->s.v.think = ( func_t ) lvl2_sentry_atk1;
        else
            self->s.v.think = ( func_t ) lvl3_sentry_atk1;
    }

    VectorSubtract( PROG_TO_EDICT( self->s.v.enemy )->s.v.origin, self->s.v.origin, vtemp );
    self->s.v.ideal_yaw = vectoyaw( vtemp );
    self->s.v.nextthink = g_globalvars.time + 0.1;
    SUB_AttackFinished( 1 ); // wait a while before first attack
}
예제 #3
0
파일: sp_ai.c 프로젝트: JosephPecoraro/ktx
/*
===========
CheckAttack

The player is in view, so decide to move or launch an attack
Returns false if movement should continue
============
*/
float CheckAttack ()
{
	vec3_t		spot1, spot2;
	gedict_t	*targ;
	float		chance;

	targ = PROG_TO_EDICT( self->s.v.enemy );

	// see if any entities are in the way of the shot
	VectorAdd( self->s.v.origin, self->s.v.view_ofs, spot1 );
	VectorAdd( targ->s.v.origin, targ->s.v.view_ofs, spot2 );

	traceline( PASSVEC3( spot1 ), PASSVEC3( spot2 ), false, self );

	if ( PROG_TO_EDICT( g_globalvars.trace_ent ) != targ )
		return false; // don't have a clear shot

	if ( g_globalvars.trace_inopen && g_globalvars.trace_inwater )
		return false; // sight line crossed contents

	if ( enemy_range == RANGE_MELEE )
	{	// melee attack
		if ( self->th_melee )
		{
			self->th_melee();

			return true;
		}
	}

	// missile attack
	if ( !self->th_missile )
		return false;

	if ( g_globalvars.time < self->attack_finished )
		return false;

	if ( enemy_range == RANGE_FAR )
		return false;

	if ( enemy_range == RANGE_MELEE )
	{
		chance = 0.9;
		self->attack_finished = 0;
	}
	else if ( enemy_range == RANGE_NEAR )
	{
		if (self->th_melee)
			chance = 0.2;
		else
			chance = 0.4;
	}
	else if ( enemy_range == RANGE_MID )
	{
		if ( self->th_melee )
			chance = 0.05;
		else
			chance = 0.1;
	}
	else
		chance = 0;

	if ( g_random() < chance )
	{
		if ( self->th_missile )
			self->th_missile();

		SUB_AttackFinished( 2 * g_random() );

		return true;
	}

	return false;
}