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
{
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;
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA
class InfiltrateForCash : IAcceptInfiltrator
{
InfiltrateForCashInfo info;
readonly InfiltrateForCashInfo info;
public InfiltrateForCash(InfiltrateForCashInfo info) { this.info = info; }

View File

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

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
{
InfiltrateForSupportPowerInfo Info;
readonly InfiltrateForSupportPowerInfo info;
public InfiltrateForSupportPower(InfiltrateForSupportPowerInfo info)
{
Info = info;
this.info = info;
}
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)
}));

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,30 +17,26 @@ 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 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)
{
@@ -59,6 +55,8 @@ namespace OpenRA.Mods.RA
if (order.ExtraData == 0 && order.TargetActor == null)
return false;
ActorInfo ai;
if (order.ExtraData != 0)
{
// Targeted an actor under the fog
@@ -70,18 +68,19 @@ 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)
@@ -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());
}
}
}

View File

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

View File

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

View File

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

View File

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