function OpenDoor(name)
{
	for (f=0;f<max_doors;f++)
	{
		if (doors[f].name == name)
		{
			doors[f].dir = "closed1";
			doors[f].frame = 0;
			doors[f].active = 1;
			PlaySound(39);

			SetPersonIDDirection(doors[f].id1, doors[f].dir);
			SetPersonIDFrame(doors[f].id1, doors[f].frame);
		}
	}
}

function GetChaingun(numy)
{
	if (numy == undefined)
	{
	SetTile(70,32, 2,0);
	SetTile(71,32, 2,0);
	
	SetTile(70,33,2, 575);
	SetTile(71,33,2,576);
	ammo_array[12].curclip = 100;
	ammo_array[12].curammo = 200;

	g_chain_cc = 30;
	if (weap_possess[10] == 0)
	{
		AddAmmoHudText(2, 1,"Obtained Chaingun!");
		AddAmmoHudText(2, 1,"Press "+inputs[CKEY_7].toUpperCase()+" twice to select.");
	}
	
	AddAmmoHudText(12, 300);
	
	weap_possess[10] = 1;
	cur_weap = 12;
	PlaySound(16);

	ammo_array[12].curclip = 100;
	ammo_array[12].curammo = 200;

	}
	else if (numy == 2 && g_chaingun_gotten==1 && g_chaingun_stocked == 1)
	{
		g_chaingun_stocked = 0;
	
		SetTile(130,75, 2,0);
		SetTile(131,75, 2,0);
		SetTile(130,76,2, 575);
		SetTile(131,76,2,576);
		PlaySound(16);
	
		//blah
		if (weap_possess[10] == 0)
		{
			g_chain_cc = 30;

			weap_possess[10] = 1;
			cur_weap = 12;
		}
		ammo_array[12].curammo+= 300;

		AddAmmoHudText(12, 300);


		if (ammo_array[12].curammo > ammo_array[12].maxammo)
			ammo_array[12].curammo = ammo_array[12].maxammo;
	}
	
	SaveWeapPossess();
	
}

//supernaut variables
var naut_head = LoadSurface("supernaut/supernaut_head_1.png");
var naut_head_mask = LoadSurface("supernaut/supernaut_head_mask_1.png");
var naut_head_blood = LoadSurface("supernaut/supernaut_head_blood_1.png");
var naut_mouth_1 = LoadSurface("supernaut/supernaut_mouth_1.png");
var naut_mouth_mask_1 = LoadSurface("supernaut/supernaut_mouth_mask_1.png");
var naut_mouth_blood_1 = LoadSurface("supernaut/supernaut_mouth_blood_1.png");
var naut_mouth_2 = LoadSurface("supernaut/supernaut_mouth_2.png");
var naut_mouth_mask_2 = LoadSurface("supernaut/supernaut_mouth_mask_2.png");
var naut_mouth_blood_2 = LoadSurface("supernaut/supernaut_mouth_blood_2.png");
var naut_mouth_3 = LoadSurface("supernaut/supernaut_mouth_3.png");
var naut_neck_bottom = LoadSurface("supernaut/supernaut_neck_bottom_1.png");
var naut_neck_bottom_mask = LoadSurface("supernaut/supernaut_neck_bottom_mask_1.png");
var naut_neck_bottom_blood = LoadSurface("supernaut/supernaut_neck_bottom_blood_1.png");
var naut_neck_top = LoadSurface("supernaut/supernaut_neck_top_1.png");
var naut_neck_top_mask = LoadSurface("supernaut/supernaut_neck_top_mask_1.png");
var naut_neck_top_blood = LoadSurface("supernaut/supernaut_neck_top_blood_1.png");

var naut_mouth_mask_2B = LoadSurface("supernaut/supernaut_mouth_mask_2B.png");


var naut_headi = LoadImage("supernaut/supernaut_head_1.png");
var naut_headg = LoadImage("supernaut/supernaut_head_1g.png");
var naut_head_bloodi = LoadImage("supernaut/supernaut_head_blood_1.png");
var naut_mouth_1i = LoadImage("supernaut/supernaut_mouth_1.png");
var naut_mouth_1g = LoadImage("supernaut/supernaut_mouth_1g.png");
var naut_mouth_blood_1i = LoadImage("supernaut/supernaut_mouth_blood_1.png");
var naut_mouth_2i = LoadImage("supernaut/supernaut_mouth_2.png");
var naut_mouth_2g = LoadImage("supernaut/supernaut_mouth_2g.png");
var naut_mouth_blood_2i = LoadImage("supernaut/supernaut_mouth_blood_2.png");
var naut_mouth_3i = LoadImage("supernaut/supernaut_mouth_3.png");
var naut_mouth_3g = LoadImage("supernaut/supernaut_mouth_3g.png");
var naut_neck_bottomi = LoadImage("supernaut/supernaut_neck_bottom_1.png");
var naut_neck_bottomg = LoadImage("supernaut/supernaut_neck_bottom_1g.png");
var naut_neck_bottom_bloodi = LoadImage("supernaut/supernaut_neck_bottom_blood_1.png");
var naut_neck_topi = LoadImage("supernaut/supernaut_neck_top_1.png");
var naut_neck_top_bloodi = LoadImage("supernaut/supernaut_neck_top_blood_1.png");

var naut_wavebeam = new Array();
var naut_wavebeam2 = new Array();
naut_wavebeam[0] = LoadImage("supernaut/supernaut_waveblast_1.png");
naut_wavebeam[1] = LoadImage("supernaut/supernaut_waveblast_2.png");
naut_wavebeam[2] = LoadImage("supernaut/supernaut_waveblast_3.png");
naut_wavebeam[3] = LoadImage("supernaut/supernaut_waveblast_4.png");
naut_wavebeam[4] = LoadImage("supernaut/supernaut_waveblast_5.png");
naut_wavebeam[5] = LoadImage("supernaut/supernaut_waveblast_6.png");
naut_wavebeam[6] = LoadImage("supernaut/supernaut_waveblast_7.png");
naut_wavebeam[7] = LoadImage("supernaut/supernaut_waveblast_8.png");
naut_wavebeam[8] = LoadImage("supernaut/supernaut_waveblast_9.png");

naut_wavebeam2[0] = LoadImage("supernaut/supernaut_waveblast_width1.png");
naut_wavebeam2[1] = LoadImage("supernaut/supernaut_waveblast_width2.png");
naut_wavebeam2[2] = LoadImage("supernaut/supernaut_waveblast_width3.png");
naut_wavebeam2[3] = LoadImage("supernaut/supernaut_waveblast_width4.png");
naut_wavebeam2[4] = LoadImage("supernaut/supernaut_waveblast_width5.png");
naut_wavebeam2[5] = LoadImage("supernaut/supernaut_waveblast_width6.png");
naut_wavebeam2[6] = LoadImage("supernaut/supernaut_waveblast_width7.png");
naut_wavebeam2[7] = LoadImage("supernaut/supernaut_waveblast_width8.png");
naut_wavebeam2[8] = LoadImage("supernaut/supernaut_waveblast_width9.png");



//supernaut2 variables
var naut2_head = LoadSurface("supernaut2/supernaut2_head_1.png");
var naut2_head_mask = LoadSurface("supernaut2/supernaut2_head_mask_1.png");
var naut2_head_blood = LoadSurface("supernaut2/supernaut2_head_blood_1.png");
var naut2_mouth_1 = LoadSurface("supernaut2/supernaut2_mouth_1.png");
var naut2_mouth_mask_1 = LoadSurface("supernaut2/supernaut2_mouth_mask_1.png");
var naut2_mouth_blood_1 = LoadSurface("supernaut2/supernaut2_mouth_blood_1.png");
var naut2_mouth_2 = LoadSurface("supernaut2/supernaut2_mouth_2.png");
var naut2_mouth_mask_2 = LoadSurface("supernaut2/supernaut2_mouth_mask_2.png");
var naut2_mouth_blood_2 = LoadSurface("supernaut2/supernaut2_mouth_blood_2.png");
var naut2_mouth_3 = LoadSurface("supernaut2/supernaut2_mouth_3.png");
var naut2_neck_top = LoadSurface("supernaut2/supernaut2_neck_top_1.png");
var naut2_neck_top_mask = LoadSurface("supernaut2/supernaut2_neck_top_mask_1.png");
var naut2_neck_top_blood = LoadSurface("supernaut2/supernaut2_neck_top_blood_1.png");

var naut2_mouth_mask_2B = LoadSurface("supernaut2/supernaut2_mouth_mask_2B.png");


var naut2_headi = LoadImage("supernaut2/supernaut2_head_1.png");
var naut2_head_bloodi = LoadImage("supernaut2/supernaut2_head_blood_1.png");
var naut2_mouth_1i = LoadImage("supernaut2/supernaut2_mouth_1.png");
var naut2_mouth_blood_1i = LoadImage("supernaut2/supernaut2_mouth_blood_1.png");
var naut2_mouth_2i = LoadImage("supernaut2/supernaut2_mouth_2.png");
var naut2_mouth_blood_2i = LoadImage("supernaut2/supernaut2_mouth_blood_2.png");
var naut2_mouth_3i = LoadImage("supernaut2/supernaut2_mouth_3.png");
var naut2_neck_topi = LoadImage("supernaut2/supernaut2_neck_top_1.png");
var naut2_neck_top2i = LoadImage("supernaut2/supernaut2_neck_top_2.png");
var naut2_neck_top_bloodi = LoadImage("supernaut2/supernaut2_neck_top_blood_1.png");

var naut2_wavebeam = new Array();
naut2_wavebeam[0] = LoadImage("supernaut2/supernaut2_waveblast_1.png");
naut2_wavebeam[1] = LoadImage("supernaut2/supernaut2_waveblast_2.png");
naut2_wavebeam[2] = LoadImage("supernaut2/supernaut2_waveblast_3.png");
naut2_wavebeam[3] = LoadImage("supernaut2/supernaut2_waveblast_4.png");
naut2_wavebeam[4] = LoadImage("supernaut2/supernaut2_waveblast_5.png");
naut2_wavebeam[5] = LoadImage("supernaut2/supernaut2_waveblast_6.png");
naut2_wavebeam[6] = LoadImage("supernaut2/supernaut2_waveblast_7.png");
naut2_wavebeam[7] = LoadImage("supernaut2/supernaut2_waveblast_8.png");
naut2_wavebeam[8] = LoadImage("supernaut2/supernaut2_waveblast_9.png");










var g_superwboffx = 3*16;
var g_superwboffy = 9*16;


var supernaught_wavedamage = 2;
var supernaut_rail_dam = 0.1875/2;

var naut1 = new Object();
var max_head_parts = 200;
var max_neck_parts = 100;
var max_mouth_parts = 100;


naut1.bx = 79*16;//in mapx (base x value)
naut1.by = 19*16;//in mapy (base y value)
naut1.x = 79*16;//in mapx
naut1.y = 19*16;//in mapy
naut1.exoff = 0;
naut1.eyoff = 0;
naut1.fc = 0;
naut1.fc2 = Math.floor(300*3.14159/2)+70;
naut1.nx = 0;//in mapx
naut1.ny = 0;//in mapy
naut1.hx = 0;//in mapx
naut1.hy = 0;//in mapy
naut1.mx = 0;//in mapx
naut1.my = 0;//in mapy
naut1.dir = -1;//facing west
naut1.dir2 = "";//facing west
naut1.frame = 0;//facing west
naut1.width = naut_head.width;//in mapx
naut1.height = naut_head.height;//in mapy
naut1.chompcount = 0;
naut1.hstart = 160;

naut1.idle_counter = 0;
naut1.maxhp = 70000;
naut1.hp1 = 70000;
naut1.hp2 = 70000;
naut1.hp3 = 70000;
naut1.openmouth = 0;
naut1.counter = 0;
naut1.headstates = new Array(max_head_parts);
naut1.neck_bottomstates = new Array(max_neck_parts);
naut1.mouthstates = new Array(max_mouth_parts);
for (i=0;i<max_head_parts;i++)
	naut1.headstates[i] = 0;
for (i=0;i<max_neck_parts;i++)
	naut1.neck_bottomstates[i] = 0;
for (i=0;i<max_mouth_parts;i++)
	naut1.mouthstates[i] = 0;








var naut2 = new Object();


naut2.bx = 41*16;//in mapx (base x value)
naut2.by = 24*16;//in mapy (base y value)
naut2.x = 41*16;//in mapx
naut2.y = 5*16;//in mapy
naut2.exoff = 0;
naut2.eyoff = 0;
naut2.fc = 0;
naut2.fc2 = Math.floor(300*3.14159/2)+70;
naut2.nx = 2;//in mapx
naut2.ny = 0;//in mapy
naut2.hx = 0;//in mapx
naut2.hy = 0;//in mapy
naut2.mx = 0;//in mapx
naut2.my = 0;//in mapy
naut2.dir = 1;//facing east
naut2.dir2 = "";//facing west
naut2.frame = 0;//facing west
naut2.width = naut2_head.width;//in mapx
naut2.height = naut2_head.height;//in mapy
naut2.chompcount = 0;
naut2.attack_counter = 0;
naut2.hstart = 160;
naut2.hbc = 1;


naut2.idle_counter = 0;
naut2.maxhp = 70000;
naut2.hp1 = 70000;
naut2.hp2 = 70000;
naut2.hp3 = 70000;
naut2.openmouth = 0;
naut2.counter = 0;
naut2.headstates = new Array(max_head_parts);
naut2.neck_topstates = new Array(max_neck_parts);
naut2.mouthstates = new Array(max_mouth_parts);
for (i=0;i<max_head_parts;i++)
	naut2.headstates[i] = 0;
for (i=0;i<max_neck_parts;i++)
	naut2.neck_topstates[i] = 0;
for (i=0;i<max_mouth_parts;i++)
	naut2.mouthstates[i] = 0;








