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

class scion06 : public SPMission 
{
public:
	scion06(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,
		powerout,vo1,vo2,
		obj1,obj2,obj3,vo3,
		base_repaired,repairs_started,vo4,spawn1,spawn2,spawn3,
		repairtakingtoolong,basekilled,vo6,vo7,convoymove,
		escort1close,escort1farahead,convoy_enroute,convoykilled,
		convoyattack,

		b_last;

	// floats
	float
		f_first,
		vo1time,
		vo2time,
		vo3time,
		vo6time,
		vo7time,
		spawn1time,
		spawn2time,
		spawn3time,
		repairtime,
		convoymovetime,
		f_last;

	// handles
	Handle
		h_first,
		enemyrecy,
		player,
		pgen1,
		pgen2,
		msg1,
		msg2,msg3,
		playerspgen1,playerspgen2,playersrecy,
		spawner1a,spawner1b,spawner2a,spawner2b,spawner3a,spawner3b,
		power,convoy_tug1,convoy_scout1,convoy_scout2,convoy_sent1,convoy_sent2,
		msg8,
		msg7,

		h_last;


	// integers
	int
		i_first,


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

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

//  bools
	missionstart = false;
	powerout = false;
	vo1 = false;
	vo2 = false;
	obj1 = false;
	base_repaired = false;
	obj2 = false;
	vo3 = false;
	repairs_started = false;
	vo4 = false;
	spawn1 = false;
	spawn2 = false;
	spawn3 = false;
	repairtakingtoolong = false;
	basekilled = false;
	vo6 = false;
	vo7 = false;
	obj3 = false;
	convoymove = false;
	convoy_enroute = false;
	convoykilled = false;
	convoyattack = false;

//  floats
	vo1time = 999999.9f;
	vo2time = 999999.9f;
	vo3time = 999999.9f;
	vo6time = 999999.9f;
	vo7time = 999999.9f;
	spawn1time = 999999.9f;	
	spawn2time = 999999.9f;	
	spawn3time = 999999.9f;	
	repairtime = 999999.9f;	
	convoymovetime = 999999.9f;	   
//  handles
	enemyrecy = GetHandle("enemyrecy");
	playersrecy = GetHandle("playersrecy");
	pgen1 = GetHandle("pgen1");
	pgen2 = GetHandle("pgen2");
	power = GetHandle("power");
	convoy_tug1 = GetHandle("convoy_tug1");
	convoy_scout1 = GetHandle("convoy_scout1");
	convoy_scout2 = GetHandle("convoy_scout2");
	convoy_sent1 = GetHandle("convoy_sent1");
	convoy_sent2 = GetHandle("convoy_sent2");
	player = NULL;
	msg1 = NULL;
	msg2 = NULL;
	msg3 = NULL;
	msg7 = NULL;
	msg8 = NULL;
	spawner1a= NULL;
	spawner1b = NULL;
	spawner2a = NULL;
	spawner2b = NULL;
	spawner3a = NULL;
	spawner3b = NULL;
//  integers




}

void scion06::AddObject(Handle h)
{
	if (missionstart)
	{
	
	
	
	}
}

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

	if (!missionstart)
	{
		SetScrap(1,1);
		vo1time = (GetTime() + 3);
		Pickup(convoy_tug1,power);
		Ally(2,3);
	//	SetObjectiveOn(enemyrecy);
	//	SetObjectiveName(enemyrecy,"Enemy");
		missionstart = true;
	}

	if ((!vo1) && (vo1time < GetTime()))
	{
		msg1 = AudioMessage("wohoo.wav"); //scion0601.wav Cook, we have learned that the Evil Scions will be delivering the last power source to Braddock's base any time now.  We must destroy Braddock's base BEFORE the Evil Scion convoy reaches it, It would be nearly impossible to get that crystal with Braddock's forces around.   Time is short, so you are being given control of the AAN base we helped to rescue in the last operation.  Use it to overtake Braddock's base before the Evil Scions can get there with the crystal.
		vo1 = true;
	}

	if ((!obj1) && (vo1) && (IsAudioMessageDone(msg1)))
	{
		ClearObjectives();
		AddObjective("scion0601.otf", WHITE);///Make base repairs!
		spawn1time = (GetTime() + 65);
		obj1 = true;
	}


//1st WAVE
	if ((!spawn1) && (spawn1time < GetTime()))
	{
		spawner1a = BuildObject("ivscout",2,"spawn1a");
		spawner1b = BuildObject("ivscout",2,"spawn1b");	
		SetSkill(spawner1a,1);
		SetSkill(spawner1b,1);
		Goto(spawner1a,"playerbase");
		Goto(spawner1b,"playerbase");
		spawn1 = true;
	}
///////


///when player has started base repairs
	if ((!repairs_started) && (GetCurHealth(playersrecy) > 3005))
	{
		AudioMessage("wohoo.wav"); // scion0602.wav Good.  That repair job could take a while, continue building up your forces in the meantime.
		spawn2time = (GetTime() +25);
		repairtime = (GetTime() + 500);
		repairs_started = true;
	}

