
state spawn_extra

 espawnvar extra

 ifvare extra 66
  {
   espawn 60
   setactor[RETURN].pal 21
  }
 else
 ifvare extra 67
  {
   espawn 60
   setactor[RETURN].pal 23
  }

ends

state operation
    operateactivators hitag 12
    operatemasterswitches hitag
    operaterespawns hitag
ends

state drop_ammo
  ifrnd SPAWNAMMOODDS
    spawn AMMO
ends

state drop_shotgun
  ifrnd SPAWNAMMOODDS
  {
    spawn SHOTGUNSPRITE
  else
    spawn SHOTGUNAMMOLESS
  }
ends

state jib_sounds
  ifrnd SWEARFREQUENCY
  {
    ifrnd 128
    {
      ifrnd 128
      {
        ifrnd 128
        {
          ifrnd 128
          {
            ifrnd 128
              globalsound JIBBED_ACTOR12
            else
              globalsound JIBBED_ACTOR1
          }
          else
          {
            ifrnd 128
              globalsound JIBBED_ACTOR9
            else
              globalsound JIBBED_ACTOR14
          }
        }
        else
        {
          ifrnd 128
            globalsound SMACKED
          else
            globalsound JIBBED_ACTOR2
        }
      }
      else
      {
        ifrnd 128
          globalsound MDEVSPEECH
        else
          globalsound JIBBED_ACTOR5
      }
    }
    else
    {
      ifrnd 128
      {
        ifrnd 128
        {
          ifrnd 128
            globalsound JIBBED_ACTOR11
          else
            globalsound JIBBED_ACTOR13
        }
        else
        {
          ifrnd 128
            globalsound JIBBED_ACTOR3
          else
            globalsound JIBBED_ACTOR8
        }
      }
      else
      {
        ifrnd 128
        {
          ifrnd 128
            globalsound JIBBED_ACTOR6
          else
            globalsound JIBBED_ACTOR4
        }
        else
        {
          ifrnd 128
          {
            ifrnd 128
              globalsound JIBBED_ACTOR10
            else
              globalsound JIBBED_ACTOR15

          }
          else
            globalsound JIBBED_ACTOR7
        }
      }
    }
  }
ends

action CANULLACTION 0

move CSHUTTLEVELS 16

state liz_body_jibs
  ifrnd 64
    guts LIZMANHEAD1 1
  ifrnd 64
    guts LIZMANLEG1 2
  ifrnd 64
    guts LIZMANARM1 1
  ifrnd 48
    spawn BLOODPOOL
ends

state standard_jibs
  guts JIBS2 1
  guts JIBS3 2
  guts JIBS4 3
  guts JIBS5 2
  guts JIBS6 3
  ifrnd 6
  {
    guts JIBS1 1
    spawn BLOODPOOL
  }         // a badly drawn spine

  state jib_sounds
ends

state rf
  ifrnd 128
    cstat 4
  else
    cstat 0
ends

state random_ooz
  ifrnd 128
    spawn OOZ2
  else
    spawn OOZ
ends
state drop_chaingun
  ifrnd SPAWNAMMOODDS
  {
    ifrnd 32
      spawn CHAINGUNSPRITE
    else
      spawn BATTERYAMMO
  }
ends

state genericgrowcode
  ifcount 32
  {
    guts JIBS4 24
    guts JIBS6 28
    addkills 1
    sound SQUISHED
    sound PIPEBOMB_EXPLODE
    hitradius 2048 60 70 80 90
    spawn BLOODPOOL
    spawn EXPLOSION2
    killit
  }
  else
  {
    ifactor COMMANDER
      sizeto 100 100
    else
      ifactor SHARK
        sizeto 84 84
    else
      sizeto MAXXSTRETCH MAXYSTRETCH
    break
  }
ends

state checksquished
  ifsquished
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    state random_ooz
    killit
  }
ends

state random_wall_jibs
  ifrnd 96
    shoot BLOODSPLAT1
  ifrnd 96
    shoot BLOODSPLAT2
  ifrnd 96
    shoot BLOODSPLAT3
  ifrnd 96
    shoot BLOODSPLAT4
  ifrnd 96
    shoot BLOODSPLAT1
ends

state genericshrunkcode
  ifcount 32
  {
    ifpdistl SQUISHABLEDISTANCE
    pstomp
  }
  else
  {
    sizeto MINXSTRETCH MINYSTRETCH
    spawn FRAMEEFFECT1
  }
ends


eventloadactor BANTI
 cstator 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

action ABANTIWALK        0  4  5  1  12
action ABANTIFROZEN        30 1  5
action ABANTIRUN         0  6  5  1  12
action ABANTISHOOT         30 2  5  1  35
action ABANTILOB         40 2  5  1  35
action ABANTIDYING        49 10  1  1  30
action BANTIFLINTCH       50 1  1  1  1
action ABANTIDEAD         59

move PALBANTISHRUNKRUNVELS 32
move PALBANTIRUNVELS 250
move BANTIWALKVELS 240
move BANTIRUNVELS 240
move BANTISTOPPED
move PSHRUNKVELS 32

ai AIBANTISEEKENEMY ABANTIWALK BANTIWALKVELS seekplayer
ai AIBANTIRUNENEMY ABANTIRUN BANTIRUNVELS faceplayer
ai AIBANTISHOOTENEMY ABANTISHOOT BANTISTOPPED faceplayer
ai AIBANTILOBBED ABANTILOB BANTISTOPPED faceplayer // faceplayersmart
ai AIBANTIDYING ABANTIDYING BANTISTOPPED faceplayer
ai AIBANTIPALSHRINK ABANTIWALK PALBANTISHRUNKRUNVELS furthestdir

state bantipalshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AIBANTISEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkbantiseekstate
  ai AIBANTISEEKENEMY
  ifspritepal 0 nullop
    else   // a fake way of doing a ifspritepal NOT.
      move PALBANTIRUNVELS seekplayer
ends

state bantirunenemystate
  ifpdistl 2048
  {
    ifp palive
      ai AIBANTISHOOTENEMY
    break
  }
  else
    ifcansee
  {
    ifactioncount 6
    {
      ifcanshoottarget
      {
        resetactioncount
      }
      else
        ai AIBANTISEEKENEMY
    }
  }
  else
    ai AIBANTISEEKENEMY
ends

state bantiseekenemystate
  ifrnd 2
    soundonce DEMONROAM
  else
    ifactioncount 6
     {
       ifaction ABANTIWALK
        {
         resetactioncount
         sound BBOSS1_WALK
        }
     }
  ifpdistl 2548
    ifp palive
  {
    ai AIBANTISHOOTENEMY
    break
  }

  ifcansee
    ifcount 32
  {
    ifrnd 32
    {
      ifp palive
        ifcanshoottarget
          ai AIBANTISHOOTENEMY
    }
    else
      ifpdistg 2548
        ifrnd 192
          ifcanshoottarget
    {
      ifrnd 64
      {
        ai AIBANTIRUNENEMY
        ifspritepal 0 nullop
        else
          move PALBANTIRUNVELS seekplayer
      }
      else
        ai AIBANTILOBBED
    }
  }

ends

state bantidyingstate
  ifaction ABANTIDEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERBEAM
      cstat 257
      strength PIGCOPSTRENGTH
      state checkbantiseekstate
    }
    else
    {
      strength 0
    }
  }
  ifactioncount 10
  {
    iffloordistl 8
      sound THUD
    action ABANTIDEAD
    cstat 0
  }
ends

state bantilobbedstate
  ifcansee
  {
    ifactioncount 2
    {
      resetactioncount
      sound RPG_SHOOT
      shoot RPG
    }
    else
      ifcount 64
        ifrnd 16
          state checkbantiseekstate
  }
  else
    state checkbantiseekstate
ends

state bantishootenemy
  ifcount 72
    state checkbantiseekstate
  else
    ifaction ABANTISHOOT
      ifactioncount 2
  {
    sound RPG_SHOOT
    shoot RPG
    resetactioncount
  }
ends

state checkbantihitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
      ifwasweapon FREEZEBLAST
      {
         state standard_jibs
         spawn BLOODPOOL
         sound SQUISHED
         killit
      }

    sound DEMONDTH

    addkills 1
    ai AIBANTIDYING
  }
  else
  {
    ifrnd 32
    {
      action BANTIFLINTCH
      move 0
    }

    ifspritepal 0 nullop

    soundonce DEMONPAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state banticode

  ifai 0
    {
     cstat 257
      ifcansee
        {
           soundonce DEMONRECOG
        }
    }

  ifaction ABANTIFROZEN
  {
    ifcount THAWTIME
    {
      ai AIBANTISEEKENEMY
      spritepal 21
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1
      lotsofglass 30

      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  ifai 0
  {
    ifspritepal 0
      ai AIBANTIRUNENEMY
    else
    {
      strength BBOSS1STRENGTH
      ai AIBANTISHOOTENEMY
    }
  }
  else
    ifaction BANTIFLINTCH
  {
    ifactioncount 3
    ai AIBANTISHOOTENEMY
  }
  else
    ifai AIBANTISEEKENEMY
      state bantiseekenemystate
  else
    ifai AIBANTIRUNENEMY
      state bantirunenemystate
  else
    ifai AIBANTISHOOTENEMY
      state bantishootenemy
  else
    ifai AIBANTILOBBED
      state bantilobbedstate
  else
    ifai AIBANTIPALSHRINK
      state bantipalshrunkstate

  ifai AIBANTIDYING
    state bantidyingstate
  else
  {
    ifhitweapon
      state checkbantihitstate
  }
ends

useractor enemy BANTISTAYPUT BBOSS1STRENGTH cactor BANTI sizeat 80 80 enda
useractor enemy BANTI BBOSS1STRENGTH fall sizeat 80 80 state banticode enda

define WEAKANTI       400

eventloadactor ANTIDUKE
 cstat 257
 setactor[THISACTOR].xrepeat 60
 setactor[THISACTOR].yrepeat 60
enda

action AANTIWALK        0  4  5  1  12
action AANTIFROZEN        30 1  5
action AANTIRUN         0  6  5  1  5
action AANTISHOOT         30 2  5  1  35
action AANTILOB         40 2  5  1  35
action AANTIDYING        50 5  1  1  35
action ANTIFLINTCH       50 1  1  1  1
action AANTIDEAD         55

move PALANTISHRUNKRUNVELS 32
move PALANTIRUNVELS 128
move ANTIWALKVELS 208
move ANTIRUNVELS 296
move ANTISTOPPED

ai AIANTISEEKENEMY AANTIWALK ANTIWALKVELS seekplayer
ai AIANTIRUNENEMY AANTIRUN ANTIRUNVELS faceplayer
ai AIANTISHOOTENEMY AANTISHOOT ANTISTOPPED faceplayer
ai AIANTILOBBED AANTILOB ANTISTOPPED faceplayer // faceplayersmart
ai AIANTIDYING AANTIDYING ANTISTOPPED faceplayer
ai AIANTIPALSHRINK AANTIWALK PALANTISHRUNKRUNVELS furthestdir

state antipalshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AIANTISEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkantiseekstate
  ai AIANTISEEKENEMY
  ifspritepal 0 nullop
    else   // a fake way of doing a ifspritepal NOT.
      move PALANTIRUNVELS seekplayer
ends

state antirunenemystate
  ifpdistl 2048
  {
    ifp palive
      ai AIANTISHOOTENEMY
    break
  }
  else
    ifcansee
  {
    ifactioncount 6
    {
      ifcanshoottarget
      {
        resetactioncount
      }
      else
        ai AIANTISEEKENEMY
    }
  }
  else
    ai AIANTISEEKENEMY
ends

state antiseekenemystate
  ifrnd 2
    soundonce ANTIROAM
  else
    ifactioncount 6
  {
    resetactioncount
  }

  ifpdistl 2548
    ifp palive
  {
    ai AIANTISHOOTENEMY
    break
  }

  ifcansee
    ifcount 32
  {
    ifrnd 32
    {
      ifp palive
        ifcanshoottarget
          ai AIANTISHOOTENEMY
    }
    else
      ifpdistg 2548
        ifrnd 192
          ifcanshoottarget
    {
      ifrnd 64
      {
        ai AIANTIRUNENEMY
        ifspritepal 0 nullop
        else
          move PALANTIRUNVELS seekplayer
      }
      else
        ai AIANTILOBBED
    }
  }

ends

state antidyingstate
  ifaction AANTIDEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength PIGCOPSTRENGTH
      state checkantiseekstate
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  ifactioncount 5
  {
    iffloordistl 8
      sound THUD
    action AANTIDEAD
    cstat 0
  }
ends

state antilobbedstate
  ifcansee
  {
    ifactioncount 2
    {
      resetactioncount
      sound SHRINKER_FIRE
      shoot SHRINKER
    }
    else
      ifcount 64
        ifrnd 16
          state checkantiseekstate
  }
  else
    state checkantiseekstate
ends

state antishootenemy
  ifcount 72
    state checkantiseekstate
  else
    ifaction AANTISHOOT
      ifactioncount 2
  {
    sound BOS1_ATTACK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    shoot SHOTSPARK1
    resetactioncount
  }
ends

state checkantihitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
      ifwasweapon FREEZEBLAST
      {
        sound SQUISHED
        state standard_jibs
        killit
      }

    sound ANTIDIE

    addkills 1
    ai AIANTIDYING
  }
  else
  {
    ifrnd 32
    {
      action ANTIFLINTCH
      move 0
    }


    soundonce ANTIPAIN

    debris SCRAP1 1
    guts JIBS6 1
  }
ends

state anticode

  ifai 0
    {
     cstat 257
       ifcansee
         {
            soundonce ANTIROAM 
         }
    }

  ifaction AANTIFROZEN
  {
    ifcount THAWTIME
    {
      ai AIANTISEEKENEMY
      spritepal 21
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1
      lotsofglass 30

      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  ifai 0
  {
    ifspritepal 0
      ai AIANTIRUNENEMY
    else
    {
      ifspritepal 3
      strength WEAKANTI
      ai AIANTISHOOTENEMY
    }
  }
  else
    ifaction ANTIFLINTCH
  {
    ifactioncount 3
    ai AIANTISHOOTENEMY
  }
  else
    ifai AIANTISEEKENEMY
      state antiseekenemystate
  else
    ifai AIANTIRUNENEMY
      state antirunenemystate
  else
    ifai AIANTISHOOTENEMY
      state antishootenemy
  else
    ifai AIANTILOBBED
      state antilobbedstate
  else
    ifai AIANTIPALSHRINK
      state antipalshrunkstate

  ifai AIANTIDYING
    state antidyingstate
  else
  {
    ifhitweapon
      state checkantihitstate
  }
ends

useractor enemy ANTISTAYPUT ANTIDUKESTRENGTH cactor ANTIDUKE enda
useractor enemy ANTIDUKE ANTIDUKESTRENGTH fall sizeat 60 60 state anticode enda


define KNIGHTSTRENGTH -300

state checknnpal
  ifai 0
  {
    ifspritepal 0
        nullop
    else
        ifspritepal 24
          addstrength KNIGHTSTRENGTH
  }
ends

define NNEWWBEAST 5658
define NNEWWBEASTSTAYPUT 5659
define NNEWWBEASTHANG 5663
define NNEWWBEASTSTRENGTH 200
define NNEWWBEASTSTRENGTHTOUGHER 300
define NNEWWBEASTHANGDEAD 5663
define NNEWWBEASTSCRATCHAMOUNT -18
define NNEWWBEASTJUMP 5122

eventloadactor NNEWWBEAST

 ifspritepal 4
 {
 cstat 259
 }
 else
 ifspritepal 0
 {
 cstat 257
 }

 setactor[THISACTOR].xrepeat 58
 setactor[THISACTOR].yrepeat 58

enda

action ANNEWWBEASTSTAND     0
action ANNEWWBEASTWALKING   0  4  5  1  12
action ANNEWWBEASTRUNNING   0  4  5  1  8
action ANNEWWBEASTTHINK     0   2  5  1  5
action ANNEWWBEASTSCRATCHING  20  3  5  1  20
action ANNEWWBEASTDYING     40  5  1  1  15
action ANNEWWBEASTFLINTCH   25  1  1  1  1
action ANNEWWBEASTLYINGDEAD 45  1  1
action ANNEWWBEASTSCREAM    20  2  5  1  40
action ANNEWWBEASTJUMP      5  1  5  1  50
action ANNEWWBEASTFALL      10  1  5
action ANNEWWBEASTFROZEN    10  1  5
action ANNEWWBEASTHANG      0  1  5

useractor enemy NNEWWBEASTHANG NNEWWBEASTSTRENGTH
  ifaction 0
  {
    action ANNEWWBEASTHANG
    cstator 257

    sizeat 60 60
  }
  else
    ifhitweapon
  {
    cactor NNEWWBEAST
    action ANNEWWBEASTSTAND
    sound BULLPAIN
  }
  else
    ifspawnedby BOSS4
      ifcount 200
        ifrnd 1
  {
    cactor NNEWWBEAST
    action ANNEWWBEASTSTAND
    sound BULLPAIN
  }
enda

action ANNEWWBEASTHANGDEAD      -1  1  5
useractor enemy NNEWWBEASTHANGDEAD TOUGH

  ifaction 0
  {
    action ANNEWWBEASTHANGDEAD
    sizeat 40 40
    cstator 257
  }
  else
    ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
    else
    {
      guts JIBS6 1
      sound SQUISHED
    }
  }
enda

move NNEWWBEASTWALKVEL 150
move NNEWWBEASTRUNVEL 180
move NNEWWBEASTJUMPVEL 264
move NNEWWBEASTSTOP

ai AINNEWWBEASTGETENEMY ANNEWWBEASTWALKING NNEWWBEASTWALKVEL seekplayer
ai AINNEWWBEASTDODGE ANNEWWBEASTRUNNING NNEWWBEASTRUNVEL dodgebullet
ai AINNEWWBEASTCHARGEENEMY ANNEWWBEASTRUNNING NNEWWBEASTRUNVEL seekplayer
ai AINNEWWBEASTFLEENEMY ANNEWWBEASTWALKING NNEWWBEASTWALKVEL fleeenemy
ai AINNEWWBEASTSCRATCHENEMY ANNEWWBEASTSCRATCHING NNEWWBEASTSTOP faceplayerslow
ai AINNEWWBEASTJUMPENEMY ANNEWWBEASTJUMP NNEWWBEASTJUMPVEL jumptoplayer
ai AINNEWWBEASTTHINK ANNEWWBEASTTHINK NNEWWBEASTSTOP
// ai AINNEWWBEASTSHRUNK ANNEWWBEASTWALKING SHRUNKVELS fleeenemy
ai AINNEWWBEASTGROW ANNEWWBEASTSTAND  NNEWWBEASTSTOP faceplayerslow
ai AINNEWWBEASTDYING ANNEWWBEASTDYING NNEWWBEASTSTOP faceplayer
ai AINNEWWBEASTSHOOT ANNEWWBEASTSCREAM NNEWWBEASTSTOP faceplayerslow
ai AINNEWWBEASTFLINTCH ANNEWWBEASTFLINTCH NNEWWBEASTSTOP faceplayerslow


state nnewwbeastseekstate

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
    {
      ai AINNEWWBEASTSCRATCHENEMY
      break
    }

    ifai AINNEWWBEASTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWWBEASTSCRATCHENEMY
        break
      }

      ifrnd 1
        ifpdistg 4096
          ifp palive
            ifcansee
      {
        ai AINNEWWBEASTCHARGEENEMY
        break
      }
    }
    else
      ifpdistg 4096
    {
      ai AINNEWWBEASTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96 break
        ai AINNEWWBEASTCHARGEENEMY
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINNEWWBEASTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
          ai AINNEWWBEASTCHARGEENEMY
        }
        else
          ai AINNEWWBEASTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWWBEASTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NNEWWBEASTWALKVEL randomangle geth
  }

ends



state nnewwbeastfleestate
  ifcount 8
  {
    ifrnd 64
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWWBEASTCHARGEENEMY
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINNEWWBEASTGETENEMY
    }
    else
      ai AINNEWWBEASTGETENEMY
    break
  }
ends

state nnewwbeastthinkstate

  ifrnd 8
    soundonce DEMONROAM

  ifactioncount 3
  {
    ifrnd 128
    {
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWWBEASTCHARGEENEMY
    }
    else
      ai AINNEWWBEASTGETENEMY
  }

  ifrnd 16
    ifbulletnear
  {
    ifgapzl 96
      ai AINNEWWBEASTDODGE
    else
    {
      ifrnd 128
      {
        ifceilingdistl 144 break
        ai AINNEWWBEASTCHARGEENEMY
      }
      else
        ai AINNEWWBEASTDODGE
    }
  }
ends

state nnewwbeastscratchstate
  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AINNEWWBEASTFLEENEMY
      break
    }
    ifrnd 80
      ai AINNEWWBEASTTHINK
    else
      ai AINNEWWBEASTGETENEMY
  }

  ifactioncount 3
  {
    ifpdistg 1596
      ai AINNEWWBEASTTHINK
    else ifp palive ifcansee
    {
      palfrom 16 16
      addphealth NNEWWBEASTSCRATCHAMOUNT
      sound DUKE_GRUNT
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifpdistl 1596
      soundonce BULLATK
    else
      soundonce BULLATK
  }
ends

state checknnewwbeasthit
  spawn BLOOD
   
/*
  ifai AINNEWWBEASTSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
/*
    ifwasweapon GROWSPARK
    {
      spritepal 2
      cstat 0
      sound ACTOR_GROWING
      ai AINNEWWBEASTGROW
      break
    }
*/
    addkills 1

    ifwasweapon RPG
    {
      spawn BURNING
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AINNEWWBEASTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound BULLDYING
  }
  else
  {
    sound DEMONPAIN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
    ifwasweapon SHRINKSPARK   
    {
      spawn SHRINKEREXPLOSION
      quote 127
      sound SQUISHED
      state standard_jibs
      killit
    }
*/
    state random_wall_jibs
    ifrnd 32
      ai AINNEWWBEASTFLINTCH
    else
      ifrnd 32
        ifpdistg 3500
          ifp palive
            ifcansee
              ai AINNEWWBEASTCHARGEENEMY
  }
ends

state nnewwbeastjumpstate
  ifaction ANNEWWBEASTFALL
  {
    iffloordistl 16
      ai AINNEWWBEASTGETENEMY
  }
  else
    ifcount 32
      action ANNEWWBEASTFALL
ends

state nnewwbeastdyingstate
  ifaction ANNEWWBEASTLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength NNEWWBEASTSTRENGTH
      ai AINNEWWBEASTGETENEMY
    }
  }
  else
    ifai AINNEWWBEASTDYING
      ifactioncount 5
  {
    iffloordistl 8
      sound THUD
    move NNEWWBEASTSTOP
    action ANNEWWBEASTLYINGDEAD
  }
ends

state nnewwbeastdodgestate
  ifcount 13
    ai AINNEWWBEASTGETENEMY
ends

useractor enemystayput NNEWWBEASTSTAYPUT NNEWWBEASTSTRENGTH ai AINNEWWBEASTGETENEMY cactor NNEWWBEAST enda
useractor enemy NNEWWBEASTJUMP NNEWWBEASTSTRENGTH ai AINNEWWBEASTJUMPENEMY cactor NNEWWBEAST enda

state nnewwbeastcode

  ifai 0
   {
    ifspritepal 4
    cstat 259
    else
    cstat 257

     sizeat 58 58
     ifcansee
       {
          soundonce BULLPAIN
       }
   }

  state checksquished
  ifai 0
  {
    ai AINNEWWBEASTGETENEMY
  }
  else
    ifaction ANNEWWBEASTLYINGDEAD
  {
    fall
    state nnewwbeastdyingstate
    break
  }  
  else
    ifai AINNEWWBEASTJUMPENEMY
      state nnewwbeastjumpstate
  else
  {
    fall
    ifai AINNEWWBEASTGETENEMY
      state nnewwbeastseekstate
    else
      ifai AINNEWWBEASTCHARGEENEMY
        state nnewwbeastseekstate
    else
      ifai AINNEWWBEASTFLINTCH
    {
      ifcount 8
        ai AINNEWWBEASTGETENEMY
    }

    else
      ifai AINNEWWBEASTDODGE
        state nnewwbeastdodgestate
    else
      ifai AINNEWWBEASTSCRATCHENEMY
        state nnewwbeastscratchstate
    else
      ifai AINNEWWBEASTFLEENEMY
        state nnewwbeastfleestate
    else
      ifai AINNEWWBEASTTHINK
        state nnewwbeastthinkstate
/*
    else
      ifai AINNEWWBEASTSHRUNK
        state nnewwbeastshrunkstate
*/
    else
      ifai AINNEWWBEASTGROW
        state genericgrowcode
    else
      ifai AINNEWWBEASTDYING
        state nnewwbeastdyingstate
    else
      ifai AINNEWWBEASTCHARGEENEMY
    {
      ifp pshrunk
        ai AINNEWWBEASTGETENEMY
      else
        ifcount 26
          ai AINNEWWBEASTGETENEMY
      else
        ifcount 25
          shoot KNEE
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
            sound BULLATK
      }
    }
  }

  ifhitweapon
    state checknnewwbeasthit
