diff --git a/OpenRA.Game/GameRules/VoiceInfo.cs b/OpenRA.Game/GameRules/VoiceInfo.cs index 536df3e783..80f3583791 100644 --- a/OpenRA.Game/GameRules/VoiceInfo.cs +++ b/OpenRA.Game/GameRules/VoiceInfo.cs @@ -9,14 +9,14 @@ #endregion using System.Collections.Generic; +using System.Linq; using OpenRA.FileFormats; namespace OpenRA.GameRules { public class VoiceInfo { - public readonly string[] SovietVariants = { ".aud" }; - public readonly string[] AlliedVariants = { ".aud" }; + public readonly Dictionary Variants; public readonly string[] Select = { }; public readonly string[] Move = { }; public readonly string[] Attack = null; @@ -26,7 +26,10 @@ namespace OpenRA.GameRules public VoiceInfo( MiniYaml y ) { - FieldLoader.Load(this, y); + FieldLoader.LoadFields(this, y.Nodes, new string[] { "Select", "Move", "Attack", "Die" }); + Variants = (y.Nodes.ContainsKey("Variants"))? y.Nodes["Variants"].Nodes.ToDictionary(a => a.Key, + a => (string[])FieldLoader.GetValue( "(value)", typeof(string[]), a.Value.Value )) + : new Dictionary(); Pools = Lazy.New(() => new Dictionary diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index d2edf39087..1a38a1a56c 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -42,7 +42,8 @@ namespace OpenRA actors = (isCombine ? oldSelection.Union(newSelection) : newSelection).ToList(); var voicedUnit = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.HasVoice()); - Sound.PlayVoice("Select", voicedUnit); + if (voicedUnit != null) + Sound.PlayVoice("Select", voicedUnit, voicedUnit.Owner.Country.Race); foreach (var ns in world.WorldActor.TraitsImplementing()) ns.SelectionChanged(); diff --git a/OpenRA.Game/Sound.cs b/OpenRA.Game/Sound.cs index 6833e17558..68f4bb8de3 100644 --- a/OpenRA.Game/Sound.cs +++ b/OpenRA.Game/Sound.cs @@ -182,7 +182,7 @@ namespace OpenRA } // Returns true if it played a phrase - public static bool PlayVoice(string phrase, Actor voicedUnit) + public static bool PlayVoice(string phrase, Actor voicedUnit, string variant) { if (voicedUnit == null) return false; if (phrase == null) return false; @@ -203,13 +203,8 @@ namespace OpenRA return true; } - // todo: fix this - var variants = (voicedUnit.Owner.Country.Race == "allies") - ? vi.AlliedVariants : vi.SovietVariants; - - var variant = variants[voicedUnit.ActorID % variants.Length]; - - Play(clip + variant); + var variantext = vi.Variants[variant][voicedUnit.ActorID % vi.Variants.Count]; + Play(clip + variantext); return true; } } diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 3f46f87b2e..7f15a0e553 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -98,7 +98,7 @@ namespace OpenRA.Widgets { foreach (var v in o.Subject.TraitsImplementing()) { - if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), o.Subject)) + if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o), o.Subject, o.Subject.Owner.Country.Race)) { done = true; break; diff --git a/OpenRA.Mods.RA/Render/RenderInfantry.cs b/OpenRA.Mods.RA/Render/RenderInfantry.cs index 3a7405e529..2681b50c72 100644 --- a/OpenRA.Mods.RA/Render/RenderInfantry.cs +++ b/OpenRA.Mods.RA/Render/RenderInfantry.cs @@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA.Render if (e.DamageState == DamageState.Dead) { var death = e.Warhead != null ? e.Warhead.InfDeath : 0; - Sound.PlayVoice("Die", self); + Sound.PlayVoice("Die", self, self.Owner.Country.Race); self.World.AddFrameEndTask(w => w.Add(new Corpse(self, death))); } } diff --git a/mods/cnc/voices.yaml b/mods/cnc/voices.yaml index 4b65d5a408..a089b6bede 100644 --- a/mods/cnc/voices.yaml +++ b/mods/cnc/voices.yaml @@ -1,13 +1,15 @@ GenericVoice: - SovietVariants: .v01,.v03 - AlliedVariants: .v01,.v03 + Variants: + nod: .v01,.v03 + gdi: .v01,.v03 Select: await1,ready,report1,yessir1 Move: ackno,affirm1,noprob,ritaway,roger,ugotit Die: nuyell1.aud,nuyell3.aud,nuyell4.aud,nuyell5.aud VehicleVoice: - SovietVariants: .v00,.v02 - AlliedVariants: .v00,.v02 + Variants: + nod: .v00,.v02 + gdi: .v00,.v02 Select: vehic1,yessir1,report1,await1,unit1 Move: ackno,affirm1,movout1