Update of /cvsroot/netrek/client/netrekxp/src
In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv30543/src

Modified Files:
	cowmain.c data.c death.c defaults.c newwin.c parsemeta.c 
	sound.c 
Log Message:
Fixed bug with metaserver - if server entry in metacache indicated one status, and we
receive a new server packet with a different status, that packet is no long rejected
based on packet age, new packets are considered priority in case of such a 
difference.
Added 9  new star trek theme songs.
Added 3 new netrekrc options (newSoundEffects, newSoundMusic, and newSoundMusicBkgd)
that allow for sound effect and music playback to be toggled separately.
Random intro sounds (instead of just the typical Kirk intro) - now all 5 trek series are represented.
Random genocide sounds (4 end themes from the trek series).
Music now fades out over 5 seconds upon entering game, rather than ending abruptly.

Index: sound.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/sound.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- sound.c	13 Dec 2006 03:14:55 -0000	1.19
+++ sound.c	31 Jan 2007 07:06:37 -0000	1.20
@@ -29,6 +29,7 @@
 #include "proto.h"
 
 Mix_Chunk *newsounds[NUM_WAVES];
+Mix_Music *newmusic[NUM_MUSIC];
 /* Each sound has a priority which controls what can override what
    Currently these are set as follows:
 
@@ -144,6 +145,32 @@
   return(1);
 }
 
+/*
+ * Load the .ogg files into the music arrays
+ */
+int loadMusic(void) {
+  int i;
+
+  newmusic[INTRO1_MUSIC] = Mix_LoadMUS(DATAFILE("intro_theme_TOS.ogg"));
+  newmusic[INTRO2_MUSIC] = Mix_LoadMUS(DATAFILE("intro_theme_TNG.ogg"));
+  newmusic[INTRO3_MUSIC] = Mix_LoadMUS(DATAFILE("intro_theme_VOY.ogg"));
+  newmusic[INTRO4_MUSIC] = Mix_LoadMUS(DATAFILE("intro_theme_DS9.ogg"));
+  newmusic[INTRO5_MUSIC] = Mix_LoadMUS(DATAFILE("intro_theme_ENT.ogg"));
+  newmusic[END1_MUSIC] = Mix_LoadMUS(DATAFILE("end_theme_TOS.ogg"));
+  newmusic[END2_MUSIC] = Mix_LoadMUS(DATAFILE("end_theme_TNG.ogg"));
+  newmusic[END3_MUSIC] = Mix_LoadMUS(DATAFILE("end_theme_VOY.ogg"));
+  newmusic[END4_MUSIC] = Mix_LoadMUS(DATAFILE("end_theme_DS9.ogg"));
+
+  for (i=0; i < NUM_MUSIC; i++) {
+    if (!newmusic[i]) {
+      LineToConsole("Mix_LoadMUS newmusic[%d] could not be loaded. Check soundDir in your .netrekrc: %s\n", i, Mix_GetError());
+      return(-1);
+    }
+  }
+
+  return(1);
+}
+
 extern void Exit_Sound (void)
 {
     if (sound_init)
@@ -174,6 +201,8 @@
         
         if (newSound)
         {
+            int i;
+
 #ifdef DEBUG
 	    LineToConsole ("Init_Sound using SDL\n");
 #endif
@@ -188,15 +217,15 @@
     	    if (Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024) < 0) 
       		LineToConsole("Mix_OpenAudio: %s\n", Mix_GetError());
 
-    	    /* If we successfully loaded the wav files, so shut-off sound_init and play
-    	     * the introduction
-    	     */
-    	    if (loadSounds())
-    	    {
-     	        if (Mix_PlayChannel(-1, newsounds[INTRO_WAV], 0) < 0)
-		    LineToConsole("Mix_PlayChannel: %s\n", Mix_GetError());
-      	    }
+            /* Toggle on sound, and load sound files */
       	    sound_toggle = 1;
+      	    loadSounds();
+ 
+      	    /* Toggle on music, load music files, and play random intro music */
+      	    music_toggle = 1;
+      	    loadMusic();
+      	    i = RANDOM() % MUSIC_OFFSET;
+      	    Play_Music(i);
       	    /* See if volume is adjustable */
       	    CheckVolumeSettings ();
       	    /* Default of 8 channels not enough */
@@ -236,7 +265,7 @@
     {
     	int channel;
     	
-        if (!sound_init || !sound_toggle)
+        if (!sound_init || !newSoundEffects || !sound_toggle)
 	    return;
 
         if ((type >= NUM_WAVES) || (type < 0))
@@ -278,11 +307,12 @@
             current_sound = NO_SOUND;
      }
 }
