ACTOR xm21 : BrutalWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoGive1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive2 0
	YScale 0.6
	XScale 0.8
	Weapon.SelectionOrder 2500
	Weapon.AmmoType1 "762NATO"
	Weapon.AmmoType2 "xm21Ammo"
	Obituary "%o was shot down by %k's assault x21."
    AttackSound "None"
    Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "$GOTx21"
    +WEAPON.NOALERT
	+WEAPON.NOAUTOFIRE
	+FORCEXYBILLBOARD
	Tag "XM-21 Rifle"
    Scale 0.8
	States
	{
 	Spawn:
		WM14 b 1
		TNT1 A 0 A_SpawnItemEx("XM21Weapon", 0, 0, 0, momx, momy, momz)
		Stop	
	
	Ready:
	Ready3:
		x21G A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		x21G A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
        x21G A 0 A_JumpIfInventory("Reloading",1,"Reload")
		x21G A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		"----" # 0 A_JumpIfInventory("UsedBandage", 1, "UseBandages")
		Loop
		
	Ready2:
		SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		x21G A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
        x21G A 0 A_JumpIfInventory("Reloading",1,"Reload")
		x21G A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		Loop	
	
		
	Deselect:
		x21G A 0
		x21G A 0 A_TakeInventory("TossGrenade", 1)
        x21G A 0 A_TakeInventory("Reloading",1)
		x21G A 0 A_TakeInventory("Unloading",1)
        x21G A 0 A_ZoomFactor(1.0)
		x21G AAAAA 1 A_Lower
		TNT1 AAAAAAAAAAAAAAAAAA 0 A_Lower
		TNT1 A 1 A_Lower
		Wait
		
	Select:
		x21G A 0
		x21G AAAAA 1 A_Raise
		TNT1 AAAAAAAAA 0 A_Raise
		Goto Ready3

	Drop:
		RIFF A 0
		TNT1 A 0 A_TakeInventory("DropWeapon", 1)
		RIFF A 0 A_SpawnItemEx("XM21Weapon", 0, 0, 30, 10, 0, 2)
		TNT1 A 0 A_TakeInventory("XM21", 1)
		TNT1 A 0 A_TakeInventory("Slot2Weapon", 1)
		Goto Ready
	
    Fire:
        x21G A 0 A_JumpIfInventory("xm21Ammo",1,2)
        Goto NoAmmo
        TNT1 AA 0
		x21G A 0 A_AlertMonsters
		x21G A 0 A_PlaySound("m14FIRE", 1)
		SMGG A 0 A_PlaySound("FARM14", 6)
		TNT1 A 0 A_JumpIFInventory("SniperAim", 1, "Fire2")
		
		x21F A 1 A_FireBullets (5, 5, -1, 26, "m14Puff", FBF_NORANDOM)
		x21F B 1 A_FireCustomMissile("SmokeSpawner", random(-0.3,0.3), 0, 0, 0, 0, random(-0.3,0.3))
		x21G A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
        x21F A 0 A_FireCustomMissile("m14Tracer", 0, 0, 0, 0, 0, 0)
		x21G A 0 A_ZoomFactor(0.96)
		x21G A 0 A_SetPitch(pitch-2.6)
		x21G A 0 A_SetANgle(angle-1.4)
		x21G A 0 A_Takeinventory("xm21Ammo",1)
		x21F C 1 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-14)
		x21G A 0 A_ZoomFactor(1.0)
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 0 A_SetPitch(pitch+0.2)
		x21G A 0 A_SetANgle(angle+0.1)
		x21G A 1 A_WeaponReady
		x21G A 5 A_WeaponReady
		x21G A 0 A_Refire
		
		Goto Ready3
	
     Fire2:
		SNIP A 1 A_FireBullets (0, 0, -1, 26, "m14Puff", FBF_NORANDOM)
		SNIP A 1 A_FireCustomMissile("SmokeSpawner", random(-0.3,0.3), 0, 0, 0, 0, random(-0.3,0.3))
		x21G A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
        x21F A 0 A_FireCustomMissile("m14Tracer", 0, 0, 0, 0, 0, 0)
		x21G A 0 A_ZoomFactor(5.96)
		SNIP A  0 A_SetPitch(pitch-2.6)
		SNIP A  0 A_SetANgle(angle-1.4)
		SNIP A  0 A_Takeinventory("xm21Ammo",1)
		SNIP A 1 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-14)
		SNIP A  0 A_ZoomFactor(6.0)
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  0 A_SetPitch(pitch+0.2)
		SNIP A  0 A_SetANgle(angle+0.1)
		SNIP A  1 A_WeaponReady
		SNIP A  5 A_WeaponReady
		SNIP A  0 A_Refire
		Goto Ready2
		
    AltFire:
		TNT1 A 0
		TNT1 A 0 A_JumpIFInventory("SniperAim", 1, "StopAlt")
		TNT1 A 0 A_GiveInventory("SniperAim", 1)
		TNT1 A 0 A_ZoomFactor(6.0)
		X21A ABC 1
		Goto Ready2
		
	StopAlt:
		TNT1 A 0 A_ZoomFactor(1.0)
		X21A CBA 1
		TNT1 A 0 A_TakeInventory("SniperAim", 1)
		Goto Ready3
			
		
	NoAmmo:
		x21G A 0
		x21G A 0 A_ZoomFactor(1.0)
		x21G A 0 A_Takeinventory("Zoomed",1)
		x21G A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_PlaySound("weapons/empty", 4)
	NoAmmo2:
		x21G A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
        x21G A 0 A_JumpIfInventory("Reloading",1,"Reload")
		x21G A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		x21G A 5 A_WeaponReady(WRF_ALLOWRELOAD | WRF_NOPRIMARY)
		x21G A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("NoAutoReload", 1, "NoAmmo2")
		x21G A 0 A_JumpIfInventory("762NATO",1,"Reload")
		Goto Ready3
	
    Reload:
		x21G A 1 A_WeaponReady
		x21G A 0 A_ZoomFactor(1.0)
		x21G A 0 A_Takeinventory("Reloading",1)
		x21G A 0 A_Takeinventory("ADSmode",1)
		x21G A 0 A_Takeinventory("Zoomed",1)
		x21G A 0 A_JumpIfInventory("xm21Ammo",21,76)
        x21G A 0 A_JumpIfInventory("762NATO",1,3)
        Goto FinishReloading
        TNT1 AAA 0
		x21G A 0 A_Takeinventory("Zoomed",1)
		x21G A 0 A_GiveInventory ("Pumping", 1)
		x21G A 0 A_Takeinventory("Reloading",1)
		
		x21G A 0
        x21R ABCDEEEE 1  A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_PLaySound("RELO1", 4)
		x21R FGH 1
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		x21R I 30
        x21R JKL 1
		TNT1 A 0 A_PLaySound("RELO2", 4)
		x21R M 2
		x21G A 0 A_JumpIfInventory("xm21Ammo",1,"InsertBullets2")
		Goto InsertBullets
		
		
	InsertBullets:
		TNT1 AAAA 0
		x21G A 0 A_JumpIfInventory("xm21Ammo",20,15)
		x21G A 0 A_JumpIfInventory("762NATO",1,3)
		Goto FinishReload3
        TNT1 AAAAAA 0
		x21G A 0 A_Giveinventory("xm21Ammo",1)
		x21G A 0 A_Giveinventory("Doublexm21Ammo",1)
		x21G A 0 A_Takeinventory("762NATO",1)
		Goto InsertBullets
		
		TNT1 AAAAAAAAAA 0
		x21G A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload3	
		TNT1 AAAA 0
		x21G A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload3	
		
	InsertBullets2:
		TNT1 AAAA 0
		x21G A 0 A_JumpIfInventory("xm21Ammo",21,15)
		x21G A 0 A_JumpIfInventory("762NATO",1,3)
		Goto FinishReload2	
        TNT1 AAAAAA 0
		x21G A 0 A_Giveinventory("xm21Ammo",1)
		x21G A 0 A_Giveinventory("Doublexm21Ammo",1)
		x21G A 0 A_Takeinventory("762NATO",1)
		Goto InsertBullets2
		
		TNT1 AAAAAAAAAA 0
		x21G A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload2	
		TNT1 AAAA 0
		x21G A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload2	
		
	FinishReloading:
		x21G A 0
		x21G A 0 A_Refire
		Goto Ready3
		
		

		
	FinishReload2:
		x21R M 8
		x21R DCBA 1
		x21R A 0 A_Takeinventory("HasUnloaded",1)
		Goto Ready3
		

	FinishReload3:
		x21R M 8
		x21R DCBA 1
		x21R N 8
		x21R OPQR 1
		x21R R 8
		x21R STUVVV 1
		x21R XYZ 1
		x21R R 8
		x21R QPO 1
		x21R A 0 A_Takeinventory("HasUnloaded",1)
		Goto Ready3		
	
	}
}

ACTOR xm21Ammo : Ammo
{
   Inventory.Amount 0
   Inventory.MaxAmount 21
   Ammo.BackpackAmount 0
   Ammo.BackpackMaxAmount 21
   Inventory.Icon "WM14b0"
}