diff --git a/OpenRA.Game/Sound/Sound.cs b/OpenRA.Game/Sound/Sound.cs
index 7ac399c040..8654ee2334 100644
--- a/OpenRA.Game/Sound/Sound.cs
+++ b/OpenRA.Game/Sound/Sound.cs
@@ -101,7 +101,7 @@ namespace OpenRA
soundEngine.SetListenerPosition(position);
}
- static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier)
+ static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier = 1f, bool loop = false)
{
if (string.IsNullOrEmpty(name))
return null;
@@ -109,16 +109,18 @@ namespace OpenRA
return null;
return soundEngine.Play2D(sounds[name],
- false, headRelative, pos,
+ loop, headRelative, pos,
InternalSoundVolume * volumeModifier, true);
}
- public static ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1); }
- public static ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1); }
+ public static ISound Play(string name) { return Play(null, name, true, WPos.Zero, 1f); }
+ public static ISound Play(string name, WPos pos) { return Play(null, name, false, pos, 1f); }
public static ISound Play(string name, float volumeModifier) { return Play(null, name, true, WPos.Zero, volumeModifier); }
public static ISound Play(string name, WPos pos, float volumeModifier) { return Play(null, name, false, pos, volumeModifier); }
- public static ISound PlayToPlayer(Player player, string name) { return Play(player, name, true, WPos.Zero, 1); }
- public static ISound PlayToPlayer(Player player, string name, WPos pos) { return Play(player, name, false, pos, 1); }
+ public static ISound PlayToPlayer(Player player, string name) { return Play(player, name, true, WPos.Zero, 1f); }
+ public static ISound PlayToPlayer(Player player, string name, WPos pos) { return Play(player, name, false, pos, 1f); }
+ public static ISound PlayLooped(string name) { return PlayLooped(name, WPos.Zero); }
+ public static ISound PlayLooped(string name, WPos pos) { return Play(null, name, true, pos, 1f, true); }
public static void PlayVideo(byte[] raw, int channels, int sampleBits, int sampleRate)
{
diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
index 3bb01cbe2c..53ea4af361 100644
--- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
+++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj
@@ -415,6 +415,7 @@
+
diff --git a/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs
new file mode 100644
index 0000000000..967f8b9b2d
--- /dev/null
+++ b/OpenRA.Mods.Common/Traits/Sound/AmbientSound.cs
@@ -0,0 +1,33 @@
+#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 OpenRA.Traits;
+
+namespace OpenRA.Mods.Common.Traits
+{
+ [Desc("Plays a looping audio file at the actor position. Attach this to the `World` actor to cover the whole map.")]
+ class AmbientSoundInfo : ITraitInfo
+ {
+ public readonly string SoundFile = null;
+
+ public object Create(ActorInitializer init) { return new AmbientSound(init.Self, this); }
+ }
+
+ class AmbientSound
+ {
+ public AmbientSound(Actor self, AmbientSoundInfo info)
+ {
+ if (self == self.World.WorldActor)
+ Sound.PlayLooped(info.SoundFile);
+ else
+ Sound.PlayLooped(info.SoundFile, self.CenterPosition);
+ }
+ }
+}