#include ww2x\_drm;

init()
{
	level.wwx_turretplanttime = [[level.drm_cvardef]]("wwx_turret_plant_time", 3, 0, 30, "int");
	level.wwx_turretpicktime	= [[level.drm_cvardef]]("wwx_turret_pick_time", 2, 0, 30, "int");
	level.wwx_disablemgpointer		= [[level.drm_cvardef]]("wwx_disablemgpointer", 0, 0, 1, "int");

	if(level.wwx_turretpicktime)
		level.wwx_turretpickingmessage= &"TURRETS_PICKING_UP";
	if(level.wwx_turretplanttime)
		level.wwx_turretplacingmessage= &"TURRETS_PLACING";

	// Delete all MG42s?
	level.wwx_mg42disable		= [[level.drm_cvardef]]("wwx_mg42_disable", 0, 0, 1, "int");
	// Delete all 30Cals?
	level.wwx_30caldisable		= [[level.drm_cvardef]]("wwx_30cal_disable", 0, 0, 1, "int");

	// Overheating turrets?
	//level.wwx_turretoverheat		= [[level.drm_cvardef]]("wwx_turret_overheat",10,0,9999,"int");
	//level.wwx_turretcooldown		= [[level.drm_cvardef]]("wwx_turret_cooldown",5,0,9999,"int");

	/*if(level.wwx_turretoverheat)
	{
		level.wwx_turretoverheatmessage= &"TURRETS_TEMPERATURE";
		level.wwx_turretoverheatmessage2= &"TURRETS_OVERHEATED1";
		level.wwx_overheatfx = loadfx ("fx/smoke/thin_black_smoke_S.efx");
	}*/


	// Precache
	if(!isdefined(game["gamestarted"]))
	{
		if(level.wwx_turretpicktime)
			precacheString( level.wwx_turretpickingmessage );
		if(level.wwx_turretplanttime)
			precacheString( level.wwx_turretplacingmessage );

		// MG42
		precacheModel("xmodel/weapon_mg42");
		precacheItem("mg42_bipod_duck_mp");
		precacheItem("mg42_bipod_prone_mp");
		precacheItem("mg42_bipod_stand_mp");
		precacheTurret("mg42_bipod_duck_mp");
		precacheTurret("mg42_bipod_prone_mp");
		precacheTurret("mg42_bipod_stand_mp");
		
		// 30Cal
		precacheModel("xmodel/weapon_30cal");
		precacheItem ("30cal_duck_mp");
		precacheItem("30cal_prone_mp");
		precacheItem("30cal_stand_mp");	
		precacheTurret ("30cal_duck_mp");
		precacheTurret("30cal_prone_mp");
		precacheTurret("30cal_stand_mp");
		
		precacheShader ("objpoint_star");
		precacheShader ("objpoint_question");
		precacheMenu ("clientcmd");
	      precacheMenu("stand");
	      precacheMenu("prone");
	      precacheMenu("crouch");

		/*if(level.wwx_turretoverheat)
		{
			precacheString( level.wwx_turretoverheatmessage );
			precacheString( level.wwx_turretoverheatmessage2 );
			precacheString (&"TURRETS_OVERHEATED2");
			precacheShader("gfx/hud/hud@health_back.tga");
			precacheShader("gfx/hud/hud@health_bar.tga");
		}*/
		
	}

	level thread turretStuff();
}

/*CleanupKilled(sMeansOfDeath)
{
	RemoveOverheatHud();
}*/

RunOnSpawn()
{
       // RemoveOverheatHud();
        self.wwx_usingturret = undefined;
	self thread checkDeployableTurret();
}

