IF
	See(NearestEnemyOf(Myself))
        !GlobalTimerNotExpired("protimer","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("protimer","LOCALS",60)
                ReallyForceSpell(Myself,CLERIC_DEFENSIVE_HARMONY)
                ReallyForceSpell(Myself,CLERIC_CHANT)
                ReallyForceSpell(Myself,CLERIC_BLESS)
                ReallyForceSpell(Myself,CLERIC_SANCTUARY)
                ReallyForceSpell(Myself,CLERIC_IRONSKIN)
                ReallyForceSpell(Myself,CLERIC_SHIELD_OF_THE_ARCHONS)
                ReallyForceSpell(Myself,CLERIC_REGENERATE)
                ReallyForceSpell(Myself,CLERIC_PHYSICAL_MIRROR)
                ReallyForceSpell(Myself,CLERIC_ARMOR_OF_FAITH)
                ReallyForceSpell(Myself,CLERIC_PROTECTION_FROM_FIRE)
                ReallyForceSpell(Myself,CLERIC_PROTECTION_FROM_LIGHTNING)
                ReallyForceSpellRES("SPPR730",Myself)
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)
THEN
	RESPONSE #100
		ForceSpell(Myself,CLERIC_HEAL)
END

IF
	See(NearestEnemyOf(Myself))
        CheckStat(Myself,0,STONESKINS)
        GlobalLT("CI","LOCALS",7)
THEN
	RESPONSE #100
                IncrementGlobal("CI","LOCALS",1)
		ForceSpell(Myself,CLERIC_IRONSKIN)
END

IF
	See(NearestEnemyOfType([GOODCUTOFF.UNDEAD]))
        !GlobalTimerNotExpired("SUNRAY","LOCALS")
THEN
	RESPONSE #50
                SetGlobalTimer("SUNRAY","LOCALS",30)
		ForceSpell(Myself,CLERIC_SUNRAY)
                Continue()
	RESPONSE #50
		Turn()
END

IF
        Allegiance(LastSeenBy(Myself),PC)
        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)
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("POWERUP","LOCALS")
THEN
	RESPONSE #100
                SetGlobalTimer("POWERUP","LOCALS",60)
		ForceSpell(Myself,CLERIC_REGENERATE)
		ForceSpell(Myself,CLERIC_DRAW_UPON_HOLY_MIGHT)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        HP(NearestEnemyOf(Myself),1)
        !CheckStat(NearestEnemyOf(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
THEN
	RESPONSE #100
                EquipMostDamagingMelee()  
                ForceSpellRES("SPCL901",Myself)
		AttackReevaluate(LastSeenBy(Myself),30)
END

IF
	See(NearestEnemyOf(Myself))
        !HasItem("HARM",Myself)
THEN
	RESPONSE #100
                ReallyForceSpell(Myself,CLERIC_HARM)
                Continue()
END

IF
	See(NearestEnemyOf(Myself))
        HPPercentGT(NearestEnemyOf(Myself),10)
        !CheckStat(NearestEnemyOf(Myself),4,WIZARD_PROTECTION_FROM_MAGIC_WEAPONS)
        HasItem("HARM",Myself)
THEN
	RESPONSE #100
		AttackReevaluate(NearestEnemyOf(Myself),30)
END

IF
	See(NearestEnemyOf(Myself))
        ActionListEmpty()
        !GlobalTimerNotExpired("SummonDeva","LOCALS")
THEN
	RESPONSE #100
                ForceSpell(Myself,CLERIC_SUMMON_FALLEN_DEVA)
                SetGlobalTimer("SummonDeva","LOCALS",78)
END

IF
	See(NearestEnemyOf(Myself))
        ActionListEmpty()
        NumCreatureLT("SKELWASU",10)

        !GlobalTimerNotExpired("SummonUndead","LOCALS")
THEN
	RESPONSE #100
                ForceSpell(Myself,CLERIC_ANIMATE_DEAD)
                SetGlobalTimer("SummonUndead","LOCALS",6)
END

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