sumghai / MedPod

Advanced regenerative medical beds for RimWorld
Other
14 stars 15 forks source link

Exiting the MedPod under certain conditions does not remove the coma. #9

Closed CodePanter closed 4 years ago

CodePanter commented 4 years ago

I can't be 100% sure of how this happened, as part of this was off-screen, but one of my colonists had just had surgery, was still 'woozy' from anesthetics, and got in the MedPod. I'm not sure whether she took damage from something, the power went off for a second, or something different entirely happened, but the colonist was ejected from the MedPod, and was still in the coma from the MedPod. She initially was carried over to a normal medical bed where I waited for quite a while, but nothing happened (not even after the wooziness was gone). I then un-assigned that bed as a hospital bed, and she was carried back to the MedPod, where her treatment was then finished, which resulted in the coma being removed. I can imagine this being a big problem if a player for some reason loses their MedPod (due to reasonable game mechanics, or the other issue I filed) and then be stuck with a seemingly permanently comatose colonist.

sumghai commented 4 years ago

This sounds bizarre.

The MedPod is designed so that if it runs out of power, is destroyed or otherwise despawned while treating a patient, the patient should immediately be given an (improper) cortical stimulation to wake them up.

As for why the delta-wave induced coma is currently "permanent", this is because I needed a way to keep the patient lying in the MedPod for a whole treatment cycle, as usually with vanilla hospital beds it is possible that a patient partially recovers to the point of regaining the ability to walk, run off to deal with food/other needs, and (maybe) return later to fully recover.

I am thinking of possibly tweaking the delta-wave coma to expire after a period of time, although if it expires while there are still hediffs remaining to be treated, the treatment will get interrupted when the pawn runs off.

Since you mentioned that you're not "100% sure of how this happened, as part of this was off-screen", please go back and try to reproduce this situation in detail, so that I know to start investigating this issue.

CodePanter commented 4 years ago

I removed a bionic part from a colonist, removed all other hospital beds so she was put in the medpod to recover. I then had a colonist turn the machine off, and carry her to a new hospital bed. She still had the coma after this. Gif of the mentioned steps here: https://imgur.com/a/Rj58cBw

sumghai commented 4 years ago

Bug confirmed - this looks like an extremely bizarre edge case.

Detailed Investigation Setup * Dev mode * 6x8 cell single-walled wooden building * 1 Door, locked * 1 MedPod * 1 Battery, filled via Dev Mode * 2 pawns (Kensuke = doctor, Mari, patient) Scenario 1 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * Battery emptied via Dev Mode during diagnosis mode * Result: Mari falls off the depowered MedPod, with no additional hediffs applied Scenario 2 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * Battery emptied via Dev Mode during treatment mode * Result: Mari falls off the depowered MedPod, with the Cortical Stimulation (improper) hediff applied, which cancels out the Delta Wave Induced Coma hediff Scenario 3 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * MedPod destroyed via Dev Mode during diagnosis mode * Result: Mari falls off the non-existent MedPod, with no additional hediffs applied Scenario 4 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * MedPod destroyed via Dev Mode during treatment mode * Result: Mari falls off the non-existent MedPod, with the Cortical Stimulation (improper) hediff applied, which cancels out the Delta Wave Induced Coma hediff Scenario 5 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * Kensuke forced to switch off MedPod during diagnostic mode, via Designate Toggle Power gizmo and Float Menu * Result: Mari falls off the MedPod _before_ it is fully depowered, with no additional hediffs applied Scenario 6 * Mari damaged until downed via Dev mode * Kensuke hauls Mari to MedPod * Kensuke forced to switch off MedPod during treatment mode, via Designate Toggle Power gizmo and Float Menu * Result: Mari falls off the MedPod _before_ it is fully depowered, **with the Delta Wave Induced Coma hediff still present**

Basically, the current code correctly handles situations where the MedPod loses power or is destroyed, by waking the patient up and cancelling out the Delta Wave Induced Coma.

When the Designate Toggle Power gizmo is set to Off, the task for switching off the MedPod is actually given to the patient lying on it. Usually, no other pawn approaches the MedPod until it has finished treating the patient, then the (ex) patient gets off and switches off the MedPod themselves.

If, however, for some bizarre reason the player decides to forcefully tell another pawn to switch off a MedPod while in treatment mode, the patient loses their reservation on the MedPod, falls off and does not get their Delta Wave Induced Coma removed.

Some ways to solve this problem:

sumghai commented 4 years ago

Right, so I've found yet another edge case that triggers this bug:

This is a more plausible situation, because perhaps the player wants to perform triage by prioritizing a critically-wounded patient over someone with a hangnail who just happened to get on the MedPod first.

To handle this particular edge case, I will need to detect when the current patient is kicked off the MedPod, and apply the improper Cortical Stimulation hediff instead to wake them up.

sumghai commented 4 years ago

@CodePanter - Please try the following development build, and see if it fixes both edge cases:

https://github.com/sumghai/MedPod/archive/d1460a96aa99c86c87fa1f0a48c1f9d4d009afa9.zip

CodePanter commented 4 years ago

I tried all situations I could come up with, including some you didn't mention like using a medpod on a prisoner, and then toggling the 'for prisoner' setting, and everything seems to work perfectly fine. Thank you for fixing this!

sumghai commented 4 years ago

Good catch on the prisoner toggle use cases as well, thanks!

Marking this one as done.