#include "main.h"
#include "global.h"

#include "sound.h"
#include "charactr.h"

#include "loadsnd.h"

// CPW: SfxBankType *pSfxGenericBank = NULL;
//SfxBankType *pSfxLevelBank = NULL;
//int sfxBankNumber = -1;

SfxSampleType	*pSamples[LOADSND_MAXSAMPLES];

int loadsndLoadBank(char *sLevelName)
{
/*	if(!pSfxGenericBank)
	{
		pSfxGenericBank = (SfxBankType *)soundLoadBodyAndHeader("GENERIC");

		DB("sfx = %p\n", pSfxGenericBank);
		ASSERT(0);

		loadsndSetUpGeneric();
	}
*/
	if(sLevelName)
	{
// The "sfxBankType" (SBH) is part of the BFF, and will be linked in during BFF_Load
// (Consequently, it's important that SBB files and SBH's in the BFF match up)
// (see BFF_Load, and soundLinkBFF)


		soundLoadJustBody(sLevelName);
/*
		if(pSfxLevelBank)
		{
			sfxUnloadSampleBank(pSfxLevelBank);
			sfxRemoveSampleBank(pSfxLevelBank, 1);
		}
		pSfxLevelBank = (SfxBankType *)soundLoadBodyAndHeader(sLevelName);
*/
	}

	return 0;
}

int loadsndKillBanks(void)
{
/*	if(pSfxGenericBank)
	{
		sfxUnloadSampleBank(pSfxGenericBank);
		sfxDestroySampleBank(pSfxGenericBank);
		pSfxGenericBank = NULL;
	}
*/

// The level bank gets freed during BFF_ReleaseFile
// (see BFF_ReleaseFile, and soundUnlinkBFF)
/*
	if(pSfxLevelBank)
	{
		sfxUnloadSampleBank(pSfxLevelBank);
		sfxDestroySampleBank(pSfxLevelBank);
		pSfxLevelBank = NULL;
	}
*/


	return 0;
}

SfxSampleType *loadsndGetSample(SfxSampleType **ppS, int offset, char *sName)
{
	SfxSampleType *pS;

	ASSERT(offset < LOADSND_MAXSAMPLES);

	pS = sfxFindSampleInAllBanks(sName);
	if(!pS)
	{
		DB(" *** I can't find the sample that goes by the name of '%s'\n", sName);
	}

// CPW: 	ASSERT(pS);

	ppS[offset] = pS;

	return pS;
}

int loadsndSetUpGeneric(void)
{
/*
	loadsndGetSample(pSamples, SFX_GINGER_JUMP,			"gljump1b");
	loadsndGetSample(pSamples, SFX_GINGER_LAND,			"glland");
	loadsndGetSample(pSamples, SFX_GINGER_FOOTSTEP,		"glfootl");
	loadsndGetSample(pSamples, SFX_GINGER_DOUBLEJUMP,	"glrjump2");

	loadsndGetSample(pSamples, SFX_DOG_BARK1,			"dog_bark1");
	loadsndGetSample(pSamples, SFX_DOG_BARK2,			"dog_bark2");
	loadsndGetSample(pSamples, SFX_DOG_BARK3,			"dog_bark3");
	loadsndGetSample(pSamples, SFX_DOG_GROWL1,			"dog_growl1");
	loadsndGetSample(pSamples, SFX_DOG_GROWL2,			"dog_growl2");
	loadsndGetSample(pSamples, SFX_DOG_WHIMPER1,		"dog_whimper1");
	loadsndGetSample(pSamples, SFX_DOG_WHIMPER2,		"dog_whimper2");
*/

	loadsndGetSample(pSamples, SFX_SUCKER,				"sucker");
	loadsndGetSample(pSamples, SFX_TESTLOOP,			"n512");// CPW: middle C sine wave

	return 0;
}

