MakeSG()
{
	S_SetName("Shield Generator");
	S_SetSize(0);
	S_SetBaseMass(10.00);
	S_SetBaseScan(0);
	S_SetCollClass(0);
	S_SetGraphic("Ships\ShieldGen.bmp");
	S_StripComp();
	S_StripArmory();
	S_StripUpgr();

	S_GiveComp(0, 0, -1, -1, -1, -1, -1);
	S_GiveComp(0, 10, -1, -1, -1, -1, -1);
	S_GiveComp(1, 0, -1, -1, -1, -1, -1);
	S_GiveComp(1, 10, -1, -1, -1, -1, -1);
	S_GiveComp(2, 0, -1, -1, -1, -1, -1);
	S_GiveComp(2, 10, -1, -1, -1, -1, -1);
	S_GiveComp(3, 0, -1, -1, -1, -1, -1);
	S_GiveComp(3, 10, -1, -1, -1, -1, -1);
}

MakeReactor()
{
	S_SetName("Reactor");
	S_SetSize(0);
	S_SetBaseMass(10.00);
	S_SetBaseScan(0);
	S_SetCollClass(0);
	S_SetGraphic("Ships\CoreThing.bmp");
	S_StripComp();
	S_StripArmory();
	S_StripUpgr();

	S_GiveComp(0, 0, -1, -1, -1, -1, -1);
	S_GiveComp(0, 10, -1, -1, -1, -1, -1);
	S_GiveComp(0, 10, -1, -1, -1, -1, -1);
	S_GiveComp(0, 5, -1, -1, -1, -1, -1);
	S_GiveComp(0, 4, -1, -1, -1, -1, -1);
	S_GiveComp(1, 0, -1, -1, -1, -1, -1);
	S_GiveComp(1, 10, -1, -1, -1, -1, -1);
	S_GiveComp(1, 10, -1, -1, -1, -1, -1);
	S_GiveComp(1, 5, -1, -1, -1, -1, -1);
	S_GiveComp(1, 4, -1, -1, -1, -1, -1);
	S_GiveComp(2, 0, -1, -1, -1, -1, -1);
	S_GiveComp(2, 10, -1, -1, -1, -1, -1);
	S_GiveComp(2, 10, -1, -1, -1, -1, -1);
	S_GiveComp(2, 5, -1, -1, -1, -1, -1);
	S_GiveComp(2, 4, -1, -1, -1, -1, -1);
	S_GiveComp(3, 0, -1, -1, -1, -1, -1);
	S_GiveComp(3, 10, -1, -1, -1, -1, -1);
	S_GiveComp(3, 10, -1, -1, -1, -1, -1);
	S_GiveComp(3, 5, -1, -1, -1, -1, -1);
	S_GiveComp(3, 4, -1, -1, -1, -1, -1);
}

OnDamageREACTOR(Amount)
{
	if (Amount > 12)
		Amount = 12; //nukes do 20 damage default, which against stationary objects like reactors 
			     //is WAY too much.
}

