// Shouts

IF
  See(NearestEnemyOf(Myself))
  !Global("Seen","LOCALS",1)
  Difficulty(HARDEST)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
    SetGlobalTimer("IgnoreBounce","LOCALS",6)
    SetGlobalTimer("IgnoreImmunity","LOCALS",12)
    Shout(254)
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !Global("Seen","LOCALS",1)
  Difficulty(HARD)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
    SetGlobalTimer("IgnoreBounce","LOCALS",6)
    SetGlobalTimer("IgnoreImmunity","LOCALS",15)
    Shout(254)
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !Global("Seen","LOCALS",1)
  Difficulty(NORMAL)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
    SetGlobalTimer("IgnoreBounce","LOCALS",6)
    SetGlobalTimer("IgnoreImmunity","LOCALS",18)
    Shout(254)
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !Global("Seen","LOCALS",1)
  Difficulty(EASY)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
    SetGlobalTimer("IgnoreBounce","LOCALS",9)
    SetGlobalTimer("IgnoreImmunity","LOCALS",18)
    Shout(254)
    Continue()
END

IF
  See(NearestEnemyOf(Myself))
  !Global("Seen","LOCALS",1)
  Difficulty(EASIEST)
THEN
  RESPONSE #100
    SetGlobal("Seen","LOCALS",1)
    SetGlobalTimer("IgnoreBounce","LOCALS",9)
    SetGlobalTimer("IgnoreImmunity","LOCALS",21)
    Shout(254)
    Continue()
END

IF
  Heard([0.0.BEHOLDER],254)
  !See(NearestEnemyOf(Myself))
THEN
  RESPONSE #100
    MoveToObject(LastHeardBy(Myself))
END

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

