From 8458dc952ce9821094b2a6f7e3dd68b3e2387189 Mon Sep 17 00:00:00 2001
From: GupGup <33478354+GupGup@users.noreply.github.com>
Date: Wed, 22 Nov 2017 16:23:26 -0500
Subject: [PATCH 1/2] Fixes hostile mobs attacking surrounding tiles when
trying to attack someone: the stunning finale
---
code/__HELPERS/game.dm | 1 +
.../simple_animal/hostile/gorilla/gorilla.dm | 4 +-
.../living/simple_animal/hostile/hostile.dm | 52 ++++++++++++++-----
.../mob/living/simple_animal/hostile/mimic.dm | 2 +-
.../living/simple_animal/hostile/statue.dm | 2 +-
5 files changed, 45 insertions(+), 16 deletions(-)
diff --git a/code/__HELPERS/game.dm b/code/__HELPERS/game.dm
index 7af9bf2280..b5d75a6f63 100644
--- a/code/__HELPERS/game.dm
+++ b/code/__HELPERS/game.dm
@@ -311,6 +311,7 @@
else
return get_step(start, EAST)
+
/proc/try_move_adjacent(atom/movable/AM)
var/turf/T = get_turf(AM)
for(var/direction in GLOB.cardinals)
diff --git a/code/modules/mob/living/simple_animal/hostile/gorilla/gorilla.dm b/code/modules/mob/living/simple_animal/hostile/gorilla/gorilla.dm
index e0afdefd6b..84bb54f242 100644
--- a/code/modules/mob/living/simple_animal/hostile/gorilla/gorilla.dm
+++ b/code/modules/mob/living/simple_animal/hostile/gorilla/gorilla.dm
@@ -67,7 +67,7 @@
var/mob/living/L = target
if(prob(80))
var/atom/throw_target = get_edge_target_turf(L, dir)
- L.throw_at(throw_target, rand(1,2), 7, src)
+ L.throw_at(throw_target, rand(1,2), 7, src)
else
L.Knockdown(20)
visible_message("[src] knocks [L] down!")
@@ -76,9 +76,11 @@
var/list/parts = target_bodyparts(target)
return ..() && !istype(the_target, /mob/living/carbon/monkey) && (!parts || parts.len > 3)
+
/mob/living/simple_animal/hostile/gorilla/CanSmashTurfs(turf/T)
return iswallturf(T)
+
/mob/living/simple_animal/hostile/gorilla/gib(no_brain)
if(!no_brain)
var/mob/living/brain/B = new(drop_location())
diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm
index f1b3043447..b3ad02af08 100644
--- a/code/modules/mob/living/simple_animal/hostile/hostile.dm
+++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm
@@ -14,7 +14,7 @@
var/list/emote_taunt = list()
var/taunt_chance = 0
-//typecache of things this mob will attack in DestroySurroundings() if it has environment_smash
+//typecache of things this mob will attack in DestroyPathToTarget() if it has environment_smash
var/list/environment_target_typecache = list(
/obj/machinery/door/window,
/obj/structure/window,
@@ -84,7 +84,8 @@
EscapeConfinement()
if(AICanContinue(possible_targets))
- DestroySurroundings()
+ if(!QDELETED(target) && !targets_from.Adjacent(target))
+ DestroyPathToTarget()
if(!MoveToTarget(possible_targets)) //if we lose our target
if(AIShouldSleep(possible_targets)) // we try to acquire a new one
toggle_ai(AI_IDLE) // otherwise we go idle
@@ -371,24 +372,49 @@
P.preparePixelProjectile(targeted_atom, src)
P.fire()
return P
+<<<<<<< HEAD
+=======
+
+
+>>>>>>> ce82a2e... Fixes hostile mobs attacking surrounding tiles when trying to attack someone: the stunning finale (#32699)
/mob/living/simple_animal/hostile/proc/CanSmashTurfs(turf/T)
return iswallturf(T) || ismineralturf(T)
-/mob/living/simple_animal/hostile/proc/DestroySurroundings()
+
+/mob/living/simple_animal/hostile/proc/DestroyObjectsInDirection(direction)
+ var/turf/T = get_step(targets_from, direction)
+ if(T.Adjacent(targets_from))
+ if(CanSmashTurfs(T))
+ T.attack_animal(src)
+ for(var/a in T)
+ var/atom/A = a
+ if(is_type_in_typecache(A, environment_target_typecache) && !A.IsObscured())
+ A.attack_animal(src)
+ return
+
+
+/mob/living/simple_animal/hostile/proc/DestroyPathToTarget()
+ if(environment_smash)
+ EscapeConfinement()
+ var/dir_to_target = get_dir(targets_from, target)
+ var/dir_list = list()
+ if(dir_to_target in GLOB.diagonals) //it's diagonal, so we need two directions to hit
+ for(var/direction in GLOB.cardinals)
+ if(direction & dir_to_target)
+ dir_list += direction
+ else
+ dir_list += dir_to_target
+ for(var/direction in dir_list) //now we hit all of the directions we got in this fashion, since it's the only directions we should actually need
+ DestroyObjectsInDirection(direction)
+
+
+mob/living/simple_animal/hostile/proc/DestroySurroundings() // for use with megafauna destroying everything around them
if(environment_smash)
EscapeConfinement()
for(var/dir in GLOB.cardinals)
- var/turf/T = get_step(targets_from, dir)
- if(CanSmashTurfs(T))
- if(T.Adjacent(targets_from))
- T.attack_animal(src)
- for(var/a in T)
- var/atom/A = a
- if(!A.Adjacent(targets_from))
- continue
- if(is_type_in_typecache(A, environment_target_typecache) && !A.IsObscured())
- A.attack_animal(src)
+ DestroyObjectsInDirection(dir)
+
/mob/living/simple_animal/hostile/proc/EscapeConfinement()
diff --git a/code/modules/mob/living/simple_animal/hostile/mimic.dm b/code/modules/mob/living/simple_animal/hostile/mimic.dm
index 83291d7822..0c7edd0334 100644
--- a/code/modules/mob/living/simple_animal/hostile/mimic.dm
+++ b/code/modules/mob/living/simple_animal/hostile/mimic.dm
@@ -45,7 +45,7 @@
for(var/obj/item/I in loc)
I.loc = src
-/mob/living/simple_animal/hostile/mimic/crate/DestroySurroundings()
+/mob/living/simple_animal/hostile/mimic/crate/DestroyPathToTarget()
..()
if(prob(90))
icon_state = "[initial(icon_state)]open"
diff --git a/code/modules/mob/living/simple_animal/hostile/statue.dm b/code/modules/mob/living/simple_animal/hostile/statue.dm
index e5aa946b00..5d30a210a8 100644
--- a/code/modules/mob/living/simple_animal/hostile/statue.dm
+++ b/code/modules/mob/living/simple_animal/hostile/statue.dm
@@ -95,7 +95,7 @@
else
return ..()
-/mob/living/simple_animal/hostile/statue/DestroySurroundings()
+/mob/living/simple_animal/hostile/statue/DestroyPathToTarget()
if(!can_be_seen(get_turf(loc)))
..()
From c97e8805f6fd181f9596e7ff0a0017ed636dcfb3 Mon Sep 17 00:00:00 2001
From: deathride58
Date: Wed, 22 Nov 2017 17:53:36 -0500
Subject: [PATCH 2/2] Update hostile.dm
---
code/modules/mob/living/simple_animal/hostile/hostile.dm | 4 ----
1 file changed, 4 deletions(-)
diff --git a/code/modules/mob/living/simple_animal/hostile/hostile.dm b/code/modules/mob/living/simple_animal/hostile/hostile.dm
index b3ad02af08..10d9fd93d7 100644
--- a/code/modules/mob/living/simple_animal/hostile/hostile.dm
+++ b/code/modules/mob/living/simple_animal/hostile/hostile.dm
@@ -372,12 +372,8 @@
P.preparePixelProjectile(targeted_atom, src)
P.fire()
return P
-<<<<<<< HEAD
-
-=======
->>>>>>> ce82a2e... Fixes hostile mobs attacking surrounding tiles when trying to attack someone: the stunning finale (#32699)
/mob/living/simple_animal/hostile/proc/CanSmashTurfs(turf/T)
return iswallturf(T) || ismineralturf(T)