actor Utility_PrecisionTurretRed : Utility_TurretBase
{
  obituary "%o was sniped by a \cgRed \c-precision turret."
  health 300
  Mass 999999
  speed 0
  painchance 50
  //seesound "turret/sight"
  attacksound "rifle/fire"
  activesound "turret/sight"
  states
  {
  Spawn:
	CIGN AA 0 A_CheckSight("Death.Deconstruction")
	CIGN A 0 ACS_ExecuteWithResult(1026)
	CIGN A 0 Thing_SetSpecial (0, 84, 345, 0, TEAM_RED)
  Idle:
    CIGN A 0 A_GiveInventory("MechReloading",12)
    CIGN A 6 A_LookEx (0, 1024, 0, 0, 0, "See")
    Wait
  See:
    CIGN A 0 A_GiveInventory("IsRed",1)
    CIGN A 2 A_ChangeFlag("FRIENDLY",0)
    CIGN D 12 A_StopSoundEx("SoundSlot6")
    CIGN A 2 A_JumpIfTargetInLOS("Missile")
    CIGN A 0 A_TakeInventory("MechReloading",12)
    CIGN A 2 A_ClearTarget
    goto Idle+1
  See2:
    CIGN A 2 A_ClearTarget
    goto See
  See3:
    CIGN A 1 A_JumpIfInTargetInventory("IsRed",1,"See2")
    CIGN A 0 A_Jump(32,"MissileGo")
    CIGN A 0 A_JumpIfCloser(128,"MissileGo")
    goto See
  MissileCheck:
    CIGN A 0 A_JumpIfInTargetInventory("IsRed",1,"See2")
    CIGN A 0 A_Chase("","",CHF_DONTMOVE)
    CIGN A 0 
    goto MissileGo+2
  Missile:
    CIGN A 0 
    CIGN A 1 A_JumpIfInTargetInventory("IsRed",1,"See2")
    CIGN A 0 A_JumpIfInTargetInventory("StealthMode",1,"See2")
    CIGN A 1 A_JumpIfCloser(18000,"MissileGo")
    CIGN A 0 
    goto See2
  MissileGo:
    CIGN BB 10 A_FaceTarget
    CIGN F 0 A_CPosRefire
    CIGN B 0 A_JumpIfInventory("MechReloading",6,"Pain")
    CIGN B 0 A_PlayWeaponSound("rifle/fire")
    CIGN B 0 A_CustomMissile("PrecisionTurretProjectile",48,0,random(-2,2))
    CIGN B 0 //A_CustomBulletAttack(2,2,1,15,"RiflePuff",4000)
    CIGN B 0 A_SpawnItemEx("Flash",0,0,0,0,0,0,0,128,0)
    CIGN B 0 A_FaceTarget
    CIGN C 4 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
    CIGN BA 6 BRIGHT A_ChangeFlag("FRIENDLY",0)
    CIGN F 0 A_CPosRefire
    CIGN F 0 A_GiveInventory("MechReloading",1)
    goto MissileCheck
  Pain:
    CIGN A 0 A_StopSoundEx("SoundSlot6")
    CIGN A 0 A_ClearTarget
    CIGN A 3 A_TakeInventory("MechReloading",6) // not 9
    goto See
  Death:  
    TC4T A 0     
    CIGN A 0 A_StopSoundEx("SoundSlot6")
    TC4T A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx("ExplosionMain", 0, 0, 32, 0, 0, 0, 0, 128, 0)
    TC4T A 0 A_PlaySound("weapons/rocklx")
    TNT1 A 0 A_SpawnItemEx("FlameWallDecay", 0, 0, 0, 0, 0, 0, 0, 0, 0)
    TNT1 A 4 bright // ACS_ExecuteAlways(345,0,4,0,0)
    stop
  }
}

