//====================================
// Formatted and Cleaned by Ru5tK1ng
//------------------------------------
//====================================

  Actor DrillBombBoss : BaseMM8BDMWep_CBM
  {
	Tag "$TAGC_4C"
	DropItem "DrillBombWepCDropped"
	Weapon.AmmoUse1 28
	Weapon.AmmoGive 0
	Obituary "$OB_DRILLBOMB"
	Inventory.Pickupmessage "Power up! Drill Bomb"
	Weapon.AmmoType "DrillBombClassAmmo"
	Weapon.AmmoType2 "DrillBombClassAmmo"
	States
	{
		Spawn:
		C_04 C 1
		Loop
		
		Ready:
		DRIA A 0 ACS_ExecuteAlways(998,0,DYE_DRILLMAN)
		Goto Ready1
		
		Ready1:
		DRIA A 0 A_JumpIfInventory("DrillBombClassAmmo",28,"Ready3")
		DRIA A 0 A_JumpIfInventory("DigLimit",800,"Ready2")
		DRIA A 1 A_WeaponReady(WRF_NOFIRE)
		DRIA A 0 A_GiveInventory("DrillBombClassAmmo",1)
		DRIA A 0 A_GiveInventory("DigLimit",4)
		Goto Ready1
		
		Ready2:
		DRIA A 0 A_JumpIfInventory("DrillBombClassAmmo",28,"Ready4")
		DRIA A 1 A_WeaponReady(WRF_NOPRIMARY)
		DRIA A 0 A_GiveInventory("DrillBombClassAmmo",1)
		DRIA A 0 A_GiveInventory("DigLimit",4)
		Loop
		
		Ready3:
		DRIA A 0 A_JumpIfInventory("DigLimit",800,"Ready4")
		DRIA A 1 A_WeaponReady(WRF_NOSECONDARY)
		DRIA A 0 A_GiveInventory("DrillBombClassAmmo",1)
		DRIA A 0 A_GiveInventory("DigLimit",4)
		Loop
		
		Ready4:
		DRIA A 0 A_JumpIfInventory("DrillBombClassAmmo", 112, "Ready5")
		DRIA A 1 A_WeaponReady
		DRIA A 0 A_GiveInventory("DrillBombClassAmmo",1)
		Loop
		
		Ready5:
		DRIA A 1 A_WeaponReady
		Loop

		Deselect:
		TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Lower
		DRIA A 1 A_Lower
		Loop
		
		Select:
		TNT1 AAAAAAAAAAAAAAAAAAAAAA 0 A_Raise
		DRIA A 1 A_Raise
		Loop

		/*Fire:
		DRIA A 0 A_JumpIfInventory("DrillBombClassAmmo",1,"Fire2")
		Goto Ready1
		Fire2:
		DRIA A 0 A_JumpIfNoAmmo("FireEnd")
		DRIA A 0 A_PlaySoundEx("Weapon/dustbit","Weapon")
		DRIA A 0 A_GiveInventory("DrillmanMain_CI",1)
		DRIA BBCCAAA 2 A_GiveInventory("DigLimit",2)
		DRIA A 0 A_Refire("Fire2")
		Goto FireEnd
		FireEnd:
		DRIA A 0
		Goto Ready1*/

		Fire:
		DRIA A 0 A_JumpIfInventory("DrillClassFireFlag",1,"FireLeft")
		DRIA A 1
		Goto FireRight
		
		FireRight:
		DRIH A 0 A_PlaySoundEx("Weapon/dustbit","Weapon")
		DRIH A 0 A_GiveInventory("DrillmanMain_CI",1)
		DRIH B 2 A_GiveInventory("DrillClassFireFlag", 1)
		DRIH CC 2
		DRIH DE 1
		DRIA AAAAA 1 A_GiveInventory("DrillClassFireFlag",1)
		Goto Ready1
		
		FireLeft:
		DRIH A 0 A_PlaySoundEx("Weapon/dustbit","Weapon")
		DRIH A 0 A_GiveInventory("DrillmanMain_CI",1)
		DRIH F 2 A_TakeInventory("DrillClassFireFlag", 1)
		DRIH GG 2
		DRIH HI 1
		DRIA AAAAAA 1 A_TakeInventory("DrillClassFireFlag",99)
		Goto Ready1

		AltFire:
		DRIA B 3 offset(0,82)A_JumpIfInventory("DigLimit", 800, "AltFire2")
		DRIA B 1 offset(0,62)
		DRIA C 1 offset(0,42)
		DRIA D 1 offset(0,22)
		Goto Ready1
		
		AltFire2:
		DRIA B 0 A_GiveInventory("NoJumpCancel",1)
		DRIA B 0 A_GiveInventory("DrillingFlag",1)
		DRIA B 0 ThrustThingZ(0,50,0,0)
		DRIA B 1 offset(0,62)A_SpawnItemEx("DrillDigCrush",0,0,66,0,0,10)
		DRIA C 1 offset(0,42)A_SpawnItemEx("DrillDigCrush",0,0,66,0,0,10)
		DRIA D 1 offset(0,22)A_SpawnItemEx("DrillDigCrush",0,0,66,0,0,10)
		Altfire2Loop:
		DRIA B 0 A_TakeInventory("JumpCancler",2)
		DRIA CD 1 offset(0,2)A_SpawnItemEx("DrillDigCrush",0,0,66,0,0,10)
		DRIA B 0 A_JumpIf(VelZ <= 0, "AltFire3HudOffset")
		loop
		
		AltFire3HudOffset:
		DRIA B 0 A_SpawnItemEx("DrillDigCrush",0,0,-10,0,0,-10)
		DRIA B 0 A_GiveInventory("DigLimitDelay",1)
		DRIA B 0 A_JumpIfInventory("DigLimitDelay",100,"AirE")
		DRIA B 1 offset(0,32)A_JumpIf(z-floorz==0,"DigStart") //The Ground and Air check
		AltFire3:
		DRIA B 0 A_SpawnItemEx("DrillDigCrush",0,0,-10,0,0,-10)
		DRIA B 0 A_GiveInventory("DigLimitDelay",1)
		DRIA B 0 A_JumpIfInventory("DigLimitDelay",100,"AirE")
		TNT1 A 1 offset(0,62)A_JumpIf(z-floorz==0,"DigStart") //The Ground and Air check
		Loop
		
		AirE:
		DRIA B 0 A_WeaponReady(WRF_NOSWITCH|WRF_NOFIRE)
		DRIA B 0 A_SpawnItemEx("DrillDigCrush",0,0,-10,0,0,-10)
		TNT1 A 1 offset(0,82)A_JumpIf(z-floorz==0,"DigStart")
		Loop
				
		DigStart:
		DRIA A 0 A_TakeInventory("DigLimit",32)
		DRIA A 0 A_SpawnItemEx("DrillDigCrushFX",0,0,0,0,0,0,0,1)
		DRIA AAAAAAAAAAAA 0 A_SpawnItemEx("DrillRocks",0,0,8,random(-30,30),0,random(3,14),random(0,359),1)
		Goto Dig
		
		Dig:
		DRIA A 0 A_GiveInventory("InvulnerableOn_Pickup",1)
		DRIA A 0 A_GiveInventory("DrillingFlag2",1)
		DRIA A 0 A_SpawnItemEx("DrillVisualHelper")
		DRIA A 0 A_TakeInventory("UnSolid",1)
		DRIA A 0 A_ChangeFlag("NONSHOOTABLE",1)
		DRIA A 0 A_ChangeFlag("SOLID",0)
		DRIA A 0 A_ChangeFlag("PICKUP",0)
		DRIA A 0 A_ChangeFlag("FLOORHUGGER",1)
		DRIA A 0 A_SetTranslucent(0.0,0)
		DRIA A 0 //A_Stop
		DRIA A 0 ThrustThingZ(0,40,1,0)
		DRIA A 0 A_GiveInventory("DrillDigSpeedRageCheck",1)
		DRIA A 0 ACS_ExecuteAlways(CORE_ACS_191,0,APROP_JumpZ,0,1)
		DRIA A 0 //A_Stop
		DRIA A 0 A_TakeInventory("DigLimitDelay",999)
		Goto DigHold
		
		DigHold:
		TNT1 A 0 A_GiveInventory("GalaxyM_BHBProtect")
		TNT1 A 0 A_GiveInventory("NoPushFlag")
		TNT1 A 0 A_TakeInventory("DigLimit",32)
		TNT1 A 0 A_PlayWeaponSound("classes/drilling")
		TNT1 A 1 ThrustThingZ(0,0,1,0)//Fix running over fans/bubbles
		TNT1 A 0 A_GiveInventory("DrillBombClassAmmo",1)
		TNT1 A 1 ThrustThingZ(0,0,1,0)//Fix running over fans/bubbles
		TNT1 A 0 A_GiveInventory("DrillBombClassAmmo",1)
		TNT1 A 0 A_JumpIfInventory("DigLimit",352,"KeepDiggin")
		TNT1 A 0 A_JumpIfInventory("DigLimit",4,"KeepDiggin2")
		Goto DigRelease
		
		KeepDiggin2:
		TNT1 AA 0 A_SpawnItemEx("DrillRocks",0,0,8,random(-10,10),0,random(2,12),random(0,359),1)
		KeepDiggin:
		TNT1 A 0 A_ReFire("DigHold")
		Goto DigRelease
		
		DigRelease:
		DRIA A 0 A_SpawnItemEx("DrillDigCrushFX",0,0,0,0,0,0,0,1)
		DRIA AAAAAAAAAAAAAAAAAA 0 A_SpawnItemEx("DrillRocks",0,0,8,random(-20,20),0,random(10,30),random(0,359),1)
		DRIA A 0 A_TakeInventory("DrillingFlag",1)
		DRIA A 0 A_TakeInventory("DrillingFlag2",99)
		DRIA A 0 A_TakeInventory("DigLimit",160)//999
		DRIA A 0 A_ClearRefire
		DRIA A 0 //A_Stop
		//DRIA A 0 SetPlayerProperty(0,1,0)
		DRIA A 0 A_SetTranslucent(1.0,0)
		DRIA A 0 A_FireCustomMissile("DrillDamager",0,0,0)
		DRIA A 0 A_PlayWeaponSound("classes/drillout")
		DRIA A 0 A_ChangeFlag("FLOORHUGGER",0)
		DRIA A 0 A_ChangeFlag("PICKUP",1)
		DRIA A 0 ACS_ExecuteAlways(CORE_ACS_191,0,APROP_Speed,1,1)
		DRIA A 0 ACS_ExecuteAlways(CORE_ACS_191,0,APROP_JumpZ,10,1)
		DRIA B 0 ThrustThingZ(0,70,0,0)//60
		DRIA B 0 A_ChangeFlag("THRUACTORS",1)
		DRIA CDCDC 2 offset(0,2)A_FireCustomMissile("DrillDamager",0,0,0,20)
		//DRIA B 0 SetPlayerProperty(0,0,0)
		DRIA B 0 A_ChangeFlag("NONSHOOTABLE",0)
		DRIA B 0 A_ChangeFlag("THRUACTORS",0)
		DRIA B 0 A_SpawnItemEx("ResolidifyPlayer_H")
		DRIA B 0 A_GiveInventory("InvulnerableOff_Pickup",1)
		DRIA B 0 A_TakeInventory("NoJumpCancel",1)
		TNT1 A 0 A_TakeInventory("GalaxyM_BHBProtect")
		TNT1 A 0 A_TakeInventory("NoPushFlag")
		DRIA B 1 offset(0,22)
		DRIA A 1 offset(0,32)
		DRIA A 1 offset(0,42)
		Goto Ready1
		
		Flash:
		Stop
	}
  }


//==========================
// Ammo & Inventory Items
//--------------------------
//==========================

  Actor DrillBombClassAmmo : Ammo
  {
    Inventory.Amount 1
	Inventory.MaxAmount 112
	+INVENTORY.IGNORESKILL
  }


  Actor DrillingFlag : OnceC{}
  Actor DrillingFlag2 : OnceC{}


  Actor DigLimit : Ammo
  {
    Inventory.Amount 1
	Inventory.maxAmount 800
	+INVENTORY.IGNORESKILL
  }


  Actor DigLimitDelay : Inventory
  {
    Inventory.Amount 1
	Inventory.MaxAmount 100
  }


  Actor DrillClassFireFlag : OnceC {}


  Actor DrillDigSpeedRageCheck : CustomInventory
  {
    States
	{
		Pickup:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("PowerRage_ST",1,"PickupR")
		TNT1 A 0 ACS_ExecuteAlways(CORE_ACS_191,0,APROP_Speed,20,10)
		Stop
		
		PickupR:
		TNT1 A 0 ACS_ExecuteAlways(CORE_ACS_191,0,APROP_Speed,40,10)
		Stop
	}
 }


//===================
// Drill Attack
//-------------------
//===================

  Actor DMDrillBomb
{
Translation "192:192=4:4", "198:198=227:227", "202:202=210:210"
PROJECTILE
damagetype "DrillM_Bomb"
Obituary "$OB_DRILLBOMB"
+EXPLODEONWATER
Damage (0)
Radius 10
Height 10
speed 34
Scale 2.5
States
{
Spawn:
X_4C A 0
X_4C A 0 ACS_NamedExecuteAlways("BULL_Tidifier", 0)
SpawnLOOP:
X_4C A 0 A_PlaySoundEx("weapon/drillfly","Weapon")
X_4C ABC 2 A_SpawnItemEx("DMDrillBombFX2",-momx,-momy,-momz,momx,momy,momz,angle,SXF_ABSOLUTEPOSITION|SXF_TRANSFERTRANSLATION)
loop
Death:
TNT1 A 0 A_PlaySoundEx("classes/drillexplode", "Weapon")
TNT1 A 0 A_Explode(25,96,0,0,24)
TNT1 A 0 A_SpawnItemEx("BasicBoom5FX_Y",0,0,0,0,0,0,0,1+32)
TNT1 A 2
stop
}
}


  Actor DMDrillBombFX : BasicClientSide
  {
    Scale 3.0
	States
	{
		Spawn:
		DRIA MNOPQ 5
		Stop
	}
  }


  Actor DMDrillBombFX2 : BasicClientSide
  {
    Scale 0.5
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_ScaleVelocity(0.75)
		DRIA M 2 A_SetScale(ScaleX+0.3)
		TNT1 A 0 A_ScaleVelocity(0.75)
		DRIA N 2 A_SetScale(ScaleX+0.3)
		TNT1 A 0 A_ScaleVelocity(0.75)
		DRIA O 2 A_SetScale(ScaleX+0.3)
		TNT1 A 0 A_ScaleVelocity(0.75)
		DRIA P 2 A_SetScale(ScaleX+0.3)
		TNT1 A 0 A_ScaleVelocity(0.75)
		DRIA Q 2 A_SetScale(ScaleX+0.3)
		Stop
	}
  }


  Actor DMDrillBombB : DMDrillBomb{translation "192:192=205:205", "198:198=74:74", "202:202=205:205"}
  Actor DMDrillBombR : DMDrillBomb{translation "192:192=171:171", "198:198=41:41", "202:202=171:171"}
  Actor DMDrillBombO : DMDrillBomb{translation "192:192=104:104", "198:198=128:128", "202:202=104:104"}
  Actor DMDrillBombP : DMDrillBomb{translation "192:192=229:229", "198:198=232:232", "202:202=229:229"}


