Skip to content
4 changes: 3 additions & 1 deletion code/__defines/_planes+layers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ What is the naming convention for planes or layers?
#define DEBRIS_LAYER 1
#define DUST_LAYER 2

// Openspace uses planes -80 through -70.
// Z-Mimic needs OPENTURF_PLANES_PER_DEPTH * OPENTURF_MAX_DEPTH planes. ZM will emit a compile-time warning if an invalid range is specified here.
#define ZMIMIC_MINIMUM_PLANE -80
#define ZMIMIC_MAXIMUM_PLANE -50

#define OVER_OPENSPACE_PLANE -3

Expand Down
1 change: 1 addition & 0 deletions code/__defines/ao.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// -- SSao --
#define WALL_AO_ALPHA 80
#define Z_AO_ALPHA 120

#define AO_UPDATE_NONE 0
#define AO_UPDATE_OVERLAY 1
Expand Down
75 changes: 61 additions & 14 deletions code/__defines/zmimic.dm
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
#define ZM_DESTRUCTION_TIMER(TARGET) addtimer(CALLBACK(TARGET, TYPE_PROC_REF(/datum, qdel_self)), 10 SECONDS, TIMER_STOPPABLE)
#define TURF_IS_MIMICKING(T) (isturf(T) && (T:z_flags & ZM_MIMIC_BELOW))
#define CHECK_OO_EXISTENCE(OO) if (OO && !MOVABLE_IS_ON_ZTURF(OO) && !OO.destruction_timer) { OO.destruction_timer = ZM_DESTRUCTION_TIMER(OO); }
/// Enable extra ZM debug logs -- these are useful for diagnosing layering issues, but they're potentially expensive.
// #define ZM_ENH_DEBUG

#ifdef ZM_ENH_DEBUG

#define ZM_DEBUG_LOG(X...) log_debug(X)

#else

#define ZM_DEBUG_LOG(X...)

#endif

// end ZM debug

#define ZM_DESTRUCTION_TIMER(TARGET, REASON) addtimer(CALLBACK(TARGET, TYPE_PROC_REF(/atom/movable/openspace/mimic, timeout), __FILE__, __LINE__, REASON), 10 SECONDS, TIMER_STOPPABLE)

#define TURF_IS_MIMIC(T) (isturf(T) && (T:z_flags & ZM_MIMIC_BELOW)) //! Is this a full Z-turf?
#define TURF_IS_MIMIC_BOUNDARY(T) (isturf(T) && (T:z_flags & ZM_BOUNDARY))
#define TURF_IS_MIMICKING(T) (isturf(T) && (T:z_flags & (ZM_MIMIC_BELOW | ZM_BOUNDARY))) //! Is this turf participating in Z-mimic?
#define CHECK_OO_EXISTENCE(OO) if (OO && !MOVABLE_IS_ON_ZTURF(OO) && !OO.destruction_timer) { OO.destruction_timer = ZM_DESTRUCTION_TIMER(OO, "COE"); }
#define UPDATE_OO_IF_PRESENT CHECK_OO_EXISTENCE(bound_overlay); if (bound_overlay) { update_above(); }
#define ZM_DIFF_HIDE_STATE(CALC, FLAG, TARGET) (CALC) ? (TARGET.hidden | FLAG) : (TARGET.hidden & ~FLAG)

// I do not apologize.

// These aren't intended to be used anywhere else, they just can't be undef'd because DM is dum.
#define ZM_INTERNAL_SCAN_LOOKAHEAD(M,VTR,F) ((get_step(M, M:dir)?:VTR & F) || (get_step(M, turn(M:dir, 180))?:VTR & F))
#define ZM_INTERNAL_SCAN_LOOKBESIDE(M,VTR,F) ((get_step(M, turn(M:dir, 90))?:VTR & F) || (get_step(M, turn(M:dir, -90))?:VTR & F))
// M: origin movable; TREF: origin loc; VTR: variable to read; F: flag to test
#define ZM_INTERNAL_SCAN_LOOKAHEAD(M,TREF,VTR,F) ((get_step(TREF, M:dir)?:VTR & F) || (get_step(TREF, turn(M:dir, 180))?:VTR & F))
#define ZM_INTERNAL_SCAN_LOOKBESIDE(M,TREF,VTR,F) ((get_step(TREF, turn(M:dir, 90))?:VTR & F) || (get_step(TREF, turn(M:dir, -90))?:VTR & F))

