// Juggernaut Mech
actor Juggernaut : MechPlayer_Base {
	+NOSKIN
	Health 5000
	Radius 58
	Height 128
	Mass 4000
	PainChance 0
	DamageFactor "Falling", 12.0
	Scale 1.8
	BloodType "HHMetalHit"
	BloodColor "White"
	MaxStepHeight 40
	DeathSound "juggernaut/death"
	Player.DisplayName "Juggernaut"
	Player.ForwardMove 0.3
	Player.SideMove 0.3
	Player.SoundClass "juggernaut"
	Player.MaxHealth 5000
	Player.DamageScreenColor "00 00 00"
	Player.ViewHeight 96
	Player.AttackZOffset 24
	Player.MorphWeapon "JuggernautWeapons"
	States {
	Spawn:
		TERM A 0
		TERM A 0 SetPlayerProperty (0, 0, 0)
		TERM A 0 SetPlayerProperty (0, 0, 3)
		TERM A 0 ACS_Execute (315, 0) // HUD
		TERM A 0 A_GiveInventory ("MechEjectButton", 1)
		TERM A 0 A_GiveInventory ("IsMech", 1)
		TERM A 15 A_PlaySound ("mech/idle", CHAN_BODY)
		Loop
	See:
		TERM A 0 A_JumpIf (waterlevel >= 1, "Drown")
		TERM A 0 SetPlayerProperty (0, 0, 3)
		TERM A 4
		TERM B 8
		TERM C 8 A_SpawnItemEx ("MechStepJuggernaut", 0, 0, 4)
		TERM D 8
		TERM A 4 A_SpawnItemEx ("MechStepJuggernaut", 0, 0, 4)
		goto Spawn
	Drown:
		TERM A 0 Thing_Damage (0, 500, 12)
		goto Spawn
	Missile:
		TERM E 2
		TERM A 0 A_JumpIfInventory ("JuggernautAttack", 4, "Attack5")
		TERM A 0 A_JumpIfInventory ("JuggernautAttack", 3, "Attack3")
		TERM A 0 A_JumpIfInventory ("JuggernautAttack", 2, "Attack2")
		TERM A 0 A_JumpIfInventory ("JuggernautAttack", 1, "Attack1")
		goto Spawn
	Attack1:
		TERM H 8 BRIGHT
		TERM I 8 BRIGHT
		goto Spawn
	Attack2:
		TERM E 0
		TERM EFEFEF 5 BRIGHT
		goto Spawn
	Attack3:
		TERM J 24
		TERM K 10 BRIGHT
		TERM J 35
		goto Spawn
	Attack5:
		TERM J 15 BRIGHT
		TERM K 40
		goto Spawn
	Death:
		TERM A 0
		TERM A 0 A_JumpIfInventory("IsKamikaze",1,"Death.IonExplosion")
		TNT1 A 0 A_JumpIfInventory("IsBombCrate", 1, "Death.BombExplosion")
		goto DeathGo
	DeathGo:
		TERM A 0 A_StopSound (0) TERM A 0 A_StopSound (4)
		TERM A 0 A_StopSound (1) TERM A 0 A_StopSound (5)
		TERM A 0 A_StopSound (2) TERM A 0 A_StopSound (6)
		TERM A 0 A_StopSound (3) TERM A 0 A_StopSound (7)
		TERM M 1
		TERM M 2 A_Scream
		TERM N 0 A_SpawnItemEx ("MechExplosionLarge", 0,0,0,0,0,0,0, SXF_NOCHECKPOSITION)
		TERM NOPQRS 4 BRIGHT
		TERM TUVWXYZ 3
		TERM "[" 3 A_NoBlocking
		TERM "[" 2048
		TERM "[" 2 Bright A_SetTranslucent(1,1)
		TERM "[" 2 Bright A_SetTranslucent(0.95,1)
		TERM "[" 2 Bright A_SetTranslucent(0.90,1)
		TERM "[" 2 Bright A_SetTranslucent(0.85,1)
		TERM "[" 2 Bright A_SetTranslucent(0.80,1)
		TERM "[" 2 Bright A_SetTranslucent(0.75,1)
		TERM "[" 2 Bright A_SetTranslucent(0.70,1)
		TERM "[" 2 Bright A_SetTranslucent(0.65,1)
		TERM "[" 2 Bright A_SetTranslucent(0.60,1)
		TERM "[" 2 Bright A_SetTranslucent(0.45,1)
		TERM "[" 2 Bright A_SetTranslucent(0.40,1)
		TERM "[" 2 Bright A_SetTranslucent(0.25,1)
		TERM "[" 2 Bright A_SetTranslucent(0.20,1)
		TERM "[" 2 Bright A_SetTranslucent(0.15,1)
		TERM "[" 2 Bright A_SetTranslucent(0.10,1)
		TERM "[" 2 Bright A_SetTranslucent(0.05,1)
		TERM "[" 2 Bright A_SetTranslucent(0.00,1)
		TNT1 A -1
		stop
	Death.IonExplosion:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory ("IsRed", 1, "Death.NukeExplosion")
		TNT1 A 0 A_SpawnItemEx("BlueStrikeKamikaze", 0, 0, 32)
		goto DeathGo
	Death.NukeExplosion:
		TNT1 A 0
		TNT1 A 0 A_SpawnItemEx("NukeKamikaze", 0, 0, 32)
		goto DeathGo
	Death.BombExplosion:
		PLAY H 0
		PLAY N 0 A_SpawnItemEx("BombExplosion")
		goto DeathGo
	}
}

