// ============================================================
// Mines (C4) - from bdoom_mines_v003.pk3
// Requires Brutal Doom v21 (uses its explosion/gore actors).
// ============================================================

ACTOR C4BombBase
{
    Radius 16
    Height 16
    Health 100
    Mass 100
	Scale 0.1
    +NOBLOCKMAP
    +ACTIVATEIMPACT
    +ACTIVATEMCROSS
    +DROPOFF
    +SOLID
    +COUNTKILL
	+STANDSTILL
	+FRIENDLY
	+FORCERADIUSDMG // hurt the cyberdemons!
    States
    {
    Spawn:
        C4BM A 0
        TNT1 A 0 A_Jump(256,"CheckForEnemies")
	CheckForEnemies:
		C4BM A 1 A_LookEx(0, 0, 64, 64, 360, "See") // Range 64
		TNT1 A 0 A_Jump(256,"Spawn")
	See:
		C4BM A 0 A_PlaySound("c4beep")
		C4BM B 7
		C4BM A 7
		C4BM B 7
		C4BM A 15
		TNT1 A 0 A_Jump(256,"Explode")
	Explode:
		C4BM A 0 A_Explode(128, 128)
		TNT1 A 0 A_Jump(256,"CauseQuake")
	CauseQuake:
		EXPL A 0 Radius_Quake (3, 8, 0, 15, 0)//(intensity, duration, damrad, tremrad, tid)
		TNT1 A 0 A_Jump(256,"FireSFX")
	FireSFX:
		TNT1 A 0 A_CustomMissile("ExplosionSplashSpawner")
        TNT1 A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	    TNT1 A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	    TNT1 A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
        TNT1 A 0 A_SpawnItemEx ("ExplosionFlareSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
        TNT1 AAAAAA 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 AAAA 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (0, 90))
		TNT1 AAAA 0 A_CustomMissile ("MediumExplosionFlames", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_SpawnItemEx ("RocketExplosion",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_Jump(256,"SpecialExplosion")
	SpecialExplosion:
		TNT1 A 0
		TNT1 A 0 A_Jump(256,"FireSFXPart2")
	FireSFXPart2:
		TNT1 A 0
		TNT1 A 2
		TNT1 A 0 A_SpawnItemEx ("LiquidExplosionEffectSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_PlaySound("FAREXPL", 3)
		TNT1 A 15
		TNT1 A 0 A_PlaySound("distantexp", 5)
		Goto Death
	Death:
		TNT1 A 1 A_FadeTo (0, 1, 1) // this kills the C4Bomb
		Loop
    }
}

ACTOR C4BombLvl1 : C4BombBase
{
	States {
		CheckForEnemies:
			C4BM A 1 A_LookEx(0, 0, 64, 64, 360, "See")
			TNT1 A 0 A_Jump(256,"Spawn")
		Explode:
			C4BM A 0 A_Explode(128, 128)
			TNT1 A 0 A_Jump(256,"CauseQuake")
		CauseQuake:
			EXPL A 0 Radius_Quake (3, 8, 0, 15, 0)
			TNT1 A 0 A_Jump(256,"FireSFX")
	}
}

ACTOR C4BombLvl2 : C4BombBase
{
	States {
		CheckForEnemies:
			C4BM A 1 A_LookEx(0, 0, 90, 90, 360, "See")
			TNT1 A 0 A_Jump(256,"Spawn")
		Explode:
			C4BM A 0 A_Explode(256, 256)
			TNT1 A 0 A_Jump(256,"CauseQuake")
		CauseQuake:
			EXPL A 0 Radius_Quake (6, 12, 0, 15, 0)
			TNT1 A 0 A_Jump(256,"FireSFX")
	}
}

ACTOR C4BombLvl3 : C4BombBase
{
	States {
		CheckForEnemies:
			C4BM A 1 A_LookEx(0, 0, 128, 128, 360, "See")
			TNT1 A 0 A_Jump(256,"Spawn")
		Explode:
			C4BM A 0 A_Explode(800, 800)
			TNT1 A 0 A_Jump(256,"CauseQuake")
		CauseQuake:
			EXPL A 0 Radius_Quake (12, 24, 0, 15, 0)
			TNT1 A 0 A_Jump(256,"FireSFX")
		SpecialExplosion:
			TNT1 A 0 A_SpawnItemEx ("spawnedexplosionbig",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_Jump(256,"FireSFXPart2")
	}
}

ACTOR C4BombLvl4 : C4BombBase
{
	States 
	{
		CheckForEnemies:
			C4BM A 1 A_LookEx(0, 0, 300, 300, 360, "See")
			TNT1 A 0 A_Jump(256,"Spawn")
		Explode:
			C4BM A 0 A_Explode(2048, 2048, 1, 1, 0, 30, 9999)
			TNT1 A 0 A_Jump(256,"CauseQuake")
		CauseQuake:
			EXPL A 0 Radius_Quake (18, 38, 0, 15, 0)
			TNT1 A 0 A_Jump(256,"FireSFX")
		SpecialExplosion:
			TNT1 A 0 A_SpawnItemEx ("SpawnedExplosionGiant",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 A_Jump(256,"FireSFXPart2")
	}
}

ACTOR MineLevel : Inventory
{
   Inventory.Amount 0
   Inventory.MaxAmount 3
}

ACTOR C4Placer : Fist
{
    Weapon.SelectionOrder 3700
    Weapon.Kickback 0
    Weapon.AmmoUse 0
    Weapon.AmmoGive 0
    Weapon.SlotNumber 9
    Weapon.UpSound "weapons/raise"
	+NOAUTOFIRE

    States
    {
    Ready:
        PLC4 A 1 A_WeaponReady
        Loop

    Deselect:
        PLC4 A 1 A_Lower
        Loop

    Select:
        PLC4 A 1 A_Raise
        Loop

    Fire:
        TNT1 A 0 A_JumpIfInventory("MineLevel", 3, "PlaceMine4")
        TNT1 A 0 A_JumpIfInventory("MineLevel", 2, "PlaceMine3")
        TNT1 A 0 A_JumpIfInventory("MineLevel", 1, "PlaceMine2")
        TNT1 A 0 A_JumpIfInventory("MineLevel", 0, "PlaceMine1")
        Goto PlaceMine1

    PlaceMine1:
        PLC4 A 3
        PLC4 B 3
        PLC4 C 3
        PLC4 D 3 A_PlaySound("c4place")
        PLC4 E 3 A_SpawnItemEx("C4BombLvl1", 32, 0, 0, 0, 0, 0, 0)  // Place Level 1 mine
        PLC4 F 3
        PLC4 A 1 A_ReFire
        Goto Ready

    PlaceMine2:
        PLC4 A 3
        PLC4 B 3
        PLC4 C 3
        PLC4 D 3 A_PlaySound("c4place")
        PLC4 E 3 A_SpawnItemEx("C4BombLvl2", 32, 0, 0, 0, 0, 0, 0)  // Place Level 2 mine
        PLC4 F 3
        PLC4 A 1 A_ReFire
        Goto Ready

    PlaceMine3:
        PLC4 A 3
        PLC4 B 3
        PLC4 C 3
        PLC4 D 3 A_PlaySound("c4place")
        PLC4 E 3 A_SpawnItemEx("C4BombLvl3", 32, 0, 0, 0, 0, 0, 0)  // Place Level 3 mine
        PLC4 F 3
        PLC4 A 1 A_ReFire
        Goto Ready

    PlaceMine4:
        PLC4 A 3
        PLC4 B 3
        PLC4 C 3
        PLC4 D 3 A_PlaySound("c4place")
        PLC4 E 3 A_SpawnItemEx("C4BombLvl4", 32, 0, 0, 0, 0, 0, 0)  // Place Level 4 mine
        PLC4 F 3
        PLC4 A 1 A_ReFire
        Goto Ready

    AltFire:
        TNT1 A 0 A_JumpIfInventory("MineLevel", 3, "ResetMineLevel")
        TNT1 A 0 A_GiveInventory("MineLevel", 1)  // Increment the mine level
		TNT1 A 0 A_JumpIfInventory("MineLevel", 3, "PrintMine4")
		TNT1 A 0 A_JumpIfInventory("MineLevel", 2, "PrintMine3")
		TNT1 A 0 A_JumpIfInventory("MineLevel", 1, "PrintMine2")
        Goto Ready

    ResetMineLevel:
        TNT1 A 0 A_TakeInventory("MineLevel", 3)  // Reset to level 1
        TNT1 A 0 A_Print("Mine Level 1 Selected", 1)
        Goto Ready

	PrintMine2:
		PLC4 A 10 A_Print("Mine Level 2 Selected", 1)
		Goto Ready
	PrintMine3:
		PLC4 A 10 A_Print("Mine Level 3 Selected", 1)
		Goto Ready
	PrintMine4:
		PLC4 A 10 A_Print("Mine Level 4 Selected", 1)
		Goto Ready
    }
}
