From a0af9ff56187bbbcf81ef00f594d60ff085534ed Mon Sep 17 00:00:00 2001
From: nehalmistry <>
Date: Thu, 13 Feb 2003 22:21:52 +0000
Subject: [PATCH] more updates for wc2 cdmode

---
 src/game/intro.cpp         |  2 ++
 src/sound/music.cpp        | 15 +++++++++++++--
 src/sound/sound_server.cpp |  5 ++++-
 src/stratagus/mainloop.cpp |  2 ++
 4 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/game/intro.cpp b/src/game/intro.cpp
index d935e6290..684c3220f 100644
--- a/src/game/intro.cpp
+++ b/src/game/intro.cpp
@@ -540,6 +540,8 @@ global void ShowIntro(const Intro *intro)
     // FIXME: should this be GameMusic?
     if( !strcmp(CDMode, ":off") ) {
 	PlayMusic(MenuMusic);
+    } else {
+	CDRomCheck(NULL);
     }
 }
 
diff --git a/src/sound/music.cpp b/src/sound/music.cpp
index 002c6bd55..bce249d18 100644
--- a/src/sound/music.cpp
+++ b/src/sound/music.cpp
@@ -49,7 +49,7 @@
 #include "iocompat.h"
 #include "sound.h"
 #include "sound_server.h"
-#include "menus.h"
+#include "interface.h"
 
 /*----------------------------------------------------------------------------
 --	Declaration
@@ -300,6 +300,7 @@ global int PlayCDRom(const char* name)
 {
     int i;
     int data_cd;
+    int track;
 
     if (!strcmp(CDMode, ":off")) {
 	if (!strncmp(name, ":", 1)) {
@@ -358,8 +359,18 @@ global int PlayCDRom(const char* name)
 	// FIXME: remove :wc2
 	if (!strcmp(name, ":wc2")) {
 	    CDMode = ":wc2";
-	    if (GuiGameStarted == 0)
+	    track = cd_current_track();
+	    if (!GameRunning && track != 15) {
 		cd_play(15);
+	    } else if (GameRunning && !ThisPlayer->Race && (track < 3 || track > 7)) {
+		do CDTrack = (MyRand() % NumCDTracks) + 3;
+		while (CDTrack < 3 || CDTrack > 7); 
+		cd_play(CDTrack);
+	    } else if (GameRunning && ThisPlayer->Race && (track < 11 || track > 14)) {
+		do CDTrack = (MyRand() % NumCDTracks) + 9;
+		while (CDTrack < 11 || CDTrack > 14); 
+		cd_play(CDTrack);
+	    }
 	}
 	return 1;
     }
diff --git a/src/sound/sound_server.cpp b/src/sound/sound_server.cpp
index 51e2f5972..abdf63188 100644
--- a/src/sound/sound_server.cpp
+++ b/src/sound/sound_server.cpp
@@ -241,10 +241,13 @@ global int CDRomCheck(void *unused __attribute__ ((unused)))
     }
 #elif defined(USE_LIBCDA)
     if (strcmp(CDMode, ":off") && strcmp(CDMode, ":stopped")
-	    && !cd_current_track()) {
+	    && !cd_current_track() && strcmp(CDMode, ":wc2")) {
 	DebugLevel0Fn("Playing new track\n");
 	PlayCDRom(CDMode);
     } else if (strcmp(CDMode, ":off") && strcmp(CDMode, ":stopped")) {
+	if (!strcmp(CDMode, ":wc2")) {
+	    PlayCDRom(CDMode);
+	}
 	DebugLevel0Fn("get track\n");
 	CDTrack = cd_current_track() + 1;
 	if (CDTrack > NumCDTracks) {
diff --git a/src/stratagus/mainloop.cpp b/src/stratagus/mainloop.cpp
index 7eee7af13..b89e5631e 100644
--- a/src/stratagus/mainloop.cpp
+++ b/src/stratagus/mainloop.cpp
@@ -636,6 +636,8 @@ global void GameMainLoop(void)
 
     MultiPlayerReplayEachCycle();
 
+    CDRomCheck(NULL);
+
     while( GameRunning ) {
 #if defined(DEBUG) && defined(HIERARCHIC_PATHFINDER)
 	if (setjmp (MainLoopJmpBuf)) {