
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//|
//| Dont change anything below here unless you know
//| What your doing.
//|
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
EditActionMap("playMap.sae");

//Our nothing function. It does.. nothing.

function nothing() {}

bindCommand($DUNE_Weapons, make, $DUNE_Nothing, TO, "DUNE_use(\"nothing\");");
bindCommand($DUNE_Weapons, make, $DUNE_Melee, TO, "DUNE_use(\"melee\");");
bindCommand($DUNE_Weapons, make, $DUNE_Projectile, TO, "DUNE_use(\"projectile\");");
bindCommand($DUNE_Weapons, make, $DUNE_Lasgun, TO, "DUNE_use(\"lasgun\");");
bindCommand($DUNE_Weapons, make, $DUNE_AA, TO, "DUNE_use(\"aa\");");
bindCommand($DUNE_Weapons, make, $DUNE_AT, TO, "DUNE_use(\"at\");");
bindCommand($DUNE_Weapons, make, $DUNE_Throwing, TO, "DUNE_use(\"throwing\");");
bindCommand($DUNE_Weapons, make, $DUNE_Tool, TO, "DUNE_use(\"tool\");");
bindCommand($DUNE_Weapons, make, $DUNE_NoAmmo, TO, "EmptyWeap();");

bindCommand($DUNE_SingleFire_or_FullAuto_Input, make, $DUNE_SingleFire_or_FullAuto, TO, "remoteeval(2048,riflesingleonoff);");

bindCommand($DUNE_UnarmedAttack_Input, make, $DUNE_UnarmedAttack, TO, "remoteEval(2048,unarmedAttackbegin);");
bindCommand($DUNE_UnarmedAttack_Input, break, $DUNE_UnarmedAttack, TO, "remoteEval(2048,unarmedAttackend);");

bindCommand($DUNE_Climb_Input, make, $DUNE_Climb, TO, "remoteeval(2048,climb);");

bindCommand($DUNE_ToggleWeaponLoop_Input, make, $DUNE_ToggleWeaponLoop, TO, "DUNE_ToggleWeaponLooping();");



function DUNE_use(%type)
{
	remoteeval(2048,useItemType,%type);
}

function DUNE_ToggleWeaponLooping()
{
	if($DUNE_WeaponLoop == true)
		$DUNE_WeaponLoop = false;
	else
		$DUNE_WeaponLoop = true;

	remoteeval(2048,setWeaponLoop,$DUNE_WeaponLoop);
}

function remoteSetTeam(%client,%team)
{
	$CurTeam = %team;
	$ServerFavoritesKey = "DUNE"@%team;
	exec(Vmenu);
}

function remoteSetArmor(%client,%armor)
{
	$CurArmor = %armor;
	exec(Vmenu);
}

$Dune_TeamList[0] = "HA";
$Dune_TeamList[1] = "HH";
$Dune_TeamList[2] = "HC";
$Dune_TeamList[3] = "IX";
$Dune_TeamList[4] = "BT";
$Dune_TeamList[5] = "MH";
$Dune_TeamList[6] = "MH2";
$Dune_TeamNum=6;



$Dune_Res["640x480"] = 275;
$Dune_Res["720x576"] = 345;
$Dune_Res["800x600"] = 365;
$Dune_Res["1024x768"] = 485;
$Dune_Res["1152x864"] = 555;
$Dune_Res["1280x1024"] = 670;
$Dune_Res["1600x1200"] = 800;

