#include "audio.h"

CAudio::CAudio() : m_pSoundEngine(createIrrKlangDevice()), m_pMusicEngine(createIrrKlangDevice()),
m_pBrakeChargeEngine(createIrrKlangDevice())
{	
	std::cout << "ThriceBall Log: Created Audio" << std::endl;	// for the log
}

void CAudio::playMusic(String name)
{
	String fileName = "media/music/" + name + ".ogg";
	m_pMusicEngine->play2D(fileName.c_str(), true);
}

void CAudio::setVolumes(int sound, int music)
{
	float fSound = float(sound) / 100.f;
	float fMusic = float(music) / 100.f;

	// set the volumes
	m_pSoundEngine->setSoundVolume(fSound);
	m_pMusicEngine->setSoundVolume(fMusic);
}

void CAudio::playSound(int num)
{
	String sRandom = StringConverter::toString(Ogre::Math::RangeRandom(1,5),1);
	String sShotSound = "media/sounds/shot" + sRandom + ".ogg";

	switch (num)
	{
	case 0: // shot sound
		m_pSoundEngine->play2D(sShotSound.c_str());
		break;
	case 1: // death sound
		m_pSoundEngine->play2D("media/sounds/death.ogg"); 
		break;
	case 2: // checkpoint sound
		m_pSoundEngine->play2D("media/sounds/checkpoint.ogg"); 
		break;
	case 3: // no way sound
		m_pSoundEngine->play2D("media/sounds/noway.ogg"); 
		break;
	case 4:	// heartbeat sound
		if (!m_pSoundEngine->isCurrentlyPlaying("media/sounds/heartbeat.ogg"))
		{
			m_pSoundEngine->play2D("media/sounds/heartbeat.ogg");
			m_pMusicEngine->setSoundVolume(m_pMusicEngine->getSoundVolume() * 0.9f);
		}
		break;
	case 5: // drain sound
		if (!m_pSoundEngine->isCurrentlyPlaying("media/sounds/drain.ogg"))
			m_pSoundEngine->play2D("media/sounds/drain.ogg"); 
		break;
	default: break;
	}
}