IfOrdered
  tmpx = selforder
  tmpy = [JOIN]
  IfXIsEqualToY                 //Another soul joined the player
    GetContent
    tmpargument = tmpargument + 1
    SetContent
    tmpargument = 14
    IfContentIs
      tmpargument = 101
      SetTargetToSelf
      ChangeTargetClass      //Change to the blue soul
      tmpargument = [FINI]
      IssueOrder
      tmpargument = 0
      SetState
  tmpy = [RUNN]
  IfXIsEqualToY                //Everyone run away!
    tmpargument = 0
    SetContent
  tmpy = [FINI]
  IfXIsEqualToY                //Make sure everyone is with us
    tmpargument = 101
    SetTargetToSelf
    ChangeTargetClass      //Change to the blue soul

//Setup character
IfSpawned
  tmpargument = 1
  SetState
  ReaffirmCharacter

  //Bad! I'm to lazy to do this in spawn.txt
  JoinGoodTeam

IfTimeOut

  //Wander mode
  IfStateIs1
    tmpx = rand % 2047 + selfx - 1024
    tmpy = rand % 2047 + selfy - 1024
    ClearWaypoints
    AddWaypoint
    tmpargument = rand % 65 + 50
    SetTime

  //Flock player mode
  IfStateIs0
    SetTargetToOwner
    tmpx = targetx
    tmpy = targety
    tmpturn = xyturnto + 16384
    tmpdistance = rand % 500 + targetspeedx + targetspeedz + targetspeedy
    Compass
    ClearWaypoints
    AddWaypoint
    tmpargument = rand & 15 + 10
    SetTime

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

  //Panic mode?
  tmpx = selfstate
  tmpy = 1
  IfXIsMoreThanY
    tmpargument = selfstate - 1
    SetState

    tmpx = rand % 2047 + selfspawnx - 1024
    tmpy = rand % 2047 + selfspawny - 1024
    ClearWaypoints
    AddWaypoint

    tmpargument = 50
    SetTime

//Go panic!
IfStateIs0
  SetTargetToOwner
  IfTargetIsAttacking
    tmpargument = 10		//10 seconds
    SetState
    tmpargument = [RUNN]
    IssueOrder
    tmpargument = 0
    SetContent
  IfTargetKilled
    tmpargument = 10		//10 seconds
    SetState
    tmpargument = [RUNN]
    IssueOrder
    tmpargument = 0
    SetContent

//Flock around the player if closer than 10 tiles
IfStateIs1
  tmpx = rand & 255
  tmpy = 12
  IfXIsLessThanY
    SetTargetToNearestLifeform
      IfTargetIsAPlayer
        tmpx = targetdistance
        tmpy = 128*10
        IfXIsLessThanY
          tmpargument = 0
          SetState
          tmpargument = [JOIN]
          IssueOrder
          SetOwnerToTarget

          //50% for a random taunt
          tmpx = rand & 1
          tmpy = 0
          IfXIsEqualToY
            tmpargument = rand % 11
            PlayFullSound

// All done
End
