
ACTOR RLIncinerationDeviceLauncher : RLWeapon
{
  Obituary "%o was scalded by %k's rocket."
  +NOAUTOAIM
  Tag "Incineration Device Launcher"
  Weapon.SelectionOrder 3900
  Weapon.SlotNumber 5
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLIncinerationDeviceLauncherClip"
  Weapon.AmmoType2 "RocketAmmo"
  Inventory.Icon "IDLAICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
    IDLA A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
  ReadyNoReload:
    IDLA A 8 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("RLIncinerationDeviceLauncherPickup", 0, 0, 40, 10, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLIncinerationDeviceLauncherSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLIncinerationDeviceLauncher",1)
	Stop
  AfterModDrop:
    IDLA A 8 A_WeaponReady (WRF_ALLOWRELOAD)
    Goto Ready
  MisfirePrevention:
    IDLA 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("RLIncinerationDeviceLauncherSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
    IDLA 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("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLIncinerationDeviceLauncherSelected", 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")
    IDLA A 1 A_Raise
    Loop
  Fire:
	IDLA A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	IDLA A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	IDLA A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	IDLA A 0 A_JumpIfInventory("RLRestrictionLowTechOnly",1,"LowTechRestricted") // Cannot fire in levels that restrict it
	IDLA A 0 A_JumpIfInventory("RLRestrictionCunningOnly",1,"CunningRestricted") // Cannot fire in levels that restrict it
	
	TNT1 A 0 A_JumpIfInventory("RLIncinerationDeviceLauncherClip", 1, 1)
	Goto Reload
    IDLA B 2 Bright A_GunFlash
	TNT1 A 0 A_AlertMonsters
	IDLA C 2 Bright A_FireCustomMissile ("RLIncinerationDevice", frandom(-0.2,0.2), 1)
    Goto FireFinish
  FireFinish:
    TNT1 A 0 A_SpawnItemEx ("RLRocketLauncherRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_TakeInventory("RLIncinerationDeviceLauncherClip", 1)
    IDLA D 2 Bright
    IDLA EFGHIA 2
	TNT1 A 0 A_JumpIf(CallACS("DRLA_AutoReload"), "Reload")
    Goto Ready
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,2)
	TNT1 A 0 A_JumpIfInventory("RocketAmmo", 2, 2)
	Goto ReadyNoReload
	TNT1 A 0 A_JumpIfInventory("RocketAmmo", 1, 1)
	Goto ReadyNoReload
	TNT1 A 0 A_JumpIfInventory("RLIncinerationDeviceLauncherClip",1,"Ready")
	TNT1 A 0 // Play the reload animation.
    IDLA I 2
    IDLA H 2
    IDLA G 2
    IDLA J 2
    IDLA K 2
    IDLA L 2
    IDLA M 2
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    TNT1 A 60
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_JumpIfInventory("RLFireangelPerk",1,3)
	TNT1 A 0 A_TakeInventory("RocketAmmo", 2, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLIncinerationDeviceLauncherClip", 1)
	Goto ReloadFinish
	TNT1 A 0 A_TakeInventory("RocketAmmo", 1, TIF_NOTAKEINFINITE)
	TNT1 A 0 A_GiveInventory("RLIncinerationDeviceLauncherClip", 1)
	Goto ReloadFinish
  ReloadFinish:
	TNT1 A 0 A_PlaySound("weapons/idlload", 7)
    TNT1 A 0 A_SpawnItemEx ("RLHeavyReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    IDLA M 2
    IDLA L 2
    IDLA K 2
    IDLA J 2
    IDLA G 2
    IDLA H 2
    IDLA I 2
    IDLA A 5
	Goto Ready
  Flash:
    TNT1 A 2 A_Light1
    TNT1 A 2 A_Light (3)
    TNT1 A 2 A_Light1
    TNT1 A 0 A_Light0
    Goto LightDone
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLIncinerationDeviceLauncherPickup",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("RLPlasmaInfusionAssemblyLearntToken", 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("RLIncinerationDeviceLauncherSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
    TNT1 A 0 A_StopSound(6)
	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("DroppedRLAgilityMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
	TNT1 A 0 A_FireCustomMissile("DroppedRLTechnicalMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLIncinerationDeviceLauncher",1)
	Stop
  }
}

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

ACTOR RLIncinerationDevice : Rocket
{
  Species "Player"
  +THRUSPECIES
  +THRUGHOST
  +SKYEXPLODE
  -ROCKETTRAIL
  +FORCEXYBILLBOARD
  Speed 13
  Decal "Scorch"
  Damagetype "Plasma"
  SeeSound "weapons/incinerationdevice"
  DeathSound ""
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_SpawnItemEx ("RLIncinerationDeviceHax", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_ISMASTER)
  SpawnLoop:
    TNT1 A 0 A_PlaySound ("weapons/incinerationdeviceloop", 7, 1, 1, 1.2)
    IDLX A 1 Bright A_SpawnItemEx ("RLMIRVMissileTrail", 8,0,8, 0,0,0, 180, SXF_NOCHECKPOSITION)
    TNT1 A 0 A_Warp (AAPTR_MASTER, 0,0,0, 0, WARPF_MOVEPTR | WARPF_NOCHECKPOSITION | WARPF_INTERPOLATE | WARPF_COPYINTERPOLATION, "SpawnLoop")
    Loop
  Death:
    TNT1 A 0 A_SetTranslucent (0.95, 1)
    TNT1 A 0 A_GiveInventory ("RLManualExplosionHax", 1, AAPTR_MASTER)
	TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
    TNT1 A 0 A_Quake (1, 8, 0, 1024, "")
    TNT1 A 0 A_Quake (4, 8, 0, 256, "")
    TNT1 A 0 A_PlaySound ("weapons/bfgx", 7, 1, 0, 0.5)
    TNT1 A 0 A_PlaySound("weapons/bfgx", CHAN_ITEM, 0.05, 0, 0.05)
    K8B4 I 3 Bright A_Explode (128,128, XF_HURTSOURCE)
    K8B4 JKLMN 3 Bright
    Stop
  }
}

// fuck everything
ACTOR RLIncinerationDeviceHax
{
  Radius 4
  Height 4
  Speed 5
  Damage 0
  Projectile
  Species "Player"
  +SEEKERMISSILE
  +THRUSPECIES
  +THRUACTORS
  +NOCLIP
  +FORCEXYBILLBOARD
  
  var int user_countdowntimer;
  States
  {
  Spawn:
    TNT1 A 0
    TNT1 A 0 A_JumpIfInventory("RLManualExplosionHax", 1, "Death")
    TNT1 A 1 A_SeekerMissile (0, 0, SMF_LOOK | SMF_CURSPEED, 256, 2)
    TNT1 A 0 A_CheckFlag("SHOOTABLE", "BBQTime", AAPTR_TRACER)
//    TNT1 A 0 A_PrintBold ("scanning", 1)
    Goto Spawn
  BBQTime:
//    TNT1 A 0 A_PrintBold ("targeting", 1)
    TNT1 A 0 A_SetUserVar("user_countdowntimer", 15)
	Goto BBQTimeLoop
  BBQTimeLoop:
//    TNT1 A 0 A_PrintBold ("firing", 1)
    TNT1 A 0 A_JumpIfInventory("RLManualExplosionHax", 1, "Death")
    TNT1 A 0 A_JumpIf (user_countdowntimer <= 0, "BBQTimeEnd")
    TNT1 A 1 A_CustomMissile ("RLIncinerationDevicePlasmaFire", 8, 0, 0, CMF_TRACKOWNER, 0, AAPTR_TRACER)
    TNT1 A 0 A_SetUserVar("user_countdowntimer", user_countdowntimer - 1)
	Loop
  BBQTimeEnd:
    TNT1 A 0 A_SetUserVar("user_countdowntimer", 10)
    TNT1 A 0 A_RearrangePointers (AAPTR_DEFAULT, AAPTR_DEFAULT, AAPTR_NULL)
	Goto SpawnNoFire
  SpawnNoFire:
//    TNT1 A 0 A_PrintBold ("cooling down", 1)
    TNT1 A 0 A_JumpIfInventory("RLManualExplosionHax", 1, "Death")
    TNT1 A 0 A_JumpIf (user_countdowntimer <= 0, "Spawn")
    TNT1 A 1
    TNT1 A 0 A_SetUserVar("user_countdowntimer", user_countdowntimer - 1)
	Loop
  Death:
//    TNT1 A 0 A_PrintBold ("ded", 1)
    TNT1 A 8
    Stop
  }
}

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

Actor RLIncinerationDeviceLauncherSelected : RLPermanentInventory {}
Actor RLManualExplosionHax : RLPermanentInventory {}

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

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

ACTOR RLIncinerationDeviceLauncherPickup : RLMasterAssembledWeaponPickup
{
	//$Sprite IDLAX0
	Tag "Incineration Device Launcher [Pickup]"
	States
	{
	SpawnFrame:
		IDLA 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("RLIncinerationDeviceLauncher",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("RLIncinerationDeviceLauncher",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvIncineration Device Launcher.")
		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= Incineration Device Launcher =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/IncinerationDeviceLauncherpickup")
		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 RLIncinerationDeviceLauncherWorldSpawnPickup : RLIncinerationDeviceLauncherPickup 17805
{
	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:
		IDLA 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("RLIncinerationDeviceLauncher",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up an \cvIncineration Device Launcher.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
