diff --git a/OpenRA.Mods.Common/ActorExts.cs b/OpenRA.Mods.Common/ActorExts.cs index 4cbe893c74..57f19ca1be 100644 --- a/OpenRA.Mods.Common/ActorExts.cs +++ b/OpenRA.Mods.Common/ActorExts.cs @@ -80,6 +80,39 @@ namespace OpenRA.Mods.Common return Target.Invalid; } + public static void PlayVoice(this Actor self, Actor actor, string phrase, string variant) + { + foreach (var voiced in self.TraitsImplementing()) + { + if (phrase == null) + return; + + if (string.IsNullOrEmpty(voiced.VoiceSet)) + return; + + voiced.PlayVoice(self, phrase, variant); + } + } + + public static void PlayVoiceLocal(this Actor self, Actor actor, string phrase, string variant, float volume) + { + foreach (var voiced in self.TraitsImplementing()) + { + if (phrase == null) + return; + + if (string.IsNullOrEmpty(voiced.VoiceSet)) + return; + + voiced.PlayVoiceLocal(self, phrase, variant, volume); + } + } + + public static bool HasVoice(this Actor self, string voice) + { + return self.TraitsImplementing().Any(x => x.HasVoice(self, voice)); + } + public static void NotifyBlocker(this Actor self, IEnumerable blockers) { foreach (var blocker in blockers) diff --git a/OpenRA.Mods.Common/Traits/Cargo.cs b/OpenRA.Mods.Common/Traits/Cargo.cs index db87aed3f0..e501df1acf 100644 --- a/OpenRA.Mods.Common/Traits/Cargo.cs +++ b/OpenRA.Mods.Common/Traits/Cargo.cs @@ -39,6 +39,9 @@ namespace OpenRA.Mods.Common.Traits [Desc("Terrain types that this actor is allowed to eject actors onto. Leave empty for all terrain types.")] public readonly string[] UnloadTerrainTypes = { }; + [Desc("Voice to play when ordered to unload the passengers.")] + public readonly string UnloadVoice = "Unload"; + [Desc("Which direction the passenger will face (relative to the transport) when unloading.")] public readonly int PassengerFacing = 128; @@ -204,10 +207,10 @@ namespace OpenRA.Mods.Common.Traits public string VoicePhraseForOrder(Actor self, Order order) { - if (order.OrderString != "Unload" || IsEmpty(self)) + if (order.OrderString != "Unload" || IsEmpty(self) || !self.HasVoice(Info.UnloadVoice)) return null; - return self.TraitsImplementing().Any(x => x.HasVoice(self, "Unload")) ? "Unload" : "Move"; + return Info.UnloadVoice; } public bool MoveDisabled(Actor self) { return reserves.Any(); } diff --git a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnBuild.cs b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnBuild.cs index b60ae2f1b8..e3ceb5fc64 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnBuild.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnBuild.cs @@ -19,8 +19,7 @@ namespace OpenRA.Mods.Common.Traits { public void BuildingComplete(Actor self) { - foreach (var voiced in self.TraitsImplementing()) - voiced.PlayVoice(self, "Build", self.Owner.Country.Race); + self.PlayVoice(self, "Build", self.Owner.Country.Race); } } } diff --git a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnKill.cs b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnKill.cs index 2f46199cb7..43e1a1e4f7 100644 --- a/OpenRA.Mods.Common/Traits/Sound/AnnounceOnKill.cs +++ b/OpenRA.Mods.Common/Traits/Sound/AnnounceOnKill.cs @@ -39,8 +39,7 @@ namespace OpenRA.Mods.Common.Traits if (e.DamageState == DamageState.Dead && damaged != e.Attacker) { if (self.World.WorldTick - lastAnnounce > info.Interval * 25) - foreach (var voiced in self.TraitsImplementing()) - voiced.PlayVoice(self, "Kill", self.Owner.Country.Race); + self.PlayVoice(self, "Kill", self.Owner.Country.Race); lastAnnounce = self.World.WorldTick; } diff --git a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs index 69ccbe1d2c..92b0068a1b 100644 --- a/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs +++ b/OpenRA.Mods.Common/Traits/Sound/DeathSounds.cs @@ -42,8 +42,7 @@ namespace OpenRA.Mods.Common.Traits if (info.DeathTypes.Contains(e.Warhead.DeathType) || (!info.DeathTypes.Any() && !self.Info.Traits.WithInterface().Any(dsi => dsi.DeathTypes.Contains(e.Warhead.DeathType)))) - foreach (var voiced in self.TraitsImplementing()) - voiced.PlayVoiceLocal(self, info.DeathSound, self.Owner.Country.Race, info.VolumeMultiplier); + self.PlayVoiceLocal(self, info.DeathSound, self.Owner.Country.Race, info.VolumeMultiplier); } } } \ No newline at end of file