Skip to content

Commit

Permalink
Merge pull request #129 from Fluffy-Frontier/upstream-mirror-24405
Browse files Browse the repository at this point in the history
[TG Mirror] Invisibility refactor [MDB IGNORE]
  • Loading branch information
AnywayFarus authored Oct 18, 2023
2 parents 09e8e5c + fc70053 commit b51a7c4
Show file tree
Hide file tree
Showing 40 changed files with 195 additions and 89 deletions.
18 changes: 18 additions & 0 deletions code/__DEFINES/sight.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define INVISIBILITY_NONE 0

#define SEE_INVISIBLE_MINIMUM 5

#define INVISIBILITY_LIGHTING 20
Expand Down Expand Up @@ -57,3 +59,19 @@
/// Bitfield of sight flags that show THINGS but no lighting
/// Since lighting is an underlay on turfs, this is everything but that
#define SEE_AVOID_TURF_BLACKNESS (SEE_MOBS|SEE_OBJS)

//------------------------
// INVISIBILITY PRIORITIES

#define INVISIBILITY_PRIORITY_ADMIN 100
#define INVISIBILITY_PRIORITY_BASIC_ANTI_INVISIBILITY 1
#define INVISIBILITY_PRIORITY_NONE 0

//------------------------
// INVISIBILITY SOURCE IDS
// Though don't feel the need to add one here if you have a simple effect that
// gets added and/or removed in only one place near eachother in the code.

#define INVISIBILITY_SOURCE_INVISIMIN "invisimin"
#define INVISIBILITY_SOURCE_STEALTHMODE "stealthmode"

2 changes: 1 addition & 1 deletion code/__HELPERS/mobs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ GLOBAL_DATUM_INIT(dview_mob, /mob/dview, new)

/mob/dview
name = "INTERNAL DVIEW MOB"
invisibility = 101
invisibility = INVISIBILITY_ABSTRACT
density = FALSE
move_resist = INFINITY
var/ready_to_die = FALSE
Expand Down
2 changes: 1 addition & 1 deletion code/__HELPERS/spatial_info.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
icon_state = null
density = FALSE
move_resist = INFINITY
invisibility = 0
invisibility = INVISIBILITY_NONE
mouse_opacity = MOUSE_OPACITY_TRANSPARENT
logging = null
held_items = null //all of these are list objects that should not exist for something like us
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
if(2 to INFINITY)
var/obj/dummy = new(get_turf(here))
dummy.pass_flags |= PASSTABLE
dummy.invisibility = INVISIBILITY_ABSTRACT
dummy.SetInvisibility(INVISIBILITY_ABSTRACT)
for(var/i in 1 to reach) //Limit it to that many tries
var/turf/T = get_step(dummy, get_dir(dummy, there))
if(dummy.CanReach(there))
Expand Down
2 changes: 1 addition & 1 deletion code/_onclick/hud/parallax/parallax.dm
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ INITIALIZE_IMMEDIATE(/atom/movable/screen/parallax_layer)
var/turf/posobj = get_turf(boss?.eye)
if(!posobj)
return
invisibility = is_station_level(posobj.z) ? 0 : INVISIBILITY_ABSTRACT
SetInvisibility(is_station_level(posobj.z) ? INVISIBILITY_NONE : INVISIBILITY_ABSTRACT, id=type)

/atom/movable/screen/parallax_layer/planet/update_o()
return //Shit won't move
9 changes: 5 additions & 4 deletions code/datums/elements/undertile.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@
src.use_alpha = use_alpha
src.use_anchor = use_anchor


///called when a tile has been covered or uncovered
/datum/element/undertile/proc/hide(atom/movable/source, underfloor_accessibility)
SIGNAL_HANDLER

source.invisibility = underfloor_accessibility < UNDERFLOOR_VISIBLE ? invisibility_level : 0
if(underfloor_accessibility < UNDERFLOOR_VISIBLE)
source.SetInvisibility(invisibility_level, id=type)
else
source.RemoveInvisibility(type)

var/turf/T = get_turf(source)

Expand Down Expand Up @@ -73,11 +75,10 @@
if(use_anchor)
source.set_anchored(FALSE)


/datum/element/undertile/Detach(atom/movable/source, visibility_trait, invisibility_level = INVISIBILITY_MAXIMUM)
. = ..()

