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

class scion05 : public SPMission 
{
public:
	scion05(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,vo2,vo3,unitsbuilt,obj1,obj2,obj4,
		bridgegoboom,bstr1goboom,bstr2goboom,bseg1goboom,bseg2goboom,bseg3goboom,
		bridgegoboomover,vo5,obj3,playeratAAN,playeratbridge,atankattack,reroute1,
		reroute1a,reroute1b,bridgedone,spawn2,wave1over,vo7,spire1built,
		b_last;

	// floats
	float
		f_first,
		vo1time,
		vo2time,
		vo3time,
		vo5time,
		bstr1boomtime,bstr2boomtime,bseg1boomtime,bseg2boomtime,bseg3boomtime,
		spawn2time,vo7time,
		f_last;

	// handles
	Handle
		h_first,
		player,msg1,msg2,
		fvtank1,fvtank2,fvtank3,fvsent1,fvsent2,fvsent3,
		bseg1,bseg2,bseg3,bstr1,bstr2,msg5,aanbase,spawner1,spawner2,spawner3,spawner4,
		spawner5,spawner6,spawner7,spawner8,atank1,atank2,bridgetank,bridgescout,
		aangtow1,aangtow2,msg7,spire1site,gspire1,
		h_last;


	// integers
	int
		i_first,


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

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

//  bools
	missionstart = false;
	vo1 = false;
	vo2 = false;
	vo3 = false;
	unitsbuilt = false;
	obj1 = false;
	obj2 = false;	
	bridgegoboom = false;
	bseg1goboom = false;
	bseg2goboom = false;
	bseg3goboom = false;
	bstr1goboom = false;
	bstr2goboom = false;
	bridgegoboomover = false;
	vo5 = false;
	obj3 = false;
	playeratAAN = false;
	playeratbridge = false;
	atankattack = false;
	reroute1 = false;
	reroute1a = false;
	reroute1b = false;
	bridgedone = false;
	spawn2 = false;
	wave1over = false;
	vo7 = false;
	obj4 = false;
	spire1built = false;
//  floats
	vo1time = 999999.9f;
	vo2time = 999999.9f;
	vo3time = 999999.9f;
	bstr1boomtime = 999999.9f;	
	bstr2boomtime = 999999.9f;
	bseg1boomtime = 999999.9f;
	bseg2boomtime = 999999.9f;
	bseg3boomtime = 999999.9f;
	vo5time = 999999.9f;
	spawn2time = 999999.9f;
	vo7time = 999999.9f;
//  handles
	player = NULL;
	msg1 = NULL;
	msg2 = NULL;
	msg5 = NULL;
	fvtank1 = NULL;
	fvtank2 = NULL;
	fvtank3 = NULL;
	fvsent1 = NULL;
	fvsent2 = NULL;
	fvsent3 = NULL;
	spawner1 = NULL;
	spawner2 = NULL;
	spawner3 = NULL;
	spawner4 = NULL;
	spawner5 = NULL;
	spawner6 = NULL;
	spawner7 = NULL;
	spawner8 = NULL;
	atank1 = NULL;
	atank2 = NULL;
	bseg1 = GetHandle("bseg1");
	bseg2 = GetHandle("bseg2");
	bseg3 = GetHandle("bseg3");
	bstr1 = GetHandle("bstr1");
	bstr2 = GetHandle("bstr2");
	aanbase = GetHandle("aanbase");
	bridgetank = GetHandle("bridgetank");
	bridgescout = GetHandle("bridgescout");
	aangtow1 = GetHandle("aangtow1");
	aangtow2 = GetHandle("aangtow2");
	spire1site = GetHandle("spire1site");
	msg7 = NULL;
	gspire1 = NULL;
//  integers
}

void scion05::AddObject(Handle h)
{
	if (missionstart)
	{
		//TANKS
		if ((fvtank1 == NULL) && (IsOdf(h,"fvtank")))
		{
			fvtank1 = h;
		}

		else if ((fvtank2 == NULL) && (IsOdf(h,"fvtank")))
		{
			fvtank2 = h;
		}

		else if ((fvtank3 == NULL) && (IsOdf(h,"fvtank")))
		{
			fvtank3 = h;
		}

		//SENTS
		else if ((fvsent1 == NULL) && (IsOdf(h,"fvsent")))
		{
			fvsent1 = h;
		}

		else if ((fvsent2 == NULL) && (IsOdf(h,"fvsent")))
		{
			fvsent2 = h;
		}

		else if ((fvsent3 == NULL) && (IsOdf(h,"fvsent")))
		{
			fvsent3 = h;
		}

		//GUN SPIRES
		else if  (IsOdf(h,"fbspir"))
		{
			gspire1 = h;
		}
	}
}

void scion05::Execute(void)
{
/*
	Here is where you put what happens every frame.  
*/
player = GetPlayerHandle();

	if (!missionstart)
	{
		Ally(1,2);
		SetScrap(1,40);
		SetScrap(2,40);
		vo1time = (GetTime() + 3);
		vo3time = (GetTime() + 65);
		missionstart = true;
	}

	if ((!vo1) && (vo1time < GetTime()))
	{
		msg1 = AudioMessage("wohoo.wav"); //scion0501.wav Cook, Braddock is out of control.  He is staging a large asualt on an AAN base using his New Regime forces.  We are here to help defend the AAN base.  Get this base underway,once you have built at least three Sentries and three Tanks we will be ready to start helping the AAN base.  Hurry, if we take too long the base will be destroyed.
		vo1 = true;
	}

	if ((!obj1) && (vo1) && (IsAudioMessageDone(msg1)))
	{
		ClearObjectives();
		AddObjective("scion0501.otf", WHITE);///  Build 3 Sentries and 3 tanks.
		obj1 = true;
	}

	if ((!vo3) && (vo3time < GetTime()))
	{
		AudioMessage("wohoo.wav"); // scion0503.wav  (AAN BASE)  "Shabayev, hurry with that support, We are taking massive hits."
		vo3 = true;
	}

	//when player has built 3 tanks and 3 sentries
	if ((!unitsbuilt) && (IsAround(fvtank1) && (IsAround(fvtank2) && (IsAround(fvtank3)
		&& (IsAround(fvsent1) && (IsAround(fvsent2) && (IsAround(fvsent3))))))))
	{
		vo2time = (GetTime() + 3);
		unitsbuilt = true;            
	}
///telling player "go blow up bridge"
	if ((!vo2) && (vo2time < GetTime()))
	{
		msg2 = AudioMessage("wohoo.wav"); // scion0502.wav --  Ok, there is an ISDF bridge that braddock is using to easily get his forces to the AAN base, lets take it out.  It won't stop him completely but it will slow down his forces.  I'm giving you the coordinates, destroy that bridge.
		vo2 = true;
	}

	if ((!obj2) && (vo2) && (IsAudioMessageDone(msg2)))
	{
		ClearObjectives();
		AddObjective("scion0502.otf", WHITE); // Destroy the ISDF bridge
		SetObjectiveOn(bseg2);
		SetObjectiveName(bseg2,"ISDF Bridge");
		obj2 = true;
	}
////spawning in 2 IVATANK to be crossing the bridge when the player is there
	if ((!playeratbridge) && (vo2) && (GetDistance(player,bstr1) < 190))
	{
		atank1 = BuildObject("ivatank",3,"atankspawn");
		atank2 = BuildObject("ivatank",3,"spawn4");
		SetSkill(atank1,3);
		SetSkill(atank2,1);
		Retreat(atank1,"bridgepath");
		Retreat(atank2,"bridgepath");
		playeratbridge = true;
	}

	if ((!reroute1) && (playeratbridge) && (bridgegoboomover))
	{
		if (IsAround(atank1))
		{
			Goto(atank1,"player");
		}

		if (IsAround(atank2))
		{
			Goto(atank2,"player");
		}	

		reroute1 = true;
	}

	if ((!bridgedone) && (bridgegoboomover) && (playeratbridge) &&
		(!IsAround(bridgetank) && (!IsAround(bridgescout) && (!IsAround(atank1)
		&& (!IsAround(atank2))))))
	{
		vo5time = (GetTime() + 5);
		bridgedone = true;
	}
/*
	if ((!reroute1a) && (reroute1) && (IsAround(atank1) && (GetDistance(atank1,"bridgegonepathend") < 20)))
	{
		Goto(atank1,"aanbase");
		reroute1a = true;
	}

	if ((!reroute1b) && (reroute1) && (IsAround(atank2) && (GetDistance(atank2,"bridgegonepathend") < 20)))
	{
		Goto(atank2,"aanbase");
		reroute1b = true;
	}
*/
/////

	if ((!vo5) && (vo2) && (vo5time < GetTime()))
	{
		msg5 = AudioMessage("wohoo.wav");	// scion0505.wav Good job cook. That won't stop them completely but it will slow them down.  Now, go to the AAN base and help defend it from the incoming waves!
		vo5 = true;
	}

	if ((!obj3) && (vo5) && (IsAudioMessageDone(msg5)))
	{
		ClearObjectives();
		AddObjective("scion0503.otf", WHITE); // Goto the AAN base and help in it's defense against Braddock's forces.	
		SetObjectiveOn(aanbase);
		SetObjectiveName(aanbase,"AAN Base");
	/*
		spawner1 = BuildObject("ivscout",3,"spawn4");
		spawner2 = BuildObject("ivtank",3,"spawn1");
		spawner3 = BuildObject("ivtank",3,"spawn2");
		SetSkill(spawner1,2);
		SetSkill(spawner2,2);
		SetSkill(spawner3,2);
		Goto(spawner1,"aanbase");
		Goto(spawner2,"aanbase");
		Goto(spawner3,"aanbase");
	*/
		obj3 = true;
	}

/// Player reaches the AAN base
	if ((!playeratAAN) && (vo5) && (GetDistance(player,"aanbase") < 200))
	{
		AudioMessage("wohoo.wav"); // scion0506.wav AAN BASE.  Cook, thank god you are here.  Help us stave off Braddock's forces!  I'm having my recycler make some repair and ammo  pods for you, to help you through the next few waves.  
		spawner1 = BuildObject("ivtank",3,"spawn4");
		spawner2 = BuildObject("ivtank",3,"spawn1");
		spawner3 = BuildObject("ivtank",3,"spawn2");
		SetSkill(spawner1,2);
		SetSkill(spawner2,2);
		SetSkill(spawner3,2);
		Goto(spawner1,"aanbase");
		Goto(spawner2,"aanbase");
		Goto(spawner3,"aanbase");
		SetPlan("scion0501.aip",2);
		SetObjectiveOff(aanbase);
		playeratAAN = true;
	}
///WAVE 1 OVER
	if ((!wave1over) && (playeratAAN) && (!IsAround(spawner1) && (!IsAround(spawner2)
		&& (!IsAround(spawner3)))))
	{
		vo7time = (GetTime() + 10);
		spawn2time = (GetTime() + 3);
		wave1over = true;
	}

	if ((!spawn2) && (spawn2time < GetTime()))
	{
		spawner4 = BuildObject("ivatank",3,"spawn4");
		spawner5 = BuildObject("ivatank",3,"spawn3");	
		SetSkill(spawner1,2);
		SetSkill(spawner2,2);
		Goto(spawner1,"aanbase");
		Goto(spawner2,"aanbase");
		spawn2 = true;
	}

//SHAB IS TELLING COOK TO BUILD A GUN SPIRE AT THE LOCATION SHE GIVES
	if ((!vo7) && (vo7time < GetTime()))
	{
		msg7 = AudioMessage("wohoo.wav"); // scion0507 SHAB FROM SCION BASE - Cook, I want you to build a Gun Spire near the main chokepoint into the AAN base, I will objectify just where I want you to build it.  This should help you considerably.
		vo7 = true;
	}

	if ((!obj4) && (vo7) && (IsAudioMessageDone(msg7)))
	{
		ClearObjectives();
		AddObjective("scion0504.otf", WHITE);
		SetObjectiveOn(spire1site);
		SetObjectiveName(spire1site,"Gun Spire Site");
		obj4 = true;
	}

	//Checking to see when the spire is built
	if ((!spire1built) && (vo7) && (IsAround(gspire1) && (GetDistance(gspire1,spire1site) < 100)))
	{
		AudioMessage("wohoo.wav");
		spire1built = true;
	}




	
	
	
	
	

//////////////////////	
	///THIS IS FOR THE BRIDGE THAT GETS BLOWN UP
	// If one seg of the bridge is blown up, the other segs blow.  BRIDGE GO BOOM
	if (!bridgegoboom)
	{
		if ((!IsAround(bseg1)))
		{
			bstr2boomtime = (GetTime() + .7f);
			bseg2boomtime = (GetTime() + .7f);
			bseg3boomtime = (GetTime() + 1.4f);
			bstr1boomtime = (GetTime() + 2.1f);
			bridgegoboom = true;
		}

		if ((!IsAround(bseg2)))
		{
			bstr2boomtime = (GetTime() + 1.4f);
			bseg1boomtime = (GetTime() + .7f);
			bseg3boomtime = (GetTime() + .7f);
			bstr1boomtime = (GetTime() + 1.4f);
			bridgegoboom = true;
		}
	
		if ((!IsAround(bseg3)))
		{
			bstr2boomtime = (GetTime() + 2.1f);
			bseg1boomtime = (GetTime() + 1.4f);
			bseg2boomtime = (GetTime() + .7f);
			bstr1boomtime = (GetTime() + .7f);
			bridgegoboom = true;
		}

		if ((!IsAround(bstr1)))
		{
			bstr2boomtime = (GetTime() + 2.8f);
			bseg1boomtime = (GetTime() + 2.1f);
			bseg2boomtime = (GetTime() + 1.4f);
			bseg3boomtime = (GetTime() + .7f);
			bridgegoboom = true;
		}

		if ((!IsAround(bstr2)))
		{
			bstr1boomtime = (GetTime() + 2.8f);
			bseg1boomtime = (GetTime() + .7f);
			bseg2boomtime = (GetTime() + 1.4f);
			bseg3boomtime = (GetTime() + 2.1f);
			bridgegoboom = true;
		}
	}

	if (!bridgegoboomover)
	{
		if ((!bseg1goboom) && (bseg1boomtime <= GetTime()))
		{
			Damage(bseg1,6000);
			bseg1goboom = true;
		}

		if ((!bseg2goboom) && (bseg2boomtime <= GetTime()))
		{
			Damage(bseg2,6000);
			bseg2goboom = true;
		}

		if ((!bseg3goboom) && (bseg3boomtime <= GetTime()))
		{
			Damage(bseg3,6000);
			bseg3goboom = true;
		}

		if ((!bstr1goboom) && (bstr1boomtime <= GetTime()))
		{
			Damage(bstr1,6000);
			bstr1goboom = true;
		}

		if ((!bstr2goboom) && (bstr2boomtime <= GetTime()))
		{
			Damage(bstr2,6000);
			bstr2goboom = true;
		}

		if ((!IsAround(bstr1) && (!IsAround(bstr2) && (!IsAround(bseg1) && (!IsAround(bseg2)
			&& (!IsAround(bseg3)))))))
		{
			bridgegoboomover = true;
		}
	}
/////
/////
/////

}

