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

class scion03 : public SPMission 
{
public:
	scion03(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,wave1,wave2,wave3,wave4,wave5,checktank1alive,tank1alive,checktank1dead,
		tank1go,checktank2alive,tank2alive,checktank2dead,tank2go,checktank3alive,tank3alive,
		checktank3dead,tank3go,vo1,obj1,powergotten,powerhome,enemyrecydead,vo3,powerdead,
		obj3,
		vo5,
		b_last;

	// floats
	float
		f_first,
		wave1time,wave2time,wave3time,wave4time,wave5time,vo1time,vo3time,vo5time,

		f_last;

	// handles
	Handle
		h_first,
		spawner1a,spawner1b,spawner2a,spawner2b,spawner3a,spawner3b,spawner4a,msg1,recy1,
		spawner4b,spawner4c,spawner5a,spawner5b,spawner5c,aitank1,aitank2,aitank3,power,
		msg4,
		h_last;


	// integers
	int
		i_first,


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

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

//  bools
	missionstart = false;
	wave1 = false;
	wave2 = false;
	wave3 = false;
	wave4 = false;
	wave5 = false;	
	checktank1alive = false;
	tank1alive = false;
	checktank1dead = false;
	tank1go = false;
	checktank2alive = false;
	tank2alive = false;
	checktank2dead = false;
	tank2go = false;
	checktank3alive = false;
	tank3alive = false;
	checktank3dead = false;
	tank3go = false;
	vo1 = false;
	obj1 = false;
	powergotten = false;
	powerhome = false;
	enemyrecydead = false;
	vo3 = false;
	powerdead = false;
	vo5 = false;
	obj3 = false;

//  floats
	wave1time = 999999.9f;
	wave2time = 999999.9f;
	wave3time = 999999.9f;	
	wave4time = 999999.9f;
	wave5time = 999999.9f;
	vo1time = 999999.9f;
	vo3time = 999999.9f;
	vo5time = 999999.9f;
//  handles
	spawner1a = NULL;
	spawner1b = NULL;
	spawner2a = NULL;
	spawner2b = NULL;
	spawner3a = NULL;
	spawner3b = NULL;
	spawner4a = NULL;
	spawner4b = NULL;
	spawner4c = NULL;
	spawner5a = NULL;
	spawner5b = NULL;
	spawner5c = NULL;
	aitank1 = NULL;
	aitank2 = NULL;
	aitank3 = NULL;
	msg1 = NULL;
	msg4 = NULL;
	power = GetHandle("power");
	recy1 = GetHandle("recy1");
//  integers




}

void scion03::AddObject(Handle h)
{
	if ((aitank1 == NULL) && (IsOdf(h,"ivtank")))
	{
		aitank1 = h;
	}

	else if ((aitank2 == NULL) && (IsOdf(h,"ivtank")))
	{
		aitank2 = h;
	}

	else if ((aitank3 == NULL) && (IsOdf(h,"ivtank")))
	{
		aitank3 = h;
	}
}

void scion03::Execute(void)
{
/*
	Here is where you put what happens every frame.  
*/

	if (!missionstart)
	{
		SetScrap(1,30);
		SetScrap(2,30);
		wave1time = (GetTime() + 60);
		SetPlan("scion0301.aip",2);
		vo1time = (GetTime() + 4);
		missionstart = true;
	}

	if ((!vo1) && (vo1time < GetTime()))
	{
		msg1 = AudioMessage("scion0301.wav"); //The last powersource is being held in a well-protected ISDF base to the North.  Cook it is up to you to retrieve it.  First, focus on destroying the base's defenses.  Then when you are able, move in with a Hauler and bring the power source back to your base.  Expect VERY heavy resistance, the ISDF will do all in their power to keep us from the power source. 
		vo1 = true;
	}

	if ((!obj1) && (vo1) && (IsAudioMessageDone(msg1)))
	{
		ClearObjectives();
		AddObjective("scion0301.otf", WHITE);
		SetObjectiveOn(power);
		SetObjectiveName(power,"Power Source");
		obj1 = true;
	}

	if ((!powergotten) && (GetTug(power)))
	{
		AudioMessage("scion0302.wav"); //Good Cook, you've got it.  Bring it back to base, hurry!
		powergotten = true;
	}


//mission lost if powersource ever gets destroyed
	if ((!powerdead) && (!IsAround(power)))
	{
		vo5time = (GetTime() + 4);
		powerdead = true;
	}

	if ((!vo5) && (vo5time < GetTime()))
	{
		AudioMessage("scion0305.wav"); //Dammit Cook, the powersource has been destroyed!!
		vo5 = true;
	}
//when player takes out the enemy reclycler
	if ((!enemyrecydead) && (!IsAround(recy1)))
	{
		vo3time = (GetTime() + 5);
		enemyrecydead = true;
	}
	
	if ((!vo3) && (vo3time < GetTime()))
	{
		AudioMessage("scion0303.wav"); //You've taken out the enemy's recycler, nice work!
		vo3 = true;
	}

//when power is near player base, mission accomplished
	if ((!powerhome) && (GetDistance(power,"playerbase") < 100))
	{
		msg4 = AudioMessage("scion0304.wav");//Cook you did it!  Nice job.  Mission accomplished
		powerhome = true;
	}

	if ((!obj3) && (powerhome) && (IsAudioMessageDone(msg4)))
	{
		ClearObjectives();
		AddObjective("scion0303.otf", WHITE);	
		obj3 = true;
	}

	///////helping out the AIP

	if ((!checktank1alive) && (IsAlive(aitank1)))	
	{
		tank1alive = true;
		checktank1alive = true;
		checktank1dead = false;
		tank1go = false;
	}

	if ((!checktank1dead) && (!IsAlive(aitank1)))
	{
		tank1alive = false;
		checktank1alive = false;
		checktank1dead = true;
	}

	if ((!tank1go) && (tank1alive))
	{
		Goto(aitank1,"scout1point");
		tank1go = true;
	}
//////////////
	if ((!checktank2alive) && (IsAlive(aitank2)))	
	{
		tank2alive = true;
		checktank2alive = true;
		checktank2dead = false;
		tank2go = false;
	}

	if ((!checktank2dead) && (!IsAlive(aitank2)))
	{
		tank2alive = false;
		checktank2alive = false;
		checktank2dead = true;
	}

	if ((!tank2go) && (tank2alive))
	{
		Goto(aitank2,"scout2point");
		tank2go = true;
	}
//////////////
	if ((!checktank3alive) && (IsAlive(aitank3)))	
	{
		tank3alive = true;
		checktank3alive = true;
		checktank3dead = false;
		tank3go = false;
	}

	if ((!checktank3dead) && (!IsAlive(aitank3)))
	{
		tank3alive = false;
		checktank3alive = false;
		checktank3dead = true;
	}

	if ((!tank3go) && (tank3alive))
	{
		Goto(aitank3,"scout3point");
		tank3go = true;
	}
//////////////
	

	
	
	if ((!wave1) && (wave1time < GetTime()))
	{
		spawner1a = BuildObject("ivscout",2,"spawn1");
		spawner1b = BuildObject("ivscout",2,"spawn2");
		SetSkill(spawner1a,1);
		SetSkill(spawner1b,2);
		Goto(spawner1a,"playerbase");
		Goto(spawner1b,"playerbase");
		wave2time = (GetTime() + 120);
		wave1 = true;
	}

	if ((!wave2) && (wave2time < GetTime()))
	{
		spawner2a = BuildObject("ivscout",2,"spawn3");
		spawner2b = BuildObject("ivscout",2,"spawn4");
		SetSkill(spawner2a,1);
		SetSkill(spawner2b,2);
		Goto(spawner2a,"playerbase");
		Goto(spawner2b,"playerbase");
		wave3time = (GetTime() + 130);
		wave2 = true;
	}

	if ((!wave3) && (wave3time < GetTime()))
	{
		spawner3a = BuildObject("ivscout",2,"spawn1");
		spawner3b = BuildObject("ivscout",2,"spawn4");
		SetSkill(spawner3a,1);
		SetSkill(spawner3b,2);
		Goto(spawner3a,"playerbase");
		Goto(spawner3b,"playerbase");
		wave4time = (GetTime() + 190);
		wave3 = true;
	}

	if ((!wave4) && (wave4time < GetTime()))
	{
		spawner4a = BuildObject("ivtank",2,"spawn1");
		spawner4b = BuildObject("ivscout",2,"spawn2");
		spawner4c = BuildObject("ivtank",2,"spawn3");
		SetSkill(spawner4a,1);
		SetSkill(spawner4b,2);
		SetSkill(spawner4c,2);
		Goto(spawner4a,"playerbase");
		Goto(spawner4b,"playerbase");
		Goto(spawner4c,"playerbase");
		wave5time = (GetTime() + 190);
		wave4 = true;
	}

	if ((!wave5) && (wave5time < GetTime()))
	{
		spawner5a = BuildObject("ivtank",2,"spawn1");
		spawner5b = BuildObject("ivscout",2,"spawn2");
		spawner5c = BuildObject("ivtank",2,"spawn3");
		SetSkill(spawner5a,1);
		SetSkill(spawner5b,2);
		SetSkill(spawner5c,2);
		Goto(spawner5a,"playerbase");
		Goto(spawner5b,"playerbase");
		Goto(spawner5c,"playerbase");
		wave5 = true;
	}
	

}

