ACTOR SurvivalistPipebombs : Weapon 
{
//$Category Weapons
//$Title "Pipebombs"
Inventory.PickupSound "misc/i_pkup"
Inventory.PickupMessage "Picked up a Pipebomb."
Weapon.AmmoType "SurvPipebombAmmo"
Weapon.AmmoGive 1
Weapon.AmmoUse 1
Weapon.SelectionOrder 2600
+WEAPON.NOAUTOAIM
+WEAPON.NOALERT
+WEAPON.AMMO_OPTIONAL
Scale 0.3
Tag "Pipebombs"
Inventory.RestrictedTo "SurvivalistClass"
States
	{
	Spawn:
		PIPP A -1
		Stop
	Ready:
		PIP1 A 0 A_JumpIfNoAmmo("ReadyNoAmmo")
		PIP1 A 1 A_WeaponReady(WRF_NOSECONDARY)
		Loop
	ReadyNoAmmo:
		NPIP A 1 A_WeaponReady(WRF_NOPRIMARY|WRF_NOSECONDARY)
		NPIP A 0 A_JumpIfInventory("SurvPipebombAmmo",1,"Ready")
		Loop
	ReadyDetonator:
		DETO A 0 A_JumpIfNoAmmo("ReadyDetonatorNoAmmo")
		DETO A 1 A_WeaponReady
		Loop
	ReadyDetonatorNoAmmo:
		DETO A 0 A_JumpIfInventory("SurvPipebombAmmo",1,"ReadyDetonator")
		DETO A 1 A_WeaponReady(WRF_NOSECONDARY)
		Loop
	Deselect:
		"####" "#" 0 A_TakeInventory("DetonatorCheck")
		"####" "#" 0 A_TakeInventory("PipeThrowSpeed",10)
		"####" "#" 1 A_Lower
		goto Deselect+2
	Select:
		PIP1 A 0 A_JumpIfNoAmmo("SelectNoAmmo")
		PIP1 A 1 A_Raise
		goto Select+1
	SelectNoAmmo:
		NPIP A 1 A_Raise
		Loop
	Fire: 
		"####" "#" 0 A_JumpIfInventory("DetonatorCheck",1,"FireDetonator")
		PIP1 A 1 offset(2,40)
		PIP1 A 1 offset(4,48)
		PIP1 A 1 offset(7,60)
		PIP1 A 1 offset(10,72)
		PIP1 A 1 offset(14,88)
		PIP1 A 1 offset(18,104)
		PIP1 A 1 offset(22,120)
	Hold:
		TNT1 A 0 offset(1,1) A_GiveInventory("PipeThrowSpeed",1)
		TNT1 A 5 A_GunFlash("RedBar",GFF_NOEXTCHANGE)
		TNT1 A 0 A_ReFire
		PIP1 B 1 offset(-1,32)
		PIP1 B 1 offset(-8,26)
		PIP1 B 1 offset(-16,20)
		PIP1 B 1 offset(-22,11)
		PIP1 B 1 offset(-28,2)
		PIP1 B 1 offset(-32,-10)
		PIP1 B 1 offset(-36,-22)
		PIP1 B 1 offset(-40,-34)
		PIP1 C 1 offset(-1,32) A_FireCustomMissile("SurvPipebomb",0,true,0,0,0,16)
		PIP1 C 1 A_PlaySound("weapons/pbthrow",CHAN_WEAPON)
		PIP1 C 1 offset(3,44)
		PIP1 C 1 offset(6,56)
		PIP1 C 1 offset(9,64)
		PIP1 C 1 offset(12,72)
		PIP1 C 1 offset(15,80)
		PIP1 C 1 offset(18,84)
		PIP1 C 1 offset(21,88)
		PIP1 C 1 offset(24,92)
		TNT1 A 8 offset(-18,104) A_GiveInventory("DetonatorCheck")
		DETO A 1 offset(-14,88)
		DETO A 1 offset(-10,72)
		DETO A 1 offset(-7,60)
		DETO A 1 offset(-4,46)
		DETO A 1 offset(-2,36)
		DETO A 1 offset(-1,32)
		Goto ReadyDetonator
	FireDetonator:
		DETO B 2
		DETO C 2 A_PlaySound("weapons/pbarm",CHAN_WEAPON)
		DETO B 2 A_GiveInventory("DetonateSignal")
		DETO A 8 A_TakeInventory("DetonatorCheck")
		DETO A 1
		DETO A 1 offset(-2,36)
		DETO A 1 offset(-4,46)
		DETO A 1 offset(-7,60)
		DETO A 1 offset(-10,72)
		DETO A 1 offset(-14,88)
		TNT1 A 1 offset(22,120)
		TNT1 A 1 A_JumpIfNoAmmo("ReadyNoAmmo")
		PIP1 A 1 offset(18,104)
		PIP1 A 1 offset(14,88)
		PIP1 A 1 offset(10,72)
		PIP1 A 1 offset(7,60)
		PIP1 A 1 offset(4,48)
		PIP1 A 1 offset(2,40)
		PIP1 A 1 offset(1,32)
		Goto Ready
	AltFire:
		DETO A 0 A_TakeInventory("DetonatorCheck")
		DETO A 1 
		DETO A 1 offset(-2,36)
		DETO A 1 offset(-4,46)
		DETO A 1 offset(-7,60)
		DETO A 1 offset(-10,72)
		DETO A 1 offset(-14,88)
		TNT1 A 2 offset(22,120)
		PIP1 A 1 offset(18,104)
		PIP1 A 1 offset(14,88)
		PIP1 A 1 offset(10,72)
		PIP1 A 1 offset(7,60)
		PIP1 A 1 offset(4,48)
		PIP1 A 1 offset(2,40)
		PIP1 A 1 offset(1,32)
		Goto Ready
	RedBar:
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",10,"RedBar10")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",9,"RedBar9")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",8,"RedBar8")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",7,"RedBar7")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",6,"RedBar6")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",5,"RedBar5")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",4,"RedBar4")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",3,"RedBar3")
		"####" "#" 0 A_JumpIfInventory("PipeThrowSpeed",2,"RedBar2")
		REDB A 5 Bright
		Stop
	RedBar2:
		REDB B 5 Bright
		Stop
	RedBar3:
		REDB C 5 Bright
		Stop
	RedBar4:
		REDB D 5 Bright
		Stop
	RedBar5:
		REDB E 5 Bright
		Stop
	RedBar6:
		REDB F 5 Bright
		Stop
	RedBar7:
		REDB G 5 Bright
		Stop
	RedBar8:
		REDB H 5 Bright
		Stop
	RedBar9:
		REDB I 5 Bright
		Stop
	RedBar10:
		REDB Z 5 Bright
		Stop
	}
}

