(External)Capturable are now conditional
This commit is contained in:
@@ -717,13 +717,33 @@ namespace OpenRA.Mods.Common.AI
|
||||
|
||||
var capturableTargetOptions = targetOptions
|
||||
.Select(a => new CaptureTarget<CapturableInfo>(a, "CaptureActor"))
|
||||
.Where(target => target.Info != null && capturers.Any(capturer => target.Info.CanBeTargetedBy(capturer, target.Actor.Owner)))
|
||||
.Where(target =>
|
||||
{
|
||||
if (target.Info == null)
|
||||
return false;
|
||||
|
||||
var capturable = target.Actor.TraitOrDefault<Capturable>();
|
||||
if (capturable == null)
|
||||
return false;
|
||||
|
||||
return capturers.Any(capturer => capturable.CanBeTargetedBy(capturer, target.Actor.Owner));
|
||||
})
|
||||
.OrderByDescending(target => target.Actor.GetSellValue())
|
||||
.Take(maximumCaptureTargetOptions);
|
||||
|
||||
var externalCapturableTargetOptions = targetOptions
|
||||
.Select(a => new CaptureTarget<ExternalCapturableInfo>(a, "ExternalCaptureActor"))
|
||||
.Where(target => target.Info != null && capturers.Any(capturer => target.Info.CanBeTargetedBy(capturer, target.Actor.Owner)))
|
||||
.Where(target =>
|
||||
{
|
||||
if (target.Info == null)
|
||||
return false;
|
||||
|
||||
var externalCapturable = target.Actor.TraitOrDefault<ExternalCapturable>();
|
||||
if (externalCapturable == null)
|
||||
return false;
|
||||
|
||||
return capturers.Any(capturer => externalCapturable.CanBeTargetedBy(capturer, target.Actor.Owner));
|
||||
})
|
||||
.OrderByDescending(target => target.Actor.GetSellValue())
|
||||
.Take(maximumCaptureTargetOptions);
|
||||
|
||||
|
||||
@@ -36,12 +36,12 @@ namespace OpenRA.Mods.Common.Activities
|
||||
|
||||
protected override bool CanReserve(Actor self)
|
||||
{
|
||||
return !capturable.BeingCaptured && capturable.Info.CanBeTargetedBy(self, actor.Owner);
|
||||
return !capturable.BeingCaptured && capturable.CanBeTargetedBy(self, actor.Owner);
|
||||
}
|
||||
|
||||
protected override void OnInside(Actor self)
|
||||
{
|
||||
if (actor.IsDead || capturable.BeingCaptured)
|
||||
if (actor.IsDead || capturable.BeingCaptured || capturable.IsTraitDisabled)
|
||||
return;
|
||||
|
||||
if (building != null && !building.Lock())
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor can be captured by a unit with Captures: trait.")]
|
||||
public class CapturableInfo : ITraitInfo
|
||||
public class CapturableInfo : ConditionalTraitInfo
|
||||
{
|
||||
[Desc("CaptureTypes (from the Captures trait) that are able to capture this.")]
|
||||
public readonly HashSet<string> Types = new HashSet<string>() { "building" };
|
||||
@@ -27,7 +27,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly int CaptureThreshold = 50;
|
||||
public readonly bool CancelActivity = false;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Capturable(this); }
|
||||
public override object Create(ActorInitializer init) { return new Capturable(this); }
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
@@ -46,11 +46,11 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
}
|
||||
|
||||
public class Capturable : INotifyCapture
|
||||
public class Capturable : ConditionalTrait<CapturableInfo>, INotifyCapture
|
||||
{
|
||||
public readonly CapturableInfo Info;
|
||||
public bool BeingCaptured { get; private set; }
|
||||
public Capturable(CapturableInfo info) { Info = info; }
|
||||
public Capturable(CapturableInfo info)
|
||||
: base(info) { }
|
||||
|
||||
public void OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner)
|
||||
{
|
||||
@@ -64,5 +64,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
t.ResolveOrder(self, stop);
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return false;
|
||||
|
||||
return Info.CanBeTargetedBy(captor, owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
var c = target.TraitOrDefault<Capturable>();
|
||||
if (c == null || !c.CanBeTargetedBy(self, target.Owner))
|
||||
{
|
||||
cursor = capturesInfo.EnterBlockedCursor;
|
||||
@@ -109,15 +109,18 @@ namespace OpenRA.Mods.Common.Traits
|
||||
}
|
||||
|
||||
var health = target.Trait<Health>();
|
||||
var lowEnoughHealth = health.HP <= c.CaptureThreshold * health.MaxHP / 100;
|
||||
var lowEnoughHealth = health.HP <= c.Info.CaptureThreshold * health.MaxHP / 100;
|
||||
|
||||
cursor = !capturesInfo.Sabotage || lowEnoughHealth || target.Owner.NonCombatant
|
||||
? capturesInfo.EnterCursor : capturesInfo.SabotageCursor;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
// TODO: This doesn't account for disabled traits.
|
||||
// Actors with FrozenUnderFog should not disable the Capturable trait.
|
||||
var c = target.Info.TraitInfoOrDefault<CapturableInfo>();
|
||||
if (c == null || !c.CanBeTargetedBy(self, target.Owner))
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ using OpenRA.Traits;
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
[Desc("This actor can be captured by a unit with ExternalCaptures: trait.")]
|
||||
public class ExternalCapturableInfo : ITraitInfo
|
||||
public class ExternalCapturableInfo : ConditionalTraitInfo
|
||||
{
|
||||
[Desc("CaptureTypes (from the ExternalCaptures trait) that are able to capture this.")]
|
||||
public readonly HashSet<string> Types = new HashSet<string>() { "building" };
|
||||
@@ -45,21 +45,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
return true;
|
||||
}
|
||||
|
||||
public object Create(ActorInitializer init) { return new ExternalCapturable(init.Self, this); }
|
||||
public override object Create(ActorInitializer init) { return new ExternalCapturable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class ExternalCapturable : ITick, ISync, IPreventsAutoTarget
|
||||
public class ExternalCapturable : ConditionalTrait<ExternalCapturableInfo>, ITick, ISync, IPreventsAutoTarget
|
||||
{
|
||||
[Sync] public int CaptureProgressTime = 0;
|
||||
[Sync] public Actor Captor;
|
||||
private Actor self;
|
||||
public ExternalCapturableInfo Info;
|
||||
public bool CaptureInProgress { get { return Captor != null; } }
|
||||
|
||||
public ExternalCapturable(Actor self, ExternalCapturableInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
Info = info;
|
||||
}
|
||||
|
||||
public void BeginCapture(Actor captor)
|
||||
@@ -95,5 +94,13 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
return Info.PreventsAutoTarget && Captor != null && attacker.AppearsFriendlyTo(Captor);
|
||||
}
|
||||
|
||||
public bool CanBeTargetedBy(Actor captor, Player owner)
|
||||
{
|
||||
if (IsTraitDisabled)
|
||||
return false;
|
||||
|
||||
return Info.CanBeTargetedBy(captor, owner);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
if (order.Target.Type == TargetType.Actor)
|
||||
{
|
||||
var c = order.TargetActor.TraitOrDefault<ExternalCapturable>();
|
||||
return c != null && !c.CaptureInProgress && c.Info.CanBeTargetedBy(self, order.TargetActor.Owner);
|
||||
return c != null && !c.CaptureInProgress && c.CanBeTargetedBy(self, order.TargetActor.Owner);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
var c = target.TraitOrDefault<ExternalCapturable>();
|
||||
|
||||
var canTargetActor = c != null && !c.CaptureInProgress && c.Info.CanBeTargetedBy(self, target.Owner);
|
||||
var canTargetActor = c != null && !c.CaptureInProgress && c.CanBeTargetedBy(self, target.Owner);
|
||||
var capturesInfo = self.Trait<ExternalCaptures>().Info;
|
||||
cursor = canTargetActor ? capturesInfo.CaptureCursor : capturesInfo.CaptureBlockedCursor;
|
||||
return canTargetActor;
|
||||
@@ -126,6 +126,8 @@ namespace OpenRA.Mods.Common.Traits
|
||||
|
||||
public override bool CanTargetFrozenActor(Actor self, FrozenActor target, TargetModifiers modifiers, ref string cursor)
|
||||
{
|
||||
// TODO: This doesn't account for disabled traits.
|
||||
// Actors with FrozenUnderFog should not disable the ExternalCapturable trait.
|
||||
var c = target.Info.TraitInfoOrDefault<ExternalCapturableInfo>();
|
||||
|
||||
var canTargetActor = c != null && c.CanBeTargetedBy(self, target.Owner);
|
||||
|
||||
Reference in New Issue
Block a user