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()
    Continue()
END

IF
  Global("BP_BOMB","LOCALS",2)
  See([PC])
THEN
  RESPONSE #100
    SetGlobal("BP_BOMB","LOCALS",0)
    SetGlobal("BP_BOMBSAWAY","MYAREA",0)
    SetGlobal("BP_CHASER","LOCALS",0)
    SetGlobal("BP_CHASE","LOCALS",0)
    SmallWait(10)
    ActionOverride("BPTARGET",DestroySelf())
END

IF
  Global("BP_BOMB","LOCALS",1)
THEN
  RESPONSE #100
    SetGlobal("BP_BOMB","LOCALS",2)
    ReallyForceSpellRES("BPTARGET",Myself)
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 #10
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
    AttackReevaluate(LastSeenBy(Myself),15)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #20
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
    RemoveSpell(WIZARD_NPC_SYMBOL_FEAR)
  RESPONSE #15
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_DEATH)
    RemoveSpell(WIZARD_NPC_SYMBOL_DEATH)
  RESPONSE #5
    DisplayStringHead(Myself,@0)
    SetGlobal("BPCHASER","LOCALS",0)
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
    RemoveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
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
  !Allegiance(Myself,ENEMY)
  !Allegiance(Myself,PC)
  OR(2)
    AttackedBy([GOODCUTOFF],DEFAULT)
    Allegiance(LastAttackerOf(Myself),GOODCUTOFF)
THEN
  RESPONSE #100
    Shout(151)
    Enemy()
    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
  Global("BP_BOMB","LOCALS",2)
  Global("BP_BOMBSAWAY","MYAREA",1)
  !GlobalTimerNotExpired("BPT","LOCALS")
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell("BPTARGET",WIZARD_ABI_DALZIMS_HORRID_WILTING)
    RemoveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell("BPTARGET",WIZARD_NPC_SYMBOL_STUN)
    RemoveSpell(WIZARD_NPC_SYMBOL_STUN)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell("BPTARGET",WIZARD_NPC_SYMBOL_FEAR)
    RemoveSpell(WIZARD_NPC_SYMBOL_FEAR)
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell("BPTARGET",WIZARD_FIREBALL)
    RemoveSpell(WIZARD_FIREBALL)
  RESPONSE #50
    SetGlobalTimer("BPT","LOCALS",6)
    ForceSpell("BPTARGET",WIZARD_DRAGONS_BREATH)
    RemoveSpell(WIZARD_DRAGONS_BREATH)
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,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ForceSpell(LastHitter(Myself),WIZARD_DIMENSION_DOOR)
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    ForceSpell(LastHitter(Myself),WIZARD_DIMENSION_DOOR)
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_ENERGY_BLADES)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    MoveToObject(LastHitter(Myself))
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    SetGlobalTimer("BPCHASE","LOCALS",12)
    SetGlobal("BPCHASER","LOCALS",1)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
    RunAwayFrom(LastHitter(Myself),45)
  RESPONSE #30
    DisplayStringHead(Myself,@3)
    SetGlobalTimer("BPCHASE","LOCALS",60)
    SetGlobal("BPCHASER","LOCALS",1)
    SetGlobal("BP_BOMB","LOCALS",1)
  RESPONSE #10
    DisplayStringHead(Myself,@2)
    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)
  CheckStatLT(TenthNearest,11,180)
  !GlobalTimerNotExpired("BPCHASE","LOCALS")
THEN
  RESPONSE #35
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@4)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_DIMENSION_DOOR)
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #65
    SetGlobalTimer("BPCHASE","LOCALS",TWO_ROUNDS)
    DisplayStringHead(Myself,@5)
    ActionOverride(LastSeenBy(Myself),ForceSpell([ENEMY.UNDEAD.LICH],WIZARD_DIMENSION_DOOR))
    Wait(1)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
    Wait(1)
    ForceSpell(TenthNearest,WIZARD_DIMENSION_DOOR)
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)
    ForceSpell(LastSeenBy(Myself),WIZARD_DIMENSION_DOOR)
    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()
    ForceSpell(LastSeenBy(Myself),WIZARD_DIMENSION_DOOR)
    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)
    ForceSpell(TenthNearest,WIZARD_DIMENSION_DOOR)
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)
    ForceSpell(Player1,WIZARD_DIMENSION_DOOR)