function DUNE_SetUpHud()
{
	Dune_KillHud();

	// Going to do this nice and inefficiently :)
	%pistol = getItemCount("Pistol Clip");
	%maula = getItemCount("Maula Clip");
	%stunner = getItemCount("Stunner Clip");
	%rifle = getItemCount("Rifle Clip");
	%Mgun = getItemCount("Machine Gun belt");	
	%sniper = getItemCount("Sniper Clip");
	%cutteray = getItemCount("Cutteray Cell");
	%smalllas = getItemCount("Small Lasgun Cell");
	%riflelas = getItemCount("Rifle Lasgun Cell");
	%heavyLas = getItemCount("Heavy Lasgun Cell");
	%rlauncher = getItemCount("Rockets");
	%health = getItemCount("Repair Kit");
	%height = 12.5;
	if($Hud_Norm_Position)
	{
	if($Dune_Res[$pref::VideoFullScreenRes] == "")
		%pos = $Dune_Res["800x600"];
	else
		%pos = $Dune_Res[$pref::VideoFullScreenRes];
	}
	else
	{
		if(isFullScreenMode(MainWindow))
		{
			%index = String::findSubStr($pref::VideoFullScreenRes, "x");
			%bot = String::getSubStr($pref::VideoFullScreenRes, %index+1, %index +5);
		}
		else
		{
			%bot = 480;
		}
		%pos = %bot - %height;
	}
	
	control::setextent("Clip_Container", 100, %height);
	
	control::setposition("Clip_Header", 75, %pos);
	control::setposition("Clip_Container", 70, %pos);
	$Dune_Hud_Clip_Container = newObject("Clip_Container", FearGui::FearGuiMenu, 70,  %pos, 100, %height); // XLoc, YLoc, Width, Height
	$Dune_Hud_Header = newObject("Clip_Header", FearGuiFormattedText, 75,  %pos, 1000, 1000);

	addToSet(PlayGui, $Dune_Hud_Clip_Container);
	addToSet(PlayGui, $Dune_Hud_Header);

	$Dune_Text_Header = "<f2>Clips<L14>#";
	$Dune_Text_Pistol =	"\\nPistol<L15><f1>"@%pistol;
	$Dune_Text_Maula =	"\\nMaula<L15><f1>"@%maula;
	$Dune_Text_Stunner = 	"\\nStunner<L15><f1>"@%stunner;
	$Dune_Text_Rifle =	"\\nRifle<L15><f1>"@%Rifle;
	$Dune_Text_MGun =	"\\nMGun<L15><f1>"@%Mgun;
	$Dune_Text_Sniper =	"\\nSniper<L15><f1>"@%sniper;
	$Dune_Text_Cutteray =	"\\nCutteray<L15><f1>"@%Cutteray;
	$Dune_Text_SmallLas =	"\\nSmallLas<L15><f1>"@%smalllas;
	$Dune_Text_RifleLas =	"\\nRifleLas<L15><f1>"@%riflelas;
	$Dune_Text_HeavyLas =	"\\nHeavyLas<L15><f1>"@%heavyLas;
	$Dune_Text_RLauncher =	"\\nRLauncher<L15><f1>"@%rlauncher;
	$Dune_Text_RepKits =	"\\nRepKits<L15><f1>"@%health;

	Control::setValue("Clip_Header", $Dune_Text_Header);

	if($Dune_Updating != true)
		Dune_Update();
}

