#include "..\Shared\SPMission.h"

class scion04 : public SPMission 
{
public:
	scion04(void)
	{
		b_count = &b_last - &b_first - 1;
		b_array = &b_first + 1;

		f_count = &f_last - &f_first - 1;
		f_array = &f_first + 1;

		h_count = &h_last - &h_first - 1;
		h_array = &h_first + 1;

		i_count = &i_last - &i_first - 1;
		i_array = &i_first + 1;
	}

	void Setup(void);
	void AddObject(Handle h);
	void Execute(void);

	// bools
	bool
		b_first,
		missionstart,vo1,obj1,attack1,playermeetevil,evilgo1,evilattacked,
		playernotcoming1,firstwarning,secondwarning,thirdwarning,playercaughtup,warn1,warn2,
		playerattackedevil,evilgo2,warn3,playeratambush,ambushstart,
		warn2a,

		b_last;

	// floats
	float
		f_first,
		vo1time,
		warn1time,
		warn2time,warn3time,

		f_last;

	// handles
	Handle
		h_first,
		tug1,power,msg1,machine,
		rtattack1,rtattack2,rtattack3,rtattack4,rtattack5,rtattack6,rtattack7,rtattack8,player,
		evil1,evil2,evil3,msg2,bomb1,bomb2,ambusher1,ambusher2,ambusher3,ambusher4,ambusher5,
		ambusher6,
		h_last;


	// integers
	int
		i_first,


		i_last;
};
DLLBase * BuildMission(void)
{
	return new scion04();
}

void scion04::Setup(void)
{
/*
	Here's where you set the values at the start.  
*/

//  bools
	missionstart = false;
	vo1 = false;
	obj1 = false;
	attack1 = false;
	playermeetevil = false;
	evilgo1 = false;
	evilattacked = false;
	playernotcoming1 = false;
	firstwarning = false;
	secondwarning = false;
	thirdwarning = false;
	playercaughtup = false;
	warn1 = false;
	warn2 = false;
	warn2a = false;
	playerattackedevil = false;
	evilgo2 = false;
	warn3 = false;
	playeratambush = false;
	ambushstart = false;
//  floats
	vo1time = 999999.9f;
	warn1time = 999999.9f;
	warn2time = 999999.9f;	
	warn3time = 999999.9f;
//  handles
	tug1 = GetHandle("tug1");
	power = GetHandle("power");
	msg1 = NULL;
	machine = GetHandle("machine");
	rtattack1 = GetHandle("rtattack1");
	rtattack2 = GetHandle("rtattack2");
	rtattack3 = GetHandle("rtattack3");
	evil1 = GetHandle("evil1");
	evil2 = GetHandle("evil2");
	evil3 = GetHandle("evil3");
	rtattack4 = NULL;
	rtattack5 = NULL;
	rtattack6 = NULL;
	rtattack7 = NULL;
	rtattack8 = NULL;
	player = NULL;
	msg2 = NULL;
	bomb1 = GetHandle("bomb1");
	bomb2 = GetHandle("bomb2");
	ambusher1 = NULL;
	ambusher2 = NULL;
	ambusher3 = NULL;
	ambusher4 = NULL;
	ambusher5 = NULL;
	ambusher6 = NULL;

//  integers




}

void scion04::AddObject(Handle h)
{
}

