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
  OR(2)
    Heard([NEUTRAL],79)
    Heard([EVILCUTOFF],79)
  Allegiance(Myself,NEUTRAL)
  !Global("BP_PlotMan","LOCALS",1)
THEN
  RESPONSE #100
    Enemy()
END

IF
  GlobalTimerNotExpired("BPCHASE","LOCALS")
  Global("BPCHASER","LOCALS",1)
  OR(2)
    See([GOODCUTOFF])
    See(LastHitter(Myself))
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_CONJURE_EARTH_ELEMENTAL)
    RemoveSpell(CLERIC_CONJURE_EARTH_ELEMENTAL)
  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_CREEPING_DOOM)
    RemoveSpell(CLERIC_CREEPING_DOOM)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
    RemoveSpell(CLERIC_FLAME_STRIKE)
  RESPONSE #10
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    ForceSpell(LastSeenBy(Myself),CLERIC_GREATER_COMMAND)
    RemoveSpell(CLERIC_GREATER_COMMAND)
END

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

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,PC)
  OR(2)
    AttackedBy([GOODCUTOFF],DEFAULT)
    Allegiance(LastAttackerOf(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Enemy()
    Shout(151)
    Continue()
END

IF
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,GOODCUTOFF)
  OR(2)
    HitBy([GOODCUTOFF],CRUSHING)
    Allegiance(LastHitter(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Shout(151)
    Enemy()
    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 #80
    SetGlobal("BP_SweetZone","LOCALS",1)
    DisplayStringHead(Myself,@2)
    ForceSpell(Myself,CLERIC_ZONE_OF_SWEET_AIR)
  RESPONSE #20
    SetGlobal("BP_SweetZone","LOCALS",1)
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 #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_SHIELD_OF_THE_ARCHONS)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_BARKSKIN)
    ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #5
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_MAGIC_RESISTANCE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,NPC_BLADE_BARRIER)
    ReallyForceSpell(Myself,CLERIC_ENERGY_BLADES)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_PHYSICAL_MIRROR)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #5
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_BARKSKIN)
    ReallyForceSpell(Myself,NPC_BLADE_BARRIER)
    ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    ReallyForceSpell(Myself,CLERIC_BLESS)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_PROTECTION_FROM_EVIL_10_FOOT)
    ReallyForceSpell(Myself,CLERIC_DEFENSIVE_HARMONY)
    ReallyForceSpell(Myself,CLERIC_STRENGTH_OF_ONE)
    ReallyForceSpell(Myself,CLERIC_BLESS)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #5
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    ReallyForceSpell(Myself,CLERIC_CHANT)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,CLERIC_TRUE_SIGHT)
    ReallyForceSpell(Myself,CLERIC_CHAOTIC_COMMANDS)
    ReallyForceSpell(Myself,CLERIC_SANCTUARY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    SetGlobalTimer("BPIP","LOCALS",15)
    IncrementGlobal("BPC","LOCALS",1)
    RunAwayFrom(LastHitter(Myself),45)
  RESPONSE #15
    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

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  See([ANYONE])
  CheckStatGT(LastSeenBy(Myself),10,180)
THEN
  RESPONSE #100
    SetGlobalTimer("BPCHASE","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@4)
    RunAwayFrom(LastSeenBy(Myself),15)
END

IF
  CheckStatGT(Myself,10,180)
  CheckStatGT(Myself,5,INT)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
  !See([GOODCUTOFF])
THEN
  RESPONSE #100
    SetGlobal("BPCHASER","LOCALS",1)
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    MoveToObject(Player1)
END

IF
  OR(2)
    !Allegiance(Myself,EVILCUTOFF)
    !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
END

IF
  Global("TURN","LOCALS",1)
  OR(3)
    GlobalTimerExpired("BPTurn","LOCALS")
    HPPercentLT(Myself,51)
    !See([GOODCUTOFF.UNDEAD])
THEN
  RESPONSE #100
    SetGlobal("TURN","LOCALS",0)
    SetGlobalTimer("BPTurn","LOCALS",0)
    ClearActions(Myself)
    SmallWait(5)
    Continue()
END

IF
  ActionListEmpty()
  SpellCast(Myself,0)
  HaveAnySpells()
  HitBy([ANYONE],CRUSHING)
  NumCreatureGT([EVILCUTOFF],3)
  !GlobalTimerNotExpired("SBN","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("SBN","LOCALS",15)
    DisplayStringHead(Myself,64573)
    Shout(69)
END

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

IF
  Global("TURN","LOCALS",1)
  OR(3)
    GlobalTimerExpired("BPTurn","LOCALS")
    HPPercentLT(Myself,51)
    !See([GOODCUTOFF.UNDEAD])
THEN
  RESPONSE #100
    SetGlobalTimer("BPTurn","LOCALS",0)
    ClearActions(Myself)
    SmallWait(5)
    Continue()
END

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

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

IF
  Global("TURN","LOCALS",1)
  GlobalTimerNotExpired("BPTurn","LOCALS")
  HPPercentGT(Myself,50)
  See([GOODCUTOFF.UNDEAD])
THEN
  RESPONSE #100
END

IF
  HPPercentLT(Myself,50)
  Global("BPNOHEAL","LOCALS",0)  
  Range(NearestEnemyOf(Myself),8)
  CheckStat(Myself,0,STONESKINS)
  CheckStat(Myself,0,128)
  OR(3)
    HaveSpell(CLERIC_HEAL)
    HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
    HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
THEN
  RESPONSE #100
    SetGlobal("BPNOHEAL","LOCALS",1)
    SmallWait(1)
    Continue()
END

IF
  HPPercentLT(Myself,50)
  Global("BPNOHEAL","LOCALS",0)  
  AttackedBy([ANYONE],RANGED)                                           // either we're NOT being attacked by archers, slingers, and dart throwers 
  CheckStat(Myself,0,SHIELDGLOBE)                                      // or we're protected against them
  CheckStat(Myself,0,122)
  CheckStat(Myself,0,STONESKINS)                                      // or we're protected against them
  CheckStat(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobal("BPNOHEAL","LOCALS",1)
    SmallWait(1)
    Continue()
END

IF
  HPPercentLT(Myself,35)
  HaveSpell(CLERIC_HEAL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(3)
    !Range(NearestEnemyOf(Myself),8)                                         // and I have space to cast
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
  OR(5)
    !AttackedBy([ANYONE],RANGED)                                           // either we're NOT being attacked by archers, slingers, and dart throwers 
    CheckStatGT(Myself,0,SHIELDGLOBE)                                      // or we're protected against them
    CheckStatGT(Myself,0,122)
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    Spell(Myself,CLERIC_HEAL)
    SetGlobal("BPNOHEAL","LOCALS",0)  
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
END

IF
  HPPercentLT(Myself,50)
  !GlobalTimerNotExpired("POT","LOCALS")
  HasItem("POTN55",Myself)
THEN
  RESPONSE #100
    SetGlobalTimer("POT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("POTN55",Myself)
END

IF
  HPPercentLT(Myself,55)
  HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(3)
    !Range(NearestEnemyOf(Myself),6)                                         // and I have space to cast
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
  OR(5)
    !AttackedBy([ANYONE],RANGED)                                           // either we're NOT being attacked by archers, slingers, and dart throwers 
    CheckStatGT(Myself,0,SHIELDGLOBE)                                      // or we're protected against them
    CheckStatGT(Myself,0,122)
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobal("BPNOHEAL","LOCALS",0)  
    Spell(Myself,CLERIC_CURE_CRITICAL_WOUNDS)
END

IF
  HPPercentLT(Myself,60)
  HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(3)
    !Range(NearestEnemyOf(Myself),6)                                         // and I have space to cast
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
  OR(5)
    !AttackedBy([ANYONE],RANGED)                                           // either we're NOT being attacked by archers, slingers, and dart throwers 
    CheckStatGT(Myself,0,SHIELDGLOBE)                                      // or we're protected against them
    CheckStatGT(Myself,0,122)
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobal("BPNOHEAL","LOCALS",0)  
    Spell(Myself,CLERIC_CURE_SERIOUS_WOUNDS)
END

IF
  HPPercentLT(Myself,65)
  HaveSpell(CLERIC_CURE_MEDIUM_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(2)
    RandomNumLT(17,6)
    CheckStatLT(Myself,28,MAXHITPOINTS)
  OR(3)
    !Range(NearestEnemyOf(Myself),4)                                         // and I have space to cast
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
  OR(5)
    !AttackedBy([ANYONE],RANGED)                                           // either we're NOT being attacked by archers, slingers, and dart throwers 
    CheckStatGT(Myself,0,SHIELDGLOBE)                                      // or we're protected against them
    CheckStatGT(Myself,0,122)
    CheckStatGT(Myself,0,STONESKINS)                                      // or we're protected against them
    CheckStatGT(Myself,0,128)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobal("BPNOHEAL","LOCALS",0)  
    Spell(Myself,CLERIC_CURE_MEDIUM_WOUNDS)
END

IF
  HPPercentLT(Myself,70)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  HaveSpell(CLERIC_CURE_LIGHT_WOUNDS)
  OR(2)
    RandomNumLT(16,4)
    CheckStatLT(Myself,16,MAXHITPOINTS)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobal("BPNOHEAL","LOCALS",0)  
    Spell(Myself,CLERIC_CURE_LIGHT_WOUNDS)
END

IF
  Global("BPNOHEAL","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("BPNOHEAL","LOCALS",0)
    RunAwayFrom(NearestEnemyOf(Myself),30)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,35)
  !GlobalTimerNotExpired("BPW","LOCALS")
  See([EVILCUTOFF])
  !HasItem("POTN55",Myself)
  !HasItem("POTN52",Myself)
  !HaveSpell(CLERIC_HEAL)
  !HaveSpell(CLERIC_CURE_CRITICAL_WOUNDS)
  !HaveSpell(CLERIC_CURE_SERIOUS_WOUNDS)
  !HaveSpell(CLERIC_CURE_MEDIUM_WOUNDS)
THEN
  RESPONSE #80
    SetGlobalTimer("BPW","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,72808)
    Shout(123)
  RESPONSE #20
    Continue()
END

IF
  StateCheck(Myself,STATE_POISONED)
  HasItem("potn17",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("potn17",Myself)
END

IF
  HaveSpell(CLERIC_SLOW_POISON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  StateCheck(Myself,STATE_POISONED)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_SLOW_POISON)
END

IF
  ActionListEmpty()
  StateCheck(Myself,STATE_POISONED)
  !GlobalTimerNotExpired("POIS","LOCALS")
  See([EVILCUTOFF])
  !HasItem("POTN17",Myself)
  !HasItem("POTN20",Myself)
  !HaveSpell(CLERIC_NEUTRALIZE_POISON)
  !HaveSpell(CLERIC_SLOW_POISON)
THEN
  RESPONSE #100
    Shout(83)
    DisplayStringHead(Myself,@5)
    SetGlobalTimer("POIS","LOCALS",ONE_ROUND)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  GlobalLT("BPC","LOCALS",3)
  Global("SNAFU","LOCALS",0)
THEN
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_SHIELD_OF_THE_ARCHONS)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_BARKSKIN)
    ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_SHIELD_OF_THE_ARCHONS)
    ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
    ReallyForceSpell(Myself,CLERIC_CHANT)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_MAGIC_RESISTANCE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,NPC_BLADE_BARRIER)
    ReallyForceSpell(Myself,CLERIC_PHYSICAL_MIRROR)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_PHYSICAL_MIRROR)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_BARKSKIN)
    ReallyForceSpell(Myself,NPC_BLADE_BARRIER)
    ReallyForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
    ReallyForceSpell(Myself,CLERIC_BLESS)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_TRUE_SIGHT)
    ReallyForceSpell(Myself,CLERIC_CHAOTIC_COMMANDS)
    ReallyForceSpell(Myself,CLERIC_SANCTUARY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_REGENERATE)
    ReallyForceSpell(Myself,CLERIC_IRONSKIN)
    ReallyForceSpell(Myself,CLERIC_CHANT)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
  RESPONSE #50
    ReallyForceSpell(Myself,CLERIC_PROTECTION_FROM_EVIL_10_FOOT)
    ReallyForceSpell(Myself,CLERIC_DEFENSIVE_HARMONY)
    ReallyForceSpell(Myself,CLERIC_STRENGTH_OF_ONE)
    ReallyForceSpell(Myself,CLERIC_BLESS)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("BPC","LOCALS",1)
END

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

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

IF
  ActionListEmpty()
  HaveSpell(CLERIC_TRUE_SIGHT)
  CheckStat(Myself,0,118)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Exists(LastAttackerOf(Myself))
  OR(8)
    !See([GOODCUTOFF])
    !See(LastAttackerOf(Myself))
    StateCheck(NearestEnemyOf(Myself),STATE_MIRRORIMAGE)
    StateCheck(NearestEnemyOf(Myself),STATE_ILLUSIONS)
    StateCheck(NearestEnemyOf(Myself),STATE_BLUR)
    Gender(NearestEnemyOf(Myself),ILLUSIONARY)
    Specifics(NearestEnemyOf(Myself),SIMULACRUM)
    Specifics(NearestEnemyOf(Myself),NEEDS_BREACH)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@6)
    Spell(Myself,CLERIC_TRUE_SIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_INVISIBILITY_PURGE)
  CheckStat(Myself,0,118)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(2)
    !See([GOODCUTOFF])
    !See(LastAttackerOf(Myself))
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,@6)
    Spell(Myself,CLERIC_INVISIBILITY_PURGE)