turretStuff()
{
	level endon("wwx_killthreads");

	// Wait a servercycle to make sure unwanted entities has been removed
	wait .05;

	// Count all turrets
	allent = getentarray();	// Get all entities

	numturrets=0;

	for(i=0;i<allent.size;i++)	// Loop through them
	{
		if(isdefined(allent[i]))		// Exist?
		{
			if(isdefined(allent[i].weaponinfo))		// Weapon?
			{
				switch(allent[i].weaponinfo)
				{
					case "mg42_bipod_prone_mp":
					case "mg42_bipod_stand_mp":
					case "mg42_bipod_duck_mp":
						if(level.wwx_mg42disable)	// Delete MG42s?
							allent[i] delete();
						else
 							numturrets++;
						break;
					case "30cal_prone_mp":
					case "30cal_stand_mp":
						if(level.wwx_30caldisable)	// Delete 30Cals?
							allent[i] delete();
						else
 							numturrets++;
						break;

					default:
						break;
				}
			}
		}
	}

	if(level.wwx_mg42disable || level.wwx_30caldisable)
		wait 0.05;	// Allow changes to happen



/*	// Build turret array
	level.wwx_turrets = [];

	allent = getentarray();	// Get all entities

	for(i=0;i<allent.size;i++)	// Loop through them
	{
		if(isdefined(allent[i]))		// Exist?
		{
			if(isdefined(allent[i].weaponinfo))		// Weapon?
			{
				switch(allent[i].weaponinfo)
				{
					case "mg42_bipod_stand_mp":
					case "mg42_bipod_duck_mp":
					case "mg42_bipod_prone_mp":
					case "30cal_prone_mp":
					case "30cal_stand_mp":
						level.wwx_turrets[level.wwx_turrets.size]["turret"] = allent[i];
						level.wwx_turrets[level.wwx_turrets.size - 1]["type"] = "misc_turret";
						level.wwx_turrets[level.wwx_turrets.size - 1]["original_position"] = allent[i].origin;
						level.wwx_turrets[level.wwx_turrets.size - 1]["original_angles"]	= allent[i].angles;
						level.wwx_turrets[level.wwx_turrets.size - 1]["original_weaponinfo"]=allent[i].weaponinfo;
						level.wwx_turrets[level.wwx_turrets.size - 1]["dropped"] = undefined;
						level.wwx_turrets[level.wwx_turrets.size - 1]["carried"] = undefined;
						level.wwx_turrets[level.wwx_turrets.size - 1]["heat"] = 0;
						break;

					default:
						break;
				}
			}
		}
	}

	// Get dropped turrets
	mgs=getEntArray("dropped_turret","targetname");
	for (i=0;i<mgs.size;i++)
	{
		if(isdefined(mgs[i]))
		{
			level.wwx_turrets[level.wwx_turrets.size]["turret"] = mgs[i];
			level.wwx_turrets[level.wwx_turrets.size - 1]["type"] = "misc_turret";
			level.wwx_turrets[level.wwx_turrets.size - 1]["original_position"] = mgs[i].origin;
			level.wwx_turrets[level.wwx_turrets.size - 1]["original_angles"]	= mgs[i].angles;
			level.wwx_turrets[level.wwx_turrets.size - 1]["original_weaponinfo"]= undefined;
			level.wwx_turrets[level.wwx_turrets.size - 1]["dropped"] = true;
			level.wwx_turrets[level.wwx_turrets.size - 1]["carried"] = undefined;
			level.wwx_turrets[level.wwx_turrets.size - 1]["heat"] = 0;
		}
	}

	// Start turret think threads
	for(i=0;i<level.wwx_turrets.size;i++)
		if( !isdefined(level.wwx_turrets[i]["dropped"]) && !isdefined(level.wwx_turrets[i]["carried"]) )
			level.wwx_turrets[i]["turret"] thread turret_think(i);*/
}

