summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author/dev/humancontroller <devhc@example.com>2014-07-14 16:12:36 +0200
committer/dev/humancontroller <devhc@example.com>2017-03-09 13:51:17 +0100
commit4770f7211ed30a0a567ba49cb0d7224ab830adcb (patch)
tree34c038af9ee15167a882bec40fdcfd77d4bcd5b8
parent7d165fdd77b85ae93acd749a15051080ea3eb0cd (diff)
make some code more robust against disappearance of entities
-rw-r--r--src/game/g_missile.c25
-rw-r--r--src/game/g_target.c2
2 files changed, 24 insertions, 3 deletions
diff --git a/src/game/g_missile.c b/src/game/g_missile.c
index 406d6f33..06a33ccb 100644
--- a/src/game/g_missile.c
+++ b/src/game/g_missile.c
@@ -590,6 +590,9 @@ void AHive_SearchAndDestroy( gentity_t *self )
int i;
float d, nearest;
+ if( self->parent && !self->parent->inuse )
+ self->parent = NULL;
+
if( level.time > self->timestamp )
{
VectorCopy( self->r.currentOrigin, self->s.pos.trBase );
@@ -598,11 +601,20 @@ void AHive_SearchAndDestroy( gentity_t *self )
self->think = G_ExplodeMissile;
self->nextthink = level.time + 50;
- self->parent->active = qfalse; //allow the parent to start again
+ if( self->parent )
+ self->parent->active = qfalse; //allow the parent to start again
return;
}
- nearest = DistanceSquared( self->r.currentOrigin, self->target_ent->r.currentOrigin );
+ ent = self->target_ent;
+ if( ent && ent->health > 0 && ent->client && ent->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS )
+ nearest = DistanceSquared( self->r.currentOrigin, ent->r.currentOrigin );
+ else
+ {
+ self->target_ent = NULL;
+ nearest = 0; // silence warning
+ }
+
//find the closest human
for( i = 0; i < MAX_CLIENTS; i++ )
{
@@ -614,7 +626,8 @@ void AHive_SearchAndDestroy( gentity_t *self )
if( ent->client &&
ent->health > 0 &&
ent->client->ps.stats[ STAT_TEAM ] == TEAM_HUMANS &&
- nearest > (d = DistanceSquared( ent->r.currentOrigin, self->r.currentOrigin ) ) )
+ ( d = DistanceSquared( ent->r.currentOrigin, self->r.currentOrigin ),
+ ( self->target_ent == NULL || d < nearest ) ) )
{
trap_Trace( &tr, self->r.currentOrigin, self->r.mins, self->r.maxs,
ent->r.currentOrigin, self->r.ownerNum, self->clipmask );
@@ -625,8 +638,14 @@ void AHive_SearchAndDestroy( gentity_t *self )
}
}
}
+
+ if( self->target_ent == NULL )
+ VectorClear( dir );
+ else
+ {
VectorSubtract( self->target_ent->r.currentOrigin, self->r.currentOrigin, dir );
VectorNormalize( dir );
+ }
//change direction towards the player
VectorScale( dir, HIVE_SPEED, self->s.pos.trDelta );
diff --git a/src/game/g_target.c b/src/game/g_target.c
index d25b8807..77b03df8 100644
--- a/src/game/g_target.c
+++ b/src/game/g_target.c
@@ -31,6 +31,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
void Think_Target_Delay( gentity_t *ent )
{
+ if( ent->activator && !ent->activator->inuse )
+ ent->activator = NULL;
G_UseTargets( ent, ent->activator );
}