Remove Infiltratable trait and refactor surrounding code to use target types
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user