From f12dacb099ad3d0cbca9735e507574fa945983a5 Mon Sep 17 00:00:00 2001 From: EgorDinamit Date: Tue, 1 Aug 2023 19:44:03 +0300 Subject: [PATCH] Fixes trajectory safety check of AI --- code/modules/ai/ai_holder_combat.dm | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/code/modules/ai/ai_holder_combat.dm b/code/modules/ai/ai_holder_combat.dm index 35ab2340bdb..69996a72b47 100644 --- a/code/modules/ai/ai_holder_combat.dm +++ b/code/modules/ai/ai_holder_combat.dm @@ -132,21 +132,20 @@ // This will hold a list of all mobs in a line, even those behind the target, and possibly the wall. // By default the test projectile goes through things like glass and grilles, which is desirable as otherwise the AI won't try to shoot through windows. - var/hit_thing = check_trajectory(AM, holder) // This isn't always reliable but its better than the previous method. + var/hit_things = check_trajectory(AM, holder) // This isn't always reliable but its better than the previous method. // Test to see if the primary target actually has a chance to get hit. // We'll fire anyways if not, if we have conserve_ammo turned off. var/would_hit_primary_target = FALSE - if (hit_thing == AM) + if(AM in hit_things) would_hit_primary_target = TRUE ai_log("test_projectile_safety() : Test projectile did[!would_hit_primary_target ? " NOT " : " "]hit \the [AM]", AI_LOG_DEBUG) // Make sure we don't have a chance to shoot our friends. - var/atom/A = hit_thing - ai_log("test_projectile_safety() : Evaluating \the [A] ([A.type]).", AI_LOG_TRACE) - if (isliving(A)) // Don't shoot at our friends, even if they're behind the target, as RNG can make them get hit. - var/mob/living/L = A - if (holder.IIsAlly(L)) + ai_log("test_projectile_safety() : Evaluating \the chance of hitting allies.", AI_LOG_TRACE) + for(var/mob/living/L in hit_things) + // Don't shoot at our friends, even if they're behind the target, as RNG can make them get hit. + if(holder.IIsAlly(L) && L.stat != DEAD) ai_log("test_projectile_safety() : Would threaten ally, exiting with FALSE.", AI_LOG_DEBUG) return FALSE