ends


useractor enemy NNEWWBEAST NNEWWBEASTSTRENGTH
   fall
   state nnewwbeastcode
enda

eventloadactor NNEWBEAST
 cstat 257
 setactor[THISACTOR].xrepeat 70
 setactor[THISACTOR].yrepeat 70
enda

action ANNEWBEASTSTAND     0
action ANNEWBEASTWALKING   10  4  5  1  12
action ANNEWBEASTRUNNING   10  4  5  1  8
action ANNEWBEASTSCRATCHING  30  3  5  1  20
action ANNEWBEASTDYING     72  8  1  1  15
action ANNEWBEASTFLINTCH   71  1  1  1  1
action ANNEWBEASTLYINGDEAD 79  1  1
action ANNEWBEASTSCREAM    50  2  5  1  40
action ANNEWBEASTFALL      90  1  5
action ANNEWBEASTFROZEN    10  1  5
action ANNEWBEASTTHINK     0   2  5  1  5
action ANNEWBEASTHANG      0  1  5

useractor enemy NNEWBEASTHANG NNEWBEASTSTRENGTH
  ifaction 0
  {
    action ANNEWBEASTHANG
    cstator 257

  }
  else
    ifhitweapon
  {
    cactor NNEWBEAST
    action ANNEWBEASTSTAND
    sound ANGPAIN
  }
  else
    ifspawnedby BOSS4
      ifcount 200
        ifrnd 1
  {
    cactor NNEWBEAST
    action ANNEWBEASTSTAND
    sound DEMONPAIN
  }
enda

action ANNEWBEASTHANGDEAD      -1  1  5
useractor enemy NNEWBEASTHANGDEAD TOUGH

  ifaction 0
  {
    action ANNEWBEASTHANGDEAD
    cstator 257
  }
  else
    ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
    else
    {
      guts JIBS6 1
      sound SQUISHED
    }
  }
enda

move NNEWBEASTWALKVEL 160
move NNEWBEASTRUNVEL 160
move NNEWBEASTSTOP

ai AINNEWBEASTGETENEMY ANNEWBEASTWALKING NNEWBEASTWALKVEL seekplayer
ai AINNEWBEASTDODGE ANNEWBEASTRUNNING NNEWBEASTRUNVEL dodgebullet
ai AINNEWBEASTCHARGEENEMY ANNEWBEASTRUNNING NNEWBEASTRUNVEL seekplayer
ai AINNEWBEASTFLEENEMY ANNEWBEASTWALKING NNEWBEASTWALKVEL fleeenemy
ai AINNEWBEASTSCRATCHENEMY ANNEWBEASTSCRATCHING NNEWBEASTSTOP faceplayerslow
// ai AINEWBEASTSHRUNK ANNEWBEASTWALKING PSHRUNKVELS fleeenemy
ai AINNEWBEASTGROW ANNEWBEASTSTAND  NNEWBEASTSTOP faceplayerslow
ai AINNEWBEASTDYING ANNEWBEASTDYING NNEWBEASTSTOP faceplayer
ai AINNEWBEASTSHOOT ANNEWBEASTSCREAM NNEWBEASTSTOP faceplayerslow
ai AINNEWBEASTFLINTCH ANNEWBEASTFLINTCH NNEWBEASTSTOP faceplayerslow
ai AINNEWBEASTTHINK ANNEWBEASTTHINK NNEWBEASTSTOP


state nnewbeastseekstate

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
    {
      ai AINNEWBEASTSCRATCHENEMY
      break
    }

    ifai AINNEWBEASTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWBEASTSCRATCHENEMY
        break
      }

      ifrnd 1
        ifpdistg 4096
          ifp palive
            ifcansee
      {
        ai AINNEWBEASTSHOOT
        break
      }
    }
    else
      ifpdistg 4096
    {
      ai AINNEWBEASTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINNEWBEASTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
        }
        else
          ai AINNEWBEASTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWBEASTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NNEWBEASTWALKVEL randomangle geth
  }

ends

/*
state nnewbeastshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AINEWBEASTGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends
*/

state nnewbeastfleestate
  ifcount 8
  {
    ifrnd 64
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWBEASTSHOOT
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINNEWBEASTGETENEMY
    }
    else
      ai AINNEWBEASTGETENEMY
    break
  }
ends

state nnewbeastscratchstate
  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AINNEWBEASTFLEENEMY
      break
    }
    ifrnd 80
      ai AINNEWBEASTTHINK
    else
      ai AINNEWBEASTGETENEMY
  }

  ifactioncount 3
  {
     ifpdistg 1596
       ai AINNEWBEASTTHINK
    else  ifp palive ifcansee
    {
      palfrom 16 16
      addphealth NNEWBEASTSCRATCHAMOUNT
      sound DUKE_GRUNT
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifpdistl 1596
      soundonce CLAW
    else
      soundonce CLAW
  }
ends

state checknnewbeasthit
  spawn BLOOD
/*
  ifai AINNEWBEASTSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SQUISHED
      state standard_jibs
      killit
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AINNEWBEASTGROW
      break
    }

    addkills 1

    ifwasweapon RPG
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state liz_body_jibs
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AINNEWBEASTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound PPIG_DYING
  }
  else
  {
    sound ANGPAIN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AINNEWBEASTSHRUNK
      break
    }
*/
    state random_wall_jibs
    ifrnd 32
      ai AINNEWBEASTFLINTCH
    else
      ifrnd 32
        ifpdistg 3500
          ifp palive
            ifcansee
              ai AINNEWBEASTSHOOT
  }
ends

state nnewbeastthinkstate

  ifrnd 8
    soundonce DEMONROAM2

  ifactioncount 3
  {
    ifrnd 128
    {
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWBEASTSHOOT
    }
    else
      ai AINNEWBEASTGETENEMY
  }

  ifrnd 16
    ifbulletnear
  {
    ifgapzl 96
      ai AINNEWBEASTDODGE
    else
    {
      ifrnd 128
      {
        ifceilingdistl 144 break
      }
      else
        ai AINNEWBEASTDODGE
    }
  }
ends


state nnewbeastdyingstate
  ifaction ANNEWBEASTLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength NNEWBEASTSTRENGTH
      ai AINNEWBEASTGETENEMY
    }
  }
  else
    ifai AINNEWBEASTDYING
      ifactioncount 7
  {
    iffloordistl 8
      sound THUD
    move NNEWBEASTSTOP
    action ANNEWBEASTLYINGDEAD
  }
ends

state nnewbeastdodgestate
  ifcount 13
    ai AINNEWBEASTGETENEMY
ends

useractor enemystayput NNEWBEASTSTAYPUT NNEWBEASTSTRENGTH ai AINNEWBEASTGETENEMY cstator 257 cactor NNEWBEAST enda

