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


Actor TankBaseNotReal
{
+THRUACTORS
YScale 1.8
XScale 1.9
+NOTIMEFREEZE
+CLIENTSIDEONLY
+FLOORCLIP
+NOGRAVITY
+FLOAT
+NOBLOCKMAP
Mass 99999
Radius 0
Height 0
Gravity 0
States
{
Spawn:
TNT1 A 0
TNK1 B 1
TNT1 A 0 A_SPawnItemEx("TankWeakSpotBase", -65, 0, 2)
Stop
}}


Actor TankBaseStationed: TankBaseNotReal
{
States
{
Spawn:
TNT1 A 0
TNK1 BBBB 2 A_SPawnItemEx("TankWeakSpotBase", -65, 0, 2)
Stop
}}


Actor TankBaseNotRealMoving1: TankBaseNotReal
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_Stop
TNT1 A 0 A_SPawnItemEx("TankWeakSpotBase", -65, 0, 2)
TNK1 B 1
Stop
}}

Actor TankBaseNotRealMoving2: TankBaseNotReal
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_Stop
TNT1 A 0 A_SPawnItemEx("TankWeakSpotBase", -75, 0, 2)
TNK1 D 1
Stop
}}

Actor TankBaseNotRealMoving3: TankBaseNotReal
{
States
{
Spawn:
TNT1 A 0
TNT1 A 0 A_Stop
TNT1 A 0 A_SPawnItemEx("TankWeakSpotBase", -75, 0, 2)
TNK1 E 1
Stop
}}



Actor TankTurretNotReal: TankBaseNotReal
{
Scale 1.25
States
{
Spawn:
TNT1 A 0
TNK1 T 1
Stop
}}








Actor TankTurretNotReal2: TankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TNK1 T 2
Stop
}}

Actor TankTurretNotReal4: TankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TNK1 T 4
Stop
}}

Actor TankTurretNotReal8: TankTurretNotReal
{
States
{
Spawn:
TNT1 A 0
TNK1 T 8
Stop
}}



