

// *** MODIFIED BY CHEBMASTER
// I mark most important places modified by me with //***Che -- unless I forget to.


ACTOR RailGun : BrutalWeapon
{
	Weapon.AmmoUse1 0
	Weapon.AmmoUse2 0
	Weapon.AmmoGive1 50
	Weapon.AmmoGive2 0
	Weapon.AmmoType1 "AmmoCell"
	Weapon.AmmoType2 "RailgunAmmo"
	Obituary "%o was pierced by %k's Railgun."
    Inventory.PickupSound "misc/w_pkup"
	Inventory.Pickupmessage "You got the Railgun!"
	+WEAPON.NOAUTOAIM
    +WEAPON.NOAUTOFIRE
	+WEAPON.NOALERT
	damagetype "Railgun"
	Weapon.SelectionOrder 2500
	States
	{
	
		//***Che disabling player weapons for cutscenes and for the evacuation center
		HoldFire:
			RAIR B 0 offset(-100,54) A_JumpIfInventory("Zoomed",1,"SuddenStopAim")
			RAIR B 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIR B 0 A_JumpIfInventory("Salute1", 1, "Salute")
			RAIR B 0 A_JumpIfInventory("Salute2", 1, "Salute")
			RAIR B 0 A_JumpIfInventory("Reloading",1,"Reload")
			RAIR B 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			RAIR B 0 A_JumpIfInventory("RailgunAmmo",1,"HoldFireHasAmmo")
			
			RAIR B 1 offset(-100,54) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE |WRF_ALLOWRELOAD)
			RAIR B 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready
			
		HoldFireHasAmmo:
			RAIL ABC 1 offset(-100,54) A_WeaponReady(WRF_NOBOB | WRF_NOFIRE | WRF_ALLOWRELOAD)
			RAIR B 0 offset(-100,54) A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto Ready
			
		SelectAnimation:
			RAIS ABC 1
			TNT1 AAA 0
			
		Ready:	
		Ready3:
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			RAIL A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			RAIL A 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIL A 0 A_JumpIfInventory("Salute1", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Salute2", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Reloading",1,"Reload")
		ReadyContinueAfterReload: //***Che instead of Goto Ready+6	
			RAIL A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			RAIL A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			RAIL A 0 A_JumpIfInventory("Unloading",1,"Unload")
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",1,2)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			Goto ReadyNoAmmo
			TNT1 AAAA 0
			
			//***Che: cannot work with user variables here, because weapons run in the context of the player pawn
			TNT1 A 0 A_TakeInventory("AlerterCooldown", 3)
			TNT1 A 0 A_JumpIfInventory("AlerterCooldown", 1, 3)
			// damage type RailAvoid, everything except super archviles and enemy mechs is immune
			RAIL A 0 A_RailAttack(1, 0, 0, None, None, RGF_SILENT, 0, "RailgunAlerterPuff")
			TNT1 A 0 A_GiveInventory("AlerterCooldown", 12)
			
			RAIL ABC 1 A_WeaponReady(WRF_ALLOWRELOAD)
			Goto Ready
		Ready2:
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "NoAim")
			
			TNT1 A 0 A_TakeInventory("AlerterCooldown", 3)
			TNT1 A 0 A_JumpIfInventory("AlerterCooldown", 1, 3)
			// damage type RailAvoid, everything except super archviles and enemy mechs is immune
			RAIL A 0 A_RailAttack(1, 0, 0, None, None, RGF_SILENT, 0, "RailgunAlerterPuff")
			TNT1 A 0 A_GiveInventory("AlerterCooldown", 12)
			"----" A 0 A_GiveInventory ("PlayerIsFighting", 20) //***Che encourages the follower NPCs to get da fug out of your line of fire
			
			SNIP A 1 BRIGHT A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("Unloading",1,"Unload")
			RAIL A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			RAIL A 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIL A 0 A_JumpIfInventory("Salute1", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Salute2", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Reloading",1,"Reload")
			RAIL A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			RAIL A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			Loop
			
		ReadyNoAmmo:
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire") //***Che
			RAIR B 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("HasUnloadedRG", 1, "ReadyUnloaded")
			RAIL A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			RAIL A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			RAIL A 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIL A 0 A_JumpIfInventory("Salute1", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Salute2", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Reloading",1,"Reload")
			RAIL A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			Loop	
		
		ReadyUnloaded:
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire") //***Che
			RAIR L 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("IsRunning",1,"CheckSprint")
			RAIL A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			RAIL A 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIL A 0 A_JumpIfInventory("Salute1", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Salute2", 1, "Salute")
			RAIL A 0 A_JumpIfInventory("Reloading",1,"Reload")
			RAIL A 0 A_JumpIfInventory("TossGrenade",1,"TossGrenade")
			Loop	
			
		DontNeedToReload:
			RAIL A 0 A_JumpIfInventory("Zoomed",1,"Ready2")
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "HoldFire")
			Goto ReadyContinueAfterReload //Ready+6 //***Che
		
		Deselect:
			RAIS CBA 1
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_ZoomFactor(1.0)
			TNT1 AAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Wait
		Select:
			RAIL A 0 A_Giveinventory("GoSpecial",1)
			RAIL A 0 A_Takeinventory("FistsSelected",1)
			RAIL A 0 A_Takeinventory("sawSelected",1)
			RAIL A 0 A_Takeinventory("ShotgunSelected",1)
			RAIL A 0 A_Takeinventory("SSGSelected",1)
			RAIL A 0 A_Takeinventory("MinigunSelected",1)
			RAIL A 0 A_Takeinventory("PlasmaGunSelected",1)
			//RAIL A 0 A_Giveinventory("RocketLauncherSelected",1)
			RAIL A 0 A_Takeinventory("RocketLauncherSelected",1)
			RAIL A 0 A_Takeinventory("GrenadeLauncherSelected",1)
			RAIL A 0 A_Takeinventory("BFGSelected",1)
			RAIL A 0 A_Takeinventory("BFG10kSelected",1)
			RAIL A 0 A_Giveinventory("RailGunSelected",1)
			RAIL A 0 A_Takeinventory("SubMachineGunSelected",1)
			RAIL A 0 A_Takeinventory("RevenantLauncherSelected",1)
	
		//***Che
			"----" A 0 A_Takeinventory("UnmakerSelected",1)
			"----" A 0 A_Takeinventory("MG42Selected",1) //***Che
			"----" A 0 A_Takeinventory("AxeSelected",1) //***Che
			
			"----" A 0 A_Takeinventory("DragonslayerSelected",1) //***Che
	
			RAIL A 0 A_Takeinventory("LostSoulSelected",1)
			RAIL A 0 A_Takeinventory("FlameCannonSelected",1)
			RAIL A 0 A_Takeinventory("HasBarrel",1)
			TNT1 A 1 A_Raise
			TNT1 AAAAAAAAAAA 0 A_Raise
			RAIL A 0 A_GunFlash
			Goto SelectAnimation
			
		Fire:
			RAIL A 0
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",10,2)
			Goto Reload
			TNT1 AA 0
			RAIL A 0 A_Takeinventory("RailgunAmmo",10)
			
			TNT1 A 0 A_TakeInventory("AlerterCooldown", 30)
			TNT1 A 0 A_GiveInventory("AlerterCooldown", 8)
			
			TNT1 A 0 A_GiveInventory ("PlayerIsFighting", 150) //***Che encourages the follower NPCs to get da fug out of your line of fire
				
			RAIL A 0 A_FireCustomMissile("RailgunTrailEffectMissile", 0, 0, 0, 0)
			RAIL A 0 A_FireCustomMissile("RailgunWallPenetrator", 0, 1, 0, 0) //RailgunProjectile
			//RAIL A 0 A_RailAttack(400, 0, 0, "none", "none", RGF_FULLBRIGHT, 1, "RailgunPuff2")
			
			//***Che: the puff is used by this function as a means 
			//  to pass helluvalot extra parameters via flags and properties of its blueprint.
			// It does not matter if the puff spawns at all.
			//  (in this case, it never spawns)
			// P.S. None must be passed without quotes: it's a special identifier, not a string.
			RAIL A 0 A_RailAttack(400, 0, 0, None, None, RGF_FULLBRIGHT, 1, "RailgunPuff2")
			
			RAIL A 0 A_PlaySound("RAILF1", 1)
			RAIL A 0 A_SetPitch(-8.0 + pitch)
			RAIL A 0 A_ZoomFactor(0.7)
			
			RAIL A 0 A_JumpIfInventory("Zoomed",1,"ZoomedRecoil")
			
			RAIF A 1 BRIGHT A_AlertMonsters
			
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_SetPitch(1.0 + pitch)
			RAIF BC 1 BRIGHT 
			
			RAIF DEFG 1 BRIGHT
			RAIL DDDDDDDD 1 A_SetPitch(1.0 + pitch)
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",1,2)
			Goto Reload
			TNT1 AA 0
			RAIL DDDDD 2 A_WeaponReady(WRF_NOFIRE | WRF_NOBOB)
			RAIL A 0 A_PlaySound("RAILR1", 2)
			RAIL DDDDDDDDDDDDDDDD 2 A_WeaponReady(WRF_NOFIRE | WRF_NOBOB)
			RAIL A 0 A_PlaySound("BEPBEP", 2)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			RAIL A 0 A_Refire
			TNT1 AAAA 0
			Goto Ready3
			
		ZoomedRecoil:
			SNIP A 1 BRIGHT A_AlertMonsters
			RAIL A 0 A_ZoomFactor(5.0)
			RAIL A 0 A_SetPitch(1.0 + pitch)
			SNIP AAA 1 A_FireCustomMissile("SmokeSpawner",0,0,0,5)
			SNIP AAAAAAAA 1 A_SetPitch(1.0 + pitch)
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",1,2)
			Goto Reload
			TNT1 AA 0
			SNIP AAAAAA 1 A_JumpifInventory("FiredSecondary", 1, "SuddenStopAim")
			RAIL A 0 A_PlaySound("RAILR1", 2)
			RAIL A 0 A_WeaponReady(WRF_NOFIRE | WRF_NOBOB)
			SNIP AAAAAAAAAAAAAAAA 2 A_JumpifInventory("FiredSecondary", 1, "SuddenStopAim2")
			RAIL A 0 A_PlaySound("BEPBEP", 2)
			SNIP A 1 A_Refire
			Goto Ready2
			
		
		SuddenStopAim:
			RAIL A 0
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIZ AB 1
			RAIL DDDDDD 1
			RAIL A 0 A_PlaySound("RAILR1", 2)
			RAIL DDDDDDDDDDDDDDDD 2
			RAIL A 0 A_PlaySound("BEPBEP", 2)
			Goto Ready
			
		SuddenStopAim2:
			RAIL A 0
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIZ AB 1
			RAIL DDDDDDDDDDDDDDDD 2
			RAIL A 0 A_PlaySound("BEPBEP", 2)
			Goto Ready	

		AltFire:
			RAIL A 0
			
			TNT1 A 0 A_TakeInventory("AlerterCooldown", 3)
			TNT1 A 0 A_JumpIfInventory("AlerterCooldown", 1, 3)
			// damage type RailAvoid, everything except super archviles and enemy mechs is immune
			RAIL A 0 A_RailAttack(1, 0, 0, None, None, RGF_SILENT, 0, "RailgunAlerterPuff")
			TNT1 A 0 A_GiveInventory("AlerterCooldown", 12)			
			
			RAIL A 0 A_JumpIfInventory("Zoomed",1,"NoAim")
			RAIL A 0 A_Giveinventory("Zoomed",1)
			RAIL A 0 A_ZoomFactor(5.0)
			RAIL A 0 A_giveinventory("PowerLightAmp", 1)
			RAIZ AB 1 BRIGHT
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			RAIL A 0 A_JumpIfInventory("FiredSecondary",1,"HoldAim")
			Goto Ready2
			
		HoldAim:	
			TNT1 A 0 A_JumpIfInventory("DisablePlayerWeapons", 1, "NoAim")
			
			TNT1 A 0 A_TakeInventory("AlerterCooldown", 3)
			TNT1 A 0 A_JumpIfInventory("AlerterCooldown", 1, 3)
			// damage type RailAvoid, everything except super archviles and enemy mechs is immune
			RAIL A 0 A_RailAttack(1, 0, 0, None, None, RGF_SILENT, 0, "RailgunAlerterPuff")
			TNT1 A 0 A_GiveInventory("AlerterCooldown", 12)
			
			TNT1 A 0 A_GiveInventory ("PlayerIsFighting", 20) //***Che encourages the follower NPCs to get da fug out of your line of fire
			
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredPrimary",1,"Fire")
			SNIP A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			RAIL A 0 A_JumpIfInventory("FiredSecondary",1,"HoldAim")
		NoAim:	
			RAIZ BA 1 BRIGHT
			RAIL A 0 A_Light0
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIL A 0 A_ZoomFactor(1.0)
			Goto Ready
			
			
		Reload:
			RAIL A 0
			
			
			
			RAIL A 0 A_Takeinventory("Reloading",1)
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",50,"DontNeedToReload")
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_JumpIfInventory("AmmoCell",1,3)
			Goto ReadyContinueAfterReload //Ready+6 //***Che
			TNT1 AAAA 0
			
			
			RAIL A 0 A_JumpIfInventory("TurboReload", 1, "InsertBullets")
			RAIL A 0 A_JumpIfInventory("HasUnloadedRG",1, 17)
			RAIR AA 1
			RAIL A 0 A_PlaySound("PLREADY", 2)
			RAIR ABCDEF 1
			RAIL A 0 A_FireCustomMissile("PlasmaCaseSpawn",-30,0,-4,-4)
			RAIR GHIJKL 1
			RAIR L 20
			RAIR MNOP 1
			RAIR QRSTUVUUUUUUWX 1
			RAIL A 0 A_PlaySound("RAILR1", 2)
			RAIL D 30
			RAIL A 0 A_PlaySound("BEPBEP", 2)
			RAIL A 0 A_Takeinventory("HasUnloadedRG", 1)
		InsertBullets:	
			TNT1 AAAA 0
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",50,"Ready")
			RAIL A 0 A_JumpIfInventory("AmmoCell",1,3)
			Goto Ready
			TNT1 AAAAAA 0
			RAIL A 0 A_Giveinventory("RailgunAmmo",1)
			RAIL A 0 A_Takeinventory("AmmoCell",1)
			Loop
			
			
			
		Unload:
			RAIL A 0
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIL A 0 A_Takeinventory("Unloading",1)
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",1,2)
			Goto ReadyUnloaded
			TNT1 AA 0
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_JumpIfInventory("AmmoCell",1,3)
			Goto ReadyContinueAfterReload //Ready+6 //***Che
			TNT1 AAAA 0
			
			RAIR AA 1
			RAIL A 0 A_PlaySound("PLREADY", 2)
			RAIR ABCDEF 1
			RAIR GHIJKL 1
			RAIL A 0 A_Giveinventory("HasUnloadedRG",1)
			RAIL A 0 A_StopSound(2)
		RemoveBullets:	
			TNT1 AAAA 0
			RAIL A 0 A_JumpIfInventory("RailgunAmmo",1,3)
			Goto ReadyUnloaded
			TNT1 AAAAAA 0
			RAIL A 0 A_Takeinventory("RailgunAmmo",1)
			RAIL A 0 A_Giveinventory("AmmoCell",1)
			Loop	
			
		Spawn:
			SRCG A -1
			Stop
			
		CheckSprint:
			RAIL A 1 A_WeaponReady(WRF_NOFIRE)
			RAIL A 0 A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			RAIL A 0 A_JumpIfInventory("IsTacticalClass", 1, "StartSprint")
			Goto Ready3
			
		CheckSprint2:
			RI2G A 1 A_WeaponReady(WRF_NOFIRE)
			RAIL A 0 A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			RAIL A 0 A_JumpIfInventory("IsTacticalClass", 1, "StartSprint")
			Goto Ready2	
			
		StartSprint:
			RAIL A 1 A_WeaponReady(WRF_NOFIRE)
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("ADSmode",1)
			RAIL A 0 A_ZoomFactor(1.0)
			RAIL A 0 A_JumpIfInventory("UsedStamina", 40, "StopSprintTired")
			
		Sprinting:	
			RAIL A 0 offset(-9,32) 
			RAIL A 0 offset(-9,32) A_JumpIfInventory("IsStandingStill", 1, "Ready3")
			RAIL A 0 offset(-9,32) A_JumpIfInventory("UsedStamina", 100, "StopSprintTired")
			PLAY A 0 offset(-9,32) ACS_ExecuteAlways(852, 0, 0, 0, 0)//Makes player faster.
			RAIL A 0 offset(-9,32) A_JumpIfInventory("PowerStrength", 1, 2)
			RAIL A 0 offset(-9,32) A_GiveInventory("UsedStamina", 5)
			RAIL A 0 offset(-9,32)
			RAIL A 1 offset(-9,34) A_SetPitch(pitch -0.5)
			RAIL B 1 offset(-6,36) A_SetPitch(pitch -0.5)
			RAIL C 1 offset(-3,38) A_SetPitch(pitch -0.5)
			RAIL A 1 offset(0,38) A_SetPitch(pitch -0.5)
			RAIL B 1 offset(3,36) A_SetPitch(pitch -0.5)
			RAIL C 1 offset(6,34) A_SetPitch(pitch -0.5)
			RAIL A 1 offset(9,32) A_SetPitch(pitch -0.5)
			RAIL A 0 offset(9,32) A_WeaponReady(WRF_NOBOB)
			RAIL A 0 A_JumpIfInventory("Kicking",1,"DoKick")
			RAIL A 0 A_JumpIfInventory("Taunting",1,"GoTaunt")
			RAIL A 0 A_JumpIfInventory("Reloading",1,"Reload")
			RAIL A 0 offset(-9,32) A_GiveInventory("UsedStamina", 5)
			RAIL A 0 offset(9,33) A_SpawnItemEx("FootStep", 0, 0, 2, 0, 0, -4)
			RAIL B 1 offset(9,34) A_SetPitch(pitch +0.5)
			RAIL C 1 offset(6,36) A_SetPitch(pitch +0.5)
			RAIL A 1 offset(3,38) A_SetPitch(pitch +0.5)
			RAIL B 1 offset(0,38) A_SetPitch(pitch +0.5)
			RAIL C 1 offset(-3,36) A_SetPitch(pitch +0.5)
			RAIL A 1 offset(-6,34) A_SetPitch(pitch +0.5)
			RAIL B 1 offset(-9,32) A_SetPitch(pitch +0.5)
			RAIL A 0 offset(-9,32) A_WeaponReady(WRF_NOBOB)
			RAIL A 0 offset(-9,32) A_JumpIfInventory("IsRunning", 1, "Sprinting")
			
			Goto StopSprint
		StopSprintTired:
			RAIL A 1
			PLAY A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			RAIL A 0 A_PlaySound("Tired", 2)
			RAIL A 0 A_TakeInventory("UsedStamina", 2)
			RAIL A 5 A_WeaponReady
			RAIL A 0 A_TakeInventory("UsedStamina", 2)
			RAIL A 5 A_WeaponReady
			RAIL A 0 A_TakeInventory("UsedStamina", 2)
			RAIL A 5 A_WeaponReady
			RAIL A 0 A_TakeInventory("UsedStamina", 2)
			RAIL A 5 A_WeaponReady
			RAIL A 0 A_TakeInventory("UsedStamina", 2)
			RAIL A 5 A_WeaponReady
			Goto Ready3
		StopSprint:
			RAIL A 1
			RAIL A 0 A_JumpIfInventory("UsedStamina", 60, "StopSprintTired")
			PLAY A 0 ACS_ExecuteAlways(853, 0, 0, 0, 0)//Makes player slower.
			Goto Ready3	
			
		GoTaunt:
			RAIL A 0
			RAIL A 0 A_Light0
			RAIL A 0 A_Takeinventory("Zoomed",1)
			RAIL A 0 A_Takeinventory("PowerLightAmp", 1)
			RAIL A 0 A_ZoomFactor(1.0)
			Goto Taunt
	}
}


