ACTOR M16 : BrutalWeapon
{
	Weapon.AmmoUse1 0 //Weapon doesn't uses ZDoom's native ammo system. It uses a custom one instead.
	Weapon.AmmoGive1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "556" //Extra ammo
	Weapon.AmmoType2 "RifleAmmo" //Ammo in the gun
	Obituary "%o was shot down by %k's assault rifle."
    Inventory.PickupSound "CLIPIN"
	Inventory.Pickupmessage "$GOTRIFLE"
    +WEAPON.NOALERT //Weapon alerts enemies when it's required
	+WEAPON.NOAUTOFIRE 
	+FORCEXYBILLBOARD
	Tag "M-16A1 Rifle"
	States
	{
	
	Spawn:
		WM16 A 1
		TNT1 A 0 A_SpawnItemEx("M16Weapon", 0, 0, 0, momx, momy, momz)
		
		Stop
	
	Ready:
	Ready3:
		RIFG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		"----" # 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
        "----" # 0 A_JumpIfInventory("Reloading",1,"Reload")
		"----" # 0 A_JumpIfInventory("Kicking",1,"DoKick")
		"----" # 0 A_JumpIfInventory("UsedBandage", 1, "UseBandages")
		Loop
	
	Deselect:
		RIFG AAAAAA 1 A_Lower
		TNT1 A 1 A_Lower
		Wait

	
	Select:
		RIFG AAAAAA 1 A_Raise
		Goto Ready3
	
    Fire:
        RIFG A 0 A_JumpIfInventory("RifleAmmo",1,2)//First checks if the weapon has ammo
        Goto NoAmmo
        TNT1 AA 0
		RIFG A 0 A_AlertMonsters // Alerts monsters of the player's position
		RIFG A 0 A_PlaySound("M16FIRE", 1) //Play weapon fire sound on slot 1
		//SMGG A 0 A_PlaySound("FARM16", 6) //play a similar sound that can be heard further
		TNT1 A 0 A_JumpIFInventory("M16SingleSHot", 1, "Fire2") //checks if alt mode is activated
		
		RIFF A 1 A_FireBullets (1.5, 1.5, 1, 15, "HitPuff", FBF_NORANDOM) //fires the actual bullet (1.0, 1.0 are the horizontal and vertical spreads, 20 is the damage)
		RIFF B 1 A_FireCustomMissile("SmokeSpawner", random(-0.3,0.3), 0, 0, 0, 0, random(-0.3,0.3))
		RIFG A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
        RIFF A 0 A_FireCustomMissile("Tracer", random(-0.6,0.6), 0, 0, -5, 0, random(-0.6,0.6))
		RIFG A 0 A_ZoomFactor(0.98)
		RIFG A 0 A_SetPitch(pitch-0.5)
		RIFG A 0 A_SetANgle(angle-0.2)
		RIFG A 0 A_Takeinventory("RifleAmmo",1)
		RIFF C 1 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-14)
		RIFG A 0 A_SetPitch(pitch+0.1)
		RIFG A 0 A_SetANgle(angle+0.1)
		RIFG A 0 A_ZoomFactor(1.0)
		RIFG A 0 A_Refire
		Goto Ready3
	
Fire2:
		RIFF A 1 A_FireBullets (0.2, 0.2, -1, 15, "HitPuff", FBF_NORANDOM)
		RIFF B 1 A_FireCustomMissile("SmokeSpawner", random(-0.3,0.3), 0, 0, 0, 0, random(-0.3,0.3))
		RIFG A 0 A_SpawnItemEx("PlayerMuzzle1",30,5,30)
        RIFF A 0 A_FireCustomMissile("Tracer", 0, 0, 0, -5, 0, 0)
		RIFG A 0 A_ZoomFactor(0.98)
		RIFG A 0 A_SetPitch(pitch-0.6)
		RIFG A 0 A_SetANgle(angle-0.6)
		RIFG A 0 A_Takeinventory("RifleAmmo",1)
		RIFF C 1 A_FireCustomMissile("RifleCaseSpawn",5,0,6,-14)
		RIFG A 0 A_ZoomFactor(1.0)
		RIFG A 0 A_SetPitch(pitch+0.2)
		RIFG A 0 A_SetANgle(angle+0.2)
		RIFG A 1 A_WeaponReady
		RIFG A 0 A_SetPitch(pitch+0.2)
		RIFG A 0 A_SetANgle(angle+0.2)
		RIFG A 1 A_WeaponReady
		RIFG A 0 A_SetPitch(pitch+0.2)
		RIFG A 0 A_SetANgle(angle+0.2)
		RIFG A 5 A_WeaponReady
		RIFG A 0 A_Refire
		Goto Ready3
		
    AltFire:
		TNT1 A 0
		TNT1 A 0 A_JumpIFInventory("M16SingleSHot", 1, "StopAlt")
		TNT1 A 0 A_GiveInventory("M16SingleSHot", 1)
		TNT1 A 0 A_Print("Semi-Auto")
		TNT1 A 0 A_PlaySound("weapons/empty", 4)
		Goto Ready3
		
	StopAlt:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("M16SingleSHot", 1)
		TNT1 A 0 A_Print("Full-Auto")
		TNT1 A 0 A_PlaySound("weapons/empty", 4)
		Goto Ready3

	
    Reload:
		RIFG A 1 A_WeaponReady
		RIFG A 0 A_ZoomFactor(1.0)
		RIFG A 0 A_Takeinventory("Reloading",1)
		RIFG A 0 A_Takeinventory("ADSmode",1)
		RIFG A 0 A_Takeinventory("Zoomed",1)
		RIFG A 0 A_JumpIfInventory("RifleAmmo",19,76)
        RIFG A 0 A_JumpIfInventory("556",1,3)
        Goto FinishReloading
        TNT1 AAA 0
		RIFG A 0 A_Takeinventory("Zoomed",1)
		RIFG A 0 A_GiveInventory ("Pumping", 1)
		RIFG A 0 A_Takeinventory("Reloading",1)
		
		RIFG A 0
        RIFR ABCDEFFFF 1  A_JumpIfInventory("Kicking",1,"DoKick")
		TNT1 A 0 A_PLaySound("RELO1", 3)
		RIFR GHI 1
		TNT1 A 0 A_FireCustomMissile("EmptyClipSpawn",-5,0,8,-4)
		RIFR K 10
		TNT1 A 0 A_PLaySound("RELO2", 4)
        RIFR LM 1
		RIFG A 0 A_JumpIfInventory("RifleAmmo",1,"InsertBullets2")
		Goto InsertBullets
		
		
	InsertBullets:
		TNT1 AAAA 0
		RIFG A 0 A_JumpIfInventory("RifleAmmo",18,15)
		RIFG A 0 A_JumpIfInventory("556",1,3)
		Goto FinishReload3
        TNT1 AAAAAA 0
		RIFG A 0 A_Giveinventory("RifleAmmo",1)
		RIFG A 0 A_Giveinventory("DoubleRifleAmmo",1)
		RIFG A 0 A_Takeinventory("556",1)
		Goto InsertBullets
		
		TNT1 AAAAAAAAAA 0
		RIFG A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload3	
		TNT1 AAAA 0
		RIFG A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload3	
		
	InsertBullets2:
		TNT1 AAAA 0
		RIFG A 0 A_JumpIfInventory("RifleAmmo",19,15)
		RIFG A 0 A_JumpIfInventory("556",1,3)
		Goto FinishReload2	
        TNT1 AAAAAA 0
		RIFG A 0 A_Giveinventory("RifleAmmo",1)
		RIFG A 0 A_Giveinventory("DoubleRifleAmmo",1)
		RIFG A 0 A_Takeinventory("556",1)
		Goto InsertBullets2
		
		TNT1 AAAAAAAAAA 0
		RIFG A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload2	
		TNT1 AAAA 0
		RIFG A 0 A_Takeinventory("Reloading",1)
        Goto FinishReload2	
		
	FinishReloading:
		RIFG A 0
		RIFG A 0 A_Refire
		Goto Ready3
		
		

		
	FinishReload2:
		RIFR N 8
		RIFR OPQQPOROOOO 1
		RIFR EDCBA 1 A_JumpIfInventory("Kicking",1,"DoKick")
		RIFG A 0 A_Takeinventory("HasUnloaded",1)
		Goto Ready3
		

	FinishReload3:
		RIFR N 8
		RIFR OPQQPOROOOO 1
		RIFG A 0 A_Takeinventory("HasUnloaded",1)
		RIFR STUVV 1
		TNT1 A 0 A_PlaySound("RELO4", 1)
		RIFR VVUTSEDCBA 1
		Goto Ready3		
		
				
		
	NoAmmo:
		RIFG A 0
		RIFG A 0 A_ZoomFactor(1.0)
		RIFG A 0 A_Takeinventory("Zoomed",1)
		RIFG A 0 A_Takeinventory("ADSmode",1)
		TNT1 A 0 A_PlaySound("weapons/empty", 4)
	NoAmmo2:
		RIFG A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
        RIFG A 0 A_JumpIfInventory("Reloading",1,"Reload")
		RIFG A 0 A_JumpIfInventory("Kicking",1,"DoKick")
		RIFG A 5 A_WeaponReady(WRF_ALLOWRELOAD | WRF_NOPRIMARY)
		RIFG A 0 A_JumpIfInventory("Reloading",1,"Reload")
		TNT1 A 0 A_JumpIfInventory("NoAutoReload", 1, "NoAmmo2")
		RIFG A 0 A_JumpIfInventory("556",1,"Reload")
		Goto Ready3
	}
}

ACTOR RifleAmmo : Ammo
{
   Inventory.Amount 0
   Inventory.MaxAmount 21
   Ammo.BackpackAmount 0
   Ammo.BackpackMaxAmount 21
   Inventory.Icon "WM16A0"
}