From 5136ceb12357252e02ef2d153c70eff545750e08 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sat, 31 Aug 2019 10:56:50 +0200 Subject: [PATCH] Try to fix monsters getting stuck by waiting forever for their enemy. 44472722e added some sanity checks to the AI code. The checks in ai_run() are likely wrong because the enemy entity might be already NULL if we arrive their. By aborting early the code is unable to determine a new enemy or return the monster to idle state, so the monster will wait forever for an enemy that'll never come. This happens only in monster vs. monster fights. Never in monster vs. player, that game ends if the player dies. In theory this change should be harmless, because if the enemy entity is gone it won't generate sound targets now be visible. If the game crashes by self->enemy being NULL we've got a problem elsewere. This was reported by @BjossiAlfreds in #483. He also suggested the fix. --- src/game/g_ai.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/game/g_ai.c b/src/game/g_ai.c index 51b9b9ff..a1146019 100644 --- a/src/game/g_ai.c +++ b/src/game/g_ai.c @@ -1131,7 +1131,7 @@ ai_run(edict_t *self, float dist) float left, center, right; vec3_t left_target, right_target; - if (!self || !self->enemy || !self->enemy->inuse) + if (!self) { return; } @@ -1149,8 +1149,7 @@ ai_run(edict_t *self, float dist) if (VectorLength(v) < 64) { - self->monsterinfo.aiflags |= - (AI_STAND_GROUND | AI_TEMP_STAND_GROUND); + self->monsterinfo.aiflags |= (AI_STAND_GROUND | AI_TEMP_STAND_GROUND); self->monsterinfo.stand(self); return; }