IF
  Die()
THEN
  RESPONSE #100
    Shout(66)
END

IF
  Global("BPCHARM","LOCALS",1)
  !StateCheck(Myself,STATE_CHARMED)
THEN
  RESPONSE #100
    SetGlobal("BPCHARM","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  GlobalTimerNotExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  OR(2)
    See([GOODCUTOFF])
    See(LastHitter(Myself))
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
THEN
  RESPONSE #30
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
    RemoveSpell(CLERIC_INSECT_PLAGUE)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_ANIMATE_TREE)
    RemoveSpell(CLERIC_ANIMATE_TREE)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_DOLOROUS_DECAY)
    RemoveSpell(CLERIC_DOLOROUS_DECAY)
  RESPONSE #10
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_CALL_WOODLAND_BEINGS)
    RemoveSpell(CLERIC_CALL_WOODLAND_BEINGS)
END

IF
  GlobalTimerExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  !See([GOODCUTOFF])
  !See(LastHitter(Myself))
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
THEN
  RESPONSE #100
    DisplayStringHead(Myself,@1)
    SetGlobal("BPCHASER","LOCALS",0)
    ClearActions(Myself)
    Continue()
END

IF
  ActionListEmpty()
  Global("BP_SweetZone","LOCALS",0)
  OR(4)
    CheckStat(Myself,11,180)
    CheckStat(Myself,16,180)
    CheckStat(Myself,17,180)
    CheckStat(Myself,20,180)
THEN
  RESPONSE #100
    SetGlobal("BP_SweetZone","LOCALS",1)
    DisplayStringHead(Myself,@2)
    ForceSpell(Myself,CLERIC_ZONE_OF_SWEET_AIR)
END

IF
  TookDamage()
  Global("BPCHASER","LOCALS",0)
  !See(LastHitter(Myself))
  !See([GOODCUTOFF])
  OR(2)
    General(Myself,HUMANOID)
    General(Myself,GIANTHUMANOID)
  CheckStatGT(Myself,5,INT)
