fallback to Default voicepack if specified voicepack is not available
authorsheepluva
Wed, 24 Jun 2015 01:23:37 +0200
changeset 10995 7faaef306837
parent 10994 cd7f918eed30
child 10996 78e49c835d96
fallback to Default voicepack if specified voicepack is not available
hedgewars/uSound.pas
--- a/hedgewars/uSound.pas	Tue Jun 16 10:08:07 2015 -0400
+++ b/hedgewars/uSound.pas	Wed Jun 24 01:23:37 2015 +0200
@@ -70,7 +70,7 @@
 // Returns sound channel of the looped sound.
 function  LoopSound(snd: TSound): LongInt;
 function  LoopSound(snd: TSound; fadems: LongInt): LongInt;
-function  LoopSoundV(snd: TSound; voicepack: PVoicepack): LongInt; // WTF?
+function  LoopSoundV(snd: TSound; voicepack: PVoicepack): LongInt;
 function  LoopSoundV(snd: TSound; voicepack: PVoicepack; fadems: LongInt): LongInt;
 
 // Stops the normal/looped sound of the given type/in the given channel
@@ -261,8 +261,9 @@
 var i: Longword;
     locName, path: shortstring;
 begin
-i:= 0;
-    // First, attempt to locate a localised version of the voice
+    i:= 0;
+
+    // Adjust voicepack name if there's a localised version version of the voice
     if cLocale <> 'en' then
         begin
         locName:= name+'_'+cLocale;
@@ -279,7 +280,16 @@
                 end
         end;
 
-    // If that fails, use the unmodified one
+    path:= cPathz[ptVoices] + '/' + name;
+
+    // Fallback to Default if voicepack can't be found at all
+    if (name <> 'Default') and (not pfsExists(path)) then
+        begin
+        path:= cPathz[ptVoices] + '/Default';
+        if pfsExists(path) then
+            exit(AskForVoicepack('Default'));
+        end;
+
     while (voicepacks[i].name <> name) and (voicepacks[i].name <> '') do
         begin
         inc(i);