ACTOR Boolean : Inventory { Inventory.MaxAmount 1 }

ACTOR IsReloading : Boolean {}
ACTOR ToReload : Boolean {}
ACTOR ToDeselect : Boolean {}
ACTOR ToUnload : Boolean {}
ACTOR DoADS : Boolean {}
ACTOR HitSomething : Boolean {}
ACTOR UsingSyringe : Boolean {}
ACTOR InIronSights : Boolean {}
ACTOR PendingQuickness : Boolean {}
ACTOR QuickGrenading : Boolean {}
ACTOR QuickHealing : Boolean {}
ACTOR PendingNade : Boolean {}
ACTOR WasZoomed : Boolean {}
ACTOR BackToEmpty : Boolean {}
ACTOR FlashMode : Boolean {}
ACTOR LoopingSound : Boolean {}

// For unloading
ACTOR UnloadPending : Boolean {}
ACTOR UnloadMode : Inventory { Inventory.MaxAmount 64 }
ACTOR AmmoSelection : Inventory { Inventory.MaxAmount 64 }

ACTOR SemiAutomatic : Boolean {}

ACTOR FireMode : Inventory { Inventory.MaxAmount 6 }
ACTOR BaseFireMode : Inventory { Inventory.MaxAmount 64 }

// UNUSED, GET RID OF THESE EVENTUALLY
ACTOR ShareMagazineAmmo : Boolean {}
ACTOR RightMagFull : Boolean {}
ACTOR LeftMagFull : Boolean {}
ACTOR ReloadingR : Boolean {}
ACTOR ReloadingL : Boolean {}
ACTOR SynthFireActive : Boolean {}
ACTOR SynthFireLeft : Boolean {}
ACTOR SynthFireRight : Boolean {}
ACTOR SwitchingAmmo : Boolean {}
ACTOR FuckYou : Boolean {}
ACTOR HasFiringModes : Boolean {}
ACTOR HasEnteredHold : Boolean {}
ACTOR DoBlocking : Boolean {}
ACTOR PullBolt : Boolean {}
ACTOR TertiaryFire : Boolean {}

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
// When a weapon is selected, we are given this item
// depending on the index of the gun in the internal weapon list
//
// This can theoretically be used to fixed desync issues, but
// it's used for spread to prevent us looping through the entire
// list every time we fire a bullet
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
ACTOR StoredIndex : Inventory { Inventory.MaxAmount 500 }

// We're in a menu
ACTOR MenuActive : Inventory { Inventory.MaxAmount 1 }
actor "MenuWeapon" : Weapon
{
  obituary "%o was killed."
  inventory.pickupmessage "PERK MENU!"
  weapon.selectionorder 1
  weapon.kickback 0
  +NOAUTOFIRE
  +NOALERT
  +CHEATNOTWEAPON
  +INVENTORY.UNDROPPABLE
  states
  {
  Spawn:
    TNT1 A 0
    stop
  Ready:
	TNT1 A 0 A_SetCrosshair(20)
    TNT1 A 1 A_WeaponReady(WRF_DISABLESWITCH|WRF_NOFIRE)
    Goto Ready+1
  Deselect:
    TNT1 A 0 A_Lower
    TNT1 A 0 A_SelectWeapon("MenuWeapon")
    TNT1 A 0 A_Lower
    TNT1 A 1 A_Lower
    loop
  Select:
    TNT1 AAAAAAAA 0 A_Raise
	TNT1 A 1 A_WeaponReady
    Goto Ready
  Fire:
    TNT1 A 0
    goto Ready
  AltFire:
    TNT1 A 0
    goto Ready
  }
}

ACTOR ShooterLight: ZTFX
{
	Renderstyle None
	States
	{
	Spawn:
	PUFF A 0
	PUFF A 1
	Stop
	}
}

// DEPRECATED
ACTOR Action_Reload : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_Print("You Need To Rebind Your Reload Key!")//A_GiveInventory("IsReloading",1)
	Fail
	}
}

ACTOR Action_SwitchAmmo : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_GiveInventory("SwitchingAmmo",1)
	Fail
	}
}

ACTOR Action_ADS : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_GiveInventory("DoADS",1)
	Fail
	}
}

ACTOR Action_FuckOff : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_GiveInventory("FuckYou",1)
	Fail
	}
}

ACTOR Action_QuickGrenade : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_Print("You Need To ReBind Your Grenade Key!")//ACS_ExecuteAlways(558,0,0,0,1)
	fail
	}
}

ACTOR Action_Block : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_Print("You Need To ReBind Your Melee Key!")//A_GiveInventory("DoBlocking",1)
	Fail
	}
}

