
ACTOR RLHighPowerChaingun : RLWeapon
{
  Obituary "%o was perforated by %k's chaingun."
  Decal BulletChip
  Tag "High Power Chaingun"
  Weapon.SelectionOrder 25
  Weapon.SlotNumber 4
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLHighPowerChaingunClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "QCHGICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunState",1)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunNanoMod",1,2)
    QCHG A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto Ready+2
  NanoRegenCheck:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip",1,2)
    QCHG A 70 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	Goto NanoRegenCheckBegin
  NanoRegenCheckBegin:
    QCHG A 70 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 26, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 34, "Ready")
	Goto NanoRegen
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 42, "Ready")
	Goto NanoRegen
  NanoRegen:
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunNanoMod",2,2)
    QCHG A 17 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Goto NanoRegenCheckBegin+1
    QCHG 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_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("RLScavengerDrop",1)
	TNT1 A 0 A_TakeInventory("RLWeaponDrop",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunModLimit", 1, "WeaponDropModded")
	TNT1 A 0 A_SpawnItemEx("RLHighPowerChaingunPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	Goto WeaponDropRemoval
  WeaponDropModded:
	TNT1 A 2 A_SpawnItemEx("RLHighPowerChaingunPickupModded", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
  WeaponDropRemoval:
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunPowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLHighPowerChaingun",1)
	Stop
	
  AfterModDrop:
    QCHG A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    QCHG 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("RLHighPowerChaingunSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    TNT1 A 0 A_Lower
    QCHG 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("RLBasicAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLRapidfireTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianBasicDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    TNT1 A 0 A_Raise
    QCHG A 1 A_Raise
    Loop
	
  Fire:
	QCHG A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	QCHG A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	QCHG A 0 A_JumpIfInventory("RLRestrictionBoomOnly",1,"BoomRestricted") // Cannot fire in levels that restrict it
	QCHG A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	QCHG 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("RLHighPowerChaingunSniperMod",1,"FireS")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunPowerMod",1,"FireP")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAgilityMod",1,"FireA")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireP:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunPowerMod",2,"FirePP")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAgilityMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*9), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*9), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireA:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunPowerMod",1,"FirePA")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAgilityMod",2,"FireAA")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FirePP:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*10), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (6, 2, -1, (random(1,5)*10), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FirePA:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, (random(1,5)*9), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5.5, 1.5, -1, (random(1,5)*9), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireAA:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (5, 1, -1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (5, 1, -1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireS:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunSniperMod",2,"FireSS")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunPowerMod",1,"FireSP")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAgilityMod",1,"FireSA")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSS:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (0, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (0, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSP:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (4, 0, 1, (random(1,5)*9), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (4, 0, 1, (random(1,5)*9), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
  FireSA:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (3.5, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_USEAMMO | FBF_NORANDOM)
    Goto FireFinish
	TNT1 A 0 A_FireBullets (3.5, 0, 1, (random(1,5)*8), "RLBulletPuff", FBF_NORANDOM)
    Goto FireFinish
	
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/highpowerchaingun", CHAN_WEAPON, 1, 0, 0.6)
    TNT1 A 0 A_PlaySound("weapons/highpowerchaingun", 7, 0.05, 0, 0.20)
	TNT1 A 0 A_CheckFloor (2)
	TNT1 A 0 A_Jump(256,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingSteelBootsToken",1,4)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingProtectiveBootsToken",1,3)
	TNT1 A 0 A_JumpIfInventory("RLGrapplingPlasteelBootsToken",1,2)
    TNT1 A 0 A_ChangeVelocity (Cos(Pitch) * -0.1, 0, Sin(Pitch) * 0.1, 1)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,"FireFinishPowerupCheck") // Check for powerups.
  FireFinishPowerupCheckDone: // No valid powerups detected.
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunFirestormMod",2,"FireFinishFF")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunFirestormMod",1,"FireFinishF")
    TNT1 A 0 A_SpawnItemEx ("RLChaingunRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG A 1 A_GunFlash
    QCHG BCD 1
    Goto FireFinishContinue
  FireFinishF:
    TNT1 A 0 A_SpawnItemEx ("RLUziRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG A 1 A_GunFlash
    QCHG BC 1
    Goto FireFinishContinue
  FireFinishFF:
    TNT1 A 0 A_SpawnItemEx ("RLThompsonRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG A 1 A_GunFlash
    QCHG C 1
    Goto FireFinishContinue
	
  FireFinishContinue:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunAmmochain",0,2)
	TNT1 A 0 A_Jump(256,6)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunAmmochain",0)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunState",1,2)
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunState",1)
    Goto Fire
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunState",1)
    TNT1 A 0 A_ReFire
    Goto WinddownMain
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunAmmochain",1)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunState",1,2)
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunState",1)
    Goto Fire
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunState",1)
    TNT1 A 0 A_ReFire
    Goto WinddownMain

//-------------------------------------------------------------------------------------------------
  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("RLHighPowerChaingunFirestormMod",1,"FireFinishFF")
	Goto FireFinishF
//-------------------------------------------------------------------------------------------------
  
  WinddownMain:
    TNT1 A 0 A_PlaySound("weapons/hpchaingunwinddown", 6, 1, 0, 1.8)
	TNT1 A 0 A_JumpIfNoAmmo("WinddownNoAmmo")
	QCHG A 1 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueA")
	QCHG B 1 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueB")
	QCHG C 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueC")
	QCHG D 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueD")
	QCHG A 2 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueA")
	QCHG B 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueB")
	QCHG C 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueC")
	QCHG D 3 A_JumpIfInventory("RLSynthFireLeft",1,"WinddownContinueD")
    Goto Ready
  WinddownNoAmmo:
	QCHG AB 1
	QCHG CDA 2
	QCHG BCD 3
    Goto Ready
  WinddownContinueA:
	QCHG ABCD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueB:
	QCHG BCD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueC:
	QCHG CD 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
  WinddownContinueD:
	QCHG D 1
	TNT1 A 0 A_JumpIfInventory("RLSynthFireLeft",1,"Fire")
    Goto WinddownMain
	
  Reload:
	QCHG A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 26, "Ready")
	Goto ReloadStartingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 34, "Ready")
	Goto ReloadStartingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip", 42, "Ready")
  ReloadStartingAmmoCheck:
	TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
	Goto Ready
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunTechnicalMod",2,"Reload2")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunTechnicalMod",1,"Reload1")
    QCHG F 3
    QCHG G 3
    QCHG F 3
    QCHG H 3
    QCHG I 3 A_PlaySound("weapons/hpchaingununload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG J 3
    QCHG K 3
    TNT1 A 20
	Goto ReloadWorking
  Reload1:
    QCHG F 2
    QCHG G 3
    QCHG F 2
    QCHG H 2
    QCHG I 3 A_PlaySound("weapons/hpchaingununload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG J 3
    QCHG K 3
    TNT1 A 20
	Goto ReloadWorking
  Reload2:
    QCHG F 2
    QCHG G 3
    QCHG F 2
    QCHG H 2
    QCHG I 2 A_PlaySound("weapons/hpchaingununload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    QCHG J 2
    QCHG K 2
    TNT1 A 20
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Clip", 1)
	TNT1 A 0 A_GiveInventory("RLHighPowerChaingunClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",1,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip",26,5)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunBulkMod",2,2)
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip",34,3)
	Goto ReloadWorkingAmmoCheck
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunClip",42,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_PlaySound("weapons/hpchaingunload", 7)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunTechnicalMod",2,"ReloadFinish2")
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunTechnicalMod",1,"ReloadFinish1")
    QCHG K 3
    QCHG J 3
    QCHG I 3
    QCHG H 3
    QCHG F 3
    QCHG G 3
    QCHG F 3
	Goto WinddownMain
  ReloadFinish1:
    QCHG K 2
    QCHG J 2
    QCHG I 2
    QCHG H 3
    QCHG F 3
    QCHG G 3
    QCHG F 3
	Goto WinddownMain
  ReloadFinish2:
    QCHG K 2
    QCHG J 2
    QCHG I 2
    QCHG H 2
    QCHG F 2
    QCHG G 3
    QCHG F 2
	Goto WinddownMain
	
  Flash:
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunState",1,5)
    QCHG E 1 Bright A_Light2
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunFirestormMod",2,2)
    TNT1 A 0 A_Light1
	TNT1 A 0
    Goto LightDone
    QCHG E 1 Bright A_Light1
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunFirestormMod",2,2)
    TNT1 A 0 A_Light1
	TNT1 A 0
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLHighPowerChaingunPickup",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")
	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_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunPowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
	Goto ScavengerTimeEnd
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLHighPowerWeaponAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_JumpIfInventory("RLHighPowerChaingunModLimit",1,"ModDiscombobulation")
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunModLimit", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunPowerMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunBulkMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunAgilityMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunTechnicalMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSniperMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunFirestormMod", 2)
    TNT1 A 0 A_TakeInventory("RLHighPowerChaingunNanoMod", 2)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLHighPowerChaingunSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianBasicDamage", 1)
	TNT1 A 0 A_Jump(256,1,2)
	TNT1 A 0 A_FireCustomMissile("DroppedRLBulkMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLHighPowerChaingun",1)
	Stop
  }
}

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

