Files
Bubberstation/code/datums/components/multiple_lives.dm
san7890 a6f49ed542 Refactors Suiciding Variable Into Trait (#74150)
## About The Pull Request

Firstly, this var was on `/mob`, even though only `/mob/living` and
`/mob/dead` could have ever used it, so who knows how much needless
memory it was consuming on stuff such as `oranges_ear` that would never
ever ever use something like this.

Edit: okay instead of memory it just polluted variable edit windows for
all /mob when it didn't need to. I like having a slim VV window

Secondly, it's a technical improvement over the previous system as we
are able to "track" where a suicide originates from, and how we can
track that from mob-to-mob-to-mob. Previously, the boolean `suiciding`
would only inform us if they had ever been connected to a mob that had
ever committed suicide, but now we are able to precisely determine which
mob gave them the trait that they must now apparently bear until the
round restarts.

## Why It's Good For The Game

Less memory usage, more indepth ability to track suicides in case you
really need that dexterity. Currently no implemented code could benefit
from using it, but it would be pretty neat if someone could figure out a
way to have someone be guilt-tripped whenever they look into a mirror
and seeing the reflection of their past life? This PR won't actually
help you code that and it'll probably require a bit more work, but it's
a possibility of some cool interactions you can do when you have this
information available to you.


![image](https://user-images.githubusercontent.com/34697715/226506321-550c37e7-5de8-4f9f-9ceb-4bf9b1052597.png)

## Changelog

🆑
refactor: Some aspects of how we track suicides from your living mob to
your observer have changed- please do let us know if anything has broken
via a GitHub Issue Report.
/🆑

There's probably some technical improvements that can be made in some
parts of the code I reworked to accommodate this change, do let me know
if you spot any easy ones (or fuckups). a lot of excess comes from the
fact that any step in the TRAIT framework trusts that you are passing in
a valid datum (or subtype) so that's a thing
2023-03-21 20:06:45 -04:00

57 lines
2.4 KiB
Plaintext

/**
* A simple component that spawns a mob of the same type and transfers itself to it when parent dies.
* For more complex behaviors, use the COMSIG_ON_MULTIPLE_LIVES_RESPAWN comsig.
*/
/datum/component/multiple_lives
can_transfer = TRUE
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
/// The number of respawns the living mob has left.
var/lives_left
/datum/component/multiple_lives/Initialize(lives_left)
if(!isliving(parent))
return COMPONENT_INCOMPATIBLE
src.lives_left = lives_left
/datum/component/multiple_lives/RegisterWithParent()
RegisterSignal(parent, COMSIG_LIVING_DEATH, PROC_REF(respawn))
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(on_examine))
RegisterSignal(parent, COMSIG_LIVING_WRITE_MEMORY, PROC_REF(on_write_memory))
/datum/component/multiple_lives/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_LIVING_DEATH, COMSIG_PARENT_EXAMINE, COMSIG_LIVING_WRITE_MEMORY))
/// Stops a dying station pet from overriding persistence data before we respawn it and thus causing issues.
/datum/component/multiple_lives/proc/on_write_memory(mob/living/source, dead, gibbed)
if(dead && !HAS_TRAIT(source, TRAIT_SUICIDED))
return COMPONENT_DONT_WRITE_MEMORY
/datum/component/multiple_lives/proc/respawn(mob/living/source, gibbed)
SIGNAL_HANDLER
if(HAS_TRAIT(source, TRAIT_SUICIDED)) //Freed from this mortail coil.
qdel(src)
return
//Gives the old mob this trait in case it gets revived, so we won't end up eventually overriding data
//that would be read by the current holder when he respawns if the old corpse is ever revived.
ADD_TRAIT(source, TRAIT_DONT_WRITE_MEMORY, EXPIRED_LIFE_TRAIT)
var/mob/living/respawned_mob = new source.type (source.drop_location())
source.mind?.transfer_to(respawned_mob)
lives_left--
if(lives_left <= 0)
qdel(src)
source.TransferComponents(respawned_mob)
SEND_SIGNAL(source, COMSIG_ON_MULTIPLE_LIVES_RESPAWN, respawned_mob, gibbed, lives_left)
/datum/component/multiple_lives/proc/on_examine(mob/living/source, mob/user, list/examine_list)
SIGNAL_HANDLER
if(isobserver(user) || source == user)
examine_list += "[source.p_theyve(TRUE)] [lives_left] extra lives left."
/datum/component/multiple_lives/InheritComponent(datum/component/multiple_lives/new_comp , lives_left)
src.lives_left += new_comp ? new_comp.lives_left : lives_left
/datum/component/multiple_lives/PostTransfer()
if(!isliving(parent))
return COMPONENT_INCOMPATIBLE