From 31c76286603d7c02e25b93a23cf4bbd46d65aa5f Mon Sep 17 00:00:00 2001 From: Contrabang <91113370+Contrabang@users.noreply.github.com> Date: Sun, 10 Mar 2024 16:08:38 -0400 Subject: [PATCH] Updates get_edge_target_turf to work better with diagonals (#24154) * my evil plan * Apply suggestions from code review Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com> --------- Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com> --- code/__HELPERS/unsorted.dm | 52 +++++++++++++------------ code/game/objects/items/weapons/dice.dm | 3 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 71e7cac7587..62a2500603b 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -510,46 +510,50 @@ Returns 1 if the chain up to the area contains the given typepath // otherwise, just reset the client mob's machine var. -// returns the turf located at the map edge in the specified direction relative to A -// used for mass driver -/proc/get_edge_target_turf(atom/A, direction) - - var/turf/target = locate(A.x, A.y, A.z) - if(!A || !target) - return 0 - //since NORTHEAST == NORTH & EAST, etc, doing it this way allows for diagonal mass drivers in the future +/// Returns the turf located at the map edge in the specified direction relative to target_atom used for mass driver +/proc/get_edge_target_turf(atom/target_atom, direction) + if(!target_atom) + return FALSE + var/turf/target = get_turf(target_atom) + if(!target) + return FALSE + //since NORTHEAST == NORTH|EAST, etc, doing it this way allows for diagonal mass drivers in the future //and isn't really any more complicated - // Note diagonal directions won't usually be accurate + var/x = target_atom.x + var/y = target_atom.y if(direction & NORTH) - target = locate(target.x, world.maxy, target.z) - if(direction & SOUTH) - target = locate(target.x, 1, target.z) + y = world.maxy + else if(direction & SOUTH) //you should not have both NORTH and SOUTH in the provided direction + y = 1 if(direction & EAST) - target = locate(world.maxx, target.y, target.z) - if(direction & WEST) - target = locate(1, target.y, target.z) + x = world.maxx + else if(direction & WEST) + x = 1 + if(IS_DIR_DIAGONAL(direction)) //let's make sure it's accurately-placed for diagonals + var/lowest_distance_to_map_edge = min(abs(x - target_atom.x), abs(y - target_atom.y)) + return get_ranged_target_turf(target_atom, direction, lowest_distance_to_map_edge) + return locate(x, y, target_atom.z) - return target - -// returns turf relative to A in given direction at set range +/** returns turf relative to A in given direction at set range // result is bounded to map size // note range is non-pythagorean // used for disposal system -/proc/get_ranged_target_turf(atom/A, direction, range) +*/ +/proc/get_ranged_target_turf(atom/target_atom, direction, range) - var/x = A.x - var/y = A.y + var/x = target_atom.x + var/y = target_atom.y if(direction & NORTH) y = min(world.maxy, y + range) - if(direction & SOUTH) + else if(direction & SOUTH) y = max(1, y - range) if(direction & EAST) x = min(world.maxx, x + range) - if(direction & WEST) + else if(direction & WEST) //if you have both EAST and WEST in the provided direction, then you're gonna have issues x = max(1, x - range) - return locate(x,y,A.z) + return locate(x, y, target_atom.z) /** * Get ranged target turf, but with direct targets as opposed to directions diff --git a/code/game/objects/items/weapons/dice.dm b/code/game/objects/items/weapons/dice.dm index e7af1f12ae1..a7f4fc10780 100644 --- a/code/game/objects/items/weapons/dice.dm +++ b/code/game/objects/items/weapons/dice.dm @@ -209,8 +209,7 @@ T.visible_message("Unseen forces throw [user]!") user.Stun(12 SECONDS) user.adjustBruteLoss(50) - var/throw_dir = GLOB.cardinal - var/atom/throw_target = get_edge_target_turf(user, throw_dir) + var/atom/throw_target = get_edge_target_turf(user, pick(GLOB.cardinal)) user.throw_at(throw_target, 200, 4) if(8) //Fueltank Explosion