hide(source, UNDERFLOOR_INTERACTABLE)

source.RemoveInvisibility(type)

#undef ALPHA_UNDERTILE
71 changes: 71 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@
/// How this atom should react to having its astar blocking checked
var/can_astar_pass = CANASTARPASS_DENSITY

VAR_PRIVATE/list/invisibility_sources
VAR_PRIVATE/current_invisibility_priority = -INFINITY

/**
* Called when an atom is created in byond (built in engine proc)
*
Expand Down Expand Up @@ -2195,3 +2198,71 @@
segment = -segment
SEND_SIGNAL(src, COMSIG_ATOM_SPIN_ANIMATION, speed, loops, segments, segment)
do_spin_animation(speed, loops, segments, segment, parallel)

#define INVISIBILITY_VALUE 1
#define INVISIBILITY_PRIORITY 2

/atom/proc/RecalculateInvisibility()
PRIVATE_PROC(TRUE)

if(!invisibility_sources)
current_invisibility_priority = -INFINITY
invisibility = initial(invisibility)
return

var/highest_priority
var/list/highest_priority_invisibility_data
for(var/entry in invisibility_sources)
var/list/priority_data
if(islist(entry))
priority_data = entry
else
priority_data = invisibility_sources[entry]

var/priority = priority_data[INVISIBILITY_PRIORITY]
if(highest_priority > priority) // In the case of equal priorities, we use the last thing in the list so that more recent changes apply first
continue

highest_priority = priority
highest_priority_invisibility_data = priority_data

current_invisibility_priority = highest_priority
invisibility = highest_priority_invisibility_data[INVISIBILITY_VALUE]

/**
* Sets invisibility according to priority.
* If you want to be able to undo the value you set back to what it would be otherwise,
* you should provide an id here and remove it using RemoveInvisibility(id)
*/
/atom/proc/SetInvisibility(desired_value, id, priority=0)
if(!invisibility_sources)
invisibility_sources = list()

if(id)
invisibility_sources[id] = list(desired_value, priority)
else
invisibility_sources += list(list(desired_value, priority))

if(current_invisibility_priority > priority)
return

RecalculateInvisibility()

/// Removes the specified invisibility source from the tracker
/atom/proc/RemoveInvisibility(source_id)
if(!invisibility_sources)
return

var/list/priority_data = invisibility_sources[source_id]
invisibility_sources -= source_id

if(length(invisibility_sources) == 0)
invisibility_sources = null

if(current_invisibility_priority > priority_data[INVISIBILITY_PRIORITY])
return

RecalculateInvisibility()

#undef INVISIBILITY_VALUE
#undef INVISIBILITY_PRIORITY
4 changes: 2 additions & 2 deletions code/game/machinery/gigabeacon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
. = ..()
var/turf/T = loc
Beacon = new(T)
Beacon.invisibility = INVISIBILITY_MAXIMUM
Beacon.SetInvisibility(INVISIBILITY_MAXIMUM)

AddElement(/datum/element/undertile, TRAIT_T_RAY_VISIBLE)

