ACTOR SwatRifle : Weapon
{
    Inventory.PickupMessage "Picked up the UAC Standard Battle Rifle."
    Obituary "%o was resisting %k's arrest."
    Tag "Standard Issue M4A1"
    Weapon.AmmoGive2 30
    Weapon.AmmoType1 "SWATAssaultRifleRounds"   // Reserve pool
    Weapon.AmmoType2 "RifleMagazineMag"     // Clip
    +WEAPON.AMMO_OPTIONAL                   // Allow fire if Ammo2 exists
    Decal "BulletChip"
    AttackSound "weapons/UACBR"
    Inventory.RestrictedTo "SwatClass"

    States
    {
    Spawn:
        M4RS C -1
        Loop
    Ready:
        M4RS A 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWZOOM)
        Loop
    Select:
        M4RS A 1 A_Raise
        TNT1 A 0 A_Raise
        TNT1 A 0 A_Raise
        Loop
    Deselect:
        M4RS A 1 A_Lower
        TNT1 A 0 A_Lower
        TNT1 A 0 A_Lower
        Loop
    Fire:
        TNT1 A 0 A_JumpIfInventory("RifleMagazineMag", 1, "DoFire")
        Goto Reload // Out of clip
    DoFire:
        TNT1 A 0 A_GunFlash
        TNT1 A 0 A_TakeInventory("RifleMagazineMag", 1)
        M4RS A 2 A_FireBullets(3, 2, 1, 15, "BulletPuff", FBF_NoRANDOM, 8192)
        M4RS B 2
        M4RS A 2 A_JumpIfInventory("RifleMagazineMag", 1, "Fired")
        Goto Reload
    Fired:
        M4RS A 1 A_ReFire
        Goto Ready
    Reload:
        TNT1 A 0 A_JumpIfInventory("RifleMagazineMag", 30, "Ready")
        TNT1 A 0 A_JumpIfInventory("SWATAssaultRifleRounds", 1, "StartReload")
        Goto Ready
    StartReload:

        M4RS F 2 A_CheckReload
        M4RS G 2
        M4RS H 2
        M4RS I 2
        M4RS O 2 A_PlaySound("UACMO")
        M4RS N 2
        M4RS M 2
        M4RS L 3
        M4RS K 4
        M4RS J 6 A_PlaySound("CLOTH")
        M4RS K 4
        M4RS L 3
        M4RS M 2
        M4RS N 2 A_PlaySound("UACMI")
        M4RS O 2
        M4RS P 2
        M4RS I 2 
        M4RS H 2 
        M4RS G 2
        M4RS F 2 A_ResetReloadCounter
        Goto ReloadLoop
    ReloadLoop:
        TNT1 A 0 A_JumpIfInventory("RifleMagazineMag", 30, "ReloadDone")
        TNT1 A 0 A_JumpIfInventory("SWATAssaultRifleRounds", 1, "ReloadOne")
        Goto ReloadDone
    ReloadOne:
        TNT1 A 0 A_TakeInventory("SWATAssaultRifleRounds", 1)
        TNT1 A 0 A_GiveInventory("RifleMagazineMag", 1)
        Goto ReloadLoop
    ReloadDone:
        M4RS F 2 A_ReFire
        Goto Ready
    Flash:
        M4RS D 1 Bright A_Light0
        M4RS E 1 Bright A_Light1
        Goto LightDone
  Zoom:
    TNT1 A 0 A_JumpIfInventory("HasSwatGrenades", 1, "CheckAmmo")
    Goto DontThrow
  CheckAmmo:
    TNT1 A 0 A_JumpIfInventory("SwatGrenadeAmmo", 1, "DoThrow")
    Goto DontThrow
  DoThrow:
    TNT1 A 0
    Goto ThrowFrag
	ThrowFrag:
	FGGN BCD 2
	TNT1 A 0 A_TakeInventory("SwatGrenadeAmmo", 1) // ONLY grenade ammo removed
	FGGN E 2 A_PlaySound("weapons/grnpullpin")
	FGGN FGHH 2
	FGGN J 0 A_FireCustomMissile("ThrownGrenade30", 0, 0, 0, 0)
	FGGN J 0 A_PlaySound("weapons/grntoss")
	FGGN JKLMNOPQ 2
	FGGN A 0
	NULL A 12 A_CheckReload
		Goto RaiseAfterThrow
	RaiseAfterThrow:
    M4RS A 1 Offset(0, 60)
    M4RS A 1 Offset(0, 50)
    M4RS A 1 Offset(0, 40)
		Goto Ready
	DontThrow:
		M4RS A 1
		Goto Ready
    }
}

