//------------------------------------------------------------------------------
//Make wings stop flapping
IfOrdered
  tmpx = selforder
  tmpy = [DEAD]
  IfXIsEqualToY
    tmpargument = ACTIONDA
    DoActionOverride
    KeepAction
    SetTargetToWhoeverIsHolding
    tmpargument = 0
    tmpx = targetx
    tmpy = targety
    tmpdistance = targetz
    SpawnExactParticle
    PoofTarget
    GoPoof
    SendMessageNear
    tmpargument = [UNDO]
    IssueOrder

  tmpy = [WAND]
  IfXIsEqualToY			//Master is wandering
    tmpargument = 0
    SetState

  tmpy = [COMB]
  IfXIsEqualToY			//Master is in combat
    tmpargument = 1
    SetState

//Summoning AI
IfTimeOut			//Every so often
  tmpargument = 150
  SetTime
  IfStateIs1			//Only if leader is in combat
    tmpx = selfmorale
    tmpy = 5
    IfXIsLessThanY		//Max 4 monsters at the time
      tmpx = rand & 100
      GetContent		//More monsters reduces chance for summoning even more
      tmpy = 12 - selfmorale *2 //Reduce with 2% for each monster summoned
      IfXIsLessThanY		//10% base chance if no monsters are summoned
        SetTargetToNearestEnemy
        tmpx = rand & 256 + targetx - 128
        tmpy = rand & 256 + targety - 128
        tmpdistance = rand & 100 + selfz + 25
        tmpturn = rand
        tmpargument = rand % 3	//Randomize monster type
        SetState
        IfStateIs0
          tmpargument = 62	//Demon
        IfStateIs1
          tmpargument = 45	//Eyeball
        IfStateIs2
          tmpargument = 98	//Ghoul
        SpawnExactCharacterXYZ
          tmpargument = 6	//Spell effect
          SpawnExactParticle
          tmpargument = 896	//Costs 3.5 mana points
          CostTargetMana
          tmpargument = 1
          SendMessageNear
        tmpargument = 1		//Return to combat state
        SetState

//------------------------------------------------------------------------------
End
//------------------------------------------------------------------------------
