diff --git a/code/modules/mob/living/simple_animal/hostile/bear.dm b/code/modules/mob/living/simple_animal/hostile/bear.dm index 3f1fdd5ccfb..99d6ec34d09 100644 --- a/code/modules/mob/living/simple_animal/hostile/bear.dm +++ b/code/modules/mob/living/simple_animal/hostile/bear.dm @@ -73,7 +73,7 @@ stop_automated_movement = 1 var/found_mob = 0 if(target && target in ListTargets()) - if(!(SA_attackable(target))) + if(CanAttack(target)) stance_step = max(0, stance_step) //If we have not seen a mob in a while, the stance_step will be negative, we need to reset it to 0 as soon as we see a mob again. stance_step++ found_mob = 1 diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm index 82cfba93704..a91d432033e 100644 --- a/code/modules/mob/living/simple_animal/hostile/hostile.dm +++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm @@ -25,16 +25,12 @@ T = F break + if(!CanAttack(A)) + continue + if(isliving(A)) - var/mob/living/L = A - if(L.faction == src.faction && !attack_same) - continue - else if(L in friends) - continue - else - if(!L.stat) - T = L - break + T = A + break else if(istype(A, /obj/mecha)) // Our line of sight stuff was already done in ListTargets(). var/obj/mecha/M = A @@ -44,6 +40,17 @@ return T +/mob/living/simple_animal/hostile/CanAttack(var/atom/the_target) + if(!..()) + return 0 + if(isliving(the_target)) + var/mob/living/L = the_target + if(L.faction == src.faction && !attack_same) + return 0 + else if(L in friends) + return 0 + return 1 + /mob/living/simple_animal/hostile/proc/GiveTarget(var/new_target) target = new_target if(target != null) @@ -58,7 +65,7 @@ /mob/living/simple_animal/hostile/proc/MoveToTarget() stop_automated_movement = 1 - if(!target || SA_attackable(target)) + if(!target || !CanAttack(target)) LoseTarget() if(target in ListTargets()) if(ranged) @@ -73,7 +80,7 @@ /mob/living/simple_animal/hostile/proc/AttackTarget() stop_automated_movement = 1 - if(!target || SA_attackable(target)) + if(!target || !CanAttack(target)) LoseTarget() return 0 if(!(target in ListTargets())) diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index bf0c5fc849c..64d25530f96 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -461,13 +461,15 @@ if(health < 1 && stat != DEAD) Die() -/mob/living/simple_animal/proc/SA_attackable(target) - if (isliving(target)) - var/mob/living/L = target - if(!L.stat) +/mob/living/simple_animal/proc/CanAttack(var/atom/the_target) + if(see_invisible < the_target.invisibility) + return 0 + if (isliving(the_target)) + var/mob/living/L = the_target + if(L.stat != CONSCIOUS) return 0 - if (istype(target,/obj/mecha)) - var/obj/mecha/M = target + if (istype(the_target, /obj/mecha)) + var/obj/mecha/M = the_target if (M.occupant) return 0 return 1