}
/*
================
botAim
================
*/
qboolean botAim( gentity_t *self )
{
vec3_t dirToTarget, dttAdjusted, angleToTarget, angularDiff, xNormal;
vec3_t refNormal = { 0.0f, 0.0f, 1.0f };
float temp, rotAngle;
int vh = 0;
vec3_t top = { 0, 0, 0};
//float accuracyTolerance, angularSpeed;
BG_FindViewheightForClass( self->client->ps.stats[ STAT_PCLASS ], &vh, NULL );
top[2]=vh;
VectorAdd( self->s.pos.trBase, top, top);
//accuracyTolerance = MGTURRET_ACCURACYTOLERANCE;
//angularSpeed = MGTURRET_ANGULARSPEED;
VectorSubtract( self->enemy->s.pos.trBase, top, dirToTarget );
VectorNormalize( dirToTarget );
//CrossProduct( self->s.origin2, refNormal, xNormal );
//VectorNormalize( xNormal );
//rotAngle = RAD2DEG( acos( DotProduct( self->s.origin2, refNormal ) ) );
//RotatePointAroundVector( dttAdjusted, xNormal, dirToTarget, rotAngle );
vectoangles( dirToTarget, angleToTarget );
//SetClientViewAngle( self, angleToTarget );
//VectorCopy( angleToTarget, self->s.angles );
//VectorCopy( self->s.angles, self->client->ps.viewangles );
//immediate turn! turn slower and check self->client->ps.viewangles
self->client->ps.delta_angles[ 0 ] = ANGLE2SHORT( angleToTarget[ 0 ] );
self->client->ps.delta_angles[ 1 ] = ANGLE2SHORT( angleToTarget[ 1 ] );
self->client->ps.delta_angles[ 2 ] = ANGLE2SHORT( angleToTarget[ 2 ] );
return qtrue; //for now assume we have perfect aim. indeed we have
/*
angularDiff[ PITCH ] = AngleSubtract( self->s.angles2[ PITCH ], angleToTarget[ PITCH ] );
angularDiff[ YAW ] = AngleSubtract( self->s.angles2[ YAW ], angleToTarget[ YAW ] );
//if not pointing at our target then move accordingly
if( angularDiff[ PITCH ] < (-accuracyTolerance) )
self->s.angles2[ PITCH ] += angularSpeed;
else if( angularDiff[ PITCH ] > accuracyTolerance )
self->s.angles2[ PITCH ] -= angularSpeed;
else
self->s.angles2[ PITCH ] = angleToTarget[ PITCH ];
//disallow vertical movement past a certain limit
temp = fabs( self->s.angles2[ PITCH ] );
if( temp > 180 )
temp -= 360;
if( temp < -MGTURRET_VERTICALCAP )
self->s.angles2[ PITCH ] = (-360) + MGTURRET_VERTICALCAP;
//if not pointing at our target then move accordingly
if( angularDiff[ YAW ] < (-accuracyTolerance) )
self->s.angles2[ YAW ] += angularSpeed;
else if( angularDiff[ YAW ] > accuracyTolerance )
self->s.angles2[ YAW ] -= angularSpeed;
else
self->s.angles2[ YAW ] = angleToTarget[ YAW ];
AngleVectors( self->s.angles2, dttAdjusted, NULL, NULL );
RotatePointAroundVector( dirToTarget, xNormal, dttAdjusted, -rotAngle );
vectoangles( dirToTarget, self->turretAim );
SetClientViewAngle( self, angleToTarget );
//if pointing at our target return true
if( abs( angleToTarget[ YAW ] - self->s.angles2[ YAW ] ) <= accuracyTolerance &&
abs( angleToTarget[ PITCH ] - self->s.angles2[ PITCH ] ) <= accuracyTolerance )
return qtrue;
return qfalse;
*/
}
/*
================
botCheckTarget
================
*/
qboolean botCheckTarget( gentity_t *self, gentity_t *target, qboolean ignorePainted )
{
trace_t trace;
gentity_t *traceEnt;
if( !target )
return qfalse;
if( !target->client )
return qfalse;
if( target->client->ps.stats[ STAT_STATE ] & SS_HOVELING )
return qfalse;
if( target->health <= 0 )
return qfalse;
if( Distance( self->s.pos.trBase, target->s.pos.trBase ) > MGTURRET_RANGE*3 )
return qfalse;
trap_Trace( &trace, self->s.pos.trBase, NULL, NULL, target->s.pos.trBase, self->s.number, MASK_SHOT );
traceEnt = &g_entities[ trace.entityNum ];
if( !traceEnt->client )
return qfalse;
//if( traceEnt->client && traceEnt->client->ps.stats[ STAT_PTEAM ] == elf->client->ps.stats[ STAT_PTEAM ] )
// return qfalse;
return qtrue;
}
/*
================
botFindEnemy
================
*/
//should return a list of entities
int botFindEnemy( gentity_t *self )
{
int entityList[ MAX_GENTITIES ];
vec3_t range;
vec3_t mins, maxs;
int i, num;
gentity_t *target;
VectorSet( range, MGTURRET_RANGE*3, MGTURRET_RANGE*3, MGTURRET_RANGE*3 );
VectorAdd( self->client->ps.origin, range, maxs );
VectorSubtract( self->client->ps.origin, range, mins );
//find aliens
num = trap_EntitiesInBox( mins, maxs, entityList, MAX_GENTITIES );
for( i = 0; i < num; i++ )
{
target = &g_entities[ entityList[ i ] ];
if( target->client && self!=target )//&& target->client->ps.stats[ STAT_PTEAM ] != self->client->ps.stats[ STAT_PTEAM ] )
{
//if target is not valid keep searching
if( !botCheckTarget( self, target, qfalse ) )
continue;
//we found a target
self->enemy = target;
return Distance( self->s.pos.trBase, target->s.pos.trBase );// qtrue;
}
}
//couldn't find a target
self->enemy = NULL;
return -1;
}
Bookmarks