ACTOR TKRWU1Automag : UWeapon
{
	Weapon.SelectionOrder 1200
	Weapon.AmmoType "TKRWBullets"
	Weapon.AmmoUse 1
	Weapon.AmmoGive 20
	Weapon.AmmoType2 "TKRWBullets"
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 0
	Inventory.PickupMessage  "You got the Automag." 
	Obituary "%o got gatted by %k's Automag."
	+WEAPON.AMMO_CHECKBOTH
	+CHEATNOTWEAPON
	inventory.Icon "TK68F0"
	Tag "Automag"
	scale 0.1
	States
	{
	Select:
		TNT1 A 0 a_playsound ("Unreal/Weapons/automagcock",6)
		UPRL YZ 1 Offset(1, 32)
		UPR1 ABCDEFGHIJK 1
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20,"SelectReloadFinish")
		TNT1 A 0 A_JumpIfInventory("TKRWBullets", 1, "SelectReload")
		PIDL A 0 A_Raise
		wait
	SelectReload:
		TNT1 A 0 A_TakeInventory ("TKRWBullets",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_TakeInventory ("Magleer",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_GiveInventory("AutomagMag", 1)
		TNT1 A 0 A_GiveInventory("TKRWBullets", 1)
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, "SelectReloadFinish")
		TNT1 A 0 A_JumpIfInventory("TKRWBullets", 1, "SelectReload")
	SelectReloadFinish:
		TNT1 A 0
		PIDL A 0 A_Raise
		goto ready
	Deselect:
		TNT1 A 0 A_Weaponready(WRF_NOFIRE)
		TNT1 A 0 A_Playsound ("weapons/holster", 0)
		TNT1 A 0 A_JumpIfInventory("TKRWBullets",1,"holster")
		TNT1 A 0 A_TakeInventory("AutomagMag", 0,TIF_NOTAKEINFINITE)
	holster:
		TNT1 A 0 A_JumpIfInventory ("AutomagAlt",1,"holster2")
		PIDL A 0 A_Lower
		PIDL A 1 A_Lower
		loop
	holster2:
		UPAE A 0 A_Lower
		UPAE A 1 A_Lower
		loop
	Ready:
		TNT1 A 0 A_JumpIfInventory("TKRWBullets",1,"Ready1")
		TNT1 A 0 A_TakeInventory("AutomagMag", 0,TIF_NOTAKEINFINITE)
	Ready1:
		PIDL A 1 A_WeaponReady
		Loop
	Fire:
		UPAL A 0 A_JumpIfInventory("TKRWBullets",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		UPIF AB 2
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagFire",6)
		PFIR A 1 A_Firebullets (0,0,1,10,"Bulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*18,sin(-pitch)*25+42, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer", 1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPIF D 2
		TNT1 A 0 A_Jump(256,2)
		UPIF D 2 A_Playsound("Unreal/Weapons/click",7)
		UPIF EFGHIJK 1
		UPIF L 0 A_Refire("Hold")
	Fireend:
		UPIF LMNOPQRSTU 1 A_Weaponready(WRF_NOSWITCH)
		Goto Ready
	Hold:
		UPAL A 0 A_JumpIfInventory("TKRWBullets",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagFire",6)
		PFIR A 1 A_Firebullets (0,0,1,10,"Bulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*18,sin(-pitch)*25+42, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer", 1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPIF D 2
		TNT1 A 0 A_Jump(256,2)
		UPIF D 2 A_Playsound("Unreal/Weapons/click",7)
		UPIF EFGHIJK 1
		UPIF L 0 A_Refire("Hold")
		Goto Fireend
	AltFire:
		UPAL A 0 A_JumpIfInventory("TKRWBullets",1,1)
		goto reloading
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		goto reloading
		TNT1 A 0 A_GiveInventory ("AutomagAlt",1)
		UPAF ABC 1
		UPAF D 1
		UPAF EFG 1
		UPAF H 1
		UPAF I 1
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagFire",6)
		PFIR B 1 A_Firebullets (7,5,1,10,"Bulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*10,sin(-pitch)*25+37, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer",1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPAF K 1
		TNT1 A 0 A_Jump(256,2)
		UPAF K 1 A_Playsound("Unreal/Weapons/click",7)
		UPAF LMNOPQR 1
		TNT1 A 0 A_Refire("AltFireloop")
		goto AltFireend
	AltFireloop:
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,"AltFireloop2")
		goto AltFireend
	AltFireloop2:
		UPAL A 0 A_JumpIfInventory("TKRWBullets",1,1)
		Goto AltFireend
		UPAL A 0 A_JumpIfInventory("AutomagMag",1,1)
		Goto AltFireend
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagFire",6)
		TNT1 A 0 A_GiveInventory ("AutomagAlt",1)
		UPAL A 1
		PFIR C 1 A_Firebullets (7,5,1,10,"Bulletpuff",FBF_USEAMMO|FBF_NORANDOM)
		TNT1 A 0 A_SpawnItemEx("ucasing", 33,cos(pitch)*10,sin(-pitch)*25+37, frandom(0.5,1.2),frandom(0.5,1.2),frandom(1.5,2.5))
		TNT1 A 0 A_Quake(2,3,0,1,"none")
		TNT1 A 0 A_GiveInventory ("Magleer",1)
		TNT1 A 0 A_TakeInventory("AutomagMag", 1)
		TNT1 A 0 A_JumpIfInventory("Magleer",17,3)
		UPAL C 1
		TNT1 A 0 A_Jump(256,2)
		UPAL C 1 A_Playsound("Unreal/Weapons/click",7)
		UPAL DEFGH 1
		UPAL H 0 A_Refire("AltFireloop2")
	AltFireend:
		TNT1 A 0 A_TakeInventory ("AutomagAlt",1)
		UPAE ABCDEFGHIJKLMNOPQRST 1
		TNT1 A 0 A_JumpIfInventory("Magleer",20,"reloading")
		Goto Ready
	reloading:
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, 2)
		TNT1 A 0 A_JumpIfInventory("TKRWBullets", 1, "Startreload")
		PIDL A 1 A_WeaponReady
		Goto Ready
	Startreload:
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagReload",6)
		UPRL ABCDEFGHIJKLM 1
	ReloadLoop:
		TNT1 A 0 A_TakeInventory ("TKRWBullets",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_TakeInventory ("Magleer",1,TIF_NOTAKEINFINITE)
		TNT1 A 0 A_GiveInventory("AutomagMag", 1)
		TNT1 A 0 A_GiveInventory("TKRWBullets", 1)
		TNT1 A 0 A_JumpIfInventory("AutomagMag", 20, "ReloadFinish")
		TNT1 A 0 A_JumpIfInventory("TKRWBullets", 1, "ReloadLoop")
		Goto ReloadFinish
	ReloadFinish:
		TNT1 A 0 A_PlaySound ("Unreal/Weapons/automagcock",6)
		UPRL NOPQRSTUVWXYZ 1
		UPR1 ABCDEFGHIJK 1
		Goto Ready
Spawn:
    TNT1 A 0
	TNT1 A 0 A_SpawnItemEx("TKRWMag60",0,0,0,random(1,2),0,5,random(0,360),SXF_NOCHECKPOSITION,0)
    Stop
	}
}

ACTOR AutomagAlt : inventory
{inventory.maxamount 1}

ACTOR AutomagMag : inventory
{inventory.maxamount 20}

actor Magleer : inventory
{inventory.maxamount 20}

Actor Ucasing
{
scale 0.04
radius 3
projectile
gravity 0.2
bouncefactor 0.5
wallbouncefactor 0.4
bouncecount 5
bouncesound "Unreal/Weapons/bounce"
bouncetype "Doom"
-NOGRAVITY
-NOBLOCKMAP
+BOUNCEONCEILINGS
+NOTELEPORT
+DROPOFF
+FLOORCLIP
+THRUACTORS
+FORCEXYBILLBOARD
	states
	{
	Spawn:
		TNT1 A 0 NoDelay A_Jump(255, "Spawn1", "Spawn2", "Spawn3", "Spawn4", "Spawn5")
		goto Spawn1
	Spawn1:
		UCAS ABCDE 2
		loop
	Spawn2:
		UCAS BF 2
		loop
	Spawn3:
		UCAS IJKL 2
		loop
	Spawn4:
		UCAS A 1
		loop
	Spawn5:
		UCAS L 1
		loop
	Death:
		TNT1 A 0 A_Jump(255, "Death1", "Death2")
		goto Death1
	Death1:
		UCAS G 175
		stop
	Death2:
		UCAS H 175
		stop
	}
}

Actor Ucasing2 : Ucasing
{
scale 0.06
}

Actor Ucasing3 : Ucasing
{
scale 0.06
bouncefactor 0.8
wallbouncefactor 0.75
+USEBOUNCESTATE
	states
		{
			Spawn:
				MCAS A 1
				loop
			Bounce:
				TNT1 A 0 A_Jump(100,"bounce2")
				MCAS BCDEFGH 2
				loop
			Bounce2:
				MCAS BCDEFGH 1
				loop
			Death:
				TNT1 A 0 A_Jump(124,2)
				TNT1 A 0 A_Setscale(-0.06,0.06)
				MCAS J 175
				stop
		}
}

Actor Ucasing4 : Ucasing3
{
	states
		{
			Spawn:
				MCAS I 1
				loop
		}
}