+
 extern void Play_Sound_Loc (int type, int angle, int distance)
 {
     int channel;
     
-    if (!sound_init || !sound_toggle)
+    if (!sound_init || !newSoundEffects || !sound_toggle)
         return;
 
     if ((type >= NUM_WAVES) || (type < 0))
@@ -324,6 +354,48 @@
     return;
 }
 
+/* Only works with SDL, i.e. newSound */
+extern void Play_Music (int type)
+{
+    if (!sound_init || !newSound || !newSoundMusic || !music_toggle)
+        return;
+
+    if ((type >= NUM_MUSIC) || (type < 0))
+    {
+        LineToConsole("Invalid music type %d\n", type);
+        return;
+    }
+
+    if (Mix_PlayMusic(newmusic[type], 1) < 0)
+    {
+        LineToConsole("Mix_PlayMusic: %s\n", Mix_GetError());
+        return;
+    }
+}
+
+/* Only works with SDL, i.e. newSound */
+extern void Play_Music_Bkgd (void)
+{
+    int i;
+
+    if (!sound_init || !newSound || !newSoundMusic || !newSoundMusicBkgd|| !music_toggle)
+        return;
+
+    if (Mix_PlayingMusic())
+        return;
+
+    i = RANDOM() % NUM_MUSIC;
+
+    if (Mix_PlayMusic(newmusic[i], 1) < 0)
+    {
+        LineToConsole("Mix_PlayMusic: %s\n", Mix_GetError());
+        return;
+    }
+    /* So we play another one when done */
+    Mix_HookMusicFinished(Play_Music_Bkgd);
+    
+}
+
 void Group_Sound (int type, int channel)
 {
     // Add channel to group by type, useful for aborting specific sounds
@@ -375,8 +447,11 @@
 #define SOUND_INIT    MESSAGE_SOUND + 2
 #define SOUND_DONE    MESSAGE_SOUND + 3
 
-#define SDL_SOUND_ANGLE 1
-#define SDL_SOUND_DONE 2
+#define SDL_EFFECTS_TOGGLE 1
+#define SDL_MUSIC_TOGGLE 2
+#define SDL_MUSIC_BKGD 3
+#define SDL_SOUND_ANGLE 4
+#define SDL_SOUND_DONE 5
 
 static void soundrefresh (int i);
 static void sdlsoundrefresh (int i);
@@ -408,6 +483,21 @@
         sprintf (buf, "Sound is turned %s",
                  (sound_toggle == 1) ? "ON" : "OFF");
     }
