hedgewars/uSound.pas
changeset 12920 4d3b52f1ba18
parent 12673 308846e05154
child 13044 aed4b25ff242
--- a/hedgewars/uSound.pas	Wed Feb 07 05:36:32 2018 +0100
+++ b/hedgewars/uSound.pas	Wed Feb 07 07:38:37 2018 +0100
@@ -106,6 +106,8 @@
 
 var MusicFN: shortstring; // music file name
     SDMusicFN: shortstring; // SD music file name
+    FallbackMusicFN: shortstring; // fallback music file name
+    FallbackSDMusicFN: shortstring; // fallback SD music fille name
 
 var Volume: LongInt;
     SoundTimerTicks: Longword;
@@ -632,9 +634,35 @@
     else s:= '/Music/' + MusicFN;
     WriteToConsole(msgLoading + s + ' ');
 
+    // Load normal music
     Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
     SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
-    WriteLnToConsole(msgOK);
+    if Mus <> nil then
+        WriteLnToConsole(msgOK);
+
+    // If normal music failed, try to get fallback music
+    if Mus = nil then
+       begin
+       WriteLnToConsole('Music not found. Trying fallback music.');
+       if SuddenDeath and (FallbackSDMusicFN <> '') then
+           s:= '/Music/' + FallbackSDMusicFN
+       else if (not SuddenDeath) and (FallbackMusicFN <> '') then
+           s:= '/Music/' + FallbackMusicFN
+       else
+           begin
+           WriteLnToConsole('No fallback music configured!');
+           s:= ''
+           end;
+
+       if (s <> '') then
+           begin
+           WriteLnToConsole(msgLoading + s + ' ');
+           Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
+           SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
+           if Mus <> nil then
+               WriteLnToConsole(msgOK)
+           end;
+       end;
 
     SDLCheck(Mix_FadeInMusic(Mus, -1, 3000) <> -1, 'Mix_FadeInMusic', false)
 end;