// audio.cpp
 
 
 
#include "common.h"
 
 
 
 
 
// global variables used in this module only
 
static int queued_sound = 0;
 
 
 
 
 
void Audio_Think (void)
 
{
 
   // this function plays the queued sounds on the right time
 
 
 
   static wchar_t soundfile_path[MAX_PATH];
 
   int sound_index;
 
 
 
   // do we have a sound to play ? if so, play it
 
   if (queued_sound != 0)
 
   {
 
      // given the type of sound we want, enqueue the right one
 
      if (queued_sound == SOUNDTYPE_CLICK)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/click.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_ILLEGALMOVE)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/illegal.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_VICTORY)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/win.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_DEFEAT)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/lose.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_CHECK)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/check.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_PIECETAKEN)
 
         swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/take.wav", app_path, theme->name);
 
      else if (queued_sound == SOUNDTYPE_MOVE)
 
      {
 
         sound_index = rand () % 6; // there are several movement sounds, pick one at random
 
         if (sound_index == 0)
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move1.wav", app_path, theme->name);
 
         else if (sound_index == 1)
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move2.wav", app_path, theme->name);
 
         else if (sound_index == 2)
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move3.wav", app_path, theme->name);
 
         else if (sound_index == 3)
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move4.wav", app_path, theme->name);
 
         else if (sound_index == 4)
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move5.wav", app_path, theme->name);
 
         else
 
            swprintf_s (soundfile_path, WCHAR_SIZEOF (soundfile_path), L"%s/themes/%s/sounds/move6.wav", app_path, theme->name);
 
      }
 
 
 
      PlaySound (soundfile_path, NULL, SND_ASYNC | SND_FILENAME | SND_NODEFAULT);
 
      queued_sound = 0; // play this sound then forget it
 
   }
 
 
 
   return; // finished, audio has been handled
 
}
 
 
 
 
 
void Audio_PlaySound (int sound_type)
 
{
 
   // helper function to play a sound
 
 
 
   if (!options.want_sounds)
 
      return; // if we want no sound, don't play anything
 
 
 
   queued_sound = sound_type; // enqueue the desired sound for playing
 
   return; // finished
 
}