actor DeepDiggerWep : BaseMM8BDMWep 10108
{
    //$Category MM8BDM-Weapons
    //$Title Deep Digger
    //$Sprite DDIGA0
    Weapon.AmmoUse 2
    Weapon.AmmoGive 28
    Weapon.SlotNumber 2
    Inventory.Pickupmessage "$PU_DEEPDIGGER"
    Obituary "$OB_DEEPDIGGER"
    Tag "$TAG_DEEPDIGGER"
    weapon.ammotype "DeepDiggerAmmo"
    inventory.icon "DDIGWI"
    States
    {
    SpawnLoop:
        DDIG A -1
        loop
    Ready:
        DDIG D 0 ACS_ExecuteAlways(998,0,212)
        DDIG D 1 A_WeaponReady
        Goto Ready+1
    Deselect:
        DDIG D 0 A_JumpIfHealthLower(1, 3) // Don't throw rocks if you're dead
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "Fire")
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "Fire")
        DDIG D 0 A_TakeInventory("DeepDiggerFlagL", 1)
        DDIG D 0 A_TakeInventory("DeepDiggerFlagR", 1)
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
        DDIG D 1 A_Lower
        goto Deselect+3
    Select:
        TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
        DDIG D 1 A_Raise
        Loop
    Altfire:
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "CheckLeft")
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "CheckLeft")
        goto Fire
    Fire:
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "CheckLeft")
        DDIG D 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "CheckLeft")
        DDIG D 0 A_JumpIfNoAmmo("NoAmmo")
        DDIG EZ 1
        DDIG D 0 A_PlaySoundEx("weapon/deepdiggerdig", "weapon")
        DDIG D 0 A_GiveInventory("DeepDiggerFlagL", 1)
        DDIG D 0 A_GiveInventory("DeepDiggerFlagR", 1)
        //DDIG A 0 SetPlayerProperty(0,1,0)
        DDIG D 0 //A_Stop
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 68,  17, 16)
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 60, -17, 16)
        DDIG F 1
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 52,  16, 32)
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 44, -16, 32)
        DDIG F 1
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 36,  15, 48)
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 28, -15, 48)
        DDIG G 1
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 20,  13, 64)
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", 12, -13, 64)
        DDIG G 1
        DDIG A 0 A_SpawnItemEx("TempDeepDigger",  4,  10, 74)
        DDIG A 0 A_SpawnItemEx("TempDeepDigger", -4, -10, 74)
        DDIG H 1
        DDIG H 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        //DDIG D 0 SetPlayerProperty(0,0,0)
        TNT1 AAAAAAAAAA 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        goto Carry
    Carry:
        TNT1 A 0 A_GiveInventory("SpawnTempDeepDigger", 1)
        TNT1 A 1 A_WeaponReady
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "Carry")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "Carry")
        TNT1 A 0 A_JumpIf(true, "FireEnd")
        loop

    FireEnd:
        TNT1 A 1 A_RailWait
        TNT1 A 0 A_JumpIfInventory("DeepDiggerAltFrames", 1, "FireEnd")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerMainFrames", 1, "FireEnd")
        TNT1 A 0 A_JumpIf(true, "FireEndReal")
        loop
    FireEndReal:
        TNT1 A 10
        DDIG OP 6
        DDIG D 2 //A_ClearRefire
        Goto Ready+1

    CheckRight:
        TNT1 A 0 A_JumpIfInventory("DeepDiggerMainFrames", 1, "FireLeft")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerAltFrames", 1, "FireRight")
        TNT1 A 0 A_Jump(256,"FireLeft")//A_GunFlash("FlashFireRight")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "RightWait")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "RightWait")
        TNT1 A 1 A_JumpIf(true, "FireEnd")
        loop
    RightWait:
        TNT1 AAAAAA 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        goto Carry
    CheckLeft:
        TNT1 A 0 A_JumpIfInventory("DeepDiggerMainFrames", 1, "FireLeft")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerAltFrames", 1, "FireLeft")
        TNT1 A 0 A_Jump(256,"FireLeft")//A_GunFlash("FlashFireRight")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "LeftWait")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "LeftWait")
        TNT1 A 1 A_JumpIf(true, "FireEnd")
        loop
    LeftWait:
        TNT1 AAAAAA 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        goto Carry

    FireLeft:
		 TNT1 A 0 A_GunFlash("FlashFireRight")
        TNT1 A 0 A_PlaySoundEx("weapon/deepdiggerthrow","Weapon")
        TNT1 A 0 A_FireCustomMissile("DeepDigger",1,1,-15,4)
        TNT1 A 0 A_GiveInventory("DeepDiggerTakeLeft", 1)
		TNT1 A 0 A_FireCustomMissile("DeepDigger",-1,1,15,4)
        TNT1 A 0 A_GiveInventory("DeepDiggerTakeRight", 1)
        DDIG QRSTUV 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        goto FireEnd
    FireRight:
		 TNT1 A 0 A_GunFlash("FlashFireRight")
        TNT1 A 0 A_PlaySoundEx("weapon/deepdiggerthrow","Weapon")
        TNT1 A 0 A_FireCustomMissile("DeepDigger",1,1,-15,4)
        TNT1 A 0 A_GiveInventory("DeepDiggerTakeLeft", 1)
		TNT1 A 0 A_FireCustomMissile("DeepDigger",-1,1,15,4)
        TNT1 A 0 A_GiveInventory("DeepDiggerTakeRight", 1)
        DDIG QRSTUV 1 A_GiveInventory("SpawnTempDeepDigger", 1)
        goto FireEnd

    FlashFireLeft:
        DDIG F 0 A_PlaySoundEx("weapon/deepdiggerthrow","Weapon")
        DDIG F 0 //A_FireCustomMissile("DeepDigger",0,1,-10,4)
        DDIG F 0 A_GiveInventory("DeepDiggerTakeLeft", 1)
        DDIG QRSTUV 1
        stop
    FlashFireRight:
        DDIG F 0 A_PlaySoundEx("weapon/deepdiggerthrow","Weapon")
        DDIG F 0 //A_FireCustomMissile("DeepDigger",0,1,10,-4)
        DDIG F 0 A_GiveInventory("DeepDiggerTakeRight", 1)
        DDIG IJKLMN 1
        stop

    NoAmmo:
        DDIG D 1 ACS_Execute(979,0)
        Goto Ready+1
    }
}

