//Sergeant Mark IV's vehicles.
//If you want to modify and reuse this on your wad, please ask me first.

Actor ArtilleryTankTurretNotReal: TankBaseNotReal
{
Scale 1.0
States
{
Spawn:
TNT1 A 0
TN2M T 1
Stop
}}

Actor ArtilleryTankTurretNotReal2: ArtilleryTankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TN2M T 2
Stop
}}

Actor ArtilleryTankTurretNotReal4: ArtilleryTankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TN2M T 4
Stop
}}

Actor ArtilleryTankTurretNotReal8: ArtilleryTankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TN2E T 8
Stop
}}

ACTOR ArtilleryTank: Tank 7264
{
	//$Category BD Vehicles
	//$Colour rgb(200, 200, 200)
	//$Sprite TNK1B1
    Radius 64
	Height 88
	health 2000
	Scale 1.0
	Mass 36300//40 tons
    States
    {
    Spawn:
	    TNT1 A 1
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_NamedExecuteAlways("BDSetNewTankDirection", 0, 0, 0, 0)//Check vehicle initial angle.
		TNT1 A 0 A_SpawnItem("ArtilleryTankTurretNotReal8")
		TNT1 A 1 A_ChangeFlag("FRIENDLY", 0)
		TNT1 A 5
		TNT1 A 0 Thing_ChangeTID(0, 0)
		TNK1 C 0 A_ChangeFlag("THRUACTORS", 0)
		TNT1 A 0 A_ChangeFlag("FRIENDLY", 1)
		Goto StandingHere

	  StandingHere:
		TNT1 A 0
		TNT1 A 0 ACS_NamedExecuteAlways("BDSetBaseAngle", 0, 0, 0, 0)//SpawnVehicleBase
		TNT1 A 0 A_SpawnItem("ArtilleryTankTurretNotReal8")
		TNT1 A 2
		//TNT1 A 0 A_SpawnItem("StationedVehicleCheckRepairs")
		Loop

	Active:
		TNT1 A 0
		TNT1 A 0 A_ChangeFLag("NOPAIN", 1)
		TNT1 A 0 A_TakeFromTarget("PowerInvulnerable", 1)
		TNT1 A 0 A_GiveToTarget("CeaseMorph", 1)
		TNK1 C 0 A_ChangeFlag("FRIENDLY", 0)
		//TNT1 A 0 A_Look
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_NamedExecuteAlways("GetVehiclePreviousHealth", 0, 0, 0, 0)//Check Vehicle Health
		//TNT1 A 0 A_Chase("","",CHF_DONTMOVE )
		TNT1 A 0 A_GiveToTarget("CheckingMorphingPlayerHealth", 1)
		TNT1 A 0 A_SpawnItem("ArtilleryTankTurretNotReal8")
		TNT1 A 3
		TNT1 A 0 A_GiveToTarget("ArtilleryTankMorpher", 1)
		TNT1 A 0 A_GiveToTarget("HeavyMachinegunAmmo", 1200)
		TNT1 A 0 A_GiveToTarget("HelicopterRocketAmmo", 30)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 A_NoBlocking
		TNT1 A 1
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
		TNT1 A 10
		TNT1 A 0 Thing_ChangeTID(0, 0)
		TNT1 A 1
		Stop
	Death:
	TNT1 A 1
	TNT1 A 0 A_SpawnItem("BigExplosion1112")
	TNT1 A 0 A_PlaySound("weapons/explode")
	TNT1 A 0 A_PlaySound("EXPLOSIO", 3)
	TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
	TNT1 A 0 A_NoBlocking
	NULL AAAAAA 0 A_CustomMissile ("MetalShard1", 96, 0, random (0, 360), 2, random (0, 180))
	NULL AAAAAA 0 A_CustomMissile ("MetalShard2", 96, 0, random (0, 360), 2, random (0, 180))
	NULL AAAAAAAAA 0 A_CustomMissile ("BDGlassShard", 96, 0, random (0, 360), 2, random (0, 360))
	TNT1 A 0 A_SpawnItem("DestroyedArmouredVehicleTemp")
	ELEC A 0 A_Explode(100, 250)
	TNT1 A 15
	TNT1 A 0
	Stop

	Pain.Repair:
		TNT1 A 0
		TNT1 A 0 A_ChangeFLag("NOPAIN", 1)
		TNT1 A 0 HealThing(160)
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1200, 2)
		TNT1 A 0 A_GiveInventory("HeavyMachinegunAmmo", 80)
		TNT1 A 0 A_JumpIfInventory("HelicopterRocketAmmo", 30, 2)
		TNT1 A 0 A_GiveInventory("HelicopterRocketAmmo", 2)
		TN2E T 1
		TNT1 A 0 A_ChangeFLag("NOPAIN", 0)
		Goto StandingHere
	}
}

