Remove Infiltratable trait and refactor surrounding code to use target types

This commit is contained in:
ScottNZ
2014-08-01 01:19:05 +12:00
parent 9422285aa2
commit 058185754e
12 changed files with 54 additions and 94 deletions

View File

@@ -29,7 +29,7 @@ namespace OpenRA.Mods.RA
{ {
get 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); yield return new DeployOrderTargeter("Detonate", 5);
} }
} }

View File

@@ -76,7 +76,7 @@ namespace OpenRA.Mods.RA
{ {
get 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 };
} }
} }

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -15,7 +15,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
[Desc("This structure can be infiltrated causing funds to be stolen.")] [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 Percentage = 50;
public readonly int Minimum = 500; public readonly int Minimum = 500;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
class InfiltrateForCash : IAcceptInfiltrator class InfiltrateForCash : IAcceptInfiltrator
{ {
InfiltrateForCashInfo info; readonly InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; } public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }

View File

@@ -12,7 +12,7 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration>, Requires<InfiltratableInfo> { } class InfiltrateForExplorationInfo : TraitInfo<InfiltrateForExploration> { }
class InfiltrateForExploration : IAcceptInfiltrator class InfiltrateForExploration : IAcceptInfiltrator
{ {

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -13,24 +13,25 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class InfiltrateForSupportPowerInfo : ITraitInfo, Requires<InfiltratableInfo> class InfiltrateForSupportPowerInfo : ITraitInfo
{ {
[ActorReference] public readonly string Proxy = null; [ActorReference] public readonly string Proxy = null;
public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); } public object Create(ActorInitializer init) { return new InfiltrateForSupportPower(this); }
} }
class InfiltrateForSupportPower : IAcceptInfiltrator class InfiltrateForSupportPower : IAcceptInfiltrator
{ {
InfiltrateForSupportPowerInfo Info; readonly InfiltrateForSupportPowerInfo info;
public InfiltrateForSupportPower(InfiltrateForSupportPowerInfo info) public InfiltrateForSupportPower(InfiltrateForSupportPowerInfo info)
{ {
Info = info; this.info = info;
} }
public void OnInfiltrate(Actor self, Actor infiltrator) public void OnInfiltrate(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) new OwnerInit(infiltrator.Owner)
})); }));

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -17,30 +17,26 @@ using OpenRA.Traits;
namespace OpenRA.Mods.RA namespace OpenRA.Mods.RA
{ {
class InfiltratableInfo : TraitInfo<Infiltratable>
{
public string Type = null;
}
class Infiltratable { }
class InfiltratesInfo : ITraitInfo class InfiltratesInfo : ITraitInfo
{ {
public string[] Types = { "Cash", "SupportPower", "Exploration" }; public readonly string[] Types = { };
public object Create(ActorInitializer init) { return new Infiltrates(this); } public object Create(ActorInitializer init) { return new Infiltrates(this); }
} }
class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice class Infiltrates : IIssueOrder, IResolveOrder, IOrderVoice
{ {
public readonly InfiltratesInfo Info; readonly InfiltratesInfo info;
public Infiltrates(InfiltratesInfo info) public Infiltrates(InfiltratesInfo info)
{ {
Info = info; this.info = info;
} }
public IEnumerable<IOrderTargeter> Orders { get { yield return new InfiltratorOrderTargeter(Info.Types); } } public IEnumerable<IOrderTargeter> Orders
{
get { yield return new TargetTypeOrderTargeter(info.Types, "Infiltrate", 7, "enter", true, false); }
}
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{ {
@@ -59,6 +55,8 @@ namespace OpenRA.Mods.RA
if (order.ExtraData == 0 && order.TargetActor == null) if (order.ExtraData == 0 && order.TargetActor == null)
return false; return false;
ActorInfo ai;
if (order.ExtraData != 0) if (order.ExtraData != 0)
{ {
// Targeted an actor under the fog // Targeted an actor under the fog
@@ -70,12 +68,13 @@ namespace OpenRA.Mods.RA
if (frozen == null) if (frozen == null)
return false; return false;
var ii = frozen.Info.Traits.GetOrDefault<InfiltratableInfo>(); ai = frozen.Info;
return ii != null && Info.Types.Contains(ii.Type);
} }
else
ai = order.TargetActor.Info;
var i = order.TargetActor.Info.Traits.GetOrDefault<InfiltratableInfo>(); var i = ai.Traits.GetOrDefault<ITargetableInfo>();
return i != null && Info.Types.Contains(i.Type); return i != null && i.GetTargetTypes().Intersect(info.Types).Any();
} }
public string VoicePhraseForOrder(Actor self, Order order) public string VoicePhraseForOrder(Actor self, Order order)
@@ -99,41 +98,5 @@ namespace OpenRA.Mods.RA
self.SetTargetLine(target, Color.Red); self.SetTargetLine(target, Color.Red);
self.QueueActivity(new Enter(target.Actor, new Infiltrate(target.Actor))); 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 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); yield return new DeployOrderTargeter("Detonate", 5);
} }
} }

View File

@@ -66,22 +66,22 @@ namespace OpenRA.Mods.RA.Orders
public class TargetTypeOrderTargeter : UnitOrderTargeter 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) : 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) 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) 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());
} }
} }
} }

