Merge pull request #6136 from ScottNZ/infiltration

Infiltration refactor
This commit is contained in:
Paul Chote
2014-08-03 18:29:23 +12:00
14 changed files with 64 additions and 104 deletions

View File

@@ -23,8 +23,8 @@ namespace OpenRA.Mods.RA.Activities
if (IsCanceled || target.Type != TargetType.Actor || target.Actor.Owner == self.Owner)
return NextActivity;
foreach (var t in target.Actor.TraitsImplementing<IAcceptInfiltrator>())
t.OnInfiltrate(target.Actor, self);
foreach (var t in target.Actor.TraitsImplementing<INotifyInfiltrated>())
t.Infiltrated(target.Actor, self);
self.Destroy();

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{
get
{
yield return new TargetTypeOrderTargeter("DetonateAttack", "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
yield return new TargetTypeOrderTargeter(new[] { "DetonateAttack" }, "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
yield return new DeployOrderTargeter("Detonate", 5);
}
}

View File

@@ -20,7 +20,7 @@ namespace OpenRA.Mods.RA
[Desc("Overrides the default ToolTip when this actor is disguised (aids in deceiving enemy players).")]
class DisguiseToolTipInfo : TooltipInfo, Requires<DisguiseInfo>
{
public override object Create (ActorInitializer init) { return new DisguiseToolTip(init.self, this); }
public override object Create(ActorInitializer init) { return new DisguiseToolTip(init.self, this); }
}
class DisguiseToolTip : IToolTip
@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA
{
get
{
yield return new TargetTypeOrderTargeter("Disguise", "Disguise", 7, "ability", true, true) { ForceAttack = false };
yield return new TargetTypeOrderTargeter(new[] { "Disguise" }, "Disguise", 7, "ability", true, true) { ForceAttack = false };
}
}
@@ -135,6 +135,6 @@ namespace OpenRA.Mods.RA
public void Attacking(Actor self, Target target, Armament a, Barrel barrel) { DisguiseAs(self, null); }
}
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> {}
class IgnoresDisguise {}
class IgnoresDisguiseInfo : TraitInfo<IgnoresDisguise> { }
class IgnoresDisguise { }
}

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
[Desc("This structure can be infiltrated causing funds to be stolen.")]
class InfiltrateForCashInfo : ITraitInfo, Requires<InfiltratableInfo>
class InfiltrateForCashInfo : ITraitInfo
{
public readonly int Percentage = 50;
public readonly int Minimum = 500;
@@ -24,13 +24,13 @@ namespace OpenRA.Mods.RA
public object Create(ActorInitializer init) { return new InfiltrateForCash(this); }
}
class InfiltrateForCash : IAcceptInfiltrator
class InfiltrateForCash : INotifyInfiltrated
{
InfiltrateForCashInfo info;
readonly InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }
public void OnInfiltrate(Actor self, Actor infiltrator)
public void Infiltrated(Actor self, Actor infiltrator)
{
var targetResources = self.Owner.PlayerActor.Trait<PlayerResources>();
var spyResources = infiltrator.Owner.PlayerActor.Trait<PlayerResources>();

View File

@@ -12,11 +12,11 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration>, Requires<InfiltratableInfo> { }
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
class InfiltrateForExploration : IAcceptInfiltrator
class InfiltrateForExploration : INotifyInfiltrated
{
public void OnInfiltrate(Actor self, Actor infiltrator)
public void Infiltrated(Actor self, Actor infiltrator)
{
// Steal and reset the owners exploration
infiltrator.Owner.Shroud.Explore(self.Owner.Shroud);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -13,24 +13,25 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class InfiltrateForSupportPowerInfo : ITraitInfo, Requires<InfiltratableInfo>
class InfiltrateForSupportPowerInfo : ITraitInfo
{
[ActorReference] public readonly string Proxy = null;
public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); }
}
class InfiltrateForSupportPower : IAcceptInfiltrator
class InfiltrateForSupportPower : INotifyInfiltrated
{
InfiltrateForSupportPowerInfo Info;
readonly InfiltrateForSupportPowerInfo info;
public InfiltrateForSupportPower(InfiltrateForSupportPowerInfo info)
{
Info = info;
this.info = info;
}
public void OnInfiltrate(Actor self, Actor infiltrator)
public void Infiltrated(Actor self, Actor infiltrator)
{
infiltrator.World.AddFrameEndTask(w => w.CreateActor(Info.Proxy, new TypeDictionary
infiltrator.World.AddFrameEndTask(w => w.CreateActor(info.Proxy, new TypeDictionary
{
new OwnerInit(infiltrator.Owner)
}));

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2012 The OpenRA Developers (see AUTHORS)
* Copyright 2007-2014 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
@@ -17,31 +17,27 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class InfiltratableInfo : TraitInfo<Infiltratable>
{
public string Type = null;
}
class Infiltratable { }
class InfiltratesInfo : ITraitInfo
{
public string[] Types = { "Cash", "SupportPower", "Exploration" };
public readonly string[] Types = { };
public object Create(ActorInitializer init) { return new Infiltrates(this); }
}
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
{
public readonly InfiltratesInfo Info;
readonly InfiltratesInfo info;
public Infiltrates(InfiltratesInfo info)
{
Info = info;
this.info = info;
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new TargetTypeOrderTargeter(info.Types, "Infiltrate", 7, "enter", true, false); }
}
public IEnumerable<IOrderTargeter> Orders { get { yield return new InfiltratorOrderTargeter(Info.Types); } }
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if (order.OrderID != "Infiltrate")
@@ -49,16 +45,18 @@ namespace OpenRA.Mods.RA
if (target.Type == TargetType.FrozenActor)
return new Order(order.OrderID, self, queued) { ExtraData = target.FrozenActor.ID };
return new Order(order.OrderID, self, queued) { TargetActor = target.Actor };
}
bool IsValidOrder(Actor self, Order order)
{
// Not targeting an actor
if (order.ExtraData == 0 && order.TargetActor == null)
return false;
ActorInfo ai;
if (order.ExtraData != 0)
{
// Targeted an actor under the fog
@@ -70,20 +68,21 @@ namespace OpenRA.Mods.RA
if (frozen == null)
return false;
var ii = frozen.Info.Traits.GetOrDefault<InfiltratableInfo>();
return ii != null && Info.Types.Contains(ii.Type);
ai = frozen.Info;
}
else
ai = order.TargetActor.Info;
var i = order.TargetActor.Info.Traits.GetOrDefault<InfiltratableInfo>();
return i != null && Info.Types.Contains(i.Type);
var i = ai.Traits.GetOrDefault<ITargetableInfo>();
return i != null && i.GetTargetTypes().Intersect(info.Types).Any();
}
public string VoicePhraseForOrder(Actor self, Order order)
{
return order.OrderString == "Infiltrate" && IsValidOrder(self, order)
? "Attack" : null;
? "Attack" : null;
}
public void ResolveOrder(Actor self, Order order)
{
if (order.OrderString != "Infiltrate" || !IsValidOrder(self, order))
@@ -99,41 +98,5 @@ namespace OpenRA.Mods.RA
self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Enter(target.Actor, new Infiltrate(target.Actor)));
}
class InfiltratorOrderTargeter : UnitOrderTargeter
{
string[] infiltrationTypes;
public InfiltratorOrderTargeter(string[] infiltrationTypes)
: base("Infiltrate", 7, "enter", true, false)
{
ForceAttack = false;
this.infiltrationTypes = infiltrationTypes;
}
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
var info = target.Info.Traits.GetOrDefault<InfiltratableInfo>();
if (info == null)
return false;
if (!infiltrationTypes.Contains(info.Type))
cursor = "enter-blocked";
return true;
}
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
var info = target.Info.Traits.GetOrDefault<InfiltratableInfo>();
if (info == null)
return false;
if (!infiltrationTypes.Contains(info.Type))
cursor = "enter-blocked";
return true;
}
}
}
}

