Complete.Org: Mailing Lists: Archives: freeciv-dev: July 2004:
[Freeciv-Dev] (PR#9490) Patch: Background "mood" music
Home

[Freeciv-Dev] (PR#9490) Patch: Background "mood" music

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#9490) Patch: Background "mood" music
From: "Gregory Richards" <akaquinn@xxxxxxxxxxx>
Date: Sat, 24 Jul 2004 00:51:12 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9490 >

Made the iterations to figure out war state work more correctly.  It 
was: 
if (offensive && defensive) { 
 
It should have been (and now is): 
if (offensive || defensive) { 
 
since, after all, you can be defending quite a bit and not have any 
offense whatsoever. 
diff -ruN -X freeciv-cvs-Jul-21/diff_ignore freeciv-cvs-Jul-21/client/audio.c 
freeciv-cvs-Jul-21-music/client/audio.c
--- freeciv-cvs-Jul-21/client/audio.c   2004-04-19 22:14:21.000000000 -0700
+++ freeciv-cvs-Jul-21-music/client/audio.c     2004-07-24 00:55:32.000000000 
-0700
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,6 +27,11 @@
 #include "registry.h"
 #include "shared.h"
 #include "support.h"
+#include "game.h"
+#include "player.h"
+#include "unit.h"
+#include "map.h"
+#include "unistd.h"
 
 #ifdef AMIGA
 #include "audio_amiga.h"
@@ -56,6 +61,7 @@
 static struct audio_plugin plugins[MAX_NUM_PLUGINS];
 static int num_plugins_used = 0;
 static int selected_plugin = -1;
+static const char *curmusic;
 
 /**********************************************************************
   Returns a static, NULL-terminated list of all sound plugins
@@ -66,7 +72,7 @@
 {
   static const char* plugin_list[MAX_NUM_PLUGINS + 1];
   int i;
-  
+
   for (i = 0; i < num_plugins_used; i++) {
     plugin_list[i] = plugins[i].name;
   }
@@ -277,7 +283,7 @@
   }
 
 #ifdef ESD
-  if (audio_select_plugin("esd")) return; 
+  if (audio_select_plugin("esd")) return;
 #endif
 #ifdef SDL
   if (audio_select_plugin("sdl")) return; 
@@ -354,10 +360,21 @@
 
   freelog(LOG_DEBUG, "audio_play_music('%s', '%s')", tag, pretty_alt_tag);
 
-  /* try playing primary tag first, if not go to alternative tag */
-  if (!audio_play_tag(tag, TRUE) && !audio_play_tag(alt_tag, TRUE)) {
-    freelog(LOG_VERBOSE, "Neither of tags %s or %s found", tag,
-           pretty_alt_tag);
+  if (!curmusic || strcmp(curmusic, tag)) {
+    if (audio_play_tag(tag, TRUE)) {
+      curmusic = tag;
+      return;
+    }
+
+    if (!curmusic || strcmp(curmusic, alt_tag)) {
+      if (audio_play_tag(alt_tag, TRUE)) {
+        curmusic = alt_tag;
+        return;
+      }
+
+      freelog(LOG_VERBOSE, "Neither of tags %s or %s found", tag,
+              pretty_alt_tag);
+    }
   }
 }
 
@@ -407,3 +424,73 @@
   sz_strlcat(buffer, "]");
   return buffer;
 }
+
+/**************************************************************************
+  This is merely a wrapper for mood_music (below)
+**************************************************************************/
+void bg_mood_music_callback(struct client_option *option)
+{
+  if (!option->p_bool_value) return;
+  if (*(option->p_bool_value) == TRUE) {
+    bg_mood_music = TRUE;
+    mood_music();
+  } else {
+    curmusic = NULL;
+    audio_stop();
+  }
+}
+
+/**************************************************************************
+  Sets the audio according to the "mood" of the game
+**************************************************************************/
+void mood_music()
+{
+  /* ESD does not stop music, and having many playing at once is bad at best */
+  if (selected_plugin == -1) return;
+  if (!strcmp(plugins[selected_plugin].name, "esd") || !bg_mood_music) return;
+  struct player *pplayer = game.player_ptr;
+  struct player *cplayer;
+  struct unit *punit;
+  int offensive = 0;
+  int defensive = 0;
+
+  /* 1) Are we at the beginning of the game? */
+  if (game.turn <= 5) {
+    printf("Music: Begin\n");
+    audio_play_music("music_begin", "music_ambient");
+    return;
+  }
+
+  /* 2) Get number of units in enemy war zones and number of enemy units in 
our zone */
+  /* A) Iterate through all players, seek out enemies, and find if they have 
people in our zone */
+  players_iterate(cplayer) {
+    if (pplayers_at_war(pplayer, cplayer)) {
+      unit_list_iterate(cplayer->units, punit) {
+        if (map_get_owner(punit->x, punit->y) == pplayer && 
is_military_unit(punit)) {
+          defensive++;
+        }
+      } unit_list_iterate_end
+    }
+  } players_iterate_end
+
+  /* B) Iterate through own units, and find if they're in enemy positions */
+  unit_list_iterate(pplayer->units, punit) {
+    if (map_get_owner(punit->x, punit->y)) {
+      if (pplayers_at_war(map_get_owner(punit->x, punit->y), pplayer) && 
is_military_unit(punit)) {
+        offensive++;
+      }
+    }
+  } unit_list_iterate_end
+
+  /* C) Choose whether to do offensive/defensive or ambient music */
+  if (offensive || defensive) {
+    if (defensive > offensive) {
+      audio_play_music("music_defense", "music_ambient");
+    } else {
+      audio_play_music("music_offense", "music_ambient");
+    }
+    return;
+  }
+
+  audio_play_music("music_ambient", NULL);
+}
diff -ruN -X freeciv-cvs-Jul-21/diff_ignore freeciv-cvs-Jul-21/client/audio.h 
freeciv-cvs-Jul-21-music/client/audio.h
--- freeciv-cvs-Jul-21/client/audio.h   2002-11-01 10:11:42.000000000 -0800
+++ freeciv-cvs-Jul-21-music/client/audio.h     2004-07-23 16:54:09.000000000 
-0700
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -14,6 +14,7 @@
 #define FC__AUDIO_H
 
 #include "shared.h"            /* bool type */
+#include "options.h"
 
 #define MAX_AUDIO_NAME_LEN             20
 #define MAX_AUDIO_DESCR_LEN            200
@@ -44,4 +45,7 @@
 bool audio_select_plugin(const char *const name);
 const char *audio_get_all_plugin_names(void);
 
+void mood_music(void);
+void bg_mood_music_callback(struct client_option *option);
+
 #endif                         /* FC__AUDIO_H */
diff -ruN -X freeciv-cvs-Jul-21/diff_ignore freeciv-cvs-Jul-21/client/options.c 
freeciv-cvs-Jul-21-music/client/options.c
--- freeciv-cvs-Jul-21/client/options.c 2004-07-20 22:14:34.000000000 -0700
+++ freeciv-cvs-Jul-21-music/client/options.c   2004-07-23 16:55:31.000000000 
-0700
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -72,6 +72,7 @@
 bool popup_new_cities = TRUE;
 bool keyboardless_goto = TRUE;
 bool show_task_icons = TRUE;
+bool bg_mood_music = TRUE;
 
 /* This option is currently set by the client - not by the user. */
 bool update_city_text_in_refresh_tile = TRUE;
@@ -107,6 +108,7 @@
   GEN_BOOL_OPTION(auto_turn_done,           N_("End Turn when done moving")),
   GEN_BOOL_OPTION(ask_city_name,            N_("Prompt for city names")),
   GEN_BOOL_OPTION(popup_new_cities,         N_("Pop up city dialog for new 
cities")),
+  GEN_BOOL_OPTION_CALLBACK(bg_mood_music,   N_("Background music"), 
bg_mood_music_callback)
 };
 #undef GEN_INT_OPTION
 #undef GEN_BOOL_OPTION
diff -ruN -X freeciv-cvs-Jul-21/diff_ignore freeciv-cvs-Jul-21/client/options.h 
freeciv-cvs-Jul-21-music/client/options.h
--- freeciv-cvs-Jul-21/client/options.h 2004-04-05 12:04:08.000000000 -0700
+++ freeciv-cvs-Jul-21-music/client/options.h   2004-07-23 16:56:07.000000000 
-0700
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -15,6 +15,7 @@
 
 #include "events.h"
 #include "shared.h"            /* bool type */
+#include "audio.h"
 
 extern char default_user_name[512];
 extern char default_server_host[512];
@@ -47,6 +48,7 @@
 extern bool update_city_text_in_refresh_tile;
 extern bool keyboardless_goto;
 extern bool show_task_icons;
+extern bool bg_mood_music;
 
 enum client_option_type {
   COT_BOOL,
@@ -81,6 +83,9 @@
 #define GEN_BOOL_OPTION(oname, desc) { #oname, desc, COT_BOOL, \
                                        NULL, &oname, NULL, 0, NULL, \
                                        NULL, NULL }
+#define GEN_BOOL_OPTION_CALLBACK(oname, desc, callback) { #oname, desc, 
COT_BOOL, \
+                                      NULL, &oname, NULL, 0, callback, \
+                                      NULL, NULL }
 #define GEN_STR_OPTION(oname, desc, str_defaults, callback) \
                                     { #oname, desc, COT_STR, \
                                       NULL, NULL, oname, sizeof(oname), \
diff -ruN -X freeciv-cvs-Jul-21/diff_ignore 
freeciv-cvs-Jul-21/client/packhand.c freeciv-cvs-Jul-21-music/client/packhand.c
--- freeciv-cvs-Jul-21/client/packhand.c        2004-07-20 22:14:34.000000000 
-0700
+++ freeciv-cvs-Jul-21-music/client/packhand.c  2004-07-22 20:42:28.000000000 
-0700
@@ -1,4 +1,4 @@
-/********************************************************************** 
+/**********************************************************************
  Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -834,6 +834,8 @@
   if(game.player_ptr->ai.control && !ai_manual_turn_done) {
     user_ended_turn();
   }
+
+  mood_music();
 }
 
 /**************************************************************************

[Prev in Thread] Current Thread [Next in Thread]