Actor PipeThrowSpeed : Inventory { Inventory.MaxAmount 10 }
Actor DetonatorCheck : Inventory { Inventory.MaxAmount 1 }
Actor DetonateSignal : Powerup { Powerup.Duration 4 }

ACTOR SurvPipebomb
{
Projectile
Radius 10
Height 8
Speed 7
Damage 0
Mass 850
PainChance 256
Scale 0.15
Obituary "%o was blown into pieces by one of %k's Pipebombs."
SelfObituary "%o detonated %p pipebomb a little too close."
PainChance Ice, 0
PainChance Poison, 0
PainChance PoisonCloud, 0
-NOGRAVITY
-NOBLOCKMAP
+SHOOTABLE
+NODAMAGE
+NOBLOOD
+NOEXPLODEFLOOR
+BOUNCEAUTOOFFFLOORONLY
+BOUNCEONACTORS
+FORCERADIUSDMG
+GHOST
+THRUGHOST
+NOTAUTOAIMED
BounceType Hexen
BounceFactor 0.8
WallBounceFactor 0.1
Gravity 0.6
BounceSound "weapons/pbbounce"
States
	{
	Spawn:
		PIPB A 0 NoDelay A_ScaleVelocity(1.15)
		PIPB A 0 A_TakeInventory("PipeThrowSpeed",1,0,AAPTR_TARGET)
		PIPB A 0 A_JumpIfInventory("PipeThrowSpeed",1,"Spawn",AAPTR_TARGET)
	ContinueState:
		PIPB A 2 A_ScaleVelocity(0.95)
		PIPB A 0 A_JumpIf(velz==0,"StopRolling")
		PIPB A 0 A_JumpIfInventory("DetonateSignal",1,"Detonate",AAPTR_TARGET)
		PIPB B 2 A_ScaleVelocity(0.98)
		PIPB B 0 A_JumpIf(velz==0,"StopRolling")
		PIPB B 0 A_JumpIfInventory("DetonateSignal",1,"Detonate",AAPTR_TARGET)
		Loop
	Death:
		"####" "#" 0 A_SetShootable
	StopRolling:
		"####" "#" 0 A_SetGravity(1.0)
		"####" "#" 0 A_JumpIf(z>=ceilingz,"Detonate")
		"####" "#" 0 A_ScaleVelocity(0.7)
		"####" "#" 2 A_JumpIfInventory("DetonateSignal",1,"Detonate",AAPTR_TARGET)
		Loop
	Pain:
	Detonate:
		TNT1 A 0 A_JumpIf(z==floorz,"DetonatePlusFlare")
		TNT1 A 0 A_UnsetShootable
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_ChangeVelocity(0,0,0,CVF_REPLACE)
		TNT1 A 0 A_SetScale(1.0)
		TNT1 A 0 A_NoGravity
		TNT1 A 0 A_Explode(350,300)
		TNT1 A 0 A_PlaySound("weapons/pipe/explode")
		TNT1 A 0 A_SetTranslucent(1,1)
		TNT1 AAAAAAAA 0 A_SpawnItemEx("PipeDebris",0,0,7,random(4,8),0,random(5,10),random(0,359))
		PEXP ABCDEFGHIJKLMNOPQRSTU 2 Bright
		Stop
	DetonatePlusFlare:
		TNT1 A 0 A_SpawnItemEx("ExplosionFloorFlare")
		goto Detonate+1
	}
}