actor TempDeepDigger
{
    +NOINTERACTION
    +NOGRAVITY
    +CLIENTSIDEONLY
    +NOTIMEFREEZE
    -SOLID
    scale 3.5
    height 0
    radius 0
    States
    {
    Spawn:
        DDIG B 0
        DDIG B 1
        stop
    }
}

actor SpawnTempDeepDigger : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0
    CheckRight:
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "SpawnRight")
        goto CheckLeft
    SpawnRight:
        TNT1 A 0 A_GiveInventory("SpawnTempDeepDigger_PR", 1)
        goto CheckLeft
    CheckLeft:
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "SpawnLeft")
        stop
    SpawnLeft:
        TNT1 A 0 A_GiveInventory("SpawnTempDeepDigger_PL", 1)
        stop
    }
}

actor SpawnTempDeepDigger_PR : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_SpawnItemEx("TempDeepDigger", -1, 15, 78 + 16, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        stop
    }
}

actor SpawnTempDeepDigger_PL : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0 A_SpawnItemEx("TempDeepDigger", -9, -15, 78 + 16, momx, momy, momz, 0, SXF_ABSOLUTEMOMENTUM)
        stop
    }
}


actor DeepDiggerTakeRight : CustomInventory
{
    States
    {
    Pickup:
        TNT1 A 0
        TNT1 A 0 A_GiveInventory("DeepDiggerMainFrames", 1)
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "TakeRight")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "TakeLeft")
        TNT1 A 1 A_JumpIf(true, "End")
        wait
    TakeRight:
        TNT1 A 0 A_TakeInventory("DeepDiggerFlagR", 1)
        goto End
    TakeLeft:
        TNT1 A 0 A_TakeInventory("DeepDiggerFlagL", 1)
        goto End
    End:
        TNT1 A 0
        stop
    }
}

actor DeepDiggerTakeLeft : DeepDiggerTakeRight
{
    States
    {
    Pickup:
        TNT1 A 0
        TNT1 A 0 A_GiveInventory("DeepDiggerAltFrames", 1)
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagL", 1, "TakeLeft")
        TNT1 A 0 A_JumpIfInventory("DeepDiggerFlagR", 1, "TakeRight")
        TNT1 A 1 A_JumpIf(true, "End")
        wait
    }
}

actor DeepDiggerAltFrames : Powerup
{
    powerup.duration 12
}

actor DeepDiggerMainFrames : Powerup
{
    powerup.duration 12
}

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

actor DeepDiggerFlagL : Inventory
{
    inventory.amount 1
    inventory.maxamount 2
}
actor DeepDiggerFlagR : DeepDiggerFlagL {}

actor DeepDigger
{
    PROJECTILE
    Radius 20
    Height 20
    scale 3.5
    damage (34)
    speed 40
    damagetype "DeepDigger"
    Obituary "$OB_DEEPDIGGER"
    States
    {
    Spawn:
        DDIG B 1
        loop
    XDeath:
        DDIG B 0 A_PlaySoundEx("weapon/deepdiggerbreak", "auto")
        DDIG BBBB 0 A_SpawnItemEx("DeepDiggerBreakFX",0,0,0,random(-10,10),random(-10,10),random(5,10),random(0,360))
        TNT1 A 2
        stop
    Death:
        DDIG B 0 A_PlaySoundEx("weapon/deepdiggerbreak", "auto")
        DDIG B 0 A_SpawnItemEx("DeepDiggerBit", 0, 0, 0, 1, 0, 0,  67.5, SXF_MULTIPLYSPEED)
        DDIG B 0 A_SpawnItemEx("DeepDiggerBit", 0, 0, 0, 1, 0, 0,  22.5, SXF_MULTIPLYSPEED)
        DDIG B 0 A_SpawnItemEx("DeepDiggerBit", 0, 0, 0, 1, 0, 0, -22.5, SXF_MULTIPLYSPEED)
        DDIG B 0 A_SpawnItemEx("DeepDiggerBit", 0, 0, 0, 1, 0, 0, -67.5, SXF_MULTIPLYSPEED)
        TNT1 A 2
        stop
    }
}

actor DeepDiggerBreakFX
{
PROJECTILE
damage 0
+RIPPER
-NOGRAVITY
+CLIENTSIDEONLY
-SOLID
scale 2.5
+HEXENBOUNCE
Height 2
Radius 2
States
{
Spawn:
DDIG C 2
TNT1 A 2
DDIG C 2
TNT1 A 2
DDIG C 2
TNT1 A 2
DDIG C 2
TNT1 A 2
DDIG C 2
TNT1 A 2
stop
}
}

actor DeepDiggerBit
{
    PROJECTILE
    +HEXENBOUNCE
    bouncecount 2
    Obituary "$OB_DEEPDIGGER"
    damagetype "DeepDigger"
    Radius 12
    Height 12
    scale 3.5
    damage (10)
    speed 40
    States
    {
    Spawn:
        DDIG C 1
        DDIG C 0 A_ChangeFlag(HEXENBOUNCE, false)
        DDIG C 1
        wait
    }
}