state nnewbeastcode

  ifai 0
   {
    cstat 257
     ifcansee
       {
         soundonce BARONSEE
       }
   }

  state checksquished
  ifai 0
  {
    cstator 257
    ai AINNEWBEASTGETENEMY
  }
  else
    ifaction ANNEWBEASTLYINGDEAD
  {
    fall
    state nnewbeastdyingstate
    break
  }
  else
    ifaction ANNEWBEASTFROZEN
  {
    ifcount THAWTIME
    {
      ai AINNEWBEASTGETENEMY
      spritepal 0
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
  {
    fall
    ifai AINNEWBEASTGETENEMY
      state nnewbeastseekstate
    else
      ifai AINNEWBEASTCHARGEENEMY
        state nnewbeastseekstate
    else
      ifai AINNEWBEASTFLINTCH
    {
      ifcount 8
        ai AINNEWBEASTGETENEMY
    }

    else
      ifai AINNEWBEASTDODGE
        state nnewbeastdodgestate
    else
      ifai AINNEWBEASTSCRATCHENEMY
        state nnewbeastscratchstate
    else
      ifai AINNEWBEASTFLEENEMY
        state nnewbeastfleestate
    else
      ifai AINNEWBEASTTHINK
        state nnewbeastthinkstate
/*
    else
      ifai AINNEWBEASTSHRUNK
        state nnewbeastshrunkstate
*/
    else
      ifai AINNEWBEASTGROW
        state genericgrowcode
    else
      ifai AINNEWBEASTDYING
        state nnewbeastdyingstate
    else
      ifai AINNEWBEASTSHOOT
    {
      ifp pshrunk
        ai AINNEWBEASTGETENEMY
      else      ifcount 26
          ai AINNEWBEASTGETENEMY
      else
        ifcount 25
          shoot METEOR
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
            sound PRED_ATTACK
      }
    }
  }

  ifhitweapon
    state checknnewbeasthit
ends



useractor enemy NNEWBEAST NNEWBEASTSTRENGTH state checknnpal fall sizeat 70 70 state nnewbeastcode enda


define FBALL2 5312

move FBALLSPEED2 750 100
move FBALL2UP 0 -2500

action FBALL12 0 1 1 1 1

ai AIFBALL2 FBALL12 FBALLSPEED2 geth getv
ai AIFBALL2UP FBALL12 FBALL2UP geth getv

useractor notenemy FBALL2 0 FBALL12
state checksquished

ifai NO { sizeat 1 1 cstat 32768 clipdist 0 ai AIFBALL2UP }
ifai AIFBALL2UP { ifcount 1 { ai AIFBALL2 cstat 257 clipdist 32 sizeat 40 40 } else break }

ifai AIFBALL2
  {
  ifpdistl 1024
    {
    addphealth -3
    sound DUKE_GRUNT
    wackplayer
    palfrom 15 100
    killit
    }
  iffloordistl 10
    {
    killit
    }
  }

ifcount 30 killit

enda

move FBALLSPEED3 750 100
move FBALL3UP 0 -2500

action FBALL13 0 1 1 1 1

ai AIFBALL3 FBALL13 FBALLSPEED3 geth getv
ai AIFBALL3UP FBALL13 FBALL3UP geth getv

useractor notenemy FBALL3 0 FBALL13
state checksquished

ifai NO { sizeat 1 1 cstat 32768 clipdist 0 ai AIFBALL3UP }
ifai AIFBALL3UP { ifcount 1 { ai AIFBALL3 cstat 257 clipdist 32 sizeat 40 40 } else break }

ifai AIFBALL3
  {
  ifpdistl 1024
    {
    addphealth -10
    sound DUKE_GRUNT
    wackplayer
    palfrom 15 100
    killit
    }
  iffloordistl 10
    {
    killit
    }
  }

ifcount 30 killit

enda

eventloadactor PIIGCOP
 cstat 257
 setactor[THISACTOR].xrepeat 70
 setactor[THISACTOR].yrepeat 70
enda

action APIIGWALK     0  4 5 1 20
action APIIGRUN      0  4 5 1 11
action APIIGSHOOT    30 2 5 1 58
action APIIGCOCK     25 1 5 1 16
action APIIGSTAND    30 1 5 1 1
action APIIGDIVE     40 2 5 1 40
action APIIGDIVESHOOT  45 2 5 1 58
action APIIGDYING    55 5 1 1 15
action APIIGHIT      55 1 1 1 10
action APIIGDEAD     60 1 1 1 1
action APIIGFROZEN    0 1 5
action APIIGGROW      0


move PIIGWALKVELS 64
move PIIGRUNVELS 94
move PIIGSTOPPED

ai AIPIIGSEEKENEMY APIIGWALK PIIGWALKVELS seekplayer
ai AIPIIGSHOOTENEMY APIIGSHOOT PIIGSTOPPED faceplayer
ai AIPIIGFLEEENEMY APIIGWALK PIIGWALKVELS fleeenemy
ai AIPIIGSHOOT APIIGSHOOT PIIGSTOPPED faceplayer
ai AIPIIGDODGE APIIGRUN PIIGRUNVELS dodgebullet
ai AIPIIGCHARGE APIIGRUN PIIGRUNVELS seekplayer
ai AIPIIGDIVING APIIGDIVE PIIGSTOPPED faceplayer
ai AIPIIGDYING APIIGDYING PIIGSTOPPED faceplayer
ai AIPIIGGROW APIIGGROW PIIGSTOPPED faceplayerslow
ai AIPIIGHIT APIIGHIT PIIGSTOPPED faceplayer

state checkpiigpal
  ifai 0
  {
    ifspritepal 0
      nullop
    else
      ifspritepal 22
        addstrength PIIGCOPSTRENGTH
    else
      ifspritepal 21
        addstrength ULTIMATEDRONESTR
    else
      ifspritepal 24
        addstrength NEWBEASTSTRENGTH
   }
ends

state piigseekenemystate

  ifai AIPIIGCHARGE
  {
    ifcansee
      ifpdistl 3084
    {
      ifnotmoving
        ai AIPIIGSEEKENEMY
      else
        ai AIPIIGDIVING
    }
    break
  }
  else iffloordistl 32
  {
    ifpdistg 4096
    {
      ifactornotstayput
      ai AIPIIGCHARGE
    }
    ifrnd 8
    {
      ifbulletnear
        ai AIPIIGDODGE
    }
  }

  ifrnd 128
    ifcansee
  {
    ifai AIPIIGDODGE
    {
      ifcount 32
        ai AIPIIGCHARGE
          break
    }
    iffloordistl 32
    {
      ifpdistl 1024
        ifp palive
          ifcanshoottarget
      {
        ai AIPIIGSHOOTENEMY
        break
      }
      ifcount 48
      {
        ifrnd 8
          ifp palive
            ifcanshoottarget
        {
          ifrnd 192
            ai AIPIIGSHOOTENEMY
          else
            ai AIPIIGDIVING
          break
        }
      }
    }
  }
ends

state piigshootenemystate
//  ifcansee
  {
    ifcount 12 nullop
    else
      ifcount 11
    {
      ifcanshoottarget { ifspritepal 22 { sound RPG_SHOOT shoot BROWNMETEOR } else
      {
        sound ZAT
        shoot BROWNMETEOR
        shoot RPG
        shoot RPG
      } }
      else
        ai AIPIIGSEEKENEMY
    }
    ifcount 25 nullop
    else
      ifcount 24
      {
        action APIIGCOCK
      }
    ifcount 48 nullop
    else
      ifcount 47
    {
      ifcanshoottarget { ifspritepal 22 { sound RPG_SHOOT shoot BROWNMETEOR } else
      {
        sound ZAT
        shoot BROWNMETEOR
      } }
      else
        ai AIPIIGSEEKENEMY
    }
    ifcount 60 nullop
    else
      ifcount 59
      {
        action APIIGCOCK
      }
    ifcount 72
    {
      ifrnd 64
        resetcount
      else
      {
        ifpdistl 768
          ai AIPIIGFLEEENEMY
        else
          ai AIPIIGSEEKENEMY
      }
    }
    ifaction APIIGCOCK
      ifactioncount 2
        action APIIGSHOOT
  }
  else
    ai AIPIIGSEEKENEMY
ends

state piigfleeenemystate
  ifactioncount 8
    ai AIPIIGSEEKENEMY
  else
    ifnotmoving
      ai AIPIIGSEEKENEMY
ends

state piigdivestate
  ifaction APIIGDIVESHOOT
  {
    ifcansee
    {
      ifcount 12 nullop
      else
        ifcount 11
      {
        ifcanshoottarget { ifspritepal 22 { sound RPG_SHOOT shoot RPG } else
        {
          sound ZALT
          shoot REDPROJ
        } }
        else
          ai AIPIIGSEEKENEMY
      }
      ifcount 25 nullop
      else
        ifcount 24
      ifcount 48 nullop
      else
        ifcount 47
      {
        ifcanshoottarget { ifspritepal 22 { sound RPG_SHOOT shoot BROWNMETEOR } else       
        {
          sound ZALT
          shoot REDPROJ
        } }
        else
          ai AIPIIGSEEKENEMY
      }
      ifcount 60 nullop
      else
        ifcount 59
      {
        ifgapzl 32
          ai AIPIIGDIVING
        else
        {
          ifpdistl 4096
            ai AIPIIGFLEEENEMY
          else
            ai AIPIIGSEEKENEMY
        }
      }
    }
    else
      ifgapzl 32
        ai AIPIIGDIVING
      else
        ai AIPIIGSEEKENEMY
  }
  else
    ifactioncount 2
    ifp palive
    {
      resetcount
      action APIIGDIVESHOOT
    }
ends


state checkpiighitstate
  spawn BLOOD
  ifdead
  {
    state random_wall_jibs

    ifwasweapon GROWSPARK
    {
      sound SQUISHED
      state standard_jibs
      killit
    }

    addkills 1

    ifwasweapon FREEZEBLAST
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RPG
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ai AIPIIGDYING
        sound ZDY
  }
  else
  {
    sound DEMONPAIN
    state random_wall_jibs

      ifwasweapon GROWSPARK
        sound EXPANDERHIT
    else
      ifrnd 32
        ai AIPIIGHIT
    else
      ifrnd 64
        ai AIPIIGSHOOTENEMY
    else
      ifrnd 64
      {
        ai AIPIIGDIVING
        action APIIGDIVESHOOT
      }
  }
ends

state piigdyingstate
  ifactioncount 5
  {
    ifrnd 64
      spawn BLOODPOOL
    state rf
    iffloordistl 8
      sound THUD
    action APIIGDEAD
    move PIIGSTOPPED
    break
  }
ends


useractor enemy PIIGCOPDIVE PIIGCOPSTRENGTH
  ai AIPIIGDIVING
  action APIIGDIVESHOOT
  cactor PIIGCOP
enda
useractor enemy PIIGCOPSTAYPUT PIIGCOPSTRENGTH
  ai AIPIIGSEEKENEMY
  cactor PIIGCOP
enda
useractor enemy PIIGCOP PIIGCOPSTRENGTH APIIGSTAND
  fall
  sizeat 70 70

  ifai 0
   {
    cstat 257
     ifcansee
       {
          soundonce ZRG
       }
   }

  state checkpiigpal
  state checksquished
  ifaction APIIGSTAND
    ai AIPIIGSEEKENEMY
  else
    ifaction APIIGDEAD
  {
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength PIGCOPSTRENGTH
      ai AIPIIGSEEKENEMY
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  else
    ifaction APIIGFROZEN
  {
    ifcount THAWTIME
    {
      ai AIPIIGSEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
        ifrnd 8
          spawn WATERDRIP

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1

      lotsofglass 30
      ifrnd 84 spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
    ifai AIPIIGDYING
      state piigdyingstate
  else
    ifai AIPIIGHIT
    {
      ifactioncount 3
      ai AIPIIGSEEKENEMY
    }
  else
  {
    ifai AIPIIGSEEKENEMY
      state piigseekenemystate
    else
      ifai AIPIIGDODGE
        state piigseekenemystate
    else
      ifai AIPIIGSHOOTENEMY
        state piigshootenemystate
    else
      ifai AIPIIGGROW
        state genericgrowcode
    else
      ifai AIPIIGFLEEENEMY
        state piigfleeenemystate
    else
      ifai AIPIIGDIVING
        state piigdivestate
    else
      ifai AIPIIGCHARGE
        state piigseekenemystate
    ifhitweapon
      state checkpiighitstate
    ifrnd 1
    {
        soundonce DEMONROAM
    }
  }
enda

eventloadactor NEEWBEAST
 cstat 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

action ANEEWBEASTSTAND     0
action ANEEWBEASTWALKING   10  4  5  1  12
action ANEEWBEASTRUNNING   10  4  5  1  8
action ANEEWBEASTTHINK     0   2  5  1  5
action ANEEWBEASTSCRATCHING  30  3  5  1  20
action ANEEWBEASTDYING     72  8  1  1  15
action ANEEWBEASTFLINTCH   71  1  1  1  1
action ANEEWBEASTLYINGDEAD 79  1  1
action ANEEWBEASTSCREAM    50  2  5  1  40
action ANEEWBEASTJUMP      80  2  5  1  50
action ANEEWBEASTFALL      90  1  5
action ANEEWBEASTFROZEN    10  1  5

action ANEEWBEASTHANG      0  1  5
useractor enemy NEEWBEASTHANG NEEWBEASTSTRENGTH
  ifaction 0
  {
    action ANEEWBEASTHANG
    cstator 257

    sizeat 40 40
  }
  else
    ifhitweapon
  {
    cactor NEEWBEAST
    action ANEEWBEASTSTAND
    sound MINPN
  }
  else
    ifspawnedby BOSS4
      ifcount 200
        ifrnd 1
  {
    cactor NEEWBEAST
    action ANEEWBEASTSTAND
    sound MINPN
  }
enda

action ANEEWBEASTHANGDEAD      -1  1  5
useractor enemy NEEWBEASTHANGDEAD TOUGH

  ifaction 0
  {
    action ANEEWBEASTHANGDEAD
    sizeat 40 40
    cstator 257
  }
  else
    ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
    else
    {
      guts JIBS6 1
      sound SQUISHED
    }
  }
enda

move NEEWBEASTWALKVEL 130
move NEEWBEASTRUNVEL 180
move NEEWBEASTJUMPVEL 300
move NEEWBEASTSTOP

ai AINEEWBEASTGETENEMY ANEEWBEASTWALKING NEEWBEASTWALKVEL seekplayer
ai AINEEWBEASTDODGE ANEEWBEASTRUNNING NEEWBEASTRUNVEL dodgebullet
ai AINEEWBEASTCHARGEENEMY ANEEWBEASTRUNNING NEEWBEASTRUNVEL seekplayer
ai AINEEWBEASTFLEENEMY ANEEWBEASTWALKING NEEWBEASTWALKVEL fleeenemy
ai AINEEWBEASTSCRATCHENEMY ANEEWBEASTSCRATCHING NEEWBEASTSTOP faceplayerslow
ai AINEEWBEASTJUMPENEMY ANEEWBEASTJUMP NEEWBEASTJUMPVEL jumptoplayer
ai AINEEWBEASTTHINK ANEEWBEASTTHINK NEEWBEASTSTOP
// ai AINEEWBEASTSHRUNK ANEEWBEASTWALKING PSHRUNKVELS fleeenemy
ai AINEEWBEASTGROW ANEEWBEASTSTAND  NEEWBEASTSTOP faceplayerslow
ai AINEEWBEASTDYING ANEEWBEASTDYING NEEWBEASTSTOP faceplayer
ai AINEEWBEASTSHOOT ANEEWBEASTSCREAM NEEWBEASTSTOP faceplayerslow
ai AINEEWBEASTFLINTCH ANEEWBEASTFLINTCH NEEWBEASTSTOP faceplayerslow


state neewbeastseekstate

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
    {
      ai AINEEWBEASTSCRATCHENEMY
      break
    }

    ifai AINEEWBEASTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINEEWBEASTSCRATCHENEMY
        break
      }

      ifrnd 1
        ifpdistg 4096
          ifp palive
            ifcansee
      {
        ai AINEEWBEASTSHOOT
        break
      }
    }
    else
      ifpdistg 4096
    {
      ai AINEEWBEASTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96 break
        ai AINEEWBEASTJUMPENEMY
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINEEWBEASTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
          ai AINEEWBEASTJUMPENEMY
        }
        else
          ai AINEEWBEASTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINEEWBEASTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NEEWBEASTWALKVEL randomangle geth
  }

ends

/*
state neewbeastshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AINEEWBEASTGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends
*/

state neewbeastfleestate
  ifcount 8
  {
    ifrnd 64
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINEEWBEASTSHOOT
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINEEWBEASTGETENEMY
    }
    else
      ai AINEEWBEASTGETENEMY
    break
  }
ends

state neewbeastthinkstate

  ifrnd 8
    soundonce MINACT

  ifactioncount 3
  {
    ifrnd 128
    {
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINEEWBEASTSHOOT
    }
    else
      ai AINEEWBEASTGETENEMY
  }

  ifrnd 16
    ifbulletnear
  {
    ifgapzl 96
      ai AINEEWBEASTDODGE
    else
    {
      ifrnd 128
      {
        ifceilingdistl 144 break
        ai AINEEWBEASTJUMPENEMY
      }
      else
        ai AINEEWBEASTDODGE
    }
  }
ends

state neewbeastscratchstate
  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 2048
    {
      ifrnd 128
        ai AINEEWBEASTFLEENEMY
      break
    }
    ifrnd 80
      ai AINEEWBEASTTHINK
    else
      ai AINEEWBEASTGETENEMY
  }

  ifactioncount 3
  {
    ifpdistg 1596
      ai AINEEWBEASTTHINK
    else ifp palive ifcansee
    {
      palfrom 16 16
      addphealth NEEWBEASTSCRATCHAMOUNT
      sound DUKE_LONGTERM_PAIN
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifpdistl 1596
      soundonce MINATK
    else
      soundonce MINATK
  }
ends

state checkneewbeasthit
  spawn BLOOD
/*
  ifai AINEEWBEASTSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SOMETHINGFROZE
      spritepal 1
      move 0
      action ANEEWBEASTFROZEN
      strength 0
      break
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AINEEWBEASTGROW
      break
    }

    addkills 1

    ifwasweapon RPG
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AINEEWBEASTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound MINDY
  }
  else
  {
    sound MINPN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AINEEWBEASTSHRUNK
      break
    }
*/
    state random_wall_jibs
    ifrnd 32
      ai AINEEWBEASTFLINTCH
    else
      ifrnd 32
        ifpdistg 3500
          ifp palive
            ifcansee
              ai AINEEWBEASTSHOOT
  }
