From 59f5e241898d834d7ef652b1e0f090155194f5b3 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 23 Apr 2016 17:14:04 +0100 Subject: [PATCH] Simplify and fix missile turnaround facing check. --- OpenRA.Mods.Common/Effects/Missile.cs | 3 ++- OpenRA.Mods.Common/Util.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/OpenRA.Mods.Common/Effects/Missile.cs b/OpenRA.Mods.Common/Effects/Missile.cs index 871db3501e..76781a0613 100644 --- a/OpenRA.Mods.Common/Effects/Missile.cs +++ b/OpenRA.Mods.Common/Effects/Missile.cs @@ -712,7 +712,8 @@ namespace OpenRA.Mods.Common.Effects var velVec = tarDistVec + predVel; var desiredHFacing = velVec.HorizontalLengthSquared != 0 ? velVec.Yaw.Facing : hFacing; - if (allowPassBy && Math.Abs((desiredHFacing - hFacing) & 0xFF) >= Math.Abs((desiredHFacing + 128 - hFacing) & 0xFF)) + var delta = Util.NormalizeFacing(hFacing - desiredHFacing); + if (allowPassBy && delta > 64 && delta < 192) { desiredHFacing = (desiredHFacing + 128) & 0xFF; targetPassedBy = true; diff --git a/OpenRA.Mods.Common/Util.cs b/OpenRA.Mods.Common/Util.cs index 926155a13c..54a3ccc538 100644 --- a/OpenRA.Mods.Common/Util.cs +++ b/OpenRA.Mods.Common/Util.cs @@ -73,6 +73,14 @@ namespace OpenRA.Mods.Common } } + public static int NormalizeFacing(int f) + { + if (f >= 0) + return f & 0xFF; + + return 0xFF - (-f & 0xFF); + } + public static WPos BetweenCells(World w, CPos from, CPos to) { return WPos.Lerp(w.Map.CenterOfCell(from), w.Map.CenterOfCell(to), 1, 2);