From 212f07f890184dbac831017bf640c40c9a3667fb Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 31 Oct 2013 21:29:50 +1300 Subject: [PATCH] Add a helper for finding the map edge in a given direction. --- OpenRA.Game/WorldUtils.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index eb5490e097..0e0b613690 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -124,6 +124,15 @@ namespace OpenRA r.Next(w.Map.Bounds.Top, w.Map.Bounds.Bottom)); } + public static WPos FindMapEdge(this World w, WPos pos, WVec dir) + { + var tl = w.Map.Bounds.TopLeftAsCPos().TopLeft; + var br = w.Map.Bounds.BottomRightAsCPos().BottomRight; + var x = dir.X == 0 ? int.MaxValue : ((dir.X < 0 ? tl.X : br.X) - pos.X) / dir.X; + var y = dir.Y == 0 ? int.MaxValue : ((dir.Y < 0 ? tl.Y : br.Y) - pos.Y) / dir.Y; + return pos + Math.Min(x, y) * dir; + } + public static bool HasVoices(this Actor a) { var selectable = a.Info.Traits.GetOrDefault();