IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer1","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer1","LOCALS",30)
                ApplySpell(Myself,CLERIC_DEFENSIVE_HARMONY)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer2","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer2","LOCALS",30)
                ApplySpell(Myself,CLERIC_CHANT)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer3","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer3","LOCALS",30)
                ApplySpell(Myself,CLERIC_BLESS)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer4","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer4","LOCALS",60)
                ForceSpell(Myself,CLERIC_SANCTUARY)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer5","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer5","LOCALS",60)
                ForceSpell(Myself,CLERIC_SHIELD_OF_THE_ARCHONS)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer6","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer6","LOCALS",60)
                ApplySpell(Myself,CLERIC_ARMOR_OF_FAITH)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer7","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer7","LOCALS",60)
                ForceSpell(Myself,CLERIC_PROTECTION_FROM_FIRE)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer8","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer8","LOCALS",60)
                ForceSpell(Myself,CLERIC_PROTECTION_FROM_LIGHTNING)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer9","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer9","LOCALS",60)
                ApplySpell(Myself,CLERIC_FREE_ACTION)
                Continue()
END

IF
	OR(2)
		See(SecondNearestMyGroupOfType)
		See(ThirdNearestMyGroupOfType)
	OR(2)
		HPPercentLT(SecondNearestMyGroupOfType,60)
		HPPercentLT(ThirdNearestMyGroupOfType,60)
THEN
	RESPONSE #100
		ForceSpell(LastSeenBy(Myself),CLERIC_MASS_CURE)
END

IF
        HPPercentLT(Myself,20)
        GlobalLT("HEAL","LOCALS",3)
THEN
	RESPONSE #100
                IncrementGlobal("HEAL","LOCALS",1)
		ForceSpell(Myself,CLERIC_HEAL)
END

IF
	See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,STONESKINS)
THEN
	RESPONSE #100
		ForceSpell(Myself,CLERIC_IRONSKIN)
                Continue()
END

IF
	See(NearestEnemyOfType([GOODCUTOFF.UNDEAD]))
THEN
	RESPONSE #50
		ForceSpell(Myself,CLERIC_SUNRAY)
                Continue()
	RESPONSE #50
		Turn()
END