THEN
  RESPONSE #20
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #15
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_BARKSKIN)
    ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    ReallyForceSpell(Myself,CLERIC_PHYSICAL_MIRROR)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    ReallyForceSpell(Myself,CLERIC_ZONE_OF_SWEET_AIR)
    ReallyForceSpell(Myself,CLERIC_AID)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #15
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,NPC_BLADE_BARRIER)
    ReallyForceSpell(Myself,CLERIC_DEFENSIVE_HARMONY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #20
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_SANCTUARY)
    ReallyForceSpell(Myself,CLERIC_CHAOTIC_COMMANDS)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    RunAwayFrom(LastHitter(Myself),45)
  RESPONSE #20
    DisplayStringHead(Myself,@3)
    RunAwayFrom(LastHitter(Myself),45)
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  CheckStatLT(LastSeenBy(Myself),11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  OR(2)
    See(TenthNearest([GOODCUTOFF]))
    See(TenthNearest([PC]))
  CheckStatLT(LastSeenBy(Myself),11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackOneRound(LastSeenBy(Myself))
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  See(TenthNearest)
  CheckStatLT(TenthNearest,11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    MoveToObject(TenthNearest)
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
  OR(2)
    !Allegiance(Myself,EVILCUTOFF)
    !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
END

IF
  Range(NearestEnemyOf(Myself),2)
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(NearestEnemyOf(Myself),0,125)
THEN
  RESPONSE #80
    RunAwayFrom(NearestEnemyOf(Myself),4)
  RESPONSE #20
    Continue()
END

IF
  Global("SNAFU","LOCALS",0)
  OR(3)
    CheckStatGT(Myself,0,SCRIPTINGSTATE4)
    CheckStatGT(Myself,60,SPELLFAILUREPRIEST)
    StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",1)
END

IF
  Global("SNAFU","LOCALS",1)
  CheckStat(Myself,0,SCRIPTINGSTATE4)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
  !StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",0)
END

IF
  HPPercentLT(Myself,50)
  HaveSpell(CLERIC_REGENERATE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,124)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_REGENERATE)
    SetInterrupt(TRUE)
END

IF
  HPPercentLT(Myself,35)
  HaveSpell(CLERIC_HEAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    SetInterrupt(FALSE)
    Spell(Myself,CLERIC_HEAL)
    SetInterrupt(TRUE)
END

IF
  TargetUnreachable(LastSeenBy(Myself))
  Delay(3)
THEN
  RESPONSE #100
    ClearActions(Myself)
    Continue()
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,61)
  HaveSpell(CLERIC_SANCTUARY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,SANCTUARY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_SANCTUARY)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_IRONSKIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,STONESKINS)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    Spell(Myself,CLERIC_IRONSKIN)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  HPPercentLT(Myself,51)
  StateCheck(Myself,STATE_POISONED)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    Spell(Myself,CLERIC_NEUTRALIZE_POISON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ZONE_OF_SWEET_AIR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(4)
    CheckStat(Myself,11,180)
    CheckStat(Myself,16,180)
    CheckStat(Myself,17,180)
    CheckStat(Myself,20,180)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_ZONE_OF_SWEET_AIR)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_TRUE_SIGHT)
  CheckStat(Myself,0,118)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,118)
  Exists(NearestEnemyOf(Myself))
  OR(9)
    SpellCast([GOODCUTOFF],WIZARD_PROJECT_IMAGE)
    SpellCast([GOODCUTOFF],WIZARD_MISLEAD)
    StateCheck(NearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(SecondNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(ThirdNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(FourthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(FifthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    StateCheck(SixthNearestEnemyOfType([GOODCUTOFF]),0x60400010)
    NumCreatureGT([GOODCUTOFF.0.0.0.0.ILLUSIONARY],0)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@6)
    Spell(Myself,CLERIC_TRUE_SIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CHAOTIC_COMMANDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(6,3)
  CheckStat(Myself,0,119)
  OR(6)
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
    StateCheck(NearestMyGroupOfType,0x80103004) //confused, charmed, panic, sleep

THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_CHAOTIC_COMMANDS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_PROTECTION_FROM_FIRE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNum(4,3)
  CheckStatLT(Myself,91,RESISTFIRE)
  OR(6)
    HitBy([0],FIRE)
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    Exists(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    Spell(Myself,CLERIC_PROTECTION_FROM_FIRE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_REMOVE_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(ThirdNearestMyGroupOfType([EVILCUTOFF]),0x400010)
  OR(6)
    StateCheck(SixthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FifthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FourthNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(ThirdNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(SecondNearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
    StateCheck(NearestMyGroupOfType([EVILCUTOFF]),STATE_PANIC)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(ThirdNearestMyGroupOfType([EVILCUTOFF]),CLERIC_REMOVE_FEAR)
END



IF
  OR(3)
    !Race(NearestEnemyOf(Myself),MORNINGSTAR)
    !Class(NearestEnemyOf(Myself),FAIRY_NYMPH)
    !Specifics(NearestEnemyOf(Myself),65)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(28,22)
  OR(4)
    See([GOODCUTOFF.0.0.0.0.SUMMONED_DEMON])
    See([GOODCUTOFF.0.0.0.0.SUMMONED])
    See([GOODCUTOFF.0.0.0.SIMULACRUM])
    See([GOODCUTOFF.0.0.0.0.ILLUSIONARY])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,26)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
THEN
  RESPONSE #100
END


IF
  Race(LastSeenBy(Myself),MORNINGSTAR)
  Class(LastSeenBy(Myself),FAIRY_NYMPH)
  Specifics(LastSeenBy(Myself),65)
THEN
  RESPONSE #100
END

IF
  ActionListEmpty()
  OR(2)
    General(LastSeenBy(Myself),HUMANOID)
    General(LastSeenBy(Myself),ANIMAL)
  HaveSpell(CLERIC_CHARM_PERSON)
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  CheckStatLT(LastSeenBy(Myself),51,RESISTMAGIC)
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #80
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CHARM_PERSON)
  RESPONSE #20
    Continue()
END

IF
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #80
    Continue()
  RESPONSE #20
END


IF
  ActionListEmpty()
  Global("SNAFU","LOCALS",1)
THEN
  RESPONSE #100
    AttackReevaluate(LastSeenBy(Myself),45)
END

IF
  OR(2)
    CheckStatGT(Myself,0,SANCTUARY)
    StateCheck(Myself,0x400010)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    IncrementGlobal("BPIP","LOCALS",-1)
  RESPONSE #90
    RunAwayFrom(NearestEnemyOf(Myself),10)
END


IF
  RandomNumLT(26,18)
  OR(9)
    See([GOODCUTOFF.0.0.MONK])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.THIEF_ALL])
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.SORCERER])
    See([GOODCUTOFF.0.0.DRUID_ALL])
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(29,23)
  OR(7)
    See(SecondNearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(SecondNearestEnemyOfType([PC.0.0.SORCERER]))
    See(SecondNearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(SecondNearestEnemyOfType([PC.0.0.DRUID_ALL]))
  RandomNumLT(27,23)
  OR(7)
    See(ThirdNearestEnemyOfType([PC.0.0.RANGER_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.PALADIN_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.BARD_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.LONG_BOW]))
    See(ThirdNearestEnemyOfType([PC.0.0.SORCERER]))
    See(ThirdNearestEnemyOfType([PC.0.0.CLERIC_ALL]))
    See(ThirdNearestEnemyOfType([PC.0.0.DRUID_ALL]))
  RandomNumLT(32,18)
  OR(4)
    See(TenthNearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(TenthNearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
    See(TenthNearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
    See(TenthNearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
  RandomNumLT(20,8)
  See(TenthNearestEnemyOf(Myself))
  RandomNumLT(30,6)
  See(Protagonist)
  False()
THEN
  RESPONSE #100
    Continue()
END


IF
  ActionListEmpty()
  HaveSpell(CLERIC_SILENCE_15_FOOT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(35,25)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  CheckStat(LastSeenBy(Myself),0,MINORGLOBE)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  CheckStatGT(LastSeenBy(Myself),3,SAVEVSSPELL) // at -5 gives a 40% chance
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
  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)
  OR(3)
    !Range(LastSeenBy(Myself),16)
    !GlobalTimerNotExpired("BPVOCAL","LOCALS")
    CheckStatGT(Myself,74,RESISTMAGIC)
  OR(6)
    !Exists(NearestMyGroupOfType)
    Range(NearestMyGroupOfType,2)
    CheckStatLT(NearestMyGroupOfType,6,SAVEVSSPELL) // save at -5, thus 50% change
    CheckStatGT(NearestMyGroupOfType,49,RESISTMAGIC)
    CheckStatGT(NearestMyGroupOfType,0,MINORGLOBE)
    StateCheck(NearestMyGroupOfType,STATE_SILENCED)
  OR(6)
    !Exists(SecondNearestMyGroupOfType)
    Range(SecondNearestMyGroupOfType,3)
    CheckStatLT(NearestMyGroupOfType,6,SAVEVSSPELL)
    CheckStatGT(SecondNearestMyGroupOfType,49,RESISTMAGIC)
    CheckStatGT(NearestMyGroupOfType,0,MINORGLOBE)
    StateCheck(NearestMyGroupOfType,STATE_SILENCED)
  OR(6)
    !Exists(ThirdNearestMyGroupOfType)
    Range(ThirdNearestMyGroupOfType,4)
    CheckStatLT(ThirdNearestMyGroupOfType,6,SAVEVSSPELL)
    CheckStatGT(ThirdNearestMyGroupOfType,49,RESISTMAGIC)
    CheckStatGT(ThirdNearestMyGroupOfType,0,MINORGLOBE)
    StateCheck(ThirdNearestMyGroupOfType,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_SILENCE_15_FOOT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_INSECT_PLAGUE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(37,26)
  CheckStat(LastSeenBy(Myself),0,120)
  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)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ANIMATE_TREE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(39,29)
  !AreaType(DUNGEON)
  !AreaType(CITY)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreatureLT([EVILCUTOFF.0.TREANT.0.0.SUMMONED],3)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_ANIMATE_TREE)
END

IF
  ActionListEmpty()
  HaveSpell(TREANT_SUMMON_TREE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(41,28)
  !AreaType(DUNGEON)
  !AreaType(CITY)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  NumCreatureLT([EVILCUTOFF.0.TREANT.0.0.SUMMONED],4)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),TREANT_SUMMON_TREE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ANIMAL_SUMMONING_3)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(33,18)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_ANIMAL_SUMMONING_3)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CALL_WOODLAND_BEINGS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(34,18)
  NumCreatureLT([EVILCUTOFF.0.0.0.0.SUMMONED],7)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_CALL_WOODLAND_BEINGS)
END

IF
  ActionListEmpty()
  OR(2)
    General(LastSeenBy(Myself),HUMANOID)
    General(LastSeenBy(Myself),ANIMAL)
  HaveSpell(CLERIC_CHARM_PERSON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(44,21)
  !General(LastSeenBy(Myself),UNDEAD)
  OR(2)
    CheckStat(LastSeenBy(Myself),0,129) // either they have no spell turning
    RandomNumLT(99,23) //or we'll just shoot the moon
  !StateCheck(LastSeenBy(Myself),0x102029) // state_harmless
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  !StateCheck(LastSeenBy(Myself),STATE_BERSERK)
  !StateCheck(LastSeenBy(Myself),0x00400010) // STATE_NOT_VISIBLE
  CheckStatGT(LastSeenBy(Myself),5,SAVEVSSPELL)
  CheckStatLT(LastSeenBy(Myself),61,RESISTMAGIC)
  CheckStatLT(Myself,61,SPELLFAILUREPRIEST)
  OR(6)
    HPGT(LastSeenBy(Myself),25)
    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_CHARM_PERSON)
END

IF
  Global("BPMRC","LOCALS",0)
  OR(3)
    Class(Myself,DRUID)
    Class(Myself,FIGHTER_DRUID)
    Class(Myself,RANGER_ALL)
THEN
  RESPONSE #100
    SetGlobal("BPMRC","LOCALS",1)
    Continue()
END

IF
  Global("BPMRC","LOCALS",0)
  !Class(Myself,DRUID)
  !Class(Myself,FIGHTER_DRUID)
  !Class(Myself,RANGER_ALL)
THEN
  RESPONSE #100
    ChangeClass(Myself,DRUID)
    SetGlobal("BPMRC","LOCALS",1)
    Continue()
END


IF
  RandomNumLT(23,14)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.LONG_BOW]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(24,11)
  OR(4)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  RandomNumLT(25,10)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.MONK]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.THIEF_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
  RandomNumLT(21,7)
  OR(3)
    See(NearestEnemyOfType([GOODCUTOFF.0.0.FIGHTER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.RANGER_ALL]))
    See(NearestEnemyOfType([GOODCUTOFF.0.0.PALADIN_ALL]))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,25)
  OR(3)
    Heard(ThirdNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(SecondNearestMyGroupOfType([EVILCUTOFF]),124)
    Heard(NearestMyGroupOfType([EVILCUTOFF]),124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  Exists(LastAttackerOf(LastHeardBy(Myself)))
  !Allegiance(LastAttackerOf(LastHeardBy(Myself)),EVILCUTOFF)
  !StateCheck(LastAttackerOf(LastHeardBy(Myself)),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(LastHeardBy(Myself)),MORNINGSTAR)
    !Class(LastAttackerOf(LastHeardBy(Myself)),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(LastHeardBy(Myself)),65)
  OR(3)  
    !StateCheck(LastAttackerOf(LastHeardBy(Myself)),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(33,13)
  HitBy([0],0x0000)
  !Allegiance(LastHitter(Myself),EVILCUTOFF)
  !StateCheck(LastHitter(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
  OR(3)  
    !StateCheck(LastHitter(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumGT(33,22)
  AttackedBy([0],DEFAULT)
  !Allegiance(LastAttackerOf(Myself),EVILCUTOFF)
  !StateCheck(LastAttackerOf(Myself),STATE_CHARMED)
  OR(3)
    !Race(LastAttackerOf(Myself),MORNINGSTAR)
    !Class(LastAttackerOf(Myself),FAIRY_NYMPH)
    !Specifics(LastAttackerOf(Myself),65)
  OR(3)  
    !StateCheck(LastAttackerOf(Myself),0x00400010)
    CheckStatGT(Myself,0,SEEINVISIBLE)
    CheckStatGT(Myself,0,118)
  See(LastAttackerOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
THEN
  RESPONSE #100
END


IF
  Race(LastSeenBy(Myself),MORNINGSTAR)
  Class(LastSeenBy(Myself),FAIRY_NYMPH)
  Specifics(LastSeenBy(Myself),65)
THEN
  RESPONSE #100
END


IF
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #80
    Continue()
  RESPONSE #20
END


IF
  ActionListEmpty()
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
  OR(3)
    !Race(LastHitter(Myself),MORNINGSTAR)
    !Class(LastHitter(Myself),FAIRY_NYMPH)
    !Specifics(LastHitter(Myself),65)
THEN
  RESPONSE #30
    DisplayStringHead(Myself,49767)  // ~No more~
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    RunAwayFrom(LastHitter(Myself),40)
  RESPONSE #15
    DisplayStringHead(Myself,@6)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    Attack(LastHitter(Myself))
  RESPONSE #40
    DisplayStringHead(Myself,49766)  // ~I can't take this~
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastSeenBy(Myself),15)
END

IF
  ActionListEmpty()
  OR(2)
    CheckStatGT(NearestEnemyOf(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #25
    Continue()
  RESPONSE #75
END

IF
  ActionListEmpty()
  !Range(LastSeenBy(Myself),10)
THEN
  RESPONSE #90
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #90
    EquipMostDamagingMelee()
    AttackReevaluate(LastSeenBy(Myself),150)
END

IF
  ActionListEmpty()
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

