IfOrdered
  tmpx = selforder
  tmpy = [RUNN]
  IfXIsEqualToY                //Everyone run away!
    tmpargument = 100
    SetTargetToSelf
    ChangeTargetClass      //Change back to the red soul
    tmpargument = 0
    SetContent
    tmpargument = 10        //10 seconds
    SetState

  tmpy = [POOF]
  IfXIsEqualToY                //Go away...
    GoPoof

  tmpy = [SOUL]
  IfXIsEqualToY                //Attacking mode!
    tmpargument = 0
    GetXY
    tmpx = tmpx + 1
    SetXY

  tmpy = [USUL]
  IfXIsEqualToY                //One retreats...
    tmpargument = 0
    GetXY
    tmpx = tmpx - 1
    SetXY

//Setup character
IfSpawned
  tmpargument = 0
  SetContent
  tmpargument = 0
  SetState
  ReaffirmCharacter

  //Attack counter
  tmpargument = 0
  tmpx = 0
  tmpy = 14
  SetXY

IfTimeOut
  tmpargument = rand & 15 + 10
  SetTime

  //Attack mode
  IfStateIs1
    SetTargetToWideEnemy
      IfTargetIsDressedUp
        tmpx = rand & 255 + targetx - 128
        tmpy = rand & 255 + targety - 128
        tmpturn = xyturnto + 16384
        tmpdistance = rand % 500 + targetspeedx + targetspeedz + targetspeedy
        Compass
        ClearWaypoints
        AddWaypoint

        //Fly up and down towards the target
        tmpargument = targetaltitude
        SetFlyHeight

        tmpargument = 0
        GetXY
        IfXIsEqualToY           //All souls attacking?
          tmpargument = [POOF]
          IssueOrder
          KillTarget
          tmpargument = 0
          SendMessage
          //TODO SOUND?
      Else
        tmpargument = 0
        SetState
        tmpargument = [USUL]      //Number of attackers is one less now
        IssueOrder
    Else
      tmpargument = 0
      SetState
      tmpargument = [USUL]      //Number of attackers is one less now
      IssueOrder

  //Follow mode
  IfStateIs0
    tmpx = rand & 255 + targetx - 128
    tmpy = rand & 255 + targety - 128
    tmpturn = xyturnto + 16384
    tmpdistance = rand % 500 + targetspeedx + targetspeedz + targetspeedy
    Compass

    //Attack something?
    SetTargetToNearbyEnemy
      IfTargetIsDressedUp
        DoNothing                   //Statues are marked as "dressy"
      Else
        tmpx = targetx
        tmpy = targety
        tmpturn = targetturnto
        tmpdistance = 1500
        Compass

        //Close enough to "attack"?
        tmpx = targetdistance
        tmpy = 150
        IfXIsLessThanY
          tmpargument = [SOUL]        //Number of attackers is one more now
          IssueOrder
          tmpargument = 1
          SetState
    ClearWaypoints
    AddWaypoint

    //Fly up and down towards the playah
    tmpargument = targetaltitude
    SetFlyHeight

//Go panic!
SetTargetToOwner
IfTargetIsAttacking
  tmpargument = 10		//10 seconds
  SetState
  tmpargument = [RUNN]
  IssueOrder

  tmpargument = 100
  SetTargetToSelf
  ChangeTargetClass      //Change back to the red soul
  tmpargument = 0
  SetContent

  //Reset attack counter too
  tmpargument = 0
  tmpx = 0
  tmpy = 14
  SetXY
IfTargetKilled
  tmpargument = 10		//10 seconds
  SetState
  tmpargument = [RUNN]
  IssueOrder

  tmpargument = 100
  SetTargetToSelf
  ChangeTargetClass      //Change back to the red soul
  tmpargument = 0
  SetContent

  //Reset attack counter too
  tmpargument = 0
  tmpx = 0
  tmpy = 14
  SetXY

// All done
End
