From a7bb217887aae243a3b2ca0fdabfada4609120d8 Mon Sep 17 00:00:00 2001 From: abcdefg30 Date: Mon, 12 Oct 2020 11:51:59 +0200 Subject: [PATCH] Make the calculation of DesiredLocalFacing more readable --- OpenRA.Mods.Common/Traits/Turreted.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Traits/Turreted.cs b/OpenRA.Mods.Common/Traits/Turreted.cs index 8901b94d85..6e98d4de8b 100644 --- a/OpenRA.Mods.Common/Traits/Turreted.cs +++ b/OpenRA.Mods.Common/Traits/Turreted.cs @@ -221,14 +221,17 @@ namespace OpenRA.Mods.Common.Traits if (desiredDirection == WVec.Zero) return LocalOrientation.Yaw; + if (facing == null) + return desiredDirection.Yaw; + // PERF: If the turret rotation axis is vertical we can directly take the difference in facing/yaw - var o = facing != null ? facing.Orientation : (WRot?)null; - if (o == null || (o.Value.Pitch == WAngle.Zero && o.Value.Roll == WAngle.Zero)) - return o.HasValue ? desiredDirection.Yaw - o.Value.Yaw : desiredDirection.Yaw; + var orientation = facing.Orientation; + if (orientation.Pitch == WAngle.Zero && orientation.Roll == WAngle.Zero) + return desiredDirection.Yaw - orientation.Yaw; // If the turret rotation axis is not vertical we must transform the // target direction into the turrets local coordinate system - return desiredDirection.Rotate(-o.Value).Yaw; + return desiredDirection.Rotate(-orientation).Yaw; } }