Do not return NULL as boolean from wonder_is_lost() nor wonder_is_built()
[freeciv.git] / client / music.c
blobdfb4163847c6f7e8897e084b8b0f5ed3868c0426
1 /**********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Team
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12 ***********************************************************************/
14 #ifdef HAVE_CONFIG_H
15 #include <fc_config.h>
16 #endif
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
22 /* utility */
23 #include "connection.h"
24 #include "log.h"
26 /* client */
27 #include "audio.h"
28 #include "client_main.h"
29 #include "options.h"
31 #include "music.h"
33 /**********************************************************************
34 Start music suitable for current game situation
35 ***********************************************************************/
36 void start_style_music(void)
38 if (client_state() != C_S_RUNNING) {
39 /* Style music plays in running game only */
40 return;
43 if (client.conn.playing == NULL) {
44 /* Detached connections and global observers currently not
45 * supported */
46 return;
49 if (gui_options.sound_enable_game_music) {
50 struct music_style *pms;
52 stop_style_music();
54 pms = music_style_by_number(client.conn.playing->music_style);
56 if (pms != NULL) {
57 const char *tag = NULL;
59 switch (client.conn.playing->client.mood) {
60 case MOOD_COUNT:
61 fc_assert(client.conn.playing->client.mood != MOOD_COUNT);
62 /* No break but use default tag */
63 case MOOD_PEACEFUL:
64 tag = pms->music_peaceful;
65 break;
66 case MOOD_COMBAT:
67 tag = pms->music_combat;
68 break;
71 if (tag != NULL && tag[0] != '\0') {
72 log_debug("Play %s", tag);
73 audio_play_music(tag, NULL, MU_INGAME);
79 /**********************************************************************
80 Stop style music completely.
81 ***********************************************************************/
82 void stop_style_music(void)
84 audio_stop();
87 /**********************************************************************
88 Start menu music.
89 ***********************************************************************/
90 void start_menu_music(const char *const tag, char *const alt_tag)
92 if (gui_options.sound_enable_menu_music) {
93 audio_play_music(tag, alt_tag, MU_MENU);
97 /**********************************************************************
98 Stop menu music completely.
99 ***********************************************************************/
100 void stop_menu_music(void)
102 audio_stop();
105 /**************************************************************************
106 Play single track before continuing normal style music
107 **************************************************************************/
108 void play_single_track(const char *const tag)
110 if (client_state() != C_S_RUNNING) {
111 /* Only in running game */
112 return;
115 audio_play_track(tag, NULL);
118 /**************************************************************************
119 Musicset changed in options.
120 **************************************************************************/
121 void musicspec_reread_callback(struct option *poption)
123 const char *musicset_name = option_str_get(poption);
125 audio_restart(sound_set_name, musicset_name);
127 /* Start suitable music from the new set */
128 if (client_state() != C_S_RUNNING) {
129 start_menu_music("music_menu", NULL);
130 } else {
131 start_style_music();