Actor InstantJugCheck : Juggernaut
{
	-SOLID
}

actor JuggernautSwitch : PermanentPowerup {Powerup.Type "Juggernaut"}
actor JuggernautPowerup : InventoryItem {
	inventory.icon "ICO_MECH"
	States {
	Spawn:
		TNT1 A 0
		stop
	Use:
		TNT1 A 0 A_JumpIfInventory ("IsInSpawnRoom", 1, "Nope")
		TNT1 A 0 A_JumpIfInventory ("IsMech", 1, "Use.Mech")
		TNT1 A 0 A_JumpIfInventory ("PowerBerserk", 1, "Failure")
		TNT1 A 0 A_JumpIf(!ACS_NamedExecuteWithResult("CanJuggernautMorph", 0, 0, 0, 0), "Failure")
		TNT1 A 0 ACS_ExecuteAlways (829) // [TT] removes armor from jugg and gives powersuit message
		TNT1 A 0 A_GiveInventory ("IsMech", 1)
		TNT1 A 0 A_GiveInventory ("JuggernautAmmoPackageSmall", 1)
		TNT1 A 0 A_GiveInventory ("MechEjectButton", 1)
		TNT1 A 0 A_GiveInventory ("JuggernautSwitch", 1)
		TNT1 A 0
		stop
	Nope:
		TNT1 A 0
		fail
	}
}

actor PowerJuggernaut : AOWMorph {PowerMorph.PlayerClass "Juggernaut"}

