Skip to content

Commit 0e92446

Browse files
committed
Initial Commit
Port of: PentestSS13/Pentest#288
1 parent ba50f2e commit 0e92446

File tree

7 files changed

+87
-46
lines changed

7 files changed

+87
-46
lines changed

code/__DEFINES/dcs/signals/signals.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,8 @@
302302
#define COMSIG_TURF_MULTIZ_DEL "turf_multiz_del"
303303
///from base of turf/multiz_turf_new: (turf/source, direction)
304304
#define COMSIG_TURF_MULTIZ_NEW "turf_multiz_new"
305+
///from base of turf/initilize_turf_transparency: (turf/source, direction)
306+
#define COMSIG_TURF_INITIALIZE_TRANSPARENCY "initilize_turf_transparency"
305307
//! from base of turf/proc/afterShuttleMove: (turf/new_turf)
306308
#define COMSIG_TURF_AFTER_SHUTTLE_MOVE "turf_after_shuttle_move"
307309

code/__DEFINES/traits.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ Remember to update _globalvars/traits.dm if you're adding/removing/renaming trai
449449
#define WARPWHISTLE_TRAIT "warpwhistle"
450450
///Turf trait for when a turf is transparent
451451
#define TURF_Z_TRANSPARENT_TRAIT "turf_z_transparent"
452+
///Turf trait for when a transparent turf should display the bottom.
453+
#define TURF_Z_SHOW_BOTTOM_TRAIT "turf_z_show_bottom"
452454
/// Trait applied to slimes by low temperature
453455
#define SLIME_COLD "slime-cold"
454456
/// Trait applied to bots by being tipped over
Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
/datum/element/turf_z_transparency
2-
var/show_bottom_level = FALSE
3-
var/turf/our_turf
2+
element_flags = ELEMENT_DETACH //Important so it is properly cleared out on turf qdel.
43

54
///This proc sets up the signals to handle updating viscontents when turfs above/below update. Handle plane and layer here too so that they don't cover other obs/turfs in Dream Maker
6-
/datum/element/turf_z_transparency/Attach(datum/target, show_bottom_level = TRUE)
5+
/datum/element/turf_z_transparency/Attach(turf/our_turf, show_bottom_level = TRUE)
76
. = ..()
8-
if(!isturf(target))
7+
if(!isturf(our_turf))
98
return ELEMENT_INCOMPATIBLE
109

11-
our_turf = target
12-
13-
src.show_bottom_level = show_bottom_level
14-
1510
our_turf.plane = OPENSPACE_PLANE
1611
our_turf.layer = OPENSPACE_LAYER
1712

18-
RegisterSignal(target, COMSIG_TURF_MULTIZ_DEL, PROC_REF(on_multiz_turf_del), TRUE)
19-
RegisterSignal(target, COMSIG_TURF_MULTIZ_NEW, PROC_REF(on_multiz_turf_new), TRUE)
13+
RegisterSignal(our_turf, COMSIG_TURF_MULTIZ_DEL, PROC_REF(on_multiz_turf_del), TRUE)
14+
RegisterSignal(our_turf, COMSIG_TURF_MULTIZ_NEW, PROC_REF(on_multiz_turf_new), TRUE)
15+
RegisterSignal(our_turf, COMSIG_TURF_INITIALIZE_TRANSPARENCY, PROC_REF(initilize_turf_transparency), TRUE)
2016

2117
ADD_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT)
22-
23-
24-
update_multiz(our_turf, TRUE, TRUE)
18+
if(show_bottom_level) //Sets up the trait to check when initializing the turf elsewhere.
19+
ADD_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT, TURF_TRAIT)
2520

