// ------------------------------------------------------------
//   Plasma Rifle
// ------------------------------------------------------------

ACTOR PlazmaGun : HDWeapon
{
	weapon.selectionorder 600
	weapon.ammotype "PlasmaBattery"
	weapon.ammotype2 "HDCellPacks"
	weapon.ammouse 1
	States
	{
	Ready:
		PLSG A 1 A_WeaponReady(16)
		PLSG A 0 A_TakeInventory("Reloading",999)
		PLSG A 0 A_TakeInventory("IsInterrupting",999)
		loop
	Interrupted:
		PLSG A 1
		PLSG A 0 A_Refire
		goto Ready
	Fire:
		PLSG A 0 A_JumpIfInventory("Reloading",1,"Interrupt")
		PLSG A 0 A_JumpIfInventory("IsInterrupting",1,"Interrupted")
		PLSG A 3 offset (0, 35)
	Hold:
		PLSG A 0 A_JumpIfInventory("Reloading",1,"Interrupt")
		PLSG A 0 A_JumpIfInventory("IsInterrupting",1,"Interrupted")
		PLSG A 0 A_JumpIfInventory("PlasmaBattery",1,"Shoot")
		PLSG C 6
		PLSG C 1 A_Refire
		goto Ready
	Shoot:
		PLSG A 0 A_ZoomFactor(0.99,ZOOM_INSTANT|ZOOM_NOSCALETURNING)
		TNT1 A 0 A_PlayWeaponSound("weapons/plasidle")
		PLSG A 0 A_FireBullets(0,0,1,1,"BeamSpot",FBF_USEAMMO|FBF_NORANDOM,65536)
		TNT1 A 0 A_SpawnItem ("DistantPlasma", 1, 1, 0, 0)
		TNT1 A 0 A_AlertMonsters
		PLSG A 1 offset (0,33)
		PLSG A 1 offset (0,34)
		PLSG A 1 offset (0,32)
		TNT1 A 0 A_ZoomFactor(1.0,ZOOM_INSTANT|ZOOM_NOSCALETURNING)
		TNT1 A 0 A_JumpIfInventory("PlasmaBattery",1,3)
		PLSG A 0 A_PlayWeaponSound ("weapons/plasmas")
		PLSG A 9 A_GunFlash
		PLSG A 1 A_ReFire
		Goto Ready
	Flash:
		PLSF A 1 bright A_Light2
		PLSF BA 1 bright
		PLSF B 1 bright A_Light1
		PLSF AB 1 bright
		PLSF B 0 bright A_Light0
		Stop
	AltFire:
	Althold:
		PLSG A 0 A_TakeInventory ("Reloading", 999)
		PLSG A 1
		PLSG A 0 A_Refire
		goto Ready
	AltholdOn:
		PLSF A 0 A_PlaySound ("weapons/plasidle")
		PLSF A 1 bright A_AlertMonsters
		PLSF A 1 bright A_Light2
		PLSF B 1 bright A_Light1
		PLSF B 1 bright A_Light0
		PLSG A 0 A_Refire
		goto Ready
	Deselect:
		PLSG C 0 A_TakeInventory ("Reloading", 999)
		PLSG A 0 bright A_Light0
		PLSG A 1 A_Lower
		loop
	Select:
		PLSG A 0 A_TakeInventory ("Reloading", 999)
		PLSG A 1 A_Raise
		loop
	Reload:
		PLSG A 0 A_JumpIfInventory ("PlasmaBattery", 60, 2)
		PLSG A 0 A_Jump (256, 2)
		PLSG A 1 A_TakeInventory ("Reloading", 999)
		goto Ready

		PLSG A 4
		PLSG A 0 A_JumpIfInventory("HDCellPacks", 1, 3)
		PLSG A 0 A_JumpIfInventory("Cell", 1, 2)
		PLSG A 0 A_TakeInventory ("Reloading", 999)
		goto Ready

		PLSG A 1 offset(0,35)
		PLSG A 1 offset(0,38)
		PLSG C 16 offset(0,42) A_PlayWeaponSound ("weapons/huntopen")
		PLSG C 14 offset(0,42) A_PlayWeaponSound ("weapons/pocket")
		TNT1 A 0 A_JumpIfHealthLower(20,2)
		TNT1 A 0 A_JumpIf(256,2)
		PLSG C 6 offset(0,42)
		TNT1 A 0 A_TakeInventory("PlasmaCounter",999)
		TNT1 A 0 A_JumpIfHealthLower(40,2)
		TNT1 A 0 A_JumpIf(256,"Reload2")
		PLSG C 10 offset(0,42)
		Goto Reload2
	Reload2:
		TNT1 A 0 A_JumpIfInventory ("PlasmaCounter", 3, "Reload3")
		TNT1 A 0 A_JumpIfInventory ("PlasmaBattery", 60, "Reload3")
		TNT1 A 0 A_JumpIfInventory ("HDCellPacks", 1, 2)
		TNT1 A 0 A_JumpIfInventory ("Cell", 1, 1)
		goto Reload3

		PLSG C 6 offset(0,42)
		PLSG C 8 offset(0,38) A_PlayWeaponSound ("weapons/rifleload")
		TNT1 A 0 A_JumpIfHealthLower(40,2)
		TNT1 A 0 A_JumpIf(256,2)
		PLSG C 4 offset(0,37)
		PLSG C 6 offset(0,36) A_PlayWeaponSound ("weapons/grenopen")
//		PLSG C 0 ACS_ExecuteAlways (554, 0, 4, 40, 0)

		TNT1 A 0 A_JumpIfInventory("HDCellPacks",1,"Reload2a")
		goto Reload2Shitty
	Reload2a:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
		TNT1 A 0 A_JumpIfInventory("PlasmaBattery",41,"Reload2EmptyFirst")
		goto Reload2EmptyFirstEnd
			Reload2EmptyFirst:
			TNT1 A 0 A_JumpIfInventory("PlasmaBattery",1,1)
			goto Reload2EmptyFirstEnd
			TNT1 A 0 A_TakeInventory("PlasmaBattery",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_JumpIfInventory("PlasmaBattery",41,"Reload2EmptyFirst")
			Reload2EmptyFirstEnd:
		TNT1 A 0 A_TakeInventory("HDCellPacks",1)
		TNT1 A 0 A_GiveInventory("PlasmaBattery",20)
		goto Reload2ReturnToPool
	Reload2Shitty:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
		TNT1 A 0 A_JumpIfInventory("PlasmaBattery",41,"Reload2EmptyFirst2")
		goto Reload2EmptyFirstEnd2
			Reload2EmptyFirst2:
			TNT1 A 0 A_JumpIfInventory("PlasmaBattery",1,1)
			goto Reload2EmptyFirstEnd2
			TNT1 A 0 A_TakeInventory("PlasmaBattery",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_JumpIfInventory("PlasmaBattery",41,"Reload2EmptyFirst2")
			Reload2EmptyFirstEnd2:
		PLSG C 1 offset(0,35) ACS_ExecuteAlways (554, 0, 4, random(1,19))
			Reload2ReturnToPool:
			TNT1 A 0 A_JumpIfInventory("ShittyReloadDummy",1,1)
			goto Reload2b
			TNT1 A 0 A_TakeInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_GiveInventory("Cell",1)
			loop
	Reload2b:
		PLSG B 0 A_GiveInventory ("Reloading", 1)
		PLSG B 0 A_GiveInventory ("PlasmaCounter", 1)
		PLSG B 0 offset(0,40) A_JumpIfInventory ("PlasmaBattery", 41, "Reload3")
		PLSG C 1 offset(0,35) A_WeaponReady
		goto Reload2

	Interrupt:
		PLSG C 0 A_GiveInventory("IsInterrupting",1)
	Reload3:
		PLSG C 0 A_TakeInventory ("Reloading", 999)
		PLSG C 6 offset(0,36) A_PlayWeaponSound ("weapons/huntopen")
		PLSG C 2 offset(0,38)
		PLSG C 2 offset(0,40)
		PLSG C 2 offset(0,42)
		PLSG A 4 offset(0,38)
		PLSG A 4 offset(0,35)
		goto Ready
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("PlasmaPickupDropped", 0,0,0,velx,vely,velz,0,32,0)
		stop
		PLAS A -1
		stop
	} 
}
actor PlasmaBattery : Ammo
{
	+inventory.ignoreskill
	+inventory.undroppable
	inventory.maxamount 60
	ammo.backpackmaxamount 60
	ammo.backpackamount 0
}
actor PlasmaCounter : InventoryFlag
{
	inventory.maxamount 3
}

actor BeamSpot
{
	+noblood
	+alwayspuff
	+puffonactors
	+nodamage
	+nogravity
	+noradiusdmg
	+puffgetsowner
	+extremedeath
	damagetype "Beam"
	health 1
	painchance 256
	radius 1
	height 1
	renderstyle add
	scale 0.6
	alpha 0.6
	obituary "%o was surprised by %k's particle beam."
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_Explode(2,12,0,0,12)
		TNT1 A 0 A_ChangeFlag("shootable",1)
		TNT1 A 6
		stop
	pain:
		TNT1 A 0
		stop
	pain.Beam:
		TNT1 A 0 A_ChangeFlag("shootable",0)
		TNT1 A 0 A_SpawnItemEx("BeamSpot2",0,0,0,velx,vely,velz,0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		PLSE AAA 2 A_FadeOut (0.2)
		stop
	}
}
actor BeamSpot1 : BeamSpot
{
	alpha 1.0
	obituary "%o was shocked by %k's particle beam."
	states
	{
	pain.Beam:
		TNT1 A 0 A_ChangeFlag("shootable",0)
		TNT1 A 0 A_SpawnItemEx("BeamSpot2",0,0,0,velx,vely,velz,0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		PLSE AAAAA 2 A_FadeOut (0.2)
		stop
	}
}
actor BeamSpot2 : BeamSpot
{
	states
	{
	pain.Beam:
		TNT1 A 0 A_ChangeFlag("shootable",0)
		TNT1 A 1 A_ChangeFlag("nointeraction",1)
		TNT1 A 0 A_Quake(6,20,0,400,none)
		TNT1 A 0 A_SpawnItemEx("BeamSpotBoom",-4,0,12,velx,vely,velz,0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		TNT1 A 0 A_SpawnItemEx("BeamSpot2",-1,0,1,velx,vely,velz,0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		stop
	}
}
actor BeamSpotBoom : IdleDummy
{
	+forceradiusdmg
	obituary "%o was shocked by %k's particle beam."
	decal "Scorch"
	radius 2
	height 2
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_Explode(320,256,1,1)
		TNT1 AAA 0 A_SpawnItemEx("DistantRocket",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION)
		TNT1 AAA 0 A_SpawnItemEx("HDExplosionBeam",0,0,0,velx+random(-2,2),vely+random(-2,2),velz+random(1,3),0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		TNT1 AAAAAAA 2 A_SpawnItemEx("HDExplosionBeam",0,0,0,velx+random(-2,2),vely+random(-2,2),velz+random(1,3),0,SXF_ABSOLUTEMOMENTUM|SXF_NOCHECKPOSITION|SXF_TRANSFERPOINTERS)
		TNT1 A 40 A_Quake(2,40,0,600,none)
		stop
	}
}
actor HDExplosionBeam : HDExplosion
{
	obituary "%o was awed by %k's particle beam."
}

Actor PlasmaBalle : FastProjectile
{
	damagetype "Thermal"
	obituary "%o was fried by %k's plasma rifle."
	renderstyle add
	scale 0.8
	alpha 0.9
	+skyexplode
	+forcexybillboard
	radius 2
	height 3
	damage 6
	+forceradiusdmg
	-noteleport
	speed 160
	decal "PlasmaShock"
	seesound "weapons/plasmaf"
	deathsound "weapons/plasmax"
	+grenadetrail
	+extremedeath
	States
	{
	Spawn:
		TNT1 A 0
		PLSE B 1 BRIGHT A_SpawnItemEx ("PlasmaBallTailHarmless", 0,0,0, (velx*0.12),(vely*0.12),(velz*0.12), 0,40,0)
	See:
		TNT1 A 0 A_TakeInventory ("Cell", 1)
		PLSS AB 1 BRIGHT A_SpawnItemEx ("PlasmaBallTail", 0,0,0, (velx*0.12),(vely*0.12),(velz*0.12), 0,40,0)
		loop
	Death:
		PLSE AA 1 BRIGHT A_FadeIn (0.2)
		PLSE A 4 BRIGHT A_Explode (random(24,36), 56)
		PLSE BCDE 4 BRIGHT A_FadeOut (0.1)
		Stop
	}
}
actor PlasmaBalleWeak : PlasmaBalle
{
	speed 120
	damage 4
	+extremedeath
	states
	{
	Spawn:
		PLSE BA 1 BRIGHT
		TNT1 A 0 A_GiveInventory ("Cell", 32)
		goto see
	death:
		PLSE A 4 BRIGHT A_Explode (24, 40)
		PLSE BCDE 4 BRIGHT A_FadeOut (0.1)
		Stop
	}
}
actor PlasmaBallTail
{
	damagetype "Thermal"
	obituary "%o was baked by %k's plasma rifle."
	+nointeraction
	+forcexybillboard
	+extremedeath
	renderstyle add
	radius 2
	height 3
	scale 0.4
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_Explode (random(8,16), 36)
		PLSE A 1 A_FadeOut (0.1)
		TNT1 A 0 A_Explode (random(4,12), 24)
		PLSE A 1 A_FadeOut (0.1)
		TNT1 A 0 A_Explode (random(3,8), 18)
		PLSE A 1 A_FadeOut (0.1)
		TNT1 A 0 A_Explode (random(1,4), 12)
	see:
		PLSE A 1 A_FadeOut (0.1)
		loop
	}
}
actor PlasmaBallTailHarmless : PlasmaBallTail
{
	states
	{
	spawn:
		PLSE A 1 A_FadeOut (0.1)
		loop
	}
}


actor PlasmaPickup : HDWeaponPickup replaces PlasmaRifle
{
	scale 0.6
	inventory.pickupmessage "You got the plasma rifle!"
	inventory.pickupsound "misc/w_pkup"
	states
	{
	spawn:
		PLAS A -1
		stop
	PickupFail:
		TNT1 A 0
		fail
	Pickup:
		TNT1 A 0 A_JumpIfInventory ("CanPickUpItems", 1, 1)
		fail
	CheckGun:
		TNT1 A 0 A_JumpIfInventory ("PlazmaGun", 1, 2)
		TNT1 A 0 A_Jump (256, "GivePickupAmmo")
	CheckAmmo:
		TNT1 A 0 A_JumpIfInventory ("Cell", 0, "PickupFail")
	GivePickupAmmo:
		TNT1 A 0 A_GiveInventory ("PlasmaPickupRounds", random(random(1,2),2)*20)
	GiveGun:
		TNT1 A 0 A_JumpIfInventory ("PlazmaGun", 1, "GiveInvAmmo")
		TNT1 A 0 A_GiveInventory ("PlazmaGun", 1)
		TNT1 A 0 A_Jump (256, "GiveGunAmmo")
	GiveInvAmmo:
		TNT1 A 0 A_JumpIfInventory ("PlasmaPickupRounds", 20, "GiveInvMagsAmmo")
		TNT1 A 0 A_GiveInventory ("Cell", 1)
		TNT1 A 0 A_TakeInventory ("PlasmaPickupRounds", 1)
		TNT1 A 0 A_JumpIfInventory ("PlasmaPickupRounds", 1, "GiveInvAmmo")
		stop
	GiveInvMagsAmmo:
		TNT1 A 0 A_GiveInventory ("HDCellPacks", 1)
		TNT1 A 0 A_TakeInventory ("PlasmaPickupRounds", 20)
		goto GiveInvAmmo
	GiveGunAmmo:
		TNT1 A 0 A_GiveInventory ("PlasmaBattery", 1)
		TNT1 A 0 A_TakeInventory ("PlasmaPickupRounds", 1)
		TNT1 A 0 A_JumpIfInventory ("PlasmaPickupRounds", 1, "GiveGunAmmo")
		stop
	}
}
actor PlasmaPickupDropped : PlasmaPickup //replaces PlazmaGun
{
	states
	{
	Pickup:
		TNT1 A 0 A_JumpIfInventory ("CanPickUpItems", 1, 1)
		fail
	CheckGun:
		TNT1 A 0 A_JumpIfInventory ("PlazmaGun", 1, 2)
		TNT1 A 0 A_Jump (256, "GivePickupAmmo")
	CheckAmmo:
		TNT1 A 0 A_JumpIfInventory ("HDCellPacks", 0, "PickupFail")
		TNT1 A 0 A_JumpIfInventory ("Cell", 0, "PickupFail")
	GivePickupAmmo:
		TNT1 A 0 A_GiveInventory ("PlasmaPickupRounds", random(1,40))
		goto GiveGun
	}
}
actor PlasmaPickupRounds : Ammo
{
	+inventory.undroppable
	inventory.maxamount 60
	ammo.backpackmaxamount 60
	ammo.backpackamount 0
}
ACTOR HDCellpacks : Ammo
{
	+inventory.ignoreskill
	+inventory.undroppable
	inventory.maxamount 9
	ammo.backpackmaxamount 18
	ammo.backpackamount 2
}


// ------------------------------------------------------------
//   BFG 9000
// ------------------------------------------------------------

actor BFG9K : HDWeapon
{
	weapon.selectionorder 700
	weapon.kickback 200
	weapon.ammotype "BFGChamber"
	weapon.ammotype2 "HDCellPacks"
	states
	{
	Ready:
		BFGG A 1 A_WeaponReady(16)
		TNT1 A 0 A_TakeInventory("IsInterrupting",999)
		loop
	Select:
		BFGG A 1 A_Raise
		loop
	Deselect:
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		BFGG A 1 A_Lower
		loop
	Interrupted:
		TNT1 A 0 A_TakeInventory("Reloading",999)
		BFGG A 1
		BFGG A 0 A_Refire
		goto Ready
	altfire:
	althold:
		TNT1 A 0 A_JumpIfInventory ("BFGChamber", 20, "Unload")
		BFGG A 1 A_WeaponReady(30)
		BFGG A 0 A_Refire
		goto Ready
	Unload:
		BFGG A 3
		BFGG A 0 A_JumpIfInventory ("BFGChamber", 20, 1)
		goto Ready
		BFGG C 2 offset(0,36)
		BFGG C 2 offset(0,38)
		BFGG C 4 offset(0,40) A_PlaySound ("weapons/rifleclick2")
		BFGG C 16 offset (0,42) A_PlaySound ("weapons/huntopen")
		TNT1 A 0 A_TakeInventory("BFGChamber",20)
		TNT1 AAAAA 0 A_FireCustomMissile("BFGVileShard",random(170,190),-10,random(-20,20),5,0,0)
		TNT1 A 0 A_Jump(192,2)
		TNT1 A 0 A_FireCustomMissile("TurretteSpawner",random(170,190),-10,random(-20,20),5,0,0)
		TNT1 A 0 A_SpawnItemEx("CellPickup",4,0,40,velx,vely,velz,0,SXF_ABSOLUTEANGLE|SXF_NOCHECKPOSITION,0)
		BFGG C 24 offset(0,42) A_PlaySound ("weapons/pocket")
		BFGG C 16 offset(0,37) A_PlaySound ("weapons/rifleclick2")
		BFGG C 2 offset(0,38)
		BFGG C 2 offset(0,36)
		BFGG A 2 offset(0,34)
		BFGG A 6 A_TakeInventory ("Reloading", 999)
		BFGG A 1 A_Refire
		goto Ready
	Fire:
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Interrupt")
		TNT1 A 0 A_JumpIfInventory("IsInterrupting",1,"Interrupted")
		BFGG C 6 A_JumpIfInventory ("BFGChamber", 20, 1)
		goto Ready

		BFGG A 3

		TNT1 A 0 A_TakeInventory ("Timer", 999)
		TNT1 A 0 A_GiveInventory ("Timer", 6)
	charge1:
		TNT1 A 0 A_JumpIfHealthLower (40, "charge1noabort")
		TNT1 A 0 A_JumpIfInventory ("Reloading", 1, "chargeabort")
		TNT1 A 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		TNT1 A 0 A_JumpIfInventory("IsMoving",4,7)
		BFGG BBBBB 1 A_WeaponReady(30)
		TNT1 A 0 A_Jump(256,6)
		BFGG BBBBB 1 offset(0,38) A_WeaponReady(30)
		TNT1 A 0 A_PlaySoundEx ("weapons/plasidle", "soundslot5")
		TNT1 A 0 A_JumpIfInventory ("BFGChamber", 60, "charge1end")
		TNT1 A 0 A_TakeInventory ("BFGChamber", random(1,2))
		TNT1 A 0 A_GiveInventory ("BFGChamber", 2)
		loop
	charge1end:
		TNT1 A 0 A_JumpIfInventory ("Timer", 1, 1)
		goto charge1a
		TNT1 A 0 A_TakeInventory ("Timer", 1)
		goto charge1

	chargeabort:
		BFGG B 10 A_TakeInventory ("Timer", 999)
		BFGG B 0 A_TakeInventory ("Reloading", 999)
		BFGG B 1 A_Refire
		goto ready
	charge1noabort:
		TNT1 A 0 A_Jump (216,6)
		TNT1 A 0 A_JumpIfHealthLower(16,2)
		TNT1 A 0 DamageThing(1)
		TNT1 A 0 A_TakeInventory ("Health", 1)
		BFGG B 1 ACS_Execute (551, 0, 100, 1, 0)
		TNT1 A 0 A_Pain

		TNT1 A 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		TNT1 A 0 A_GiveInventory ("BFGChamber",1)
		goto charge1+2

	charge1a:
		TNT1 A 0 A_GiveInventory ("Timer", 6)
	charge2:
		TNT1 A 0 A_JumpIfHealthLower (40, 2)
		TNT1 A 0 A_JumpIfInventory ("Reloading", 1, "chargeabort")
		goto charge2a
		TNT1 A 0 A_TakeInventory ("Timer", 1)
		TNT1 A 0 A_JumpIfHealthLower (40, 2)
		TNT1 A 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		TNT1 A 0 A_JumpIfInventory("IsMoving",4,5)
		BFGG BBB 1 A_WeaponReady(30)
		TNT1 A 0 A_Jump(256,4)
		BFGG BBB 1 offset(0,38) A_WeaponReady(30)
		TNT1 A 0 A_JumpIfInventory ("Timer", 1, 1)
		TNT1 A 0 A_PlaySoundEx ("weapons/plasidle", "soundslot5")
		loop

	charge2a:
		TNT1 A 0 A_GiveInventory ("Timer", 8)
	charge3:
		TNT1 A 0 A_JumpIfInventory ("Timer", 1, 1)
		goto charge3a
		TNT1 A 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		TNT1 A 0 A_JumpIfInventory("IsMoving",4,4)
		BFGG BB 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
		TNT1 A 0 A_Jump(256,3)
		BFGG BB 1 offset(0,38) A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH|WRF_NOBOB)
		TNT1 A 0 A_TakeInventory ("Timer", 1)
		TNT1 A 0 A_PlaySoundEx ("weapons/plasidle", "soundslot5")
		loop

	charge3a:
		TNT1 A 0 A_GiveInventory ("BFGCycled", 1)
		TNT1 A 0 A_PlayWeaponSound ("weapons/bfgf")
		TNT1 A 0 A_TakeInventory ("BFGChamber", 999)
		TNT1 A 0 A_GiveInventory ("Timer", 8)
	charge4:
		TNT1 A 0 A_JumpIfInventory ("Timer", 1, 1)
		goto chargeend
		TNT1 A 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		TNT1 A 0 A_JumpIfInventory("IsMoving",4,3)
		BFGG B 1 A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH)
		TNT1 A 0 A_Jump(256,2)
		BFGG B 1 offset(0,38) A_WeaponReady(WRF_NOFIRE|WRF_NOSWITCH|WRF_NOBOB)
		TNT1 A 0 A_TakeInventory ("Timer", 1)
		TNT1 A 0 A_PlaySoundEx ("weapons/plasidle", "soundslot5")
		loop

	chargeend:
		BFGG BBB 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		BFGG B 1 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -2)
		BFGG BBB 0 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)
		BFGG B 1 A_FireCustomMissile ("BFGSparkSpawnerSpawner", random(-40,40), 0, 0, -4)

//		TNT1 A 0 A_JumpIfInventory ("IsMoving", 4, 2)
		TNT1 A 0 A_Jump (256, 3)
		BFGG A 1 ACS_Execute (553, 0, (random(0,1)*2-1)*random(4,20),(random(0,1)*2-1)*random(4,28))
		BFGG A 0 ACS_Execute (553, 0, (random(0,1)*2-1)*random(4,20),(random(0,1)*2-1)*random(4,28))

		BFGG A 0 A_AlertMonsters

//		TNT1 A 0 A_JumpIfInventory ("IsMoving", 4, 2)
		TNT1 A 0 A_Jump (256, 2)
		BFGG B 0 ACS_Execute (553, 0, (random(0,1)*2-1)*random(10,26),(random(0,1)*2-1)*random(12,32))
		BFGG B 4 A_GunFlash
//		TNT1 A 0 A_JumpIfInventory ("IsMoving", 4, 2)
		TNT1 A 0 A_Jump (256, 2)
		BFGG B 0 ACS_Execute (553, 0, (random(0,1)*2-1)*random(10,26),(random(0,1)*2-1)*random(12,32))
		BFGG B 4 ACS_ExecuteAlways (558, 0)

		TNT1 A 0 A_PlaySoundEx ("weapons/plasmas", "soundslot5")

		BFGG B 0 A_FireCustomMissile ("BFGBallTail", 0, 1, 0, -4)
		BFGG B 0 A_JumpIfInventory ("PlayingDeathmatch",1,3)
		BFGG B 0 A_FireCustomMissile ("BFGBoll", 0, 0, 0, -4)
		BFGG B 0 A_Jump (256, 2)
		BFGG B 0 A_FireCustomMissile ("BFGBallExploder", 0, 1, 0, -4)
		BFGG B 2 A_FireCustomMissile ("BFGBalle", 0, 1, 0, -4)

		TNT1 A 0 A_TakeInventory ("BFGCycled", 999)
		TNT1 A 0 A_TakeInventory ("Reloading", 999)
		BFGG A 3 ThrustThingZ(0, 62, 1, 0)
		BFGG C 3 A_Recoil (random(4,5))
		BFGG C 10 ACS_Execute (553, 0, random(64, 96), random(12, 18), 0)
		BFGG CC 2 A_Refire
		goto Ready
	Hold:
		TNT1 A 0 A_JumpIfInventory("Reloading",1,"Interrupt")
		TNT1 A 0 A_JumpIfInventory("IsInterrupting",1,"Interrupted")
		BFGG C 0 A_JumpIfInventory ("BFGChamber", 20, "Fire")
		goto Reload
	ReloadAbort:
	  BFGG A 1 A_TakeInventory("Reloading",999)
		Goto Ready
	Reload:
		TNT1 A 0 A_JumpIfInventory("Timer",1,"chargeabort")

		BFGG A 0 A_JumpIfInventory ("BFGChamber", 60, "ReloadAbort")
		BFGG A 4
		BFGG A 0 A_JumpIfInventory ("BFGChamber", 20, 2)
		BFGG A 0 A_JumpIfInventory ("HDCellPacks", 1, 1)
		goto Ready
		BFGG C 2 offset(0,36)
		BFGG C 2 offset(0,38)
		BFGG C 4 offset(0,40) A_PlaySound ("weapons/rifleclick2")
		BFGG C 16 offset (0,42) A_PlaySound ("weapons/huntopen")

		BFGG C 24 offset(0,42) A_PlaySound ("weapons/pocket")
		TNT1 A 0 A_TakeInventory("PlasmaCounter",999)

	Reload2:
		TNT1 A 0 A_JumpIfInventory ("PlasmaCounter", 3, "Reload3")
		TNT1 A 0 A_JumpIfInventory ("BFGChamber", 60, "Reload3")
		TNT1 A 0 A_JumpIfInventory ("HDCellPacks", 1, 2)
		TNT1 A 0 A_JumpIfInventory ("Cell", 1, 1)
		goto Reload3

//		BFGG C 0 ACS_Execute (554, 0, 5, 20, 0)
		BFGG C 12 offset(0,42) A_PlayWeaponSound ("weapons/rifleload")
		BFGG C 10 offset(0,36) A_PlayWeaponSound ("weapons/grenopen")
		TNT1 A 0 A_GiveInventory ("Reloading", 1)
//		BFGG C 1 offset(0,40) A_WeaponReady//(WRF_NOBOB)

		TNT1 A 0 A_JumpIfInventory("HDCellPacks",1,"Reload2a")
		goto Reload2Shitty
	Reload2a:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
		TNT1 A 0 A_JumpIfInventory("BFGChamber",41,"Reload2EmptyFirst")
		goto Reload2EmptyFirstEnd
			Reload2EmptyFirst:
			TNT1 A 0 A_JumpIfInventory("BFGChamber",1,1)
			goto Reload2EmptyFirstEnd
			TNT1 A 0 A_TakeInventory("BFGChamber",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_JumpIfInventory("BFGChamber",41,"Reload2EmptyFirst")
			Reload2EmptyFirstEnd:
		TNT1 A 0 A_TakeInventory("HDCellPacks",1)
		TNT1 A 0 A_GiveInventory("BFGChamber",20)
		goto Reload2ReturnToPool
	Reload2Shitty:
		TNT1 A 0 A_TakeInventory("ShittyReloadDummy",999)
		TNT1 A 0 A_JumpIfInventory("BFGChamber",41,"Reload2EmptyFirst2")
		goto Reload2EmptyFirstEnd2
			Reload2EmptyFirst2:
			TNT1 A 0 A_JumpIfInventory("BFGChamber",1,1)
			goto Reload2EmptyFirstEnd2
			TNT1 A 0 A_TakeInventory("BFGChamber",1)
			TNT1 A 0 A_GiveInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_JumpIfInventory("BFGChamber",41,"Reload2EmptyFirst2")
			Reload2EmptyFirstEnd2:
		BFGG C 1 offset(0,35) ACS_ExecuteAlways (554, 0, 5, random(1,19))
			Reload2ReturnToPool:
			TNT1 A 0 A_JumpIfInventory("ShittyReloadDummy",1,1)
			goto Reload2b
			TNT1 A 0 A_TakeInventory("ShittyReloadDummy",1)
			TNT1 A 0 A_GiveInventory("Cell",1)
			loop
	Reload2b:
		PLSG B 0 A_GiveInventory ("Reloading", 1)
		PLSG B 0 A_GiveInventory ("PlasmaCounter", 1)
		PLSG B 0 offset(0,40) A_JumpIfInventory ("BFGChamber", 41, "Reload3")
		BFGG C 1 offset(0,38) A_WeaponReady//(WRF_NOBOB)
		goto Reload2

	Interrupt:
		TNT1 A 0 A_GiveInventory("IsInterrupting",1)
	Reload3:
		BFGG C 12 offset(0,38) A_PlaySound ("weapons/huntopen")
		BFGG C 16 offset(0,37) A_PlaySound ("weapons/rifleclick2")
		BFGG C 2 offset(0,38)
		BFGG C 2 offset(0,36)
		BFGG A 2 offset(0,34)
		BFGG A 12 A_TakeInventory ("Reloading", 999)
		goto Ready
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx ("BFGPickupDropped", 0,0,0,velx,vely,velz,0,32,0)
		stop
		BFUG A -1
		stop
	}
}
actor BFGCycled : InventoryFlag {}
ACTOR BFGChamber : Ammo
{
	+inventory.undroppable
	inventory.maxamount 60
	ammo.backpackmaxamount 60
	ammo.backpackamount 0
}

actor BFGSParkSpawnerSpawner
{
	projectile
	+nointeraction
	damage 0
	height 0
	radius 0
	speed 40
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_SpawnItemEx ("BFGSparkSpawner",0,0,0, velx,vely,(velz+random(-30,30)),0,168)
		stop
	}
}
actor BFGSParkSpawner
{
	+nointeraction
	height 0
	radius 0
	states
	{
	spawn:
		TNT1 A 1
		TNT1 A 0 A_SpawnItemEx ("BFGSpark",0,0,0, (-velx/10),(-vely/10),(-velz/10),0,168)
		stop
	}
}
actor BFGSpark
{
	scale 0.16
	+nointeraction
	+forcexybillboard
	radius 0
	height 0
	renderstyle add
	alpha 0.1
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_GiveInventory ("Timer", 10)
	spawn2:
		TNT1 A 0 A_JumpIfInventory ("Timer",1,1)
		goto death
		TNT1 A 0 A_TakeInventory ("Timer", 1)
		TNT1 A 0 A_JumpIfCloser (1, "death")
		BFE2 D 1 bright A_FadeIn (0.1)
		loop
	death:
		BFE2 D 1 A_FadeOut (0.3)
		loop
	}
}
actor BFGVileShard
{
	+ismonster
	+float
	+nogravity
	+noclip
	+lookallaround
	radius 0
	height 0
	renderstyle add
	speed 12
	scale 0.16
	states
	{
	spawn:
		BFE2 A 0
		BFE2 A 0 A_SetGravity (0.1)
		BFE2 AB 1 bright A_Look
		loop
	see:
		BFE2 D 0 A_Jump (64, 2)
		BFE2 D 0 ThrustThingZ (0, random(-4, 8), 0, 0)
		BFE2 D 1 bright A_JumpIf(alpha < 0.2, "see2")
		BFE2 D 1 A_Wander
		BFE2 A 0 A_CustomMissile ("BFGSpark", 0, random(-24, 24), random(-24, 24), 2, random(-14, 14))
		BFE2 A 1 bright
		BFE2 A 0 A_Wander
		BFE2 B 1 bright A_FadeOut (0.1)
		BFE2 A 0 A_Wander
		loop
	see2:
		TNT1 A 1 A_VileChase
		loop
	heal:
		TNT1 A 1
		stop
	}
}

