// --------------------------------------------------------------------------
//
// MP5SD (Weapon)
//
// --------------------------------------------------------------------------

ACTOR "MP5SD" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon MP5SD_rat

+AMMO_OPTIONAL

	Weapon.SelectionOrder 300
  weapon.ammotype "MP5SDClip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "9mmAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //30
	obituary "%k killed %o with MP5SD."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a MP5SD"
	Tag "MP5SD"
	Weapon.UpSound "MP5SD/Ready"
	//AttackSound "MP5SD/Fire"
	Scale 0.16

	States
	{
	Ready:
		W50C A 1 A_WeaponReady
		Loop



	Deselect:
	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 2, 0, 0)
    TNT1 A 1 
	Goto DeselectLoop

	Select:
	TNT1 A 1 A_Raise
	TNT1 AA 0 A_Raise
	TNT1 A 0 ACS_ExecuteAlways(798, 0, 220, 0, 0)//Weapon Weight
	W50A B 1 A_TakeInventory("CrosshairType",2)

	TNT1 A 0 ACS_NamedExecuteAlways("HSPreviousWeapon", 0, 1, 0, 0)
    TNT1 A 0 A_JumpIfInventory("RAT_Trigger",1,"RAT_TriggerSelect")

		W50A CDEFGHIJKLMNOPQR 1 A_WEAPONREADY(WRF_NOFIRE)
		W50A STUVWXYZ 1 A_WeaponReady
		W50B CDEFGHI 1 A_WEAPONREADY
		Goto Ready

	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		W50A CDEFGHIJKLMNOPQR 1 A_WEAPONREADY(WRF_NOFIRE)
		W50A STUVWXYZ 1 A_WeaponReady
		W50B CDEFGHI 1 A_WEAPONREADY
		Goto Ready

	Fire:

	W50E D 0 A_JumpIfNoAmmo("AltFire")
	
	
		W50D A 1 A_GunFlash
		W50D B 1 A_WEAPONREADY(WRF_NOFIRE)
		W50D C 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		W50D DEFGHIJKLM 1 A_WeaponReady
		Goto Ready



  Altfire:
    TNT1 A 0 A_JumpIfInventory("MP5SDClip",30,"Ready")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W50E ABC 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("MP5SD/Reload", 6)
		W50E DEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W50F ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W50G ABCDEFGHIJKLMNOPQRS 1 A_WEAPONREADY(WRF_NOFIRE)
		
		Goto ReloadAmmo

  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("MP5SDClip",1)
    TNT1 A 0 A_TakeInventory("9mmAmmo",1)
    TNT1 A 0 A_JumpIfInventory("MP5SDClip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("9mmAmmo",1,"ReloadAmmo")
    goto ReloadEnd
	
	
	ReloadEnd:
		W50G TUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W50H ABCDEFGHIJKLMNOPQRSTUVWX 1 A_WEAPONREADY(WRF_NOFIRE)
		W50H Y 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		
//		W50I ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
//		W50J ABCDEFGHIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE|WRF_NOBOB)
		Goto Ready	
	
	



	Flash:
	TNT1 A 0 ACS_ExecuteAlways(799, 0, 0, 0, 0)
	TNT1 A 0 A_GiveInventory("CrosshairGrow", 6)
	TNT1 A 0 A_FireCustomMissile("WeaponSMGSILENCEDSmokePuff",0,0,16,1)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 //A_AlertMonsters
		TNT1 A 0 A_PlaySound ("MP5SD/FIRE")
		TNT1 A 0 A_PlaySound("m4a1_sil/Distant_sil", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-1.5,1.5), 0, 11, 0, 0, frandom(-1.5,1.5))
		TNT1 A 2 A_FireBullets(1.1, 1.1, 1, 58.0, "MP5SDBullet")//6.25
		Goto LightDone
 	Spawn:
		W50Z A -1
		Stop
	}
}