ACTOR SmoothBFG9000 : DoomWeapon
{
	Height 20
	Weapon.SelectionOrder 2800
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 1
	Weapon.AmmoType1 "BFGCell1"
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 40
	Weapon.AmmoType2 "BFGCell2"
	+WEAPON.NOAUTOFIRE
	+WEAPON.AMMO_CHECKBOTH
	Inventory.PickupMessage "$GOTBFG9000"
	Tag "$TAG_BFG9000"
	Obituary "$OB_MPBFG_SPLASH" // "%o couldn't hide from %k's BFG"
	States
	{
	Ready:
		BFGG A 1 A_WeaponReady(0)
		Loop
	Deselect:
		BFGS FEDCB 1
		BFGS A 1 A_Lower(1) // state smoothed for animation
		Wait
	Select:
		BFGS A 1 A_Raise(1) // state smoothed for animation
		BFGS BCDEF 1
		Goto Ready
	Fire:
        TNT1 A 0 A_JumpIfInventory("BFGCell1",1,2,AAPTR_DEFAULT)
        Goto Click
		TNT1 A 0 A_JumpIf(GetCVAR("bdoom_shakes") == 0, "Fire.Noshake")
		TNT1 A 0 A_JumpIf(GetCVAR("bdoom_weapons") == 1, "Fire.Enhanced")
		BFGG A 1 A_PlaySound("Weapons/BFGF",CHAN_WEAPON,1.0,false,attn_norm,false) // Tic 1 of 20 in BFGG A 20 A_BFGSound. This animation is used to show the red lights brightening during warmup. The sound call is its own tic to prevent bugs
		BFGG BCDEFGHIJKLMNOPQRST 1 // Tics 2-20 of 20 in BFGG A 20 A_BFGSound. Rest of the "brightening warmup lights" animation
		BFG2 A 1 A_GunFlash("Flash",0) // Tic 1 of 10 in BFGG B 10 A_GunFlash. Used for the pre-fire kick.
		BFG2 BCDEFGHIJ 1 // Tics 2-10 of 10 in BFGG B 10 A_GunFlash
		BFG2 K 1 // Tic 1 of 10 in BFGG B 10 A_FireBFG. Used for the firing.
		{
		A_QuakeEx(1,1,1,20,0,128,"world/quake",0,1.0,1.0,1.0,0,0,1.0,1.0);
		A_FireProjectile("SmoothBFGBall1",0.0,true,0.0,0.0,0,0.0);
		}
		BFG2 LMNOPQRST 1 // Tics 2-10 of 10 in BFGG B 10 A_FireBFG. Used for post-fire cooldown
		TNT1 A 0 A_ReFire("Fire")
		Goto Cooldown
	Fire.Noshake:
        TNT1 A 0 A_JumpIfInventory("BFGCell1",1,2,AAPTR_DEFAULT)
        Goto Click
		BFGG A 1 A_PlaySound("Weapons/BFGF",CHAN_WEAPON,1.0,false,attn_norm,false)
		BFGG BCDEFGHIJKLMNOPQRST 1
		BFG2 A 1 A_GunFlash("Flash",0)
		BFG2 BCDEFGHIJ 1
		BFG2 K 1 A_FireProjectile("SmoothBFGBall1",0.0,1,0.0,0.0,0,0.0)
		BFG2 LMNOPQRST 1
		TNT1 A 0 A_ReFire("Fire.Noshake")
		Goto Cooldown
	Fire.Enhanced:
        TNT1 A 0 A_JumpIfInventory("BFGCell1",1,2,AAPTR_DEFAULT)
        Goto Click
		BFGG A 1 A_PlaySound("Weapons/EnhancedBFG/Charge",CHAN_WEAPON,1.0,false,attn_norm,false)
		BFGG BCDEFGHIJKLMNOPQRST 1
		goto Hold.Enhanced
	Hold.Enhanced:
        TNT1 A 0 A_JumpIfInventory("BFGCell1",1,2,AAPTR_DEFAULT)
        Goto Click
		TNT1 A 0 A_JumpIf(GetCVAR("bdoom_shakes") == 0, "Hold.Enhanced.Noshake")
		BFG2 A 1 A_GunFlash("Flash",0)
		BFG2 BCDEFGHIJ 1
		BFG2 K 1
		{
		A_QuakeEx(1,1,1,20,0,128,"world/quake",0,1.0,1.0,1.0,0,0,1.0,1.0);
		A_FireProjectile("SmoothBFGBall2",0.0,true,0.0,0.0,0,0.0);
		}
		BFG2 LMNOPQRST 1
		TNT1 A 0 A_ReFire("Hold.Enhanced")
		Goto Cooldown
	Hold.Enhanced.Noshake:
        TNT1 A 0 A_JumpIfInventory("BFGCell1",1,2,AAPTR_DEFAULT)
        Goto Click
		BFG2 A 1 A_GunFlash("Flash",0)
		BFG2 BCDEFGHIJ 1
		BFG2 K 1 A_FireProjectile("SmoothBFGBall2",0.0,true,0.0,0.0,0,0.0)
		BFG2 LMNOPQRST 1
		TNT1 A 0 A_ReFire("Hold.Enhanced.Noshake")
		Goto Cooldown
	Cooldown:
		TNT1 A 0 A_JumpIf(GetCVAR("bdoom_debris")==0,"Cooldown.NoEffects")
		BFGG T 1 // Tic 1 of 20 in BFGG B 20 A_Refire. This animation is used to show the red lights dimming during cooldown
		{
		A_Playsound("weapons/bfg/cool",CHAN_WEAPON,1.0,false,attn_norm,false);
		A_SpawnItemEx("WeaponSmoke",cos(pitch)*25,random(-5,5),sin(-pitch)*25+random(33,37),0,0,1,0,0,0,0);
		}
		BFGG SRQPONMLKJIHGFEDCBA 1 // Tics 2-20 of 20 in BFGG B 20 A_ReFire
		Goto Ready
	Cooldown.NoEffects:
		BFGG T 1 A_Playsound("weapons/bfg/cool",CHAN_WEAPON,1.0,false,attn_norm,false)
		BFGG SRQPONMLKJIHGFEDCBA 1
		Goto Ready
	Flash:
		BFGF ABCDEFGHIJK 1 Bright A_Light(1) // BFGF A 11 Bright A_Light1
		BFGF LMNOPQ 1 Bright A_Light(2) // BFGF B 6 Bright A_Light2
		Goto LightDone
	Spawn:
		BFUG A -1
		Stop
	AltFire:
        TNT1 A 0 A_JumpIfInventory("BFGCell2",1,2,AAPTR_DEFAULT)
        Goto Click
		BFG3 A 1 A_PlaySound("Weapons/BFGF",CHAN_WEAPON,1.0,false,attn_norm,false) // BFGG A 10 A_BFGSound. Warmup/pre-fire kick
		BFG3 BCDEFGHIJ 1
		AltHold:
        TNT1 A 0 A_JumpIfInventory("BFGCell2",1,2,AAPTR_DEFAULT)
        Goto Click
        TNT1 A 0
		BFG3 K 1 // BFGG BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 1 A_FireOldBFG
		{
		A_FireCustomMissile("SmoothGreenBetaPlasmaBall",frandom(8.0,-8.0),0,frandom(5.0,-5.0),frandom(5.0,-5.0),FPF_NOAUTOAIM,frandom(5.0,-5.0));
		A_FireCustomMissile("SmoothRedBetaPlasmaBall",frandom(8.0,-8.0),0,frandom(5.0,-5.0),frandom(5.0,-5.0),FPF_NOAUTOAIM,frandom(5.0,-5.0));
		A_TakeInventory("BFGCell2",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		A_Light(2);
		}
		TNT1 A 0 A_ReFire("AltHold")
		Goto AltCooldown
	AltCooldown:
		BFG4 TSRQPONMLKJIHGFEDCBA 1 A_Light(0) // Used for the post-fire recoil recovery, followed by the light dimming.
		Goto Ready
	Click:
		TNT1 A 0 A_PlaySound("weapons/dry",CHAN_BODY,1.0,0,ATTN_NORM,false)
		Goto Ready
	}
}

ACTOR SmoothBFGBall1 // all states must be fully smoothed & have a full 16 rotations per frame.
{
	Radius 13
	Height 8
	Speed 25
	Damage 100
	Projectile
	+DONTBLAST
	+RANDOMIZE
	+BLOODLESSIMPACT
	+FORCEXYBILLBOARD
	+THRUGHOST
	+SKYEXPLODE
	RenderStyle Add
	Alpha 0.7
	decal "" //BFGLightning //so that its rays don't leave decals
	translation "192:207=112:127"
	scale 0.4
	activesound "weapons/bfg/fly"
	DeathSound "weapons/bfgx"
	Obituary "$OB_MPBFG_BOOM"
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_debris")==0,"Spawn.noeffects")
		BFS1 ABCDEFGH 1 Bright
		{
		A_SpawnItemEx("BFGTrail",0.0,0.0,0.0,velx,vely,velz,0.0,SXF_SETMASTER|SXF_ORIGINATOR|SXF_ABSOLUTEVELOCITY,0,0);
		A_CustomRailGun(0,0,none,green,RGF_SILENT|RGF_NOPIERCING,0,4.0,"BFGBallRayPuff",frandom(0.0,360.0),frandom(0.0,360.0),64.0,20,0.0,4.0,"BFGBallRay",0.0,270,0);
		}
		Loop
	Spawn.noeffects:
		BFS1 ABCDEFGH 1 Bright A_CustomRailGun(0,0,none,green,RGF_SILENT|RGF_NOPIERCING,0,4.0,"BFGBallRayPuff",frandom(0.0,360.0),frandom(0.0,360.0),64.0,20,0.0,4.0,"BFGBallRay",0.0,270,0)
		Loop
	Death.Sky:
		TNT1 A 0 A_RemoveChildren(1,RMVF_EVERYTHING,"none","none")
		stop
	Death:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_shakes")==0,"Death.noshake")
		BFD1 A 1 Bright
		{
		A_RemoveChildren(1,RMVF_EVERYTHING,"none","none");
		A_SprayDecal("BFGLightning",32);//I already have decal graphics
		A_SetScale(1.0,1.0,aaptr_default,false);
		A_QuakeEx(1,1,1,34,0,256,"world/quake",0,1.0,1.0,1.0,0,0,1.0,1.0);
		}
		BFD1 BCDEFGH 1 Bright
		BFD1 I 1 Bright A_BFGSpray("SmoothBFGExtra",40,15,90.0,1024.0,32.0,0,0|0)
		BFD1 JKLMNOP 1 Bright
		BFD2 ABCDEFGHIJKLMNOPQRSTUVWX 1 Bright
		Stop
	Death.noshake:
		BFD1 A 1 Bright
		{
		A_RemoveChildren(1,RMVF_EVERYTHING,"none","none");
		A_SprayDecal("BFGLightning",32);
		A_SetScale(1.0,1.0,aaptr_default,false);
		}
		BFD1 BCDEFGH 1 Bright
		BFD1 I 1 Bright A_BFGSpray("SmoothBFGExtra",40,15,90.0,1024.0,32.0,0,0|0)
		BFD1 JKLMNOP 1 Bright
		BFD2 ABCDEFGHIJKLMNOPQRSTUVWX 1 Bright
		Stop
	}
}