END

IF
  ActionListEmpty()
  HaveSpell(NPC_BLADE_BARRIER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,121)
  RandomNum(3,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,NPC_BLADE_BARRIER)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_PHYSICAL_MIRROR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,122)
  OR(2)
    AttackedBy([ANYONE],RANGED)
    HitBy([ANYONE],MISSILE)
  RandomNum(4,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_PHYSICAL_MIRROR)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_FREE_ACTION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,131)
  OR(4)
    RandomNumLT(16,5)
    StateCheck(Myself,STATE_HELPLESS)
    !CheckStat(Myself,0,WEB)
    !CheckStat(Myself,0,ENTANGLE)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_FREE_ACTION)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DEFENSIVE_HARMONY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,133)
  RandomNumLT(5,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_DEFENSIVE_HARMONY)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_STRENGTH_OF_ONE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStatLT(Myself,2,SCRIPTINGSTATE6)
  CheckStatLT(Myself,19,STR)
  CheckStatLT(Myself,50,STREXTRA)
  CheckStatLT([EVILCUTOFF],19,STR)
  CheckStatLT([EVILCUTOFF],50,STREXTRA)
  CheckStatLT(SecondNearest([EVILCUTOFF]),19,STR)
  CheckStatLT(SecondNearest([EVILCUTOFF]),50,STREXTRA)
  CheckStatLT(ThirdNearest([EVILCUTOFF]),19,STR)
  CheckStatLT(ThirdNearest([EVILCUTOFF]),50,STREXTRA)
  RandomNumLT(6,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_STRENGTH_OF_ONE)