Expand All @@ -25,6 +25,6 @@
if(QDELETED(Beacon)) //Don't move it out of nullspace BACK INTO THE GAME for the love of god
var/turf/T = loc
Beacon = new(T)
Beacon.invisibility = INVISIBILITY_MAXIMUM
Beacon.SetInvisibility(INVISIBILITY_MAXIMUM)
else if (Beacon.loc != loc)
Beacon.forceMove(loc)
10 changes: 5 additions & 5 deletions code/game/machinery/porta_turret/portable_turret.dm
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ DEFINE_BITFIELD(turret_flags, list(
//This code handles moving the turret around. After all, it's a portable turret!
if(!anchored && !isinspace())
set_anchored(TRUE)
invisibility = INVISIBILITY_MAXIMUM
SetInvisibility(INVISIBILITY_MAXIMUM, id=type)
update_appearance()
to_chat(user, span_notice("You secure the exterior bolts on the turret."))
if(has_cover)
Expand All @@ -336,7 +336,7 @@ DEFINE_BITFIELD(turret_flags, list(
set_anchored(FALSE)
to_chat(user, span_notice("You unsecure the exterior bolts on the turret."))
power_change()
invisibility = 0
RemoveInvisibility(type)
qdel(cover) //deletes the cover, and the turret instance itself becomes its own cover.

else if(I.GetID())
Expand Down Expand Up @@ -407,7 +407,7 @@ DEFINE_BITFIELD(turret_flags, list(
. = ..()
if(.)
power_change()
invisibility = 0
RemoveInvisibility(type)
spark_system.start() //creates some sparks because they look cool
qdel(cover) //deletes the cover - no need on keeping it there!

Expand Down Expand Up @@ -514,7 +514,7 @@ DEFINE_BITFIELD(turret_flags, list(
return
if(machine_stat & BROKEN)
return
invisibility = 0
RemoveInvisibility(type)
raising = 1
if(cover)
flick("popup", cover)
Expand All @@ -539,7 +539,7 @@ DEFINE_BITFIELD(turret_flags, list(
if(cover)
cover.icon_state = "turretCover"
raised = 0
invisibility = 2
SetInvisibility(2, id=type)
update_appearance()

/obj/machinery/porta_turret/proc/assess_perp(mob/living/carbon/human/perp)
Expand Down
6 changes: 3 additions & 3 deletions code/game/machinery/porta_turret/portable_turret_cover.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/obj/machinery/porta_turret_cover/Destroy()
if(parent_turret)
parent_turret.cover = null
parent_turret.invisibility = 0
parent_turret.RemoveInvisibility(type)
parent_turret = null
return ..()

Expand All @@ -43,12 +43,12 @@
if(!parent_turret.anchored)
parent_turret.set_anchored(TRUE)
to_chat(user, span_notice("You secure the exterior bolts on the turret."))
parent_turret.invisibility = 0
parent_turret.RemoveInvisibility(type)
parent_turret.update_appearance()
else
parent_turret.set_anchored(FALSE)
to_chat(user, span_notice("You unsecure the exterior bolts on the turret."))
parent_turret.invisibility = INVISIBILITY_MAXIMUM
parent_turret.SetInvisibility(INVISIBILITY_MAXIMUM, id=type)
parent_turret.update_appearance()
qdel(src)
return
Expand Down
5 changes: 3 additions & 2 deletions code/game/machinery/shieldgen.dm
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,10 @@
/obj/structure/emergency_shield/cult/barrier/proc/Toggle()
set_density(!density)
air_update_turf(TRUE, !density)
invisibility = initial(invisibility)
if(!density)
invisibility = INVISIBILITY_OBSERVER
SetInvisibility(INVISIBILITY_OBSERVER, id=type)
else
RemoveInvisibility(type)

/obj/machinery/shieldgen
name = "anti-breach shielding projector"
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/countdown.dm
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
return round(time_left)

/obj/effect/countdown/arena
invisibility = 0
invisibility = INVISIBILITY_NONE
name = "arena countdown"

/obj/effect/countdown/arena/get_value()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/effects/spawners/random/maintenance.dm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
return ..()

/obj/effect/spawner/random/maintenance/proc/hide()
invisibility = INVISIBILITY_OBSERVER
SetInvisibility(INVISIBILITY_OBSERVER)
alpha = 100

/obj/effect/spawner/random/maintenance/proc/get_effective_lootcount()
Expand Down
2 changes: 1 addition & 1 deletion code/game/objects/items/robot/robot_parts.dm
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
O.laws = M.laws
M.laws.associate(O)

O.invisibility = 0
O.SetInvisibility(INVISIBILITY_NONE)
//Transfer debug settings to new mob
O.custom_name = created_name
O.locked = panel_locked
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@
/obj/machinery/computer/camera_advanced/base_construction/GrantActions(mob/living/user)
..()
//When the eye is in use, make it visible to players so they know when someone is building.
eyeobj.invisibility = 0
SetInvisibility(INVISIBILITY_NONE, id=type)

/obj/machinery/computer/camera_advanced/base_construction/remove_eye_control(mob/living/user)
..()
//Hide the eye when not in use.
eyeobj.invisibility = INVISIBILITY_MAXIMUM
//Set back to default invisibility when not in use.
RemoveInvisibility(type)

/**
* A mob used by [/obj/machinery/computer/camera_advanced/base_construction] for building in specific areas.
Expand All @@ -101,6 +101,7 @@
move_on_shuttle = TRUE
icon = 'icons/obj/mining.dmi'
icon_state = "construction_drone"
invisibility = INVISIBILITY_MAXIMUM
///Reference to the camera console controlling this drone
var/obj/machinery/computer/camera_advanced/base_construction/linked_console

Expand Down
24 changes: 12 additions & 12 deletions code/modules/admin/admin_verbs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ GLOBAL_PROTECT(admin_verbs_poll)
set name = "Invisimin"
set category = "Admin.Game"
set desc = "Toggles ghost-like invisibility (Don't abuse this)"
if(holder && mob)
if(initial(mob.invisibility) == INVISIBILITY_OBSERVER)
to_chat(mob, span_boldannounce("Invisimin toggle failed. You are already an invisible mob like a ghost."), confidential = TRUE)
return
if(mob.invisibility == INVISIBILITY_OBSERVER)
mob.invisibility = initial(mob.invisibility)
to_chat(mob, span_boldannounce("Invisimin off. Invisibility reset."), confidential = TRUE)
else
mob.invisibility = INVISIBILITY_OBSERVER
to_chat(mob, span_adminnotice("<b>Invisimin on. You are now as invisible as a ghost.</b>"), confidential = TRUE)
if(isnull(holder) || isnull(mob))
return
if(mob.invisimin)
mob.invisimin = FALSE
mob.RemoveInvisibility(INVISIBILITY_SOURCE_INVISIMIN)
to_chat(mob, span_boldannounce("Invisimin off. Invisibility reset."), confidential = TRUE)
else
mob.invisimin = TRUE
mob.SetInvisibility(INVISIBILITY_OBSERVER, INVISIBILITY_SOURCE_INVISIMIN, INVISIBILITY_PRIORITY_ADMIN)
to_chat(mob, span_adminnotice("<b>Invisimin on. You are now as invisible as a ghost.</b>"), confidential = TRUE)

/client/proc/check_antagonists()
set name = "Check Antagonists"
Expand Down Expand Up @@ -550,7 +550,7 @@ GLOBAL_PROTECT(admin_verbs_poll)
holder.fakekey = new_key
createStealthKey()
if(isobserver(mob))
mob.invisibility = INVISIBILITY_MAXIMUM //JUST IN CASE
mob.SetInvisibility(INVISIBILITY_ABSTRACT, INVISIBILITY_SOURCE_STEALTHMODE, INVISIBILITY_PRIORITY_ADMIN)
mob.alpha = 0 //JUUUUST IN CASE
mob.name = " "
mob.mouse_opacity = MOUSE_OPACITY_TRANSPARENT
Expand All @@ -564,7 +564,7 @@ GLOBAL_PROTECT(admin_verbs_poll)
/client/proc/disable_stealth_mode()
holder.fakekey = null
if(isobserver(mob))
mob.invisibility = initial(mob.invisibility)
mob.RemoveInvisibility(INVISIBILITY_SOURCE_STEALTHMODE)
mob.alpha = initial(mob.alpha)
if(mob.mind)
if(mob.mind.ghostname)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/abductor/machinery/camera.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
eyeobj.visible_icon = TRUE
eyeobj.icon = 'icons/mob/silicon/cameramob.dmi'
eyeobj.icon_state = "abductor_camera"
eyeobj.invisibility = INVISIBILITY_OBSERVER
eyeobj.SetInvisibility(INVISIBILITY_OBSERVER)

/obj/machinery/computer/camera_advanced/abductor/GrantActions(mob/living/carbon/user)
if(!abduct_created)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/antagonists/blob/overmind.dm
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ GLOBAL_LIST_EMPTY(blob_nodes)
check_area.icon = 'icons/mob/nonhuman-player/blob.dmi'
check_area.icon_state = "blob_shield"
check_area.layer = BELOW_MOB_LAYER
check_area.invisibility = 0
check_area.SetInvisibility(INVISIBILITY_NONE)
check_area.blend_mode = 0

var/datum/antagonist/blob/B = mind.has_antag_datum(/datum/antagonist/blob)
Expand Down
Loading

0 comments on commit b51a7c4

Please sign in to comment.