#include "scripts/common.txt"
#include "scripts/BP_common.txt"
#include "scripts/BP_MapCommon.txt"

//Tag IDs
//1000: Start Warp
//1001: 

array<kStr> statLines(5);
uint16 mapInputButtons = 0;
int page = 0;
//------------------------------------------------------------------------------------------------------------------------
// Start Map
//------------------------------------------------------------------------------------------------------------------------
$script 0
{
	StartMap();
	Game.StopMusic();

	Player.Actor().PlayerFlags() |= (1 << 30); //hide weapon
	Camera.StartCinematic(CMF_NO_LETTERBOX | CMF_LOCK_PLAYER | CMF_UNLOCK_PLAYER_ON_FINISH | CMF_NO_INITIAL_FADEOUT);
	Camera.ClearLookAtActor();
	Camera.ClearFinalView();
	Camera.ClearViewTracks();
	Camera.origin = Math::vecZero;
	Camera.yaw = 0.0f;
	Camera.pitch = 0.0f;
	Camera.roll = 0.0f;
	Camera.fov = 70.0f;
	Camera.lookZOffset = 0.0f;
	delay(0.5f);
	CheckNotStarted();
	
	delay(0.5f);
	page = 1;
	if (GetFeathers() < AdonFeathers)
	{
		page++;
	}
	ShowStats();
	
	// Game.PlaySound("sounds/shaders/explosion_3.ksnd");
	// delay(0.5f);
	// Game.PlaySound("sounds/shaders/generic_157.ksnd");
	// // bg.SetTexture(21); //show josh and adon
	// int msgTime = 360;
	// Game.PrintLine("", 0, msgTime);
	// Game.PrintLine("What was that?", 1, msgTime);
	// Game.PrintLine("------", 2, msgTime);
	// Game.PrintLine("Joshua", 3, msgTime);
	// delay(3.0f);
	// Game.PrintLine("The chronoscepter has been destroyed.", 0, msgTime);
	// Game.PrintLine("It seems we are too late, Joshua.", 1, msgTime);
	// Game.PrintLine("----", 2, msgTime);
	// Game.PrintLine("Adon", 3, msgTime);
	// delay(7.0f);
	// Game.PrintLine("", 0, msgTime);
	// Game.PrintLine("Damn, we were so close.", 1, msgTime);
	// Game.PrintLine("------", 2, msgTime);
	// Game.PrintLine("Joshua", 3, msgTime);
	// delay(4.0f);
	// ClearHUDMessages();
	// // bg.SetTexture(23); //show black
	// delay(1.0f);
	// // bg.SetTexture(22); //show primagen
	// Game.PlaySound("sounds/shaders/end04.ksnd");
	// delay(5.0f);
	// // bg.SetTexture(23); //show black
	// delay(2.0f);
	
	
	Game.PlayMusic("music/track01.ogg", true);
	// bg.SetTexture(24); //show credits
	Game.CallDelayedMapScript(1, instigator, 0); //Update Stat Screen
	
	if (GetPlayerCharacter() == PLAYER_CHAR_TUROK)
	{
		SetSysFlag(SYSFLAG_BEATTUROK, true);
	}
	else if (GetPlayerCharacter() == PLAYER_CHAR_ADON)
	{
		SetSysFlag(SYSFLAG_BEATADON, true);
	}
	
	if (GetFeathers() >= AdonFeathers)
	{
		SetUnlockCharacter(PLAYER_CHAR_ADON, true);
	}
	// if (GetFeathers() >= HummerFeathers)
	// {
		// SetUnlockCharacter(PLAYER_CHAR_HUMMER, true);
	// }
}
//------------------------------------------------------------------------------------------------------------------------
void PrintMessages(const kStr &in line1, const kStr &in line2, const kStr &in line3, const kStr &in line4, const int msgTime)
{
	Game.PrintLine(line4, 0, msgTime);
	Game.PrintLine(line3, 1, msgTime);
	Game.PrintLine(line2, 2, msgTime);
	Game.PrintLine(line1, 3, msgTime);
}
//------------------------------------------------------------------------------------------------------------------------
void SetStatScreenText(const kStr &in line1, const kStr &in line2, const kStr &in line3, const kStr &in line4, const kStr &in line5 = "")
{
	statLines[0] = line1;
	statLines[1] = line2;
	statLines[2] = line3;
	statLines[3] = line4;
	statLines[4] = line5;
}
void ShowStats()
{
	// bg.SetTexture(23); //show black
	Game.PlaySound("sounds/shaders/generic_216.ksnd");
	delay(0.2f);
	Game.PlaySound("sounds/shaders/longhunter_taunt_1.ksnd");
	SetStatScreenText(Game.GetLocalizedText(LTKey(21)) + " " + GetKills(),
						Game.GetLocalizedText(LTKey(22)) + " " + GetDeaths(),
						Game.GetLocalizedText(LTKey(23)) + " " + (GetDefensePickups() + GetSpeedPickups()) + " " + Game.GetLocalizedText(LTKey(7)) + " 11",
						Game.GetLocalizedText(LTKey(24)) + " " + (SpecialPickupCount()) + " " + Game.GetLocalizedText(LTKey(7)) + " 4",
						Game.GetLocalizedText("" + GetFeathers() + " " + Game.GetLocalizedText(LTKey(29)))
						);
}
//------------------------------------------------------------------------------------------------------------------------
// Update Stat Screen
//------------------------------------------------------------------------------------------------------------------------
$script 1
{
	for (int i = 0; i < 5; i++)
	{
		Game.PrintLine(statLines[4 - i], i, 30);
	}
	
	mapInputButtons = InputUpdate(mapInputButtons);
	if (InputAttackDown() || InputJumpDown())
	{
		page++;
		if (page == 1)
		{
			ShowStats();
		}
		else if (page == 2)
		{
			Game.PlaySound("sounds/shaders/adon_unlock.ksnd");
			SetStatScreenText("", "", LTKey(31), "");
		}
		else if (page == 3)
		{
			SetStatScreenText("", "", "", "");
			Game.StopMusic();
			delay(1.0f);
			Camera.StopCinematic();
			Player.Actor().PlayerFlags() &= ~(1 << 30); //unhide weapon
			PlayLoop.StartWarp(Player.Actor().CastToActor(), 1000, 115);
			return;
		}
	}
	
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
