
ACTOR RLDemolitionAmmoBattleRifle : RLWeapon
{
  Obituary "%o's head exploded from %k's battle rifle."
  Decal RevenantScorch
  Tag "Demolition Ammo Battle Rifle"
  Weapon.SelectionOrder 25
  Weapon.SlotNumber 5
  Weapon.AmmoUse1 1
  Weapon.AmmoGive1 0
  Weapon.AmmoType1 "RLDemolitionAmmoBattleRifleClip"
  Weapon.AmmoType2 "Clip"
  Inventory.Icon "DEMRICON"
  States
  {
  Ready:
	TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown",1,"MisfirePrevention")
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,2)
	TNT1 A 0 A_JumpIfInventory("Clip",1,2)
    DEMR B 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
    DEMR B 1 A_WeaponReady (WRF_NOFIRE | WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
    DEMR A 1 A_WeaponReady (WRF_ALLOWZOOM | WRF_ALLOWRELOAD)
    Loop
	
  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("RLDemolitionAmmoBattleRiflePickup", 0, 0, 40, 12, 0, 0, 0, SXF_SETMASTER)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoBattleRifleSelected", 1)
	TNT1 A 0 A_TakeInventory("RLWeaponLimit",1)
	TNT1 A 1 A_TakeInventory("RLDemolitionAmmoBattleRifle",1)
	Stop
	
  AfterModDrop:
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,2)
    DEMR B 8 A_WeaponReady (16)
    Goto Ready
    DEMR A 8 A_WeaponReady (16)
    Goto Ready
  MisfirePrevention:
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,3)
    DEMR B 1 A_WeaponReady (WRF_NOFIRE | WRF_NOBOB)
    TNT1 A 0 A_JumpIfInventory("RLMisfireSpamPreventionCooldown", 1, "MisfirePrevention")
    Goto Ready
    DEMR 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("RLDemolitionAmmoBattleRifleSelected", 1)
	TNT1 A 0 A_GiveInventory("RLRarityTokenRemover", 1)
	TNT1 A 0 A_TakeInventory("PowerRLTechnicianMasterDamage", 1)
  DeselectLoop:
    TNT1 A 0 A_JumpIfInventory("RLShellshockPerk", 1, "DeselectRenegade")
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,3)
    TNT1 A 0 A_Lower
    DEMR B 1 A_Lower
    Loop
    TNT1 A 0 A_Lower
    DEMR 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("RLRapidfireTypeWeapon", 1)
	TNT1 A 0 A_GiveInventory("RLAssembledWeaponToken", 1)
	TNT1 A 0 A_GiveInventory("RLDemolitionAmmoBattleRifleSelected", 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")
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,3)
    TNT1 A 0 A_Raise
    DEMR B 1 A_Raise
    Loop
    TNT1 A 0 A_Raise
    DEMR A 1 A_Raise
    Loop
	
  Fire:
	DEMR A 0 A_JumpIfInventory("RLRestrictionMeleeOnly",1,"MeleeRestricted") // Cannot fire in levels that restrict it
	DEMR A 0 A_JumpIfInventory("RLRestrictionSilencedOnly",1,"SilencedRestricted") // Cannot fire in levels that restrict it
	DEMR A 0 A_JumpIfInventory("RLRestrictionNoBoom",1,"NoBoomRestricted") // Cannot fire in levels that restrict it
	DEMR A 0 A_JumpIfInventory("RLRestrictionHighTechOnly",1,"HighTechRestricted") // Cannot fire in levels that restrict it
	DEMR 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("RLDemolitionAmmoBattleRifleAmmochain",0,2)
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,2)
	TNT1 A 0 A_FireBullets (2, 0.5, -1, 5, "RLDemoBattleRiflePuff")
    Goto FireFinish
	TNT1 A 0 A_FireBullets (2, 0.5, -1, 5, "RLDemoBattleRiflePuff", 0)
    Goto FireFinish
	
  FireFinish:
    TNT1 A 0 A_PlaySound("weapons/demobattlerifle", CHAN_WEAPON, 1, 0, 0.7)
    TNT1 A 0 A_PlaySound("weapons/demobattlerifle", 7, 0.05, 0, 0.20)
    TNT1 A 0 A_SpawnItemEx ("RLBattleRifleRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
	TNT1 A 0 A_JumpIfInventory("RLAmmochainPerk",1,"FireFinishPowerupCheck") // Check for powerups.
  FireFinishPowerupCheckDone: // No valid powerups detected.
    DEMR Y 1 Bright A_GunFlash
    DEMR Z 1 Bright
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,3)
    DEMR VB 1
    Goto FireFinishContinue
    DEMR WA 1
    Goto FireFinishContinue
  FireFinishContinue:
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleAmmochain",0,2)
	TNT1 A 0 A_Jump(256,3)
	TNT1 A 0 A_TakeInventory("RLDemolitionAmmoBattleRifleAmmochain",0)
    TNT1 A 0 A_ReFire
    Goto Ready
	TNT1 A 0 A_GiveInventory("RLDemolitionAmmoBattleRifleAmmochain",1)
    TNT1 A 0 A_ReFire
    Goto Ready

