IF
  See("Cernd")  // Cernd
  !InParty("Cernd")  // Cernd
  Global("change","LOCALS",0)
THEN
  RESPONSE #100
    ReallyForceSpell("Cernd",CERND_BEAR)
    SetGlobal("change","LOCALS",1)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),4)
  HPPercentLT(Myself,40)
  HaveSpell(CLERIC_HEAL)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Range(LastSeenBy(Myself),4)
  CheckStat(Myself,0,124)
  HPPercentLT(Myself,50)
  HaveSpell(CLERIC_REGENERATE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  Global("Panther","LOCALS",0)
  HPLT(Myself,20)
THEN
  RESPONSE #100
    ReallyForceSpell(Myself,FALDORN_PANTHER)
    SetGlobal("Panther","LOCALS",1)
END

IF
  ActionListEmpty()
  Allegiance(Myself,ENEMY)
  Global("didOnce","LOCALS",0)
  OR(2)
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    ApplySpell(Myself,CLERIC_IRONSKIN)
    ApplySpell(Myself,CLERIC_PROTECTION_FROM_LIGHTNING)
    ApplySpell(Myself,CLERIC_REGENERATE)
    SetGlobal("didOnce","LOCALS",1)
    SetGlobalTimer("BPT","LOCALS",10)
END

IF
  ActionListEmpty()
  Global("Pickup","LOCALS",0)
  OR(2)
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    PickUpItem("STAF04")
    FillSlot(SLOT_WEAPON1)
    EquipItem("STAF04")
    SetGlobal("Pickup","LOCALS",1)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("didOnce","LOCALS",1)
  OR(2)
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    SetGlobal("didOnce","LOCALS",2)
    ReallyForceSpell(Myself,CLERIC_CHAOTIC_COMMANDS)
    ReallyForceSpell(Myself,CLERIC_FREE_ACTION)
    ForceSpell(LastSeenBy(Myself),CLERIC_CALL_LIGHTNING)
    SetGlobalTimer("BPT","LOCALS",10)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("didOnce","LOCALS",2)
  OR(2)
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    SetGlobal("didOnce","LOCALS",3)
    ReallyForceSpell(Myself,CLERIC_RESIST_FIRE)
    ReallyForceSpell(Myself,CLERIC_SLOW_POISON)
    ReallyForceSpell(Myself,CLERIC_MAGIC_RESISTANCE)
    ForceSpell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
    SetGlobalTimer("BPT","LOCALS",10)
END

IF
  ActionListEmpty()
  Global("didOnce","LOCALS",3)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    SetGlobal("didOnce","LOCALS",4)
    ReallyForceSpell(Myself,CLERIC_RIGHTEOUS_MAGIC)
    ReallyForceSpell(Myself,CLERIC_FLAME_BLADE)
    ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
    ForceSpell(LastSeenBy(Myself),CLERIC_POISON)
    SetGlobalTimer("BPT","LOCALS",10)
END
//////////////CLOUDLIKE  EFFECTS//////////////////////

IF
  CheckStat(Myself,11,180) // I'm in a stinking cloud
  CheckStatGT(Myself,5,INT)
  !StateCheck(Myself,STATE_SLEEPING) // not yet affected
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(2)
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStatGT(Myself,11,180) // I'm in a web,entangle, or grease spell
  CheckStatLT(Myself,15,180)
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,1,131) // I don't have free action
  CheckStatLT(Myself,1,WEB) //and not webbed up
  CheckStatLT(Myself,1,ENTANGLE) //nor entangled --I can move
  CheckStatGT(Myself,4,SAVEVSSPELL) //and I got a reasonable chance of failing a save throw (25%+)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,15,180) // I'm in an Ice Storm
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTCOLD) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,16,180) // I'm in a Cloudkill or Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTPOISON) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,17,180) // I'm in a Death Fog
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTACID) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

IF
  CheckStat(Myself,18,180) // Incendiary Cloud, Meteor Swarm or Fire Storm -- bad stuff
  CheckStatGT(Myself,5,INT)
  CheckStatLT(Myself,100,RESISTFIRE) // Not Immune
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  Range(LastSeenBy(Myself),16)
THEN
  RESPONSE #100
    SetInterrupt(FALSE)
    RunAwayFrom(LastSeenBy(Myself),30)
    SetInterrupt(TRUE)
END