ACTOR RailgunProjectile
{
	
	Radius 2
	Height 2
	Speed 80
	Damage (random(400, 400))
    DamageType Railgun
	Decal "SmallerScorch"
	Projectile
	+RANDOMIZE
	+MISSILE
	+FORCERADIUSDMG
	+THRUACTORS
	Species "Marines"
	Scale 1.0
	var int user_railangle;
	
	renderstyle ADD
	alpha 0.90
	Scale 0.10
	DeathSound "weapons/plasmax"
	//SeeSound "PLSM9"
    SeeSound "None"
	Obituary "$OB_MPPLASMARIFLE"
	+BounceOnWalls
	+BounceOnFloors
	+BounceOnCeilings
	BounceFactor 1.0
	+USEBOUNCESTATE
	BounceCOunt 3
	//MissileType "WhiteShockwave"
	States
	{
	DM:
		RAIL A 0
		RAIL A 0 A_ChangeFLag("THRUSPECIES", 0)
		RAIL A 0 A_ChangeFLag("MTHRUSPECIES", 0)
		Goto Spawn1
	
	Spawn:
		RAIL A 0
		RAIL A 0 A_FaceTarget
		RAIL A 0 A_SetUserVar("user_railangle", angle)
		RAIL A 0 A_SpawnItem("WhiteShockwave")
		RAIL A 0 ACS_NamedExecuteAlways("CheckIfDM", 0, 0, 0, 0)//Check if Coop
		
		TNT1 C 1 BRIGHT A_SpawnItem("WhiteShockwave")
		

	Spawn1:
        TNT1 C 1 BRIGHT A_SpawnItem("WhiteShockwave")
		RAIL A 0 A_SpawnItem("WhiteShockwave")
		RAIL A 0 A_CheckFloor("Death")
		RAIL A 0 A_CustomMissile ("OldschoolRocketSmokeTrail2", 2, 0, random (160, 210), 2, random (-30, 30))
		Loop
	
	Bounce.Wall:
		RAIL A 0
		RAIL A 0 A_SetAngle(user_railangle)
		RAIL A 0 BRIGHT A_CustomMissile("RailgunPenetrator1", 0, 0, 180, 2, momz)
		Goto Death
		
	Bounce.Floor:
	Bounce.Ceiling:
		TNT1 A 1
		RAIL A 0 A_SetAngle(user_railangle)
		RAIL A 0 BRIGHT A_CustomMissile("RailgunPenetrator1b", 0, 0, 180, 2, -momz)
		Goto Death
		
	Death:
	Melee:
	Xdeath:
		TNT1 AAAA 0 A_SpawnItemEx("BluePlasmaParticleSpawner", 0, 0, 0, 0, 0, 0, 0, 128)
		TNT1 AA 0 A_SpawnItem("WhiteShockwave")
		RAIL A 0 A_Explode(120,5, 1)
        TNT1 AAAAAAAAA 0 A_CustomMissile ("ExplosionParticleHeavy", 0, 0, random (0, 360), 2, random (0, 180))
        TNT1 AAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("ExplosionParticleHeavy", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 AAAAAAAAA 0 A_CustomMissile ("ExplosionParticleVeryFast", 0, 0, random (0, 360), 2, random (0, 360))
        EXPL AAAAA 0 A_CustomMissile ("ExplosionSmokeFast22", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 AAAA 0 A_CustomMissile ("FireworkSFXType2", 2, 0, random (0, 360), 2, random (10, 80))
		RAIL A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		RAIL A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
		RAIL A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 AAAAA 0 A_CustomMissile ("BluePlasmaParticle", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 ABE 0 BRIGHT A_SpawnItem("BlueFlare" ,0)
		Stop
		Stop
	}
}

aCTOR rAILGUNpENETRATOR1
{
	PROJECTILE
	+Missile
	+NOCLIP
	Radius 2
	Height 2
	Speed 40
	Damagetype "Extreme"
	States
	{
		Spawn:
			RAIL A 0
			RAIL A 0 A_CheckFloor("XDeath")
			RAIL A 0 A_Checkceiling("XDeath")
			TNT1 A 0 A_Explode(100, 100)
			TNT1 A 1
			TNT1 A 0 A_Explode(100, 100)
			RAIL A 0 BRIGHT A_CustomMissile("RailgunPenetrator", 0, 0, 0, 2, momz)
			Stop
		XDeath:
			RAIL A 0
			Stop
	}
}


aCTOR rAILGUNpENETRATOR1B: rAILGUNpENETRATOR1
{
	Speed 40
}
		



actor RailgunTracerTrail
{
    Scale 0.2
    RenderStyle Add
    Alpha 0.9
    +NOINTERACTION
    +CLIENTSIDEONLY
	+FORCEXYBILLBOARD
    States
    {
    Spawn:
        PBAL A 2 BRIGHT
        stop
    }
}

Actor RailgunPenetrationParticle
{
+THRUACTORS
+CLIENTSIDEONLY
+MISSILE
+NOGRAVITY
States
	{
		Spawn:
			
			TNT1 A 15
			TNT1 AAAA 0 A_CustomMissile ("OldschoolRocketSmokeTrailDarker", 2, 0, random (160, 210), 2, random (-30, 30))
			Stop
}}



Actor RailgunTrailEffectMissile: FastProjectile
{
	damage (random(0, 0))
	//Decal "Scorch"
	Decal None
	DamageType Railgun
	+NODAMAGETHRUST
	Radius 1
	Height 1
	Scale 0.2
	Speed 999
	-SKYEXPLODE
	//+ripper
	+THRUGHOST
	+THRUACTORS

	MissileType "RailgunTrailEffect"
	States
	{
		Spawn:
			TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 1 A_SpawnItem("RailgunTrailEffect")
			Stop
			
		Death:
			TNT1 A 0
			Stop
//***Che: moved to a separate wall penetrator projectile			
/*			
			RAIL A 0
			TNT1 B 0
			RAIL A 0 A_SpawnItemEx ("Footstep91",0,0, 40,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 B 1 
			RAIL A 0 A_SpawnItemEx ("ExplosionSplashSpawner", 0, 0, 0)
			RAIL A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AA 0 A_CustomMissile ("SparkXNoModel", 2, 0, random (0, 360), 2, random (0, 360))
			RAIL A 0 A_SpawnItem("RailgunFlameTrails")
			
			EXPL A 0 Radius_Quake (3, 8, 0, 15, 0)
			RAIL A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL 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 ("ExplosionFlames", 0, 0, random (0, 360), 2, random (0, 360))
			RAIL A 0 A_SpawnItemEx ("RocketExplosion",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 2
			RAIL A 0 A_SpawnItemEx ("LiquidExplosionEffectSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL A 0 A_PlaySound("FAREXPL", 3)
			TNT1 A 15
			RAIL A 0 A_PlaySound("distantexp", 5)
			Stop
*/			
	}
}


//***Che: ignores actors, only collides with map geometry

Actor RailgunWallPenetrator: FastProjectile 
{
	damage (random(0, 0))
	Decal "Scorch"
	
	DamageType Railgun
	+NODAMAGETHRUST
	Radius 2
	Height 1
	Scale 0.2
	Speed 999
	-SKYEXPLODE
	+THRUGHOST
	+THRUACTORS
	MissileType None
//	var int user_vx;
//	var int user_vy;
//	var int user_vz;
	States
	{
		Spawn:
			TNT1 A 1
			Loop
		Crash:
		Death:
			TNT1 A 0
			
			TNT1 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA 0 A_CustomMissile("RailgunSpallTracker1", 0, 0, random(-30,30), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, pitch + random(-30, 30))
			

			TNT1 A 0 A_SpawnItemEx ("Footstep91",0,0, 40,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 A 0 
			RAIL A 0 A_SpawnItemEx ("ExplosionSplashSpawner", 0, 0, 0)
			RAIL A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			TNT1 AA 0 A_CustomMissile ("SparkXNoModel", 2, 0, random (0, 360), 2, random (0, 360))
			RAIL A 0 A_SpawnItem("RailgunFlameTrails")
			
			EXPL A 0 Radius_Quake (3, 8, 0, 15, 0)
			RAIL A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL 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 ("ExplosionFlames", 0, 0, random (0, 360), 2, random (0, 360))
			
			
			//inflict damage
			RAIL A 0 A_SpawnItemEx ("RocketExplosion",0,0,13,0,0,0,0,SXF_NOCHECKPOSITION,0)
			
			
			TNT1 A 2
			RAIL A 0 A_SpawnItemEx ("LiquidExplosionEffectSpawner",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
			RAIL A 0 A_PlaySound("FAREXPL", 3)
			TNT1 A 15
			RAIL A 0 A_PlaySound("distantexp", 5)
			Stop
		
	}
}

//***Che Step one: fire a bunch of missiles with collision OFF that go through walls, *floors* and everything.

Actor RailgunSpallTracker1 {
	//PROJECTILE
	+NOINTERACTION // ignore *ALL* collision
	-CLIENTSIDEONLY
	Decal None
	Radius 1
	Height 1
	Speed 50
	Scale 1
	States {
		Spawn:
			TNT1 A 1
			
			//***Che Step two: fire, straight backwards, 
			//  	projectiles tasked with finding the other side of the wall.
			//  Must pass through everything but walls.
			
			TNT1 A 0 A_Stop
			TNT1 A 10 A_CustomMissile("RailgunSpallTracker2", 0, 0, 180, CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, -pitch)
			TNT1 A 0
			Stop
	
	}
}


Actor RailgunSpallTracker2: FastProjectile
{
	damage (random(0, 0))
	Decal "Scorch"
	DamageType Railgun
	+NODAMAGETHRUST
	Radius 2
	Height 1
	Scale 0.2
	Speed 64
	-SKYEXPLODE
	+THRUGHOST
	+THRUACTORS
	States {
		Spawn:
			TNT1 A 1
			//KYDB G 30 A_Stop
			Stop
		Death:
			TNT1 A 0
			
			//***Che Step three: we found the wall surface! Fire damaging tracers forward.
			// (also causes shrapnel from the floor and ceiling when hit at a shallow angle)			
			
			
			TNT1 A 0 A_Stop
			TNT1 A 0 A_CustomMissile("ShotgunguyTracer", 0, 0, random(150,210), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, - pitch + random(-30, 30))
			//SPRK AAAAAA 1 A_FadeOut(0.2)
			TNT1 A 0 A_Jump(140, 2)
			TNT1 A 0 A_CustomMissile ("Spark_BD13", 0, 0, random(150,210), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, - pitch + random(-30, 30))
			TNT1 A 0 A_Jump(140, 2)
			TNT1 A 0 A_CustomMissile ("Spark_BD16", 0, 0, random(150,210), CMF_AIMDIRECTION | CMF_TRACKOWNER | CMF_ABSOLUTEPITCH | CMF_SAVEPITCH, - pitch + random(-30, 30))
			TNT1 A 10
			//KYDB J 30
		Crash:
		XDeath:
			// this should never happen
			TNT1 A 0
			Stop
	}
}	





Actor RailgunTrailEffect
{
	+THRUACTORS
	+CLIENTSIDEONLY
	+MISSILE
	+NOGRAVITY
	States
	{
		Spawn:
			//TNT1 AAAA 0 A_CustomMissile ("RailgunTrailParticle", 2, 0, random (0, 360), 2, random (0, 360))
			RAIL A 0
			RAIL A 0 A_SpawnItem("RailgunFlameTrailsBlue")
			TNT1 A 12
			TNT1 AAAA 0 A_CustomMissile ("OldschoolRocketSmokeTrailDarker", 2, 0, random (160, 210), 2, random (-30, 30))
			Stop
	}
}

Actor RailgunPenetrator: MarineTracer
{
damage (random(50, 60))
//Decal "BulletDecalNew1"
Decal "Scorch"
DamageType Extreme
Radius 4
Height 4
Scale 0.2
+MISSILE
+RIPPER
Speed 80
-SKYEXPLODE
MissileType "RailgunPenetrationParticle"
States
{
	Spawn:
		RAIL A 0
		RAIL A 0 A_CustomMissile("SpawnBulletDecalBackwards", 0, 0, 0)
		TNT1 A 10
		
		sTOP
		
Death:
	RAIL A 0
    TNT1 A 1
	RAIL A 0 A_SpawnItemEx ("DetectFloorCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	    RAIL A 0 A_SpawnItemEx ("DetectCeilCrater",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	    RAIL A 0 A_SpawnItemEx ("UnderwaterExplosion",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
        TNT1 AAAAAAAAA 0 A_CustomMissile ("ExplosionParticleHeavy", 0, 0, random (0, 360), 2, random (0, 180))
        TNT1 AAAAAAAAAAAAAAAAAA 0 A_CustomMissile ("ExplosionParticleHeavy", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 AAAAAAAAA 0 A_CustomMissile ("ExplosionParticleVeryFast", 0, 0, random (0, 360), 2, random (0, 360))
        EXPL AAAAA 0 A_CustomMissile ("ExplosionSmokeFast22", 0, 0, random (0, 360), 2, random (0, 360))
		TNT1 A 0 A_Explode(50, 100)
	RAIL A 0 A_SpawnItemEx ("DetectFloorCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	RAIL A 0 A_SpawnItemEx ("DetectCeilCraterSmall",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION,0)
	RAIL A 0 A_CustomMissile ("BluePlasmaFire", 0, 0, random (0, 360), 2, random (0, 360))
	TNT1 AAAAA 0 A_CustomMissile ("BluePlasmaParticle", 0, 0, random (0, 360), 2, random (0, 360))
	TNT1 ABCDE 2 BRIGHT A_SpawnItem("BlueFlare" ,0)
    TNT2 AAAAAAAAA 9 A_CustomMissile ("PlasmaSmoke", 1, 0, random (0, 360), 2, random (0, 160))
	Stop
	
DeathSpecial:	
	
    Stop
XDEath:
RAIL A 0
//RAIL A 0 A_Explode(2, 5)
TNT1 A 1
Stop	
}
}

/*
actor DebugRailgunPuff2: Hitpuff
{
	Scale 2
	DamageType Railgun
	Radius 2
	Height 2
	+ALWAYSPUFF
	+PUFFONACTORS
	States {
		Death:
			KYDB I 90 BRIGHT 
			Stop
		XDeath:
			KYDB O 90 BRIGHT 
			Stop
		Crash:	
			KYDB H 90 BRIGHT 
			Stop
		Melee:	
			KYDB M 90 BRIGHT 
			Stop			
	}
}
*/

ACTOR RailgunAlerterPuff: RailgunPuff2
{
	+BLOODLESSIMPACT
	DamageType RailAvoid
	States {
		Death:
			TNT1 A 1
			Stop
		XDeath:
			TNT1 A 1
			Stop
		Crash:	
			TNT1 A 1
			Stop
		Melee:	
			TNT1 A 1
			Stop			
	}	
}