/*
Solar Conquest
Copyright (C) 2006 Greg Beaman

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

float g_respawnTime = 0;
Vector g_respawnPoint;

#define NUM_MESSAGES 10
#define MSG_TYPE_ALERT 0
#define MSG_TYPE_INFO 1
#define MSG_TYPE_COMMAND 2
#define MSG_TYPE_ASHLEY 3
#define MSG_TYPE_RODNEY 4
#define MSG_TYPE_MORETTI 5
#define MSG_TYPE_YOU 6

struct Message
{
	char text[MAX_STRING_SIZE];
	int msgType;
};
Message Messages[NUM_MESSAGES];

void ClearMessages()
{
	for (int i=0; i < NUM_MESSAGES; i++)
		strcpy(Messages[i].text, "");
}

void AddMessage(char* msg, int type)
{
	if (strlen(msg) >= MAX_STRING_SIZE)
		return;

	for (int i=NUM_MESSAGES-1; i > 0; i--)
	{
		strcpy(Messages[i].text,Messages[i-1].text);
		Messages[i].msgType == Messages[i-1].msgType;
	}
	strcpy(Messages[0].text,msg);
	Messages[0].msgType = type;
}

void PlaceSpaceStation(Vector position, int team)
{
	//Station
	CObject* station = AddObject(FindObjectData(203));
	if (station)
	{
		station->SetTeam(team);
		station->SetPosition(position);
	}

	CFactory* factory;

	//Factories!
	for (int x=0; x < 3; x++)
	{
		for (int y=0; y < 3; y++)
		{
			factory = AddFactory();
			if (factory)
			{
				factory->team = team;
				factory->obj = 4;
				factory->parent = station;
				factory->position = AddVectors(position,CreateVector(-295 + 30 + 60*x, -92.5 + 30 + 60*y));
			}
	
			factory = AddFactory();
			if (factory)
			{
				factory->team = team;
				factory->obj = 4;
				factory->parent = station;
				factory->position = AddVectors(position,CreateVector( 95 + 30 + 60*x, -92.5 + 30 + 60*y));
			}
		}
	}
}

void PlaceTurretStation(Vector position, int team)
{
	//Station
	CObject* station = AddObject(FindObjectData(202));
	if (station)
	{
		station->SetTeam(team);
		station->SetPosition(position);
	}

	CObject* obj;

	//Station turrets, top
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(-80,-220)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(  0,-220)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector( 80,-220)));
	}
	//bottom
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(-80,220)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(  0,220)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector( 80,220)));
	}
	//left
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(-220, -80)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(-220, 0)));
	}
	//right
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(220, -80)));
	}
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(220, 0)));
	}
}

void PlaceLightTurretStation(Vector position, int team)
{
	//Station
	CObject* station = AddObject(FindObjectData(202));
	if (station)
	{
		station->SetTeam(team);
		station->SetPosition(position);
	}

	CObject* obj;

	//Station turrets, top
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(  0,-220)));
	}
	//bottom
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(  0,220)));
	}
	//left
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(-220, 0)));
	}
	//right
	obj = AddObject(FindObjectData(5));
	if (obj)
	{
		obj->SetTeam(team);
		obj->SetPosition(AddVectors(position,CreateVector(220, 0)));
	}
}

void PlaceAttackerCarrierShip(Vector position, float angle, int team, int obj)
{
	//Carrier
	CObject* capShip = AddObject(FindObjectData(200));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,-130),position));
	}
	
	//Repair ship
	CFactory* factory = AddFactory();
	if (factory)
	{
		factory->team = team;
		factory->obj = 3;
		factory->position = AddVectors(CreateVector(0,-195),position);
		factory->parent = capShip;
	}

	//Production
	{
	for (int z=-1; z < 2; z++)
	{
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = obj;
			factory->position = AddVectors(CreateVector(-100,65*z),position);
			factory->parent = capShip;
		}
	
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = obj;
			factory->position = AddVectors(CreateVector(100,65*z),position);
			factory->parent = capShip;
		}
	}
	}

	//Turrets
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(-40,-130),position));
	}
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(40,-130),position));
	}
}

void PlaceCharacterShip(Vector position, float angle, int team, int character)
{
	//Carrier
	CObject* capShip = AddObject(FindObjectData(200));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,-130),position));
	}
	
	//Adv. Fighter (Character)
	CFactory* factory;
	CFactory* hero = AddFactory();
	if (hero)
	{
		hero->team = team;
		hero->obj = 4;
		hero->aiType = character;
		hero->position = AddVectors(CreateVector(0,-195),position);
		hero->parent = capShip;
	}

	//Production
	{
	for (int z=-1; z < 2; z++)
	{
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = 1;
			factory->aiType = AI_TYPE_FOLLOWER;
			factory->aiParent = hero;
			factory->position = AddVectors(CreateVector(-100,65*z),position);
			factory->parent = capShip;
		}
	
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = 1;
			factory->aiType = AI_TYPE_FOLLOWER;
			factory->aiParent = hero;
			factory->position = AddVectors(CreateVector(100,65*z),position);
			factory->parent = capShip;
		}
	}
	}

	//Turrets
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(-40,-130),position));
	}
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(40,-130),position));
	}
}

void PlaceAttackerDestroyerShip(Vector position, float angle, int team)
{
	//Carrier
	CObject* capShip = AddObject(FindObjectData(201));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,0),position));
	}

	//Turrets
	for (int i=1; i < 5; i++)
	{
		capShip = AddObject(FindObjectData(8)); //5
		if (capShip)
		{
			capShip->SetAngle(angle);
			capShip->SetTeam(team);
			capShip->SetPosition(AddVectors(CreateVector(-40,-225 + i*80),position));
		}
		capShip = AddObject(FindObjectData(8)); //5
		if (capShip)
		{
			capShip->SetAngle(angle);
			capShip->SetTeam(team);
			capShip->SetPosition(AddVectors(CreateVector(40,-225 + i*80),position));
		}
	}

/*	capShip = AddObject(FindObjectData(8));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,-225 + 80),position));
	}*/

	capShip = AddObject(FindObjectData(8));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,225 - 80),position));
	}
}

