/* BILLY RAY */


action ABILLYWALK      -66   8  5  1 11
action ABILLYRUN       -66   8  5  1 11
action ABILLYSHOOT       0   5  5  1 28
action ABILLYCOCK      -15   3  5  1 26
action ABILLYSTAND       0   1  1  1 40

action ABILLYDYING     -26  11  1  1 11
action ABILLYHIT        40   5  5  1 26
action ABILLYDEAD      -16   1  1  1  1
action ABILLYTRKDEAD    71   1  1  1  1


action ABILLYITCH       26   3  1  1 18
action ABILLYSCRATCH    29   3  1  1 18
action ABILLYSNIFF      32   7  1  1 11

action ABILLYJIBONE     66   1  1  1  1 
action ABILLYJIBTWO     66   5  1  1 12
action ABILLYJIBDEAD    70   1  1  1  1

move BILLYWALKVELS 72
move BILLYRUNVELS 108
move BILLYSTOPPED

ai AIBILLYSEEKENEMY  ABILLYWALK    BILLYWALKVELS seekplayer
ai AIBILLYSHOOTENEMY ABILLYSHOOT   BILLYSTOPPED faceplayer
ai AIBILLYFLEEENEMY  ABILLYWALK    BILLYWALKVELS fleeenemy
ai AIBILLYSHOOT      ABILLYSHOOT   BILLYSTOPPED faceplayer
ai AIBILLYDODGE      ABILLYRUN     BILLYRUNVELS dodgebullet
ai AIBILLYCHARGE     ABILLYRUN     BILLYRUNVELS seekplayer
ai AIBILLYDYING      ABILLYDYING   BILLYSTOPPED faceplayer
ai AIBILLYTRKDYING   ABILLYDYING   BILLYSTOPPED faceplayer
ai AIBILLYHIT        ABILLYHIT     BILLYSTOPPED faceplayer
ai AIBILLYITCH       ABILLYITCH    BILLYSTOPPED faceplayer
ai AIBILLYSCRATCH    ABILLYSCRATCH BILLYSTOPPED faceplayer
ai AIBILLYSNIFF      ABILLYSNIFF   BILLYSTOPPED faceplayer
ai AIBILLYJIBONE     ABILLYJIBONE  BILLYSTOPPED faceplayer
ai AIBILLYJIBTWO     ABILLYJIBTWO  BILLYSTOPPED faceplayer


state billyitchstate
  ifcount 18
  {
    ai AIBILLYSCRATCH
    sound BRSCRATH
  }
ends

state billyscratchstate
  ifactioncount 18
  {
      ai AIBILLYSNIFF
      sound BRSNIFF
  }
ends

state billysniffstate
  ifcount 18
  {
    ai AIBILLYSEEKENEMY
  }
ends


state billyseekenemystate
  ifactornotstayput
  {
     // Billy with set pal num 31 and 32
     //  shoot less and seek more (32 is also deaf)
     ifspritepal 31
     {
        ifrnd 8
        {
          ifp palive
            ifcansee
              ifcanshoottarget
            {
              ai AIBILLYSHOOTENEMY
              break
            }
        }
     }                
     else ifspritepal 32
     {
        ifrnd 8
        {
          ifp palive
            ifcansee
              ifcanshoottarget
            {
              ai AIBILLYSHOOTENEMY
              break
            }
        }
     }                
     // NN out of 256 times, if player is alive and billy can 
     // see player, switch ai to shoot 
     else ifrnd 32
     {
       ifp palive
         ifcansee
           ifcanshoottarget
           {
             ai AIBILLYSHOOTENEMY
             break
           }
     }
     else ifrnd 32 
     {
        ifpdistg 3084
        {
          ai AIBILLYSEEKENEMY    
          break
        }
     }

     // NN out of 256 times, if we get down here in 
     // the code and we're not moving
     // try opening a door to find player
     ifrnd 8
       ifnotmoving
         operate

  }
  // Else Billy Ray confined to home sector
  else
  {
    ifrnd 32
      ifp palive
        ifcansee
          ifcanshoottarget
        {
          ai AIBILLYSHOOTENEMY
          break
        }

    ifcount 48
    {
      ifrnd 8
        ifp palive
          ifcansee
            ifcanshoottarget
          {
            ifrnd 192
              ai AIBILLYSHOOTENEMY
            else
              ai AIBILLYFLEEENEMY
            break
          }
    }
  }
ends


state billyshootenemystate

    {

        ifrnd 2
          ifrnd 16
          {
              ai AIBILLYSCRATCH
              break
          }

        // Logic means when count = 12, and ifcanshoottarget
        //    shoot SHOTGUN
        ifcount 12 
            { } 
        else ifcount 11
        {
          ifcansee
            ifcanshoottarget
            { 
              sound BILLY_ATTACK 
              shoot SHOTGUN 
              shoot SHOTGUN 
              shoot SHOTGUN 
              shoot SHOTGUN 
              shoot SHOTGUN 
            }
            else 
                ai AIBILLYSEEKENEMY
        }

        // Logic means when count = 25, cock shotgun
        ifcount 25 
            { } 
        else ifcount 24 
        { 
            action ABILLYCOCK 
            sound SHOTGUN_COCK 
         
        }

        // Billy with set pal num 31 and 32
        //  shoot less and seek more (32 is also deaf)
        ifcount 46 
            { } 
        else ifcount 45
        {
            ifspritepal 31
            {
                action ABILLYWALK
                ifpdistl 768 
                    ai AIBILLYFLEEENEMY
                else
                    ai AIBILLYSEEKENEMY
                break
            }
            else ifspritepal 32
            {
                action ABILLYWALK
                ifpdistl 768 
                    ai AIBILLYFLEEENEMY
                else
                    ai AIBILLYSEEKENEMY
                break
            }
        }

        // Logic means when count = 48, and ifcanshoottarget
        //    shoot SHOTGUN
        ifcount 48 
            { } 
        else ifcount 47
        {
          ifcansee
            ifcanshoottarget 
            { 
                sound BILLY_ATTACK 
                shoot SHOTGUN 
                shoot SHOTGUN 
                shoot SHOTGUN 
                shoot SHOTGUN 
                shoot SHOTGUN 
            }
            else 
                ai AIBILLYSEEKENEMY
        }

        // Logic means when count = 60, cock shotgun
        ifcount 60 
        { } 
        else ifcount 59 
        { 
            action ABILLYCOCK 
            sound SHOTGUN_COCK 
        }

        // Logic means when count > 72, 
        // NN out of 256 times resetcount 
        // else either flee, or seek enemy
        ifcount 72
        {
            ifrnd 64 
                resetcount
            else
            {
                ifpdistl 768 
                    ai AIBILLYFLEEENEMY
                else
                    ai AIBILLYSEEKENEMY
                break
            }
        }

        ifaction ABILLYCOCK 
            ifactioncount 2 
                action ABILLYSHOOT


    }

