(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
@@ -35,6 +35,7 @@ namespace Barotrauma
{ {
public readonly string File; public readonly string File;
public readonly string Type; public readonly string Type;
public readonly bool DuckVolume;
public readonly Vector2 IntensityRange; public readonly Vector2 IntensityRange;
@@ -43,6 +44,7 @@ namespace Barotrauma
this.File = Path.GetFullPath(element.GetAttributeString("file", "")); this.File = Path.GetFullPath(element.GetAttributeString("file", ""));
this.Type = element.GetAttributeString("type", "").ToLowerInvariant(); this.Type = element.GetAttributeString("type", "").ToLowerInvariant();
this.IntensityRange = element.GetAttributeVector2("intensityrange", new Vector2(0.0f, 100.0f)); 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; movementSoundVolume = 0.0f;
} }
} }
}
if (waterAmbiences.Count > 1) if (waterAmbiences.Count > 1)
{ {
@@ -550,6 +553,7 @@ namespace Barotrauma
updateMusicTimer = UpdateMusicInterval; updateMusicTimer = UpdateMusicInterval;
} }
int activeTrackCount = targetMusic.Count(m => m != null);
for (int i = 0; i < MaxMusicChannels; i++) for (int i = 0; i < MaxMusicChannels; i++)
{ {
//nothing should be playing on this channel //nothing should be playing on this channel
@@ -589,7 +593,12 @@ namespace Barotrauma
musicChannel[i] = currentMusic[i].Play(0.0f, "music"); musicChannel[i] = currentMusic[i].Play(0.0f, "music");
musicChannel[i].Looping = true; 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) foreach (Character character in Character.CharacterList)
{ {
if (character.IsDead || !character.Enabled) continue; if (character.IsDead || !character.Enabled) continue;
EnemyAIController enemyAI = character.AIController as EnemyAIController; if (!(character.AIController is EnemyAIController enemyAI) || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue;
if (enemyAI == null || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue;
if (targetSubmarine != null) 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"; return "default";