ACTOR SmoothBFGBall2 // uses same sprites, defines custom sounds.
{
	Radius 13
	Height 8
	Speed 25
	Damage 100
	Projectile
	+DONTBLAST
	+RANDOMIZE
	+BLOODLESSIMPACT
	+FORCEXYBILLBOARD
	+THRUGHOST
	+SKYEXPLODE
	RenderStyle Add
	alpha 0.7
	decal "" //BFGLightning
	translation "192:207=112:127"
	scale 0.4
	seesound "weapons/bfg/fire" // enhanced BFG ball has an internally defined "see sound" that sounds like a remastered version of the "projectile launch" part of the Vanilla BFG's fire sound
	activesound "weapons/bfg/fly"
	DeathSound "weapons/bfg/explosion"
	Obituary "$OB_MPBFG_BOOM"
	States
	{
	Spawn:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_debris")==0,"Spawn.noeffects")
		BFS1 ABCDEFGH 1 Bright
		{
		A_SpawnItemEx("BFGTrail",0.0,0.0,0.0,velx,vely,velz,0.0,SXF_SETMASTER|SXF_ORIGINATOR|SXF_ABSOLUTEVELOCITY,0,0);
		A_CustomRailGun(0,0,none,green,RGF_SILENT|RGF_NOPIERCING,0,4.0,"BFGBallRayPuff",frandom(0.0,360.0),frandom(0.0,360.0),64.0,20,0.0,4.0,"BFGBallRay",0.0,270,0);
		}
		Loop
	Spawn.noeffects:
		BFS1 ABCDEFGH 1 Bright A_CustomRailGun(0,0,none,green,RGF_SILENT|RGF_NOPIERCING,0,4.0,"BFGBallRayPuff",frandom(0.0,360.0),frandom(0.0,360.0),64.0,20,0.0,4.0,"BFGBallRay",0.0,270,0)
		Loop
	Death.Sky:
		TNT1 A 0 A_RemoveChildren(1,RMVF_EVERYTHING,"none","none")
		stop
	Death:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_shakes")==0,"Death.noshake")
		BFD1 A 1 Bright
		{
		A_RemoveChildren(1,RMVF_EVERYTHING,"none","none");
		A_SprayDecal("BFGLightning",32);
		A_SetScale(1.0,1.0,aaptr_default,false);
		A_QuakeEx(1,1,1,34,0,256,"world/quake",0,1.0,1.0,1.0,0,0,1.0,1.0);
		}
		BFD1 BCDEFGHIJKLMNOP 1 Bright
		BFD1 Q 1 Bright A_BFGSpray("SmoothBFGExtra",40,15,90.0,1024.0,32.0,0,0|0)
		BFD1 RSTUVWX 1 Bright
		BFD2 ABCDEFGHIJKLMNOPQRSTUVWX 1 Bright
		Stop
	Death.noshake:
		BFD1 A 1 Bright
		{
		A_RemoveChildren(1,RMVF_EVERYTHING,"none","none");
		A_SprayDecal("BFGLightning",32);
		A_SetScale(1.0,1.0,aaptr_default,false);
		}
		BFD1 BCDEFGHIJKLMNOP 1 Bright
		BFD1 Q 1 Bright A_BFGSpray("SmoothBFGExtra",40,15,90.0,1024.0,32.0,0,0|0)
		BFD1 RSTUVWX 1 Bright
		BFD2 ABCDEFGHIJKLMNOPQRSTUVWX 1 Bright
		Stop
	}
}