ACTOR ArtilleryTankRealism: ArtilleryTank
{
Health 8000
}

ACTOR ArtilleryTankUsed: ArtilleryTank
{
    States
    {
	Spawn:
		TNT1 A 0
	    TNT1 A 1
		TNT1 A 0 ACS_NamedExecuteAlways("BDSetBaseAngle", 0, 0, 0, 0)//SpawnVehicleBase
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 1 A_ChangeFlag("FRIENDLY", 0)
		TNT1 A 5
		TNT1 A 0 Thing_ChangeTID(0, 0)
		TNK1 C 0 A_ChangeFlag("THRUACTORS", 0)
		TNT1 A 0 A_ChangeFlag("FRIENDLY", 1)
		TNT1 A 0 ACS_NamedExecuteAlways("BDCHeckOnline")
		Goto StandingHere

	IsOnline:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_TAkeInventory("TankBaseDirection", 500)
		Goto StandingHere

Active:
		TNT1 A 0
		TNT1 A 0 A_ChangeFLag("NOPAIN", 1)
		TNT1 A 0 A_TakeFromTarget("PowerInvulnerable", 1)
		TNT1 A 0 A_GiveToTarget("CeaseMorph", 1)
		TTR1 A 0 A_ChangeFlag("FRIENDLY", 0)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_NamedExecuteAlways("GetVehiclePreviousHealth", 0, 0, 0, 0)//Check Vehicle Health
		//TNT1 A 0 A_Chase("","",CHF_DONTMOVE )
		TNT1 A 0 A_GiveToTarget("CheckingMorphingPlayerHealth", 1)
		TNT1 A 3
		TNT1 A 0 A_GiveToTarget("ArtilleryTankMorpher", 1)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 A_NoBlocking
		TNT1 A 1
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
		TNT1 A 10
		TNT1 A 0 Thing_ChangeTID(0, 0)
		Stop
	}
}

ACTOR PowerArtilleryTankSwitch : PowerMorph {PowerMorph.PlayerClass "PlayerArtilleryTank"}

ACTOR ArtilleryTankMorpher : CustomInventory
{
  States
  {
  PickUp:
  TNT1 A 1
  TNT1 A 0 ACS_NamedExecuteAlways("BDEnterTank", 0, 0, 0, 0)//Get into ArtilleryTank
  TNT1 A 0 A_GiveInventory("ArtilleryTankMorphActivation")
  TNT1 A 0 A_SpawnItem("CancelTeleportFog")
  TNT1 A 1
  Stop
  }
 }

ACTOR ArtilleryTankMorphActivation : PowerupGiver
{
  Powerup.Type "PowerArtilleryTankSwitch"
  Powerup.Duration 252000
  +INVENTORY.AUTOACTIVATE
  +INVENTORY.ALWAYSPICKUP
  Inventory.MaxAmount 1
  Health 100
  GibHealth 1
  Mass 5000
  Height 72
  Radius 32
  States
  {
  Spawn:
  TNT1 A 100
  Stop

  PickUp:
  TNT1 A 1
  TNT1 A 1
  Stop
  }
 }