// Damaging Eyestalks
// (If the RandomNum selects an eye the beholder doesn't have, we assume the dud stalk was hit.)
IF
  HitBy([ANYONE],CRUSHING)
  TookDamage()
  DamageTakenGT(15)
  HPPercentLT(Myself,65)
  RandomNum(5,1)
  Global("ParalyzeEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    SetGlobal("ParalyzeEyeLost","LOCALS",1)
    DisplayString(Myself,@289) // ~Eyestalk Destroyed~
END

IF
  HitBy([ANYONE],CRUSHING)
  TookDamage()
  DamageTakenGT(15)
  HPPercentLT(Myself,65)
  RandomNum(5,2)
  Global("CauseWoundsEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    SetGlobal("CauseWoundsEyeLost","LOCALS",1)
    DisplayString(Myself,@289) // ~Eyestalk Destroyed~
END

IF
  HitBy([ANYONE],CRUSHING)
  TookDamage()
  DamageTakenGT(15)
  HPPercentLT(Myself,65)
  RandomNum(5,3)
  Global("SlowEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    SetGlobal("SlowEyeLost","LOCALS",1)
    DisplayString(Myself,@289) // ~Eyestalk Destroyed~
END

IF
  HitBy([ANYONE],CRUSHING)
  TookDamage()
  DamageTakenGT(15)
  HPPercentLT(Myself,65)
  RandomNum(5,4)
  Global("HoldEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    SetGlobal("HoldEyeLost","LOCALS",1)
    DisplayString(Myself,@289) // ~Eyestalk Destroyed~
END

IF
  HitBy([ANYONE],CRUSHING)
  TookDamage()
  DamageTakenGT(15)
  HPPercentLT(Myself,40)
  RandomNum(5,5)
  Global("CentralEyeLost","LOCALS",0) // This isn't really the centre eye, I just can't be bothered to rename the variables
  !StateCheck(Myself,STATE_REALLY_DEAD)
THEN
  RESPONSE #100
    SetGlobal("CentralEyeLost","LOCALS",1)
    DisplayString(Myself,@289) // ~Eyestalk Destroyed~
END

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

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  Detect(Myself)
  See(Myself)
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  OR(3)
    !See(NearestEnemyOf(Myself))
    StateCheck(NearestEnemyOf(Myself),0x00000029)
    RandomNumGT(4,1)
  OR(3)
    !See(SecondNearestEnemyOf(Myself))
    StateCheck(SecondNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(5,2)
  OR(3)
    !See(ThirdNearestEnemyOf(Myself))
    StateCheck(ThirdNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(6,3)
  OR(3)
    !See(FourthNearestEnemyOf(Myself))
    StateCheck(FourthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(7,4)
  OR(3)
    !See(FifthNearestEnemyOf(Myself))
    StateCheck(FifthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(8,5)
  OR(3)
    !See(SixthNearestEnemyOf(Myself))
    StateCheck(SixthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(9,6)
  OR(3)
    !See(SeventhNearestEnemyOf(Myself))
    StateCheck(SeventhNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(10,7)
  OR(3)
    !See(EighthNearestEnemyOf(Myself))
    StateCheck(EighthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(11,8)
  OR(3)
    !See(NinthNearestEnemyOf(Myself))
    StateCheck(NinthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(12,9)
  OR(3)
    !See(TenthNearestEnemyOf(Myself))
    StateCheck(TenthNearestEnemyOf(Myself),0x00000029)
    RandomNumGT(13,11)
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

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

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  !GlobalTimerNotExpired("Lightning","LOCALS")
  Global("CentralEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_BLIND)
  See(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),0)
  See(LastSeenBy(Myself))
  RandomNumGT(8,3)
THEN
  RESPONSE #100
    //      SetGlobalTimer("Ray","LOCALS",2)
    SetGlobalTimer("Lightning","LOCALS",4)
    FaceObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),BEHOLDER_MAGIC_MISSILE)
END

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  !GlobalTimerNotExpired("CauseWounds","LOCALS")
  Global("CauseWoundsEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_BLIND)
  See(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),0)
  Range(LastSeenBy(Myself),5)
  See(LastSeenBy(Myself))
  RandomNumGT(7,3)
THEN
  RESPONSE #100
    //      SetGlobalTimer("Ray","LOCALS",2)
    SetGlobalTimer("CauseWounds","LOCALS",4)
    FaceObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),WIZARD_BURNING_HANDS)
END

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  !GlobalTimerNotExpired("Paralyze","LOCALS")
  Global("ParalyzeEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_BLIND)
  See(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),0)
  See(LastSeenBy(Myself))
  RandomNumGT(3,1)
THEN
  RESPONSE #100
    //      SetGlobalTimer("Ray","LOCALS",2)
    SetGlobalTimer("Paralyze","LOCALS",6)
    FaceObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),WIZARD_ICE_STORM)
END

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  !GlobalTimerNotExpired("Slow","LOCALS")
  Global("SlowEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_BLIND)
  See(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),0)
  See(LastSeenBy(Myself))
  RandomNumGT(4,1)
THEN
  RESPONSE #100
    //      SetGlobalTimer("Ray","LOCALS",2)
    SetGlobalTimer("Slow","LOCALS",6)
    FaceObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),BEHOLDER_SLOW)
END

IF
  //  !GlobalTimerNotExpired("Ray","LOCALS")
  !GlobalTimerNotExpired("Hold","LOCALS")
  Global("HoldEyeLost","LOCALS",0)
  !StateCheck(Myself,STATE_BLIND)
  See(LastSeenBy(Myself))
  !Range(LastSeenBy(Myself),0)
  See(LastSeenBy(Myself))
THEN
  RESPONSE #100
    //      SetGlobalTimer("Ray","LOCALS",2)
    SetGlobalTimer("Hold","LOCALS",6)
    FaceObject(LastSeenBy(Myself))
    ForceSpell(LastSeenBy(Myself),BEHOLDER_HOLD_PERSON)
END

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

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player1)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player1,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player1,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player1,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player1)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player2)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player2,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player2,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player2,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player2)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player3)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player3,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player3,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player3,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player3)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player4)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player4,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player4,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player4,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player4)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player5)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player5,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player5,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player5,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player5)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !Detect(Player6)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    CheckStat(Player6,0,SANCTUARY)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player6,STATE_INVISIBLE)
  OR(2)
    CheckStat(Myself,1,SEEINVISIBLE)
    !StateCheck(Player6,STATE_IMPROVEDINVISIBILITY)
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  HPPercentGT(Myself,50)
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(Player6)
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  !HPPercentGT(Myself,50)
  !Range(NearestMyGroupOfType([0.0.BEHOLDER]),5)
  InMyArea(NearestMyGroupOfType([0.0.BEHOLDER]))
