#library "Tomtefar"
#include "zcommon.acs"



//str weapon;
//weapon = GetWeapon();
//SetWeapon(weapon);

//return state
//SetActorState
//FireCustomMissile

//"####"
//"----"

script "TE_UseInput" ENTER
{
	int buttons;

	while (TRUE)
	{
		buttons = GetPlayerInput(-1, INPUT_BUTTONS);

		if (buttons & BT_USE)
		{
			//PrintBold(s:":::::Pressed:::::");
			TakeInventory("PressedUse", 100);
			
			int uid1 = UniqueTID();
			int uid2 = UniqueTID();
			int ptc = GetActorPitch(0)>>8;
			int ang = GetActorAngle(0)>>8;
			int speed = cos(GetActorPitch(0)) * 64 >> 16;
			int vspeed = -sin(GetActorPitch(0)) * 64 >> 16;
			
			SpawnProjectile(0, "TE_UseAttack", ang, speed, vspeed, 0, uid1);
			SetActorPosition(uid1, GetActorX(uid1), GetActorY(uid1), GetActorZ(uid1)+40.0, FALSE);
			SetActorPitch(uid1, ptc);
			SetPointer(AAPTR_TARGET, 0, uid1);
			
			SpawnProjectile(0, "TE_StealthAttack", ang, speed, vspeed, 0, uid2);
			SetActorPosition(uid2, GetActorX(uid2), GetActorY(uid2), GetActorZ(uid2)+40.0, FALSE);
			SetActorPitch(uid2, ptc);
			SetPointer(AAPTR_TARGET, 0, uid2);
			
			//Thing_ChangeTID(uid, 0);
			
			while (buttons & BT_USE)
			{
				buttons = GetPlayerInput(-1, INPUT_BUTTONS);
				delay(3);
			}
		}
		delay(1);
	}
}






// --------------------------------------------------------------------------
//
//	Spawn checkers
//
// --------------------------------------------------------------------------

// Script 1001 (int X)	//New weapon checker
//{
//	if(X == 1){
//	SetResultValue(GetCVar("TE_Weap_Pistol"));
//	}else if(X == 2){
//	SetResultValue(GetCVar("TE_Weap_Revolver"));
//	}else if(X == 3){
//	SetResultValue(GetCVar("TE_Weap_AutoShotgun"));
//	}else if(X == 4){
//	SetResultValue(GetCVar("TE_Weap_Sniper"));
//	}else if(X == 5){
//	SetResultValue(GetCVar("TE_Weap_Railgun"));
//	}else if(X == 6){
//	SetResultValue(GetCVar("TE_Weap_C4"));
//	}else{
//	SetResultValue(0);
//	}
//}