END

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BPT","LOCALS")
  !CheckStatGT(Myself,17,STR)
  RandomNum(7,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN44",Myself)
    DisplayStringHead(Myself,46150)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_AID)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_AID)
  RandomNumLT(8,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_AID)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_BLESS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_BLESS)
  RandomNumLT(9,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_BLESS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_ARMOR_OF_FAITH)
  CheckStatLT(Myself,10,SCRIPTINGSTATE5)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  RandomNumLT(10,3)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_ARMOR_OF_FAITH)
END

IF
  ActionListEmpty()
  HasItem("potn10",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_INVISIBLE)
  RandomNumLT(11,7)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("potn10",Myself)
END

IF
  ActionListEmpty()
  HasItem("potn11",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(5)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  RandomNumLT(12,47)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    DisplayStringHead(Myself,46150)
    UseItem("potn11",Myself)
END

IF
  ActionListEmpty()
  HasItem("POTN19",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(Myself,18,DEX)
  RandomNumLT(13,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN19",Myself)
    DisplayStringHead(Myself,46150)
END

IF
  ActionListEmpty()
  HasItem("POTN28",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !CheckStatLT(Myself,18,CON)
  RandomNumLT(14,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN28",Myself)
    DisplayStringHead(Myself,46150)
END

IF
  ActionListEmpty()
  HasItem("POTN31",Myself)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(Myself,30,RESISTELECTRICITY)
  OR(6)
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
    HitBy([ANYONE],ELECTRICITY)
  RandomNumLT(15,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    UseItem("POTN31",Myself)
    DisplayStringHead(Myself,46150)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_DISPEL_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  See(SecondNearest([EVILCUTOFF]))
  OR(7)
     CheckStatGT(LastSeenBy(Myself),0,HELD)
     CheckStatGT(LastSeenBy(Myself),0,ENTANGLE)
     CheckStatGT(LastSeenBy(Myself),0,GREASE)
     CheckStatGT(LastSeenBy(Myself),0,WEB)
     StateCheck(LastSeenBy(Myself),STATE_OUT_OF_ACTION)
     StateCheck(LastSeenBy(Myself),STATE_SILENCED)
     StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  OR(2)
    !HasImmunityEffects(Myself)
    !Range(LastSeenBy(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_DISPEL_MAGIC)
END

IF
  ActionListEmpty()
  HitBy([GOODCUTOFF],CRUSHING)
  !GlobalTimerNotExpired("RANG","LOCALS")
  !StateCheck(Myself,STATE_POISONED)
  OR(3)
    Class(Myself,FIGHTER_CLERIC)
    Class(Myself,CLERIC_RANGER)
    Class(Myself,FIGHTER_MAGE_CLERIC)
  OR(2)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  !Range(LastSeenBy(Myself),7)
  !TargetUnreachable(LastSeenBy(Myself))
  !InWeaponRange(LastSeenBy(Myself))
  HPGT(LastSeenBy(Myself),0)
THEN
  RESPONSE #50
    DisplayStringHead(Myself,@7)
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #50
    DisplayStringHead(Myself,@8)
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #25
    DisplayStringHead(Myself,@9)
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #25
    DisplayStringHead(Myself,@10)
    SetGlobalTimer("RANG","LOCALS",ONE_ROUND)
  RESPONSE #50
    DisplayStringHead(Myself,@11)
    SetGlobalTimer("RANG","LOCALS",THREE_ROUNDS)
    EquipMostDamagingMelee()
    MoveToObject(LastSeenBy(Myself))
    AttackReevaluate(LastSeenBy(Myself),180)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_FREE_ACTION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(3)
    StateCheck([EVILCUTOFF],STATE_HELPLESS)
    !CheckStat([EVILCUTOFF],0,WEB)
    !CheckStat([EVILCUTOFF],0,ENTANGLE)
  !StateCheck([EVILCUTOFF],STATE_INVISIBLE)
  !StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([EVILCUTOFF],CLERIC_FREE_ACTION)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SLOW_POISON)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),83)
    Heard(SecondNearest([EVILCUTOFF]),83)
    Heard([EVILCUTOFF],83)
  Range(LastHeardBy(Myself),10)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  StateCheck(LastHeardBy(Myself),STATE_POISONED)
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),CLERIC_SLOW_POISON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_NEUTRALIZE_POISON)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),83)
    Heard(SecondNearest([EVILCUTOFF]),83)
    Heard([EVILCUTOFF],83)
  Range(LastHeardBy(Myself),10)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  StateCheck(LastHeardBy(Myself),STATE_POISONED)
  !StateCheck(LastHeardBy(Myself),STATE_INVISIBLE)
  !StateCheck(LastHeardBy(Myself),STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastHeardBy(Myself),CLERIC_NEUTRALIZE_POISON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_LESSER_RESTORATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  Range([EVILCUTOFF],15)
  CheckStatGT([EVILCUTOFF],0,LEVELDRAIN)
  !StateCheck([EVILCUTOFF],STATE_INVISIBLE)
  !StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([EVILCUTOFF],CLERIC_LESSER_RESTORATION)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_REMOVE_PARALYSIS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  Range([EVILCUTOFF],15)
  OR(2)
    StateCheck([EVILCUTOFF],STATE_HELPLESS)
    CheckStatGT([EVILCUTOFF],0,HELD)
  !StateCheck([EVILCUTOFF],STATE_INVISIBLE)
  !StateCheck([EVILCUTOFF],STATE_IMPROVEDINVISIBILITY)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell([EVILCUTOFF],CLERIC_REMOVE_PARALYSIS)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_REMOVE_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(6)
    StateCheck(SixthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FifthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(FourthNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(ThirdNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck(SecondNearest([EVILCUTOFF]),STATE_PANIC)
    StateCheck([EVILCUTOFF],STATE_PANIC)
  See(ThirdNearest([EVILCUTOFF]))
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(ThirdNearest([EVILCUTOFF]),CLERIC_REMOVE_FEAR)
END

IF
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(32,21)
  OR(3)
    Heard(ThirdNearest([EVILCUTOFF]),124)
    Heard(SecondNearest([EVILCUTOFF]),124)
    Heard([EVILCUTOFF],124)
  HPGT(LastHeardBy(Myself),1)
  Range(LastHeardBy(Myself),20)
  HPGT(LastHitter(LastHeardBy(Myself)),1)
  !See(LastHitter(LastHeardBy(Myself)))
  HPGT(LastAttackerOf(LastHeardBy(Myself)),1)
  !See(LastAttackerOf(LastHeardBy(Myself)))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  RandomNumLT(31,21)
  OR(6)
    See(NearestEnemyOf(Myself))
    See(WeakestOf)
    See(WorstAC)
    See(MostDamagedOf)
    See(LastAttackerOf(Myself))
    See(LastHitter(Myself))
  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])
  RandomNumLT(29,23)
  OR(7)
    See([PC.0.0.RANGER_ALL])
    See([PC.0.0.PALADIN_ALL])
    See([PC.0.0.BARD_ALL])
    See([PC.0.0.DRUID_ALL])
    See([PC.0.0.CLERIC_ALL])
    See([PC.0.0.LONG_BOW])
    See([PC.0.0.SORCERER])
  RandomNumLT(30,16)
  See(Protagonist)
  RandomNumLT(26,10)
  OR(4)
    See([GOODCUTOFF.0.0.RANGER_ALL])
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.PALADIN_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
  RandomNumLT(27,10)
  OR(3)
    See([GOODCUTOFF.0.0.MONK])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.THIEF_ALL])
  RandomNumLT(24,9)
  OR(3)
    See(StrongestOf)
    See(BestAC)
    See(LeastDamagedOf)
  RandomNumLT(25,9)
  See(WeakestOf)
  RandomNumLT(23,8)
  See(WorstAC)
  RandomNumLT(21,8)
  See(MostDamagedOf)
  RandomNumLT(32,11)
  OR(2)
    See(TenthNearest([GOODCUTOFF.0.0.LONG_BOW]))
    See(TenthNearest([GOODCUTOFF.0.0.SORCERER]))
  RandomNumLT(20,8)
  See(TenthNearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  OR(3)
    Allegiance(LastSeenBy(Myself),ENEMY)
    Allegiance(LastSeenBy(Myself),EVILCUTOFF)
    Allegiance(LastSeenBy(Myself),GOODBUTRED)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
THEN
  RESPONSE #100
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)
    StateCheck(Myself,STATE_INVISIBLE)
    StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  GlobalTimerNotExpired("BPIP","LOCALS")
