//Copyright (C) 2007 SiegeLord
//See ReadMe.txt and License.txt for copying information

#include "neonz.h"
#include "sounds.h"
#include "camera.h"

SSoundFile* g_sndButtonSound;
SSoundFile* g_sndRocketFire;
SSoundFile* g_sndPlasmaFire;
SSoundFile* g_sndExplosion;
SSoundFile* g_sndBeam;

void InitSounds()
{
	g_sndRocketFire = FindSound("rocket_launch.ogg");
	g_sndPlasmaFire = FindSound("plasma_launch.ogg");
	g_sndButtonSound = FindSound("button.ogg");
	g_sndExplosion = FindSound("explosion.ogg");
	g_sndBeam = FindSound("beam.ogg");
}

SSound* PlayButtonSound()
{
	return PlaySound(g_sndButtonSound, false);
}

int SSoundHolder::Handle()
{
	if(sound)
	{
		if(sound->marked_for_stop)
		{
			dead = true;
			sound = 0;
			return 0;
		}
		vector2d pos = position;
		if(target_object)
			target_object->net_transform.TransformVector(&pos);
		else
			pos = GetGlobalPosition();
		UpdateSoundParams(sound, pos);
	}
	return 0;
}

SSoundHolder* CreateRocketFireSound(SObjectEx* parent, SObject* target_object)
{
	SSoundHolder* sound = new SSoundHolder();
	InitObject(sound, parent);
	sound->target_object = target_object;
	sound->sound = PlaySound(g_sndRocketFire, false);

	return sound;
}

SSoundHolder* CreatePlasmaFireSound(SObjectEx* parent, SObject* target_object)
{
	SSoundHolder* sound = new SSoundHolder();
	InitObject(sound, parent);
	sound->target_object = target_object;
	sound->sound = PlaySound(g_sndPlasmaFire, false);

	return sound;
}

SSoundHolder* CreateExplosionSound(SObjectEx* parent, SObject* target_object)
{
	SSoundHolder* sound = new SSoundHolder();
	InitObject(sound, parent);
	sound->target_object = target_object;
	sound->sound = PlaySound(g_sndExplosion, false);

	return sound;
}

SSoundHolder* CreateBeamFireSound(SObjectEx* parent, SObject* target_object)
{
	SSoundHolder* sound = new SSoundHolder();
	InitObject(sound, parent);
	sound->target_object = target_object;
	sound->sound = PlaySound(g_sndBeam, false);

	return sound;
}
