Files
SmArtKar f58b8511f0 Refactors effect_system (#94999)
## About The Pull Request

This PR refactors ``effect_system``s to be a bit easier to use by
getting rid of ``set_up``, allowing ``attach()`` to be chained into
``start()`` and refactoring most direct system usages in our code to use
helper procs.

``set_up`` was unnecessary and only existed to allow ``New``'s behavior
to be fully overriden, which is not required if we split
sparks/lightning/steam into a new ``/datum/effect_system/basic`` subtype
which houses the effect spreading behavior. This allows us to roll all
logic from ``set_up`` into ``New`` and cut down on code complexity.
Chaining setup as ``system.attach(src).start()`` also helps a bit in
case no helper method exists

I've added ``do_chem_smoke`` and ``do_foam`` helpers, which respectively
allow chemical smoke or foam to be spawned easily without having to
manually create effect datums and reagent holders.

Also turns out we've had some nonfunctional effect systems which either
never set themselves up, or never started, so I fixed those while I was
at it (mostly by moving them to aforementioned helper procs)

## Why It's Good For The Game

Cleaner code, makes it significantly easier for users to work with. Also
most of our effect system usage was copypasta which was passing booleans
as numbers, while perfectly fine helper procs existed in our code.

## Changelog
🆑
refactor: Refactored sparks, foam, smoke, and other miscellaneous effect
systems.
refactor: Vapes now have consistent rigging with cigs using the new
system.
fix: Fixed some effects never working.
/🆑
2026-02-03 22:23:09 -05:00

104 lines
2.8 KiB
Plaintext

/////////////////////////////////////////////
//////// Attach a trail to any object, that spawns when it moves (like for the jetpack)
/// just pass in the object to attach it to in set_up
/// Then do start() to start it and stop() to stop it, obviously
/// and don't call start() in a loop that will be repeated otherwise it'll get spammed!
/////////////////////////////////////////////
/datum/effect_system/trail_follow
/// Previous position of the atom we're tracking
var/turf/oldposition
/// Are we currently spawning particles?
var/active = FALSE
/// Can the particles be spawned ontop of eachother?
var/allow_overlap = FALSE
/// Should we automatically start processing ourselves?
var/auto_process = TRUE
/// Delay before we delete the particles
var/qdel_in_time = 1 SECONDS
/// Typepath we should spawn
var/effect_type = null
/// Should we flick an icon state and blank out the particles afterwards?
var/fade = TRUE
/// icon_state to flick on our particles
var/fadetype = "ion_fade"
/// Are we restricted to zero-g only?
var/nograv_required = FALSE
/datum/effect_system/trail_follow/New(turf/location)
. = ..()
attach(location)
oldposition = location
/datum/effect_system/trail_follow/Destroy()
oldposition = null
stop()
return ..()
/datum/effect_system/trail_follow/proc/stop()
oldposition = null
STOP_PROCESSING(SSfastprocess, src)
active = FALSE
return TRUE
/datum/effect_system/trail_follow/start()
oldposition = get_turf(holder)
if(!check_conditions())
return FALSE
if(auto_process)
START_PROCESSING(SSfastprocess, src)
active = TRUE
return TRUE
/datum/effect_system/trail_follow/process()
generate_effect()
/datum/effect_system/trail_follow/proc/generate_effect()
if(!check_conditions())
return stop()
if(!oldposition || oldposition == get_turf(holder))
oldposition = get_turf(holder)
return
if(nograv_required && oldposition.has_gravity())
oldposition = get_turf(holder)
return
var/obj/effect/particle = new effect_type(oldposition)
set_dir(particle)
if(fade)
flick(fadetype, particle)
particle.icon_state = ""
if(qdel_in_time)
QDEL_IN(particle, qdel_in_time)
/datum/effect_system/trail_follow/proc/check_conditions()
if(!get_turf(holder))
return FALSE
return TRUE
/datum/effect_system/trail_follow/proc/set_dir(obj/effect/effect)
effect.setDir(holder.dir)
/datum/effect_system/trail_follow/steam
effect_type = /obj/effect/particle_effect/steam
/obj/effect/particle_effect/ion_trails
name = "ion trails"
icon_state = "ion_trails"
anchored = TRUE
/obj/effect/particle_effect/ion_trails/flight
icon_state = "ion_trails_flight"
/datum/effect_system/trail_follow/ion
effect_type = /obj/effect/particle_effect/ion_trails
nograv_required = TRUE
qdel_in_time = 2 SECONDS
/datum/effect_system/trail_follow/ion/grav_allowed
nograv_required = FALSE