THEN
  RESPONSE #15
    Continue()
  RESPONSE #60
    IncrementGlobal("BPIP","LOCALS",-1)
  RESPONSE #90
    RunAwayFrom(NearestEnemyOf(Myself),10)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CHARM_PERSON)
  Allegiance(LastSeenBy(Myself),EVILCUTOFF)
  StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  OR(2)
    General(LastSeenBy(Myself),HUMANOID)
    General(LastSeenBy(Myself),ANIMAL)
THEN
  RESPONSE #80
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CHARM_PERSON)
  RESPONSE #20
    Continue()
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SILENCE_15_FOOT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  !Range(LastSeenBy(Myself),15)
  !StateCheck(LastSeenBy(Myself),STATE_SILENCED)
  RandomNumLT(35,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_SILENCE_15_FOOT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_MISCAST_MAGIC)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),60,SPELLFAILUREMAGE)
  CheckStatLT(LastSeenBy(Myself),60,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)
  RandomNumLT(34,25)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_MISCAST_MAGIC)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CREEPING_DOOM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  CheckStat(LastSeenBy(Myself),0,120)
  RandomNumLT(36,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CREEPING_DOOM)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_INSECT_PLAGUE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  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)
  CheckStat(LastSeenBy(Myself),0,120)
  RandomNumLT(37,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_INSECT_PLAGUE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_SUNRAY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(2)
    General(LastSeenBy(Myself),UNDEAD)
    RandomNumLT(38,18)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_SUNRAY)
