Make AppearsOnRadar trait conditional
This commit is contained in:
@@ -18,38 +18,44 @@ using OpenRA.Traits;
|
|||||||
|
|
||||||
namespace OpenRA.Mods.Common.Traits.Radar
|
namespace OpenRA.Mods.Common.Traits.Radar
|
||||||
{
|
{
|
||||||
public class AppearsOnRadarInfo : ITraitInfo
|
public class AppearsOnRadarInfo : ConditionalTraitInfo
|
||||||
{
|
{
|
||||||
public readonly bool UseLocation = false;
|
public readonly bool UseLocation = false;
|
||||||
|
|
||||||
public object Create(ActorInitializer init) { return new AppearsOnRadar(this); }
|
[Desc("Player stances who can view this actor on radar.")]
|
||||||
|
public readonly Stance ValidStances = Stance.Ally | Stance.Neutral | Stance.Enemy;
|
||||||
|
|
||||||
|
public override object Create(ActorInitializer init) { return new AppearsOnRadar(this); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AppearsOnRadar : IRadarSignature, INotifyCreated
|
public class AppearsOnRadar : ConditionalTrait<AppearsOnRadarInfo>, IRadarSignature
|
||||||
{
|
{
|
||||||
readonly AppearsOnRadarInfo info;
|
static readonly IEnumerable<Pair<CPos, Color>> NoCells = Enumerable.Empty<Pair<CPos, Color>>();
|
||||||
IRadarColorModifier modifier;
|
IRadarColorModifier modifier;
|
||||||
|
|
||||||
Color currentColor = Color.Transparent;
|
Color currentColor = Color.Transparent;
|
||||||
Func<Pair<CPos, SubCell>, Pair<CPos, Color>> cellToSignature;
|
Func<Pair<CPos, SubCell>, Pair<CPos, Color>> cellToSignature;
|
||||||
|
|
||||||
public AppearsOnRadar(AppearsOnRadarInfo info)
|
public AppearsOnRadar(AppearsOnRadarInfo info)
|
||||||
{
|
: base(info) { }
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Created(Actor self)
|
protected override void Created(Actor self)
|
||||||
{
|
{
|
||||||
|
base.Created(self);
|
||||||
modifier = self.TraitsImplementing<IRadarColorModifier>().FirstOrDefault();
|
modifier = self.TraitsImplementing<IRadarColorModifier>().FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self)
|
public IEnumerable<Pair<CPos, Color>> RadarSignatureCells(Actor self)
|
||||||
{
|
{
|
||||||
|
var viewer = self.World.RenderPlayer ?? self.World.LocalPlayer;
|
||||||
|
if (IsTraitDisabled || (viewer != null && !Info.ValidStances.HasStance(self.Owner.Stances[viewer])))
|
||||||
|
return NoCells;
|
||||||
|
|
||||||
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color.RGB;
|
var color = Game.Settings.Game.UsePlayerStanceColors ? self.Owner.PlayerStanceColor(self) : self.Owner.Color.RGB;
|
||||||
if (modifier != null)
|
if (modifier != null)
|
||||||
color = modifier.RadarColorOverride(self, color);
|
color = modifier.RadarColorOverride(self, color);
|
||||||
|
|
||||||
if (info.UseLocation)
|
if (Info.UseLocation)
|
||||||
return new[] { Pair.New(self.Location, color) };
|
return new[] { Pair.New(self.Location, color) };
|
||||||
|
|
||||||
// PERF: Cache cellToSignature delegate to avoid allocations as color does not change often.
|
// PERF: Cache cellToSignature delegate to avoid allocations as color does not change often.
|
||||||
|
|||||||
Reference in New Issue
Block a user