New interface for things that show on radar; groundwork for future patches.

This commit is contained in:
Paul Chote
2010-07-22 10:40:23 +12:00
parent 31d5d18d65
commit a234dd4382
4 changed files with 42 additions and 10 deletions

View File

@@ -126,9 +126,15 @@ namespace OpenRA.Graphics
{
int* c = (int*)bitmapData.Scan0;
foreach (var a in world.Queries.WithTrait<Unit>().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<IRadarSignature>())
{
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<BuildingInfluence>().GetBuildingAt(new int2(mapX, mapY));
if (b != null)
*(c + (y * bitmapData.Stride >> 2) + x) = b.Owner.Color.ToArgb();
}
}

View File

@@ -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<int2> RadarSignatureCells(Actor self)
{
return Footprint.Tiles(self);
}
public Color RadarSignatureColor(Actor self)
{
return self.Owner.Color;
}
}
}

View File

@@ -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<int2> RadarSignatureCells(Actor self);
Color RadarSignatureColor(Actor self);
}
public interface IOccupySpace
{
int2 TopLeft { get; }

View File

@@ -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<int2> RadarSignatureCells(Actor self)
{
yield return self.Location;
}
public Color RadarSignatureColor(Actor self)
{
return self.Owner.Color;
}
}
}