Files
Bubberstation/modular_skyrat/modules/pixel_shift/code/pixel_shift.dm
RimiNosha 56d1f36654 [MODULAR] [HOST REQUEST] Pixel Shift Out of the Way! (#15175)
* Out of the way pixel shift? No way!

* Push suggestions and a logic fix!

* *Much* better logic!

* Oops comment!

* Apply suggestions!

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

* Document var!

Website moment!

* Apply suggestions!

* Fix inaccurate comment!

* Update modular_skyrat/modules/pixel_shift/code/pixel_shift.dm

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>

Co-authored-by: GoldenAlpharex <58045821+GoldenAlpharex@users.noreply.github.com>
2022-08-27 15:56:42 -04:00

98 lines
2.6 KiB
Plaintext

#define MAXIMUM_PIXEL_SHIFT 16
#define PASSABLE_SHIFT_THRESHOLD 8
/mob
/// Whether the mob is pixel shifted or not
var/is_shifted = FALSE
/// If we are in the shifting setting.
var/shifting = FALSE
/// Takes the four cardinal direction defines. Any atoms moving into this atom's tile will be allowed to from the added directions.
var/passthroughable = NONE
/datum/keybinding/mob/pixel_shift
hotkey_keys = list("B")
name = "pixel_shift"
full_name = "Pixel Shift"
description = "Shift your characters offset."
category = CATEGORY_MOVEMENT
keybind_signal = COMSIG_KB_MOB_PIXELSHIFT
/datum/keybinding/mob/pixel_shift/down(client/user)
. = ..()
if(.)
return
var/mob/M = user.mob
M.shifting = TRUE
return TRUE
/datum/keybinding/mob/pixel_shift/up(client/user)
. = ..()
if(.)
return
var/mob/M = user.mob
M.shifting = FALSE
return TRUE
/mob/proc/unpixel_shift()
return
/mob/living/unpixel_shift()
. = ..()
passthroughable = NONE
if(is_shifted)
is_shifted = FALSE
pixel_x = body_position_pixel_x_offset + base_pixel_x
pixel_y = body_position_pixel_y_offset + base_pixel_y
/mob/proc/pixel_shift(direction)
return
/mob/living/set_pull_offsets(mob/living/pull_target, grab_state)
pull_target.unpixel_shift()
return ..()
/mob/living/reset_pull_offsets(mob/living/pull_target, override)
pull_target.unpixel_shift()
return ..()
/mob/living/pixel_shift(direction)
passthroughable = NONE
switch(direction)
if(NORTH)
if(pixel_y <= MAXIMUM_PIXEL_SHIFT + base_pixel_y)
pixel_y++
is_shifted = TRUE
if(EAST)
if(pixel_x <= MAXIMUM_PIXEL_SHIFT + base_pixel_x)
pixel_x++
is_shifted = TRUE
if(SOUTH)
if(pixel_y >= -MAXIMUM_PIXEL_SHIFT + base_pixel_y)
pixel_y--
is_shifted = TRUE
if(WEST)
if(pixel_x >= -MAXIMUM_PIXEL_SHIFT + base_pixel_x)
pixel_x--
is_shifted = TRUE
// Yes, I know this sets it to true for everything if more than one is matched.
// Movement doesn't check diagonals, and instead just checks EAST or WEST, depending on where you are for those.
if(pixel_y > PASSABLE_SHIFT_THRESHOLD)
passthroughable |= EAST | SOUTH | WEST
if(pixel_x > PASSABLE_SHIFT_THRESHOLD)
passthroughable |= NORTH | SOUTH | WEST
if(pixel_y < -PASSABLE_SHIFT_THRESHOLD)
passthroughable |= NORTH | EAST | WEST
if(pixel_x < -PASSABLE_SHIFT_THRESHOLD)
passthroughable |= NORTH | EAST | SOUTH
/mob/living/CanAllowThrough(atom/movable/mover, border_dir)
// Make sure to not allow projectiles of any kind past where they normally wouldn't.
if(!istype(mover, /obj/projectile) && !mover.throwing && passthroughable & border_dir)
return TRUE
return ..()
#undef MAXIMUM_PIXEL_SHIFT
#undef PASSABLE_SHIFT_THRESHOLD