var neck_bottomcolors = new Array();
var neck_topcolors = new Array();
var mouthcolors = new Array();
var mouthcolors2 = new Array();
var headcolors = new Array();


var neck_bottomcolors_pos = new Array();
var neck_topcolors_pos = new Array();
var headcolors_pos = new Array();
var mouthcolors_pos1 = new Array();
var mouthcolors_pos2 = new Array();


var s2_neck_bottomcolors = new Array();
var s2_neck_topcolors = new Array();
var s2_mouthcolors = new Array();
var s2_mouthcolors2 = new Array();
var s2_headcolors = new Array();
var s2_neck_bottomcolors_pos = new Array();
var s2_neck_topcolors_pos = new Array();
var s2_headcolors_pos = new Array();
var s2_mouthcolors_pos1 = new Array();
var s2_mouthcolors_pos2 = new Array();

var supernaut_flame_damage = 1;
var supernaut_grenade_damage = 0.5;


var c_pixel = 0;

var sfile = OpenFile("super_data.naut");
var ssave = false;
var load_temp = 0;
var tr1, tg1, tb1;
//setup head mask info

if (ssave == true)
{
	for (x=0;x<naut_head_mask.width;x++)
	{
		for (y=0;y<naut_head_mask.height;y++)
		{
			c_pixel = naut_head_mask.getPixel(x,y);
			for (l=0;l<headcolors.length;l++)
			{
				if (c_pixel.red == headcolors[l].red && c_pixel.green == headcolors[l].green && c_pixel.blue == headcolors[l].blue)
				{	
					break;
				}
			}
			if (l<headcolors.length )
			{
				if (l != 0)
				{
					headcolors_pos[l].avgx = (x+headcolors_pos[l].firstx)/2;
					headcolors_pos[l].avgy = (y+headcolors_pos[l].firsty)/2;
					
					sfile.write("super1_headcolors_posx"+l, ((x+headcolors_pos[l].firstx)/2));
					sfile.write("super1_headcolors_posy"+l, ((y+headcolors_pos[l].firsty)/2));
					
				}
			}
			else
			{
				headcolors[l] = c_pixel;
				
				headcolors_pos[l] = new Object();
				headcolors_pos[l].firstx = x;
				headcolors_pos[l].firsty = y;
	
				headcolors_pos[l].avgx = (x+headcolors_pos[l].firstx)/2;
				headcolors_pos[l].avgy = (y+headcolors_pos[l].firsty)/2;
				
				sfile.write("super1_headcolors_posfirstx"+l, x);
				sfile.write("super1_headcolors_posfirsty"+l, y);
		
				sfile.write("super1_headcolors_posx"+l, ((x+headcolors_pos[l].firstx)/2));
				sfile.write("super1_headcolors_posy"+l, ((y+headcolors_pos[l].firsty)/2));
			}
		}
	}
	
	sfile.write("headcolors_length", headcolors.length);
	for (l=0;l<headcolors.length;l++)
	{
		sfile.write("headcolors_red"+l, headcolors[l].red);
		sfile.write("headcolors_green"+l, headcolors[l].green);
		sfile.write("headcolors_blue"+l, headcolors[l].blue);
	}
	//setup neck mask info
	for (x=0;x<naut_neck_bottom_mask.width;x++)
	{
		for (y=0;y<naut_neck_bottom_mask.height;y++)
		{
			c_pixel = naut_neck_bottom_mask.getPixel(x,y);
			for (l=0;l<neck_bottomcolors.length;l++)
			{
				if (c_pixel.red == neck_bottomcolors[l].red && c_pixel.green == neck_bottomcolors[l].green && c_pixel.blue == neck_bottomcolors[l].blue)
				{	
					break;
				}
			}
			if (l<neck_bottomcolors.length)
			{
				if (l != 0)
				{
					neck_bottomcolors_pos[l].avgx = (x+neck_bottomcolors_pos[l].firstx)/2;
					neck_bottomcolors_pos[l].avgy = (y+neck_bottomcolors_pos[l].firsty)/2;
					sfile.write("super1_neck_bottom_colors_posx"+l, ((x+neck_bottomcolors_pos[l].firstx)/2));
					sfile.write("super1_neck_bottom_colors_posy"+l, ((y+neck_bottomcolors_pos[l].firsty)/2));
				}
			}
			else
			{
				neck_bottomcolors[l] = c_pixel;
	
				neck_bottomcolors_pos[l] = new Object();
				neck_bottomcolors_pos[l].firstx = x;
				neck_bottomcolors_pos[l].firsty = y;
	
				neck_bottomcolors_pos[l].avgx = (x+neck_bottomcolors_pos[l].firstx)/2;
				neck_bottomcolors_pos[l].avgy = (y+neck_bottomcolors_pos[l].firsty)/2;
				
				sfile.write("super1_neck_bottom_colors_posfirstx"+l, x);
				sfile.write("super1_neck_bottom_colors_posfirsty"+l, y);
	
				sfile.write("super1_neck_bottom_colors_posx"+l, ((x+neck_bottomcolors_pos[l].firstx)/2));
				sfile.write("super1_neck_bottom_colors_posy"+l, ((y+neck_bottomcolors_pos[l].firsty)/2));
				
	
			}
		}
	}

	sfile.write("neck_bottomcolors_length", neck_bottomcolors.length);
	for (l=0;l<neck_bottomcolors.length;l++)
	{
		sfile.write("neck_bottomcolors_red"+l, neck_bottomcolors[l].red);
		sfile.write("neck_bottomcolors_green"+l, neck_bottomcolors[l].green);
		sfile.write("neck_bottomcolors_blue"+l, neck_bottomcolors[l].blue);
	}
	//setup mouth mask info
	for (x=0;x<naut_mouth_mask_1.width;x++)
	{
		for (y=0;y<naut_mouth_mask_1.height;y++)
		{
			c_pixel = naut_mouth_mask_1.getPixel(x,y);
			for (l=0;l<mouthcolors.length;l++)
			{
				if (c_pixel.red == mouthcolors[l].red && c_pixel.green == mouthcolors[l].green && c_pixel.blue == mouthcolors[l].blue)
				{	
					break;
				}
			}
			if (l<mouthcolors.length)
			{
				if (l!= 0)
				{
					mouthcolors_pos1[l].avgx = (x+mouthcolors_pos1[l].firstx)/2;
					mouthcolors_pos1[l].avgy = (y+mouthcolors_pos1[l].firsty)/2;
	
					sfile.write("super1_mouth_colors_pos1x"+l, ((x+mouthcolors_pos1[l].firstx)/2));
					sfile.write("super1_mouth_colors_pos1y"+l, ((y+mouthcolors_pos1[l].firsty)/2));
					
				}
			}
			else
			{
				mouthcolors[l] = c_pixel;
				mouthcolors_pos1[l] = new Object();
				mouthcolors_pos1[l].firstx = x;
				mouthcolors_pos1[l].firsty = y;
	
				mouthcolors_pos1[l].avgx = (x+mouthcolors_pos1[l].firstx)/2;
				mouthcolors_pos1[l].avgy = (y+mouthcolors_pos1[l].firsty)/2;
				
				sfile.write("super1_mouth_colors_pos1firstx"+l, x);
				sfile.write("super1_mouth_colors_pos1firsty"+l, y);
	
				sfile.write("super1_mouth_colors_pos1x"+l, ((x+mouthcolors_pos1[l].firstx)/2));
				sfile.write("super1_mouth_colors_pos1y"+l, ((y+mouthcolors_pos1[l].firsty)/2));
				
			}
		}
	}
	
	sfile.write("mouthcolors_length", mouthcolors.length);
	for (l=0;l<mouthcolors.length;l++)
	{
		sfile.write("mouthcolors_red"+l, mouthcolors[l].red);
		sfile.write("mouthcolors_green"+l, mouthcolors[l].green);
		sfile.write("mouthcolors_blue"+l, mouthcolors[l].blue);
	}
	
	for (x=0;x<naut_mouth_mask_2.width;x++)
	{
		for (y=0;y<naut_mouth_mask_2.height;y++)
		{
			c_pixel = naut_mouth_mask_2.getPixel(x,y);
			for (l=0;l<mouthcolors2.length;l++)
			{
				if (c_pixel.red == mouthcolors2[l].red && c_pixel.green == mouthcolors2[l].green && c_pixel.blue == mouthcolors2[l].blue)
				{	
					break;
				}
			}
			if (l<mouthcolors2.length)
			{
				if (l!= 0)
				{
					mouthcolors_pos2[l].avgx = (x+mouthcolors_pos2[l].firstx)/2;
					mouthcolors_pos2[l].avgy = (y+mouthcolors_pos2[l].firsty)/2;
	
					sfile.write("super1_mouth_colors_pos2x"+l, ((x+mouthcolors_pos2[l].firstx)/2));
					sfile.write("super1_mouth_colors_pos2y"+l, ((y+mouthcolors_pos2[l].firsty)/2));
				}
			}
			else
			{
				mouthcolors2[l] = c_pixel;
				mouthcolors_pos2[l] = new Object();
				mouthcolors_pos2[l].firstx = x;
				mouthcolors_pos2[l].firsty = y;
	
				mouthcolors_pos2[l].avgx = (x+mouthcolors_pos2[l].firstx)/2;
				mouthcolors_pos2[l].avgy = (y+mouthcolors_pos2[l].firsty)/2;
	
				sfile.write("super1_mouth_colors_pos2firstx"+l, x);
				sfile.write("super1_mouth_colors_pos2firsty"+l, y);
		
				sfile.write("super1_mouth_colors_pos2x"+l, ((x+mouthcolors_pos2[l].firstx)/2));
				sfile.write("super1_mouth_colors_pos2y"+l, ((y+mouthcolors_pos2[l].firsty)/2));
	
			}
		}
	}
	
	sfile.write("mouthcolors2_length", mouthcolors2.length);
	for (l=0;l<mouthcolors2.length;l++)
	{
		sfile.write("mouthcolors2_red"+l, mouthcolors2[l].red);
		sfile.write("mouthcolors2_green"+l, mouthcolors2[l].green);
		sfile.write("mouthcolors2_blue"+l, mouthcolors2[l].blue);
	}
	//supernaut 2 colours
	
	for (x=0;x<naut2_head_mask.width;x++)
	{
		for (y=0;y<naut2_head_mask.height;y++)
		{
			c_pixel = naut2_head_mask.getPixel(x,y);
			for (l=0;l<s2_headcolors.length;l++)
			{
				if (c_pixel.red == s2_headcolors[l].red && c_pixel.green == s2_headcolors[l].green && c_pixel.blue == s2_headcolors[l].blue)
				{	
					break;
				}
			}
			if (l<s2_headcolors.length )
			{
				if (l != 0)
				{
					s2_headcolors_pos[l].avgx = (x+s2_headcolors_pos[l].firstx)/2;
					s2_headcolors_pos[l].avgy = (y+s2_headcolors_pos[l].firsty)/2;
					
					sfile.write("super2_headcolors_posx"+l, ((x+s2_headcolors_pos[l].firstx)/2));
					sfile.write("super2_headcolors_posy"+l, ((y+s2_headcolors_pos[l].firsty)/2));
					
				}
			}
			else
			{
				s2_headcolors[l] = c_pixel;
				
				s2_headcolors_pos[l] = new Object();
				s2_headcolors_pos[l].firstx = x;
				s2_headcolors_pos[l].firsty = y;
	
				s2_headcolors_pos[l].avgx = (x+s2_headcolors_pos[l].firstx)/2;
				s2_headcolors_pos[l].avgy = (y+s2_headcolors_pos[l].firsty)/2;
				
				sfile.write("super2_headcolors_posfirstx"+l, x);
				sfile.write("super2_headcolors_posfirsty"+l, y);
		
				sfile.write("super2_headcolors_posx"+l, ((x+s2_headcolors_pos[l].firstx)/2));
				sfile.write("super2_headcolors_posy"+l, ((y+s2_headcolors_pos[l].firsty)/2));
			}
		}
	}
	
	sfile.write("s2_headcolors_length", s2_headcolors.length);
	for (l=0;l<s2_headcolors.length;l++)
	{
		sfile.write("s2_headcolors_red"+l, s2_headcolors[l].red);
		sfile.write("s2_headcolors_green"+l, s2_headcolors[l].green);
		sfile.write("s2_headcolors_blue"+l, s2_headcolors[l].blue);
	}
	//setup neck mask info
	for (x=0;x<naut2_neck_top_mask.width;x++)
	{
		for (y=0;y<naut2_neck_top_mask.height;y++)
		{
			c_pixel = naut2_neck_top_mask.getPixel(x,y);
			for (l=0;l<s2_neck_topcolors.length;l++)
			{
				if (c_pixel.red == s2_neck_topcolors[l].red && c_pixel.green == s2_neck_topcolors[l].green && c_pixel.blue == s2_neck_topcolors[l].blue)
				{	
					break;
				}
			}
			if (l<s2_neck_topcolors.length)
			{
				if (l != 0)
				{
					s2_neck_topcolors_pos[l].avgx = (x+s2_neck_topcolors_pos[l].firstx)/2;
					s2_neck_topcolors_pos[l].avgy = (y+s2_neck_topcolors_pos[l].firsty)/2;
	
					sfile.write("super2_neck_topcolors_posx"+l, ((x+s2_neck_topcolors_pos[l].firstx)/2));
					sfile.write("super2_neck_topcolors_posy"+l, ((y+s2_neck_topcolors_pos[l].firsty)/2));
				}
			}
			else
			{
				s2_neck_topcolors[l] = c_pixel;
	
				s2_neck_topcolors_pos[l] = new Object();
				s2_neck_topcolors_pos[l].firstx = x;
				s2_neck_topcolors_pos[l].firsty = y;
	
				s2_neck_topcolors_pos[l].avgx = (x+s2_neck_topcolors_pos[l].firstx)/2;
				s2_neck_topcolors_pos[l].avgy = (y+s2_neck_topcolors_pos[l].firsty)/2;
	
				sfile.write("super2_neck_topcolors_posfirstx"+l, x);
				sfile.write("super2_neck_topcolors_posfirsty"+l, y);
		
				sfile.write("super2_neck_topcolors_posx"+l, ((x+s2_neck_topcolors_pos[l].firstx)/2));
				sfile.write("super2_neck_topcolors_posy"+l, ((y+s2_neck_topcolors_pos[l].firsty)/2));
			}
		}
	}

	sfile.write("s2_neck_topcolors_length", s2_neck_topcolors.length);
	for (l=0;l<s2_neck_topcolors.length;l++)
	{
		sfile.write("s2_neck_topcolors_red"+l, s2_neck_topcolors[l].red);
		sfile.write("s2_neck_topcolors_green"+l, s2_neck_topcolors[l].green);
		sfile.write("s2_neck_topcolors_blue"+l, s2_neck_topcolors[l].blue);
	}

	//setup mouth mask info
	for (x=0;x<naut2_mouth_mask_1.width;x++)
	{
		for (y=0;y<naut2_mouth_mask_1.height;y++)
		{
			c_pixel = naut2_mouth_mask_1.getPixel(x,y);
			for (l=0;l<s2_mouthcolors.length;l++)
			{
				if (c_pixel.red == s2_mouthcolors[l].red && c_pixel.green == s2_mouthcolors[l].green && c_pixel.blue == s2_mouthcolors[l].blue)
				{	
					break;
				}
			}
			if (l<s2_mouthcolors.length)
			{
				if (l!= 0)
				{
					s2_mouthcolors_pos1[l].avgx = (x+s2_mouthcolors_pos1[l].firstx)/2;
					s2_mouthcolors_pos1[l].avgy = (y+s2_mouthcolors_pos1[l].firsty)/2;
			
					sfile.write("super2_mouth_colors_pos1x"+l, ((x+s2_mouthcolors_pos1[l].firstx)/2));
					sfile.write("super2_mouth_colors_pos1y"+l, ((y+s2_mouthcolors_pos1[l].firsty)/2));
				}
			}
			else
			{
				s2_mouthcolors[l] = c_pixel;
				s2_mouthcolors_pos1[l] = new Object();
				s2_mouthcolors_pos1[l].firstx = x;
				s2_mouthcolors_pos1[l].firsty = y;
	
				s2_mouthcolors_pos1[l].avgx = (x+s2_mouthcolors_pos1[l].firstx)/2;
				s2_mouthcolors_pos1[l].avgy = (y+s2_mouthcolors_pos1[l].firsty)/2;
	
				sfile.write("super2_mouth_colors_pos1firstx"+l, x);
				sfile.write("super2_mouth_colors_pos1firsty"+l, y);
		
				sfile.write("super2_mouth_colors_pos1x"+l, ((x+s2_mouthcolors_pos1[l].firstx)/2));
				sfile.write("super2_mouth_colors_pos1y"+l, ((y+s2_mouthcolors_pos1[l].firsty)/2));
			}
		}
	}
	
	sfile.write("s2_mouthcolors_length", s2_mouthcolors.length);
	for (l=0;l<s2_mouthcolors.length;l++)
	{
		sfile.write("s2_mouthcolors_red"+l, s2_mouthcolors[l].red);
		sfile.write("s2_mouthcolors_green"+l, s2_mouthcolors[l].green);
		sfile.write("s2_mouthcolors_blue"+l, s2_mouthcolors[l].blue);
	}	
	for (x=0;x<naut2_mouth_mask_2.width;x++)
	{
		for (y=0;y<naut2_mouth_mask_2.height;y++)
		{
			c_pixel = naut2_mouth_mask_2.getPixel(x,y);
			for (l=0;l<s2_mouthcolors2.length;l++)
			{
				if (c_pixel.red == s2_mouthcolors2[l].red && c_pixel.green == s2_mouthcolors2[l].green && c_pixel.blue == s2_mouthcolors2[l].blue)
				{	
					break;
				}
			}
			if (l<s2_mouthcolors2.length)
			{
				if (l!= 0)
				{
					s2_mouthcolors_pos2[l].avgx = (x+s2_mouthcolors_pos2[l].firstx)/2;
					s2_mouthcolors_pos2[l].avgy = (y+s2_mouthcolors_pos2[l].firsty)/2;
	
					sfile.write("super2_mouth_colors_pos2x"+l, ((x+s2_mouthcolors_pos2[l].firstx)/2));
					sfile.write("super2_mouth_colors_pos2y"+l, ((y+s2_mouthcolors_pos2[l].firsty)/2));
				}
			}
			else
			{
				s2_mouthcolors2[l] = c_pixel;
				s2_mouthcolors_pos2[l] = new Object();
				s2_mouthcolors_pos2[l].firstx = x;
				s2_mouthcolors_pos2[l].firsty = y;
	
				s2_mouthcolors_pos2[l].avgx = (x+s2_mouthcolors_pos2[l].firstx)/2;
				s2_mouthcolors_pos2[l].avgy = (y+s2_mouthcolors_pos2[l].firsty)/2;
				
				sfile.write("super2_mouth_colors_pos2firstx"+l, x);
				sfile.write("super2_mouth_colors_pos2firsty"+l, y);
		
				sfile.write("super2_mouth_colors_pos2x"+l, ((x+s2_mouthcolors_pos2[l].firstx)/2));
				sfile.write("super2_mouth_colors_pos2y"+l, ((y+s2_mouthcolors_pos2[l].firsty)/2));
				
			}
		}
	}
	sfile.write("s2_mouthcolors2_length", s2_mouthcolors2.length);
	for (l=0;l<s2_mouthcolors2.length;l++)
	{
		sfile.write("s2_mouthcolors2_red"+l, s2_mouthcolors2[l].red);
		sfile.write("s2_mouthcolors2_green"+l, s2_mouthcolors2[l].green);
		sfile.write("s2_mouthcolors2_blue"+l, s2_mouthcolors2[l].blue);
	}		
}
else
{
	load_temp = sfile.read("headcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("headcolors_red"+l, 0)
		tg1 = sfile.read("headcolors_green"+l, 0)
		tb1 = sfile.read("headcolors_blue"+l, 0)
		headcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}

	//setup head mask info
	for (l=0;l<headcolors.length;l++)
	{
		headcolors_pos[l] = new Object();
		headcolors_pos[l].firstx = sfile.read("super1_headcolors_posfirstx"+l, 0);
		headcolors_pos[l].firsty = sfile.read("super1_headcolors_posfirsty"+l, 0);
	
		headcolors_pos[l].avgx = sfile.read("super1_headcolors_posx"+l, 0);
		headcolors_pos[l].avgy = sfile.read("super1_headcolors_posy"+l, 0);
	}


	load_temp = sfile.read("neck_bottomcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("neck_bottomcolors_red"+l, 0)
		tg1 = sfile.read("neck_bottomcolors_green"+l, 0)
		tb1 = sfile.read("neck_bottomcolors_blue"+l, 0)
		neck_bottomcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}

	
	//setup neck mask info
	for (l=0;l<neck_bottomcolors.length;l++)
	{
		neck_bottomcolors_pos[l] = new Object();
		neck_bottomcolors_pos[l].firstx = sfile.read("super1_neck_bottom_colors_posfirstx"+l, 0);
		neck_bottomcolors_pos[l].firsty = sfile.read("super1_neck_bottom_colors_posfirsty"+l, 0);
	
		neck_bottomcolors_pos[l].avgx = sfile.read("super1_neck_bottom_colors_posx"+l, 0);
		neck_bottomcolors_pos[l].avgy = sfile.read("super1_neck_bottom_colors_posy"+l, 0);
	}
	
	load_temp = sfile.read("mouthcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("mouthcolors_red"+l, 0)
		tg1 = sfile.read("mouthcolors_green"+l, 0)
		tb1 = sfile.read("mouthcolors_blue"+l, 0)
		mouthcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}
	//setup mouth mask info
	for (l=0;l<mouthcolors.length;l++)
	{
		mouthcolors_pos1[l] = new Object();
		mouthcolors_pos1[l].firstx = sfile.read("super1_mouth_colors_pos1firstx"+l, 0);
		mouthcolors_pos1[l].firsty = sfile.read("super1_mouth_colors_pos1firsty"+l, 0);
	
		mouthcolors_pos1[l].avgx = sfile.read("super1_mouth_colors_pos1x"+l, 0);
		mouthcolors_pos1[l].avgy = sfile.read("super1_mouth_colors_pos1y"+l, 0);
	}
	
	load_temp = sfile.read("mouthcolors2_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("mouthcolors2_red"+l, 0)
		tg1 = sfile.read("mouthcolors2_green"+l, 0)
		tb1 = sfile.read("mouthcolors2_blue"+l, 0)
		mouthcolors2[l] = CreateColor(tr1, tg1, tb1, 0);
	}	
	
	for (l=0;l<mouthcolors2.length;l++)
	{
		mouthcolors_pos2[l] = new Object();
		mouthcolors_pos2[l].firstx = sfile.read("super1_mouth_colors_pos2firstx"+l, 0);
		mouthcolors_pos2[l].firsty = sfile.read("super1_mouth_colors_pos2firsty"+l, 0);
	
		mouthcolors_pos2[l].avgx = sfile.read("super1_mouth_colors_pos2x"+l, 0);
		mouthcolors_pos2[l].avgy = sfile.read("super1_mouth_colors_pos2y"+l, 0);
	}
	
	//supernaut 2 colours
	load_temp = sfile.read("s2_headcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("s2_headcolors_red"+l, 0)
		tg1 = sfile.read("s2_headcolors_green"+l, 0)
		tb1 = sfile.read("s2_headcolors_blue"+l, 0)
		s2_headcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}		
	for (l=0;l<s2_headcolors.length;l++)
	{
		s2_headcolors_pos[l] = new Object();
		s2_headcolors_pos[l].firstx = sfile.read("super2_headcolors_posfirstx"+l, 0);
		s2_headcolors_pos[l].firsty = sfile.read("super2_headcolors_posfirsty"+l, 0);
	
		s2_headcolors_pos[l].avgx = sfile.read("super2_headcolors_posx"+l, 0);
		s2_headcolors_pos[l].avgy = sfile.read("super2_headcolors_posy"+l, 0);
	}
	
	
	load_temp = sfile.read("s2_neck_topcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("s2_neck_topcolors_red"+l, 0)
		tg1 = sfile.read("s2_neck_topcolors_green"+l, 0)
		tb1 = sfile.read("s2_neck_topcolors_blue"+l, 0)
		s2_neck_topcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}			
	//setup neck mask info
	for (l=0;l<s2_neck_topcolors.length;l++)
	{
		s2_neck_topcolors_pos[l] = new Object();
		s2_neck_topcolors_pos[l].firstx = sfile.read("super2_neck_topcolors_posfirstx"+l, 0);
		s2_neck_topcolors_pos[l].firsty = sfile.read("super2_neck_topcolors_posfirsty"+l, 0);
	
		s2_neck_topcolors_pos[l].avgx = sfile.read("super2_neck_topcolors_posx"+l, 0);
		s2_neck_topcolors_pos[l].avgy = sfile.read("super2_neck_topcolors_posy"+l, 0);
	}
	load_temp = sfile.read("s2_mouthcolors_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("s2_mouthcolors_red"+l, 0)
		tg1 = sfile.read("s2_mouthcolors_green"+l, 0)
		tb1 = sfile.read("s2_mouthcolors_blue"+l, 0)
		s2_mouthcolors[l] = CreateColor(tr1, tg1, tb1, 0);
	}			
		//setup mouth mask info
	for (l=0;l<s2_mouthcolors.length;l++)
	{
		s2_mouthcolors_pos1[l] = new Object();
		s2_mouthcolors_pos1[l].firstx = sfile.read("super2_mouth_colors_pos1firstx"+l, 0);
		s2_mouthcolors_pos1[l].firsty = sfile.read("super2_mouth_colors_pos1firsty"+l, 0);
	
		s2_mouthcolors_pos1[l].avgx = sfile.read("super2_mouth_colors_pos1x"+l, 0);
		s2_mouthcolors_pos1[l].avgy = sfile.read("super2_mouth_colors_pos1y"+l, 0);
	}
	
	load_temp = sfile.read("s2_mouthcolors2_length", 0);
	for (l=0;l<load_temp;l++)
	{
		tr1 = sfile.read("s2_mouthcolors2_red"+l, 0)
		tg1 = sfile.read("s2_mouthcolors2_green"+l, 0)
		tb1 = sfile.read("s2_mouthcolors2_blue"+l, 0)
		s2_mouthcolors2[l] = CreateColor(tr1, tg1, tb1, 0);
	}		
	for (l=0;l<s2_mouthcolors2.length;l++)
	{
		s2_mouthcolors_pos2[l] = new Object();
		s2_mouthcolors_pos2[l].firstx = sfile.read("super2_mouth_colors_pos2firstx"+l, 0);
		s2_mouthcolors_pos2[l].firsty = sfile.read("super2_mouth_colors_pos2firsty"+l, 0);
	
		s2_mouthcolors_pos2[l].avgx = sfile.read("super2_mouth_colors_pos2x"+l, 0);
		s2_mouthcolors_pos2[l].avgy = sfile.read("super2_mouth_colors_pos2y"+l, 0);
	}
}

