38f1ddb...178a853: v0.8.9.1, removed content folder

This commit is contained in:
Joonas Rikkonen
2019-03-18 19:46:58 +02:00
parent 38f1ddb6fe
commit 6c0679c297
1054 changed files with 151673 additions and 144931 deletions
@@ -1,9 +1,8 @@
using Barotrauma.Items.Components;
using Barotrauma.Extensions;
using Barotrauma.Sounds;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Xml.Linq;
@@ -34,16 +33,16 @@ namespace Barotrauma
public class BackgroundMusic
{
public readonly string file;
public readonly string type;
public readonly string File;
public readonly string Type;
public readonly Vector2 priorityRange;
public BackgroundMusic(string file, string type, Vector2 priorityRange)
public readonly Vector2 IntensityRange;
public BackgroundMusic(XElement element)
{
this.file = file;
this.type = type;
this.priorityRange = priorityRange;
this.File = Path.GetFullPath(element.GetAttributeString("file", ""));
this.Type = element.GetAttributeString("type", "").ToLowerInvariant();
this.IntensityRange = element.GetAttributeVector2("intensityrange", new Vector2(0.0f, 100.0f));
}
}
@@ -52,20 +51,21 @@ namespace Barotrauma
private static ILookup<string, Sound> miscSounds;
//music
public static float MusicVolume = 1.0f;
private const float MusicLerpSpeed = 1.0f;
private const float UpdateMusicInterval = 5.0f;
private static BackgroundMusic currentMusic;
private static BackgroundMusic targetMusic;
const int MaxMusicChannels = 6;
private readonly static Sound[] currentMusic = new Sound[MaxMusicChannels];
private readonly static SoundChannel[] musicChannel = new SoundChannel[MaxMusicChannels];
private readonly static BackgroundMusic[] targetMusic = new BackgroundMusic[MaxMusicChannels];
private static List<BackgroundMusic> musicClips;
private static float currMusicVolume;
private static float updateMusicTimer;
//ambience
private static List<Sound> waterAmbiences = new List<Sound>();
private static int[] waterAmbienceIndexes = new int[2];
private static SoundChannel[] waterAmbienceChannels = new SoundChannel[2];
private static float ambientSoundTimer;
private static Vector2 ambientSoundInterval = new Vector2(20.0f, 40.0f); //x = min, y = max
@@ -73,6 +73,19 @@ namespace Barotrauma
//misc
public static List<Sound> FlowSounds = new List<Sound>();
public static List<Sound> SplashSounds = new List<Sound>();
private static SoundChannel[] flowSoundChannels;
private static float[] flowVolumeLeft;
private static float[] flowVolumeRight;
const float FlowSoundRange = 1500.0f;
const float MaxFlowStrength = 400.0f; //the heaviest water sound effect is played when the water flow is this strong
private static SoundChannel[] fireSoundChannels;
private static float[] fireVolumeLeft;
private static float[] fireVolumeRight;
const float FireSoundRange = 1000.0f;
const float FireSoundLargeLimit = 200.0f; //switch to large fire sound when the size of a firesource is above this
private static List<DamageSound> damageSounds;
@@ -94,7 +107,7 @@ namespace Barotrauma
{
OverrideMusicType = null;
List<string> soundFiles = GameMain.Config.SelectedContentPackage.GetFilesOfType(ContentType.Sounds);
var soundFiles = GameMain.Instance.GetFilesOfType(ContentType.Sounds);
List<XElement> soundElements = new List<XElement>();
foreach (string soundFile in soundFiles)
@@ -111,7 +124,7 @@ namespace Barotrauma
var startUpSoundElement = soundElements.Find(e => e.Name.ToString().ToLowerInvariant() == "startupsound");
if (startUpSoundElement != null)
{
startUpSound = Sound.Load(startUpSoundElement, false);
startUpSound = GameMain.SoundManager.LoadSound(startUpSoundElement, false);
startUpSound.Play();
}
@@ -125,48 +138,59 @@ namespace Barotrauma
{
yield return CoroutineStatus.Running;
switch (soundElement.Name.ToString().ToLowerInvariant())
try
{
case "music":
string file = soundElement.GetAttributeString("file", "");
string type = soundElement.GetAttributeString("type", "").ToLowerInvariant();
Vector2 priority = soundElement.GetAttributeVector2("priorityrange", new Vector2(0.0f, 100.0f));
musicClips.Add(new BackgroundMusic(file, type, priority));
break;
case "splash":
SplashSounds.Add(Sound.Load(soundElement, false));
break;
case "flow":
FlowSounds.Add(Sound.Load(soundElement, false));
break;
case "waterambience":
waterAmbiences.Add(Sound.Load(soundElement, false));
break;
case "damagesound":
Sound damageSound = Sound.Load(soundElement.GetAttributeString("file", ""), false);
if (damageSound == null) continue;
switch (soundElement.Name.ToString().ToLowerInvariant())
{
case "music":
musicClips.Add(new BackgroundMusic(soundElement));
break;
case "splash":
SplashSounds.Add(GameMain.SoundManager.LoadSound(soundElement, false));
break;
case "flow":
FlowSounds.Add(GameMain.SoundManager.LoadSound(soundElement, false));
break;
case "waterambience":
waterAmbiences.Add(GameMain.SoundManager.LoadSound(soundElement, false));
break;
case "damagesound":
Sound damageSound = GameMain.SoundManager.LoadSound(soundElement, false);
if (damageSound == null) continue;
string damageSoundType = soundElement.GetAttributeString("damagesoundtype", "None");
string damageSoundType = soundElement.GetAttributeString("damagesoundtype", "None");
damageSounds.Add(new DamageSound(
damageSound,
soundElement.GetAttributeVector2("damagerange", new Vector2(0.0f, 100.0f)),
damageSoundType,
soundElement.GetAttributeString("requiredtag", "")));
damageSounds.Add(new DamageSound(
damageSound,
soundElement.GetAttributeVector2("damagerange", new Vector2(0.0f, 100.0f)),
damageSoundType,
soundElement.GetAttributeString("requiredtag", "")));
break;
default:
Sound sound = Sound.Load(soundElement.GetAttributeString("file", ""), false);
if (sound != null)
{
miscSoundList.Add(new KeyValuePair<string, Sound>(soundElement.Name.ToString().ToLowerInvariant(), sound));
}
break;
default:
Sound sound = GameMain.SoundManager.LoadSound(soundElement, false);
if (sound != null)
{
miscSoundList.Add(new KeyValuePair<string, Sound>(soundElement.Name.ToString().ToLowerInvariant(), sound));
}
break;
break;
}
}
catch (FileNotFoundException e)
{
DebugConsole.ThrowError("Error while initializing SoundPlayer.", e);
}
}
flowSoundChannels = new SoundChannel[FlowSounds.Count];
flowVolumeLeft = new float[FlowSounds.Count];
flowVolumeRight = new float[FlowSounds.Count];
fireSoundChannels = new SoundChannel[2];
fireVolumeLeft = new float[2];
fireVolumeRight = new float[2];
miscSounds = miscSoundList.ToLookup(kvp => kvp.Key, kvp => kvp.Value);
Initialized = true;
@@ -180,27 +204,31 @@ namespace Barotrauma
{
UpdateMusic(deltaTime);
if (startUpSound != null && !startUpSound.IsPlaying)
if (startUpSound != null && !GameMain.SoundManager.IsPlaying(startUpSound))
{
startUpSound.Remove();
startUpSound.Dispose();
startUpSound = null;
}
//stop submarine ambient sounds if no sub is loaded
if (Submarine.MainSub == null)
//stop water sounds if no sub is loaded
if (Submarine.MainSub == null || Screen.Selected != GameMain.GameScreen)
{
for (int i = 0; i < waterAmbienceIndexes.Length; i++)
for (int i = 0; i < waterAmbienceChannels.Length; i++)
{
if (waterAmbienceIndexes[i] <= 0) continue;
SoundManager.Stop(waterAmbienceIndexes[i]);
waterAmbienceIndexes[i] = 0;
}
if (waterAmbienceChannels[i] == null) continue;
waterAmbienceChannels[i].Dispose();
waterAmbienceChannels[i] = null;
}
for (int i = 0; i < FlowSounds.Count; i++)
{
if (flowSoundChannels[i] == null) continue;
flowSoundChannels[i].Dispose();
flowSoundChannels[i] = null;
}
return;
}
float ambienceVolume = 0.8f;
float lowpassHFGain = 1.0f;
if (Character.Controlled != null)
{
AnimController animController = Character.Controlled.AnimController;
@@ -208,13 +236,17 @@ namespace Barotrauma
{
ambienceVolume = 1.0f;
ambienceVolume += animController.Limbs[0].LinearVelocity.Length();
lowpassHFGain = 0.2f;
}
lowpassHFGain *= Character.Controlled.LowPassMultiplier;
}
UpdateWaterAmbience(ambienceVolume);
UpdateWaterFlowSounds(deltaTime);
UpdateRandomAmbience(deltaTime);
UpdateFireSounds(deltaTime);
}
private static void UpdateWaterAmbience(float ambienceVolume)
{
//how fast the sub is moving, scaled to 0.0 -> 1.0
float movementSoundVolume = 0.0f;
@@ -223,7 +255,7 @@ namespace Barotrauma
float movementFactor = (sub.Velocity == Vector2.Zero) ? 0.0f : sub.Velocity.Length() / 10.0f;
movementFactor = MathHelper.Clamp(movementFactor, 0.0f, 1.0f);
if (Character.Controlled==null || Character.Controlled.Submarine != sub)
if (Character.Controlled == null || Character.Controlled.Submarine != sub)
{
float dist = Vector2.Distance(GameMain.GameScreen.Cam.WorldViewCenter, sub.WorldPosition);
movementFactor = movementFactor / Math.Max(dist / 1000.0f, 1.0f);
@@ -232,9 +264,172 @@ namespace Barotrauma
movementSoundVolume = Math.Max(movementSoundVolume, movementFactor);
}
if (waterAmbiences.Count > 1)
{
if (waterAmbienceChannels[0] == null || !waterAmbienceChannels[0].IsPlaying)
{
waterAmbienceChannels[0] = waterAmbiences[0].Play(ambienceVolume * (1.0f - movementSoundVolume),"waterambience");
//waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f - movementSoundVolume));
waterAmbienceChannels[0].Looping = true;
}
else
{
waterAmbienceChannels[0].Gain = ambienceVolume * (1.0f - movementSoundVolume);
}
if (waterAmbienceChannels[1] == null || !waterAmbienceChannels[1].IsPlaying)
{
waterAmbienceChannels[1] = waterAmbiences[1].Play(ambienceVolume * movementSoundVolume, "waterambience");
//waterAmbienceIndexes[1] = waterAmbiences[1].Loop(waterAmbienceIndexes[1], ambienceVolume * movementSoundVolume);
waterAmbienceChannels[1].Looping = true;
}
else
{
waterAmbienceChannels[1].Gain = ambienceVolume * movementSoundVolume;
}
}
}
private static void UpdateWaterFlowSounds(float deltaTime)
{
if (FlowSounds.Count == 0) { return; }
float[] targetFlowLeft = new float[FlowSounds.Count];
float[] targetFlowRight = new float[FlowSounds.Count];
Vector2 listenerPos = new Vector2(GameMain.SoundManager.ListenerPosition.X, GameMain.SoundManager.ListenerPosition.Y);
foreach (Gap gap in Gap.GapList)
{
if (gap.Open < 0.01f) continue;
float gapFlow = Math.Abs(gap.LerpedFlowForce.X) + Math.Abs(gap.LerpedFlowForce.Y) * 2.5f;
if (gapFlow < 10.0f) continue;
int flowSoundIndex = (int)Math.Floor(MathHelper.Clamp(gapFlow / MaxFlowStrength, 0, FlowSounds.Count));
flowSoundIndex = Math.Min(flowSoundIndex, FlowSounds.Count - 1);
Vector2 diff = gap.WorldPosition - listenerPos;
if (Math.Abs(diff.X) < FlowSoundRange && Math.Abs(diff.Y) < FlowSoundRange)
{
float dist = diff.Length();
float distFallOff = dist / FlowSoundRange;
if (distFallOff >= 0.99f) continue;
//flow at the left side
if (diff.X < 0)
{
targetFlowLeft[flowSoundIndex] = 1.0f - distFallOff;
}
else
{
targetFlowRight[flowSoundIndex] = 1.0f - distFallOff;
}
}
}
for (int i = 0; i < FlowSounds.Count; i++)
{
flowVolumeLeft[i] = (targetFlowLeft[i] < flowVolumeLeft[i]) ?
Math.Max(targetFlowLeft[i], flowVolumeLeft[i] - deltaTime) :
Math.Min(targetFlowLeft[i], flowVolumeLeft[i] + deltaTime);
flowVolumeRight[i] = (targetFlowRight[i] < flowVolumeRight[i]) ?
Math.Max(targetFlowRight[i], flowVolumeRight[i] - deltaTime) :
Math.Min(targetFlowRight[i], flowVolumeRight[i] + deltaTime);
if (flowVolumeLeft[i] < 0.05f && flowVolumeRight[i] < 0.05f)
{
if (flowSoundChannels[i] != null)
{
flowSoundChannels[i].Dispose();
flowSoundChannels[i] = null;
}
}
else
{
Vector2 soundPos = new Vector2(GameMain.SoundManager.ListenerPosition.X + (flowVolumeRight[i] - flowVolumeLeft[i]) * 100, GameMain.SoundManager.ListenerPosition.Y);
if (flowSoundChannels[i] == null || !flowSoundChannels[i].IsPlaying)
{
flowSoundChannels[i] = FlowSounds[i].Play(1.0f, FlowSoundRange, soundPos);
flowSoundChannels[i].Looping = true;
}
flowSoundChannels[i].Gain = Math.Max(flowVolumeRight[i], flowVolumeLeft[i]);
flowSoundChannels[i].Position = new Vector3(soundPos, 0.0f);
}
}
}
private static void UpdateFireSounds(float deltaTime)
{
for (int i = 0; i < fireVolumeLeft.Length; i++)
{
fireVolumeLeft[i] = 0.0f;
fireVolumeRight[i] = 0.0f;
}
Vector2 listenerPos = new Vector2(GameMain.SoundManager.ListenerPosition.X, GameMain.SoundManager.ListenerPosition.Y);
foreach (Hull hull in Hull.hullList)
{
foreach (FireSource fs in hull.FireSources)
{
Vector2 diff = fs.WorldPosition + fs.Size / 2 - listenerPos;
if (Math.Abs(diff.X) < FireSoundRange && Math.Abs(diff.Y) < FireSoundRange)
{
Vector2 diffLeft = (fs.WorldPosition + new Vector2(fs.Size.X, fs.Size.Y / 2)) - listenerPos;
if (diff.X < fs.Size.X / 2.0f) diff.X = 0.0f;
if (diffLeft.X <= 0)
{
float distFallOffLeft = diffLeft.Length() / FireSoundRange;
if (distFallOffLeft < 0.99f)
{
fireVolumeLeft[0] += (1.0f - distFallOffLeft) * (fs.Size.X / FireSoundLargeLimit);
if (fs.Size.X > FireSoundLargeLimit) fireVolumeLeft[1] += (1.0f - distFallOffLeft) * ((fs.Size.X - FireSoundLargeLimit) / FireSoundLargeLimit);
}
}
Vector2 diffRight = (fs.WorldPosition + new Vector2(0.0f, fs.Size.Y / 2)) - listenerPos;
if (diff.X < fs.Size.X / 2.0f) diff.X = 0.0f;
if (diffRight.X >= 0)
{
float distFallOffRight = diffRight.Length() / FireSoundRange;
if (distFallOffRight < 0.99f)
{
fireVolumeRight[0] += 1.0f - distFallOffRight;
if (fs.Size.X > FireSoundLargeLimit) fireVolumeRight[1] += (1.0f - distFallOffRight) * ((fs.Size.X - FireSoundLargeLimit) / FireSoundLargeLimit);
}
}
}
}
}
for (int i = 0; i < fireVolumeLeft.Length; i++)
{
if (fireVolumeLeft[i] < 0.05f && fireVolumeRight[i] < 0.05f)
{
if (fireSoundChannels[i] != null)
{
fireSoundChannels[i].Dispose();
fireSoundChannels[i] = null;
}
}
else
{
Vector2 soundPos = new Vector2(GameMain.SoundManager.ListenerPosition.X + (fireVolumeRight[i] - fireVolumeLeft[i]) * 100, GameMain.SoundManager.ListenerPosition.Y);
if (fireSoundChannels[i] == null || !fireSoundChannels[i].IsPlaying)
{
fireSoundChannels[i] = GetSound(i == 0 ? "fire" : "firelarge").Play(1.0f, FlowSoundRange, soundPos);
fireSoundChannels[i].Looping = true;
}
fireSoundChannels[i].Gain = Math.Max(fireVolumeRight[i], fireVolumeLeft[i]);
fireSoundChannels[i].Position = new Vector3(soundPos, 0.0f);
}
}
}
private static void UpdateRandomAmbience(float deltaTime)
{
if (ambientSoundTimer > 0.0f)
{
ambientSoundTimer -= (float)Timing.Step;
ambientSoundTimer -= deltaTime;
}
else
{
@@ -242,18 +437,10 @@ namespace Barotrauma
"ambient",
Rand.Range(0.5f, 1.0f),
1000.0f,
new Vector2(Sound.CameraPos.X, Sound.CameraPos.Y) + Rand.Vector(100.0f));
new Vector2(GameMain.SoundManager.ListenerPosition.X, GameMain.SoundManager.ListenerPosition.Y) + Rand.Vector(100.0f));
ambientSoundTimer = Rand.Range(ambientSoundInterval.X, ambientSoundInterval.Y);
}
SoundManager.LowPassHFGain = lowpassHFGain;
if (waterAmbiences.Count > 1)
{
waterAmbienceIndexes[0] = waterAmbiences[0].Loop(waterAmbienceIndexes[0], ambienceVolume * (1.0f - movementSoundVolume));
waterAmbienceIndexes[1] = waterAmbiences[1].Loop(waterAmbienceIndexes[1], ambienceVolume * movementSoundVolume);
}
}
public static Sound GetSound(string soundTag)
@@ -264,16 +451,23 @@ namespace Barotrauma
return matchingSounds[Rand.Int(matchingSounds.Count)];
}
public static void PlaySound(string soundTag, float volume = 1.0f)
public static SoundChannel PlaySound(string soundTag, float volume = 1.0f)
{
var sound = GetSound(soundTag);
if (sound != null) sound.Play(volume);
return sound?.Play(volume);
}
public static void PlaySound(string soundTag, float volume, float range, Vector2 position)
public static SoundChannel PlaySound(string soundTag, float volume, float range, Vector2 position, Hull hullGuess = null)
{
var sound = GetSound(soundTag);
if (sound != null) sound.Play(volume, range, position);
if (sound == null) return null;
return PlaySound(sound, sound.BaseGain * volume, range, position, hullGuess);
}
public static SoundChannel PlaySound(Sound sound, float volume, float range, Vector2 position, Hull hullGuess = null)
{
if (Vector2.DistanceSquared(new Vector2(GameMain.SoundManager.ListenerPosition.X, GameMain.SoundManager.ListenerPosition.Y), position) > range * range) return null;
return sound.Play(sound.BaseGain * volume, range, position, muffle: ShouldMuffleSound(Character.Controlled, position, range, hullGuess));
}
private static void UpdateMusic(float deltaTime)
@@ -293,66 +487,110 @@ namespace Barotrauma
updateMusicTimer -= deltaTime;
if (updateMusicTimer <= 0.0f)
{
List<BackgroundMusic> suitableMusic = GetSuitableMusicClips();
//find appropriate music for the current situation
string currentMusicType = GetCurrentMusicType();
float currentIntensity = GameMain.GameSession?.EventManager != null ?
GameMain.GameSession.EventManager.CurrentIntensity * 100.0f : 0.0f;
if (suitableMusic.Count == 0)
{
targetMusic = null;
}
else if (!suitableMusic.Contains(currentMusic))
{
int index = Rand.Int(suitableMusic.Count);
IEnumerable<BackgroundMusic> suitableMusic = GetSuitableMusicClips(currentMusicType, currentIntensity);
if (currentMusic == null || suitableMusic[index].file != currentMusic.file)
if (suitableMusic.Count() == 0)
{
targetMusic[0] = null;
}
//switch the music if nothing playing atm or the currently playing clip is not suitable anymore
else if (targetMusic[0] == null || currentMusic[0] == null || !suitableMusic.Any(m => m.File == currentMusic[0].Filename))
{
targetMusic[0] = suitableMusic.GetRandom();
}
//get the appropriate intensity layers for current situation
IEnumerable<BackgroundMusic> suitableIntensityMusic = GetSuitableMusicClips("intensity", currentIntensity);
for (int i = 1; i < MaxMusicChannels; i++)
{
//disable targetmusics that aren't suitable anymore
if (targetMusic[i] != null && !suitableIntensityMusic.Any(m => m.File == targetMusic[i].File))
{
targetMusic = suitableMusic[index];
targetMusic[i] = null;
}
}
foreach (BackgroundMusic intensityMusic in suitableIntensityMusic)
{
//already playing, do nothing
if (targetMusic.Any(m => m != null && m.File == intensityMusic.File)) continue;
for (int i = 1; i < MaxMusicChannels; i++)
{
if (targetMusic[i] == null)
{
targetMusic[i] = intensityMusic;
break;
}
}
}
updateMusicTimer = UpdateMusicInterval;
}
if (targetMusic == null || currentMusic == null || targetMusic.file != currentMusic.file)
for (int i = 0; i < MaxMusicChannels; i++)
{
currMusicVolume = MathHelper.Lerp(currMusicVolume, 0.0f, MusicLerpSpeed * deltaTime);
if (currentMusic != null) Sound.StreamVolume(currMusicVolume);
if (currMusicVolume < 0.01f)
//nothing should be playing on this channel
if (targetMusic[i] == null)
{
Sound.StopStream();
try
if (musicChannel[i] != null && musicChannel[i].IsPlaying)
{
if (targetMusic != null) Sound.StartStream(targetMusic.file, currMusicVolume);
//mute the channel
musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, 0.0f, MusicLerpSpeed * deltaTime);
if (musicChannel[i].Gain < 0.01f) DisposeMusicChannel(i);
}
catch (FileNotFoundException e)
{
DebugConsole.ThrowError("Music clip " + targetMusic.file + " not found!", e);
}
currentMusic = targetMusic;
}
}
else
{
currMusicVolume = MathHelper.Lerp(currMusicVolume, MusicVolume, MusicLerpSpeed * deltaTime);
Sound.StreamVolume(currMusicVolume);
}
//something should be playing, but the channel is playing nothing or an incorrect clip
else if (currentMusic[i] == null || targetMusic[i].File != currentMusic[i].Filename)
{
//something playing -> mute it first
if (musicChannel[i] != null && musicChannel[i].IsPlaying)
{
musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, 0.0f, MusicLerpSpeed * deltaTime);
if (musicChannel[i].Gain < 0.01f) DisposeMusicChannel(i);
}
//channel free now, start playing the correct clip
if (currentMusic[i] == null || (musicChannel[i] == null || !musicChannel[i].IsPlaying))
{
DisposeMusicChannel(i);
currentMusic[i] = GameMain.SoundManager.LoadSound(targetMusic[i].File, true);
musicChannel[i] = currentMusic[i].Play(0.0f, "music");
musicChannel[i].Looping = true;
}
}
else
{
//playing something, lerp volume up
if (musicChannel[i] == null || !musicChannel[i].IsPlaying)
{
musicChannel[i]?.Dispose();
musicChannel[i] = currentMusic[i].Play(0.0f, "music");
musicChannel[i].Looping = true;
}
musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, 1.0f, MusicLerpSpeed * deltaTime);
}
}
}
public static void SwitchMusic()
private static void DisposeMusicChannel(int index)
{
var suitableMusic = GetSuitableMusicClips();
if (suitableMusic.Count > 1)
{
targetMusic = suitableMusic.Find(m => m != currentMusic);
}
musicChannel[index]?.Dispose(); musicChannel[index] = null;
currentMusic[index]?.Dispose(); currentMusic[index] = null;
}
private static List<BackgroundMusic> GetSuitableMusicClips()
private static IEnumerable<BackgroundMusic> GetSuitableMusicClips(string musicType, float currentIntensity)
{
string musicType = GetCurrentMusicType();
return musicClips.Where(music => music != null && music.type == musicType).ToList();
return musicClips.Where(music =>
music != null &&
music.Type == musicType &&
currentIntensity >= music.IntensityRange.X &&
currentIntensity <= music.IntensityRange.Y);
}
private static string GetCurrentMusicType()
@@ -375,20 +613,7 @@ namespace Barotrauma
}
if (targetSubmarine != null)
{
List<Reactor> reactors = new List<Reactor>();
foreach (Item item in Item.ItemList)
{
if (item.Submarine != targetSubmarine) continue;
var reactor = item.GetComponent<Reactor>();
if (reactor != null)
{
reactors.Add(reactor);
}
}
if (reactors.All(r => r.Temperature < 1.0f)) return "repair";
{
float floodedArea = 0.0f;
float totalArea = 0.0f;
foreach (Hull hull in Hull.hullList)
@@ -398,10 +623,9 @@ namespace Barotrauma
totalArea += hull.Volume;
}
if (totalArea > 0.0f && floodedArea / totalArea > 0.25f) return "repair";
if (totalArea > 0.0f && floodedArea / totalArea > 0.25f) return "flooded";
}
float enemyDistThreshold = 5000.0f;
if (targetSubmarine != null)
@@ -411,8 +635,9 @@ namespace Barotrauma
foreach (Character character in Character.CharacterList)
{
if (character.IsDead || !character.Enabled) continue;
EnemyAIController enemyAI = character.AIController as EnemyAIController;
if (enemyAI == null || (enemyAI.AttackHumans < 0.0f && enemyAI.AttackRooms < 0.0f)) continue;
if (enemyAI == null || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue;
if (targetSubmarine != null)
{
@@ -430,39 +655,64 @@ namespace Barotrauma
}
}
if (GameMain.GameSession != null && Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0)
{
return "start";
}
return "default";
}
public static bool ShouldMuffleSound(Character listener, Vector2 soundWorldPos, float range, Hull hullGuess)
{
if (listener == null) return false;
float lowpassHFGain = 1.0f;
AnimController animController = listener.AnimController;
if (animController.HeadInWater)
{
lowpassHFGain = 0.2f;
}
lowpassHFGain *= Character.Controlled.LowPassMultiplier;
if (lowpassHFGain < 0.5f) return true;
Hull targetHull = Hull.FindHull(soundWorldPos, hullGuess, true);
if (listener.CurrentHull == null || targetHull == null)
{
return listener.CurrentHull != targetHull;
}
return listener.CurrentHull.GetApproximateDistance(targetHull, range) > range;
}
public static void PlaySplashSound(Vector2 worldPosition, float strength)
{
if (SplashSounds.Count == 0) { return; }
int splashIndex = MathHelper.Clamp((int)(strength + Rand.Range(-2, 2)), 0, SplashSounds.Count - 1);
SplashSounds[splashIndex].Play(1.0f, 800.0f, worldPosition);
float range = 800.0f;
var channel = SplashSounds[splashIndex].Play(1.0f, range, worldPosition, muffle: ShouldMuffleSound(Character.Controlled, worldPosition, range, null));
}
public static void PlayDamageSound(string damageType, float damage, PhysicsBody body)
{
Vector2 bodyPosition = body.DrawPosition;
PlayDamageSound(damageType, damage, bodyPosition, 800.0f);
}
public static void PlayDamageSound(string damageType, float damage, Vector2 position, float range = 2000.0f, List<string> tags = null)
public static void PlayDamageSound(string damageType, float damage, Vector2 position, float range = 2000.0f, IEnumerable<string> tags = null)
{
damage = MathHelper.Clamp(damage+Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f);
var sounds = damageSounds.FindAll(s =>
damage = MathHelper.Clamp(damage + Rand.Range(-10.0f, 10.0f), 0.0f, 100.0f);
var sounds = damageSounds.FindAll(s =>
s.damageRange == null ||
(damage >= s.damageRange.X &&
damage <= s.damageRange.Y) &&
(damage >= s.damageRange.X &&
damage <= s.damageRange.Y) &&
s.damageType == damageType &&
(tags == null ? string.IsNullOrEmpty(s.requiredTag) : tags.Contains(s.requiredTag)));
if (!sounds.Any()) return;
int selectedSound = Rand.Int(sounds.Count);
sounds[selectedSound].sound.Play(1.0f, range, position);
Debug.WriteLine("playing: " + sounds[selectedSound].sound);
sounds[selectedSound].sound.Play(1.0f, range, position, muffle: ShouldMuffleSound(Character.Controlled, position, range, null));
}
}