diff --git a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs b/OpenRA.Mods.RA/Activities/CaptureActor.cs similarity index 92% rename from OpenRA.Mods.RA/Activities/CaptureBuilding.cs rename to OpenRA.Mods.RA/Activities/CaptureActor.cs index 1ce5ab66eb..7323534821 100644 --- a/OpenRA.Mods.RA/Activities/CaptureBuilding.cs +++ b/OpenRA.Mods.RA/Activities/CaptureActor.cs @@ -14,11 +14,11 @@ using OpenRA.Traits.Activities; namespace OpenRA.Mods.RA.Activities { - class CaptureBuilding : CancelableActivity + class CaptureActor : CancelableActivity { Actor target; - public CaptureBuilding(Actor target) { this.target = target; } + public CaptureActor(Actor target) { this.target = target; } public override IActivity Tick(Actor self) { diff --git a/OpenRA.Mods.RA/Capturable.cs b/OpenRA.Mods.RA/Capturable.cs index 633ec6a255..cdf4e110a7 100644 --- a/OpenRA.Mods.RA/Capturable.cs +++ b/OpenRA.Mods.RA/Capturable.cs @@ -16,7 +16,10 @@ namespace OpenRA.Mods.RA { public class CapturableInfo : TraitInfo { - public readonly string[] CaptureClasses = {"Building"}; + public readonly string Type = "building"; + public readonly bool AllowAllies = false; + public readonly bool AllowNeutral = false; + public readonly bool AllowEnemies = true; } public class Capturable {} diff --git a/OpenRA.Mods.RA/Captures.cs b/OpenRA.Mods.RA/Captures.cs new file mode 100644 index 0000000000..1efdf59dc1 --- /dev/null +++ b/OpenRA.Mods.RA/Captures.cs @@ -0,0 +1,99 @@ +#region Copyright & License Information +/* + * Copyright 2007-2011 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, + * see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using OpenRA.Mods.RA.Activities; +using OpenRA.Mods.RA.Buildings; +using OpenRA.Mods.RA.Orders; +using OpenRA.Traits; + +namespace OpenRA.Mods.RA +{ + class CapturesInfo : ITraitInfo + { + public string[] CaptureTypes = {"building"}; + public object Create(ActorInitializer init) { return new Captures(this); } + } + + class Captures : IIssueOrder, IResolveOrder, IOrderVoice + { + public readonly CapturesInfo Info; + public Captures(CapturesInfo info) + { + Info = info; + } + + public IEnumerable Orders + { + get + { + yield return new CaptureOrderTargeter(Info.CaptureTypes); + } + } + + public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) + { + if( order.OrderID == "CaptureActor" ) + return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; + + return null; + } + + public string VoicePhraseForOrder(Actor self, Order order) + { + return (order.OrderString == "CaptureActor") ? "Attack" : null; + } + + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "CaptureActor") + { + self.SetTargetLine(Target.FromOrder(order), Color.Red); + + self.CancelActivity(); + self.QueueActivity(new Enter(order.TargetActor)); + self.QueueActivity(new CaptureActor(order.TargetActor)); + } + } + } + + class CaptureOrderTargeter : UnitTraitOrderTargeter + { + readonly string[] captureTypes; + public CaptureOrderTargeter(string[] captureTypes) + : base( "CaptureActor", 6, "enter", true, true ) + { + this.captureTypes = captureTypes; + } + + public override bool CanTargetActor(Actor self, Actor target, bool forceAttack, bool forceMove, bool forceQueued, ref string cursor) + { + if( !base.CanTargetActor( self, target, forceAttack, forceMove, forceQueued, ref cursor ) ) return false; + + var ci = target.Info.Traits.Get(); + var playerRelationship = self.Owner.Stances[ target.Owner ]; + + if( playerRelationship == Stance.Ally && !ci.AllowAllies ) return false; + if( playerRelationship == Stance.Enemy && !ci.AllowEnemies ) return false; + if( playerRelationship == Stance.Neutral && !ci.AllowNeutral ) return false; + + IsQueued = forceQueued; + if (captureTypes.Contains(ci.Type)) + { + cursor = "enter"; + return true; + } + + return false; + } + } +} diff --git a/OpenRA.Mods.RA/EngineerCapture.cs b/OpenRA.Mods.RA/EngineerCapture.cs deleted file mode 100644 index 5bb6ea6939..0000000000 --- a/OpenRA.Mods.RA/EngineerCapture.cs +++ /dev/null @@ -1,69 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2011 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, - * see COPYING. - */ -#endregion - -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using OpenRA.Mods.RA.Activities; -using OpenRA.Mods.RA.Buildings; -using OpenRA.Mods.RA.Orders; -using OpenRA.Traits; - -namespace OpenRA.Mods.RA -{ - class EngineerCaptureInfo : ITraitInfo - { - public string[] CaptureClasses = {"Building"}; - public object Create(ActorInitializer init) { return new EngineerCapture(this); } - } - - class EngineerCapture : IIssueOrder, IResolveOrder, IOrderVoice - { - public readonly EngineerCaptureInfo Info; - public EngineerCapture(EngineerCaptureInfo info) - { - Info = info; - } - - public IEnumerable Orders - { - get - { - yield return new EnterOrderTargeter( "CaptureBuilding", 5, true, false, - _ => true, target => target.Info.Traits.Get().CaptureClasses.Intersect(Info.CaptureClasses).Any() ); - } - } - - public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) - { - if( order.OrderID == "CaptureBuilding" ) - return new Order(order.OrderID, self, queued) { TargetActor = target.Actor }; - - return null; - } - - public string VoicePhraseForOrder(Actor self, Order order) - { - return (order.OrderString == "CaptureBuilding") ? "Attack" : null; - } - - public void ResolveOrder(Actor self, Order order) - { - if (order.OrderString == "CaptureBuilding") - { - self.SetTargetLine(Target.FromOrder(order), Color.Red); - - self.CancelActivity(); - self.QueueActivity(new Enter(order.TargetActor)); - self.QueueActivity(new CaptureBuilding(order.TargetActor)); - } - } - } -} diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 287d4242f8..7e464f398d 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -55,7 +55,6 @@ - @@ -207,7 +206,6 @@ - @@ -342,6 +340,8 @@ + + diff --git a/mods/cnc/rules/infantry.yaml b/mods/cnc/rules/infantry.yaml index e572b91759..e61ce40343 100644 --- a/mods/cnc/rules/infantry.yaml +++ b/mods/cnc/rules/infantry.yaml @@ -144,7 +144,7 @@ E6: Passenger: PipType: Yellow EngineerRepair: - EngineerCapture: + Captures: -AutoTarget: AttackMove: JustMove: true diff --git a/mods/ra/rules/infantry.yaml b/mods/ra/rules/infantry.yaml index 15da42a2af..38592e9e79 100644 --- a/mods/ra/rules/infantry.yaml +++ b/mods/ra/rules/infantry.yaml @@ -155,7 +155,7 @@ E6: Passenger: PipType: Yellow EngineerRepair: - EngineerCapture: + Captures: TakeCover: -AutoTarget: AttackMove: