// TITAN MECH
actor Titan : MechPlayer_Base {
	Health 5000
	Radius 58
	Height 128
	Player.DisplayName "Titan"
	player.soundclass "titan"
	player.forwardmove 0.425
	player.sidemove 0.15
	player.maxhealth 5000
	Player.ViewHeight 96
	Player.AttackZOffset 13
	Player.MorphWeapon "TitanWeapons"
	scale 1.1
	States {
	Spawn:
		RAVN I 0
		RAVN A 0 SetPlayerProperty(0,0,3)
		ROB3 A 0 ACS_ExecuteAlways (SC_STEALTH, 0, STEALTH_FORCEOFF)
		RAVN I 0 ACS_Execute(315,0,0,0,0)
		RAVN I 0 A_GiveInventory("MechEjectButton",1)
		RAVN I 0 A_GiveInventory("IsMech",1)
		ROB3 A 35
		ROB3 AAAA 35 A_PlaySoundEx("mech/idle","SoundSlot5",1,-1)
		ROB3 A 35
		Loop
	See:
		ROB3 A 0 SetPlayerProperty(0,0,3)
		ROB3 CD 7 A_JumpIfHealthLower(500,"SeeDamaged")
		ROB3 D 0 A_PlaySoundEx("mech/idle","SoundSlot5",1,-1)
		ROB3 E 0 A_SpawnItemEx("MechStepSmokePuffLarge", 0, -34, 4, 0, 0, 0, 0, 128, 0)
		ROB3 E 0 A_SpawnItemEx("MechStepDamageStrong", 0, -34, 4, 0, 0, 0, 0, 0, 0)
		ROB3 E 10 //A_PlaySound("mech/step")
		ROB3 DC 7
		ROB3 B 0 A_SpawnItemEx("MechStepSmokePuffLarge", 0, 34, 4, 0, 0, 0, 0, 128, 0)
		ROB3 B 0 A_SpawnItemEx("MechStepDamageStrong", 0, 34, 4, 0, 0, 0, 0, 0, 0)
		ROB3 B 10 //A_PlaySound("mech/step")
		ROB3 A 0 A_JumpIf(WaterLevel >= 1, "Drown")
		Goto Spawn
	Melee:
		ROB3 GGG 1 A_JumpIfInventory("TitanShootingLRM",1,"FireRockets")
		ROB3 G 10
		goto Spawn
	FireRockets:
		ROB3 K 10
		ROB3 KK 15 A_SpawnItemEx("MechStepDamageStrong", 0, -34, 4, 0, 0, 0, 0, 0, 0)
		goto Spawn
	SeeDamaged:
		ROB3 CD 7 
		ROB3 D 0 A_PlaySoundEx("mech/idle","SoundSlot5",1,-1)
		ROB3 E 0 A_SpawnItemEx("MechStepSmokePuffLarge", 0, -34, 4, 0, 0, 0, 0, 128, 0)
		ROB3 E 0 A_SpawnItemEx("MechStepDamageStrong", 0, -34, 4, 0, 0, 0, 0, 0, 0)
		ROB3 E 10 A_SpawnItemEx("EjectedMechSmokePuff",random(-32,32),random(-32,32),random(96,128),0,0,3,0,0,0)
		ROB3 DC 7
		ROB3 B 0 A_SpawnItemEx("MechStepSmokePuffLarge", 0, 34, 4, 0, 0, 0, 0, 128, 0)
		ROB3 B 0 A_SpawnItemEx("MechStepDamageStrong", 0, 34, 4, 0, 0, 0, 0, 0, 0)
		ROB3 B 10 A_SpawnItemEx("EjectedMechSmokePuff",random(-32,32),random(-32,32),random(96,128),0,0,3,0,0,0)
		ROB3 A 0 A_JumpIf(WaterLevel >= 1, "Drown")
		Goto Spawn
	Drown:
		TNT1 A 0 Thing_Damage(0,500,12)
		goto Spawn
	Death:
		ROB3 A 0 A_StopSound (6)
		TNT1 A 0 A_JumpIfInventory("IsKamikaze",1,"Death.IonExplosion")
		TNT1 A 0 A_JumpIfInventory("IsBombCrate", 1, "Death.BombExplosion")
	DeathGo:
		ROB3 A 10 A_NoBlocking
		ROB3 A 0 A_StopSoundEx("SoundSlot5")
		ROB3 A 0 A_StopSoundEx("Weapon")
		ROB3 A 35 A_SpawnItemEx ("MechExplosionLarge", 0,0,0,0,0,0,0, SXF_NOCHECKPOSITION)
		DISR Z -1 A_SetTranslucent(0,0.0)
		Stop
	Death.IonExplosion:
		ROB3 A 0
		ROB3 A 0 A_JumpIfInventory ("IsBlue", 1, "Death.NukeExplosion")
		ROB3 A 0 A_SpawnItemEx ("BlueStrikeKamikaze", 0, 0, 32)
		goto DeathGo
	Death.NukeExplosion:
		ROB3 A 0
		ROB3 A 0 A_SpawnItemEx ("NukeKamikaze", 0, 0, 32)
		goto DeathGo
	Death.BombExplosion:
		ROB3 A 0
		ROB3 A 0 A_SpawnItemEx("BombExplosion")
		goto DeathGo
	}
}

