actor "Thumper" : RGUWeapon
{
  obituary "%k thumped %o with the Thumper."
  inventory.pickupmessage "Thumper"  
  //attacksound "m79/fire"
  weapon.selectionorder 20
  weapon.ammotype "ThumperClip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "ThumperAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  states
  {
  Ready:
    M79A A 2 //A_PlayWeaponSound("m79/select")
    M79A BCDEFGHIJKLMN 2 A_WeaponReady(WRF_NOPRIMARY)
    M79A N 0 A_JumpIfNoAmmo("Reload")
    M79A N 0 A_JumpIfInventory("Aiming",1,5)
    M79A N 0 A_JumpIfInventory("Reloading",1,"Reload")
    M79A N 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    M79A N 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79A N 1 A_WeaponReady
    goto Ready+14
    M79B H 0 A_JumpIfInventory("Reloading",1,"Reload")    
    M79B H 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    M79B H 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79B H 1 A_WeaponReady(WRF_NOBOB)
    goto Ready+20
  Deselect:
    M79A L 0 A_TakeInventory("Aiming",1)
    M79A A 0 ACS_ExecuteAlways(602,0,0,0,0)
    SPSA L 0 A_TakeInventory("Reloading",1)
    INTA L 0 A_ZoomFactor(1.0)
    M79A L 0 A_Lower
    M79A L 1 A_Lower
    goto Deselect+2
  Select:
    M79A A 0 A_Raise
	M79A A 0 ACS_ExecuteAlways(602,0,0,0,0)
	TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    loop
  Fire:	
    M79A A 0 A_JumpIfInventory("Aiming",1,10)
    M79A N 1 A_JumpIfNoAmmo("ReloadStart")
    U45F A 0 A_ZoomFactor(1.2)
    M79B ABCDEFGH 2
    M79B A 0 A_TakeInventory("Aiming",1)
    M79A A 0 ACS_ExecuteAlways(602,0,0,0,0)
    M79B H 0 A_PlayWeaponSound("m79/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    M79B H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,0,6)
    M79B H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,-4,0)
    M79B H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,4,0)
    M79B I 2 BRIGHT A_FireCustomMissile("ThumperShell",0,1,0,6)
    M79B I 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    M79B JK 2 BRIGHT A_GunFlash
    U45F A 0 A_ZoomFactor(1.0)
    M79B LMNOPQR 2
    M79B A 0 A_JumpIfInventory("ThumperAmmo",1,2)
    M79B A 0 A_ReFire
    goto Ready+14
    U45C A 0 A_JumpIfNoAmmo("ReloadStart")
    U45C A 0 A_ReFire
    goto Ready+14
  Hold:
    M79A N 1 
    M79A N 1 A_ReFire
    goto Ready+14
  Reload: //AltFire:
    M79A A 0 A_JumpIfInventory("ThumperAmmo",1,"ReloadStart")
    M79A A 0 A_TakeInventory("Reloading",1)
    goto Ready+17
  ReloadStart:
    M79C A 0 A_JumpIfInventory("Aiming",1,"ReloadStartAim")
    M79C A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    M79C A 3 A_PlaySoundEx("m79/open","SoundSlot5")
    M79C BCDEFGHI 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79C J 3 A_PlaySoundEx("m79/out","SoundSlot5")
    M79C KLMNOPQR 3 A_WeaponReady(WRF_NOFIRE)
    M79C S 3 A_TakeInventory("Reloading",1)
    M79C T 3 A_PlayWeaponSound("m79/in")
    goto ReloadAmmo
  ReloadAmmo:
    M79C P 0 A_GiveInventory("ThumperClip",1)
    M79C P 0 A_TakeInventory("ThumperAmmo",1)
    M79C P 0 A_JumpIfInventory("ThumperClip",1,"ReloadEnd")
    M79C P 0 A_JumpIfInventory("ThumperAmmo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    M79C UVWXYZ 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79D A 3 A_WeaponReady(WRF_NOFIRE)
    M79D B 3 A_PlaySound("m79/close")
    M79D C 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79D G 0 A_ReFire
    goto Ready+14
  AltFire:
    U45F A 0 A_ZoomFactor(1.2)
    M79B A 0 A_JumpIfInventory("Aiming",1,"AltFire2")
    M79B ABCDEFGH 2
    M79B G 0 A_GiveInventory("Aiming",1)
    M79B G 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto Ready+20
  AltFire2:
    U45F A 0 A_ZoomFactor(1.0)
    M79B HGFEDCBA 2
    M79B A 0 A_TakeInventory("Aiming",1)
    M79B A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto Ready+14
  ReloadStartAim:
    U45F A 0 A_ZoomFactor(1.0)
    M79B HGFEDCBA 2
    M79B A 0 A_TakeInventory("Aiming",1)
    M79B A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto ReloadStart+1
  Flash:
    TNT1 A 2 bright A_Light1
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
    WEAP N 15
    TNT1 A 0 A_SpawnItem("ThumperPickup")
    stop
  ReloadStart_SOH:
    M79C A 2 A_PlaySoundEx("m79/open","SoundSlot5")
    M79C BCDEFGHI 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79C J 2 A_PlaySoundEx("m79/out","SoundSlot5")
    M79C KLMNOPQR 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79C S 2 A_TakeInventory("Reloading",1)
    M79C T 2 A_PlayWeaponSound("m79/in")
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    M79C P 0 A_GiveInventory("ThumperClip",1)
    M79C P 0 A_TakeInventory("ThumperAmmo",1)
    M79C P 0 A_JumpIfInventory("ThumperClip",1,"ReloadEnd_SOH")
    M79C P 0 A_JumpIfInventory("ThumperAmmo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    M79C UVWXYZ 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79D A 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79D B 2 A_PlaySound("m79/close")
    M79D C 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    M79D G 0 A_ReFire
    goto Ready+14
  FragGrenade:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"FragGrenade_SOH")
    GRNA A 2 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 2
    TNT1 A 15 
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 2
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 2 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 2 
    goto Ready+1
  FragGrenade_SOH:
    GRNA A 1 A_PlaySound("grenade/pinpull")
    GRNA BCDEFGH 1
    TNT1 A 10
    TNT1 A 0 A_PlaySound("grenade/throw")
    GRNA A 0 A_PlaySoundEx("us/grenades","Voice")
    GRNA IJK 1
    GRNA L 0 A_TakeInventory("FragGrenadeAmmo",1)
    GRNA L 0 A_TakeInventory("ThrowingGrenade",1)
    U45A L 0 A_TakeInventory("Aiming",1)
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    GRNA L 1 A_FireCustomMissile("FragGrenade",0,0,0,16)
    GRNA MN 1 
    goto Ready+1
  KnifeAttack:
    U45F A 0 A_ZoomFactor(1.0)
    U45A L 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    U45A L 0 A_TakeInventory("Aiming",1)
    U45A L 0 A_TakeInventory("Reloading",1)
    U45F A 0 ACS_ExecuteAlways(602,0,0,0,0)
    U45A L 0 A_JumpIfInventory("Perk1_SOH_Pro",1,"KnifeAttack_SOH")
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 20
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH:
    U45C A 0 A_JumpIfInventory("Perk3_Commando",1,"KnifeAttack_SOH_Commando")
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",96)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  KnifeAttack_SOH_Commando:
    KNFA A 0 ACS_ExecuteAlways(599,0,0,0,0)
    KNFA AB 1
    KNFA B 0 A_PlaySound("knife/swing")
    KNFA CDE 1 A_CustomPunch(34,1,0,"KnifePuff",160)
    KNFA FGHIJKL 1 
    TNT1 A 10
    GRNA L 0 A_TakeInventory("KnifeAttack",1)
    goto Ready+1
  }
}