ends

state billyfleeenemystate
  ifactioncount 8
  {
    ifrnd 32 
    {
      ai AIBILLYITCH
      sound BRITCH
    }
    else
      ai AIBILLYSEEKENEMY
  }
  else
    ifnotmoving
      ai AIBILLYITCH
ends

state checkbillyhitstate
  spawn BLOOD
  ifdead
  {
    state random_wall_jibs
    // state drop_shotgun
    addkills 1
    ifwasweapon SHOTGUN
    {
      state drop_shotgun
    }
    ifwasweapon SHOTSPARK1
    {
      state drop_shotgun
    }
    ifwasweapon RADIUSEXPLOSION
    {
       state drop_shotgun
       sound SQUISHED
       spawn BLOODPOOL
       state nf
       ai AIBILLYJIBONE
       break
    }
    else
      ifwasweapon CROSSBOW
      {
        state drop_shotgun
        sound SQUISHED
        state standard_jibs
        killit
      }
    else
    {
      ai AIBILLYDYING
    }
    sound BILLY_DYING
  }
  else
  {
    sound BILLY_PAIN
    state random_wall_jibs

    ifrnd 64
        ai AIBILLYHIT
    else
      ifrnd 64
        ai AIBILLYSHOOTENEMY
    else
      ifrnd 64
      {
        ai AIBILLYFLEEENEMY
        action ABILLYWALK
      }
  }
ends

state billydyingstate
  ifactioncount 11
  {
    ifrnd 64
      spawn BLOODPOOL
    state bf
    iffloordistl 8
      sound THUD
    action ABILLYDEAD
    move BILLYSTOPPED
    break
  }
ends

state billytrkdyingstate
  ifactioncount 5
  {
    spawn BLOODPOOL
    state nf
    iffloordistl 8
      sound THUD
    action ABILLYTRKDEAD
    move BILLYSTOPPED
    break
  }
ends

state billyjibbedstate
  ifai AIBILLYJIBTWO
    ifactioncount 5
    {
      iffloordistl 8
        sound THUD
      action ABILLYJIBDEAD
      move BILLYSTOPPED
      break
    }
ends

actor BILLYRAYSTAYPUT BILLYRAYSTRENGTH ABILLYSTAND
  ai AIBILLYSEEKENEMY
  cactor BILLYRAY
enda

actor BILLYRAY BILLYRAYSTRENGTH ABILLYSTAND
  fall
  state checksquished
  ifaction ABILLYSTAND
    ai AIBILLYSEEKENEMY
  else
    ifaction ABILLYDEAD
  {
      strength 0
      ifhitweapon
        ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
  }
  else ifaction ABILLYJIBONE
  {
    strength 0

    ifactioncount 30
    {    
      ai AIBILLYJIBTWO
      break
    }
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
  }
  else ifaction ABILLYJIBDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
  }
  else ifaction ABILLYTRKDEAD
  {
    strength 0
    ifhitweapon
      ifwasweapon RADIUSEXPLOSION
      {
        sound SQUISHED
        state standard_jibs
        killit
      }
      break
  }
  else
    ifai AIBILLYDYING
      state billydyingstate
  else
    ifai AIBILLYTRKDYING
      state billytrkdyingstate
  else
    ifai AIBILLYJIBONE
      state billyjibbedstate
  else
    ifai AIBILLYJIBTWO
      state billyjibbedstate
  else
    ifai AIBILLYHIT
    {
      ifactioncount 3
      ai AIBILLYSEEKENEMY
    }
  else
  {
    ifai AIBILLYSEEKENEMY
      state billyseekenemystate
    else
      ifai AIBILLYDODGE
        state billyseekenemystate
    else
      ifai AIBILLYSHOOTENEMY
        state billyshootenemystate
    else
      ifai AIBILLYFLEEENEMY
        state billyfleeenemystate
    else
      ifai AIBILLYCHARGE
        state billyseekenemystate
    else
      ifai AIBILLYITCH
        state billyitchstate
    else
      ifai AIBILLYSCRATCH
        state billyscratchstate
    else
      ifai AIBILLYSNIFF
        state billysniffstate
        
    ifhittruck
    {
        ai AIBILLYTRKDYING
        break
    }
    else ifhitweapon
      state checkbillyhitstate

    ifrnd 1
    { 
      ifrnd 32
        soundonce BILLY_ROAM
      else
        ifrnd 64
          soundonce BILLY_ROAM2
      else
        soundonce BILLY_ROAM3
    }

  }
enda