ACTOR Tank: SwitchableDecoration 7261
{
var int user_stationedtankbasedirection;
    Radius 48
	Height 96
	+SOLID
	+USESPECIAL
	MONSTER
	-COUNTKILL
	+SHOOTABLE
	+LOOKALLAROUND
	+THRUACTORS
	+NOINFIGHTING
	+NORADIUSDMG
	-COUNTKILL
	damagefactor "stomp", 0
	damagefactor "Explosives", 0.5 damagefactor "bullet", 0.25 damagefactor "monsterbullet", 0.25 damagefactor "shotgun", 0 damagefactor "monstershotgun", 0.2 damagefactor "monsterminigun", 0.2
	MaxTargetRange 120
	PainChance "Repair", 255
	BloodType "TankBlood", "TankBlood", "TankBlood"
	Activation THINGSPEC_Activate | THINGSPEC_ThingTargets | THINGSPEC_NoDeathSpecial
	Mass 9999
	Speed 0
	health 1000
	Scale 1.25
	damagefactor "slime", 0.0
	damagefactor "Repair", 1.0 damagefactor "CheckRepair", 0.0
	damagefactor "Head", 0.0	damagefactor "FriendBullet", 0.0    damagefactor "Taunt", 0.0    damagefactor "KillMe", 0.0
	damagefactor "Shotgun", 0.7    damagefactor "Shrapnel", 0.0    damagefactor "Blood", 0.0    damagefactor "BlueBlood", 0.0
	damagefactor "Explosives", 0.5 damagefactor "bullet", 0.25 damagefactor "monsterbullet", 0.25 damagefactor "shotgun", 0 damagefactor "monstershotgun", 0.2 damagefactor "monsterminigun", 0.2
	damagefactor "GreenBlood", 0.0    damagefactor "MinorHead", 0.0    damagefactor "Decaptate", 0.0	damagefactor "MonsterKnocked", 0.0
    damagefactor "CancelTeleportFog", 0.0	damagefactor "BHFTOnBarrel", 0.0	damagefactor "GibRemoving", 0.0	damagefactor "SuperPunch", 5.0
	damagefactor "HelperMarineFatallity", 0.0	damagefactor "Leg", 0.0	damagefactor "SpawnMarine", 0.0	damagefactor "TeleportRemover", 0.0
	DamageFactor "CauseObjectsToSplash", 0.0 DamageFactor "Trample", 0.0 DamageFactor "Minigun", 0.1 damageFactor "Machinegun", 0.1
	DamageFactor "TankWeakSpot", 3.0 damagefactor "Plasma", 1.5 damagefactor "Plasma2", 1.5
	damagefactor "Desintegrate", 3.0
    States
    {
    Spawn:
	    TNT1 A 1
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_ExecuteAlways(137, 0, 0, 0, 0)//Check vehicle initial angle.
		TNT1 A 1 A_ChangeFlag("FRIENDLY", 0)
		TNT1 A 5
		TNT1 A 0 A_SpawnItem("TankTurretNotReal8")
		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_ExecuteAlways(136, 0, 0, 0, 0)//SpawnVehicleBase
		TNT1 A 6
		TNT1 A 0 A_SpawnItem("TankTurretNotReal8")
		TNT1 A 0 A_SpawnItem("StationedVehicleCheckRepairs")
		Loop
		
	Active:
		TNT1 A 0 
		TNK1 C 0 A_ChangeFlag("FRIENDLY", 0)
		//TNT1 A 0 A_Look
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_ExecuteAlways(130, 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("TankTurretNotReal8")
		NULL A 3
		TNT1 A 0 A_GiveToTarget("TankMorpher", 1)
		TNT1 A 0 A_GiveToTarget("HeavyMachinegunAmmo", 400)
		TNT1 A 0 A_GiveToTarget("TankAmmo", 40)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 A_NoBlocking
		NULL A 1
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
		NULL A 10
		TNT1 A 0 Thing_ChangeTID(0, 0)
		NULL 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_Scream
	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 ("GlassShard", 96, 0, random (0, 360), 2, random (0, 360))
	TNT1 A 0 A_SpawnItem("DestroyedArmouredVehicle")
	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(5)
		 TNK1 T 1
		 TNT1 A 0 HealThing(5)
		 TNT1 A 0 A_ChangeFLag("NOPAIN", 0)
		 Goto StandingHere
	}
}



ACTOR TankUsed: Tank
{
    States
    {
	Spawn:
		TNT1 A 0
	    TNT1 A 1
		TNT1 A 0 ACS_ExecuteAlways(136, 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_Execute(129)
		Goto StandingHere
	
	IsOnline:
		TNT1 A 0
		TNT1 A 1
		TNT1 A 0 A_TAkeInventory("TankBaseDirection", 500)
		Goto StandingHere
		
	
	
	Active:
		TNT1 A 0 
		TTR1 A 0 A_ChangeFlag("FRIENDLY", 0)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 ACS_ExecuteAlways(130, 0, 0, 0, 0)//Check Vehicle Health
		//TNT1 A 0 A_Chase("","",CHF_DONTMOVE )
		TNT1 A 0 A_GiveToTarget("CheckingMorphingPlayerHealth", 1)
		NULL A 3
		TNT1 A 0 A_GiveToTarget("TankMorpher", 1)
		TNT1 A 0 Thing_ChangeTID(0, 261)
		TNT1 A 0 A_NoBlocking
		NULL A 1
		TNT1 A 0 A_ChangeFlag("USESPECIAL", 0)
		NULL A 10
		TNT1 A 0 Thing_ChangeTID(0, 0)
		Stop
	}
}

	


ACTOR PowerTankSwitch : PowerMorph {PowerMorph.PlayerClass "PlayerTank"}



ACTOR TankMorpher : CustomInventory 
{
  States
  {
  PickUp:
  TNT1 A 1
  TNT1 A 0 ACS_ExecuteAlways(134, 0, 0, 0, 0)//Get into Tank
  TNT1 A 0 A_GiveInventory("TankMorphActivation")
  TNT1 A 0 A_SpawnItem("CancelTeleportFog")
  TNT1 A 1
  Stop
  }
 }
 


ACTOR TankMorphActivation : PowerupGiver
{
  Powerup.Type "PowerTankSwitch"
  Powerup.Duration 252000
  +INVENTORY.AUTOACTIVATE
  +INVENTORY.ALWAYSPICKUP
  Inventory.MaxAmount 1
  Health 100
  GibHealth 1
  Mass 9999
  Height 96
  Radius 32
  States
  {
  Spawn:
  TNT1 A 100
  Stop
  
  PickUp:
  TNT1 A 1
  TNT1 A 1
  Stop
  }
 }
 
 


ACTOR PlayerTank : PlayerPawn
{
var int user_tankbasedirection;
	Speed 0
	Scale 1.25
	Radius 48
	Height 96
	Mass 9999
	PainChance 0
	health 1000
	-PICKUP
	Speed 0.01
	player.viewheight	90
    player.attackzoffset 90
	MaxStepHeight 32
	Player.MorphWeapon "TankGun"
    Player.JumpZ 0
	damagefactor "slime", 0.0
	damagefactor "Explosives", 0.5 damagefactor "bullet", 0.25 damagefactor "monsterbullet", 0.25 damagefactor "shotgun", 0 damagefactor "monstershotgun", 0.2 damagefactor "monsterminigun", 0.2
	BloodType "TankBlood", "TankBlood", "TankBlood"
	damagefactor "stomp", 0
	+NOSKIN
	+NORADIUSDMG
	+FORCERADIUSDMG
	+FIXMAPTHINGPOS
	+DONTRIP
	-CANUSEWALLS
	-PICKUP
	DamageFactor "Repair", 0.0 damagefactor "CheckRepair", 0.0
	damagefactor "Head", 0.0	damagefactor "FriendBullet", 0.0    damagefactor "Taunt", 0.0    damagefactor "KillMe", 0.0
	damagefactor "Shotgun", 0.7    damagefactor "Shrapnel", 0.0    damagefactor "Blood", 0.0    damagefactor "BlueBlood", 0.0
	damagefactor "Explosives", 0.5 damagefactor "bullet", 0.25 damagefactor "monsterbullet", 0.25 damagefactor "shotgun", 0 damagefactor "monstershotgun", 0.2 damagefactor "monsterminigun", 0.2
	damagefactor "GreenBlood", 0.0    damagefactor "MinorHead", 0.0    damagefactor "Decaptate", 0.0	damagefactor "MonsterKnocked", 0.0
    damagefactor "CancelTeleportFog", 0.0	damagefactor "BHFTOnBarrel", 0.0	damagefactor "GibRemoving", 0.0	damagefactor "SuperPunch", 5.0
	damagefactor "HelperMarineFatallity", 0.0	damagefactor "Leg", 0.0	damagefactor "SpawnMarine", 0.0	damagefactor "TeleportRemover", 0.0
	DamageFactor "CauseObjectsToSplash", 0.0 DamageFactor "Trample", 0.0 DamageFactor "Minigun", 0.1 damageFactor "Machinegun", 0.1
	DamageFactor "TankWeakSpot", 3.0 damagefactor "Plasma", 1.5 damagefactor "Plasma2", 1.5
	damagefactor "Desintegrate", 3.0 
	States
	{
	
	
		
	Spawn:
		TNT1 A 0
		TNT1 A 0 A_TakeInventory("PressedUse", 1)
		TNT1 A 0 ThrustTHingZ(0, 100, -1, 1)
		TNK1 A 1
	Spawn2:
	    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 ACS_ExecuteAlways(877, 0, 0, 0, 0)
		TNK1 A 1
		TNK1 AAAA 1 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, -90, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNK1 AAAA 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_TakeInventory("FiredTankMainGun", 1)
		TNT1 A 0 A_Print (a, 4, "TUTO1")
	Goto Stay

		

	ExitVehicle:
	TNT1 A 1
	
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	
	TNT1 A 0 A_SpawnItemEx ("TransferPlayerOutOfVehicle", 0, 0, 110)
	
	TNK1 A 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
	TNK1 A 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
	TNK1 A 1
	TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
	
	TNT1 A 0 A_JumpIfInventory("CanLeaveVehicle", 1, "CanExit")
	TNT1 A 0 A_Print("Can't leave from this direction", 1)
	Goto Stay
	
	CanExit:
	TNT1 A 0
	TNT1 A 2
	TNT1 A 0 A_TakeInventory("PressedUse", 1)
	TNT1 A 0 A_TakeInventory("CanLeaveVehicle", 1)
	TNT1 A 0 ACS_Execute(135)
	TNT1 A 0 ACS_Execute(871)
	TNT1 A 0 A_SpawnItemEx ("TankUsed", 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
	
		
		
	TurnLeft:
		TNT1 A 0
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection > 359, "TurnLeft2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection+6)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		Goto CheckIfStillMoves
	
	TurnLeft2:
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", 0)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		Goto CheckIfStillMoves
		
	TurnRight:
		TNT1 A 0
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_JumpIf(user_tankbasedirection == 0, "TurnRIght2")
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", user_tankbasedirection-6)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		Goto CheckIfStillMoves
	
	TurnRight2:
		TNT1 A 0 A_SetUserVar("user_tankbasedirection", 360)
		TNT1 A 0 A_TakeInventory("TurnRight", 1)
		TNT1 A 0 A_TakeInventory("TurnLeft", 1)
		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 
		
		TNT1 A 0 A_PlaySound("TANK2", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, 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")
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		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, 0, 0, 0, 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")
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		Goto Stay
		
		
	
	Accelerate:
		
		TNT1 A 0 A_PlaySound("TANK1", 5, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankTreadsDamage" , 100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)
		
		TNT1 A 0 A_SpawnItemEx("TankStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 2, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		
		
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnRight")
		
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		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("TankStep", 0, 0, 8, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SpawnItemEx ("TankTreadsDamage" , -100, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEANGLE | SXF_ABSOLUTEVELOCITY)
		
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving3" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 //ThrustThing(user_tankbasedirection*256/360+128, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving2" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 1, 1)
		
		TNT1 A 0 A_JumpIfInventory("TurnRight", 1, "TurnLeft")
		TNT1 A 0 A_JumpIfInventory("TurnLeft", 1, "TurnRight")
		
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 ThrustThing(user_tankbasedirection*256/360+128, 1, 1)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, 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
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, 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")
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, 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(1, 6, 0, 4, 0)
		TNT1 A 0 A_PlaySound("EBIKEBNC", 2)
		TNT1 A 0 A_TakeInventory("VehicleFallingCount", 100)
		Goto Stay
		
	CrashIntoGroundViolently:
		TNT1 A 0
		TNK1 A 1 A_SpawnItemEx ("TankTurretNotReal" , 0, 0, 0, 0, 0, 0, 0, SXF_ABSOLUTEVELOCITY)
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, 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(8, 24, 0, 4, 0)
		TNT1 A 0 A_PlaySound("BIKECLW", 1)
		TNT1 A 0 A_PlaySound("EBIKECLS", 2)
		TNT1 AAAA 0 A_CustomMissile ("ExplosionSmoke", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_TakeInventory("VehicleFallingCount", 100)
		TNT1 A 0 A_SetPitch(-8.0 + pitch)
		TNK1 A 1 
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SetPitch(4.0 + pitch)
		TNK1 A 1
		TNT1 A 0 A_SpawnItemEx ("TankBaseNotRealMoving1" , 0, 0, 0, 0, 0, 0, user_tankbasedirection, SXF_ABSOLUTEVELOCITY | SXF_ABSOLUTEANGLE)
		TNT1 A 0 A_SetPitch(4.0 + pitch)
		Goto Stay	
		
		
		
	Death:	
	XDeath:
	TNT1 A 0 ACS_ExecuteAlways(871, 0, 0, 0, 0)
    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 ("GlassShard", 96, 0, random (0, 360), 2, random (0, 360))
	ELEC A 0 A_Explode(100, 250)
	TNT1 A 0 A_SpawnItem("DestroyedArmouredVehicle")
	8762 A 5
	TNT1 A 0 A_TakeInventory("TankGun", 1)
	8762 A 100
	8762 A -1
	Stop
	
	
	}
}


////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Vehicle's weapons and misc
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////



ACTOR TankReady : Ammo
{
   Inventory.Amount 0
   Inventory.MaxAmount 100
   Ammo.BackpackAmount 0
   Ammo.BackpackMaxAmount 100
   Inventory.Icon TNT1A0
}

ACTOR TankGun : DoomWeapon
{
	Game Doom
	Weapon.SelectionOrder 1900
	Weapon.AmmoUse1 0
	Weapon.AmmoGive1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive2 0
	Weapon.AmmoType2 "TankAmmo"
	Weapon.AmmoType1 "HeavyMachinegunAmmo"
	Obituary "$OB_MPPISTOL"
	+WEAPON.AMMO_OPTIONAL
	+WEAPON.ALT_AMMO_OPTIONAL
	//+WEAPON.NOAUTOFIRE
	Inventory.Pickupmessage "$PICKUP_PISTOL_DROPPED"
	Tag "$TAG_PISTOL"
	States
	{
	
	
	
	Ready:
	    TNT1 A 0
		//TNT1 A 0 A_JumpIfInventory("PressedJump", 1, "ZoomMode")
		TNT1 A 0 A_GunFlash
		TNT1 A 1 A_WeaponReady(1)
		TNT1 A 0 A_GiveInventory("TankReady", 1)
		TNT1 A 0 ACS_ExecuteAlways(111, 0, 0, 0, 0)//SHOWHUD
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck2")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck2")
		Loop
		
	ZoomMode:
		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 10
		TNT1 A 0 A_TakeInventory("PressedJump", 1)
		Goto Ready
	
	StopZoom:
		TNT1 A 1
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 A_TakeInventory("TankZoom", 1)
		TNT1 A 10
		TNT1 A 0 A_TakeInventory("PressedJump", 1)
		Goto Ready
		
	NotReady:
		TNT1 A 1 A_GiveInventory("TankReady", 1)
		TNT1 A 0 ACS_ExecuteAlways(111, 0, 0, 0, 0)//SHOWHUD
		Goto Ready
		
	Deselect:
		TNT1 A 1 A_Lower
		TNT1 A 0 A_ZoomFactor(1.0)
		TNT1 A 0 SetPlayerProperty(0,0,4)
		Loop
	Select:
		TNHD AAAAAAAAAAAA 0 A_Raise
		TNT1 A 0 SetPlayerProperty(0,1,4)
		TNT1 A 1 A_TakeInventory("PressedUse", 1)
		TNT1 A 1 A_TakeInventory("PressedJump", 2)
		TNHD AAAAA 1 A_Raise
		TNT1 A 1 A_TakeInventory("PressedJump", 2)
		TNT1 A 0
		Goto Ready
	Fire:
	    TNT1 A 0
		TNT1 A 0 A_JumpIfInventory("TankReady", 99, 1)
		Goto NotReady
		TNHD A 1
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmo
		TNT1 A 1
		TNT1 A 0 A_TakeInventory("TankReady", 100, 1)
		TNT1 A 0 A_PlaySound("TANKF", 1)
		TNT1 A 0 A_TakeInventory("TankAmmo", 1)
		MISG A 0 A_FireCustomMissile("TankShell", 0, 1, 0, -24)
		MISG A 0 A_FireCustomMissile("TankFireEffect", 0, 1, 0, -24)
		TNHD B 1 BRIGHT A_SetPitch(-8.0 + pitch)
		
		TNHD CD 1 A_SetPitch(+2.0 + pitch)
		TNHD EF 1 A_SetPitch(+2.0 + pitch)
		TNT1 A 0 A_GunFlash
		TNT1 A 0 A_GiveInventory("FiredTankMainGun", 1)
		TNT1 A 0 A_PlaySound("TANKRE", 3)
		Goto Ready
		
	NoAmmo:
		TNT1 A 2
		Goto Ready 
		
	AltFire:
		TNT1 A 0 A_GunFlash
		TNT1 A 0 ACS_ExecuteAlways(111, 0, 0, 0, 0)//SHOWHUD
		TNT1 A 0 A_JumpIfInventory("HeavyMachinegunAmmo", 1, 1)
		Goto NoAmmo
		TNT1 A 0 A_PlaySound("TANKMG", 1)
		TNT1 A 0 A_FireCustomMissile("HeavyMachinegunProjectile", 0, 1, 20, -25, 0, 0)
		TNT1 AA 0 A_FireCustomMissile("HeavyMachinegunFlash", 0, 1, 20, -25)
		TNT1 A 0 A_TakeInventory("HeavyMachinegunAmmo", 1)
		TNHA A 1 BRIGHT
		TNT1 A 0 A_GunFlash
		TNT1 A 0 A_GiveInventory("TankReady", 1)
		TNHA BC 1 A_GiveInventory("TankReady", 1)
		TNT1 A 0 A_GunFlash
		TNHD A 1 A_GiveInventory("TankReady", 1)
		TNT1 A 0 A_ReFire
		Goto Ready
		
		
	
	TooHigh2:
		TNT1 A 0 A_SetPitch(326)
		Goto Ready
		
	
	TooLowCheck2:
		//NULL A 0 A_JumpIf (pitch > 180, "TooHighCheck1")
		TNT1 A 0 A_SetPitch(16)
		Goto Ready
		
		
	TooHighCheck2:
		TNT1 A 0
		NULL A 0 A_JumpIf (pitch < 325, "TooHigh2")
		Goto Ready
	
	
	
	TooHigh:
		TNT1 A 0 A_SetPitch(326)
		Goto Flash
		
	
	TooLowCheck1:
		//NULL A 0 A_JumpIf (pitch > 180, "TooHighCheck1")
		TNT1 A 0 A_SetPitch(16)
		Goto Flash
		
	TooHighCheck1:
		TNT1 A 0
		NULL A 0 A_JumpIf (pitch < 325, "TooHigh")
		Goto Flash
	
	
	Flash:
		TNT1 A 1
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck1")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck1")
		TNT1 A 1
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck1")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck1")
		TNT1 A 1
		TNT1 A 0 A_JumpIfInventory("PressedUse", 1, "LightEnd")
		NULL A 0 A_JumpIf (pitch > 220, "TooHighCheck1")
		NULL A 0 A_JumpIf (pitch > 16, "TooLowCheck1")
		Stop
	
	LightEnd:
		TNT1 A 10
		Stop
		
	Spawn:
		LAUN A -1
		Stop
		
	}
}
