diff --git a/OpenRA.Game/Orders/UnitOrderGenerator.cs b/OpenRA.Game/Orders/UnitOrderGenerator.cs index 2da5b60b31..b0be25e591 100644 --- a/OpenRA.Game/Orders/UnitOrderGenerator.cs +++ b/OpenRA.Game/Orders/UnitOrderGenerator.cs @@ -115,6 +115,7 @@ namespace OpenRA.Orders case "Capture": return "capture"; case "Harvest": return "attackmove"; case "Steal" : return "enter"; + case "BeginMinefield": return "ability"; default: return null; } diff --git a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs index af1561404e..4848d292a8 100644 --- a/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs +++ b/OpenRA.Mods.Aftermath/ChronoshiftDeploy.cs @@ -59,7 +59,8 @@ namespace OpenRA.Mods.Aftermath { if (order.OrderString == "Deploy") { - Game.controller.orderGenerator = new SetChronoTankDestination(self); + if (self.Owner == self.World.LocalPlayer) + Game.controller.orderGenerator = new SetChronoTankDestination(self); return; } @@ -70,7 +71,9 @@ namespace OpenRA.Mods.Aftermath if (!self.Owner.Shroud.IsExplored(order.TargetLocation)) return; - Game.controller.CancelInputMode(); + if (self.Owner == self.World.LocalPlayer) + Game.controller.CancelInputMode(); + self.CancelActivity(); self.QueueActivity(new Teleport(order.TargetLocation)); Sound.Play("chrotnk1.aud", self.CenterLocation); diff --git a/OpenRA.Mods.RA/Minelayer.cs b/OpenRA.Mods.RA/Minelayer.cs index b488fd38f3..a8bd7ba0b0 100644 --- a/OpenRA.Mods.RA/Minelayer.cs +++ b/OpenRA.Mods.RA/Minelayer.cs @@ -21,42 +21,80 @@ using System.Linq; using OpenRA.Mods.RA.Activities; using OpenRA.Traits; +using System.Collections.Generic; namespace OpenRA.Mods.RA { class MinelayerInfo : TraitInfo { public readonly string Mine = "minv"; + public readonly int MinefieldDepth = 2; } class Minelayer : IIssueOrder, IResolveOrder { + int2[] minefield = null; + int2 minefieldStart; /* nosync! */ + public Order IssueOrder(Actor self, int2 xy, MouseInput mi, Actor underCursor) { - var limitedAmmo = self.traits.GetOrDefault(); - if (limitedAmmo != null && !limitedAmmo.HasAmmo()) - return null; - - // Ensure that the cell is empty except for the minelayer - if (self.World.WorldActor.traits.Get().GetUnitsAt(xy).Any(a => a != self)) - return null; - - if (mi.Button == MouseButton.Right && underCursor == self) - return new Order("Deploy", self); + if (mi.Button == MouseButton.Right && underCursor == null) + return new Order("BeginMinefield", self, xy); return null; } public void ResolveOrder(Actor self, Order order) { - if (order.OrderString == "Deploy") - { - var limitedAmmo = self.traits.GetOrDefault(); - if (limitedAmmo != null) - limitedAmmo.Attacking(self); + if (order.OrderString == "BeginMinefield") + if (self.Owner == self.World.LocalPlayer) + { + minefieldStart = order.TargetLocation; + Game.controller.orderGenerator = new MinefieldOrderGenerator(self); + } - self.QueueActivity( new LayMine() ); + if (order.OrderString == "PlaceMinefield") + { + if (self.Owner == self.World.LocalPlayer) + Game.controller.CancelInputMode(); + minefield = GetMinefieldCells(minefieldStart, order.TargetLocation, + self.Info.Traits.Get().MinefieldDepth).ToArray(); + + /* todo: start the mnly actually laying mines there */ } } + + IEnumerable GetMinefieldCells(int2 start, int2 end, int depth) + { + yield break; /* todo: cells in locus */ + } + + class MinefieldOrderGenerator : IOrderGenerator + { + Actor minelayer; + + public MinefieldOrderGenerator(Actor self) { minelayer = self; } + + public IEnumerable Order(World world, int2 xy, MouseInput mi) + { + var underCursor = world.FindUnitsAtMouse(mi.Location) + .Where(a => a.Info.Traits.Contains()) + .OrderByDescending(a => a.Info.Traits.Get().Priority) + .FirstOrDefault(); + + if (mi.Button == MouseButton.Right && underCursor == null) + yield return new Order("PlaceMinefield", minelayer, xy); + } + + public void Tick(World world) + { + if (minelayer.IsDead || !minelayer.IsInWorld) + Game.controller.CancelInputMode(); + } + + public void Render(World world) { } + + public string GetCursor(World world, int2 xy, MouseInput mi) { return "ability"; } /* todo */ + } } }