/********************************************************************** 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 the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ***********************************************************************/ #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include #include "fcintl.h" #include "log.h" #include "mem.h" #include "chatline_g.h" #include "citydlg_g.h" #include "dialogs_g.h" #include "gui_main_g.h" #include "mapctrl_g.h" #include "mapview_g.h" #include "menu_g.h" #include "registry.h" #include "civclient.h" #include "clinet.h" #include "goto.h" #include "options.h" #include "tilespec.h" #include "sound.h" /* sound specific */ struct timeval timelast; int lastsound, lastsoundx; char play_command[120], play_options[20], dir[80], sound_config_file[120] = "/usr/local/share/freeciv/freeciv.soundspec"; int is_parsed = 0; void play_sound_unit (struct unit *punit, enum sound_magics action) { /* Actions: 0 : Activate 1 : Move 2 : Attack 3 : Special 4 : Destroyed */ char *name; char giveout[100]; int x = 0; struct timeval now; if (!is_parsed) parse_sound_config(sound_config_file); name = get_unit_type(punit->type)->name_orig; while (x < 52) { if (!strcoll(name, unit_sounds[x].name)) break; else x++; } sprintf (giveout, "%s %s %s%s &", play_command, play_options, dir, unit_sounds[x].file[action]); gettimeofday (&now, NULL); if (strcoll(unit_sounds[x].file[action], "")) if ((now.tv_sec - timelast.tv_sec) > 2 || lastsound != action || lastsoundx != x) { system (giveout); timelast = now; lastsound = action; lastsoundx = x; } } void play_sound_event (enum sound_magics event) { /* see event IDs from header-file */ char giveout[100]; struct timeval now; if (!is_parsed) parse_sound_config(sound_config_file); sprintf (giveout, "%s %s %s%s &", play_command, play_options, dir, event_sounds[event].file); gettimeofday (&now, NULL); if (strcoll(event_sounds[event].file, "")) if ((now.tv_sec - timelast.tv_sec) > 2 || lastsound != event) { system (giveout); timelast = now; lastsound = event; } } void parse_sound_config (const char *fname) { struct section_file the_file, *file = &the_file; char unit_sec_activate[100], unit_sec_move[100], unit_sec_attack[100], unit_sec_special[100], unit_sec_destroyed[100]; int x = 0; freelog(LOG_VERBOSE, "soundspec file is %s", fname); if (!section_file_load(file, fname)) { freelog(LOG_FATAL, _("Could not open \"%s\"."), fname); } sprintf(play_command, "%s", secfile_lookup_str(file, "Options.play_command")); sprintf(play_options, "%s", secfile_lookup_str(file, "Options.play_options")); sprintf(dir, "%s", secfile_lookup_str(file, "Options.dir")); printf("Using Soundfile: %s\n", secfile_lookup_str(file, "Options.name")); while (x < SOUND_UNITS) { sprintf(unit_sec_activate, "Unit-Names.%d", x); /* using unit_sec_activate to save memory as a temp var */ sprintf(unit_sounds[x].name, "%s", secfile_lookup_str(file, unit_sec_activate)); x++; } x = 0; while (x < SOUND_UNITS) { if (strcmp(unit_sounds[x].name, "")) { sprintf(unit_sec_activate, "%s.activate", unit_sounds[x].name); sprintf(unit_sec_move, "%s.move", unit_sounds[x].name); sprintf(unit_sec_attack, "%s.attack", unit_sounds[x].name); sprintf(unit_sec_special, "%s.special", unit_sounds[x].name); sprintf(unit_sec_destroyed, "%s.destroyed", unit_sounds[x].name); sprintf(unit_sounds[x].file[0], "%s", secfile_lookup_str(file, unit_sec_activate)); sprintf(unit_sounds[x].file[1], "%s", secfile_lookup_str(file, unit_sec_move)); sprintf(unit_sounds[x].file[2], "%s", secfile_lookup_str(file, unit_sec_attack)); sprintf(unit_sounds[x].file[3], "%s", secfile_lookup_str(file, unit_sec_special)); sprintf(unit_sounds[x].file[4], "%s", secfile_lookup_str(file, unit_sec_destroyed)); x++; } else { break ; } } x = 0; while (x < SOUND_EVENTS) { sprintf (unit_sec_activate, "events.%d", x); sprintf(event_sounds[x].file, "%s", secfile_lookup_str(file, unit_sec_activate)); /* using unit_sec_activate to save memory as a temp var */ x++; } section_file_check_unused(file, fname); section_file_free(file); freelog(LOG_VERBOSE, "finished reading %s", fname); is_parsed = 1;} void set_sound_config_file(const char *fname) { /* Specially made for all the modpack makers outside ;-) With this function it is also possible to change the soundspec file during the game */ strcpy(sound_config_file, fname); is_parsed = 0; }