END

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

IF
  ActionListEmpty()
  General(LastSeenBy(Myself),UNDEAD)
  Range(LastSeenBy(Myself),15)
  !GlobalTimerNotExpired("BPTurn","LOCALS")
  Global("TURN","LOCALS",0)
  HPPercentGT(Myself,50)
  !Range([EVILCUTOFF.UNDEAD],15)
  RandomNumLT(44,12)
THEN
  RESPONSE #100
    SetGlobalTimer("BPTurn","LOCALS",TWO_ROUNDS)
    SetGlobal("TURN","LOCALS",1)
    Turn()
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_GREATER_COMMAND)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(40,23)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_GREATER_COMMAND)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_FINGER_OF_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  RandomNumLT(41,24)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
END

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

IF
  ActionListEmpty()
  HaveSpell(CLERIC_UNHOLY_BLIGHT)
  Alignment(LastSeenBy(Myself),MASK_GOOD)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !Alignment(Myself,MASK_GOOD)
  RandomNumLT(43,23)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_UNHOLY_BLIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_FLAME_STRIKE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGICFIRE)
  RandomNumLT(45,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CALL_LIGHTNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),50,RESISTELECTRICITY)
  AreaType(OUTDOOR)
  RandomNumLT(50,34)
THEN
  RESPONSE #100
    SetGlobal("BPT","LOCALS",6)
    Spell(LastSeenBy(Myself),CLERIC_CALL_LIGHTNING)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CAUSE_SERIOUS_WOUNDS)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !HasItem("SERIOUS",Myself)
  CheckStat(LastSeenBy(Myself),0,181)
  RandomNumLT(52,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CAUSE_SERIOUS_WOUNDS)
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_HOLD_PERSON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_HELPLESS)
  General(LastSeenBy(Myself),HUMANOID)
  RandomNumLT(55,41)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_HOLD_PERSON)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CLOAK_OF_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(57,27)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,CLERIC_CLOAK_OF_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(CLERIC_CHARM_PERSON)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  OR(2)
    General(LastSeenBy(Myself),HUMANOID)
    General(LastSeenBy(Myself),ANIMAL)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  RandomNumLT(44,21)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),CLERIC_CHARM_PERSON)