/// Is this movable visible from a turf that is mimicking below? Note: this does not necessarily mean *directly* below.
#define MOVABLE_IS_BELOW_ZTURF(M) (\
isturf(M:loc) && (TURF_IS_MIMICKING(M:loc:above) \
|| ((M:z_flags & ZMM_LOOKAHEAD) && ZM_INTERNAL_SCAN_LOOKAHEAD(M, above?:z_flags, ZM_MIMIC_BELOW)) \
|| ((M:z_flags & ZMM_LOOKBESIDE) && ZM_INTERNAL_SCAN_LOOKBESIDE(M, above?:z_flags, ZM_MIMIC_BELOW))) \
|| ((M:z_flags & ZMM_LOOKAHEAD) && ZM_INTERNAL_SCAN_LOOKAHEAD(M, M, above?:z_flags, (ZM_MIMIC_BELOW | ZM_BOUNDARY))) \
|| ((M:z_flags & ZMM_LOOKBESIDE) && ZM_INTERNAL_SCAN_LOOKBESIDE(M, M, above?:z_flags, (ZM_MIMIC_BELOW | ZM_BOUNDARY)))) \
)

/// Is this movable located on a turf that is mimicking below? Note: this does not necessarily mean *directly* on.
#define MOVABLE_IS_ON_ZTURF(M) (\
(TURF_IS_MIMICKING(M:loc) \
|| ((M:z_flags & ZMM_LOOKAHEAD) && ZM_INTERNAL_SCAN_LOOKAHEAD(M, z_flags, ZM_MIMIC_BELOW)) \
|| ((M:z_flags & ZMM_LOOKBESIDE) && ZM_INTERNAL_SCAN_LOOKBESIDE(M, z_flags, ZM_MIMIC_BELOW))) \
|| ((M:z_flags & ZMM_LOOKAHEAD) && ZM_INTERNAL_SCAN_LOOKAHEAD(M, M, z_flags, (ZM_MIMIC_BELOW | ZM_BOUNDARY))) \
|| ((M:z_flags & ZMM_LOOKBESIDE) && ZM_INTERNAL_SCAN_LOOKBESIDE(M, M, z_flags, (ZM_MIMIC_BELOW | ZM_BOUNDARY)))) \
)
#define MOVABLE_SHALL_MIMIC(AM) (!(AM.z_flags & ZMM_IGNORE) && MOVABLE_IS_BELOW_ZTURF(AM))

/* Don't copy:
- (q)deleted objects
- Explicitly ignored objects
- Always-invisible atoms
*/
#define MOVABLE_SHALL_MIMIC(AM) (!QDELETED(AM) && !(AM.z_flags & ZMM_IGNORE) && AM.invisibility != INVISIBILITY_ABSTRACT)

// Turf MZ flags.
#define ZM_MIMIC_BELOW 1 //! If this turf should mimic the turf on the Z below.
Expand All @@ -30,14 +57,33 @@
#define ZM_ALLOW_ATMOS 8 //! If this turf permits passage of air.
#define ZM_MIMIC_NO_AO 16 //! If the turf shouldn't apply regular turf AO and only do Z-mimic AO.
#define ZM_NO_OCCLUDE 32 //! Don't occlude below atoms if we're a non-mimic z-turf.
#define ZM_OVERRIDE 64 //! Copy only z_appearance or baseturf and bail, do not attempt to copy movables. This is significantly cheaper and allows you to override the mimic, but results in movables not being visible.
#define ZM_NO_SHADOW 128 //! If this turf is being copied, hide the shadower.
#define ZM_TERMINATOR 256 //! Consider this turf the terminus of a Z-group, like the bottom of a Z-group or a ZM_OVERRIDE turf.
#define ZM_OVERRIDE 64 //! Copy only z_appearance or baseturf and bail, do not attempt to copy movables. This is significantly cheaper and allows you to override the mimic, but results in movables not being visible. This also terminates the Z-stack for purposes of ZM invariants.
#define ZM_NO_SHADOW 128 //! If this turf is being copied, don't darken the shadower.
#define ZM_BOUNDARY 256 //! Internal use. Partially mimic the turf: allow creation of movables, but do not copy the actual turf. Movables are hidden from rightclick.
#define ZM_HIDE_ATOMS 512 //! If this turf is considered opaque to mouse clicks, also hide below mimics from the right-click menu. This makes it harder to examine atoms below, however.

