actor "RPG-7" : RGUWeapon
{
  obituary "%k splattered %o with the RPG-7."
  inventory.pickupmessage "RPG-7"  
  //attacksound "m79/fire"
  weapon.selectionorder 20
  weapon.ammotype "RPGClip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "RPGAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0
  states
  {
  Ready:
    RPGA A 2 
    RPGA B 2 A_JumpIfNoAmmo("ReadyEmpty")
    RPGA CDEFGHI 2 A_WeaponReady(WRF_NOPRIMARY)
    RPGA I 0 A_JumpIfNoAmmo("Reload")
    RPGA I 0 A_JumpIfInventory("Aiming",1,5)
    RPGA I 0 A_JumpIfInventory("Reloading",1,"Reload")
    RPGA I 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    RPGA I 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGA I 1 A_WeaponReady
    goto Ready+9
    RPGB H 0 A_JumpIfInventory("Reloading",1,"Reload")    
    RPGB H 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    RPGB H 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGB H 1 A_WeaponReady(WRF_NOBOB)
    goto Ready+15
  ReadyEmpty:
    RPGE A 2 
    RPGE BCDEFGHI 2 A_WeaponReady(WRF_NOFIRE)
    RPGE I 0 A_JumpIfNoAmmo("Reload")
    RPGE I 0 A_JumpIfInventory("Aiming",1,5)
    RPGE I 0 A_JumpIfInventory("Reloading",1,"Reload")
    RPGE I 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    RPGE I 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGE I 1 A_WeaponReady
    goto ReadyEmpty+9
    RPGF H 0 A_JumpIfInventory("Reloading",1,"Reload")    
    RPGF H 0 A_JumpIfInventory("ThrowingGrenade",1,"FragGrenade")
    RPGF H 0 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGF H 1 A_WeaponReady(WRF_NOBOB)
    goto ReadyEmpty+15
  Deselect:
    RPGA N 0 A_JumpIfNoAmmo("DeselectEmpty")
    RPGA N 0 A_TakeInventory("Aiming",1)
    RPGA N 0 ACS_ExecuteAlways(602,0,0,0,0)
    RPGA N 0 A_TakeInventory("Reloading",1)
    RPGA N 0 A_ZoomFactor(1.0)
    RPGA N 0 A_Lower
    RPGA I 1 A_Lower
    goto Deselect+5
  DeselectEmpty:
    RPGE N 0 A_TakeInventory("Aiming",1)
    RPGE N 0 ACS_ExecuteAlways(602,0,0,0,0)
    RPGE N 0 A_TakeInventory("Reloading",1)
    RPGE N 0 A_ZoomFactor(1.0)
    RPGE N 0 A_Lower
    RPGE I 1 A_Lower
    goto Deselect+4
  Select:
    RPGA A 0 A_Raise
	RPGA A 0 ACS_ExecuteAlways(602,0,0,0,0)
	TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    loop
  Fire:
    RPGA A 0 A_JumpIfInventory("Aiming",1,11)
    RPGA I 1 A_JumpIfNoAmmo("ReloadStart")
    RPGA A 0 A_ZoomFactor(1.2)
    RPGB ABCDEFGH 2
    RPGC A 2
    RPGC A 0 A_TakeInventory("Aiming",1)
    RPGC A 0 ACS_ExecuteAlways(602,0,0,0,0)
    RPGC H 0 //A_PlayWeaponSound("at4/fire")
    TNT1 F 0 A_GiveInventory("InCombatCrosshair",35)
    TNT1 F 0 A_GiveInventory("InCombat", 5)
    RPGC H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,0,6)
    RPGC H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,-4,0)
    RPGC H 0 A_FireCustomMissile("WeaponSmokePuffLong",0,0,4,0)
    RPGC B 2 BRIGHT A_FireCustomMissile("RPGMissile",0,1,0,6)
    RPGC C 0 BRIGHT ACS_ExecuteAlways(600,0,0,0,0)
    RPGC C 2 BRIGHT A_GunFlash
    RPGC A 0 A_ZoomFactor(1.0)
    RPGC DEFGHI 2 BRIGHT 
    RPGC A 0 A_JumpIfInventory("RPGAmmo",1,2)
    RPGC A 0 A_ReFire
    goto ReadyEmpty+9
    RPGC A 0 A_JumpIfNoAmmo("ReloadStart")
    RPGC A 0 A_ReFire
    goto ReadyEmpty+9
  Hold:
    RPGA I 1 
    RPGA I 1 A_ReFire
    goto Ready+9
  Reload: //AltFire:
    RPGA A 0 A_JumpIfInventory("RPGAmmo",1,"ReloadStart")
    RPGA A 0 A_TakeInventory("Reloading",1)
    goto ReadyEmpty+12
  ReloadStart:
    RPGC A 0 A_JumpIfInventory("Aiming",1,"ReloadStartAim")
    RPGC A 0 A_JumpIfInventory("Perk1_SOH",1,"ReloadStart_SOH")
    RPGC I 3 A_PlaySoundEx("rpg/open","SoundSlot5")
    RPGC JKLMNOPQR 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGC S 3 A_PlaySoundEx("rpg/in","SoundSlot5")
    RPGC TUVWXY 3 A_WeaponReady(WRF_NOFIRE)
    RPGC Z 3 A_TakeInventory("Reloading",1)
    goto ReloadAmmo
  ReloadAmmo:
    RPGC P 0 A_GiveInventory("RPGClip",1)
    RPGC P 0 A_TakeInventory("RPGAmmo",1)
    RPGC P 0 A_JumpIfInventory("RPGClip",1,"ReloadEnd")
    RPGC P 0 A_JumpIfInventory("RPGAmmo",1,"ReloadAmmo")
    goto ReloadEnd
  ReloadEnd:
    RPGD ABCDEF 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGD GHIJKL 3 A_WeaponReady(WRF_NOFIRE)
    RPGD MNOPQR 3 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGD STU 3 A_WeaponReady(WRF_NOFIRE)
    RPGD G 0 A_ReFire
    goto Ready+9
  AltFire:
    RPGA A 0 A_JumpIfInventory("RPGClip",1,1)
    goto AltFireEmpty
    RPGB A 0 A_ZoomFactor(1.2)
    RPGB A 0 A_JumpIfInventory("Aiming",1,"AltFire2")
    RPGB ABCDEFGH 2
    RPGB G 0 A_GiveInventory("Aiming",1)
    RPGB G 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto Ready+15
  AltFireEmpty:
    RPGB A 0 A_ZoomFactor(1.2)
    RPGB A 0 A_JumpIfInventory("Aiming",1,"AltFire2Empty")
    RPGF ABCDEFGH 2
    RPGF G 0 A_GiveInventory("Aiming",1)
    RPGF G 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto ReadyEmpty+15
  AltFire2:
    RPGB A 0 A_ZoomFactor(1.0)
    RPGB HGFEDCBA 2
    RPGB A 0 A_TakeInventory("Aiming",1)
    RPGB A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto Ready+9
  AltFire2Empty:
    RPGB A 0 A_ZoomFactor(1.0)
    RPGF HGFEDCBA 2
    RPGF A 0 A_TakeInventory("Aiming",1)
    RPGF A 0 ACS_ExecuteAlways(602,0,0,0,0)
    goto ReadyEmpty+9
  ReloadStartAim:
    RPGF A 0 A_ZoomFactor(1.0)
    RPGF HGFEDCBA 2
    RPGF A 0 A_TakeInventory("Aiming",1)
    RPGF 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:
    WEP2 I 15
    TNT1 A 0 A_SpawnItem("RPGPickup")
    stop
  ReloadStart_SOH:
    RPGC I 2 A_PlaySoundEx("rpg/open","SoundSlot5")
    RPGC JKLMNOPQR 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGC S 2 A_PlaySoundEx("rpg/in","SoundSlot5")
    RPGC TUVWXY 2 A_WeaponReady(WRF_NOFIRE)
    RPGC Z 2 A_TakeInventory("Reloading",1)
    goto ReloadAmmo_SOH
  ReloadAmmo_SOH:
    RPGC P 0 A_GiveInventory("RPGClip",1)
    RPGC P 0 A_TakeInventory("RPGAmmo",1)
    RPGC P 0 A_JumpIfInventory("RPGClip",1,"ReloadEnd_SOH")
    RPGC P 0 A_JumpIfInventory("RPGAmmo",1,"ReloadAmmo_SOH")
    goto ReloadEnd_SOH
  ReloadEnd_SOH:
    RPGD ABCDEF 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGD GHIJKL 2 A_WeaponReady(WRF_NOFIRE)
    RPGD MNOPQR 2 A_JumpIfInventory("KnifeAttack",1,"KnifeAttack")
    RPGD STU 2 A_WeaponReady(WRF_NOFIRE)
    RPGD G 0 A_ReFire
    goto Ready+9
  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 RPGClip : Ammo
{
    inventory.icon "CLIPA0"
    inventory.amount 0
    inventory.maxamount 1
    ammo.backpackamount 0
    ammo.backpackmaxamount 1
    +IGNORESKILL
}

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