ends

state neewbeastjumpstate
  ifaction ANEEWBEASTFALL
  {
    iffloordistl 16
      ai AINEEWBEASTGETENEMY
  }
  else
    ifcount 32
      action ANEEWBEASTFALL
ends

state neewbeastdyingstate
  ifaction ANEEWBEASTLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength NEEWBEASTSTRENGTH
      ai AINEEWBEASTGETENEMY
    }
  }
  else
    ifai AINEEWBEASTDYING
      ifactioncount 7
  {
    iffloordistl 8
      sound THUD
    move NEEWBEASTSTOP
    action ANEEWBEASTLYINGDEAD
  }
ends

state neewbeastdodgestate
  ifcount 13
    ai AINEEWBEASTGETENEMY
ends

useractor enemystayput NEEWBEASTSTAYPUT NEEWBEASTSTRENGTH ai AINEEWBEASTGETENEMY cstator 257 cactor NEEWBEAST enda
useractor enemy NEEWBEASTJUMP NEEWBEASTSTRENGTH ai AINEEWBEASTJUMPENEMY cstator 257 cactor NEEWBEAST enda

state neewbeastcode

  ifai 0
    {
      cstat 257
       ifcansee
         {
            soundonce MINACT
         }
    }

  state checksquished
  ifai 0
  {
    cstator 257
    ai AINEEWBEASTGETENEMY
  }
  else
    ifaction ANEEWBEASTLYINGDEAD
  {
    fall
    state neewbeastdyingstate
    break
  }
  else
    ifaction ANEEWBEASTFROZEN
  {
    ifcount THAWTIME
    {
      ai AINEEWBEASTGETENEMY
      spritepal 0
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
    ifai AINEEWBEASTJUMPENEMY
      state neewbeastjumpstate
  else
  {
    fall
    ifai AINEEWBEASTGETENEMY
      state neewbeastseekstate
    else
      ifai AINEEWBEASTCHARGEENEMY
        state neewbeastseekstate
    else
      ifai AINEEWBEASTFLINTCH
    {
      ifcount 8
        ai AINEEWBEASTGETENEMY
    }

    else
      ifai AINEEWBEASTDODGE
        state neewbeastdodgestate
    else
      ifai AINEEWBEASTSCRATCHENEMY
        state neewbeastscratchstate
    else
      ifai AINEEWBEASTFLEENEMY
        state neewbeastfleestate
    else
      ifai AINEEWBEASTTHINK
        state neewbeastthinkstate
/*
    else
      ifai AINEEWBEASTSHRUNK
        state neewbeastshrunkstate
*/
    else
      ifai AINEEWBEASTGROW
        state genericgrowcode
    else
      ifai AINEEWBEASTDYING
        state neewbeastdyingstate
    else
      ifai AINEEWBEASTSHOOT
    {
      ifp pshrunk
        ai AINEEWBEASTGETENEMY
      else
        ifcount 26
          ai AINEEWBEASTGETENEMY
      else
        ifcount 25
          shoot BROWNMETEOR
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
            sound MINATK2
      }
    }
  }

  ifhitweapon
    state checkneewbeasthit
ends


useractor enemy NEEWBEAST NEEWBEASTSTRENGTH
 fall
 sizeat 80 80
 state neewbeastcode
enda

action APLIZWALKING     0   4  5  1  15
move PLIZWALKVEL 72
ai AIPLIZGETENEMY APLIZWALKING PLIZWALKVEL seekplayer


state checkprpal
  ifai 0
  {
    ifspritepal 0
        nullop
    else
          addstrength ARCHANGELSTR
  }
ends

eventloadactor OOCTABRAIN
 cstat 257
 setactor[THISACTOR].xrepeat 70
 setactor[THISACTOR].yrepeat 70
enda

action AOOCTAWALK    0   3   5   1   15
action AOOCTASTAND     0   1   5   1   15
action AOOCTASCRATCH   0   4   5   1   15
action AOOCTAHIT    30   1   1   1   10
action AOOCTASHOOT    20   1   5   1   10
action AOOCTADYING    30   8   1   1   17
action AOOCTADEAD     38   1   1   1  1
action AOOCTAFROZEN    0   1   5

move OOCTAWALKVELS 96 -30
move OOCTAUPVELS 96 -70
move OOCTASTOPPED 0 -30
move OOCTAINWATER 96 24

ai AIOOCTAGETENEMY AOOCTAWALK OOCTAWALKVELS seekplayer
ai AIOOCTASHOOTENEMY AOOCTASHOOT OOCTASTOPPED faceplayer
ai AIOOCTASCRATCHENEMY AOOCTASCRATCH OOCTASTOPPED faceplayerslow
ai AIOOCTAHIT AOOCTAHIT OOCTASTOPPED faceplayer
ai AIOOCTASHRUNK AOOCTAWALK PSHRUNKVELS faceplayer
ai AIOOCTAGROW AOOCTASTAND OOCTASTOPPED faceplayerslow
ai AIOOCTADYING AOOCTADYING OOCTASTOPPED faceplayer

state ooctagetenemystate

  ifcansee
  {
    ifactioncount 32
    {
      ifrnd 48
        ifcanshoottarget
      {
        sound PRED_ATTACK
        ai AIOOCTASHOOTENEMY
        break
      }
    }
    else
      ifpdistl 1280
        ai AIOOCTASCRATCHENEMY
  }

ends

state ooctascratchenemystate
  ifpdistg 1280
    ai AIOOCTAGETENEMY
  else
    ifcount 32
  {
    resetcount
    sound PRED_ATTACK
    palfrom 25 100 25
    addphealth OOCTASCRATCHINGPLAYER
  }
ends

state ooctashootenemystate
  ifcount 25
  {
    ifcount 27
      ai AIOOCTAGETENEMY
  }
  else
    ifcount 24
      ifspritepal 25
        {
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
          spawn FBALL3
        }
        else
      spawn FBALL2
      spawn FBALL2
  else
    ifactioncount 6
      resetactioncount
ends

state checkooctahitstate
  ifwasweapon SHRINKSPARK
  {
    sound ACTOR_SHRINKING
    ai AIOOCTASHRUNK
  }
  else
  {
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SOMETHINGFROZE
        spritepal 1
        move 0
        action AOOCTAFROZEN
        strength 0
        break
      }

      addkills 1
      ifwasweapon RPG
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon GROWSPARK
      {
        cstat 0
        sound ACTOR_GROWING
        ai AIOOCTAGROW
        break
      }
      else
      {
        state rf
        ai AIOOCTADYING
      }
      sound MAGEDY
    }
    else
    {
      ifwasweapon RPG
      {
        sound MAGEPN
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT

      sound MAGEPN
      spawn BLOOD
      ifrnd 64
        ai AIOOCTAHIT
    }
  }
  state random_wall_jibs
ends

state ooctashrunkstate
  ifcount SHRUNKDONECOUNT
    ai AIPLIZGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends


state ooctadyingstate
  ifactioncount 8
  {
    ifrnd 64
      spawn BLOODPOOL
    move OOCTASTOPPED
    action AOOCTADEAD
    break
  }
  else
    ifactioncount 5 nullop
  else
    ifactioncount 4
      iffloordistl 8
        sound THUD
ends

useractor enemy OOCTABRAINSTAYPUT MAGESTR
  state checkprpal
  ai AIOOCTAGETENEMY
  cactor OOCTABRAIN
enda

