From 4f299c403a1e60deddd70b568974bf1b8b1ce467 Mon Sep 17 00:00:00 2001 From: moxian Date: Fri, 27 May 2022 19:15:40 +0000 Subject: [PATCH] Un-jank diagonal movement (#17872) * Un-jank diagonal movement * grab fix --- code/game/atoms_movable.dm | 34 ++++++++++++++++---------------- code/modules/mob/mob_movement.dm | 17 ++++++++++------ 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/code/game/atoms_movable.dm b/code/game/atoms_movable.dm index 6c0984dd091..f8256c392d3 100644 --- a/code/game/atoms_movable.dm +++ b/code/game/atoms_movable.dm @@ -181,45 +181,45 @@ // The `&& moving_diagonally` checks are so that a forceMove taking // place due to a Crossed, Bumped, etc. call will interrupt // the second half of the diagonal movement, or the second attempt - // at a first half if step() fails because we hit something. + // at a first half if ..() fails because we hit something. if(direct & NORTH) if(direct & EAST) - if(step(src, NORTH) && moving_diagonally) + if(..(get_step(src, NORTH), NORTH) && moving_diagonally) first_step_dir = NORTH moving_diagonally = SECOND_DIAG_STEP - . = step(src, EAST) - else if(moving_diagonally && step(src, EAST)) + . = ..(get_step(src, EAST), EAST) + else if(moving_diagonally && ..(get_step(src, EAST), EAST)) first_step_dir = EAST moving_diagonally = SECOND_DIAG_STEP - . = step(src, NORTH) + . = ..(get_step(src, NORTH), NORTH) else if(direct & WEST) - if(step(src, NORTH) && moving_diagonally) + if(..(get_step(src, NORTH), NORTH) && moving_diagonally) first_step_dir = NORTH moving_diagonally = SECOND_DIAG_STEP - . = step(src, WEST) - else if(moving_diagonally && step(src, WEST)) + . = ..(get_step(src, WEST), WEST) + else if(moving_diagonally && ..(get_step(src, WEST), WEST)) first_step_dir = WEST moving_diagonally = SECOND_DIAG_STEP - . = step(src, NORTH) + . = ..(get_step(src, NORTH), NORTH) else if(direct & SOUTH) if(direct & EAST) - if(step(src, SOUTH) && moving_diagonally) + if(..(get_step(src, SOUTH), SOUTH) && moving_diagonally) first_step_dir = SOUTH moving_diagonally = SECOND_DIAG_STEP - . = step(src, EAST) - else if(moving_diagonally && step(src, EAST)) + . = ..(get_step(src, EAST), EAST) + else if(moving_diagonally && ..(get_step(src, EAST), EAST)) first_step_dir = EAST moving_diagonally = SECOND_DIAG_STEP - . = step(src, SOUTH) + . = ..(get_step(src, SOUTH), SOUTH) else if(direct & WEST) - if(step(src, SOUTH) && moving_diagonally) + if(..(get_step(src, SOUTH), SOUTH) && moving_diagonally) first_step_dir = SOUTH moving_diagonally = SECOND_DIAG_STEP - . = step(src, WEST) - else if(moving_diagonally && step(src, WEST)) + . = ..(get_step(src, WEST), WEST) + else if(moving_diagonally && ..(get_step(src, WEST), WEST)) first_step_dir = WEST moving_diagonally = SECOND_DIAG_STEP - . = step(src, SOUTH) + . = ..(get_step(src, SOUTH), SOUTH) if(moving_diagonally == SECOND_DIAG_STEP) if(!.) setDir(first_step_dir) diff --git a/code/modules/mob/mob_movement.dm b/code/modules/mob/mob_movement.dm index 4261f16a9a7..7fbdfcab2df 100644 --- a/code/modules/mob/mob_movement.dm +++ b/code/modules/mob/mob_movement.dm @@ -180,18 +180,23 @@ if(mob.pulling) prev_pulling_loc = mob.pulling.loc - . = mob.SelfMove(n, direct, delay) // The actual movement + if(!(direct & (direct - 1))) // cardinal direction + . = mob.SelfMove(n, direct, delay) + else // diagonal movements take twice as long + . = mob.SelfMove(n, direct, delay * 2) + if(mob.loc == n) + // only incur the extra delay if the move was *actually* diagonal + // There would be a bit of visual jank if we try to walk diagonally next to a wall + // and the move ends up being cardinal, rather than diagonal, + // but that's better than it being jank on every *successful* diagonal move. + delay *= 2 + move_delay += delay if(prev_pulling_loc && mob.pulling?.face_while_pulling && (mob.pulling.loc != prev_pulling_loc)) mob.setDir(get_dir(mob, mob.pulling)) // Face welding tanks and stuff when pulling else mob.setDir(direct) - if((direct & (direct - 1)) && mob.loc == n) //moved diagonally successfully - delay = mob.movement_delay() * 2 //Will prevent mob diagonal moves from smoothing accurately, sadly - - move_delay += delay - for(var/obj/item/grab/G in mob) if(G.state == GRAB_NECK) mob.setDir(angle2dir((dir2angle(direct) + 202.5) % 365))