Files
OpenRA/OpenRA.Game/VoiceExts.cs
reaperrr 3777a8bca9 Moved Voice-related extensions to VoiceExts.
Note: This is a work-around until Selectable can be moved to Mods.Common, which is when the voice extensions should be moved back to ActorExts.

Pulled phrase check before foreach in PlayVoice ActorExts.
Removed superflous actor parameter from PlayVoice/PlayVoiceLocal.

Simplified PlayVoice extensions.

variant is no longer customisable, as all current usages use self.Owner.Country.Race anyway.
2015-05-23 13:46:01 +02:00

76 lines
1.8 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using OpenRA.Traits;
namespace OpenRA
{
public static class VoiceExts
{
public static void PlayVoice(this Actor self, string phrase)
{
if (phrase == null)
return;
foreach (var voiced in self.TraitsImplementing<IVoiced>())
{
if (string.IsNullOrEmpty(voiced.VoiceSet))
return;
voiced.PlayVoice(self, phrase, self.Owner.Country.Race);
}
}
public static void PlayVoiceLocal(this Actor self, string phrase, float volume)
{
if (phrase == null)
return;
foreach (var voiced in self.TraitsImplementing<IVoiced>())
{
if (string.IsNullOrEmpty(voiced.VoiceSet))
return;
voiced.PlayVoiceLocal(self, phrase, self.Owner.Country.Race, volume);
}
}
public static bool HasVoice(this Actor self, string voice)
{
return self.TraitsImplementing<IVoiced>().Any(x => x.HasVoice(self, voice));
}
public static void PlayVoiceForOrders(this World w, Order[] orders)
{
// Find an actor with a phrase to say
foreach (var o in orders)
{
if (o == null)
continue;
var orderSubject = o.Subject;
if (orderSubject.Destroyed)
continue;
foreach (var voice in orderSubject.TraitsImplementing<IVoiced>())
foreach (var v in orderSubject.TraitsImplementing<IOrderVoice>())
{
if (voice.PlayVoice(orderSubject, v.VoicePhraseForOrder(orderSubject, o),
orderSubject.Owner.Country.Race))
return;
}
}
}
}
}