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>
This commit is contained in:
Contrabang
2024-03-10 20:08:38 +00:00
committed by GitHub
co-authored by DGamerL
parent e9cd4825a4
commit 31c7628660
2 changed files with 29 additions and 26 deletions
+28 -24
View File
@@ -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
+1 -2
View File
@@ -209,8 +209,7 @@
T.visible_message("<span class='userdanger'>Unseen forces throw [user]!</span>")
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