END

IF
  OR(2)
    !Allegiance(Myself,EVILCUTOFF)
    !Detect([GOODCUTOFF])
THEN
  RESPONSE #100
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("SNAFU","LOCALS",0)
  OR(4)
    CheckStatGT(Myself,1,120)
    CheckStatGT(Myself,60,SPELLFAILUREMAGE)
    CheckStatGT(Myself,0,SCRIPTINGSTATE4)
    StateCheck(Myself,STATE_SILENCED)
THEN
  RESPONSE #100
    SetGlobal("SNAFU","LOCALS",1)
END

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

IF
  Global("BPMRC","LOCALS",0)
  OR(3)
    Class(Myself,LONG_BOW)
    Class(Myself,BARD)
    Class(Myself,SORCERER)
THEN
  RESPONSE #100
    SetGlobal("BPMRC","LOCALS",1)
END

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

IF
  ActionListEmpty()
  !GlobalTimerNotExpired("CHE","LOCALS")
  Global("SNAFU","LOCALS",0)
  GlobalLT("SCH","LOCALS",4)
THEN
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_ABSOLUTE_IMMUNITY)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_BLACK_BLADE_OF_DISASTER)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_INVISIBILITY)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_IMPROVED_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_HASTE)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SPELL_SHIELD)
    ReallyForceSpell(Myself,WIZARD_STONE_SKIN)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_MISSILES)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_THE_ELEMENTS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_NORMAL_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_MINOR_SPELL_TURNING)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_MANTLE)
    ReallyForceSpell(Myself,WIZARD_SPELL_DEFLECTION)
    ReallyForceSpell(Myself,WIZARD_MELF_METEOR)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
  RESPONSE #50
    DisplayString(Myself,@6)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
    ReallyForceSpell(Myself,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
    ReallyForceSpell(Myself,WIZARD_SHADOW_DOOR)
    SetGlobalTimer("BPIP","LOCALS",15)
    SetGlobalTimer("CHE","LOCALS",ONE_TURN)
    IncrementGlobal("SCH","LOCALS",1)
END

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

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TRUE_SIGHT)
  CheckStat(Myself,0,118)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  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,@7)
    Spell(Myself,WIZARD_TRUE_SIGHT)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_TURNING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  OR(5)
    See([GOODCUTOFF.0.0.DRUID_ALL])
    See([GOODCUTOFF.0.0.BARD_ALL])
    See([GOODCUTOFF.0.0.CLERIC_ALL])
    See([GOODCUTOFF.0.0.LONG_BOW])
    See([GOODCUTOFF.0.0.SORCERER])
  CheckStat(Myself,0,129)
  CheckStat(Myself,0,164)
  CheckStat(Myself,0,116)
  RandomNumLT(7,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_SPELL_TURNING)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPROVED_INVISIBILITY)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  !StateCheck(Myself,STATE_INVISIBLE)
  !StateCheck(Myself,STATE_IMPROVEDINVISIBILITY)
  RandomNumLT(9,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPIP","LOCALS",15)
    Spell(Myself,WIZARD_IMPROVED_INVISIBILITY)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FIRE_SHIELD_RED)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Global("SNAFU","LOCALS",0)
  CheckStat(Myself,0,128)
  CheckStat(Myself,0,125)
  CheckStat(Myself,0,SHIELDGLOBE)
  Range(NearestEnemyOf(Myself),8)
  RandomNumLT(12,4)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_FIRE_SHIELD_RED)
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)
THEN
  RESPONSE #100
END

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

IF
  ActionListEmpty()
  CheckStatGT(Myself,0,182)
THEN
  RESPONSE #100
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  HPPercentGT(Myself,35)
  OR(4)
    Global("SNAFU","LOCALS",1)
    HasItem("BLAKBLAD",Myself)  // ~Black Blade of Disaster~
    HasItem("PHANBLAD",Myself)  // ~Phantom Blade~
    HasItem("MELFMET",Myself)  // ~Melf's Minute Meteor~
