Surgery on napping people wakes them up. (#17661)

* Surgery on napping people wakes them up.

* Fix a potential afreeze issue

* Code review

* has_status_effect now returns `null` if no status effect

* move `voluntary` to be an arg to New

* Update code/modules/surgery/helpers.dm

Co-authored-by: Charlie <69320440+hal9000PR@users.noreply.github.com>

* And this other IsSleeping call

Co-authored-by: Charlie <69320440+hal9000PR@users.noreply.github.com>
This commit is contained in:
moxian
2022-06-25 00:20:24 +01:00
committed by GitHub
co-authored by Charlie
parent 5f58a80d8a
commit f4bd86cc5e
6 changed files with 44 additions and 13 deletions
+8 -2
View File
@@ -382,7 +382,7 @@
S = apply_status_effect(STATUS_EFFECT_SLEEPING, amount)
return S
/mob/living/proc/SetSleeping(amount, ignore_canstun = FALSE)
/mob/living/proc/SetSleeping(amount, ignore_canstun = FALSE, voluntary = FALSE)
if(frozen) // If the mob has been admin frozen, sleeping should not be changeable
return
if(status_flags & GODMODE)
@@ -393,13 +393,19 @@
if(S)
S.duration = amount + world.time
else if(amount > 0)
S = apply_status_effect(STATUS_EFFECT_SLEEPING, amount)
S = apply_status_effect(STATUS_EFFECT_SLEEPING, amount, voluntary)
if(!voluntary && S)
// Only set it one way (true => false)
// Otherwise if we are hard knocked out, and then try to nap, we'd be
// treated as "just lightly napping" and woken up by trivial stuff.
S.voluntary = FALSE
return S
/mob/living/proc/PermaSleeping() /// used for admin freezing.
var/datum/status_effect/incapacitating/sleeping/S = IsSleeping()
if(S)
S.duration = -1
S.voluntary = FALSE
else
S = apply_status_effect(STATUS_EFFECT_SLEEPING, -1)
return S
+2 -3
View File
@@ -460,9 +460,8 @@ GLOBAL_LIST_INIT(intents, list(INTENT_HELP,INTENT_DISARM,INTENT_GRAB,INTENT_HARM
if(IsSleeping())
to_chat(src, "<span class='notice'>You are already sleeping.</span>")
return
else
if(alert(src, "You sure you want to sleep for a while?", "Sleep", "Yes", "No") == "Yes")
SetSleeping(40 SECONDS) //Short nap
if(alert(src, "You sure you want to sleep for a while?", "Sleep", "Yes", "No") == "Yes")
SetSleeping(40 SECONDS, voluntary = TRUE) //Short nap
/mob/living/verb/lay_down()
set name = "Rest"
+7 -1
View File
@@ -118,7 +118,13 @@
/proc/get_pain_modifier(mob/living/carbon/human/M) //returns modfier to make surgery harder if patient is conscious and feels pain
if(M.stat) //stat=0 if CONSCIOUS, 1=UNCONSCIOUS and 2=DEAD. Operating on dead people is easy, too. Just sleeping won't work, though.
if(M.stat == DEAD) // Operating on dead people is easy
return 1
var/datum/status_effect/incapacitating/sleeping/S = M.IsSleeping()
if(M.stat == UNCONSCIOUS && !(S?.voluntary))
// Either unconscious due to something other than sleep,
// or "sleeping" due to being hard knocked out (N2O or similar), rather than just napping.
// Either way, not easily woken up.
return 1
if(HAS_TRAIT(M, TRAIT_NOPAIN))//if you don't feel pain, you can hold still
return 1
+10 -1
View File
@@ -114,7 +114,16 @@
if(!ispath(surgery.steps[surgery.status], /datum/surgery_step/robotics))//Repairing robotic limbs doesn't hurt, and neither does cutting someone out of a rig
if(ishuman(target))
var/mob/living/carbon/human/H = target //typecast to human
prob_chance *= get_pain_modifier(H)//operating on conscious people is hard.
var/pain_mod = get_pain_modifier(H)
var/datum/status_effect/incapacitating/sleeping/S = H.IsSleeping()
if(S?.voluntary)
H.SetSleeping(0) // wake up people who are napping through the surgery
if(pain_mod < 0.95)
to_chat(H, "<span class='danger'>The surgery on your [target_zone] is agonizingly painful, and wrecks you out of your shallow slumber!</span>")
else
// Still wake people up, but they shouldn't be as alarmed.
to_chat(H, "<span class='warning'>The surgery being performed on your [target_zone] wakes you up.</span>")
prob_chance *= pain_mod //operating on conscious people is hard.
if(prob(prob_chance) || isrobot(user))
if(end_step(user, target, target_zone, tool, surgery))