sfile.flush();
sfile.close();


//supernaut active variables
var g_supernaut_active = -1;



var g_pressedy = false;
var h_pressedy = false;
var t_pressedy = false;
var m_pressedy = false;


function MakeHeadBleed(num)
{
	if (num == 0)
		return;
//	num = 3;
	var nauty = ReturnActiveSupernaut();
	
	if (g_supernaut_active == 1)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(headcolors[num].red, headcolors[num].green, headcolors[num].blue, 255);
		naut_head_mask.replaceColor(headcolors[num], temp);
		naut_head_mask.setBlendMode(SUBTRACT);
		naut_head.setBlendMode(ADD);
		naut_head.blitSurface(naut_head_mask, 0, 0);
		naut_head.replaceColor(temp, CreateColor(0,0,0,0));




		naut_head_mask.replaceColor(temp, headcolors[num]);
		naut_head_mask.setBlendMode(REPLACE);
		naut_head.setBlendMode(REPLACE);
		naut_headi = naut_head.createImage();
		
		naut1.headstates[num] = 1;
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			SpawnGuts(-4, headcolors_pos[num].avgx+nauty.x+nauty.hx,headcolors_pos[num].avgy+nauty.y+nauty.hy,4*Math.random()-1,-4-2*Math.random(), "supernaut_head"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	}
	else if (g_supernaut_active == 2)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(s2_headcolors[num].red, s2_headcolors[num].green, s2_headcolors[num].blue, 255);
		naut2_head_mask.replaceColor(s2_headcolors[num], temp);
		naut2_head_mask.setBlendMode(SUBTRACT);
		naut2_head.setBlendMode(ADD);
		naut2_head.blitSurface(naut2_head_mask, 0, 0);
		naut2_head.replaceColor(temp, CreateColor(0,0,0,0));


		naut2_head_mask.replaceColor(temp, s2_headcolors[num]);
		naut2_head_mask.setBlendMode(REPLACE);
		naut2_head.setBlendMode(REPLACE);
		naut2_headi = naut2_head.createImage();
		
		naut2.headstates[num] = 1;
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			SpawnGuts(-4, s2_headcolors_pos[num].avgx+nauty.x+nauty.hx,s2_headcolors_pos[num].avgy+nauty.y+nauty.hy,4*Math.random()-1,-4-2*Math.random(), "supernaut_head"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	
	}
}

