From caccc13e824966d83ee9f162f494b5e2addb4f2c Mon Sep 17 00:00:00 2001 From: tigercat2000 Date: Thu, 19 Apr 2018 19:01:29 -0800 Subject: [PATCH] Directional Locking This adds the ability to lock your mob towards facing either a certain direction or a certain atom. Direction is done by shift-middleclick, atom is done by shift-ctrl-middleclick. --- code/_onclick/click.dm | 32 ++++++++++++++++++++++++++++++++ code/modules/mob/mob.dm | 20 ++++++++++++++++++++ code/modules/mob/mob_defines.dm | 2 ++ code/modules/mob/mob_movement.dm | 2 ++ 4 files changed, 56 insertions(+) diff --git a/code/_onclick/click.dm b/code/_onclick/click.dm index f300608e699..9679935bdaa 100644 --- a/code/_onclick/click.dm +++ b/code/_onclick/click.dm @@ -70,6 +70,12 @@ changeNext_click(1) var/list/modifiers = params2list(params) + if(modifiers["middle"] && modifiers["shift"] && modifiers["ctrl"]) + MiddleShiftControlClickOn(A) + return + if(modifiers["middle"] && modifiers["shift"]) + MiddleShiftClickOn(A) + return if(modifiers["shift"] && modifiers["ctrl"]) CtrlShiftClickOn(A) return @@ -225,6 +231,32 @@ else ..() +/* + Middle shift-click + Makes the mob face the direction of the clicked thing +*/ +/mob/proc/MiddleShiftClickOn(atom/A) + var/face_dir = get_cardinal_dir(src, A) + if(forced_look == face_dir) + forced_look = null + to_chat(src, "You are no longer facing any direction.") + return + forced_look = face_dir + to_chat(src, "You are now facing [dir2text(forced_look)].") + +/* + Middle shift-control-click + Makes the mob constantly face the object (until it's out of sight) +*/ +/mob/proc/MiddleShiftControlClickOn(atom/A) + var/face_uid = A.UID() + if(forced_look == face_uid) + forced_look = null + to_chat(src, "You are no longer facing [A].") + return + forced_look = face_uid + to_chat(src, "You are now facing [A].") + // In case of use break glass /* /atom/proc/MiddleClick(var/mob/M as mob) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index d3641533ad8..79f14b7bc67 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -170,6 +170,15 @@ return 0 /mob/proc/Life() + if(forced_look) + if(!isnum(forced_look)) + var/atom/A = locateUID(forced_look) + if(istype(A)) + if(get_dist(src, A) > (client ? client.view : world.view)) + forced_look = null + to_chat(src, "Your direction target has left your view, you are no longer facing anything.") + return + setDir() // handle_typing_indicator() return @@ -533,6 +542,17 @@ var/list/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 = {" diff --git a/code/modules/mob/mob_defines.dm b/code/modules/mob/mob_defines.dm index 4a5e9d1a1f4..d411482534b 100644 --- a/code/modules/mob/mob_defines.dm +++ b/code/modules/mob/mob_defines.dm @@ -199,3 +199,5 @@ var/list/progressbars = null //for stacking do_after bars var/list/tkgrabbed_objects = list() // Assoc list of items to TK grabs + + var/forced_look = null // This can either be a numerical direction or a soft object reference (UID). It makes the mob always face towards the selected thing. \ No newline at end of file diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index a112513a3a1..779ec706b22 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -268,6 +268,8 @@ else . = ..() + mob.setDir(direct) + for(var/obj/item/grab/G in mob) if(G.state == GRAB_NECK) mob.setDir(reverse_dir[direct])