(f314ad2a3) New music track when the end of the level is reached, decrease the volume of the background music layer 0 when there's multiple tracks playing at the same time

This commit is contained in:
Joonas Rikkonen
2019-04-23 11:22:04 +03:00
parent aa0466ad5b
commit b1038628e7

View File

@@ -35,6 +35,7 @@ namespace Barotrauma
{
public readonly string File;
public readonly string Type;
public readonly bool DuckVolume;
public readonly Vector2 IntensityRange;
@@ -43,6 +44,7 @@ namespace Barotrauma
this.File = Path.GetFullPath(element.GetAttributeString("file", ""));
this.Type = element.GetAttributeString("type", "").ToLowerInvariant();
this.IntensityRange = element.GetAttributeVector2("intensityrange", new Vector2(0.0f, 100.0f));
this.DuckVolume = element.GetAttributeBool("duckvolume", false);
}
}
@@ -277,6 +279,7 @@ namespace Barotrauma
movementSoundVolume = 0.0f;
}
}
}
if (waterAmbiences.Count > 1)
{
@@ -515,7 +518,7 @@ namespace Barotrauma
//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();
targetMusic[0] = suitableMusic.GetRandom();
}
//get the appropriate intensity layers for current situation
@@ -550,6 +553,7 @@ namespace Barotrauma
updateMusicTimer = UpdateMusicInterval;
}
int activeTrackCount = targetMusic.Count(m => m != null);
for (int i = 0; i < MaxMusicChannels; i++)
{
//nothing should be playing on this channel
@@ -589,7 +593,12 @@ namespace Barotrauma
musicChannel[i] = currentMusic[i].Play(0.0f, "music");
musicChannel[i].Looping = true;
}
musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, 1.0f, MusicLerpSpeed * deltaTime);
float targetGain = 1.0f;
if (targetMusic[i].DuckVolume)
{
targetGain = (float)Math.Sqrt(1.0f / activeTrackCount);
}
musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, targetGain, MusicLerpSpeed * deltaTime);
}
}
}
@@ -657,8 +666,7 @@ 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 && !enemyAI.AttackRooms)) continue;
if (!(character.AIController is EnemyAIController enemyAI) || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue;
if (targetSubmarine != null)
{
@@ -676,9 +684,16 @@ namespace Barotrauma
}
}
if (GameMain.GameSession != null && Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0)
if (GameMain.GameSession != null)
{
return "start";
if (Submarine.Loaded != null && Level.Loaded != null && Submarine.MainSub.AtEndPosition)
{
return "levelend";
}
if (Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0)
{
return "start";
}
}
return "default";