2621
/datum/element/turf_z_transparency/Detach(datum/source, force)
2722
. = ..()
2823
var/turf/our_turf = source
29-
our_turf.vis_contents.len = 0
24+
our_turf.vis_contents.len = 0 //vis_contents are handled by Destroy() when a turf is qdel'd, but you could also call Detach from elsewhere.
3025
UnregisterSignal(our_turf, COMSIG_TURF_MULTIZ_DEL)
3126
UnregisterSignal(our_turf, COMSIG_TURF_MULTIZ_NEW)
27+
UnregisterSignal(our_turf, COMSIG_TURF_INITIALIZE_TRANSPARENCY)
3228
REMOVE_TRAIT(our_turf, TURF_Z_TRANSPARENT_TRAIT, TURF_TRAIT)
29+
REMOVE_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT, TURF_TRAIT)
3330

3431
///Updates the viscontents or underlays below this tile.
3532
/datum/element/turf_z_transparency/proc/update_multiz(turf/our_turf, prune_on_fail = FALSE, init = FALSE)
@@ -39,15 +36,16 @@
3936
if(!show_bottom_level(our_turf) && prune_on_fail) //If we cant show whats below, and we prune on fail, change the turf to plating as a fallback
4037
our_turf.ChangeTurf(/turf/open/floor/plating, flags = CHANGETURF_INHERIT_AIR)
4138
return FALSE
42-
if(init)
43-
our_turf.vis_contents += below_turf
44-
if(isclosedturf(our_turf)) //Show girders below closed turfs
45-
var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01)
46-
girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR
47-
our_turf.underlays += girder_underlay
48-
var/mutable_appearance/plating_underlay = mutable_appearance('icons/turf/floors.dmi', "plating", layer = TURF_LAYER-0.02)
49-
plating_underlay = RESET_ALPHA | RESET_COLOR
50-
our_turf.underlays += plating_underlay
39+
else
40+
if(init)
41+
our_turf.vis_contents += below_turf
42+
if(isclosedturf(our_turf)) //Show girders below closed turfs
43+
var/mutable_appearance/girder_underlay = mutable_appearance('icons/obj/structures.dmi', "girder", layer = TURF_LAYER-0.01)
44+
girder_underlay.appearance_flags = RESET_ALPHA | RESET_COLOR
45+
our_turf.underlays += girder_underlay
46+
var/mutable_appearance/plating_underlay = mutable_appearance('icons/turf/floors.dmi', "plating", layer = TURF_LAYER-0.02)
47+
plating_underlay = RESET_ALPHA | RESET_COLOR
48+
our_turf.underlays += plating_underlay
5149
return TRUE
5250

5351
/datum/element/turf_z_transparency/proc/on_multiz_turf_del(turf/our_turf, turf/T, dir)
@@ -62,17 +60,47 @@
6260
return
6361
update_multiz(our_turf)
6462

