diff --git a/src/modes/overworld.cpp b/src/modes/overworld.cpp index a8c7bd0b3..1f060ecbf 100644 --- a/src/modes/overworld.cpp +++ b/src/modes/overworld.cpp @@ -124,10 +124,11 @@ void OverWorld::update(int ticks) setPhase(RACE_PHASE); // Normally done in WorldStatus::update(), during phase SET_PHASE, // so we have to start music 'manually', since we skip all phases. + MusicInformation* mi = Track::getCurrentTrack()->getTrackMusic(); Track::getCurrentTrack()->startMusic(); if (UserConfigParams::m_music) - music_manager->startMusic(); + music_manager->startMusic(mi); m_karts[0]->startEngineSFX(); } World::update(ticks); diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index fd4afac65..d22814fee 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -176,6 +176,7 @@ Track::Track(const std::string &filename) m_minimap_y_scale = 1.0f; m_force_disable_fog = false; m_startup_run = false; + m_music_idx = 0; m_red_flag = m_blue_flag = btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f)); m_default_number_of_laps = 3; @@ -709,6 +710,8 @@ void Track::getMusicInformation(std::vector& filenames, "Music information for track '%s' replaced by default music.\n", m_name.c_str()); } + if (!m_music.empty()) + m_music_idx = rand() % m_music.size(); } // getMusicInformation @@ -719,7 +722,7 @@ void Track::startMusic() const { // In case that the music wasn't found (a warning was already printed) if(m_music.size()>0) - music_manager->startMusic(m_music[rand()% m_music.size()], false); + music_manager->startMusic(m_music[m_music_idx], false); else music_manager->clearCurrentMusic(); } // startMusic diff --git a/src/tracks/track.hpp b/src/tracks/track.hpp index 8b3767529..c64b339c2 100644 --- a/src/tracks/track.hpp +++ b/src/tracks/track.hpp @@ -118,6 +118,7 @@ private: std::string m_screenshot; bool m_is_day; std::vector m_music; + unsigned m_music_idx; /** Will only be used on overworld */ std::vector m_challenges; @@ -732,6 +733,13 @@ public: // ------------------------------------------------------------------------ bool isOnGround(const Vec3& xyz, const Vec3& down, Vec3* hit_point, Vec3* normal, bool print_warning = true); + // ------------------------------------------------------------------------ + MusicInformation* getTrackMusic() const + { + if (m_music_idx < m_music.size()) + return m_music[m_music_idx]; + return NULL; + } }; // class Track #endif