function Dune_Update()
{
	$Dune_Updating = true;			
	%pistol = getItemCount("Pistol Clip");
	%maula = getItemCount("Maula Clip");
	%stunner = getItemCount("Stunner Clip");
	%rifle = getItemCount("Rifle Clip");
	%Mgun = getItemCount("Machine Gun belt");	
	%sniper = getItemCount("Sniper Clip");
	%cutteray = getItemCount("Cutteray Cell");
	%smalllas = getItemCount("Small Lasgun Cell");
	%riflelas = getItemCount("Rifle Lasgun Cell");
	%heavyLas = getItemCount("Heavy Lasgun Cell");
	%rlauncher = getItemCount("Rockets");
	%health = getItemCount("Repair Kit");

	%num=0;
	$Dune_Text_Header = "<f2>Clips\t\t\t\t#";
	$Dune_Text_Pistol =	"\n<f0>Pistol\t\t\t<f1>"@%pistol;
	$Dune_Text_Maula =	"\n<f0>Maula\t\t\t<f1>"@%maula;
	$Dune_Text_Stunner = 	"\n<f0>Stunner\t\t<f1>"@%stunner;
	$Dune_Text_Rifle =	"\n<f0>Rifle\t\t\t\t<f1>"@%Rifle;
	$Dune_Text_MGun =	"\n<f0>MGun\t\t\t<f1>"@%Mgun;
	$Dune_Text_Sniper =	"\n<f0>Sniper\t\t\t<f1>"@%sniper;
	$Dune_Text_Cutteray =	"\n<f0>Cutteray\t\t<f1>"@%Cutteray;
	$Dune_Text_SmallLas =	"\n<f0>SmallLas\t\t<f1>"@%smalllas;
	$Dune_Text_RifleLas =	"\n<f0>RifleLas\t\t<f1>"@%riflelas;
	$Dune_Text_HeavyLas =	"\n<f0>HeavyLas\t\t<f1>"@%heavyLas;
	$Dune_Text_RLauncher =	"\n<f0>RLauncher\t<f1>"@%rlauncher;
	$Dune_Text_RepKits =	"\n<f0>RepKits\t\t<f1>"@%health;

	%CurText = $Dune_Text_Header;
	%num++;

	if(%health>0)
	{
		%CurText = %CurText @ $Dune_Text_RepKits;
		%num++;
	}
	if(%pistol>0)
	{
		%CurText = %CurText @ $Dune_Text_Pistol;
		%num++;
	}		
	if(%maula>0)
	{
		%CurText = %CurText @ $Dune_Text_Maula;
		%num++;
	}		
	if(%stunner>0)
	{
		%CurText = %CurText @ $Dune_Text_Stunner;
		%num++;
	}		
	if(%rifle>0)
	{
		%CurText = %CurText @ $Dune_Text_Rifle;
		%num++;
	}		
	if(%mgun>0)
	{
		%CurText = %CurText @ $Dune_Text_Mgun;
		%num++;
	}		
	if(%sniper>0)
	{
		%CurText = %CurText @ $Dune_Text_Sniper;
		%num++;
	}		
	if(%cutteray>0)
	{
		%CurText = %CurText @ $Dune_Text_Cutteray;
		%num++;
	}		
	if(%smalllas>0)
	{
		%CurText = %CurText @ $Dune_Text_SmallLas;
		%num++;
	}		
	if(%riflelas>0)
	{
		%CurText = %CurText @ $Dune_Text_RifleLas;
		%num++;
	}		
	if(%heavylas>0)
	{
		%CurText = %CurText @ $Dune_Text_HeavyLas;
		%num++;
	}		
	if(%rlauncher>0)
	{
		%CurText = %CurText @ $Dune_Text_RLauncher;
		%num++;
	}		

	$Dune_Cur_Text = %curText;
	Control::setValue("Clip_Header", $Dune_Cur_Text);
	Control::SetVisible("Clip_Header",true);
	%height = (%num+1) * (12.5);
	control::setextent("Clip_Container", 100, %height);
	
	if($Hud_Norm_Position)
	{
	if($Dune_Res[$pref::VideoFullScreenRes] == "")
		%pos = $Dune_Res["800x600"];
	else
		%pos = $Dune_Res[$pref::VideoFullScreenRes];
	}
	else
	{
		if(isFullScreenMode(MainWindow))
		{
			%index = String::findSubStr($pref::VideoFullScreenRes, "x");
			%bot = String::getSubStr($pref::VideoFullScreenRes, %index+1, %index +5);
		}
		else
		{
			%bot = 480;
		}
		%pos = %bot - %height;
	}
	
	control::setextent("Clip_Container", 100, %height);
	
	control::setposition("Clip_Header", 75, %pos);
	control::setposition("Clip_Container", 70, %pos);

	schedule("Dune_Update();",1);
}

function Dune_KillHud()
{
	deleteObject($Dune_Hud_Clip_Container);
	deleteObject($Dune_Hud_Header);
	dune_killall();
}


function Dune_KillAll()
{
%ngs = nameToId("NamedGuiSet\\PlayGUI");
%len = Group::objectCount(%ngs);
for(%i = 0; %i < %len; %i++)
  {
  %obj = Group::getObject(%ngs, %i);
  %objectName=Object::getName(%obj);
  if(String::findSubStr(%objectName, "Clip_") != -1)
    deleteObject(%obj);
  }
%ngs = nameToId("NamedGuiSet");
%len = Group::objectCount(%ngs);
for(%i = 0; %i < %len; %i++)
  {
  %obj = Group::getObject(%ngs, %i);
  %objectName=Object::getName(%obj);
  if(String::findSubStr(%objectName, "Clip_") != -1)
    deleteObject(%obj);
  }
%ngs = nameToId("PlayGuiSet");
%len = Group::objectCount(%ngs);
for(%i = 0; %i < %len; %i++)
  {
  %obj = Group::getObject(%ngs, %i);
  %objectName=Object::getName(%obj);
  if(String::findSubStr(%objectName, "Clip_") != -1)
    deleteObject(%obj);
  }
$dune_updating = false;
}