Actor DebrisGeneral
{
	+FIXMAPTHINGPOS
	+LOOKALLAROUND
	+NOTAUTOAIMED
	+MISSILE
	+NOBLOCKMAP
	+MOVEWITHSECTOR
	+NOGRAVITY
	+DROPOFF
	+NOTELEPORT
	+FORCEXYBILLBOARD
	//+NOTDMATCH
	+GHOST
	+THRUACTORS
	+FLOORCLIP
	renderstyle Translucent
	alpha 1.0
	radius 1
	height 1
	mass 1
	damage 0
}

Actor BFGTrail : DebrisGeneral // I already have this fully-smooth sprite, I just need an extra 15 rotations
{
	alpha 0.4
	scale 0.5
	+NOINTERACTION
	+NOCLIP
	-MISSILE
	-FORCEXYBILLBOARD
	renderstyle Add
	states
	{	
	Spawn:
		TNT1 A 0 NoDelay A_JumpIf(GetCVAR("Bdoom_debris")==0,"Null")
		LENG A 1 bright A_Warp(AAPTR_MASTER,0.0,0.0,0.0,0.0,0,"",0.0,0.0,0.0)
		wait
	}
}

Actor BFGBallRay : DebrisGeneral // I already have this fully-smooth sprite, I just need an extra 15 rotations
{
	-MISSILE
	+NOINTERACTION
	renderstyle Add
	alpha 0.5
	scale .03
	translation "192:207=112:127"
	states
	{
	Spawn:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_debris")==0,"Spawn.noeffects")
		PEXP A 1 bright
		{
		A_SpawnItemEx("BFGBallRayFlare",0.0,0.0,0.0,0.0,0.0,0.0,0.0,0,0,0);
		A_FadeOut(0.08,FTF_REMOVE|0);
		}
		PEXP BCDEFGHIJKLM 1 bright A_FadeOut(0.08,FTF_REMOVE|0)
		stop
	Spawn.noeffects:
		PEXP ABCDEFGHIJKLM 1 bright A_FadeOut(0.08,FTF_REMOVE|0)
		stop
	}
}

