diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index c183edcf7d..c81820721a 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -24,8 +24,30 @@ namespace OpenRa.Game if (order.Subject != null && order.Player == Game.LocalPlayer) doVoice = order.Subject; } + if (doVoice != null && doVoice.traits.Contains()) - Game.PlaySound(Game.SovietVoices.First.GetNext() + GetVoiceSuffix(doVoice), false); + PlayVoiceClip("Move", doVoice); + } + + static void PlayVoiceClip(string phrase, Actor voicedUnit) + { + if (voicedUnit == null) return; + + var mi = voicedUnit.unitInfo as MobileInfo; + if (mi == null) return; + + var vi = Rules.VoiceInfo[ mi.Voice ]; + + var clip = vi.Pools.Value[phrase].GetNext(); + if (clip == null) + return; + + var variants = (voicedUnit.Owner.Race == Race.Soviet) + ? vi.SovietVariants : vi.AlliedVariants; + + var variant = variants[ voicedUnit.ActorID % variants.Length ]; + + Game.PlaySound(clip + variant, false); } public void AddOrder(Order o) { recentOrders.Add(o); } @@ -79,8 +101,7 @@ namespace OpenRa.Game && a.Owner == Game.LocalPlayer) .FirstOrDefault(); - if (voicedUnit != null) - Game.PlaySound(Game.SovietVoices.Second.GetNext() + GetVoiceSuffix(voicedUnit), false); + PlayVoiceClip("Select", voicedUnit); } dragStart = dragEnd = xy; diff --git a/OpenRa.Game/Game.cs b/OpenRa.Game/Game.cs index fb8f16ed25..da0edef438 100644 --- a/OpenRa.Game/Game.cs +++ b/OpenRa.Game/Game.cs @@ -291,11 +291,6 @@ namespace OpenRa.Game public static Random SharedRandom = new Random(0); /* for things that require sync */ public static Random CosmeticRandom = new Random(); /* for things that are just fluff */ - public static readonly Pair SovietVoices = - Pair.New( - new VoicePool("ackno", "affirm1", "noprob", "overout", "ritaway", "roger", "ugotit"), - new VoicePool("await1", "ready", "report1", "yessir1")); - public static int2? FindAdjacentTile(Actor a, UnitMovementType umt) { var tiles = Footprint.Tiles(a, a.traits.Get()); diff --git a/OpenRa.Game/GameRules/VoiceInfo.cs b/OpenRa.Game/GameRules/VoiceInfo.cs index 333ac8b9bf..7e4dfa6393 100644 --- a/OpenRa.Game/GameRules/VoiceInfo.cs +++ b/OpenRa.Game/GameRules/VoiceInfo.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using IjwFramework.Types; +using IjwFramework.Collections; namespace OpenRa.Game.GameRules { @@ -12,5 +14,18 @@ namespace OpenRa.Game.GameRules public readonly string[] Select = {}; public readonly string[] Move = {}; public readonly string[] Attack = null; + + public readonly Lazy> Pools; + + public VoiceInfo() + { + Pools = Lazy.New(() => + new Dictionary + { + { "Select", new VoicePool(Select) }, + { "Move", new VoicePool(Move) }, + { "Attack", new VoicePool( Attack ?? Move ) }, + }); + } } } diff --git a/OpenRa.Game/VoicePool.cs b/OpenRa.Game/VoicePool.cs index c6dafb89e6..b6bdfa7eec 100644 --- a/OpenRa.Game/VoicePool.cs +++ b/OpenRa.Game/VoicePool.cs @@ -17,6 +17,9 @@ namespace OpenRa.Game if (liveclips.Count == 0) liveclips.AddRange(clips); + if (liveclips.Count == 0) + return null; /* avoid crashing if there's no clips at all */ + var i = Game.CosmeticRandom.Next(liveclips.Count); var s = liveclips[i]; liveclips.RemoveAt(i);