Refactor usage of sndRideOfTheValkyries, now can play if music is on and sound is off
authorWuzzy <Wuzzy2@mail.ru>
Fri, 26 Oct 2018 03:59:20 +0200
changeset 13980 350adfa0e896
parent 13979 4d0c80f7aa32
child 13981 2828ec67c47c
Refactor usage of sndRideOfTheValkyries, now can play if music is on and sound is off
ChangeLog.txt
hedgewars/uGearsHandlersMess.pas
hedgewars/uSound.pas
--- a/ChangeLog.txt	Thu Oct 25 23:46:31 2018 +0200
+++ b/ChangeLog.txt	Fri Oct 26 03:59:20 2018 +0200
@@ -31,6 +31,7 @@
  * Laser sight now works properly through wrap world edge
  * Fix projectiles behaving incorrectly with land just behind the wrap world edge
  * Fix bee weapon becoming unusable when hitting attack key in mid-air
+ * Fix hog sometimes getting stuck in land if roping very fast
  * Limit hedgehog health to 268435455 to prevent some bugs
 
 Game, controls and commands:
@@ -57,6 +58,7 @@
  * Prevent voices from being spoken directly before a victory voice
  * Fix damage not being displayed if hog drowns in water with 100% opacity (like in Compost theme)
  * Fix retreat timer appearing after using baseball bat or whip and immediately taking damage
+ * Fix Ride of the Valkyries not playing if music is enabled and sounds are disabled
 
 Frontend:
  + Add help button in main menu (link to Hedgewars Wiki)
--- a/hedgewars/uGearsHandlersMess.pas	Thu Oct 25 23:46:31 2018 +0200
+++ b/hedgewars/uGearsHandlersMess.pas	Fri Oct 26 03:59:20 2018 +0200
@@ -4174,8 +4174,7 @@
     if (HHGear <> nil) and ((HHGear^.Message and gmLJump) <> 0) and ((Gear^.State and gsttmpFlag) = 0) then
         begin
         Gear^.State := Gear^.State or gsttmpFlag;
-        PauseMusic;
-        playSound(sndRideOfTheValkyries);
+        PlayMusicSound(sndRideOfTheValkyries);
         inCinematicMode:= true;
         end;
 
@@ -4190,8 +4189,7 @@
         begin
         inCinematicMode:= false;
         StopSoundChan(Gear^.SoundChannel);
-        StopSound(sndRideOfTheValkyries);
-        ResumeMusic;
+        StopMusicSound(sndRideOfTheValkyries);
 
         if ((Gear^.State and gstCollision) <> 0) then
             begin
--- a/hedgewars/uSound.pas	Thu Oct 25 23:46:31 2018 +0200
+++ b/hedgewars/uSound.pas	Fri Oct 26 03:59:20 2018 +0200
@@ -65,9 +65,15 @@
 procedure PlaySound(snd: TSound);
 procedure PlaySound(snd: TSound; keepPlaying: boolean);
 procedure PlaySound(snd: TSound; keepPlaying: boolean; ignoreMask: boolean);
+procedure PlaySound(snd: TSound; keepPlaying, ignoreMask, soundAsMusic: boolean);
 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
-procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean; ignoreMask: boolean);
+procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying, ignoreMask: boolean);
+procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying, ignoreMask, soundAsMusic: boolean);
+
+// Plays/stops a sound to replace the main background music temporarily.
+procedure PlayMusicSound(snd: TSound);
+procedure StopMusicSound(snd: TSound);
 
 // Plays sound snd [of voicepack] in a loop, but starts with fadems milliseconds of fade-in.
 // Returns sound channel of the looped sound.
@@ -79,6 +85,7 @@
 // Stops the normal/looped sound of the given type/in the given channel
 // [with a fade-out effect for fadems milliseconds].
 procedure StopSound(snd: TSound);
+procedure StopSound(snd: TSound; soundAsMusic: boolean);
 procedure StopSoundChan(chn: LongInt);
 procedure StopSoundChan(chn, fadems: LongInt);
 
@@ -435,34 +442,44 @@
 
 procedure PlaySound(snd: TSound);
 begin
-    PlaySoundV(snd, nil, false, false);
+    PlaySoundV(snd, nil, false, false, false);
 end;
 
 procedure PlaySound(snd: TSound; keepPlaying: boolean);
 begin
-    PlaySoundV(snd, nil, keepPlaying, false);
+    PlaySoundV(snd, nil, keepPlaying, false, false);
 end;
 
 procedure PlaySound(snd: TSound; keepPlaying: boolean; ignoreMask: boolean);
 begin
-    PlaySoundV(snd, nil, keepPlaying, ignoreMask);
+    PlaySoundV(snd, nil, keepPlaying, ignoreMask, false);
+end;
+
+procedure PlaySound(snd: TSound; keepPlaying: boolean; ignoreMask, soundAsMusic: boolean);
+begin
+    PlaySoundV(snd, nil, keepPlaying, ignoreMask, soundAsMusic);
 end;
 
 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack);
 begin
-    PlaySoundV(snd, voicepack, false, false);
+    PlaySoundV(snd, voicepack, false, false, false);
 end;
 
 procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean);
 begin
-    PlaySoundV(snd, voicepack, keepPlaying, false);
+    PlaySoundV(snd, voicepack, keepPlaying, false, false);
 end;
 
-procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying: boolean; ignoreMask: boolean);
+procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying, ignoreMask: boolean);
+begin
+    PlaySoundV(snd, voicepack, keepPlaying, ignoreMask, false);
+end;
+
+procedure PlaySoundV(snd: TSound; voicepack: PVoicepack; keepPlaying, ignoreMask, soundAsMusic: boolean);
 var s:shortstring;
 rwops: PSDL_RWops;
 begin
-    if (not isSoundEnabled) or fastUntilLag then
+    if ((not isSoundEnabled) and (not (soundAsMusic and isMusicEnabled))) or fastUntilLag then
         exit;
 
     if keepPlaying and (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then
@@ -528,6 +545,18 @@
         end;
 end;
 
+procedure PlayMusicSound(snd: TSound);
+begin
+    PauseMusic;
+    PlaySound(snd, false, false, true);
+end;
+
+procedure StopMusicSound(snd: TSound);
+begin
+    StopSound(snd, true);
+    ResumeMusic;
+end;
+
 procedure AddVoice(snd: TSound; voicepack: PVoicepack);
 begin
     AddVoice(snd, voicepack, false);
@@ -651,7 +680,12 @@
 
 procedure StopSound(snd: TSound);
 begin
-    if not isSoundEnabled then
+    StopSound(snd, false);
+end;
+
+procedure StopSound(snd: TSound; soundAsMusic: boolean);
+begin
+    if ((not isSoundEnabled) and (not (soundAsMusic and isMusicEnabled))) then
         exit;
 
     if (lastChan[snd] <> -1) and (Mix_Playing(lastChan[snd]) <> 0) then