SfxSampleType **loadsndSetUpEnemy(int ch)
{
	// CPW: don't forget to free this at the end of the level
	SfxSampleType **pCharS = (SfxSampleType **)MALLOC(sizeof(SfxSampleType *) * MAX_CHAR_SFX);
	int i;

	ASSERT(pCharS);

	DB("Setting up enemy %d sounds...\n", ch);

	for(i=0; i<MAX_CHAR_SFX; i++)
		pCharS[i] = NULL;

	switch(ch)
	{
	case ENEMY_MRST_PATROL:
	case ENEMY_MRST_CLIP_PATROL:
		pCharS[ENEMY_SFX_MRSTMINISCULE] =	loadsndGetSample(pSamples, SFX_MRSTMINISCULE,	"minisculeprofits");
		pCharS[ENEMY_SFX_MRSTCHICKENS] =	loadsndGetSample(pSamples, SFX_MRSTCHICKENS,	"mrstchickens");
		pCharS[ENEMY_SFX_MRSTCHICKENS2] =	loadsndGetSample(pSamples, SFX_MRSTCHICKENS2,	"mrstchickens2");	
//		pCharS[ENEMY_SFX_MRSTFOOTSTPS1] =	loadsndGetSample(pSamples, SFX_MRSTFOOTSTPS1,	"mrstfootstps1");	
//		pCharS[ENEMY_SFX_MRSTFOOTSTPS2] =	loadsndGetSample(pSamples, SFX_MRSTFOOTSTPS2,	"mrstfootstps2");	
//		pCharS[ENEMY_SFX_MRSTFOOTSTPS3] =	loadsndGetSample(pSamples, SFX_MRSTFOOTSTPS3,	"mrstfootstps3");

		break;

	case ENEMY_SLEEPYDOG:
	case ENEMY_DOG:
		pCharS[ENEMY_SFX_DOGBARK1] =		loadsndGetSample(pSamples, SFX_DOGBARK1,		"dogbark1");
		pCharS[ENEMY_SFX_DOGBARK2] =		loadsndGetSample(pSamples, SFX_DOGBARK2,		"dogbark2");
		pCharS[ENEMY_SFX_DOGBARK3] =		loadsndGetSample(pSamples, SFX_DOGBARK3,		"dogbark3");	
//		pCharS[ENEMY_SFX_DOGGROWLBIG] =		loadsndGetSample(pSamples, SFX_DOGGROWLBIG,		"doggrowlbig");	
		pCharS[ENEMY_SFX_DOGGROWLS1] =		loadsndGetSample(pSamples, SFX_DOGGROWLS1,		"doggrowls1");	
		pCharS[ENEMY_SFX_DOGGROWLS2] =		loadsndGetSample(pSamples, SFX_DOGGROWLS2,		"doggrowls2");	
		pCharS[ENEMY_SFX_DOGSCRATCH1] =		loadsndGetSample(pSamples, SFX_DOGSCRATCH1,		"dogscratch1");	
//		pCharS[ENEMY_SFX_DOGSCRATCH2] =		loadsndGetSample(pSamples, SFX_DOGSCRATCH2,		"dogscratch2");	
		pCharS[ENEMY_SFX_DOGSKIDS] =		loadsndGetSample(pSamples, SFX_DOGSKIDS,		"dogskids");	
		pCharS[ENEMY_SFX_DOGSNIFFS1] =		loadsndGetSample(pSamples, SFX_DOGSNIFFS1,		"dogsniffs1");	
		pCharS[ENEMY_SFX_DOGSNIFFS2] =		loadsndGetSample(pSamples, SFX_DOGSNIFFS2,		"dogsniffs2");	
		pCharS[ENEMY_SFX_DOGSNORES1] =		loadsndGetSample(pSamples, SFX_DOGSNORES1,		"dogsnores1");	
//		pCharS[ENEMY_SFX_DOGWALKS1] =		loadsndGetSample(pSamples, SFX_DOGWALKS1,		"dogwalks1");	
//		pCharS[ENEMY_SFX_DOGWALKS2] =		loadsndGetSample(pSamples, SFX_DOGWALKS2,		"dogwalks2");	
		pCharS[ENEMY_SFX_DOGWHIMPER1] =		loadsndGetSample(pSamples, SFX_DOGWHIMPER1,		"dogwhimper1");	
//		pCharS[ENEMY_SFX_DOGWHIMPER2] =		loadsndGetSample(pSamples, SFX_DOGWHIMPER2,		"dogwhimper2");	
		pCharS[ENEMY_SFX_DOGYAWNS1] =		loadsndGetSample(pSamples, SFX_DOGYAWNS1,		"dogyawns1");	
//		pCharS[ENEMY_SFX_DOGYELPS1] =		loadsndGetSample(pSamples, SFX_DOGYELPS1,		"dogyelps1");	

		break;

	case ENEMY_MRT_TORCH:
	case ENEMY_MRT_PATROL:
		pCharS[ENEMY_SFX_MRTINMEHEAD] =			loadsndGetSample(pSamples, SFX_MRTINMEHEAD,		"inmehead");
		pCharS[ENEMY_SFX_MRTHUH1] =				loadsndGetSample(pSamples, SFX_MRTHUH1,			"mrt_huh1");
//		pCharS[ENEMY_SFX_MRTSTEP] =				loadsndGetSample(pSamples, SFX_MRTSTEP,			"mrt_step");	
		pCharS[ENEMY_SFX_MRTNOCHICKESCAPES] =	loadsndGetSample(pSamples, SFX_MRTNOCHICKESCAPES,"nochikescapes");	
		pCharS[ENEMY_SFX_MRTTHIEVEBUGGRS] =		loadsndGetSample(pSamples, SFX_MRTTHIEVEBUGGRS,	"thievebuggrs");

	}

	DB("Seems to have completed OK\n");

	return(pCharS);
}

