From 2daeb45bfe53b11fe181b86796ce943ec016a3a0 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Tue, 1 Feb 2011 22:06:09 +1300 Subject: [PATCH] Fix a subtle bug with flying units in spatialbins. Fixes #489. --- OpenRA.Game/Actor.cs | 18 ++++++++++++------ OpenRA.Game/Graphics/WorldRenderer.cs | 2 +- OpenRA.Game/Traits/Selectable.cs | 2 +- OpenRA.Game/WorldUtils.cs | 2 +- OpenRA.Mods.RA/GainsExperience.cs | 2 +- OpenRA.Mods.RA/UnitStances/UnitStance.cs | 2 +- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index 9b43c0cace..a066e805b8 100755 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -88,7 +88,11 @@ namespace OpenRA var sprites = TraitsImplementing().SelectMany(x => x.Render(this)); 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,12 +102,14 @@ 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(); - if (move != null) loc -= new float2(0, move.Altitude); + var move = TraitOrDefault(); + 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); } diff --git a/OpenRA.Game/Graphics/WorldRenderer.cs b/OpenRA.Game/Graphics/WorldRenderer.cs index b1771344b5..d1985ba24a 100644 --- a/OpenRA.Game/Graphics/WorldRenderer.cs +++ b/OpenRA.Game/Graphics/WorldRenderer.cs @@ -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); diff --git a/OpenRA.Game/Traits/Selectable.cs b/OpenRA.Game/Traits/Selectable.cs index 8290fb4ee0..99200b83d1 100644 --- a/OpenRA.Game/Traits/Selectable.cs +++ b/OpenRA.Game/Traits/Selectable.cs @@ -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); diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 2e6564cacf..244ab3dc00 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -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); } diff --git a/OpenRA.Mods.RA/GainsExperience.cs b/OpenRA.Mods.RA/GainsExperience.cs index d264b4715f..e493b259a3 100644 --- a/OpenRA.Mods.RA/GainsExperience.cs +++ b/OpenRA.Mods.RA/GainsExperience.cs @@ -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); } diff --git a/OpenRA.Mods.RA/UnitStances/UnitStance.cs b/OpenRA.Mods.RA/UnitStances/UnitStance.cs index 35a0497692..4caf306b9e 100644 --- a/OpenRA.Mods.RA/UnitStances/UnitStance.cs +++ b/OpenRA.Mods.RA/UnitStances/UnitStance.cs @@ -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);