actor RPGMissile
{
  obituary "%k splattered %o with the RPG-7."
  radius 5
  height 5
  speed 50
  damage (175)
  seesound "at4/fire"
  deathsound "generic/fleshhit"
  PROJECTILE
  +RANDOMIZE
  +NOEXTREMEDEATH
  +FORCERADIUSDMG
  Scale 0.05
  damagetype "Explosion"
  -NOTELEPORT
  states
  {
  Spawn:
    G69X AAAAAAAAAA 1 A_SpawnItemEx("WeaponSmokePuffLong", 0, 0, 0, 0, 0, 0, 0, 128, 0)
    G69X A 0 //ThrustThingZ(0,random(0,5),random(0,1),1)
    G69X A 0 //ThrustThing((angle*256/360)+(random(-5,5)), 5, 0, 0)
    Loop
  XDeath:
    TNT1 A 0 
    TNT1 A 0 A_GiveToTarget("HitIndicator",1)
  Death:
    TNT1 A 0 
	TNT1 A 0 A_RadiusThrust(160,128)
    TNT1 A 0 Radius_Quake(3,30,0,128,0)
    TNT1 A 0 A_AlertMonsters
    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(350,40)
    TNT1 A 0 A_Explode(150,80)
    TNT1 A 0 A_Explode(80,200,0)
    TNT1 A 20
    stop
  DangerClosePro:
    TNT1 A 0 A_Explode(350,60)
    TNT1 A 0 A_Explode(150,120)
    TNT1 A 0 A_Explode(80,300,0)
    TNT1 A 20
	stop
  }
}

actor RPGPickup : CustomInventory
{
  inventory.pickupmessage "RPG-7"  
  inventory.pickupsound "misc/w_pkup"
  +INVENTORY.AUTOACTIVATE
  inventory.respawntics 35
  scale 0.15
  States
  {
  Spawn:
    WEP2 I -1
    stop
  Pickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("RPG-7",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,35,0,0)
    stop
  AmmoPickup:
    JDGP A 0
    JDGP A 0 A_JumpIfInventory("RPGAmmo",0,"FailPickup")
    JDGP A 0 A_GiveInventory("RPGAmmo",1)
    stop
  FailPickup:
    WEP2 I 1
    fail
  FailPickup2:
    WEP2 I 1 
    WEP2 A 0 ACS_ExecuteAlways(620,0,4,0,0)
    fail
  }
}