if($Dune_Activate_ClipBox)
	schedule("dune_Setuphud();",10);

function EndGame()
{
	if($dune)
	Dune_KillAll();
	
	
	$ConnectedToServer = FALSE;
   setCursor(MainWindow, "Cur_Arrow.bmp");
   disconnect();
   if ($SinglePlayer)
	   TrainingEndGameCallback();

	if ($pref::userCDOverride == False)
	{
		rbSetPlayMode (CD, 0);
		rbStop (CD);
		$cdTrack = "";
	}
	$recordDemo = FALSE;
   startMainMenuScreen();
   deleteServer();
	QuickStart();
   deleteObject(ConsoleScheduler);
   newObject(ConsoleScheduler, SimConsoleScheduler);
   if($quitOnDisconnect)
      schedule("quit();", 0);
}


function EmptyWeap()
{
	%x = 0;
	%item[%x++] = "Rocket Launcher (SSM SAM)";
	%check[%x] = (getItemCount("Rockets")==0 && getItemCount("Loaded Rocket")==0 && getItemCount("Rocket Launcher (SSM SAM)")>0);

	%item[%x++] = "Pistol";
	%check[%x] = (getItemCount("Pistol Clip")==0 && getItemCount("Pistol Bullet")==0 && getItemCount("Pistol")>0);

	%item[%x++] = "Maula Pistol";
	%check[%x] = (getItemCount("Maula Clip")==0 && getItemCount("Maula Bullet")==0 && getItemCount("Maula Pistol")>0);

	%item[%x++] = "Stunner";
	%check[%x] = (getItemCount("Stunner Clip")==0 && getItemCount("Stunner Slug")==0 && getItemCount("Stunner")>0);

	%item[%x++] = "Assault Rifle";
	%check[%x] = (getItemCount("Rifle Clip")==0 && getItemCount("Rifle Bullet")==0 && getItemCount("Assault Rifle")>0);

	%item[%x++] = "Heavy Machine Gun";
	%check[%x] = (getItemCount("Machine Gun belt")==0 && getItemCount("MGun Bullet")==0 && getItemCount("Heavy Machine Gun")>0);	

	%item[%x++] = "Sniper Rifle";
	%check[%x] = (getItemCount("Sniper Clip")==0 && getItemCount("Sniper Bullet")==0 && getItemCount("Sniper Rifle")>0);

	%item[%x++] = "Cutteray";
	%check[%x] = (getItemCount("Cutteray Cell")==0 && getItemCount("Cutteray Blast")==0 && getItemCount("Cutteray")>0);

	%item[%x++] = "Small Lasgun";
	%check[%x] = (getItemCount("Small Lasgun Cell")==0 && getItemCount("Small Lasgun Blast")==0 && getItemCount("Small Lasgun")>0);

	%item[%x++] = "Rifle Lasgun";
	%check[%x] = (getItemCount("Rifle Lasgun Cell")==0 && getItemCount("Rifle Lasgun Blast")==0 && getItemCount("Rifle Lasgun")>0);

	%item[%x++] = "Heavy Lasgun";
	%check[%x] = (getItemCount("Heavy Lasgun Cell")==0 && getItemCount("Heavy Lasgun Blast")==0 && getItemCount("Heavy Lasgun")>0);

	%item[%x++] = "Flamethrower";
	%check[%x] = (getItemCount("Napalm")==0 && getItemCount("Flamethrower")>0);

	%item[%x++] = "Pillar of Fire";
	%check[%x] = (getItemCount("Napalm")==0 && getItemCount("Pillar of Fire")>0);
	
	for(%i = 0; %i<=%x; %i++)
	{
	if(%check[%i])
		{
		use(%item[%i]);
		return;
		}
	}
		
}