/*turret_think(num, carrier)
{
	level endon("wwx_killthreads");
	self endon("wwx_killthreads");

	dist = 0;
	oldammo = 0;
	cooldown = 0;
	oddeven = 0;

	for(;;)
	{
		globalused = false;
		fired = false;

		// No need to run if turret is being carried (Thread should be killed, but just in case)
		if(isdefined(level.wwx_turrets[num]["carried"]))
		{
			wait 0.5;
			continue;
		}
			
		// Every other run flag
		if(oddeven)
			oddeven = 0;
		else
			oddeven = 1;
		players = getentarray("player", "classname");

		// Loop through all the players
		for(i = 0;i < players.size;i++)
		{
                    if(isdefined(carrier) && (carrier != players[i]))
                      continue;

			used = false;
			touched = false;

			player = players[i];

			// Does player exist, alive and playing?
			if(isdefined(player) && isAlive(player) && player.sessionstate == "playing")
			{
				touched = player istouching(self);

				// Within distance?
				dist = distance(self.origin, player.origin);
                                if(isdefined(carrier)) used = true;
				else if(isdefined(dist) && dist < 65 && dist > 49 && !touched)
				{
					cw = player getCurrentWeapon();
					// If curretweapon is "none" then we are for sure using the turret
					if(cw == "none")
						used = true;
					else	// However sometimes it is not set to "none" and we need more checking
					{
						// Is the player fireing?
						if(level.wwx_turretoverheat)
						{
							if(player attackButtonPressed())
							{
								// Which slot are we checking?
								slot = "none";
								if(cw == player getWeaponSlotWeapon("primary"))
									slot = "primary";
								if(cw == player getWeaponSlotWeapon("primaryb"))
									slot = "primaryb";
								if(slot != "none")
								{
									// Get ammo
									ammo = player getWeaponSlotAmmo(slot);	

									if(oldammo)
									{
										// Is it unchanged?
										if(ammo == oldammo)
										{
											used = true;
										}
									}
									oldammo = ammo;
								}
							}
							else	// Have used this turret and is within distance and has not fired
							{
								if(isdefined(player.wwx_usingturret) && player.wwx_usingturret == num)
									used = true;
							}
						}
					}
				}

				if(used)
				{
					globalused = true;
					player.wwx_usingturret = num;

					// Is it being fired?
					if(level.wwx_turretoverheat)
					{
						if(player attackButtonPressed())
						{
							fired = true;
							oddeven = 1;
							// Is it overheated?
							level.wwx_turrets[num]["heat"]++;
							if(level.wwx_turrets[num]["heat"] > level.wwx_turretoverheat*5)
							{
								cooldown = level.wwx_turretcooldown*5;
								player iprintlnbold (&"TURRETS_OVERHEATED2");
								sMeansOfDeath = "MOD_EXPLOSIVE";
								iDFlags = 1;
								iDamage = level.wwx_turrets[num]["heat"] - level.wwx_turretoverheat*5;
								sWeapon = self.weaponinfo;
								vDir=(0,0,0);
								player thread [[level.callbackPlayerDamage]](self, self, iDamage, iDFlags, sMeansOfDeath, sWeapon, undefined, vDir, "none", 0);
							}
						}
						else
						{
							if(cooldown)
							{
								if(randomint(2))
									playfx(level.wwx_overheatfx,self.origin + (0,0,10));
								cooldown--;
							}
							else
							{
								if(oddeven && level.wwx_turrets[num]["heat"]) level.wwx_turrets[num]["heat"]--;
							}
						}
						// Show heatbar
						player UpdateOverheatHud(num, fired, oddeven);
					}
				}
				else
				{
					// Clear player flag if this turret has been used previously
					if(isdefined(player.wwx_usingturret) && player.wwx_usingturret == num)
					{
						player.wwx_usingturret = undefined;
						player RemoveOverheatHud();
					}
				}
			}
		}
		// Cool down even if noone is using it.
		if(!globalused && !fired)
		{
			if(cooldown)
			{
				if(randomint(2))
					playfx(level.wwx_overheatfx,self.origin + (0,0,10));
				cooldown--;
			}
			else
			{
				if(oddeven && level.wwx_turrets[num]["heat"]) level.wwx_turrets[num]["heat"]--;
			}
		}
		wait .2;
	}
}

UpdateOverheatHud(num, fired, oddeven)
{
	if(!oddeven) return;

	if(fired)
		time = 0.2;
	else
		time = 0.4;

	barsize = 200;
	y = 452;
	heat = level.wwx_turrets[num]["heat"];
	if(heat>level.wwx_turretoverheat*5)
	{
		heat = level.wwx_turretoverheat*5;
		message = level.wwx_turretoverheatmessage2; 
	}
	else
		message = level.wwx_turretoverheatmessage; 
	size = int(heat * barsize / (level.wwx_turretoverheat * 5) + 0.5);
	
	c = size / barsize;

	if(!size) size = 1;

	color = (1,1-c,1-c);
	if(!isdefined(self.wwx_overheatbarbackground))
	{
		// Background
		self.wwx_overheatbarbackground = newClientHudElem(self);				
		self.wwx_overheatbarbackground.alignX = "center";
		self.wwx_overheatbarbackground.alignY = "top";
		self.wwx_overheatbarbackground.x = 320;
		self.wwx_overheatbarbackground.y = y;
		self.wwx_overheatbarbackground setShader("gfx/hud/hud@health_back.tga", (barsize + 4), 11);			
	}
	if(!isdefined(self.wwx_overheatbar))
	{
		// Progress bar
		self.wwx_overheatbar = newClientHudElem(self);				
		self.wwx_overheatbar.alignX = "left";
		self.wwx_overheatbar.alignY = "top";
		self.wwx_overheatbar.x = (320 - (barsize / 2.0));
		self.wwx_overheatbar.y = y+1;
		self.wwx_overheatbar.color = color;
		self.wwx_overheatbar setShader("gfx/hud/hud@health_bar.tga", size, 9);
	}
	else
	{
		self.wwx_overheatbar.color = color;
		self.wwx_overheatbar scaleOverTime(time , size, 9);
	}

	if(!isdefined(self.wwx_overheatmessage))
	{
		self.wwx_overheatmessage = newClientHudElem( self );
		self.wwx_overheatmessage.alignX = "center";
		self.wwx_overheatmessage.alignY = "top";
		self.wwx_overheatmessage.x = 320;
		self.wwx_overheatmessage.y = y+1;
		self.wwx_overheatmessage.alpha = 1;
		self.wwx_overheatmessage.fontScale = 0.80;
	}
	self.wwx_overheatmessage setText( message );
}

RemoveOverheatHud()
{
	if(!level.wwx_turretoverheat)
		return;

	if(isdefined(self.wwx_overheatbarbackground))	self.wwx_overheatbarbackground destroy();
	if(isdefined(self.wwx_overheatbar))			self.wwx_overheatbar destroy();
	if(isdefined(self.wwx_overheatmessage))		self.wwx_overheatmessage destroy();
}*/