ACTOR Action_TertiaryFire : CustomInventory
{
	Inventory.Amount 1
	Inventory.MaxAmount 1
	-INVBAR
	+INVENTORY.UNDROPPABLE
	States
	{
	Spawn:
	TNT1 A 1
	Loop
	Use:
	TNT1 A 0 A_GiveInventory("TertiaryFire",1)
	Fail
	}
}

// Slow down in iron sights
// This is given via ACS and handled in ZTWeapon's core
ACTOR PowerADS : PowerSpeed
{
  Speed 0.5
  Powerup.Duration 0x7FFFFFFF
}

//--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==
// ZT2 CORE WEAPON
// Has base states that the child MUST jump to
//
// These prevent the need for having jumps in every single weapon
// and keeps things centralized
//--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==

ACTOR ZTWeaponNew : Weapon
{
	+WEAPON.NOAUTOFIRE
	+WEAPON.NOALERT
	+WEAPON.AMMO_OPTIONAL
	+WEAPON.NOAUTOAIM
	Weapon.AmmoUse 1
	Weapon.AmmoGive1 0
	Weapon.BobStyle Smooth
	Weapon.BobSpeed 2.5
	Weapon.BobRangeX 0.5
	Weapon.BobRangeY 0.3
	Inventory.PickupSound "ppsh/pickup"
	Decal Bullet
}