THEN
  RESPONSE #75
    AttackOneRound(LastSeenBy(Myself))
  RESPONSE #25
    Continue()
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
  Global("TRIGGER","LOCALS",0)
THEN
  RESPONSE #30
    SetGlobalTimer("BPT","LOCALS",3)
    SetGlobal("TRIGGER","LOCALS",1)
    DisplayStringHead(Myself,39968)
    DisplayString(Myself,@8)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_GREATER_MALISON)
    DisplayString(Myself,363)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
    DisplayString(Myself,743)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_CHAOS)
  RESPONSE #25
    SetGlobalTimer("BPT","LOCALS",3)
    SetGlobal("TRIGGER","LOCALS",1)
    DisplayStringHead(Myself,39968)
    DisplayString(Myself,45727)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
    DisplayString(Myself,40251)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_DISINTEGRATE)
    DisplayString(Myself,728)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_FLESH_TO_STONE)
  RESPONSE #25
    SetGlobalTimer("BPT","LOCALS",3)
    SetGlobal("TRIGGER","LOCALS",1)
    DisplayStringHead(Myself,39968)
    DisplayString(Myself,363)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
    DisplayString(Myself,363)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
    DisplayString(Myself,363)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_CHAIN_LIGHTNING)
  RESPONSE #20
    SetGlobalTimer("BPT","LOCALS",3)
    SetGlobal("TRIGGER","LOCALS",1)
    DisplayStringHead(Myself,39968)
    DisplayString(Myself,@9)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_TRUE_DISPEL_MAGIC)
    DisplayString(Myself,@10)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_PIERCE_MAGIC)
    DisplayString(Myself,@11)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_BREACH)
END 

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_SPELL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  Gender(LastSeenBy(Myself),SUMMONED)
  !Range(LastSeenBy(Myself),15)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_TIME_STOP)
  !GlobalTimerNotExpired("BPT","LOCALS")
  RandomNumLT(37,29)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_TIME_STOP)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_WAIL_OF_THE_BANSHEE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  NumCreatureVsPartyLT([ENEMY],2)
  RandomNumLT(35,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(Myself,WIZARD_WAIL_OF_THE_BANSHEE)
END


IF
  ActionListEmpty()
  HaveSpell(WIZARD_NPC_SYMBOL_STUN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_STUNNED)
  RandomNumLT(39,26)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_STUN)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_NPC_SYMBOL_FEAR)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_PANIC)
  RandomNumLT(42,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_FEAR)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_ABI_DALZIMS_HORRID_WILTING)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGIC)
  RandomNumLT(43,29)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_METEOR_SWARM)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),80,RESISTMAGICFIRE)
  CheckStatLT(LastSeenBy(Myself),80,RESISTMAGIC)
  !Range(LastSeenBy(Myself),15)
  RandomNumLT(44,28)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_IMPRISONMENT)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !CheckStat(LastSeenBy(Myself),1,SCRIPTINGSTATE4)
  RandomNumLT(46,22)
THEN
  RESPONSE #100
    Spell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DISINTEGRATE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatLT(LastSeenBy(Myself),70,RESISTMAGIC)
  RandomNumLT(49,27)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DISINTEGRATE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SPELL_STRIKE)
  !GlobalTimerNotExpired("BPT","LOCALS")
  OR(7)
    CheckStatGT(LastSeenBy(Myself),0,129)
    CheckStatGT(LastSeenBy(Myself),0,116)
    CheckStatGT(LastSeenBy(Myself),0,MINORGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,SHIELDGLOBE)
    CheckStatGT(LastSeenBy(Myself),0,162)
    CheckStatGT(LastSeenBy(Myself),0,177)
    CheckStatGT(LastSeenBy(Myself),0,164)
  !HaveSpell(WIZARD_PIERCE_SHIELD)
  RandomNumLT(52,34)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_FINGER_OF_DEATH)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatGT(LastSeenBy(Myself),6,SAVEVSDEATH)
  RandomNumLT(54,30)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_FINGER_OF_DEATH)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DEATH_SPELL)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  CheckStatGT(LastSeenBy(Myself),6,SAVEVSDEATH)
  !Range(LastSeenBy(Myself),15)
  RandomNumLT(55,33)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DEATH_SPELL)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_DOMINATION)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStat(LastSeenBy(Myself),0,129)
  !StateCheck(LastSeenBy(Myself),STATE_CHARMED)
  RandomNumLT(67,34)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_DOMINATION)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_POLYMORPH_OTHER)
  !GlobalTimerNotExpired("BPT","LOCALS")
  CheckStatLT(LastSeenBy(Myself),50,RESISTMAGIC)
  CheckStat(LastSeenBy(Myself),0,POLYMORPHED)
  CheckStat(LastSeenBy(Myself),0,129)
  HPGT(LastSeenBy(Myself),40)
  RandomNumLT(72,37)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
