Tidy TargetableUnit and subclasses.

This commit is contained in:
Paul Chote
2013-07-10 19:22:11 +12:00
parent bed2745c61
commit 935b829532
5 changed files with 31 additions and 24 deletions

View File

@@ -18,16 +18,15 @@ namespace OpenRA.Mods.RA
{
public readonly string[] TargetTypes = { };
public virtual object Create( ActorInitializer init ) { return new TargetableUnit<TargetableUnitInfo>( init.self, this ); }
public virtual object Create(ActorInitializer init) { return new TargetableUnit(init.self, this); }
}
public class TargetableUnit<Info> : ITargetable
where Info : TargetableUnitInfo
public class TargetableUnit : ITargetable
{
protected readonly Info info;
protected Cloak Cloak;
readonly TargetableUnitInfo info;
protected Cloak cloak;
public TargetableUnit( Actor self, Info info )
public TargetableUnit(Actor self, TargetableUnitInfo info)
{
this.info = info;
ReceivedCloak(self);
@@ -36,15 +35,15 @@ namespace OpenRA.Mods.RA
// Arbitrary units can receive cloak via a crate during gameplay
public void ReceivedCloak(Actor self)
{
Cloak = self.TraitOrDefault<Cloak>();
cloak = self.TraitOrDefault<Cloak>();
}
public virtual bool TargetableBy(Actor self, Actor byActor)
{
if (Cloak == null)
if (cloak == null || !cloak.Cloaked)
return true;
if (!Cloak.Cloaked || self.Owner == byActor.Owner || self.Owner.Stances[byActor.Owner] == Stance.Ally)
if (self.Owner.IsAlliedWith(byActor.Owner))
return true;
return self.World.ActorsWithTrait<DetectCloaked>().Any(a => (self.Location - a.Actor.Location).Length < a.Actor.Info.Traits.Get<DetectCloakedInfo>().Range);