
ACTOR RLAutocannon : RLHeavyWeapon
{
  Obituary "%k's autocannon blasted %o all across the room."
  Decal Scorch
  Tag "Autocannon"
  Weapon.Kickback 75
  Weapon.SelectionOrder 1900
  Weapon.SlotNumber 5
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLAutocannonClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "AUTOICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    AUTO A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyExtra:
    AUTO A 1 A_WeaponReady (WRF_ALLOWZOOM)
    Goto Ready
	
  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("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_SpawnItemEx("RLAutocannonPickup", 0, 0, 40, 8, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLAutocannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLAutocannon",1)
	Stop
  AfterModDrop:
    AUTO A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
    AUTO 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("RLAutocannonSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    AUTO 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("RLMasterAssemblyTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLEfficientAmmoTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLSingleShotRifleTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLAutocannonSelected", 1)
	TNT1 A 0 A_JumpIfInventory("RLScavengerPerk",1, 1)
    Goto SelectLoop
	TNT1 A 0 A_GiveInventory("PowerRLTechnicianMasterDamage", 1)
    Goto SelectLoop
  SelectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "SelectRenegade")
    AUTO A 1 A_Raise
    Loop
	
  Fire:
	AUTO A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	AUTO A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	AUTO A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	AUTO A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	AUTO A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLAutocannonClip", 1, 1)
	Goto Reload
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 A_FireBullets (1, 1, -1, 150, "RLAutocannonPuff")
    Goto FireFinish
  FireFinish:
	TNT1 A 0 A_TakeInventory("RLAutocannonClip", 1)
    TNT1 A 0 A_PlaySound("weapons/autocannon", CHAN_WEAPON, 1, 0, 0.5)
    TNT1 A 0 A_PlaySound("weapons/autocannon", 7, 0.05, 0, 0.10)
	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) * -4, 0, Sin(Pitch) * 4, 1)
    TNT1 A 0 A_SpawnItemEx ("RLRocketLauncherRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    AUTO F 2 Bright A_GunFlash
    AUTO E 2 Bright
    AUTO GHI 1
    AUTO HG 3
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLAutocannonClip", 1, "ReadyExtra")
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,2)
	TNT1 A 0 A_JumpIfInventory("Clip", 5, 1)
	Goto Ready
	TNT1 A 0 A_JumpIfInventory("Clip", 2, 1)
	Goto Ready
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_PlaySound("weapons/autocannonload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLCombatShotgunPumpRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    AUTO B 5
    AUTO C 5
    AUTO D 5
  ReloadWorking:
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,3)
	TNT1 A 0 A_TakeInventory("Clip", 5, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLAutocannonClip", 1)
	Goto ReloadFinish
	TNT1 A 0 A_TakeInventory("Clip", 2, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLAutocannonClip", 1)
	Goto ReloadFinish
  ReloadFinish:
	AUTO A 9
	Goto Ready
  Flash:
    TNT1 A 2 A_Light2
    TNT1 A 2 A_Light1
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLAutocannonPickup",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
  ScavengerTime:
	TNT1 A 0 A_GiveInventory("RLScavengingExtraEffects", 1)
    TNT1 A 0 A_GiveInventory("RLAutocannonAssemblyLearntToken", 1) // Assembly is now listed in the HUD menus
	TNT1 A 0 A_Print("Mod pack extracted from discarded weapon.")
	TNT1 A 0 A_TakeInventory("RLScavengerDrop",1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLAutocannonSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
	TNT1 A 0 A_Jump(256,1,2,3,4)
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLFirestormMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLFirestormMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLAutocannon",1)
	Stop
  }
}

//-------------------------------------------------------------------
//		PROJECTILES

ACTOR RLAutocannonPuff
{ 
	+NOGRAVITY
	+NOBLOCKMAP
	+PUFFONACTORS
	+PUFFGETSOWNER
	+RANDOMIZE
	+THRUGHOST
	+MTHRUSPECIES
	+FORCEXYBILLBOARD
	RenderStyle Add
	Alpha 0.9
	Mass 5
	Scale 0.8
	Decal "Scorch"
	Damagetype "Fire"
    PainType "Explosion"
    DeathType "Explosion"
	var int user_apvar;
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_GiveToTarget ("RLFireangelBonusCheck", 1)
			TNT1 A 0 A_RadiusGive ("RLFireangelRadiusBonusCheck", 128, RGF_PLAYERS)
			TNT1 A 0 A_SetTranslucent (0.95, 1)
			TNT1 A 0 A_Explode (256,128)
			TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
			TNT1 A 0 A_Quake (1, 8, 0, 1024, "")
			TNT1 A 0 A_Quake (6, 8, 0, 512, "")
		Spawn.Normal:
			MEXP A 0 A_JumpIf(CallACS("DRLA_Fancyprojectiles") == 1, "Spawn.Fancy")
			TNT1 A 0 A_PlaySound ("weapons/mediumexp", 7, 1, 0, 0.5)
			TNT1 A 0 A_PlaySound("weapons/mediumexp", CHAN_ITEM, 0.05, 0, 0.05)
			MEXP A 4 Bright
			MEXP B 4 Bright
			MEXP C 3 Bright
			MEXP D 3 Bright
			MEXP E 2 Bright
			MEXP F 2 Bright
			Stop
		Spawn.Fancy:
			TNT1 A 0 A_PlaySound ("weapons/torgueexp", 7, 1, 0, 0.5)
			TNT1 A 0 A_PlaySound("weapons/mediumexp", CHAN_ITEM, 0.05, 0, 0.05)
			NAPX AAAAAAAAAAAAAAAA 0 A_SpawnItemEx("RLMiniMissileParticles", 0, 0, 0, frandom(-2.0,2.0), frandom(-6.0,6.0), frandom(0.0,6.0), frandom(0.0,360.0))
			NAPX AAAAAAAAAAAAAAAA 0 A_SpawnItemEx("RLRocketShrapnel", 0, 0, 0, frandom(-2.0,2.0), frandom(-6.0,6.0), frandom(0.0,6.0), frandom(0.0,360.0))
			NAPX A 0 A_SpawnItemEx("RLAutocannonExplosionFancy",1)
			NAPX AA 1 Bright A_SpawnItemEx("RLAutocannonExplosionPuff",0,0,0)
			NAPX B 2 Bright
			NAPX C 3 Bright
			NAPX D 3 Bright
			NAPX E 4 Bright
			NAPX F 4 Bright
			Stop
	}
}