actor BFGBalle : BFGBall
{
	decal BFGLightning
	alpha 0.9
	height 6
	radius 6
	+skyexplode
	+foilinvul
	+forceradiusdmg
	-noteleport
	+telestomp
	speed 20
	obituary "%o was good for goose, and good for %k's Big F(ornicat)ing Gander."
	states
	{
	spawn:
		TNT1 A 0
		BFS1 AB 2 bright A_SpawnItemEx ("BFGBallTail", 0,0,0, (velx*0.2),(vely*0.2),(velz*0.2), 0,168,0)
		loop
	death:
		BFE1 A 2 ACS_ExecuteAlways (558, 0)
		TNT1 A 0 A_JumpIfInventory ("PlayingDeathmatch", 1, 2)
		TNT1 A 0 A_Jump (256, 2)
		BFE1 B 0 bright A_Explode (1024, 1024, 0)
		BFE1 B 2 bright A_Explode (160, 512, 0)
		TNT1 A 0 A_SpawnItemEx ("DistantBFG", 0,0,0, 0,0,0, 0,160)
		BFE1 B 4 bright Radius_Quake (2, 21, 0, 10, 0)
		BFE1 C 8 bright A_BFGSpray
		BFE1 DEF 6 bright
	fade:
		BFE1 F 6 A_FadeOut (0.2)
		loop
	}
}
actor BFGBallTail
{
	+nointeraction
	+forcexybillboard
	scale 0.8
	renderstyle add
	states
	{
	spawn:
		BFS1 AB 2 bright A_FadeOut (0.2)
		loop
	}
}
actor BFGBoll
{
	-noteleport
	+telestomp
	+notarget
	projectile
	damage 10
	speed 20
	radius 6
	height 6
	damagetype "BFGBallAttack"
	+friendly
	+missilemore
	+missileevenmore
	+forcexybillboard
	minmissilechance 256
	+lookallaround
	+shortmissilerange
	+bloodlessimpact
	+foilinvul
	+quicktoretaliate
	decal BFGLightningSmall
	renderstyle add
	speed 20
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_ClearTarget
		TNT1 AAAAAA 0 A_Look
		APLS A 1 bright A_Look
		TNT1 AAAAAAA 0 A_Look
		APLS B 1 bright A_Look
		loop
	see:
		APLS AB 1 bright
		goto missile
	missile:
		APLS A 1 bright A_CustomRailgun (0, 3, "55 ff 88", none, RGF_SILENT|RGF_NOPIERCING, 0, 0.4, "BFGPuff",0,0,0,0,0,6.6)
		APLS B 0 bright A_CustomBulletAttack (0, 0, 1, 16, "BFGPuff")
		APLS B 1 bright A_CustomBulletAttack (4, 4, 2, 8, "BFGPuff")
		goto spawn
		TNT1 A 0 A_CPosRefire
		loop
	death:
		APBX ABCDE 2 bright A_FadeOut (0.2)
		stop
	}
}
ACTOR BFGPuff
{
	+nointeraction
	+forcexybillboard
	+bloodlessimpact
	+noblood
	-allowparticles
	+puffonactors
	+puffgetsowner
	+forceradiusdmg
	+foilinvul
	renderstyle add
	damagetype "BFGBallAttack"
	scale 0.8
	states
	{
	spawn:
		BFE2 A 0
		BFE2 A 0 A_Jump (200, 2)
		BFE2 A 0 A_PlaySoundEx ("misc/bfgrail", "SoundSlot5")
		BFE2 A 4 bright A_Explode (random(24,120), 256)
		BFE2 ABCDE 2 bright A_FadeOut (0.1)
		stop
	}
}
actor BFGBallExploder : BFGBalle
{
	speed 2
	+bloodlessimpact
	+ripper
	+forcexybillboard
	damage 1
	damagetype ""
	decal "BFGLightning"
	obituary "%o couldn't be bothered to get away from %k's BFG."
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 A_Scream
	death:
		BFE1 A 3 bright
		TNT1 A 0 A_SpawnItemEx ("DistantBFG", 0,0,0, 0,0,0, 0,160)
		BFE1 B 1 bright A_Explode (256, 512, 0)
		BFE1 B 3 bright Radius_Quake (2, 21, 0, 10, 0)
		BFE1 B 1 bright A_BFGSpray
		BFE1 CC 4 bright A_BFGSpray
		BFE1 DEF 5 bright
	fade:
		BFE1 F 3 A_FadeOut (0.2)
		loop
	}
}