useractor enemy OOCTABRAIN MAGESTR

 ifai 0
  {
   cstat 257
  }

  state checkprpal
  fall
  sizeat 70 70
  state checksquished
  ifai 0
    ai AIOOCTAGETENEMY
  else
    ifaction AOOCTADEAD
  {
    strength 0
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      addkills -1
      spawn TRANSPORTERSTAR
      cstat 257
      strength MAGESTR
      ai AIOOCTAGETENEMY
    }
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      killit
    }
    break
  }
  else ifaction AOOCTAFROZEN
  {
    ifcount THAWTIME
    {
      ai AIOOCTAGETENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
      {
        ifactioncount 26
        {
          spawn WATERDRIP
          resetactioncount
        }
      }

    ifhitweapon
    {
      addkills 1
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      lotsofglass 30
      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
  {
    ifrnd 1
      soundonce MAGERM

    ifai AIOOCTAGETENEMY
      state ooctagetenemystate
    else
      ifai AIOOCTAHIT
      {
        ifcount 8
          ai AIOOCTASHOOTENEMY
      }
    else
      ifai AIOOCTADYING
      {
        state ooctadyingstate
        break
      }
    else
      ifai AIOOCTASCRATCHENEMY
        state ooctascratchenemystate
    else
      ifai AIOOCTASHOOTENEMY
        state ooctashootenemystate
    else
      ifai AIOOCTASHRUNK
      {
        state ooctashrunkstate
        break
      }
    else
      ifai AIOOCTAGROW
        state genericgrowcode

    ifmove OOCTAUPVELS nullop
    else
      ifp phigher
        move OOCTAUPVELS seekplayer
    else
      ifmove OOCTAINWATER nullop
      else
        ifinwater
          move OOCTAINWATER seekplayer

    ifhitweapon
      state checkooctahitstate
  }
enda

eventloadactor NNEWBEASTT
 cstat 257
 setactor[THISACTOR].xrepeat 75
 setactor[THISACTOR].yrepeat 70
enda

action ANNEWBEASTTSTAND     0
action ANNEWBEASTTWALKING   10  4  5  1  15
action ANNEWBEASTTRUNNING   10  4  5  1  10
action ANNEWBEASTTSCRATCHING  30  3  5  1  20
action ANNEWBEASTTDYING     72  24  1  1  15
action ANNEWBEASTTFLINTCH   71  1  1  1  1
action ANNEWBEASTTLYINGDEAD 96  1  1
action ANNEWBEASTTSCREAM    50  2  5  1  40
action ANNEWBEASTTFALL      90  1  5
action ANNEWBEASTTFROZEN    10  1  5
action ANNEWBEASTTTHINK     0   2  5  1  5
action ANNEWBEASTTHANG      0  1  5

useractor enemy NNEWBEASTTHANG BRUISERSTR
  ifaction 0
  {
    action ANNEWBEASTTHANG
    cstator 257

  }
  else
    ifhitweapon
  {
    cactor NNEWBEASTT
    action ANNEWBEASTTSTAND
    sound BRUSPAIN
  }
  else
    ifspawnedby BOSS4
      ifcount 200
        ifrnd 1
  {
    cactor NNEWBEASTT
    action ANNEWBEASTTSTAND
    sound BRUSPAIN
  }
enda

action ANNEWBEASTTHANGDEAD      -1  1  5
useractor enemy NNEWBEASTHANGDEAD TOUGH

  ifaction 0
  {
    action ANNEWBEASTTHANGDEAD
    cstator 257
  }
  else
    ifhitweapon
  {
    ifdead
    {
      state standard_jibs
      spawn BLOODPOOL
      sound SQUISHED
      killit
    }
    else
    {
      guts JIBS6 1
      sound SQUISHED
    }
  }
enda

move NNEWBEASTTWALKVEL 100
move NNEWBEASTTRUNVEL 200
move NNEWBEASTTSTOP

ai AINNEWBEASTTGETENEMY ANNEWBEASTTWALKING NNEWBEASTTWALKVEL seekplayer
ai AINNEWBEASTTDODGE ANNEWBEASTTRUNNING NNEWBEASTTRUNVEL dodgebullet
ai AINNEWBEASTTCHARGEENEMY ANNEWBEASTTRUNNING NNEWBEASTTRUNVEL seekplayer
ai AINNEWBEASTTFLEENEMY ANNEWBEASTTWALKING NNEWBEASTTWALKVEL fleeenemy
ai AINNEWBEASTTSCRATCHENEMY ANNEWBEASTTSCRATCHING NNEWBEASTTSTOP faceplayerslow
// ai AINEWBEASTTSHRUNK ANNEWBEASTTWALKING PSHRUNKVELS fleeenemy
ai AINNEWBEASTTGROW ANNEWBEASTTSTAND  NNEWBEASTTSTOP faceplayerslow
ai AINNEWBEASTTDYING ANNEWBEASTTDYING NNEWBEASTTSTOP faceplayer
ai AINNEWBEASTTSHOOT ANNEWBEASTTSCREAM NNEWBEASTTSTOP faceplayerslow
ai AINNEWBEASTTFLINTCH ANNEWBEASTTFLINTCH NNEWBEASTTSTOP faceplayerslow
ai AINNEWBEASTTTHINK ANNEWBEASTTTHINK NNEWBEASTTSTOP


state nnewbeasttseekstate

  ifactornotstayput
  {
    ifp palive
      ifcansee
        ifpdistl 1596
    {
      ai AINNEWBEASTTSCRATCHENEMY
      break
    }

    ifai AINNEWBEASTTCHARGEENEMY
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWBEASTTSCRATCHENEMY
        break
      }

      ifrnd 1
        ifpdistg 2048
          ifp palive
            ifcansee
      {
        ai AINNEWBEASTTSHOOT
        break
      }
    }
    else
      ifpdistg 2048
    {
      ai AINNEWBEASTTCHARGEENEMY
      break
    }

    iffloordistl 16
    {
      ifcount 32
        ifrnd 16
      {
        ifceilingdistl 96
      }
      break
    }

    ifrnd 4
    {
      ifnotmoving
        operate
    }
    else
      ifrnd 16
        ifbulletnear
    {
      ifgapzl 128
        ai AINNEWBEASTTDODGE
      else
        ifactornotstayput
      {
        ifrnd 128
        {
          ifceilingdistl 96 break
        }
        else
          ai AINNEWBEASTTDODGE
      }
    }
  }
  else
  {
    ifactioncount 16
    {
      ifp palive
        ifpdistl 1596
          ifcansee
      {
        ai AINNEWBEASTTSCRATCHENEMY
        break
      }
    }
    ifcount 16
      ifrnd 32
        move NNEWBEASTTWALKVEL randomangle geth
  }

ends

/*
state nnewbeastshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AINEWBEASTGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends
*/

state nnewbeasttfleestate
  ifcount 8
  {
    ifrnd 64
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWBEASTTSHOOT
  }
  else
  {
    iffloordistl 16
    {
      ifnotmoving
        ai AINNEWBEASTTGETENEMY
    }
    else
      ai AINNEWBEASTTGETENEMY
    break
  }
ends

state nnewbeasttscratchstate
  ifcount 20
    ifrnd 8
  {
    ifcansee
      ifpdistl 1024
    {
      ifrnd 128
        ai AINNEWBEASTTFLEENEMY
      break
    }
    ifrnd 80
      ai AINNEWBEASTTTHINK
    else
      ai AINNEWBEASTTGETENEMY
  }

  ifactioncount 3
  {
     ifpdistg 1596
       ai AINNEWBEASTTTHINK
    else  ifp palive ifcansee
    {
      palfrom 16 16
      addphealth NNEWBEASTTSCRATCHAMOUNT
      sound DUKE_LONGTERM_PAIN2
      resetactioncount
      resetcount
    }
  }
  else
    ifcount 15
      nullop
  else
    ifcount 14
  {
    ifpdistl 1596
      soundonce CLAW
    else
      soundonce CLAW
  }
ends

state checknnewbeastthit
  spawn BLOOD
/*
  ifai AINNEWBEASTSHRUNK
  {
    addkills 1
    sound SQUISHED
    state standard_jibs
    killit
  }
*/
  ifdead
  {
    ifwasweapon FREEZEBLAST
    {
      sound SQUISHED
      state standard_jibs
      killit
    }

    ifwasweapon GROWSPARK
    {
      cstat 0
      sound ACTOR_GROWING
      ai AINNEWBEASTGROW
      break
    }

    addkills 1

    ifwasweapon RPG
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
    {
      state rf
      ai AINNEWBEASTTDYING
      ifrnd 64
        spawn BLOODPOOL
    }
    sound BRUSDEATH
  }
  else
  {
    sound BRUSPAIN
    ifwasweapon GROWSPARK
      sound EXPANDERHIT
/*
//  The alien is immune to the shrinker
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AINNEWBEASTSHRUNK
      break
    }
*/
    state random_wall_jibs
    ifrnd 32
      ai AINNEWBEASTTFLINTCH
    else
      ifrnd 32
        ifpdistg 3500
          ifp palive
            ifcansee
              ai AINNEWBEASTTSHOOT
  }
ends

state nnewbeasttthinkstate

  ifrnd 8
    soundonce BRUSROAM

  ifactioncount 3
  {
    ifrnd 128
    {
      ifpdistg 3500
        ifp palive
          ifcansee
            ai AINNEWBEASTTSHOOT
    }
    else
      ai AINNEWBEASTTGETENEMY
  }

  ifrnd 16
    ifbulletnear
  {
    ifgapzl 96
      ai AINNEWBEASTTDODGE
    else
    {
      ifrnd 128
      {
        ifceilingdistl 144 break
      }
      else
        ai AINNEWBEASTTDODGE
    }
  }
ends


state nnewbeasttdyingstate
  ifaction ANNEWBEASTTLYINGDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength BRUISERSTR
      ai AINNEWBEASTTGETENEMY
    }
  }
  else
    ifai AINNEWBEASTTDYING
      ifactioncount 21
  {
    iffloordistl 8
      sound THUD
    move NNEWBEASTTSTOP
    action ANNEWBEASTTLYINGDEAD
  }
ends

state nnewbeasttdodgestate
  ifcount 13
    ai AINNEWBEASTTGETENEMY
ends

useractor enemystayput NNEWBEASTTSTAYPUT BRUISERSTR ai AINNEWBEASTTGETENEMY cstator 257 cactor NNEWBEASTT enda

