diff --git a/OpenRA.Mods.RA/AutoTarget.cs b/OpenRA.Mods.RA/AutoTarget.cs index b09d09c28a..1cedf6c5d9 100644 --- a/OpenRA.Mods.RA/AutoTarget.cs +++ b/OpenRA.Mods.RA/AutoTarget.cs @@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA public enum UnitStance { HoldFire, ReturnFire, AttackAnything }; - public class AutoTarget : INotifyIdle, INotifyDamage, ITick + public class AutoTarget : INotifyIdle, INotifyDamage, ITick, IResolveOrder { readonly AutoTargetInfo Info; readonly AttackBase attack; @@ -38,6 +38,12 @@ namespace OpenRA.Mods.RA attack = self.Trait(); } + public void ResolveOrder(Actor self, Order order) + { + if (order.OrderString == "SetUnitStance") + stance = (UnitStance)order.TargetLocation.X; + } + public void Damaged(Actor self, AttackInfo e) { if (!self.IsIdle) return; diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index 1d5228d0b7..fa0ad57d24 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -27,6 +27,7 @@ namespace OpenRA.Mods.RA.Widgets public string StopKey = "s"; public string ScatterKey = "x"; public string DeployKey = "f"; + public string StanceCycleKey = "z"; public string BaseCycleKey = "backspace"; public readonly OrderManager OrderManager; @@ -38,6 +39,7 @@ namespace OpenRA.Mods.RA.Widgets public override string GetCursor(int2 pos) { return null; } public override Rectangle GetEventBounds() { return Rectangle.Empty; } + public override bool HandleKeyPress(KeyInput e) { if (World == null) return false; @@ -67,6 +69,9 @@ namespace OpenRA.Mods.RA.Widgets if (e.KeyName == DeployKey) return PerformDeploy(); + + if (e.KeyName == StanceCycleKey) + return PerformStanceCycle(); } return false; @@ -115,6 +120,28 @@ namespace OpenRA.Mods.RA.Widgets return true; } + bool PerformStanceCycle() + { + var actor = World.Selection.Actors + .Where(a => a.Owner == World.LocalPlayer) + .Select(a => Pair.New( a, a.TraitOrDefault() )) + .Where(a => a.Second != null).FirstOrDefault(); + + if (actor.First == null) + return true; + + var stances = (UnitStance[])Enum.GetValues(typeof(UnitStance)); + + var nextStance = stances.Concat(stances).SkipWhile(s => s != actor.Second.stance).Skip(1).First(); + + PerformKeyboardOrderOnSelection(a => + new Order("SetUnitStance", a, false) { TargetLocation = new int2((int)nextStance, 0) }); + + Game.Debug( "Unit stance set to: {0}".F(nextStance) ); + + return true; + } + bool CycleBases() { var bases = World.ActorsWithTrait()