Subversion Repositories Games.Chess Giants

Rev

Rev 11 | Rev 130 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. // audio.cpp
  2.  
  3. #include "common.h"
  4.  
  5.  
  6. // global variables used in this module only
  7. static int queued_sound = 0;
  8.  
  9.  
  10. void Audio_Think (void)
  11. {
  12.    // this function plays the queued sounds on the right time
  13.  
  14.    static wchar_t soundfile_path[MAX_PATH];
  15.    int sound_index;
  16.  
  17.    // do we have a sound to play ? if so, play it
  18.    if (queued_sound != 0)
  19.    {
  20.       // given the type of sound we want, enqueue the right one
  21.       if (queued_sound == SOUNDTYPE_CLICK)
  22.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/click.wav", app_path, theme->name);
  23.       else if (queued_sound == SOUNDTYPE_ILLEGALMOVE)
  24.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/illegal.wav", app_path, theme->name);
  25.       else if (queued_sound == SOUNDTYPE_VICTORY)
  26.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/win.wav", app_path, theme->name);
  27.       else if (queued_sound == SOUNDTYPE_DEFEAT)
  28.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/lose.wav", app_path, theme->name);
  29.       else if (queued_sound == SOUNDTYPE_CHECK)
  30.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/check.wav", app_path, theme->name);
  31.       else if (queued_sound == SOUNDTYPE_PIECETAKEN)
  32.          swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/take.wav", app_path, theme->name);
  33.       else if (queued_sound == SOUNDTYPE_MOVE)
  34.       {
  35.          sound_index = rand () % 6; // there are several movement sounds, pick one at random
  36.          if (sound_index == 0)
  37.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move1.wav", app_path, theme->name);
  38.          else if (sound_index == 1)
  39.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move2.wav", app_path, theme->name);
  40.          else if (sound_index == 2)
  41.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move3.wav", app_path, theme->name);
  42.          else if (sound_index == 3)
  43.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move4.wav", app_path, theme->name);
  44.          else if (sound_index == 4)
  45.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move5.wav", app_path, theme->name);
  46.          else
  47.             swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move6.wav", app_path, theme->name);
  48.       }
  49.  
  50.       PlaySound (soundfile_path, NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
  51.       queued_sound = 0; // play this sound then forget it
  52.    }
  53.  
  54.    return; // finished, audio has been handled
  55. }
  56.  
  57.  
  58. void Audio_PlaySound (int sound_type)
  59. {
  60.    // helper function to play a sound
  61.  
  62.    if (!options.want_sounds)
  63.       return; // if we want no sound, don't play anything
  64.  
  65.    queued_sound = sound_type; // enqueue the desired sound for playing
  66.    return; // finished
  67. }
  68.