Actor RLHighPowerChaingunSelected : RLPermanentInventory {}
Actor RLHighPowerChaingunState : RLPermanentInventory {}
Actor RLHighPowerChaingunAmmochain : RLAmmochainDefault {}
Actor RLHighPowerChaingunModLimit : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunPowerMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunBulkMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunAgilityMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunTechnicalMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunFirestormMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunNanoMod : RLBasicAssemblyModAmount {}
Actor RLHighPowerChaingunSniperMod : RLBasicAssemblyModAmount {}

ACTOR RLHighPowerChaingunClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 42
   Inventory.Icon ""
}

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

ACTOR RLHighPowerChaingunPickup : RLBasicAssembledWeaponPickup 17409
{
	//$Sprite QCHGX0
	Tag "High Power Chaingun [Pickup]"
	States
	{
	SpawnFrame:
		QCHG X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	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("RLHighPowerChaingun",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("RLHighPowerChaingun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvHigh Power Chaingun.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_Jump(256, "NotPickup")
		Goto NotPickup
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= High Power Chaingun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/hpChaingunpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonClip",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	}
}

ACTOR RLHighPowerChaingunPickupModded : RLHighPowerChaingunPickup
{
	+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:
		QCHG X 4
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
	SpawnLoop:
		"####" "#" 0 A_JumpIf(VelZ <= 0.01 && user_floorhit == 0, "FloorHit")
		"####" "#" 0 ACS_NamedExecuteAlways("RLWeaponModDisplay", 0)
		"####" "#" 1
		Loop
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLHighPowerChaingun",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cbmodded \cvHigh Power Chaingun.")
		Goto PickupSound
	NotPickupLimit:
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= High Power Chaingun =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup:
		"####" "#" 0 A_JumpIfInventory("RLHighPowerChaingunModLimit", 1, "NotPickup_Modded")
		"####" "#" 0 A_JumpIfInventory("DRLA_WeaponAntiLogFloodCheck",1,"NotPickup_NoPrint")
		"####" "#" 0 A_GiveInventory("DRLA_WeaponAntiLogFloodCheck")
		"####" "#" 0 A_Print("\cv= High Power Chaingun =\n\n\ccYou replace your unmodded\n\ccweapon with the one you picked up.", 5, "CONFONT")
		"####" "#" 0 A_GiveInventory("Clip",26)
		Goto PickupSound
	NotPickup_Modded:
		"####" "#" 0 A_Print("\cv= High Power Chaingun =\n\n\caYou are already carrying a modded\n\caweapon of this type", 5, "CONFONT")
		Fail
	}
}