View File

@@ -78,7 +78,7 @@ namespace OpenRA.Mods.RA
{
get
{
yield return new TargetTypeOrderTargeter("DetonateAttack", "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
yield return new TargetTypeOrderTargeter(new[] { "DetonateAttack" }, "DetonateAttack", 5, "attack", true, false) { ForceAttack = false };
yield return new DeployOrderTargeter("Detonate", 5);
}
}

View File

@@ -66,22 +66,22 @@ namespace OpenRA.Mods.RA.Orders
public class TargetTypeOrderTargeter : UnitOrderTargeter
{
string targetType;
readonly string[] targetTypes;
public TargetTypeOrderTargeter(string targetType, string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits)
public TargetTypeOrderTargeter(string[] targetTypes, string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits)
: base(order, priority, cursor, targetEnemyUnits, targetAllyUnits)
{
this.targetType = targetType;
this.targetTypes = targetTypes;
}
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
{
return target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Contains(targetType));
return target.TraitsImplementing<ITargetable>().Any(t => t.TargetTypes.Intersect(targetTypes).Any());
}
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
{
return target.Info.Traits.WithInterface<ITargetableInfo>().Any(t => t.GetTargetTypes().Contains(targetType));
return target.Info.Traits.WithInterface<ITargetableInfo>().Any(t => t.GetTargetTypes().Intersect(targetTypes).Any());
}
}
}