THEN
  RESPONSE #100
    Shout(254) // Need a safe shout number, or an alternative to using shouts
    MoveToObject(NearestMyGroupOfType([0.0.BEHOLDER]))
END

IF
  !See(NearestEnemyOf(Myself))
  OR(2)
    !CheckStat(Myself,1,SEEINVISIBLE)
    !Detect(NearestEnemyOf(Myself))
  !StateCheck(Myself,STATE_CHARMED)
  Global("Seen","LOCALS",1)
  !HPPercentGT(Myself,50)
  OR(2)
    Range(NearestMyGroupOfType([0.0.BEHOLDER]),5)
    !InMyArea(NearestMyGroupOfType([0.0.BEHOLDER]))
THEN
  RESPONSE #100
    RandomWalkContinuous()
  RESPONSE #100
    Face(-1)
END

IF
  OR(5)
    !See(LastSeenBy(Myself))
    !GlobalTimerNotExpired("D0_ATTACK","LOCALS")
    StateCheck(Myself,STATE_CHARMED)
    !Allegiance(Myself,ENEMY)
    Allegiance(LastSeenBy(Myself),ENEMY)
  See(NearestEnemyOf(Myself))
  OR(2)
    StateCheck(NearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,3)
  See(SecondNearestEnemyOf(Myself))
  OR(2)
    StateCheck(SecondNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,4)
  See(ThirdNearestEnemyOf(Myself))
  OR(2)
    StateCheck(ThirdNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,5)
  See(FourthNearestEnemyOf(Myself))
  OR(2)
    StateCheck(FourthNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,3)
  See(FifthNearestEnemyOf(Myself))
  OR(2)
    StateCheck(FifthNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,3)
  See(SixthNearestEnemyOf(Myself))
  OR(2)
    StateCheck(SixthNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,3)
  See(TenthNearestEnemyOf(Myself))
  OR(2)
    StateCheck(TenthNearestEnemyOf(Myself),D0_STATE_DISABLED)
    RandomNumGT(10,3)
  !See(NearestEnemyOfType([GOODCUTOFF.0.0.SORCERER]))
  !See(NearestEnemyOfType([GOODCUTOFF.0.0.MAGE_ALL]))
  !See(NearestEnemyOfType([GOODCUTOFF.0.0.CLERIC_ALL]))
  !See(NearestEnemyOfType([GOODCUTOFF.0.0.BARD_ALL]))
  !See(NearestEnemyOfType([GOODCUTOFF.0.0.DRUID_ALL]))
  See(NearestEnemyOf(Myself))
  False()
THEN
  RESPONSE #100
    Continue()
END

IF
  !StateCheck(Myself,STATE_CHARMED)
  Allegiance(Myself,ENEMY)
  !Allegiance(LastSeenBy(Myself),ENEMY)
  OR(2)
    See(LastSeenBy(Myself))
    CheckStat(Myself,1,SEEINVISIBLE)
  OR(2)
    CheckStat(NearestEnemyOf(Myself),0,SANCTUARY)
    CheckStat(Myself,1,SEEINVISIBLE)
THEN
  RESPONSE #100
    SetGlobalTimer("D0_ATTACK","LOCALS",6)
    AttackOneRound(LastSeenBy(Myself))
END
