Files
CHOMPStation2/code/modules/overmap/ships/computers/ship.dm
Leshana 73c4809d26 Add proc set_viewsize() to allow hooking actions when client.view is changed.
- Proc is on mob to simplify the standard use case; maybe someday actually save it there too if desired.
2020-03-15 17:59:17 -04:00

97 lines
3.4 KiB
Plaintext

/*
While these computers can be placed anywhere, they will only function if placed on either a non-space, non-shuttle turf
with an /obj/effect/overmap/visitable/ship present elsewhere on that z level, or else placed in a shuttle area with an /obj/effect/overmap/visitable/ship
somewhere on that shuttle. Subtypes of these can be then used to perform ship overmap movement functions.
*/
/obj/machinery/computer/ship
var/obj/effect/overmap/visitable/ship/linked
var/list/viewers // Weakrefs to mobs in direct-view mode.
var/extra_view = 0 // how much the view is increased by when the mob is in overmap mode.
// A late init operation called in SSshuttles, used to attach the thing to the right ship.
/obj/machinery/computer/ship/proc/attempt_hook_up(obj/effect/overmap/visitable/ship/sector)
if(!istype(sector))
return
if(sector.check_ownership(src))
linked = sector
return 1
/obj/machinery/computer/ship/proc/sync_linked()
var/obj/effect/overmap/visitable/ship/sector = map_sectors["[z]"]
if(!sector)
return
return attempt_hook_up_recursive(sector)
/obj/machinery/computer/ship/proc/attempt_hook_up_recursive(obj/effect/overmap/visitable/ship/sector)
if(attempt_hook_up(sector))
return sector
for(var/obj/effect/overmap/visitable/ship/candidate in sector)
if((. = .(candidate)))
return
/obj/machinery/computer/ship/proc/display_reconnect_dialog(var/mob/user, var/flavor)
var/datum/browser/popup = new (user, "[src]", "[src]")
popup.set_content("<center><strong><font color = 'red'>Error</strong></font><br>Unable to connect to [flavor].<br><a href='?src=\ref[src];sync=1'>Reconnect</a></center>")
popup.open()
// In computer_shims for now - we had to define it.
// /obj/machinery/computer/ship/interface_interact(var/mob/user)
// ui_interact(user)
// return TRUE
/obj/machinery/computer/ship/OnTopic(var/mob/user, var/list/href_list)
if(..())
return TOPIC_HANDLED
if(href_list["sync"])
sync_linked()
return TOPIC_REFRESH
if(href_list["close"])
unlook(user)
user.unset_machine()
return TOPIC_HANDLED
return TOPIC_NOACTION
// Management of mob view displacement. look to shift view to the ship on the overmap; unlook to shift back.
/obj/machinery/computer/ship/proc/look(var/mob/user)
if(linked)
user.reset_view(linked)
user.set_viewsize(world.view + extra_view)
GLOB.moved_event.register(user, src, /obj/machinery/computer/ship/proc/unlook)
// TODO GLOB.stat_set_event.register(user, src, /obj/machinery/computer/ship/proc/unlook)
LAZYDISTINCTADD(viewers, weakref(user))
/obj/machinery/computer/ship/proc/unlook(var/mob/user)
user.reset_view()
user.set_viewsize() // reset to default
GLOB.moved_event.unregister(user, src, /obj/machinery/computer/ship/proc/unlook)
// TODO GLOB.stat_set_event.unregister(user, src, /obj/machinery/computer/ship/proc/unlook)
LAZYREMOVE(viewers, weakref(user))
/obj/machinery/computer/ship/proc/viewing_overmap(mob/user)
return (weakref(user) in viewers)
/obj/machinery/computer/ship/CouldNotUseTopic(mob/user)
. = ..()
unlook(user)
/obj/machinery/computer/ship/CouldUseTopic(mob/user)
. = ..()
if(viewing_overmap(user))
look(user)
/obj/machinery/computer/ship/check_eye(var/mob/user)
if (!get_dist(user, src) > 1 || user.blinded || !linked )
unlook(user)
return -1
else
return 0
/obj/machinery/computer/ship/sensors/Destroy()
sensors = null
if(LAZYLEN(viewers))
for(var/weakref/W in viewers)
var/M = W.resolve()
if(M)
unlook(M)
. = ..()