//Script 1002 (int X) //BDv21 weapon checker
//{
//	if(X == 0){
//	SetResultValue(GetCVar("TE_Weap_SMG"));
//	}else if(X == 1){
//	SetResultValue(GetCVar("TE_Weap_AA12"));
//	}else if(X == 2){
//	SetResultValue(GetCVar("TE_Weap_Machinegun"));
//	}else if(X == 3){
//	SetResultValue(GetCVar("TE_Weap_GrenadeLauncher"));
//	}else if(X == 4){
//	SetResultValue(GetCVar("TE_Weap_Unmaker"));
//	}else if(X == 5){
//	SetResultValue(GetCVar("TE_Weap_BFG10k"));
//	}else if(X == 6){
//	SetResultValue(GetCVar("TE_Weap_Rifle"));
v	}else if(X == 7){
//	SetResultValue(GetCVar("TE_Weap_Flamer"));
//	}else if(X == 8){
//	SetResultValue(GetCVar("TE_Weap_HellLauncher"));
//	}else if(X == 9){
//	SetResultValue(GetCVar("TE_Weap_MP40"));
//	}else if(X == 10){
//	SetResultValue(GetCVar("TE_Weap_Buzzsaw"));
//	}else if(X == 11){
//	SetResultValue(GetCVar("TE_Weap_Grenades"));
//	}else{
//	SetResultValue(0);
//	}
//}




// --------------------------------------------------------------------------
//
//	Graphics
//
// --------------------------------------------------------------------------

Script 1020 (int X)//Check Graphics
{
	if(X == 0){
	SetResultValue(GetCVar("TE_Enviro"));
	}else if(X == 1){
	SetResultValue(GetCVar("TE_Graphics"));
	}else if(X == 2){
	SetResultValue(GetCVar("TE_Flashlight"));
	}else{
	SetResultValue(0);
	}
}

Script 1021 (VOID)//SSG animation
{
	SetResultValue(GetCVar("TE_SSG"));
}

Script 1022 (VOID)//Check shotgun strap physics
{
	if(GetCvar("TE_Shotgunstrap") == 1)
	{
		GiveInventory("useshotgunstrap", 1);
	}
}

Script "TE_WeaponSprites" (VOID)
{
	if(GetCvar("TE_Sprites_Shotgun") == 1 && CheckInventory("ShotgunSelected") == 1)
	{
		GiveInventory("BD21graphics", 1);
	}
	if(GetCvar("TE_Sprites_Buzzsaw") == 1 && CheckInventory("MinigunSelected") == 1)
	{
		GiveInventory("BD21graphics", 1);
	}
	if(GetCvar("TE_Sprites_SSG") == 1 && CheckInventory("SSGSelected") == 1)
	{
		GiveInventory("BD21graphics", 1);
	}
	if(GetCvar("TE_Sprites_SSG") == 2 && CheckInventory("SSGSelected") == 1)
	{
		GiveInventory("BD21graphics", 2);
	}
	if(GetCvar("TE_Sprites_Grenade") == 1 && CheckInventory("FistsSelected") == 1)
	{
		GiveInventory("BD21graphics", 1);
	}
}

Script 1025 (int X) NET//Check weapon sprites
{
	if(X == 0){
	SetResultValue(GetUserCVar(PlayerNumber(),("TE_Sprites_Shotgun")));
	}else if(X == 1){
	SetResultValue(GetUserCVar(PlayerNumber(),("TE_Sprites_Buzzsaw")));
	}else if(X == 2){
	SetResultValue(GetUserCVar(PlayerNumber(),("TE_Sprites_SSG")));
	}else if(X == 3){
	SetResultValue(GetUserCVar(PlayerNumber(),("TE_Sprites_Grenade")));
	}else{
	SetResultValue(0);
	}
}


// --------------------------------------------------------------------------
//
//	Misc. Options
//
// --------------------------------------------------------------------------

Script "TE_StartWeapon" (VOID)
{
	While(CheckInventory("dummytoken") < GetCVar("TE_StartWeapon"))
	{
		GiveInventory("dummytoken", 1);
	}
}

Script "TE_SmartAmmo" (VOID)
{
	if(GetCvar("TE_SmartAmmo") == 0)
	{
		SetActorState(0, "NoSmart");
	}
}

Script 1023 (int X) NET
{
	if(X == 0){
	SetResultValue(GetCVar("TE_StartWeapon"));
	}else if(X == 1){
	SetResultValue(GetCVar("TE_SmartAmmo"));
	}else if(X == 2){
	SetResultValue(GetCVar("TE_BFGbehaviour"));
	}else if(X == 3){
	SetResultValue(GetCVar("TE_RocketLauncherAltFire"));
	}else{
	SetResultValue(0);
	}
}
/*
Script 1024 (VOID)//BFG behaviour
{
	SetResultValue(GetCVar("TE_BFGbehaviour"));
}

Script 1026 (VOID)//Rocket Launcher alt fire type
{
	SetResultValue(GetCVar("TE_RocketLauncherAltFire"));
}
*/
Script 1027 (VOID)//Check if this game should play random level progression
{
	SetResultValue(GetCVar("TE_RandomLevel"));
}

Script 1028 (VOID)//Check dualwielding
{
	SetResultValue(GetCVar("TE_DualWielding"));
}

Script 1029 (VOID)//Check ADS mode
{
	SetResultValue(GetCVar("TE_ADSmode"));
}

Script "TE_DMweapons" (VOID)//Check if we should use the new weapons in DM
{
	SetResultValue(GetCVar("TE_DMweapons"));
}

// --------------------------------------------------------------------------
//
//	Keybinds
//
// --------------------------------------------------------------------------


Script 1032 (VOID) NET//WeapSpecial
{
	GiveInventory("WeapSpecial", 1);
}


// --------------------------------------------------------------------------
//
//	Gameplay stuff
//
// --------------------------------------------------------------------------


Script 1043 (VOID)//Ammo drop counters.
{
	while (CheckWeapon("U_AmmoDropper"))
	{
		SetFont("BIGFONT");
		HudMessage(s:"Press any weapon number to exit";	HUDMSG_PLAIN, 0, CR_GRAY, 0.5, 0.20, 0.2);
		HudMessage(s:"Drop ammo with primary fire";		HUDMSG_PLAIN, 0, CR_GRAY, 0.5, 0.80, 0.2);
		HudMessage(s:"Cycle ammo with secondary fire";	HUDMSG_PLAIN, 0, CR_GRAY, 0.5, 0.85, 0.2);
		SetFont("SMALLFONT");

		int ammo1 = CheckInventory("Clip1");
		HudMessage(d:ammo1; HUDMSG_PLAIN, 0, CR_WHITE, 0.140, 0.605, 0.2, 2.0);
		int ammo2 = CheckInventory("RevolverBullets");
		HudMessage(d:ammo2; HUDMSG_PLAIN, 0, CR_WHITE, 0.212, 0.605, 0.2, 2.0);
		int ammo3 = CheckInventory("AmmoShell");
		HudMessage(d:ammo3; HUDMSG_PLAIN, 0, CR_WHITE, 0.284, 0.605, 0.2, 2.0);
		int ammo4 = CheckInventory("GreenShell");
		HudMessage(d:ammo4; HUDMSG_PLAIN, 0, CR_WHITE, 0.356, 0.605, 0.2, 2.0);
		int ammo5 = CheckInventory("Clip2");
		HudMessage(d:ammo5; HUDMSG_PLAIN, 0, CR_WHITE, 0.428, 0.605, 0.2, 2.0);
		int ammo6 = CheckInventory("MinigunAmmo");
		HudMessage(d:ammo6; HUDMSG_PLAIN, 0, CR_WHITE, 0.500, 0.605, 0.2, 2.0);
		int ammo7 = CheckInventory("AmmoRocket");
		HudMessage(d:ammo7; HUDMSG_PLAIN, 0, CR_WHITE, 0.572, 0.605, 0.2, 2.0);
		int ammo8 = CheckInventory("AmmoCell");
		HudMessage(d:ammo8; HUDMSG_PLAIN, 0, CR_WHITE, 0.644, 0.605, 0.2, 2.0);
		int ammo9 = CheckInventory("RailCore");
		HudMessage(d:ammo9; HUDMSG_PLAIN, 0, CR_WHITE, 0.716, 0.605, 0.2, 2.0);
		int ammo10 = CheckInventory("Gasoline");
		HudMessage(d:ammo10; HUDMSG_PLAIN, 0, CR_WHITE, 0.788, 0.605, 0.2, 2.0);
		int ammo11 = CheckInventory("GrenadeAmmo");
		HudMessage(d:ammo11; HUDMSG_PLAIN, 0, CR_WHITE, 0.860, 0.605, 0.2, 2.0);
		delay(6);
	}
}

script 1045 (VOID)//Check if on a liquid surface.
// 1 = water
// 2 = nukage
// 3 = blood
// 4 = lava
// 5 = slime
// 0 = default
{
	if (CheckActorFloorTexture(0, "FWATER1")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER2")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER3")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "FWATER4")){SetResultValue(1);}
	else if (CheckActorFloorTexture(0, "NUKAGE1")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE2")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE3")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "NUKAGE4")){SetResultValue(2);}
	else if (CheckActorFloorTexture(0, "BLOOD1")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD2")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD3")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "BLOOD4")){SetResultValue(3);}
	else if (CheckActorFloorTexture(0, "LAVA1")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA2")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA3")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "LAVA4")){SetResultValue(4);}
	else if (CheckActorFloorTexture(0, "SLIME01")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME02")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME03")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME04")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME05")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME06")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME07")){SetResultValue(5);}
	else if (CheckActorFloorTexture(0, "SLIME08")){SetResultValue(5);}
	else {SetResultValue(0);}
}