END

IF
  ActionListEmpty()
  HaveSpell(WIZARD_SLOW)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !StateCheck(LastSeenBy(Myself),STATE_SLOWED)
  RandomNumLT(73,39)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    Spell(LastSeenBy(Myself),WIZARD_SLOW)
END

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

IF
  ActionListEmpty()
  HaveSpell(WIZARD_LARLOCH_MINOR_DRAIN)
  !GlobalTimerNotExpired("BPT","LOCALS")
  !GlobalTimerNotExpired("BPVampT","LOCALS")
  HPPercentLT(Myself,90)
  RandomNumLT(79,27)
THEN
  RESPONSE #100
    SetGlobalTimer("BPT","LOCALS",ONE_ROUND)
    SetGlobalTimer("BPVampT","LOCALS",ONE_TURN)
    Spell(LastSeenBy(Myself),WIZARD_LARLOCH_MINOR_DRAIN)
END
IF
  ActionListEmpty()
  !GlobalTimerNotExpired("BP_LichCheese","LOCALS")
THEN
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_ABI_DALZIMS_HORRID_WILTING)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_NPC_SYMBOL_DEATH)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_WAIL_OF_THE_BANSHEE)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_METEOR_SWARM)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_IMPRISONMENT)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_SUMMON_EFREET)
    ReallyForceSpell(Myself,WIZARD_FIRE_SHIELD_RED)
  RESPONSE #10
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_ANIMATE_DEAD)
    ReallyForceSpell(LastSeenBy(Myself),WIZARD_ANIMATE_DEAD)
  RESPONSE #10
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_ANIMATE_DEAD)
    ReallyForceSpell(LastSeenBy(Myself),ENEMY_SUMMON_GHAST)
  RESPONSE #10
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_FLAME_ARROW)
  RESPONSE #5
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_POLYMORPH_OTHER)
  RESPONSE #10
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
    ForceSpell(LastSeenBy(Myself),WIZARD_SPELL_STRIKE)
    ReallyForceSpell(Myself,WIZARD_SPELL_TURNING)
  RESPONSE #25
    SetGlobalTimer("BP_LichCheese","LOCALS",12)
END

IF
  ActionListEmpty()
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
  CheckStatGT(LastSeenBy(Myself),10,180)
  CheckStatLT(Myself,11,180)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItem("BLAKBLAD",Myself)
  !HasItem("PHANBLAD",Myself)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
  OR(3)
    !Range(NearestEnemyOf(Myself),5)
    CheckStatGT(LastSeenBy(Myself),0,121)
    CheckStatGT(LastSeenBy(Myself),0,125)
THEN
  RESPONSE #100
    EquipRanged()
    AttackOneRound(LastSeenBy(Myself))
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)
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #90
    EquipMostDamagingMelee()
    AttackOneRound(NearestEnemyOf(Myself))
  RESPONSE #40
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

IF
  ActionListEmpty()
  !HasItemSlot(Myself,SLOT_MISC0)
  !HasItemSlot(Myself,SLOT_MISC1)
  !HasItemSlot(Myself,SLOT_MISC2)
THEN
  RESPONSE #100
    EquipMostDamagingMelee()
    AttackOneRound(LastSeenBy(Myself))
END

