Files
Bubberstation/code/datums/components/material_turf_tracking.dm
Alexis 21b4095dfd [MDB IGNORE] [IDB IGNORE] Upstream Sync - 04/17/2026 (#5453)
Upstream 04/17/2026

fixes https://github.com/Bubberstation/Bubberstation/issues/5549

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com>
Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com>
Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com>
Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com>
Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com>
Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com>
Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com>
Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com>
Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com>
Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com>
Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com>
Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com>
Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com>
Co-authored-by: loganuk <fakeemail123@aol.com>
Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com>
Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com>
Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com>
Co-authored-by: Lucy <lucy@absolucy.moe>
Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com>
Co-authored-by: Isratosh <Isratosh@hotmail.com>
Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com>
Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com>
Co-authored-by: Alexander V. <volas@ya.ru>
Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com>
Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com>
Co-authored-by: Cameron Lennox <killer65311@gmail.com>
Co-authored-by: Tim <timothymtorres@gmail.com>
Co-authored-by: Iamgoofball <iamgoofball@gmail.com>
Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com>
Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com>
Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com>
Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com>
Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com>
Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com>
Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com>
Co-authored-by: Josh <josh.adam.powell@gmail.com>
Co-authored-by: Josh Powell <josh.powell@softwire.com>
Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com>
Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com>
Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com>
Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
2026-05-16 00:56:00 +02:00

204 lines
7.3 KiB
Plaintext

/// Sends a signal to the owner material whenever something enters its objects' turf and steps onto said object
/datum/component/material_turf_tracking
dupe_mode = COMPONENT_DUPE_ALLOWED
/// Material we're linked to
var/datum/material/owner_material = null
/// Does our parent require the target to be elevated for us to trigger?
var/requires_elevation = FALSE
/// Typecache of things we should ignore
var/static/list/interaction_blacklist = typecacheof(list(
/obj/docking_port,
/obj/effect/abstract,
/obj/effect/atmos_shield,
/obj/effect/collapse,
/obj/effect/constructing_effect,
/obj/effect/dummy/phased_mob,
/obj/effect/ebeam,
/obj/effect/fishing_float,
/obj/effect/hotspot,
/obj/effect/landmark,
/obj/effect/light_emitter/tendril,
/obj/effect/mapping_helpers,
/obj/effect/particle_effect/ion_trails,
/obj/effect/particle_effect/sparks,
/obj/effect/portal,
/obj/effect/projectile,
/obj/effect/spectre_of_resurrection,
/obj/effect/temp_visual,
/obj/effect/wisp,
/obj/energy_ball,
/obj/narsie,
/obj/singularity,
))
/// Typecache of objects which we only consider "touched" when they elevate the mob, or the mob is buckled to them
/// Easy way to keep track of snowflake behavior like flipped tables
var/static/list/elevation_interactions = typecacheof(list(
/obj/structure/platform,
/obj/structure/table,
/obj/structure/rack,
/obj/structure/bed,
/obj/structure/closet/crate,
/obj/structure/reagent_dispensers,
/obj/structure/altar,
))
/datum/component/material_turf_tracking/Initialize(datum/material/owner_material)
if (!isopenturf(parent) && !isobj(parent))
return COMPONENT_INCOMPATIBLE
src.owner_material = owner_material
if (is_type_in_typecache(parent, elevation_interactions))
requires_elevation = TRUE
/datum/component/material_turf_tracking/Destroy(force)
owner_material = null
return ..()
/datum/component/material_turf_tracking/RegisterWithParent()
var/turf/target_turf = parent
if (ismovable(parent))
var/atom/movable/as_movable = parent
RegisterSignal(as_movable, COMSIG_ATOM_ENTERING, PROC_REF(on_source_entering))
RegisterSignal(as_movable, COMSIG_ATOM_EXITING, PROC_REF(on_source_exiting))
target_turf = as_movable.loc
if (!isopenturf(target_turf))
return
if (!requires_elevation)
RegisterSignal(target_turf, SIGNAL_ADDTRAIT(TRAIT_ELEVATED_TURF), PROC_REF(on_turf_lost))
RegisterSignal(target_turf, SIGNAL_REMOVETRAIT(TRAIT_ELEVATED_TURF), PROC_REF(on_turf_gained))
if (HAS_TRAIT(target_turf, TRAIT_ELEVATED_TURF))
return
// Not tracking initializations or existing objects as this would allow you to TP someone from plating by placing a tile underneath
RegisterSignal(target_turf, COMSIG_ATOM_ENTERED, PROC_REF(on_entered))
RegisterSignal(target_turf, COMSIG_TURF_MOVABLE_THROW_LANDED, PROC_REF(on_entered)) // Need this as shoves are 1 tile throws, and COMSIG_ATOM_ENTERED runs before the throw ends
RegisterSignal(target_turf, COMSIG_ATOM_EXITED, PROC_REF(on_exited))
/datum/component/material_turf_tracking/UnregisterFromParent()
. = ..()
if (isturf(parent))
on_source_exiting(parent)
return
var/atom/movable/as_movable = parent
UnregisterSignal(as_movable, list(COMSIG_ATOM_ENTERING, COMSIG_ATOM_EXITING))
on_source_exiting(as_movable.loc)
/datum/component/material_turf_tracking/proc/on_source_entering(atom/movable/source, atom/entering, atom/old_loc)
SIGNAL_HANDLER
if (!isopenturf(entering))
return
if (!requires_elevation)
RegisterSignal(entering, SIGNAL_ADDTRAIT(TRAIT_ELEVATED_TURF), PROC_REF(on_turf_lost))
RegisterSignal(entering, SIGNAL_REMOVETRAIT(TRAIT_ELEVATED_TURF), PROC_REF(on_turf_gained))
if (HAS_TRAIT(entering, TRAIT_ELEVATED_TURF))
return
on_turf_gained(entering)
/datum/component/material_turf_tracking/proc/on_source_exiting(atom/movable/source, atom/exiting)
SIGNAL_HANDLER
if (!isturf(exiting))
return
UnregisterSignal(exiting, list(SIGNAL_ADDTRAIT(TRAIT_ELEVATED_TURF), SIGNAL_REMOVETRAIT(TRAIT_ELEVATED_TURF)))
on_turf_lost(exiting)
/datum/component/material_turf_tracking/proc/on_turf_gained(turf/source)
SIGNAL_HANDLER
RegisterSignal(source, COMSIG_ATOM_ENTERED, PROC_REF(on_entered))
RegisterSignal(source, COMSIG_TURF_MOVABLE_THROW_LANDED, PROC_REF(on_entered))
RegisterSignal(source, COMSIG_ATOM_EXITED, PROC_REF(on_exited))
for (var/atom/movable/thing in source)
on_entered(source, thing)
/datum/component/material_turf_tracking/proc/on_turf_lost(turf/source)
SIGNAL_HANDLER
UnregisterSignal(source, list(COMSIG_ATOM_ENTERED, COMSIG_TURF_MOVABLE_THROW_LANDED, COMSIG_ATOM_EXITED))
for (var/atom/movable/thing in source)
UnregisterSignal(thing, list(SIGNAL_ADDTRAIT(TRAIT_MOB_ELEVATED), COMSIG_MOVETYPE_FLAG_DISABLED))
/datum/component/material_turf_tracking/proc/on_entered(datum/source, atom/movable/arrived, atom/old_loc, list/atom/old_locs)
SIGNAL_HANDLER
if (arrived.throwing || arrived.invisibility >= INVISIBILITY_ABSTRACT || arrived == parent)
return
if (is_type_in_typecache(arrived, interaction_blacklist))
return
if (!isliving(arrived) && requires_elevation)
return
// Its floating but it may touch down
if (arrived.movement_type & MOVETYPES_NOT_TOUCHING_GROUND)
RegisterSignal(arrived, COMSIG_MOVETYPE_FLAG_DISABLED, PROC_REF(on_move_flag_disabled))
return
if (!isliving(arrived))
trigger_effect(arrived)
return
if (requires_elevation)
// We want to know when they touch down so we can interact with them
RegisterSignal(arrived, SIGNAL_ADDTRAIT(TRAIT_MOB_ELEVATED), PROC_REF(on_mob_elevated))
// The trait is kept even if the mob is buckled which is weird but plays into our hand here
if (!HAS_TRAIT(arrived, TRAIT_MOB_ELEVATED))
return
trigger_effect(arrived)
/datum/component/material_turf_tracking/proc/on_exited(datum/source, atom/movable/gone)
SIGNAL_HANDLER
UnregisterSignal(gone, list(SIGNAL_ADDTRAIT(TRAIT_MOB_ELEVATED), COMSIG_MOVETYPE_FLAG_DISABLED))
/datum/component/material_turf_tracking/proc/trigger_effect(atom/movable/arrived)
if (!isliving(arrived))
SEND_SIGNAL(owner_material, COMSIG_MATERIAL_EFFECT_STEP, parent, arrived, null, null, FALSE)
return
var/mob/living/victim = arrived
var/skin_contact = FEET
if (victim.body_position == LYING_DOWN)
skin_contact = CHEST|GROIN|LEGS|FEET|ARMS|HANDS
for (var/obj/item/worn_item in victim.get_equipped_items(INCLUDE_ABSTRACT))
skin_contact &= ~worn_item.body_parts_covered
if (!skin_contact)
break
SEND_SIGNAL(owner_material, COMSIG_MATERIAL_EFFECT_STEP, parent, arrived, null, pick(BODY_ZONE_L_LEG, BODY_ZONE_R_LEG), !!skin_contact)
/datum/component/material_turf_tracking/proc/on_mob_elevated(mob/living/source, trait)
if (source.throwing || source.invisibility >= INVISIBILITY_ABSTRACT || (source.movement_type & MOVETYPES_NOT_TOUCHING_GROUND))
return
if (is_type_in_typecache(source, interaction_blacklist))
return
trigger_effect(source)
/datum/component/material_turf_tracking/proc/on_move_flag_disabled(atom/movable/source, flag, old_state)
if (source.throwing || source.invisibility >= INVISIBILITY_ABSTRACT || (source.movement_type & MOVETYPES_NOT_TOUCHING_GROUND))
return
if (is_type_in_typecache(source, interaction_blacklist))
return
if (requires_elevation)
if (!isliving(source))
return
RegisterSignal(source, SIGNAL_ADDTRAIT(TRAIT_MOB_ELEVATED), PROC_REF(on_mob_elevated))
if (!HAS_TRAIT(source, TRAIT_MOB_ELEVATED))
return
trigger_effect(source)