state nnewbeasttcode

  ifai 0
    {
      cstat 257
       ifcansee
         {
            soundonce BRUSSEE
         }
    }

  state checksquished
  ifai 0
  {
    cstator 257
    ai AINNEWBEASTTGETENEMY
  }
  else
    ifaction ANNEWBEASTLYINGDEAD
  {
    fall
    state nnewbeasttdyingstate
    break
  }
  else
    ifaction ANNEWBEASTTFROZEN
  {
    ifcount THAWTIME
    {
      ai AINNEWBEASTTGETENEMY
      spritepal 0
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1

      ifrnd 84
        spawn BLOODPOOL
      lotsofglass 30
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
  {
    fall
    ifai AINNEWBEASTTGETENEMY
      state nnewbeasttseekstate
    else
      ifai AINNEWBEASTTCHARGEENEMY
        state nnewbeasttseekstate
    else
      ifai AINNEWBEASTTFLINTCH
    {
      ifcount 8
        ai AINNEWBEASTTGETENEMY
    }

    else
      ifai AINNEWBEASTTDODGE
        state nnewbeasttdodgestate
    else
      ifai AINNEWBEASTTSCRATCHENEMY
        state nnewbeasttscratchstate
    else
      ifai AINNEWBEASTTFLEENEMY
        state nnewbeasttfleestate
    else
      ifai AINNEWBEASTTTHINK
        state nnewbeasttthinkstate
/*
    else
      ifai AINNEWBEASTSHRUNK
        state nnewbeastshrunkstate
*/
    else
      ifai AINNEWBEASTTGROW
        state genericgrowcode
    else
      ifai AINNEWBEASTTDYING
        state nnewbeasttdyingstate
    else
      ifai AINNEWBEASTTSHOOT
    {
      ifp pshrunk
        ai AINNEWBEASTTGETENEMY
      else      ifcount 26
          ai AINNEWBEASTTGETENEMY
      else
        ifcount 20
          shoot BROWNMETEOR
      else
      {
        ifcount 5
          nullop
        else
          ifcount 4
            sound BRUSACT
      }
    }
  }

  ifhitweapon
    state checknnewbeastthit
ends



useractor enemy NNEWBEASTT BRUISERSTR sizeat 75 70 fall state nnewbeasttcode enda

eventloadactor OCCTABRAIN
 cstat 257
 setactor[THISACTOR].xrepeat 60
 setactor[THISACTOR].yrepeat 60
enda

action AOCCTAWALK    0   3   5   1   15
action AOCCTASTAND     0   1   5   1   15
action AOCCTASCRATCH   0   4   5   1   15
action AOCCTAHIT    30   1   1   1   10
action AOCCTASHOOT    20   1   5   1   10
action AOCCTADYING    30   7   1   1   30
action AOCCTADEAD     38   1   1   1  1
action AOCCTAFROZEN    0   1   5

move OCCTAWALKVELS 96 -30
move OCCTAUPVELS 96 -70
move OCCTASTOPPED 0 -30
move OCCTAINWATER 96 24

ai AIOCCTAGETENEMY AOCCTAWALK OCCTAWALKVELS seekplayer
ai AIOCCTASHOOTENEMY AOCCTASHOOT OCCTASTOPPED faceplayer
ai AIOCCTASCRATCHENEMY AOCCTASCRATCH OCCTASTOPPED faceplayerslow
ai AIOCCTAHIT AOCCTAHIT OCCTASTOPPED faceplayer
ai AIOCCTASHRUNK AOCCTAWALK OCCTAWALKVELS faceplayer
ai AIOCCTAGROW AOCCTASTAND OCCTASTOPPED faceplayerslow
ai AIOCCTADYING AOCCTADYING OCCTASTOPPED faceplayer

state occtagetenemystate

  ifcansee
  {
    ifactioncount 32
    {
      ifrnd 48
        ifcanshoottarget
      {
        sound DARKATK
        ai AIOCCTASHOOTENEMY
        break
      }
    }
    else
      ifpdistl 1280
        ai AIOCCTASCRATCHENEMY
  }

ends

state occtascratchenemystate
  ifpdistg 1280
    ai AIOCCTAGETENEMY
  else
    ifcount 32
  {
    resetcount
    sound OCTA_ATTACK2
    palfrom 8 32
    addphealth BADHURT
  }
ends

state occtashootenemystate
  ifcount 25
  {
    ifcount 27
      ai AIOCCTAGETENEMY
  }
  else
    ifcount 24
      shoot REDMETEOR
  else
    ifactioncount 24
      resetactioncount
ends

state checkocctahitstate
/*
  ifwasweapon SHRINKSPARK
  {
    sound ACTOR_SHRINKING
    ai AIOCCTASHRUNK
  }
  else
*/
  {
    ifdead
    {
      ifwasweapon FREEZEBLAST
      {
        sound SQUISHED
        state standard_jibs
        killit
      }

      addkills 1
      ifwasweapon RPG
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      else
        ifwasweapon GROWSPARK
      {
        sound SQUISHED
        state standard_jibs
        spawn EXPLOSION2
        killit
      }
      else
      {
        state rf
        ai AIOCCTADYING
      }
      sound DARKDTH
    }
    else
    {
      ifwasweapon RPG
      {
        sound DARKPN
      }
      else
        ifwasweapon GROWSPARK
          sound EXPANDERHIT

      sound DARKPN
      spawn BLOOD
      ifrnd 64
        ai AIOCCTAHIT
    }
  }
  state random_wall_jibs
ends

state occtashrunkstate
  ifcount SHRUNKDONECOUNT
    ai AIOCCTAGETENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends


state occtadyingstate
  ifactioncount 8
  {
    ifrnd 64
      spawn BLOODPOOL
    move OCCTASTOPPED
    action AOCCTADEAD
    break
  }
  else
    ifactioncount 5 nullop
  else
    ifactioncount 4
      iffloordistl 8
        sound THUD
ends

useractor enemystayput OCCTABRAINSTAYPUT SOULDSTRENGTH
  ai AIOCCTAGETENEMY
  cactor OCCTABRAIN
enda

useractor enemy OCCTABRAIN SOULDSTRENGTH

 ifai 0
  {
    cstat 257
  }

  fall
  sizeat 60 60
  state checksquished
  ifai 0
    ai AIOCCTAGETENEMY
  else
    ifaction AOCCTADEAD
  {
    strength 0
    ifcount RESPAWNACTORTIME
      ifrespawn
    {
      addkills -1
      spawn TRANSPORTERSTAR
      cstat 257
      strength SOULDSTRENGTH
      ai AIOCCTAGETENEMY
    }
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
    {
      state standard_jibs
      killit
    }
    break
  }
  else ifaction AOCCTAFROZEN
  {
    ifcount THAWTIME
    {
      ai AIOCCTAGETENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
      {
        ifactioncount 26
        {
          spawn WATERDRIP
          resetactioncount
        }
      }

    ifhitweapon
    {
      addkills 1
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }

      lotsofglass 30
      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
  {
    ifrnd 1
      soundonce DARKACT2

    ifai AIOCCTAGETENEMY
      state occtagetenemystate
    else
      ifai AIOCCTAHIT
      {
        ifcount 8
          ai AIOCCTASHOOTENEMY
      }
    else
      ifai AIOCCTADYING
      {
        state occtadyingstate
        break
      }
    else
      ifai AIOCCTASCRATCHENEMY
        state occtascratchenemystate
    else
      ifai AIOCCTASHOOTENEMY
        state occtashootenemystate
    else
      ifai AIOCCTASHRUNK
      {
        state occtashrunkstate
        break
      }
    else
      ifai AIOCCTAGROW
        state genericgrowcode

    ifmove OCCTAUPVELS nullop
    else
      ifp phigher
        move OCCTAUPVELS seekplayer
    else
      ifmove OCCTAINWATER nullop
      else
        ifinwater
          move OCCTAINWATER seekplayer

    ifhitweapon
      state checkocctahitstate
  }
enda

eventloadactor ZOMBIER
 cstat 257
 setactor[THISACTOR].xrepeat 60
 setactor[THISACTOR].yrepeat 60
enda

action APIG2WALK     0  4 5 1 20
action APIG2RUN      0  4 5 1 11
action APIG2SHOOT    30 2 5 1 58
action APIG2COCK     25 1 5 1 16
action APIG2STAND    30 1 5 1 1
action APIG2DIVE     40 2 5 1 40
action APIG2DIVESHOOT  45 2 5 1 58
action APIG2DYING    55 6 1 1 15
action APIG2HIT      55 1 1 1 10
action APIG2DEAD     62 1 1 1 1
action APIG2FROZEN    0 1 5
action APIG2GROW      0


move PIG2WALKVELS 64
move PIG2RUNVELS 96
move PIG2STOPPED

ai AIPIG2SEEKENEMY APIG2WALK PIG2WALKVELS seekplayer
ai AIPIG2SHOOTENEMY APIG2SHOOT PIG2STOPPED faceplayer
ai AIPIG2FLEEENEMY APIG2WALK PIG2WALKVELS fleeenemy
ai AIPIG2SHOOT APIG2SHOOT PIG2STOPPED faceplayer
ai AIPIG2DODGE APIG2RUN PIG2RUNVELS dodgebullet
ai AIPIG2CHARGE APIG2RUN PIG2RUNVELS seekplayer
ai AIPIG2DIVING APIG2DIVE PIG2STOPPED faceplayer
ai AIPIG2DYING APIG2DYING PIG2STOPPED faceplayer
ai AIPIG2SHRINK APIG2WALK PIG2WALKVELS fleeenemy
ai AIPIG2GROW APIG2GROW PIG2STOPPED faceplayerslow
ai AIPIG2HIT APIG2HIT PIG2STOPPED faceplayer

state pig2seekenemystate

  ifai AIPIG2CHARGE
  {
    ifcansee
      ifpdistl 3084
    {
      ifnotmoving
        ai AIPIG2SEEKENEMY
      else
        ai AIPIG2DIVING
    }
    break
  }
  else iffloordistl 32
  {
    ifpdistg 4096
    {
      ifactornotstayput
      ai AIPIG2CHARGE
    }
    ifrnd 8
    {
      ifbulletnear
        ai AIPIG2DODGE
    }
  }

  ifrnd 128
    ifcansee
  {
    ifai AIPIG2DODGE
    {
      ifcount 32
        ai AIPIG2CHARGE
          break
    }
    iffloordistl 32
    {
      ifpdistl 1024
        ifp palive
          ifcanshoottarget
      {
        ai AIPIG2SHOOTENEMY
        break
      }
      ifcount 48
      {
        ifrnd 8
          ifp palive
            ifcanshoottarget
        {
          ifrnd 192
            ai AIPIG2SHOOTENEMY
          else
            ai AIPIG2DIVING
          break
        }
      }
    }
  }
ends


state pig2shootenemystate
//  ifcansee
  {
    ifcount 12 nullop
    else
      ifcount 11
    {
      ifcanshoottarget
      {
        sound RAILSHOOT
        shoot RAILSLUG
      }
      else
        ai AIPIG2SEEKENEMY
    }
    ifcount 25 nullop
    else
      ifcount 24
      {
        action APIG2COCK
      }
    ifcount 48 nullop
    else
      ifcount 47
    {
      ifcanshoottarget
      {
        sound RAILSHOOT
        shoot RAILSLUG
      }
      else
        ai AIPIG2SEEKENEMY
    }
    ifcount 60 nullop
    else
      ifcount 59
      {
        action APIG2COCK
      }
    ifcount 72
    {
      ifrnd 64
        resetcount
      else
      {
        ifpdistl 768
          ai AIPIG2FLEEENEMY
        else
          ai AIPIG2SEEKENEMY
      }
    }
    ifaction APIG2COCK
      ifactioncount 2
        action APIG2SHOOT
  }
  else
    ai AIPIG2SEEKENEMY
ends

state pig2fleeenemystate
  ifactioncount 8
    ai AIPIG2SEEKENEMY
  else
    ifnotmoving
      ai AIPIG2SEEKENEMY
ends

state pig2divestate
  ifaction APIG2DIVESHOOT
  {
    ifcansee
    {
      ifcount 12 nullop
      else
        ifcount 11
      {
        ifcanshoottarget
        {
          
          sound RAILSHOOT
          shoot RAILSLUG
        } 
        else
          ai AIPIG2SEEKENEMY
      }
      ifcount 25 nullop
      else
        ifcount 24
      ifcount 48 nullop
      else
        ifcount 47
      {
        ifcanshoottarget
        {
          sound RAILSHOOT
          shoot RAILSLUG
        }
        else
          ai AIPIG2SEEKENEMY
      }
      ifcount 60 nullop
      else
        ifcount 59
      {
        ifgapzl 32
          ai AIPIG2DIVING
        else
        {
          ifpdistl 4096
            ai AIPIG2FLEEENEMY
          else
            ai AIPIG2SEEKENEMY
        }
      }
    }
    else
      ifgapzl 32
        ai AIPIG2DIVING
      else
        ai AIPIG2SEEKENEMY
  }
  else
    ifactioncount 2
    ifp palive
    {
      resetcount
      action APIG2DIVESHOOT
    }
ends

state checkpig2hitstate
  spawn BLOOD
  ifdead
  {
    state random_wall_jibs

    ifwasweapon GROWSPARK
    {
      sound SQUISHED
      state standard_jibs
      spawn BURNING2
      killit
    }

    addkills 1

    ifrnd 16
     spawn FREEZEAMMO

    ifwasweapon FREEZEBLAST
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    ifwasweapon RADIUSEXPLOSION
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ifwasweapon RPG
    {
      sound SQUISHED
      state standard_jibs
      killit
    }
    else
      ai AIPIG2DYING
        ifrnd 128
        sound PIGDY4
    else
        ifrnd 128
        sound PIGDY3
    else
        sound PIGDY2
 }
  else
  {
    sound PRED_PAIN
    state random_wall_jibs
/*
    ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AIPIGSHRINK
    }
    else
*/
      ifwasweapon GROWSPARK
        sound EXPANDERHIT
    else
      ifrnd 32
        ai AIPIG2HIT
    else
      ifrnd 64
        ai AIPIG2SHOOTENEMY
    else
      ifrnd 64
      {
        ai AIPIG2DIVING
        action APIG2DIVESHOOT
      }
  }
ends

state pig2shrinkstate
  ifcount SHRUNKDONECOUNT
    ai AIPIG2SEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 48 40
  else
    state genericshrunkcode
ends

state pig2dyingstate
  ifactioncount 6
  {
    ifrnd 64
      spawn BLOODPOOL
    state rf
    iffloordistl 8
      sound THUD
    action APIG2DEAD
    move PIG2STOPPED
    break
  }
ends


useractor enemy ZOMBIERDIVING ZOMBIESTR
  ai AIPIG2DIVING
  action APIG2DIVESHOOT
  cactor ZOMBIER
enda
useractor enemystayput ZOMBIERSTAYPUT ZOMBIESTR
  ai AIPIG2SEEKENEMY
  cactor ZOMBIER
enda
useractor enemy ZOMBIER ZOMBIESTR APIG2STAND
  fall
  sizeat 60 60
  state checksquished
  ifaction APIG2STAND
    ai AIPIG2SEEKENEMY
  else
    ifaction APIG2DEAD
  {
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERSTAR
      cstat 257
      strength ZOMBIESTR
      ai AIPIG2SEEKENEMY
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  else
    ifaction APIG2FROZEN
  {
    ifcount THAWTIME
    {
      ai AIPIG2SEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
        ifrnd 8
          spawn WATERDRIP

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1

      lotsofglass 30
      ifrnd 84 spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
  else
    ifai AIPIG2DYING
      state pig2dyingstate
  else
    ifai AIPIG2HIT
    {
      ifactioncount 3
      ai AIPIG2SEEKENEMY
    }
  else
    ifai AIPIG2SHRINK
      state pig2shrinkstate
  else
  {
    ifai AIPIG2SEEKENEMY
      state pig2seekenemystate
    else
      ifai AIPIG2DODGE
        state pig2seekenemystate
    else
      ifai AIPIG2SHOOTENEMY
        state pig2shootenemystate
    else
      ifai AIPIG2GROW
        state genericgrowcode
    else
      ifai AIPIG2FLEEENEMY
        state pig2fleeenemystate
    else
      ifai AIPIG2DIVING
        state pig2divestate
    else
      ifai AIPIG2CHARGE
        state pig2seekenemystate
    ifhitweapon
      state checkpig2hitstate
    ifrnd 1
    {
        soundonce ZROAM
    }
  }
enda


action ABOOSS1WALK        0  6  5  1  12
action ABOOSS1FROZEN        30 1  5
action ABOOSS1RUN         0  6  5  1  10
action ABOOSS1SHOOT      30  2  5  1  4
action ABOOSS1LOB         51 2  5  1  45
action ABOOSS1DYING        40 10  1  1  40
action BOOSS1FLINTCH       40 1  1  1  1
action ABOOSS1DEAD         50
action ATROOP2WALKING   0  4  5  1   12

move PALBOSS12SHRUNKRUNVELS 32
move PALBOSS12RUNVELS 128
move TROOP2WALKVELS 72
move BOOSS1WALKVELS 168
move BOOSS1RUNVELS 246
move BOOSS1STOPPED


ai AITROOP2SEEKENEMY  ATROOP2WALKING   TROOP2WALKVELS seekplayer
ai AIBOOSS1SEEKENEMY ABOOSS1WALK BOOSS1WALKVELS seekplayer
ai AIBOOSS1RUNENEMY ABOOSS1RUN BOOSS1RUNVELS faceplayer
ai AIBOOSS1SHOOTENEMY ABOOSS1SHOOT BOOSS1STOPPED faceplayer
ai AIBOOSS1LOBBED ABOOSS1LOB BOOSS1STOPPED faceplayer // faceplayersmart
ai AIBOOSS1DYING ABOOSS1DYING BOOSS1STOPPED faceplayer
ai AIBOOSS1PALSHRINK ABOOSS1WALK PALBOSS12SHRUNKRUNVELS furthestdir

state booss1palshrunkstate
  ifcount SHRUNKDONECOUNT
    ai AITROOP2SEEKENEMY
  else
    ifcount SHRUNKCOUNT
      sizeto 40 40
  else
    state genericshrunkcode
ends

state checkbooss1seekstate
  ai AIBOOSS1SEEKENEMY
  ifspritepal 0 nullop
    else   // a fake way of doing a ifspritepal NOT.
      move PALBOSS12RUNVELS seekplayer
ends

state booss1runenemystate
  ifpdistl 2048
  {
    ifp palive
      ai AIBOOSS1SHOOTENEMY
    break
  }
  else
    ifcansee
  {
    ifactioncount 6
    {
      ifcanshoottarget
      {
        resetactioncount
        sound BOS1_WALK
      }
      else
        ai AIBOOSS1SEEKENEMY
    }
  }
  else
    ai AIBOOSS1SEEKENEMY
ends

state booss1seekenemystate
  ifrnd 2
    soundonce DEMONROAM
  else
    ifactioncount 6
  {
    resetactioncount
    sound BOS1_WALK
  }

  ifpdistl 2548
    ifp palive
  {
    ai AIBOOSS1SHOOTENEMY
    break
  }

  ifcansee
    ifcount 32
  {
    ifrnd 32
    {
      ifp palive
        ifcanshoottarget
          ai AIBOOSS1SHOOTENEMY
    }
    else
      ifpdistg 2548
        ifrnd 192
          ifcanshoottarget
    {
      ifrnd 64
      {
        ai AIBOOSS1RUNENEMY
        ifspritepal 0 nullop
        else
          move PALBOSS12RUNVELS seekplayer
      }
      else
        ai AIBOOSS1LOBBED
    }
  }

ends

state booss1dyingstate
  ifaction ABOOSS1DEAD
  {
    ifspritepal 0
      break
    ifrespawn
      ifcount RESPAWNACTORTIME
    {
      spawn TRANSPORTERBEAM
      cstat 257
      strength PIGCOPSTRENGTH
      state checkbooss1seekstate
    }
    else
    {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
    }
  }
  ifactioncount 10
  {
    iffloordistl 8
      sound THUD
        getuserdef[THISACTOR].volume_number TEMP
        setuserdef[THISACTOR].volume_number 0
        ifspritepal 0
         {
           starttrack 11
         }
         setuserdef[THISACTOR].volume_number TEMP
    action ABOOSS1DEAD
    cstat 0
    ifspritepal 0
    endofgame 52
  }
ends

state booss1lobbedstate
  ifcansee
  {
    ifactioncount 2
    {
      resetactioncount
      sound DEM_LOB
      shoot BFG // *********************
    }
    else
      ifcount 64
        ifrnd 16
          state checkbooss1seekstate
  }
  else
    state checkbooss1seekstate
ends

state booss1shootenemy
  ifcount 72
    state checkbooss1seekstate
  else
    ifaction ABOOSS1SHOOT
      ifactioncount 2
  {
    sound DEM_ATTACK
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    shoot RIFLESHELL
    resetactioncount
  }
ends

state checkbooss1hitstate
  ifrnd 2
    spawn BLOODPOOL
  ifdead
  {
    ifspritepal 0
      globalsound DUKE_TALKTOBOSSFALL
    else
    {
      ifwasweapon FREEZEBLAST
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
    }

    sound DEM_DTH

    addkills 1
    ai AIBOOSS1DYING
  }

  else
  {
    ifrnd 32
    {
      action BOOSS1FLINTCH
      move 0
    }

    ifspritepal 0 nullop
    else
      ifwasweapon SHRINKSPARK
    {
      sound ACTOR_SHRINKING
      ai AIBOOSS1PALSHRINK
      cstat 0
      break
    }

    soundonce DEMONPAIN

    debris SCRAP1 1
    guts JIBS6 1
  }

  ifhitweapon { ifwasweapon RPG { setactor[THISACTOR].xvel -96 } else ifwasweapon RADIUSEXPLOSION { setactor[THISACTOR].xvel -32 } }

ends

state booss1code

 ifai 0
  {
    sound DEM_SEE
    ifcansee
      {
        getuserdef[THISACTOR].volume_number TEMP
        setuserdef[THISACTOR].volume_number 0
        ifspritepal 0
         {
           starttrack 8
         }
         setuserdef[THISACTOR].volume_number TEMP
      }
  }

  ifaction ABOOSS1FROZEN
  {
    ifcount THAWTIME
    {
      ai AIBOOSS1SEEKENEMY
      getlastpal
    }
    else
      ifcount FROZENDRIPTIME
    {
      ifactioncount 26
      {
        spawn WATERDRIP
        resetactioncount
      }
    }

    ifhitweapon
    {
      ifwasweapon FREEZEBLAST
      {
        strength 0
        break
      }
      addkills 1
      lotsofglass 30

      ifrnd 84
        spawn BLOODPOOL
      sound GLASS_BREAKING
      killit
    }
    ifp pfacing
      ifpdistl FROZENQUICKKICKDIST
        pkick
    break
  }
getsector[THISACTOR].lotag BOSSLOTAG // This prevents BOOSS1 from going into water to prevent issues.
   ifvare BOSSLOTAG 1
   {
       setactor[THISACTOR].x BOSSX
       setactor[THISACTOR].y BOSSY
       setactor[THISACTOR].z BOSSZ
       updatesectorz BOSSX BOSSY BOSSZ BOSSSECTOR
       changespritesect THISACTOR BOSSSECTOR
   }
   else
   {
       getactor[THISACTOR].x BOSSX
       getactor[THISACTOR].y BOSSY
       getactor[THISACTOR].z BOSSZ
   }

  ifai 0
  {
    ifspritepal 0
      ai AIBOOSS1RUNENEMY
    else
    {
     strength DEMOLISHERSTR
     stopallsounds
     sound DEM_SEE
     ai AIBOOSS1SHOOTENEMY
     clipdist 16
    }
  }

  else
    ifaction BOOSS1FLINTCH
  {
    ifactioncount 3
    ai AIBOOSS1SHOOTENEMY
  }
  else
    ifai AIBOOSS1SEEKENEMY
      state booss1seekenemystate
  else
    ifai AIBOOSS1RUNENEMY
      state booss1runenemystate
  else
    ifai AIBOOSS1SHOOTENEMY
      state booss1shootenemy
  else
    ifai AIBOOSS1LOBBED
      state booss1lobbedstate
  else
    ifai AIBOOSS1PALSHRINK
      state booss1palshrunkstate

  ifai AIBOOSS1DYING
    state booss1dyingstate
  else
  {
    ifhitweapon
      state checkbooss1hitstate
    else
      ifp palive
        ifspritepal 0
          ifpdistl 1280
    {
      addphealth -1000
      palfrom 63 63
    }
  }
ends

eventloadactor BOOSS1
 cstator 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

eventloadactor BOOSS1SHOOT
 cstator 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

eventloadactor BOOSS1LOB
 cstator 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

eventloadactor BOOSS1STAYPUT
 cstator 257
 setactor[THISACTOR].xrepeat 80
 setactor[THISACTOR].yrepeat 80
enda

actor BOOSS1STAYPUT DEMOLISHERSTR cactor BOOSS1 enda
useractor enemy BOOSS1 DEMOLISHERSTR fall sizeat 80 80 state booss1code enda
useractor enemy BOOSS1SHOOT DEMOLISHERSTR fall cactor BOOSS1 ai AIBOOSS1SHOOTENEMY enda // This actor automatically shoots the player.
useractor enemy BOOSS1LOB DEMOLISHERSTR fall cactor BOOSS1 ai AIBOOSS1LOBBED enda // This actor automatically lobs MORTERs at the player

eventloadactor CHAINGUNNER
 cstat 257
 setactor[THISACTOR].xrepeat 63
 setactor[THISACTOR].yrepeat 63
 getactor[THISACTOR].extra extra
 getactor[THISACTOR].hitag hitag
 setactor[THISACTOR].extra 0
 setactor[THISACTOR].hitag 0
enda

action ACMDWALKING     0   4  5  1  18
action ACMDSHOOTING    20  2  5  1  6
action ACMDFLINTCH  30  1  1  1  6
action ACMDDYING     30  9  1  1  15
action ACMDLYINGDEAD   39  1

move CMDWALKVEL 96
move CMDSTOP

ai AICMDGETENEMY ACMDWALKING CMDWALKVEL seekplayer
ai AICMDSHOOTENEMY ACMDSHOOTING CMDSTOP faceplayer
ai AICMDDYING ACMDDYING CMDSTOP faceplayer
ai AICMDFLINTCH ACMDFLINTCH CMDSTOP faceplayer

state cmddead

strength 0
ifhitweapon
{
	ifwasweapon RADIUSEXPLOSION
	{
		state standard_jibs
  		killit
	}
}

ends

state cmdhit
 ifdead
 {
 addkills 1
 ai AICMDDYING
 sound CMDDEATH
 spawn CHAINGUNSPRITE
 }
 else
 {
 spawn BLOOD
 ifrnd 160 { ai AICMDFLINTCH  sound CMDPAIN }
 ifwasweapon RPG setactor[THISACTOR].xvel -768
 ifwasweapon RADIUSEXPLOSION setactor[THISACTOR].xvel -768
 }
ends

useractor enemy CHAINGUNNER CMDSTRENGTH
  fall
  sizeat 63 63
  state checksquished

  ifai 0
  {
  cstat 257
  ifcansee
  {
   sound CMDSEE
  }
  }

  ifaction 0
  {
   ai AICMDGETENEMY
  }
  
  ifaction ACMDLYINGDEAD { state cmddead break }
  else
  ifai AICMDDYING
  {
  ifactioncount 9
  {
  action ACMDLYINGDEAD
  cstat 0
  }
  }

  ifai AICMDGETENEMY { ifcansee { ifcanshoottarget { ifrnd 64 { ai AICMDSHOOTENEMY resetactioncount } } } }

  ifai AICMDSHOOTENEMY
  {
  ifactioncount 2
  {
  sound DEM_ATTACK
  shoot RIFLESHELL
  shoot RIFLESHELL
  flash
  resetactioncount
  ifpdistg 9216 ai AICMDGETENEMY
  }
  else
  ifcount 40
  ai AICMDGETENEMY
  }

  ifai AICMDFLINTCH { ifactioncount 2 { ai AICMDSHOOTENEMY } }

 ifhitweapon state cmdhit

enda

useractor enemystayput CHAINGUNNERSTAYPUT CMDSTRENGTH
 fall
 sizeat 63 63
 state checksquished
 cactor CHAINGUNNER
enda

define DEVILSTR 450
define DEVILSCRATCH -12

eventloadactor DEVIL
 cstat 257
 setactor[THISACTOR].xrepeat 65
 setactor[THISACTOR].yrepeat 65
 getactor[THISACTOR].hitag hitag
 getactor[THISACTOR].extra extra
 setactor[THISACTOR].hitag 0
 setactor[THISACTOR].extra 0
enda

action ADEVWALK 0  4  5  1  16
action ADEVSHOOT 20  3  5  1  19
action ADEVSHOOT2 35  3  5  1  19
action ADEVPAIN 50  1  1  1  8
action ADEVDIE  50  5  1  1  16
action ADEVDEAD 55 1 

move DEVWALKVEL 96
move DEVSTOP

ai AIDEVWALK ADEVWALK DEVWALKVEL seekplayer
ai AIDEVSHOOT ADEVSHOOT DEVSTOP faceplayerslow
ai AIDEVSHOOT2 ADEVSHOOT2 DEVSTOP faceplayer
ai AIDEVDYING ADEVDIE DEVSTOP faceplayer
ai AIDEVPAIN ADEVPAIN DEVSTOP faceplayer

state devdead

strength 0
ifhitweapon
{
	ifwasweapon RADIUSEXPLOSION
	{
		state standard_jibs
  		killit
	}
}

ends

state devhit
 ifdead
 {
 addkills 1
 ai AIDEVDYING
 ifrnd 128 sound DEVIL_DIE else sound DEVIL_DIE2
 }
 else
 {
 spawn BLOOD
 ifrnd 96 { ai AIDEVPAIN  sound DEVIL_PAIN }
 ifwasweapon RPG setactor[THISACTOR].xvel -512
 ifwasweapon RADIUSEXPLOSION setactor[THISACTOR].xvel -512
 }
ends

state devdie
 ifai AIDEVDYING
 {
 ifactioncount 5
 {
 action ADEVDEAD
 cstat 0
 }
 }
ends

useractor enemy DEVIL DEVILSTR
  fall
  sizeat 65 65
  state checksquished

  ifrnd 4 soundonce DEVIL_ACT

  ifai 0
  {
  cstat 257
  ifcansee
  {
  ifrnd 128 soundonce DEVIL_SEE2 else soundonce DEVIL_SEE
  }
  }

  ifaction 0
  {
   ai AIDEVWALK
  }
  
  ifaction ADEVDEAD { state devdead break }
  else
  ifaction ADEVDIE
  {
  state devdie
  break
  }

  ifai AIDEVWALK { ifcansee { ifcanshoottarget { ifrnd 36 { ai AIDEVSHOOT resetactioncount } } } }

  ifai AIDEVSHOOT
  {
  ifactioncount 3
  {
  sound PRED_ATTACK
  shoot SERPENTBALL
  resetactioncount
  }
  else
  ifcount 30
  {
  ai AIDEVWALK
  }
  }

  ifai AIDEVSHOOT2 nullop else ifpdistl 1592 ai AIDEVSHOOT2

  ifai AIDEVSHOOT2
  {
  ifactioncount 3
  {
  ai AIDEVSHOOT2
  addphealth DEVILSCRATCH
  sound CLAW
  palfrom 16 16
  resetactioncount
  ifpdistg 1592 ai AIDEVWALK
  }
  }

  ifai AIDEVPAIN { ifactioncount 2 { ai AIDEVSHOOT } }

  ifhitweapon state devhit

enda

useractor enemystayput DEVILSTAYPUT DEVILSTR
 fall 
 sizeat 65 65
 state checksquished
 cactor DEVIL
enda