void PlaceDefenderCarrierShip(Vector position, float angle, int team, int obj)
{
	CObject* capShip = AddObject(FindObjectData(200));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,130),position));
	}
		
	CFactory* factory = AddFactory();
	if (factory)
	{
		factory->team = team;
		factory->obj = 3;
		factory->position = AddVectors(CreateVector(0,195),position);
		factory->parent = capShip;
	}

	{
	for (int z=-1; z < 2; z++)
	{
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = obj;
			factory->position = AddVectors(CreateVector(-100,65*z),position);
			factory->parent = capShip;
		}
	
		factory = AddFactory();
		if (factory)
		{
			factory->team = team;
			factory->obj = obj;
			factory->position = AddVectors(CreateVector(100,65*z),position);
			factory->parent = capShip;
		}
	}
	}

	//Turrets
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(-40,130),position));
	}
	capShip = AddObject(FindObjectData(5));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(40,130),position));
	}
}

void PlaceDefenderDestroyerShip(Vector position, float angle, int team)
{
	//Carrier
	CObject* capShip = AddObject(FindObjectData(201));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,0),position));
	}

	//Turrets
	for (int i=1; i < 5; i++)
	{
		capShip = AddObject(FindObjectData(8)); //5
		if (capShip)
		{
			capShip->SetAngle(angle);
			capShip->SetTeam(team);
			capShip->SetPosition(AddVectors(CreateVector(-40,225 - i*80),position));
		}
		capShip = AddObject(FindObjectData(8)); //5
		if (capShip)
		{
			capShip->SetAngle(angle);
			capShip->SetTeam(team);
			capShip->SetPosition(AddVectors(CreateVector(40,225 - i*80),position));
		}
	}
	capShip = AddObject(FindObjectData(8));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,-225 + 80),position));
	}

/*	capShip = AddObject(FindObjectData(8));
	if (capShip)
	{
		capShip->SetAngle(angle);
		capShip->SetTeam(team);
		capShip->SetPosition(AddVectors(CreateVector(0,225 - 80),position));
	}*/
}