function MakeNeckBleed(num)
{
	if (num == 0)
		return;
//	num = 3;
	var nauty = naut1;

	if (g_supernaut_active == 1)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(neck_bottomcolors[num].red, neck_bottomcolors[num].green, neck_bottomcolors[num].blue, 255);
		naut_neck_bottom_mask.replaceColor(neck_bottomcolors[num], temp);
		naut_neck_bottom_mask.setBlendMode(SUBTRACT);
		naut_neck_bottom.setBlendMode(ADD);
		naut_neck_bottom.blitSurface(naut_neck_bottom_mask, 0, 0);
		naut_neck_bottom.replaceColor(temp, CreateColor(0,0,0,0));


		naut_neck_bottom_mask.replaceColor(temp, neck_bottomcolors[num]);
		naut_neck_bottom_mask.setBlendMode(REPLACE);
		naut_neck_bottom.setBlendMode(REPLACE);
		naut_neck_bottomi = naut_neck_bottom.createImage();
		
		naut1.neck_bottomstates[num] = 1;
	
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			SpawnGuts(-4, neck_bottomcolors_pos[num].avgx+nauty.x+nauty.nx,neck_bottomcolors_pos[num].avgy+nauty.y+nauty.ny,4*Math.random()-1,-4-2*Math.random(), "supernaut_neck"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	}
	else if (g_supernaut_active == 2)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(s2_neck_topcolors[num].red, s2_neck_topcolors[num].green, s2_neck_topcolors[num].blue, 255);
		naut2_neck_top_mask.replaceColor(s2_neck_topcolors[num], temp);
		naut2_neck_top_mask.setBlendMode(SUBTRACT);
		naut2_neck_top.setBlendMode(ADD);
		naut2_neck_top.blitSurface(naut2_neck_top_mask, 0, 0);
		naut2_neck_top.replaceColor(temp, CreateColor(0,0,0,0));


		naut2_neck_top_mask.replaceColor(temp, s2_neck_topcolors[num]);
		naut2_neck_top_mask.setBlendMode(REPLACE);
		naut2_neck_top.setBlendMode(REPLACE);
		naut2_neck_topi = naut2_neck_top.createImage();
		
		naut2.neck_topstates[num] = 1;
	
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			SpawnGuts(-4, s2_neck_topcolors_pos[num].avgx+nauty.x+nauty.nx,s2_neck_topcolors_pos[num].avgy+nauty.y+nauty.ny,4*Math.random()-1,-4-2*Math.random(), "supernaut_neck"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	}
}

function MakeMouthBleed(num)
{
	if (num == 0)
		return;
//	num = 3;
	var nauty = ReturnActiveSupernaut();

	if (g_supernaut_active == 1)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(mouthcolors[num].red, mouthcolors[num].green, mouthcolors[num].blue, 255);
		naut_mouth_mask_1.replaceColor(mouthcolors[num], temp);
		naut_mouth_mask_1.setBlendMode(SUBTRACT);
		naut_mouth_1.setBlendMode(ADD);
		naut_mouth_1.blitSurface(naut_mouth_mask_1, 0, 0);
		naut_mouth_1.replaceColor(temp, CreateColor(0,0,0,0));


		naut_mouth_mask_1.replaceColor(temp, mouthcolors[num]);
		naut_mouth_mask_1.setBlendMode(REPLACE);
		naut_mouth_1.setBlendMode(REPLACE);
		naut_mouth_1i = naut_mouth_1.createImage();
		
		naut_mouth_mask_2.replaceColor(mouthcolors[num], temp);
		naut_mouth_mask_2.setBlendMode(SUBTRACT);
		naut_mouth_2.setBlendMode(ADD);
		naut_mouth_2.blitSurface(naut_mouth_mask_2, 0, 0);
		naut_mouth_2.replaceColor(temp, CreateColor(0,0,0,0));


		naut_mouth_mask_2.replaceColor(temp, mouthcolors[num]);
		naut_mouth_mask_2.setBlendMode(REPLACE);
		naut_mouth_2.setBlendMode(REPLACE);
		naut_mouth_2i = naut_mouth_2.createImage();
		
		naut1.mouthstates[num] = 1;
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			if (nauty.openmouth == 0)
				SpawnGuts(-4, mouthcolors_pos1[num].avgx+nauty.x+nauty.mx,mouthcolors_pos1[num].avgy+nauty.y+nauty.my,4*Math.random()-1,-4-2*Math.random(), "supernaut_mouth"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
			else if (nauty.openmouth == 1)
				SpawnGuts(-4, mouthcolors_pos2[num].avgx+nauty.x+nauty.mx,mouthcolors_pos2[num].avgy+nauty.y+nauty.my,4*Math.random()-1,-4-2*Math.random(), "supernaut_mouth"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	}
	else if (g_supernaut_active == 2)
	{
		var temp = CreateColor(255, 255, 255, 255);//CreateColor(s2_mouthcolors[num].red, s2_mouthcolors[num].green, s2_mouthcolors[num].blue, 255);
		naut2_mouth_mask_1.replaceColor(s2_mouthcolors[num], temp);
		naut2_mouth_mask_1.setBlendMode(SUBTRACT);
		naut2_mouth_1.setBlendMode(ADD);
		naut2_mouth_1.blitSurface(naut2_mouth_mask_1, 0, 0);
		naut2_mouth_1.replaceColor(temp, CreateColor(0,0,0,0));


		naut2_mouth_mask_1.replaceColor(temp, s2_mouthcolors[num]);
		naut2_mouth_mask_1.setBlendMode(REPLACE);
		naut2_mouth_1.setBlendMode(REPLACE);
		naut2_mouth_1i = naut2_mouth_1.createImage();
		
		naut2_mouth_mask_2.replaceColor(s2_mouthcolors[num], temp);
		naut2_mouth_mask_2.setBlendMode(SUBTRACT);
		naut2_mouth_2.setBlendMode(ADD);
		naut2_mouth_2.blitSurface(naut2_mouth_mask_2, 0, 0);
		naut2_mouth_2.replaceColor(temp, CreateColor(0,0,0,0));


		naut2_mouth_mask_2.replaceColor(temp, s2_mouthcolors[num]);
		naut2_mouth_mask_2.setBlendMode(REPLACE);
		naut2_mouth_2.setBlendMode(REPLACE);
		naut2_mouth_2i = naut2_mouth_2.createImage();
		
		naut2.mouthstates[num] = 1;
		for (sn = 0; sn<1+Math.floor(2*Math.random());sn++)
		{
			if (nauty.openmouth == 0)
				SpawnGuts(-4, s2_mouthcolors_pos1[num].avgx+nauty.x+nauty.mx,s2_mouthcolors_pos1[num].avgy+nauty.y+nauty.my,4*Math.random()-1,-4-2*Math.random(), "supernaut_mouth"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
			else if (nauty.openmouth == 1)
				SpawnGuts(-4, s2_mouthcolors_pos2[num].avgx+nauty.x+nauty.mx,s2_mouthcolors_pos2[num].avgy+nauty.y+nauty.my,4*Math.random()-1,-4-2*Math.random(), "supernaut_mouth"+(Math.floor(3*Math.random()) + 1), false, gut_layer+Math.floor(2*Math.random()));
		}
	
	}
}




function ReturnActiveSupernaut()
{
	if (g_supernaut_active == 1)
		return naut1;
	if (g_supernaut_active == 2)
		return naut2;
	if (g_supernaut_active == 3)
		return naut3;
	return false;
}

function DoSupernautDamage(dam, type, color)
{
	var nauty = ReturnActiveSupernaut();
	if (g_supernaut_active == 1)
	{
	
		if (type == "head")
		{
			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<headcolors.length;l++)
				{
	/*					GetSystemFont().drawText(0,0,headcolors[l].red + " " + color.red);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();*/
					if (headcolors[l].red == color.red && headcolors[l].green == color.green && headcolors[l].blue == color.blue)
					{
						MakeHeadBleed(l);
						break;
					}
				}
			}
		}
		if (type == "neck")
		{
			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<neck_bottomcolors.length;l++)
				{
	/*					GetSystemFont().drawText(0,0,headcolors[l].red + " " + color.red);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();*/
					if (neck_bottomcolors[l].red == color.red && neck_bottomcolors[l].green == color.green && neck_bottomcolors[l].blue == color.blue)
					{
						MakeNeckBleed(l);
						break;
					}
				}
			}
		}	
		
		if (type == "mouth_1" || type == "mouth_2")
		{
			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<mouthcolors.length;l++)
				{
	/*					GetSystemFont().drawText(0,0,headcolors[l].red + " " + color.red);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();*/
					if (mouthcolors[l].red == color.red && mouthcolors[l].green == color.green && mouthcolors[l].blue == color.blue)
					{
						MakeMouthBleed(l);
						break;
					}
				}
			}
		}	
	}
	else if (g_supernaut_active == 2)
	{
		if (type == "head")
		{

			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<s2_headcolors.length;l++)
				{
						/*GetSystemFont().drawText(0,0,s2_headcolors[l].red + " " + color.red);
						GetSystemFont().drawText(0,10,s2_headcolors[l].green + " " + color.green);
						GetSystemFont().drawText(0,20,s2_headcolors[l].blue + " " + color.blue);
						GetSystemFont().drawText(0,30,s2_headcolors[l].alpha + " " + color.alpha);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();
*/					if (s2_headcolors[l].red == color.red && s2_headcolors[l].green == color.green && s2_headcolors[l].blue == color.blue)
					{
						MakeHeadBleed(l);
						break;
					}
				}
			}
		}
		if (type == "neck")
		{
			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<s2_neck_topcolors.length;l++)
				{
	/*					GetSystemFont().drawText(0,0,headcolors[l].red + " " + color.red);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();*/
					if (s2_neck_topcolors[l].red == color.red && s2_neck_topcolors[l].green == color.green && s2_neck_topcolors[l].blue == color.blue)
					{
						MakeNeckBleed(l);
						break;
					}
				}
			}
		}	
		
		if (type == "mouth_1" || type == "mouth_2")
		{
			nauty.hp1 -= dam;
			if (Math.floor(nauty.hp1/333) < Math.floor((nauty.hp1+dam)/333))
			{
				for (l=0;l<s2_mouthcolors.length;l++)
				{
	/*					GetSystemFont().drawText(0,0,headcolors[l].red + " " + color.red);
						FlipScreen();
						while(AreKeysLeft())GetKey();
						GetKey();*/
					if (s2_mouthcolors[l].red == color.red && s2_mouthcolors[l].green == color.green && s2_mouthcolors[l].blue == color.blue)
					{
						MakeMouthBleed(l);
						break;
					}
				}
			}
		}	
	}
	return;
}


var g_supernaut_head_layer = 5;


function SetupSupernautDrawing()
{
	SetLayerRenderer(0, "DrawSupernautNeck();");
	SetLayerRenderer(g_supernaut_head_layer, "DrawSupernautMouth();DrawSupernautHead();");		
}




var idle_base = 15;
var idle_max = 25;
		

var g_stage_wait = 160;
var g_stage1_x = 220;
var g_stage2_x = 380;
var g_stage3_x = 540;
var g_headbutt_require=12;

var naut2_stage1_limit = 25;