Script 1046 (VOID)//Misc stuff to do all the time.
{
	int x, y, z, speed;
	while (TRUE)
	{
		//Idle checker
		x = GetActorVelX(0);
		y = GetActorVelY(0);
		z = GetActorVelZ(0);
		speed = x + y + z;
		if (speed != 0)
		{
			TakeInventory("IdleCounter", 200);
		} else {
			GiveInventory("IdleCounter", 1);
		}
		//New ammo dropper
		if (CheckWeapon("AmmoDroper"))
		{
			TakeInventory("AmmoDroper", 1);
			SetWeapon("U_AmmoDropper");	
		}
		//Give soul ammo
		GiveInventory("U_SoulAmmo", 1);
		delay(50);
	}
}

Script "TE_GametypeCheck" (VOID)
{
	if	(PlayerIsBot(PlayerNumber()))
	{
		GiveInventory("PlayerIsABot", 1);
	}
	if (GameType() == GAME_NET_DEATHMATCH)
	{
		GiveInventory("DMGame", 1);
	}
}
/*
Script 1047 (VOID)//Check current gametype and if calling player is a bot.
// 0 = Single player
// 1 = Multiplayer, player is not a bot
// 2 = Multiplayer, player is a bot
// 3 = Coop
{
	if (GameType () == GAME_NET_DEATHMATCH)
	{
		if (PlayerIsBot(PlayerNumber()))
		{
			SetResultValue(2);
		} else {
			SetResultValue(1);
		}
	} else if (GameType () == GAME_NET_COOPERATIVE )
	{
		SetResultValue(3);
	} else {
		SetResultValue(3);
	}
}
*/
Script 1048 (VOID)//Blow C-4 charges.
{
	SetActorState(1999,"explode");
}

