actor PileDriverWep_NormalBar : NormalBar{args 90, 221}
actor PileDriverWep : BaseMM8BDMWep
{
Weapon.AmmoUse 4
Weapon.AmmoGive 28
Weapon.SlotNumber 4
Inventory.Pickupmessage "$PU_PILEDRIVER"
Obituary "$OB_PILEDRIVER"
Tag "$TAG_PILEDRIVER"
weapon.ammotype "PileDriverAmmo"
inventory.icon "PLDRICON"
States
{
SpawnLoop:
11WP G 1
loop
Ready:
PDRV A 0 ACS_NamedExecuteWithResult("core_weaponcolor",COLOR_PILEDRIVER)
PDRV A 1 A_WeaponReady
Goto Ready+1
ReadyC: Goto Ready+1
Deselect:
PDRV A 0
goto DeselectSwap
Select:
PDRV A 0
goto SelectSwap
Fire:
PDRV A 0 A_JumpIfNoAmmo("NoAmmo")
SAKH A 0 A_PlaySoundEx("weapon/piledriver","Weapon")
PDRV A 0 A_Stop
TNT1 A 0 ACS_NamedExecuteWithResult("core_freezeplayer",0,1)
PDRV A 0 SetPlayerProperty(0,1,PROP_FROZEN)
PDRV A 0 A_Recoil(6)
PDRV A 1 A_GiveInventory("PileDriverTake",1)
TNT1 A 0 ACS_NamedExecuteWithResult("core_freezeplayer",0,0)
PDRV A 0 SetPlayerProperty(0,0,PROP_FROZEN)
PDRV BC 1 
Goto Dash
Dash:
TNT1 A 0 ACS_NamedExecuteWithResult("core_freezeplayer",0,1)
PDRV A 0 SetPlayerProperty(0,1,PROP_FROZEN)
PDRV C 0 A_GiveInventory("PileDashPickup")
Goto Continue
Continue:
PDRV C 0 ACS_NamedExecute("vile_statechange",0,2)
PDRV C 0 A_JumpIfInventory("PileDriverRecoil",1,"Impact")
PDRV C 1 A_GiveInventory("PileDashPickup")

PDRV C 0 A_GiveInventory("WeaponCharge",1)
PDRV C 0 A_JumpIfInventory("WeaponCharge",11,"DashStop")
PDRV C 0 A_JumpIfInventory("PileDriverRecoil",1,"Impact")
loop
Impact:
PDRV A 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
PDRV B 0 A_Stop
PDRV E 0 A_PlaySoundEx("weapon/pileimpact","Weapon")
PDRV B 0 A_PlaySoundEx("weapon/pileexplode","Body")
PDRV B 0 A_SpawnItemEX("PileDriverExplosion",10,0,8)
//PDRV CBB 2
PDRV A 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
PDRV A 0 SetPlayerProperty(0,0,PROP_FROZEN)
PDRV A 0 SetPlayerProperty(0,0,PROP_FLY)
PDRV BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB 0 A_Quake(2,20,0,300,0)
PDRV B 0 A_PlaySoundEx("weapon/piledriverthree","Weapon")
PDRV B 0 ThrustThingZ(0,35,0,0)
PDRV B 0 ThrustThing(angle*256/360+128,15,1,0)
PDRV BCCCBA 3
PDRV A 0 A_TakeInventory("ImpactFlag_V",999)
PDRV A 0 A_TakeInventory("WeaponCharge",999)
PDRV A 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
PDRV A 10
goto Ready+1
DashStop:
PDRV A 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
PDRV A 0 SetPlayerProperty(0,0,PROP_FROZEN)
PDRV A 0 SetPlayerProperty(0,0,PROP_FLY)
PDRV A 0 A_ScaleVelocity(0.25)
PDRV C 0 A_TakeInventory("WeaponCharge",999)
PDRV CCCC 1 A_GiveInventory("PileDashPickup2",1)
PDRV A 0 ACS_NamedExecuteAlways("core_freezeplayer",0,0,0)
PDRV BBBB 1 A_JumpIfInventory("PileDriverRecoil",1,"Impact")
PDRV AAAAAAAAAAAA 1 A_JumpIfInventory("PileDriverRecoil",1,"Impact")
Goto Ready+1
NoAmmo:
PDRV A 1 ACS_NamedExecute("core_noammo",0)
Goto Ready+1
}
}

actor PileDriverCheck : BasicProjectile
{
    PROJECTILE
    Obituary "$OB_PILEDRIVER"
    Damagetype "PileDriver"
    height 32
    radius 32
    speed 32
	+DONTREFLECT
    Damage (CallACS("vile_cbm_damage",48))
	var int user_PierceRipper;

    States
    {
    Spawn:
        TNT1 A 0
        TNT1 A 1
        stop
    Death:
		TNT1 A 0 A_SpawnItemEx("PropBlowerEffect")
		TNT1 A 0 A_Explode (48, 100, 0,0,100)
        TNT1 A 0 A_GiveToTarget("PileDriverRecoil", 1)
        stop
    }
}

actor PileDriverRecoil : Powerup {powerup.duration 10}
actor ImpactFlag_V : Once {}

actor PileDriverAmmo : Ammo
{
inventory.amount 1
inventory.maxamount 28
+INVENTORY.IGNORESKILL
}


actor PileDriverTake : CustomInventory
{
States
{
Pickup:
TNT1 A 0 A_TakeInventory("PileDriverAmmo", 4, TIF_NOTAKEINFINITE)
stop
}
}

actor PileDashPickup : CustomInventory
{
States
{
Pickup:
PDRV C 0 A_SpawnItemEX("PileDriverWave",40,8,32)
PDRV C 0 A_SpawnItemEX("PileDashFX",-8,0,0,0,0,0)
PDRV C 0 A_SpawnItemEX("PileDriverCheck",18,0,8,1)
TNT1 A 0 A_ChangeVelocity(50,0,0,CVF_RELATIVE|CVF_REPLACE)
stop
}
}

actor PileDashFX : BasicGraphicEffect
{
States
{
Spawn:
TNT1 AA 0 
PDRI UUVVWWXX 1 A_FadeOut(.05)
wait
}
}

actor PileDashPickup2 : CustomInventory
{
States
{
Pickup:
PDRV C 0 A_SpawnItemEX("PileDriverWave",40,8,32)
PDRV C 0 A_SpawnItemEX("PileDashFX",-8,0,8,0,0,-1)
PDRV C 0 A_SpawnItemEX("PileDriverCheck",18,0,8,1)
stop
}
}


actor PileDriverProtect : PowerProtection
{
Powerup.Duration 8
DamageFactor "PileDriver", 0.0
}


actor PileDriverWave : BasicGraphicEffect
{
translation "198:198=221:221", "192:192=214:214"
Radius 7
Height 15
scale 2.5
States
{
SpawnFrame:
PDRI Y 0 
PDRI Y 1 A_Warp(AAPTR_TARGET, 32, 12, 32, 0, WARPF_INTERPOLATE|WARPF_NOCHECKPOSITION)
stop
}
}

actor PileDriverExplosion : BasicExplosionEffect
{
	translation "198:198=221:221", "192:192=90:90"
    mass 2
    States
    {
    SpawnFrame:
        PDRI MNOPQRS 2 A_SetTics(mass)
        stop
    }
}