Actor PipeDebris
{
Projectile
Radius 4
Height 4
Damage 0
Scale 0.5
Gravity 0.5
+THRUACTORS
+DONTSPLASH
-ACTIVATEIMPACT
-ACTIVATEPCROSS
-NOGRAVITY
States
	{
	Spawn:
		TNT1 A 0 NoDelay A_Jump(80,"PipeTop")
	PipePart:
		TNT1 A 0 A_Jump(220,1,2,3,4,5,6,7,8)
		PDEB ABCDEFGHI 3
		goto PipePart+1
	PipeTop:
		TNT1 A 0 A_Jump(220,1,2,3)
		PDE2 ABCD 4
		goto PipeTop+1
	Death:
		TNT1 A 1
		Stop
	}
}

Actor ExplosionFloorFlare
{
+NOINTERACTION
Renderstyle Add
States
	{
	Spawn:
		NKX2 ABCDEFGHIJKLMNOP 2 Bright
		Stop
	}
}

ACTOR SurvPipebombAmmo : Ammo //dummy ammo, don't place on the map
{
Inventory.Amount 1
Inventory.MaxAmount 10
Ammo.BackpackAmount 1
Ammo.BackpackMaxAmount 20
Inventory.PickupMessage "i told you not to place this on your maps, idiot"
Inventory.PickupSound "cyber/sight"
Scale 1.0
States
	{
	Spawn:
		PIPP A -1
		Stop
	}
}
