diff --git a/Subsurface/Barotrauma.csproj b/Subsurface/Barotrauma.csproj
index e7c9eb510..6ec2a62e6 100644
--- a/Subsurface/Barotrauma.csproj
+++ b/Subsurface/Barotrauma.csproj
@@ -92,6 +92,7 @@
+
@@ -1079,6 +1080,15 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
@@ -1100,6 +1110,12 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
@@ -1115,6 +1131,21 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
@@ -1136,6 +1167,33 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
@@ -1268,6 +1326,57 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
@@ -1382,6 +1491,21 @@
PreserveNewest
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
+
+ PreserveNewest
+
PreserveNewest
diff --git a/Subsurface/Content/Characters/Coelanth/attack1.ogg b/Subsurface/Content/Characters/Coelanth/attack1.ogg
new file mode 100644
index 000000000..8985861ab
Binary files /dev/null and b/Subsurface/Content/Characters/Coelanth/attack1.ogg differ
diff --git a/Subsurface/Content/Characters/Coelanth/coelanth.xml b/Subsurface/Content/Characters/Coelanth/coelanth.xml
index 369627839..4e820b397 100644
--- a/Subsurface/Content/Characters/Coelanth/coelanth.xml
+++ b/Subsurface/Content/Characters/Coelanth/coelanth.xml
@@ -1,9 +1,9 @@
-
-
-
+
+
+
diff --git a/Subsurface/Content/Characters/Coelanth/idle1.ogg b/Subsurface/Content/Characters/Coelanth/idle1.ogg
new file mode 100644
index 000000000..079231c03
Binary files /dev/null and b/Subsurface/Content/Characters/Coelanth/idle1.ogg differ
diff --git a/Subsurface/Content/Characters/Coelanth/idle2.ogg b/Subsurface/Content/Characters/Coelanth/idle2.ogg
new file mode 100644
index 000000000..998f7769b
Binary files /dev/null and b/Subsurface/Content/Characters/Coelanth/idle2.ogg differ
diff --git a/Subsurface/Content/Characters/Fractalguardian/Die1.ogg b/Subsurface/Content/Characters/Fractalguardian/Die1.ogg
new file mode 100644
index 000000000..a3786d9bc
Binary files /dev/null and b/Subsurface/Content/Characters/Fractalguardian/Die1.ogg differ
diff --git a/Subsurface/Content/Characters/Fractalguardian/Die2.ogg b/Subsurface/Content/Characters/Fractalguardian/Die2.ogg
new file mode 100644
index 000000000..4e24f4425
Binary files /dev/null and b/Subsurface/Content/Characters/Fractalguardian/Die2.ogg differ
diff --git a/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml b/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml
index 86c561a70..69ad89036 100644
--- a/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml
+++ b/Subsurface/Content/Characters/Fractalguardian/fractalguardian.xml
@@ -3,6 +3,8 @@
+
+
diff --git a/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml b/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml
index e1d743557..9f45de877 100644
--- a/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml
+++ b/Subsurface/Content/Characters/Fractalguardian2/fractalguardian2.xml
@@ -3,6 +3,8 @@
+
+
diff --git a/Subsurface/Content/Characters/Mantis/attack1.ogg b/Subsurface/Content/Characters/Mantis/attack1.ogg
new file mode 100644
index 000000000..46084f03a
Binary files /dev/null and b/Subsurface/Content/Characters/Mantis/attack1.ogg differ
diff --git a/Subsurface/Content/Characters/Mantis/attack2.ogg b/Subsurface/Content/Characters/Mantis/attack2.ogg
new file mode 100644
index 000000000..72de2e2e7
Binary files /dev/null and b/Subsurface/Content/Characters/Mantis/attack2.ogg differ
diff --git a/Subsurface/Content/Characters/Mantis/idle1.ogg b/Subsurface/Content/Characters/Mantis/idle1.ogg
new file mode 100644
index 000000000..261360518
Binary files /dev/null and b/Subsurface/Content/Characters/Mantis/idle1.ogg differ
diff --git a/Subsurface/Content/Characters/Mantis/idle2.ogg b/Subsurface/Content/Characters/Mantis/idle2.ogg
new file mode 100644
index 000000000..d1f349935
Binary files /dev/null and b/Subsurface/Content/Characters/Mantis/idle2.ogg differ
diff --git a/Subsurface/Content/Characters/Mantis/idle3.ogg b/Subsurface/Content/Characters/Mantis/idle3.ogg
new file mode 100644
index 000000000..03d2bd9bc
Binary files /dev/null and b/Subsurface/Content/Characters/Mantis/idle3.ogg differ
diff --git a/Subsurface/Content/Characters/Mantis/mantis.xml b/Subsurface/Content/Characters/Mantis/mantis.xml
index 669325144..298d4c9e6 100644
--- a/Subsurface/Content/Characters/Mantis/mantis.xml
+++ b/Subsurface/Content/Characters/Mantis/mantis.xml
@@ -1,12 +1,13 @@
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient1.ogg b/Subsurface/Content/Sounds/Ambient/Ambient1.ogg
new file mode 100644
index 000000000..989dbe9e2
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient1.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient10.ogg b/Subsurface/Content/Sounds/Ambient/Ambient10.ogg
new file mode 100644
index 000000000..d3eca7178
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient10.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient11.ogg b/Subsurface/Content/Sounds/Ambient/Ambient11.ogg
new file mode 100644
index 000000000..770195613
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient11.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient12.ogg b/Subsurface/Content/Sounds/Ambient/Ambient12.ogg
new file mode 100644
index 000000000..c1204701a
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient12.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient13.ogg b/Subsurface/Content/Sounds/Ambient/Ambient13.ogg
new file mode 100644
index 000000000..f2928a565
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient13.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient2.ogg b/Subsurface/Content/Sounds/Ambient/Ambient2.ogg
new file mode 100644
index 000000000..770509f0d
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient2.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient3.ogg b/Subsurface/Content/Sounds/Ambient/Ambient3.ogg
new file mode 100644
index 000000000..bded9985d
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient3.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient4.ogg b/Subsurface/Content/Sounds/Ambient/Ambient4.ogg
new file mode 100644
index 000000000..8780f7e17
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient4.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient5.ogg b/Subsurface/Content/Sounds/Ambient/Ambient5.ogg
new file mode 100644
index 000000000..2b9b2b92f
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient5.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient6.ogg b/Subsurface/Content/Sounds/Ambient/Ambient6.ogg
new file mode 100644
index 000000000..d68139998
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient6.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient7.ogg b/Subsurface/Content/Sounds/Ambient/Ambient7.ogg
new file mode 100644
index 000000000..2531af434
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient7.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient8.ogg b/Subsurface/Content/Sounds/Ambient/Ambient8.ogg
new file mode 100644
index 000000000..4f3ce0d0e
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient8.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/Ambient9.ogg b/Subsurface/Content/Sounds/Ambient/Ambient9.ogg
new file mode 100644
index 000000000..8824bc1eb
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/Ambient9.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/DistantPod1.ogg b/Subsurface/Content/Sounds/Ambient/DistantPod1.ogg
new file mode 100644
index 000000000..6cca53a49
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/DistantPod1.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/DistantPod2.ogg b/Subsurface/Content/Sounds/Ambient/DistantPod2.ogg
new file mode 100644
index 000000000..4024a403f
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/DistantPod2.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/DistantPod3.ogg b/Subsurface/Content/Sounds/Ambient/DistantPod3.ogg
new file mode 100644
index 000000000..25d7d7906
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/DistantPod3.ogg differ
diff --git a/Subsurface/Content/Sounds/Ambient/GlacialMovement.ogg b/Subsurface/Content/Sounds/Ambient/GlacialMovement.ogg
new file mode 100644
index 000000000..574cc64f5
Binary files /dev/null and b/Subsurface/Content/Sounds/Ambient/GlacialMovement.ogg differ
diff --git a/Subsurface/Content/Sounds/Water/Drown1.ogg b/Subsurface/Content/Sounds/Water/Drown1.ogg
new file mode 100644
index 000000000..f4b97d4db
Binary files /dev/null and b/Subsurface/Content/Sounds/Water/Drown1.ogg differ
diff --git a/Subsurface/Content/Sounds/Water/Drown2.ogg b/Subsurface/Content/Sounds/Water/Drown2.ogg
new file mode 100644
index 000000000..5e68eab83
Binary files /dev/null and b/Subsurface/Content/Sounds/Water/Drown2.ogg differ
diff --git a/Subsurface/Content/Sounds/Water/Drown3.ogg b/Subsurface/Content/Sounds/Water/Drown3.ogg
new file mode 100644
index 000000000..d6077852b
Binary files /dev/null and b/Subsurface/Content/Sounds/Water/Drown3.ogg differ
diff --git a/Subsurface/Content/Sounds/Water/Drown4.ogg b/Subsurface/Content/Sounds/Water/Drown4.ogg
new file mode 100644
index 000000000..e7f511419
Binary files /dev/null and b/Subsurface/Content/Sounds/Water/Drown4.ogg differ
diff --git a/Subsurface/Content/Sounds/Water/DrownLoop.ogg b/Subsurface/Content/Sounds/Water/DrownLoop.ogg
new file mode 100644
index 000000000..29169d014
Binary files /dev/null and b/Subsurface/Content/Sounds/Water/DrownLoop.ogg differ
diff --git a/Subsurface/Content/Sounds/sounds.xml b/Subsurface/Content/Sounds/sounds.xml
index 8bab2245a..5cc56f402 100644
--- a/Subsurface/Content/Sounds/sounds.xml
+++ b/Subsurface/Content/Sounds/sounds.xml
@@ -32,14 +32,35 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Subsurface/Source/Characters/AICharacter.cs b/Subsurface/Source/Characters/AICharacter.cs
index 72bc85385..43affafbc 100644
--- a/Subsurface/Source/Characters/AICharacter.cs
+++ b/Subsurface/Source/Characters/AICharacter.cs
@@ -57,7 +57,15 @@ namespace Barotrauma
}
else
{
- PlaySound((aiController == null) ? AIController.AiState.None : aiController.State);
+ switch (aiController.State)
+ {
+ case AIController.AiState.Attack:
+ PlaySound(CharacterSound.SoundType.Attack);
+ break;
+ default:
+ PlaySound(CharacterSound.SoundType.Idle);
+ break;
+ }
soundTimer = soundInterval;
}
diff --git a/Subsurface/Source/Characters/Character.cs b/Subsurface/Source/Characters/Character.cs
index 1b5dd2d71..0399c34c8 100644
--- a/Subsurface/Source/Characters/Character.cs
+++ b/Subsurface/Source/Characters/Character.cs
@@ -121,10 +121,7 @@ namespace Barotrauma
private float bleeding;
- private Sound[] sounds;
- private float[] soundRange;
- //which AIstate each sound is for
- private AIController.AiState[] soundStates;
+ private List sounds;
private float attackCoolDown;
@@ -574,28 +571,13 @@ namespace Barotrauma
soundInterval = ToolBox.GetAttributeFloat(doc.Root, "soundinterval", 10.0f);
var soundElements = doc.Root.Elements("sound").ToList();
- if (soundElements.Any())
+
+ sounds = new List();
+ foreach (XElement soundElement in soundElements)
{
- sounds = new Sound[soundElements.Count];
- soundStates = new AIController.AiState[soundElements.Count];
- soundRange = new float[soundElements.Count];
- int i = 0;
- foreach (XElement soundElement in soundElements)
- {
- sounds[i] = Sound.Load(soundElement.Attribute("file").Value);
- soundRange[i] = ToolBox.GetAttributeFloat(soundElement, "range", 1000.0f);
- if (soundElement.Attribute("state") == null)
- {
- soundStates[i] = AIController.AiState.None;
- }
- else
- {
- soundStates[i] = (AIController.AiState)Enum.Parse(
- typeof(AIController.AiState), soundElement.Attribute("state").Value, true);
- }
- i++;
- }
+ sounds.Add(new CharacterSound(soundElement));
}
+
if (file == humanConfigFile)
{
@@ -1322,8 +1304,14 @@ namespace Barotrauma
private void UpdateOxygen(float deltaTime)
{
+ float prevOxygen = oxygen;
Oxygen += deltaTime * (oxygenAvailable < 30.0f ? -5.0f : 10.0f);
+ if (prevOxygen > 0.0f && Oxygen <= 0.0f && controlled == this)
+ {
+ SoundPlayer.PlaySound("drown");
+ }
+
PressureProtection -= deltaTime * 100.0f;
float hullAvailableOxygen = 0.0f;
@@ -1449,24 +1437,15 @@ namespace Barotrauma
return progressBar;
}
- public void PlaySound(AIController.AiState state)
+ public void PlaySound(CharacterSound.SoundType soundType)
{
- if (sounds == null || !sounds.Any()) return;
- var matchingSoundStates = soundStates.Where(x => x == state).ToList();
+ if (sounds == null || sounds.Count == 0) return;
- int selectedSound = Rand.Int(matchingSoundStates.Count);
+ var matchingSounds = sounds.FindAll(s => s.Type == soundType);
+ if (matchingSounds.Count == 0) return;
- int n = 0;
- for (int i = 0; i < sounds.Length; i++)
- {
- if (soundStates[i] != state) continue;
- if (n == selectedSound && sounds[i]!=null)
- {
- sounds[i].Play(1.0f, soundRange[i], AnimController.Limbs[0].WorldPosition);
- return;
- }
- n++;
- }
+ var selectedSound = matchingSounds[Rand.Int(matchingSounds.Count)];
+ selectedSound.Sound.Play(1.0f, selectedSound.Range, AnimController.WorldPosition);
}
public virtual void AddDamage(CauseOfDeath causeOfDeath, float amount, IDamageable attacker)
@@ -1567,7 +1546,7 @@ namespace Barotrauma
// limb.Damage = 100.0f;
}
- SoundPlayer.PlayDamageSound(DamageSoundType.Implode, 50.0f, AnimController.Collider);
+ SoundPlayer.PlaySound("implode", 1.0f, 150.0f, WorldPosition);
for (int i = 0; i < 10; i++)
{
@@ -1620,11 +1599,9 @@ namespace Barotrauma
GameServer.Log(Name+" has died (Cause of death: "+causeOfDeath+")", Color.Red);
if (OnDeath != null) OnDeath(this, causeOfDeath);
-
- //CoroutineManager.StartCoroutine(DeathAnim(GameMain.GameScreen.Cam));
-
- //health = 0.0f;
-
+
+ PlaySound(CharacterSound.SoundType.Die);
+
isDead = true;
this.causeOfDeath = causeOfDeath;
AnimController.movement = Vector2.Zero;
@@ -1635,7 +1612,7 @@ namespace Barotrauma
if (selectedItems[i] != null) selectedItems[i].Drop(this);
}
- if (aiTarget!=null)
+ if (aiTarget != null)
{
aiTarget.Remove();
aiTarget = null;
diff --git a/Subsurface/Source/Characters/CharacterSound.cs b/Subsurface/Source/Characters/CharacterSound.cs
new file mode 100644
index 000000000..fac222550
--- /dev/null
+++ b/Subsurface/Source/Characters/CharacterSound.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace Barotrauma
+{
+ class CharacterSound
+ {
+ public enum SoundType
+ {
+ Idle, Attack, Die
+ }
+
+ public readonly Sound Sound;
+
+ public readonly SoundType Type;
+
+ public readonly float Range;
+
+ public CharacterSound(XElement element)
+ {
+ Sound = Sound.Load(element.Attribute("file").Value);
+ Range = ToolBox.GetAttributeFloat(element, "range", 1000.0f);
+
+ Enum.TryParse(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type);
+ }
+ }
+}
diff --git a/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs b/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs
index c64a1a5e3..cbfe29e10 100644
--- a/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs
+++ b/Subsurface/Source/GameSession/GameModes/Tutorials/BasicTutorial.cs
@@ -293,7 +293,7 @@ namespace Barotrauma.Tutorials
"Content/Characters/Moloch/moloch.xml",
steering.Item.WorldPosition + new Vector2(3000.0f, -500.0f));
- moloch.PlaySound(AIController.AiState.Attack);
+ moloch.PlaySound(CharacterSound.SoundType.Attack);
yield return new WaitForSeconds(1.0f);
diff --git a/Subsurface/Source/Sounds/SoundPlayer.cs b/Subsurface/Source/Sounds/SoundPlayer.cs
index 2854f2e17..6d483ec57 100644
--- a/Subsurface/Source/Sounds/SoundPlayer.cs
+++ b/Subsurface/Source/Sounds/SoundPlayer.cs
@@ -15,8 +15,7 @@ namespace Barotrauma
{
None,
StructureBlunt, StructureSlash,
- LimbBlunt, LimbSlash, LimbArmor,
- Implode, Pressure
+ LimbBlunt, LimbSlash, LimbArmor
}
public struct DamageSound
@@ -54,25 +53,30 @@ namespace Barotrauma
static class SoundPlayer
{
- public static Sound[] flowSounds = new Sound[3];
-
- public static Sound[] SplashSounds = new Sound[10];
+ private static ILookup miscSounds;
+ //music
public static float MusicVolume = 1.0f;
-
private const float MusicLerpSpeed = 0.1f;
- private static Sound[] waterAmbiences = new Sound[2];
- private static int[] waterAmbienceIndexes = new int[2];
-
-
- private static DamageSound[] damageSounds;
-
private static BackgroundMusic currentMusic;
private static BackgroundMusic targetMusic;
private static BackgroundMusic[] musicClips;
private static float currMusicVolume;
+ //ambience
+ private static Sound[] waterAmbiences = new Sound[2];
+ private static int[] waterAmbienceIndexes = new int[2];
+
+ private static float ambientSoundTimer;
+ private static Vector2 ambientSoundInterval = new Vector2(20.0f, 40.0f); //x = min, y = max
+
+ //misc
+ public static Sound[] flowSounds = new Sound[3];
+ public static Sound[] SplashSounds = new Sound[10];
+
+ private static List damageSounds;
+
private static Sound startDrone;
public static bool Initialized;
@@ -133,39 +137,43 @@ namespace Barotrauma
i++;
}
}
+
+ List> miscSoundList = new List>();
+ damageSounds = new List();
- var xDamageSounds = doc.Root.Elements("damagesound").ToList();
-
- if (xDamageSounds.Any())
+ foreach (XElement subElement in doc.Root.Elements())
{
- damageSounds = new DamageSound[xDamageSounds.Count];
- int i = 0;
- foreach (XElement element in xDamageSounds)
+ yield return CoroutineStatus.Running;
+
+ switch (subElement.Name.ToString().ToLowerInvariant())
{
- yield return CoroutineStatus.Running;
-
- Sound sound = Sound.Load(ToolBox.GetAttributeString(element, "file", ""), false);
- if (sound == null) continue;
+ case "music":
+ continue;
+ case "damagesound":
+ Sound damageSound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false);
+ if (damageSound == null) continue;
- DamageSoundType damageSoundType = DamageSoundType.None;
+ DamageSoundType damageSoundType = DamageSoundType.None;
- try
- {
- damageSoundType = (DamageSoundType)Enum.Parse(typeof(DamageSoundType),
- ToolBox.GetAttributeString(element, "damagesoundtype", "None"));
- }
- catch
- {
- damageSoundType = DamageSoundType.None;
- }
+ Enum.TryParse(ToolBox.GetAttributeString(subElement, "damagesoundtype", "None"), false, out damageSoundType);
+ damageSounds.Add(new DamageSound(
+ damageSound, ToolBox.GetAttributeVector2(subElement, "damagerange", new Vector2(0.0f, 100.0f)), damageSoundType));
+ break;
+ default:
+ Sound sound = Sound.Load(ToolBox.GetAttributeString(subElement, "file", ""), false);
+ if (sound != null)
+ {
+ miscSoundList.Add(new KeyValuePair(subElement.Name.ToString().ToLowerInvariant(), sound));
+ }
- damageSounds[i] = new DamageSound(
- sound, ToolBox.GetAttributeVector2(element, "damagerange", new Vector2(0.0f,100.0f)), damageSoundType);
- i++;
+ break;
}
}
+ miscSounds = miscSoundList.ToLookup(kvp => kvp.Key, kvp => kvp.Value);
+
+
Initialized = true;
yield return CoroutineStatus.Success;
@@ -177,7 +185,7 @@ namespace Barotrauma
{
UpdateMusic();
- if (startDrone!=null && !startDrone.IsPlaying)
+ if (startDrone != null && !startDrone.IsPlaying)
{
startDrone.Remove();
startDrone = null;
@@ -229,11 +237,20 @@ namespace Barotrauma
movementSoundVolume = Math.Max(movementSoundVolume, movementFactor);
}
- //if (Submarine.MainSub != null)
- //{
- // movementFactor = (Submarine.MainSub.Velocity == Vector2.Zero) ? 0.0f : Submarine.MainSub.Velocity.Length() / 5.0f;
- // movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
- //}
+ if (ambientSoundTimer > 0.0f)
+ {
+ ambientSoundTimer -= (float)Timing.Step;
+ }
+ else
+ {
+ PlaySound(
+ "ambient",
+ Rand.Range(0.5f, 1.0f),
+ 1000.0f,
+ new Vector2(Sound.CameraPos.X, Sound.CameraPos.Y) + Rand.Vector(100.0f));
+
+ ambientSoundTimer = Rand.Range(ambientSoundInterval.X, ambientSoundInterval.Y);
+ }
SoundManager.LowPassHFGain = lowpassHFGain;
waterAmbienceIndexes[0] = waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f - movementSoundVolume));
@@ -241,6 +258,26 @@ namespace Barotrauma
}
+ public static Sound GetSound(string soundTag)
+ {
+ var matchingSounds = miscSounds[soundTag].ToList();
+ if (matchingSounds.Count == 0) return null;
+
+ return matchingSounds[Rand.Int(matchingSounds.Count)];
+ }
+
+ public static void PlaySound(string soundTag, float volume = 1.0f)
+ {
+ var sound = GetSound(soundTag);
+ if (sound != null) sound.Play(volume);
+ }
+
+ public static void PlaySound(string soundTag, float volume, float range, Vector2 position)
+ {
+ var sound = GetSound(soundTag);
+ if (sound != null) sound.Play(volume, range, position);
+ }
+
private static void UpdateMusic()
{
if (musicClips == null) return;
@@ -276,7 +313,7 @@ namespace Barotrauma
}
catch (FileNotFoundException e)
{
- DebugConsole.ThrowError("Music clip " + targetMusic.file + " not found!");
+ DebugConsole.ThrowError("Music clip " + targetMusic.file + " not found!", e);
}
currentMusic = targetMusic;