ACTOR RLAutocannonExplosionPuff
{
	Renderstyle Add
	Scale	0.8
	Alpha	0.8
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			NAPX ABC 2 Bright A_SetScale(scalex + 0.1)
			NAPX DD 1 A_SetScale(scalex + 0.11)
			NAPX EE 1 A_SetScale(scalex + 0.13)
			"####" "#" 0 A_FadeOut
			NAPX FFFFFFFF 1 A_SetScale(scalex + 0.11)
			"####" "#" 0 A_FadeOut(0.05)
			Stop
	}
}

ACTOR RLAutocannonExplosionFancy
{
	Renderstyle Add
	+NOINTERACTION
	+FORCEXYBILLBOARD
	States
	{
		Spawn:
			R053 KLMN 2 Bright
			R053 OPQ 2 A_FadeOut
			Stop
	}
}

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

Actor RLAutocannonSelected : RLPermanentInventory {}

ACTOR RLAutocannonClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 1
   Inventory.Icon ""
}

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

ACTOR RLAutocannonPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite AUTOX0
	Tag "Autocannon [Pickup]"
	States
	{
	SpawnFrame:
		AUTO 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/gundropbigger")
		"####" "#" 0 A_ScaleVelocity (0.15)
		"####" "#" 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("RLAutocannon",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("RLAutocannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvAutocannon.")
		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= Autocannon =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/Autocannonpickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonGrenades",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLAutocannonWorldSpawnPickup : RLAutocannonPickup 17833
{
	States
	{
	NoSpecialStartsStuff:
		TNT1 A 0 A_JumpIf(CallACS("DRLA_opengl"), 3) // If enabled, rarity beam will be cyan, rather than blue
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorld", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_Jump(256,2)
		TNT1 A 0 A_SpawnItemEx("RLRarityBeamAssembledWorldDRPG", 0, 0, 0, 0, 0, 0, 0, SXF_SETMASTER)
		TNT1 A 0 A_JumpIf(CallACS("DRPGCheckTiem"), "DRPGInit")
	SpawnFrame:
		AUTO X 4
		"####" "#" 0 A_GiveInventory("RLMasterItemSpawnMessageSender",1)
		"####" "#" 0 A_PlaySound("weapons/masterspawned", 7, 0.25, 0, 0)
		"####" "#" 0 A_Jump(256, "SpawnLoop")
		Goto SpawnLoop
		
	GiveWeapon:
		"####" "#" 0 A_GiveInventory("RLAutocannon",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvAutocannon.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