actor Utility_PrecisionTurretBlue : Utility_TurretBase
{
  obituary "%o was sniped by a \chBlue \c-precision turret."
  health 300
  Mass 999999
  speed 0
  painchance 50
  //seesound "turret/sight"
  attacksound "rifle/fire"
  activesound "turret/sight"
  states
  {
  Spawn:
	CIGN AA 0 A_CheckSight("Death.Deconstruction")
	CIGN A 0 ACS_ExecuteWithResult(1026)
	CIGN A 0 Thing_SetSpecial (0, 84, 345, 0, TEAM_BLUE)
  Idle:
    CIGN A 0 A_GiveInventory("MechReloading",12)
    CIGN A 6 A_LookEx (0, 1024, 0, 0, 0, "See")
    Wait
  See:
    CIGN A 0 A_GiveInventory("IsBlue",1)
    CIGN A 2 A_ChangeFlag("FRIENDLY",0)
    CIGN D 12 A_StopSoundEx("SoundSlot6")
    CIGN A 2 A_JumpIfTargetInLOS("Missile")
    CIGN A 0 A_TakeInventory("MechReloading",12)
    CIGN A 2 A_ClearTarget
    goto Idle+1
  See2:
    CIGN A 2 A_ClearTarget
    goto See
  See3:
    CIGN A 1 A_JumpIfInTargetInventory("IsBlue",1,"See2")
    CIGN A 0 A_Jump(16,"MissileGo")
    CIGN A 0 A_JumpIfCloser(128,"MissileGo")
    goto See
  MissileCheck:
    CIGN A 0 A_JumpIfInTargetInventory("IsBlue",1,"See2")
    CIGN A 0 A_Chase("","",CHF_DONTMOVE)
    CIGN A 0 
    goto MissileGo+2
  Missile:
    CIGN A 0 
    CIGN A 1 A_JumpIfInTargetInventory("IsBlue",1,"See2")
    CIGN A 0 A_JumpIfInTargetInventory("StealthMode",1,"See2")
    CIGN A 1 A_JumpIfCloser(18000,"MissileGo")
    CIGN A 0 
    goto See2
  MissileGo:
    CIGN BB 10 A_FaceTarget
    CIGN F 0 A_CPosRefire
    CIGN B 0 A_JumpIfInventory("MechReloading",6,"Pain")
    CIGN B 0 A_PlayWeaponSound("rifle/fire")
    CIGN B 0 A_CustomMissile("PrecisionTurretProjectileBlue",48,0,random(-2,2))
    CIGN B 0 //A_CustomBulletAttack(2,2,1,15,"RiflePuff",4000)
    CIGN B 0 A_SpawnItemEx("Flash",0,0,0,0,0,0,0,128,0)
    CIGN B 0 A_FaceTarget
    CIGN C 4 BRIGHT A_SpawnItemEx("ShellCasing",8,8,48,random(1,3),random(0,1),random(1,3),random(45,60),128)
    CIGN BA 6 BRIGHT A_ChangeFlag("FRIENDLY",0)
    CIGN F 0 A_CPosRefire
    CIGN F 0 A_GiveInventory("MechReloading",1)
    goto MissileCheck
  Pain:
    CIGN A 0 A_StopSoundEx("SoundSlot6")
    CIGN A 0 A_ClearTarget
    CIGN A 3 A_TakeInventory("MechReloading",6)
    goto See
  Death:  
    TC4T A 0     
    CIGN A 0 A_StopSoundEx("SoundSlot6")
    TC4T A 0 A_NoBlocking
    TNT1 A 0 A_SpawnItemEx("ExplosionMain", 0, 0, 32, 0, 0, 0, 0, 128, 0)
    TC4T A 0 A_PlaySound("weapons/rocklx")
    TNT1 A 0 A_SpawnItemEx("FlameWallDecay", 0, 0, 0, 0, 0, 0, 0, 0, 0)
    TNT1 A 4 bright // ACS_ExecuteAlways(345,0,4,1,0)
    stop
  }
}

actor PrecisionTurretProjectile : FastProjectile
{
  Radius 5
  Height 5
  Speed 550
  Damage (18)
  Projectile
  -RANDOMIZE
  Obituary "%o died."
  DamageType "Rifle"
  Scale 0.0
  States
  { 
  Spawn:
    TNT1 A 35
    loop
  Death:
    TNT1 A 5 A_SpawnItemEx("BulletPuff",0,0,0,0,0,0,0,128,0)
    stop
  }
}

actor PrecisionTurretProjectileBlue : FastProjectile
{
  Radius 5
  Height 5
  Speed 550
  Damage (18)
  Projectile
  -RANDOMIZE
  Obituary "%o died."
  DamageType "Rifle"
  Scale 0.0
  States
  {
  Spawn:
    TNT1 A 35
    loop
  Death:
    TNT1 A 5 A_SpawnItemEx("BulletPuff",0,0,0,0,0,0,0,128,0)
    stop
  }
}