diff --git a/code/game/objects/items/implants/implant_abductor.dm b/code/game/objects/items/implants/implant_abductor.dm index 5c8d822ec4f..dc127a2c05b 100644 --- a/code/game/objects/items/implants/implant_abductor.dm +++ b/code/game/objects/items/implants/implant_abductor.dm @@ -13,22 +13,55 @@ to_chat(imp_in, span_warning("You must wait [timeleft(on_cooldown)*0.1] seconds to use [src] again!")) return - home.Retrieve(imp_in,1) + if(isnull(home) && !link_pad()) + imp_in.balloon_alert(imp_in, "no teleport pads detected!") + return + + home.Retrieve(imp_in) on_cooldown = addtimer(VARSET_CALLBACK(src, on_cooldown, null), cooldown , TIMER_STOPPABLE) /obj/item/implant/abductor/implant(mob/living/target, mob/user, silent = FALSE, force = FALSE) - if(..()) - var/obj/machinery/abductor/console/console - if(ishuman(target)) - var/datum/antagonist/abductor/A = target.mind.has_antag_datum(/datum/antagonist/abductor) - if(A) - console = get_abductor_console(A.team.team_number) - home = console.pad + if(!..()) + return FALSE - if(!home) - var/list/consoles = list() - for(var/obj/machinery/abductor/console/C in GLOB.machines) - consoles += C - console = pick(consoles) - home = console.pad + link_pad() + return TRUE + +/** + * Manages the process of linking a recall implant to an abductor pad + * + * Attempts to link the abductor implant to an abductor console. First, it tries to do so through the abductor's antag datum + * If not, a random teleport pad will be defaulted to. Returns TRUE if a home is found, and FALSE is one somehow is not. + */ + +/obj/item/implant/abductor/proc/link_pad() + if(home) return TRUE + + var/obj/machinery/abductor/console/console + if(ishuman(imp_in)) + var/datum/antagonist/abductor/new_abductor = imp_in.mind.has_antag_datum(/datum/antagonist/abductor) + if(new_abductor) + console = get_abductor_console(new_abductor.team.team_number) + if(!console) + WARNING("Attempted to link [name] within [imp_in] to a pad using their abductor antagonist datum, however no associated machinery exists for their team.") + return FALSE + home = console.pad + + if(home) + return TRUE + + else //If we still cannot find a home associated with our team, we just pick a random pad and make it our own. + var/list/consoles = list() + for(var/obj/machinery/abductor/console/found_console in GLOB.machines) + consoles += found_console + console = pick(consoles) + if(console) + home = console.pad + + if(home) + return TRUE + + stack_trace("[name] within [imp_in] failed to find any abductor machinery to connect to.") + + return FALSE //We somehow couldn't find any pads (maybe they're not loaded in yet)