function SupernautUpdateAI()
{
	var nauty = ReturnActiveSupernaut();
	if (nauty.hp1 <= 0)
	{
		if (g_supernaut_active == 1)
		{
			nauty.openmouth = 1;
			GoToLevel(14);
			return;
		}
		else if (g_supernaut_active == 2)
		{
			nauty.openmouth = 1;
			GoToLevel(16);
			return;
		}
	}
	var tempnum;
	var rand;
	var angle;
	
	var eat_ammy = 0;
	
	var ttx = 0;
	var tty = 0;
	
	
	var testings=false
	//testing code
	if (testings == true)
	{
		if (IsKeyPressed(KEY_G) && g_pressedy == false)
		{
			g_pressedy = true;
			tempnum = Math.floor(s2_headcolors.length*Math.random());
			for (ds = 0; ds<s2_headcolors.length;ds++)
			{
				
				if (naut2.headstates[(tempnum+ds)%s2_headcolors.length] == 0 && (tempnum+ds)%s2_headcolors.length != 0)
				{
					MakeHeadBleed((tempnum+ds)%s2_headcolors.length);
					break;
				}
			}
		}
		if (!IsKeyPressed(KEY_G))
			g_pressedy = false;
	
		if (IsKeyPressed(KEY_H) && h_pressedy == false)
		{
			h_pressedy = true;
			tempnum = Math.floor(s2_neck_topcolors.length*Math.random());
			for (ds = 0; ds<s2_neck_topcolors.length;ds++)
			{
				
				if (naut2.neck_topstates[(tempnum+ds)%s2_neck_topcolors.length] == 0 && (tempnum+ds)%s2_neck_topcolors.length != 0)
				{
					MakeNeckBleed((tempnum+ds)%s2_neck_topcolors.length);
					break;
				}
			}
		}
		if (!IsKeyPressed(KEY_H))
			h_pressedy = false;
	
			
		if (IsKeyPressed(KEY_M) && m_pressedy == false)
		{
			m_pressedy = true;
		}
		if (!IsKeyPressed(KEY_M))
			m_pressedy = false;
	}
/*
	if (nauty.dir2 == "wait")
	{
		nauty.idle_counter--;
		if (nauty.idle_counter <= 0)
		{
			nauty.idle_counter = idle_base+idle_max*Math.random();
			
			if (Math.random()<0.5)
				PlaySound(70);
			else
				PlaySound(71);
		}
	}
*/
//		naut1.openmouth = (naut1.openmouth+1)%2;

//AI Section:
	if (g_supernaut_active == 1)
	{
		if (nauty.counter == 0)
		{
			//setup new attack
			if (nauty.dir2 == "wavebeam_warmup")
			{
				nauty.counter = 30;
				nauty.openmouth = 1;
			
				nauty.dir2 = "wavebeam";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "wait2")
			{
				nauty.counter = 1;
				nauty.dir2 = "";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "wait")
			{
				if (Math.random()<0.4)
				{
					if (Math.random()<0.5)
						PlaySound(70);
					else
						PlaySound(71);
				}
				nauty.counter = 60;
				nauty.openmouth = 0;
				
				nauty.dir2 = "";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat_warmup")
			{
				nauty.counter = 32;
			
				nauty.dir2 = "eat";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat")
			{
				nauty.counter = 48;
		//		nauty.eyoff = 0;
			//	nauty.exoff = 0;
				nauty.dir2 = "eat_back";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat_back")
			{
				nauty.counter = 2;
				if (eat_camera == 1)
					nauty.counter = 2000;
				nauty.eyoff = 0;
				nauty.exoff = 0;
				nauty.dir2 = "wait";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "oblit_warmup")
			{
				nauty.counter = 60;
				nauty.openmouth = 1;
			
				nauty.dir2 = "oblit_beam";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "flame_warmup")
			{
				nauty.counter = 120;
				nauty.openmouth = 1;
			
				PlaySound(73);
				nauty.dir2 = "flame";//facing west
				nauty.frame = 0;//facing west
			}
			else
			{
				//come up with new stuff
				rand = Math.random();

				if (entities[0].y < 412)
					nauty.ptop_count++;
				else
					nauty.ptop_count=0;
					
				if (nauty.ptop_count > 2 || (nauty.ptop_count>1 && Math.random() <0.5))
				{
					nauty.counter = 64;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
					PlaySound(108);
					nauty.dir2 = "flame_warmup";//facing west
					nauty.frame = 0;//facing west
				}
				else if ((PlayerInEatRange()==true && nauty.chompcount == 0)||(PlayerInEatRange()==true && Math.random()<0.5))
				{
					if (nauty.y+nauty.hy+16*12+32 < nauty.by+216)
					{
						nauty.counter = 1;
				
						nauty.dir2 = "";//wait2";//facing west
						nauty.frame = 0;//facing west				
					}
					else
					{
						nauty.counter = 16;
						nauty.openmouth = 1;
						nauty.chompcount++;
						nauty.dir2 = "eat_warmup";//facing west
						nauty.frame = 0;//facing west
					}
				}
				else if (rand < 0.333333)
				{
					nauty.counter = 48;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
	//				PlaySound(67);
					PlaySound(74);
					
					nauty.dir2 = "wavebeam_warmup";//facing west
					nauty.frame = 0;//facing west
				}
				else //if (rand < 0.66666)
				{
					nauty.counter = 48;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
				
					if (Math.random()<0.5)
						PlaySound(68);
					else
						PlaySound(69);
	
					nauty.dir2 = "oblit_warmup";//facing west
					nauty.frame = 0;//facing west
				}
//				else
	///			{
		//			nauty.counter = 64;
			//		nauty.openmouth = 1;
				//	nauty.chompcount = 0;
					//play a warmup-sound
					//PlaySound(108);
				
//					nauty.dir2 = "flame_warmup";//facing west
	//				nauty.frame = 0;//facing west
		//		}
				
			

				
			}
		}
		if (g_frames%2 == 0 || nauty.dir2 == "eat" || nauty.dir2 == "eat_warmup"|| nauty.dir2 == "eat_back")
		{
			if (nauty.dir2 == "wavebeam")
			{
				if (nauty.frame == 0)
					PlaySound(75);
	
				nauty.frame++;
				if (nauty.frame ==6)
				{
					if (g_supernaut_active == 1)
					{
					
						ttx = nauty.x+nauty.mx+g_superwboffx-720;
						tty = 16+nauty.y+nauty.my+g_superwboffy;
						if (entities[0].x < ttx+720 && entities[0].x > ttx &&
								entities[0].y < tty+48+32 && entities[0].y > tty+48-32-16)
								{
									//caught in the wave!
									if (!(entities[0].invince > 0 || entities[0].hp <= 0 || oblit_shield > 0))
									{
										RemovePlayerHP(supernaught_wavedamage);
										entities[0].invince = invince_max;
		
										for (bl=0;bl<4;bl++)
										{
											if (Math.random()<0.5)
												SpawnBlood(entities[0].x,entities[0].y,-3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
											else
												SpawnBlood(entities[0].x,entities[0].y,3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
										}
									}
								}
					}
					else if (g_supernaut_active == 2)
					{
	
						ttx = nauty.x+nauty.mx+80+g_superwboffx-720+naut_wavebeam2[nauty.frame].width+80;
						tty = 16+nauty.y+nauty.my+g_superwboffy;
						if (entities[0].x < ttx+720 && entities[0].x > ttx &&
								entities[0].y < tty+48+32 && entities[0].y > tty+48-32-16)
								{
									//caught in the wave!
									if (!(entities[0].invince > 0 || entities[0].hp <= 0 || oblit_shield > 0))
									{
										RemovePlayerHP(supernaught_wavedamage);
										entities[0].invince = invince_max;
		
										for (bl=0;bl<4;bl++)
										{
											if (Math.random()<0.5)
												SpawnBlood(entities[0].x,entities[0].y,-3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
											else
												SpawnBlood(entities[0].x,entities[0].y,3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
										}
									}
								}
					
					}
				}
				if (nauty.frame > 8)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
			else if (nauty.dir2 == "wavebeam_warmup")
			{
				nauty.frame = (nauty.frame+1)%4;
			}
			else if (nauty.dir2 == "eat_warmup")
			{
				nauty.exoff = 0;
				nauty.eyoff-= 1;
			}
			else if (nauty.dir2 == "eat")
			{
				if (nauty.eyoff > 20 && nauty.openmouth != 0)
				{
					if (sounds[65].isPlaying() == false)
						PlaySound(65);
				}
	
				if (nauty.eyoff >= 30)
				{
					nauty.eyoff = 30;
					if (nauty.openmouth != 0)
					{
					/*
PlayerInEatRange()

		var ntx = naut1.bx+48-48;
		var nty = naut1.by+48;
					
79*16				*/	
						if (entities[0].x > 1264 && entities[0].x < 1336)
						{
							if (entities[0].y > 304 && entities[0].y < 540)
							{
								EatThePlayer();
							
							}
						}
					}
					nauty.openmouth = 0;
					
				}
				else
				{
					if (nauty.counter > 6)
					{
						nauty.exoff-=0.5;
						nauty.eyoff+=0.5;
						if (nauty.counter < 29)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 26)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 23)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 20)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 17)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}				
						if (nauty.counter < 14)
						{
							nauty.exoff-=0.5;
							nauty.eyoff+=0.5;
						}				
					}
				}
			}
			else if (nauty.dir2 == "eat_back")
			{
				eat_ammy = 0.5;
				if (Math.abs(nauty.counter-24) < 16)
					eat_ammy = 1;
				if (Math.abs(nauty.counter-24) < 8)
					eat_ammy = 1.5;
			
				if (nauty.exoff < 0)
					nauty.exoff+=eat_ammy;
				else
					nauty.exoff=0;
					
				if (nauty.eyoff > 0)
					nauty.eyoff-=eat_ammy;
				else
					nauty.eyoff=0;
			}
			else if (nauty.dir2 == "flame_warmup")
			{
				nauty.frame = 0;
			}
			else if (nauty.dir2 == "oblit_warmup")
			{
				//drawrailguns
				var radius1 = 200;
				var radius2 = 10;
				var mcx = 16*6;
				var mcy = 16*12;
				var rcy = 64*Math.random()-32;
				var rcx = -rcy/1.5;
				if (nauty.counter < 50)
				{
					for (dd=0;dd<3;dd++)
					{
						if (g_supernaut_active == 1)
						{
						
							angle = Math.random()*3.14159/12+3.14159-3.14159/24;
							SpawnRailgun(
														radius2*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius2*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													 
													 1,supernaut_rail_dam);
							SpawnRailgun(
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx-radius1, 2*radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													 
													 1,supernaut_rail_dam);
						}
						else if (g_supernaut_active == 2)
						{
							angle = Math.random()*3.14159/12-3.14159/24;
							SpawnRailgun(
														radius2*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius2*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													 
													 1,supernaut_rail_dam);
							SpawnRailgun(
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80+radius1, 2*radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
														radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													 
													 1,supernaut_rail_dam);
						
						}
					}
				}
			}
			else if (nauty.dir2 == "oblit_beam")
			{
				nauty.frame++;
				if (nauty.frame ==8)
				{
	//				FireObliterator(0);
				}
				if (nauty.frame > 8)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
			else if (nauty.dir2 == "flame")
			{
				var mcx = 16*6;
				var mcy = 16*12;
				var rcy = 64*Math.random()-32;
				var rcx = -rcy/1.5;
				var rands = 1+Math.random();
				for (dd=0;dd<5;dd++)
				{
					if (g_supernaut_active == 1)
					{
						rcy = 64*Math.random()-32;
						rcx = -rcy/1.5;
						rands = 1+Math.random();
						SpawnExplosion(nauty.x+nauty.hx+mcx+rcx,nauty.y+nauty.hy+mcy+rcy, supernaut_flame_damage,-1, 1*rands, 3,-1*7*rands,0);
					}
					else if (g_supernaut_active == 2)
					{
						rcy = 64*Math.random()-32;
						rcx = rcy/1.5;
						rands = 1+Math.random();
						SpawnExplosion(nauty.x+nauty.hx+mcx+rcx+80,nauty.y+nauty.hy+mcy+rcy, supernaut_flame_damage,-1, 1*rands, 3,1*7*rands,0);
					}
				}
				nauty.frame++;
				if (nauty.frame > 48)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
		}
		nauty.counter--;
		nauty.fc++;
		if (nauty.dir2 != "eat_warmup" && nauty.dir2 != "eat" && nauty.dir2 != "flame")
		{
			if (nauty.y+nauty.hy+16*12+32 > entities[0].y+16 +8)
			{
		//		font.drawText(0,0,"up");
				nauty.fc2++;
			}
			else if (nauty.y+nauty.hy+16*12+32 < entities[0].y+16 -8)
			{
		//		font.drawText(0,0,"down");
				nauty.fc2--;
			}
			
			if (entities[0].x > nauty.x+16*5+8)
			{
				//try to eat the player
				if (nauty.y+nauty.hy+16*12+32 > entities[0].y+16 +8)
				{
			//		font.drawText(0,0,"up");
					nauty.fc2+=7;
				}
				else if (nauty.y+nauty.hy+16*12+32 < entities[0].y+16 -8)
				{
			//		font.drawText(0,0,"down");
					nauty.fc2-=7;
				}
				
			}
		
			if (nauty.fc2 < -314/2)
				nauty.fc2 = -314/2;
			if (nauty.fc2 > 314/2)
				nauty.fc2 = 314/2;
			
		}
	nauty.x = nauty.bx - 48*Math.sin(nauty.fc2/100)-48+nauty.exoff;
	nauty.y = nauty.by - 40*Math.sin(nauty.fc2/100)-40+nauty.eyoff;
	nauty.ny = 1*Math.cos(nauty.fc/3)-2;//in mapy
	nauty.hy = 1*Math.sin(nauty.fc/3);//in mapy
	nauty.my = (2+eat_camera*2)*Math.sin(nauty.fc/3);//in mapy		
	nauty.mx = 2+(eat_camera)*Math.sin(nauty.fc/3);//in mapy		
	nauty.hx = 2;//in mapy
	}
	else if (g_supernaut_active == 2)
	{
		if (nauty.counter == 0)
		{
			//setup new attack

			if (nauty.dir2 == "headbutt" && nauty.hbc > 0)
			{
					nauty.counter = nauty.hstart;
					nauty.dir2 = "headbutt";//facing west
					nauty.frame = 0;//facing west
					nauty.hbc--;
			}
			else if (nauty.dir2 == "wavebeam_warmup")
			{
				nauty.counter = 30;
				nauty.openmouth = 1;
			
				nauty.dir2 = "wavebeam";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "grenade_warmup")
			{
				nauty.counter = 160;
				nauty.openmouth = 1;
			
				nauty.dir2 = "grenade";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "wait2")
			{
				nauty.counter = 1;
				nauty.dir2 = "";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "wait3")
			{
				nauty.openmouth = 0;
				nauty.counter = 30;
				nauty.dir2 = "";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "wait")
			{
				if (Math.random()<0.4)
				{
					if (Math.random()<0.5)
						PlaySound(70);
					else
						PlaySound(71);
				}
				nauty.counter = 60;
				nauty.openmouth = 0;
				
				nauty.dir2 = "";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "yell")
			{
				nauty.openmouth = 0;
				if (Math.random()<0.5)
				{
					PlaySound(72);
					nauty.openmouth = 1;
					nauty.counter = 160;
				}
				else if (Math.random()<0.5)
				{
					PlaySound(70);
					nauty.openmouth = 0;
					nauty.counter = 60;
				}
				else
				{
					PlaySound(71);
					nauty.openmouth = 0;
					nauty.counter = 60;
				}

				
				nauty.dir2 = "wait3";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat_warmup")
			{
				nauty.counter = 32;
			
				nauty.dir2 = "eat";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat")
			{
				nauty.counter = 48;
		//		nauty.eyoff = 0;
			//	nauty.exoff = 0;
				nauty.dir2 = "eat_back";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "eat_back")
			{
				nauty.counter = 2;
				if (eat_camera == 1)
					nauty.counter = 2000;
				nauty.eyoff = 0;
				nauty.exoff = 0;
				nauty.dir2 = "wait";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "oblit_warmup")
			{
				nauty.counter = 60;
				nauty.openmouth = 1;
			
				nauty.dir2 = "oblit_beam";//facing west
				nauty.frame = 0;//facing west
			}
			else if (nauty.dir2 == "flame_warmup")
			{
				nauty.counter = 80;
				nauty.openmouth = 1;
				PlaySound(73);
			
				nauty.dir2 = "flame";//facing west
				nauty.frame = 0;//facing west
			}
			else
			{
				naut2.phasey_count++;
			
				//come up with new stuff
				rand = Math.random();
				naut2.attack_counter++;
				if (naut2.hp1 < ((3-naut2.stage)/3)*naut2.maxhp || (naut2.attack_counter > naut2_stage1_limit && naut2.stage == 1))
				{
					nauty.counter = g_stage_wait;
					nauty.openmouth = 1;
					nauty.chompcount++;
					nauty.dir2 = "";//facing west
					nauty.frame = 0;//facing west
					Supernaut2StageBreak(naut2.stage);
				}
				else if ((PlayerInEatRange()==true && nauty.chompcount == 0)||(PlayerInEatRange()==true && Math.random()<0.5))
				{
					nauty.counter = 16;
					nauty.openmouth = 1;
					nauty.chompcount++;
					nauty.dir2 = "eat_warmup";//facing west
					nauty.frame = 0;//facing west
					
				}
				else if (naut2.run == true)
				{
					nauty.counter = 48;
					nauty.openmouth = 0;
					nauty.chompcount = 0;
					
					if (Math.random()<0.5)
						nauty.dir2 = "yell";
					else
						nauty.dir2 = "wait3";
					nauty.frame = 0;//facing west
				}
				
				else if ((rand < 0.2 && nauty.dir2 != "headbutt") || naut2.phasey_count > g_headbutt_require)
				{
					naut2.phasey_count = 0;
					nauty.counter = nauty.hstart;
					nauty.dir2 = "headbutt";//facing west
					nauty.frame = 0;//facing west
					nauty.hbc = 1+Math.floor(Math.random());//facing west
					
				}
				else if (rand < 0.4)
				{
					nauty.counter = 48;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
	//				PlaySound(67);
					PlaySound(74);
					
					nauty.dir2 = "wavebeam_warmup";//facing west
					nauty.frame = 0;//facing west
				}
				else if (rand < 0.6)
				{
					nauty.counter = 48;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
				
					if (Math.random()<0.5)
						PlaySound(68);
					else
						PlaySound(69);
	
					nauty.dir2 = "oblit_warmup";//facing west
					nauty.frame = 0;//facing west
				}
				else if (rand < 0.8)
				{
					nauty.counter = 48;
					nauty.openmouth = 1;
					nauty.chompcount = 0;

					PlaySound(121);

					nauty.dir2 = "grenade_warmup";//facing west
					nauty.frame = 0;//facing west
				}
				else
				{
					nauty.counter = 120;
					nauty.openmouth = 1;
					nauty.chompcount = 0;
				
					nauty.dir2 = "flame_warmup";//facing west
					nauty.frame = 0;//facing west
				}
			}
		}
		if (g_frames%2 == 0 || nauty.dir2 == "eat" || nauty.dir2 == "eat_warmup"|| nauty.dir2 == "eat_back")
		{
			if (nauty.dir2 == "wavebeam")
			{
				if (nauty.frame == 0)
					PlaySound(75);
	
				nauty.frame++;
				if (nauty.frame ==6)
				{
					if (g_supernaut_active == 1)
					{
					
						ttx = nauty.x+nauty.mx+g_superwboffx-720;
						tty = 16+nauty.y+nauty.my+g_superwboffy;
						if (entities[0].x < ttx+720 && entities[0].x > ttx &&
								entities[0].y < tty+48+32 && entities[0].y > tty+48-32)
								{
									//caught in the wave!
									if (!(entities[0].invince > 0 || entities[0].hp <= 0 || oblit_shield > 0))
									{
										RemovePlayerHP(supernaught_wavedamage);
										entities[0].invince = invince_max;
		
										for (bl=0;bl<4;bl++)
										{
											if (Math.random()<0.5)
												SpawnBlood(entities[0].x,entities[0].y,-3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
											else
												SpawnBlood(entities[0].x,entities[0].y,3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
										}
									}
								}
					}
					else if (g_supernaut_active == 2)
					{
	
						ttx = nauty.x+nauty.mx+80+g_superwboffx-720+naut_wavebeam2[nauty.frame].width+80;
						tty = 16+nauty.y+nauty.my+g_superwboffy;
						if (entities[0].x < ttx+720 && entities[0].x > ttx &&
								entities[0].y < tty+48+32 && entities[0].y > tty+48-32)
								{
									//caught in the wave!
									if (!(entities[0].invince > 0 || entities[0].hp <= 0 || oblit_shield > 0))
									{
										RemovePlayerHP(supernaught_wavedamage);
										entities[0].invince = invince_max;
		
										for (bl=0;bl<4;bl++)
										{
											if (Math.random()<0.5)
												SpawnBlood(entities[0].x,entities[0].y,-3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
											else
												SpawnBlood(entities[0].x,entities[0].y,3*2+Math.random()*2-1,-4*3-Math.random()-1,3, "w");		
										}
									}
								}
					
					}
				}
				if (nauty.frame > 8)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
			else if (nauty.dir2 == "wavebeam_warmup")
			{
				nauty.frame = (nauty.frame+1)%4;
			}
			else if (nauty.dir2 == "grenade_warmup")
			{
				nauty.frame = 0;
			}
			else if (nauty.dir2 == "grenade")
			{
				var mcx = 16*6;
				var mcy = 16*12;
				var rcy = 64*Math.random()-32;
				var rcx = -rcy/1.5;
				var rands = 1+Math.random();
				if (nauty.frame < 16)
				{
					if (nauty.frame %2 == 0)
					{
						for (dd=0;dd<1;dd++)
						{
							rcy = 64*Math.random()-32;
							rcx = rcy/1.5;
							rands = 1+Math.random();

							SpawnGrenade(nauty.x+nauty.hx+mcx+rcx+80,nauty.y+nauty.hy+mcy+rcy, 1*2*rands,-3-7*Math.random(), supernaut_grenade_damage, 5, -10, 2)
						}
					}
				}
				else
					nauty.openmouth = 0;

				nauty.frame++;

				if (nauty.frame > 48)
				{
					nauty.counter = 60;
					nauty.openmouth = 0;
					
					nauty.dir2 = "";//facing west
					nauty.frame = 0;//facing west
				}
			}
			else if (nauty.dir2 == "eat_warmup")
			{
				nauty.exoff = 0;
				nauty.eyoff-= 1;
			}
			else if (nauty.dir2 == "eat")
			{
				if (nauty.counter < 10 && nauty.openmouth != 0)
				{
					if (sounds[65].isPlaying() == false)
						PlaySound(65);
				}
	
				if (nauty.counter <2)
				{
//					nauty.eyoff = 30;
					if (nauty.openmouth != 0)
					{
						if (entities[0].x < naut2.bx+naut2.width-8)
						{
							if (entities[0].y > naut2.y && entities[0].y < naut2.y+naut2.height)
							{
								EatThePlayer();
							}
						}
					}
					nauty.openmouth = 0;
					
				}
				else
				{
					if (nauty.counter > 6)
					{
						nauty.exoff+=0.125;
						nauty.eyoff+=0.5;
						if (nauty.counter < 29)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 26)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 23)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 20)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}
						if (nauty.counter < 17)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}				
						if (nauty.counter < 14)
						{
							nauty.exoff+=0.125;
							nauty.eyoff+=0.5;
						}				
					}
				}
			}
			else if (nauty.dir2 == "eat_back")
			{
				eat_ammy = 0.5;
				if (Math.abs(nauty.counter-24) < 16)
					eat_ammy = 1;
				if (Math.abs(nauty.counter-24) < 8)
					eat_ammy = 1.5;
			
				if (nauty.exoff > 0)
					nauty.exoff-=eat_ammy/4;
				else
					nauty.exoff=0;
					
				if (nauty.eyoff > 0)
					nauty.eyoff-=eat_ammy;
				else
					nauty.eyoff=0;
			}
			else if (nauty.dir2 == "flame_warmup")
			{
				nauty.frame = 0;
			}
			else if (nauty.dir2 == "oblit_warmup")
			{
				//drawrailguns
				var radius1 = 200;
				var radius2 = 10;
				var mcx = 16*6;
				var mcy = 16*12;
				var rcy = 64*Math.random()-32;
				var rcx = -rcy/1.5;
	
				for (dd=0;dd<3;dd++)
				{
					if (g_supernaut_active == 1)
					{
					
						angle = Math.random()*3.14159/12+3.14159-3.14159/24;
						SpawnRailgun(
													radius2*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius2*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
												 
												 1,supernaut_rail_dam);
						SpawnRailgun(
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx-radius1, 2*radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx+rcx, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
												 
												 1,supernaut_rail_dam);
					}
					else if (g_supernaut_active == 2)
					{
						angle = Math.random()*3.14159/12-3.14159/24;
						SpawnRailgun(
													radius2*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius2*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
												 
												 1,supernaut_rail_dam);
						SpawnRailgun(
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80+radius1, 2*radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
													radius1*Math.cos(angle)+nauty.x+nauty.mx+mcx-rcx+80, radius1*Math.sin(angle)+nauty.y+nauty.my+mcy+rcy+10,
												 
												 1,supernaut_rail_dam);
					
					}
				}
			}
			else if (nauty.dir2 == "oblit_beam")
			{
				nauty.frame++;
				if (nauty.frame ==8)
				{
	//				FireObliterator(0);
				}
				if (nauty.frame > 8)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
			else if (nauty.dir2 == "flame")
			{
				var mcx = 16*6;
				var mcy = 16*12;
				var rcy = 64*Math.random()-32;
				var rcx = -rcy/1.5;
				var rands = 1+Math.random();
				for (dd=0;dd<5;dd++)
				{
					if (g_supernaut_active == 1)
					{
						rcy = 64*Math.random()-32;
						rcx = -rcy/1.5;
						rands = 1+Math.random();
						SpawnExplosion(nauty.x+nauty.hx+mcx+rcx,nauty.y+nauty.hy+mcy+rcy, supernaut_flame_damage,-1, 1*rands, 2,-1*7*rands,0);
					}
					else if (g_supernaut_active == 2)
					{
						rcy = 64*Math.random()-32;
						rcx = rcy/1.5;
						rands = 1+Math.random();
						SpawnExplosion(nauty.x+nauty.hx+mcx+rcx+80,nauty.y+nauty.hy+mcy+rcy, supernaut_flame_damage/2,-1, 1*rands, 3,1*7*rands,0);
					}
				}
				nauty.frame++;
				if (nauty.frame > 16)
				{
					nauty.dir2 = "wait";
					nauty.frame = 0;
				}
			}
		}
		else if ((nauty.dir2).substr(0,4) == "wait" || nauty.dir2 == ""|| (nauty.dir2).substr(0,3) == "eat" || (nauty.dir2).substr(0,8) == "headbutt")
		{
			if (entities[0].y > nauty.y+220)
			{
				nauty.eyoff++;
			}
			if (entities[0].y > nauty.y+300)
			{
				nauty.eyoff++;
			}
			if (entities[0].y > nauty.y+380)
			{
				nauty.eyoff++;
			}
			
			if (entities[0].y < nauty.y+200)
			{
				nauty.eyoff--
			}
			if (entities[0].y < nauty.y+120)
			{
				nauty.eyoff--
			}
			if (entities[0].y < nauty.y+40)
			{
				nauty.eyoff--
			}
		}
		if (nauty.dir2 == "eat")
		{
			if (entities[0].y > nauty.y+220)
			{
				nauty.eyoff+=2;
			}
			if (entities[0].y < nauty.y+200)
			{
				nauty.eyoff-=2;
			}
			g_rumble = -1;
		}
		else if (nauty.dir2 == "headbutt")
		{
			nauty.exoff = SuperHeadButtFunct((nauty.hstart-nauty.counter)/nauty.hstart);

			if ((nauty.hstart-nauty.counter)/nauty.hstart > 0.5 && (nauty.hstart-nauty.counter)/nauty.hstart<0.75)
			{
				g_rumble = 3-12*((nauty.hstart-nauty.counter)/nauty.hstart-0.5);

			}
			else
				g_rumble = -1;
			if (nauty.counter == Math.floor(nauty.hstart/2))
			{
				PlaySound(130,true);
			}

		}
		else
		{
			g_rumble = -1;
		}
		nauty.counter--;
		nauty.fc++;

		if (entities[0].hp > 0)
		{
			if (naut2.run == true && naut2.bx < naut2.stagex*16-naut2.width*1.5-16)
			{
				nauty.bx+=nauty.vx;
				nauty.vx+=0.125;
				if (nauty.vx > 6)
					nauty.vx = 6;
				if (entities[0].x > naut2.x+naut2.width)
					nauty.vx+=0.15/2;
	
				if (naut2.last_stomp < naut2.x-naut2.width/2)
				{
					naut2.last_stomp = naut2.x;
					PlaySound(81,true);
				}
	
			}
			else if (naut2.run == true && naut2.bx < naut2.stagex*16)
			{
				nauty.bx+=nauty.vx;
				nauty.vx-=0.140;
				if (nauty.vx < 0)
				{
					naut2.run = false;
					nauty.vx = 0;
				}
			}
		}
		
		if (nauty.dir2 != "eat_warmup" && nauty.dir2 != "eat" && nauty.dir2 != "flame")
		{
		}
		nauty.x = nauty.bx +nauty.exoff;
		nauty.y = nauty.by +nauty.eyoff;
		nauty.ny = 1*Math.cos(nauty.fc/3)-2;//in mapy
		nauty.hy = 1*Math.sin(nauty.fc/3);//in mapy
		nauty.my = (2+eat_camera*2)*Math.sin(nauty.fc/3);//in mapy		
		nauty.mx = 2+(eat_camera)*Math.sin(nauty.fc/3);//in mapy		
		nauty.hx = 2;//in mapy
	}
}

function SuperHeadButtFunct(num)
{
	if (num < 0.33333)
		return 40*(Math.sin(-3*num*3.14159/2));
	else if (num < 0.5)
		return 20*(3*Math.pow(6*(num-0.33333333),8)-2);
	else if (num < 0.6666666)
		return 20*(1);
	return 20*(0.5+0.5*Math.sin(3.14159/2+3*(num-0.666666)*3.14159));


}


function EatThePlayer()
{
	if (!(oblit_shield > 0))
	{
		entities[0].hp = 0;
		eat_camera = 1;
		StopAllMusics();
		PlaySound(66);

		for (e=1;e<max_weapons_1;e++)
		{
			entities[0]["la"+e] = GetPersonIDLayer(entities[0]["id"+e]);
			SetPersonIDLayer(entities[0]["id"+e], 0);
		}
		if (sounds[32].isPlaying())
		{
			sounds[32].stop();
			sounds[32].setPosition(0);
		}
		if (sounds[91].isPlaying())
		{
			sounds[91].stop();
			sounds[91].setPosition(0);
		}
	}
}


var g_naut_override = 0;
function DrawSupernautHead()
{
	if (g_supernaut_active == 1 || g_naut_override == 1)
		var nauty = naut1;
	else if (g_supernaut_active == 2|| g_naut_override == 2)
		var nauty = naut2;
	else
		var nauty = naut1;
	
	if (g_current_level > 16)
	{
		naut_headg.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	}
	else if (g_supernaut_active == 1 || g_naut_override == 1)
	{
	naut_head_bloodi.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	naut_headi.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	}
	else if (g_supernaut_active == 2 || g_naut_override == 2)
	{
	naut2_head_bloodi.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	naut2_headi.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	
	}
}

function DrawSupernautNeck()
{
	if (g_supernaut_active == 1|| g_naut_override == 1)
		var nauty = naut1;
	else if (g_supernaut_active == 2|| g_naut_override == 2)
		var nauty = naut2;
	else
		var nauty = naut1;
	if (g_current_level > 16)
	{
		naut_neck_bottomg.blit(MapToScreenX(1, nauty.x+nauty.nx), MapToScreenY(1, nauty.y+nauty.ny));
	}
	else if (g_supernaut_active == 1 || g_naut_override == 1)
	{
		naut_neck_bottom_bloodi.blit(MapToScreenX(1, nauty.x+nauty.nx), MapToScreenY(1, nauty.y+nauty.ny));
		naut_neck_bottomi.blit(MapToScreenX(1, nauty.x+nauty.nx), MapToScreenY(1, nauty.y+nauty.ny));
	}
	else if (g_supernaut_active == 2 || g_naut_override == 2)
	{
		naut2_neck_top_bloodi.blit(MapToScreenX(1, nauty.x+nauty.nx-80), MapToScreenY(1, nauty.y+nauty.ny));
		naut2_neck_topi.blit(MapToScreenX(1, nauty.x+nauty.nx-80), MapToScreenY(1, nauty.y+nauty.ny));
		naut2_neck_top2i.blit(MapToScreenX(1, nauty.x+nauty.nx-80-16), MapToScreenY(1, nauty.y+nauty.ny-96));
	
	}
}
function DrawSupernautMouth()
{
	if (g_supernaut_active == 1|| g_naut_override == 1)
		var nauty = naut1;
	else if (g_supernaut_active == 2|| g_naut_override == 2)
		var nauty = naut2;
	else
		var nauty = naut1;

	if (g_current_level > 16)
	{
		if (nauty.openmouth == 0)
		{
			naut_mouth_1g.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_3g.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	
		}
		else
		{
			naut_mouth_2g.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_3g.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	//		naut_mouth_mask_2B.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
		}
	}
	else if (g_supernaut_active == 1 || g_naut_override == 1)
	{
		if (nauty.openmouth == 0)
		{
			naut_mouth_blood_1i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_1i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_3i.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	
		}
		else
		{
			if (nauty.dir2 == "wavebeam" || nauty.dir2 == "wavebeam_warmup")
			{
				naut_wavebeam[nauty.frame].blit(MapToScreenX(2,nauty.x+nauty.mx)+g_superwboffx, MapToScreenY(2,nauty.y+nauty.my)+g_superwboffy);
				naut_wavebeam2[nauty.frame].blit(MapToScreenX(2,nauty.x+nauty.mx)+g_superwboffx-720, 16+MapToScreenY(2,nauty.y+nauty.my)+g_superwboffy);
			}
	
			naut_mouth_blood_2i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_2i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut_mouth_3i.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	//		naut_mouth_mask_2B.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
		}
	}
	else if (g_supernaut_active == 2 || g_naut_override == 2)
	{
		if (nauty.openmouth == 0)
		{
			naut2_mouth_blood_1i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut2_mouth_1i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut2_mouth_3i.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	
		}
		else
		{
			if (nauty.dir2 == "wavebeam" || nauty.dir2 == "wavebeam_warmup")
			{
				naut2_wavebeam[nauty.frame].blit(MapToScreenX(2,nauty.x+nauty.mx+80)+g_superwboffx, MapToScreenY(2,nauty.y+nauty.my)+g_superwboffy);
				naut_wavebeam2[nauty.frame].blit(MapToScreenX(2,nauty.x+nauty.mx+80)+g_superwboffx-720+naut_wavebeam2[nauty.frame].width+80, 16+MapToScreenY(2,nauty.y+nauty.my)+g_superwboffy);
			}
	
			naut2_mouth_blood_2i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut2_mouth_2i.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
			naut2_mouth_3i.blit(MapToScreenX(2,nauty.x+nauty.hx), MapToScreenY(2,nauty.y+nauty.hy));
	//		naut_mouth_mask_2B.blit(MapToScreenX(2,nauty.x+nauty.mx), MapToScreenY(2,nauty.y+nauty.my));
		}
	}
}

function StartSupernaut1()
{
	naut1.chompcount = 0;

	naut1.x = (79+18)*16;//in mapx (base x value)
	naut1.exoff = 0;
	naut1.eyoff = 0;
	naut1.idle_counter = 20;
	g_naut_override = 1;
	SetLayerRenderer(0, "DrawSupernautNeck();");
	SetLayerRenderer(1, "DrawSupernautMouth();DrawSupernautHead();");
	SetLayerRenderer(g_supernaut_head_layer, "");		

	var s_x = cam_xoff;
	var s_y = cam_yoff;

	var cfr = 40;
	var dx = (3*96-s_x)/cfr;
	var dy = (-64-s_y)/cfr;

	g_upate_input_suspend = true;
	CloseDoor("door1b_1c");

	for (kl=1;kl<cfr+1;kl++)
	{
		Queue_Command("cam_xoff = "+(s_x+dx*kl)+"; cam_yoff = "+(s_y+dy*kl)+";", kl);
	}

	Queue_Command("Start_Supernaut2();", kl+2);
}

function Start_Supernaut2()
{
	ResetNaut1();
	Queue_Command("Start_Supernaut3(5);", 15);
}

function Start_Supernaut3(counter)
{

	if (counter == 2)
		Queue_Command("PlaySound(72);	naut1.openmouth = 1;", 10);
	else if (counter == 0 && g_current_level < 17)
		MakeTransition(6);



//	naut1.x = (79+12)*16;//in mapx (base x value)
	naut1.y = 19*16;//in mapy (base y value)

	var cfr = 40;
	for (kl=1;kl<cfr+1;kl++)
	{
		Queue_Command("naut1.x = "+(naut1.x - (3*16*kl)/cfr)+";EndYell();", kl);
		Queue_Command("naut1.fc++; naut1.ny = 1*Math.cos(naut1.fc/3)-2;naut1.hy = 1*Math.sin(naut1.fc/3);naut1.my = 2*Math.sin(naut1.fc/3);",kl);
	}

	
	if (counter > 0)
		Queue_Command("Start_Supernaut3("+(counter-1)+");", 40);
	else
		Queue_Command("Start_SupernautEnd();", 40);
}

function EndYell()
{
	if (sounds[72].isPlaying() == false)
		naut1.openmouth = 0;
}

function Start_Supernaut4()
{
	
	naut1.x = (79+3)*16;//in mapx (base x value)
	naut1.y = 19*16;//in mapy (base y value)

	var cfr = 40;

	for (kl=1;kl<cfr+1;kl++)
	{
		Queue_Command("naut1.x = "+((79+3)*16 - (3*16*kl)/cfr)+";", kl);
		Queue_Command("naut1.fc++; naut1.ny = 1*Math.cos(naut1.fc/3)-2;naut1.hy = 1*Math.sin(naut1.fc/3);naut1.my = 2*Math.sin(naut1.fc/3);",kl);
	}

	Queue_Command("SetupSupernautDrawing();	SetLayerRenderer(1, \"\");", 35);
	for (j=41;j<46;j++)
		Queue_Command("naut1.fc++; naut1.ny = 1*Math.cos(naut1.fc/3)-2;naut1.hy = 1*Math.sin(naut1.fc/3);naut1.my = 2*Math.sin(naut1.fc/3);",j);


	Queue_Command("Start_SupernautEnd();", 45);
}

function Start_SupernautEnd()
{
	SetLayerRenderer(0, "DrawSupernautNeck();");
	SetLayerRenderer(g_supernaut_head_layer, "DrawSupernautMouth();DrawSupernautHead();");
	SetLayerRenderer(1, "");		

	var s_x = cam_xoff;

	var cfr = 20;
	var dx = (96-s_x)/cfr;

	g_upate_input_suspend = true;
	CloseDoor("door1b_1c");

	for (kl=21;kl<21+cfr;kl++)
	{
		Queue_Command("cam_xoff = "+(s_x+dx*(kl-20))+";", kl);
	}

	Queue_Command("g_supernaut_active = 1;	g_naut_override = 0;", 22+cfr);
	Queue_Command("g_upate_input_suspend = false;", 23+cfr);
	for (j=1;j<23+cfr;j++)
		Queue_Command("naut1.fc++; naut1.ny = 1*Math.cos(naut1.fc/3)-2;naut1.hy = 1*Math.sin(naut1.fc/3);naut1.my = 2*Math.sin(naut1.fc/3);",j);

	naut1.fc2= -314/2;
	naut1.bx = naut1.x;
	naut1.by = naut1.y;
}





function Queue_Command(string, frame)
{
	if (frame > 45)
	{
		string = "Queue_Command(\""+string+"\","+(frame-45)+");";
		Queue_Command(string, 45);
	
	}
	else
	{
	script_commands[(g_frames+frame)%max_scripts_commands] += string;
	}
}	

function IsCommandQueueEmpty()
{
	for (is=0;is<max_scripts_commands;is++)
	{
		if (script_commands[is] != "")
			return false;
	}
	return true;
}


function DoScript(string)
{
	eval(string);
}

function PlayerInEatRange()
{
	if (g_supernaut_active == 1)
	{
		var ntx = naut1.bx+48-48;
		var nty = naut1.by+48;
		if (entities[0].x > ntx)
		{
			if (entities[0].y >nty)
			{
				return true;
			}
		}
	}
	else if (g_supernaut_active ==2)
	{
		var ntx = naut2.bx+naut2.width-8;
		var nty = naut2.by+naut2.height-128;
		if (entities[0].x < ntx)
		{
			if (entities[0].y >nty)
			{
				return true;
			}
		}
	}
	return false;
}

function ResetNaut1()
{
naut_head = LoadSurface("supernaut/supernaut_head_1.png");
naut_head_mask = LoadSurface("supernaut/supernaut_head_mask_1.png");
naut_head_blood = LoadSurface("supernaut/supernaut_head_blood_1.png");
naut_mouth_1 = LoadSurface("supernaut/supernaut_mouth_1.png");
naut_mouth_mask_1 = LoadSurface("supernaut/supernaut_mouth_mask_1.png");
naut_mouth_blood_1 = LoadSurface("supernaut/supernaut_mouth_blood_1.png");
naut_mouth_2 = LoadSurface("supernaut/supernaut_mouth_2.png");
naut_mouth_mask_2 = LoadSurface("supernaut/supernaut_mouth_mask_2.png");
naut_mouth_blood_2 = LoadSurface("supernaut/supernaut_mouth_blood_2.png");
naut_mouth_3 = LoadSurface("supernaut/supernaut_mouth_3.png");
naut_neck_bottom = LoadSurface("supernaut/supernaut_neck_bottom_1.png");
naut_neck_bottom_mask = LoadSurface("supernaut/supernaut_neck_bottom_mask_1.png");
naut_neck_bottom_blood = LoadSurface("supernaut/supernaut_neck_bottom_blood_1.png");
naut_neck_top = LoadSurface("supernaut/supernaut_neck_top_1.png");
naut_neck_top_mask = LoadSurface("supernaut/supernaut_neck_top_mask_1.png");
naut_neck_top_blood = LoadSurface("supernaut/supernaut_neck_top_blood_1.png");


naut_headi = LoadImage("supernaut/supernaut_head_1.png");
naut_head_bloodi = LoadImage("supernaut/supernaut_head_blood_1.png");
naut_mouth_1i = LoadImage("supernaut/supernaut_mouth_1.png");
naut_mouth_blood_1i = LoadImage("supernaut/supernaut_mouth_blood_1.png");
naut_mouth_2i = LoadImage("supernaut/supernaut_mouth_2.png");
naut_mouth_blood_2i = LoadImage("supernaut/supernaut_mouth_blood_2.png");
naut_mouth_3i = LoadImage("supernaut/supernaut_mouth_3.png");
naut_neck_bottomi = LoadImage("supernaut/supernaut_neck_bottom_1.png");
naut_neck_bottom_bloodi = LoadImage("supernaut/supernaut_neck_bottom_blood_1.png");
naut_neck_topi = LoadImage("supernaut/supernaut_neck_top_1.png");
naut_neck_top_bloodi = LoadImage("supernaut/supernaut_neck_top_blood_1.png");


for (i=0;i<max_head_parts;i++)
	naut1.headstates[i] = 0;
for (i=0;i<max_neck_parts;i++)
	naut1.neck_bottomstates[i] = 0;
for (i=0;i<max_mouth_parts;i++)
	naut1.mouthstates[i] = 0;
naut1.maxhp = 105000;
naut1.hp1 = 105000;
naut1.hp2 = 1500000;
naut1.hp3 = 500000;

naut1.maxhp = 70000;
naut1.hp1 = 70000;
naut1.hp2 = 70000;
naut1.hp3 = 70000;
naut1.ptop_count=0;


eat_camera = 0;
}



function ResetNaut2()
{
naut2_head = LoadSurface("supernaut2/supernaut2_head_1.png");
naut2_head_mask = LoadSurface("supernaut2/supernaut2_head_mask_1.png");
naut2_head_blood = LoadSurface("supernaut2/supernaut2_head_blood_1.png");
naut2_mouth_1 = LoadSurface("supernaut2/supernaut2_mouth_1.png");
naut2_mouth_mask_1 = LoadSurface("supernaut2/supernaut2_mouth_mask_1.png");
naut2_mouth_blood_1 = LoadSurface("supernaut2/supernaut2_mouth_blood_1.png");
naut2_mouth_2 = LoadSurface("supernaut2/supernaut2_mouth_2.png");
naut2_mouth_mask_2 = LoadSurface("supernaut2/supernaut2_mouth_mask_2.png");
naut2_mouth_blood_2 = LoadSurface("supernaut2/supernaut2_mouth_blood_2.png");
naut2_mouth_3 = LoadSurface("supernaut2/supernaut2_mouth_3.png");
naut2_neck_top = LoadSurface("supernaut2/supernaut2_neck_top_1.png");
naut2_neck_top_mask = LoadSurface("supernaut2/supernaut2_neck_top_mask_1.png");
naut2_neck_top_blood = LoadSurface("supernaut2/supernaut2_neck_top_blood_1.png");
naut2_mouth_mask_2B = LoadSurface("supernaut2/supernaut2_mouth_mask_2B.png");
naut2_headi = LoadImage("supernaut2/supernaut2_head_1.png");
naut2_head_bloodi = LoadImage("supernaut2/supernaut2_head_blood_1.png");
naut2_mouth_1i = LoadImage("supernaut2/supernaut2_mouth_1.png");
naut2_mouth_blood_1i = LoadImage("supernaut2/supernaut2_mouth_blood_1.png");
naut2_mouth_2i = LoadImage("supernaut2/supernaut2_mouth_2.png");
naut2_mouth_blood_2i = LoadImage("supernaut2/supernaut2_mouth_blood_2.png");
naut2_mouth_3i = LoadImage("supernaut2/supernaut2_mouth_3.png");
naut2_neck_topi = LoadImage("supernaut2/supernaut2_neck_top_1.png");
naut2_neck_top2i = LoadImage("supernaut2/supernaut2_neck_top_2.png");
naut2_neck_top_bloodi = LoadImage("supernaut2/supernaut2_neck_top_blood_1.png");


naut2.bx = 41*16;//in mapx (base x value)
naut2.by = 24*16;//in mapy (base y value)
naut2.x = 41*16;//in mapx
naut2.y = 5*16;//in mapy
naut2.exoff = 0;
naut2.eyoff = 0;
naut2.fc = 0;
naut2.fc2 = Math.floor(300*3.14159/2)+70;
naut2.nx = 2;//in mapx
naut2.ny = 0;//in mapy
naut2.hx = 0;//in mapx
naut2.hy = 0;//in mapy
naut2.mx = 0;//in mapx
naut2.my = 0;//in mapy
naut2.dir = 1;//facing east
naut2.dir2 = "";//facing west
naut2.frame = 0;//facing west
naut2.width = naut2_head.width;//in mapx
naut2.height = naut2_head.height;//in mapy
naut2.chompcount = 0;
naut2.attack_counter = 0;
naut2.hbc = 1;

naut2.phasey_count =0;

naut2.idle_counter = 0;
naut2.maxhp = 105000;
naut2.hp1 = 105000;
naut2.hp2 = 1500000;
naut2.hp3 = 500000;

naut2.maxhp = 70000;
naut2.hp1 = 70000;
naut2.hp2 = 70000;
naut2.hp3 = 70000;

naut2.openmouth = 0;
naut2.counter = 0;
for (i=0;i<max_head_parts;i++)
	naut2.headstates[i] = 0;
for (i=0;i<max_neck_parts;i++)
	naut2.neck_topstates[i] = 0;
for (i=0;i<max_mouth_parts;i++)
	naut2.mouthstates[i] = 0;
	
eat_camera = 0;
naut2.vx = 0;
naut2.run = true;
naut2.last_stomp = 0;
naut2.stage=1;
}

function Supernaut2Start1()
{
	g_upate_input_suspend = true;
	g_isrunning = false
	entities[0].vx=0;
	var tw = GetTileWidth();
	var th = GetTileHeight();

	
		for (zi=46;zi<56;zi++)
		{
			for (zj=23;zj<37;zj++)
			{
				if (GetTile(zi,zj,0) == 1 || GetTile(zi,zj,0) == 2)
				{
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 1+Math.floor(Math.random()*16));
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 17+Math.floor(Math.random()*16));
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 33+Math.floor(Math.random()*16));
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 49+Math.floor(Math.random()*16));
				}
			}
		}
		Queue_Command("Supernaut2Start2();", 32);
}

function Supernaut2Start2()
{
	g_naut_override = 2;
	SetLayerRenderer(0, "DrawSupernautNeck();");
	SetLayerRenderer(g_supernaut_head_layer, "DrawSupernautMouth();DrawSupernautHead();");		
	for (i=1;i<33;i++)
	{
		Queue_Command("cam_yoff = "+(-1*i*2)+";", i);
	}
	
	for (i=36;i<63;i++)
	{
		for (j=0;j<38;j++)
		{
			SetTile(i,j,2,0);
		}
	}

	for (i=36;i<63;i++)
	{
		for (j=0;j<34;j++)
		{
			SetTile(i,j,1,0);
		}
	}

	for (i=46;i<56;i++)
	{
		for (j=23;j<37;j++)
		{
			SetTile(i,j,0,0);
		}
	}
	Queue_Command("Supernaut2Start3a();", 50);
	
}
function Supernaut2Start3a()
{
	PlaySound(81,true);
	Queue_Command("Supernaut2Start3b();", 32);
}
function Supernaut2Start3b()
{
	PlaySound(81,true);
	Queue_Command("Supernaut2Start3c();", 24);
}
function Supernaut2Start3c()
{
	PlaySound(81,true);
	Queue_Command("Supernaut2Start3();", 24);
}
function Supernaut2Start3()
{
	PlaySound(72);
	naut2.openmouth = 1;
	Queue_Command("Supernaut2Start4();", 24);
}

function Supernaut2Start4()
{
	Queue_Command("MakeTransition(7);", 64);

	ammo_array[10].curammo+=3;
	if (ammo_array[10].curammo > ammo_array[10].maxammo)
		ammo_array[10].curammo = ammo_array[10].maxammo;

naut2.bx = 41*16-128-32;//in mapx (base x value)
naut2.by = 24*16-64-16;//in mapy (base y value)

naut2.x = 41*16-128-32;//in mapx (base x value)
naut2.y = 24*16-64-16;//in mapy (base y value)
//naut2.x = 41*16-32;//in mapx
//naut2.y = 5*16-23;//in mapy
		//nauty.x = nauty.bx - 48*Math.sin(nauty.fc2/100)-48+nauty.exoff;
naut2.fc= 0;
	for (s=0;s<128;s++)
	{
		if (s%2==0)
			Queue_Command("naut2.bx+=1;naut2.by+=1; naut2.x+=1; naut2.y+=1;", 1+s);
		else
			Queue_Command("naut2.bx+=1;naut2.x+=1;", 1+s);
		Queue_Command("naut2.fc++; naut2.ny = 1*Math.cos(naut2.fc/3)-2;naut2.hy = 1*Math.sin(naut2.fc/3);naut2.my = 2*Math.sin(naut2.fc/3);",1+s);
	}


	Queue_Command("Supernaut2Start5();", s+8);
}

function Supernaut2Start5()
{
	g_naut_override = 0;
	g_supernaut_active = 2;
	g_upate_input_suspend = false;
		naut2.openmouth = 0;	
	naut2.run = true;
	naut2.last_stomp = naut2.x;
	naut2.stage=1;
	naut2.stagex = g_stage1_x;
}

function Supernaut2StageBreak(stage)
{
	PlaySound(72);
	Queue_Command("Supernaut2StageBreak_b("+stage+");", 48);
}

function Supernaut2StageBreak_b(stage)
{
	var tw = GetTileWidth();
	var th = GetTileHeight();

	var start_x = 220;
	var end_x = 242;
	var start_y = 9;
	var end_y = 38;

	if (stage == 1)
	{
		start_x = 220;
		end_x = 242;
		start_y = 9;
		end_y = 38;
	}
	else if (stage == 2)
	{
		start_x = 380;
		end_x = 397;
		start_y = 9;
		end_y = 38;
	}	
	var chance = 0.3333333;
	
		for (zi=start_x;zi<end_x;zi++)
		{
			for (zj=start_y;zj<end_y;zj++)
			{
				if (Math.random()<chance)
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 1+Math.floor(Math.random()*16));
				if (Math.random()<chance)
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 17+Math.floor(Math.random()*16));
				if (Math.random()<chance)
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 33+Math.floor(Math.random()*16));
				if (Math.random()<chance)
					Queue_Command("SpawnExplosion("+(zi*tw+GetTileWidth()*Math.random())+","+(zj*th+GetTileHeight()*Math.random())+", 0, 0, "+(1*(Math.random()*0.75+0.75))+");", 49+Math.floor(Math.random()*16));
			}
		}
		Queue_Command("Supernaut2Break2("+stage+");", 48);
}

