//------------------------------------------------------------------------------
//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 = 400
  SetTime
  IfStateIs1			//Only if leader is in combat
    tmpx = selfmorale
    tmpy = 7
    IfXIsLessThanY		//Max 5 monsters at the time -2 for each of the wings
      tmpx = rand % 100
      GetContent		//More monsters reduces chance for summoning even more
      tmpy = 16 - selfmorale *2 //Reduce with 2% for each monster summoned
      IfXIsLessThanY		//14% base chance if no monsters are summoned
        SetTargetToNearestEnemy
        tmpx = rand & 255 + targetx - 128
        tmpy = rand & 255 + targety - 128
        tmpdistance = rand % 100 + selfz + 25
        tmpturn = rand
        tmpargument = rand & 3	//Randomize monster type
        SetState
        IfStateIs0
          tmpargument = 42	//Demon
        IfStateIs1
          tmpargument = 37	//Eyeball
        IfStateIs2
          tmpargument = 55	//Fiend bug
        IfStateIs3
          tmpargument = 56	//Sabotager
        SpawnExactCharacterXYZ
          tmpargument = 6	//Spell effect
          SpawnExactParticle
          SetTargetToWhoeverIsHolding
          tmpargument = 896	//Costs 3.5 mana points
          CostTargetMana
          tmpargument = 1
          SendMessageNear
        tmpargument = 1		//Return to combat state
        SetState

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