#include "scripts/common.txt"
#include "scripts/bp_common.txt"
#include "scripts/main.txt"
#include "scripts/map/common_level_script.txt"

bool gotFirstKey = false;
bool triggeredKeyPlate = false;
kActor @keyLaser;
kActor @keyPressurePlate;
kActor @keyForceField;
kActor @keyButtonForceField;

kActor @challengeTotem;
kActor @monkeyActor;
kActor @monkeyActor2;
kActor @monkeyActor3;
//------------------------------------------------------------------------------------------------------------------------
$script 0 {
	World.ChangeAreaArg(35, 4, 5);
	World.ChangeAreaArg(35, 5, 256);
	World.ChangeAreaFlag(35, AAF_DAMAGE, true);

	World.ChangeAreaFlag(89, AAF_WATER, true);
	World.ChangeAreaWaterHeight(89, 1300.0f);
	
	World.ChangeAreaFlag(90, AAF_WATER, true);
	World.ChangeAreaWaterHeight(90, 1300.0f);
	
	World.ChangeAreaFlag(209, AAF_DAMAGE, true);
	World.ChangeAreaArg(209, 4, 5);
	World.ChangeAreaArg(209, 5, 256);

	//Areas with chrono piece
	// World.ChangeAreaFlag(25, AAF_CRAWL, true);
	World.ChangeAreaFlag(27, AAF_CRAWL, true);
	// World.ChangeAreaFlag(56, AAF_CRAWL, true);
	World.ChangeAreaFlag(63, AAF_CRAWL, true);
	World.ChangeAreaFlag(64, AAF_CRAWL, true);	

	MapSpawnItem("LifeForce_1", -2313, -3594, 1302);
	MapSpawnItem("LifeForce_1", -2313, -3594, 1002);
	MapSpawnItem("LifeForce_1", -2313, -3594, 702);
	
	MapSpawnItem("LifeForce_1", -1362, -3594, 1302);
	MapSpawnItem("LifeForce_1", -1362, -3594, 1002);
	MapSpawnItem("LifeForce_1", -1362, -3594, 702);

	ActorFactory.Spawn("Emitter_Misc2", -1832, -6116, 410, 0, 0);
	ActorFactory.Spawn("Emitter_Misc2", -1832, -6116, 410, 0, 0);
	
	ActorFactory.Spawn("ShopPoint", 3686, -8045, 1025, Math::Deg2Rad(90), 0); //Spawn Shop Portal
	
	SpawnMonkey(0, 1701, -9493, 924, 90);
	SpawnMonkey(1, 1053, -12241, 1536, -90);
	SpawnMonkey(2, 2125, -8051, 921, 90);
	SpawnMonkey(3, 5295, -8058, 1228, 180);
	SpawnMonkey(5, -5796, -7772, 665, 0);
	SpawnMonkey(6, -5622, -6883, 1638, 40);
	SpawnMonkey(7, -4539, -260, 2655, 90);
	SpawnMonkey(8, -5681, 586, 2508, 0);
	SpawnMonkey(9, -9001, 1822, 2764, -90);
	SpawnMonkey(10, 1564, 6236, 0, 125);
	
	SpawnSolidActor("BPDetail-Tree5", 681, -10540, 921);

	//knife challenge totem
	@challengeTotem = SpawnSolidActor("BPChallengeTotemKnife", -2061, -6492, 716, Math::Deg2Rad(90));
	
	//knife challenge stone
	if (!HasUpgradeKnife()) {
		SpawnSolidActor("BPChallengeKeyKnife", -1517, -4667, 563);
		SpawnActor("BP_WallForceField", -1710, -6813, 722);
		SpawnActor("BP_WallForceField", -1966, -6813, 722);
	}
	
	if (!HasChallengeKey(2)) {
		SpawnSolidActor("BPChallengeKeyBow", -4492, -8619, 665, 3068);
	}
	SpawnSolidActor("BPChallengeTotemBow", -8476, 1303, 2068, 2031, Math::Deg2Rad(90));
		
	//beams in hallway with raptors and warp at end
	MapSpawnBeamTrapHorzY(kVec3(5803, -8197, 1240), kVec3(7011, -8197, 1240), 4.0f, 0);
	MapSpawnBeamTrapHorzY(kVec3(7011, -8197, 1240), kVec3(5803, -8197, 1240), 4.0f, 0);
	MapSpawnBeamTrapHorzY(kVec3(6211, -8197, 1350), kVec3(6803, -8197, 1350), 2.5f, 0);
	MapSpawnBeamTrapVert(kVec3(6147, -8140, 1228), kVec3(6147, -7952, 1228), 1.0f, 0);
	MapSpawnBeamTrapVert(kVec3(6764, -7952, 1228), kVec3(6764, -8140, 1228), 1.0f, 0);
	
	//Falling Rock left of first key
	ActorFactory.Spawn("BP_FallingRocks", 463, -8398, 900, 0, 0);

	ActorFactory.Spawn("BP_FallingRocks", -2010, -6128, 409, 0, 0);
	ActorFactory.Spawn("BP_FallingRocks", -1840, -4375, 160, 0, 0);

	ActorFactory.Spawn("BP_SpikeFence", -2103, -3981, 357, 0, 0);
	kActor @fenceSpike2 = ActorFactory.Spawn("BP_SpikeFenceLarge", -1631, -4233, 357, 0, 0);
	fenceSpike2.Yaw() = Math::Deg2Rad(-90);	
	
	ActorFactory.Spawn("Emitter_BP_Fire_Tall2", -1840, -3441, 358, 0, 0);
	@keyLaser = ActorFactory.Spawn("DummyActor", -1840, -8190, 919, 0, 0);
	
	//forcefield around key
	@keyForceField = ActorFactory.Spawn("BP_ForceField", -1840, -8190, 1219, 0, 0); //750 z offset
	keyForceField.Scale() = kVec3(0.5f, 0.5f, 0.5f);
	keyForceField.Yaw() = Math::Deg2Rad(90);
	
	@keyButtonForceField = SpawnActor("BP_ForceField", -1202, -8034, 1219);
	keyButtonForceField.Scale() = kVec3(0.4f, 0.4f, 0.5f);
	keyButtonForceField.Yaw() = Math::Deg2Rad(90);
	
	@keyPressurePlate = ActorFactory.Spawn("BP_PressurePlate", -1837, -8640, 819, 0, 0);
	if (HasPPKey1A()) {
		Game.CallDelayedMapScript(3, instigator, 0); //Trigger key pressure plate
	}

	World.TriggerActorsByTID(instigator, 889); //2 guys near warp
	World.TriggerActorsByTID(instigator, 891); //Hulk before climbing to cave
	
	if (HasKey1A()) {
		Game.CallDelayedMapScript(2, instigator, 0); //Got first key
	}

	if (!HasPlayedChallengeIntro()) {
		Game.CallDelayedMapScript(6, instigator, 0); //Update Challenge Cin Area
	}

	if (!HasDoneMonkeyIntro()) {
		@monkeyActor = SpawnActor("BPMonkeyActor", 190, -10550, 921);
		monkeyActor.RunFxEvent("Monkey_Glow");
		monkeyActor.Scale() = kVec3(0.6f, 0.6f, 0.6f);
		
		@monkeyActor2 = SpawnActor("BPMonkeyActor", 80, -10510, 921);
		monkeyActor2.RunFxEvent("Monkey_Glow");
		monkeyActor2.Scale() = kVec3(0.6f, 0.6f, 0.6f);
		
		@monkeyActor3 = SpawnActor("BPMonkeyActor", 150, -10590, 921);
		monkeyActor3.RunFxEvent("Monkey_Glow");
		monkeyActor3.Scale() = kVec3(0.6f, 0.6f, 0.6f);
		
		Game.CallDelayedMapScript(7, instigator, 0); //Update Monkey Intro Area
	}

	//Opening and First Key Areas
	SpawnActor("BPDetail_Bones05", -1573.192993f, -3746.820068f, 357.527863f, -0.785398f);
	SpawnActor("BPDetail_Bones01", -1669.610107f, -3763.685303f, 357.583893f, -2.748894f);
	SpawnSolidActor("BPDetail_CaveRock08", -1942.305298f, -3821.453857f, 357.803619f, -0.785398f);
	SpawnActor("BPDetail_Weeds02", -1640.480103f, -4209.825684f, 357.447388f, 2.748893f);
	SpawnActor("BPDetail_VillageFence01", -1523.215088f, -3570.772217f, 357.942719f, 1.570796f);
	SpawnActor("BPDetail_VillageFence01", -2166.064453f, -3584.134766f, 358.077606f, -1.570796f);
	SpawnActor("Plant5", -2117.221436f, -3429.752930f, 358.388519f, 1.178097f);
	SpawnActor("Plant6", -1545.283569f, -3442.955566f, 358.388519f, 1.570796f);
	SpawnActor("Plant7", -1888.881958f, -3788.456055f, 357.786163f, -3.141593f);
	SpawnActor("Plant8", -2041.871582f, -4465.921875f, 353.543762f, -2.356195f);
	SpawnSolidActor("BPDetail-Tree3", -2030.855591f, -4519.956055f, 347.407166f, 1.963495f);
	SpawnSolidActor("BPDetail-Tree3", -1673.809082f, -4511.541504f, 346.237518f, -1.570796f);
	SpawnActor("Plant13", -1689.676636f, -4491.963379f, 352.666565f, 1.178097f);
	SpawnSolidActor("BPDestruct-PalmTree", -2071.244629f, -6674.612305f, 716.806335f, -2.748893f);
	SpawnActor("Plant1", -1597.266479f, -6670.299805f, 716.806335f, 2.748894f);
	SpawnSolidActor("BPDetail_CaveRock06", -1660.413574f, -6785.972168f, 716.971436f, 2.748893f);
	SpawnActor("BPDetail_Bones01", -2102.799072f, -7465.281250f, 819.190186f, 2.356194f);
	SpawnSolidActor("BPDetail_Ruins04", -1591.132568f, -7435.313477f, 819.172668f, -2.356195f);
	SpawnActor("Plant10", -1645.516968f, -7468.269043f, 819.184204f, 2.356194f);
	SpawnSolidActor("BPDetail-Tree5", -2076.570557f, -7697.900391f, 819.204834f, 1.570796f);
	SpawnSolidActor("BPDetail-Tree5", -1278.825562f, -8606.196289f, 819.528687f, -1.178097f);
	SpawnSolidActor("BPDetail-Tree5", -2331.170898f, -8436.847656f, 819.243591f, -2.356194f);
	SpawnActor("Plant18", -2544.943359f, -8530.863281f, 819.198853f, -2.748894f);
	SpawnActor("Plant17", -2264.363525f, -8743.686523f, 819.236877f, 0.392699f);
	SpawnActor("Plant15", -2351.708984f, -8413.760742f, 819.243591f, 2.356194f);
	SpawnSolidActor("BPDetail-Tree3", -1399.844849f, -7673.043945f, 819.207947f, -0.785398f);
	SpawnActor("BPGruntGuardRange-Poacher", -156.162781f, -8652.482422f, 921.503540f, 418, 1.963496f);
	SpawnActor("BPRaptor_Common", 696.011841f, -8841.833984f, 921.503540f, 1541, -0.785398f);
	SpawnActor("BPGruntGuardRange-Poacher", -408.913330f, -10539.198242f, 921.503418f, 411, -0.392699f);
	SpawnActor("BPGruntGuardRange-Poacher", -507.805878f, -10525.622070f, 921.503418f, 411, -0.000000f);
	
	//1st key to second key areas	
	SpawnActor("BPDetail_Bones05", 987.371460f, -8669.415039f, 921.503540f, -1.178097f);
	SpawnActor("BPDetail-Tree1", 296.163574f, -9107.221680f, 921.503479f, -2.356194f);
	SpawnActor("BPDetail-Tree1", 3.844261f, -9422.908203f, 921.503479f, -2.356194f);
	SpawnActor("BPDetail-Tree1", -216.156097f, -8870.769531f, 921.503540f, -2.748894f);
	SpawnActor("BPDetail-Tree1", -256.523743f, -9340.772461f, 921.503479f, -2.748894f);
	SpawnActor("BPDetail-Tree2", -564.019531f, -10512.642578f, 921.503418f, -0.392699f);
	SpawnActor("BPDetail-Tree2", -359.564331f, -10537.541016f, 921.503418f, 2.748894f);
	SpawnActor("Plant4", 456.094360f, -8123.607422f, 921.503540f, 1.570796f);
	SpawnActor("Plant6", -212.371323f, -9701.423828f, 921.503479f, 0.000000f);
	SpawnActor("Plant4", 68.528091f, -9098.871094f, 921.503479f, -1.963495f);
	SpawnActor("Plant4", 775.163208f, -8344.733398f, 921.503540f, -1.570796f);
	SpawnActor("Plant4", 744.246521f, -8759.376953f, 921.503540f, -1.963495f);
	SpawnActor("Plant4", 482.915771f, -8688.508789f, 921.503540f, -1.178097f);
	SpawnActor("Plant4", 514.601624f, -8429.305664f, 921.503540f, -2.748894f);
	SpawnActor("Plant7", 160.626221f, -8131.845215f, 921.503540f, 1.570796f);
	SpawnSolidActor("BPDestruct-PalmTree", 173.100067f, -8599.259766f, 921.503540f, -1.178097f);
	SpawnSolidActor("BPDestruct-PalmTree", -187.745590f, -9081.903320f, 921.503479f, -2.356194f);
	SpawnSolidActor("BPDestruct-PalmTree", 217.783707f, -9236.980469f, 921.503479f, -0.392699f);
	SpawnActor("Plant12", 206.054565f, -8666.299805f, 921.503540f, 2.748894f);
	SpawnActor("Plant13", 0.535072f, -8859.856445f, 921.503479f, -1.963495f);
	SpawnActor("Plant15", 381.234497f, -8659.379883f, 921.503540f, -2.356194f);
	SpawnActor("Plant17", 376.194763f, -8902.299805f, 921.503540f, 2.356195f);
	SpawnSolidActor("BPDestruct-PalmTree", 63.793499f, -10072.995117f, 921.503479f, -0.000000f);
	SpawnSolidActor("BPDestruct-PalmTree", -508.703247f, -9965.344727f, 921.503479f, -2.356194f);
	SpawnActor("Plant1", 812.385315f, -10402.168945f, 921.641113f, 0.392699f);
	SpawnSolidActor("BPDetail-Tree3", 793.780640f, -10178.690430f, 921.618103f, 3.141593f);
	SpawnSolidActor("BPDetail-Tree3", 815.334412f, -10796.460938f, 921.653015f, 2.356194f);
	SpawnActor("Plant18", 658.641968f, -10576.677734f, 921.748657f, 1.570796f);
	SpawnActor("Plant15", 667.021423f, -10515.896484f, 921.728760f, 1.570796f);
	SpawnActor("BPDetail-Tree6", 1997.435547f, -8683.171875f, 921.591431f, 0.785398f);
	SpawnActor("BP_SpikeFence", 1869.340698f, -8817.428711f, 921.591431f, -1.570796f);
	SpawnActor("BP_FallingRocks", 603.070374f, -10517.379883f, 921.669739f, -2.748894f);
	SpawnActor("BP_FallingRocks", 1117.628174f, -11469.045898f, 921.554077f, -2.356194f);
	SpawnSolidActor("BPDestruct-PalmTree", 1886.124756f, -8042.493652f, 921.583435f, 0.000000f);
	SpawnSolidActor("BPDestruct-PalmTree", 2010.775024f, -7954.301758f, 921.623840f, -1.570796f);
	SpawnActor("BPGruntGuardRange-Poacher", 2069.912842f, -8679.271484f, 921.591431f, 1920, -1.570797f);
	SpawnActor("BPGruntGuardGrenade", 3510, -7499, 1253, 2677, -2.046779f);
	SpawnActor("BPGruntGuardGrenade", 3747, -7424, 1320, 2673, -2.037624f);
	SpawnActor("BPGruntGuardGrenade", 3515, -8564, 1253, 2684, -1.039699f);
	SpawnActor("BPGruntGuardGrenade", 3734, -8635, 1320, 2683, -1.076320f);
	SpawnActor("BPGruntRange_Poacher", 5383.450684f, -8262.307617f, 1228.798828f, 764, -1.570796f);
	SpawnActor("BPGruntRange_Poacher", 5409.685547f, -7848.120117f, 1228.798828f, 771, -1.570797f);

	//Right of first key to cave area
	SpawnActor("BPGruntGuardRange-Poacher", -4328.554199f, -8301.579102f, 1075.517212f, 650, -0.392699f);
	SpawnActor("BPGruntGuardRange-Poacher", -4767.478027f, -7859.832031f, 1075.517212f, 636, 1.963495f);
	SpawnActor("BPPurlin_MeleeCommon", -4966.760742f, -6386.014160f, 1638.398193f, 731, -1.963495f);
	SpawnActor("BPGruntMelee_PoacherKnife", -5595.647949f, -8099.128418f, 665.595337f, 3120, 1.570796f);
	SpawnActor("BPGruntGuardRange-Poacher", -4966.523926f, -8718.945313f, 665.595337f, 3058, 0.392699f);
	SpawnActor("BPGruntGuardRange-Poacher", -4787.729004f, -8398.018555f, 665.595337f, 3058, -2.356194f);
	SpawnActor("BPGruntGuardRange-Poacher", -5127.090332f, -8587.557617f, 665.595337f, 3059, 1.178097f);
	
	//open area with ruin building and spiritual item
	SpawnActor("BPPurlin_MeleeCommon", -4460.579102f, -2355.012451f, 2713.593750f, 3195, 1.178097f);
	SpawnActor("BPGruntGuardRange-Poacher", -4340.986816f, -1590.104736f, 2508.808594f, 1399, -2.356195f);
	SpawnActor("BPGruntMelee_PoacherKnife", -6620.651855f, -326.818298f, 2508.808594f, 1406, 2.356194f);
	SpawnActor("BPGruntMelee_PoacherKnife", -7177.431152f, -256.325470f, 2508.808594f, 1698, 1.570796f);
	SpawnActor("BPGruntMelee_PoacherKnife", -6331.257324f, -140.979843f, 2508.808594f, 1641, 2.748894f);
	SpawnActor("BPRaptor_Common", -5561.981445f, -1116.237915f, 2508.808594f, 1472, 1.963495f);
	SpawnActor("BPGruntGuardRange-Poacher", -8499.916992f, 1745.248169f, 2764.833984f, 1188, 2.748894f);
	SpawnActor("BPGruntGuardRange-Poacher", -9270.447266f, 1173.680908f, 2764.804688f, 1279, 1.963495f);
	SpawnActor("BPGruntGuardGrenade", -7843.114746f, 1252.940674f, 2900.248535f, 1162, 2.356194f);
	SpawnActor("BPGruntGuardGrenade", -7794.645508f, 1682.351318f, 2839.478271f, 1171, -2.748894f);
	SpawnActor("BPGruntGuardGrenade", -7717.153809f, 1456.855713f, 2870.663818f, 1166, 2.748894f);
	SpawnActor("BPGruntRange_Poacher", -7223.248047f, 1240.502075f, 2508.808594f, 1620, 3.141593f);
	
	//circle area with chrono
	SpawnActor("BPBeetle", 2957.678467f, 8868.372070f, 0.000388f, 588, 1.570796f);
	SpawnActor("BPBeetle", 2488.209961f, 8619.490234f, 0.000386f, 1738, 0.392699f);
	SpawnActor("BPBeetle", 2643.858643f, 7695.271973f, 0.000339f, 1742, 1.570796f);
	SpawnActor("BPBeetle", 2149.279785f, 8356.277344f, 0.000372f, 1751, 2.748894f);
	SpawnActor("BPBeetle", 2557.434326f, 9074.321289f, 0.000403f, 592, -2.356194f);
	SpawnActor("BPBeetle", 4132.207031f, 8460.255859f, 0.000362f, 1006, -0.392699f);
	SpawnActor("BPStalker", 4062.694092f, 9461.173828f, 0.000418f, 1853, 2.748894f);
	SpawnActor("BPGruntMelee_PoacherKnife", 2806.332764f, 7337.313965f, 0.000323f, 1834, 1.963495f);
	SpawnActor("BPGruntGuardRange-Poacher", 2779.629639f, 10577.923828f, 0.000468f, 579, 2.356194f);
	SpawnActor("BPGruntGuardRange-Poacher", 3221.438721f, 10564.783203f, 0.000477f, 580, -2.748894f);

	//--------------------
	
	//start intro or update map
	if (HasPlayedIntro1()) { // start Game (start map normally)
		Game.CallDelayedMapScript(1, instigator, 0); //Update Game
	} else {
		Game.CallDelayedMapScript(4, instigator, 0); //Start Intro
	}
}
//------------------------------------------------------------------------------------------------------------------------
// Update Game
//------------------------------------------------------------------------------------------------------------------------
$script 1 {	
	//if doesn't have knife upgrade
	if (!HasUpgradeKnife()) {
		BlockAreaMinMax(kVec3(-2194, -7197, 700), kVec3(-1483, -6802, 2700), kVec3(0, 1, 0));
	}
	
	//haven't deactivated key force field
	if (!triggeredKeyPlate) {
		BlockArea(kVec3(-1840, -8190, 819), 150.0f, 1000.0f); //blocks the key 
		//if hasn't pressed switch and on switch then press switch
		if (InArea(keyPressurePlate.Origin() + PressurePlate2Offset, PressurePlate2Size) and Player.Actor().OnGround()) {
			keyPressurePlate.PlaySound("sounds/shaders/generic_177.ksnd");
			SetPPKey1A(true);
			triggeredKeyPlate = true;
			keyForceField.Remove();
			SpawnActor("BPRaptor_Common", -2409, -7940, 819, Math::Deg2Rad(180)).Health() = 20;
			SpawnActor("BPRaptor_Common", -2531, -7909, 819, Math::Deg2Rad(180)).Health() = 20;
		}
		
		if (PlayLoop.Ticks() % 10 == 0) {
			if (InAreaMinMax(kVec3(-2394, -8406, 819), kVec3(-1105, -7572, 1819))) {
				keyLaser.SpawnProjectile("fx/laserTrap.kfx", kVec3(0, 0, 0), Player.Actor().Origin(), Math::Deg2Rad(45.0f));
			}
		}
	}
	
	//haven't got the first key
	if (!gotFirstKey) {
		BlockArea(kVec3(-1241, -8032, 819), 135.0f, 3000.0f);
		BlockAreaMinMax(kVec3(-2600, -9072, 819), kVec3(-2400, -8796, 3000), kVec3(0, 1, 0));
	}
	
	UpdateGeneralGame();
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Got first key
//------------------------------------------------------------------------------------------------------------------------
$script 2 {
	if (!gotFirstKey) {
		gotFirstKey = true;
		kActor @shop = ActorFactory.Spawn("ShopPoint", -1832, -7544, 819, 0, 0); //Spawn Shop Portal
		keyButtonForceField.Remove();
	}
}
//------------------------------------------------------------------------------------------------------------------------
// Triggered plate
//------------------------------------------------------------------------------------------------------------------------
$script 3 {
	if (!triggeredKeyPlate) {
		triggeredKeyPlate = true;
		keyForceField.Remove();
	}
}
//------------------------------------------------------------------------------------------------------------------------
// Start Intro
//------------------------------------------------------------------------------------------------------------------------
$script 4 {
	Game.StopMusic();
	Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_NO_INITIAL_FADEOUT);
	Camera.SetLookAtActor(Player.Actor().CastToActor());
	Camera.fov = 74.0f;
	
	Game.CallDelayedMapScript(5, instigator, 0); //Update Intro
	
	Player.Actor().ModelVariation() = TV_KNIFE;
	Player.Actor().AnimState().Set(anim_player_idle, 8.0f, ANF_LOOP);
	Player.Actor().Flags() &= ~AF_NODRAW;
	
	Camera.SetFinalView(0);
	Camera.SetRotationTrack(0,
							Math::Deg2Rad(-45.0f),  // start angle
							Math::Deg2Rad(25.0f),   // dest angle
							15*GAME_SCALE,           // start distance
							4*GAME_SCALE,           // dest distance
							12*GAME_SCALE,           // start height
							7*GAME_SCALE,           // dest height
							7*GAME_SCALE,           // start look at height
							7*GAME_SCALE);          // dest look at height
	Camera.AutoPlayRotationTrack(0, 33.0f, CMLT_COSINE);
	
	//cut2_intro01 (2sec) - Adon: Thank the elders you're alive
	DoCutScene("sounds/shaders/cut2_intro01.ksnd", 2.0f, "Thank the elders you're alive", "", "");
	
	//cut2_intro02 (2sec) - Adon: I am Adon
	DoCutScene("sounds/shaders/cut2_intro02.ksnd", 2.0f, "I am Adon", "", "");
	
	//cut2_intro03 (3sec) - Adon: You have entered the time stream
	DoCutScene("sounds/shaders/cut2_intro03.ksnd", 3.0f, "You have entered the time stream", "", "");
	
	//cut2_intro04 (12sec) - Adon: Two years ago you were attacked by an entity. No other being like it has ever existed. A massive lifeform capable of devouring worlds...of rendering entire planets lifeless and barren
	DoCutScene("sounds/shaders/cut2_intro04.ksnd", 8.0f, "Two years ago you were attacked by an entity", "No other being like it has ever existed", "A massive lifeform capable of devouring worlds");
	DoCutScene(4.0f, "of rendering entire planets lifeless and barren", "", "");

	//cut2_intro05 (7sec) - Adon: It seeks to crush that which the turok protect...the energy within the light burden
	DoCutScene("sounds/shaders/cut2_intro05.ksnd", 7.0f, "It seeks to crush that", "which the turok protect", "the energy within the light burden");
	
	//cut2_intro06 (2sec) - Adon: You must take up the mantle
	DoCutScene("sounds/shaders/cut2_intro06.ksnd", 2.0f, "You must take up the mantle", "", "");
	
	//cut2_intro07 (3sec) - Adon: You must become the son of stone
	DoCutScene("sounds/shaders/cut2_intro07.ksnd", 3.0f, "You must become the son of stone", "", "");
	
	//cut2_intro08 (3sec) - Adon: You must become Turok
	DoCutScene("sounds/shaders/cut2_intro08.ksnd", 3.0f, "You must become Turok", "", "");
	
	Camera.AutoPlayRotationTrack(0, 0.01f, CMLT_COSINE);
	Game.HaltMapScript(5);
	Player.Victory();
	delay(3.0f);
	Game.PlaySound("sounds/shaders/generic_234.ksnd"); //I am Turok!
	delay(1.4f);
	Game.PlayMusic("music/track01.ogg", true);
	Game.CallDelayedMapScript(1, instigator, 0); //Update Game
	SetPlayedIntro1(true);
}
//------------------------------------------------------------------------------------------------------------------------
// Update Intro
//------------------------------------------------------------------------------------------------------------------------
$script 5 {
	if (Camera.UserInterrupted()) {
		ClearCinematicText();
		Game.HaltMapScript(4);
		Player.Victory();
		delay(3.0f);
		Game.PlaySound("sounds/shaders/generic_234.ksnd"); //I am Turok!
		delay(1.4f);
		Game.PlayMusic("music/track01.ogg", true);
		Game.CallDelayedMapScript(1, instigator, 0); //Update Game
		SetPlayedIntro1(true);
        return;
    }
    $restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Update Challenge Cinematic Area
//------------------------------------------------------------------------------------------------------------------------
$script 6 {
	if (InAreaMinMax(kVec3(-2135, -6621, 700), kVec3(-1546, -6366, 2700))) {
		SetPlayedChallengeIntro(true);
		Player.Actor().ModelVariation() = TV_KNIFE;
		Player.Actor().AnimState().Set(anim_player_idle, 8.0f, ANF_LOOP);
		Player.Actor().Flags() &= ~AF_NODRAW;
		Camera.fov = 70.0f;
		Camera.SetLookAtActor(challengeTotem);
		Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_UNLOCK_PLAYER_ON_FINISH|CMF_NO_INITIAL_FADEOUT);
		Camera.SetFinalView(0);
		Camera.SetRotationTrack(0,
								Math::Deg2Rad(-80.0f),  // start angle
								Math::Deg2Rad(20.0f),   // dest angle
								20*GAME_SCALE,           // start distance
								15*GAME_SCALE,           // dest distance
								20*GAME_SCALE,           // start height
								12*GAME_SCALE,           // dest height
								7*GAME_SCALE,           // start look at height
								4*GAME_SCALE);          // dest look at height
		Camera.AutoPlayRotationTrack(0, 7.0f, CMLT_COSINE);
		Game.CallDelayedMapScript(8, instigator, 0); //Update Challenge Intro Cinematic
		delay(1.0f);
		Game.PrintLine("Find Challenge Keys to activate the totems", 0, 300);
		delay(6.0f);
		Game.HaltMapScript(8);
		Camera.StopCinematic();
		delay(0.5f);
		Player.Actor().Flags() |= AF_NODRAW;
		return;
	}
	
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
$script 7 {
	if (InAreaMinMax(kVec3(15, -10471, 900), kVec3(106, -10227, 2900))) {
		SetMonkeyIntro(true);
		Camera.fov = 70.0f;
		Camera.ClearLookAtActor();
	    Camera.ClearViewTracks();
		Camera.StartCinematic(CMF_LOCK_PLAYER|CMF_UNLOCK_PLAYER_ON_FINISH|CMF_NO_INITIAL_FADEOUT);
		Camera.origin = kVec3(60, -10250, 1021);
		Camera.yaw = Math::Deg2Rad(160);
		Camera.pitch = Math::Deg2Rad(20);
		Game.PlaySound("sounds/shaders/monkeyIntro.ksnd");
		Game.CallDelayedMapScript(9, instigator, 0); //Update Monkey Intro Cinematic
		delay(3.0f);
		Game.PrintLine("Catch the monkeys", 0, 240);
		monkeyActor2.Yaw() = Math::Deg2Rad(90);
		monkeyActor2.AnimState().Blend(anim_activate, 4.0f, 8.0f, ANF_LOOP);
		delay(0.5f);
		monkeyActor3.Yaw() = Math::Deg2Rad(90);
		monkeyActor3.AnimState().Blend(anim_activate, 4.0f, 8.0f, ANF_LOOP);
		delay(1.5f);
		monkeyActor.Yaw() = Math::Deg2Rad(90);
		Camera.origin = kVec3(40, -10550, 1021);
		Camera.yaw = Math::Deg2Rad(90);
		Camera.pitch = Math::Deg2Rad(20);
		monkeyActor.AnimState().Blend(anim_activate, 4.0f, 8.0f, ANF_LOOP);
		delay(5.0f);
		Game.HaltMapScript(9); //Update Monkey Intro Cinematic
		Camera.StopCinematic();
		delay(0.5f);
		monkeyActor.Remove();
		monkeyActor2.Remove();
		monkeyActor3.Remove();
		return;
	}
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Update Challenge Intro Cinematic
//------------------------------------------------------------------------------------------------------------------------
$script 8 {
	if (Camera.UserInterrupted()) {
		Game.HaltMapScript(6);
		Camera.StopCinematic();
		delay(0.5f);
		Player.Actor().Flags() |= AF_NODRAW;
		return;
	}
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
// Update Monkey Intro Cinematic
//------------------------------------------------------------------------------------------------------------------------
$script 9 {
	if (Camera.UserInterrupted()) {
		Game.HaltMapScript(7);
		Camera.StopCinematic();
		delay(0.5f);
		monkeyActor.Remove();
		monkeyActor2.Remove();
		monkeyActor3.Remove();
		return;
	}
	$restart;
}
//------------------------------------------------------------------------------------------------------------------------
void DoCutScene(const kStr &in sound, float time, const kStr &in topText, const kStr &in middleText, const kStr &in bottomText) {
	Game.PlaySound(sound);
	int iTime = int(60.0f * time - 10);
	Game.PrintLine(bottomText, 0, iTime); //bottom
	Game.PrintLine(middleText, 1, iTime); //middle
	Game.PrintLine(topText, 2, iTime); //top
	delay(time);
}
//------------------------------------------------------------------------------------------------------------------------
void DoCutScene(float time, const kStr &in topText, const kStr &in middleText, const kStr &in bottomText) {
	int iTime = int(60.0f * time - 10);
	Game.PrintLine(bottomText, 0, iTime); //bottom
	Game.PrintLine(middleText, 1, iTime); //middle
	Game.PrintLine(topText, 2, iTime); //top
	delay(time);
}
//------------------------------------------------------------------------------------------------------------------------