IF
        See([ENEMY])
        OR(13)
          StateCheck(LastSeenBy(Myself), STATE_INVISIBLE)
          StateCheck(LastSeenBy(Myself), STATE_IMPROVEDINVISIBILITY)
          StateCheck(LastSeenBy(Myself), STATE_MIRRORIMAGE)
          StateCheck(LastSeenBy(Myself), STATE_HASTED)
	  HasBounceEffects(LastSeenBy(Myself))
	  HasImmunityEffects(LastSeenBy(Myself))
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_MAGIC_ENERGY)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_MISLEAD)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_TENSERS_TRANSFORMATION)
	  CheckStatGT(LastSeenBy(Myself),0,WIZARD_PROTECTION_FROM_ENERGY)
          CheckStatGT(LastSeenBy(Myself),0,STONESKINS)
          CheckStatGT(LastSeenBy(Myself),0,IMPROVEDHASTE)
        GlobalLT("CDM","LOCALS",7)
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
THEN
	RESPONSE #100
                IncrementGlobal("CDM","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),WIZARD_DISPEL_MAGIC)
                Continue()
END

IF
	See([ENEMY])
        !StateCheck(LastSeenBy(Myself), STATE_HELPLESS)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("CHP","LOCALS",5)
THEN
	RESPONSE #100
                IncrementGlobal("CHP","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_HOLD_PERSON)
END

IF
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("CSTATE","LOCALS",15)
THEN
	RESPONSE #20
                IncrementGlobal("CSTATE","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_RIGID_THINKING)
                Continue()
	RESPONSE #20
                IncrementGlobal("CSTATE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),CLERIC_FINGER_OF_DEATH)
                Continue()
	RESPONSE #20
                IncrementGlobal("CSTATE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),CLERIC_UNHOLY_WORD)
                Continue()
	RESPONSE #20
                IncrementGlobal("CSTATE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),CLERIC_CONFUSION)
                Continue()
	RESPONSE #20
                IncrementGlobal("CSTATE","LOCALS",1)
                ForceSpell(LastSeenBy(Myself),CLERIC_CHAOTIC_COMMANDS)
                Continue()
END

IF
        AreaType(OUTDOOR)
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself),80,RESISTMAGIC)
        OR(4)
          CheckStatLT(LastSeenBy(Myself),80,RESISTELECTRICITY)
          CheckStatLT(LastSeenBy(Myself),80,RESISTFIRE)
          CheckStatLT(LastSeenBy(Myself),80,RESISTCOLD)
          CheckStatLT(LastSeenBy(Myself),80,RESISTACID)
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("CMATT","LOCALS",20)
THEN
	RESPONSE #20
                IncrementGlobal("CMATT","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_STORM_OF_VENGEANCE)
                Continue()
	RESPONSE #20
                IncrementGlobal("CMATT","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_SUNRAY)
                Continue()
	RESPONSE #20
                IncrementGlobal("CMATT","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_FIRE_STORM)
                Continue()
	RESPONSE #20
                IncrementGlobal("CMATT","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_HOLY_SMITE)
                Continue()
	RESPONSE #20
                IncrementGlobal("CMATT","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_FLAME_STRIKE)
                Continue()
END

IF
        AreaType(OUTDOOR)
	See([ENEMY])
        CheckStatLT(LastSeenBy(Myself),100,RESISTELECTRICITY)
        CheckStatLT(LastSeenBy(Myself),100,RESISTMAGIC)
        !HasBounceEffects(LastSeenBy(Myself))
        !HasImmunityEffects(LastSeenBy(Myself))
	!InMyGroup(LastSeenBy(Myself))
        !Allegiance(LastSeenBy(Myself),EVILCUTOFF)
        GlobalLT("CMLIG","LOCALS",8)
THEN
	RESPONSE #50
                IncrementGlobal("CMLIG","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_CALL_LIGHTNING)
                Continue()
	RESPONSE #50
                IncrementGlobal("CMLIG","LOCALS",1)
		ForceSpell(LastSeenBy(Myself),CLERIC_BOLT_OF_GLORY)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("REGENERATE","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("REGENERATE","LOCALS",60)
		ForceSpell(Myself,CLERIC_REGENERATE)
END

IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("HOLYMIGHT","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("HOLYMIGHT","LOCALS",78)
		ForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
                Continue()
END

IF
        ActionListEmpty()
	See(NearestEnemyOf(Myself))
        !CheckStat(LastSeenBy(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
	!InMyGroup(LastSeenBy(Myself))
THEN
	RESPONSE #100
                ApplySpell(Myself,CLERIC_AURA_OF_FLAMING_DEATH)
		AttackReevaluate(LastSeenBy(Myself),30)
END

IF
        ActionListEmpty()
	!CombatCounter(0)
        !GlobalTimerNotExpired("Summon","LOCALS")
THEN
	RESPONSE #50
                SetGlobalTimer("Summon","LOCALS",78)
                ForceSpell(Myself,CLERIC_SUMMON_FALLEN_DEVA)
	RESPONSE #50
                SetGlobalTimer("Summon","LOCALS",120)
                ForceSpell(Myself,CLERIC_GREATER_ELEMENTAL_SWARM)
END

IF
	!See(NearestEnemyOf(Myself))
        GlobalGT("HEAL","LOCALS",0)
THEN
	RESPONSE #100
		SetGlobal("HEAL","LOCALS",0)
END

IF
	!InActiveArea(Myself)
        OR(6)
        GlobalGT("HEAL","LOCALS",0)
        GlobalGT("CI","LOCALS",0)
        GlobalGT("CHP","LOCALS",0)
        GlobalGT("CSTATE","LOCALS",0)
        GlobalGT("CMATT","LOCALS",0)
        GlobalGT("CMLIG","LOCALS",0)
THEN
	RESPONSE #100
	SetGlobal("HEAL","LOCALS",0)
        SetGlobal("CI","LOCALS",0)
        SetGlobal("CHP","LOCALS",0)
        SetGlobal("CSTATE","LOCALS",0)
        SetGlobal("CMATT","LOCALS",0)
        SetGlobal("CMLIG","LOCALS",0)
END