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

class scion08 : public SPMission 
{
public:
	scion08(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,
		spawn1,spawn2,spawn3,
		timedattacksover,
		wave1killed,wave2killed,wave3killed,
		setobjectives,vo1,vo2,vo3,vo4,vo5,obj1,obj2,obj3,obj4,obj5,playerandtugatrondevous,
		basecleared,power1killed,poweratmachine,
		b_last;

	// floats
	float
		f_first,
		spawn1time,spawn2time,spawn3time,obj1time,obj3time,
		f_last;

	// handles
	Handle
		h_first,
		player,
		enemy1,enemy2,enemy3,enemy4,enemy5,enemy6,talk1,talk2,talk3,talk4,talk5,machine,nav1,tug1,power1,
		nav2,basetank1,basetank2,basescout1,basescout2,basescav1,basescav2,
		h_last;


	// integers
	int
		i_first,


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

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

//  bools
	spawn1 = false;
	spawn2 = false;
	spawn3 = false;
	timedattacksover = false;
	wave1killed = false;
	wave2killed = false;
	wave3killed = false;
	setobjectives = false;
	vo1 = false;
	vo2 = false;
	vo3 = false;
	vo4 = false;
	vo5 = false;
	obj1 = false;
	obj2 = false;
	obj3 = false;
	obj4 = false;
	obj5 = false;
	playerandtugatrondevous = false;
	basecleared = false;
	power1killed = false;
	poweratmachine = false;


//  floats
	spawn1time = 999999.9f;
	spawn2time = 999999.9f;
	spawn3time = 999999.9f;
	obj1time = 999999.9f;
	obj3time = 999999.9f;
//  handles
	enemy1 = NULL;
	enemy2 = NULL;
	enemy3 = NULL;
	enemy4 = NULL;
	enemy5 = NULL;
	enemy6 = NULL; 
	player = GetPlayerHandle();
	talk1 = NULL;		
	talk2 = NULL;
	talk3 = NULL;
	talk4 = NULL;
	talk5 = NULL;
	machine = GetHandle("machine");
	nav1 = GetHandle("nav1");
	nav2 = GetHandle("nav2");
	tug1 = GetHandle("tug1");
	power1 = GetHandle("power1");
	basetank1 = GetHandle("basetank1");
	basetank2 = GetHandle("basetank2");
	basescav1 = GetHandle("basescav1");
	basescav2 = GetHandle("basescav2");
	basescout1 = GetHandle("basescout1");
	basescout2 = GetHandle("basescout2");




//  integers




}

void scion08::AddObject(Handle h)
{
}

void scion08::Execute(void)
{
/*
	Here is where you put what happens every frame.  
*/
	//SetCurAmmo(player,1000);//TEMP	
//	SetCurHealth(player, 2000);//TEMP
	player = GetPlayerHandle();
	if (!setobjectives)
	{
		obj1time = (GetTime() + 3);
		Pickup(tug1,power1,0);
		SetScrap(1,40);
		setobjectives = true;
	}

	if (!obj1)
	{
		if ((!vo1) && (obj1time < GetTime()))
		{
			talk1 = AudioMessage("scion0801.wav");	
			vo1 = true;
		}

		if ((!obj1) && (vo1) && (IsAudioMessageDone(talk1)))
		{
			ClearObjectives();
			AddObjective("scion0801.otf",WHITE,20.0f); 
			SetObjectiveOn(nav1);
			obj1 = true;
		}
	}

//when player and tug are at rondevous point
	if (!obj2)
	{
		if ((!playerandtugatrondevous) && (GetDistance(player,nav1) < 90) && (GetDistance(power1,nav1) < 80))
		{
			talk2 = AudioMessage("scion0802.wav");
			SetObjectiveOff(nav1);
			playerandtugatrondevous = true;
		}

		if ((!obj2) && (playerandtugatrondevous) && (IsAudioMessageDone(talk2)))
		{
			ClearObjectives();
			AddObjective("scion0802.otf",WHITE,20.0f); 
	    	spawn1time = (GetTime() + 120.0f);
            spawn2time = (GetTime() + 450.0f);
	        spawn3time = (GetTime() + 800.0f);
	 		SetObjectiveOn(nav2); 
			obj2 = true;
		}
	}
		
	if (!timedattacksover)
	{
			//1st wave
		if ((!spawn1) && (spawn1time < GetTime()))
		{
			enemy1 = BuildObject("ivtank",2,"spawn1point1");
			Goto(enemy1,"playerbase");
			SetSkill(enemy1,1);
			spawn1 = true;
		}

		if ((!wave1killed) && (spawn1) && (!IsAlive(enemy1))) 
		{
			wave1killed = true;
		}

			//2nd wave
		if ((!spawn2) && (spawn2time < GetTime()))
		{
			enemy2 = BuildObject("ivscout",2,"spawn2point1");
			enemy3 = BuildObject("ivscout",2,"spawn2point2");
			Goto(enemy2,"playerbase");
			Goto(enemy3,"playerbase");
			SetSkill(enemy2,2);
			SetSkill(enemy3,3);
			spawn2 = true;
		}

		if ((!wave2killed) && (spawn2) && (!IsAlive(enemy3) && (!IsAlive(enemy2)))) 
		{
			wave2killed = true;
		}

			//3rd wave
		if ((!spawn3) && (spawn3time < GetTime()))
		{
			enemy4 = BuildObject("ivtank",2,"spawn3point1");
			enemy5 = BuildObject("ivtank",2,"spawn3point2");
			Goto(enemy4,"playerbase");
			Goto(enemy5,"playerbase");
			SetSkill(enemy4,2);
			SetSkill(enemy5,2);
			spawn3 = true;
		}

	
		if ((!wave3killed) && (spawn3) && (!IsAlive(enemy4) && (!IsAlive(enemy5))))
		{
			wave3killed = true;
			timedattacksover = true;
		}
	}

	//whan the base is cleared
	if ((!basecleared) && (obj2) && (!IsAlive(basetank1) && (!IsAlive(basetank2) 
		&& (!IsAlive(basescout1) && (!IsAlive(basescout2) && (!IsAlive(basescav1)
		 && (!IsAlive(basescav2))))))))
	{
		obj3time = (GetTime() + 3);
		basecleared = true;
	}

	if ((!obj3) && (obj3time < GetTime()))
	{
		if  (!vo3)
		{
			talk3 = AudioMessage("scion0803.wav");	//base killed, good work.  bring in power source
			vo3 = true;
		}

		if ((!obj3) && (vo3) && (IsAudioMessageDone(talk3)))
		{
			ClearObjectives();
			AddObjective("scion0803.otf",WHITE,20.0f); 
			SetObjectiveOff(nav2);
			SetObjectiveOn(machine);
			SetObjectiveName(machine,"Machine");
			obj3 = true;	
		}
	}
//if power1 is brought to the machine, mission successful
	if ((!poweratmachine) && (obj3) && (GetDistance(power1,machine) < 80))
	{
		poweratmachine = true;
	}

	if ((!obj4) && (poweratmachine))
	{
		if  (!vo4)
		{
			talk4 = AudioMessage("scion0804.wav");	//base killed, good work.  bring in power source
			vo4 = true;
		}

		if ((!obj4) && (vo4) && (IsAudioMessageDone(talk4)))
		{
			ClearObjectives();
			AddObjective("scion0804.otf",WHITE,20.0f); 
			SucceedMission(GetTime() + 10);
			obj3 = true;	
		}
	}



	//if power1 is killed, mission failed
	if ((!power1killed) && (!IsAround(power1)))
	{
		FailMission(GetTime() + 15);
		ClearObjectives();
		AddObjective("scion0805.otf",WHITE,30.0f); 
		AudioMessage("scion0805.wav");
		power1killed = true;
	}
}

