Files
Bubberstation/code/datums/components/stationstuck.dm
T
MothblocksandGitHub fa7688d043 Save 0.6-0.7s of init time by splitting registering lists of signals into its own proc, and optimizing QDELETED (#71056)
- Makes QDELETED use isnull(x) instead of !x, giving about 0.2 to 0.25s
of speed.
- Make disposal constructs only update icon state rather than go through
expensive overlay code. Unfortunately did not have much effect, but is
something they should've been doing nonetheless.
- Makes RegisterSignal only take signals directly as opposed to
allocating a fresh list of signals. Very few consumers actually used
this and it costs about 0.4s. Also I think this is just a bad API anyway
and that separate procs are important

`\bRegisterSignal\((.*)list\(` replaced with `RegisterSignals($1list(`
2022-11-22 07:40:05 +00:00

66 lines
2.3 KiB
Plaintext

#define PUNISHMENT_MURDER "murder"
#define PUNISHMENT_GIB "gib"
#define PUNISHMENT_TELEPORT "teleport"
//very similar to stationloving, but more made for mobs and not objects. used on derelict drones currently
/*
This component is similar to stationloving in that it is meant to keep something on the z-level
The difference is that stationloving is for objects and stationstuck is for mobs.
It has a punishment variable that is what happens to the parent when they leave the z-level. See punish() documentation
*/
/datum/component/stationstuck
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
var/punishment = PUNISHMENT_GIB //see defines above
var/stuck_zlevel
var/message = ""
/datum/component/stationstuck/Initialize(_punishment = PUNISHMENT_GIB, _message = "")
if(!isliving(parent))
return COMPONENT_INCOMPATIBLE
var/mob/living/L = parent
RegisterSignals(L, list(COMSIG_MOVABLE_Z_CHANGED), PROC_REF(punish))
punishment = _punishment
message = _message
stuck_zlevel = L.z
/datum/component/stationstuck/InheritComponent(datum/component/stationstuck/newc, original, _punishment, _message)
if(newc)
punishment = newc.punishment
message = newc.message
else
punishment = _punishment
message = _message
/**
* Called when parent leaves the zlevel this is set to (aka whichever zlevel it was on when it was added)
* Sends a message, then does an effect depending on what the punishment was.
*
* Punishments:
* * PUNISHMENT_MURDER: kills parent
* * PUNISHMENT_GIB: gibs parent
* * PUNISHMENT_TELEPORT: finds a safe turf if possible, or a completely random one if not.
*/
/datum/component/stationstuck/proc/punish()
SIGNAL_HANDLER
var/mob/living/escapee = parent
if(message)
var/span = punishment == PUNISHMENT_TELEPORT ? "danger" : "userdanger"
to_chat(escapee, "<span class='[span]'>[message]</span>")
switch(punishment)
if(PUNISHMENT_MURDER)
if(escapee.stat != DEAD)
escapee.investigate_log("has been killed by stationstuck component.", INVESTIGATE_DEATHS)
escapee.death()
if(PUNISHMENT_GIB)
escapee.investigate_log("has been gibbed by stationstuck component.", INVESTIGATE_DEATHS)
escapee.gib()
if(PUNISHMENT_TELEPORT)
var/targetturf = find_safe_turf(stuck_zlevel)
if(!targetturf)
targetturf = locate(world.maxx/2,world.maxy/2,stuck_zlevel)
escapee.forceMove(targetturf)