Skip to content

Commit

Permalink
Ports the infinity/interbay vision cone system.
Browse files Browse the repository at this point in the history
Added changelog

Put the screen vars into their own object so re-defining each var is no longer necessary.
Addessed a majority of the feedback recieved.
Removed un-used and un-needed code.
  • Loading branch information
virgili555 authored and comma committed Jun 21, 2018
1 parent ac73eee commit 4ed38e8
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 1 deletion.
1 change: 1 addition & 0 deletions baystation12.dme
Expand Up @@ -2494,6 +2494,7 @@
#include "code\modules\virus2\helpers.dm"
#include "code\modules\virus2\isolator.dm"
#include "code\modules\virus2\items_devices.dm"
#include "code\modules\vision_cone\vision_cone.dm"
#include "code\modules\wireless\devices.dm"
#include "code\modules\wireless\interfaces.dm"
#include "code\modules\xenoarcheaology\anomaly_container.dm"
Expand Down
5 changes: 5 additions & 0 deletions code/_onclick/hud/human.dm
Expand Up @@ -20,6 +20,11 @@
var/obj/screen/using
var/obj/screen/inventory/inv_box

if(target.can_have_vision_cone)
var/mob/living/carbon/human/H = mymob
H.vision_cone_overlay = new /obj/screen/fov()
hud_elements |= H.vision_cone_overlay

// Draw the various inventory equipment slots.
var/has_hidden_gear
for(var/gear_slot in hud_data.gear)
Expand Down
6 changes: 6 additions & 0 deletions code/_onclick/hud/robot.dm
Expand Up @@ -10,6 +10,12 @@ var/obj/screen/robot_inventory

var/obj/screen/using

//Fov
var/mob/living/silicon/robot/r = mymob
if(r.can_have_vision_cone)
r.vision_cone_overlay = new /obj/screen/fov()
src.adding += r.vision_cone_overlay

//Radio
using = new /obj/screen()
using.SetName("radio")
Expand Down
9 changes: 9 additions & 0 deletions code/_onclick/hud/screen_objects.dm
Expand Up @@ -409,3 +409,12 @@
usr.update_inv_l_hand(0)
usr.update_inv_r_hand(0)
return 1

/obj/screen/fov
icon = 'icons/mob/vision_cone.dmi'
icon_state = "combat"
name = ""
screen_loc = "SOUTH,WEST"
mouse_opacity = 0
layer = UNDER_HUD_LAYER
plane = HUD_PLANE
4 changes: 4 additions & 0 deletions code/modules/mob/living/carbon/human/human.dm
Expand Up @@ -4,6 +4,7 @@
voice_name = "unknown"
icon = 'icons/mob/human.dmi'
icon_state = "body_m_s"
can_have_vision_cone = FALSE

var/list/hud_list[10]
var/embedded_flag //To check if we've need to roll for damage on movement while an item is imbedded in us.
Expand All @@ -27,6 +28,9 @@
if(mind)
mind.name = real_name

if(species.have_vision_cone)
can_have_vision_cone = TRUE

hud_list[HEALTH_HUD] = new /image/hud_overlay('icons/mob/hud_med.dmi', src, "100")
hud_list[STATUS_HUD] = new /image/hud_overlay('icons/mob/hud.dmi', src, "hudhealthy")
hud_list[LIFE_HUD] = new /image/hud_overlay('icons/mob/hud.dmi', src, "hudhealthy")
Expand Down
2 changes: 2 additions & 0 deletions code/modules/mob/living/carbon/human/species/species.dm
Expand Up @@ -31,6 +31,8 @@
var/tail_blend = ICON_ADD
var/tail_hair

var/have_vision_cone = TRUE

var/list/hair_styles
var/list/facial_hair_styles

Expand Down
Expand Up @@ -32,6 +32,8 @@

reagent_tag = IS_NABBER

have_vision_cone = FALSE

icon_template = 'icons/mob/human_races/r_template_tall.dmi'
icobase = 'icons/mob/human_races/r_nabber.dmi'
deform = 'icons/mob/human_races/r_nabber.dmi'
Expand Down
6 changes: 6 additions & 0 deletions code/modules/mob/living/living.dm
Expand Up @@ -576,6 +576,11 @@ default behaviour is:
for(var/mob/living/carbon/slime/M in view(1,src))
M.UpdateFeed()

for(var/mob/M in oview(src))
M.update_vision_cone()

update_vision_cone()

/mob/living/verb/resist()
set name = "Resist"
set category = "IC"
Expand Down Expand Up @@ -766,6 +771,7 @@ default behaviour is:
if(auras)
for(var/a in auras)
remove_aura(a)

return ..()

/mob/living/proc/melee_accuracy_mods()
Expand Down
3 changes: 3 additions & 0 deletions code/modules/mob/living/living_defines.dm
Expand Up @@ -45,6 +45,9 @@
var/stuttering = null //Carbon
var/slurring = null //Carbon

var/obj/screen/vision_cone_overlay = null
var/can_have_vision_cone = FALSE