//-------------------------------------------------------------------------------------------------
  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_SpawnItemEx ("RLUziRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    DEMR Y 1 Bright A_GunFlash
    DEMR Z 1 Bright
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,2)
    DEMR V 1
    Goto FireFinishContinue
    DEMR W 1
    Goto FireFinishContinue
//-------------------------------------------------------------------------------------------------
  
  Reload:
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,2)
	DEMR B 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	Goto Reload+3
	DEMR A 1 A_WeaponReady (WRF_NOPRIMARY | WRF_ALLOWZOOM)
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip", 20, "Ready")
	TNT1 A 0 A_JumpIfInventory("Clip", 1, 1)
	Goto Ready
	TNT1 A 0 // Play the reload animation.
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",1,11)
    DEMR N 2
    DEMR O 2
    DEMR P 2
    TNT1 A 0 A_PlaySound("weapons/demobattlerifleunload", CHAN_ITEM)
    DEMR Q 2
    DEMR R 8
    DEMR S 2
    DEMR T 2
    DEMR U 2
//    TNT1 A 0 A_PlaySound("weapons/demobattleriflecock", 7)
	Goto ReloadWorking
    DEMR C 2
    DEMR D 2
    DEMR E 2
    TNT1 A 0 A_PlaySound("weapons/demobattlerifleunload", CHAN_ITEM)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadOutRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    DEMR F 2
    DEMR G 8
    DEMR H 2
    DEMR I 2
    DEMR J 2
	Goto ReloadWorking
  ReloadWorking:
	TNT1 A 0 A_TakeInventory("Clip", 1)
	TNT1 A 0 A_GiveInventory("RLDemolitionAmmoBattleRifleClip", 1)
	TNT1 A 0 A_JumpIfInventory("RLDemolitionAmmoBattleRifleClip",20,2)
	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/demobattlerifleload", 7)
    TNT1 A 0 A_SpawnItemEx ("RLStandardReloadInRecoil", 0,0,0, 0,0,0, 0, SXF_NOCHECKPOSITION | SXF_SETMASTER) // Pitch-based recoil
    DEMR K 3
    DEMR L 5
    DEMR M 3
    DEMR A 6
	Goto Ready
	
  Flash:
    TNT1 A 1 A_Light1
    TNT1 A 1 A_Light2
    Goto LightDone
	
  Spawn:
	TNT1 A 0 NoDelay A_SpawnItemEx("RLDemolitionAmmoBattleRiflePickup",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("RLDemolitionAmmoAssemblyLearntToken", 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("RLDemolitionAmmoBattleRifleSelected", 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("DroppedRLFirestormMod",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
	TNT1 A 0 A_FireCustomMissile("DroppedRLPowerMod",0,0,0)
	Goto ScavengerTimeEnd
  ScavengerTimeEnd:
	TNT1 A 1 A_TakeInventory("RLDemolitionAmmoBattleRifle",1)
	Stop
  }
}

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

ACTOR RLDemoBattleRiflePuff : RLDemoPuffBase
{
	Scale 1.0
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_GiveToTarget ("RLFireangelBonusCheck", 1)
			TNT1 A 0 A_RadiusGive ("RLFireangelRadiusBonusCheck", 20, RGF_PLAYERS)
			TNT1 A 0 A_JumpIf(CallACS("DRLA_QuakeNShake") == 0, 3)
			TNT1 A 0 A_Quake (1, 8, 0, 256, "")
			TNT1 A 0 A_Quake (3, 8, 0, 64, "")
			TNT1 A 0 A_PlaySound ("weapons/bulletexp", 7, 0.5, 0, 0.7)
			TNT1 A 0 A_PlaySound("weapons/bulletexp", CHAN_ITEM, 0.05, 0, 0.05)
			//TNT1 A 0 A_Explode (25, 20, 1, 1, 20)
			TNT1 A 0 A_Explode (40, 64, 1, 1, 64) // New experimental damage calculation
			Goto RLDemoPuffBase::Spawn.Normal
	}
}

//==============================================================================
//DEMOLITION AMMO FUN CHART OF MATHING
//SIDDOYLE IS A MATH FRISBEE
//==============================================================================
//					Firerate	Mag		Exp DMG		Exp DPS		Avg DMG		DPS		Ammo Eff.	Total DPS
//Pistol			14			6		77.33		193.325		12			30		5			223.325
//Chaingun			4			40		20.43		178.763		12			105		2.625		283.763
//Battle Rifle		4			20		25.43		222.513		10			87.5	4.375		310.013
//Uzi				3			32		18.82		219.567		8			93.333	2.917		312.9
//Minigun			1			200		7.86		275.1 		10			350		1.75		625.1
//Combat Pistol		10			15		45.9		160.65		14			49		3.267		209.65
//Marksman Pistol	13			10		61.14		164.608		12			32.308	3.231		196.916
//Handcannon		19			7		86.86		160.005		32			58.947	8.421		218.952
//==============================================================================

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

Actor RLDemolitionAmmoBattleRifleSelected : RLPermanentInventory {}
Actor RLDemolitionAmmoBattleRifleAmmochain : RLAmmochainDefault {}

ACTOR RLDemolitionAmmoBattleRifleClip : Ammo
{
   +INVENTORY.IGNORESKILL
   Inventory.MaxAmount 20
   Inventory.Icon ""
}

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

ACTOR RLDemolitionAmmoBattleRiflePickup : RLMasterAssembledWeaponPickup
{
	//$Sprite DEMRX0
	Tag "Demolition Ammo Battle Rifle [Pickup]"
	States
	{
	SpawnFrame:
		DEMR 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/gundropmedium")
		"####" "#" 0 A_ScaleVelocity (0.5)
		"####" "#" 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("RLDemolitionAmmoBattleRifle",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("RLDemolitionAmmoBattleRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvDemolition Ammo Battle Rifle.")
		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= Demolition Ammo Battle Rifle =", 2, "CONFONT")
		Goto NotPickup_NoPrint
	NotPickup_NoPrint:
		"####" "#" 0
		Fail
	PickupSound:
		"####" "#" 0 A_PlaySound("weapons/DemoBattleRiflepickup")
		Stop
//==============================================================================
	MarathonStuff:
		"####" "#" 0 A_SpawnItemEx("RLMarathonClip",0,0,0, 0,0,0, 0,SXF_NOCHECKPOSITION)
		Stop
	SuperweaponStuff:
		"####" "#" 0 A_Jump(256, "NoSpecialStartsStuff")
		Goto NoSpecialStartsStuff
	}
}

ACTOR RLDemolitionAmmoBattleRifleWorldSpawnPickup : RLDemolitionAmmoBattleRiflePickup 17823
{
	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:
		DEMR 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("RLDemolitionAmmoBattleRifle",1)
		"####" "#" 0 A_GiveInventory("RLWeaponLimit",1)
		"####" "#" 0 A_Print("\ccPicked up a \cvDemolition Ammo Battle Rifle.")
		"####" "#" 0 A_GiveInventory("RLDangerLevelMasterGiver",1, AAPTR_PLAYER1)
		Goto PickupSound
	}
}
