Make sure that a monsters enemy is still alive when deciding to attack.

When the monster was already killed by another monster or a coop player
some references may be NULL and the game was crashed. This was observed
by maraakte, who reported it in issue #164. I've just merged his fix
from q2dos.
This commit is contained in:
Yamagi Burmeister 2016-12-18 09:59:46 +01:00
parent d98e1b9eb0
commit 80fb945cff

View file

@ -200,7 +200,11 @@ ai_charge(edict_t *self, float dist)
return; return;
} }
if(self->enemy)
{
VectorSubtract(self->enemy->s.origin, self->s.origin, v); VectorSubtract(self->enemy->s.origin, self->s.origin, v);
}
self->ideal_yaw = vectoyaw(v); self->ideal_yaw = vectoyaw(v);
M_ChangeYaw(self); M_ChangeYaw(self);
@ -382,7 +386,11 @@ HuntTarget(edict_t *self)
self->monsterinfo.run(self); self->monsterinfo.run(self);
} }
if(visible(self, self->enemy))
{
VectorSubtract(self->enemy->s.origin, self->s.origin, vec); VectorSubtract(self->enemy->s.origin, self->s.origin, vec);
}
self->ideal_yaw = vectoyaw(vec); self->ideal_yaw = vectoyaw(vec);
/* wait a while before first attack */ /* wait a while before first attack */
@ -395,7 +403,7 @@ HuntTarget(edict_t *self)
void void
FoundTarget(edict_t *self) FoundTarget(edict_t *self)
{ {
if (!self) if (!self|| !self->enemy || !self->enemy->inuse)
{ {
return; return;
} }
@ -697,7 +705,7 @@ M_CheckAttack(edict_t *self)
float chance; float chance;
trace_t tr; trace_t tr;
if (!self) if (!self || !self->enemy || !self->enemy->inuse)
{ {
return false; return false;
} }
@ -899,8 +907,10 @@ ai_checkattack(edict_t *self, float dist)
vec3_t temp; vec3_t temp;
qboolean hesDeadJim; qboolean hesDeadJim;
if (!self) if (!self || !self->enemy || !self->enemy->inuse)
{ {
enemy_vis = false;
return false; return false;
} }
@ -1029,10 +1039,13 @@ ai_checkattack(edict_t *self, float dist)
} }
} }
if (self->enemy)
{
enemy_infront = infront(self, self->enemy); enemy_infront = infront(self, self->enemy);
enemy_range = range(self, self->enemy); enemy_range = range(self, self->enemy);
VectorSubtract(self->enemy->s.origin, self->s.origin, temp); VectorSubtract(self->enemy->s.origin, self->s.origin, temp);
enemy_yaw = vectoyaw(temp); enemy_yaw = vectoyaw(temp);
}
if (self->monsterinfo.attack_state == AS_MISSILE) if (self->monsterinfo.attack_state == AS_MISSILE)
{ {
@ -1073,7 +1086,7 @@ ai_run(edict_t *self, float dist)
float left, center, right; float left, center, right;
vec3_t left_target, right_target; vec3_t left_target, right_target;
if (!self) if (!self || !self->enemy || !self->enemy->inuse)
{ {
return; return;
} }