Fix a subtle bug with flying units in spatialbins. Fixes #489.

This commit is contained in:
Paul Chote
2011-02-01 22:06:09 +13:00
parent 467c2a969d
commit 2daeb45bfe
6 changed files with 17 additions and 11 deletions

View File

@@ -89,6 +89,10 @@ namespace OpenRA
return mods.Aggregate(sprites, (m, p) => p.ModifyRender(this, m));
}
// When useAltitude = true, the bounding box is extended
// vertically to altitude = 0 to support FindUnitsInCircle queries
// When false, the bounding box is given for the actor
// at its current altitude
public RectangleF GetBounds(bool useAltitude)
{
var size = Size.Value;
@@ -98,10 +102,12 @@ namespace OpenRA
if (si != null && si.Bounds != null && si.Bounds.Length > 2)
loc += new float2(si.Bounds[2], si.Bounds[3]);
if (useAltitude)
{
var move = TraitOrDefault<IMove>();
if (move != null) loc -= new float2(0, move.Altitude);
if (move != null)
{
loc -= new float2(0, move.Altitude);
if (useAltitude)
size = new float2(size.X, size.Y + move.Altitude);
}
return new RectangleF(loc.X, loc.Y, size.X, size.Y);

View File

@@ -127,7 +127,7 @@ namespace OpenRA.Graphics
public void DrawSelectionBox(Actor selectedUnit, Color c)
{
var bounds = selectedUnit.GetBounds(true);
var bounds = selectedUnit.GetBounds(false);
var xy = new float2(bounds.Left, bounds.Top);
var Xy = new float2(bounds.Right, bounds.Top);

View File

@@ -30,7 +30,7 @@ namespace OpenRA.Traits
public void RenderAfterWorld (WorldRenderer wr, Actor self)
{
var bounds = self.GetBounds(true);
var bounds = self.GetBounds(false);
Color selectionColor = Color.White;
var xy = new float2(bounds.Left, bounds.Top);

View File

@@ -45,7 +45,7 @@ namespace OpenRA
var rect = new RectangleF(min.X, min.Y, max.X - min.X, max.Y - min.Y);
var inBox = actors.Where(x => x.GetBounds(false).IntersectsWith(rect));
var inBox = actors.Where(x => x.GetBounds(true).IntersectsWith(rect));
return inBox.Where(x => (x.CenterLocation - a).LengthSquared < r * r);
}

View File

@@ -92,7 +92,7 @@ namespace OpenRA.Mods.RA
if (self.Owner == self.World.LocalPlayer && Level > 0)
{
RankAnim.Tick(); // hack
var bounds = self.GetBounds(true);
var bounds = self.GetBounds(false);
yield return new Renderable(RankAnim.Image,
new float2(bounds.Right - 6, bounds.Bottom - 8), "effect", (int)self.CenterLocation.Y);
}

View File

@@ -248,7 +248,7 @@ namespace OpenRA.Mods.RA
private void RenderStance(Actor self)
{
var bounds = self.GetBounds(true);
var bounds = self.GetBounds(false);
var loc = new float2(bounds.Left, bounds.Top) + new float2(0, 1);
var max = Math.Max(bounds.Height, bounds.Width);