ACTOR SMGAmmo : Ammo
{
	Inventory.Amount 25
	Inventory.MaxAmount 350
	Ammo.BackpackAmount 25
	Ammo.BackpackMaxAmount 700
	Inventory.Icon SMGAA0
	Inventory.PickupMessage "Picked up some SMG ammo."
	//Inventory.PickupSound "misc/i_pkup"

	States
	{
		Spawn:
			SMGA A -1
			Loop
	}
}

ACTOR SMGAmmoBox : SMGAmmo
{
	Inventory.PickupMessage "Picked up a box of SMG ammo."
	Inventory.Amount 125

	States
	{
		Spawn:
			SMGP A -1
			Loop
	}
}

// ------------------------------------------------------------------

// SMG pickup that creates random weapon values
ACTOR RandomSMGPickup : PickupBase
{
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_isBDPickupItem", 1)	// mark thing as BorderDoom pickup item
			TNT1 A 0 A_SetUserVar("user_pickupType", ItemType_SMG)	// set pickup type to weapon (SMG)
			TNT1 A 0 ACS_NamedExecuteAlways("CreateRandomSMGData")
			TNT1 A 0 A_SetSpecial(ACS_ExecuteAlways,901,0,0,0,0)
			goto Waiting
		Waiting:
			SMGL A -1
			stop
		// called by script. makes the pickup "useable" for a short amount of time so it can be picked up.
		IsUseable:
			TNT1 A 0 A_ChangeFlag("USESPECIAL", TRUE)
			SMGL A 7
			TNT1 A 0 A_ChangeFlag("USESPECIAL", FALSE)
			goto Waiting
	}
}

// SMG pickup that uses pre-existing/pre-set weapon values
ACTOR FixedSMGPickup : RandomSMGPickup
{
	States
	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_SetUserVar("user_isBDPickupItem", 1)	// mark thing as BorderDoom pickup item
			TNT1 A 0 A_SetUserVar("user_pickupType", ItemType_SMG)	// set pickup type to weapon (SMG)
			TNT1 A 0 A_SetSpecial(ACS_ExecuteAlways,901,0,0,0,0)	// script for picking up the item
			SMGL A -1
			stop
	}
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

ACTOR RealSMG : Chaingun
{
	Weapon.AmmoGive 0
	Weapon.BobSpeed 2.0

	+INVENTORY.UNDROPPABLE	// should only be dropped by script
	+Weapon.CHEATNOTWEAPON	// don't give this weapon when using cheats
	+Weapon.Ammo_Optional

	Decal BulletChip	// so this weapon also creates decals when fired at walls
	Tag "SMG"

	States
	{
		Ready:
			SMGG A 1 A_WeaponReady(WRF_ALLOWRELOAD)
			TNT1 A 0 A_JumpIfNoAmmo("Reload")	// auto-reload if player has more ammo
			Loop
		Select:
			TNT1 A 0 ACS_NamedExecuteAlways("SetWeaponDamageMultiplier")
//			TNT1 A 0 ACS_NamedExecute("PrintEquippedWeaponInfo", 0, CallACS("GetWeaponIndex"))
			SMGG A 1 A_Raise
			Loop
		Deselect:
			SMGG A 1 A_Lower
			Loop
		Fire:
			TNT1 A 0 A_JumpIfNoAmmo("NoAmmo")
			goto DoFire
			NoAmmo:
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "Reload")
			TNT1 A 0 A_PlaySound("player/noammo", CHAN_AUTO)
			NoAmmoHold:
			SMGG A 1 A_WeaponReady(WRF_NOFIRE)
			TNT1 A 0 A_Refire("NoAmmoHold")
			goto Ready
			DoFire:
			//TNT1 A 0 A_Quake (4, 4, 0, 1)
			TNT1 A 0 A_PlaySound("SMG/fire_med", CHAN_AUTO)
			TNT1 A 0 A_FireBullets (CallACS("GetCurrentSpread")/65536.0, (CallACS("GetCurrentSpread")/65536.0)/2, CallACS("GetCurrentBulletcount"), CallACS("GetCurrentDamage"), "BulletPuff", FBF_USEAMMO|FBF_NORANDOM)

			TNT1 A 0 A_JumpIf(CallACS("GetCurrentFirerate") == 1, "FireSpeed1")
			TNT1 A 0 A_JumpIf(CallACS("GetCurrentFirerate") == 2, "FireSpeed2")
			TNT1 A 0 A_JumpIf(CallACS("GetCurrentFirerate") == 3, "FireSpeed3")
			TNT1 A 0 A_JumpIf(CallACS("GetCurrentFirerate") == 4, "FireSpeed4")
			TNT1 A 0 A_JumpIf(CallACS("GetCurrentFirerate") == 5, "FireSpeed5")
			Goto Ready
		// fire speeds: very fast: -2, fast: -1, normal: +0, slow: +1, very slow: +2
		FireSpeed1:
			TNT1 A 0 ACS_NamedExecuteAlways("WeaponRecoil", 0, CallACS("GetCurrentRecoil"), 0, 2)
			TNT1 A 0 A_GunFlash
			SMGG A 1 Offset(0, 36)
			SMGG A 1 Offset(0, 32)
			TNT1 A 0 A_ReFire
			Goto Ready
		FireSpeed2:
			TNT1 A 0 ACS_NamedExecuteAlways("WeaponRecoil", 0, CallACS("GetCurrentRecoil"), 0, 2)
			TNT1 A 0 A_GunFlash
			SMGG A 1 Offset(0, 36)
			SMGG A 1 Offset(0, 34)
			SMGG A 2 Offset(0, 32)
			TNT1 A 0 A_ReFire
			Goto Ready
		FireSpeed3:
			TNT1 A 0 ACS_NamedExecuteAlways("WeaponRecoil", 0, CallACS("GetCurrentRecoil"), 66, 4)
			TNT1 A 0 A_GunFlash
			SMGG A 1 Offset(0, 36)
			SMGG A 2 Offset(0, 34)
			SMGG A 3 Offset(0, 32)
			TNT1 A 0 A_ReFire
			Goto Ready
		FireSpeed4:
			TNT1 A 0 ACS_NamedExecuteAlways("WeaponRecoil", 0, CallACS("GetCurrentRecoil"), 66, 4)
			TNT1 A 0 A_GunFlash
			SMGG A 1 Offset(0, 40)
			SMGG A 2 Offset(0, 36)
			SMGG A 3 Offset(0, 32)
			SMGG A 4
			TNT1 A 0 A_ReFire
			Goto Ready
		FireSpeed5:
			TNT1 A 0 ACS_NamedExecuteAlways("WeaponRecoil", 0, CallACS("GetCurrentRecoil"), 66, 4)
			TNT1 A 0 A_GunFlash
			SMGG A 1 Offset(0, 40)
			SMGG A 2 Offset(0, 36)
			SMGG A 2 Offset(0, 32)
			SMGG A 5
			TNT1 A 0 A_ReFire
			Goto Ready
		Flash:
			SMGF A 1 Bright A_Light2
			Goto LightDone

		ReloadWork:
			SMGG A 0 A_ZoomFactor(1.0)
			SMGG A 1 Offset(0,40)
			SMGG A 1 Offset(0,44)
			SMGG A 1 Offset(0,48)
			SMGG A 1 Offset(0,52)
			SMGG A 1 Offset(0,56)
			SMGG A 1 Offset(0,60)
			SMGG A 1 Offset(0,64)
			SMGG A 1 Offset(0,68)
			TNT1 A 0 A_PlaySound("SMG/reload_clipout", CHAN_WEAPON)
			SMGG A 40	// wait for reload
			TNT1 A 0 A_PlaySound("SMG/reload_clipin", CHAN_WEAPON)
			TNT1 A 0 A_Jump(256, "ReloadLoop")	// A_Jump jumps are virtual, "goto" is not
			//Goto ReloadLoop
		ReloadFinish:
			SMGG A 1 Offset(0,68)
			SMGG A 1 Offset(0,64)
			SMGG A 1 Offset(0,60)
			SMGG A 1 Offset(0,56)
			SMGG A 1 Offset(0,52)
			SMGG A 1 Offset(0,48)
			SMGG A 1 Offset(0,44)
			SMGG A 1 Offset(0,40)
			SMGG A 1 Offset(0,36)
			Goto Ready
	}
}