END

IF
  Global("BPRC","LOCALS",0)
  OR(2)
    Class(Myself,CLERIC_ALL)
    Class(Myself,PALADIN)
THEN
  RESPONSE #100
    SetGlobal("BPRC","LOCALS",1)
END

IF
  Global("BPRC","LOCALS",0)
THEN
  RESPONSE #100
    ChangeClass(Myself,CLERIC)
    SetGlobal("BPRC","LOCALS",1)
END

IF
  ActionListEmpty()
  HPPercentLT(Myself,25)
  Range(LastHitter(Myself),10)
  !GlobalTimerNotExpired("BPW","LOCALS")
THEN
  RESPONSE #30
    DisplayStringHead(Myself,49767)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    RunAwayFrom(LastHitter(Myself),40)
  RESPONSE #15
    DisplayStringHead(Myself,@12)
    Shout(124)
    SetGlobalTimer("BPW","LOCALS",10)
    Attack(LastHitter(Myself))
  RESPONSE #40
    DisplayStringHead(Myself,49766)
    Shout(123)
    SetGlobalTimer("BPW","LOCALS",10)
    AttackReevaluate(LastSeenBy(Myself),15)
END

IF
  ActionListEmpty()
  !HasItem("SERIOUS",Myself) 
  CheckStatGT(LastSeenBy(Myself),10,180)
  CheckStatLT(Myself,11,180)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItem("SERIOUS",Myself) 
  OR(3)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #100
    EquipRanged()
    AttackReevaluate(LastSeenBy(Myself),45)
END

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

IF
  ActionListEmpty()
  !Range(LastSeenBy(Myself),8)
THEN
  RESPONSE #90
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #90
    EquipMostDamagingMelee()
    MoveToObjectNoInterrupt(LastSeenBy(Myself))
    AttackReevaluate(LastSeenBy(Myself),135)
END

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

