Actor SpecOpsMachinegunner
{
  Health 150
  Height 56
  Radius 20
  Speed 8
  PainChance 96
  Monster
  +FloorClip
  +NoTarget
  +NoInfighting
  +DontHurtSpecies
  Species "SpecOps"
  SeeSound "SpecOpsZombie/Sight"
  ActiveSound "SpecOpsZombie/Active"
  PainSound "SpecOpsZombie/Pain"
  DeathSound "SpecOpsZombie/Death"
  Obituary "%o was gunned down by a Spec Ops Zombie."
  Decal BulletChip
  DropItem "Assault Rifle" 256 1
  DropItem "StimKit" 80
  DropItem "ArmorBooster" 80
  DropItem "AmmoPack" 60
  DropItem "HandGrenadeAmmo" 100 1
  DropItem "MineAmmo" 50 1
  DropItem "BulletMag" 100 20
  DropItem "BulletMag" 100 20
  States
  {
  Spawn:
    SPE2 A 1 A_Look
    Loop

  //Switching
  See:
	TNT1 A 0 A_JumpIfTargetInLOS("See2")
	SPE2 ABCD 4 A_Chase
	Loop
  
  See2:
    SPE2 A 0 A_TakeInventory("ZSpecOpAggressive", 1)
    SPE2 A 0 A_TakeInventory("ZSpecOpSnipe", 1)
    SPE2 A 0 A_TakeInventory("ZSpecOpWander", 1)
    SPE2 A 0 A_TakeInventory("ZSpecOpCreep", 1)
    SPE2 A 0 A_TakeInventory("ZSpecOpFlee", 1)
    SPE2 A 0 A_ChangeFlag("MissileMore", 0)
    SPE2 A 0 A_ChangeFlag("MissileEvenMore", 0)
    SPE2 A 0 A_ChangeFlag("AvoidMelee", 0)
    SPE2 A 0 A_ChangeFlag("Frightened", 0)
    SPE2 A 0 A_GiveInventory("ZSpecOpsMSitRep", 1)
    SPE2 A 0 A_JumpIfInventory("ZSpecOpAggressive", 1, "AggressiveSwitch")
    SPE2 A 0 A_JumpIfInventory("ZSpecOpSnipe", 1, "SnipeSwitch")
    SPE2 A 0 A_JumpIfInventory("ZSpecOpWander", 1, "WanderSwitch")
    SPE2 A 0 A_JumpIfInventory("ZSpecOpCreep", 1, "CreepSwitch")
    SPE2 A 0 A_JumpIfInventory("ZSpecOpFlee", 1, "FleeSwitch")

  //Aggressive Mode
  AggressiveSwitch:
    SPE2 A 0 A_ChangeFlag("MissileMore", 1)
    SPE2 A 0 A_ChangeFlag("MissileEvenMore", 1)
    Goto AggressiveSee
  AggressiveSee:
    SPE2 A 3 A_Chase("", "AggressiveMissile")
    SPE2 A 0 A_JumpIfHealthLower(50, "See")
    SPE2 A 0 A_Jump(32, 2)
    SPE2 A 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 A 3 A_Chase("", "AggressiveMissile")
    SPE2 A 0 A_JumpIfHealthLower(50, "See")
    SPE2 A 0 A_Jump(32, 2)
    SPE2 A 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 B 3 A_Chase("", "AggressiveMissile")
    SPE2 B 0 A_JumpIfHealthLower(50, "See")
    SPE2 B 0 A_Jump(32, 2)
    SPE2 B 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 B 3 A_Chase("", "AggressiveMissile")
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    SPE2 B 0 A_JumpIfHealthLower(50, "See")
    SPE2 B 0 A_Jump(32, 2)
    SPE2 B 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 C 3 A_Chase("", "AggressiveMissile")
    SPE2 C 0 A_JumpIfHealthLower(50, "See")
    SPE2 C 0 A_Jump(32, 2)
    SPE2 C 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 C 3 A_Chase("", "AggressiveMissile")
    SPE2 C 0 A_JumpIfHealthLower(50, "See")
    SPE2 C 0 A_Jump(32, 2)
    SPE2 C 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 D 3 A_Chase("", "AggressiveMissile")
    SPE2 D 0 A_JumpIfHealthLower(50, "See")
    SPE2 D 0 A_Jump(32, 2)
    SPE2 D 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 D 3 A_Chase("", "AggressiveMissile")
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    SPE2 D 0 A_JumpIfHealthLower(50, "See")
    SPE2 D 0 A_Jump(32, 2)
    SPE2 D 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 A 0
    Loop
  AggressiveMissile:
    SPE2 EEE 4 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    SPE2 F 0 A_Jump(32, "AggressiveSee")
    SPE2 F 0 A_Jump(192, 2)
    SPE2 F 0 A_MonsterRefire(40, "AggressiveSee")
    SPE2 F 0
    Goto AggressiveMissile+3

  //Snipe Mode
  SnipeSwitch:
    SPE2 A 0 A_ChangeFlag("MissileMore", 1)
    SPE2 A 0 A_ChangeFlag("MissileEvenMore", 1)
    Goto SnipeSee
  SnipeSee:
    SPE2 E 0 A_Chase("", "SnipeMissile", 17)
    SPE2 EEEE 2 A_FaceTarget
    SPE2 E 0 A_JumpIfCloser(384, "See")
    SPE2 E 0 A_CheckSight("SnipeIdle")
    Loop
  SnipeIdle:
    SPE2 E 0 A_ClearTarget
    SPE2 E 1 A_LookEx(10, 0, 0, 0, 360, "SnipeSee")
    Goto SnipeIdle+1
  SnipeMissile:
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(128, 2)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(6,4,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    SPE2 E 0 A_Jump(192, "SnipeSee")
    SPE2 E 0 A_MonsterRefire(40, "SnipeSee")
    Loop

  //Wander Mode
  WanderSwitch:
    SPE2 A 0 A_ClearTarget
    Goto WanderSee
  WanderSee:
    SPE2 A 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 A 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 B 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 B 4 A_Wander
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 C 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 C 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 D 4 A_Wander
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    SPE2 D 4 A_Wander
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    SPE2 A 0 A_LookEx(10, 0, 0, 0, 360, "See")
    Loop

  //Creep Mode
  CreepSwitch:
    SPE2 A 0 A_ChangeFlag("MissileMore", 1)
    SPE2 A 0 A_ChangeFlag("AvoidMelee", 1)
    Goto CreepSee
  CreepSee:
    SPE2 A 0 A_CheckSight("CreepCheck")
    SPE2 A 0 A_JumpIfHealthLower(50, "See")
    SPE2 AABB 5 A_Chase("", "CreepMissile", 2)
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
	SPE2 CCDD 5 A_Chase("", "CreepMissile", 2)
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    Loop
  CreepCheck:
    SPE2 A 0 A_Jump(32, "See")
    Goto CreepSee+1
  CreepMissile:
    SPE2 EEE 4 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    SPE2 F 0 A_Jump(32, "CreepSee")
    SPE2 F 0 A_MonsterRefire(40, "CreepSee")
    Goto CreepMissile+3

  //Flee Mode
  FleeSwitch:
    SPE2 A 0 A_ChangeFlag("Frightened", 1)
    Goto FleeSee
  FleeSee:
    SPE2 AABB 3 A_Chase("", "FleeMissile")
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
	SPE2 CCDD 3 A_Chase("", "FleeMissile")
    TNT1 A 0 A_SpawnItem("FootStep",0,0,0,0)
    SPE2 A 0 A_JumpIfCloser(768, 1)
    Goto See
    SPE2 A 0
    Loop
  FleeMissile:
    SPE2 EE 4 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    TNT1 A 0 A_SpawnItemEx("RifleCasing", 12, 6, 30, Random(2, 6), 0, Random(1, 3), Random(-80, -90), 128)
    SPE2 F 0 Bright A_PlayWeaponSound("SpecOpsZombie/Machinegun")
    SPE2 F 2 Bright A_CustomBulletAttack(11,8,1,Random(1,5)*3)
    SPE2 E 2 A_FaceTarget
    Goto FleeSee

  //Misc hurting states
  Pain:
    SPE2 G 4
    SPE2 G 4 A_Pain
    SPE2 G 0 A_Jump(96, "See")
    Goto WhatPainState
  WhatPainState:
    SPE2 G 0 A_JumpIfInventory("ZSpecOpAggressive", 1, "AggressiveSee")
    SPE2 G 0 A_JumpIfInventory("ZSpecOpSnipe", 1, "SnipeSee")
    SPE2 G 0 A_JumpIfInventory("ZSpecOpWander", 1, "WanderSee")
    SPE2 G 0 A_JumpIfInventory("ZSpecOpCreep", 1, "CreepSee")
    SPE2 G 0 A_JumpIfInventory("ZSpecOpFlee", 1, "FleeSee")
    Goto AggressiveSee
  Death:
    SPE2 H 5
    SPE2 I 5 A_Scream
    SPE2 J 5
    SPE2 K 5 A_NoBlocking
    SPE2 L -1
  Raise:
	TNT1 A 0
	TNT1 A 0 A_SpawnItemEx("VileHealEffect",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION)
    SPE2 LKJIH 5
    Goto See
  }
}

Actor ZSpecOpsMSitRep : CustomInventory
{
  Inventory.MaxAmount 0
  +Inventory.AutoActivate
  States
  {
  Spawn:
    TNT1 A 1
    Fail

  Use:
    TNT1 A 0 A_JumpIfHealthLower(50, "LowHealth")
    TNT1 A 0 A_CheckSight("OutOfSight")
    TNT1 A 0 A_JumpIfCloser(384, "Close")
  ChecksFailed:
    TNT1 A 0 A_Jump(256, "AggressiveMode", "SnipeMode")

  LowHealth:
    TNT1 A 0 A_CheckSight("LowHealthOutOfSight")
    TNT1 A 0 A_JumpIfCloser(768, "LowHealthClose")
    TNT1 A 0 A_Jump(256, "SnipeMode")
  LowHealthOutOfSight:
    TNT1 A 0 A_JumpIfCloser(768, "LowHealthOutOfSightClose")
    TNT1 A 0 A_Jump(256, "FleeMode", "SnipeMode")
  LowHealthOutOfSightClose:
    TNT1 A 0 A_Jump(256, "FleeMode")
  LowHealthClose:
    TNT1 A 0 A_Jump(256, "FleeMode")

  OutOfSight:
    TNT1 A 0 A_JumpIfCloser(384, "OutOfSightClose")
    TNT1 A 0 A_Jump(256, "AggressiveMode", "SnipeMode", "WanderMode", "CreepMode")
  OutOfSightClose:
    TNT1 A 0 A_Jump(256, "AggressiveMode", "CreepMode")

  Close:
    TNT1 A 0 A_Jump(256, "AggressiveMode")

  AggressiveMode:
    TNT1 A 0 A_GiveInventory("ZSpecOpAggressive", 1)
    Stop
  SnipeMode:
    TNT1 A 0 A_GiveInventory("ZSpecOpSnipe", 1)
    Stop
  WanderMode:
    TNT1 A 0 A_GiveInventory("ZSpecOpWander", 1)
    Stop
  CreepMode:
    TNT1 A 0 A_GiveInventory("ZSpecOpCreep", 1)
    Stop
  FleeMode:
    TNT1 A 0 A_GiveInventory("ZSpecOpFlee", 1)
    Stop
  }
}

Actor ZSpecOpAggressive : Inventory { Inventory.MaxAmount 1 }