///////////////////////////////
// EQUIPPABLE SMGS
///////////////////////////////

ACTOR RealSMG0 : RealSMG
{
	Weapon.SlotNumber 1
	Weapon.AmmoType "LoadedAmmoSlot0"

	States
	{
		Reload:
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot0", CallACS("GetCurrentClipSize"), "Ready")	// ignore if fully loaded
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadWork")	// do real reload
			Goto Ready
		ReloadLoop:
			TNT1 A 0 A_TakeInventory("SMGAmmo", 1)
			TNT1 A 0 A_GiveInventory("LoadedAmmoSlot0", 1)
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot0", CallACS("GetCurrentClipSize"), "ReloadFinish")
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadLoop")
			Goto ReloadFinish
	}
}

ACTOR RealSMG1 : RealSMG
{
	Weapon.SlotNumber 2
	Weapon.AmmoType "LoadedAmmoSlot1"

	States
	{
		Reload:
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot1", CallACS("GetCurrentClipSize"), "Ready")	// ignore if fully loaded
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadWork")	// do real reload
			Goto Ready
		ReloadLoop:
			TNT1 A 0 A_TakeInventory("SMGAmmo", 1)
			TNT1 A 0 A_GiveInventory("LoadedAmmoSlot1", 1)
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot1", CallACS("GetCurrentClipSize"), "ReloadFinish")
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadLoop")
			Goto ReloadFinish
	}
}

ACTOR RealSMG2 : RealSMG
{
	Weapon.SlotNumber 3
	Weapon.AmmoType "LoadedAmmoSlot2"

	States
	{
		Reload:
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot2", CallACS("GetCurrentClipSize"), "Ready")	// ignore if fully loaded
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadWork")	// do real reload
			Goto Ready
		ReloadLoop:
			TNT1 A 0 A_TakeInventory("SMGAmmo", 1)
			TNT1 A 0 A_GiveInventory("LoadedAmmoSlot2", 1)
			TNT1 A 0 A_JumpIfInventory("LoadedAmmoSlot2", CallACS("GetCurrentClipSize"), "ReloadFinish")
			TNT1 A 0 A_JumpIfInventory("SMGAmmo", 1, "ReloadLoop")
			Goto ReloadFinish
	}
}
