//SMARTGUN

ACTOR Smartgun : Weapon replaces plasmarifle
{
  Scale 0.2
  spawnid 28
  obituary "%o couldn't escape %k's smart gun."
  radius 20
  height 16
  attacksound "smartfir"
  inventory.pickupmessage "You got the smart gun!"
  weapon.selectionorder 700
  weapon.kickback 100
  weapon.ammotype1 "SmartLoaded"
  weapon.ammotype2 "Smartgunbullets"
  weapon.ammouse 1
  weapon.upsound "smartup"
  weapon.ammogive1 150
  weapon.ammogive2 300
  Weapon.BobSpeed 2.5
  Weapon.BobRangeY 0.3
  Weapon.BobRangeX 0.0
  +NOALERT
  +Weapon.Ammo_Optional
  decal BulletChip
  states
  {
  Ready:
    SMAR A 1 A_WeaponReady
	TNT1 A 0 A_PlayWeaponSound("SMRTDESL")
    goto RealReady 
  RealReady:
    TNT1 B 0 A_StopSound(1)
    SMAR A 1 A_WeaponReady(WRF_ALLOWRELOAD)
	TNT1 A 0 	
    loop
  Dryfire:
  SMAR A 15 A_PlayWeaponSound("DRYFIRE")
  Goto Reload
  Deselect:
    TNT1 A 0 A_SetCrosshair(0)
    SMAR A 1 A_Lower
	TNT1 B 0 A_StopSound(1)
    loop
  Select:
    TNT1 A 0 A_SetCrosshair(8)
    SMAR A 1 A_Raise
    loop
  Fire:
  TNT1 A 0 A_JumpIfNoAmmo("Dryfire")
  TNT1 A 0 A_JumpIfInventory("SmartAlt", 1, "Fire2")
  TNT1 A 0 A_JumpIfInventory("HOLDFIRE", 1, "HoldFire")
	LockOnTarget:
	HoldFire:
    SMAR A 1 A_JumpIfTargetInLOS("LockedOn", 0, JLOSF_CHECKMASTER)
	Goto RealReady
	LockedOn:
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	TNT1 A 0 Bright A_Light1
    TNT1 A 0 A_PlaySound("SMARTFIR", 5)
	SMAR B 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.5 + pitch)
	SMAR C 1
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	SMAR B 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.5 + pitch)
	SMAR C 1
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	SMAR c 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.5 + pitch)
	SMAR C 1
    TNT1 A 0 A_Refire
	TNT1 B 0 A_StopSound(1)
	SMAR A 1 A_WeaponReady(1)
	TNT1 A 0 A_GunFLash
	SMAR A 5 A_WeaponReady(1)
	TNT1 A 0 A_GunFLash
	SMAR A 5 A_WeaponReady(1)
     Goto RealReady 
	 Fire2:
	TNT1 A 0 A_AlertMonsters
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	TNT1 A 0 Bright A_Light1
    TNT1 A 0 A_PlaySound("SMARTFIR", 5)
	SMAR B 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.5 + pitch)
	SMAR C 1
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	SMAR B 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.8 + pitch)
	SMAR C 1
	TNT1 A 0 Radius_Quake (1, 2, 0, 1, 0)
	SMAR c 1 Bright A_FireCustomMissile("SmartGunBullet",0,-4,0)

    TNT1 A 0 A_SetPitch(-0.8 + pitch)
	SMAR C 1
    TNT1 A 0 A_Refire
	TNT1 B 0 A_StopSound(1)
	SMAR A 1 A_WeaponReady(1)
	TNT1 A 0 A_GunFLash
	SMAR A 5 A_WeaponReady(1)
	TNT1 A 0 A_GunFLash
	SMAR A 5 A_WeaponReady(1)
     Goto RealReady	 	
		AltFire:
	TNT1 A 0
	TNT1 A 0 A_JumpIfInventory("SmartAlt", 1, "AltFire2")
	TNT1 A 0 A_GiveInventory("SmartAlt", 1)
	TNT1 A 0 A_Print("Free-Aim Mode selected.")
	TNT1 A 0 A_SetCrosshair(0)
	SMAR A 20 A_Playweaponsound("SMARTUP")
	Goto RealReady
	
	AltFire2:
	TNT1 A 0
	TNT1 A 0 A_TakeInventory("SmartAlt", 1)
	TNT1 A 0 A_Print("Locked Mode selected.")
	TNT1 A 0 A_SetCrosshair(8)
	SMAR A 20 A_Playweaponsound("SMARTUP")
	Goto RealReady
	 
	 Reload:
    SMAR D 0 A_JumpIfInventory("SmartLoaded", 150, 2)
    SMAR D 0 A_JumpIfInventory("Smartgunbullets", 1, "ReloadWork")
    SMAR D 0
  Goto RealReady
	 ReloadWork:
     TNT1 A 0 A_PlaySound("SMARCLIP")
     SMAR D 2 
     SMAR E 3
	 SMAR F 2 
	 ReloadLoop:
     TNT1 A 0 A_TakeInventory("Smartgunbullets", 1)
     TNT1 A 0 A_GiveInventory("SmartLoaded", 1)
     TNT1 A 0 A_JumpIfInventory("SmartLoaded", 150, "ReloadFinish")
     TNT1 A 0 A_JumpIfInventory("Smartgunbullets", 1, "ReloadLoop")
  Goto ReloadFinish
     ReloadFinish:
	 SMAR D 4 
	 Goto RealReady
  Flash:
    TNT1 A 0 bright A_Light1
    TNT1 A 0 bright A_Light2
    TNT1 A 0 bright A_Light0
    stop
  Spawn:
    SMTG A -1
    stop
  }
}


Actor SmartGunBullet : StandartBullet { Damage 4 DeathSound "SMARRIC" }

ACTOR SmartLoaded : Ammo
{
 Inventory.Icon "CELLA0"
 Inventory.MaxAmount 150
 +IGNORESKILL
   States
  {
  Spawn:
    CELP A -1
    Stop
  }
}

ACTOR HoldFire : Inventory
{
Inventory.Amount 1
}

ACTOR SmartAlt : Inventory
{
Inventory.Amount 1
}

ACTOR Smartgunbullets : Ammo
{
  Game Doom
  SpawnID 75
  Inventory.PickupMessage "Picked up some Smartgun bullets."
  Inventory.PickupSound "SMARCLIP"
  Inventory.Amount 20
  Inventory.MaxAmount 500
  Ammo.BackpackAmount 20
  Ammo.BackpackMaxAmount 999
  Inventory.Icon "CELPA0"
  States
  {
  Spawn:
    CELL A -1
    Stop
  }
}

ACTOR Smartgundrum : Smartgunbullets
{
  Game Doom
  SpawnID 142
  Inventory.PickupMessage "Picked up a smart gun ammo drum."
  Inventory.PickupSound "SMARCLIP"
  Inventory.Amount 100
  Inventory.MaxAmount 500
  Ammo.BackpackAmount 20
  Ammo.BackpackMaxAmount 999
  States
  {
  Spawn:
    MING A -1
    Stop
  }
}