diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 9fc9b0bf7d..57c74ffc8b 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -109,6 +109,7 @@ + @@ -179,6 +180,7 @@ + diff --git a/OpenRa.Game/Traits/Activities/CaptureBuilding.cs b/OpenRa.Game/Traits/Activities/CaptureBuilding.cs new file mode 100644 index 0000000000..4df1009190 --- /dev/null +++ b/OpenRa.Game/Traits/Activities/CaptureBuilding.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenRa.Game.Traits.Activities +{ + class CaptureBuilding : IActivity + { + Actor target; + + public CaptureBuilding(Actor target) { this.target = target; } + + public IActivity NextActivity { get; set; } + + public IActivity Tick(Actor self) + { + if (target == null || target.IsDead) return NextActivity; + // todo: don't waste engineers on things that have been captured + // between order issue time and the time we hit the building. + + target.Health -= EngineerCapture.EngineerDamage; + if (target.Health <= 0) + { + target.Owner = self.Owner; + target.Health = EngineerCapture.EngineerDamage; + } + + // the engineer is sacrificed. + Game.world.AddFrameEndTask(w => w.Remove(self)); + + return NextActivity; + } + + public void Cancel(Actor self) { target = null; NextActivity = null; } + } +} diff --git a/OpenRa.Game/Traits/EngineerCapture.cs b/OpenRa.Game/Traits/EngineerCapture.cs new file mode 100644 index 0000000000..31e9b8eaac --- /dev/null +++ b/OpenRa.Game/Traits/EngineerCapture.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.Traits.Activities; + +namespace OpenRa.Game.Traits +{ + class EngineerCapture : IOrder + { + public const int EngineerDamage = 300; + + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) + { + if (underCursor == null) return null; + if (!underCursor.traits.Contains()) return null; + + // todo: other bits + + return new Order(underCursor.Health <= EngineerDamage ? "Capture" : "Enter", + self, underCursor, int2.Zero, null); + } + + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "Enter" || order.OrderString == "Capture") + { + self.CancelActivity(); + self.QueueActivity(new Move(order.TargetActor, 2)); + self.QueueActivity(new CaptureBuilding(order.TargetActor)); + } + } + } +} diff --git a/units.ini b/units.ini index 156c0f25da..3e66b0dd62 100755 --- a/units.ini +++ b/units.ini @@ -564,7 +564,7 @@ FireDelay=8 LongDesc=Advanced Anti-infantry unit.\n Strong vs Infantry, Buildings\n Weak vs Vehicles [E6] Description=Engineer -Traits=Unit, Mobile, RenderInfantry, TakeCover, SquishByTank +Traits=Unit, Mobile, EngineerCapture, RenderInfantry, TakeCover, SquishByTank Voice=EngineerVoice LongDesc=Infiltrates and captures enemy structures.\n Strong vs Nothing\n Weak vs Everything [SPY]