// --------------------------------------------------------------------------
//
// M249 (Demo weapon)
//
// --------------------------------------------------------------------------



ACTOR "M249" : CSDMOWeapon //5010
{
	Weapon.SisterWeapon m249_rat

+AMMO_OPTIONAL

Weapon.SelectionOrder 100
  weapon.ammotype "M249Clip"
  weapon.ammouse 1
  weapon.ammogive 0
  weapon.ammotype2 "556mmBoxAmmo"
  weapon.ammouse2 0
  weapon.ammogive2 0 //100
	obituary "%k killed %o with M249."
	+WEAPON.WIMPY_WEAPON
	Inventory.Pickupmessage "Picked up a M249."
	Tag "M249"
	Weapon.UpSound "M249/Ready"
	//AttackSound "M249/Fire" 
	Scale 0.15

DamageType "M249"

	States
	{
	Ready:
		W21E E 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, 195, 0, 0)//Weapon Weight
		TNT1 A 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")

		W21A BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21B ABCDEFGHIJKLMN 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto Ready
				
	Rat_TriggerSelect:
    TNT1 A 0 A_TakeInventory("Rat_Trigger",1)

		W21A BCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21B ABCDEFGHIJKLMN 1 A_WEAPONREADY//(WRF_NOFIRE)
		Goto Ready		
		
	Fire:
	
	W21C A 0 A_JumpIfNoAmmo("AltFire")


		W21D A 1 A_Gunflash
		W21D BC 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_Refire
		W21D CDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WeaponReady
		W21E ABCDE 1 A_WeaponReady
		Goto Ready







  Altfire:
    TNT1 A 0 A_JumpIfInventory("M249Clip",300,"Ready")
    TNT1 A 0 A_JumpIfInventory("556mmBoxAmmo",1,"ReloadStart")
    goto Ready


	ReloadStart:
		W21O ABCDEFGHIJKLMNOPQRS 1 A_WEAPONREADY(WRF_NOFIRE)
		TNT1 A 0 A_PlaySound("M249/Reload", 6)
		W21O TUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21P ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21Q ABC 1 A_WEAPONREADY(WRF_NOFIRE)
		W21H ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21I ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		//I've skipped the "J" while renaming, so, it continues with "K"
		W21K ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21L ABCDEFGHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21M ABCDEF 1 A_WEAPONREADY(WRF_NOFIRE)
		Goto ReloadAmmo
		
  ReloadAmmo:
    TNT1 A 0 A_GiveInventory("M249Clip",1)
    TNT1 A 0 A_TakeInventory("556mmBoxAmmo",1)
    TNT1 A 0 A_JumpIfInventory("M249Clip",0,"ReloadEnd")
    TNT1 A 0 A_JumpIfInventory("556mmBoxAmmo",1,"ReloadAmmo")
    goto ReloadEnd		

	ReloadEnd:
		W21M GHIJKLMNOPQRSTUVWXYZ 1 A_WEAPONREADY(WRF_NOFIRE)
		W21N ABCDEFGHIJKLMNOPQRSTUV 1 A_WEAPONREADY(WRF_NOFIRE)
		W21E CDEE 1 A_WEAPONREADY(WRF_NOFIRE)
		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("WeaponSmokePuff",0,0,11,3)
		TNT1 A 0 Bright A_Light1
		TNT1 A 0 A_AlertMonsters
		TNT1 A 0 A_PlaySound ("M249/FIRE")
		TNT1 A 0 A_PlaySound("NEGEV/Distant", 7)
//		TNT1 A 0 A_PlaySound("m249/Distant", 7)
		TNT1 A 0 A_FireCustomMissile("RifleCaseSpawn",5,0,12,-6)
        TNT1 A 0 BRIGHT A_FireCustomMissile("Tracer", frandom(-2.5,2.5), 0, 11, 0, 0, frandom(-2.5,2.5))
		TNT1 A 1 A_FireBullets(0.4, 0.4, -1, 300.0, "m249Bullet")//7
		Goto LightDone
 	Spawn:
		W21Z A -1
		Stop
	}
}