summaryrefslogtreecommitdiff
path: root/src/game/g_missile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/g_missile.c')
-rw-r--r--src/game/g_missile.c95
1 files changed, 33 insertions, 62 deletions
diff --git a/src/game/g_missile.c b/src/game/g_missile.c
index 83a1ce88..a122d4f6 100644
--- a/src/game/g_missile.c
+++ b/src/game/g_missile.c
@@ -174,7 +174,7 @@ void G_MissileImpact( gentity_t *ent, trace_t *trace )
//prevent collision with the client when returning
ent->r.ownerNum = other->s.number;
- ent->think = AHive_ReturnToHive;
+ ent->think = G_ExplodeMissile;
ent->nextthink = level.time + FRAMETIME;
//only damage humans
@@ -198,7 +198,7 @@ void G_MissileImpact( gentity_t *ent, trace_t *trace )
velocity[ 2 ] = 1; // stepped on a grenade
G_Damage( other, ent, attacker, velocity, ent->s.origin, ent->damage,
- 0, ent->methodOfDeath );
+ DAMAGE_NO_LOCDAMAGE, ent->methodOfDeath );
}
}
@@ -580,83 +580,54 @@ gentity_t *launch_grenade( gentity_t *self, vec3_t start, vec3_t dir )
}
//=============================================================================
+
+
/*
================
-AHive_ReturnToHive
+AHive_SearchAndDestroy
-Adjust the trajectory to point towards the hive
+Adjust the trajectory to point towards the target
================
*/
-void AHive_ReturnToHive( gentity_t *self )
+void AHive_SearchAndDestroy( gentity_t *self )
{
- vec3_t dir;
- trace_t tr;
+ vec3_t dir;
+ trace_t tr;
+ gentity_t *ent;
+ int i;
+ float d, nearest;
- if( !self->parent )
+ if( self->timestamp > level.time )
{
- G_Printf( S_COLOR_YELLOW "WARNING: AHive_ReturnToHive called with no self->parent\n" );
- return;
- }
-
- trap_UnlinkEntity( self->parent );
- trap_Trace( &tr, self->r.currentOrigin, self->r.mins, self->r.maxs,
- self->parent->r.currentOrigin, self->r.ownerNum, self->clipmask );
- trap_LinkEntity( self->parent );
-
- if( tr.fraction < 1.0f )
- {
- //if can't see hive then disperse
VectorCopy( self->r.currentOrigin, self->s.pos.trBase );
self->s.pos.trType = TR_STATIONARY;
self->s.pos.trTime = level.time;
self->think = G_ExplodeMissile;
- self->nextthink = level.time + 2000;
+ self->nextthink = level.time + 50;
self->parent->active = qfalse; //allow the parent to start again
+ return;
}
- else
- {
- VectorSubtract( self->parent->r.currentOrigin, self->r.currentOrigin, dir );
- VectorNormalize( dir );
-
- //change direction towards the hive
- VectorScale( dir, HIVE_SPEED, self->s.pos.trDelta );
- SnapVector( self->s.pos.trDelta ); // save net bandwidth
- VectorCopy( self->r.currentOrigin, self->s.pos.trBase );
- self->s.pos.trTime = level.time;
-
- self->think = G_ExplodeMissile;
- self->nextthink = level.time + 15000;
- }
-}
-
-/*
-================
-AHive_SearchAndDestroy
-
-Adjust the trajectory to point towards the target
-================
-*/
-void AHive_SearchAndDestroy( gentity_t *self )
-{
- vec3_t dir;
- trace_t tr;
-
- trap_Trace( &tr, self->r.currentOrigin, self->r.mins, self->r.maxs,
- self->target_ent->r.currentOrigin, self->r.ownerNum, self->clipmask );
- //if there is no LOS or the parent hive is too far away or the target is dead, return
- if( tr.entityNum == ENTITYNUM_WORLD ||
- Distance( self->r.currentOrigin, self->parent->r.currentOrigin ) > HIVE_RANGE ||
- self->target_ent->health <= 0 )
+ nearest = DistanceSquared( self->r.currentOrigin, self->target_ent->r.currentOrigin );
+ //find the closest human
+ for( i = 0; i < MAX_CLIENTS; i++ )
{
- self->r.ownerNum = ENTITYNUM_WORLD;
-
- self->think = AHive_ReturnToHive;
- self->nextthink = level.time + FRAMETIME;
+ ent = &g_entities[ i ];
+ if( ent->client &&
+ ent->health > 0 &&
+ ent->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS &&
+ nearest > (d = DistanceSquared( ent->r.currentOrigin, self->r.currentOrigin ) ) )
+ {
+ trap_Trace( &tr, self->r.currentOrigin, self->r.mins, self->r.maxs,
+ ent->r.currentOrigin, self->r.ownerNum, self->clipmask );
+ if( tr.entityNum != ENTITYNUM_WORLD )
+ {
+ nearest = d;
+ self->target_ent = ent;
+ }
+ }
}
- else
- {
VectorSubtract( self->target_ent->r.currentOrigin, self->r.currentOrigin, dir );
VectorNormalize( dir );
@@ -667,7 +638,6 @@ void AHive_SearchAndDestroy( gentity_t *self )
self->s.pos.trTime = level.time;
self->nextthink = level.time + HIVE_DIR_CHANGE_PERIOD;
- }
}
/*
@@ -699,6 +669,7 @@ gentity_t *fire_hive( gentity_t *self, vec3_t start, vec3_t dir )
bolt->methodOfDeath = MOD_SWARM;
bolt->clipmask = MASK_SHOT;
bolt->target_ent = self->target_ent;
+ bolt->timestamp = level.time + HIVE_LIFETIME;
bolt->s.pos.trType = TR_LINEAR;
bolt->s.pos.trTime = level.time - MISSILE_PRESTEP_TIME; // move a bit on the very first frame