// This is to try and keep them from going back in to whomp somebody
IF
  CheckStatLT(Myself,11,180) // No longer in the cloud effects
  CheckStatGT(Myself,5,INT)
  OR(3)
    Detect([0.0.MORNINGSTAR.FAIRY_NYMPH.65])
    Detect(NearestEnemyOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
    Detect(NearestMyGroupOfType([0.0.MORNINGSTAR.FAIRY_NYMPH.65]))
  !Range(LastSeenBy(Myself),16)
  Exists([EVILCUTOFF])
  !Range(NearestEnemyOf(Myself),2)
THEN
  RESPONSE #100
    EquipRanged()  //use your bow, then
    SmallWait(3)
    Continue()
END

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

IF
  StateCheck(Myself,STATE_SILENCED)
  GlobalLT("FAL_VOC","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("FAL_VOC","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_VOCALIZE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SANCTUARY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("FAL_CHE","LOCALS",0)
  CheckStat(Myself,0,SANCTUARY)
  HPPercentLT(Myself,50)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobal("FAL_CHE","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_SANCTUARY)
    ForceSpell(Myself,CLERIC_PROTECTION_FROM_FIRE)
    ForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    ForceSpell(Myself,CLERIC_BARKSKIN)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SLOW_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  GlobalLT("FAL_POIS","LOCALS",3)
  StateCheck(Myself,STATE_POISONED)
  HPPercentLT(Myself,76)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    IncrementGlobal("FAL_POIS","LOCALS",1)
    ForceSpell(Myself,CLERIC_SLOW_POISON)
END

IF
  ActionListEmpty()
  OR(4)
    CheckStatGT(Myself,0,120)
    CheckStatGT(Myself,0,SCRIPTINGSTATE4)
    CheckStatGT(Myself,61,SPELLFAILUREPRIEST)
    StateCheck(Myself,STATE_SILENCED)
  OR(3)
    See([GOODCUTOFF])
    See("Cernd")
    See([PC.0.0.DRUID_ALL])
THEN
  RESPONSE #100
    AttackReevaluate(LastSeenBy(Myself),45)
END

IF
  HPPercentLT(Myself,65)
  HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_CURE_SERIOUS_WOUNDS)
    SetInterrupt(TRUE)
END

IF
  HPPercentLT(Myself,70)
  HaveSpell(CLERIC_CURE_MEDIUM_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_CURE_MEDIUM_WOUNDS)
    SetInterrupt(TRUE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_IRONSKIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(Myself,0,STONESKINS)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_IRONSKIN)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CHAOTIC_COMMANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(4,4)
  CheckStat(Myself,0,119)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_CHAOTIC_COMMANDS)
END

IF
  OR(3)
    See([GOODCUTOFF])
    See("Cernd")  // Cernd
    See([PC.0.0.DRUID_ALL])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(INNATE_SUMMON_DREADWOLF)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(15,12)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),INNATE_SUMMON_DREADWOLF)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ANIMAL_SUMMONING_3)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(3,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_ANIMAL_SUMMONING_3)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_MISCAST_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(5,4)
  CheckStatLT(LastSeenBy(Myself),60,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),60,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_MISCAST_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_FLAME_STRIKE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(6,5)
  CheckStat(LastSeenBy(Myself),0,129)
  !CheckStatGT(LastSeenBy(Myself),65,RESISTMAGICFIRE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CALL_WOODLAND_BEINGS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(7,5)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreatureLT([EVILCUTOFF.0.FAIRY.FAIRY_NYMPH.0.SUMMONED],3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CALL_WOODLAND_BEINGS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CALL_LIGHTNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(8,6)
  AreaType(OUTDOOR)
  CheckStatLT(LastSeenBy(Myself),51,RESISTELECTRICITY)
  !StateCheck(LastSeenBy(Myself),0x00400010)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CALL_LIGHTNING)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SUMMON_INSECTS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(9,7)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  CheckStat(LastSeenBy(Myself),0,120)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  OR(5)
    Class(LastSeenBy(Myself),DRUID_ALL)
    Class(LastSeenBy(Myself),BARD_ALL)
    Class(LastSeenBy(Myself),CLERIC_ALL)
    Class(LastSeenBy(Myself),LONG_BOW)
    Class(LastSeenBy(Myself),SORCERER)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_SUMMON_INSECTS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(10,7)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  !StateCheck(LastSeenBy(Myself),STATE_POISONED)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_POISON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ANIMAL_SUMMONING_1)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(11,6)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_ANIMAL_SUMMONING_1)
END

IF
  ActionListEmpty()
  OR(2)
    General(LastSeenBy(Myself),HUMANOID)
    General(LastSeenBy(Myself),ANIMAL)
  HaveSpell(CLERIC_CHARM_PERSON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(12,4)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CHARM_PERSON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_COMMAND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(13,5)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  !StateCheck(LastSeenBy(Myself),0x102029) // state_harmless
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_COMMAND)
END

IF
  HaveSpell(CLERIC_DOOM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(14,5)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129)
    RandomNumLT(99,23)
  !StateCheck(LastSeenBy(Myself),0x102029) // state_harmless
  !StateCheck(LastSeenBy(Myself),STATE_SLEEPING)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_DOOM)
END

IF
  True()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackReevaluate(LastSeenBy(Myself),45)
END