Actor BFGBallRayFlare : DebrisGeneral // I already have this fully-smooth sprite, I just need an extra 15 rotations
{
	+NOINTERACTION
	+NOCLIP
	-MISSILE
	-FORCEXYBILLBOARD
	renderstyle Add
	alpha 0.1
	scale 0.07
	states
	{
	Spawn:
		TNT1 A 0 NoDelay A_JumpIf(GetCVAR("Bdoom_debris")==0,"Null")
		LENG A 1 bright A_FadeOut(0.01,FTF_REMOVE|0)
		wait
	}
}

Actor BFGBallRayPuff
{
	damagetype none
	+BLOODLESSIMPACT
}

Actor BFGGreenPlasmaPiece : DebrisGeneral // I already have this fully-smooth sprite, I just need an extra 15 rotations
{
	translation "192:207=112:127","240:247=9:12"
	+NOINTERACTION
	+DONTSPLASH
	-NOGRAVITY
	renderstyle Add
	alpha .5
	speed 3
	scale .1
	gravity 0.8
	states
	{
	Spawn:
		TNT1 A 0 A_JumpIf(GetCVAR("Bdoom_debris")==0,"Null")
		PLBS A 1 bright A_FadeOut(0.03,FTF_REMOVE|0)
		loop
	}
}