SfxSampleType **loadsndSetUpCharacter(int ch)
{
	// CPW: don't forget to free this at the end of the level
	SfxSampleType **pCharS = (SfxSampleType **)MALLOC(sizeof(SfxSampleType *) * MAX_CHAR_SFX);
	int i;

	ASSERT(pCharS);

	DB("Setting up character %d sounds...\n", ch);

	for(i=0; i<MAX_CHAR_SFX; i++)
		pCharS[i] = NULL;

	switch(ch)
	{
	case CHAR_NAME_GINGER:
		pCharS[CHAR_SFX_DOUBLEJUMP] =	loadsndGetSample(pSamples, SFX_GINGERDBLEJUMP1,		"gingerexert2");
		pCharS[CHAR_SFX_EXERT1] =		loadsndGetSample(pSamples, SFX_GINGEREXERT1,		"gingerexert1");
		pCharS[CHAR_SFX_JUMP1] =		loadsndGetSample(pSamples, SFX_GINGERJUMP1,			"gingerexert2");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_GINGERLAND,			"gingerland");
		pCharS[CHAR_SFX_PUSH] =			loadsndGetSample(pSamples, SFX_GINGERPUSH1,			"gingerpush1");
//		pCharS[CHAR_SFX_STEP1] =		loadsndGetSample(pSamples, SFX_GINGERSTEP,			"gingerstep");
		pCharS[CHAR_SFX_THROW] =		loadsndGetSample(pSamples, SFX_GINGERTHROW,			"gingerjump1");
		pCharS[CHAR_SFX_PICKUPTALK] =	loadsndGetSample(pSamples, SFX_GINGERPICKUPTALK,	"whats_this");

		break;
	
	case CHAR_NAME_ROCKY:
		pCharS[CHAR_SFX_EXERT1] =		loadsndGetSample(pSamples, SFX_ROCKYEXERT1,			"rockyexert1");
		pCharS[CHAR_SFX_JUMP1] =		loadsndGetSample(pSamples, SFX_ROCKYJUMP1,			"rockyjump1");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_ROCKYLAND,			"rockyland");