63+
/**
64+
* Initializes, or actually gives appearance to, transparent tiles.
65+
*
66+
* Called via COMSIG_TURF_INITIALIZE_TRANSPARENCY from:
67+
* ChangeTurf() - generic case for glass floors, initialized when plating turns into glass floor.
68+
* on_applied_turf() - material application, special case. You can make transparent tiled floor, so it's initialized here as the proc calls are different.
69+
* onShuttleMove() is a case for both glass and material floors, as it's called only when the shuttle moves.
70+
*
71+
* We do these calls as late as possible to get a full baseturfs list to later pass to show_bottom_level().
72+
* This should have no effect on multi-z performance, but I have not tested it.
73+
*
74+
* Arguments:
75+
* * our_turf - turf being passed to initialize transparency. Only tested on open turfs.
76+
*/
77+
/datum/element/turf_z_transparency/proc/initilize_turf_transparency(turf/our_turf)
78+
SIGNAL_HANDLER
79+
update_multiz(our_turf, TRUE, TRUE)
80+
6581
///Called when there is no real turf below this turf
6682
/datum/element/turf_z_transparency/proc/show_bottom_level(turf/our_turf)
67-
if(!show_bottom_level)
83+
if(!HAS_TRAIT(our_turf, TURF_Z_SHOW_BOTTOM_TRAIT))
6884
return FALSE
69-
var/turf/path = our_turf.virtual_level_trait(ZTRAIT_BASETURF) || /turf/open/space
70-
if(!ispath(path))
71-
path = text2path(path)
85+
86+
var/turf/path
87+
if(our_turf.baseturfs && length(our_turf.baseturfs) > 1)
88+
path = our_turf.baseturfs[2] //Why 2? It's usually a better indicator of what we landed on.
89+
if(ispath(path, /turf/closed)) //Do not want to show walls, looks strange.
90+
path = our_turf.baseturfs[1] //The first element is going to be a floor of some kind.
91+
92+
if(!path) //Fallback to the regular, bland, method of determining a level baseturf.
93+
//linters fix, change to this in the future:
94+
//path = our_turf.get_z_base_turf()
95+
path = our_turf.virtual_level_trait(ZTRAIT_BASETURF) || /turf/open/space
7296
if(!ispath(path))
73-
warning("Z-level [our_turf.z] has invalid baseturf '[our_turf.virtual_level_trait(ZTRAIT_BASETURF)]'")
74-
path = /turf/open/space
75-
var/mutable_appearance/underlay_appearance = mutable_appearance(initial(path.icon), initial(path.icon_state), layer = TURF_LAYER-0.02, plane = PLANE_SPACE)
97+
path = text2path(path)
98+
if(!ispath(path))
99+
warning("Z-level [our_turf.z] has invalid baseturf '[our_turf.virtual_level_trait(ZTRAIT_BASETURF)]'")
100+
path = /turf/open/space
101+
102+
//PLANE_SPACE to show the parallax if it's a space tile.
103+
var/mutable_appearance/underlay_appearance = mutable_appearance(initial(path.icon), initial(path.icon_state), layer = TURF_LAYER-0.02, plane = (ispath(path, /turf/open/space) ? PLANE_SPACE : null))
76104
underlay_appearance.appearance_flags = RESET_ALPHA | RESET_COLOR
77105
our_turf.underlays += underlay_appearance
78106
return TRUE

code/datums/materials/_material.dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Simple datum which is instanced once per type and is used for every object of sa
126126
O.heavyfootstep = turf_sound_override
127127
if(alpha < 255)
128128
T.AddElement(/datum/element/turf_z_transparency, TRUE)
129+
SEND_SIGNAL(T, COMSIG_TURF_INITIALIZE_TRANSPARENCY)
129130
return
130131

131132
///This proc is called when the material is removed from an object.
@@ -159,8 +160,7 @@ Simple datum which is instanced once per type and is used for every object of sa
159160
o.throwforce = initial(o.throwforce)
160161

161162
/datum/material/proc/on_removed_turf(turf/T, amount, material_flags)
162-
if(alpha != 255)
163-
RemoveElement(/datum/element/turf_z_transparency, FALSE)
163+
return
164164