ACTOR SmoothBFGExtra // need fully-smoothed sprites & a full 16 rotations for each, based on the vanilla animations
{
	+NOBLOCKMAP
	+NOGRAVITY
	RenderStyle Add
	Alpha 0.75
	DamageType "BFGSplash"
	Obituary "$OB_MPBFG_SPLASH" // "%o couldn't hide from %k's BFG"
	States
	{
	Spawn:
		BFE1 A 1 Bright
		{
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		A_SpawnProjectile("BFGGreenPlasmaPiece",0.0,0.0,frandom(-360.0,360.0),2,frandom(-80.0,80.0),aaptr_target);
		}
		BFE1 BCDEFGHIJKLMNOPQRSTUVWX 1 Bright
		BFE2 ABCDEFGH 1 Bright
		Stop
	}
}

ACTOR SmoothGreenBetaPlasmaBall // need fully-smoothed sprites & a full 16 rotations for each, based on the vanilla animations. Also needs a full sound effect set
{
	Radius 13
	Height 8
	Speed 25
	Damage 4
	BounceType "Classic"
	BounceFactor 1.0
	Projectile
	+RANDOMIZE
	RenderStyle Add
	Alpha 0.75
	SeeSound "weapons/bfggreenbetaplasmaf"
	DeathSound "weapons/bfggreenbetaplasmax"
	ActiveSound "weapons/bfggreenbetaplasmaa"
	BounceSound "weapons/bfggreenbetaplasmachb"
	WallBounceSound "weapons/bfggreenbetaplasmavb"
	Obituary "$OB_MPBFG_MBF" // "%o was burned by %k's BFG."
	States
	{
	Spawn:
		SPLG ABCDEFGHIJKL 1 Bright
		Loop
	Death:
		BPGD ABCDEFGHIJKLMNOPQRST 1 Bright
		Stop
	}
}

ACTOR SmoothRedBetaPlasmaBall : SmoothGreenBetaPlasmaBall // need fully-smoothed sprites & a full 16 rotations for each, based on the vanilla animations. Also needs a full sound effect set
{
	SeeSound "weapons/bfgredbetaplasmaf"
	DeathSound "weapons/bfgredbetaplasmax"
	ActiveSound "weapons/bfgredbetaplasmaa"
	BounceSound "weapons/bfgredbetaplasmahb"
	WallBounceSound "weapons/bfgredbetaplasmavb"
	States
	{
	Spawn:
		PLS2 ABCDEFGHIJKL 1 Bright
		Loop
	Death:
		PLS2 MNOPQRSTUVWX 1 Bright
		Stop
	}
}

ACTOR BFGCell1 : Ammo // small primary ammo. New Sprite from scratch
{
	Scale 0.315
	Inventory.Amount 1
	Inventory.MaxAmount 9
	Inventory.PickupSound "cellget"
	Ammo.BackpackAmount 1
	Ammo.BackpackMaxAmount 18
	Inventory.PickupMessage "$GOTBFG9KCELLS1"
	Inventory.Icon "BF1CA0"
	States
	{
	Spawn:
		BF1C A -1
		Stop
	}
}

ACTOR BFGCell1big : BFGCell1 // large primary ammo. New Sprite from scratch
{
	Scale 0.315
	Inventory.Amount 3
	Inventory.PickupMessage "$GOTBFG9KCELLS1"
	States
	{
	Spawn:
		BF1C B -1
		Stop
	}
}

ACTOR BFGCell2 : Ammo // small secondary ammo. New Sprite from scratch
{
	Scale 0.315
	Inventory.Amount 20
	Inventory.MaxAmount 300
	Inventory.PickupSound "cellget"
	Ammo.BackpackAmount 20
	Ammo.BackpackMaxAmount 600
	Inventory.PickupMessage "$GOTBFG9KCELLS1"
	Inventory.Icon "BF2CA0"
	States
	{
	Spawn:
		BF2C A -1
		Stop
	}
}

ACTOR BFGCell2big : BFGCell2 // large secondary ammo. New Sprite from scratch
{
	Scale 0.315
	Inventory.Amount 100
	Inventory.PickupMessage "$GOTBFG9KCELLS1"
	States
	{
	Spawn:
		BF2C B -1
		Stop
	}
}