void scion04::Execute(void)
{
/*
	Here is where you put what happens every frame.  
*/	
	player = GetPlayerHandle();
	SetCurHealth(tug1,2500);
	if (!missionstart)
	{
		SetScrap(1,40);
		Pickup(tug1,power,0);
		vo1time = (GetTime() + 4);
		Pickup(tug1,power,0);
		missionstart = true;
	}
	
	if ((!vo1) && (vo1time < GetTime()))
	{
		msg1 = AudioMessage("scion0401.wav"); //  Ok Cook, we MUST get this power source to the data transfer machine.  We have been unable to locate any scrap veins in the area, so you will have to make due with the units we have available.  Good luck Cook, the fate of an entire race is in your hands. (SHAB)
		vo1 = true;
	}

	if ((!obj1) && (vo1) && (IsAudioMessageDone(msg1)))
	{
		ClearObjectives();
		AddObjective("scion0401.otf", WHITE);
		SetObjectiveOn(machine);
		SetObjectiveName(machine,"Machine");
		Attack(rtattack1,tug1);
		obj1 = true;
	}

	if ((!attack1) && (GetDistance(player,rtattack2) < 150))
	{
		Goto(rtattack2,player);
		Goto(rtattack3,player);
		attack1 = true;
	}

	if ((!playermeetevil) && (GetDistance(player,evil1) < 85))
	{
		msg2 = AudioMessage("scion0402.wav"); //Cook stop!  The way ahead is very dangerous, a massive ISDF blockade is intrenched in the canyon.  Follow us we know a safe way through the pass!
		LookAt(evil1,player);
		LookAt(evil2,player);
		LookAt(evil3,player);
		playermeetevil = true;
	}

	if ((!evilgo1) && (!playerattackedevil) && (!warn2) && (!warn2a)
		&& (playermeetevil) && (IsAudioMessageDone(msg2)))
	{
		Retreat(evil1,"evilpath");
		Follow(evil2,evil1);
		Follow(evil3,evil2);
		evilgo1 = true;
	}

	if ((!playernotcoming1) && (evilgo1) && (GetDistance(player,evil1) > 150))
	{
		Stop(evil1);
		Stop(evil2);		
		Stop(evil3);
		LookAt(evil1,player);
		LookAt(evil2,player);
		LookAt(evil3,player);
		warn1time = (GetTime() + 4);
		playernotcoming1 = true;
	}

	if ((!playercaughtup) && (playernotcoming1) && (!warn2) && (!warn2a) && (!playerattackedevil)
		&& (GetDistance(player,evil1) < 100))
	{
		Retreat(evil1,"evilpath");
		Follow(evil2,evil1);
		Follow(evil3,evil2);
		playercaughtup = true;
	}

	if ((!warn1) && (playernotcoming1) && (!ambushstart) && (!warn2) && (!warn3) && (!playerattackedevil)
		&& (!playercaughtup))
	{
		AudioMessage("scion0403.wav");//C'mon Cook, you coming with us or not?
		warn2time = (GetTime() + 50);
		warn1 = true;
	}

	if ((!warn2) && (!playercaughtup) && (!playerattackedevil) && (!warn3) && (warn2time < GetTime()))
	{
		AudioMessage("scion0405.wav"); //	Ok Cook, I was hoping we could do this the easy way but you are too stubborn!  Attack men!
		SetPerceivedTeam(evil1,2);
		SetPerceivedTeam(evil2,2);
		SetPerceivedTeam(evil3,2);
		Attack(evil1,player);
		Attack(evil2,player);
		Attack(evil3,player);
		warn2 = true;
	}

	if ((!warn2a) && (!playerattackedevil) && (!warn2) && (playercaughtup) && (GetDistance(evil1,"ambush") < 50))
	{

		Stop(evil1);
		Stop(evil2);
		Stop(evil3);
		LookAt(evil1,player);
		LookAt(evil2,player);
		LookAt(evil3,player);
		warn2a = true;
	}

	if ((!playeratambush) && (warn2a) && (GetDistance(player,"ambush") < 100))
	{
		playeratambush = true;
	}

	if ((!warn3) && (!playeratambush) && (!playerattackedevil) && (!warn2) && (GetDistance(player,"goodroute") < 150))
	{
		AudioMessage("scion0405.wav"); //	Ok Cook, I was hoping we could do this the easy way but you are too stubborn!  Attack men!
		RemoveObject(evil1); 
		RemoveObject(evil2);		
		RemoveObject(evil3);
		evil1 = BuildObject("fvscout",0,"evil1respawn");
		evil2 = BuildObject("fvscout",0,"evil2respawn");
		evil3 = BuildObject("fvscout",0,"evil3respawn");
		Attack(evil1,player); 
		Attack(evil2,player);
		Attack(evil3,player);
		warn3 = true;
	}
////////////////When player attacks first
	if ((!playerattackedevil) && (!warn2) && (!warn3) && (GetCurHealth(evil1) < 750)) 

	{
		if (!IsAudioMessageDone(msg2))
		{
			StopAudioMessage(msg2);
		}
		
		AudioMessage("scion0404.wav");//He's onto us! Attack!
		SetPerceivedTeam(evil1,2);
		SetPerceivedTeam(evil2,2);
		SetPerceivedTeam(evil3,2);
		Attack(evil1,player);
		Attack(evil2,player);
		Attack(evil3,player);
		playerattackedevil = true;
	}

	if ((!playerattackedevil) && (!warn2) && (!warn3) && (GetCurHealth(evil2) < 750)) 

	{
		if (!IsAudioMessageDone(msg2))
		{
			StopAudioMessage(msg2);
		}
	
		AudioMessage("scion0404.wav");//He's onto us! Attack!
		SetPerceivedTeam(evil1,2);
		SetPerceivedTeam(evil2,2);
		SetPerceivedTeam(evil3,2);
		Attack(evil1,player);
		Attack(evil2,player);
		Attack(evil3,player);
		playerattackedevil = true;
	}

	if ((!playerattackedevil) && (!warn2) && (!warn3) && (GetCurHealth(evil3) < 750)) 

	{

		if (!IsAudioMessageDone(msg2))
		{
			StopAudioMessage(msg2);
		}
		
		AudioMessage("scion0404.wav");//He's onto us! Attack!
		SetPerceivedTeam(evil1,2);
		SetPerceivedTeam(evil2,2);
		SetPerceivedTeam(evil3,2);
		Attack(evil1,player);
		Attack(evil2,player);
		Attack(evil3,player);
		playerattackedevil = true;
	}
	////////////


	/// If player falls for the trap......the ambush
	if ((!ambushstart) && (!warn2) && (!warn3) && (!playerattackedevil) && (GetDistance(player,"ambush") < 125))
	{
		ambusher1 = BuildObject("ivtank",2,"ambushspawn1");
		ambusher2 = BuildObject("ivtank",2,"ambushspawn2");
		ambusher3 = BuildObject("ivrckt",2,"ambushspawn3");
		ambusher4 = BuildObject("ivrckt",2,"ambushspawn4");
		ambusher5 = BuildObject("ivscout",2,"ambushspawn5");
		ambusher6 = BuildObject("ivscout",2,"ambushspawn6");
		SetSkill(ambusher1,2);
		SetSkill(ambusher2,2);
		SetSkill(ambusher3,2);
		SetSkill(ambusher4,2);		
		SetSkill(ambusher5,2);
		SetSkill(ambusher6,2);
		Goto(ambusher1,player);
		Goto(ambusher2,player);
		Goto(ambusher3,player);
		Goto(ambusher4,player);
		Goto(ambusher5,player);
		Goto(ambusher6,player);
		Attack(bomb1,player);
		ambushstart = true;
	}



}

