Files
Bubberstation/code/modules
Timberpoes f5e30da403 Fixes cliented brainmobs being sent to the gem room when their amputated head is reattached to a body. (#74227)
## About The Pull Request

Fixes #74126

Hi vsauce, Timberpoes here!

Brains are being sent the gem room. But why???? *musical sting*

Issue was caused by #73026

![image](https://user-images.githubusercontent.com/24975989/227698989-76e96198-b000-44d5-8c71-65721f25f9df.png)

This early return added to brain Insert is the root cause.

Let's have a butcher's at some code, eh?


![image](https://user-images.githubusercontent.com/24975989/227699118-217bc7a2-160c-41a0-b75e-ef389c43f538.png)

Here we have a parent call in `. = ..()` and then a check for brains and
brainmobs to do some special snowflake stuff before
`brain.Insert(new_head_owner)`.

This causes a problem. But WHY???????

Well... The parent call already inserts the brain, but without any
snowflake stuff done.


![image](https://user-images.githubusercontent.com/24975989/227699193-2bb29dce-c92d-4253-aa78-4f771d765bf2.png)

The parent call returns and the child proc
`/obj/item/bodypart/head/try_attach_limb()` which mashes the brainmob
into the brain and slams the `brain.Insert()` proc a **second** time.

This is a bug. But it worked despite being a bug, because the brain's
Insert proc would still do logic even if the Insert was technically not
successful.

But... We come back to this again:

![image](https://user-images.githubusercontent.com/24975989/227701040-a98b0ae7-1221-431a-8cc5-d47061372f7a.png)

If the new early return for the parent call is FALSEy, it stops all that
wonderful brainmob code from being executed.


![image](https://user-images.githubusercontent.com/24975989/227699367-c6aafcf1-8c50-41fe-b90d-820cd8cd1618.png)

... And ITS parent call is FALSE because `owner == receiver` is now
TRUE, as it was set the first time `Insert()` was called all the way
back in `/obj/item/bodypart/proc/try_attach_limb()`.

So the first `brain.Insert()` call in the parent
`/obj/item/bodypart/proc/try_attach_limb()` succeeds, but brainmob
related code isn't executed because the head bodypart hasn't set up the
brain's state correctly at this point.

And the second `brain.Insert()` call in the child
`/obj/item/bodypart/head/try_attach_limb()` which occurs after the
brain's state is correctly set, now fails because of an early return
when the insertion fails (the owner is already the receiver).

So, the old code only worked because it was bugged. Fixing the bug where
it worked, created a bug where it didn't.

But wait, why the gem room?

Well, since all the code that handled qdeleting the brainmob failed, it
persisted in the brain **even after the brain was inserted into the
body**. Where does the body store all of its organs? That's right, it
transfers them all to ~~the balls~~ nullspace!


![image](https://user-images.githubusercontent.com/24975989/227700676-47b8d7ef-b77d-42f8-996a-fa994136d501.png)

And what is the brainmob? A mob! And what did it have? A client! And
what happens when cliented mobs find themselves in nullspace when a
Life() tick happens? A vacation to the gem room!

I have opted for a very simple fix. I've moved the code into
`/obj/item/organ/internal/brain/Insert()`. It now checks to see if it's
in a head when it's inserted into the new brain_owner. If it is, the
brain handles setting up its own state so it can successfully transfer.

`brain.Insert()` only gets called once instead of twice and the
snowflake behaviour is no longer controlled by the head.

In my testing of shearing off heads of guest clients and reattaching
them, this fixes the bug without any gem room errors on the other
clients.
## Why It's Good For The Game

Feex.
## Changelog
🆑
fix: Having your severed, brain-filled head reattached to a body no
longer teleports your brain to the mythical Gem Room.
/🆑
2023-03-25 13:59:22 -06:00
..
2023-03-24 12:21:43 -06:00