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

class Misn04Mission : public SPMission 
{
public:
	Misn04Mission(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, deploy, unDeploy,

		b_last;

	// floats
	float
		f_first, delayTime,
		f_last;

	// handles
	Handle
		h_first,
		player, spawn1, spawn2, animal1, animal2, animal3, animal4,
		enemy1, animalFood, apc, building, recycler, constructor, spawn3,
		armoredPC, point1, point2,
		
		h_last;

	// integers
	int
		i_first, missionState, 

		i_last;
};

DLLBase * BuildMission(void)
{
	return new Misn04Mission();
}

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

//  bools
	deploy = false;
	unDeploy = false;


//  floats
	delayTime = 0.0;


//  handles
	player = GetPlayerHandle();
	spawn1 = GetHandle("spawn1");
	spawn2 = GetHandle("spawn2");
	spawn3 = GetHandle("spawn3");
	recycler = GetHandle("recycler");
	building = GetHandle("building");
	SetGroup(recycler, -2);
	constructor = GetHandle("construction");
	SetGroup(constructor, -2);
	armoredPC = GetHandle("apc");
	SetGroup(armoredPC, -2);
	enemy1 = GetHandle("tank");
	point1 = GetHandle("bridge");
	point2 = GetHandle("point2");
//  integers
	missionState = 0;



	IFace_CreateInteger("script.mission.state", 0);
}

void Misn04Mission::AddObject(Handle h)
{
	// SCOUT

}


void Misn04Mission::Execute(void)
{
/*
	Here is where you put what happens every frame.  
*/
	missionState = IFace_GetInteger("script.mission.state");

	switch (missionState) {
	case 0: // create the animals
		animal1 = BuildObject("mcjak01",3,spawn1);
		animal2 = BuildObject("mcjak01",3,spawn3);
		animalFood = BuildObject("assold",2,spawn2);
		Attack(animal1,animalFood,1);
		Attack(animal2,animalFood,1);
		Attack(animalFood, animal1, 1);
		IFace_SetInteger("script.mission.state", 1);
		break;
	case 1: //wait until I kill all of the animals
		if ((!IsAlive(animal1)) && (!IsAlive(animal2))) {
			IFace_SetInteger("script.mission.state", 2);
		}
		break;
	case 2: //spawn enemy unit to show morphing
		SetSkill(enemy1, 3);
		Attack(enemy1, player, 1);
		IFace_SetInteger("script.mission.state", 3);
		break;
	case 3: //wait for the player to kill the morph tank
		if (!IsAlive(enemy1)) {
			IFace_SetInteger("script.mission.state", 4);
		}
		if ((GetDistance(enemy1, player) < 125) && (!deploy)) {
			deploy = true;
			Deploy(enemy1);
		}
/*		if ((GetDistance(enemy1, player) < 50) && (deploy) && (!unDeploy)) {
			unDeploy = true;
			Deploy(enemy1);
		} */
		break;
	case 4: //send in the apc
		SetGroup(armoredPC, 0);
		IFace_SetInteger("script.mission.state", 5);
		break;
	case 5:
		if (!IsAlive(building)) {
			Damage(armoredPC, 10000);
			IFace_SetInteger("script.mission.state", 6);
		}
		break;
	case 6:
		SetGroup(recycler, 0);
		SetGroup(constructor, 1);
		IFace_SetInteger("script.mission.state", 7);
		SetScrap(2, 200);
		break;
	case 7:
		SetObjectiveOn(point1);
		SetObjectiveName(point1,"Bridge");
		SetPerceivedTeam(point1, 1);
		IFace_SetInteger("script.mission.state", 8);
		break;
	case 8:
		if (!IsAlive(point1)) {
			IFace_SetInteger("script.mission.state", 9);
		}
		break;
	case 9:
		SetObjectiveOn(point2);
		SetObjectiveName(point2,"Ruins");
		IFace_SetInteger("script.mission.state", 10);
		break;
	case 10:
		break;
	}

	if (GetScrap(2) < 50) {
		SetScrap(2, 50);
	}



}