165165
/** Returns the composition of this material.
166166
*

code/game/turfs/change_turf.dm

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,10 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
1616
if(turf_type)
1717
ChangeTurf(turf_type, baseturf_type, flags)
1818

19+
//This proc is actually evil. Needs a rewrite.
1920
/turf/proc/copyTurf(turf/T, copy_air, flags)
2021
if(T.type != type)
21-
var/obj/O
22-
if(underlays.len) //we have underlays, which implies some sort of transparency, so we want to a snapshot of the previous turf as an underlay
23-
O = new()
24-
O.underlays.Add(T)
2522
T.ChangeTurf(type, null, flags)
26-
if(underlays.len)
27-
T.underlays = O.underlays
2823
if(T.icon_state != icon_state)
2924
T.icon_state = icon_state
3025
if(T.icon != icon)
@@ -34,14 +29,26 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
3429
T.update_atom_colour()
3530
if(T.dir != dir)
3631
T.setDir(dir)
32+
if(T.alpha != alpha)
33+
T.alpha = alpha
34+
if(custom_materials)
35+
//If it's not a glass floor, it's a material floor with transparency (glass floors are initialized in ChangeTurf()).
36+
if(HAS_TRAIT(src, TURF_Z_TRANSPARENT_TRAIT))
37+
T.AddElement(/datum/element/turf_z_transparency, TRUE)
38+
T.custom_materials = custom_materials
3739
return T
3840

39-
/turf/open/copyTurf(turf/T, copy_air = FALSE)
41+
/turf/open/copyTurf(turf/open/T, copy_air = FALSE)
4042
. = ..()
4143
if(isopenturf(T))
4244
if(copy_air)
4345
var/turf/open/openTurf = T
4446
openTurf.air.copy_from(air)
47+
if(custom_materials) //For custom material floor overrides on footsteps.
48+
T.footstep = footstep
49+
T.barefootstep = barefootstep
50+
T.clawfootstep = clawfootstep
51+
T.heavyfootstep = heavyfootstep
4552

4653
//wrapper for ChangeTurf()s that you want to prevent/affect without overriding ChangeTurf() itself
4754
/turf/proc/TerraformTurf(path, new_baseturf, flags)
@@ -127,6 +134,10 @@ GLOBAL_LIST_INIT(blacklisted_automated_baseturfs, typecacheof(list(
127134

128135
W.virtual_z = old_virtual_z
129136

137+
//We need baseturfs and virtual_z to be set before sending this signal.
138+
if(!(flags & CHANGETURF_DEFER_CHANGE)) //Travel transparency initialization is handled in onShuttleMove().
139+
SEND_SIGNAL(W, COMSIG_TURF_INITIALIZE_TRANSPARENCY)
140+
130141
lighting_corner_NE = old_lighting_corner_NE
131142
lighting_corner_SE = old_lighting_corner_SE
132143
lighting_corner_SW = old_lighting_corner_SW

code/game/turfs/open/glass.dm

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/turf/open/floor/glass
2-
name = "Glass floor"
2+
name = "glass floor"
33
desc = "While it at first appears to be a dangerous glass floor over space, closer inspection reveals it to simply be a screen behind a layer of glass."
44
icon = 'icons/turf/floors/glass.dmi'
55
icon_state = "glass-0"
@@ -16,15 +16,11 @@
1616

1717
/turf/open/floor/glass/Initialize(mapload, inherited_virtual_z)
1818
icon_state = "" //Prevent the normal icon from appearing behind the smooth overlays
19-
..()
20-
return INITIALIZE_HINT_LATELOAD
21-
22-
/turf/open/floor/glass/LateInitialize()
23-
. = ..()
2419
AddElement(/datum/element/turf_z_transparency, TRUE)
20+
. = ..()
2521

2622
/turf/open/floor/glass/reinforced
27-
name = "Reinforced glass floor"
23+
name = "reinforced glass floor"
2824
desc = "While it at first appears to be a dangerous glass floor over space, closer inspection reveals it to simply be a screen behind a reinforced protective layer of glass."
2925
icon = 'icons/turf/floors/reinf_glass.dmi'
3026
icon_state = "reinf_glass-0"

code/modules/shuttle/on_move.dm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ All ShuttleMove procs go here
7676
for(var/i in 0 to new_loc.get_missing_shuttles(newT)) //Start at 0 because get_missing_shuttles() will report 1 less missing shuttle because of the CopyOnTop()
7777
newT.baseturfs.Insert(inject_index, /turf/baseturf_skipover/shuttle)
7878

79+
SEND_SIGNAL(newT, COMSIG_TURF_INITIALIZE_TRANSPARENCY) //After baseturfs ares established, we send this signal. Deferred to here on travel, otherwise usually performed in ChangeTurf().
80+
7981
return TRUE
8082

8183
// Called on the new turf after everything has been moved

0 commit comments

Comments
 (0)