View File

@@ -226,7 +226,7 @@ SPY:
TakeCover: TakeCover:
Disguise: Disguise:
Infiltrates: Infiltrates:
Types: Cash, SupportPower, Exploration Types: SpyInfiltrate
-AutoTarget: -AutoTarget:
-RenderInfantry: -RenderInfantry:
RenderDisguise: RenderDisguise:

View File

@@ -81,8 +81,6 @@ GAP:
SPEN: SPEN:
Inherits: ^Building Inherits: ^Building
Infiltratable:
Type: SupportPower
InfiltrateForSupportPower: InfiltrateForSupportPower:
Proxy: powerproxy.sonarpulse Proxy: powerproxy.sonarpulse
Valued: Valued:
@@ -96,7 +94,7 @@ SPEN:
Prerequisites: anypower, ~structures.soviet, ~techlevel.low Prerequisites: anypower, ~structures.soviet, ~techlevel.low
Hotkey: y Hotkey: y
TargetableBuilding: TargetableBuilding:
TargetTypes: Ground, Water TargetTypes: Ground, Water, C4, DetonateAttack, SpyInfiltrate
Building: Building:
Power: -30 Power: -30
Footprint: xxx xxx xxx Footprint: xxx xxx xxx
@@ -137,8 +135,6 @@ SPEN:
SYRD: SYRD:
Inherits: ^Building Inherits: ^Building
Infiltratable:
Type: SupportPower
InfiltrateForSupportPower: InfiltrateForSupportPower:
Proxy: powerproxy.sonarpulse Proxy: powerproxy.sonarpulse
Buildable: Buildable:
@@ -152,7 +148,7 @@ SYRD:
Name: Shipyard Name: Shipyard
Description: Produces and repairs ships\nand transports. Description: Produces and repairs ships\nand transports.
TargetableBuilding: TargetableBuilding:
TargetTypes: Ground, Water TargetTypes: Ground, Water, C4, DetonateAttack, SpyInfiltrate
Building: Building:
Power: -30 Power: -30
Footprint: xxx xxx xxx Footprint: xxx xxx xxx
@@ -384,6 +380,8 @@ DOME:
Power: -40 Power: -40
Footprint: xx xx Footprint: xx xx
Dimensions: 2,2 Dimensions: 2,2
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
RequiresPower: RequiresPower:
CanPowerDown: CanPowerDown:
DisabledOverlay: DisabledOverlay:
@@ -396,8 +394,6 @@ DOME:
Bib: Bib:
ProvidesRadar: ProvidesRadar:
IronCurtainable: IronCurtainable:
Infiltratable:
Type: Exploration
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10 Range: 10
@@ -768,6 +764,8 @@ PROC:
Power: -30 Power: -30
Footprint: _x_ xxx x== Footprint: _x_ xxx x==
Dimensions: 3,3 Dimensions: 3,3
TargetableBuilding:
TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate
Health: Health:
HP: 900 HP: 900
Armor: Armor:
@@ -788,8 +786,6 @@ PROC:
InitialActivity: FindResources InitialActivity: FindResources
SpawnOffset: 1,2 SpawnOffset: 1,2
Facing: 64 Facing: 64
Infiltratable:
Type: Cash
InfiltrateForCash: InfiltrateForCash:
Percentage: 50 Percentage: 50
Minimum: 500 Minimum: 500

View File

@@ -298,7 +298,7 @@ CHAMSPY:
TakeCover: TakeCover:
Disguise: Disguise:
Infiltrates: Infiltrates:
Types: Cash, SupportPower, Exploration Types: SpyInfiltrate
-AutoTarget: -AutoTarget:
-RenderInfantry: -RenderInfantry:
RenderDisguise: RenderDisguise:

View File

@@ -623,8 +623,6 @@ GARADR:
RequiresPower: RequiresPower:
CanPowerDown: CanPowerDown:
ProvidesRadar: ProvidesRadar:
Infiltratable:
Type: Exploration
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10 Range: 10
@@ -634,6 +632,8 @@ GARADR:
WithIdleOverlay@DISH: WithIdleOverlay@DISH:
Sequence: idle-dish Sequence: idle-dish
PauseOnLowPower: yes PauseOnLowPower: yes
TargetableBuilding:
TargetTypes: Ground, C4, SpyInfiltrate
NARADR: NARADR:
Inherits: ^Building Inherits: ^Building
@@ -661,8 +661,6 @@ NARADR:
RequiresPower: RequiresPower:
CanPowerDown: CanPowerDown:
ProvidesRadar: ProvidesRadar:
Infiltratable:
Type: Exploration
InfiltrateForExploration: InfiltrateForExploration:
DetectCloaked: DetectCloaked:
Range: 10 Range: 10
@@ -672,6 +670,8 @@ NARADR:
WithIdleOverlay@DISH: WithIdleOverlay@DISH:
Sequence: idle-dish Sequence: idle-dish
PauseOnLowPower: yes PauseOnLowPower: yes
TargetableBuilding:
TargetTypes: Ground, C4, SpyInfiltrate
GATECH: GATECH:
Inherits: ^Building Inherits: ^Building