function Supernaut2Break2(stage)
{
	naut2.phasey_count =0;

	var start_x = 220;
	var end_x = 242;
	var start_y = 9;
	var end_y = 38;

	if (stage == 1)
	{
		start_x = 220;
		end_x = 242;
		start_y = 9;
		end_y = 38;
	}
	else if (stage == 2)
	{
		start_x = 380;
		end_x = 400;
		start_y = 9;
		end_y = 38;
	}


	for (zi=start_x;zi<end_x;zi++)
	{
		for (zj=start_y;zj<end_y-1;zj++)
		{
			SetTile(zi,zj,2,0);
			SetTile(zi,zj,0,279);
			SetTile(zi,zj,3,0);
			SetTile(zi,zj,4,0);
			SetTile(zi,zj,5,0);
		}
	}
	if (stage==1)
	{
		SetTile(223,33,1,0);
		SetTile(225,27,1,0);
	}
	if (stage==2)
	{
		SetTile(382,33,1,0);
		SetTile(383,26,1,0);
		SetTile(387,28,1,0);
	}
	for (zi=start_x;zi<end_x;zi++)
	{
		SetTile(zi,end_y-1,2,0);
		SetTile(zi,end_y-1,0,2);
	}
	if (stage == 1)
		Queue_Command("naut2.run = true;naut2.stage = 2;naut2.stagex = g_stage2_x;", 32);
	if (stage == 2)
		Queue_Command("naut2.run = true;naut2.stage = 3;naut2.stagex = g_stage3_x;", 32);
}

function GetSword(numy)
{
	if (numy == 2 && g_sword_gotten == 0)
		return;
	if (numy == 2 && g_sword_gotten == 1 && g_wave_num < 7)
		return;

	if (numy==undefined)
	{
		SetTile(379,35,1, 1357);
		SetTile(380,35,1, 1358);
		SetTile(379,36,1, 1362);
		SetTile(380,36,1, 1363);
	}
	else if (numy == 2)
	{
		//blah
		if (weap_possess[11] == 0)
		{
		SetTile(127,75,2, 1357);
		SetTile(128,75,2, 1358);
		SetTile(127,76,2, 1362);
		SetTile(128,76,2, 1363);
		}
	}
	
	if (weap_possess[11] == 0)
	{
		weap_possess[11] = 1;
		AddAmmoHudText(2, 1,"Obtained Sword!");
		AddAmmoHudText(2, 1,"Press "+inputs[CKEY_8].toUpperCase()+" twice to select.");

		cur_weap = 13;
		g_sword_cc = 30;
	}
	else
		cur_weap = 13;
		
	SaveWeapPossess();
}