actor JuggernautWeapons : AOWWeapon {
	+CHEATNOTWEAPON
	+DONTBOB
	+NOAUTOAIM
	obituary "$OB_JUGGERNAUT" // %o was ground to bits by %k's Juggernaut MKII.
	weapon.selectionorder 1
	weapon.kickback 150
	Weapon.PreferredSkin "Juggernaut"
	states {
	Ready:
		MHUD A 0 A_StopSound (CHAN_WEAPON)
		MHUD AAAAAAAAAA 1 A_WeaponReady (WRF_NOSWITCH)
		loop
	Deselect:
		TNT1 A 1 A_Lower
		wait
	Select:
		TNT1 A 1 A_Raise
		wait
	Fire:
		MHUD A 0 A_JumpIfInventory ("Wolverine-WhatWeapon", 3, "Fire.Nuke")
		MHUD A 0 A_JumpIfInventory ("Wolverine-WhatWeapon", 2, "Fire.Flak")
		MHUD A 0 A_JumpIfInventory ("Wolverine-WhatWeapon", 1, "Fire.Missiles")
		goto Fire.Artillery
	Fire.Artillery:
		MHUD C 0 A_JumpIfInventory ("Reload-80mm", 1, "Fire.Missiles")
		MHUD C 0 A_JumpIfInventory ("ArtilleryShellAmmo", 2, 1)
		goto Fire.Missiles
		MHUD C 0 SetPlayerProperty (0, 1, 0)
		MHUD C 0 A_TakeInventory ("ArtilleryShellAmmo", 2)
		MHUD C 0 ACS_ExecuteAlways (319, 0, 3, 5) // reload
		MHUD C 10 A_GiveInventory ("JuggernautAttack", 2)
		MHUD C 0 A_PlaySound ("artillery/fire", 5)
		MHUD D 3 Bright A_FireCustomMissile ("JuggernautShell", 0, 0, -18)
		MHUD C 7
		MHUD D 0 A_PlaySound ("artillery/fire", 6)
		MHUD D 3 Bright A_FireCustomMissile ("JuggernautShell", 0, 0, 18)
		MHUD C 7
		MHUD C 0 SetPlayerProperty (0, 0, 0)
		MHUD C 20 A_TakeInventory ("JuggernautAttack", 2)
		goto Ready
	Fire.Missiles:
		MHUD C 0 A_JumpIfInventory ("Reload-LRM", 1, "Fire.Flak")
		MHUD C 0 A_JumpIfInventory ("ShortRangeMissileAmmo", 15, 1)
		goto Fire.Flak
		MHUD C 0 SetPlayerProperty (0, 1, 0)
		MHUD C 0 A_TakeInventory ("ShortRangeMissileAmmo", 15)
		MHUD C 0 ACS_ExecuteAlways (319, 0, 1, 6) // reload
		MHUD C 10 A_GiveInventory("JuggernautAttack", 2)
		MHUD C 0 A_PlayWeaponSound ("lrm/fire")
		MHUD C 0 A_JumpIfInventory("IsBlue", 1, "Fire.MissilesBlue")
		MHUD DDDDDDDDDDDDDDD 2 Bright A_FireCustomMissile ("ShortRangeMissile", random (-3, 3), 0, -18, 0, 0, random (-3, 3))
		MHUD C 10
		MHUD C 0 SetPlayerProperty (0, 0, 0)
		MHUD C 20 A_TakeInventory ("JuggernautAttack", 2)
		goto Ready
	Fire.MissilesBlue:
		MHUD DDDDDDDDDDDDDDD 2 Bright A_FireCustomMissile ("ShortRangeMissileBlue", random (-3, 3), 0, -18, 0, 0, random (-3, 3))
		Goto Fire.Missiles+23
	Fire.Flak:
		MHUD C 0 A_JumpIfInventory ("MachineGunAmmo", 4, 1)
		goto NoAmmo
		MHUD C 0 A_PlaySound ("gatling/alt", CHAN_WEAPON)
		MHUD C 0 A_Light2
		// MHUD C 0 SetPlayerProperty (0, 1, 0) [Bloax] - I think it's a bit harsh to prevent movement while firing flak.
		MHUD DD 0 A_SpawnItemEx ("RifleShellCasing", 2, 8, 32, random(1,3), random(0,1), random(1,3), random(45,60))
		MHUD D 0 A_TakeInventory ("MachineGunAmmo", 4)
		MHUD D 0 A_GiveInventory ("JuggernautAttack", 1)
		MHUD D 2 BRIGHT A_FireBullets (2.6, 1.6, 2, 10, "ExplosionPuffSmall", 0, 3500)
		MHUD C 3
		MHUD D 0 A_Light0
		MHUD C 0 A_PlaySound ("gatling/alt", CHAN_WEAPON)
		MHUD D 2 BRIGHT A_FireBullets (2.6, 1.6, 2, 10, "ExplosionPuffSmall", 0, 3500)
		MHUD C 3
		MHUD D 3 A_ReFire
		// MHUD D 0 SetPlayerProperty (0, 0, 0)
		goto Fire.FlakEnd
	Fire.FlakEnd:
		MHUD D 3 A_TakeInventory ("JuggernautAttack", 1)
		MHUD D 3 A_PlaySound ("gatling/spin", CHAN_WEAPON)
		MHUD D 5
		MHUD D 6 A_ReFire
		goto Ready
	Fire.Nuke:
		MHUD C 0 A_JumpIfInventory ("Reload-Nuke", 1, "Fire.Artillery")
		MHUD C 0 A_JumpIfInventory ("NukeAmmo", 1, 1)
		goto NoAmmo
		MHUD C 0 SetPlayerProperty (0, 1, 0)
		MHUD C 0 A_TakeInventory ("NukeAmmo", 1)
		MHUD C 0 ACS_ExecuteAlways (319, 0, 6, 20) // reload
		MHUD C 10 A_GiveInventory("JuggernautAttack", 2)
		MHUD D 0 A_PlaySound ("mech/artillery", CHAN_WEAPON)
		MHUD D 0 A_JumpIfInventory ("IsBlue", 1, "Fire.NukeBlue")
		MHUD D 5 Bright A_FireCustomMissile ("MiniNuke", 0, 0, 18, 12)
		MHUD C 30
		MHUD C 0 SetPlayerProperty (0, 0, 0)
		MHUD C 20 A_TakeInventory ("JuggernautAttack", 2)
		goto Ready
	Fire.NukeBlue:
		MHUD D 5 Bright A_FireCustomMissile ("IonBomb", 0, 0, 18, 12)
		MHUD C 30
		MHUD C 0 SetPlayerProperty (0, 0, 0)
		MHUD C 20 A_TakeInventory ("JuggernautAttack", 2)
		goto Ready
	AltFire:
		MHUD C 20 ACS_ExecuteAlways (314, 0, 4)
		goto Ready
	NoAmmo:
		MHUD A 10 A_WeaponReady (WRF_NOPRIMARY)
		goto Ready
	Flash:
		TNT1 A 4 Bright A_Light1
		TNT1 A 3 Bright A_Light2
		Goto LightDone
	Spawn:
		TNT1 A 0
		stop
	}
}