//=================
// Dig Attack
//-----------------
//=================

  Actor DrillDigCrush
  {
    PROJECTILE
	+DONTBLAST
	Damage (4)
	Radius 15
	Height 2
	Obituary "$OB_DRILLDIG"
	DamageType "DrillM_Stab"
	RenderStyle none
	States
	{
		Spawn:
		TNT1 A 1
		Stop
	}
  }


  Actor DrillDigCrushFX : BasicHelper
  {
    ReactionTime 4
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 0 A_Jump(256,1,3,5)
		TNT1 A 0 A_SpawnItemEx("DMDrillBombFX",random(0,36),0,random(0,16),0,0,0,random(0,359),1)
		TNT1 A 3 A_CountDown
		TNT1 A 0 A_SpawnItemEx("DMDrillBombFX",random(0,30),0,random(20,36),0,0,0,random(0,359),1)
		TNT1 A 3 A_CountDown
		TNT1 A 0 A_SpawnItemEx("DMDrillBombFX",random(0,24),0,random(40,56),0,0,0,random(0,359),1)
		TNT1 A 3 A_CountDown
		Goto Spawn+2
	}
  }


  Actor DrillDamager : BasicExplosion
  {
    Damagetype "DrillM_DigUp"
	Obituary "$OB_DRILLDIG"
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 3 A_Explode(5,72,0,0,72)
		Stop
	}
  }