actor ThumperClip : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 1
    ammo.backpackamount 0
    ammo.backpackmaxamount 1
    +IGNORESKILL
}

actor ThumperAmmo : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 3
    ammo.backpackamount 1
    ammo.backpackmaxamount 6
    +IGNORESKILL
}

actor ThumperShell
{
  obituary "%k thumped %o with the Thumper."
  radius 5
  height 5
  speed 45
  damage (45)
  deathsound "generic/fleshhit"
  PROJECTILE
  -NOGRAVITY
  +RANDOMIZE
  +NOEXTREMEDEATH
  +FORCERADIUSDMG
  +CANBOUNCEWATER
  -NOTELEPORT
  Scale 0.05
  gravity 0.4
  bouncefactor 0.5
  DamageType "Explosion"
  states
  {
  Spawn:
    G69X AAAAAA 1 A_SpawnItemEx("FlightSmokePuff", 0, 0, 0, 0, 0, 0, 0, 128, 0)
    G69X A 0 A_GiveInventory("M203Armed",1)
    Loop
  XDeath:
    TNT1 A 0 
    TNT1 A 0 A_GiveToTarget("HitIndicator",1)
  Death:
    TNT1 A 0 A_JumpIfInventory("M203Armed",1,"DeathArmed")
    TNT1 A 0 A_Explode(250,16,0)
    TNT1 A 20 A_SpawnItemEx("M203ShellUnarmedDrop",0,0,0,-2,0,2,random(-8,8),0,0)
    stop
  DeathArmed:
    TNT1 AAAA 0 A_SpawnItemEx("ExplosionMain",random(-8,8),random(-8,8),0,0,0,0,0,0,0)
    TNT1 AAAAAAAAAA 0 A_SpawnItemEx("ImpactSpark2", random(-32,32), random(-32,32), random(-32,32), random(-5,5), random(-5,5), random(-1,5), 0, 128, 0)
    TNT1 AAAAAAAAAA 0 A_SpawnItemEx("ImpactSpark2", random(-32,32), random(-32,32), random(-32,32), random(-5,5), random(-5,5), random(-1,5), 0, 128, 0)
	TNT1 A 0 A_JumpIfInTargetInventory("Perk2_DangerClose_Pro", 1, "DangerClosePro")
    TNT1 A 0 A_Explode(150,80)
    TNT1 A 0 A_Explode(80,135)
	TNT1 A 20
    stop
  DangerClosePro:
    TNT1 A 0 A_Explode(150,125)
    TNT1 A 0 A_Explode(80,200)
	TNT1 A 20
	stop
  }
}

actor ThumperPickup : CustomInventory
{
  inventory.pickupmessage "Thumper"  
  inventory.pickupsound "misc/w_pkup"
  +INVENTORY.AUTOACTIVATE
  inventory.respawntics 35
  scale 0.15
  States
  {
  Spawn:
    WEAP N -1
    stop
  Pickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("Thumper",1,"FailPickup") // If the player already has this weapon, they get more ammo for it
    JDGP A 0 A_JumpIfInventory("MaxWeaponsFilled",0,"FailPickup2")
    BKPK A 0 ACS_ExecuteWithResult(618,23,0,0)
    stop
  AmmoPickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("ThumperAmmo",0,"FailPickup")
    JDGP A 0 A_GiveInventory("ThumperAmmo",1)
    stop
  FailPickup:
    WEAP N 1
    fail
  FailPickup2:
    WEAP N 1 
    BKPK A 0 ACS_ExecuteAlways(620,0,4,0,0)
    fail
  }
}