// Convenience flags.
#define ZM_MIMIC_DEFAULTS (ZM_MIMIC_BELOW|ZM_ALLOW_LIGHTING) //! Common defaults for zturfs.
#define ZMM_WIDE_LOAD (ZMM_LOOKAHEAD | ZMM_LOOKBESIDE) //! Atom is big and needs to scan one extra turf in both X and Y. This only extends the range by one turf. Cheap, but not free.

/// Preset: you're creating a hole in the ground. No icon, nothing to cast shadows on. Just a hole.
#define ZM_MIMIC_PRESET_HOLE (ZM_MIMIC_DEFAULTS | ZM_OVERWRITE | ZM_MIMIC_NO_AO | ZM_ALLOW_ATMOS)
/// Preset: you're creating a hole in the ground with a border. This turf has an icon, but you want to be able to click things in the hole like with a regular Z-hole.
#define ZM_MIMIC_PRESET_HOLE_WITH_BORDER (ZM_MIMIC_DEFAULTS | ZM_NO_OCCLUDE | ZM_ALLOW_ATMOS)
/// Preset: you're creating a turf with translucent accents (like glass flooring). This will block clicks even where alpha on the icon is 0, add MIMIC_NO_OCCLUDE if this is unwanted.
#define ZM_MIMIC_PRESET_TRANSLUCENT_TURF (ZM_MIMIC_DEFAULTS)

#define ZM_FLAGS_AFFECTS_VIS (ZM_BOUNDARY | ZM_HIDE_ATOMS) //! Flags that affect mimic right-click visibility (maps to ZM_HIDE_*).
#define ZM_FLAGS_AFFECTS_LAYERING (0) //! Flags that affect mimic layering (different render slice placement).

/// Flags that persist across changeturf.
#define ZM_INFECTIOUS_MIMIC_FLAGS (ZM_OVERRIDE) // Hopefully I don't regret making OVERRIDE sticky.

// ZM hide state flags for simplicity of logic.
#define ZM_HIDE_BOUNDARY 1 //! This mimic is being hidden by its parent being a boundary.
#define ZM_HIDE_NONMIMIC 2 //! This mimic is being hidden by its parent not being a mimic.
#define ZM_HIDE_OPAQUE 4 //! This mimic is being hidden by its parent having mouse_opacity set with MIMIC_HIDE_ATOMS active.

// For debug purposes, should contain the above defines in ascending order.
var/global/list/mimic_defines = list(
"ZM_MIMIC_BELOW",
Expand All @@ -48,7 +94,8 @@ var/global/list/mimic_defines = list(
"ZM_NO_OCCLUDE",
"ZM_OVERRIDE",
"ZM_NO_SHADOW",
"ZM_TERMINATOR"
"ZM_BOUNDARY",
"ZM_HIDE_ATOMS"
)

// Movable flags.
Expand Down
2 changes: 1 addition & 1 deletion code/controllers/subsystems/ambience.dm
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SUBSYSTEM_DEF(ambience)
var/turf/above = src
var/datum/level_data/above_level_data
while ((above = GetAbove(above)))
if((above.z_flags & ZM_TERMINATOR) || !HasAbove(above.z))
if((above.z_flags & ZM_OVERRIDE) || !HasAbove(above.z))
break
above_level_data = SSmapping.levels_by_z[above.z]
if(above_level_data.daycycle_id)
Expand Down
Loading
Loading