actor BFGPickup : HDWeaponPickup replaces BFG9000
{
	scale 0.7
	inventory.pickupmessage "You got the BFG 9000! Oh yes."
	inventory.pickupsound "misc/w_pkup"
	states
	{
	spawn:
		BFUG A -1
		stop
	PickupFail:
		TNT1 A 0
		fail
	Pickup:
		TNT1 A 0 A_JumpIfInventory ("CanPickUpItems", 1, 1)
		fail
	CheckGun:
		BFUG A 0 A_JumpIfInventory ("BFG9K", 1, 2)
		TNT1 A 0 A_Jump (256, "GivePickupAmmo")
	CheckAmmo:
		BFUG A 0 A_JumpIfInventory ("HDCellPacks", 0, 1)
		goto GivePickupAmmo
		BFUG A 0 A_JumpIfInventory ("Cell", 0, "PickupFail")
	GivePickupAmmo:
		BFUG A 0 A_GiveInventory ("PlasmaPickupRounds", random(1,2)*20+random(random(1,20),20))
	GiveGun:
		TNT1 A 0 A_JumpIfInventory ("BFG9K", 1, "GiveInvAmmo")
		TNT1 A 0 A_GiveInventory ("BFG9K", 1)
		goto GiveGunAmmo
	GiveInvAmmo:
		TNT1 A 0 A_JumpIfInventory ("PlasmaPickupRounds", 20, "GiveInvMagsAmmo")
		TNT1 A 0 A_GiveInventory ("Cell", 1)
		TNT1 A 0 A_TakeInventory ("PlasmaPickupRounds", 1)
		TNT1 A 0 A_JumpIfInventory ("PlasmaPickupRounds", 1, "GiveInvAmmo")
		stop
	GiveInvMagsAmmo:
		TNT1 A 0 A_GiveInventory ("HDCellPacks", 1)
		TNT1 A 0 A_TakeInventory ("PlasmaPickupRounds", 20)
		goto GiveInvAmmo
	GiveGunAmmo:
		BFUG A 0 A_GiveInventory ("BFGChamber", 1)
		BFUG A 0 A_TakeInventory ("PlasmaPickupRounds", 1)
		BFUG A 0 A_JumpIfInventory ("PlasmaPickupRounds", 1, "GiveGunAmmo")
		stop
	}
}
actor BFGPickupDropped : BFGPickup //replaces BFG9K
{
	states
	{
	Pickup:
		TNT1 A 0 A_JumpIfInventory ("CanPickUpItems", 1, 1)
		fail
	CheckGun:
		BFUG A 0 A_JumpIfInventory ("BFG9K", 1, 2)
		TNT1 A 0 A_Jump (256, "GivePickupAmmo")
	GivePickupAmmo:
		BFUG A 0 A_GiveInventory ("PlasmaPickupRounds", 20+random(1,random(1,40)))
		goto GiveGun
	CheckAmmo:
		BFUG A 0 A_JumpIfInventory ("HDCellPacks", 0, 1)
		goto GivePickupAmmo
		BFUG A 0 A_JumpIfInventory ("Cell", 300, "PickupFail")
		goto GivePickupAmmo
	}
}
