diff --git a/simulation_parameters/Constants.cs b/simulation_parameters/Constants.cs index c6fa595fb9..438bb9de91 100644 --- a/simulation_parameters/Constants.cs +++ b/simulation_parameters/Constants.cs @@ -264,6 +264,8 @@ public static class Constants public const float BASE_CELL_DENSITY = 1000; + public const float CONTEXTUAL_ONLY_MUSIC_CHANCE = 0.33f; + public const float MICROBE_MOVEMENT_SOUND_EMIT_COOLDOWN = 1.3f; // Note that the rotation speed is reversed, i.e. lower values mean faster diff --git a/src/general/Jukebox.cs b/src/general/Jukebox.cs index 5e841b22f9..37c97b519a 100644 --- a/src/general/Jukebox.cs +++ b/src/general/Jukebox.cs @@ -551,7 +551,25 @@ private void StartPlayingFromMissingLists(MusicCategory target) private void PlayNextTrackFromList(TrackList list, Func getPlayer, int playerToUse) { var mode = list.TrackOrder; - var tracks = list.GetTracksForContexts(activeContexts).ToArray(); + TrackList.Track[]? tracks = null; + + var random = new XoShiRo128starstar(); + + if (random.NextFloat() <= Constants.CONTEXTUAL_ONLY_MUSIC_CHANCE) + { + var contextMusicOnly = list.GetTracksForContexts(activeContexts).Where(c => c.ExclusiveToContexts != null) + .ToArray(); + + if (contextMusicOnly.Length > 0) + { + tracks = contextMusicOnly; + + // TODO: it would be nice to ensure that contextual track doesn't cause the same track to play in a row + // Currently it is way more likely as most contexts only have one track for them. + } + } + + tracks ??= list.GetTracksForContexts(activeContexts).ToArray(); if (tracks.Length == 0) return; @@ -564,7 +582,6 @@ private void PlayNextTrackFromList(TrackList list, Func getPla } else { - var random = new XoShiRo128starstar(); int nextIndex; if (mode == TrackList.Order.Random)