ACTOR PlayerArtilleryTank : PlayerTank
{
	Height 88
	health 2000
	player.viewheight 65
    player.attackzoffset 21
	Player.MorphWeapon "ArtilleryTankGun"
	Mass 36300//40 tons
	States
	{
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("PressedUse", 1)
		TNT1 A 0 ThrustTHingZ(0, 100, -1, 1)
		TN2M T 4
		TNT1 A 0 ACS_NamedExecuteAlways("BDVehicleInputs", 0, 0, 0, 0)//Button-checker for vehicle actions
		MARN A 0 ACS_NamedExecuteAlways("CheckIfDM", 0, 0, 0, 0)//Check if Deathmatch
	Spawn2:
	    TNT1 A 0 A_GiveInventory("IsInATank", 1)
		TNT1 A 0 A_TakeInventory("PressedUse", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_TakeInventory("BackPedal", 1)
		TNT1 A 0 SetPlayerProperty(0, 1, PROP_BUDDHA)
		TN2M T 1
		TN2M TTTT 1 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, -90, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TN2M TTTT 1 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, -90, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_TakeInventory("PressedUse", 1)
		TNT1 A 0 A_Print ("A", 2, "TUTO2")
	Goto Stay

ExitVehicle:
	TNT1 A 1
	TNT1 A 0 A_ChangeFlag(NOPAIN, 1)
	TNT1 A 0 A_JumpIfHealthLower(2, "EmergencyExit")
	TNT1 A 0 A_TakeInventory("PressedUse", 1)

	TNT1 A 0 A_SpawnItemEx ("TransferPlayerOutOfVehicle", 0, 0, 92)

	TN2M T 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
	TN2M T 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
	TN2M T 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

	TNT1 A 0 A_JumpIfInventory("CanLeaveVehicle", 1, "CanExit")
	TNT1 A 0 A_ChangeFlag(NOPAIN, 0)
	TNT1 A 0 A_Print("Can't leave from this direction", 1)
	Goto Stay

	CanExit:
	TNT1 A 0
	TNT1 A 2 A_TakeInventory("IsInATank", 1)
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	TNT1 A 0 A_TakeInventory("CanLeaveVehicle", 1)
	TNT1 A 0 A_TakeInventory("TankZoom", 1)
	TNT1 A 0 A_Takeinventory("FlashlightOn",1)
	TNT1 A 0 A_TakEinventory("PowerLightAmp", 1)
	TNT1 A 0 SetPlayerProperty(0, 0, PROP_BUDDHA)
	TNT1 A 0 ACS_NamedExecuteAlways("BDLeaveTank")
	TNT1 A 0 A_SpawnItemEx ("ArtilleryTankUsed", 0, 0, 0, 0, 0, 0, 0, SXF_NOCHECKPOSITION)
	Goto FinishExit

	FinishExit:
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	TNT1 AAA 10 A_TakeInventory("PressedUse", 1)
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	Goto Stay

	EmergencyExit:
	TNT1 A 0

	TNT1 A 2 A_TakeInventory("IsInATank", 1)
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	TNT1 A 0 A_TakeInventory("CanLeaveVehicle", 1)

	TNT1 A 0 ThrustThingZ(0,120,0,1)
	TNT1 A 0 A_SpawnItem("TankExplode")
	PLA1 J 2
	TNT1 A 0 A_StopSound(1)
	TNT1 A 0 SetPlayerProperty(0, 0, PROP_BUDDHA)
	TNT1 A 0 SetPlayerProperty(0, 0, PROP_FLIGHT)
	TNT1 A 0 ACS_NamedExecuteAlways("BDLeaveTank")
	PLA1 J 100
	Goto Stay

	TurnLeft:
		TNT1 A 0
		TN2M T 2
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "Stay")
		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+4)

		TN2M T 2
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+4)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)

		TN2M T 2
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+4)
		Goto CheckIfStillMoves

	TurnLeft2:
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", 0)
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "TurnLeftAccel")
		TNT1 A 0 A_JumpIfInventory("Backpedal", 1, "TurnLeftBackpedal")
		Goto TurnLeft

	TurnLeftAccel:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)

		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

	TurnRight:
		TNT1 A 0
		TN2M T 2
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-4)

		TN2M T 2
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-4)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)

		TN2M T 2
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-4)
		Goto CheckIfStillMoves

	TurnRight2:
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", 360)
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "TurnRightAccel")
		TNT1 A 0 A_JumpIfInventory("Backpedal", 1, "TurnRightBackpedal")
		Goto TurnRight

	TurnRightAccel:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)

		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)

		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

	CheckIfStillMoves:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "Accelerate")
		TNT1 A 0 A_JumpIfInventory("BackPedal", 1, "BackPedal")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRight")
		TNT1 A 0 A_StopSound(2)
		TNT1 A 0 A_PlaySound("TANK2", 5, 1, 1)
		TNT1 A 0 A_PlaySound("TANK3", 2)

	Stay:
	    TNT1 A 0
		TNT1 A 0 A_PlaySound("TANK2", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 A_JumpIfInventory("BackPedal", 1, "BackPedal")
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "Accelerate")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRight")
		TN2M T 1
		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto Stay

