From aaafb6be770cddcb3cc4576d67f214372f4f4268 Mon Sep 17 00:00:00 2001 From: dearmochi <1496804+dearmochi@users.noreply.github.com> Date: Tue, 12 Dec 2023 02:05:12 +0900 Subject: [PATCH] Adds alert to direction locking, minor refactor (#23445) * Adds alert to direction locking, minor refactor * use return --- code/__DEFINES/mob_defines.dm | 2 + code/_onclick/click.dm | 14 +++---- code/_onclick/hud/alert.dm | 10 +++++ code/modules/mob/living/living.dm | 39 +++++++++++++++++- code/modules/mob/living/living_defines.dm | 3 ++ code/modules/mob/living/living_life.dm | 19 +++++---- .../mob/living/simple_animal/simple_animal.dm | 2 +- code/modules/mob/mob.dm | 11 ----- code/modules/mob/mob_vars.dm | 1 - icons/mob/screen_alert.dmi | Bin 70807 -> 71519 bytes 10 files changed, 71 insertions(+), 30 deletions(-) diff --git a/code/__DEFINES/mob_defines.dm b/code/__DEFINES/mob_defines.dm index efd9a4d2991..497c229f08d 100644 --- a/code/__DEFINES/mob_defines.dm +++ b/code/__DEFINES/mob_defines.dm @@ -199,6 +199,8 @@ #define INVISIBILITY_ABSTRACT 101 #define UNHEALING_EAR_DAMAGE 100 +#define DIRECTION_LOCK_SLOWDOWN 3 + //Human sub-species #define isabductor(A) (is_species(A, /datum/species/abductor)) #define isgolem(A) (is_species(A, /datum/species/golem)) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index 5a0c22cbdba..5cbbc279a53 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -252,11 +252,9 @@ return var/face_dir = get_cardinal_dir(src, A) if(!face_dir || forced_look == face_dir || A == src) - forced_look = null - to_chat(src, "Cancelled direction lock.") + clear_forced_look() return - forced_look = face_dir - to_chat(src, "You are now facing [dir2text(forced_look)]. To cancel this, shift-middleclick yourself.") + set_forced_look(A, FALSE) /* Middle shift-control-click @@ -266,13 +264,13 @@ return /mob/living/MiddleShiftControlClickOn(atom/A) + if(incapacitated()) + return var/face_uid = A.UID() if(forced_look == face_uid || A == src) - forced_look = null - to_chat(src, "Cancelled direction lock.") + clear_forced_look() return - forced_look = face_uid - to_chat(src, "You are now facing [A]. To cancel this, shift-middleclick yourself.") + set_forced_look(A, TRUE) // In case of use break glass /* diff --git a/code/_onclick/hud/alert.dm b/code/_onclick/hud/alert.dm index 9d94e5f5ca6..0b70b7f28f0 100644 --- a/code/_onclick/hud/alert.dm +++ b/code/_onclick/hud/alert.dm @@ -337,6 +337,16 @@ or shoot a gun to move around via Newton's 3rd Law of Motion." var/mob/living/L = usr return L.resist() +/obj/screen/alert/direction_lock + name = "Direction Lock" + desc = "You are facing only one direction, slowing your movement down. Click here to stop the direction lock." + icon_state = "direction_lock" + +/obj/screen/alert/direction_lock/Click() + if(isliving(usr)) + var/mob/living/L = usr + return L.clear_forced_look() + //Constructs /obj/screen/alert/holy_fire name = "Holy Fire" diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index 3543ba03393..3a1dfe23296 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -1034,7 +1034,7 @@ if(S) . += S.slowdown_value if(forced_look) - . += 3 + . += DIRECTION_LOCK_SLOWDOWN if(ignorewalk) . += GLOB.configuration.movement.base_run_speed else @@ -1167,3 +1167,40 @@ C.take_organ_damage(damage) C.KnockDown(3 SECONDS) C.visible_message("[C] crashes into [src], knocking them both over!", "You violently crash into [src]!") + +/** + * Sets the mob's direction lock towards a given atom. + * + * Arguments: + * * a - The atom to face towards. + * * track - If TRUE, updates our direction relative to the atom when moving. + */ +/mob/living/proc/set_forced_look(atom/A, track = FALSE) + forced_look = track ? A.UID() : get_cardinal_dir(src, A) + to_chat(src, "You are now facing [track ? A : dir2text(forced_look)]. To cancel this, shift-middleclick yourself.") + throw_alert("direction_lock", /obj/screen/alert/direction_lock) + +/** + * Clears the mob's direction lock if enabled. + * + * Arguments: + * * quiet - Whether to display a chat message. + */ +/mob/living/proc/clear_forced_look(quiet = FALSE) + if(!forced_look) + return + forced_look = null + if(!quiet) + to_chat(src, "Cancelled direction lock.") + clear_alert("direction_lock") + +/mob/living/setDir(new_dir) + if(forced_look) + if(isnum(forced_look)) + dir = forced_look + else + var/atom/A = locateUID(forced_look) + if(istype(A)) + dir = get_cardinal_dir(src, A) + return + return ..() diff --git a/code/modules/mob/living/living_defines.dm b/code/modules/mob/living/living_defines.dm index f1a8e960a15..4abf312b4f1 100644 --- a/code/modules/mob/living/living_defines.dm +++ b/code/modules/mob/living/living_defines.dm @@ -88,6 +88,9 @@ /// the type of holder that will be created when a mob gets scooped up var/holder_type + /// This can either be a numerical direction or a soft object reference (UID). It makes the mob always face towards the selected thing. + var/forced_look = null + var/datum/language/default_language var/datum/middleClickOverride/middleClickOverride = null diff --git a/code/modules/mob/living/living_life.dm b/code/modules/mob/living/living_life.dm index 197a7f084ce..39f9fd35f7e 100644 --- a/code/modules/mob/living/living_life.dm +++ b/code/modules/mob/living/living_life.dm @@ -75,15 +75,18 @@ handle_status_effects() //all special effects, stunned, weakened, jitteryness, hallucination, sleeping, etc if(stat != DEAD) + if(forced_look && !isnum(forced_look)) + var/atom/A = locateUID(forced_look) + if(istype(A)) + var/view = client ? client.maxview() : world.view + if(get_dist(src, A) > view || !(src in viewers(view, A))) + clear_forced_look(TRUE) + to_chat(src, "Your direction target has left your view, you are no longer facing anything.") + else + clear_forced_look(TRUE) + to_chat(src, "Your direction target has left your view, you are no longer facing anything.") + // Make sure it didn't get cleared if(forced_look) - if(!isnum(forced_look)) - var/atom/A = locateUID(forced_look) - if(istype(A)) - var/view = client ? client.maxview() : world.view - if(get_dist(src, A) > view || !(src in viewers(view, A))) - forced_look = null - to_chat(src, "Your direction target has left your view, you are no longer facing anything.") - return setDir() if(machine) diff --git a/code/modules/mob/living/simple_animal/simple_animal.dm b/code/modules/mob/living/simple_animal/simple_animal.dm index ae452633bee..fd4525657ec 100644 --- a/code/modules/mob/living/simple_animal/simple_animal.dm +++ b/code/modules/mob/living/simple_animal/simple_animal.dm @@ -364,7 +364,7 @@ /mob/living/simple_animal/movement_delay() . = speed if(forced_look) - . += 3 + . += DIRECTION_LOCK_SLOWDOWN . += GLOB.configuration.movement.animal_delay /mob/living/simple_animal/Stat() diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index ca5375be9f2..6360aadf128 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -601,17 +601,6 @@ GLOBAL_LIST_INIT(slot_equipment_priority, list( \ client.screen = list() hud_used.show_hud(hud_used.hud_version) -/mob/setDir(new_dir) - if(forced_look) - if(isnum(forced_look)) - dir = forced_look - else - var/atom/A = locateUID(forced_look) - if(istype(A)) - dir = get_cardinal_dir(src, A) - return - . = ..() - /mob/proc/show_inv(mob/user) user.set_machine(src) var/dat = {"