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

//Tag IDs
//1000: Start Warp
//2003: Save Point
//2005: Checkpoint 1
//2006: Checkpoint 2
//1001: Trap Floor 1
//1002: WD Warp 1
//1003: WD Warp 2
//1004: SD Warp 1
//1005: SD Warp 2
//1006: SD Platform 1
//1007: SD Platform 2
//1008: FW Warp 1
//1009: FW Warp 2
//1010: Sound Robot Warning
//1011: FW Reached first
//1012: 

float musicDelay;
kActor@ fwPart1;
bool isPlayingMusic;
bool lastUnderWater;
//------------------------------------------------------------------------------------------------------------------------
// Start Map
//------------------------------------------------------------------------------------------------------------------------
$script 0
{
	StartMap();
	isPlayingMusic = false;
	@fwPart1 = World.GetActorByTID(1011);
	Game.CallDelayedMapScript(1, instigator, 0); //Update Map	
}
//------------------------------------------------------------------------------------------------------------------------
// Update Map
//------------------------------------------------------------------------------------------------------------------------
$script 1
{
	TickMap();
	
	const int areaID = Player.Actor().AreaID();
	
	//Restore music after exiting water
	int areaFlags = World.GetAreaFlags(areaID);
	bool underWater = Player.Actor().GetWaterLevel() == WLT_UNDER && (areaFlags & AAF_ANTIGRAVITY) == 0;
	if (!underWater && lastUnderWater && isPlayingMusic)
	{
		Game.PlayMusic("music/track13.ogg", true);
	}
	
    int arg6 = World.GetAreaArg(areaID, 5);
	if (arg6 != 32000)
	{
		if (musicDelay <= 0.0f)
		{
			if (!isPlayingMusic)
			{
				isPlayingMusic = true;
				Game.PlayMusic("music/track13.ogg", true);
			}
			//PlayWavMusic("music_rage.ksnd");
		}
		else
		{
			musicDelay -= GAME_DELTA_TIME;
		}
	}
	else
	{
		if (isPlayingMusic)
		{
			isPlayingMusic = false;
			Game.StopMusic();
		}
		//StopWavMusic();
		musicDelay = 2.0f;
	}
	lastUnderWater = underWater;

	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Local Teleport 1
//------------------------------------------------------------------------------------------------------------------------
$script 10000
{
	if (Player.Actor().OnGround())
		PlayLoop.StartWarp(Player.Actor().CastToActor(), 1004, 107);
	//WarpWithMusic(1004, true);
}
//------------------------------------------------------------------------------------------------------------------------
// Local Teleport 2
//------------------------------------------------------------------------------------------------------------------------
$script 10001
{
	if (Player.Actor().OnGround())
		PlayLoop.StartWarp(Player.Actor().CastToActor(), 1003, 107);
	//WarpWithMusic(1003, true);
}
//------------------------------------------------------------------------------------------------------------------------
// Local Teleport 3
//------------------------------------------------------------------------------------------------------------------------
$script 10002
{
	if (Player.Actor().OnGround())
		PlayLoop.StartWarp(Player.Actor().CastToActor(), 1008, 107);
	//WarpWithMusic(1008, true);
}
//------------------------------------------------------------------------------------------------------------------------
// Local Teleport 4
//------------------------------------------------------------------------------------------------------------------------
$script 10003
{
	if (fwPart1.IsPersistentMarked())
	{
		if (Player.Actor().OnGround())
			PlayLoop.StartWarp(Player.Actor().CastToActor(), 1005, 107);
		//WarpWithMusic(1005, true);
	}
}
//------------------------------------------------------------------------------------------------------------------------