Script 1049 (VOID)//Shotgun stuff spawned?
{
	if (ShotgunStuffSpawned == 0)
	{
		ShotgunStuffSpawned = 1;
		SetResultValue(0);
	} else if (ShotgunStuffSpawned == 1)
	{
		ShotgunStuffSpawned = 2;
		SetResultValue(1);
	} else
	{
		SetResultValue(2);
	}
}

script 1050 (VOID)//C-4 charges indicator
{
	while (TRUE)
	{
		int Ammo = CheckInventory("C4Ammo");
		int Weapon = CheckInventory("C4Weapon");
		int X = GetCVar("TE_C4X");
		int Y = GetCVar("TE_C4Y");
		int Z = GetCVar("TE_C4img");
		
		if(Z == 1) //Smart show - Only shows C-4 if player has the weapon and ammo.
		{
			if(Ammo != 0 && Weapon != 0)
			{
				SetFont("BIGFONT");
				HudMessage(d:Ammo; HUDMSG_PLAIN, 0, CR_RED, (X*0.01-0.02), (Y*0.01-0.04), 0.2, 2.0);
				SetFont("C4EWA0");
				HudMessage(s:"A"; HUDMSG_PLAIN, 0, 0, (X*0.01), (Y*0.01), 0.2);
			}
		}
		
		if(Z == 2) //Always show
		{
			SetFont("BIGFONT");
			HudMessage(d:Ammo; HUDMSG_PLAIN, 0, CR_RED, (X*0.01-0.02), (Y*0.01-0.04), 0.2, 2.0);
			SetFont("C4EWA0");
			HudMessage(s:"A"; HUDMSG_PLAIN, 0, 0, (X*0.01), (Y*0.01), 0.2);
		}
		delay(6);
	}
}



Script "1046"// (VOID)//Misc stuff to do all the time.
{

		//Give soul ammo
		GiveInventory("U_SoulAmmo", 1);
		delay(50);

}



