From a234dd4382187d52abbbe19edc6e3f86cd4cf215 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 22 Jul 2010 10:40:23 +1200 Subject: [PATCH] New interface for things that show on radar; groundwork for future patches. --- OpenRA.Game/Graphics/Minimap.cs | 18 ++++++++++-------- OpenRA.Game/Traits/Building.cs | 13 ++++++++++++- OpenRA.Game/Traits/TraitsInterfaces.cs | 6 ++++++ OpenRA.Game/Traits/Unit.cs | 15 ++++++++++++++- 4 files changed, 42 insertions(+), 10 deletions(-) diff --git a/OpenRA.Game/Graphics/Minimap.cs b/OpenRA.Game/Graphics/Minimap.cs index 22906f8dd3..4455225d0e 100644 --- a/OpenRA.Game/Graphics/Minimap.cs +++ b/OpenRA.Game/Graphics/Minimap.cs @@ -126,10 +126,16 @@ namespace OpenRA.Graphics { int* c = (int*)bitmapData.Scan0; - foreach (var a in world.Queries.WithTrait().Where(a => a.Actor.Owner != null && a.Actor.IsVisible())) - *(c + ((a.Actor.Location.Y - world.Map.TopLeft.Y)* bitmapData.Stride >> 2) + a.Actor.Location.X - world.Map.TopLeft.X) = - a.Actor.Owner.Color.ToArgb(); - + foreach (var t in world.Queries.WithTraitMultiple()) + { + var color = t.Trait.RadarSignatureColor(t.Actor); + if (color == null) + continue; + + foreach( var cell in t.Trait.RadarSignatureCells(t.Actor)) + *(c + ((cell.Y - world.Map.TopLeft.Y)* bitmapData.Stride >> 2) + cell.X - world.Map.TopLeft.X) = color.ToArgb(); + } + for (var x = 0; x < map.Width; x++) for (var y = 0; y < map.Height; y++) { @@ -146,10 +152,6 @@ namespace OpenRA.Graphics *(c + (y * bitmapData.Stride >> 2) + x) = Util.LerpARGBColor(fogOpacity, *(c + (y * bitmapData.Stride >> 2) + x), shroud); continue; } - - var b = world.WorldActor.traits.Get().GetBuildingAt(new int2(mapX, mapY)); - if (b != null) - *(c + (y * bitmapData.Stride >> 2) + x) = b.Owner.Color.ToArgb(); } } diff --git a/OpenRA.Game/Traits/Building.cs b/OpenRA.Game/Traits/Building.cs index 3a0169b4ad..634e568cf6 100644 --- a/OpenRA.Game/Traits/Building.cs +++ b/OpenRA.Game/Traits/Building.cs @@ -10,6 +10,7 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; using OpenRA.Effects; using OpenRA.GameRules; @@ -47,7 +48,7 @@ namespace OpenRA.Traits public object Create(ActorInitializer init) { return new Building(init); } } - public class Building : INotifyDamage, IResolveOrder, ITick, IRenderModifier, IOccupySpace + public class Building : INotifyDamage, IResolveOrder, ITick, IRenderModifier, IOccupySpace, IRadarSignature { readonly Actor self; public readonly BuildingInfo Info; @@ -160,5 +161,15 @@ namespace OpenRA.Traits { return Footprint.UnpathableTiles( self.Info.Name, Info, TopLeft ); } + + public IEnumerable RadarSignatureCells(Actor self) + { + return Footprint.Tiles(self); + } + + public Color RadarSignatureColor(Actor self) + { + return self.Owner.Color; + } } } diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index b1bb6d134d..081452cf1a 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -55,6 +55,12 @@ namespace OpenRA.Traits public interface IExplodeModifier { bool ShouldExplode(Actor self); } public interface INudge { void OnNudge(Actor self, Actor nudger); } + public interface IRadarSignature + { + IEnumerable RadarSignatureCells(Actor self); + Color RadarSignatureColor(Actor self); + } + public interface IOccupySpace { int2 TopLeft { get; } diff --git a/OpenRA.Game/Traits/Unit.cs b/OpenRA.Game/Traits/Unit.cs index 878e8fa10d..f237ef7250 100755 --- a/OpenRA.Game/Traits/Unit.cs +++ b/OpenRA.Game/Traits/Unit.cs @@ -8,6 +8,9 @@ */ #endregion +using System.Collections.Generic; +using System.Drawing; + namespace OpenRA.Traits { public class UnitInfo : OwnedActorInfo, ITraitInfo @@ -19,7 +22,7 @@ namespace OpenRA.Traits public object Create( ActorInitializer init ) { return new Unit(); } } - public class Unit : INotifyDamage + public class Unit : INotifyDamage, IRadarSignature { [Sync] public int Facing; @@ -32,5 +35,15 @@ namespace OpenRA.Traits if (self.Owner == self.World.LocalPlayer) Sound.PlayVoice("Lost", self); } + + public IEnumerable RadarSignatureCells(Actor self) + { + yield return self.Location; + } + + public Color RadarSignatureColor(Actor self) + { + return self.Owner.Color; + } } }