void ActionScreen_Start()
{
	ClearMessages();
	SetupProjectileCache();

#ifdef STATISTICS_MODE
	if (g_particles)
		printf("Action screen starting with %d particles in the cache\n",g_particles->GetCacheCount());
#endif
	if (g_numBackgrounds > 0 && g_textureList)
	{
		srand(SDL_GetTicks());
		g_curBackground = g_textureList->FindNode((rand()%g_numBackgrounds)+100);
	}

	g_curScreen = GAME_SCREEN_ACTION;
	g_respawnTime = 0;
	
	CObject* obj;
	obj = AddObject(FindObjectData(4));
	if (obj)
	{
		//Player spanws at the center of the map, on the x axis
		obj->SetState(OBJ_STATE_PLAYER);
		g_respawnPoint = CreateVector(MAP_SIZE*TILE_SIZE*0.5,3000);
		obj->SetPosition(g_respawnPoint);
		obj->SetTeam(1);
		playerObject = obj;
	}
	else
		playerObject = NULL;
		
	DebugMessage(3,"Placing other objects");

	CFactory* factory;
	CObject* capShip;
	Vector position;
	
	float randAngle,randDist;

	if (g_level > 1) //If we're not in skirmish and we're not in the tutorial
	{
		//Ashley's carrier
		if (g_level != 3)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%3)+4) * 100;
		
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
			PlaceCharacterShip(position,3.14,1,AI_TYPE_ASHLEY);
		}
		//Rodney's carrier
		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%3)+4) * 100;
	
		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		PlaceCharacterShip(position,3.14,1,AI_TYPE_RODNEY);
	}

	//Add light turret stations
	if (g_level == 1)
	{
		PlaceLightTurretStation(CreateVector(MAP_SIZE*TILE_SIZE*0.5, MAP_SIZE*TILE_SIZE*0.5),2);
		PlaceLightTurretStation(CreateVector(500, MAP_SIZE*TILE_SIZE*0.5),2);
		PlaceLightTurretStation(CreateVector(MAP_SIZE*TILE_SIZE - 500, MAP_SIZE*TILE_SIZE*0.5),2);
	}

	//Add the SPACE STATION! >:)
	if (g_level == 4)
	{
		Vector stationPos = CreateVector(MAP_SIZE*TILE_SIZE*0.5,MAP_SIZE*TILE_SIZE - 300);
		PlaceSpaceStation(stationPos, 1);
		PlaceTurretStation(AddVectors(CreateVector(-600,0),stationPos),1);
		PlaceTurretStation(AddVectors(CreateVector( 600,0),stationPos),1);
		PlaceTurretStation(AddVectors(CreateVector(0,-600),stationPos),1);
	}

	{
	for (int i=0; i < g_alliedFighterCarriers; i++)
	{
//		position = CreateVector(150+(i*400),2500);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_alliedFighterCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_alliedFighterCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceAttackerCarrierShip(position,3.14,1,1); //Fighters
	}
	}

	{
	for (int i=0; i < g_alliedBomberCarriers; i++)
	{
//		position = CreateVector(150+(i*400),2000);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_alliedBomberCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_alliedBomberCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceAttackerCarrierShip(position,3.14,1,2); //Bombers
	}
	}

	{
	for (int i=0; i < g_alliedAdvFighterCarriers; i++)
	{
//		position = CreateVector(150+(i*400),2000);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_alliedAdvFighterCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_alliedAdvFighterCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceAttackerCarrierShip(position,3.14,1,4); //Adv. Fighters
	}
	}

	{
	for (int i=0; i < g_alliedAdvBomberCarriers; i++)
	{
//		position = CreateVector(150+(i*400),2000);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_alliedAdvBomberCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_alliedAdvBomberCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceAttackerCarrierShip(position,3.14,1,6); //Adv. Bombers
	}
	}

	{
	for (int i=0; i < g_alliedDestroyers; i++)
	{
		position = CreateVector(150+(i*400),3000);
		PlaceAttackerDestroyerShip(position,0,1);
	}
	}

	{
	for (int i=0; i < g_enemyFighterCarriers; i++)
	{
//		position = CreateVector(150+(i*400),5000);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_enemyFighterCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + (MAP_SIZE*TILE_SIZE-3000));

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_enemyFighterCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceDefenderCarrierShip(position,0,2,1); //Fighters
	}
	}

	{
	for (int i=0; i < g_enemyBomberCarriers; i++)
	{
//		position = CreateVector(150+(i*400),5500);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_enemyBomberCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + (MAP_SIZE*TILE_SIZE-3000));

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_enemyBomberCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceDefenderCarrierShip(position,0,2,2); //Bombers
	}
	}

	{
	for (int i=0; i < g_enemyAdvFighterCarriers; i++)
	{
//		position = CreateVector(150+(i*400),5500);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_enemyAdvFighterCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + (MAP_SIZE*TILE_SIZE-3000));

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_enemyAdvFighterCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceDefenderCarrierShip(position,0,2,4); //Adv. Fighters
	}
	}

	{
	for (int i=0; i < g_enemyAdvBomberCarriers; i++)
	{
//		position = CreateVector(150+(i*400),5500);

		randAngle = ToRadians(rand()%360);
		randDist = ((rand()%g_enemyAdvBomberCarriers)+4) * 100;

		position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + (MAP_SIZE*TILE_SIZE-3000));

		while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
		{
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_enemyAdvBomberCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
		}

		PlaceDefenderCarrierShip(position,0,2,6); //Adv. Bombers
	}
	}

	{
	for (int i=0; i < g_enemyDestroyers; i++)
	{
		position = CreateVector(150+(i*400),4500);
		PlaceDefenderDestroyerShip(position,3.14,2);
	}
	}

	//Laser Fighters
	if (g_level == 5)
	{
		int g_enemyLaserFighterCarriers = 8;
		{
		for (int i=0; i < g_enemyLaserFighterCarriers; i++)
		{
	//		position = CreateVector(150+(i*400),5500);
	
			randAngle = ToRadians(rand()%360);
			randDist = ((rand()%g_enemyLaserFighterCarriers)+4) * 100;
	
			position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + (MAP_SIZE*TILE_SIZE-3000));
	
			while (position.x < 0 || position.x >= MAP_SIZE*TILE_SIZE || position.y < 0 || position.y >= MAP_SIZE*TILE_SIZE)
			{
				randAngle = ToRadians(rand()%360);
				randDist = ((rand()%g_enemyLaserFighterCarriers)+4) * 100;
		
				position = CreateVector(sin(randAngle)*randDist + MAP_SIZE*TILE_SIZE*0.5, cos(randAngle)*randDist + 3000);
			}
	
			PlaceDefenderCarrierShip(position,0,2,9); //Laser Fighters
		}
		}
	}
}