checkDeployableTurret()
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");

	self.turret_deployed = false;
	self thread checkBinoculars();
	self createTurretPointer();

       if(isdefined(self.turret_pointer.status))
	self thread changeTurretPointer("hidden");


	while(true)
	{
		wait 0.5;

		if(self.turret_deployed)
			continue;
			
		weapon = self getcurrentweapon();

		if((weapon != "30cal_mp") && (weapon != "mg42_mp"))
		{
                     if(isdefined(self.turret_pointer.status))
			self thread changeTurretPointer("hidden");
			continue;
		}

		if(isdefined(self.turret_pointer.status))
		self thread changeTurretPointer("neutral");

		if((self playerads() == 1.0) && (!self.using_binoculars))
		{
			wait 0.05;
			self ww2x\_wwx_utils::ExecClientCommand("toggleads");
			wait 0.05;

			self deployTurret(weapon);
		}
	}
}

deployTurret(weapon)
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");
	
	stance = self ww2x\_wwx_utils::GetStance(true);
	
	if(stance == 3)
		return;

	if(self getWeaponSlotWeapon ("primary") == weapon)
		slot = "primary";
	else
		slot = "primaryb";

	ammo = self getWeaponSlotAmmo(slot);
	
	if(!ammo)
	{
              if(isdefined(self.turret_pointer.status))
		self thread changeTurretPointer("undeployable");
		return;
	}
	
	player_angles	= self getplayerangles ();
	forward_angles = (0, player_angles[1], 0);
	offset = (18, 2, -27);
	position_view = self getEye() + (0, 0, offset[stance]);
	position_far = position_view + maps\mp\_utility::vectorScale (anglesToForward(player_angles), 30000);
	trace = bullettrace (position_view, position_far, false, undefined);
	position_center = trace["position"];

	position_around[0] = groundPos (position_center + maps\mp\_utility::vectorScale (anglesToForward(forward_angles), 2));
	position_around[1] = groundPos (position_center + maps\mp\_utility::vectorScale (anglesToForward(forward_angles + (0, 90, 0)), 8));
	position_around[2] = groundPos (position_center + maps\mp\_utility::vectorScale (anglesToForward(forward_angles + (0, 180, 0)), 2));
	position_around[3] = groundPos (position_center + maps\mp\_utility::vectorScale (anglesToForward(forward_angles + (0, 270, 0)), 8));
	
	dist = distance(position_view, position_center);

	higher = position_center[2];
	lower = higher;
	obstacle_turret = false;
	for (i = 0 ; i <= 3 ; i ++)
	{
		if(position_around[i][2] > higher)
			higher = position_around[i][2];
		if(position_around[i][2] < lower)
			lower = position_around[i][2];
		trace = bullettrace (position_view, position_around[i], false, undefined);
		obstacle_turret = obstacle_turret || (trace["fraction"] < 0.9);
	}
	max_height_turret = higher - lower;

	position_feet = self getOrigin();

	pod1 = position_around[1];
	pod2 = position_around[3];

	angles = vectorToAngles(pod2 - pod1);
	angle_pods = angles[0];

	turret_angles = forward_angles + (0, 0, angle_pods);
	position_turret = ((pod1[0] + pod2[0]) / 2, (pod1[1] + pod2[1]) / 2, (pod1[2] + pod2[2]) / 2 - 1);

	diff_height = maps\mp\_utility::abs (position_turret[2] - position_feet[2]);
	if (diff_height > 40)
	{
		stance_str = "stand";
		clearing = 20;
	}
	else if (diff_height < 15)
	{
		stance_str = "prone";
		clearing = 50;
	}
	else
	{
		stance_str = "duck";
		clearing = 20;
	}

	position_behind[0] = groundPos (position_feet + (0, 0, 15) + maps\mp\_utility::vectorScale (anglesToForward (forward_angles + (0, 135, 0)), clearing));
	position_behind[1] = groundPos (position_feet + (0, 0, 15) + maps\mp\_utility::vectorScale (anglesToForward (forward_angles + (0, 180, 0)), clearing));
	position_behind[2] = groundPos (position_feet + (0, 0, 15) + maps\mp\_utility::vectorScale (anglesToForward (forward_angles + (0, 225, 0)), clearing));

	higher = position_feet[2];
	lower = higher;
	obstacle_behind = false;
	for (i = 0 ; i <= 2 ; i ++)
	{
		if(position_behind[i][2] > higher)
			higher = position_behind[i][2];
		if(position_behind[i][2] < lower)
			lower = position_behind[i][2];
		trace = bullettrace (position_view, position_behind[i], false, undefined);
		obstacle_behind = obstacle_behind || (trace["fraction"] < 0.9);
	}
	max_height_behind = higher - lower;


	if((max_height_turret > 10) || (max_height_behind > 18) || obstacle_turret || obstacle_behind || (dist > 80) || (dist < 10))
	{
              if(isdefined(self.turret_pointer.status))
		self thread changeTurretPointer("undeployable");
		return;
	}

       if(isdefined(self.turret_pointer.status))
	self thread changeTurretPointer("deployable");

	self iprintlnbold (level.wwx_turretplacingmessage);
	self playsound ("weap_bar_reload_not_empty_npc");
	
	self disableWeapon();
	//self freezecontrols(true);
	wait level.wwx_turretplanttime;

	if(weapon == "30cal_mp")
	{
		turret_type = "30cal_" + stance_str + "_mp";
		turret_model = "xmodel/weapon_30cal";
	}
	else
	{
		turret_type = "mg42_bipod_" + stance_str + "_mp";
		turret_model = "xmodel/weapon_mg42";
	}

       if(isdefined(self.turret_pointer.status))
	self thread changeTurretPointer("hidden");
	
	turret = spawnTurret ("misc_turret", position_turret, turret_type);
	turret.angles = turret_angles;
	turret setmodel (turret_model);
	turret setleftarc (45);
	turret setrightarc (45);
 	turret settoparc (15);
	turret setbottomarc (15);
	turret.weaponinfo = turret_type;

	turret thread waitUntilRemove(self);

	self enableWeapon();
	self forceUse();
	//self freezecontrols(false);

	self.turret_deployed = true;

	wait 0.5;

	while(! self useButtonPressed())
	{
		if (!ammo)
			break;

		if(self attackButtonPressed())
		{
			ammo --;
			self setWeaponSlotAmmo(slot, ammo);
		}
		
		wait 0.05;
	}

	self disableWeapon();

	wait 0.5;
	
	self setplayerangles(player_angles);

	self notify ("end_deploy");

	self iprintlnbold (level.wwx_turretpickingmessage);
	self playsound ("weap_m1carbine_reload_not_empty_npc");
		
	//self freezecontrols(true);
	wait level.wwx_turretpicktime;

       if(isdefined(self.turret_pointer.status))
	self thread changeTurretPointer("neutral");
	//self freezecontrols(false);
	self enableWeapon();

	self.turret_deployed = false;
}