//=========================
// Ground Drill Effects
//-------------------------
//=========================

actor DrillRocks
{
+DONTBLAST
+MISSILE
-NOGRAVITY
+RIPPER
+THRUACTORS
+CLIENTSIDEONLY
+FLOORCLIP
//+NOCLIP
Damage (0)
Height 5
Radius 5
Speed 30
Scale 2.5
States
{
Spawn:
Y_5C A 0
Y_5C A 30
stop
}
}


  Actor DrillVisualHelper : BasicHelper
  {
    ReactionTime 200 //Backup
	States
	{
		Spawn:
		TNT1 A 0
		TNT1 A 1
		Goto Spawn2
		
		Spawn2:
		TNT1 A 1 A_JumpIfInTargetInventory("DrillingFlag2",1,1)
		Goto Death
		TNT1 A 1 A_GiveToTarget("DrillVisualSpawner",1)
		TNT1 A 0
		TNT1 A 0 A_CountDown
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(C_CHECK_TARGET_OOC)==0,"Death")
		Loop
	}
  }


  Actor DrillVisualSpawner : CustomInventory
  {
    States
	{
		Pickup:
		TNT1 A 0
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(143,0)==-1,"Spawn2")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(143,0)==0,"Blue")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(143,0)==1,"Red")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(143,0)==2,"Orange")
		TNT1 A 0 A_JumpIf(ACS_ExecuteWithResult(143,0)==3,"Purple")
		
		Spawn2:
		TNT1 A 1
		Stop
		
		Blue://60
		TNT1 A 0 A_SpawnItemEx("DrillVisualB",0,0,48,momx,momy,momz,0,9,0)
		Stop
		
		Red:
		TNT1 A 0 A_SpawnItemEx("DrillVisualR",0,0,48,momx,momy,momz,0,9,0)
		Stop
		
		Orange:
		TNT1 A 0 A_SpawnItemEx("DrillVisualO",0,0,48,momx,momy,momz,0,9,0)
		Stop
		
		Purple:
		TNT1 A 0 A_SpawnItemEx("DrillVisualP",0,0,48,momx,momy,momz,0,9,0)
		Stop
	}
  }


  Actor DrillVisualB : CloakVisualB
  {
    States
	{
		Spawn:
		DRIM N 0
		DRIM N 1
		Stop
	}
 }


  Actor DrillVisualR : CloakVisualR
  {
    States
	{
		Spawn:
		DRIM N 0
		DRIM N 1
		Stop
	}
  }


  Actor DrillVisualO : CloakVisualO
  {
    States
	{
		Spawn:
		DRIM N 0
		DRIM N 1
		Stop
	}
  }


  Actor DrillVisualP : CloakVisualP
  {
    States
	{
		Spawn:
		DRIM N 0
		DRIM N 1
		Stop
	}
  }


//=================
// Attack Item
//-----------------
//=================

  Actor DrillmanMain_CI : TeamColor_CI
  {
    States
	{
		FireX:
		TNT1 A 0 A_FireCustomMissile("DMDrillBomb",0,1,0,0)
		Goto Done
		
		FireB:
		TNT1 A 0 A_FireCustomMissile("DMDrillBombB",0,1,0,0)
		Goto Done
		
		FireR:
		TNT1 A 0 A_FireCustomMissile("DMDrillBombR",0,1,0,0)
		Goto Done
		
		FireO:
		TNT1 A 0 A_FireCustomMissile("DMDrillBombO",0,1,0,0)
		Goto Done
		
		FireP:
		TNT1 A 0 A_FireCustomMissile("DMDrillBombP",0,1,0,0)
		Goto Done
	}
  }
