Files
Yogstation/code/game/machinery/computer/teleporter.dm
Emmett Gaines 825ab4def4 [512] The great \ref purge (#31824)
* The great \ref purge

* cleanup
2017-10-28 17:20:04 -04:00

212 lines
6.8 KiB
Plaintext

/obj/machinery/computer/teleporter
name = "teleporter control console"
desc = "Used to control a linked teleportation Hub and Station."
icon_screen = "teleport"
icon_keyboard = "teleport_key"
light_color = LIGHT_COLOR_BLUE
circuit = /obj/item/circuitboard/computer/teleporter
var/obj/item/device/gps/locked
var/regime_set = "Teleporter"
var/id
var/obj/machinery/teleport/station/power_station
var/calibrating
var/turf/target //Used for one-time-use teleport cards (such as clown planet coordinates.)
//Setting this to 1 will set src.locked to null after a player enters the portal and will not allow hand-teles to open portals to that location.
/obj/machinery/computer/teleporter/Initialize()
. = ..()
id = "[rand(1000, 9999)]"
link_power_station()
/obj/machinery/computer/teleporter/Destroy()
if (power_station)
power_station.teleporter_console = null
power_station = null
return ..()
/obj/machinery/computer/teleporter/proc/link_power_station()
if(power_station)
return
for(dir in GLOB.cardinals)
power_station = locate(/obj/machinery/teleport/station, get_step(src, dir))
if(power_station)
break
return power_station
/obj/machinery/computer/teleporter/attackby(obj/I, mob/living/user, params)
if(istype(I, /obj/item/device/gps))
var/obj/item/device/gps/L = I
if(L.locked_location && !(stat & (NOPOWER|BROKEN)))
if(!user.transferItemToLoc(L, src))
to_chat(user, "<span class='warning'>\the [I] is stuck to your hand, you cannot put it in \the [src]!</span>")
return
locked = L
to_chat(user, "<span class='caution'>You insert the GPS device into the [name]'s slot.</span>")
else
return ..()
/obj/machinery/computer/teleporter/attack_ai(mob/user)
return attack_hand(user)
/obj/machinery/computer/teleporter/attack_hand(mob/user)
if(..())
return
interact(user)
/obj/machinery/computer/teleporter/interact(mob/user)
var/data = "<h3>Teleporter Status</h3>"
if(!power_station)
data += "<div class='statusDisplay'>No power station linked.</div>"
else if(!power_station.teleporter_hub)
data += "<div class='statusDisplay'>No hub linked.</div>"
else
data += "<div class='statusDisplay'>Current regime: [regime_set]<BR>"
data += "Current target: [(!target) ? "None" : "[get_area(target)] [(regime_set != "Gate") ? "" : "Teleporter"]"]<BR>"
if(calibrating)
data += "Calibration: <font color='yellow'>In Progress</font>"
else if(power_station.teleporter_hub.calibrated || power_station.teleporter_hub.accurate >= 3)
data += "Calibration: <font color='green'>Optimal</font>"
else
data += "Calibration: <font color='red'>Sub-Optimal</font>"
data += "</div><BR>"
data += "<A href='?src=[REF(src)];regimeset=1'>Change regime</A><BR>"
data += "<A href='?src=[REF(src)];settarget=1'>Set target</A><BR>"
if(locked)
data += "<BR><A href='?src=[REF(src)];locked=1'>Get target from memory</A><BR>"
data += "<A href='?src=[REF(src)];eject=1'>Eject GPS device</A><BR>"
else
data += "<BR><span class='linkOff'>Get target from memory</span><BR>"
data += "<span class='linkOff'>Eject GPS device</span><BR>"
data += "<BR><A href='?src=[REF(src)];calibrate=1'>Calibrate Hub</A>"
var/datum/browser/popup = new(user, "teleporter", name, 400, 400)
popup.set_content(data)
popup.open()
/obj/machinery/computer/teleporter/Topic(href, href_list)
if(..())
return
if(href_list["eject"])
eject()
updateDialog()
return
if(!check_hub_connection())
say("Error: Unable to detect hub.")
return
if(calibrating)
say("Error: Calibration in progress. Stand by.")
return
if(href_list["regimeset"])
power_station.engaged = 0
power_station.teleporter_hub.update_icon()
power_station.teleporter_hub.calibrated = 0
reset_regime()
if(href_list["settarget"])
power_station.engaged = 0
power_station.teleporter_hub.update_icon()
power_station.teleporter_hub.calibrated = 0
set_target(usr)
if(href_list["locked"])
power_station.engaged = 0
power_station.teleporter_hub.update_icon()
power_station.teleporter_hub.calibrated = 0
target = get_turf(locked.locked_location)
if(href_list["calibrate"])
if(!target)
say("Error: No target set to calibrate to.")
return
if(power_station.teleporter_hub.calibrated || power_station.teleporter_hub.accurate >= 3)
say("Hub is already calibrated!")
return
say("Processing hub calibration to target...")
calibrating = 1
spawn(50 * (3 - power_station.teleporter_hub.accurate)) //Better parts mean faster calibration
calibrating = 0
if(check_hub_connection())
power_station.teleporter_hub.calibrated = 1
say("Calibration complete.")
else
say("Error: Unable to detect hub.")
updateDialog()
updateDialog()
/obj/machinery/computer/teleporter/proc/check_hub_connection()
if(!power_station)
return FALSE
if(!power_station.teleporter_hub)
return FALSE
return TRUE
/obj/machinery/computer/teleporter/proc/reset_regime()
target = null
if(regime_set == "Teleporter")
regime_set = "Gate"
else
regime_set = "Teleporter"
/obj/machinery/computer/teleporter/proc/eject()
if(locked)
locked.forceMove(get_turf(src))
locked = null
/obj/machinery/computer/teleporter/proc/set_target(mob/user)
var/list/L = list()
var/list/areaindex = list()
if(regime_set == "Teleporter")
for(var/obj/item/device/radio/beacon/R in GLOB.teleportbeacons)
var/turf/T = get_turf(R)
if(!T)
continue
if(T.z == ZLEVEL_CENTCOM || T.z > ZLEVEL_SPACEMAX)
continue
L[avoid_assoc_duplicate_keys(T.loc.name, areaindex)] = R
for(var/obj/item/implant/tracking/I in GLOB.tracked_implants)
if(!I.imp_in || !ismob(I.loc))
continue
else
var/mob/M = I.loc
if(M.stat == DEAD)
if(M.timeofdeath + 6000 < world.time)
continue
var/turf/T = get_turf(M)
if(!T)
continue
if(T.z == ZLEVEL_CENTCOM)
continue
L[avoid_assoc_duplicate_keys(M.real_name, areaindex)] = I
var/desc = input("Please select a location to lock in.", "Locking Computer") as null|anything in L
target = L[desc]
else
var/list/S = power_station.linked_stations
if(!S.len)
to_chat(user, "<span class='alert'>No connected stations located.</span>")
return
for(var/obj/machinery/teleport/station/R in S)
var/turf/T = get_turf(R)
if(!T || !R.teleporter_hub || !R.teleporter_console)
continue
if(T.z == ZLEVEL_CENTCOM || T.z > ZLEVEL_SPACEMAX)
continue
L[avoid_assoc_duplicate_keys(T.loc.name, areaindex)] = R
var/desc = input("Please select a station to lock in.", "Locking Computer") as null|anything in L
target = L[desc]
if(target)
var/obj/machinery/teleport/station/trg = target
trg.linked_stations |= power_station
trg.stat &= ~NOPOWER
if(trg.teleporter_hub)
trg.teleporter_hub.stat &= ~NOPOWER
trg.teleporter_hub.update_icon()
if(trg.teleporter_console)
trg.teleporter_console.stat &= ~NOPOWER
trg.teleporter_console.update_icon()