From be355edab533db63b3177f80c29725cd607874e2 Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 31 Jan 2022 02:04:07 -0600 Subject: [PATCH] Refactor incapacitated optional arguments (#63771) --- code/__DEFINES/status_effects.dm | 8 +++++ code/_onclick/click.dm | 2 +- code/_onclick/hud/screen_objects.dm | 2 +- code/_onclick/other_mobs.dm | 11 +++++-- code/datums/components/riding/riding_mob.dm | 4 +-- code/datums/martial/sleeping_carp.dm | 2 +- code/game/objects/items/RPD.dm | 2 +- .../crates_lockers/closets/cardboardbox.dm | 2 +- .../abductor/equipment/abduction_gear.dm | 2 +- code/modules/clothing/head/jobs.dm | 2 +- code/modules/mob/living/carbon/human/human.dm | 6 ++-- .../mob/living/carbon/human/human_defense.dm | 2 +- code/modules/mob/living/living.dm | 30 ++++++++++++++++--- code/modules/mob/mob.dm | 2 +- code/modules/mob/mob_movement.dm | 2 +- code/modules/mod/modules/_module.dm | 2 +- code/modules/mod/modules/module_kinesis.dm | 2 +- code/modules/paperwork/paper.dm | 4 +-- 18 files changed, 62 insertions(+), 25 deletions(-) diff --git a/code/__DEFINES/status_effects.dm b/code/__DEFINES/status_effects.dm index 77a2532ba98..200e76b80a9 100644 --- a/code/__DEFINES/status_effects.dm +++ b/code/__DEFINES/status_effects.dm @@ -23,6 +23,14 @@ ///hands reach out from the sides of the screen, doing damage and stunning if they hit the target #define CURSE_GRASPING (1<<3) +//Incapacitated status effect flags +/// If the incapacitated status effect will ignore a mob in restraints (handcuffs) +#define IGNORE_RESTRAINTS (1<<0) +/// If the incapacitated status effect will ignore a mob in stasis (stasis beds) +#define IGNORE_STASIS (1<<1) +/// If the incapacitated status effect will ignore a mob being agressively grabbed +#define IGNORE_GRAB (1<<2) + // Grouped effect sources, see also code/__DEFINES/traits.dm #define STASIS_MACHINE_EFFECT "stasis_machine" diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 2de2683c38b..a462166c5e7 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -105,7 +105,7 @@ CtrlClickOn(A) return - if(incapacitated(ignore_restraints = TRUE, ignore_stasis = TRUE)) + if(incapacitated(IGNORE_RESTRAINTS|IGNORE_STASIS)) return face_atom(A) diff --git a/code/_onclick/hud/screen_objects.dm b/code/_onclick/hud/screen_objects.dm index 395dfb0aa15..843f235a573 100644 --- a/code/_onclick/hud/screen_objects.dm +++ b/code/_onclick/hud/screen_objects.dm @@ -132,7 +132,7 @@ if(world.time <= usr.next_move) return TRUE - if(usr.incapacitated(ignore_stasis = TRUE)) + if(usr.incapacitated(IGNORE_STASIS)) return TRUE if(ismecha(usr.loc)) // stops inventory actions in a mech return TRUE diff --git a/code/_onclick/other_mobs.dm b/code/_onclick/other_mobs.dm index c5da0db75ed..c65e7aef65e 100644 --- a/code/_onclick/other_mobs.dm +++ b/code/_onclick/other_mobs.dm @@ -76,8 +76,15 @@ if((interaction_flags_atom & INTERACT_ATOM_REQUIRES_DEXTERITY) && !ISADVANCEDTOOLUSER(user)) to_chat(user, span_warning("You don't have the dexterity to do this!")) return FALSE - if(!(interaction_flags_atom & INTERACT_ATOM_IGNORE_INCAPACITATED) && user.incapacitated((interaction_flags_atom & INTERACT_ATOM_IGNORE_RESTRAINED), !(interaction_flags_atom & INTERACT_ATOM_CHECK_GRAB))) - return FALSE + if(!(interaction_flags_atom & INTERACT_ATOM_IGNORE_INCAPACITATED)) + var/ignore_flags = NONE + if(interaction_flags_atom & INTERACT_ATOM_IGNORE_RESTRAINED) + ignore_flags |= IGNORE_RESTRAINTS + if(!(interaction_flags_atom & INTERACT_ATOM_CHECK_GRAB)) + ignore_flags |= IGNORE_GRAB + + if(user.incapacitated(ignore_flags)) + return FALSE return TRUE /atom/ui_status(mob/user) diff --git a/code/datums/components/riding/riding_mob.dm b/code/datums/components/riding/riding_mob.dm index 70a6ccdc54d..9de207a6423 100644 --- a/code/datums/components/riding/riding_mob.dm +++ b/code/datums/components/riding/riding_mob.dm @@ -54,10 +54,10 @@ if(living_parent.body_position != STANDING_UP) // if we move while on the ground, the rider falls off . = FALSE // for piggybacks and (redundant?) borg riding, check if the rider is stunned/restrained - else if((ride_check_flags & RIDER_NEEDS_ARMS) && (HAS_TRAIT(rider, TRAIT_RESTRAINED) || rider.incapacitated(TRUE, TRUE))) + else if((ride_check_flags & RIDER_NEEDS_ARMS) && (HAS_TRAIT(rider, TRAIT_RESTRAINED) || rider.incapacitated(IGNORE_RESTRAINTS|IGNORE_GRAB))) . = FALSE // for fireman carries, check if the ridden is stunned/restrained - else if((ride_check_flags & CARRIER_NEEDS_ARM) && (HAS_TRAIT(living_parent, TRAIT_RESTRAINED) || living_parent.incapacitated(TRUE, TRUE))) + else if((ride_check_flags & CARRIER_NEEDS_ARM) && (HAS_TRAIT(living_parent, TRAIT_RESTRAINED) || living_parent.incapacitated(IGNORE_RESTRAINTS|IGNORE_GRAB))) . = FALSE if(. || !consequences) diff --git a/code/datums/martial/sleeping_carp.dm b/code/datums/martial/sleeping_carp.dm index 3df3a43710e..dda86b82ccc 100644 --- a/code/datums/martial/sleeping_carp.dm +++ b/code/datums/martial/sleeping_carp.dm @@ -100,7 +100,7 @@ /datum/martial_art/the_sleeping_carp/on_projectile_hit(mob/living/A, obj/projectile/P, def_zone) . = ..() - if(A.incapacitated(FALSE, TRUE)) //NO STUN + if(A.incapacitated(IGNORE_GRAB)) //NO STUN return BULLET_ACT_HIT if(!(A.mobility_flags & MOBILITY_USE)) //NO UNABLE TO USE return BULLET_ACT_HIT diff --git a/code/game/objects/items/RPD.dm b/code/game/objects/items/RPD.dm index cd265eaa472..b6080ed226c 100644 --- a/code/game/objects/items/RPD.dm +++ b/code/game/objects/items/RPD.dm @@ -636,7 +636,7 @@ GLOBAL_LIST_INIT(transit_tube_recipes, list( /obj/item/pipe_dispenser/proc/mouse_wheeled(mob/source, atom/A, delta_x, delta_y, params) SIGNAL_HANDLER - if(source.incapacitated(ignore_restraints = TRUE, ignore_stasis = TRUE)) + if(source.incapacitated(IGNORE_RESTRAINTS|IGNORE_STASIS)) return if(delta_y < 0) diff --git a/code/game/objects/structures/crates_lockers/closets/cardboardbox.dm b/code/game/objects/structures/crates_lockers/closets/cardboardbox.dm index 1314e081359..058665c4437 100644 --- a/code/game/objects/structures/crates_lockers/closets/cardboardbox.dm +++ b/code/game/objects/structures/crates_lockers/closets/cardboardbox.dm @@ -53,7 +53,7 @@ egged = world.time + SNAKE_SPAM_TICKS for(var/mob/living/L in alerted) if(!L.stat) - if(!L.incapacitated(ignore_restraints = 1)) + if(!L.incapacitated(IGNORE_RESTRAINTS)) L.face_atom(src) L.do_alert_animation() playsound(loc, 'sound/machines/chime.ogg', 50, FALSE, -5) diff --git a/code/modules/antagonists/abductor/equipment/abduction_gear.dm b/code/modules/antagonists/abductor/equipment/abduction_gear.dm index 0263795dfe0..2be0af405e8 100644 --- a/code/modules/antagonists/abductor/equipment/abduction_gear.dm +++ b/code/modules/antagonists/abductor/equipment/abduction_gear.dm @@ -536,7 +536,7 @@ Congratulations! You are now trained for invasive xenobiology research!"} /obj/item/melee/baton/abductor/proc/SleepAttack(mob/living/L,mob/living/user) playsound(src, on_stun_sound, 50, TRUE, -1) - if(L.incapacitated(TRUE, TRUE)) + if(L.incapacitated(IGNORE_RESTRAINTS|IGNORE_GRAB)) if(L.anti_magic_check(FALSE, FALSE, TRUE)) to_chat(user, span_warning("The specimen's tinfoil protection is interfering with the sleep inducement!")) L.visible_message(span_danger("[user] tried to induced sleep in [L] with [src], but [L.p_their()] tinfoil protection [L.p_them()]!"), \ diff --git a/code/modules/clothing/head/jobs.dm b/code/modules/clothing/head/jobs.dm index c8c4213d647..e9fbe1f388d 100644 --- a/code/modules/clothing/head/jobs.dm +++ b/code/modules/clothing/head/jobs.dm @@ -35,7 +35,7 @@ if(!istype(user, /mob/living/simple_animal/mouse) || !isliving(loc) || !prob(mouse_control_probability)) return var/mob/living/L = loc - if(L.incapacitated(TRUE)) //just in case + if(L.incapacitated(IGNORE_RESTRAINTS)) //just in case return step_towards(L, get_step(L, direction)) diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 68dc2142ae1..6b9855adeb3 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -897,7 +897,7 @@ return ishuman(target) && target.body_position == LYING_DOWN /mob/living/carbon/human/proc/fireman_carry(mob/living/carbon/target) - if(!can_be_firemanned(target) || incapacitated(FALSE, TRUE)) + if(!can_be_firemanned(target) || incapacitated(IGNORE_GRAB)) to_chat(src, span_warning("You can't fireman carry [target] while [target.p_they()] [target.p_are()] standing!")) return @@ -917,7 +917,7 @@ return //Second check to make sure they're still valid to be carried - if(!can_be_firemanned(target) || incapacitated(FALSE, TRUE) || target.buckled) + if(!can_be_firemanned(target) || incapacitated(IGNORE_GRAB) || target.buckled) visible_message(span_warning("[src] fails to fireman carry [target]!")) return @@ -933,7 +933,7 @@ visible_message(span_warning("[target] fails to climb onto [src]!")) return - if(target.incapacitated(FALSE, TRUE) || incapacitated(FALSE, TRUE)) + if(target.incapacitated(IGNORE_GRAB) || incapacitated(IGNORE_GRAB)) target.visible_message(span_warning("[target] can't hang onto [src]!")) return diff --git a/code/modules/mob/living/carbon/human/human_defense.dm b/code/modules/mob/living/carbon/human/human_defense.dm index de130730343..b469a56b113 100644 --- a/code/modules/mob/living/carbon/human/human_defense.dm +++ b/code/modules/mob/living/carbon/human/human_defense.dm @@ -143,7 +143,7 @@ /mob/living/carbon/human/proc/check_block() if(mind) - if(mind.martial_art && prob(mind.martial_art.block_chance) && mind.martial_art.can_use(src) && throw_mode && !incapacitated(FALSE, TRUE)) + if(mind.martial_art && prob(mind.martial_art.block_chance) && mind.martial_art.can_use(src) && throw_mode && !incapacitated(IGNORE_GRAB)) return TRUE return FALSE diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 563e2d393df..8e7e4c058d9 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -437,10 +437,32 @@ to_chat(src, span_notice("You have given up life and succumbed to death.")) death() -/mob/living/incapacitated(ignore_restraints = FALSE, ignore_grab = FALSE, ignore_stasis = FALSE) - if(HAS_TRAIT(src, TRAIT_INCAPACITATED) || (!ignore_restraints && (HAS_TRAIT(src, TRAIT_RESTRAINED) || (!ignore_grab && pulledby && pulledby.grab_state >= GRAB_AGGRESSIVE))) || (!ignore_stasis && IS_IN_STASIS(src))) +/** + * Checks if a mob is incapacitated + * + * Normally being restrained, agressively grabbed, or in stasis counts as incapacitated + * unless there is a flag being used to check if it's ignored + * + * args: + * * flags (optional) bitflags that determine if special situations are exempt from being considered incapacitated + * + * bitflags: (see code/__DEFINES/status_effects.dm) + * * IGNORE_RESTRAINTS - mob in a restraint (handcuffs) is not considered incapacitated + * * IGNORE_STASIS - mob in stasis (stasis bed, etc.) is not considered incapacitated + * * IGNORE_GRAB - mob that is agressively grabbed is not considered incapacitated +**/ +/mob/living/incapacitated(flags) + if(HAS_TRAIT(src, TRAIT_INCAPACITATED)) return TRUE + if(HAS_TRAIT(src, TRAIT_RESTRAINED) && !(flags & IGNORE_RESTRAINTS)) + return TRUE + if(IS_IN_STASIS(src) && !(flags & IGNORE_STASIS)) + return TRUE + if((pulledby && pulledby.grab_state >= GRAB_AGGRESSIVE) && !(flags & IGNORE_GRAB)) + return TRUE + return FALSE + /mob/living/canUseStorage() if (usable_hands <= 0) return FALSE @@ -919,7 +941,7 @@ ..(pressure_difference, direction, pressure_resistance_prob_delta) /mob/living/can_resist() - return !((next_move > world.time) || incapacitated(ignore_restraints = TRUE, ignore_stasis = TRUE)) + return !((next_move > world.time) || incapacitated(IGNORE_RESTRAINTS|IGNORE_STASIS)) /mob/living/verb/resist() set name = "Resist" @@ -1710,7 +1732,7 @@ ///Checks if the user is incapacitated or on cooldown. /mob/living/proc/can_look_up() - return !(incapacitated(ignore_restraints = TRUE)) + return !(incapacitated(IGNORE_RESTRAINTS)) /** * look_up Changes the perspective of the mob to any openspace turf above the mob diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 208bc2a3400..28313deceb9 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -301,7 +301,7 @@ ///Is the mob incapacitated -/mob/proc/incapacitated(ignore_restraints = FALSE, ignore_grab = FALSE, ignore_stasis = FALSE) +/mob/proc/incapacitated(flags) return /** diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index 6c7df57a387..f14bf200f04 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -177,7 +177,7 @@ return FALSE if(mob.pulledby == mob.pulling && mob.pulledby.grab_state == GRAB_PASSIVE) //Don't autoresist passive grabs if we're grabbing them too. return FALSE - if(mob.incapacitated(ignore_restraints = TRUE)) + if(mob.incapacitated(IGNORE_RESTRAINTS)) COOLDOWN_START(src, move_delay, 1 SECONDS) return TRUE else if(HAS_TRAIT(mob, TRAIT_RESTRAINED)) diff --git a/code/modules/mod/modules/_module.dm b/code/modules/mod/modules/_module.dm index 6a4fbd15fcd..be7d1b02693 100644 --- a/code/modules/mod/modules/_module.dm +++ b/code/modules/mod/modules/_module.dm @@ -178,7 +178,7 @@ /// Called when an activated module without a device is used /obj/item/mod/module/proc/on_select_use(atom/target) - if(mod.wearer.incapacitated(ignore_grab = TRUE)) + if(mod.wearer.incapacitated(IGNORE_GRAB)) return FALSE mod.wearer.face_atom(target) if(!on_use()) diff --git a/code/modules/mod/modules/module_kinesis.dm b/code/modules/mod/modules/module_kinesis.dm index cdc65a3f723..e90170c2873 100644 --- a/code/modules/mod/modules/module_kinesis.dm +++ b/code/modules/mod/modules/module_kinesis.dm @@ -73,7 +73,7 @@ clear_grab() /obj/item/mod/module/anomaly_locked/kinesis/process(delta_time) - if(!mod.wearer.client || mod.wearer.incapacitated(ignore_grab = TRUE)) + if(!mod.wearer.client || mod.wearer.incapacitated(IGNORE_GRAB)) clear_grab() return if(!range_check(grabbed_atom)) diff --git a/code/modules/paperwork/paper.dm b/code/modules/paperwork/paper.dm index 6cfc975e3c9..d7e23e62125 100644 --- a/code/modules/paperwork/paper.dm +++ b/code/modules/paperwork/paper.dm @@ -137,7 +137,7 @@ set category = "Object" set src in usr - if(!usr.can_read(src) || usr.incapacitated(TRUE, TRUE) || (isobserver(usr) && !isAdminGhostAI(usr))) + if(!usr.can_read(src) || usr.incapacitated(IGNORE_RESTRAINTS|IGNORE_GRAB) || (isobserver(usr) && !isAdminGhostAI(usr))) return if(ishuman(usr)) var/mob/living/carbon/human/H = usr @@ -180,7 +180,7 @@ return UI_CLOSE if(!in_range(user, src) && !isobserver(user)) return UI_CLOSE - if(user.incapacitated(TRUE, TRUE) || (isobserver(user) && !isAdminGhostAI(user))) + if(user.incapacitated(IGNORE_RESTRAINTS|IGNORE_GRAB) || (isobserver(user) && !isAdminGhostAI(user))) return UI_UPDATE // Even harder to read if your blind...braile? humm // .. or if you cannot read