Bunch of new sounds by Omniary, some charactersound & soundplayer refactoring

This commit is contained in:
Regalis
2016-12-15 21:42:15 +02:00
parent 3797233839
commit b01b38da68
53 changed files with 315 additions and 101 deletions
+124
View File
@@ -92,6 +92,7 @@
<Compile Include="Source\Characters\CharacterHUD.cs" />
<Compile Include="Source\Characters\CharacterInfo.cs" />
<Compile Include="Source\Characters\AI\ISteerable.cs" />
<Compile Include="Source\Characters\CharacterSound.cs" />
<Compile Include="Source\Characters\DelayedEffect.cs" />
<Compile Include="Source\Characters\HUDProgressBar.cs" />
<Compile Include="Source\Characters\HuskInfection.cs" />
@@ -1079,6 +1080,15 @@
<None Include="Content\Characters\Charybdis\charybdisattack.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Coelanth\attack1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Coelanth\idle1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Coelanth\idle2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Crawler\attack1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -1100,6 +1110,12 @@
<None Include="Content\Characters\Endworm\endwormidle.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Fractalguardian\Die1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Fractalguardian\Die2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Fractalguardian\guardian1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -1115,6 +1131,21 @@
<None Include="Content\Characters\Husk\Husk3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Mantis\attack1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Mantis\attack2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Mantis\idle1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Mantis\idle2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Mantis\idle3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Moloch\attack1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -1136,6 +1167,33 @@
<None Include="Content\Characters\Scorpion\scorpionidle2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\attack1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\attack2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\attack3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch5.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Characters\Watcher\watch6.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Content.mgcb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -1268,6 +1326,57 @@
<None Include="Content\SmallFont.xnb">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient10.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient11.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient12.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient13.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient5.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient6.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient7.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient8.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\Ambient9.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\DistantPod1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\DistantPod2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\DistantPod3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Ambient\GlacialMovement.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Damage\creak1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
@@ -1382,6 +1491,21 @@
<None Include="Content\Sounds\UI\UImsg.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\Drown1.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\Drown2.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\Drown3.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\Drown4.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\DrownLoop.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Sounds\Water\FlowLarge.ogg">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Binary file not shown.
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<Character name ="coelanth" humanoid="false" health="100.0">
<sound file="Content/Characters/Scorpion/scorpionattack1.ogg" state="Attack" />
<sound file="Content/Characters/Scorpion/scorpionidle1.ogg" state="None" />
<sound file="Content/Characters/Scorpion/scorpionidle2.ogg" state="None" />
<sound file="Content/Characters/Coelanth/attack1.ogg" state="Attack" />
<sound file="Content/Characters/Coelanth/idle1.ogg" state="None" />
<sound file="Content/Characters/Coelanth/idle2.ogg" state="None" />
<ragdoll waveamplitude="50.0" wavelength="2500" swimspeed="5.0" walkspeed="3.5" canentersubmarine="false">
Binary file not shown.
Binary file not shown.
@@ -3,6 +3,8 @@
<sound file="Content/Characters/Fractalguardian/guardian1.ogg" state="Attack" range="3000" />
<sound file="Content/Characters/Fractalguardian/guardian2.ogg" state="Attack" range="3000" />
<sound file="Content/Characters/Fractalguardian/Die1.ogg" state="Die" range="3000" />
<sound file="Content/Characters/Fractalguardian/Die2.ogg" state="Die" range="3000" />
<ragdoll waveamplitude="50.0" wavelength="500" swimspeed="3.0" walkspeed="0.3" flip="false" canentersubmarine="false">
@@ -3,6 +3,8 @@
<sound file="Content/Characters/Fractalguardian/guardian1.ogg" state="Attack" range="3000" />
<sound file="Content/Characters/Fractalguardian/guardian2.ogg" state="Attack" range="3000" />
<sound file="Content/Characters/Fractalguardian/Die1.ogg" state="Die" range="3000" />
<sound file="Content/Characters/Fractalguardian/Die2.ogg" state="Die" range="3000" />
<ragdoll waveamplitude="0.0" swimspeed="1.0" walkspeed="0.3" flip="false" canentersubmarine="false" rotatetowardsmovement="false">
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,12 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<Character name ="mantis" humanoid="false" health="200" doesbleed="false">
<sound file="Content/Characters/Crawler/attack1.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Crawler/attack2.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Crawler/idle1.ogg" state="None" range="500"/>
<sound file="Content/Characters/Crawler/idle2.ogg" state="None" range="500"/>
<sound file="Content/Characters/Mantis/attack1.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Mantis/attack2.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Mantis/idle1.ogg" state="None" range="500"/>
<sound file="Content/Characters/Mantis/idle2.ogg" state="None" range="500"/>
<sound file="Content/Characters/Mantis/idle3.ogg" state="None" range="500"/>
<ragdoll headposition="120" headangle="-90"
waveamplitude="50.0" wavelength="2500"
swimspeed="2.0" walkspeed="3.0"
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<Character name ="watcher" humanoid="false" health ="1000">
<sound file="Content/Characters/Watcher/attack1.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Watcher/attack2.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Watcher/attack3.ogg" state="Attack" range="500"/>
<sound file="Content/Characters/Watcher/watch1.ogg" state="None" range="500"/>
<sound file="Content/Characters/Watcher/watch2.ogg" state="None" range="500"/>
<sound file="Content/Characters/Watcher/watch3.ogg" state="None" range="500"/>
<sound file="Content/Characters/Watcher/watch4.ogg" state="None" range="500"/>
<sound file="Content/Characters/Watcher/watch5.ogg" state="None" range="500"/>
<sound file="Content/Characters/Watcher/watch6.ogg" state="None" range="500"/>
<ragdoll waveamplitude="0.0" swimspeed="0.5" walkspeed="0.3" mirror="true" rotatetowardsmovement="false" headangle="-90">
<collider radius="100"/>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+24 -3
View File
@@ -32,14 +32,35 @@
<damagesound file="Content/Sounds/Damage/HitArmor2.ogg" damagerange="5.0,80.0" damagesoundtype="LimbArmor"/>
<damagesound file="Content/Sounds/Damage/HitArmor3.ogg" damagerange="40.0,100.0" damagesoundtype="LimbArmor"/>
<damagesound file="Content/Sounds/Damage/implode.ogg" damagerange="0.0,100.0" damagesoundtype="Implode"/>
<damagesound file="Content/Sounds/Damage/creak1.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak2.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak3.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak4.ogg" damagesoundtype="Pressure"/>
<damagesound file="Content/Sounds/Damage/creak5.ogg" damagesoundtype="Pressure"/>
<implode file="Content/Sounds/Damage/implode.ogg"/>
<drown file="Content/Sounds/Water/Drown1.ogg"/>
<drown file="Content/Sounds/Water/Drown2.ogg"/>
<drown file="Content/Sounds/Water/Drown3.ogg"/>
<drown file="Content/Sounds/Water/Drown4.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient1.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient2.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient3.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient4.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient5.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient6.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient7.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient8.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient9.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient10.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient11.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient12.ogg"/>
<ambient file="Content/Sounds/Ambient/Ambient13.ogg"/>
<ambient file="Content/Sounds/Ambient/DistantPod1.ogg"/>
<ambient file="Content/Sounds/Ambient/DistantPod2.ogg"/>
<ambient file="Content/Sounds/Ambient/DistantPod3.ogg"/>
<ambient file="Content/Sounds/Ambient/GlacialMovement.ogg"/>
<music file="Content/Sounds/Music/Simplex.ogg" type="default"/>
<music file="Content/Sounds/Music/Tenebrous Brothers Carnival - Prelude.ogg" type="default"/>
+9 -1
View File
@@ -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;
}
+23 -46
View File
@@ -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<CharacterSound> 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<CharacterSound>();
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;
@@ -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<SoundType>(ToolBox.GetAttributeString(element, "state", "Idle"), true, out Type);
}
}
}
@@ -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);
+79 -42
View File
@@ -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<string, Sound> 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<DamageSound> damageSounds;
private static Sound startDrone;
public static bool Initialized;
@@ -133,39 +137,43 @@ namespace Barotrauma
i++;
}
}
List<KeyValuePair<string, Sound>> miscSoundList = new List<KeyValuePair<string, Sound>>();
damageSounds = new List<DamageSound>();
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<DamageSoundType>(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<string, Sound>(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;