	if ((!repairtakingtoolong) && (!base_repaired) && (repairtime < GetTime()))
	{
		AudioMessage("wohoo.wav"); //scion0605.wav That recycler should have been fully repaired by now, cook what's going on?
		repairtakingtoolong = true;
	}

	//2nd WAVE
	if ((!spawn2) && (spawn2time < GetTime()))
	{
		spawner2a = BuildObject("ivtank",2,"spawn2a");
		spawner2b = BuildObject("ivtank",2,"spawn2b");	
		SetSkill(spawner2a,2);
		SetSkill(spawner2b,3);
		Goto(spawner2a,"playerbase");
		Goto(spawner2b,"playerbase");
		spawn2 = true;	
	}
	///
	////When player has finished base repairs	
	if ((!base_repaired) && (obj1) && (GetCurHealth(playersrecy) > 10000))
	{
		vo3time = (GetTime() + 2);
		spawn3time = (GetTime() + 10);
		base_repaired = true;
	}

	//3rd WAVE
	if ((!spawn3) && (spawn3time < GetTime()))
	{
		spawner3a = BuildObject("ivtank",3,"spawn3a");
		spawner3b = BuildObject("ivscout",3,"spawn3b");
		SetSkill(spawner3a,2);
		SetSkill(spawner3b,2);
		Goto(spawner3a,"playerbase");
		Goto(spawner3b,"playerbase");
		spawn3 = true;
	}
	////

	if ((!vo3) && (vo3time < GetTime()))
	{
		msg3 = AudioMessage("wohoo.wav"); ///Scion0603.wav Ok the repairs are complete.  Now we should be in good shape for the base assault.  Continue to build your forces, and take out that base!	
		vo3 = true;
	}

	if ((!obj2) && (vo3) && (IsAudioMessageDone(msg3)))
	{
		ClearObjectives();
		AddObjective("scion0602.otf", WHITE);///Destroy Braddock's Base
		SetObjectiveOn(enemyrecy);
		SetObjectiveName(enemyrecy,"Braddock's Base");
		obj2 = true;
	}

	//when player gets near enemy base
	if ((!vo4) && (obj2) && (GetDistance(player,"enemybase") < 220))
	{
		AudioMessage("wohoo.wav"); //Scion0604.wav Cook go for the power generators, that will buy you some time to take out those guntowers.
		vo4 = true;
	}

//// When braddock's base is KILLED before the convoy gets there
	if ((!basekilled) && (obj2) && (!IsAround(enemyrecy)))
	{
		vo6time = (GetTime() + 4);
		basekilled = true;
	}

	if ((!vo6) && (vo6time < GetTime()))
	{
		AudioMessage("wohoo.wav"); //Scion0606.wav Good job, you've knocked the base out of commission.
		vo7time = (GetTime() + 8);
		vo6 = true;
	}

	if ((!vo7) && (vo7time < GetTime()))
	{
		msg7 = AudioMessage("wohoo.wav"); ///Scion0607.wav It looks like we took out that base just in time, we've just picked up the Evil Scion convoy on radar and they are nearing the base!  Move as many forces to the destroyed base as you can, we must take out that convoy. Remember, do not damage the power source.  (SHAB)
		vo7 = true;
	}

	if ((!obj3) && (vo7) && (IsAudioMessageDone(msg7)))
	{
		ClearObjectives();
		AddObjective("scion0603.otf", WHITE);///Move forces to destroyed base, intercept Evil Scion convoy
		convoymovetime = (GetTime() + 10);
		obj3 = true;
	}

	if ((!convoymove) && (convoymovetime < GetTime()))
	{
		Retreat(convoy_scout1,"convoypath");
		Follow(convoy_scout2,convoy_scout1);
		Retreat(convoy_tug1,"convoypath");
		Follow(convoy_sent1,convoy_tug1);
		Follow(convoy_sent2,convoy_tug1);
		convoymove = true;
	}

	if (!convoy_enroute)
	{
		if ((!escort1farahead) && (GetDistance(convoy_scout1,convoy_tug1) > 100))
		{
			Stop(convoy_scout1);
			Stop(convoy_scout2);
			escort1close = false;
			escort1farahead = true;
		}

		if ((!escort1close) && (escort1farahead) && (GetDistance(convoy_scout1,convoy_tug1) < 90))
		{
			Retreat(convoy_scout1,"convoypath");
			Follow(convoy_scout2,convoy_scout1);		
			escort1close = true;
			escort1farahead = false;
		}

	////When convoy meets player
		if ((GetDistance(player,convoy_scout1) < 200))
		{
			msg8 = AudioMessage("wohoo.wav");  //scion0608.wav EVIL CONVOY:  Squad alpha here, we have the package…Hey wait a minute, those aren't Braddock's forces!  Destroy them!
			convoy_enroute = true;
		}
	}

	if ((!convoyattack) && (convoy_enroute) && (IsAudioMessageDone(msg8)))
	{
		Attack(convoy_scout1,player);
		convoyattack = true;
	}
}