Pain.TracksDamaged:
	    TNT1 A 0
		TNT1 A 0

		TNT1 A 0 A_Jump(32, "DestroyTracks")
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 A_JumpIfInventory("BackPedal", 1, "BackPedal")
		TNT1 A 0 A_JumpIfInventory("Accelerate", 1, "Accelerate")
		TN2M T 1
		Goto Stay

	Pain.Repair:
		TNT1 A 0
		TN2E T 1 A_PlaySound("vehicle/pain")
		TNT1 A 0 HealThing(160)
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1200, 2)
		TNT1 A 0 A_GiveInventory("HeavyMachinegunAmmo", 80)
		TNT1 A 0 A_JumpIfInventory("HelicopterRocketAmmo", 30, 2)
		TNT1 A 0 A_GiveInventory("HelicopterRocketAmmo", 2)
		TN2E T 1
		Goto Stay

	Accelerate:

		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftAccel")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightAccel")
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)

		TN2M T 2
		TNT1 A 0 A_JumpIf(waterlevel > 1, "Stay")
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftAccel")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightAccel")

		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftAccel")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightAccel")

		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftAccel")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightAccel")

		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

Backpedal:
		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , -100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)

		TN2M T 2
		TNT1 A 0 A_JumpIf(waterlevel > 1, "Stay")
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightBackpedal")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftBackpedal")

		TN2M T 2
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnLeftBackpedal")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnRightBackpedal")

		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 4, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRightBackpedal")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeftBackpedal")

		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

	TurnLeftBackpedal:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)

		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

	TurnRightBackpedal:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("Accelerate", 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)

		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TnkTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)

		TNT1 A 0 A_SpawnItemEx("TnkStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)

		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-3)
		TN2M T 2
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 3)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIF(velz < 0, "Falling")
		Goto CheckIfStillMoves

	Falling:
		TNT1 A 0
		TNT1 A 0 A_CheckFloor("CheckIfStillMoves")

	FallingForReal:
		TNT1 A 0
		TN2M T 1
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "ExitVehicle")
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIF(velz == 0, "CrashIntoGround")
		TNT1 A 0 A_GiveInventory("VehicleFallingCount", 1)
		Loop

	CrashIntoGround:
		TNT1 A 0
		TNT1 A 0 A_JumpIfinventory("VehicleFallingCount", 6, "CrashIntoGroundViolently")
		TN2M T 1
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItem("CrashTankIntotheGround1")
		TNT1 A 0 A_SpawnItem("CrashTankIntotheGround2")
		TNT1 A 0 A_SpawnItemEx ("LargeMassWaterImpact", 0, 0, -10)
		TNT1 A 0 Radius_Quake(2, 35, 0, 5, 0)
		TNT1 A 0 A_PlaySound("EBIKEBNC", 2)
		TNT1 A 0 A_TakeInventory("VehicleFallingCount", 100)
		Goto Stay

	CrashIntoGroundViolently:
		TNT1 A 0
		TN2M T 1
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItem("CrashTankIntotheGround1")
		TNT1 A 0 A_SpawnItem("CrashTankIntotheGround2")

		TNT1 A 0 A_SpawnItemEx ("ExplosionSplashSpawner", 0, 0, -10)

		TNT1 A 0 Radius_Quake(4, 35, 0, 10, 0)
		TNT1 A 0 A_PlaySound("BIKECLW", 1)
		TNT1 A 0 A_PlaySound("EBIKECLS", 2)
		TNT1 AAAA 0 A_CustomMissile ("PlasmaSmoke", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_TakeInventory("VehicleFallingCount", 100)
		TNT1 A 0 A_SetPitch(-8.0 + pitch)
		TN2M T 1
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SetPitch(4.0 + pitch)
		TN2M T 1
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, momx, momy, momz, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SetPitch(4.0 + pitch)
		Goto Stay

Death:
	XDeath:
    TNT1 A 1
	TNT1 A 0 A_SpawnItem("BigExplosion1112")
	TNT1 A 0 A_PlaySound("weapons/explode")
	TNT1 A 0 A_PlaySound("EXPLOSIO", 3)
	TNT1 A 0 A_Scream
	TNT1 A 0 A_NoBlocking
	NULL AAAAAA 0 A_CustomMissile ("MetalShard1", 96, 0, random (0, 360), 2, random (0, 180))
	NULL AAAAAA 0 A_CustomMissile ("MetalShard2", 96, 0, random (0, 360), 2, random (0, 180))
	NULL AAAAAAAAA 0 A_CustomMissile ("BDGlassShard", 96, 0, random (0, 360), 2, random (0, 360))
	ELEC A 0 A_Explode(100, 250)
	TNT1 A 0 A_SpawnItem("DestroyedArmouredVehicleTemp")
	8762 A 5
	TNT1 A 0 A_TakeInventory("ArtilleryTankGun", 1)
	TNT1 A 0 A_TakeInventory("IsInATank", 1)
	8762 A 100
	8762 A 0
	Stop
	}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Vehicle's weapons and misc
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ACTOR ArtilleryTankGun : DoomWeapon
{
	Game Doom
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 0
	Weapon.AmmoUse2 1
	Weapon.AmmoGive1 0
	Weapon.AmmoType1 "HeavyMachinegunAmmo"
	Weapon.AmmoType2 "HelicopterRocketAmmo"
	Obituary "%o was wasted by an artillery tank."
	Weapon.SelectionOrder 9999
	+WEAPON.AMMO_OPTIONAL
	+WEAPON.ALT_AMMO_OPTIONAL
	+WEAPON.NOAUTOAIM
	+WEAPON.EXPLOSIVE
	+WEAPON.CHEATNOTWEAPON
	+WEAPON.NO_AUTO_SWITCH
	Inventory.Pickupmessage "$PICKUP_PISTOL_DROPPED"
	Tag "Artillery Tank"
	States
	{
	Ready:
		TNT1 A 0
		TNT1 A 0 A_PlaySound("TNKENGS", 4)
		TNHD W 10
		TNT1 A 0 A_PlaySound("INFRARED", 1)
		TNHD XYZXYZXYZXYZXYZXYZXYZ 1 BRIGHT
		TNT1 A 0 A_TakeInventory("PressedUse", 1)
		TNHD Y 0 A_TakeInventory("PressedJump", 2)
		TNT1 A 0 A_TakeInventory("TankZoom", 1)
		TNHD X 1 A_Gunflash
		TNT1 A 0 A_SetCrosshair(34)
		Goto ReadyToFire

	ReadyToFire:
	    TNT1 A 0
		TNT1 A 0 A_JumpIfinventory("TankZoom", 1, "ReadyToFire2")
		TNT1 A 0 A_JumpIfInventory("SwitchFlashlight",1,"SwitchFlashlight")
		TNLH G 2 A_WeaponReady(1)
		TNT1 A 0 A_JumpIfInventory("Kicking", 1, "ZoomMode")
		Loop

	ReadyToFire2:
		TNT1 A 0
		TNT1 A 2 A_WeaponReady(1)
		TNT1 A 0 A_JumpIfInventory("SwitchFlashlight",1,"SwitchFlashlight")
		TNT1 A 0 A_JumpIfInventory("Kicking", 1, "ZoomMode")
		Loop

	NoAmmo:
		TNLH G 2
		TNT1 A 0 A_Print("Ammunition Depleted", 2)
		Goto ReadyToFire

	NoAmmoZoom:
		TNT1 A 2
		TNT1 A 0 A_Print("Ammunition Depleted", 2)
		Goto ReadyToFire2

	ZoomMode:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_JumpIfinventory("TankZoom", 1, "StopZoom")
		TNT1 A 0 A_ZoomFactor(5.0)
		TNT1 A 0 A_GiveInventory("TankZoom")
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("Kicking", 1)
		Goto ReadyToFire2

	StopZoom:
		TNT1 A 0
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_TakeInventory("TankZoom", 1)
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("Kicking", 1)
		Goto ReadyToFire

	Deselect:
		TNHD Z 1 A_Lower
		TNT1 A 0 SetPlayerProperty(0,0,4)
		Loop

	Select:
		TNT1 A 0
		TNHD z 1 A_Raise
		TNHD zzzzzzzzzzzzzzzzzzzzzz 0 A_Raise
		TNHD z 1 A_Raise
		Goto Ready

	EmergencyExit:
		TNT1 A 0
		TNT1 A 0 A_PlaySound("CARSTE", 1)
		TNT1 A 0 A_GiveInventory("PressedUse")
		TNT1 A 5
		Goto LightEnd

	Fire://zero-offset = 65 pixels high
	    TNT1 A 0
		TNT1 A 0 A_JumpIfinventory("TankZoom", 1, "FireZoom")
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmo

		TNT1 A 0 A_FireCustomMissile("Alerter",0,0)
		TNLH H 1 BRIGHT A_FireCustomMissile("AutocannonFlash", 0, 0, -32, -16, 0, 0)
		TNLH I 1 BRIGHT A_FireCustomMissile("AutoCannonProjectile", -0.2, 1, -32, -16, 0, 0.1)
		TNLH J 2 A_PlaySound("ACANO1", 1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundAC", random(-1,1), 0, 0, -12, 0, random(-1,1))

		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmo

		TNT1 A 0 A_FireCustomMissile("Alerter",0,0)
		TNLH K 1 BRIGHT A_FireCustomMissile("AutocannonFlash", 0, 0, 32, -16, 0, 0)
		TNLH L 1 BRIGHT A_FireCustomMissile("AutoCannonProjectile", 0.2, 1, 32, -16, 0, 0.1)
		TNLH M 2 A_PlaySound("ACANO1", 1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundAC", random(-1,1), 0, 0, -12, 0, random(-1,1))

		TNT1 A 0 A_ReFire
		Goto ReadyToFire

	FireZoom:
		TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmoZoom

		TNT1 A 0 A_FireCustomMissile("Alerter",0,0)
		TNT1 H 1 BRIGHT A_FireCustomMissile("AutocannonFlash", 0, 0, -32, -16, 0, 0)
		TNT1 I 1 BRIGHT A_FireCustomMissile("AutoCannonProjectile", -0.2, 1, -32, -16, 0, 0.1)
		TNT1 J 2 A_PlaySound("ACANO1", 1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundAC", random(-1,1), 0, 0, -12, 0, random(-1,1))

		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmo

		TNT1 A 0 A_FireCustomMissile("Alerter",0,0)
		TNT1 K 1 BRIGHT A_FireCustomMissile("AutocannonFlash", 0, 0, 32, -16, 0, 0)
		TNT1 L 1 BRIGHT A_FireCustomMissile("AutoCannonProjectile", 0.2, 1, 32, -16, 0, 0.1)
		TNT1 M 2 A_PlaySound("ACANO1", 1)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundAC", random(-1,1), 0, 0, -12, 0, random(-1,1))

		TNT1 A 0 A_ReFire
		Goto ReadyToFire2

	AltFire:
		TNT1 A 0
		TNT1 A 0 A_JumpIfinventory("TankZoom", 1, "AltFire2")
		TNT1 A 0 A_JumpIfInventory("HelicopterRocketAmmo", 2, 1)
		Goto NoAmmo
		TNT1 A 0 A_FireCustomMissile("TankMissile", 0.5, 1, random(56,72), random(56,72), 0, -0.5)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundMissile", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNLH G 15 BRIGHT
		TNT1 A 0 A_FireCustomMissile("TankMissile", -0.5, 1, random(-72,-56), random(56,72), 0, -0.5)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundMissile", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNLH G 15 BRIGHT
		Goto ReadyToFire

	AltFire2:
		TNT1 A 0 A_JumpIfInventory("HelicopterRocketAmmo", 2, 1)
		Goto NoAmmoZoom
		TNT1 A 0 A_FireCustomMissile("Alerter",0,0)
		TNT1 A 0 A_FireCustomMissile("TankMissile", 0.5, 1, random(56,72), random(56,72), 0, -0.5)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundMissile", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNT1 A 15 BRIGHT
		TNT1 A 0 A_FireCustomMissile("TankMissile", -0.5, 1, random(-72,-56), random(56,72), 0, -0.5)
		TNT1 A 0 A_FireCustomMissile("DistantFireSoundMissile", random(-1,1), 0, 0, -12, 0, random(-1,1))
		TNT1 A 15 BRIGHT
		Goto ReadyToFire2

	Flash:
		TNT1 A 0
		TNT1 A 0 A_JumpIfHealthLower(2, "EmergencyExit")
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		Goto Flash

	TooHigh:
		TNT1 A 0
		TNT1 A 0 A_SetPitch(325)
		Goto Flash

	TooLowCheck:
		TNT1 A 0
		TNT1 A 0 A_SetPitch(15)
		Goto Flash

	TooHighCheck:
		TNT1 A 0
		NULL A 0 A_JumpIf (pitch < 324, "TooHigh")
		Goto Flash

	TooHighCheckGZD:
		TNT1 A 0
		NULL A 0 A_SetPitch(-35)
		Goto Flash

	SwitchFlashlight:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("SwitchFlashlight", 1)
		TNT1 A 0 A_JumpIfInventory("FlashlightOn",1,"TurnFlashOff")
		TNT1 A 0 A_Giveinventory("FlashlightOn",1)
		TNT1 A 0 A_giveinventory("VehicleInfraredGiver", 1)
		TNT1 A 0 A_PlaySound("INFRARED", 1)
		TNT1 A 0 A_PlaySound("FLASHON", 2)
        Goto ReadyToFire

	TurnFlashOff:
		TNT1 A 0 A_Takeinventory("FlashlightOn",1)
		TNT1 A 0 A_TakEinventory("PowerLightAmp", 1)
		TNT1 A 0 A_PlaySound("FLASHOFF", 2)
        Goto ReadyToFire

	LightEnd:
		TNT1 A 0
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		TNT1 A 0 ACS_NamedExecuteAlways("BDATHUD")
		TNHD K 1 Bright
		NULL A 0 A_JumpIf (pitch < -36, "TooHighCheckGZD")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck")
		TNT1 A 0 A_JumpIfInventory("CanLeaveVehicle",1,1)
		Goto Flash
		TNT1 A 0 A_TakeInventory("TankZoom", 1)
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_Takeinventory("FlashlightOn",1)
		TNT1 A 0 A_TakEinventory("PowerLightAmp", 1)
		TNT1 A 10
		Stop

	Spawn:
		LAUN A -1
		Stop

	}
}

ACTOR TankMissile: Rocket2
{
	Speed 50
	Health 10
	Radius 4
	Height 8
    Damage (random (450, 450))
	DamageType Explosive
	Scale 1.0
	+SEEKERMISSILE
	+SCREENSEEKER
	-NOGRAVITY
	+SHOOTABLE
	+NOBLOOD
	Gravity 0.2
	SeeSound "DSMISFIR"
	States
	{
	Spawn:
		MISL A 0 A_CustomMissile("BackblastFlames1", 0, 0, angle-170, CMF_ABSOLUTEANGLE)
		MISL A 1 Bright A_SeekerMissile (4,8, SMF_LOOK)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_SpawnItem ("HighExplosiveFlamesSmall")
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		MISL A 1 Bright A_SeekerMissile (4,8, SMF_LOOK)
		MISL A 0 A_CustomMissile("BackblastFlames2", 0, 0, angle-190, CMF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_SpawnItem ("HighExplosiveFlamesSmall")
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		MISL A 1 Bright A_SeekerMissile (4,8, SMF_LOOK)
		MISL A 0 A_CustomMissile("BackblastFlames3", 0, 0, angle-180, CMF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))

	Live:
	    MISL A 1 Bright A_SeekerMissile (4,8, SMF_LOOK)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		Loop

	SpawnUnderwater:
	    TNT1 A 0 A_ChangeFlag("NOGRAVITY", 0)
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
	    TNT1 A 0 A_CustomMissile ("BUBULZ", 0, 0, random (0, 360), 2, random (0, 180))
	    Goto Live

	Death:
	XDeath:
		TNT1 A 0
		TNT1 A 0 A_StopSound(1)
        EXPL A 0 Radius_Quake (2, 35, 0, 5, 0)//(intensity, duration, damrad, tremrad, tid)
		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 AAA 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), 2, random (40, 90))
		TNT1 AA 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (40, 90))
		TNT1 AA 0 A_CustomMissile ("BDExplosionparticles3", 10, 0, random (0, 360), 2, random (40, 90))
        EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_SpawnItemEx ("TankMissileExplosion",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx ("BarrelKaboom",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 AAA 0 A_CustomMissile ("HighExplosiveFlames", random (10, 20), 0, random (0, 360), 2, random (10, 90))
		//TNT1 A 0 A_SpawnItemEx ("RocketPenetrator",cos(-pitch)*42,0,0+(sin(pitch)*42),cos(-pitch)*40,0,sin(pitch)*40,0,SXF_TRANSFERPITCH)
		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)
		TNT1 AA 4 A_CustomMissile ("ExplosionSmoke", 2, 0, random (0, 360), 2, random (0, 360))
		Stop
	}
}

ACTOR TankMissile2: TankMissile
{
	Speed 25
    Damage (random (225, 225))
	DamageType ExplosiveImpact
	Scale 1.0
	Species "EnemyTank"
	-NOGRAVITY
	-SHOOTABLE
	Gravity 0.1
	States
	{
	Spawn:
		MISL A 0 A_CustomMissile("BackblastFlames1", 0, 0, angle-170, CMF_ABSOLUTEANGLE)
		MISL A 1 Bright
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_SpawnItem ("HighExplosiveFlamesSmall")
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		MISL A 1 Bright
		MISL A 0 A_CustomMissile("BackblastFlames2", 0, 0, angle-190, CMF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_SpawnItem ("HighExplosiveFlamesSmall")
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		MISL A 1 Bright
		MISL A 0 A_CustomMissile("BackblastFlames3", 0, 0, angle-180, CMF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))

	Live:
	    MISL A 1 Bright
		TNT1 A 0 A_JumpIf(waterlevel > 1, "SpawnUnderwater")
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
		TNT1 A 0 A_CustomMissile ("PlasmaSmoke", 2, 0, random (160, 210), 2, random (-30, 30))
		Loop

	SpawnUnderwater:
	    TNT1 A 0 A_ChangeFlag("NOGRAVITY", 0)
		TNT1 A 0 A_SpawnItem("RocketFlare",-20,0)
	    TNT1 A 0 A_CustomMissile ("BUBULZ", 0, 0, random (0, 360), 2, random (0, 180))
	    Goto Live

	Death:
	XDeath:
		TNT1 A 0
		TNT1 A 0 A_StopSound(1)
        EXPL A 0 Radius_Quake (2, 35, 0, 5, 0)//(intensity, duration, damrad, tremrad, tid)
		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 AAA 0 A_CustomMissile ("BDExplosionparticles", 0, 0, random (0, 360), 2, random (40, 90))
		TNT1 AA 0 A_CustomMissile ("BDExplosionparticles2", 0, 0, random (0, 360), 2, random (40, 90))
		TNT1 AA 0 A_CustomMissile ("BDExplosionparticles3", 10, 0, random (0, 360), 2, random (40, 90))
		TNT1 AAA 0 A_CustomMissile ("MediumExplosionFlames", 0, 0, random (0, 360), 2, random (0, 360))
        EXPL A 0 A_CustomMissile ("BigNeoSmoke", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_SpawnItemEx ("BarrelExplosion",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
		TNT1 A 0 A_SpawnItemEx ("BarrelKaboom",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
		//TNT1 A 0 A_SpawnItemEx ("RocketPenetrator",cos(-pitch)*42,0,0+(sin(pitch)*42),cos(-pitch)*40,0,sin(pitch)*40,0,SXF_TRANSFERPITCH)
		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)
		TNT1 AA 4 A_CustomMissile ("ExplosionSmoke", 2, 0, random (0, 360), 2, random (0, 360))
		Stop
	}
}