//		pCharS[CHAR_SFX_STEP1] =		loadsndGetSample(pSamples, SFX_ROCKYSTEP,			"rockystep");
		pCharS[CHAR_SFX_DOUBLEJUMP] =	pCharS[CHAR_SFX_JUMP1];
		pCharS[CHAR_SFX_THROW] =		loadsndGetSample(pSamples, SFX_ROCKYTHROW,			"rockyjump1");
		pCharS[CHAR_SFX_PICKUPTALK] =	loadsndGetSample(pSamples, SFX_ROCKYPICKUPTALK,		"how_about_that");
		break;

	case CHAR_NAME_NICK:
		pCharS[CHAR_SFX_JUMP1] =		loadsndGetSample(pSamples, SFX_NICKJUMP,			"nickhup");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_NICKLAND,			"nickland");
		pCharS[CHAR_SFX_PUSH] =			loadsndGetSample(pSamples, SFX_NICKPUSH1,			"nickpush1");
//		pCharS[CHAR_SFX_STEP1] =		loadsndGetSample(pSamples, SFX_NICKSTEP,			"nickstep");
		pCharS[CHAR_SFX_PICKUPTALK] =	loadsndGetSample(pSamples, SFX_NICKPICKUPTALK,		"here_it_is");

		break;

	case CHAR_NAME_FETCHER:
		pCharS[CHAR_SFX_DOUBLEJUMP] =	loadsndGetSample(pSamples, SFX_FETCHDBLEJUMP,		"fetcherhup");
		pCharS[CHAR_SFX_EXERT1] =		loadsndGetSample(pSamples, SFX_FETCHEXERT,			"fletchexert");
		pCharS[CHAR_SFX_JUMP1] =		loadsndGetSample(pSamples, SFX_FETCHJUMP,			"fetcherhup");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_FETCHLAND,			"fletchland");
		pCharS[CHAR_SFX_PUSH] =			loadsndGetSample(pSamples, SFX_FETCHPUSH1,			"fletchpush1");
//		pCharS[CHAR_SFX_STEP1] =		loadsndGetSample(pSamples, SFX_FETCHSTEP,			"fletchstep");
		pCharS[CHAR_SFX_PICKUPTALK] =	loadsndGetSample(pSamples, SFX_FETCHPICKUPTALK,		"oh_look");
		break;


/*
		pCharS[CHAR_SFX_DOUBLEJUMP] =	loadsndGetSample(pSamples, SFX_NICKJUMP,			"fletchdblejump");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_NICKLAND,			"fletchexert");
		pCharS[CHAR_SFX_JUMP1] =		loadsndGetSample(pSamples, SFX_NICKPUSH1,			"fetcherhup");
		pCharS[CHAR_SFX_LAND] =			loadsndGetSample(pSamples, SFX_NICKSTEP,			"fletchland");
		pCharS[CHAR_SFX_PUSH] =			loadsndGetSample(pSamples, SFX_NICKSTEP,			"fletchpush1");
//		pCharS[CHAR_SFX_STEP1] =		loadsndGetSample(pSamples, SFX_NICKSTEP,			"fletchstep");
		pCharS[CHAR_SFX_PICKUPTALK] =	loadsndGetSample(pSamples, SFX_NICKPICKUPTALK,		"oh_look");
*/

	}

	DB("Seems to have completed OK\n");

	return(pCharS);
}


/*
	SFX_FOWLER_BRONZE,
	SFX_FOWLER_SILVER,
	SFX_FOWLER_GOLD,
	SFX_FOWLER_FAIL,
	NUM_SFX_FOWLER_SAMPLES,
*/

SfxSampleType *fowlerSubGameSample[NUM_SFX_FOWLER_SAMPLES];






