///////////////////////////////////////////////////////////////////////////////////////
// -- VOICE SCRIPT AND CLASS SWITCH SCRIPTS, WILL BE ADDED SOON -- //
///////////////////////////////////////////////////////////////////////////////////////

///////////////////////////////////
// - VOICE CHANGE SCRIPT ------- //
/////////////////////////////////////////////////////////////
// - Credit to TMC and ZzZombo for helping with this //
/////////////////////////////////////////////////////////////

#library "VOICES"
#include "zcommon.acs"
#import "zt2functions.acs"

#define VOICE_COUNT 5

//-- SCOPES IN USE: ----------------
// 1-17
// 20-27
// 30-43
// 44-49 <-- VOICES
// 50-60

#define MAX_VOICES 100

// Names of the voicepacks
str voiceNames[MAX_VOICES];
// Reloading sounds
str voiceSoundReload[MAX_VOICES];
// Taunt
str voiceSoundTaunt[MAX_VOICES];
// Pain
str voiceSoundPain[MAX_VOICES];
// How long each taunt takes
int voiceTauntTimes[MAX_VOICES];
// How many voicepacks we actually have
int voicePackCount;

// -- VARIABLES --

#define VOICE_ID			385
#define SECTION_ID			390
#define SECTION_BG_ID		400

// How many voices on either side of the selection to display
#define SECTION_PADDING		2

// -- VOICE SYSTEM FUNCTIONS -----------------------------------------------------

// Add a new voice
// Name, Reload Sound, Taunt Sound, Pain Sound, Taunt Time
function void AddVoicepack(str vName, str sReload, str sTaunt, str sPain, int tTime)
{
	voiceNames[voicePackCount] = vName;
	voiceSoundReload[voicePackCount] = sReload;
	voiceSoundTaunt[voicePackCount] = sTaunt;
	voiceSoundPain[voicePackCount] = sPain;
	voicePackCount ++;
}

// Remove all voicepacks
function void ClearVoicepacks(void)
{
	voicePackCount = 0;
}

function void CompileSection(int Selected)
{
	// str sectionString = "\cDAvailable Voicepacks:\n\n";
	str color = "\cM";
	str pic = "VOICEBLK";
	int startX, startY;
	int sectionHeight;
	int counter;
	
	int adder;
	int totalHeight;
	
	totalHeight = (SECTION_PADDING*2)+1;
	
	counter = 0;
	
	startX = 0.0;
	startY = FixedMul(CheckInventory("ResolutionY")*1.0,0.25);
	
	sectionHeight = 26.0 * totalHeight;
	startY = startY - FixedDiv(sectionHeight,2.0);
	
	sectionHeight = 26.0;
	
	if (Selected == 0)
		adder = totalHeight-1;
	else if (Selected == 1)
		adder = totalHeight-2;
	else
		adder = SECTION_PADDING;
	
	for (int l=Selected-SECTION_PADDING; l<=Selected+adder; l++)
	{
		SetFont(pic);
		HMUSRedux(startX, startY+(sectionHeight*counter), "", 0, 1, SECTION_BG_ID+counter, 2.0, 0);
		SetFont("BIGFONT");
		HMUSRedux(startX+16.0, startY+(sectionHeight*counter), "", 0, 1, SECTION_ID+counter, 2.0, 0);
		SetFont("SMALLFONT");
		
		if (l >= voicePackCount)
			break;
		
		if (l < 0)
			continue;
			
		if (l == Selected)
		{
			color = "\cK";
			pic = "VOICERED";
		}
		else
		{
			color = "\cM";
			pic = "VOICEBLK";
		}
		
		SetFont(pic);
		HMUSRedux(startX, startY+(sectionHeight*counter), "a", 0, 1, SECTION_BG_ID+counter, 2.0, 0);
		SetFont("BIGFONT");
		HMUSRedux(startX+16.0, startY+(sectionHeight*counter), StrParam(s:color,d:l,s:".) ",s:voiceNames[l]), 0, 1, SECTION_ID+counter, 2.0, 0);
		SetFont("SMALLFONT");
		
		counter ++;
	}
}

//----------------------------------

// Add the actual voices
script 817 OPEN
{
	// BO2 Merc
	AddVoicepack("CoD:BO2 (Merc)","merc/reload","merc/taunt","merc/pain",70);
	// KF Male
	AddVoicepack("Killing Floor (Human)","kfmale/reload","kfmale/taunt","kfmale/pain",70);
	// KF D.A.R.
	AddVoicepack("Killing Floor (D.A.R.)","dar/reload","dar/taunt","dar/pain",70);
	// Cod:MW American
	AddVoicepack("CoD:MW (American)","usa/reload","usa/taunt","rga/pain",70);
	// CoD:WAW German
	AddVoicepack("CoD:WAW (German)","german/reload","german/taunt","german/pain",140);
}

// Can be puked via the console, what is this even
script 818 (int casing) NET CLIENTSIDE
{
	switch (casing)
	{
		case 0:
		ACS_ExecuteAlways(819,0,0,0,0);
		break;

		case 1:
		ACS_ExecuteAlways(820,0,0,0,0);
		break;

		case 2:
		ACS_ExecuteAlways(820,0,1,0,0);
		break;

		case 3:
		ACS_ExecuteAlways(820,0,2,0,0);
		break;
	}
}

// -- CHANGE VOICES --
script 819 (void) NET
{
			// Actually control the junk
			if (CheckInventory("PlayerVoice") < voicePackCount-1)
				GiveInventory("PlayerVoice",1);
			else
				TakeInventory("PlayerVoice",99);

			// Show a message
			SetFont("BIGWRITR");
			HudMessage(s:"\cKVoice changed:\n\cD",s:voiceNames[CheckInventory("PlayerVoice")];HUDMSG_FADEOUT,VOICE_ID,CR_WHITE,1.5,0.8,2.0,0.5);
			SetFont("BIGFONT");
			
			CompileSection(CheckInventory("PlayerVoice"));
			
			int SH = Round(FixedMul(CheckInventory("ResolutionY")*1.0,0.25));
			
			// HMUSRedux(96.0, SH*1.0, sectionString, 0, 1, SECTION_ID, 2.0,0);
			SetFont("SMALLFONT");
			
			// Play a sample sound
			LocalAmbientSound(voiceSoundReload[CheckInventory("PlayerVoice")],127);
			
			SetCVarString("cl_zt2voice",voiceNames[CheckInventory("PlayerVoice")]);
}

// -- CALLED FROM TAUNTING AND THINGS --
script 820 (int args) NET
{
	ACS_ExecuteAlways(821,0,args,0,0);
}

//-- PLAY THE ACTUAL SOUND --
script 821 (int soundmode)
{
	int voice;
	int value;

	value = GetCVar("cl_noreloadsound");
	voice = CheckInventory("PlayerVoice");

	switch (soundmode)
	{
			//-- RELOAD --
			case 0:
				// If cl_noreloadsound is 0...
				if (!value)
					ActivatorSound(voiceSoundReload[voice],127);
			break;

			//-- TAUNT --
			case 1:
				if (!CheckInventory("TauntTimer"))
				{
					ActivatorSound(voiceSoundTaunt[voice],127);
					GiveInventory("TauntTimer",voiceTauntTimes[voice]);
				}
			break;

			// -- PAIN --
			case 2:
					ActivatorSound(voiceSoundPain[voice],127);
			break;
	}
}