diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 6e1e348e4b..71af523026 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -99,17 +99,9 @@ namespace OpenRA.Widgets if (world.OrderGenerator == null) return; var orders = world.OrderGenerator.Order(world, xy.ToInt2(), mi).ToArray(); - orders.Do( o => world.IssueOrder( o ) ); - - // Find an actor with a phrase to say - foreach (var o in orders) - { - if (o.Subject.Destroyed) continue; - foreach (var v in o.Subject.TraitsImplementing()) - if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), - o.Subject, o.Subject.Owner.Country.Race)) - return; - } + orders.Do( o => world.IssueOrder( o ) ); + + world.PlayVoiceForOrders(orders); } public override string GetCursor(int2 pos) diff --git a/OpenRA.Game/WorldUtils.cs b/OpenRA.Game/WorldUtils.cs index 6efaedd616..764216857b 100755 --- a/OpenRA.Game/WorldUtils.cs +++ b/OpenRA.Game/WorldUtils.cs @@ -124,6 +124,19 @@ namespace OpenRA if (!a.Info.Traits.Contains()) return null; var v = a.Info.Traits.Get().Voice; return (v == null) ? null : Rules.Voices[v]; + } + + public static void PlayVoiceForOrders(this World w, Order[] orders) + { + // Find an actor with a phrase to say + foreach (var o in orders) + { + if (o.Subject.Destroyed) continue; + foreach (var v in o.Subject.TraitsImplementing()) + if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), + o.Subject, o.Subject.Owner.Country.Race)) + return; + } } } } diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index b85df3980a..6dfd50cb35 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -15,6 +15,7 @@ namespace OpenRA.Mods.RA.Widgets public char AttackMoveKey = 'a'; public char StopKey = 's'; public char ScatterKey = 'x'; + public char DeployKey = 'f'; public readonly OrderManager OrderManager; [ObjectCreator.UseCtor] @@ -50,11 +51,16 @@ namespace OpenRA.Mods.RA.Widgets if (e.KeyChar == ScatterKey) return PerformScatter(); + + if (e.KeyChar == DeployKey) + return PerformDeploy(); } return false; } + // todo: take ALL this garbage and route it through the OrderTargeter stuff. + bool PerformAttackMove() { World.OrderGenerator = new GenericSelectTarget(World.Selection.Actors, "AttackMove", @@ -63,21 +69,28 @@ namespace OpenRA.Mods.RA.Widgets return true; } + void PerformKeyboardOrderOnSelection(Func f) + { + var orders = World.Selection.Actors.Select(f).ToArray(); + foreach (var o in orders) World.IssueOrder(o); + World.PlayVoiceForOrders(orders); + } + bool PerformStop() { - /* issue a stop order to everyone. */ - foreach (var a in World.Selection.Actors) - World.IssueOrder(new Order("Stop", a, false)); - + PerformKeyboardOrderOnSelection(a => new Order("Stop", a, false)); return true; } bool PerformScatter() { - /* issue a stop order to everyone. */ - foreach (var a in World.Selection.Actors) - World.IssueOrder(new Order("Scatter", a, false)); + PerformKeyboardOrderOnSelection(a => new Order("Scatter", a, false)); + return true; + } + bool PerformDeploy() + { + PerformKeyboardOrderOnSelection(a => new Order("Deploy", a, false)); return true; } }