actor JuggernautShell : ArtilleryShell80mm {
	obituary "$OB_JUGGERNAUT"
	speed 70
	damage (210)
	damagetype "AntiArmor"
	scale 0.8
	states {
	Death:
		TNT1 A 0 bright A_NoGravity
		TNT1 A 0 A_StopSound (CHAN_BODY)
		TNT1 A 0 A_SpawnItemEx ("FlameDecay", random(-32,32), random(-32,32), 4)
		TNT1 A 0 A_SpawnItemEx ("ExplosionMain")
		TNT1 AA 0 bright A_Explode (30, 128, 1)
		TNT1 AA 0 bright A_Explode (30, 192, 1)
		stop
	}
}

actor EjectedJuggernaut {
	deathsound "juggernaut/death"
	scale 1.8
	translation "112:127=[255,255,255]:[0,0,0]"
	states {
	Spawn:
		TERM A 0
		TERM M 1
		TERM M 2 A_Scream
		TERM NOPQRS 4 BRIGHT
		TERM TUVWXYZ 3
		TERM "[" 3 A_NoBlocking
		TERM "[" 2048
		TERM "[" 2 Bright A_SetTranslucent(1,1)
		TERM "[" 2 Bright A_SetTranslucent(0.95,1)
		TERM "[" 2 Bright A_SetTranslucent(0.90,1)
		TERM "[" 2 Bright A_SetTranslucent(0.85,1)
		TERM "[" 2 Bright A_SetTranslucent(0.80,1)
		TERM "[" 2 Bright A_SetTranslucent(0.75,1)
		TERM "[" 2 Bright A_SetTranslucent(0.70,1)
		TERM "[" 2 Bright A_SetTranslucent(0.65,1)
		TERM "[" 2 Bright A_SetTranslucent(0.60,1)
		TERM "[" 2 Bright A_SetTranslucent(0.45,1)
		TERM "[" 2 Bright A_SetTranslucent(0.40,1)
		TERM "[" 2 Bright A_SetTranslucent(0.25,1)
		TERM "[" 2 Bright A_SetTranslucent(0.20,1)
		TERM "[" 2 Bright A_SetTranslucent(0.15,1)
		TERM "[" 2 Bright A_SetTranslucent(0.10,1)
		TERM "[" 2 Bright A_SetTranslucent(0.05,1)
		TERM "[" 2 Bright A_SetTranslucent(0.00,1)
		TNT1 A -1
		stop
	}
}

actor NukeAmmo : Ammo {
	+IGNORESKILL
	inventory.amount 1
	inventory.maxamount 2
	ammo.backpackamount 1
	ammo.backpackmaxamount 2
}

actor JuggernautAttack : Inventory {inventory.maxamount 10}
actor Reload-Nuke : Inventory {}

actor MiniNuke {
	PROJECTILE
	-RANDOMIZE
	-NOGRAVITY
	+FULLVOLDEATH
	Radius 11
	Height 8
	Speed 40
	Damage (400)
	Gravity 0.125
	SeeSound "mech/artillery"
	DeathSound "nuke/boom"
	DamageType "Explosion"
	Scale 1.25
	Obituary "$OB_JUGGERNAUT"
	States {
	Spawn:
		SHRP A 0
		SHRP A 2 bright A_SpawnItemEx ("PulseBallSmokePuff", -25)
		wait
	Death:
		TNT1 A 0 A_Explode (450, 128, 1)
		TNT1 A 0 A_Explode (1000, 300, 1)
		TNT1 A 0 A_Explode (150, 700, 1)
		TNT1 A 0 A_Explode (100, 1500, 1)
		TNT1 A 0 A_SpawnItemEx ("MiniNukeEffect")
		TNT1 AAAAAAA 5 A_Explode (25, 1500, 1)
		stop
	}
}

