From 2a161f47277386ec6789d427218591775050e2ff Mon Sep 17 00:00:00 2001 From: CitadelStationBot Date: Mon, 5 Mar 2018 13:01:18 -0600 Subject: [PATCH] [MIRROR] Fix brains in MMIs being unable to pilot mechs (#5808) * Merge pull request #36128 from AutomaticFrenzy/patch/brainmech Fix brains in MMIs being unable to pilot mechs * Fix brains in MMIs being unable to pilot mechs --- code/game/mecha/mecha.dm | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/code/game/mecha/mecha.dm b/code/game/mecha/mecha.dm index 3e29a6f07e..b9dcbbfd03 100644 --- a/code/game/mecha/mecha.dm +++ b/code/game/mecha/mecha.dm @@ -370,15 +370,21 @@ occupant.throw_alert("mech damage", /obj/screen/alert/low_mech_integrity, 3) else occupant.clear_alert("mech damage") - var/actual_loc = occupant.loc - if(istype(actual_loc, /obj/item/device/mmi)) - var/obj/item/device/mmi/M = actual_loc - actual_loc = M.mecha - if(actual_loc != src) //something went wrong - occupant.clear_alert("charge") - occupant.clear_alert("mech damage") - RemoveActions(occupant, human_occupant=1) - occupant = null + var/atom/checking = occupant.loc + // recursive check to handle all cases regarding very nested occupants, + // such as brainmob inside brainitem inside MMI inside mecha + while (!isnull(checking)) + if (isturf(checking)) + // hit a turf before hitting the mecha, seems like they have + // been moved out + occupant.clear_alert("charge") + occupant.clear_alert("mech damage") + RemoveActions(occupant, human_occupant=1) + occupant = null + break + else if (checking == src) + break // all good + checking = checking.loc if(lights) var/lights_energy_drain = 2