[MIRROR] Fixes projectiles facing north if ricocheting, deflected or homing (#29057)

* Fixes projectiles facing north if ricocheting, deflected or homing (#85216)

## About The Pull Request
It **turns** out that `TurnTo` doesn't re**turn** `Turn`, but the angle
(number, not matrix) it's **turn**ed to (used nowhere in the code), and
`transform` is built-in variable that default to an identity matrix if
set to an invalid value (anything but another matrix)

The only thing keeping the projectiles facing the right direction when
fired up to one of the aforementioned situations was another `Turn` call
(not `turnTo`) called on `projectile/fire`, which I apparently didn't
fully grasp the redundancy of (if there were no such issue to begin
with) at the time.

This PR also cleans up and rearranges the related code a little,
including a fallback that was never reached because the projectile
`Angle` variable is never null (unless something theorically fucky wucky
happens with projectile code but that'd be an even bigger issue).

## Why It's Good For The Game
Fixing an old issue caused by the author of this PR in #80599, me.

## Changelog

🆑
fix: Fixes projectiles facing north if ricocheting, deflected or homing
/🆑

* Fixes projectiles facing north if ricocheting, deflected or homing

---------

Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com>
This commit is contained in:
SkyratBot
2024-07-26 17:33:10 +02:00
committed by GitHub
parent b724be3f6c
commit 8fd896e1ca
2 changed files with 7 additions and 9 deletions
+1 -2
View File
@@ -40,8 +40,7 @@
decompose_matrix.rotation = arctan(cossine, sine) * flip_sign
/matrix/proc/TurnTo(old_angle, new_angle)
. = new_angle - old_angle
Turn(.) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT
return Turn(new_angle - old_angle) //BYOND handles cases such as -270, 360, 540 etc. DOES NOT HANDLE 180 TURNS WELL, THEY TWEEN AND LOOK LIKE SHIT
/**
* Shear the transform on either or both axes.
+6 -7
View File
@@ -84,7 +84,8 @@
/// `speed` a modest value like 1 and set this to a low value like 0.2.
var/pixel_speed_multiplier = 1
var/Angle = 0
/// The current angle of the projectile. Initially null, so if the arg is missing from [/fire()], we can calculate it from firer and target as fallback.
var/Angle
var/original_angle = 0 //Angle at firing
var/nondirectional_sprite = FALSE //Set TRUE to prevent projectiles from having their sprites rotated based on firing angle
var/spread = 0 //amount (in degrees) of projectile spread
@@ -811,21 +812,19 @@
process_hit(get_turf(direct_target), direct_target)
if(QDELETED(src))
return
var/turf/starting = get_turf(src)
if(isnum(angle))
set_angle(angle)
if(spread)
set_angle(Angle + ((rand() - 0.5) * spread))
var/turf/starting = get_turf(src)
if(isnull(Angle)) //Try to resolve through offsets if there's no angle set.
else if(isnull(Angle)) //Try to resolve through offsets if there's no angle set.
if(isnull(xo) || isnull(yo))
stack_trace("WARNING: Projectile [type] deleted due to being unable to resolve a target after angle was null!")
qdel(src)
return
var/turf/target = locate(clamp(starting + xo, 1, world.maxx), clamp(starting + yo, 1, world.maxy), starting.z)
set_angle(get_angle(src, target))
if(spread)
set_angle(Angle + (rand() - 0.5) * spread)
original_angle = Angle
if(!nondirectional_sprite)
transform = transform.Turn(Angle)
trajectory_ignore_forcemove = TRUE
forceMove(starting)
trajectory_ignore_forcemove = FALSE