checkBinoculars()
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");

	self.using_binoculars = false;

	while(true)
	{
		self waittill ("binocular_enter");
		self.using_binoculars = true;
		self waittill ("binocular_exit");
		self.using_binoculars = false;
	}
}

groundPos(position)
{
	trace = bullettrace (position + (0, 0, 10), position + (0, 0, -10000), false, undefined);
	return (trace["position"]);
}

createTurretPointer()
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");

	if(isdefined(self.turret_pointer))
		self.turret_pointer destroy();

	self.turret_pointer = newClientHudElem(self);
	self.turret_pointer.x = 320;
	self.turret_pointer.y = 240;
	self.turret_pointer.alpha = 0;
	self.turret_pointer setshader ("objpoint_star", 32, 32);
	self.turret_pointer.status = "";
}

changeTurretPointer(status)
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");

	if(self.turret_pointer.status == status)
		return;
		
	switch(status)
	{
		case "deployable" :
			self.turret_pointer setshader ("objpoint_star", 48, 48);
			self.turret_pointer.x = 296;
			self.turret_pointer.y = 216;
			self.turret_pointer.alpha = 1;
                     if(level.wwx_disablemgpointer)self.turret_pointer.alpha = 0;
			break;
		case "neutral" :
			self.turret_pointer setshader ("objpoint_star", 32, 32);
			self.turret_pointer.x = 304;
			self.turret_pointer.y = 224;
			self.turret_pointer.alpha = 0.7;
                     if(level.wwx_disablemgpointer)self.turret_pointer.alpha = 0;
			break;
		case "undeployable" :
			self.turret_pointer setshader ("objpoint_question", 32, 32);
			self.turret_pointer.x = 304;
			self.turret_pointer.y = 224;
			self.turret_pointer.alpha = 1;
                     if(level.wwx_disablemgpointer)self.turret_pointer.alpha = 0;
			break;
		case "hidden" :
			self.turret_pointer.alpha = 0;
                     if(level.wwx_disablemgpointer)self.turret_pointer.alpha = 0;
			break;
		default :
			break;
	}
	self.turret_pointer.status = status;
}