ACTOR ZTWeapon : Weapon
{
	+WEAPON.NOAUTOFIRE
	+WEAPON.NOALERT
	+WEAPON.AMMO_OPTIONAL
	+WEAPON.NOAUTOAIM
	Weapon.AmmoUse 1
	Weapon.AmmoGive1 0
	Weapon.BobStyle Smooth
	Weapon.BobSpeed 2.5
	Weapon.BobRangeX 0.5
	Weapon.BobRangeY 0.3
	Inventory.PickupSound "ppsh/pickup"
	Decal Bullet
	
	States
	{
		// HACK: Required for weapons to even select properly
		// This has to be a VALID sprite
		// This state is basically ignored by everything
		Ready:
			PISG A 1
			Goto Main
			
		// Required state jumps
		Main:
			"####" "#" 0 A_JumpIfInventory("UnloadPending",1,"UnloadCheck")
			"####" "#" 0 A_JumpIfInventory("DoADS",1,"ToggleADS")
			"####" "#" 0 A_JumpIfInventory("DoBlocking",1,"QuickMelee")
			"####" "#" 0 A_JumpIfInventory("IsReloading",1,"ReloadCheck")
			"####" "#" 0 A_JumpIfInventory("InIronSights",1,"ADS")
			"####" "#" 0 A_Jump(256, "Hip")
			"####" "#" -1 A_WeaponReady(WRF_NOSWITCH|WRF_NOFIRE)
			Goto Hip
		Hip:
			"####" "#" 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOFIRE)
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
		// ADS
		// Does nothing unless you override it
		ADS:
			"####" "#" 0
			Goto Main
			
		// Toggle iron sights
		// This is called when you press the key
		ToggleADS:
			"####" "#" 0 A_TakeInventory("DoADS", 1)
			"####" "#" 0 A_JumpIfInventory("InIronSights", 1, "PreZoomOut")
			"####" "#" -1 A_Jump(256, "PreZoomIn")
			Goto PreZoomIn
			
		// Pre-ZoomOut
		// Inventory-related things go here
		PreZoomOut:
			"####" "#" 0 ACS_NamedExecuteAlways("ZoomInOut",0,0,0,0)
			"####" "#" 0 A_TakeInventory("InIronSights", 1)
			"####" "#" 0 A_ZoomFactor(1.00)
			"####" "#" 0 A_SetCrosshair( ACS_NamedExecuteWithResult("GetCrosshair",0) )
			"####" "#" -1 A_Jump(256, "ZoomOut")
			Goto ZoomOut
			
		// Zoom Out
		// Actual zoom out animation
		ZoomOut:
			"####" "#" 1
			Goto ZoomedOut
		
		// Zoomed Out
		// Once we finish zooming out, go to appropriate states
		ZoomedOut:
			"####" "#" 0 A_JumpIfInventory("ToReload",1,"ReloadAnim")
			"####" "#" 0 A_JumpIfInventory("ToDeselect",1,"DeselectAnim")
			Goto Main
			
		// Pre-ZoomIn
		// Inventory-related things go here
		PreZoomIn:
			"####" "#" 0 ACS_NamedExecuteAlways("ZoomInOut",0,1,0,0)
			"####" "#" 0 A_GiveInventory("InIronSights", 1)
			"####" "#" 0 A_SetCrosshair(20)
			"####" "#" -1 A_Jump(256, "ZoomIn")
			Goto ZoomIn
			
		// Zoom In
		// Actual zoom out animation
		ZoomIn:
			"####" "#" 0 A_ZoomFactor(1.05)
			"####" "#" 1
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
		// Quick melee
		// Does nothing unless you override it
		QuickMelee:
			// "####" "#" 0 A_TakeInventory("QuickMelee", 1)
			// "####" "#" 1 A_WeaponReady(WRF_NOSWITCH|WRF_NOFIRE)
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
		// Reload Check
		// Checks for ammunition, you should override this
		ReloadCheck:
			"####" "#" 0 A_TakeInventory("IsReloading", 1)
			"####" "#" 0 A_JumpIf(ACS_NamedExecuteWithResult("ReloadAllowed",0), 1)
			Goto Main
			"####" "#" 0 A_GiveInventory("ToReload", 1)
			
			// Reload voice
			"####" "#" 0 ACS_NamedExecuteAlways("Vocalize",0,0,0,0)

			// Stores IS state if we are zoomed in
		
			"####" "#" 0 A_JumpIfInventory("InIronSights",1,3)
			
			"####" "#" 0 A_TakeInventory("WasZoomed", 1)
			"####" "#" -1 A_Jump(256,"ReloadAnim")
			
			"####" "#" 0 A_GiveInventory("WasZoomed", 1)
			"####" "#" -1 A_Jump(256,"PreZoomOut")
			Goto PreZoomOut

		// Reload Animation
		// Actual animation for reloading
		ReloadAnim:
			"####" "#" 0
			Goto Main
			
		// Reload Complete
		// Take items we used in reloading
		ReloadComplete:
			"####" "#" 0 A_TakeInventory("DoADS", 1)
			"####" "#" 0 A_TakeInventory("ToReload", 1)
			"####" "#" 0 A_TakeInventory("BackToEmpty",1)
			"####" "#" 0 A_TakeInventory("IsReloading",1)
			"####" "#" 0 A_JumpIfInventory("WasZoomed",1,"PreZoomIn")
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
		Deselect:
			"####" "#" 0 A_TakeInventory("UnloadPending",1)
			"####" "#" 0 A_GiveInventory("ToDeselect", 1)
			"####" "#" 0 A_JumpIfInventory("InIronSights",1,"PreZoomOut")
			"####" "#" -1 A_Jump(256, "DeselectAnim")
			Goto DeselectAnim
		DeselectAnim:
			"####" "#" 1
			"####" "#" -1 A_Jump(256, "Deselecting")
			Goto Deselecting
			
		// Instantly deselects the weapon
		Deselecting:
			TNT1 AAAAAAAAAA 0 A_Lower
			TNT1 A 1 A_Lower
			Loop
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
		Select:
			TNT1 A 0 A_TakeInventory("ToDeselect", 1)
			TNT1 A 0 A_TakeInventory("ToReload", 1)
			TNT1 A 0 A_Raise
			TNT1 A 1 A_WeaponReady
			TNT1 A 0 A_SetCrosshair( ACS_NamedExecuteWithResult("GetCrosshair",0) )
			"####" "#" -1 A_Jump(256, "SelectAnim")
			Goto SelectAnim
			 
		SelectAnim:
			TNT1 A 1
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
		// XHairCheck
		// Sets crosshair appropriately
		// Used after switching fire modes
		XHairCheck:
			"####" "#" 1
			"####" "#" 0 A_SetCrosshair( ACS_NamedExecuteWithResult("GetCrosshair",0) )
			Goto Main
		
		// DryFire
		// Play a little click
		DryFire:
			"####" "#" 0 A_PlaySoundEx("orderpistol/dryfire","SoundSlot6")
			Goto Main
		
		// Fire
		// Not a lot of core things we can do there
		Fire:
			"####" "#" 1
			Goto Main
			
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
		
		// UnloadCheck
		// This checks whether or not we can unload this weapon
		// Unload checking is done via ACS, so this will ALWAYS work
		UnloadCheck:
			"####" "#" 0 A_TakeInventory("UnloadPending",1)
			"####" "#" -1 A_Jump(256, "UnloadAnim")
			Goto UnloadAnim
		
		// - - - - - - - - - - - - - - - - - - - - - - - - - - -
			
		Spawn:
			PPSH F -1
			Stop
	}
}

//--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==
// ZT2 MELEE WEAPON
// TODO: This will control parry and directional junk
//--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==--==

ACTOR ZTMeleeWeapon : ZTWeapon
{
	States
	{
		// This gun has no ADS
		ToggleADS:
			"####" "#" 0 A_TakeInventory("DoADS", 1)
			Goto Super::Main
	}
}