// --------------------------------------------------------------------------
//
// Tec-9
//
// --------------------------------------------------------------------------

ACTOR "Tec9" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon tec9_rat

+AMMO_OPTIONAL

	Weapon.SelectionOrder 600
  weapon.ammotype "Tec9Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "9mmAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //20
	obituary "%k killed %o with Tec-9."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a Tec-9."
	Tag "Tec-9"
	Weapon.UpSound "Tec9/Ready"
	//AttackSound "Tec9/Fire" 
	Scale 0.15
	+NOAUTOFIRE

	States
	{
	Ready:
		W38E M 1 A_WeaponReady
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotReady")
		Loop



	Deselect:
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
	Goto DeselectLoop

	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 240, 0, 0)//Weapon Weight
	TNT1 A 1 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelect")

		W38A CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W38B ABCDEFGHIJK 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready
		
	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		W38A CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W38B ABCDEFGHIJK 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready		
		
	Fire:

	W38D U 0 A_JumpIfNoAmmo("AltFire")
	TNT1 A 0 A_JumpIfInventory("IsBot",1,"BotFire")
	
		W38D A 1 A_GunFlash
		W38D B 1 A_WEAPONREADY(WRF_NOFIRE)
		//W38D D 1

		//TNT1 A 0 A_Refire
		W38D CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W38E ABCDEFGHIJKLM 1 A_WeaponReady
		Goto Ready








//Bot compatibility

	BotReady:
		
		W38D U 1 A_WeaponReady
		TNT1 A 0 A_REFIRE
		Loop


	BotFire:
		W38D A 1 A_GunFlash
		W38D B 1 A_WEAPONREADY(WRF_NOFIRE)
		W38D CD 1 A_WEAPONREADY(WRF_NOFIRE)
		W38D EFGHIJKLMNOPQRSTUVWXYZ 1 A_Refire
		W38E ABCDEFGHIJKLM 1 A_Refire
		Goto Ready




  Altfire:
    TNT1 A 0 A_JumpIfInventory("Tec9Clip",24,"Ready")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W38F ABCDEFGHIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("Tec9/Reload", 6)
		W38F OPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W38G ABCDEFGHIJKLMNOPQRSTUV 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmo
	
	
  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("Tec9Clip",1)
    TNT1 A 0 A_TakeInventory("9mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("Tec9Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadAmmo")
    goto ReloadEnd		

	ReloadEnd:
		W38G WXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W38H ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W38I ABCDEFGHIJKLM 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_JumpIfInventory("Fire_Holdkey",1,"Fire")//A_Refire
		Goto Ready




	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
	TNT1 A 0 A_GiveInventory("CrosshairGrow", 7)
	    TNT1 A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,13,4)
TNT1 A 0 A_PlaySound ("Tec9/FIRE")
		TNT1 A 0 A_PlaySound("TEC9/Distant", 7)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-1.5,1.5), 0, 11, 0, 0, frandom(-1.5,1.5))
		TNT1 A 2 A_FireBullets(0.8, 0.8, -1, 55.0, "tec9Bullet")//7.25
		Goto LightDone
 	Spawn:
		W38Z A -1
		Stop
	}
}