MakeCharger()
{
	S_SetName("Charger");
	S_SetSize(0);
	S_SetBaseMass(10.00);
	S_SetBaseScan(0);
	S_SetCollClass(0);
	S_SetGraphic("Ships\Devastator.bmp");
	S_StripComp();
	S_StripArmory();
	S_StripUpgr();

	S_GiveComp(0, 0, -1, -1, -1, -1, -1);
	S_GiveComp(0, 10, -1, -1, -1, -1, -1);
	S_GiveComp(0, 1, -1, -1, -1, -1, -1);
	S_GiveComp(0, 1, -1, -1, -1, -1, -1);
	S_GiveComp(0, 6, -1, -1, -1, -1, -1);
	S_GiveComp(0, 6, -1, -1, -1, -1, -1);
	S_GiveComp(1, 0, -1, -1, -1, -1, -1);
	S_GiveComp(1, 9, -1, -1, -1, -1, -1);
	S_GiveComp(1, 9, -1, -1, -1, -1, -1);
	S_GiveComp(1, 9, -1, -1, -1, -1, -1);
	S_GiveComp(1, 4, -1, -1, -1, -1, -1);
	S_GiveComp(1, 4, -1, -1, -1, -1, -1);
	S_GiveComp(2, 0, -1, -1, -1, -1, -1);
	S_GiveComp(2, 10, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(2, 9, -1, -1, -1, -1, -1);
	S_GiveComp(3, 0, -1, -1, -1, -1, -1);
	S_GiveComp(3, 9, -1, -1, -1, -1, -1);
	S_GiveComp(3, 9, -1, -1, -1, -1, -1);
	S_GiveComp(3, 9, -1, -1, -1, -1, -1);
	S_GiveComp(3, 4, -1, -1, -1, -1, -1);
	S_GiveComp(3, 4, -1, -1, -1, -1, -1);
	S_SetMiss(0, 18, -1, -1, -1, -1, -1);
	S_SetMiss(1, 18, -1, -1, -1, -1, -1);
	S_SetMiss(2, 18, -1, -1, -1, -1, -1);
	S_SetMiss(3, 18, -1, -1, -1, -1, -1);
	S_SetMiss(4, 18, -1, -1, -1, -1, -1);
	S_SetMiss(5, 18, -1, -1, -1, -1, -1);
	S_SetMiss(6, 18, -1, -1, -1, -1, -1);
	S_SetMiss(7, 18, -1, -1, -1, -1, -1);
	S_SetMiss(8, 18, -1, -1, -1, -1, -1);
	S_SetMiss(9, 18, -1, -1, -1, -1, -1);
	S_SetMiss(10, 18, -1, -1, -1, -1, -1);
	S_SetMiss(11, 18, -1, -1, -1, -1, -1);
	S_SetMiss(12, 18, -1, -1, -1, -1, -1);
	S_SetMiss(13, 18, -1, -1, -1, -1, -1);
	S_SetMiss(14, 33, -1, -1, -1, -1, -1);
	S_SetMiss(15, 33, -1, -1, -1, -1, -1);
	S_SetMiss(16, 18, -1, -1, -1, -1, -1);
	S_SetMiss(17, 18, -1, -1, -1, -1, -1);
	S_SetMiss(18, 18, -1, -1, -1, -1, -1);
	S_SetMiss(19, 18, -1, -1, -1, -1, -1);
	S_SetMiss(20, 18, -1, -1, -1, -1, -1);
	S_SetMiss(21, 18, -1, -1, -1, -1, -1);
	S_SetMiss(22, 18, -1, -1, -1, -1, -1);
	S_SetMiss(23, 18, -1, -1, -1, -1, -1);
	S_SetMiss(24, 41, -1, -1, -1, -1, -1);
	S_SetMiss(25, 23, -1, -1, -1, -1, -1);
	S_SetMiss(26, 18, -1, -1, -1, -1, -1);
	S_SetMiss(27, 18, -1, -1, -1, -1, -1);
	S_SetMiss(28, 18, -1, -1, -1, -1, -1);
	S_SetMiss(29, 18, -1, -1, -1, -1, -1);
	S_SetMiss(30, 43, -1, -1, -1, -1, -1);
	S_SetMiss(31, 43, -1, -1, -1, -1, -1);
	S_SetMiss(32, 43, -1, -1, -1, -1, -1);
	S_SetMiss(33, 20, -1, -1, -1, -1, -1);
	S_SetMiss(34, 21, -1, -1, -1, -1, -1);
	S_SetMiss(35, 21, -1, -1, -1, -1, -1);
	S_SetMiss(36, 20, -1, -1, -1, -1, -1);
	S_SetMiss(37, 43, -1, -1, -1, -1, -1);
	S_SetMiss(38, 43, -1, -1, -1, -1, -1);
	S_SetMiss(39, 43, -1, -1, -1, -1, -1);
	S_SetUpgr(0, 9, -1, -1, -1, -1, -1);
	
}

MakeTurret()
{
	S_SetName("Turret");
	S_SetSize(24);
	S_SetBaseMass(10.00);
	S_SetBaseScan(-50);
	S_SetCollClass(0);
	S_SetGraphic("Ships\Turret.bmp");
	S_StripComp();
	S_StripArmory();
	S_StripUpgr();

	S_GiveComp(0, 5, -1, -1, -1, -1, -1);
	S_GiveComp(0, 1, -1, -1, -1, -1, -1);
	S_GiveComp(1, 5, -1, -1, -1, -1, -1);
	S_GiveComp(1, 9, -1, -1, -1, -1, -1);
	S_GiveComp(1, 8, -1, -1, -1, -1, -1);
	S_GiveComp(2, 5, -1, -1, -1, -1, -1);
	S_GiveComp(2, 10, -1, -1, -1, -1, -1);
	S_GiveComp(2, 0, -1, -1, -1, -1, -1);
	S_GiveComp(3, 5, -1, -1, -1, -1, -1);
	S_GiveComp(3, 9, -1, -1, -1, -1, -1);
	S_GiveComp(3, 16, -1, -1, -1, -1, -1);

	S_SetMiss(0, 18, 3, 0, 3, -1, -1);
}

OnSpawnTURRET()
{
	SetActive("SPAWNED");
	call-script MakeTurret();
}

OnSpawnSHIPS()
{
	IsAlso("SPAWNED", "TURRET");
	if (Exists() == 0) //if it's not a turret then replace it with a charger
	{
		SetActive("SPAWNED");
		call-script MakeCharger();
	}
}

GrantInv(Team) //this function is called by foreachteam
{
	IsAlso("SHIELDS", Team);
	// See annotation in ShieldUnInv to find out why no set active is necessary
	if (Exists() != 0) //if there IS a shared shield generator
	{
		SetActive(Team); //make the team invincible
		S_SetInvincibility(1);
	}
}

ShieldUnInv(Team)
{
	IsAlso("SHIELDS", Team);
	//the active group is now the SHARED members of "SHIELDS" and Team
	//if i needed to include a third group, I would use "SHARED" in the next IsAlso call
	S_SetInvincibility(0); //shield generators can't be invincible..
}

GiveTurrets(Team)
{
	SetActive(Team);
	RandomMembers(3);
	S_GiveUpgr(9, -1, -1, -1, -1, -1);
}

EveryTurn(Turn) //MUST BE THAT EXACT LINE.
{
	if (Turn == 1) //initialize
	{
		//All ships already chargers :)
		SetActive("SHIELDS"); //make squads labelled SHIELDS into shield gens
		call-script MakeSG();
		SetActive("CORES"); //and those labelled CORES into reactors!
		call-script MakeReactor();
		SetActive("DEFENSES");
		call-script MakeTurret();

		//SetActive("SHIPS");
		//RandomMembers(3);
		//S_GiveUpgr(9, -1, -1, -1, -1, -1);
		//foreachteam("GiveTurrets");

		DisableSD();
	}

	SetActive("SHIPS");
	S_SetInvincibility(0);
	foreachteam("GrantInv"); //for every team, make it invincible if it has shield generators left
	foreachteam("ShieldUnInv"); //called for every team.

	//make sure shields and cores DO NOT MOVE AT ALL
	SetActive("SHIELDS");
	S_Bump(); //Bumping a ship makes it uncontrollable.  The same as getting hit by a clamper
	SetActive("CORES");
	S_Bump();
}

OnDestroySHIELDS()
{
	SetActive("DESTROYD"); //get the object destroyed
	IsAlso("SHIELDS", S_GetTeamID()); //find if there are any shields left
	if (Exists() == 0) //NO MORE LEFT!  Make them vulnerable
	{
		SetActive("DESTROYD");
		SetActive(S_GetTeamID());
		S_SetInvincibility(0);

		SetActive("DESTROYD");
		Event_Text(S_GetTeamID(), 1);
		Event_Text(" shields down", 0);
		Event_Graphic(S_GetGraphic());
		Event_Do();
	}
}

OnDestroyCORES()
{
	SetActive("DESTROYD");
	IsAlso("CORES", S_GetTeamID()); //any left?
	if (Exists() == 0) //none, KILL THEM ALL!
	{
		SetActive("DESTROYD");
		SetActive(S_GetTeamID());
		Destroy();  //MWHAHAHAHAHHA
	}
}

//OnTrigExitKILLALL()
//{
//	SetActive("TRIG");
//	Destroy();
//}
//
//OnTriggerKILLALL()
//{
//	SetActive("TRIG");
//	S_Replenish(); //replenish any ships in the group
//}