From b74d754c7b7076841e5162d31a55845e9c8b4834 Mon Sep 17 00:00:00 2001 From: Doubleumc Date: Thu, 14 Dec 2023 02:00:21 -0500 Subject: [PATCH] refactor Get_Pixel_Angle() Get_Pixel_Angle() renamed and refactored, Get_Angle() now calls it instead of having its own calcuation --- code/__HELPERS/unsorted.dm | 11 ++++++----- code/modules/projectiles/projectile.dm | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/code/__HELPERS/unsorted.dm b/code/__HELPERS/unsorted.dm index 23c7a9f2dc08..194db09bede8 100644 --- a/code/__HELPERS/unsorted.dm +++ b/code/__HELPERS/unsorted.dm @@ -99,6 +99,7 @@ var/atom/movable/big_subject = subject . += (big_subject.bound_height - world.icon_size) / 2 +/// Calculate the angle between two atoms. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc. /proc/Get_Angle(atom/start, atom/end)//For beams. if(!start || !end) return 0 @@ -112,14 +113,14 @@ return 0 //Atoms are not on turfs. var/dy = get_pixel_position_y(end) - get_pixel_position_y(start) var/dx = get_pixel_position_x(end) - get_pixel_position_x(start) - . = arctan(dy, dx) + return delta_to_angle(dx, dy) + +/// Calculate the angle produced by a pair of x and y deltas. Uses north-clockwise convention: NORTH = 0, EAST = 90, etc. +/proc/delta_to_angle(dx, dy) + . = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc. if(. < 0) . += 360 -/proc/Get_Pixel_Angle(dx, dy)//for getting the angle when animating something's pixel_x and pixel_y - var/da = arctan(dy, dx) //y-then-x results in north-clockwise convention: https://en.wikipedia.org/wiki/Atan2#East-counterclockwise,_north-clockwise_and_south-clockwise_conventions,_etc. - return (da >= 0 ? da : da + 360) - /proc/angle_to_dir(angle) switch(angle) //diagonal directions get priority over straight directions in edge cases if (22.5 to 67.5) diff --git a/code/modules/projectiles/projectile.dm b/code/modules/projectiles/projectile.dm index f44da069c917..a473c06b2b9d 100644 --- a/code/modules/projectiles/projectile.dm +++ b/code/modules/projectiles/projectile.dm @@ -245,7 +245,7 @@ var/dx = p_x + aim_turf.x * 32 - source_turf.x * 32 // todo account for firer offsets var/dy = p_y + aim_turf.y * 32 - source_turf.y * 32 - angle = Get_Pixel_Angle(dx, dy) + angle = delta_to_angle(dx, dy) /obj/projectile/process(delta_time) . = PROC_RETURN_SLEEP @@ -287,7 +287,7 @@ //Change the bullet angle to its visual path - var/vis_angle = Get_Pixel_Angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source) + var/vis_angle = delta_to_angle(pixel_x_target - pixel_x_source, pixel_y_target - pixel_y_source) var/matrix/rotate = matrix() rotate.Turn(vis_angle) apply_transform(rotate)