actor TitanUsed : Titan {health 2500}

actor PowerTitan : AOWMorph {powermorph.playerclass "Titan"}
actor PowerTitan2 : AOWMorph {PowerMorph.PlayerClass "TitanUsed"}
actor TitanSwitch : PermanentPowerup {Powerup.Type "Titan"}
actor TitanSwitch2 : PermanentPowerup {Powerup.Type "Titan2"}

actor TitanSwitchPickup : CustomInventory {
	inventory.pickupsound "mech/start"
	Translation "112:127=[255,255,255]:[0,0,0]"
	+INVENTORY.AUTOACTIVATE
	scale 1.1
	States {
	Spawn:
		ROB3 A -1
		stop
	Pickup:
		ROB3 A 0 ACS_ExecuteWithResult (353, 0)
		stop
	Use:
		TNT1 A 0
		//TNT1 A 0 ACS_NamedExecuteAlways("mechPickupCheck", 0, 1, 0, 0)
		RAVN I 0 A_GiveInventory ("TitanSwitch2", 1)
		RAVN I 0 A_GiveInventory ("IsMech", 1)
		RAVN I 0 A_GiveInventory("MechEjectButton",1)
		stop
	}
}

actor TitanShootingLRM : inventory { } // [SG] for firing animation

actor TitanWeapons : AOWWeapon {
	Weapon.SelectionOrder 1
	Weapon.AmmoUse 0
	Weapon.AmmoGive 0
	Weapon.AmmoType "Titan-80mmAmmo"
	Obituary "$OB_TITAN"
	+WEAPON.CHEATNOTWEAPON
	+WEAPON.DONTBOB
	States {
	Ready:
		MHUD C 1 A_WeaponReady
		wait
	Deselect:
		MHUD A 0 A_JumpIfHealthLower(1,1)
		goto Ready
		MHUD CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 0 A_Lower
		TNT1 A 1 A_Lower
		wait
	Select:
		MHUD C 0
		MHUD CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC 0 A_Raise
		MHUD C 1 A_Raise
		goto Select+31
	WaitReload:
		MHUD A 2
		MHUD A 2 A_ReFire
		Goto Ready
	Fire:
		MHUD A 0 A_JumpIfInventory("Wolverine-WhatWeapon",2,"Fire.Missiles")
		MHUD A 0 A_JumpIfInventory("Wolverine-WhatWeapon",1,"Fire.Flamer")
		//Continue firing 80mm
		MHUD A 0 A_JumpIfInventory("Reload-80mm",1,"Fire.Missiles")
		MHUD A 10 A_JumpIfInventory("Titan-80mmAmmo",1,1)
		Goto NoAmmo
		MHUD B 0 A_JumpIfInventory("IsBlue", 1, "Fire.Blue")
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash
		MHUD B 2 Bright A_FireCustomMissile("TitanShell",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 12
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash 
		MHUD B 2 Bright A_FireCustomMissile("TitanShell",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 12
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash
		MHUD B 2 Bright A_FireCustomMissile("TitanShell",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 0 ACS_ExecuteAlways (319, 0, 3, 3) // reload
		MHUD A 35
		MHUD A 2 A_Refire
		goto Ready
	Fire.Blue:
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash
		MHUD B 2 Bright A_FireCustomMissile("TitanShellBlue",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 12
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash 
		MHUD B 2 Bright A_FireCustomMissile("TitanShellBlue",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 12
		MHUD A 0 A_PlayWeaponSound ("100mm/fire")
		MHUD B 0 Radius_Quake (4,10,0,1,0)
		MHUD B 0 A_GunFlash
		MHUD B 2 Bright A_FireCustomMissile("TitanShellBlue",frandom(-1,1), 0, -10, 0, 0, frandom(-1,1))
		MHUD A 0 A_TakeInventory ("Titan-80mmAmmo",1)
		MHUD A 0 ACS_ExecuteAlways (319, 0, 3, 3) // reload
		MHUD A 35
		MHUD A 2 A_Refire
		GoTo Ready
	Fire.Flamer:
		MHUD A 0 A_JumpIfInventory ("Titan-FlamerAmmo", 10, 1)
		Goto NoAmmo
		MHUD A 0 A_TakeInventory ("Titan-FlamerAmmo", 10)
		MHUD A 0 A_PlaySound ("flamer2/fire", 6)
		MHUD A 0 bright A_Light2
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD A 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 bright A_Light1
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD A 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 bright A_Light2
		MHUD A 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD A 0 bright A_Light1
		MHUD A 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD A 0 bright A_Light2
		MHUD A 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD B 1 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,18,3)
		MHUD A 0 Bright A_FireCustomMissile("FastFlameShot",random(-2,2),0,-18,3)
		MHUD A 0 Bright A_ReFire 
		MHUD B 3 Bright A_PlaySound ("flamer2/down", 6)
		MHUD A 3 A_Light0
		goto Ready
	Fire.Missiles:
		//Continue firing Rockets
		MHUD A 0 A_JumpIfInventory("Reload-LRM",1,"Fire.Flamer")
		MHUD A 10 A_JumpIfInventory("MechRocketAmmo",20,1)
		Goto NoAmmo
		MHUD A 0 A_PlayWeaponSound("lrm/fire")
		MHDU AA 1 A_GiveInventory("TitanShootingLRM",1)
		MHUD B 0 Radius_Quake(2,70,0,1,0)
		MHUD A 0 A_TakeInventory("MechRocketAmmo",20)
		MHUD A 0 ACS_ExecuteAlways (319, 0, 1, 6) // reload
		MHUD B 0 A_GunFlash
		MHUD B 0 A_JumpIfInventory("IsBlue", 1, "Fire.MissilesBlue")
		MHUD BBBBBBBBBBBBBBBBBBBB 3 bright A_FireCustomMissile("LongRangeTitanMissile",frandom(-1.5,1.5), 0, -10, 0, 0, frandom(-1.5,1.5))
		MHUD AAAAA 7 A_TakeInventory("TitanShootingLRM",1)
		MHUD A 2 A_ReFire
		goto Ready
	Fire.MissilesBlue:
		MHUD BBBBBBBBBBBBBBBBBBBB 3 bright A_FireCustomMissile("LongRangeTitanMissileBlue",frandom(-1.5,1.5), 0, -10, 0, 0, frandom(-1.5,1.5))
		Goto Fire.Missiles+30
	Flash:
		TNT1 A 2 Bright A_Light2
		TNT1 A 2 Bright A_Light1
		TNT1 A 0 A_JumpIfInventory("TitanShootingLRM",1,"Flash")
		Goto LightDone
	AltFire:
		MHUD A 0
		MHUD B 15 ACS_ExecuteAlways (314, 0)
		MHUD A 10
		Goto Ready
	NoAmmo:
		MHUD A 10 A_WeaponReady (WRF_NOPRIMARY)
		goto Ready
	Spawn:
		TNT1 A 0 
		stop
	}
}

actor Titan-80mmAmmo : Ammo {
	inventory.amount 1
	inventory.maxamount 48
	ammo.backpackamount 1
	ammo.backpackmaxamount 48
}

actor Titan-FlamerAmmo : Ammo {
	inventory.amount 50
	inventory.maxamount 800
	ammo.backpackamount 50
	ammo.backpackmaxamount 800
}

actor TitanShell {
	PROJECTILE
	-RANDOMIZE
	-NOGRAVITY
	radius 14
	height 10
	Scale 0.85
	speed 150
	damage (30)
	deathsound "80mm/explosion"
	obituary "$OB_TITAN"
	damagetype "MassDriver"
	gravity 0.05
	decal "BiggerScorch"
	States {
	Spawn:
		RART AAA 0 bright A_PlaySound ("ambient/shell", CHAN_BODY, 1.0, 1)
		goto Idle
	Idle:
		RART AAAA 1 bright A_SpawnItemEx ("PulseBallSmokePuff", -25)
		loop
	Death:
		TNT1 A 0 A_NoGravity
		TNT1 A 0 A_StopSound (CHAN_BODY)
		TNT1 AA 0 A_SpawnItemEx ("FlameDecayStrong", random(-32,32), random(-32,32), 4)
		TNT1 A 0 A_SpawnItemEx ("ExplosionMainLarge")
		TNT1 A 1 bright A_Explode(16,32,0)
		TNT1 A 1 bright A_Explode(16,32,0)
		TNT1 A 1 bright A_Explode(32,64,0)
		TNT1 A 1 bright A_Explode(32,64,0)
		TNT1 A 5 bright A_Explode(64,192,0)
		stop
	}
}

Actor TitanShellBlue : TitanShell
 {
	States 
	{
	Spawn:
		BART AAA 0 bright A_PlaySound ("ambient/shell", CHAN_BODY, 1.0, 1)
		goto Idle
	Idle:
		BART AAAA 1 bright A_SpawnItemEx ("PulseBallSmokePuff", -25)
		loop
	}
 }

Actor LongRangeTitanMissile : LongRangeMissile
 {
	damage (15)
	speed 25
	DamageType "MassDriver"
	States
	{
		Spawn:
			TMIR AA 0 A_PlaySound ("ambient/rocket", CHAN_BODY, 1.0, 1)
			TMIR A -1 bright
			stop
	}
 }

Actor LongRangeTitanMissileBlue : LongRangeMissile
 {
	damage (15)
	speed 25
	DamageType "MassDriver"
	States
	{
		Spawn:
			TMIB AA 0 A_PlaySound ("ambient/rocket", CHAN_BODY, 1.0, 1)
			TMIB A -1 bright
			stop
	}
 }

actor Reload-80mm : Inventory {inventory.maxamount 5}

actor DamagedTitan {
	Health 300
	Radius 58
	Height 128
	Mass 2000
	+SHOOTABLE
	damagefactor "Disarm", 0.0
	scale 1.1
	bloodtype "HHMetalHit"
	bloodcolor "White"
	obituary "%o went boom."
	Translation "112:127=[255,255,255]:[0,0,0]"
	States {
	Spawn:
		ROB3 A 175
		ROB3 A 5 A_SpawnItemEx("EjectedMechSmokePuff",random(-32,32),random(-32,32),random(96,128),0,0,3,0,128,0)
		wait
	Death:
		ROB1 A 0
		ROB3 A 10 A_NoBlocking
		ROB3 A 10 A_SpawnItemEx ("MechExplosionLarge", 0,0,0,0,0,0,0, SXF_NOCHECKPOSITION)
		TNT1 A 0
		Stop
	}
}

actor EjectedTitan {
	scale 1.1
	Translation "112:127=[255,255,255]:[0,0,0]"
	states {
	Spawn:
		ROB3 AAAA 35
		ROB3 A 0 A_SpawnItemEx ("TitanSwitchPickup")
		stop
	}
}

actor TitanAmmoPackage : CustomInventory {
	+AUTOACTIVATE
	inventory.maxamount 0
	states {
	Pickup:
		TNT1 A 0 A_GiveInventory ("Titan-80mmAmmo", 48)
		TNT1 A 0 A_GiveInventory ("Titan-FlamerAmmo", 800)
		TNT1 A 0 A_GiveInventory ("MechRocketAmmo", 360)
		stop
	}
}
