[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 22:45:10 -0700 |
Reply-to: |
rt@xxxxxxxxxxx |
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9490 >
I got tired of screwing around with ESD, so I moved it from first
option to last. If mood music was ever incorporated into CVS, it
would be imperative that SDL be chosen above ESD, since ESD doesn't do
music well.
diff -ruN -X freeciv-cvs-Jul-23/diff_ignore freeciv-cvs-Jul-23/client/audio.c
freeciv-cvs-Jul-23-music/client/audio.c
--- freeciv-cvs-Jul-23/client/audio.c 2004-04-19 22:14:21.000000000 -0700
+++ freeciv-cvs-Jul-23-music/client/audio.c 2004-07-24 22:50:35.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;
}
@@ -154,9 +160,6 @@
assert(num_plugins_used == 1);
selected_plugin = 0;
-#ifdef ESD
- audio_esd_init();
-#endif
#ifdef SDL
audio_sdl_init();
#endif
@@ -169,6 +172,9 @@
#ifdef AMIGA
audio_amiga_init();
#endif
+#ifdef ESD
+ audio_esd_init();
+#endif
}
/**************************************************************************
@@ -276,11 +282,8 @@
return;
}
-#ifdef ESD
- if (audio_select_plugin("esd")) return;
-#endif
#ifdef SDL
- if (audio_select_plugin("sdl")) return;
+ if (audio_select_plugin("sdl")) return;
#endif
#ifdef ALSA
if (audio_select_plugin("alsa")) return;
@@ -291,6 +294,9 @@
#ifdef AMIGA
if (audio_select_plugin("amiga")) return;
#endif
+#ifdef ESD
+ if (audio_select_plugin("esd")) return;
+#endif
freelog(LOG_ERROR,
_("No real audio subsystem managed to initialize!"));
freelog(LOG_ERROR,
@@ -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,71 @@
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()
+{
+ struct player *pplayer = game.player_ptr;
+ int offensive = 0;
+ int defensive = 0;
+
+ /* 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;
+
+ /* 1) Are we at the beginning of the game? */
+ if (game.turn <= 5) {
+ 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 > 0 || defensive > 0) {
+ 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-23/diff_ignore freeciv-cvs-Jul-23/client/audio.h
freeciv-cvs-Jul-23-music/client/audio.h
--- freeciv-cvs-Jul-23/client/audio.h 2002-11-01 10:11:42.000000000 -0800
+++ freeciv-cvs-Jul-23-music/client/audio.h 2004-07-24 17:49:35.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-23/diff_ignore freeciv-cvs-Jul-23/client/options.c
freeciv-cvs-Jul-23-music/client/options.c
--- freeciv-cvs-Jul-23/client/options.c 2004-07-20 22:14:34.000000000 -0700
+++ freeciv-cvs-Jul-23-music/client/options.c 2004-07-24 17:49:35.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-23/diff_ignore freeciv-cvs-Jul-23/client/options.h
freeciv-cvs-Jul-23-music/client/options.h
--- freeciv-cvs-Jul-23/client/options.h 2004-04-05 12:04:08.000000000 -0700
+++ freeciv-cvs-Jul-23-music/client/options.h 2004-07-24 17:49:59.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
@@ -47,6 +47,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 +82,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-23/diff_ignore
freeciv-cvs-Jul-23/client/packhand.c freeciv-cvs-Jul-23-music/client/packhand.c
--- freeciv-cvs-Jul-23/client/packhand.c 2004-07-20 22:14:34.000000000
-0700
+++ freeciv-cvs-Jul-23-music/client/packhand.c 2004-07-24 17:49:35.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();
}
/**************************************************************************
Files freeciv-cvs-Jul-23/data/gregorsounds/ambient.ogg and
freeciv-cvs-Jul-23-music/data/gregorsounds/ambient.ogg differ
Files freeciv-cvs-Jul-23/data/gregorsounds/begin.ogg and
freeciv-cvs-Jul-23-music/data/gregorsounds/begin.ogg differ
Files freeciv-cvs-Jul-23/data/gregorsounds/defense.ogg and
freeciv-cvs-Jul-23-music/data/gregorsounds/defense.ogg differ
Files freeciv-cvs-Jul-23/data/gregorsounds/offense.ogg and
freeciv-cvs-Jul-23-music/data/gregorsounds/offense.ogg differ
Files freeciv-cvs-Jul-23/data/gregorsounds/start.ogg and
freeciv-cvs-Jul-23-music/data/gregorsounds/start.ogg differ
diff -ruN -X freeciv-cvs-Jul-23/diff_ignore
freeciv-cvs-Jul-23/data/gregorsounds.soundspec
freeciv-cvs-Jul-23-music/data/gregorsounds.soundspec
--- freeciv-cvs-Jul-23/data/gregorsounds.soundspec 1969-12-31
16:00:00.000000000 -0800
+++ freeciv-cvs-Jul-23-music/data/gregorsounds.soundspec 2004-07-24
12:11:59.000000000 -0700
@@ -0,0 +1,268 @@
+[soundspec]
+; Format and options of this spec file:
+options = "+soundspec"
+
+[info]
+artists = "Music by Gregor Richards, samples taken from
+www.waveform.dk (various authors), and OpenQuartz (Ali
+Jackson, alister667@xxxxxxxxxxx) and Paroxysm (pOx,
+pox@xxxxxxxxxxxxxxx)."
+
+; For a list of tags used see README.sound, buildings.ruleset and
+; units.ruleset.
+
+[files]
+
+;b_generic = ""
+;b_airport = ""
+;b_aqueduct = ""
+;b_bank = ""
+;b_barracks_i = ""
+;b_barracks_ii = ""
+;b_barracks_iii = ""
+;b_cathedral = ""
+;b_city_walls = ""
+;b_coastal_defense = ""
+;b_colosseum = ""
+;b_courthouse = ""
+;b_factory = ""
+;b_granary = ""
+;b_harbour = ""
+;b_hydro_plant = ""
+;b_library = ""
+;b_marketplace = ""
+;b_mass_transit = ""
+;b_mfg_plant = ""
+;b_nuclear_plant = ""
+;b_offshore_platform = ""
+;b_palace = ""
+;b_police_station = ""
+;b_port_facility = ""
+;b_power_plant = ""
+;b_recycling_center = ""
+;b_research_lab = ""
+;b_sam_battery = ""
+;b_sdi_defense = ""
+;b_sewer_system = ""
+;b_solar_plant = ""
+;b_space_component = ""
+;b_space_module = ""
+;b_space_structural = ""
+;b_stock_exchange = ""
+;b_super_highways = ""
+;b_supermarket = ""
+;b_temple = ""
+;b_university = ""
+
+f_generic = "gregorsounds/woodbrk.wav"
+f_aegis_cruiser = "gregorsounds/rhino.wav"
+f_alpine_troops = "gregorsounds/guncock.wav"
+;f_archers = ""
+f_armor = "gregorsounds/rhino.wav"
+f_artillery = "gregorsounds/rhino.wav"
+;f_barbarian_leader = ""
+f_battleship = "gregorsounds/r_exp3.wav"
+f_bomber = "gregorsounds/rhino.wav"
+f_cannon = "gregorsounds/wall01.wav"
+;f_caravan = ""
+;f_caravel = ""
+;f_carrier = ""
+f_catapult = "gregorsounds/wall01.wav"
+f_cavalry = "gregorsounds/bang10.wav"
+;f_chariot = ""
+f_cruise_missile = "gregorsounds/rhino.wav"
+f_cruiser = "gregorsounds/rhino.wav"
+;f_crusaders = ""
+f_destroyer = "gregorsounds/r_exp3.wav"
+;f_diplomat = ""
+;f_dragoons = ""
+;f_elephants = ""
+;f_engineers = ""
+;f_explorer = ""
+;f_fanatics = ""
+f_fighter = "gregorsounds/rhino.wav"
+;f_freight = ""
+;f_frigate = ""
+;f_galleon = ""
+f_helicopter = "gregorsounds/rhino.wav"
+;f_horsemen = ""
+f_howitzer = "gregorsounds/r_exp3.wav"
+f_ironclad = "gregorsounds/rhino.wav"
+;f_knights = ""
+;f_legion = ""
+f_marines = "gregorsounds/guncock.wav"
+f_mech_inf = "gregorsounds/guncock.wav"
+f_musketeers = "gregorsounds/bang10.wav"
+f_nuclear = "gregorsounds/rhino.wav"
+f_paratroopers = "gregorsounds/guncock.wav"
+f_partisan = "gregorsounds/bang10.wav"
+;f_phalanx = ""
+;f_pikemen = ""
+f_riflemen = "gregorsounds/guncock.wav"
+;f_settlers = ""
+;f_spy = ""
+f_stealth_bomber = "gregorsounds/rhino.wav"
+f_stealth_fighter = "gregorsounds/rhino.wav"
+f_submarine = "gregorsounds/rhino.wav"
+;f_transport = ""
+;f_trireme = ""
+;f_warriors = ""
+
+m_generic = "gregorsounds/foot3.wav"
+m_aegis_cruiser = "gregorsounds/inh2o.wav"
+;m_alpine_troops = ""
+;m_archers = ""
+;m_armor = ""
+;m_artillery = ""
+;m_barbarian_leader = ""
+m_battleship = "gregorsounds/inh2o.wav"
+;m_bomber = ""
+;m_cannon = ""
+;m_caravan = ""
+m_caravel = "gregorsounds/inh2o.wav"
+m_carrier = "gregorsounds/inh2o.wav"
+;m_catapult = ""
+;m_cavalry = ""
+;m_chariot = ""
+;m_cruise_missile = ""
+m_cruiser = "gregorsounds/inh2o.wav"
+;m_crusaders = ""
+m_destroyer = "gregorsounds/inh2o.wav"
+;m_diplomat = ""
+;m_dragoons = ""
+;m_elephants = ""
+;m_engineers = ""
+;m_explorer = ""
+;m_fanatics = ""
+;m_fighter = ""
+;m_freight = ""
+m_frigate = "gregorsounds/inh2o.wav"
+m_galleon = "gregorsounds/inh2o.wav"
+;m_helicopter = ""
+;m_horsemen = ""
+;m_howitzer = ""
+m_ironclad = "gregorsounds/inh2o.wav"
+;m_knights = ""
+;m_legion = ""
+;m_marines = ""
+;m_mech_inf = ""
+;m_musketeers = ""
+;m_nuclear = ""
+;m_paratroopers = ""
+;m_partisan = ""
+;m_phalanx = ""
+;m_pikemen = ""
+;m_riflemen = ""
+;m_settlers = ""
+;m_spy = ""
+;m_stealth_bomber = ""
+;m_stealth_fighter = ""
+m_submarine = "gregorsounds/inh2o.wav"
+m_transport = "gregorsounds/inh2o.wav"
+m_trireme = "gregorsounds/inh2o.wav"
+;m_warriors = ""
+
+w_generic = "gregorsounds/gong10.wav"
+;w_apollo_program = ""
+;w_asmiths_trading_co = ""
+;w_colossus = ""
+;w_copernicus_observatory = ""
+;w_cure_for_cancer = ""
+;w_darwins_voyage = ""
+;w_eiffel_tower = ""
+;w_great_library = ""
+;w_great_wall = ""
+;w_hanging_gardens = ""
+;w_hoover_dam = ""
+;w_isaac_newtons_college = ""
+;w_js_bachs_cathedral = ""
+;w_king_richards_crusade = ""
+;w_leonardos_workshop = ""
+;w_lighthouse = ""
+;w_magellans_expedition = ""
+;w_manhattan_project = ""
+;w_marco_polos_embassy = ""
+;w_michelangelos_chapel = ""
+;w_oracle = ""
+;w_pyramids = ""
+;w_seti_program = ""
+;w_shakespeares_theatre = ""
+;w_statue_of_liberty = ""
+;w_sun_tzus_war_academy = ""
+;w_united_nations = ""
+;w_womens_suffrage = ""
+
+;e_anarchy = ""
+;e_broadcast_report = ""
+;e_cancel_pact = ""
+;e_city_aq_building = ""
+;e_city_aqueduct = ""
+;e_city_build = ""
+;e_city_cantbuild = ""
+;e_city_cma_release = ""
+;e_city_disorder = ""
+;e_city_famine = ""
+;e_city_famine_feared = ""
+;e_city_gran_throttle = ""
+;e_city_growth = ""
+;e_city_lost = ""
+;e_city_love = ""
+;e_city_may_soon_grow = ""
+;e_city_normal = ""
+;e_city_nuked = ""
+;e_city_wonder_will_be_built = ""
+;e_destroyed = ""
+;e_dipl_incident = ""
+e_diplomated = "gregorsounds/cfx01.wav"
+;e_first_contact = ""
+;e_game_end = ""
+e_game_start = "gregorsounds/chineseprc09.wav"
+;e_global_eco = ""
+;e_hut_barb = ""
+;e_hut_barb_city_near = ""
+;e_hut_barb_killed = ""
+;e_hut_city = ""
+;e_hut_gold = ""
+;e_hut_merc = ""
+;e_hut_settler = ""
+;e_hut_tech = ""
+;e_imp_auctioned = ""
+;e_imp_auto = ""
+;e_imp_build = ""
+;e_imp_buy = ""
+e_imp_sold = "gregorsounds/metbrk.wav"
+;e_low_on_funds = ""
+;e_message_wall = ""
+e_my_diplomat = "gregorsounds/cfx11.wav"
+e_nation_selected = "gregorsounds/plopp.wav"
+;e_new_government = ""
+;e_next_year = ""
+;e_nuke = ""
+;e_pollution = ""
+;e_report = ""
+;e_revolt_done = ""
+;e_revolt_start = ""
+;e_spaceship = ""
+;e_tech_gain = ""
+;e_tech_learned = ""
+e_turn_bell = "gregorsounds/chineseprc09.wav"
+;e_unit_build = ""
+;e_unit_buy = ""
+;e_unit_lost = ""
+;e_unit_lost_att = ""
+;e_unit_upgraded = ""
+;e_unit_win = ""
+;e_unit_win_att = ""
+;e_uprising = ""
+;e_wonder_build = ""
+;e_wonder_obsolete = ""
+;e_wonder_started = ""
+;e_wonder_stopped = ""
+;e_worklist = ""
+
+music_start = "gregorsounds/start.ogg"
+music_begin = "gregorsounds/begin.ogg"
+music_ambient = "gregorsounds/ambient.ogg"
+music_offense = "gregorsounds/offense.ogg"
+music_defense = "gregorsounds/defense.ogg"
+
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, (continued)
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Gregory Richards, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Mateusz Stefek, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Gregory Richards, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Gregory Richards, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Gregory Richards, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Gregory Richards, 2004/07/24
- [Freeciv-Dev] (PR#9490) Patch: Background "mood" music, Mateusz Stefek, 2004/07/24
|
|