Skip to content

Commit

Permalink
[MIRROR] Fixes Mech Strafing [MDB IGNORE] (#686)
Browse files Browse the repository at this point in the history
* Fixes Mech Strafing (#79749)
---------

Co-authored-by: SkyratBot <[email protected]>
Co-authored-by: SapphicOverload <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2023
1 parent 22c21bb commit 4431e18
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
#define COMSIG_ATOM_DIR_CHANGE "atom_dir_change"
///from base of atom/setDir(): (old_dir, new_dir). Called after the direction changes.
#define COMSIG_ATOM_POST_DIR_CHANGE "atom_dir_change"
///from base of atom/movable/keybind_face_direction(): (dir). Called before turning with the movement lock key.
#define COMSIG_MOVABLE_KEYBIND_FACE_DIR "keybind_face_dir"
///ignores the movement lock key, used for turning while strafing in a mech
#define COMSIG_IGNORE_MOVEMENT_LOCK (1<<0)

/// from /datum/component/singularity/proc/can_move(), as well as /obj/energy_ball/proc/can_move()
/// if a callback returns `SINGULARITY_TRY_MOVE_BLOCK`, then the singularity will not move to that turf
#define COMSIG_ATOM_SINGULARITY_TRY_MOVE "atom_singularity_try_move"
Expand Down
3 changes: 2 additions & 1 deletion code/modules/keybindings/bindings_atom.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
if(user && movement_dir) //If we're not moving, don't compensate, as byond will auto-fill dir otherwise
movement_dir = turn(movement_dir, -dir2angle(user.dir)) //By doing this we ensure that our input direction is offset by the client (camera) direction

if(user?.movement_locked)
//turn without moving while using the movement lock key, unless something wants to ignore it and move anyway
if(user?.movement_locked && !(SEND_SIGNAL(src, COMSIG_MOVABLE_KEYBIND_FACE_DIR, movement_dir) & COMSIG_IGNORE_MOVEMENT_LOCK))
keybind_face_direction(movement_dir)
else
user?.Move(get_step(src, movement_dir), movement_dir)
Expand Down
8 changes: 6 additions & 2 deletions code/modules/vehicles/mecha/mecha_mob_interaction.dm
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@
/obj/vehicle/sealed/mecha/add_occupant(mob/M, control_flags)
RegisterSignal(M, COMSIG_MOB_CLICKON, PROC_REF(on_mouseclick), TRUE)
RegisterSignal(M, COMSIG_MOB_SAY, PROC_REF(display_speech_bubble), TRUE)
RegisterSignal(M, COMSIG_MOVABLE_KEYBIND_FACE_DIR, PROC_REF(on_turn), TRUE)
. = ..()
update_appearance()

/obj/vehicle/sealed/mecha/remove_occupant(mob/M)
UnregisterSignal(M, COMSIG_MOB_CLICKON)
UnregisterSignal(M, COMSIG_MOB_SAY)
UnregisterSignal(M, list(
COMSIG_MOB_CLICKON,
COMSIG_MOB_SAY,
COMSIG_MOVABLE_KEYBIND_FACE_DIR,
))
M.clear_alert(ALERT_CHARGE)
M.clear_alert(ALERT_MECH_DAMAGE)
if(M.client)
Expand Down
9 changes: 7 additions & 2 deletions code/modules/vehicles/mecha/mecha_movement.dm
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
return TRUE
return FALSE

///Called when the driver turns with the movement lock key
/obj/vehicle/sealed/mecha/proc/on_turn(mob/living/driver, direction)
SIGNAL_HANDLER
return COMSIG_IGNORE_MOVEMENT_LOCK

/obj/vehicle/sealed/mecha/relaymove(mob/living/user, direction)
. = TRUE
if(!canmove || !(user in return_drivers()))
Expand Down Expand Up @@ -121,11 +126,11 @@
break

//if we're not facing the way we're going rotate us
if(dir != direction && !strafe || forcerotate || keyheld)
if(dir != direction && (!strafe || forcerotate || keyheld))
if(dir != direction && !(mecha_flags & QUIET_TURNS) && !step_silent)
playsound(src,turnsound,40,TRUE)
setDir(direction)
if(!pivot_step) //If we pivot step, we don't return here so we don't just come to a stop
if(keyheld || !pivot_step) //If we pivot step, we don't return here so we don't just come to a stop
return TRUE

set_glide_size(DELAY_TO_GLIDE_SIZE(movedelay))
Expand Down

0 comments on commit 4431e18

Please sign in to comment.