// --------------------------------------------------------------------------
//
// P90 (Demo weapon "Appears on weapons training")
//
// --------------------------------------------------------------------------

//Weapon Auxiliar
Actor P90Refire : Inventory
{
Inventory.MaxAmount 2
}

ACTOR "P90" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon p90_rat

+AMMO_OPTIONAL

Weapon.SelectionOrder 300
  weapon.ammotype "P90Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "57mmAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //50
	obituary "%k killed %o with P90."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a P90."
	Tag "P90"
	Weapon.UpSound "P90/Ready"
	//AttackSound "P90/Fire" 
	Scale 0.2

	States
	{
	Ready:
		W30C A 1 A_WeaponReady
		Loop




	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 230, 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")

		TNT1 A 1 A_WEAPONREADY(WRF_NOFIRE)
		W30A DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W30B ABCDEFGHIJ 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready

	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		TNT1 A 1 A_WEAPONREADY(WRF_NOFIRE)
		W30A DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W30B ABCDEFGHIJ 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready

		
	Deselect:
				TNT1 A 1 A_ZoomFactor(1.0)
                TNT1 A 0 A_TakeInventory("P90Refire", 3)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
				TNT1 AAAAAAAAAAAAAAAAA 0 A_Lower
                TNT1 AAAAAA 1 A_Lower
		Loop		
		
		
	Fire:
	
	W30C A 0 A_JumpIfNoAmmo("AltFire")

	
	    TNT1 A 0 A_JumpIfInventory("P90Refire", 2, "Fire3")
		TNT1 A 0 A_JumpIfInventory("P90Refire", 1, "Fire2")
		W30D A 1 A_Gunflash
		TNT1 A 0 A_GiveInventory("P90Refire", 1)
		W30D B 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		TNT1 A 0 A_TakeInventory("P90Refire", 3)
		W30D CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W30E A 1 A_WeaponReady
		Goto Ready

	Fire2:
		W30D C 1 A_Gunflash
		TNT1 A 0 A_GiveInventory("P90Refire", 1)
		W30D A 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		TNT1 A 0 A_TakeInventory("P90Refire", 3)
		W30D BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W30E A 1 A_WeaponReady
		Goto Ready
		
	Fire3:
		W30D B 1 A_Gunflash
		TNT1 A 0 A_TakeInventory("P90Refire", 3)
		W30D C 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		TNT1 A 0 A_TakeInventory("P90Refire", 3)
		W30D DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W30E A 1 A_WeaponReady
		Goto Ready		





  Altfire:
    TNT1 A 0 A_JumpIfInventory("P90Clip",50,"Ready")
    TNT1 A 0 A_JumpIfInventory("57mmAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W30F ABCDEFGHIJK 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		TNT1 A 0 A_PlaySound("P90/Reload", 6)
		W30F LMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W30G ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W30H ABCDEFGHIJKLMNOPQ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		W30H RSTU 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmo
		
  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("P90Clip",1)
    TNT1 A 0 A_TakeInventory("57mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("P90Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("57mmAmmo",1,"ReloadAmmo")
    goto ReloadEnd		

	ReloadEnd:
		W30H VWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W30I ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W30J ABCDEFGHIJKLMNOPQ 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready




	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
		TNT1 A 0 A_GiveInventory("CrosshairGrow", 5)
TNT1 A 0 A_FireCustomMissile("WeaponSmokePuff",0,0,16,0)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound ("P90/FIRE")
		TNT1 A 0 A_PlaySound("P90/Distant", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-2.5,2.5), 0, 11, 0, 0, frandom(-2.5,2.5))
		TNT1 A 1 A_FireBullets(5, 5, 1, 40.0, "p90Bullet")//6.5
		Goto LightDone
 	Spawn:
		W30Z A -1
		Stop
	}
}