+    else if (i == SDL_EFFECTS_TOGGLE)
+    {
+        sprintf (buf, "Sound effects are turned %s",
+                 (newSoundEffects == 1) ? "ON" : "OFF");
+    }
+    else if (i == SDL_MUSIC_TOGGLE)
+    {
+        sprintf (buf, "Music is turned %s",
+                 (newSoundMusic == 1) ? "ON" : "OFF");
+    }
+    else if (i == SDL_MUSIC_BKGD)
+    {
+        sprintf (buf, "Background music is turned %s",
+                 (newSoundMusicBkgd == 1) ? "ON" : "OFF");
+    }
     else if (i == SDL_SOUND_ANGLE)
     {
         sprintf (buf, "Angular sound is turned %s",
@@ -544,8 +634,40 @@
     {
         if (sound_init)
             sound_toggle = (sound_toggle == 1) ? 0 : 1;
+        // Halt all sounds if toggled off
+        if (!sound_toggle)
+        {
+            Mix_HaltChannel(-1);
+            Mix_HaltMusic();
+        }
         sdlsoundrefresh (SOUND_TOGGLE);
     }
+    else if (i == SDL_EFFECTS_TOGGLE)
+    {
+    	if (sound_init)
+            newSoundEffects = (newSoundEffects) ? 0 : 1;
+        if (!newSoundEffects)
+            Mix_HaltChannel(-1);
+    	sdlsoundrefresh (SDL_EFFECTS_TOGGLE);
+    }
+    else if (i == SDL_MUSIC_TOGGLE)
+    {
+    	if (sound_init)
+            newSoundMusic = (newSoundMusic) ? 0 : 1;
+        if (!newSoundMusic)
+            Mix_HaltMusic();
+    	sdlsoundrefresh (SDL_MUSIC_TOGGLE);
+    }
+    else if (i == SDL_MUSIC_BKGD)
+    {
+    	if (sound_init)
+    	    newSoundMusicBkgd = (newSoundMusicBkgd) ? 0 : 1;
+    	if (!newSoundMusicBkgd)
+    	    Mix_HaltMusic();
+    	else
+    	    Play_Music_Bkgd();
+    	sdlsoundrefresh (SDL_MUSIC_BKGD);
+    }
     else if (i == SDL_SOUND_ANGLE)
     {
     	newSoundAngles = (newSoundAngles) ? 0 : 1;

Index: newwin.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/newwin.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -d -r1.45 -r1.46
--- newwin.c	30 Nov 2006 11:28:57 -0000	1.45
+++ newwin.c	31 Jan 2007 07:06:37 -0000	1.46
@@ -1012,8 +1012,8 @@
 {
     if (newSound)
     {
-        soundWin = W_MakeMenu("sound", WINSIDE + 20, -BORDER + 10, 30,
-                        3, NULL, 2);
+        soundWin = W_MakeMenu("sound", WINSIDE + 20, -BORDER + 10, 33,
+                        6, NULL, 2);
         W_SetWindowKeyDownHandler(soundWin, sdlsoundaction);
         W_SetWindowButtonHandler(soundWin, sdlsoundaction);
         W_DefineArrowCursor(soundWin);

Index: cowmain.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/cowmain.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- cowmain.c	10 Dec 2006 02:49:14 -0000	1.19
+++ cowmain.c	31 Jan 2007 07:06:37 -0000	1.20
@@ -1083,7 +1083,11 @@
 #ifdef SOUND
     if (newSound)
     {
-        Mix_HaltChannel(-1); /* Kill all currently playing sounds when entering game */
+        /* Kill all currently playing sounds when entering game */
+        Mix_HaltChannel(-1);
+        /* Fade out any music playing over 5 seconds */
+        if (Mix_PlayingMusic())
+            Mix_FadeOutMusic(5000);
         Play_Sound(ENTER_SHIP_WAV);
     }
     else

Index: death.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/death.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- death.c	11 Jun 2006 20:53:52 -0000	1.11
+++ death.c	31 Jan 2007 07:06:37 -0000	1.12
@@ -152,6 +152,13 @@
                 W_TileWindow (mapw, genopic2);
                 break;
         }
+#ifdef SOUND
+        if (newSound)
+        {
+            i = MUSIC_OFFSET + (RANDOM() % MUSIC_OFFSET); // Play random end theme
+            Play_Music(i);
+        }
+#endif
         break;
     case KGHOST:
         strcpy (deathmessage, "You were killed by a confused daemon.");
@@ -176,6 +183,13 @@
                 W_TileWindow (mapw, genopic2);
                 break;
         }
+#ifdef SOUND
+        if (newSound)
+        {
+            i = MUSIC_OFFSET + (RANDOM() % MUSIC_OFFSET); // Play random end theme
+            Play_Music(i);
+        }
+#endif
         break;
     case KPROVIDENCE:
         strcpy (deathmessage, "You were nuked by GOD.");

Index: defaults.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/defaults.c,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -d -r1.37 -r1.38
--- defaults.c	13 Dec 2006 03:14:53 -0000	1.37
+++ defaults.c	31 Jan 2007 07:06:37 -0000	1.38
@@ -339,6 +339,24 @@
             NULL
         }
     },
+    {"newSoundEffects", &newSoundEffects, RC_BOOL,
+        {
+            "Play sound effects (newSound only)",
+            NULL
+        }
+    },
+    {"newSoundMusic", &newSoundMusic, RC_BOOL,
+        {
+            "Play music (newSound only)",
+            NULL
+        }
+    },
+    {"newSoundMusicBkgd", &newSoundMusicBkgd, RC_BOOL,
+        {
+            "Play theme music in background (requires newSound and newSoundMusic)",
+            NULL
+        }
+    },
     {"newSoundAngles", &newSoundAngles, RC_BOOL,
         {
             "Use 3D sound effects (only works if newSound is on)",
@@ -1498,6 +1516,9 @@
     allowWheelActions = booleanDefault ("allowWheelActions", allowWheelActions);
     newQuit = booleanDefault ("newQuit", newQuit);
     newSound = booleanDefault ("newSound", newSound);
+    newSoundEffects= booleanDefault ("newMusic", newSoundEffects);
+    newSoundMusic = booleanDefault ("newMusicPlayRandom", newSoundMusic);
+    newSoundMusicBkgd = booleanDefault ("newSoundMusicBkgd", newSoundMusicBkgd);
     newSoundAngles = booleanDefault ("newSoundAngles", newSoundAngles);
     useFullShipInfo = booleanDefault ("useFullShipInfo", useFullShipInfo);
     tpDotDist = intDefault ("tpDotDist", tpDotDist);

Index: data.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/data.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- data.c	13 Dec 2006 00:00:00 -0000	1.47
+++ data.c	31 Jan 2007 07:06:37 -0000	1.48
@@ -632,6 +632,7 @@
 #ifdef SOUND
 int sound_init = 1;
 int sound_toggle = 0;
+int music_toggle = 0;
 char *sounddir = NULL;
 W_Window soundWin = NULL;
 
@@ -786,9 +787,12 @@
 
 WNDPROC lpfnDefRichEditWndProc;     /* default window proc */
 
-int richText = 0;   /* temporary variable to select rich text message windows */
-int newQuit = 0;    /* new quit clock */
-int newSound = 1;   /* use new SDL sound */
-int newSoundAngles = 1; /* use new SDL sound with angular 3d component */
+int richText = 0;   		/* temporary variable to select rich text message windows */
+int newQuit = 0;    		/* new quit clock */
+int newSound = 1;   		/* Use new SDL sound interface */
+int newSoundEffects = 1;	/* Use SDL sound effects playback */
+int newSoundMusic = 1;		/* Use SDL music playback */
+int newSoundMusicBkgd = 0;	/* Play random background music continuously */
+int newSoundAngles = 1; 	/* Use SDL with angular 3D sound */
 
 int useFullShipInfo = 1;  /* Prefer SP_PLAYER packets over SP_S_PLAYER packets */
\ No newline at end of file

Index: parsemeta.c
===================================================================
RCS file: /cvsroot/netrek/client/netrekxp/src/parsemeta.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- parsemeta.c	29 Jan 2007 10:34:23 -0000	1.28
+++ parsemeta.c	31 Jan 2007 07:06:37 -0000	1.29
@@ -589,9 +589,11 @@
         sp->pkt_rtt[j] = (unsigned long) -1;
 #endif
     }
-    /* if it was found, check age */
+    /* if it was found, check age.  Don't update if old entry is newer or
+       of the same age.  However, make sure status hasn't changed.  If status
+       differs, we want to use the new information packet regardless of age. */
     else {
-      if ((now-age) < (sp->when-sp->age)) {
+      if ((now-age) < (sp->when-sp->age) && (sp->status == tempstatus)) {
 	sp->age = (int)now - (int)(sp->when-sp->age);
 	sp->when = now;
 	sp->refresh = 1;