Skip to content

Commit

Permalink
Refactor uncrossed/crossed back into the game
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapu1178 committed Aug 24, 2023
1 parent 4269332 commit de03dc5
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 159 deletions.
5 changes: 5 additions & 0 deletions code/__DEFINES/flags.dm
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,8 @@ GLOBAL_LIST_INIT(z_defines, list(
// This is intended for use on dev-defined openspace turfs, don't put _OVERWRITE in here unless you feel like having people ask why their zturfs are empty
#define Z_MIMIC_DEFAULTS (Z_MIMIC_BELOW) //! 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.

/// Atom wants Crossed() called
#define CROSSED (1<<0)
/// Atom wants Uncrossed() called
#define UNCROSSED (1<<1)
2 changes: 1 addition & 1 deletion code/controllers/subsystem/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ SUBSYSTEM_DEF(atoms)
else if(!(A.initialized))
BadInitializeCalls[the_type] |= BAD_INIT_DIDNT_INIT
else
if(ismovable(A))
if(ismovable(A) && !qdeleted)
A.loc?.Entered(A)
SEND_SIGNAL(A,COMSIG_ATOM_AFTER_SUCCESSFUL_INITIALIZE)
if(created_atoms && from_template && ispath(the_type, /atom/movable))//we only want to populate the list with movables
Expand Down
26 changes: 26 additions & 0 deletions code/game/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
/// pass_flags that we are. If any of this matches a pass_flag on a moving thing, by default, we let them through.
var/pass_flags_self = NONE

//Cross/Uncrossed related flags
///Atoms in our contents that want Crossed() called.
var/list/crossers
///Atoms in our contents that want Uncrossed() called.
var/list/uncrossers
/// Informs our loc if we need Crossed and/or Uncrossed() called
var/cross_flags = NONE

///If non-null, overrides a/an/some in all cases
var/article

Expand Down Expand Up @@ -1387,6 +1395,15 @@
SEND_SIGNAL(src, COMSIG_ATOM_ENTERED, arrived, old_loc, old_locs)
SEND_SIGNAL(arrived, COMSIG_ATOM_ENTERING, src, old_loc, old_locs)

if(LAZYLEN(crossers))
for(var/atom/movable/crossed as anything in crossers)
crossed.Crossed(arrived, old_loc, old_locs)

if(arrived.cross_flags & CROSSED)
LAZYADD(crossers, arrived)
if(arrived.cross_flags & UNCROSSED)
LAZYADD(uncrossers, arrived)

/**
* An atom is attempting to exit this atom's contents
*
Expand Down Expand Up @@ -1414,6 +1431,15 @@
. = (1 || ..()) //Linter defeat device, does not actually call parent.
SEND_SIGNAL(src, COMSIG_ATOM_EXITED, gone, direction)

if(LAZYLEN(uncrossers))
for(var/atom/movable/uncrossed as anything in uncrossers)
uncrossed.Uncrossed(gone, direction)

if(gone.cross_flags & CROSSED)
LAZYREMOVE(crossers, gone)
if(gone.cross_flags & UNCROSSED)
LAZYREMOVE(uncrossers, gone)

///Return atom temperature
/atom/proc/return_temperature()
return
Expand Down
16 changes: 4 additions & 12 deletions code/game/atoms_movable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -958,9 +958,8 @@
return CanPass(crosser, get_dir(src, crosser))

///default byond proc that is deprecated for us in lieu of signals. do not call
/atom/movable/Crossed(atom/movable/crossed_by, oldloc)
SHOULD_NOT_OVERRIDE(TRUE)
CRASH("atom/movable/Crossed() was called!")
/atom/movable/Crossed(atom/movable/crossed_by, oldloc, list/old_locs)
CRASH("Bad Crossed() call.")

/**
* `Uncross()` is a default BYOND proc that is called when something is *going*
Expand All @@ -986,15 +985,8 @@
SHOULD_NOT_OVERRIDE(TRUE)
CRASH("Uncross() should not be being called, please read the doc-comment for it for why.")

/**
* default byond proc that is normally called on everything inside the previous turf
* a movable was in after moving to its current turf
* this is wasteful since the vast majority of objects do not use Uncrossed
* use connect_loc to register to COMSIG_ATOM_EXITED instead
*/
/atom/movable/Uncrossed(atom/movable/uncrossed_atom)
SHOULD_NOT_OVERRIDE(TRUE)
CRASH("/atom/movable/Uncrossed() was called")
/atom/movable/Uncrossed(atom/movable/gone, direction)
CRASH("Bad Uncrossed() call.")

/atom/movable/Bump(atom/bumped_atom)
if(!bumped_atom)
Expand Down
13 changes: 4 additions & 9 deletions code/game/machinery/recycler.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
layer = ABOVE_ALL_MOB_LAYER // Overhead
density = TRUE
circuit = /obj/item/circuitboard/machine/recycler
cross_flags = CROSSED

var/safety_mode = FALSE // Temporarily stops machine if it detects a mob
var/icon_name = "grinder-o"
var/bloody = FALSE
Expand Down Expand Up @@ -40,10 +42,6 @@
. = ..()
update_appearance(UPDATE_ICON)
req_one_access = SSid_access.get_region_access_list(list(REGION_ALL_STATION, REGION_CENTCOM))
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

/obj/machinery/recycler/RefreshParts()
. = ..()
Expand Down Expand Up @@ -108,11 +106,8 @@
if(border_dir == eat_dir)
return TRUE

/obj/machinery/recycler/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
return
INVOKE_ASYNC(src, PROC_REF(eat), AM)
/obj/machinery/recycler/Crossed(atom/movable/crossed_by, oldloc)
INVOKE_ASYNC(src, PROC_REF(eat), crossed_by)

/obj/machinery/recycler/proc/eat(atom/movable/AM0, sound=TRUE)
if(machine_stat & (BROKEN|NOPOWER))
Expand Down
22 changes: 8 additions & 14 deletions code/game/machinery/teambuilder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
can_buckle = FALSE
resistance_flags = INDESTRUCTIBLE // Just to be safe.
use_power = NO_POWER_USE
cross_flags = CROSSED
///Are non-humans allowed to use this?
var/humans_only = FALSE
///What color is your mob set to when crossed?
Expand All @@ -20,27 +21,20 @@
/obj/machinery/teambuilder/Initialize(mapload)
. = ..()
add_filter("teambuilder", 2, list("type" = "outline", "color" = team_color, "size" = 2))
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

/obj/machinery/teambuilder/examine_more(mob/user)
. = ..()
. += span_notice("You see a hastily written note on the side, it says '1215-1217, PICK A SIDE'.")

/obj/machinery/teambuilder/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
/obj/machinery/teambuilder/Crossed(atom/movable/crossed_by, oldloc)
if(!ishuman(crossed_by) && humans_only)
return
if(!ishuman(AM) && humans_only)
if(crossed_by.get_filter("teambuilder"))
return
if(AM.get_filter("teambuilder"))
return
if(isliving(AM) && team_color)
AM.add_filter("teambuilder", 2, list("type" = "outline", "color" = team_color, "size" = 2))
if(ishuman(AM) && team_radio)
var/mob/living/carbon/human/human = AM
if(isliving(crossed_by) && team_color)
crossed_by.add_filter("teambuilder", 2, list("type" = "outline", "color" = team_color, "size" = 2))
if(ishuman(crossed_by) && team_radio)
var/mob/living/carbon/human/human = crossed_by
var/obj/item/radio/Radio = human.ears
if(!Radio)
return
Expand Down
24 changes: 6 additions & 18 deletions code/game/objects/effects/anomalies.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,13 @@
icon_state = "shield2"
density = FALSE
aSignal = /obj/item/assembly/signaler/anomaly/grav
cross_flags = CROSSED
var/boing = 0
///Warp effect holder for displacement filter to "pulse" the anomaly
var/atom/movable/warp_effect/warp

/obj/effect/anomaly/grav/Initialize(mapload, new_lifespan, drops_core)
. = ..()
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

warp = new(src)
vis_contents += warp
Expand Down Expand Up @@ -155,11 +152,8 @@
animate(warp, time = delta_time*3, transform = matrix().Scale(0.5,0.5))
animate(time = delta_time*7, transform = matrix())

/obj/effect/anomaly/grav/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
return
gravShock(AM)
/obj/effect/anomaly/grav/Crossed(atom/movable/crossed_by, oldloc)
gravShock(crossed_by)

/obj/effect/anomaly/grav/Bump(atom/A)
gravShock(A)
Expand Down Expand Up @@ -196,17 +190,14 @@
density = TRUE
aSignal = /obj/item/assembly/signaler/anomaly/flux
zmm_flags = ZMM_MANGLE_PLANES
cross_flags = CROSSED
var/canshock = FALSE
var/shockdamage = 20
var/explosive = TRUE

/obj/effect/anomaly/flux/Initialize(mapload, new_lifespan, drops_core = TRUE, _explosive = TRUE)
. = ..()
explosive = _explosive
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

/obj/effect/anomaly/flux/anomalyEffect()
..()
Expand All @@ -218,11 +209,8 @@
. = ..()
. += emissive_appearance(icon, icon_state, alpha=src.alpha)

/obj/effect/anomaly/flux/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
return
mobShock(AM)
/obj/effect/anomaly/flux/Crossed(atom/movable/crossed_by, oldloc)
mobShock(crossed_by)

/obj/effect/anomaly/flux/Bump(atom/A)
mobShock(A)
Expand Down
17 changes: 4 additions & 13 deletions code/game/objects/effects/effect_system/effects_smoke.dm
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@

/obj/effect/particle_effect/smoke/bad
lifetime = 8

/obj/effect/particle_effect/smoke/bad/Initialize(mapload)
. = ..()
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)
cross_flags = CROSSED

/obj/effect/particle_effect/smoke/bad/smoke_mob(mob/living/carbon/M)
. = ..()
Expand All @@ -140,12 +134,9 @@
M.emote("cough")
return TRUE

/obj/effect/particle_effect/smoke/bad/proc/on_entered(datum/source, atom/movable/arrived, atom/old_loc, list/atom/old_locs)
SIGNAL_HANDLER
if(arrived == src)
return
if(istype(arrived, /obj/projectile/beam))
var/obj/projectile/beam/beam = arrived
/obj/effect/particle_effect/smoke/bad/Crossed(atom/movable/crossed_by, oldloc)
if(istype(crossed_by, /obj/projectile/beam))
var/obj/projectile/beam/beam = crossed_by
beam.damage *= 0.5

/datum/effect_system/smoke_spread/bad
Expand Down
16 changes: 5 additions & 11 deletions code/game/objects/effects/mines.dm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
anchored = TRUE
icon = 'icons/obj/items_and_weapons.dmi'
icon_state = "uglymine"
cross_flags = CROSSED

/// We manually check to see if we've been triggered in case multiple atoms cross us in the time between the mine being triggered and it actually deleting, to avoid a race condition with multiple detonations
var/triggered = FALSE
/// Can be set to FALSE if we want a short 'coming online' delay, then set to TRUE. Can still be set off by damage
Expand All @@ -18,10 +20,6 @@
armed = FALSE
icon_state = "uglymine-inactive"
addtimer(CALLBACK(src, PROC_REF(now_armed)), arm_delay)
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

/obj/effect/mine/examine(mob/user)
. = ..()
Expand All @@ -39,18 +37,14 @@
playsound(src, 'sound/machines/nuke/angry_beep.ogg', 40, FALSE, -2)
visible_message(span_danger("\The [src] beeps softly, indicating it is now active."), vision_distance = COMBAT_MESSAGE_RANGE)

/obj/effect/mine/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
return

/obj/effect/mine/Crossed(atom/movable/crossed_by, oldloc)
if(triggered || !isturf(loc) || !armed)
return

if(AM.movement_type & FLYING)
if(crossed_by.movement_type & FLYING)
return

triggermine(AM)
triggermine(crossed_by)

/obj/effect/mine/take_damage(damage_amount, damage_type, damage_flag, sound_effect, attack_dir)
. = ..()
Expand Down
14 changes: 3 additions & 11 deletions code/game/objects/items/stacks/sheets/glass.dm
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ GLOBAL_LIST_INIT(plastitaniumglass_recipes, list(
var/turf/T = get_turf(src)
if(T && is_station_level(T.z))
SSblackbox.record_feedback("tally", "station_mess_created", 1, name)
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_entered),
)
AddElement(/datum/element/connect_loc, loc_connections)

/obj/item/shard/Destroy()
. = ..()
Expand Down Expand Up @@ -370,13 +366,9 @@ GLOBAL_LIST_INIT(plastitaniumglass_recipes, list(
qdel(src)
return TRUE

/obj/item/shard/proc/on_entered(datum/source, atom/movable/AM)
SIGNAL_HANDLER
if(AM == src)
return

if(isliving(AM))
var/mob/living/L = AM
/obj/item/shard/Crossed(atom/movable/crossed_by, oldloc)
if(isliving(crossed_by))
var/mob/living/L = crossed_by
if(!(L.movement_type & (FLYING|FLOATING)) || L.buckled)
playsound(src, 'sound/effects/glass_step.ogg', HAS_TRAIT(L, TRAIT_LIGHT_STEP) ? 30 : 50, TRUE)

Expand Down
17 changes: 4 additions & 13 deletions code/game/objects/items/stacks/stack.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
gender = PLURAL
material_modifier = 0.05 //5%, so that a 50 sheet stack has the effect of 5k materials instead of 100k.
max_integrity = 100
cross_flags = CROSSED

var/list/datum/stack_recipe/recipes
var/singular_name
Expand Down Expand Up @@ -95,10 +96,6 @@
recipes += temp
update_weight()
update_appearance()
var/static/list/loc_connections = list(
COMSIG_ATOM_ENTERED = PROC_REF(on_movable_entered_occupied_turf),
)
AddElement(/datum/element/connect_loc, loc_connections)

/** Sets the amount of materials per unit for this stack.
*
Expand Down Expand Up @@ -512,15 +509,9 @@
is_zero_amount(delete_if_zero = TRUE)

/// Signal handler for connect_loc element. Called when a movable enters the turf we're currently occupying. Merges if possible.
/obj/item/stack/proc/on_movable_entered_occupied_turf(datum/source, atom/movable/arrived)
SIGNAL_HANDLER

// Edge case. This signal will also be sent when src has entered the turf. Don't want to merge with ourselves.
if(arrived == src)
return

if(!arrived.throwing && can_merge(arrived))
INVOKE_ASYNC(src, PROC_REF(merge), arrived)
/obj/item/stack/Crossed(atom/movable/crossed_by, oldloc)
if(!crossed_by.throwing && can_merge(crossed_by))
INVOKE_ASYNC(src, PROC_REF(merge), crossed_by)

/obj/item/stack/hitby(atom/movable/hitting, skipcatch, hitpush, blocked, datum/thrownthing/throwingdatum)
if(can_merge(hitting, inhand = TRUE))
Expand Down
Loading

0 comments on commit de03dc5

Please sign in to comment.