Adds Virtual Mobs (#14718)

This commit is contained in:
SleepyGemmy
2022-08-29 21:57:36 +02:00
committed by GitHub
parent 512e77353e
commit b769ffa1ab
21 changed files with 218 additions and 107 deletions
@@ -16,7 +16,7 @@
loc = null
my_client = client
sight |= SEE_TURFS
set_sight(sight|SEE_TURFS)
player_list |= src
client.playtitlemusic()
+9 -11
View File
@@ -860,7 +860,7 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
set category = "Ghost"
ghostvision = !(ghostvision)
updateghostsight()
to_chat(usr, "You [(ghostvision?"now":"no longer")] have ghost vision.")
to_chat(usr, "You [(ghostvision ? "now" : "no longer")] have ghost vision.")
/mob/abstract/observer/verb/toggle_darkness()
set name = "Toggle Darkness"
@@ -872,21 +872,19 @@ This is the proc mobs get to turn into a ghost. Forked from ghostize due to comp
//if they are on a restricted level, then set the ghost vision for them.
if(on_restricted_level())
//On the restricted level they have the same sight as the mob
sight &= ~(SEE_TURFS | SEE_MOBS | SEE_OBJS)
see_in_dark = 2
see_invisible = SEE_INVISIBLE_OBSERVER
set_sight(sight&(~SEE_TURFS)&(~SEE_MOBS)&(~SEE_OBJS))
set_see_in_dark(2)
set_see_invisible(SEE_INVISIBLE_OBSERVER)
else
//Outside of the restrcited level, they have enhanced vision
sight |= (SEE_TURFS | SEE_MOBS | SEE_OBJS)
see_in_dark = 100
see_invisible = SEE_INVISIBLE_LEVEL_TWO
set_sight(sight|SEE_TURFS|SEE_MOBS|SEE_OBJS)
set_see_in_dark(100)
set_see_invisible(SEE_INVISIBLE_LEVEL_TWO)
if (!seedarkness)
see_invisible = SEE_INVISIBLE_NOLIGHTING
set_see_invisible(SEE_INVISIBLE_NOLIGHTING)
else
see_invisible = SEE_INVISIBLE_OBSERVER
if (!ghostvision)
see_invisible = SEE_INVISIBLE_LIVING
set_see_invisible(ghostvision ? SEE_INVISIBLE_OBSERVER : SEE_INVISIBLE_LIVING)
updateghostimages()
@@ -0,0 +1,4 @@
var/global/const/VIRTUAL_ABILITY_NONE = 0
var/global/const/VIRTUAL_ABILITY_HEAR = 1
var/global/const/VIRTUAL_ABILITY_SEE = 2
var/global/const/VIRTUAL_ABILITY_ALL = (~VIRTUAL_ABILITY_NONE)
+69
View File
@@ -0,0 +1,69 @@
//
// Virtual Mob
//
var/global/list/all_virtual_listeners = list()
/mob/abstract/observer/virtual
icon = 'icons/mob/abstract/virtual.dmi'
invisibility = INVISIBILITY_SYSTEM
see_in_dark = SEE_IN_DARK_DEFAULT
see_invisible = SEE_INVISIBLE_LIVING
sight = SEE_SELF
virtual_mob = null
no_z_overlay = TRUE
var/atom/movable/host
var/host_type = /atom/movable
var/abilities = VIRTUAL_ABILITY_HEAR|VIRTUAL_ABILITY_SEE
var/list/broadcast_methods
var/static/list/overlay_icons
/mob/abstract/observer/virtual/New(var/location, var/atom/movable/host)
..()
if(!istype(host, host_type))
CRASH("Received an unexpected host type. Expected [host_type], was [log_info_line(host)].")
src.host = host
moved_event.register(host, src, /atom/movable/proc/move_to_turf_or_null)
all_virtual_listeners += src
update_icon()
/mob/abstract/observer/virtual/Initialize()
. = ..()
STOP_PROCESSING(SSmob, src)
/mob/abstract/observer/virtual/Destroy()
moved_event.unregister(host, src, /atom/movable/proc/move_to_turf_or_null)
all_virtual_listeners -= src
host = null
return ..()
/mob/abstract/observer/virtual/update_icon()
if(!overlay_icons)
overlay_icons = list()
for(var/i_state in icon_states(icon))
overlay_icons[i_state] = image(icon = icon, icon_state = i_state)
overlays.Cut()
if(abilities & VIRTUAL_ABILITY_HEAR)
overlays += overlay_icons["hear"]
if(abilities & VIRTUAL_ABILITY_SEE)
overlays += overlay_icons["see"]
//
// Virtual Mob Creation
//
/atom/movable
var/mob/abstract/observer/virtual/virtual_mob
/atom/movable/Initialize()
. = ..()
if(shall_have_virtual_mob())
virtual_mob = new virtual_mob(get_turf(src), src)
/atom/movable/proc/shall_have_virtual_mob()
return ispath(initial(virtual_mob))
@@ -0,0 +1,13 @@
/proc/mobs_in_range(var/atom/movable/AM)
. = list()
for(var/mob/abstract/observer/virtual/v_mob in range(world.view, get_turf(AM)))
if(ismob(v_mob.host))
. += v_mob.host
/proc/clients_in_range(var/atom/movable/AM)
. = list()
for(var/mob/abstract/observer/virtual/v_mob in range(world.view, get_turf(AM)))
if(ismob(v_mob.host))
var/mob/M = v_mob.host
if(M.client)
. |= M.client
+22
View File
@@ -0,0 +1,22 @@
/mob/abstract/observer/virtual/mob
host_type = /mob
/mob/abstract/observer/virtual/mob/New(var/location, var/mob/host)
..()
sight_set_event.register(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
see_invisible_set_event.register(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
see_in_dark_set_event.register(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
sync_sight(host)
/mob/abstract/observer/virtual/mob/Destroy()
sight_set_event.unregister(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
see_invisible_set_event.unregister(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
see_in_dark_set_event.unregister(host, src, /mob/abstract/observer/virtual/mob/proc/sync_sight)
. = ..()
/mob/abstract/observer/virtual/mob/proc/sync_sight(var/mob/mob_host)
sight = mob_host.sight
see_invisible = mob_host.see_invisible
see_in_dark = mob_host.see_in_dark