var/job = null//Living
var/list/obj/aura/auras = null //Basically a catch-all aura/force-field thing.

Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/silicon/ai/ai.dm
Expand Up @@ -50,6 +50,7 @@ var/list/ai_verbs_default = list(
status_flags = CANSTUN|CANPARALYSE|CANPUSH
shouldnt_see = list(/obj/effect/rune)
maxHealth = 200
can_have_vision_cone = FALSE
var/list/network = list("Exodus")
var/obj/machinery/camera/camera = null
var/list/connected_robots = list()
Expand Down
1 change: 1 addition & 0 deletions code/modules/mob/living/silicon/silicon.dm
Expand Up @@ -2,6 +2,7 @@
gender = NEUTER
voice_name = "synthesized voice"
skillset = /datum/skillset/silicon
can_have_vision_cone = TRUE
var/syndicate = 0
var/const/MAIN_CHANNEL = "Main Frequency"
var/lawchannel = MAIN_CHANNEL // Default channel on which to state laws
Expand Down
4 changes: 3 additions & 1 deletion code/modules/mob/mob.dm
Expand Up @@ -727,6 +727,8 @@
else if( lying != lying_prev )
update_icons()

update_vision_cone()

/mob/proc/reset_layer()
if(lying)
plane = LYING_MOB_PLANE
Expand Down Expand Up @@ -1061,7 +1063,7 @@
else
to_chat(usr, "You must be observing or in the lobby to join the antag pool.")
/mob/proc/is_invisible_to(var/mob/viewer)
return (!alpha || !mouse_opacity || viewer.see_invisible < invisibility)
return (!alpha || !mouse_opacity || viewer.see_invisible < invisibility || (viewer.client && (src in (viewer.client.hidden_mobs || viewer.client.hidden_atoms))))

/client/proc/check_has_body_select()
return mob && mob.hud_used && istype(mob.zone_sel, /obj/screen/zone_sel)
Expand Down
123 changes: 123 additions & 0 deletions code/modules/vision_cone/vision_cone.dm
@@ -0,0 +1,123 @@
/////////////VISION CONE///////////////
// Vision cone code by Honkertron (for Otuska) and Matt.
// This vision cone code allows for mobs and/or items to blocked out from a players field of vision.
// This code makes use of the "cone of effect" proc created by Lummox, contributed by Jtgibson.
//
// More info on that here:
// http://www.byond.com/forum/?post=195138
///////////////////////////////////////

//Defines.
#define OPPOSITE_DIR(D) turn(D, 180)

/client
var/list/hidden_atoms = list()
var/list/hidden_mobs = list()

/proc/cone(atom/center = usr, dir = NORTH, list/list = oview(center))
for(var/atom/O in list) if(!O.InCone(center, dir)) list -= O
return list

/atom/proc/InCone(atom/center = usr, dir = NORTH)
if(get_dist(center, src) == 0 || src == center) return 0
var/d = get_dir(center, src)

if(!d || d == dir) return 1
if(dir & (dir-1))
return (d & ~dir) ? 0 : 1
if(!(d & dir)) return 0
var/dx = abs(x - center.x)
var/dy = abs(y - center.y)
if(dx == dy) return 1
if(dy > dx)
return (dir & (NORTH|SOUTH)) ? 1 : 0
return (dir & (EAST|WEST)) ? 1 : 0

/mob/dead/InCone(mob/center = usr, dir = NORTH)
return

/mob/living/InCone(mob/center = usr, dir = NORTH)
. = ..()
for(var/obj/item/grab/G in center)//TG doesn't have the grab item. But if you're porting it and you do then uncomment this.
if(src == G.affecting)
return 0
else
return .

/mob/proc/update_vision_cone()
return

/mob/living/update_vision_cone()
if(!can_have_vision_cone)
if(vision_cone_overlay)
hide_cone()
return

var/delay = 10
if(src.client)
var/image/I = null
for(I in src.client.hidden_atoms)
I.override = 0
addtimer(CALLBACK(src, .proc/clear_cone_effect, I), delay)
delay += 10

check_fov()
src.client.hidden_atoms = list()
src.client.hidden_mobs = list()
src.vision_cone_overlay.dir = src.dir
if(vision_cone_overlay.alpha != 0)
var/mob/living/M
for(M in cone(src, OPPOSITE_DIR(src.dir), view(10, src)))
I = image("split", M)
I.override = 1
src.client.images += I
src.client.hidden_atoms += I
src.client.hidden_mobs += M
if(src.pulling == M)//If we're pulling them we don't want them to be invisible, too hard to play like that.
I.override = 0

/mob/living/proc/clear_cone_effect(var/image/I)
qdel(I)

/mob/living/proc/SetFov(var/n)
if(!can_have_vision_cone)
return

if(!n)
hide_cone()
else
show_cone()

/mob/living/proc/check_fov()
if(!can_have_vision_cone)
return

if(isnull(vision_cone_overlay))
src.vision_cone_overlay = new /obj/screen/fov()
src.client.screen |= src.vision_cone_overlay

if(resting || lying || client.eye != client.mob)
src.vision_cone_overlay.alpha = 0
return

else if(src.vision_cone_overlay)
show_cone()
else
hide_cone()

//Making these generic procs so you can call them anywhere.
/mob/living/proc/show_cone()
if(!can_have_vision_cone)
return

if(src.vision_cone_overlay)
src.vision_cone_overlay.alpha = 255

/mob/living/proc/hide_cone()
if(src.vision_cone_overlay)
src.vision_cone_overlay.alpha = 0

/mob/living/set_dir()
. = ..()
if(.)
update_vision_cone()
5 changes: 5 additions & 0 deletions html/changelogs/virgie-vision-port.yml
@@ -0,0 +1,5 @@
author: Virgil
delete-after: True
changes:
- rscadd: "Added vision cones to mobs."
- rscdel: "Removed 360 degree vision of other mobs. Items are not effected."
Binary file added icons/mob/vision_cone.dmi
Binary file not shown.

0 comments on commit 4ed38e8

Please sign in to comment.