forceUse()
{
	wait 0.05;
	self ww2x\_wwx_utils::ExecClientCommand("+activate");
	wait 0.05;
	self ww2x\_wwx_utils::ExecClientCommand("-activate");
}

leaveTurret()
{
	self endon("wwx_killthreads");
	self endon("disconnect");
	self endon("killed_player");

	if(isAlive(self) && (self.sessionstate == "playing") && self.turret_deployed)
	{
		self forceUse();
		while(self.turret_deployed)
			wait 0.2;
	}
}

waitUntilRemove(player)
{
	/*level.wwx_turrets[level.wwx_turrets.size]["turret"] = self;
	level.wwx_turrets[level.wwx_turrets.size - 1]["type"] = "misc_turret";
	level.wwx_turrets[level.wwx_turrets.size - 1]["original_position"] = self.origin;
	level.wwx_turrets[level.wwx_turrets.size - 1]["original_angles"]	= self.angles;
	level.wwx_turrets[level.wwx_turrets.size - 1]["original_weaponinfo"] = self.weaponinfo;
	level.wwx_turrets[level.wwx_turrets.size - 1]["dropped"] = undefined;
	level.wwx_turrets[level.wwx_turrets.size - 1]["carried"] = undefined;
	level.wwx_turrets[level.wwx_turrets.size - 1]["heat"] = 0;
	self thread turret_think (level.wwx_turrets.size - 1, player);*/

	player ww2x\_wwx_utils::waittill_multi("wwx_killthreads disconnect killed_player end_deploy");
	
	self notify ("wwx_killthreads");
	//level.wwx_turrets[level.wwx_turrets.size - 1] = undefined;
	//player RemoveOverheatHud ();

	wait 0.05;
	if(isdefined(self))
		self delete();
}