ACTOR UpgradedSwatRifle : Weapon
{
    Inventory.PickupMessage "Picked up the UAC Standard Battle Rifle."
    Obituary "%o was resisting %k's arrest and had to use Lethal Force."
    Tag "Modified M4A1"
    Weapon.AmmoUse 1
    Weapon.AmmoGive2 60
    Weapon.AmmoType1 "SWATAssaultRifleRounds"   // Reserve pool
    Weapon.AmmoType2 "UpgradedRifleMagazineMag"     // Clip
    +WEAPON.AMMO_OPTIONAL                   // Allow fire if Ammo2 exists
    Decal "BulletChip"
    AttackSound "weapons/UACBR"
    Inventory.RestrictedTo "SwatClass"

    States
    {
    Spawn:
        M4RS C -1
        Loop
    Ready:
        M4RS A 1 A_WeaponReady(WRF_ALLOWRELOAD|WRF_ALLOWZOOM)
        Loop
    Select:
        M4RS A 1 A_Raise
        TNT1 A 0 A_Raise
        TNT1 A 0 A_Raise
        Loop
    Deselect:
        M4RS A 1 A_Lower
        TNT1 A 0 A_Lower
        TNT1 A 0 A_Lower
        Loop
    Fire:
        TNT1 A 0 A_JumpIfInventory("UpgradedRifleMagazineMag", 1, "DoFire")
        Goto Reload // Out of clip
    DoFire:
        TNT1 A 0 A_GunFlash
        TNT1 A 0 A_TakeInventory("UpgradedRifleMagazineMag", 1)
        M4RS A 1 A_FireBullets(3, 2, 1, 30, "BulletPuff", FBF_NoRANDOM, 8192)
        M4RS B 1
        M4RS A 1 A_JumpIfInventory("UpgradedRifleMagazineMag", 1, "Fired")
        Goto Reload
    Fired:
        M4RS A 1 A_ReFire
        Goto Ready
    Reload:
        TNT1 A 0 A_JumpIfInventory("UpgradedRifleMagazineMag", 60, "Ready") // Full
        TNT1 A 0 A_JumpIfInventory("SWATAssaultRifleRounds", 1, "StartReload")
        Goto Ready // No ammo
    StartReload:
        // Full reload animation
        M4RS F 1 A_CheckReload
        M4RS G 1
        M4RS H 1
        M4RS I 1
        M4RS O 1 A_PlaySound("UACMO")
        M4RS N 1
        M4RS M 1
        M4RS L 2
        M4RS K 3
        M4RS J 4 A_PlaySound("CLOTH")
        M4RS K 3
        M4RS L 2
        M4RS M 1
        M4RS N 1 A_PlaySound("UACMI")
        M4RS O 1
        M4RS P 1
        M4RS I 1 
        M4RS H 1 
        M4RS G 1
        M4RS F 1 A_ResetReloadCounter
        Goto ReloadLoop
    ReloadLoop:
        // Refill mag by 1 until full or no more reserve
        TNT1 A 0 A_JumpIfInventory("UpgradedRifleMagazineMag", 60, "ReloadDone")
        TNT1 A 0 A_JumpIfInventory("SWATAssaultRifleRounds", 1, "ReloadOne")
        Goto ReloadDone // No reserve left
    ReloadOne:
        TNT1 A 0 A_TakeInventory("SWATAssaultRifleRounds", 1)
        TNT1 A 0 A_GiveInventory("UpgradedRifleMagazineMag", 1)
        Goto ReloadLoop
    ReloadDone:
        M4RS F 2 A_ReFire
        Goto Ready
    Flash:
        M4RS D 1 Bright A_Light0
        M4RS E 1 Bright A_Light1
        Goto LightDone
  Zoom:
    TNT1 A 0 A_JumpIfInventory("HasSwatGrenades", 1, "CheckAmmo")
    Goto DontThrow
  CheckAmmo:
    TNT1 A 0 A_JumpIfInventory("SwatGrenadeAmmo", 1, "DoThrow")
    Goto DontThrow
  DoThrow:
    TNT1 A 0
    Goto ThrowFrag
	ThrowFrag:
	FGGN BCD 2
	TNT1 A 0 A_TakeInventory("SwatGrenadeAmmo", 1) // ONLY grenade ammo removed
	FGGN E 2 A_PlaySound("weapons/grnpullpin")
	FGGN FGHH 2
	FGGN J 0 A_FireCustomMissile("ThrownGrenade30", 0, 0, 0, 0)
	FGGN J 0 A_PlaySound("weapons/grntoss")
	FGGN JKLMNOPQ 2
	FGGN A 0
	NULL A 12 A_CheckReload
		Goto RaiseAfterThrow
	RaiseAfterThrow:
    M4RS A 1 Offset(0, 60)
    M4RS A 1 Offset(0, 50)
    M4RS A 1 Offset(0, 40)
		Goto Ready
	DontThrow:
		M4RS A 1
		Goto Ready
    }
}

ACTOR RifleMagazineMag : Ammo
{
	Inventory.Amount 0
	Inventory.MaxAmount 30
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 30
}

ACTOR UpgradedRifleMagazineMag : Ammo
{
	Inventory.Amount 0
	Inventory.MaxAmount 60
	Ammo.BackpackAmount 0
	Ammo.BackpackMaxAmount 60
}


Actor SWATAssaultRifleRounds : Ammo
{
	Inventory.Amount 30
	Inventory.Maxamount 300
	Ammo.Backpackmaxamount 0
	Ammo.Backpackmaxamount 600
}