actor MiniNukeEffect {
	+CLIENTSIDEONLY
	+NOBLOCKMAP
	+NOGRAVITY
	scale 3.0
	states {
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_SetTranslucent (0.75, 1)
		TNT1 A 0 Radius_Quake (7, 35, 0, 50, 0)
		TNT1 A 0 A_SpawnItemEx ("NukeFloor")
		TNT1 A 0 A_SpawnItemEx ("NukeSmokePillar", 0,0,0, 0,0,4.8)
		TNT1 A 0 A_SpawnItemEx ("NukeMushroom2", 0,0,0, 1.5,0,5, 0)
		TNT1 A 0 A_SpawnItemEx ("NukeMushroom2", 0,0,0, 1.5,0,5, 90)
		TNT1 A 0 A_SpawnItemEx ("NukeMushroom2", 0,0,0, 1.5,0,5, 180)
		TNT1 A 0 A_SpawnItemEx ("NukeMushroom2", 0,0,0, 1.5,0,5, 270)
		NKE1 ABCDEFGHIJKLMN 9 BRIGHT
		TNT1 A 0 A_SpawnItemEx ("NukeMushroom", 0,0,500, 0,0,0.5)
		TNT1 A 0 A_SpawnItemEx ("NukeSmokeMushroom", 0,0,500, 0,0,0.5)
		NKE1 OPQRSTU 8 BRIGHT A_FadeOut(0.05)
		stop
	}
}

actor IonBomb : MiniNuke {
	deathsound "ion/strike"
	translation "112:120=200:207", "121:127=241:247", "80:111=[64,64,64]:[0,0,0]"
	states {
	Death:
		TNT1 A 0 A_Explode (450, 128, 1)
		TNT1 A 0 A_Explode (1000, 300, 1)
		TNT1 A 0 A_Explode (150, 700, 1)
		TNT1 A 0 A_Explode (100, 1500, 1)
		TNT1 A 0 A_SpawnItemEx ("IonFXSmall")
		TNT1 AAAAAAA 5 A_Explode (25, 1500, 1)
		stop
	}
}

actor ShortRangeMissile : LongRangeMissile {
	obituary "$OB_JUGGERNAUT" // %o couldn't get past %k's Juggernaut.
	speed 35
	damage (38)
	deathsound "weapons/rocklx"
	damagetype "AntiArmor"
	scale 0.8
	states {
	Spawn:
		MISR AA 0 A_PlaySound ("ambient/rocket", CHAN_BODY, 1.0, 1)
		MISR A 28 bright
		MISR A -1 bright A_Gravity
	Death:
		TNT1 A 0 A_StopSound (CHAN_BODY)
		TNT1 A 0 A_Explode (38, 128, 0)
		TNT1 A 0 A_SpawnItemEx ("FlameDecay", random (-16,16), random (-16,16), 4, 0, 0, 0, 0, 0, 80)
		TNT1 A 5 A_SpawnItemEx ("ExplosionMain")
		stop
	}
}

Actor ShortRangeMissileBlue : ShortRangeMissile
{
	States
	{
		Spawn:
			MISB AA 0 A_PlaySound ("ambient/rocket", CHAN_BODY, 1.0, 1)
			MISB A 28 bright
			MISB A -1 bright A_Gravity
	}
}

actor JuggernautAmmoPackage : CustomInventory {
	+AUTOACTIVATE
	inventory.maxamount 0
	states {
	Pickup:
		TNT1 A 0 A_GiveInventory ("MachineGunAmmo", 400)
		TNT1 A 0 A_GiveInventory ("ArtilleryShellAmmo", 30)
		TNT1 A 0 A_GiveInventory ("ShortRangeMissileAmmo", 150)
		TNT1 A 0 A_GiveInventory ("NukeAmmo", 2)
		stop
	}
}

actor JuggernautAmmoPackageSmall : CustomInventory {
	+AUTOACTIVATE
	inventory.maxamount 0
	states {
	Pickup:
		TNT1 A 0 A_GiveInventory ("MachineGunAmmo", 100)
		TNT1 A 0 A_GiveInventory ("ArtilleryShellAmmo", 10)
		TNT1 A 0 A_GiveInventory ("ShortRangeMissileAmmo", 40)
		TNT1 A 0 A_GiveInventory ("NukeAmmo", 1)
		stop
	}
}