diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 6b8cd0d4a6..8e343415f1 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -442,19 +442,23 @@ Turf and target are seperate in case you want to teleport some distance from a t 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 + //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 = A.x + var/y = A.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) - return target + x = world.maxx + else if(direction & WEST) + x = 1 + if(direction in GLOB.diagonals) //let's make sure it's accurately-placed for diagonals + var/lowest_distance_to_map_edge = min(abs(x - A.x), abs(y - A.y)) + return get_ranged_target_turf(A, direction, lowest_distance_to_map_edge) + return locate(x,y,A.z) // returns turf relative to A in given direction at set range // result is bounded to map size @@ -466,11 +470,11 @@ Turf and target are seperate in case you want to teleport some distance from a t var/y = A.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) diff --git a/code/game/machinery/camera/camera.dm b/code/game/machinery/camera/camera.dm index be33ed9f8b..cc756caf98 100644 --- a/code/game/machinery/camera/camera.dm +++ b/code/game/machinery/camera/camera.dm @@ -323,19 +323,10 @@ /atom/proc/auto_turn() //Automatically turns based on nearby walls. var/turf/closed/wall/T = null - for(var/i = 1, i <= 8; i += i) + for(var/i in GLOB.cardinals) T = get_ranged_target_turf(src, i, 1) if(istype(T)) - //If someone knows a better way to do this, let me know. -Giacom - switch(i) - if(NORTH) - src.setDir(SOUTH) - if(SOUTH) - src.setDir(NORTH) - if(WEST) - src.setDir(EAST) - if(EAST) - src.setDir(WEST) + setDir(turn(i, 180)) break //Return a working camera that can see a given mob