void LoadLevel(int level)
{
	if (level == 1)
	{
		g_alliedFighterCarriers = 1;
		g_alliedBomberCarriers = 0;
		g_alliedAdvFighterCarriers = 0;
		g_alliedAdvBomberCarriers = 0;
		g_enemyFighterCarriers = 0;
		g_enemyBomberCarriers = 0;
		g_enemyAdvFighterCarriers = 0;
		g_enemyAdvBomberCarriers = 0;
	}
	else if (level == 2)
	{
		g_alliedFighterCarriers = 0;
		g_alliedBomberCarriers = 0;
		g_alliedAdvFighterCarriers = 0;
		g_alliedAdvBomberCarriers = 0;
		g_enemyFighterCarriers = 0;
		g_enemyBomberCarriers = 3;
		g_enemyAdvFighterCarriers = 0;
		g_enemyAdvBomberCarriers = 0;
	}
	else if (level == 3)
	{
		g_alliedFighterCarriers = 2;
		g_alliedBomberCarriers = 1;
		g_alliedAdvFighterCarriers = 0;
		g_alliedAdvBomberCarriers = 0;
		g_enemyFighterCarriers = 3;
		g_enemyBomberCarriers = 4;
		g_enemyAdvFighterCarriers = 0;
		g_enemyAdvBomberCarriers = 0;
	}
	else if (level == 4)
	{
		g_alliedFighterCarriers = 10;
		g_alliedBomberCarriers = 6;
		g_alliedAdvFighterCarriers = 0;
		g_alliedAdvBomberCarriers = 0;
		g_enemyFighterCarriers = 45;
		g_enemyBomberCarriers = 45;
		g_enemyAdvFighterCarriers = 0;
		g_enemyAdvBomberCarriers = 0;
	}
	else if (level == 5)
	{
		g_alliedFighterCarriers = 0;
		g_alliedBomberCarriers = 8;
		g_alliedAdvFighterCarriers = 5;
		g_alliedAdvBomberCarriers = 0;
		g_enemyFighterCarriers = 0;
		g_enemyBomberCarriers = 0;
		g_enemyAdvFighterCarriers = 0;
		g_enemyAdvBomberCarriers = 2;
	}

	ActionScreen_Start();

	if (level == 1)
	{
		AddMessage("Use the W and S keys to move your ship forward and backward.", MSG_TYPE_INFO);
		AddMessage("Use the A and D keys to move your ship sideways.", MSG_TYPE_INFO);
		AddMessage("Use the mouse to look around, and the left mouse button to fire.", MSG_TYPE_INFO);
		AddMessage("Hold the Tab key to see a map of the surrounding area.", MSG_TYPE_INFO);
	}
	else if (level == 2)
	{
		AddMessage("Ashley: To destroy a carrier, you have to shoot the generator. It is located near the",MSG_TYPE_ASHLEY);
		AddMessage("Ashley: middle of the ship, usually guarded by 2 turrets.",MSG_TYPE_ASHLEY);
	}
	else if (level == 3)
	{
	}
	else if (level == 4)
	{
		AddMessage("Rodney: Greeaat. They're between us and the station.",MSG_TYPE_RODNEY);
		AddMessage("You: And with 10 times the force! What do we do?",MSG_TYPE_YOU);
		AddMessage("Ashley: You can dart down to the station and try to help it.",MSG_TYPE_ASHLEY);
		AddMessage("You: Uhhh.....",MSG_TYPE_YOU);
		AddMessage("Ashley: It was only a suggestion.",MSG_TYPE_ASHLEY);
	}
	else if (level == 5)
	{
		AddMessage("Rodney: Finally we get to play with some decent firepower!",MSG_TYPE_RODNEY);
	}
}