
ACTOR RLChaingun : RLWeapon
{
  Obituary "%o was perforated by %k's chaingun."
  Decal BulletChip
  Tag "Chaingun"
  Weapon.SelectionOrder 25
  Weapon.SlotNumber 4
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLChaingunClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "MGUNICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_TakeInventory("RLChaingunState",1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunNanoMod",1,2)
    PKCG A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto Ready+1
  NanoRegenCheck:
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",1,2)
    PKCG A 70 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	Goto NanoRegenCheckBegin+1
  NanoRegenCheckBegin:
    PKCG A 70 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 40, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 52, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",3,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 64, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",4,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 76, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 88, "Ready")
	Goto NanoRegen
  NanoRegen:
	TNT1 A 0 A_GiveInventory("RLChaingunClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunNanoMod",2,2)
    PKCG A 17 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto NanoRegenCheckBegin+1
    PKCG A 9 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto NanoRegenCheckBegin+1
	
  ScavengerDrop:
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"WeaponDropConfirm")
	TNT1 A 0 A_GiveInventory("RLScavengerDrop",1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunModLimit",1,2)
	TNT1 A 0 A_Print("Press again to drop current weapon.")
	Goto AfterModDrop
	TNT1 A 0 A_Print("Press again to drop current weapon,\nor press \crAlt Fire\c- to scrap it to retrieve a Mod Pack.")
	Goto AfterModDrop
  WeaponDropConfirm:
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLChaingunPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLChaingunPickupModded", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_TakeInventory("RLGatlingGunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBulletstormChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLAssaultRifleChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBurstCannonChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 1 A_TakeInventory("RLChaingun",1)
	Stop
	
  AfterModDrop:
    PKCG A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    PKCG A 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
	
  Deselect:
	TNT1 A 0
	TNT1 A 0 A_GiveInventory("RLDeselectionFunction",1)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 A 0 A_Lower
    PKCG A 1 A_Lower
    Loop
  DeselectRenegade:
    TNT1 A 0 A_Lower
    loop
  SelectRenegade: 
    TNT1 A 0 A_Raise
    loop
  SelectSetWeapon:
	TNT1 A 0 A_GiveInventory("RLRapidfireTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLStandardWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLChaingunSelected", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_Raise
    PKCG A 1 A_Raise
    Loop
	
  Fire:
	TNT1 A 0 A_JumpIfInventory("RLGatlingGunConfirm",1, "AssembleGatlingGun")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunConfirm",1, "AssembleHighPowerChaingun")
	TNT1 A 0 A_JumpIfInventory("RLBulletstormChaingunConfirm",1, "AssembleBulletstormChaingun")
	TNT1 A 0 A_JumpIfInventory("RLAssaultRifleChaingunConfirm",1, "AssembleAssaultRifleChaingun")
	TNT1 A 0 A_JumpIfInventory("RLBurstCannonChaingunConfirm",1, "AssembleBurstCannonChaingun")
	TNT1 A 0 A_JumpIfInventory("RLNanoManufactureAmmoChaingunConfirm",1, "AssembleNanoManufactureAmmoChaingun")
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoChaingunConfirm",1, "AssembleDemolitionAmmoChaingun")
	
	PKCG A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	PKCG A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	PKCG A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	PKCG A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	PKCG A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfNoAmmo("Reload")
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FirePP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FireAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FirePP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",3,"FirePPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FirePPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FirePA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FirePPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FirePAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FirePAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",3,"FireAAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5, 1, -1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5, 1, -1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FirePPP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",4,"FirePPPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FirePPPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, 9, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, 9, "RLBulletPuff", 0)
    Goto FireFinish
  FirePPA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",3,"FirePPPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FirePPAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FirePAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FirePPAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",3,"FirePAAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5, 1, -1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5, 1, -1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireAAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FirePAAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",4,"FireAAAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4.5, 0.5, -1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4.5, 0.5, -1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FirePPPP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, 10, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, 10, "RLBulletPuff", 0)
    Goto FireFinish
  FirePPPA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 9, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, 9, "RLBulletPuff", 0)
    Goto FireFinish
  FirePPAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5, 1, -1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5, 1, -1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FirePAAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4.5, 0.5, -1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4.5, 0.5, -1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireAAAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, -1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, -1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireS:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSS")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireSP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireSA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSS:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireSSP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireSSA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSSP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FireSPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireSPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireSA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSSA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireSPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FireSAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSSP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FireSSPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireSSPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireSSA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireSSPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FireSSAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSPP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSSPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",3,"FireSPPP")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",1,"FireSPPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FireSPA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSSPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",2,"FireSPPA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",2,"FireSPAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireSAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunSniperMod",2,"FireSSAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunPowerMod",1,"FireSPAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAgilityMod",3,"FireSAAA")
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSSPP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FireSSAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
  FireSSPA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireSPPP:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, 9, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, 9, "RLBulletPuff", 0)
    Goto FireFinish
  FireSPPA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 8, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.5, 0, 1, 8, "RLBulletPuff", 0)
    Goto FireFinish
  FireSPAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3, 0, 1, 7, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3, 0, 1, 7, "RLBulletPuff", 0)
    Goto FireFinish
  FireSAAA:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (2.5, 0, 1, 6, "RLBulletPuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (2.5, 0, 1, 6, "RLBulletPuff", 0)
    Goto FireFinish
	
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/chaingun", CHAN_WEAPON, 1, 0, 0.7)
    TNT1 A 0 A_PlaySound("weapons/chaingun", 7, 0.05, 0, 0.20)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,"FireFinishPowerupCheck") // Check for powerups.
  FireFinishPowerupCheckDone: // No valid powerups detected.
	TNT1 A 0 A_JumpIfInventory("RLChaingunFirestormMod",2,"FireFinishFF")
	TNT1 A 0 A_JumpIfInventory("RLChaingunFirestormMod",1,"FireFinishF")
    TNT1 A 0 A_SpawnItemEx ("RLChaingunRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    PKCG E 1 A_GunFlash
    PKCG FGH 1
	Goto FireFinishContinue
  FireFinishF:
    TNT1 A 0 A_SpawnItemEx ("RLUziRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    PKCG E 1 A_GunFlash
    PKCG FG 1
    Goto FireFinishContinue
  FireFinishFF:
    TNT1 A 0 A_SpawnItemEx ("RLThompsonRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    PKCG E 1 A_GunFlash ("FlashFF")
    PKCG G 1
    Goto FireFinishContinue

//-------------------------------------------------------------------------------------------------
  FireFinishPowerupCheck: // Marine fires one Firestorm's worth faster while affected by powerups.
	TNT1 A 0 A_JumpIfInventory("PowerInvulnerable",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInvisibility",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerIronFeet",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerLightAmp",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerInfiniteAmmo",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerDrain",1,"FireFinishPowerupCheckConfirmed")
	TNT1 A 0 A_JumpIfInventory("PowerRLBerserkResistance",1,"FireFinishPowerupCheckConfirmed")
	Goto FireFinishPowerupCheckDone
  FireFinishPowerupCheckConfirmed:
	TNT1 A 0 A_JumpIfInventory("RLChaingunFirestormMod",1,"FireFinishFF")
	Goto FireFinishF
//-------------------------------------------------------------------------------------------------
  
  FireFinishContinue:
	TNT1 A 0 A_JumpIfInventory("RLChaingunAmmochain",0,2)
	TNT1 A 0 A_Jump(256,6)
	TNT1 A 0 A_TakeInventory("RLChaingunAmmochain",0)
	TNT1 A 0 A_JumpIfInventory("RLChaingunState",1,2)
	TNT1 A 0 A_GiveInventory("RLChaingunState",1)
    Goto Fire
	TNT1 A 0 A_TakeInventory("RLChaingunState",1)
    TNT1 A 0 A_ReFire
    Goto WinddownMain
	TNT1 A 0 A_GiveInventory("RLChaingunAmmochain",1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunState",1,2)
	TNT1 A 0 A_GiveInventory("RLChaingunState",1)
    Goto Fire
	TNT1 A 0 A_TakeInventory("RLChaingunState",1)
    TNT1 A 0 A_ReFire
    Goto WinddownMain
	
  WinddownMain:
    TNT1 A 0 A_PlaySound("weapons/chaingunwinddown", 6, 1, 0, 1.8)
	TNT1 A 0 A_JumpIfNoAmmo("WinddownNoAmmo")
	PKCG A 1 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueA")
	PKCG B 1 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueB")
	PKCG C 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueC")
	PKCG D 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueD")
	PKCG A 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueA")
	PKCG B 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueB")
	PKCG C 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueC")
	PKCG D 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueD")
    Goto Ready
  WinddownNoAmmo:
	PKCG AB 1
	PKCG CDA 2
	PKCG BCD 3
    Goto Ready
  WinddownContinueA:
	PKCG ABCD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueB:
	PKCG BCD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueC:
	PKCG CD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueD:
	PKCG D 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
	
  Reload:
	PKCG A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 40, "Ready")
	Goto ReloadStartAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 52, "Ready")
	Goto ReloadStartAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",3,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 64, "Ready")
	Goto ReloadStartAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",4,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 76, "Ready")
	Goto ReloadStartAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip", 88, "Ready")
  ReloadStartAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
	Goto Ready
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",4,"Reload4")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",3,"Reload3")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",2,"Reload2")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",1,"Reload1")
    PKCR A 2
    PKCR B 2
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingununload", CHAN_ITEM)
    PKCR C 2
    PKCR D 2
    PKCR E 2
    PKCR F 2
    PKCR G 2
    PKCR H 5
	Goto ReloadWorking
  Reload1:
    PKCR A 1
    PKCR B 1
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingununload", CHAN_ITEM)
    PKCR C 1
    PKCR D 2
    PKCR E 2
    PKCR F 2
    PKCR G 2
    PKCR H 5
	Goto ReloadWorking
  Reload2:
    PKCR A 1
    PKCR B 1
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingununload", CHAN_ITEM)
    PKCR C 1
    PKCR D 1
    PKCR E 1
    PKCR F 1
    PKCR G 2
    PKCR H 5
	Goto ReloadWorking
  Reload3:
    PKCR A 1
    PKCR B 1
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingununload", CHAN_ITEM)
    PKCR C 1
    PKCR D 1
    PKCR E 1
    PKCR F 1
    PKCR G 1
    PKCR H 3
	Goto ReloadWorking
  Reload4:
    PKCR B 1
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingununload", CHAN_ITEM)
    PKCR C 1
    PKCR D 1
    PKCR E 1
    PKCR F 1
    PKCR H 2
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Clip", 1)
	TNT1 A 0 A_GiveInventory("RLChaingunClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",40,9)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",52,7)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",3,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",64,5)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunBulkMod",4,2)
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",76,3)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLChaingunClip",88,2)
  ReloadWorkingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Clip",1,2)
	TNT1 A 0
	Goto ReloadFinish
	TNT1 A 0
	Goto ReloadWorking
  ReloadFinish:
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 0 A_PlaySound("weapons/chaingunload", CHAN_WEAPON)
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",4,"ReloadFinish4")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",3,"ReloadFinish3")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",2,"ReloadFinish2")
	TNT1 A 0 A_JumpIfInventory("RLChaingunTechnicalMod",1,"ReloadFinish1")
    PKCR J 2
    PKCR I 2
    PKCR H 2
    PKCR G 2
    PKCR F 2
    PKCR E 2
    PKCR D 2
    PKCR C 2
    PKCR B 2
    PKCR A 2
	Goto WinddownMain
  ReloadFinish1:
    PKCR J 1
    PKCR I 1
    PKCR H 1
    PKCR G 2
    PKCR F 2
    PKCR E 2
    PKCR D 2
    PKCR C 2
    PKCR B 2
    PKCR A 2
	Goto WinddownMain
  ReloadFinish2:
    PKCR J 1
    PKCR I 1
    PKCR H 1
    PKCR G 1
    PKCR F 1
    PKCR E 1
    PKCR D 2
    PKCR C 2
    PKCR B 2
    PKCR A 2
	Goto WinddownMain
  ReloadFinish3:
    PKCR J 1
    PKCR I 1
    PKCR H 1
    PKCR G 1
    PKCR F 1
    PKCR E 1
    PKCR D 1
    PKCR C 1
    PKCR B 1
    PKCR A 2
	Goto WinddownMain
  ReloadFinish4:
    PKCR J 1
    PKCR I 1
    PKCR G 1
    PKCR F 1
    PKCR E 1
    PKCR D 1
    PKCR C 1
    PKCR B 1
	Goto WinddownMain
	
  Flash:
	TNT1 A 0 A_JumpIfInventory("RLChaingunState",1,3)
    PKCF E 1 Bright A_Light2
    PKCF F 1 Bright A_Light1
    Goto LightDone
    PKCF G 1 Bright A_Light2
    PKCF H 1 Bright A_Light1
    Goto LightDone
  FlashFF:
	TNT1 A 0 A_JumpIfInventory("RLChaingunState",1,2)
    PKCF E 1 Bright A_Light2
    Goto LightDone
    PKCF G 1 Bright A_Light2
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLChaingunPickup",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION, 0, tid)
    Stop
	
  Altfire:
	TNT1 A 0 A_JumpIfInventory("RLArmorModItemActivate",1, "ArmorModConversion")
	TNT1 A 0 A_JumpIfInventory("RLScavengerDrop",1,"ScavengerTime")
	TNT1 A 0 A_JumpIfInventory("RLGatlingGunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLBulletstormChaingunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLAssaultRifleChaingunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLBurstCannonChaingunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLNanoManufactureAmmoChaingunConfirm",1, "CancelAssembly")
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoChaingunConfirm",1, "CancelAssembly")
	Goto Ready
  CancelAssembly:
	TNT1 A 0 A_Print("Assembly canceled.")
  CancelAssembly2:
	TNT1 A 0 A_PlaySound("hud/assemblycancel", 5)
	TNT1 A 0 A_TakeInventory("RLGatlingGunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBulletstormChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLAssaultRifleChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBurstCannonChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoChaingunConfirm",1)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	Goto MisfirePrevention
  ScavengerTime:
	TNT1 A 0 A_JumpIfInventory("RLChaingunModLimit",1,"ModDiscombobulation")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_Print("This weapon cannot be scavenged.")
	Goto Ready
  ModDiscombobulation:
	TNT1 A 0 A_Print("Applied Mod pack extracted from discarded weapon.")
	TNT1 A 0 ACS_NamedExecuteAlways("ScavengeMods", 0)
	TNT1 A 3
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLGatlingGunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBulletstormChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLAssaultRifleChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLBurstCannonChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoChaingunConfirm",1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleGatlingGun:
	TNT1 A 0 A_JumpIfInventory("RLGatlingGun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelBasicGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvGatling Gun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLGatlingGunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLGatlingGun",1)
	TNT1 A 0 A_SelectWeapon("RLGatlingGun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleHighPowerChaingun:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelBasicGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvHigh Power Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLHighPowerChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleBulletstormChaingun:
	TNT1 A 0 A_JumpIfInventory("RLBulletstormChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelAdvancedGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvBulletstorm Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLBulletstormChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLBulletstormChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLBulletstormChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleAssaultRifleChaingun:
	TNT1 A 0 A_JumpIfInventory("RLAssaultRifleChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelAdvancedGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvAssault Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLAssaultRifleChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLAssaultRifleChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLAssaultRifleChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleBurstCannonChaingun:
	TNT1 A 0 A_JumpIfInventory("RLBurstCannonChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelAdvancedGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvBurst Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/assembly", CHAN_ITEM)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLBurstCannonChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLBurstCannonChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLBurstCannonChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleNanoManufactureAmmoChaingun:
	TNT1 A 0 A_JumpIfInventory("RLNanoManufactureAmmoChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvNanomachic Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/masterassembly", CHAN_ITEM)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 2)
	TNT1 A 0 A_Jump(256, 2)
    TNT1 A 0 A_PlaySound("technician/laugh", CHAN_VOICE)
    TNT1 A 0 A_PlaySound("weapons/masterassemblyfanfare", CHAN_AUTO)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLNanoManufactureAmmoChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLNanoManufactureAmmoChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLNanoManufactureAmmoChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  AssembleDemolitionAmmoChaingun:
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoChaingun",1, "AlreadyHaveAssembly")
	TNT1 A 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
	TNT1 A 0 A_Print("\cvDemolition Ammo Chaingun \c-assembled.")
    TNT1 A 0 A_PlaySound("weapons/masterassembly", CHAN_ITEM)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 2)
	TNT1 A 0 A_Jump(256, 2)
    TNT1 A 0 A_PlaySound("technician/laugh", CHAN_VOICE)
    TNT1 A 0 A_PlaySound("weapons/masterassemblyfanfare", CHAN_AUTO)
	TNT1 A 0 A_TakeInventory("RLChaingunSelected", 1)
    TNT1 A 0 A_TakeInventory("RLChaingunModLimit", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunPowerMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunBulkMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunAgilityMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunTechnicalMod", 4)
    TNT1 A 0 A_TakeInventory("RLChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoChaingunConfirm",1)
	TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, 2)
	TNT1 A 0 A_Jump(256, 2)
	TNT1 A 0 A_GiveInventory("RLMisfireSpamPreventionCooldown",1)
	TNT1 A 0 A_GiveInventory("RLDemolitionAmmoChaingun",1)
	TNT1 A 0 A_SelectWeapon("RLDemolitionAmmoChaingun")
	TNT1 A 0 A_TakeInventory("RLChaingun",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		MECHANICS

Actor RLChaingunSelected : RLPermanentInventory {}
Actor RLChaingunState : RLPermanentInventory {}
Actor RLChaingunAmmochain : RLAmmochainDefault {}

Actor RLChaingunModLimit : RLStandardModAmount {}
Actor RLChaingunPowerMod : RLStandardModAmount {}
Actor RLChaingunBulkMod : RLStandardModAmount {}
Actor RLChaingunAgilityMod : RLStandardModAmount {}
Actor RLChaingunTechnicalMod : RLStandardModAmount {}
Actor RLChaingunFirestormMod : RLExoticModAmount {}
Actor RLChaingunNanoMod : RLExoticModAmount {}
Actor RLChaingunSniperMod : RLExoticModAmount {}

ACTOR RLChaingunClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 88
   Inventory.Icon ""
}

//-------------------------------------------------------------------
//		PICKUPS

ACTOR RLChaingunPickup : RLStandardWeaponPickup 16805
{
	//$Sprite PKCGX0
	Tag "Chaingun [Pickup]"
	States
	{
	SpawnFrame:
		PKCG X 4
	SpawnLoop:
		"####" "#" 0 A_JumpIf(Abs(VelZ) <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 1
		Loop
	FloorHit:
		"####" "#" 0 A_PlaySound("weapons/gundropbig")
		"####" "#" 0 A_ScaleVelocity (0.25)
		"####" "#" 0 A_ChangeFlag("SPECIAL", true)
		"####" "#" 0 A_ChangeFlag("THRUACTORS", false)
		"####" "#" 0 A_SetUserVar("user_floorhit", 1)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Stop
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLSynthFireReload",1,"AmmoPickup") // If the player is holding reload, pickup the gun for ammo.
		"####" "#" 0 A_JumpIfInventory("RLChaingun",1,"NotPickup") // If the player already has this weapon, they are not given the weapon
		"####" "#" 0 A_JumpIfInventory("RLWeaponLimit",0,"NotPickupLimit") // The absolute max limit check for weapons
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLChaingun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cjChaingun.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickup")
		Goto NotPickup
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("Clip",0,"NotPickupNothing")
		Goto AmmoPickup
	NotPickupNothing:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cj= Chaingun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	AmmoPickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("Clip",0,"NotPickupNothing")
		"####" "#" 1 A_GiveInventory("Clip",40)
		Goto PickupSound
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/Chaingunpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonClip",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}

ACTOR RLChaingunPickupModded : RLChaingunPickup
{
	+INVENTORY.TRANSFER
	+DONTGIB
	States
	{
	Spawn:
		TNT1 A 0 NoDelay ACS_NamedExecuteAlways("GetWeaponMods", 0)
		TNT1 A 0 A_JumpIf(CallACS("DRLA_specialstarts") == 0, "NoSpecialStartsStuff")
		"####" "#" 0 A_Jump(256, "SpecialStartsStuff")
		Goto SpecialStartsStuff
		
	SpawnFrame:
		PKCG X 4
	SpawnLoop:
		"####" "#" 0 A_JumpIf(VelZ <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 0 ACS_NamedExecuteAlways("RLWeaponModDisplay", 0)
		"####" "#" 1
		Loop
		
	Pickup:
		"####" "#" 0
		"####" "#" 0 A_JumpIfInventory("RLChaingun",1,"NotPickup") // If the player already has this weapon, they are not given the weapon
		"####" "#" 0 A_JumpIfInventory("RLWeaponLimit",0,"NotPickupLimit") // The absolute max limit check for weapons
		"####" "#" 0 A_Jump(256, "GiveWeapon")
		Goto GiveWeapon
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLChaingun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cjChaingun.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cj= Chaingun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLChaingunModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cj= Chaingun =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		"####" "#" 0 A_GiveInventory("Clip",40)
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\cj= Chaingun =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
