Move DistanceToMapEdge from WorldUtils to Map

This commit is contained in:
Pavlos Touboulidis
2014-06-13 14:04:36 +03:00
parent f0c672b70c
commit 03b8096807
3 changed files with 11 additions and 11 deletions

View File

@@ -564,5 +564,14 @@ namespace OpenRA
r.Next(Bounds.Left, Bounds.Right),
r.Next(Bounds.Top, Bounds.Bottom));
}
public WRange DistanceToEdge(WPos pos, WVec dir)
{
var tl = Bounds.TopLeftAsCPos().TopLeft;
var br = 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 new WRange(Math.Min(x, y) * dir.Length);
}
}
}

View File

@@ -100,15 +100,6 @@ namespace OpenRA
: (edge ? w.Map.Bounds.Top : w.Map.Bounds.Bottom));
}
public static WRange DistanceToMapEdge(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 new WRange(Math.Min(x, y) * dir.Length);
}
public static bool HasVoices(this Actor a)
{
var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();

View File

@@ -65,8 +65,8 @@ namespace OpenRA.Mods.RA
var altitude = self.World.Map.Rules.Actors[info.UnitType].Traits.Get<PlaneInfo>().CruiseAltitude.Range;
var target = order.TargetLocation.CenterPosition + new WVec(0, 0, altitude);
var startEdge = target - (self.World.DistanceToMapEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.DistanceToMapEdge(target, delta) + info.Cordon).Range * delta / 1024;
var startEdge = target - (self.World.Map.DistanceToEdge(target, -delta) + info.Cordon).Range * delta / 1024;
var finishEdge = target + (self.World.Map.DistanceToEdge(target, delta) + info.Cordon).Range * delta / 1024;
Actor flare = null;
Actor camera = null;