#Spell system and FfH specific callout python functions
#All code by Kael, all bugs by woodelf

from CvPythonExtensions import *
import CvUtil
import Popup as PyPopup
import CvScreensInterface
import sys
import PyHelpers
import CustomFunctions
import ScenarioFunctions

PyInfo = PyHelpers.PyInfo
PyPlayer = PyHelpers.PyPlayer
gc = CyGlobalContext()
cf = CustomFunctions.CustomFunctions()
sf = ScenarioFunctions.ScenarioFunctions()


def cast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	eval(spell.getPyResult())

def canCast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	return eval(spell.getPyRequirement())

def effect(argsList):
	pCaster, eProm = argsList
	prom = gc.getPromotionInfo(eProm)
	eval(prom.getPyPerTurn())

def atRange(argsList):
	pCaster, pPlot, eImp = argsList
	imp = gc.getImprovementInfo(eImp)
	eval(imp.getPythonAtRange())

def onMove(argsList):
	pCaster, pPlot, eImp = argsList
	imp = gc.getImprovementInfo(eImp)
	eval(imp.getPythonOnMove())

def onMoveFeature(argsList):
	pCaster, pPlot, eFeature = argsList
	feature = gc.getFeatureInfo(eFeature)
	eval(feature.getPythonOnMove())

def vote(argsList):
	eVote, int = argsList
	vote = gc.getVoteInfo(eVote)
	eval(vote.getPyResult())

def miscast(argsList):
	pCaster, eSpell = argsList
	spell = gc.getSpellInfo(eSpell)
	eval(spell.getPyMiscast())

def postCombatLost(argsList):
	pCaster, pOpponent = argsList
	unit = gc.getUnitInfo(pCaster.getUnitType())
	eval(unit.getPyPostCombatLost())

def postCombatWon(argsList):
	pCaster, pOpponent = argsList
	unit = gc.getUnitInfo(pCaster.getUnitType())
	eval(unit.getPyPostCombatWon())

def findClearPlot(pUnit, plot):
	BestPlot = -1
	iBestPlot = 0
	if pUnit == -1:
		iX = plot.getX()
		iY = plot.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				iCurrentPlot = 0
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					if pPlot.getNumUnits() == 0:
						if (pPlot.isWater() == plot.isWater() and pPlot.isPeak() == False and pPlot.isCity() == False):
							iCurrentPlot += 5
					if iCurrentPlot >= 1:
						iCurrentPlot = iCurrentPlot + CyGame().getSorenRandNum(5, "findClearPlot")
						if iCurrentPlot >= iBestPlot:
							BestPlot = pPlot
							iBestPlot = iCurrentPlot
		return BestPlot
	iX = pUnit.getX()
	iY = pUnit.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			iCurrentPlot = 0
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.getNumUnits() == 0:
					if pUnit.canMoveOrAttackInto(pPlot, False):
						iCurrentPlot += 5
				for i in range(pPlot.getNumUnits()):
					if pPlot.getUnit(i).getOwner() == pUnit.getOwner():
						if pUnit.canMoveOrAttackInto(pPlot, False):
							iCurrentPlot += 15
				if pPlot.isCity():
					if pPlot.getPlotCity().getOwner() == pUnit.getOwner():
						iCurrentPlot += 50
				if (iX == iiX and iY == iiY):
					iCurrentPlot = 0
				if iCurrentPlot >= 1:
					iCurrentPlot = iCurrentPlot + CyGame().getSorenRandNum(5, "findClearPlot")
					if iCurrentPlot >= iBestPlot:
						BestPlot = pPlot
						iBestPlot = iCurrentPlot
	return BestPlot

def postCombatConsumePaladin(pCaster, pOpponent):
	if (pOpponent.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_PALADIN')):
		pCaster.setDamage(0, pCaster.getOwner())
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CONSUME_PALADIN", ()),'',1,'Art/Interface/Buttons/Units/Beast of Agares.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)

def postCombatDonal(pCaster, pOpponent):
	if (pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON')) or pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD'))):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RECRUITER'), True)

def postCombatExplode(pCaster, pOpponent):
	iX = pCaster.getX()
	iY = pCaster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			if not (iiX == iX and iiY == iY):
				pPlot = CyMap().plot(iiX,iiY)
				if pPlot.isNone() == False:
					if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
						if CyGame().getSorenRandNum(100, "Flames Spread") < gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
							bValid = True
							iImprovement = pPlot.getImprovementType()
							if iImprovement != -1 :
								if gc.getImprovementInfo(iImprovement).isPermanent() :
									bValid = False
							if bValid:
								pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
					for i in range(pPlot.getNumUnits()):
						pUnit = pPlot.getUnit(i)
						pUnit.doDamage(10, 99, pCaster, gc.getInfoTypeForString('DAMAGE_FIRE'), False)

def postCombatHealSelf(pCaster, amount):
	if pCaster.getDamage() > 0:
		pCaster.changeDamage(-amount,0)

def postCombatIra(pCaster, pOpponent):
	if pOpponent.isAlive():
		if pCaster.baseCombatStr() < 32:
			pCaster.setBaseCombatStr(pCaster.baseCombatStr() - pCaster.getTotalDamageTypeCombat() + 1)
			pCaster.setBaseCombatStrDefense(pCaster.baseCombatStrDefense() - pCaster.getTotalDamageTypeCombat() + 1)

def postCombatMimic(pCaster, pOpponent):
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
	iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE')
	iDivine2 = gc.getInfoTypeForString('PROMOTION_DIVINE2')
	iGreatCommander = gc.getInfoTypeForString('PROMOTION_GREAT_GENERAL')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	iHN = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iRusted = gc.getInfoTypeForString('PROMOTION_RUSTED')
	listProms = []
	iCount = 0
	for iProm in range(gc.getNumPromotionInfos()):
		if pCaster.isHasPromotion(iProm):
			iCount += 1
		else:
			if (pOpponent.isHasPromotion(iProm)):
				if gc.getPromotionInfo(iProm).isEquipment() == False:
					if (iProm != iChanneling3 and iProm != iDivine and iProm != iDivine2 and iProm != iBronze and iProm != iIron and iProm != iMithril and iProm != iGreatCommander and iProm != iRusted):
						if gc.getPromotionInfo(iProm).isRace() == False:
							if ((iProm != iHN) or (pCaster.getGroup().getNumUnits()==1)):
								listProms.append(iProm)
	if len(listProms) > 0:
		iCount += 1
		iRnd = CyGame().getSorenRandNum(len(listProms), "Mimic")
		pCaster.setHasPromotion(listProms[iRnd], True)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_PROMOTION_STOLEN", ()),'',1,gc.getPromotionInfo(listProms[iRnd]).getButton(),ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if iCount >= 20:
		pPlayer = gc.getPlayer(pCaster.getOwner())
		if pPlayer.isHuman():
			t = "TROPHY_FEAT_MIMIC_20"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)


def postCombatAcheron(pCaster, pOpponent):
	if not pCaster.isImmortal():
		pPlayer = gc.getPlayer(pOpponent.getOwner())
		if pPlayer.isHuman():
			t = "TROPHY_DEFEATED_ACHERON"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)



def postCombatArs(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_ARS"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)


def postCombatAuricAscendedWon(pCaster, pOpponent,sLeader, sTrophy):


	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_NETHER_BLADE')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_NETHERBIND'))
		while pCaster.isImmortal():
			pCaster.changeImmortal(-1)
		pCaster.kill(True, pOpponent.getOwner())
	if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GODSLAYER')):
		while pCaster.isImmortal():
			pCaster.changeImmortal(-1)
		pCaster.kill(True, pOpponent.getOwner())
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			t = "TROPHY_FEAT_GODSLAYER"
			if not CyGame().isHasTrophy(t):
				CyGame().changeTrophyValue(t, 1)

	if not pCaster.isImmortal():
		iPlayer = pCaster.getOwner()
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.getLeaderType() == gc.getInfoTypeForString(sLeader):
			for iTrait in range(gc.getNumTraitInfos()):
				if pPlayer.hasTrait(iTrait):
					if iTrait != gc.getInfoTypeForString('TRAIT_FALLOW'):
						pPlayer.setHasTrait(iTrait, False)
		pOppPlayer = gc.getPlayer(pOpponent.getOwner())
		if pOppPlayer.isHuman():
			if sTrophy != -1:
				if not CyGame().isHasTrophy(sTrophy):
					CyGame().changeTrophyValue(sTrophy, 1)
			if pOpponent.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GODSLAYER')):
				if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AVATAR')):
					t = "TROPHY_FEAT_GODSLAYER"
					if not CyGame().isHasTrophy(t):
						CyGame().changeTrophyValue(t, 1)













def postCombatBuboes(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_BUBOES"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)


def postCombatLeviathan(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_LEVIATHAN"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)



def postCombatStephanos(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_STEPHANOS"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatTreant(pCaster, pOpponent):
	pPlot = pCaster.plot()

	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST'):
		pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT'), 0)
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW'):
		pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST'), 0)

	if pPlot.getFeatureType() == -1:
		if pPlot.canHaveFeature(gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
			pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FOREST_NEW'), 0)

def postCombatYersinia(pCaster, pOpponent):
	pPlayer = gc.getPlayer(pOpponent.getOwner())
	if pPlayer.isHuman():
		t = "TROPHY_DEFEATED_YERSINIA"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def postCombatReduceCombat1(pCaster, pOpponent):
	if pOpponent.isAlive():
		if pCaster.baseCombatStr() > pCaster.getTotalDamageTypeCombat():
			pCaster.setBaseCombatStr(pCaster.baseCombatStr() - pCaster.getTotalDamageTypeCombat() - 1)
			pCaster.setBaseCombatStrDefense(pCaster.baseCombatStrDefense() - pCaster.getTotalDamageTypeCombat() - 1)
			CyInterface().addMessage(pCaster.getOwner(), True, gc.getEVENT_MESSAGE_TIME(), CyTranslator().getText("TXT_KEY_MESSAGE_STRENGTH_REDUCED", ()), '', InterfaceMessageTypes.MESSAGE_TYPE_INFO, pCaster.getButton(), gc.getInfoTypeForString('COLOR_RED'), pCaster.getX(), pCaster.getY(), True, True)


def postCombatDullahan(pCaster, pOpponent):
	if pOpponent.isAlive():
		pOpponent.changeImmortal(-1)
	pPlot = pOpponent.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getPopulation() > 1:
			pCity.changePopulation(-1)
			CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POPULATION_REDUCED", ()),'',1,'Art/Interface/Buttons/Units/Angel of Death.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)


def postCombatReducePopulation(pCaster, pOpponent):
	pPlot = pOpponent.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getPopulation() > 1:
			pCity.changePopulation(-1)
			CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POPULATION_REDUCED", ()),'',1,'Art/Interface/Buttons/Units/Angel of Death.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)

def postCombatLostSailorsDirge(pCaster, pOpponent):
	iPlayer = pOpponent.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_SAILORS_DIRGE_DEFEATED')
	triggerData = pPlayer.initTriggeredData(iEvent, False, -1, pCaster.getX(), pCaster.getY(), iPlayer, -1, -1, -1, -1, -1)

def postCombatSplit(pCaster, pOpponent):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK')) == False:
		pPlayer = gc.getPlayer(pCaster.getOwner())
		iUnit = pCaster.getUnitType()
		newUnit = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit2 = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
		newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
		newUnit.setDamage(25, -1)
		newUnit2.setDamage(25, -1)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG')) == False:
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
			newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
		newUnit.setDuration(pCaster.getDuration())
		newUnit2.setDuration(pCaster.getDuration())
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SPLIT", ()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)


def postCombatWolfRider(pCaster, pOpponent):
	if (pOpponent.getUnitType() == gc.getInfoTypeForString('UNIT_WOLF') or pOpponent.getUnitType() == gc.getInfoTypeForString('UNIT_WOLF_PACK')):
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WOLF_RIDER", ()),'',1,'Art/Interface/Buttons/Units/Wolf Rider.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
		pPlayer = gc.getPlayer(pCaster.getOwner())
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WOLF_RIDER'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(pCaster)


def spellAcceptChallenge(caster):
	pPlot = caster.plot()
	iChallengerProm = gc.getInfoTypeForString('PROMOTION_CHALLENGER')
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if caster.getID()  != pUnit.getID() :
			if pUnit.isHasPromotion(iChallengerProm) == True:
				break
	iRnd = CyGame().getSorenRandNum(100, "Doviello Duel")
	iChallengerOdds = getCombatOdds(pUnit, caster)
	iChallengerRnd = (iRnd + (iChallengerOdds * 2)) / 3
	iDefenderOdds = getCombatOdds(caster, pUnit)
	iDefenderRnd = (iRnd + (iDefenderOdds * 2)) / 3
	if iDefenderOdds > iChallengerOdds:
		iDefenseRnd = CyGame().getSorenRandNum(100, "Doviello Duel Defender")
		iDefenseTieRnd = CyGame().getSorenRandNum(100, "Doviello Duel Defender Tie")
		if iDefenseTieRnd < 10:
			caster.changeExperience(pUnit.getExperience() / 10, -1, False, False, False)
			caster.setDamage(75, caster.getOwner())
			pUnit.changeExperience(caster.getExperience() / 10, -1, False, False, False)
			pUnit.setDamage(75, pUnit.getOwner())
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_DRAW", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
		elif (iDefenseTieRnd < 12 and iDefenseTieRnd >= 10):
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_DEATH", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
			caster.kill(True, PlayerTypes.NO_PLAYER)
			pUnit.kill(True, PlayerTypes.NO_PLAYER)
		elif iDefenseTieRnd > 12:
			if iDefenseRnd > iDefenderOdds:
				pUnit.changeExperience((caster.getExperience() / 4) + 2, -1, False, False, False)
				pUnit.setDamage(25, pUnit.getOwner())
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_LOSS", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
				if not pUnit.isHasPromotion(iMithril):
					if caster.isHasPromotion(iMithril):
						pUnit.setHasPromotion(iMithril, True)
					elif not pUnit.isHasPromotion(iIron):
						if caster.isHasPromotion(iIron):
							pUnit.setHasPromotion(iIron, True)
						elif not pUnit.isHasPromotion(iBronze):
							if caster.isHasPromotion(iBronze):
								pUnit.setHasPromotion(iBronze, True)
				caster.kill(True, PlayerTypes.NO_PLAYER)
			if iDefenseRnd < iDefenderOdds:
				caster.changeExperience((pUnit.getExperience() / 4) + 2, -1, False, False, False)
				caster.setDamage(25, caster.getOwner())
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_WIN", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
				if not caster.isHasPromotion(iMithril):
					if pUnit.isHasPromotion(iMithril):
						caster.setHasPromotion(iMithril, True)
					elif not caster.isHasPromotion(iIron):
						if pUnit.isHasPromotion(iIron):
							caster.setHasPromotion(iIron, True)
						elif not caster.isHasPromotion(iBronze):
							if pUnit.isHasPromotion(iBronze):
								caster.setHasPromotion(iBronze, True)
				pUnit.kill(True, PlayerTypes.NO_PLAYER)
	if iChallengerOdds > iDefenderOdds:
		iChallengeRnd = CyGame().getSorenRandNum(100, "Doviello Duel Challenger")
		iChallengerTieRnd = CyGame().getSorenRandNum(100, "Doviello Duel Challenger Tie")
		if iChallengerTieRnd < 10:
			caster.changeExperience(pUnit.getExperience() / 10, -1, False, False, False)
			caster.setDamage(75, caster.getOwner())
			pUnit.changeExperience(caster.getExperience() / 10, -1, False, False, False)
			pUnit.setDamage(75, pUnit.getOwner())
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_DRAW", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
		elif (iChallengerTieRnd < 12 and iChallengerTieRnd >= 10):
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_DEATH", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
			caster.kill(True, PlayerTypes.NO_PLAYER)
			pUnit.kill(True, PlayerTypes.NO_PLAYER)
		elif iChallengerTieRnd > 12:
			if iChallengeRnd < iChallengerOdds:
				pUnit.changeExperience((caster.getExperience() / 4) + 2, -1, False, False, False)
				pUnit.setDamage(25, pUnit.getOwner())
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_LOSS", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
				if not pUnit.isHasPromotion(iMithril):
					if caster.isHasPromotion(iMithril):
						pUnit.setHasPromotion(iMithril, True)
					elif not pUnit.isHasPromotion(iIron):
						if caster.isHasPromotion(iIron):
							pUnit.setHasPromotion(iIron, True)
						elif not pUnit.isHasPromotion(iBronze):
							if caster.isHasPromotion(iBronze):
								pUnit.setHasPromotion(iBronze, True)
				caster.kill(True, PlayerTypes.NO_PLAYER)
			if iChallengeRnd > iChallengerOdds:
				caster.changeExperience((pUnit.getExperience() / 4) + 2, -1, False, False, False)
				caster.setDamage(25, caster.getOwner())
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_WIN", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
				if not caster.isHasPromotion(iMithril):
					if pUnit.isHasPromotion(iMithril):
						caster.setHasPromotion(iMithril, True)
					elif not caster.isHasPromotion(iIron):
						if pUnit.isHasPromotion(iIron):
							caster.setHasPromotion(iIron, True)
						elif not caster.isHasPromotion(iBronze):
							if pUnit.isHasPromotion(iBronze):
								caster.setHasPromotion(iBronze, True)
				pUnit.kill(True, PlayerTypes.NO_PLAYER)
	if iChallengerOdds == iDefenderOdds:
		iEqualRnd = CyGame().getSorenRandNum(100, "Doviello Duel Equals")
		iEqualTieRnd = CyGame().getSorenRandNum(100, "Doviello Duel Equals Tie")
		if iEqualTieRnd < 10:
			caster.changeExperience(pUnit.getExperience() / 10, -1, False, False, False)
			caster.setDamage(75, caster.getOwner())
			pUnit.changeExperience(caster.getExperience() / 10, -1, False, False, False)
			pUnit.setDamage(75, pUnit.getOwner())
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_DRAW", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
		elif (iEqualTieRnd < 12 and iEqualTieRnd >= 10):
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_DEATH", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
			caster.kill(True, PlayerTypes.NO_PLAYER)
			pUnit.kill(True, PlayerTypes.NO_PLAYER)
		elif iEqualTieRnd > 12:
			if iEqualRnd < 50:
				pUnit.changeExperience((caster.getExperience() / 4) + 2, -1, False, False, False)
				pUnit.setDamage(25, pUnit.getOwner())
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHALLENGER'), False)
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_LOSS", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)






				if not pUnit.isHasPromotion(iMithril):
					if caster.isHasPromotion(iMithril):
						pUnit.setHasPromotion(iMithril, True)
					elif not pUnit.isHasPromotion(iIron):
						if caster.isHasPromotion(iIron):
							pUnit.setHasPromotion(iIron, True)
						elif not pUnit.isHasPromotion(iBronze):
							if caster.isHasPromotion(iBronze):
								pUnit.setHasPromotion(iBronze, True)





				caster.kill(True, PlayerTypes.NO_PLAYER)
			if iEqualRnd >= 50:
				caster.changeExperience((pUnit.getExperience() / 4) + 2, -1, False, False, False)
				caster.setDamage(25, caster.getOwner())
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOVIELLO_DUEL_WIN", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)




				if not caster.isHasPromotion(iMithril):
					if pUnit.isHasPromotion(iMithril):
						caster.setHasPromotion(iMithril, True)
					elif not caster.isHasPromotion(iIron):
						if pUnit.isHasPromotion(iIron):
							caster.setHasPromotion(iIron, True)
						elif not caster.isHasPromotion(iBronze):
							if pUnit.isHasPromotion(iBronze):
								caster.setHasPromotion(iBronze, True)




				pUnit.kill(True, PlayerTypes.NO_PLAYER)



def reqAddToFleshGolem(caster):
	if caster.isImmortal():
		return False
	if caster.isImmuneToMagic():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		pPlot = caster.plot()
		iChanneling = gc.getInfoTypeForString('PROMOTION_CHANNELING1')
		iChanneling2 = gc.getInfoTypeForString('PROMOTION_CHANNELING2')
		iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
		iEx1 = gc.getInfoTypeForString('PROMOTION_EXTENSION1')
		iEx2 = gc.getInfoTypeForString('PROMOTION_EXTENSION2')
		iEx3 = gc.getInfoTypeForString('PROMOTION_EXTENSION3')
		iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE')
		iDivine2 = gc.getInfoTypeForString('PROMOTION_DIVINE2')
		iMerc = gc.getInfoTypeForString('PROMOTION_MERCENARY')
		iFleshGolem = gc.getInfoTypeForString('UNITCLASS_FLESH_GOLEM')
		pFleshGolem = -1
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iFleshGolem):
				pFleshGolem = pUnit
		if pFleshGolem != -1:
			if caster.baseCombatStr() > pFleshGolem.baseCombatStr():
				return True
			if caster.baseCombatStrDefense() > pFleshGolem.baseCombatStrDefense():
				return True
			for iCount in range(gc.getNumPromotionInfos()):
				if (caster.isHasPromotion(iCount)):
					if not gc.getPromotionInfo(iCount).getExpireChance() > 0:
						if not (pFleshGolem.isHasPromotion(iCount)):
							if (iCount != iMerc and iCount != iChanneling and iCount != iChanneling2 and iCount != iChanneling3 and iCount != iDivine and iCount != iDivine2 and iCount != iEx1 and iCount != iEx2 and iCount != iEx3):
								if not gc.getPromotionInfo(iCount).isRace():
									if gc.getPromotionInfo(iCount).getBonusPrereq() == -1:
										if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling2:
											if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling3:
												if gc.getPromotionInfo(iCount).isEquipment() == False:
													return True
		return False
	return True

def spellAddToFleshGolem(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iChanneling = gc.getInfoTypeForString('PROMOTION_CHANNELING1')
	iChanneling2 = gc.getInfoTypeForString('PROMOTION_CHANNELING2')
	iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')
	iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE')
	iFleshGolem = gc.getInfoTypeForString('UNITCLASS_FLESH_GOLEM')
	pFleshGolem = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iFleshGolem):
			pFleshGolem = pUnit
	if pFleshGolem != -1:
		if caster.baseCombatStr() > pFleshGolem.baseCombatStr():
			pFleshGolem.setBaseCombatStr(pFleshGolem.baseCombatStr() + 1)
		if caster.baseCombatStrDefense() > pFleshGolem.baseCombatStrDefense():
			pFleshGolem.setBaseCombatStrDefense(pFleshGolem.baseCombatStrDefense() + 1)
		for iCount in range(gc.getNumPromotionInfos()):
			if (caster.isHasPromotion(iCount)):
				if (iCount != iChanneling and iCount != iChanneling2 and iCount != iChanneling3 and iCount != iDivine):
					if not gc.getPromotionInfo(iCount).isRace():
						if gc.getPromotionInfo(iCount).getBonusPrereq() == -1:
							if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling2:
								if gc.getPromotionInfo(iCount).getPromotionPrereqAnd() != iChanneling3:
									if gc.getPromotionInfo(iCount).isEquipment() == False:
										pFleshGolem.setHasPromotion(iCount, True)
		if pFleshGolem.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')):
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS'), False)
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS'), False)
		if pFleshGolem.isHasPromotion(gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')):
			pFleshGolem.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS'), False)
		if pFleshGolem.baseCombatStr() >= 15:
			if pPlayer.isHuman():
				t = "TROPHY_FEAT_FLESH_GOLEM_15"
				if not CyGame().isHasTrophy(t):
					CyGame().changeTrophyValue(t, 1)

def reqAddToFreakShowHuman(caster):
	if caster.getRace() != -1:
		return False
	return True

def reqAddToWolfPack(caster):
	pPlot = caster.plot()
	iWolfPack = gc.getInfoTypeForString('UNIT_WOLF_PACK')
	iEmpower5 = gc.getInfoTypeForString('PROMOTION_EMPOWER5')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iWolfPack:
			if pUnit.getOwner() == caster.getOwner():
				if not pUnit.isHasPromotion(iEmpower5):
					return True
	return False

def spellAddToWolfPack(caster):
	pPlot = caster.plot()
	iWolfPack = gc.getInfoTypeForString('UNIT_WOLF_PACK')
	iEmpower1 = gc.getInfoTypeForString('PROMOTION_EMPOWER1')
	iEmpower2 = gc.getInfoTypeForString('PROMOTION_EMPOWER2')
	iEmpower3 = gc.getInfoTypeForString('PROMOTION_EMPOWER3')
	iEmpower4 = gc.getInfoTypeForString('PROMOTION_EMPOWER4')
	iEmpower5 = gc.getInfoTypeForString('PROMOTION_EMPOWER5')
	bValid = True
	for i in range(pPlot.getNumUnits()):
		if bValid:
			pUnit = pPlot.getUnit(i)
			if pUnit.getUnitType() == iWolfPack:
				if pUnit.getOwner() == caster.getOwner():
					iProm = -1
					if not pUnit.isHasPromotion(iEmpower5):
						iProm = iEmpower5
					if not pUnit.isHasPromotion(iEmpower4):
						iProm = iEmpower4
					if not pUnit.isHasPromotion(iEmpower3):
						iProm = iEmpower3
					if not pUnit.isHasPromotion(iEmpower2):
						iProm = iEmpower2
					if not pUnit.isHasPromotion(iEmpower1):
						iProm = iEmpower1
					if iProm != -1:
						pUnit.setHasPromotion(iProm, True)
						bValid = False





def spellArcaneLacuna(pCaster):
	iManaCount = 0
	iAirCount = 0
	iBodyCount = 0
	iChaosCount = 0
	iCreationCount = 0
	iDeathCount = 0
	iDimensionalCount = 0
	iEarthCount = 0
	iEnchantmentCount = 0
	iEntropyCount = 0
	iFireCount = 0
	iForceCount = 0
	iIceCount = 0
	iLawCount = 0
	iLifeCount = 0
	iMetaCount = 0
	iMindCount = 0
	iNatureCount = 0
	iShadowCount = 0
	iSpiritCount = 0
	iSunCount = 0
	iWaterCount = 0

	sMana = 'BONUS_MANA'
	sAir = 'BONUS_MANA_AIR'
	sBody = 'BONUS_MANA_BODY'
	sCreation = 'BONUS_MANA_CREATION'
	sChaos = 'BONUS_MANA_CHAOS'
	sDeath = 'BONUS_MANA_DEATH'
	sDimensional = 'BONUS_MANA_DIMENSIONAL'
	sEarth = 'BONUS_MANA_EARTH'
	sEnchantment = 'BONUS_MANA_ENCHANTMENT'
	sEntropy = 'BONUS_MANA_ENTROPY'
	sFire = 'BONUS_MANA_FIRE'
	sForce = 'BONUS_MANA_FORCE'
	sIce = 'BONUS_MANA_ICE'
	sLaw = 'BONUS_MANA_LAW'
	sLife = 'BONUS_MANA_LIFE'
	sMeta = 'BONUS_MANA_METAMAGIC'
	sMind = 'BONUS_MANA_MIND'
	sNature = 'BONUS_MANA_NATURE'
	sShadow = 'BONUS_MANA_SHADOW'
	sSpirit = 'BONUS_MANA_SPIRIT'
	sSun = 'BONUS_MANA_SUN'
	sWater = 'BONUS_MANA_WATER'

	iAir = gc.getInfoTypeForString('IMPROVEMENT_MANA_AIR')
	iBody = gc.getInfoTypeForString('IMPROVEMENT_MANA_BODY')
	iCreation = gc.getInfoTypeForString('IMPROVEMENT_MANA_CREATION')
	iChaos = gc.getInfoTypeForString('IMPROVEMENT_MANA_CHAOS')
	iDeath = gc.getInfoTypeForString('IMPROVEMENT_MANA_DEATH')
	iDimensional = gc.getInfoTypeForString('IMPROVEMENT_MANA_DIMENSIONAL')
	iEarth = gc.getInfoTypeForString('IMPROVEMENT_MANA_EARTH')
	iEnchantment = gc.getInfoTypeForString('IMPROVEMENT_MANA_ENCHANTMENT')
	iEntropy = gc.getInfoTypeForString('IMPROVEMENT_MANA_ENTROPY')
	iFire = gc.getInfoTypeForString('IMPROVEMENT_MANA_FIRE')
	iForce = gc.getInfoTypeForString('IMPROVEMENT_MANA_FORCE')
	iIce = gc.getInfoTypeForString('IMPROVEMENT_MANA_ICE')
	iLaw = gc.getInfoTypeForString('IMPROVEMENT_MANA_LAW')
	iLife = gc.getInfoTypeForString('IMPROVEMENT_MANA_LIFE')
	iMeta = gc.getInfoTypeForString('IMPROVEMENT_MANA_METAMAGIC')
	iMind = gc.getInfoTypeForString('IMPROVEMENT_MANA_MIND')
	iNature = gc.getInfoTypeForString('IMPROVEMENT_MANA_NATURE')
	iShadow = gc.getInfoTypeForString('IMPROVEMENT_MANA_SHADOW')
	iSpirit = gc.getInfoTypeForString('IMPROVEMENT_MANA_SPIRIT')
	iSun = gc.getInfoTypeForString('IMPROVEMENT_MANA_SUN')
	iWater = gc.getInfoTypeForString('IMPROVEMENT_MANA_WATER')

	for iPlotIndex in range(CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(iPlotIndex)
		if not pPlot.isOwned() or pPlot.getOwner() != pCaster.getOwner():
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sMana):
				iManaCount += 1
				pPlot.setBonusType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sAir):
				iAirCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iAir:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sBody):
				iBodyCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iBody:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sChaos):
				iChaosCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iChaos:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sCreation):
				iCreationCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iCreation:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sDeath):
				iDeathCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iDeath:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sDimensional):
				iDimensionalCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iDimensional:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sEarth):
				iEarthCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iEarth:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sEnchantment):
				iEnchantmentCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iEnchantment:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sEntropy):
				iEntropyCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iEntropy:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sFire):
				iFireCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iFire:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sForce):
				iForceCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iForce:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sIce):
				iIceCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iIce:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sLaw):
				iLawCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iLaw:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sLife):
				iLifeCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iLife:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sMeta):
				iMetaCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iMeta:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sMind):
				iMindCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iMind:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sNature):
				iNatureCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iNature:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sShadow):
				iShadowCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iShadow:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sSpirit):
				iSpiritCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iSpirit:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sSun):
				iSunCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iSun:
					pPlot.setImprovementType(-1)
			if pPlot.getBonusType(-1) == gc.getInfoTypeForString(sWater):
				iWaterCount += 1
				pPlot.setBonusType(-1)
				if pPlot.getImprovementType() == iWater:
					pPlot.setImprovementType(-1)

	cf.addBonus(sMana,iManaCount,'Art/Interface/Buttons/WorldBuilder/mana_button.dds')
	cf.addBonus(sAir,iAirCount,'Art/Interface/Buttons/WorldBuilder/Air.dds')
	cf.addBonus(sBody,iBodyCount,'Art/Interface/Buttons/WorldBuilder/Body.dds')
	cf.addBonus(sChaos,iChaosCount,'Art/Interface/Buttons/WorldBuilder/Chaos.dds')
	cf.addBonus(sCreation,iCreationCount,'Art/Interface/Buttons/WorldBuilder/Creation.dds')
	cf.addBonus(sDeath,iDeathCount,'Art/Interface/Buttons/WorldBuilder/Death.dds')
	cf.addBonus(sDimensional,iDimensionalCount,'Art/Interface/Buttons/WorldBuilder/Dimensional.dds')
	cf.addBonus(sEarth,iEarthCount,'Art/Interface/Buttons/WorldBuilder/Earth.dds')
	cf.addBonus(sEnchantment,iEnchantmentCount,'Art/Interface/Buttons/WorldBuilder/Enchantment.dds')
	cf.addBonus(sEntropy,iEntropyCount,'Art/Interface/Buttons/WorldBuilder/Entropy.dds')
	cf.addBonus(sFire,iFireCount,'Art/Interface/Buttons/WorldBuilder/Fire.dds')
	cf.addBonus(sForce,iForceCount,'Art/Interface/Buttons/WorldBuilder/Force.dds')
	cf.addBonus(sIce,iIceCount,'Art/Interface/Buttons/WorldBuilder/Ice.dds')
	cf.addBonus(sLaw,iLawCount,'Art/Interface/Buttons/WorldBuilder/Law.dds')
	cf.addBonus(sLife,iLifeCount,'Art/Interface/Buttons/WorldBuilder/Life.dds')
	cf.addBonus(sMeta,iMetaCount,'Art/Interface/Buttons/WorldBuilder/Metamagic.dds')
	cf.addBonus(sNature,iNatureCount,'Art/Interface/Buttons/WorldBuilder/Nature.dds')
	cf.addBonus(sShadow,iShadowCount,'Art/Interface/Buttons/WorldBuilder/Shadow.dds')
	cf.addBonus(sSpirit,iSpiritCount,'Art/Interface/Buttons/WorldBuilder/Spirit.dds')
	cf.addBonus(sSun,iSunCount,'Art/Interface/Buttons/WorldBuilder/Sun.dds')
	cf.addBonus(sWater,iWaterCount,'Art/Interface/Buttons/WorldBuilder/Water.dds')



def reqArdor(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getGreatPeopleCreated() == 0:
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getGreatPeopleCreated() < 6:
			return False
	return True

def spellArdor(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.setGreatPeopleCreated(0)
	pPlayer.setGreatPeopleThresholdModifier(0)

def reqArenaBattle(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == True:
		if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_MELEE'):
			return True
		if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_RECON'):
			return True
		if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE'):
			return True
	if pPlayer.isHuman() == False:
		if caster.getLevel() > 3:
			return False
		if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_MELEE') or caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_RECON') or caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE'):
			if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK')):
				return True

	return False

def spellArenaBattle(caster):
	pCity = caster.plot().getPlotCity()
	pCity.changeHappinessTimer(3)
	if CyGame().getSorenRandNum(100, "Arena Battle") < 50:
		caster.changeExperience(CyGame().getSorenRandNum(6, "Arena Battle") + 1, -1, False, False, False)
		caster.setDamage(25, caster.getOwner())
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_WIN", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
		if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_SLAVE'):
			pPlayer = gc.getPlayer(caster.getOwner())
			newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WARRIOR'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(caster)
	else:
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ARENA_LOSE", ()),'',1,'Art/Interface/Buttons/Buildings/Arena.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
		caster.kill(True, PlayerTypes.NO_PLAYER)


def reqRage(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isHuman() or pPlayer.isBarbarian() or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED')):
		return True
	return False



def spellAssuage(caster):
	iX = caster.getX()
	iY = caster.getY()
	iWrath = gc.getInfoTypeForString('UNIT_WRATH')
	iOdio = gc.getInfoTypeForString('UNIT_ODIO')
	iChaos = gc.getInfoTypeForString('UNIT_CHAOS_MARAUDER')
	iIra = gc.getInfoTypeForString('UNIT_IRA')

	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					iUnit = pUnit.getUnitType()
					if iUnit == iWrath or iUnit == iOdio or iUnit == iChaos or iUnit == iIra:
						pUnit.doDamage(70, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), True)

def reqAssuage(caster):
	iX = caster.getX()
	iY = caster.getY()
	iCrazed = gc.getInfoTypeForString('PROMOTION_CRAZED')
	iEnraged = gc.getInfoTypeForString('PROMOTION_ENRAGED')
	iBBlood = gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD')

	iWrath = gc.getInfoTypeForString('UNIT_WRATH')
	iOdio = gc.getInfoTypeForString('UNIT_ODIO')
	iChaos = gc.getInfoTypeForString('UNIT_CHAOS_MARAUDER')
	iIra = gc.getInfoTypeForString('UNIT_IRA')

	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if pUnit.isAlive():
						if pUnit.isHasPromotion(iCrazed) or pUnit.isHasPromotion(iEnraged) or pUnit.isHasPromotion(iBBlood):
							return True
					else:
						iUnit = pUnit.getUnitType()
						if iUnit == iWrath or iUnit == iOdio or iUnit == iChaos or iUnit == iIra:
							return True
	return False





def reqBlaze(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	pPlot = caster.plot()

	if not ((pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')) or (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE')) or (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST'))):
		return False

	if ((pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE')) or (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES'))):
		return False

	if pPlayer.isHuman() == False:
		if pPlot.isOwned():
			p2Player = gc.getPlayer(pPlot.getOwner())
			e2Team = gc.getTeam(p2Player.getTeam())
			if e2Team.isAtWar(eTeam) == True:
				return True
			else:
				return False
	return True


def reqCallAnimal(pCaster):
	iSummon = gc.getInfoTypeForString('UNITCOMBAT_ANIMAL')
	casterID = pCaster.getID()
	iPlayer = pCaster.getOwner()
	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.getUnitCombatType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True



def spellCallAnimal(pCaster):
	listUnits = []
	pPlot = pCaster.plot()
	iLev = pCaster.getLevel()
	pPlayer = gc.getPlayer(pCaster.getOwner())
	iCoast = gc.getInfoTypeForString('TERRAIN_COAST')
	iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
	iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
	iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
	iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
	iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
	iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iForestAncient = gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')
	iForestNew = gc.getInfoTypeForString('FEATURE_FOREST_NEW')
	iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
	listUnits.append(gc.getInfoTypeForString('UNIT_WOLF'))
	if pPlot.getTerrainType() == iCoast or pPlot.getTerrainType() == iOcean:
		if iLev > 3:
			listUnits.append(gc.getInfoTypeForString('UNIT_SEA_SERPENT'))
		if iLev > 5:
			listUnits.append(gc.getInfoTypeForString('UNIT_GIANT_TORTOISE'))
			listUnits.append(gc.getInfoTypeForString('UNIT_GIANT_TORTOISE'))
	if pPlot.getTerrainType() == iDesert:
		listUnits.append(gc.getInfoTypeForString('UNIT_LION'))
		if iLev > 5:
			listUnits.append(gc.getInfoTypeForString('UNIT_LION_PRIDE'))
		if iLev > 5:
			listUnits.append(gc.getInfoTypeForString('UNIT_SCORPION'))
			listUnits.append(gc.getInfoTypeForString('UNIT_SCORPION'))
	if pPlot.getTerrainType() == iPlains or pPlot.getTerrainType() == iGrass:
		listUnits.append(gc.getInfoTypeForString('UNIT_LION'))
		if iLev > 5:
			listUnits.append(gc.getInfoTypeForString('UNIT_LION_PRIDE'))
		if iLev > 7:
			listUnits.append(gc.getInfoTypeForString('UNIT_ELEPHANT'))
			listUnits.append(gc.getInfoTypeForString('UNIT_ELEPHANT'))
	if pPlot.getTerrainType() == iTundra or pPlot.getTerrainType() == iSnow:
		listUnits.append(gc.getInfoTypeForString('UNIT_WOLF'))
		if iLev > 4:
			listUnits.append(gc.getInfoTypeForString('UNIT_WOLF_PACK'))
		if iLev > 4:
			listUnits.append(gc.getInfoTypeForString('UNIT_POLAR_BEAR'))
			listUnits.append(gc.getInfoTypeForString('UNIT_POLAR_BEAR'))
	if pPlot.getFeatureType() == iForest or pPlot.getFeatureType() == iForestAncient:
		if iLev > 2:
			listUnits.append(gc.getInfoTypeForString('UNIT_WOLF'))
		if iLev > 4:
			listUnits.append(gc.getInfoTypeForString('UNIT_BEAR'))
		if iLev > 4:
			listUnits.append(gc.getInfoTypeForString('UNIT_BABY_SPIDER'))
		if iLev > 6:
			listUnits.append(gc.getInfoTypeForString('UNIT_GIANT_SPIDER'))
			listUnits.append(gc.getInfoTypeForString('UNIT_GIANT_SPIDER'))
	if pPlot.getFeatureType() == iJungle:
		if iLev > 3:
			listUnits.append(gc.getInfoTypeForString('UNIT_TIGER'))
		if iLev > 4:
			listUnits.append(gc.getInfoTypeForString('UNIT_PANTHER'))
			listUnits.append(gc.getInfoTypeForString('UNIT_PANTHER'))
		if iLev > 5:
			listUnits.append(gc.getInfoTypeForString('UNIT_GORILLA'))
			listUnits.append(gc.getInfoTypeForString('UNIT_GORILLA'))
		if iLev > 6:
			listUnits.append(gc.getInfoTypeForString('UNIT_BABOON'))
			listUnits.append(gc.getInfoTypeForString('UNIT_BABOON'))
	if iLev > 12:
		listUnits.append(gc.getInfoTypeForString('UNIT_GRIFFON'))
		listUnits.append(gc.getInfoTypeForString('UNIT_GRIFFON'))
		listUnits.append(gc.getInfoTypeForString('UNIT_GRIFFON'))
	if iLev > 8:
		listUnits.append(gc.getInfoTypeForString('UNIT_HAWK'))
	if len(listUnits) > 0:
		iUnit = listUnits[CyGame().getSorenRandNum(len(listUnits), "Call Animal")]
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_ANIMAL, DirectionTypes.DIRECTION_SOUTH)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT1')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EMPOWER1'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT2')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EMPOWER2'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT3')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EMPOWER3'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT4')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EMPOWER4'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT5')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EMPOWER5'), True)

		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2'), True)

		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MERCENARY')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MERCENARY'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PUPPET')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PUPPET'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), True)


		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT2'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL2')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT3'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL3')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT4'), True)

		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUMMONER')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT5'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUNDERED')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STIGMATA'), True)


		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION1')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MOBILITY1'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION2')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MOBILITY1'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION3')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BLITZ'), True)


		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW3')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER3')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER_WALKING'), True)

		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_KANNAS_RING')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WARCRY'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPELLSTAFF')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MARCH'), True)

		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION'), True)
		if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION'), True)

		if gc.getGame().getProjectCreatedCount(gc.getInfoTypeForString('PROJECT_NATURES_REVOLT')) > 0:
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE'), True)
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_DEFENSE2'), True)
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH'), True)
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HEROIC_STRENGTH2'), True)

		newUnit.setSummoner(pCaster.getID())


def reqCallBlizzard(caster):
	iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
	pPlot = caster.plot()
	if pPlot.getFeatureType() == iBlizzard:
		return False
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT'):
		return False
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.getFeatureType() == iBlizzard:
					return True
	return False

def spellCallBlizzard(caster):
	iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
	iTundra = gc.getInfoTypeForString('TERRAIN_TUNDRA')
	iX = caster.getX()
	iY = caster.getY()
	pBlizPlot = -1
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.getFeatureType() == iBlizzard:
					pBlizPlot = pPlot
	if pBlizPlot != -1:
		pBlizPlot.setFeatureType(-1, -1)
	pPlot = caster.plot()
	pPlot.setFeatureType(iBlizzard, 0)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		pPlot.setTerrainType(iTundra,True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(iTundra,True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT'):
		pPlot.setTerrainType(iTundra,True,True)




def reqCreatePuppet(pCaster):
	iSummon = gc.getInfoTypeForString('UNIT_PUPPET')
	casterID = pCaster.getID()
	iPlayer = pCaster.getOwner()
	py = PyPlayer(iPlayer)
	if pCaster.getSummoner() != -1:
		return False
	for pUnit in py.getUnitList():
		if pUnit.getUnitType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True


def reqSeverSoul(pCaster):
	iSummon = gc.getInfoTypeForString('UNIT_SEVERED_SOUL')
	casterID = pCaster.getID()
	iPlayer = pCaster.getOwner()
	py = PyPlayer(iPlayer)
	if pCaster.getSummoner() != -1:
		return False
	for pUnit in py.getUnitList():
		if pUnit.getUnitType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True



def reqCallForm(caster):
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SOUL_SPLITTER'), False)
	caster.setHasCasted(True)
	if caster.getSummoner() == -1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	pUnit = pPlayer.getUnit(caster.getSummoner())
	if pUnit == -1:
		return False
	pPlot = caster.plot()
	if not pUnit.canMoveInto(pPlot, False, False, False):
		return False
	return True

def spellCallForm(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pUnit = pPlayer.getUnit(caster.getSummoner())
	pPlot = caster.plot()
	pUnit.setXY(pPlot.getX(), pPlot.getY(), False, True, True)

def reqCallOfTheGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iX = caster.getX()
	iY = caster.getY()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iGraveyard = gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					p2Player = gc.getPlayer(pUnit.getOwner())
					e2Team = p2Player.getTeam()
					if eTeam.isAtWar(e2Team) == True:
						return True
					if pUnit.getRace() == iUndead:
						if pUnit.getDamage() != 0:
							return True
					if pPlot.getImprovementType() == iGraveyard:
						return True
	return False

def spellCallOfTheGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iX = caster.getX()
	iY = caster.getY()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iGraveyard = gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				bValid = False
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					p2Player = gc.getPlayer(pUnit.getOwner())
					e2Team = p2Player.getTeam()
					if eTeam.isAtWar(e2Team) == True:
						pUnit.doDamage(40, 100, caster, gc.getInfoTypeForString('DAMAGE_DEATH'), True)
						bValid = True
					else:
						if pUnit.getRace() == iUndead:
							if pUnit.getDamage() != 0:
								pUnit.setDamage(0, caster.getOwner())
					if pPlot.getImprovementType() == iGraveyard:
						pPlot.setImprovementType(-1)
						newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setSummoner(caster.getID())

						newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setSummoner(caster.getID())

						newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setSummoner(caster.getID())

						bValid = True
				if bValid:
					CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SACRIFICE'),pPlot.getPoint())

def reqCommanderJoin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GREAT_GENERAL')):
		return False
	iCommander = gc.getInfoTypeForString('UNITCLASS_GREAT_GENERAL')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iCommander):
			pCommander = pUnit
	if pCommander == -1:
		return False
	if pCommander.isHasCasted():
		return False
	if pPlayer.isHuman() == False:
		if caster.baseCombatStr() < 5:
			return False
	return True

def spellCommanderJoin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iCommander = gc.getInfoTypeForString('UNITCLASS_GREAT_GENERAL')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitClassType() == iCommander):
			pCommander = pUnit
	if pCommander != -1:
		pCommander.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)
		pCommander.kill(False, PlayerTypes.NO_PLAYER)

def spellCommanderJoinDecius(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iDecius = gc.getInfoTypeForString('UNIT_DECIUS')
	pCommander = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (caster.getOwner() == pUnit.getOwner() and pUnit.getUnitType() == iDecius):
			pCommander = pUnit
	if pCommander != -1:
		caster.setScenarioCounter(iDecius)
		pCommander.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)
		pCommander.kill(False, PlayerTypes.NO_PLAYER)

def spellCommanderSplit(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iCommander = gc.getInfoTypeForString('UNIT_GREAT_GENERAL')
	if caster.getScenarioCounter() == gc.getInfoTypeForString('UNIT_DECIUS'):
		iCommander = gc.getInfoTypeForString('UNIT_DECIUS')
		caster.setScenarioCounter(-1)
	newUnit = pPlayer.initUnit(iCommander, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)



def reqConvertCityBasium(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	if caster.getTeam() == pCity.getTeam():
		pPlayer = gc.getPlayer(caster.getOwner())
		pPlayer2 = gc.getPlayer(pCity.getOwner())
		if pCity.isCapital():
			return False
		if not pPlayer2.isHuman():
			if pPlayer.isHuman():
				return True
			if pCity.isSettlement():
				return True
			if 2*pPlayer.getNumCities() < pPlayer2.getNumCities():
				return True
		return False



def spellConvertCityBasium(caster):
	pCity = caster.plot().getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)

	pPlayer2 = gc.getPlayer(pCity.getOwner())

	pPlayer.acquireCity(pCity,False,False)
	pCity = caster.plot().getPlotCity()
	pCity.changeCulture(iPlayer, 300, True)

	pCity.setCivilizationType(pPlayer2.getCivilizationType())



def reqConvertCityGela(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.isCapital():
		return False
	elif pCity.getOwner() == caster.getOwner():
		return False
	elif pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL')):
		pPlayer2 = gc.getPlayer(pCity.getOwner())
		if pPlayer2.getStateReligion() != gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
			return True
	return False



def spellConvertCityGela(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.acquireCity(pCity,False,False)



def reqConvertCityRantine(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	if pCity.getOwner() != gc.getBARBARIAN_PLAYER():
		return False
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getOwner() == gc.getBARBARIAN_PLAYER():
			if pUnit.baseCombatStr() > caster.baseCombatStr():
				return False
	return True

def spellConvertCityRantine(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.acquireCity(pCity,False,False)





def reqCraftIceGolem(caster):
	pPlot = caster.plot()
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		return True
	if pPlot.getFeatureType() == gc.getInfoTypeForString('TERRAIN_ICE'):
		return True
	return False


def spellCreateBatteringRam(caster):
	pPlot = caster.plot()
	pPlot.setFeatureType(-1, -1)

def reqCreateDenBear(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_BEAR_DEN')
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, caster.getOwner(), True) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				if pPlot2.getImprovementType() == iImprovement:
					return False
	return True

def spellCreateDenBear(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_BEAR_DEN')
	iUnit = gc.getInfoTypeForString('UNIT_BEAR')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), False, True, True)
		pPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCreateDenLion(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_LAIRS):
		return False
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_LION_DEN')
	if caster.getDamage() > 0:
		return False
	pPlot = caster.plot()
	if pPlot.isOwned():
		return False
	if pPlot.getNumUnits() != 1:
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.canHaveImprovement(iImprovement, caster.getOwner(), True) == False:
		return False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				if pPlot2.getImprovementType() == iImprovement:
					return False
	return True

def spellCreateDenLion(caster):
	pPlot = caster.plot()
	iImprovement = gc.getInfoTypeForString('IMPROVEMENT_LION_DEN')
	iUnit = gc.getInfoTypeForString('UNIT_LION')
	pPlot.setImprovementType(iImprovement)
	pPlot2 = findClearPlot(-1, caster.plot())
	if pPlot2 != -1:
		caster.setXY(pPlot2.getX(), pPlot2.getY(), False, True, True)
		pPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
		newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.convert(caster)

def reqCrewBuccaneers(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BUCCANEERS')):
		return False
	if caster.maxMoves() < 2:
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_ATTACK_SEA'):
			if gc.getUnitInfo(caster.getUnitType()).getMoves() > 2:
				return True
		return False
	return True

def reqCrewLongshoremen(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LONGSHOREMEN')):
		return False
	if caster.cargoSpaceAvailable(-1, gc.getInfoTypeForString('DOMAIN_LAND')) == 0:
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if not caster.isFull():
			if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_ESCORT_SEA'):
				return True
			if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_EXPLORE_SEA'):
				return True
			if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_MISSIONARY_SEA'):
				return True
		return False
	return True

def reqCrewNormalCrew(caster):
	pPlot = caster.plot()
	if (caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BUCCANEERS')) == False and caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SKELETON_CREW')) == False and caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LONGSHOREMEN')) == False):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_RESERVE_SEA'):
			return True
		return False
	return True

def reqCrewSkeletonCrew(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SKELETON_CREW')):
		return False
	if caster.baseCombatStr() < 1:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if (caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_ASSAULT_SEA') or caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_SETTLER_SEA')):
			return True
		return False
	return True


def effectNotDead(pCaster):
	pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)


def effectCrownOfBrillance(caster):
	caster.cast(gc.getInfoTypeForString('SPELL_CROWN_OF_BRILLANCE'))

	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED')):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), False)
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD')):
		return False
	if not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		pPlot = caster.plot()
		pPlot.changePlotCounter(-caster.getLevel()*CyGame().getGlobalCounter()/5)

def reqCrownOfBrillance(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EREMITE')):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN3'), True)
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CROWN_OF_BRILLANCE')):
		return False
	return True

def reqCrush(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				bEnemy = False
				bNeutral = False
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.getDamage() < 76:
							bEnemy = True
					else:
						bNeutral = True
				if (bEnemy and bNeutral == False):
					return True
	return False

def spellCrush(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iBestValue = 0
	pBestPlot = -1
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			bNeutral = False
			iValue = 0
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.getDamage() < 76:
							iValue += 10
					else:
						bNeutral = True
				if (iValue > iBestValue and bNeutral == False):
					iBestValue = iValue
					pBestPlot = pPlot
	if pBestPlot != -1:
		for i in range(pBestPlot.getNumUnits()):
			pUnit = pBestPlot.getUnit(i)
			pUnit.doDamage(50, 75, caster, gc.getInfoTypeForString('DAMAGE_PHYSICAL'), True)
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_CRUSH'),pBestPlot.getPoint())

def reqDeclareNationality(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.isBarbarian():
			return False
		if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
			return False
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN')) or caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_INVISIBLE')):
			return False
	return True

def spellDeclareNationality(caster):
	caster.setBlockading(False)





def spellDestroyClava(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer )
	iManes=gc.getInfoTypeForString('UNIT_MANES')
	iInf = gc.getInfoTypeForString('CIVILIZATION_INFERNAL')
	iVV = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	iD = gc.getInfoTypeForString('PROMOTION_DEMON')
	iWarcry = gc.getInfoTypeForString('PROMOTION_WARCRY')
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	iMorale = gc.getInfoTypeForString('PROMOTION_MORALE')
	pPlot = CyMap().plot(0,0)
	iCount = 0
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iVV):

			infoCiv = gc.getCivilizationInfo(iInf)
			iUnit = pUnit.getUnitType()
			iUnit = infoCiv.getCivilizationUnits(gc.getUnitInfo(iUnit).getUnitClassType())
			if iUnit == -1:
				iUnit = gc.getInfoTypeForString('UNIT_MANES')

			for iPlayer2 in range(gc.getMAX_PLAYERS()):
				pPlayer2 = gc.getPlayer(iPlayer2)
				if (pPlayer2.isAlive()):
					if pPlayer2.getCivilizationType() == iInf:

						if iUnit == gc.getInfoTypeForString('UNIT_HYBOREM'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_HYBOREM'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_LETHE'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_LETHE'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_JUDECCA'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_JUDECCA'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_OUZZA'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_OUZZA'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_MERESIN'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_MERESIN'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_SALLOS'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_SALLOS'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue
						if iUnit == gc.getInfoTypeForString('UNIT_STATIUS'):
							if pPlayer2.getLeaderType() == gc.getInfoTypeForString('LEADER_STATIUS'):
								pPlayer2.AI_changeAttitudeExtra(iPlayer,13)
							else:
								continue

						pPlayer2.AI_changeAttitudeExtra(iPlayer,2)

						py = PyPlayer(iPlayer2)
						if pPlayer2.getNumCities() > 0:
							iRnd = CyGame().getSorenRandNum(py.getNumCities(), "Gift Unit")
							pCity = py.getCityList()[iRnd]
							pPlot2 = pCity.plot()
							newUnit = pPlayer2.initUnit(iUnit, pPlot2.getX(), pPlot2.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							iCount += 1
							newUnit.convert(pUnit)
							newUnit.setHasPromotion(iD, True)
							newUnit.setHasPromotion(iMorale, True)
							newUnit.setHasPromotion(iWarcry, True)
							newUnit.setHasPromotion(iHeld, False)
							newUnit.setHasPromotion(iVV, False)
							for iProm in range(gc.getNumPromotionInfos()):
								if gc.getPromotionInfo(iProm).isEquipment():
									newUnit.setHasPromotion(iProm, False)
							CyInterface().addMessage(newUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_ESCAPE_CLAVA",()),'AS2D_UNIT_FALLS',1,gc.getUnitInfo(newUnit.getUnitType()).getButton(),ColorTypes(7),newUnit.getX(),newUnit.getY(),True,True)


	szBuffer = CyTranslator().getText("TXT_KEY_MESSAGE_ESCAPE_CLAVA_NUMBER", (iCount, ))
	CyInterface().addMessage(caster.getOwner(),True,25,szBuffer,'AS2D_UNIT_FALLS',1,'Art/Interface/Buttons/Promotions/Demon.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)

def spellDestroyNether(caster):
	iNB = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	pPlot = CyMap().plot(0,0)
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		pUnit.setHasPromotion(iNB, False)


def reqDestroyUndead(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_UNDEAD'):
						if pPlayer.isHuman():
							return True
						p2Player = gc.getPlayer(pUnit.getOwner())
						e2Team = gc.getTeam(p2Player.getTeam())
						if e2Team.isAtWar(eTeam):
							return True
	return False

def spellDestroyUndead(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getRace() == gc.getInfoTypeForString('PROMOTION_UNDEAD'):
						pUnit.doDamage(30, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), True)

def reqDispelMagic(caster):
	if caster.canDispel(gc.getInfoTypeForString('SPELL_DISPEL_MAGIC')):
		return True
	pPlot = caster.plot()
	if pPlot.getBonusType(-1) != -1:
		if gc.getBonusInfo(pPlot.getBonusType(-1)).getBonusClassType() == gc.getInfoTypeForString('BONUSCLASS_MANA'):
			if pPlot.isCity():
				return False
			if pPlot.getImprovementType() == -1:
				return True
			if not gc.getImprovementInfo(pPlot.getImprovementType()).isUnique():
				return True
	return False

def spellDispelMagic(caster):
	pPlot = caster.plot()
	if pPlot.getBonusType(-1) != -1:
		if gc.getBonusInfo(pPlot.getBonusType(-1)).getBonusClassType() == gc.getInfoTypeForString('BONUSCLASS_MANA'):
			if pPlot.getImprovementType() == -1:
				pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA'))
			else:
				if not gc.getImprovementInfo(pPlot.getImprovementType()).isUnique():
					pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA'))
					pPlot.setImprovementType(-1)

def reqDisrupt(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if caster.getTeam() == pCity.getTeam():
		return False
	return True

def spellDisrupt(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iPlayer2 = pCity.getOwner()
	pPlayer2 = gc.getPlayer(iPlayer2)
	pCity.changeHurryAngerTimer(2)
	iRnd = CyGame().getSorenRandNum(3, "Disrupt")

	if iRnd > pCity.getCulture(iPlayer2):
		iRnd =  pCity.getCulture(iPlayer2)

	if iRnd != 0:
		pCity.changeCulture(iPlayer2,-1 * iRnd,True)
	CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DISRUPT_ENEMY",()),'',1,'Art/Interface/Buttons/Spells/Disrupt.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
	CyInterface().addMessage(iPlayer2,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DISRUPT",()),'',1,'Art/Interface/Buttons/Spells/Disrupt.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
	if pCity.getCulture(iPlayer2) < 1:
		pPlayer.acquireCity(pCity,False,False)
		pPlayer2.AI_changeAttitudeExtra(iPlayer,-4)

def reqDivineRetribution(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellDivineRetribution(caster):
	iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
	iUndead = gc.getInfoTypeForString('PROMOTION_UNDEAD')
	for iPlayer in range(gc.getMAX_PLAYERS()):
		player = gc.getPlayer(iPlayer)
		if player.isAlive():
			py = PyPlayer(iPlayer)
			for pUnit in py.getUnitList():
				if (pUnit.getRace() == iDemon or pUnit.getRace() == iUndead):
					pUnit.doDamage(70, 100, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), False)

def reqDomination(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	if pPlayer.isHuman() == False:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.isAlive():
						if not pUnit.isDelayedDeath():
							if eTeam.isAtWar(pUnit.getTeam()):
								iResist = pUnit.getResistChance(caster, gc.getInfoTypeForString('SPELL_DOMINATION'))
								if iResist < iResistMax:
									return True
	return False


def spellDomination(caster):
	iSpell = gc.getInfoTypeForString('SPELL_DOMINATION')
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	iBestValue = 0
	pBestUnit = -1
	if pPlayer.isHuman() == False:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					iValue = 0
					if pUnit.isAlive():
						if pUnit.isDelayedDeath() == False:
							if eTeam.isAtWar(pUnit.getTeam()):
								iResist = pUnit.getResistChance(caster, iSpell)
								if iResist < iResistMax:
									iValue = pUnit.baseCombatStr() * 10
									iValue = iValue + (100 - iResist)
									if iValue > iBestValue:
										iBestValue = iValue
										pBestUnit = pUnit
	if pBestUnit != -1:
		pPlot = caster.plot()
		if pBestUnit.isResisted(caster, iSpell) == False:
			CyInterface().addMessage(pBestUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(7),pBestUnit.getX(),pBestUnit.getY(),True,True)
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION_ENEMY", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			newUnit = pPlayer.initUnit(pBestUnit.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(pBestUnit)
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
		else:
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION_FAILED", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(7),pPlot.getX(),pPlot.getY(),True,True)
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)






def reqUnsummon(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_DIMENSIONAL_MANA')):
			return False
	iRange = 1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION1')):
		iRange +=1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION2')):
		iRange +=1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION3')):
		iRange +=1
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-iRange, iX+iRange+1, 1):
		for iiY in range(iY-iRange, iY+iRange+1, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if pUnit.getSummoner() != -1:
						return True
	return False


def spellUnsummon(caster):
	iRange = 1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION1')):
		iRange +=1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION2')):
		iRange +=1
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION3')):
		iRange +=1
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-iRange, iX+iRange+1, 1):
		for iiY in range(iY-iRange, iY+iRange+1, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if pUnit.getSummoner() != -1:
						pUnit.setExperience(0, -1)
						pUnit.kill(True, caster.getOwner())


def spellCaveTrials(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CASWALLAWN')):
		CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CAVE_TRIALS_CASS", ()),'',1,'Art/Interface/Buttons/Buildings/Caveofancestors.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)
	else:
		if CyGame().getSorenRandNum(10, "Cave Trials") < 8:
			caster.changeFreePromotionPick(1)
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CAVE_TRIALS_SUCCESS", ()),'',1,'Art/Interface/Buttons/Buildings/Caveofancestors.dds',ColorTypes(8),caster.getX(),caster.getY(),True,True)

			if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3')) and CyGame().getSorenRandNum(10, "Arena Battle") < 2:
				for pUnit in (PyPlayer(caster.getOwner())).getUnitList():
					if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3')) and pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ADEPT'):
						if caster.getLevel() > pUnit.getLevel():
							if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CASWALLAWN')):
								pUnit.kill(True, PlayerTypes.NO_PLAYER)
								CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CAVE_TRIALS_OLD_CASS", ()),'',1,'Art/Interface/Buttons/Buildings/Caveofancestors.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
						else:
							break
						caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CASWALLAWN'), True)
						CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CAVE_TRIALS_NEW_CASS", ()),'',1,'Art/Interface/Buttons/Buildings/Caveofancestors.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
						caster.setName("The Caswallawn")
		else:
			CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_CAVE_TRIALS_DEATH", ()),'',1,'Art/Interface/Buttons/Buildings/Caveofancestors.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
			caster.kill(True, PlayerTypes.NO_PLAYER)




def reqFreeBrigit(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_EVIL'):
		return False
	return True

def spellFreeBrigit(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BRIGIT'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	pPlayer.setAlignment(gc.getInfoTypeForString('ALIGNMENT_GOOD'))
	pPlot = pCaster.plot()
	pPlot.setImprovementType(-1)
	if pPlayer.isHuman():
		t = "TROPHY_FEAT_RESCUE_BRIGIT"
		if not CyGame().isHasTrophy(t):
			CyGame().changeTrophyValue(t, 1)

def reqUnleashOdio(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_GOOD'):
		return False
	return True


def spellUnleashOdio(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ODIO'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	pPlayer.setAlignment(gc.getInfoTypeForString('ALIGNMENT_EVIL'))
	pPlot = pCaster.plot()
	pPlot.setImprovementType(-1)





def reqEarthquake(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		eTeam = pPlayer.getTeam()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					p2Player = gc.getPlayer(pPlot.getOwner())
					if pPlot.isOwned():
						e2Team = gc.getTeam(p2Player.getTeam())
						if e2Team.isAtWar(eTeam) == False:
							return False
	return True

def spellEarthquake(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if (pPlot.isCity() or pPlot.getImprovementType() != -1):
					if pPlot.isOwned():
						cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
				if pPlot.isCity():
					pCity = pPlot.getPlotCity()
					for i in range(gc.getNumBuildingInfos()):
						iRnd = CyGame().getSorenRandNum(100, "Bob")
						if (gc.getBuildingInfo(i).getConquestProbability() != 100 and iRnd < 25):
							pCity.setNumRealBuilding(i, 0)
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if pUnit.isFlying() == False:
						pUnit.setFortifyTurns(0)
				iRnd = CyGame().getSorenRandNum(100, "Bob")
				if iRnd < 25:
					iImprovement = pPlot.getImprovementType()
					if iImprovement != -1:
						if gc.getImprovementInfo(iImprovement).isPermanent() == False:
							pPlot.setImprovementType(-1)







def reqEnlightenCity(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	for iTarget in range(gc.getNumReligionInfos()):
		if (pCity.isHasReligion(iTarget) and pCity.isHolyCityByType(iTarget) == False):
			return True
	return False

def spellEnlightenCity(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	iRnd = CyGame().getSorenRandNum(4, "Bob")
	for iTarget in range(gc.getNumReligionInfos()):
		if (pCity.isHasReligion(iTarget) and not pCity.isHolyCityByType(iTarget)):
			pCity.setHasReligion(iTarget, False, True, True)
			iRnd += 1
			for i in range(gc.getNumBuildingInfos()):
				if gc.getBuildingInfo(i).getPrereqReligion() == iTarget:
					pCity.setNumRealBuilding(i, 0)
	if iRnd >= 1:
		pCity.changeHurryAngerTimer(iRnd)



def reqBuildAltarLuon1(pCaster):
	iBuild1 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR')
	iBuild2 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_ANOINTED')
	iBuild3 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_BLESSED')
	iBuild4 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_CONSECRATED')
	iBuild5 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_DIVINE')
	iBuild6 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_EXALTED')
	iBuild7 = gc.getInfoTypeForString('BUILDING_ALTAR_OF_THE_LUONNOTAR_FINAL')
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		if pCity.getNumRealBuilding(iBuild1) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild2) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild3) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild4) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild5) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild6) > 0:
			return False
		if pCity.getNumRealBuilding(iBuild7) > 0:
			return False
	return True


def spellRemoveBuilding(pCaster, sBuilding):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setNumRealBuilding(gc.getInfoTypeForString(sBuilding), 0)
	pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)



def spellEnterPortal(caster):
	pPlot = caster.plot()
	iX = pPlot.getPortalExitX()
	iY = pPlot.getPortalExitY()
	pExitPlot = CyMap().plot(iX,iY)
	if not pExitPlot.isNone():
		caster.setXY(iX, iY, False, True, True)


def spellIntoTheMist(pCaster):
	for iPlotIndex in range(CyMap().numPlots()):
		pLoopPlot = CyMap().plotByIndex(iPlotIndex)
		if pLoopPlot.isOwned():
			if pLoopPlot.getOwner() == pCaster.getOwner():
				for iPlayer in range(gc.getMAX_PLAYERS()):
					pPlayer = gc.getPlayer(iPlayer)
					iTeam = pPlayer.getTeam()
					if iTeam != pCaster.getTeam():
						pLoopPlot.setRevealed(iTeam, False, False, iTeam)
						pLoopPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_LAND"), -1)
						pLoopPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_ANIMAL"), -1)
						pLoopPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_ALL"), -1)
						pLoopPlot.updateVisibility()



def postCombatNegatusMysterium(pCaster,pOpponent):
	for iCount in range(gc.getNumPromotionInfos()):
		if pOpponent.isHasPromotion(iCount):
			if gc.getPromotionInfo(iCount).getBonusPrereq() != -1:
				if gc.getBonusInfo(gc.getPromotionInfo(iCount).getBonusPrereq()).getBonusClassType() == gc.getInfoTypeForString('BONUSCLASS_MANA'):
					pOpponent.setHasPromotion(iCount, False)





def postCombatValinSaverous(pCaster,pOpponent):

	if pOpponent.getUnitType() == gc.getInfoTypeForString('UNIT_SAVEROUS'):
		pOpponent.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), False)
		pOpponent.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), True)
		pPlayer = gc.getPlayer(pCaster.getOwner())
		iUnit = gc.getInfoTypeForString('UNIT_SQUIRE_SAVEROUS')
		newUnit = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		for i in range(gc.getNumPromotionInfos()):
			newUnit.setHasPromotion(i, pOpponent.isHasPromotion(i))
			if gc.getPromotionInfo(i).isEquipment():
				newUnit.setHasPromotion(i, False)
		newUnit.setDamage(pOpponent.getDamage()/2, pCaster.getOwner())
		newUnit.setLevel(pOpponent.getLevel())
		newUnit.setExperience(pOpponent.getExperience(), -1)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GOLEM'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)





def spellEntertain(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	iPlayer2 = pCity.getOwner()
	if iPlayer != iPlayer2:
		pPlayer = gc.getPlayer(iPlayer)
		pPlayer2 = gc.getPlayer(iPlayer2)
		iGold = (pCity.getPopulation() / 2) + 1
		if pPlayer2.getGold() < iGold:
			iGold = pPlayer2.getGold()
		pPlayer.changeGold(iGold)
		szBuffer = CyTranslator().getText("TXT_KEY_MESSAGE_ENTERTAIN_GOOD", (iGold, ))
		CyInterface().addMessage(iPlayer,True,25,szBuffer,'',1,'Art/Interface/Buttons/Spells/Entertain.dds',ColorTypes(8),pCity.getX(),pCity.getY(),True,True)
		iGold = iGold * -1
		pPlayer2.changeGold(iGold)
		szBuffer = CyTranslator().getText("TXT_KEY_MESSAGE_ENTERTAIN_BAD", (iGold, ))
		CyInterface().addMessage(iPlayer2,True,25,szBuffer,'',1,'Art/Interface/Buttons/Spells/Entertain.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
	pCity.changeHappinessTimer(2)

def effectEscapeAsylum(pCaster):
	pPlot = pCaster.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getOwner() == pCaster.getOwner():
			if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_ASYLUM')) > 0:
				return False
	pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_COMMITTED'),False)
	pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'),True)
	pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'),True)
	return False

def reqEscape(caster):
	if caster.getOwner() == gc.getBARBARIAN_PLAYER():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_DIMENSIONAL_MANA')):
			return False
	pPlot = caster.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getOwner() == caster.getOwner():
			if pCity.isCapital():
				return False
	if pPlayer.isHuman() == False:
		if caster.getDamage() >= 50:
			return False
	return True

def reqExploreLair(caster, sSpell):
	if caster.isBarbarian():
		return False
	if caster.getSummoner() != -1:
		return False
	if caster.getDuration() > 0:
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_BIRD'):
		return False
	if caster.isOnlyDefensive():
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	pPlot = caster.plot()
	if not pPlot.isPythonActive():
		return False
	if sSpell != -1:
		iSpell = gc.getInfoTypeForString(sSpell)
		for iUnit in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(iUnit)
			if pUnit.getDelayedSpell() == iSpell:
				return False
	return True

def spellExploreLair(caster):
	pPlot = caster.plot()
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair") + caster.getLevel()
	iDestroyLair = 0
	if iRnd < 14:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 14 and iRnd < 44:
		iDestroyLair = cf.exploreLairBad(caster)
	if iRnd >= 44 and iRnd < 74:
		iDestroyLair = cf.exploreLairNeutral(caster)
	if iRnd >= 74 and iRnd < 94:
		iDestroyLair = cf.exploreLairGood(caster)
	if iRnd >= 94:
		iDestroyLair = cf.exploreLairBigGood(caster)
	iImprovement = pPlot.getImprovementType()
	if iImprovement != -1 :
		if iDestroyLair > CyGame().getSorenRandNum(100, "Explore Lair"):
			if not gc.getImprovementInfo(iImprovement).isUnique():
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LAIR_DESTROYED", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				pPlot.setImprovementType(-1)
			else:
				pPlot.setPythonActive(False)

	caster.changeExperience(1, -1, False, False, False)

def spellExploreLairEpic(caster):
	pPlot = caster.plot()
	iRnd = CyGame().getSorenRandNum(100, "Explore Lair") + caster.getLevel()
	iDestroyLair = 0
	if iRnd >= 20:
		iDestroyLair = cf.exploreLairBad(caster)
	elif iRnd < 90:
		iDestroyLair = cf.exploreLairBigBad(caster)
	if iRnd >= 80:
		iDestroyLair = cf.exploreLairBigGood(caster)
	iImprovement = pPlot.getImprovementType()
	if iImprovement != -1 :
		if iDestroyLair > CyGame().getSorenRandNum(100, "Explore Lair"):
			if not gc.getImprovementInfo(iImprovement).isUnique():
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_LAIR_DESTROYED", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				pPlot.setImprovementType(-1)
	#		else:
	#			pPlot.setPythonActive(False)

	caster.changeExperience(1, -1, False, False, False)

def reqFeast(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	if pCity.getPopulation() < 3:
		return False
	return True

def spellFeast(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer.setAlignment(gc.getInfoTypeForString('ALIGNMENT_EVIL'))

	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	caster.changeExperience(pCity.getPopulation()*2/3, -1, False, False, False)
	pCity.changeHurryAngerTimer(3)

	pPlayer2 = gc.getPlayer(pCity.getOriginalOwner())
	pPlayer2.AI_changeAttitudeExtra(iPlayer,-1)





def spellConsumeSoul(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlayer.setAlignment(gc.getInfoTypeForString('ALIGNMENT_EVIL'))
	caster.changeImmortal(1)
	caster.setMadeAttack(False)
	caster.setHasCasted(False)
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.changeHurryAngerTimer(3)
	pPlayer2 = gc.getPlayer(pCity.getOriginalOwner())
	iPlayer = caster.getOwner()
	pPlayer2.AI_changeAttitudeExtra(iPlayer,-1)







def reqFeed(pCaster):
	if pCaster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
		return False
	if pCaster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if pCaster.getDuration() > 0:
		return False
	iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
	iBlood = gc.getInfoTypeForString('UNIT_BLOODPET')

	pPlayer = gc.getPlayer(pCaster.getOwner())
	pPlot = pCaster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iVamp) and pCaster.getID()  != pUnit.getID()  and pUnit.getOwner() == pCaster.getOwner() and gc.getUnitInfo(pCaster.getUnitType()).getTier() < gc.getUnitInfo(pUnit.getUnitType()).getTier()  and pCaster.getLevel() < pUnit.getLevel():
			if not pPlayer.isHuman():
				if pUnit.getDamage() > 25:
					return True
			elif pUnit.getDamage() > 0:
				return True
			elif pCaster.getUnitType() == iBlood:
				if pUnit.isHasCasted() or (pUnit.getMoves() - gc.getMOVE_DENOMINATOR() < 0):
					return True
			elif pUnit.isMadeAttack() and not pUnit.isBlitz ():
				return True
	return False




def spellFeed(pCaster):
	iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
	pPlayer = gc.getPlayer(pCaster.getOwner())
	pPlot = pCaster.plot()
	pVamp = -1
	pVampDam = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.isHasPromotion(iVamp) and pCaster.getID() != pUnit.getID()  and pUnit.getOwner() == pCaster.getOwner() and gc.getUnitInfo(pCaster.getUnitType()).getTier()  < gc.getUnitInfo(pUnit.getUnitType()).getTier()  and pCaster.getLevel() < pUnit.getLevel():
			if pUnit.getDamage() > pVampDam:
				pVamp = pUnit
				pVampDam = pUnit.getDamage()
	if pVamp != -1:
		pVamp.changeDamage(-20,0)
		pVamp.setMadeAttack(False)

		if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_BLOODPET'):
			iMoves = pVamp.getMoves() - gc.getMOVE_DENOMINATOR()
			if iMoves < 0:
				iMoves = 0
			pVamp.setMoves(iMoves)
			pVamp.setHasCasted(False)

			pVamp.changeExperience(pCaster.getExperience() / 2, -1, False, False, False)
		pCaster.kill(True,0)


def reqForTheHorde(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
	eTeam = gc.getTeam(pPlayer.getTeam())
	if eTeam.isAtWar(bPlayer.getTeam()):
		return False
	if bPlayer.getNumUnits() == 0:
		return False
	if pPlayer.isHuman() == False:
		map = gc.getMap()
		if pPlayer.getNumCities() > (gc.getWorldInfo(map.getWorldSize()).getTargetNumCities() - 1):
			return True
		if eTeam.getAtWarCount(True) == 0:
			return False
		if bPlayer.getNumUnits() < (pPlayer.getNumCities() * 5):
			return False
	return True

def spellForTheHorde(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = gc.getPlayer(caster.getOwner()).getTeam()
	eTeam = gc.getTeam(iTeam)
	iBarbTeam = gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam()
	eTeam.makePeace(iBarbTeam)

	iHero = gc.getInfoTypeForString('PROMOTION_HERO')
	iOrc = gc.getInfoTypeForString('PROMOTION_ORC')
	iDisciple = gc.getInfoTypeForString('UNITCLASS_DISCIPLE_OF_ACHERON')
	iSon = gc.getInfoTypeForString('UNITCLASS_SON_OF_THE_INFERNO')
	py = PyPlayer(gc.getBARBARIAN_PLAYER())
	for pUnit in py.getUnitList():
		if (pUnit.getRace() == iOrc):
			if ( (pUnit.getUnitClassType()!= iDisciple) and (pUnit.getUnitClassType()!= iSon) ):
				if CyGame().getSorenRandNum(100, "Bob") < 50:
					newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.convert(pUnit)

def reqFormWolfPack(caster):
	pPlot = caster.plot()
	iWolf = gc.getInfoTypeForString('UNIT_WOLF')
	iCount = 0
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iWolf:
			if pUnit.getOwner() == caster.getOwner():
				iCount += 1
	if iCount < 2:
		return False
	return True

def spellFormWolfPack(caster):
	pPlot = caster.plot()
	iWolf = gc.getInfoTypeForString('UNIT_WOLF')
	pWolf2 = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iWolf:
			if pUnit.getOwner() == caster.getOwner():
				if pUnit.getID() != caster.getID():
					pWolf2 = pUnit
	if pWolf2 != -1:
		pPlayer = gc.getPlayer(caster.getOwner())
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WOLF_PACK'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.setExperience(caster.getExperience() + pWolf2.getExperience(), -1)
		newUnit.setUnitAIType(gc.getInfoTypeForString('UNITAI_ATTACK'))
		caster.kill(True, PlayerTypes.NO_PLAYER)
		pWolf2.kill(True, PlayerTypes.NO_PLAYER)

def reqGiftsOfNantosuelta(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
#	if pPlayer.isHuman() == False:
#		map = gc.getMap()

#		if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_ONE_CITY_CHALLENGE) or gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_SETTLERS):
#			if pPlayer.getNumCities() > 0:
#				return True
#		if CyGame().getSorenRandNum(200, "Gifts") == 1:
#			return True
#		if pPlayer.getNumCities() < gc.getWorldInfo(map.getWorldSize()).getTargetNumCities():
#			return False
	return True

def spellGiftsOfNantosuelta(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iGoldenHammer = gc.getInfoTypeForString('PROMOTION_GOLDEN_HAMMER')
	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.getUnitCombatType() != -1:
			pUnit.setHasPromotion(iGoldenHammer, True)

def reqGiftVampirism(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			if not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
				if pUnit.getLevel() >= 6:
					return True
				if (pUnit.getLevel() >= 4 and pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MOROI')):
					return True
	return False

def spellGiftVampirism(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			if not pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
				if pUnit.getLevel() >= 6:
					pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE'),True)
				if (pUnit.getLevel() >= 4 and pUnit.getUnitType() == gc.getInfoTypeForString('UNIT_MOROI')):
					pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE'),True)



def reqAcceptVampirism(pCaster):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
		return False
	if pCaster.getReligion() ==  gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
		return False
	if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_MOROI'):
		if pCaster.getLevel() < 4:
			return False
	elif pCaster.getLevel() < 6:
		return False
	pPlot = pCaster.plot()
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getOwner() == pCaster.getOwner():
			if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_GOVERNORS_MANOR')) > 0:
				return True
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getOwner() == pCaster.getOwner() and pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_VAMPIRE')):
			return True
	return False


def spellVampireMagic(unit):
	pPlayer = gc.getPlayer(unit.getOwner())
	iCiv = pPlayer.getCivilizationType()
	iStateReligion = pPlayer.getStateReligion()
	iBarb = gc.getInfoTypeForString('CIVILIZATION_BARBARIAN')

	if unit.getReligion() ==  gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
		unit.setReligion(-1)
	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUMMONER'), True)
	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_ARCANE')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ARCANE'), True)
	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUNDERED')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUNDERED'), True)

	iChanneling3 = gc.getInfoTypeForString('PROMOTION_CHANNELING3')


	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_ARCANE')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ARCANE'), True)
	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUMMONER'), True)
	if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUNDERED')):
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUNDERED'), True)


	iMana = gc.getInfoTypeForString('BONUS_MANA_BODY')
	iNum = pPlayer.getNumAvailableBonuses(iMana)
	if iCiv == iBarb:
		iNum += CyGame().getSorenRandNum(unit.area().getNumBonuses(iMana), "Barbaran Mana")
	if iNum > 1:
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1'), True)
		if iNum > 2:
			unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY2'), True)
			if (iNum > 3 and unit.isHasPromotion(iChanneling3)):
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY3'), True)

	iMana = gc.getInfoTypeForString('BONUS_MANA_MIND')
	iNum = pPlayer.getNumAvailableBonuses(iMana)
	if iCiv == iBarb:
		iNum += CyGame().getSorenRandNum(unit.area().getNumBonuses(iMana), "Barbaran Mana")
	if iNum > 2:
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1'), True)
		if iNum > 3:
			unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND2'), True)
			if (iNum > 4 and unit.isHasPromotion(iChanneling3)):
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND3'), True)

	iMana = gc.getInfoTypeForString('BONUS_MANA_SHADOW')
	iNum = pPlayer.getNumAvailableBonuses(iMana)
	if iCiv == iBarb:
		iNum += CyGame().getSorenRandNum(unit.area().getNumBonuses(iMana), "Barbaran Mana")
	if iStateReligion ==gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
		iNum += 1
	if iNum > 2:
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1'), True)
		if iNum > 3:
			unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW2'), True)
			if (iNum > 4 and unit.isHasPromotion(iChanneling3)):
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW3'), True)

	iMana = gc.getInfoTypeForString('BONUS_MANA_DEATH')
	iNum = pPlayer.getNumAvailableBonuses(iMana)
	if iCiv == iBarb:
		iNum += CyGame().getSorenRandNum(unit.area().getNumBonuses(iMana), "Barbaran Mana")
	if iNum > 2:
		unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
		if iNum > 3:
			unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), True)
			if (iNum > 4 and unit.isHasPromotion(iChanneling3)):
				unit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3'), True)

def spellGiveHammerToCraftsman(caster):
	pCity = caster.plot().getPlotCity()
	pCity.changeFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_ENGINEER'), 1)

def reqHastursRazor(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = pPlayer.getTeam()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getDamage() > 0:
						if pPlayer.isHuman():
							return True
						if pUnit.getOwner() == caster.getOwner():
							return True
	return False

def spellHastursRazor(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	listDamage = []
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					listDamage.append(pUnit.getDamage())
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					iRnd = listDamage[CyGame().getSorenRandNum(len(listDamage), "Hasturs Razor")]
					if iRnd != pUnit.getDamage():
						CyInterface().addMessage(pUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_HASTURS_RAZOR",()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Spells/Hasturs Razor.dds',ColorTypes(7),pUnit.getX(),pUnit.getY(),True,True)
						if pUnit.getOwner() != caster.getOwner():
							CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_HASTURS_RAZOR",()),'AS2D_CHARM_PERSON',1,'Art/Interface/Buttons/Spells/Hasturs Razor.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
						pUnit.setDamage(iRnd, caster.getOwner())

def reqHeal(caster):
	pPlot = caster.plot()
	iPoisoned = gc.getInfoTypeForString('PROMOTION_POISONED')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getDamage() > 0):
			return True
		if pUnit.isHasPromotion(iPoisoned):
			return True
	return False

def spellHeal(caster,amount):
	pPlot = caster.plot()
	iPoisoned = gc.getInfoTypeForString('PROMOTION_POISONED')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		pUnit.setHasPromotion(iPoisoned,False)
		if pUnit.isAlive():
			pUnit.changeDamage(-amount, PlayerTypes.NO_PLAYER)

def reqHealingSalve(caster):
	if caster.getDamage() == 0:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if caster.getDamage() < 25:
			return False
	return True

def spellHealingSalve(caster):
	caster.setDamage(0, caster.getOwner())
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), False)

def reqHellfire(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	if CyGame().getGlobalCounter() < 60:
		return False
	if pPlot.isCity():
		return False
	if pPlot.isWater():
		return False
	if pPlot.getImprovementType() != -1:
		return False
	iHellFire = gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE')
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				if pPlot2.getImprovementType() == iHellFire:
					return False
	if pPlayer.isHuman() == False:
		if pPlot.isOwned():
			if pPlot.getOwner() == caster.getOwner():
				return False
	return True

def spellHellfire(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())

	iSect = gc.getInfoTypeForString('UNIT_SECT_OF_FLIES')
	iImp = gc.getInfoTypeForString('UNIT_IMP')
	iHellfire = gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE')
	iHellfireChance = gc.getDefineINT('HELLFIRE_CHANCE')

	gc.getTeam(pPlayer.getTeam()).makePeace(gc.getBARBARIAN_TEAM())

	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if not pPlot.isWater():
			if pPlot.getNumUnits() == 0:
				if not pPlot.isCity():
					if pPlot.isFlatlands():
						if pPlot.getBonusType(-1) == -1:
							if CyGame().getSorenRandNum(10000, "Hellfire") < iHellfireChance:
								iImprovement = pPlot.getImprovementType()
								bValid = True
								if iImprovement != -1 :
									if gc.getImprovementInfo(iImprovement).isPermanent():
										bValid = False
								if bValid :
									pPlot.setImprovementType(iHellfire)
									pPlayer.initUnit(iSect, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
									pPlayer.initUnit(iImp, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)





def reqHeraldsCall(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			return True
	return False


def effectHeraldsBlessing(unit):
	if CyGame().getSorenRandNum(10, "Herald") < 7:
		cf.giftUnit(gc.getInfoTypeForString('UNIT_ANGEL'), gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'), unit.getExperience(), unit.plot(), unit.getOwner(),unit.getReligion())
		unit.kill(True, PlayerTypes.NO_PLAYER)



def spellHeraldsCall(caster):
	iValor = gc.getInfoTypeForString('PROMOTION_VALOR')
	iBlessed = gc.getInfoTypeForString('PROMOTION_BLESSED')
	iCourage = gc.getInfoTypeForString('PROMOTION_COURAGE')
	iLoyalty = gc.getInfoTypeForString('PROMOTION_LOYALTY')
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.isAlive() and pUnit.getOwner() == caster.getOwner()):
			pUnit.setHasPromotion(iValor,True)
			pUnit.setHasPromotion(iBlessed, True)
			pUnit.setHasPromotion(iCourage, True)
			pUnit.setHasPromotion(iLoyalty, True)
			pUnit.setDuration(1)

def reqHide(caster):
	if caster.isMadeAttack():
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN')):
		return False
	return True

def reqHireScorpionClan(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
	eTeam = gc.getTeam(pPlayer.getTeam())
	if eTeam.isAtWar(bPlayer.getTeam()):
		return False
	return True

def spellHireArcher(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ARCHER_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireChariot(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_CHARIOT_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireGoblin(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_GOBLIN_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

def spellHireUnits(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pCity = caster.plot().getPlotCity()
	iEvent = CvUtil.findInfoTypeNum(gc.getEventTriggerInfo, gc.getNumEventTriggerInfos(),'EVENTTRIGGER_MAGNADINE_HIRE_UNITS')
	triggerData = pPlayer.initTriggeredData(iEvent, True, pCity.getID(), pCity.getX(), pCity.getY(), iPlayer, -1, -1, -1, -1, -1)

def spellHireWolfRider(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WOLF_RIDER_SCORPION_CLAN'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)



def reqIllusion(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	return True

def spellIllusion(caster):
	iRnd = CyGame().getSorenRandNum(caster.getLevel(), "Illusion")
	pPlayer = gc.getPlayer(caster.getOwner())
	iX = caster.getX()
	iY = caster.getY()
	iCount = 0
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if not pLoopPlot.isNone():
				for i in range(pLoopPlot.getNumUnits()):
					pUnit = pLoopPlot.getUnit(i)
					iCount += 1
					if iCount > iRnd:
						return
					newUnit = pPlayer.initUnit(pUnit.getUnitType(), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
					newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION'), True)
					newUnit.setHasCasted(True)
					newUnit.setIgnoreHide(True)

					newUnit.setSummoner(caster.getID())

					if pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')):
						newUnit.setDuration(2)
					else:
						newUnit.setDuration(1)


def reqImpersonateLeader(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getOwner() == caster.getOwner():
		return False
	if gc.getPlayer(pCity.getOwner()).isHuman():
		return False
	return True

def spellImpersonateLeader(caster):
	pCity = caster.plot().getPlotCity()
	iNewPlayer = pCity.getOwner()
	iOldPlayer = caster.getOwner()
	iTimer = 5 + CyGame().getSorenRandNum(10, "Impersonate Leader")
	CyGame().reassignPlayerAdvanced(iOldPlayer, iNewPlayer, iTimer)

def reqInquisition(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	StateBelief = pPlayer.getStateReligion()
	UnitBelief = caster.getReligion()
	if UnitBelief != StateBelief:
		if StateBelief != -1:
			return False
	if (StateBelief != gc.getPlayer(pCity.getOwner()).getStateReligion()):
		return False
	iSpell = gc.getInfoTypeForString('SPELL_INQUISITION')
	for iUnit in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(iUnit)
		if pUnit.getDelayedSpell() == iSpell:
			return False
	for iTarget in range(gc.getNumReligionInfos()):
		if UnitBelief != iTarget:
			if (StateBelief != iTarget and pCity.isHasReligion(iTarget) and pCity.isHolyCityByType(iTarget) == False):
				return True
	return False

def spellInquisition(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	StateBelief = gc.getPlayer(pCity.getOwner()).getStateReligion()
	UnitBelief = caster.getReligion()
	iRnd = CyGame().getSorenRandNum(4, "Bob")
	if StateBelief == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
		iRnd = iRnd - 1
	for iTarget in range(gc.getNumReligionInfos()):
		if UnitBelief != iTarget:
			if (not StateBelief == iTarget and pCity.isHasReligion(iTarget) and not pCity.isHolyCityByType(iTarget)):
				pCity.setHasReligion(iTarget, False, True, True)
				iRnd += 1
				for i in range(gc.getNumBuildingInfos()):
					if gc.getBuildingInfo(i).getPrereqReligion() == iTarget:
						pCity.setNumRealBuilding(i, 0)
	if iRnd >= 1:
		pCity.changeHurryAngerTimer(iRnd)

def reqIraUnleashed(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_IRA')) >= 4:
		return False
	return True

def spellIraUnleashed(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iCount = 4 - pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_IRA'))
	for i in range(iCount):
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_IRA'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

		newUnit.setSummoner(caster.getID())
def reqKidnap(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getTeam() == caster.getTeam():
		return False
	i = 0
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER'))
	i = i + pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST'))
	if i == 0:
		return False
	return True

def spellKidnap(caster):
	pCity = caster.plot().getPlotCity()
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_PROPHET')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_PRIEST')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_ARTIST')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_ARTIST')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_MERCHANT')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_MERCHANT')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_ENGINEER')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_ENGINEER')
	if pCity.getFreeSpecialistCount(gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST')) > 0:
		iUnit = gc.getInfoTypeForString('UNIT_SCIENTIST')
		iSpec = gc.getInfoTypeForString('SPECIALIST_GREAT_SCIENTIST')
	iChance = caster.baseCombatStr() * 8
	if iChance > 95:
		iChance = 95
	pPlayer = gc.getPlayer(caster.getOwner())
	if CyGame().getSorenRandNum(100, "Kidnap") < iChance:
		newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		pCity.changeFreeSpecialistCount(iSpec, -1)
	else:
		if CyGame().getSorenRandNum(100, "Kidnap") < 50:
			caster.setXY(pPlayer.getCapitalCity().getX(), pPlayer.getCapitalCity().getY(), False, True, True)
		else:
			caster.kill(True, PlayerTypes.NO_PLAYER)
		cf.startWar(caster.getOwner(), pCity.getOwner(), WarPlanTypes.WARPLAN_TOTAL)


def reqLegends(pCaster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_ACHERON):
		return False
	return True


def spellLegends(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	gc.getGame().setHolyCity(gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON'), pCity, True)
	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		pPlayer2 = gc.getPlayer(iPlayer2)
		for pyCity in PyPlayer(iPlayer2).getCityList():
			if CyGame().getSorenRandNum(10, "Bob") < 3:
				pCity2 = pyCity.GetCy()
				pCity2.setHasReligion(gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON'), True, True, True)

		py = PyPlayer(iPlayer2)
		for pUnit in py.getUnitList():
			if CyGame().getSorenRandNum(50, "Cult of Dragon") < 2:
				pUnit.setReligion(gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON'))

def effectEremite(pCaster):
	pPlot = pCaster.plot()
	if (not pPlot.isCity()) and pPlot.getImprovementType() == -1 and pPlot.getNumUnits() <2 and pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT') and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS'):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EREMITE'), True)
	else:
		for iUnit in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(iUnit)
			pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_EREMITE'), False)



def effectStopRebelling(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO')) or caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEVOTION')) or caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY')):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)

def effectCultusDraconis(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRAGON')):
		return False
	elif pPlayer.isBarbarian():
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		return False
	elif pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_KURIOTATES'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_KURIOTATES'))
		return False
	elif pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SHEAIM'):
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_SHEAIM'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_SHEAIM'))
		return False
	elif pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_ACHERON')) >0:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_BARBARIAN'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_BARBARIAN'))
		return False
	elif pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_ABASHI')) >0:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_SHEAIM'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_SHEAIM'))
		return False
	elif pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_EURABATRES')) >0:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_KURIOTATES'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_KURIOTATES'))
		return False
	elif pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_DRIFA')) >0:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_ILLIANS'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_ILLIANS'))
		return False
	elif pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_THALATTH')) >0:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DRAGON_FANATIC'):
			if caster.getUnitArtStyleType() != gc.getInfoTypeForString('UNIT_ARTSTYLE_LANUN'):
				caster.setUnitArtStyleType(gc.getInfoTypeForString('UNIT_ARTSTYLE_LANUN'))
		return False
	else:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), False)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), True)
		iDr = gc.getInfoTypeForString('PROMOTION_DRAGON')
		iCult = gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON')
		iX = caster.getX()
		iY = caster.getY()
		for iiX in range(iX-2, iX+3, 1):
			for iiY in range(iY-2, iY+3, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					for i in range(pPlot.getNumUnits()):
						pUnit = pPlot.getUnit(i)
						if pUnit.getOwner() != caster.getOwner():
							pPlayer = gc.getPlayer(pUnit.getOwner())
							if pUnit.getRace() == iDr:
								newUnit = pPlayer.initUnit(caster.getUnitType(), pUnit.getX(), pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.convert(caster)
								newUnit.setReligion(iCult)
								return False
	return False



def effectDefectAuric(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getLeaderType() == gc.getInfoTypeForString('LEADER_AURIC'):
		return False
	if gc.getGame().getProjectCreatedCount(gc.getInfoTypeForString('PROJECT_THE_DRAW')) > 0:
		pPlot = caster.plot()
		if pPlot.isOwned():
			pPlayer = gc.getPlayer(pPlot.getOwner())
			if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_AURIC')) >0:
				iTeam = pPlayer.getTeam()
				eTeam = gc.getTeam(iTeam)
				if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')) or eTeam.isAtWar(caster.getTeam()):
					pPlot = cf.findClearPlot(-1, pPlot)
					newUnit = pPlayer.initUnit(caster.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.convert(caster)
					return False
		iX = caster.getX()
		iY = caster.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					for i in range(pPlot.getNumUnits()):
						pUnit = pPlot.getUnit(i)
						pPlayer = gc.getPlayer(pUnit.getOwner())
						if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_AURIC')) >0:
							iTeam = pPlayer.getTeam()
							eTeam = gc.getTeam(iTeam)
							if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')) or eTeam.isAtWar(caster.getTeam()):
								newUnit = pPlayer.initUnit(caster.getUnitType(), pUnit.getX (),pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
								newUnit.convert(caster)
								return False
	return False


def effectMercenaryFee(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if not pPlayer.isBarbarian():
		iGold = pCaster.getLevel()
		if pPlayer.getGold() > iGold:
			pPlayer.changeGold(-iGold)
		else:
			bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
			pPlot = pCaster.plot()
			pPlot = cf.findClearPlot(-1, pPlot)
			newUnit = bPlayer.initUnit(pCaster.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(pCaster)

def effectDefectLugus(caster):
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), False)
	iEmp = gc.getInfoTypeForString('RELIGION_THE_EMPYREAN')
	pPlot = caster.plot()
	if pPlot.isOwned():
		pPlayer = gc.getPlayer(pPlot.getOwner())
		if pPlayer.getStateReligion() == iEmp:
			pPlot = cf.findClearPlot(-1, pPlot)
			newUnit = pPlayer.initUnit(caster.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.convert(caster)
			return False
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					pPlayer = gc.getPlayer(pUnit.getOwner())
					if pPlayer.getStateReligion() == iEmp:
						if pUnit.getReligion() == iEmp:
							newUnit = pPlayer.initUnit(caster.getUnitType(), pUnit.getX (),pUnit.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							newUnit.convert(caster)
							newUnit.setReligion(iEmp)
							newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), False)
							return False
	if CyGame().getSorenRandNum(50, "Rebel") < 2:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_REBELLIOUS'), True)
	return False




def reqLichdom(caster):
	if caster.isImmortal():
		return False
	if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_FLESH_GOLEM'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PUPPET')):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_LICH')) >0:
		return False
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_DEATH_MANA')):
			return False
	return True



def reqUpgradeAngel(caster, sUnit):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString(sUnit)) >= 4:
		return False
	return True





def reqMask(caster):
	if caster.isHiddenNationality():
		return False
	if caster.hasCargo():
		return False
	if caster.isCargo():
		return False
	pGroup = caster.getGroup()
	if pGroup.isNone() == False:
		if pGroup.getNumUnits() > 1:
			return False
	return True

def reqMezmerizeAnimal(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
						if eTeam.isAtWar(pUnit.getTeam()):
							return True
	return False

def spellMezmerizeAnimal(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
						if eTeam.isAtWar(pUnit.getTeam()):
							if pUnit.isDelayedDeath() == False:
								if pUnit.isResisted(caster, gc.getInfoTypeForString('SPELL_MEZMERIZE_ANIMAL')) == False:
									newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
									newUnit.convert(pUnit)

def reqMezmerizeBeast(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
						if eTeam.isAtWar(pUnit.getTeam()):
							return True
	return False

def spellMezmerizeBeast(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
						if eTeam.isAtWar(pUnit.getTeam()):
							if pUnit.isDelayedDeath() == False:
								if pUnit.isResisted(caster, gc.getInfoTypeForString('SPELL_MEZMERIZE_ANIMAL')) == False:
									newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
									newUnit.convert(pUnit)





def reqMezmerizeSea(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getDomainType() == gc.getInfoTypeForString('DOMAIN_SEA'):
						if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL') or pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
							if eTeam.isAtWar(pUnit.getTeam()):
								pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHARMED'), True)
								return True
	return False

def spellMezmerizeSea(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getDomainType() == gc.getInfoTypeForString('DOMAIN_SEA'):
						if pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL') or pUnit.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
							if eTeam.isAtWar(pUnit.getTeam()):
								if pUnit.isDelayedDeath() == False:
									if pUnit.isResisted(caster, gc.getInfoTypeForString('SPELL_MEZMERIZE_ANIMAL')) == False:
										newUnit = pPlayer.initUnit(pUnit.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
										newUnit.convert(pUnit)
										newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHARMED'), False)

def reqMirror(caster):
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	if caster.isImmuneToMagic():
		return False
	if pPlot.isVisibleEnemyUnit(iPlayer):
		return False
	return True

def spellMirror(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	newUnit = pPlayer.initUnit(caster.getUnitType(), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	for i in range(gc.getNumPromotionInfos()):
		newUnit.setHasPromotion(i, caster.isHasPromotion(i))
		if gc.getPromotionInfo(i).isEquipment():
			newUnit.setHasPromotion(i, False)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), True)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GREAT_GENERAL'), False)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), False)
	while newUnit.isImmortal():
		newUnit.changeImmortal(-1)
	newUnit.setDamage(caster.getDamage(), caster.getOwner())
	newUnit.setLevel(caster.getLevel())
	newUnit.setHasCasted(True)
	newUnit.setDuration(1)
	newUnit.setSummoner(caster.getID())

def reqParanoia(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False

	pCity = caster.plot().getPlotCity()
	if not pCity.isCapital():
		return False
	if pCity.getOwner() == caster.getOwner():
		return False
	if caster.getTeam() == pCity.getTeam():
		return False
	return True


def spellParanoia(caster):
	pCity = caster.plot().getPlotCity()
	pParPlayer = gc.getPlayer(pCity.getOwner())
	iCasterPlayer = caster.getOwner()
	for iPlayer in range(gc.getMAX_PLAYERS()):
		if not iPlayer == iCasterPlayer:
			pParPlayer.AI_changeAttitudeExtra(iPlayer,-1)



def reqPeace(caster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_CHANGING_WAR_PEACE):
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	if eTeam.getAtWarCount(True) == 0:
		return False
	return True

def spellPeace(caster):
	eTeam = gc.getTeam(gc.getPlayer(caster.getOwner()).getTeam())
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if (pPlayer.isAlive() and iPlayer != caster.getOwner() and iPlayer != gc.getBARBARIAN_PLAYER()):
			i2Team = gc.getPlayer(iPlayer).getTeam()
			if eTeam.isAtWar(i2Team):
				eTeam.makePeace(i2Team)
	CyGame().changeGlobalCounter(-1 * caster.getLevel())

def reqPeaceSevenPines(caster):
	pPlot = caster.plot()
	if not pPlot.isPythonActive():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	if eTeam.getAtWarCount(True) == 0:
		return False
	if caster.isBarbarian():
		return False
	if not pPlayer.isHuman():
		for iTeam in range(gc.getMAX_CIV_TEAMS()):
			eTeam = gc.getTeam(iTeam)
			if iTeam!=caster.getTeam():
				if eTeam.isAtWar(caster.getTeam()):
					if gc.getTeam(caster.getTeam()).getPower(True)*80<eTeam.getPower(True)*100:
						return True
		return False
	return True

def spellPeaceSevenPines(caster):
	eTeam = gc.getTeam(gc.getPlayer(caster.getOwner()).getTeam())
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if (pPlayer.isAlive() and iPlayer != caster.getOwner() and iPlayer != gc.getBARBARIAN_PLAYER()):
			i2Team = gc.getPlayer(iPlayer).getTeam()
			if eTeam.isAtWar(i2Team):
				eTeam.makePeace(i2Team)
	CyGame().changeGlobalCounter(-1 * (CyGame().getGlobalCounter() / 2))
	pPlot = caster.plot()
	pPlot.setPythonActive(False)

def reqPillarofFire(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				bEnemy = False
				bNeutral = False
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.getDamage() < 76:
							bEnemy = True
					else:
						bNeutral = True
				if (bEnemy and bNeutral == False):
					return True
	return False

def spellPillarofFire(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	iBestValue = 0
	pBestPlot = -1
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			bNeutral = False
			iValue = 0
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.getDamage() < 76:
							iValue += 5 * pUnit.baseCombatStr()
					else:
						bNeutral = True
				if (iValue > iBestValue and bNeutral == False):
					iBestValue = iValue
					pBestPlot = pPlot
	if pBestPlot != -1:
		for i in range(pBestPlot.getNumUnits()):
			pUnit = pBestPlot.getUnit(i)
			pUnit.doDamage(50, 75, caster, gc.getInfoTypeForString('DAMAGE_FIRE'), True)
		if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE')):
			bValid = True
			iImprovement = pPlot.getImprovementType()
			if iImprovement != -1 :
				if gc.getImprovementInfo(iImprovement).isPermanent():
					bValid = False
			if bValid:
				if CyGame().getSorenRandNum(100, "Flames Spread") < gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
					pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE'),pBestPlot.getPoint())

def reqPirateCove(caster):
	pPlot = caster.plot()
	if pPlot.isWater() == False:
		return False
	if pPlot.isAdjacentToLand() == False:
		return False
	if pPlot.isCity():
		return False
	if pPlot.getOwner() != caster.getOwner():
		return False
	if pPlot.getImprovementType() != -1:
		return False
	if pPlot.getBonusType(caster.getTeam()) != -1:
		return False
	iPirateCove = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_COVE')
	iPirateHarbor = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_HARBOR')
	iPiratePort = gc.getInfoTypeForString('IMPROVEMENT_PIRATE_PORT')
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				iImprovement = pPlot.getImprovementType()
				if iImprovement == iPirateCove:
					return False
				if iImprovement == iPirateHarbor:
					return False
				if iImprovement == iPiratePort:
					return False
	return True

def spellPirateCove(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())

	if pPlayer.getCivilizationType()==gc.getInfoTypeForString('CIVILIZATION_LANUN'):
		pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PIRATE_COVE'))

def reqMarchOfTheTrees(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellMarchOfTheTrees(caster):
	iAncientForest = gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT')
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iNewForest = gc.getInfoTypeForString('FEATURE_FOREST_NEW')
	iTreant = gc.getInfoTypeForString('UNIT_TREANT')
	iHeavy = gc.getInfoTypeForString('PROMOTION_HEAVY')
	iVtF = gc.getInfoTypeForString('PROMOTION_VULNERABLE_TO_FIRE')
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				if not pPlot.isVisibleEnemyUnit(iPlayer):
					if pPlot.getFeatureType() == iForest:
						newUnit = pPlayer.initUnit(iTreant, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setDuration(4)
						pPlot.setFeatureType(iNewForest,0)
						newUnit.AI_setGroupflag(43)	# 43=GROUPFLAG_SUICIDE_SUMMON
						if newUnit.isHuman():
							newUnit.getGroup().setActivityType(ActivityTypes.ACTIVITY_SLEEP)
					if pPlot.getFeatureType() == iAncientForest:
						newUnit = pPlayer.initUnit(iTreant, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setDuration(5)
						newUnit.setHasPromotion(iHeavy, True)
						newUnit.setHasPromotion(iVtF, False)
						pPlot.setFeatureType(iForest,0)
						newUnit.AI_setGroupflag(43)	# 43=GROUPFLAG_SUICIDE_SUMMON
						if newUnit.isHuman():
							newUnit.getGroup().setActivityType(ActivityTypes.ACTIVITY_SLEEP)


def reqMotherLode(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iPeakCount = 0
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isPeak():
			if pPlot.isOwned():
				if pPlot.getOwner() == iPlayer:
					if pPlayer.isHuman():
						return True
					iPeakCount += 1
	if iPeakCount > 10:
		return True
	return False


def spellMotherLode(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iRoad = gc.getInfoTypeForString('ROUTE_ROAD')
	iMine = gc.getInfoTypeForString('IMPROVEMENT_MINE')
	iQuarry = gc.getInfoTypeForString('IMPROVEMENT_QUARRY')

	iMarble= gc.getInfoTypeForString('BONUS_MARBLE')
	iGold= gc.getInfoTypeForString('BONUS_GOLD')
	iGems= gc.getInfoTypeForString('BONUS_GEMS')
	iJewels= gc.getInfoTypeForString('BONUS_JEWELS')
	iMithril= gc.getInfoTypeForString('BONUS_MITHRIL')
	iIron= gc.getInfoTypeForString('BONUS_IRON')
	iCopper= gc.getInfoTypeForString('BONUS_COPPER')
	iGun= gc.getInfoTypeForString('BONUS_GUNPOWDER')

	pPlayer.changeGold(pPlayer.getImprovementCount(iMine) * 50)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				if pPlot.isPeak():
					gc.getGame().setPlotExtraYield(pPlot.getX(), pPlot.getY(), YieldTypes.YIELD_COMMERCE, 2)
					if pPlot.getBonusType(-1) == -1 and pPlot.getImprovementType() != -1:
						iRnd = CyGame().getSorenRandNum(50, "Motherlode")
						if iRnd < 10:
							pPlot.setBonusType(iGold)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 17:
							pPlot.setBonusType(iGems)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 21:
							pPlot.setBonusType(iJewels)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 25:
							pPlot.setBonusType(iMithril)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 27:
							pPlot.setBonusType(iIron)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 32:
							pPlot.setBonusType(iCopper)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd < 35:
							pPlot.setBonusType(iGun)
							pPlot.setImprovementType(iMine)
							pPlot.setRouteType(iRoad)
						elif iRnd > 40:
							pPlot.setBonusType(iMarble)
							pPlot.setImprovementType(iQuarry)
							pPlot.setRouteType(iRoad)





def spellOpenChest(caster):
	pPlot = caster.plot()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	bValid = True
	if CyGame().getWBMapScript():
		bValid = sf.openChest(caster, pPlot)
	if bValid:
		if CyGame().getSorenRandNum(100, "Explore Lair") < 25:
			lTrapList = ['POISON', 'FIRE', 'SPORES']
			sTrap = lTrapList[CyGame().getSorenRandNum(len(lTrapList), "Pick Trap")-1]
			point = pPlot.getPoint()
			if sTrap == 'POISON':
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), True)
				caster.doDamageNoCaster(25, 90, gc.getInfoTypeForString('DAMAGE_POISON'), False)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_POISON", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Promotions/Poisoned.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			if sTrap == 'FIRE':
				caster.doDamageNoCaster(50, 90, gc.getInfoTypeForString('DAMAGE_FIRE'), False)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_FIRE", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Ring of Flames.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_RING_OF_FLAMES'),point)
				CyAudioGame().Play3DSound("AS3D_SPELL_FIREBALL",point.x,point.y,point.z)
			if sTrap == 'SPORES':
				caster.changeImmobileTimer(3)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TRAP_SPORES", ()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Spells/Spores.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPORES'),point)
				CyAudioGame().Play3DSound("AS3D_SPELL_CONTAGION",point.x,point.y,point.z)

		lList = ['EMPTY', 'HIGH_GOLD', 'ITEM_HEALING_SALVE', 'ITEM_JADE_TORC', 'ITEM_KANNAS_RING', 'ITEM_ROD_OF_WINDS', 'ITEM_TIMOR_MASK', 'TECH']
		sGoody = lList[CyGame().getSorenRandNum(len(lList), "Pick Goody")-1]
		if sGoody == 'EMPTY':
			CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_EXPLORE_LAIR_TREASURE_EMPTY",()),'AS2D_POSITIVE_DINK',1,'Art/Interface/Buttons/Equipment/Treasure.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if sGoody == 'HIGH_GOLD':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_HIGH_GOLD'), caster)
		if sGoody == 'ITEM_HEALING_SALVE':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_HEALING_SALVE'), caster)
		if sGoody == 'ITEM_JADE_TORC':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_JADE_TORC'), caster)
		if sGoody == 'ITEM_KANNAS_RING':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_KANNAS_RING'), caster)
		if sGoody == 'ITEM_POTION_OF_INVISIBILITY':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_POTION_OF_INVISIBILITY'), caster)
		if sGoody == 'ITEM_POTION_OF_RESTORATION':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_POTION_OF_RESTORATION'), caster)
		if sGoody == 'ITEM_ROD_OF_WINDS':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_ROD_OF_WINDS'), caster)
		if sGoody == 'ITEM_TIMOR_MASK':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_EXPLORE_LAIR_ITEM_TIMOR_MASK'), caster)
		if sGoody == 'TECH':
			pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster)
		pTreasure = -1
		iTreasure = gc.getInfoTypeForString('EQUIPMENT_TREASURE')
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getUnitType() == iTreasure and not pUnit.isDelayedDeath():
				pTreasure = pUnit
		pTreasure.kill(True, 0)





def reqOpenMercurianGate(pCaster):
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_HYBOREM_OR_BASIUM):
		return False
	if CyGame().isLeaderEverActive(gc.getInfoTypeForString('LEADER_BASIUM')):
		return False
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iReligion = pPlayer.getStateReligion()
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_EVIL'):
			return False
	return True




def spellOpenMercurianGate(pCaster):
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iMercurianPlayer = cf.getOpenPlayer()
	iTeam = pPlayer.getTeam()
	if (iMercurianPlayer != -1):
		CyGame().addPlayerAdvanced(iMercurianPlayer, iTeam, gc.getInfoTypeForString('LEADER_BASIUM'), gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'))
		pBasiumUnit = gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_BASIUM'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		pBasiumUnit.setAvatarOfCivLeader(True)
		iSettler = gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_SETTLER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		iSettler.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STARTING_SETTLER'), True)
		gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_WORKER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_WORKER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)


		i = 6
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
			iDelay = 3
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
			iDelay = 9
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
			iDelay = 17
		for j in range(CyGame().getGameTurn() / i):
			gc.getPlayer(iMercurianPlayer).initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)

		if pPlayer.isHuman() == True:
			popupInfo = CyPopupInfo()
			popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
			popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_CONTROL_MERCURIANS",()))
			popupInfo.setData1(iPlayer)
			popupInfo.setData2(iMercurianPlayer)
			popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_YES", ()), "")
			popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_NO", ()), "")
			popupInfo.setOnClickedPythonCallback("reassignPlayer")
			popupInfo.addPopup(iPlayer)




def reqMercurianReinforcements(pCaster):
	if not CyGame().isLeaderEverActive(gc.getInfoTypeForString('LEADER_BASIUM')):
		return False
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
		return False
	iReligion = pPlayer.getStateReligion()
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
		return False
	iHero = gc.getInfoTypeForString('UNITCLASS_BASIUM')
	if not CyGame().isUnitClassMaxedOut(iHero, 0):
		return False
	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		if iPlayer2 != gc.getBARBARIAN_PLAYER():
			pPlayer2 = gc.getPlayer(iPlayer2)
			if pPlayer2.getUnitClassCount(iHero) > 0:
				return False

	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_BASIUM')
	iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	pPlot = CyMap().plot(0,0)
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if pUnit.isHasPromotion(iLL) or pUnit.isHasPromotion(iVB) or  pUnit.isDelayedDeath():
				return False
			return True
	return False



def spellMercurianReinforcements(pCaster):
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pPlot = pCaster.plot()
	iMercurianPlayer = -1
	pMercurianPlayer = -1
	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		pPlayer2 = gc.getPlayer(iPlayer2)
		if pPlayer2.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
			iMercurianPlayer = iPlayer2
			pMercurianPlayer = pPlayer2
	if (iMercurianPlayer != -1):
		iFounderTeam = gc.getPlayer(iPlayer).getTeam()
		eFounderTeam = gc.getTeam(gc.getPlayer(iPlayer).getTeam())
		iMercurianTeam = gc.getPlayer(iMercurianPlayer).getTeam()
		eMercurianTeam = gc.getTeam(iMercurianTeam)
		eFounderTeam.makePeace(iMercurianTeam)
		eMercurianTeam.makePeace(iFounderTeam)
		pMercurianPlayer.AI_changeAttitudeExtra(iPlayer,8)
		eFounderTeam.signOpenBorders(iMercurianTeam)
		eMercurianTeam.signOpenBorders(iFounderTeam)
		eFounderTeam.signDefensivePact(iMercurianTeam)
		eMercurianTeam.signDefensivePact(iFounderTeam)
		for iTeam in range(gc.getMAX_TEAMS()):
			eTeam = gc.getTeam(iTeam)
			if eTeam.isAlive():
				if eMercurianTeam.isAtWar(iTeam):
					eFounderTeam.declareWar(iTeam, False, WarPlanTypes.WARPLAN_LIMITED)
				if eFounderTeam.isAtWar(iTeam):
					eMercurianTeam.declareWar(iTeam, False, WarPlanTypes.WARPLAN_LIMITED)


		pMercurianPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_AGGRESSIVE'),True)
		pMercurianPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_CHARISMATIC'),True)
		pMercurianPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_INGENUITY'),True)
		pMercurianPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_RAIDERS'),True)
		pMercurianPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_TOLERANT'),True)

		newUnit = pMercurianPlayer.initUnit(gc.getInfoTypeForString('UNIT_BASIUM'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		newUnit.setAvatarOfCivLeader(True)
		iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_BASIUM')
		iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
		iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
		iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
		pPlotNether = CyMap().plot(0,0)
		for i in range(pPlotNether.getNumUnits()):
			pUnit = pPlotNether.getUnit(i)
			if pUnit.getUnitType() == iUnit:
				if not pUnit.isHasPromotion(iLL) and not pUnit.isHasPromotion(iVB):
					break
		newUnit.convert(pUnit)
		newUnit.setHasPromotion(iHeld, False)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)

		pMercurianPlayer.initUnit(gc.getInfoTypeForString('UNIT_SETTLER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		pMercurianPlayer.initUnit(gc.getInfoTypeForString('UNIT_WORKER'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		i = 8
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_QUICK'):
			iDelay = 4
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_EPIC'):
			iDelay = 12
		if CyGame().getGameSpeedType() == gc.getInfoTypeForString('GAMESPEED_MARATHON'):
			iDelay = 20
		for j in range(CyGame().getGameTurn() / i):
			pMercurianPlayer.initUnit(gc.getInfoTypeForString('UNIT_ANGEL'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)




def reqOrdain(caster,sPriest):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString(sPriest)) >= 4:
		return False
	return True



def spellOrdainOrder(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_THE_ORDER')
	if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BANNOR'):
		iUnit = gc.getInfoTypeForString('UNIT_PONTIF')
	newUnit = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.convert(pCaster)
	newUnit.finishMoves()


def reqPromoteSettlement(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()

	if not pCity.isSettlement():
		return False

	pPlayer = gc.getPlayer(caster.getOwner())

	if pPlayer.getNumCities() - pPlayer.getNumSettlements() >= pPlayer.getMaxCities():
		return False

	if pPlayer.isHuman() == False:
		return True

	return True

def spellPromoteSettlement(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setSettlement(False)
	pCity.setPlotRadius(3)

def reqRagingSeas(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		eTeam = gc.getTeam(pPlayer.getTeam())
		iCount = 0
		for iPlayer2 in range(gc.getMAX_PLAYERS()):
			pPlayer2 = gc.getPlayer(iPlayer2)
			if pPlayer2.isAlive():
				if not pPlayer2.isBarbarian():
					iTeam2 = gc.getPlayer(iPlayer2).getTeam()
					if eTeam.isAtWar(iTeam2):
						iCount += pPlayer2.countNumCoastalCities()
		if iCount > 5:
			return True
		return False
	return True

def spellRagingSeas(caster):
	iCold = gc.getInfoTypeForString('DAMAGE_COLD')
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iLanun = gc.getInfoTypeForString('CIVILIZATION_LANUN')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSpring = gc.getInfoTypeForString('EFFECT_SPRING')
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isAdjacentToWater():
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getCivilizationType() != iLanun:
					pUnit.doDamageNoCaster(75, 100, iCold, False)
			if pPlot.getImprovementType() != -1:
				if pPlot.getFeatureType() == iFlames:
					pPlot.setFeatureType(-1, 0)
				if pPlot.getImprovementType() == iSmoke:
					pPlot.setImprovementType(-1)
				else:
					if pPlot.isOwned():
						if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
							if gc.getPlayer(pPlot.getOwner()).getCivilizationType() != iLanun:
								if CyGame().getSorenRandNum(100, "Raging Seas") < 25:
									pPlot.setImprovementType(-1)
			if pPlot.isVisibleToWatchingHuman():
				CyEngine().triggerEffect(iSpring,pPlot.getPoint())



def reqRaiseSkeleton(caster,sVote):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString(sVote)):
			return False
	iSummon = gc.getInfoTypeForString('UNIT_SKELETON')
	casterID = caster.getID()
	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.getUnitType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True


def spellRaiseSkeleton(caster):
	pPlot = caster.plot()
	if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD'):
		pPlot.setImprovementType(-1)
		caster.cast(gc.getInfoTypeForString('SPELL_RAISE_SKELETON'))
		caster.cast(gc.getInfoTypeForString('SPELL_RAISE_SKELETON'))

def reqRally(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getCivics(gc.getInfoTypeForString('CIVICOPTION_MEMBERSHIP')) != gc.getInfoTypeForString('CIVIC_CRUSADE'):
		return False
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.getImprovementCount(gc.getInfoTypeForString('IMPROVEMENT_TOWN')) < (3 * pPlayer.getNumCities()):
			return False
	return True

def spellRally(caster):
	iOwner = caster.getOwner()
	pPlayer = gc.getPlayer(iOwner)
	iReligion = pPlayer.getStateReligion()
	iDemagog = gc.getInfoTypeForString('UNIT_DEMAGOG')
	iTown = gc.getInfoTypeForString('IMPROVEMENT_TOWN')
	iVillage = gc.getInfoTypeForString('IMPROVEMENT_VILLAGE')
	pCity = pPlayer.getCapitalCity()

	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.getOwner() == iOwner:
			if not pPlot.isVisibleEnemyUnit(iOwner):
				if pPlot.isCity():
					newUnit = pPlayer.initUnit(iDemagog, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.setReligion(iReligion)

				if pPlot.getImprovementType() == iTown:
					pPlot.setImprovementType(iVillage)
					newUnit = pPlayer.initUnit(iDemagog, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.setReligion(iReligion)
					if pPlot.isConnectedTo(pCity):
						if pCity.hasBonus(gc.getInfoTypeForString ('BONUS_MITHRIL')):
							newUnit.setHasPromotion(gc.getInfoTypeForString ('PROMOTION_MITHRIL_WEAPONS'), True)
						elif pCity.hasBonus(gc.getInfoTypeForString ('BONUS_IRON')):
							newUnit.setHasPromotion(gc.getInfoTypeForString ('PROMOTION_IRON_WEAPONS'), True)
						elif pCity.hasBonus(gc.getInfoTypeForString ('BONUS_COPPER')):
							newUnit.setHasPromotion(gc.getInfoTypeForString ('PROMOTION_BRONZE_WEAPONS'), True)


def spellReadTheGrimoire(caster):
	iBonus=0
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot=caster.plot()
	point = pPlot.getPoint()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING1')):
		iBonus+=100
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2')):
		iBonus+=100
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3')):
		iBonus+=100
	if caster.getReligion() == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3')):
		iBonus+=5
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO')):
		iBonus+=10
	iRnd = CyGame().getSorenRandNum(100, "Read the Grimoire")+iBonus
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PROPHECY_MARK'), True)
	if iRnd < 30:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
	if iRnd >= 30 and iRnd < 40:
		iSpell = gc.getInfoTypeForString('SPELL_BURNING_BLOOD')
		caster.cast(iSpell)
	if iRnd >= 40 and iRnd < 50:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
	if iRnd >= 50 and iRnd < 60:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), True)
	if iRnd >= 60 and iRnd < 70:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), True)
	if iRnd >= 70 and iRnd < 80:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
	if iRnd >= 80 and iRnd < 100:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING1'), True)
	if iRnd >= 100 and iRnd < 110:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_PIT_BEAST')
		caster.cast(iSpell)
	if iRnd >= 110 and iRnd < 120:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_SPECTRE')
		caster.cast(iSpell)
	if iRnd >= 120 and iRnd < 130:
		iSpell = gc.getInfoTypeForString('SPELL_WITHER')
		caster.cast(iSpell)
	if iRnd >= 130 and iRnd < 140:
		iSpell = gc.getInfoTypeForString('SPELL_MUTATION')
		caster.cast(iSpell)
	if iRnd >= 140 and iRnd < 145:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STIGMATA'), True)
	if iRnd >= 145 and iRnd < 150:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), True)
	if iRnd >= 150 and iRnd < 155:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
	if iRnd >= 155 and iRnd < 160:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
	if iRnd >= 160 and iRnd < 170:
		caster.kill(True, PlayerTypes.NO_PLAYER)
	if iRnd >= 170 and iRnd < 180:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), True)
	if iRnd >= 180 and iRnd < 185:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
	if iRnd >= 185 and iRnd < 190:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), True)
	if iRnd >= 190 and iRnd < 200:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2'), True)
	if iRnd >= 200 and iRnd < 210:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_BALOR')
		caster.cast(iSpell)
	if iRnd >= 210 and iRnd < 220:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_WRAITH')
		caster.cast(iSpell)
	if iRnd >= 220 and iRnd < 230:
		iSpell = gc.getInfoTypeForString('SPELL_WITHER')
		caster.cast(iSpell)
		caster.cast(iSpell)
	if iRnd >= 230 and iRnd < 240:
		iSpell = gc.getInfoTypeForString('SPELL_WONDER')
		caster.cast(iSpell)
	if iRnd >= 240 and iRnd < 245:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STIGMATA'), True)
	if iRnd >= 245 and iRnd < 250:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), True)
	if iRnd >= 250 and iRnd < 255:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
	if iRnd >= 255 and iRnd < 260:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
	if iRnd >= 260 and iRnd < 265:
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
		CyAudioGame().Play3DSound("AS3D_SPELL_DEFILE",point.x,point.y,point.z)
		for iX in range(pPlot.getX()-1, pPlot.getX()+2, 1):
			for iY in range(pPlot.getY()-1, pPlot.getY()+2, 1):
				pLoopPlot = CyMap().plot(iX,iY)
				if pLoopPlot.isNone() == False:
					pLoopPlot.changePlotCounter(100)
	if iRnd >= 265 and iRnd < 270:
		caster.kill(True, PlayerTypes.NO_PLAYER)
	if iRnd >= 270 and iRnd < 275:
		iSpell = gc.getInfoTypeForString('SPELL_BURNING_BLOOD')
		caster.cast(iSpell)
	if iRnd >= 275 and iRnd < 280:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ARCANE'), True)
	if iRnd >= 280 and iRnd < 285:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), True)
	if iRnd >= 285 and iRnd < 290:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2'), True)
	if iRnd >= 290 and iRnd < 295:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), True)
	if iRnd >= 295 and iRnd < 300:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3'), True)
	if iRnd >= 300 and iRnd < 310:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_BALOR')
		caster.cast(iSpell)
		caster.cast(iSpell)
		caster.cast(iSpell)
	if iRnd >= 310 and iRnd < 320:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_WRAITH')
		caster.cast(iSpell)
		caster.cast(iSpell)
		caster.cast(iSpell)
	if iRnd >= 320 and iRnd < 330:
		iSpell = gc.getInfoTypeForString('SPELL_WITHER')
		caster.cast(iSpell)
		caster.cast(iSpell)
		caster.cast(iSpell)
	if iRnd >= 330 and iRnd < 340:
		iSpell = gc.getInfoTypeForString('SPELL_SUMMON_WONDER')
		caster.cast(iSpell)
		caster.cast(iSpell)
		caster.cast(iSpell)
	if iRnd >= 340 and iRnd < 345:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
	if iRnd >= 345 and iRnd < 350:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON'), True)
	if iRnd >= 350 and iRnd < 355:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
	if iRnd >= 355 and iRnd < 360:
		CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
		CyAudioGame().Play3DSound("AS3D_SPELL_DEFILE",point.x,point.y,point.z)
		for iX in range(pPlot.getX()-1, pPlot.getX()+2, 1):
			for iY in range(pPlot.getY()-1, pPlot.getY()+2, 1):
				pLoopPlot = CyMap().plot(iX,iY)
				if pLoopPlot.isNone() == False:
					pLoopPlot.changePlotCounter(100)
	if iRnd >= 360 and iRnd < 363:
		caster.kill(True, PlayerTypes.NO_PLAYER)
	if iRnd >= 363 and iRnd < 365:
		iSpell = gc.getInfoTypeForString('SPELL_BURNING_BLOOD')
		caster.cast(iSpell)
	if iRnd >= 365 and iRnd < 370:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_VILE_TOUCH'), True)
	if iRnd >= 370 and iRnd < 380:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ARCANE'), True)
	if iRnd >= 380 and iRnd < 385:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STIGMATA'), True)
	if iRnd >= 385 and iRnd < 390:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUNDERED'), True)
	if iRnd >= 390 and iRnd < 395:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3'), True)
	if iRnd >= 395 and iRnd < 400:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2'), True)
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3'), True)
	if iRnd >= 400 and iRnd < 405:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MAGIC_IMMUNE'), True)
	if iRnd >= 405 and iRnd < 410:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FEAR'), True)
	if iRnd >= 410 and iRnd < 420:
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_WRAITH'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD'), True)
		newUnit.setSummoner(caster.getID())

	if iRnd >= 420 and iRnd < 430:
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BALOR'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD'), True)
		newUnit.setSummoner(caster.getID())
	if iRnd >= 430 and iRnd < 435:
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BEAST_OF_AGARES'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	if iRnd >= 435 and iRnd < 440:
		caster.changeExperience(66, -1, False, False, False)
	if iRnd >= 440 and iRnd < 443:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_TWINCAST'), True)
	if iRnd >= 443:
		caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMORTAL'), True)



def spellRebuildMithril(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pCityPlayer = gc.getPlayer(pCity.getOwner())
	newUnit = pCityPlayer.initUnit(gc.getInfoTypeForString('UNIT_MITHRIL_GOLEM'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_MITHRIL_GOLEM')
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	pPlotNether = CyMap().plot(0,0)
	for i in range(pPlotNether.getNumUnits()):
		pUnit = pPlotNether.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if not pUnit.isHasPromotion(iLL) and not pUnit.isHasPromotion(iVB):
				newUnit.convert(pUnit)
				newUnit.setHasPromotion(iHeld, False)
				for iProm in range(gc.getNumPromotionInfos()):
					if gc.getPromotionInfo(iProm).isEquipment() and iProm != gc.getInfoTypeForString('PROMOTION_PIECES_OF_MITHRIL_GOLEM'):
						newUnit.setHasPromotion(iProm, False)
				break
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_BLASTING_WORKSHOP')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE2'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_PALLENS_ENGINE')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PERFECT_SIGHT'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_ADULARIA_CHAMBER')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STEALTH'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_GOLEM_TRACKS')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MOBILITY2'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_DWARVEN_SMITHY')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
	newUnit.setDamage(50, caster.getOwner())
	newUnit.finishMoves()
	if pPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		pCityPlayer.AI_changeAttitudeExtra(iPlayer,2)


def reqRebuildBarnaxus(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCityPlayer = gc.getPlayer(pCity.getOwner())
	if caster.getUnitType() == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		return False
	if pCityPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		return False
	return True

def spellRebuildBarnaxus(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	pCityPlayer = gc.getPlayer(pCity.getOwner())
	newUnit = pCityPlayer.initUnit(gc.getInfoTypeForString('UNIT_BARNAXUS'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_BARNAXUS')
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	pPlotNether = CyMap().plot(0,0)
	for i in range(pPlotNether.getNumUnits()):
		pUnit = pPlotNether.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if not pUnit.isHasPromotion(iLL) and not pUnit.isHasPromotion(iVB):
				newUnit.convert(pUnit)
				newUnit.setHasPromotion(iHeld, False)
				for iProm in range(gc.getNumPromotionInfos()):
					if gc.getPromotionInfo(iProm).isEquipment() and iProm != gc.getInfoTypeForString('PROMOTION_PIECES_OF_BARNAXUS'):
						newUnit.setHasPromotion(iProm, False)
				break
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_BLASTING_WORKSHOP')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE2'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_PALLENS_ENGINE')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PERFECT_SIGHT'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_ADULARIA_CHAMBER')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STEALTH'), True)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_GOLEM_TRACKS')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MOBILITY2'), True)
	if pCity.getNumRealBuilding(gc.getInfoTypeForString('BUILDING_DWARVEN_SMITHY')) > 0:
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), True)
	newUnit.setDamage(50, caster.getOwner())
	newUnit.finishMoves()
	if pPlayer.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		pCityPlayer.AI_changeAttitudeExtra(iPlayer,2)

def reqRecruit(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isHuman() == False:
		if caster.getUnitType() == gc.getInfoTypeForString('UNIT_DONAL'):
			if pCity.getPopulation() > 8:
				return True
		return False
	return True

def spellRecruit(caster):
	iReligion = caster.getReligion()
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = gc.getTeam(pPlayer.getTeam())
	iLoop = (pCity.getPopulation() / 3) + 1
	if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_TEMPLE_OF_THE_ORDER')) == 1:
		iLoop = iLoop * 2
	for i in range(iLoop):
		iRnd = CyGame().getSorenRandNum(60, "Bob")
		iUnit = -1
		if iRnd < 10:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HANDLING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_RANGER')
		elif iRnd < 20:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_POISONS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_ASSASSIN')
		elif iRnd < 30:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_STIRRUPS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSE_ARCHER')
		elif iRnd < 40:
			iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_TRADE')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_CHARIOT')
		elif iRnd < 50:
			iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BRONZE_WORKING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_AXEMAN')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_IRON_WORKING')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_CHAMPION')
		elif iRnd < 60:
			iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_ARCHER')
			if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BOWYERS')):
				iUnit = gc.getInfoTypeForString('UNITCLASS_LONGBOWMAN')
		if iUnit != -1:
			infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
			iUnit = infoCiv.getCivilizationUnits(iUnit)
			if iUnit != -1:
				newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
				pCity.applyBuildEffects(newUnit)
				newUnit.setReligion(iReligion)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_RECRUITER'), False)
	if caster.getUnitClassType() == gc.getInfoTypeForString('UNITCLASS_GREAT_GENERAL'):
		caster.kill(True, PlayerTypes.NO_PLAYER)


def reqRecruitMercenary(caster, sUnitClass):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()

	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)

	iPlayerC = pCity.getOwner()
	pPlayerC = gc.getPlayer(iPlayerC)
	iTeamC = pPlayerC.getTeam()
	eTeamC = gc.getTeam(iTeamC)
	if eTeam.isAtWar(iTeamC):
		return False
	iPlayerO = pCity.getOriginalOwner()
	pPlayerO = gc.getPlayer(iPlayerO)
	iTeamO = pPlayerO.getTeam()
	eTeamO = gc.getTeam(iTeamO)

	iCivO = pPlayerO.getCivilizationType()
	if pPlayerO.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
		if pPlayer.getStateReligion() != gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
			return False
	infoCiv = gc.getCivilizationInfo(iCivO)
	iUnit = infoCiv.getCivilizationUnits(gc.getInfoTypeForString(sUnitClass))
	if iUnit == -1:
		return False
	if pPlayer.isHuman():
		return True
	else:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KHAZAD'):
			if pPlayer.getGold() / pPlayer.getNumCities() < 700:
				return False
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 1:
			return False
		iCount = 0
		for i in range(pPlot.getNumUnits(), 0, -1):
			pUnit = pPlot.getUnit(i)
			if caster.getOwner() == pUnit.getOwner():
				iCount += 1
				if iCount > 4:
					return False
	return True






def spellRecruitMercUnit(pCaster, sUnitClass, iCost):
	iUnitClass = gc.getInfoTypeForString(sUnitClass)
	iGold = iCost/10
	iPlayerU = pCaster.getOwner()
	pPlayerU = gc.getPlayer(iPlayerU)
	iCivU = pPlayerU.getCivilizationType()
	infoCivU = gc.getCivilizationInfo(iCivU)
	pPlot = pCaster.plot()
	pCity = pPlot.getPlotCity()
	iPlayerC = pCity.getOriginalOwner()
	pPlayerC = gc.getPlayer(iPlayerC)
	iCivC = pPlayerC.getCivilizationType()
	infoCivC = gc.getCivilizationInfo(iCivC)
	iUnit = infoCivC.getCivilizationUnits(iUnitClass)
	newUnit = pPlayerU.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.finishMoves()
	newUnit.setHasCasted(True)

	pCity.applyBuildEffects(newUnit)

	if pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_MAGNADINE'):
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WARCRY'), True)

	elif pPlayerU.getCivilizationType() != gc.getInfoTypeForString('CIVILIZATION_HIPPUS'):
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MERCENARY'), True)


	if infoCivC.getDefaultRace() != -1:
		if newUnit.isHasPromotion(infoCivC.getDefaultRace()):
			newUnit.setHasPromotion(infoCivC.getDefaultRace(), True)
	iArt = -1
	if pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BANNOR'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_BANNOR')
		if pUnit.getUnitCombatType() ==  gc.getInfoTypeForString('UNITCOMBAT_ARCHER') or pUnit.getUnitCombatType() ==  gc.getInfoTypeForString('UNITCOMBAT_MELEE'):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_GUARDSMAN'), True)
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MALAKIM'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_MALAKIM')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_ELOHIM')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_MERCURIANS')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LUCHUIRP'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_LUCHUIRP')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_KURIOTATES')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_LJOSALFAR')
		if pCaster.getUnitCombatType() ==  gc.getInfoTypeForString('UNITCOMBAT_ARCHER'):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEXTEROUS'), True)
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KHAZAD'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_KHAZAD')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SIDAR'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_SIDAR')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LANUN'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_LANUN')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_GRIGORI'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_GRIGORI')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_HIPPUS'):
		iGold = 5* iGold
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_HIPPUS')
		if pUnit.getUnitCombatType() ==  gc.getInfoTypeForString('UNITCOMBAT_MOUNTED'):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HORSELORD'), True)
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_AMURITES'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_AMURITES')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_DOVIELLO')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BALSERAPHS'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_BALSERAPHS')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_CLAN_OF_EMBERS'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_CLAN_OF_EMBERS')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_SVARTALFAR')
		if pUnit.getUnitCombatType() ==  gc.getInfoTypeForString('UNITCOMBAT_RECON'):
			newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SINISTER'), True)
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_CALABIM'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_CALABIM')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SHEAIM'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_SHEAIM')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_ILLIANS')
	elif pPlayerC.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
		iArt = gc.getInfoTypeForString('UNIT_ARTSTYLE_INFERNAL')
	pPlayerC.changeGold(iGold)
	if iArt !=-1:
		newUnit.setUnitArtStyleType(iArt)


def spellReleaseFromCage(caster):
	pPlot = caster.plot()
	pPlot.setImprovementType(-1)

def reqReligiousFervor(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iReligion = pPlayer.getStateReligion()
	if iReligion == -1:
		return False
	if pPlayer.isHuman() == False:
		iCount = 0
		for pyCity in PyPlayer(iPlayer).getCityList() :
			pCity = pyCity.GetCy()
			if pCity.isHasReligion(iReligion):
				iCount += 1
		map = gc.getMap()
		if iCount < gc.getWorldInfo(map.getWorldSize()).getTargetNumCities():
			return False
	return True

def spellReligiousFervor(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iReligion = pPlayer.getStateReligion()
	if iReligion == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES')
		iProm = gc.getInfoTypeForString('PROMOTION_SUBDUE_ANIMAL')
	if iReligion == gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_KILMORPH')
		iProm = gc.getInfoTypeForString('PROMOTION_CITY_GARRISON1')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_EMPYREAN')
		iProm = gc.getInfoTypeForString('PROMOTION_SUN2')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_ORDER')
		iProm = gc.getInfoTypeForString('PROMOTION_VALOR')
	if iReligion == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_OVERLORDS')
		iProm = gc.getInfoTypeForString('PROMOTION_WATER_WALKING')
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
		iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_VEIL')
		iProm = gc.getInfoTypeForString('PROMOTION_EXTENSION1')
	if iReligion == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
		iUnit = gc.getInfoTypeForString('UNIT_ASSASSIN')
		iProm = gc.getInfoTypeForString('PROMOTION_STEALTH')
	iCount = 0
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		if pCity.isHasReligion(iReligion):
			iCount += 1
	for pyCity in PyPlayer(iPlayer).getCityList() :
		pCity = pyCity.GetCy()
		newUnit = pPlayer.initUnit(iUnit, pCity.getX(), pCity.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		newUnit.changeExperience(iCount, -1, False, False, False)
		newUnit.setReligion(iReligion)
		newUnit.setHasPromotion(iProm, True)


def reqRepair(caster):
	pPlot = caster.plot()
	iGolem = gc.getInfoTypeForString('PROMOTION_GOLEM')
	iNaval = gc.getInfoTypeForString('UNITCOMBAT_NAVAL')
	iSiege = gc.getInfoTypeForString('UNITCOMBAT_SIEGE')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getUnitCombatType() == iSiege or pUnit.getUnitCombatType() == iNaval or pUnit.isHasPromotion(iGolem)):
			if pUnit.getDamage() > 0:
				return True
	return False

def spellRepair(caster,amount):
	pPlot = caster.plot()
	iGolem = gc.getInfoTypeForString('PROMOTION_GOLEM')
	iNaval = gc.getInfoTypeForString('UNITCOMBAT_NAVAL')
	iSiege = gc.getInfoTypeForString('UNITCOMBAT_SIEGE')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getUnitCombatType() == iSiege or pUnit.getUnitCombatType() == iNaval or pUnit.isHasPromotion(iGolem)):
			pUnit.changeDamage(-amount,0)
		if pUnit.getUnitCombatType() == -1:
			caster.changeExperience(pUnit.getExperience() / 4, -1, False, False, False)
			pUnit.setExperience(0, -1)



def reqResurrection(pCaster, sSluagh, sLeader):
	if sLeader != -1:
		pPlayer = gc.getPlayer(pCaster.getOwner())
		if pPlayer.getLeaderType() != gc.getInfoTypeForString(sLeader):
			return False
	iUnit = gc.getInfoTypeForString(sSluagh)
	iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	pPlot = CyMap().plot(0,0)
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if pUnit.isHasPromotion(iLL) or pUnit.isHasPromotion(iVB):
				return False
			if not pUnit.isDelayedDeath():
				return True
	return False


def spellResurrection(pCaster,sSluagh):
	pPlotC = pCaster.plot()
	pPlayer = gc.getPlayer(pCaster.getOwner())
	iUnit = gc.getInfoTypeForString(sSluagh)
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	iLL = gc.getInfoTypeForString('PROMOTION_NETHERBIND')
	iVB = gc.getInfoTypeForString('PROMOTION_VINDEXBIND')
	pPlot = CyMap().plot(0,0)
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if not pUnit.isHasPromotion(iLL) and not pUnit.isHasPromotion(iVB):
				break


	if iUnit == gc.getInfoTypeForString('UNIT_SLUAGH_DISCIPLE'):
		iReligion = pUnit.getReligion()
		iDivine = gc.getInfoTypeForString('PROMOTION_DIVINE2')
		iDivine2 = gc.getInfoTypeForString('PROMOTION_DIVINE2')
		if pUnit.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRUIDIC')):
			iUnit = gc.getInfoTypeForString('UNIT_DRUID')
		elif iReligion == gc.getInfoTypeForString('RELIGION_THE_ORDER'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ORDER')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_ORDER')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_THE_ORDER')
		elif iReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_EMPYREAN')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_EMPYREAN')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_THE_EMPYREAN')
		elif iReligion == gc.getInfoTypeForString('RELIGION_RUNES_OF_KILMORPH'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_RUNES_OF_KILMORPH')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_KILMORPH')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_KILMORPH')
		elif iReligion == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_FELLOWSHIP_OF_LEAVES')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_LEAVES')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_LEAVES')
		elif iReligion == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_OCTOPUS_OVERLORDS')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_OVERLORDS')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_THE_OVERLORDS')
		elif iReligion == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
			iUnit = gc.getInfoTypeForString('UNIT_DISCIPLE_THE_ASHEN_VEIL')
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_THE_VEIL')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_THE_VEIL')
		elif iReligion == gc.getInfoTypeForString('RELIGION_WHITE_HAND'):
			iUnit = -1
			if pUnit.isHasPromotion(iDivine):
				iUnit = gc.getInfoTypeForString('UNIT_PRIEST_OF_WINTER')
				if pUnit.isHasPromotion(iDivine2):
					iUnit = gc.getInfoTypeForString('UNIT_HIGH_PRIEST_OF_WINTER')
		elif iReligion == gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON'):
			iUnit = gc.getInfoTypeForString('UNIT_DRAGON_FANATIC')
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BARBARIAN'):
				iUnit = gc.getInfoTypeForString('UNIT_SON_OF_THE_INFERNO')
		elif pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ELOHIM'):
			iUnit = gc.getInfoTypeForString('UNIT_MONK')


	infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
	iUnit = infoCiv.getCivilizationUnits(gc.getUnitInfo(iUnit).getUnitClassType())
	if iUnit == -1:
		iUnit = gc.getInfoTypeForString('UNIT_CHAMPION')
	newUnit = pPlayer.initUnit(iUnit, pPlotC.getX(), pPlotC.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	newUnit.convert(pUnit)
	newUnit.setDamage(20, PlayerTypes.NO_PLAYER)
	newUnit.setMadeAttack(True)
	newUnit.setHasCasted(True)
	for iProm in range(gc.getNumPromotionInfos()):
		if gc.getPromotionInfo(iProm).isEquipment():
			newUnit.setHasPromotion(iProm, False)
	newUnit.setHasPromotion(iHeld, False)





def reqRessurectDragon(pCaster):
	if gc.getGame().getProjectCreatedCount(gc.getInfoTypeForString('PROJECT_STIR_FROM_SLUMBER')) > 0:
		return True
	return False




def spellRessurectAbashi(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_ABASHI')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	caster.cast(gc.getInfoTypeForString('SPELL_WITHER'))
	for iX in range(pPlot.getX()-2, pPlot.getX()+3, 1):
		for iY in range(pPlot.getY()-2, pPlot.getY()+3, 1):
			pLoopPlot = CyMap().plot(iX,iY)
			if not pLoopPlot.isNone():
				pLoopPlot.changePlotCounter(100)

	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_ABASHI')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)

def spellRessurectAcheron(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_ACHERON')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	caster.cast(gc.getInfoTypeForString('SPELL_RING_OF_FLAMES_ASHEN'))
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
					pPlot.setFeatureType(gc.getInfoTypeForString('FEATURE_FLAMES'), 0)

	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_ACHERON')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)

def spellRessurectBlue(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_THALATTH')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.isAdjacentToWater():
					if (iX != iiX or iY != iiY):
						for i in range(pPlot.getNumUnits()):
							pUnit = pPlot.getUnit(i)
							pUnit.doDamage(30, 100, caster, gc.getInfoTypeForString('DAMAGE_COLD'), True)
						if pPlot.getImprovementType() != -1:
							if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
								if CyGame().getSorenRandNum(100, "Tsunami") < 25:
									pPlot.setImprovementType(-1)
						CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPRING'),pPlot.getPoint())

	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_THALATTH')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)

def spellRessurectBlueMajosi(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_THALATTH')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)

	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_THALATTH')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)

	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), False)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), False)
	newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD'), False)
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-4, iX+5, 1):
		for iiY in range(iY-4, iY+5, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.isAdjacentToWater():
					if (iX != iiX or iY != iiY):
						for i in range(pPlot.getNumUnits()):
							pUnit = pPlot.getUnit(i)
							pUnit.doDamage(30, 100, caster, gc.getInfoTypeForString('DAMAGE_COLD'), True)
						if pPlot.getImprovementType() != -1:
							if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
								if CyGame().getSorenRandNum(100, "Tsunami") < 25:
									pPlot.setImprovementType(-1)
						CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPRING'),pPlot.getPoint())



def spellRessurectDrifa(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	iUnit = gc.getInfoTypeForString('UNIT_DRIFA')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	caster.cast(gc.getInfoTypeForString('SPELL_SNOWFALL'))
	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_DRIFA')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)


def spellRessurectEurabatres(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())

	pPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_CREATIVE'),True)
	pPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_PHILOSOPHICAL'),True)
	pPlayer.setHasTrait(gc.getInfoTypeForString('TRAIT_DEFENDER'),True)

	iUnit = gc.getInfoTypeForString('UNIT_EURABATRES')
	newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.UNITAI_HERO, DirectionTypes.DIRECTION_SOUTH)
	newUnit.cast(gc.getInfoTypeForString('SPELL_CROWN_OF_BRILLANCE'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_DESTROY_UNDEAD'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_VALOR'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_MORALE'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_LOYALTY'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_SANCTIFY'))
	newUnit.cast(gc.getInfoTypeForString('SPELL_COURAGE'))
	pPlayer.changeGoldenAgeTurns(CyGame().goldenAgeLength() * 2)
	newUnit.setAvatarOfCivLeader(True)


	pPlot = CyMap().plot(0,0)
	iUnit = gc.getInfoTypeForString('UNIT_SLUAGH_EURABATRES')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			break
	if pUnit != -1:
		newUnit.convert(pUnit)
		for iProm in range(gc.getNumPromotionInfos()):
			if gc.getPromotionInfo(iProm).isEquipment():
				newUnit.setHasPromotion(iProm, False)
		newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD'), False)

def reqReveal(caster):
	if caster.isIgnoreHide():
		return False
	pPlot = caster.plot()
	if pPlot.getOwner() != caster.getOwner():
		return False
	return True

def spellReveal(caster):
	caster.setIgnoreHide(True)

def reqRevelry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isGoldenAge():
		return False
	if pPlayer.isHuman() == False:
#		if pPlayer.getTotalPopulation() < 25:
		map = gc.getMap()
		if pPlayer.getNumCities() < gc.getWorldInfo(map.getWorldSize()).getTargetNumCities():
			return False
	return True

def spellRevelry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.changeGoldenAgeTurns(CyGame().goldenAgeLength() * 2)

def reqRevelation(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	iX = caster.getX()
	iY = caster.getY()
	iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
	iReflection = gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')
	iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')
	iBlur = gc.getInfoTypeForString('PROMOTION_BLUR')
	iShadow = gc.getInfoTypeForString('PROMOTION_SHADOWWALK')
	iBlind = gc.getInfoTypeForString('PROMOTION_BLIND')
	iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	for iiX in range(iX-3, iX+4, 1):
		for iiY in range(iY-3, iY+4, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if not pPlot.isRevealed(iTeam, False):
					return True
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if not pUnit.isHasPromotion(iHeld):
						if pUnit.getTeam() == iTeam:
							if pUnit.isHasPromotion(iBlind):
								return True
						if pUnit.isHasPromotion(iHidden):
							return True
						if pUnit.isHasPromotion(iHiddenNationality):
							return True
						if pUnit.isHasPromotion(iInvisible):
							return True
						if pUnit.isHasPromotion(iIllusion):
							return True
						if pUnit.isHasPromotion(iReflection):
							return True
						if pUnit.isHasPromotion(iBlur):
							return True
						if pUnit.isHasPromotion(iShadow):
							return True
						if pUnit.isHasPromotion(iVamp):
							return True
						if not pUnit.isIgnoreHide():
							if pUnit.getOwner() == pPlot.getOwner():
								if gc.getPlayer(pUnit.getOwner()).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SIDAR'):
									return True

	return False

def spellRevelation(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	iX = caster.getX()
	iY = caster.getY()
	iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
	iReflection = gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')
	iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')
	iBlur = gc.getInfoTypeForString('PROMOTION_BLUR')
	iShadow = gc.getInfoTypeForString('PROMOTION_SHADOWWALK')
	iBlind = gc.getInfoTypeForString('PROMOTION_BLIND')
	iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
	iHeld = gc.getInfoTypeForString('PROMOTION_HELD')
	for iiX in range(iX-3, iX+4, 1):
		for iiY in range(iY-3, iY+4, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				pPlot.setRevealed(iTeam, True, False, TeamTypes.NO_TEAM)

				pPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_LAND"), 1)
				pPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_ANIMAL"), 1)
				pPlot.changeInvisibleVisibilityCount(iTeam, gc.getInfoTypeForString("INVISIBLE_ALL"), 1)


				pPlot.updateVisibility()
				for iUnit in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(iUnit)
					if not pUnit.isHasPromotion(iHeld):
						if pUnit.getTeam() != iTeam:
							if pUnit.isHasPromotion(iIllusion):
								pUnit.kill(True, caster.getOwner())
							if pUnit.isHasPromotion(iReflection):
								pUnit.kill(True, caster.getOwner())
							pUnit.setIgnoreHide(True)
							if pUnit.isHasPromotion(iInvisible):
								pUnit.setHasPromotion(iInvisible, False)
							if pUnit.isHasPromotion(iHidden):
								pUnit.setHasPromotion(iHidden, False)
							if pUnit.isHasPromotion(iHiddenNationality):
								pUnit.setHasPromotion(iHiddenNationality, False)
								pUnit.setBlockading(False)
							if pUnit.isHasPromotion(iBlur):
								pUnit.setHasPromotion(iBlur, False)
							if pUnit.isHasPromotion(iShadow):
								pUnit.setHasPromotion(iShadow, False)
						elif pUnit.isHasPromotion(iBlind):
							pUnit.setHasPromotion(iBlind, False)
						if pUnit.isHasPromotion(iVamp):
							pUnit.doDamage(3, 30, caster, gc.getInfoTypeForString('DAMAGE_HOLY'), True)

def spellRingofFlames(caster):
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			if not (iiX == iX and iiY == iY):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					bValid = True
					if pPlot.getImprovementType() != -1:
						if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent():
							bValid = False
					if bValid:
						if (pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
							if CyGame().getSorenRandNum(100, "Flames Spread") < gc.getDefineINT('FLAMES_SPREAD_CHANCE'):
								pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))

def reqRiverOfBlood(caster):
	iOwner = caster.getOwner()
	iPopCount =0
	for iPlayer in range(gc.getMAX_PLAYERS()):
		if iPlayer != iOwner:
			pPlayer = gc.getPlayer(iPlayer)
			iPopCount = iPopCount + pPlayer.getTotalPopulation()

	if iPopCount < 5:
		return False

	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():

		if iPopCount < 25:
			return False

		iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
		py = PyPlayer(caster.getOwner())
		iCount =0
		for pUnit in py.getUnitList():
			if pUnit.isHasPromotion(iVamp):
				iCount +=1
			if iCount > 3:
				return True
		return False
	return True

def spellRiverOfBlood(caster):
	iXP = 0
	iV = gc.getInfoTypeForString('PROMOTION_VAMPIRE')
	iOwner = caster.getOwner()
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.isAlive():
			if iPlayer != iOwner:
				for pyCity in PyPlayer(iPlayer).getCityList() :
					pCity = pyCity.GetCy()
					pCity.changePopulation(-2)
					iXP = iXP +2
					CyInterface().addMessage(pCity.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_RIVER_OF_BLOOD", ()),'',1,'Art/Interface/Buttons/Spells/River of Blood.dds',ColorTypes(7),pCity.getX(),pCity.getY(),True,True)
					if pCity.getPopulation() < 2:
						pCity.setPopulation(1)

	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.isHasPromotion(iV):
			pUnit.changeExperience(iXP, -1, False, False, True)




def reqRoar(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = gc.getTeam(pPlayer.getTeam())
	iX = caster.getX()
	iY = caster.getY()
	iTarget = -1
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if not pUnit.isImmuneToFear():
						p2Player = gc.getPlayer(pUnit.getOwner())
						e2Team = p2Player.getTeam()
						if eTeam.isAtWar(e2Team) == True:
							return True
	return False

def spellRoar(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	eTeam = gc.getTeam(pPlayer.getTeam())
	pPlot = caster.plot()
	iX = caster.getX()
	iY = caster.getY()
	iCult = gc.getInfoTypeForString('RELIGION_CULT_OF_THE_DRAGON')
	iDr = gc.getInfoTypeForString('PROMOTION_DRAGON')
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if not pLoopPlot.isNone():
				for i in range(pLoopPlot.getNumUnits() -1, -1, -1):
					pUnit = pLoopPlot.getUnit(i)
					p2Player = gc.getPlayer(pUnit.getOwner())
					i2Team = p2Player.getTeam()
					if eTeam.isAtWar(i2Team):
						if pUnit.getReligion() == iCult and not pUnit.getRace() == iDr:
							newUnit = pPlayer.initUnit(pUnit.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							newUnit.convert(pUnit)
							newUnit.finishMoves()
						elif cf.doFear(pUnit, pPlot, caster, True):
							CyInterface().addMessage(pUnit.getOwner (),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR", (gc.getUnitInfo(pUnit.getUnitType ()).getDescription(), )),'',1,'Art/Interface/Buttons/Spells/Roar.dds',ColorTypes(7),pUnit.getX (),pUnit.getY(),True,True)
							CyInterface().addMessage (iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR_ENEMY", (gc.getUnitInfo (pUnit.getUnitType()).getDescription(),  )),'',1,'Art/Interface/Buttons/Spells/Roar.dds',ColorTypes(8),pUnit.getX(),pUnit.getY(),True,True)
def reqRobGrave(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getAlignment() == gc.getInfoTypeForString('ALIGNMENT_GOOD'):
			return False
	return True


def spellRobGrave(caster):
	CyGame().changeGlobalCounter(1)
	pPlot = caster.plot()
	pPlot.setImprovementType(-1)
	pPlayer = gc.getPlayer(caster.getOwner())
	lList = ['LOW_GOLD', 'HIGH_GOLD', 'SPAWN_SKELETONS', 'SPAWN_SPECTRE']
	if pPlayer.canReceiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster):
		lList = lList + ['TECH']
	sGoody = lList[CyGame().getSorenRandNum(len(lList), "Pick Goody")-1]
	if sGoody == 'LOW_GOLD':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_LOW_GOLD'), caster)
	if sGoody == 'HIGH_GOLD':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_HIGH_GOLD'), caster)
	if sGoody == 'TECH':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_TECH'), caster)
	if sGoody == 'SPAWN_SKELETONS':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_SKELETONS'), caster)
	if sGoody == 'SPAWN_SPECTRE':
		pPlayer.receiveGoody(pPlot, gc.getInfoTypeForString('GOODY_GRAVE_SPECTRE'), caster)

def spellSacrificeAltar(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	eTeam = gc.getTeam(pPlayer.getTeam())
	iTech = pPlayer.getCurrentResearch()
	iNum = 10 + (caster.getLevel() * caster.getLevel())
	eTeam.changeResearchProgress(iTech, iNum, caster.getOwner())




def spellSacrificePyre(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	caster.cast(gc.getInfoTypeForString('SPELL_RING_OF_FLAMES_ASHEN'))
	iDur = caster.getDuration()
	iCount = 1
	if isWorldUnitClass(caster.getUnitClassType()):
		iCount = 7
	for i in range(iCount):
		newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_FIRE_ELEMENTAL'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
		if iDur > 0:
			iDur += 1
		newUnit.setDuration(iDur)
	while caster.isImmortal():
		caster.changeImmortal(-1)


		newUnit.setSummoner(caster.getID())
def reqSanctify(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
			return False
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_BARBARIAN'):
			return False
	iTorment = gc.getInfoTypeForString('FEATURE_TORMENTED_SOULS')
	iX = caster.getX()
	iY = caster.getY()
	if gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		if CyGame().getWBMapScript():
			return False
		iBrokenLands = gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS')
		iBurningSands = gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')
		iFieldsOfPerdition = gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')
		iShallows = gc.getInfoTypeForString('TERRAIN_SHALLOWS')
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					iTerrain = pPlot.getTerrainType()
					if (iTerrain == iBrokenLands or iTerrain == iBurningSands or iTerrain == iFieldsOfPerdition or iTerrain == iShallows):
						return True
					if pPlot.getFeatureType() == iTorment:
						return True
					if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE'):
						return True
	else:
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot = CyMap().plot(iiX,iiY)
				if not pPlot.isNone():
					if pPlot.getPlotCounter() > 0:
						return True
					if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_CITY_RUINS'):
						return True
					if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD'):
						return True
					if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE'):
						return True
					if pPlot.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_PIT'):
						return True
	return False

def spellSanctify(pCaster):
	iTorment = gc.getInfoTypeForString('FEATURE_TORMENTED_SOULS')
	iBrokenLands = gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS')
	iBurningSands = gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')
	iDesert = gc.getInfoTypeForString('TERRAIN_DESERT')
	iFieldsOfPerdition = gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')
	iGrass = gc.getInfoTypeForString('TERRAIN_GRASS')
	iMarsh = gc.getInfoTypeForString('TERRAIN_MARSH')
	iPlains = gc.getInfoTypeForString('TERRAIN_PLAINS')
	iShallows = gc.getInfoTypeForString('TERRAIN_SHALLOWS')
	iHell = gc.getInfoTypeForString('IMPROVEMENT_HELLFIRE')
	iPit = gc.getInfoTypeForString('IMPROVEMENT_PIT')
	iRuin = gc.getInfoTypeForString('IMPROVEMENT_CITY_RUINS')
	iGrave = gc.getInfoTypeForString('IMPROVEMENT_GRAVEYARD')
	iX = pCaster.getX()
	iY = pCaster.getY()

	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.getFeatureType() == iTorment:
					pPlot.setFeatureType(-1, -1)
				if pPlot.getImprovementType() == iPit:
					pPlot.setImprovementType(-1)
					CyGame().changeGlobalCounter(-2)
				if pPlot.getImprovementType() == iHell:
					pPlot.setImprovementType(-1)
					CyGame().changeGlobalCounter(-2)
				if pPlot.getImprovementType() == iRuin:
					pPlot.setImprovementType(-1)
					CyGame().changeGlobalCounter(-1)
				if pPlot.getImprovementType() == iGrave:
					pPlot.setImprovementType(-1)
					CyGame().changeGlobalCounter(-1)
					pPlayer = gc.getPlayer(pCaster.getOwner())
					newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_EINHERJAR'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.setSummoner(pCaster.getID())

				if not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
					if pPlot.getPlotCounter() > 0:
						pPlot.changePlotCounter(pPlot.getPlotCounter() * -1)
				else:
					iTerrain = pPlot.getTerrainType()
					if iTerrain == iBrokenLands:
						pPlot.setTerrainType(iGrass, True, True)
					if iTerrain == iBurningSands:
						pPlot.setTerrainType(iDesert, True, True)
					if iTerrain == iFieldsOfPerdition:
						pPlot.setTerrainType(iPlains, True, True)
					if iTerrain == iShallows:
						pPlot.setTerrainType(iMarsh, True, True)


def reqSanctuary(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getNumCities() == 0:
		return False
	if not pPlayer.isHuman():
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) < 2:
			return False
	return True

def spellSanctuary(caster):
	iPlayer = caster.getOwner()
	iTeam = caster.getTeam()
	pPlayer = gc.getPlayer(iPlayer)
	iBaseDelay = 30
	iDelay = (iBaseDelay * gc.getGameSpeedInfo(CyGame().getGameSpeedType()).getVictoryDelayPercent()) / 100

	pPlayer.changeSanctuaryTimer(iDelay)
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		if pPlot.isOwned():
			if pPlot.getOwner() == iPlayer:
				for i in range(pPlot.getNumUnits(), -1, -1):
					pUnit = pPlot.getUnit(i)
					if pUnit.getTeam() != iTeam:
						pUnit.jumpToNearestValidPlot()



def reqSironasTouch(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isFeatAccomplished(FeatTypes.FEAT_HEAL_UNIT_PER_TURN):
		return False
	if caster.getDamage() > 0:
		if not pPlayer.isHuman():
			if caster.getDamage() < 15:
				return False
		return True
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED')):
		return True
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED')):
		return True
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED')):
		return True
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED')):
		return True
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED')):
		return True
	return False

def spellSironasTouch(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlayer.setFeatAccomplished(FeatTypes.FEAT_HEAL_UNIT_PER_TURN, False)
	caster.changeDamage(-10,0)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), False)
	caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), False)



def spellSlaveTradeBuy(caster):
	pCity = caster.plot().getPlotCity()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_SLAVE'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

	pCity.applyBuildEffects(newUnit)
	newUnit.setHasCasted(True)

	for iProm in range(gc.getNumPromotionInfos()):
		if newUnit.isHasPromotion(iProm):
			if gc.getPromotionInfo(iProm).isRace():
				newUnit.setHasPromotion(iProm, False)

	iPromotion = -1
	iRnd = CyGame().getSorenRandNum(100, "Slave Trade Buy")
	if (iRnd >= 35 and iRnd < 37):
		iPromotion = gc.getInfoTypeForString('PROMOTION_LAMIA')
	if (iRnd >= 37 and iRnd < 40):
		iPromotion = gc.getInfoTypeForString('PROMOTION_CENTAUR')
	if (iRnd >= 40 and iRnd < 50):
		iPromotion = gc.getInfoTypeForString('PROMOTION_NOMAD')
	if (iRnd >= 50 and iRnd < 60):
		iPromotion = gc.getInfoTypeForString('PROMOTION_WINTERBORN')
	if (iRnd >= 60 and iRnd < 70):
		iPromotion = gc.getInfoTypeForString('PROMOTION_DWARF')
	if (iRnd >= 70 and iRnd < 75):
		iPromotion = gc.getInfoTypeForString('PROMOTION_ELF')
	if (iRnd >= 75 and iRnd < 80):
		iPromotion = gc.getInfoTypeForString('PROMOTION_DARK_ELF')
	if (iRnd >= 80 and iRnd < 85):
		iPromotion = gc.getInfoTypeForString('PROMOTION_LIZARDMAN')
	if (iRnd >= 85):
		iPromotion = gc.getInfoTypeForString('PROMOTION_ORC')
	if iPromotion != -1:
		newUnit.setHasPromotion(iPromotion, True)






def reqDominationDemon(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
	if pPlayer.isHuman() == False:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getRace() == iDemon:
						if not isWorldUnitClass(pUnit.getUnitClassType()):
							if not pUnit.isDelayedDeath():
								if eTeam.isAtWar(pUnit.getTeam()):
									iResist = pUnit.getResistChance(caster, gc.getInfoTypeForString('SPELL_DOMINATION_DEMON'))
									if iResist < iResistMax:
										return True
	return False

def spellDominationDemon(caster):
	iSpell = gc.getInfoTypeForString('SPELL_DOMINATION_DEMON')
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iResistMax = 95
	iDemon = gc.getInfoTypeForString('PROMOTION_DEMON')
	if pPlayer.isHuman() == False:
		iResistMax = 20
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getRace() == iDemon:
						if not isWorldUnitClass(pUnit.getUnitClassType()):
							if not pUnit.isDelayedDeath():
								if eTeam.isAtWar(pUnit.getTeam()):
									pPlot = caster.plot()
									if pUnit.isResisted(caster, iSpell) == False:
										CyInterface().addMessage(pUnit.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(7),pUnit.getX(),pUnit.getY(),True,True)
										CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_DOMINATION_ENEMY", ()),'',1,'Art/Interface/Buttons/Spells/Domination.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
										newUnit = pPlayer.initUnit(pUnit.getUnitType(), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
										newUnit.convert(pUnit)




def reqSandLion(caster):
	pPlot = caster.plot()
	if (pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_DESERT') and pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_BURNING_SANDS')):
		return False
	iSummon = gc.getInfoTypeForString('UNIT_SAND_LION')
	casterID = caster.getID()
	iPlayer = caster.getOwner()
	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.getUnitType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True



def reqScorch(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_ICE'):
		return True
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_BLIZZARD'):
		if pPlayer.getStateReligion() != gc.getInfoTypeForString('RELIGION_WHITE_HAND'):
			return True
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS') or pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION')):
		if pPlayer.isHuman() == False:
			if caster.getOwner() == pPlot.getOwner():
				return False
		return True
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW') or pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GLACIER'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
			if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_DOVIELLO') or pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_ILLIANS'):
				return False
		return True
# Tholal AI - allow marshes to be scorched
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
		return True
	return False

def spellScorch(caster):
	pPlot = caster.plot()
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_ICE'):
		pPlot.setFeatureType(-1, -1)
	if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_BLIZZARD'):
		pPlot.setFeatureType(-1, -1)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'),True,True)
	elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'),True,True)
	elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GLACIER'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_WASTELAND'),True,True)
	elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	if pPlot.isOwned():
		cf.startWar(caster.getOwner(), pPlot.getOwner(), WarPlanTypes.WARPLAN_TOTAL)

def spellSing(caster):
	pPlot = caster.plot()
	point = pPlot.getPoint()
	lszSound = ["AS3D_SING1", "AS3D_SING2", "AS3D_SING3", "AS3D_SING4"]
	CyAudioGame().Play3DSound(lszSound[CyGame().getSorenRandNum(4, "Sing")], point.x, point.y, point.z)





def reqDrown(pCaster):
	if pCaster.isImmortal():
		return False
	if isWorldUnitClass(pCaster.getUnitClassType()):
		return False
	if isNationalUnitClass(pCaster.getUnitClassType()):
		return False
	pPlayer = gc.getPlayer(pCaster.getOwner())
	iGold = 5 * pCaster.baseCombatStrDefense() * pCaster.baseCombatStr() * pCaster.getLevel()
	if pPlayer.getGold() < iGold:
		return False
	return True


def spellDrown(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_DROWN'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

	pCity = pCaster.plot().getPlotCity()
	pCity.applyBuildEffects(newUnit)

	newUnit.convert(pCaster)
	newUnit.finishMoves()
	newUnit.setBaseCombatStr(pCaster.baseCombatStr())
	newUnit.setBaseCombatStrDefense(pCaster.baseCombatStrDefense())
	iGold = -5 * pCaster.baseCombatStrDefense() * pCaster.baseCombatStr() * pCaster.getLevel()
	pPlayer.changeGold(iGold)


def reqSealWell(pCaster):
	pPlot = pCaster.plot()
	if pPlot.getBonusType(-1) == gc.getInfoTypeForString('BONUS_MANA_CREATION'):
		return True
	return False

def spellSealWell(pCaster):
	pPlot = pCaster.plot()
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_DEATH'))
	for iX in range(pPlot.getX()-2, pPlot.getX()+3, 1):
		for iY in range(pPlot.getY()-2, pPlot.getY()+3, 1):
			pLoopPlot = CyMap().plot(iX,iY)
			if not pLoopPlot.isNone():
				pLoopPlot.changePlotCounter(100)



def reqUnsealWell(pCaster):
	pPlot = pCaster.plot()
	if pPlot.getBonusType(-1) == gc.getInfoTypeForString('BONUS_MANA_DEATH'):
		return True
	return False

def spellUnsealWell(pCaster):
	pPlot = pCaster.plot()
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_CREATION'))
	for iX in range(pPlot.getX()-2, pPlot.getX()+3, 1):
		for iY in range(pPlot.getY()-2, pPlot.getY()+3, 1):
			pLoopPlot = CyMap().plot(iX,iY)
			if not pLoopPlot.isNone():
				pLoopPlot.changePlotCounter(-100)


def spellSnowfall(caster):
	iX = caster.getX()
	iY = caster.getY()
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iBlizzard = gc.getInfoTypeForString('FEATURE_BLIZZARD')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if not pPlot.isWater():
					if pPlot.getTerrainType() != iSnow:
						iRnd = CyGame().getSorenRandNum(6, "Snowfall") + 3
						pPlot.setTempTerrainType(iSnow, iRnd)
						if pPlot.getFeatureType() == -1:
							if CyGame().getSorenRandNum(100, "Snowfall") < 2:
								pPlot.setFeatureType(iBlizzard, -1)
						if pPlot.getFeatureType() == iFlames:
							pPlot.setFeatureType(-1, -1)
						if pPlot.getImprovementType() == iSmoke:
							pPlot.setImprovementType(-1)

def spellSnowfallGreator(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	iWH = gc.getInfoTypeForString('PROMOTION_THE_WHITE_HAND')
	iX = caster.getX()
	iY = caster.getY()
	iFlames = gc.getInfoTypeForString('FEATURE_FLAMES')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	iSnow = gc.getInfoTypeForString('TERRAIN_SNOW')
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():

				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getOwner() != iPlayer and pUnit.isHasPromotion(iWH):
						newUnit = pPlayer.initUnit(pUnit.getUnitType(), iX, iY, UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.convert(pUnit)


				if not pPlot.isWater():
					if pPlot.getTerrainType() != iSnow:
						iRnd = CyGame().getSorenRandNum(12, "Snowfall") + 6
						pPlot.setTempTerrainType(iSnow, iRnd)
						if pPlot.getFeatureType() == iFlames:
							pPlot.setFeatureType(-1, -1)
						if pPlot.getImprovementType() == iSmoke:
							pPlot.setImprovementType(-1)

	if not caster.isImmortal():
		caster.changeImmortal(1)




def reqSpreadTheCouncilOfEsus(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = caster.plot().getPlotCity()
	if pCity.isHasReligion(gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS')):
		return False
	if pPlayer.isHuman() == False:
		if pPlayer.getStateReligion() != gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
			return False
	return True

def reqSpring(caster):
	pPlot = caster.plot()
	pPlayer = gc.getPlayer(caster.getOwner())
	bFlames = False
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				if pPlot2.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES') or pPlot2.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE'):
					bFlames = True
	if bFlames == False:
		if pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_DESERT'):
			return False
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS'):
			return False
		if pPlayer.isHuman() == False:
			if caster.getOwner() != pPlot.getOwner():
				return False
	if pPlayer.isHuman() == False:
		if pPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_INFERNAL'):
			return False
		iX = pPlot.getX()
		iY = pPlot.getY()
		for iiX in range(iX-1, iX+2, 1):
			for iiY in range(iY-1, iY+2, 1):
				pPlot2 = CyMap().plot(iiX,iiY)
				if not pPlot2.isNone():
					if pPlot2.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES'):
						return True
					if pPlot2.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE'):
						return True
	return True

def spellSpring(caster):
	pPlot = caster.plot()
	if (pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_DESERT') and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FLOOD_PLAINS')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_SCRUB'):
			pPlot.setFeatureType(-1, -1)
	iX = pPlot.getX()
	iY = pPlot.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				if pPlot2.getFeatureType() == gc.getInfoTypeForString('FEATURE_FLAMES'):
					pPlot2.setFeatureType(-1, -1)
				if pPlot2.getImprovementType() == gc.getInfoTypeForString('IMPROVEMENT_SMOKE'):
					pPlot2.setImprovementType(-1)

def reqSprint(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FATIGUED')):
		return False
	return True

def reqStasis(caster):
	pPlayer = gc.getPlayer(caster.getOwner())

	if pPlayer.isHuman() == False:
		if pPlayer.getNumCities() < 5:
			return False
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
	return True

def spellStasis(caster):
	pPlayer = gc.getPlayer(caster.getOwner())

	iBaseDelay = 20
	iDelay = (iBaseDelay * gc.getGameSpeedInfo(CyGame().getGameSpeedType()).getVictoryDelayPercent()) / 100
	iTeam = pPlayer.getTeam()


	for iPlayer2 in range(gc.getMAX_PLAYERS()):
		pPlayer2 = gc.getPlayer(iPlayer2)
		if pPlayer2.isAlive():
			if pPlayer2.getTeam() != iTeam:
				pPlayer2.changeDisableProduction(iDelay)
				pPlayer2.changeDisableResearch(iDelay)
				pPlayer2.changeDisableSpellcasting(iDelay)



def reqSteal(caster):
	iTeam = caster.getTeam()
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() != iTeam:
			for iProm in range(gc.getNumPromotionInfos()):
				if pUnit.isHasPromotion(iProm):
					if gc.getPromotionInfo(iProm).isEquipment():
						return True
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getTeam() != iTeam:
			for iBuild in range(gc.getNumBuildingInfos()):
				if pCity.getNumRealBuilding(iBuild) > 0:
					if gc.getBuildingInfo(iBuild).isEquipment():
						return True
	return False

def spellSteal(caster):
	iTeam = caster.getTeam()
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() != iTeam:
			for iProm in range(gc.getNumPromotionInfos()):
				if pUnit.isHasPromotion(iProm):
					if gc.getPromotionInfo(iProm).isEquipment():
 						if CyGame().getSorenRandNum(100, "Steal") < 20:
							cf.startWar(caster.getOwner(), pUnit.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
						else:
							caster.setHasPromotion(iProm, True)
							pUnit.setHasPromotion(iProm, False)
	if pPlot.isCity():
		pCity = pPlot.getPlotCity()
		if pCity.getTeam() != iTeam:
			for iBuild in range(gc.getNumBuildingInfos()):
				if pCity.getNumRealBuilding(iBuild) > 0:
					if gc.getBuildingInfo(iBuild).isEquipment():
 						if CyGame().getSorenRandNum(100, "Steal") < 20:
							cf.startWar(caster.getOwner(), pUnit.getOwner(), WarPlanTypes.WARPLAN_TOTAL)
						else:
							for iUnit in range(gc.getNumUnitInfos()):
								if gc.getUnitInfo(iUnit).getBuildings(iBuild):
									pCity.setNumRealBuilding(iBuild, 0)
									caster.setHasPromotion(gc.getUnitInfo(iUnit).getEquipmentPromotion(), True)

def reqTakeEquipmentBuilding(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	return True

def spellTakeEquipmentBuilding(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	pPlot = caster.plot()
	for i in range(gc.getNumBuildingInfos()):
		if gc.getUnitInfo(iUnit).getBuildings(i):
			pPlot.getPlotCity().setNumRealBuilding(i, 0)

def reqTakeEquipmentPromotion(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('NONE'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.isHasPromotion(iProm)):
			pHolder = pUnit
	if pHolder == -1:
		return False
	if pHolder.isHasCasted():
		return False
	if pHolder.getUnitType() == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		if iProm == gc.getInfoTypeForString('PROMOTION_PIECES_OF_BARNAXUS'):
			return False
	if pHolder.getUnitType() == gc.getInfoTypeForString('UNIT_WAR_MACHINE'):
		if iProm == gc.getInfoTypeForString('PROMOTION_PIECES_OF_WAR_MACHINE'):
			return False
	if pHolder.getUnitType() == gc.getInfoTypeForString('UNIT_MITHRIL_GOLEM'):
		if iProm == gc.getInfoTypeForString('PROMOTION_PIECES_OF_MITHRIL_GOLEM'):
			return False
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isHuman() == False:
		if caster.baseCombatStr() - 2 <= pHolder.baseCombatStr():
			return False
		if gc.getUnitInfo(pHolder.getUnitType()).getFreePromotions(iProm):
			return False
	return True

def spellTakeEquipmentPromotion(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if (pUnit.getOwner() == iPlayer and pUnit.isHasPromotion(iProm) and pUnit != caster):
			pHolder = pUnit
	if pHolder != -1:
		pHolder.setHasPromotion(iProm, False)
		caster.setHasPromotion(iProm, True)

def reqTakeEquipmentUnit(caster,unit):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_NAVAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_SIEGE'):
		return False
	if caster.getSpecialUnitType() == gc.getInfoTypeForString('SPECIALUNIT_SPELL'):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ILLUSION')):
		return False
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')):
		return False
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	if caster.isHasPromotion(iProm):
		return False
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if pUnit.isDelayedDeath() == False:
				pHolder = pUnit
	if pHolder == -1:
		return False
	if pHolder.isMadeAttack():
		return False
	return True

def spellTakeEquipmentUnit(caster,unit):
	iUnit = gc.getInfoTypeForString(unit)
	iProm = gc.getUnitInfo(iUnit).getEquipmentPromotion()
	iPlayer = caster.getOwner()
	pPlot = caster.plot()
	pHolder = -1
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getUnitType() == iUnit:
			if pUnit.isDelayedDeath() == False:
				pHolder = pUnit
	if pHolder != -1:
		pHolder.setHasCasted(True)
		pHolder.kill(True, PlayerTypes.NO_PLAYER)

def reqTaunt(caster):
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	bValid = False
	pPlot = caster.plot()

	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if not pLoopPlot.isNone():
				for i in range(pLoopPlot.getNumUnits()):
					pUnit = pLoopPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.isAlive():
							if pPlot.isNone() == False:
								if pUnit.canMoveInto(pPlot,True,False,True):	#modified Sephi
									if not pUnit.isOnlyDefensive():
										if pUnit.getImmobileTimer() == 0:
											return True
	return bValid

def spellTaunt(caster):
	iSpell = gc.getInfoTypeForString('SPELL_TAUNT')
	iX = caster.getX()
	iY = caster.getY()
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	bValid = False
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pLoopPlot = CyMap().plot(iiX,iiY)
			if not pLoopPlot.isNone():
				for i in range(pLoopPlot.getNumUnits()):
					pUnit = pLoopPlot.getUnit(i)
					if eTeam.isAtWar(pUnit.getTeam()):
						if pUnit.isAlive():
							if not pUnit.isOnlyDefensive():
								if pPlot.isNone() == False:
									if pUnit.canMoveInto(pPlot,True,False,True):	#modified Sephi
										if pUnit.getImmobileTimer() == 0:
											if (pUnit.getGroup().getNumUnits()==1) or (pUnit.getGroup().getHeadUnit()!=pUnit):
												if not pUnit.isResisted(caster, iSpell):
													pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'),True)
													pUnit.attack(pPlot, False)

def spellTeleport(caster,loc):
	player = caster.getOwner()
	pPlayer = gc.getPlayer(player)
	pCity = pPlayer.getCapitalCity()
	caster.setXY(pCity.getX(), pCity.getY(), False, True, True)





def effectAdventure(caster):
	if caster.getUnitCombatType() != -1 and caster.getUnitCombatType() != gc.getInfoTypeForString('UNITCOMBAT_CIVILIAN'):
		pPlot = caster.plot()
		if not pPlot.isOwned():
			if CyGame().getSorenRandNum(100, "Adventure") < caster.getLevel():
				iRnd = CyGame().getSorenRandNum(100, "Explore Lair")
				if iRnd < 14:
					cf.exploreLairBigBad(caster)
				if iRnd >= 14 and iRnd < 44:
					cf.exploreLairBad(caster)
				if iRnd >= 44 and iRnd < 70:
					cf.exploreLairNeutral(caster)
				if iRnd >= 70 and iRnd < 99:
					cf.exploreLairGood(caster)
				if iRnd >= 90:
					cf.exploreLairBigGood(caster)
				caster.changeExperience(1, -1, False, False, False)
		elif not caster.hasMoved() and pPlot.getOwner() == caster.getOwner():
			if CyGame().getSorenRandNum(100, "Adventure") < 2*caster.getLevel():
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("And now, for something completely different...", ()),'',1,'Art/Interface/Buttons/Units/Adventurer.dds',ColorTypes(7),caster.getX(),caster.getY(),True,True)
				pPlayer = gc.getPlayer(caster.getOwner())
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ADVENTURER'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_HERO'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING1'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MAGIC_IMMUNE'), False)
				caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), True)
				newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_ADVENTURER'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit.convert(caster)
				newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION'), False)




def effectTaint(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD')):
		return False
	elif gc.getPlayer(caster.getOwner()).getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_MERCURIANS'):
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), False)


		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH2'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL2')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL2'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL3')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL3'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY2'), False)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3'), False)

		if caster.getReligion() == gc.getInfoTypeForString('RELIGION_THE_ASHEN_VEIL'):
			caster.setReligion(-1)
		elif caster.getReligion() == gc.getInfoTypeForString('RELIGION_WHITE_HAND'):
			caster.setReligion(-1)
		elif caster.getReligion() == gc.getInfoTypeForString('RELIGION_OCTOPUS_OVERLORDS'):
			caster.setReligion(-1)
		elif caster.getReligion() == gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS'):
			caster.setReligion(-1)
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON')):
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ANGEL'), True)
			if gc.getUnitInfo(caster.getUnitType()).getTier() == 4:
				pPlayer = gc.getPlayer(caster.getOwner())
				if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_LICH')) < 4:
					iUnit = gc.getInfoTypeForString('UNIT_REPENTANT_ANGEL')
					newUnit = pPlayer.initUnit(iUnit, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
					newUnit.convert(caster)
		elif caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD')):
			caster.kill(False, caster.getOwner())
	elif caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED')):
		if not caster.isAlive():
			caster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DEMON_POSSESSED'), False)
	elif not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		pPlot = caster.plot()
		iTaint = caster.getLevel()*(1 + CyGame().getGlobalCounter()//20)
		pPlot.changePlotCounter(iTaint)


def effectHallow(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD')):
		return False
	if not gc.getGame().isOption(GameOptionTypes.GAMEOPTION_NO_PLOT_COUNTER):
		pPlot = caster.plot()
		pPlot.changePlotCounter(-caster.getLevel()*CyGame().getGlobalCounter()/10)


def perTurnTeachMagic(caster):
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HELD')):
		return False
	if CyGame().getSorenRandNum(5, "Govannon") <3:
		return False
	lList = []
	iMagLib = gc.getInfoTypeForString('PROMOTION_MAGICALLY_LIBERAL')
	lList = lList + [iMagLib]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING2')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_CHANNELING1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_AIR1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_BODY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_CHAOS1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CREATION1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_CREATION1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DEATH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_DIMENSIONAL1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_EARTH1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENCHANTMENT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ENTROPY1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_FIRE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FORCE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_FORCE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_ICE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LAW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_LIFE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_METAMAGIC1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_METAMAGIC1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_MIND1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_NATURE1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SHADOW1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SPIRIT1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_SUN1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER1')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_WATER1')]
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION2')):
		lList = lList + [gc.getInfoTypeForString('PROMOTION_EXTENSION1')]
	lList2 = []
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHANNELING3')):
		lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_CHANNELING2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AIR3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_AIR2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BODY3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_BODY2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CHAOS3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_CHAOS2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CREATION3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_CREATION2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DEATH3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_DEATH2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DIMENSIONAL3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_DIMENSIONAL2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EARTH3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_EARTH2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENCHANTMENT3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_ENCHANTMENT2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENTROPY3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_ENTROPY2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FIRE3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_FIRE2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FORCE3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_FORCE2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ICE3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_ICE2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LAW3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_LAW2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_LIFE3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_LIFE2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MIND3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_MIND2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_NATURE3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_NATURE2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOW3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_SHADOW2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SPIRIT3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_SPIRIT2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SUN3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_SUN2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WATER3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_WATER2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_EXTENSION3')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_EXTENSION2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CASWALLAWN')):
			lList2 = lList2 + [gc.getInfoTypeForString('PROMOTION_CHANNELING3')]
	if len(lList) > 0:
		iAdept = gc.getInfoTypeForString('UNITCOMBAT_ADEPT')
		iAnimal = gc.getInfoTypeForString('UNITCOMBAT_ANIMAL')
		iBeast = gc.getInfoTypeForString('UNITCOMBAT_BEAST')
		pPlot = caster.plot()
		iPlayer = caster.getOwner()
		iTaught = 0
		iProm = lList[CyGame().getSorenRandNum(len(lList), "Govannon")]
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getOwner() == iPlayer:
				if pUnit.isAlive():
					if pUnit.getUnitCombatType() != iAnimal and pUnit.getUnitCombatType() != iBeast:
						if iProm == iMagLib or pUnit.isHasPromotion(iMagLib) or pUnit.getUnitCombatType() != iAdept:
							if not pUnit.isHasPromotion(iProm):
								pUnit.setHasPromotion(iProm, True)
								iTaught += 1
								CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAGIC_TAUGHT", ()),'',1,gc.getPromotionInfo(iProm).getButton(),ColorTypes(8),caster.getX(),caster.getY(),True,True)
		if iTaught == 0:
			iProm = lList[CyGame().getSorenRandNum(len(lList), "Govannon")]
			for i in range(pPlot.getNumUnits()):
				pUnit = pPlot.getUnit(i)
				if pUnit.getOwner() == iPlayer:
					if pUnit.isAlive():
						if pUnit.getUnitCombatType() != iAnimal and pUnit.getUnitCombatType() != iBeast:
							if iProm == iMagLib or pUnit.isHasPromotion(iMagLib) or pUnit.getUnitCombatType() != iAdept:
								if not pUnit.isHasPromotion(iProm):
									pUnit.setHasPromotion(iProm, True)
									iTaught += 1
									CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAGIC_TAUGHT", ()),'',1,gc.getPromotionInfo(iProm).getButton(),ColorTypes(8),caster.getX(),caster.getY(),True,True)
		if len(lList2)>0:
			if iTaught == 0:
				iProm = lList2[CyGame().getSorenRandNum(len(lList2), "School of Govannon")]
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getOwner() == iPlayer:
						if pUnit.isAlive():
							if pUnit.getUnitCombatType() != iAnimal and pUnit.getUnitCombatType() != iBeast:
								if pUnit.isHasPromotion(iMagLib):
									if not pUnit.isHasPromotion(iProm):
										pUnit.setHasPromotion(iProm, True)
										iTaught += 1
										CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAGIC_TAUGHT", ()),'',1,gc.getPromotionInfo(iProm).getButton(),ColorTypes(8),caster.getX(),caster.getY(),True,True)
										break
			if iTaught == 0:
				iProm = lList2[CyGame().getSorenRandNum(len(lList2), "Secondary School of Govannon")]
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.getOwner() == iPlayer:
						if pUnit.isAlive():
							if pUnit.getUnitCombatType() != iAnimal and pUnit.getUnitCombatType() != iBeast:
								if pUnit.isHasPromotion(iMagLib):
									if not pUnit.isHasPromotion(iProm):
										pUnit.setHasPromotion(iProm, True)
										iTaught += 1
										CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAGIC_TAUGHT", ()),'',1,gc.getPromotionInfo(iProm).getButton(),ColorTypes(8),caster.getX(),caster.getY(),True,True)
										break


def perTurnTeachGolems(caster):
	if caster.getUnitType() == gc.getInfoTypeForString('UNIT_BARNAXUS'):
		iGolem = gc.getInfoTypeForString('PROMOTION_GOLEM')
		lList = []
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMBAT1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMBAT2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT3')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMBAT3')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT4')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMBAT4')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMBAT5')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMBAT5')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COMMANDO')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COMMANDO')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_MOBILITY1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_MOBILITY1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CITY_RAIDER1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_CITY_RAIDER1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CITY_RAIDER2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_CITY_RAIDER2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CITY_RAIDER3')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_CITY_RAIDER3')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRILL1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_DRILL1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRILL2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_DRILL2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRILL3')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_DRILL3')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DRILL4')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_DRILL4')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHOCK')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_SHOCK')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHOCK2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_SHOCK2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COVER')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COVER')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_COVER2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_COVER2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_UNDEAD_SLAYING')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_UNDEAD_SLAYING')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SCOURGE')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_SCOURGE')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BLITZ')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_BLITZ')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SENTRY')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_SENTRY')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FORMATION')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_FORMATION')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_FORMATION2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_FORMATION2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GUERILLA1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_GUERILLA1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_GUERILLA2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_GUERILLA2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WOODSMAN1')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_WOODSMAN1')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WOODSMAN2')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_WOODSMAN2')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_AMPHIBIOUS')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_AMPHIBIOUS')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BOUNTY_HUNTER')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_BOUNTY_HUNTER')]
		if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BOARDING')):
			lList = lList + [gc.getInfoTypeForString('PROMOTION_BOARDING')]

		pPlot = caster.plot()
		iPlayer = caster.getOwner()
		for i in range(pPlot.getNumUnits()):
			pUnit = pPlot.getUnit(i)
			if pUnit.getOwner() == iPlayer:
				if pUnit.isHasPromotion(iGolem):
					for iProm in range(len(lList)):
						if not pUnit.isHasPromotion(lList[iProm]):
							pUnit.setHasPromotion(lList[iProm], True)

def spellTreetopDefence(caster):
	pPlot = caster.plot()
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pUnit.getTeam() == caster.getTeam():
			pUnit.setFortifyTurns(15)

def reqTrust(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_TRUST):
		pPlot = caster.plot()
		if pPlot.isCity():
			pCity = pPlot.getPlotCity()
			if pCity.isCapital():
				if pCity.getOwner() != caster.getOwner():
					return True
		return False
	if pPlayer.isBarbarian():
		return False
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False
	return True

def spellTrust(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	pCity = pPlayer.getCapitalCity()

	if pPlayer.isFeatAccomplished(FeatTypes.FEAT_TRUST):
		pPlot = caster.plot()
		if pPlot.isCity():
			pCity = pPlot.getPlotCity()
			pCityPlayer = gc.getPlayer(pCity.getOwner())
			pCityPlayer.AI_changeAttitudeExtra(caster.getOwner(),1)
	else:
		pPlayer.setFeatAccomplished(FeatTypes.FEAT_TRUST, True)



def reqTsunami(caster):

	pPlot = caster.plot()
	if pPlot.isAdjacentToWater() or pPlot.isWater() or pPlot.isRiverSide():
		return True
	return False


def spellTsunami(caster):
	iX = caster.getX()
	iY = caster.getY()
	for iiX in range(iX-2, iX+3, 1):
		for iiY in range(iY-2, iY+3, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				if pPlot.isAdjacentToWater() or pPlot.isRiverSide():
					if (iX != iiX or iY != iiY):
						for i in range(pPlot.getNumUnits()):
							pUnit = pPlot.getUnit(i)
							pUnit.doDamage(30, 75, caster, gc.getInfoTypeForString('DAMAGE_COLD'), True)
						if pPlot.getImprovementType() != -1:
							if gc.getImprovementInfo(pPlot.getImprovementType()).isPermanent() == False:
								if CyGame().getSorenRandNum(100, "Tsunami") < 25:
									pPlot.setImprovementType(-1)
						CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPRING'),pPlot.getPoint())

def spellUnyieldingOrder(caster):
	pPlot = caster.plot()
	pCity = pPlot.getPlotCity()
	pCity.setOccupationTimer(0)

	iChange = -9
	pTimer = pCity.getHurryAngerTimer()

	if  pTimer < 9:
		iChange = 0 - pTimer
	pCity.changeHurryAngerTimer(iChange)

def reqUpgradeDovielloWarrior(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.getNumCities() > pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_WORKER')):
			return False
	return True

def reqVeilOfNight(caster):
#	pPlayer = gc.getPlayer(caster.getOwner())
#	if pPlayer.isHuman() == False:
#		if pPlayer.getNumUnits() < 25:
#			return False
#		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
#		eTeam = gc.getTeam(iTeam)
#		if eTeam.getAtWarCount(True) > 0:
#			return False
	return True

def spellVeilOfNight(caster):
	iHN = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iStealth = gc.getInfoTypeForString('PROMOTION_STEALTH')
	iMark = gc.getInfoTypeForString('PROMOTION_MARKSMAN')
	iCoE = gc.getInfoTypeForString('RELIGION_COUNCIL_OF_ESUS')
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.baseCombatStr() > 0:
			pUnit.setHasPromotion(iHN, True)
			pUnit.setHasPromotion(iStealth, True)
			if pUnit.getReligion() ==-1:
				pUnit.setReligion(iCoe)
			if pUnit.getReligion() == iCoe:
				pUnit.setHasPromotion(iMark, True)




def reqVitalize(caster):
	pPlot = caster.plot()

	pPlayer = gc.getPlayer(caster.getOwner())
	if not pPlayer.isHuman():
		if pPlot.getOwner() != caster.getOwner():
			return False
	if pPlot.isWater():
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_GRASS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BURNING_SANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_BROKEN_LANDS'):
		return False
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_FIELDS_OF_PERDITION'):
		return False
	return True

def spellVitalize(caster):
	pPlot = caster.plot()
	if(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_SNOW')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'),True,True)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_TUNDRA')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_DESERT')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'),True,True)
		if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_SCRUB'):
			pPlot.setFeatureType(-1, -1)
	elif(pPlot.getTerrainType()==gc.getInfoTypeForString('TERRAIN_PLAINS')):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'),True,True)
	if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_MARSH'):
		pPlot.setTerrainType(gc.getInfoTypeForString('TERRAIN_GRASS'),True,True)

def reqWane(caster):
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ANIMAL'):
		return False
	if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_BEAST'):
		return False
	if caster.isImmortal():
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.getUnitClassCount(gc.getInfoTypeForString('UNITCLASS_SHADE')) >= 4:
		return False

	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) > 0:
			return False
		if caster.getUnitCombatType() == gc.getInfoTypeForString('UNITCOMBAT_ADEPT'):
			return False
		if caster.getUnitAIType() == gc.getInfoTypeForString('UNITAI_HERO'):
			return False
		if caster.getLevel() > 7:
			return False

	return True

def reqWarcry(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if pPlayer.getNumUnits() < 25:
			return False
		iTeam = gc.getPlayer(caster.getOwner()).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.AI_getNumAIUnits(gc.getInfoTypeForString('UNITAI_ATTACK_CITY')) < (pPlayer.getNumCities() * 3):
			return False
	return True

def spellWarcry(caster):
	iWarcry = gc.getInfoTypeForString('PROMOTION_WARCRY')
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.getUnitCombatType() != -1:
			pUnit.setHasPromotion(iWarcry, True)

def reqWhiteout(caster):
	pPlot = caster.plot()
	if caster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN')):
		return False
	if pPlot.getTerrainType() != gc.getInfoTypeForString('TERRAIN_SNOW'):
		return False
	return True

def reqWildHunt(caster):
	iPlayer = caster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	if pPlayer.isHuman() == False:
		iTeam = gc.getPlayer(iPlayer).getTeam()
		eTeam = gc.getTeam(iTeam)
		if eTeam.getAtWarCount(True) == 0:
			return False
		if pPlayer.getNumUnits() < 20:
			return False
	return True

def spellWildHunt(caster):
	iWolf = gc.getInfoTypeForString('UNIT_WOLF')
	pPlayer = gc.getPlayer(caster.getOwner())
	py = PyPlayer(caster.getOwner())
	for pUnit in py.getUnitList():
		if pUnit.baseCombatStr() > 0:
			newUnit = pPlayer.initUnit(iWolf, pUnit.getX(), pUnit.getY(), UnitAITypes.UNITAI_ATTACK, DirectionTypes.DIRECTION_SOUTH)
			pPlot = newUnit.plot()
			newUnit.setSummoner(pUnit.getID())
			if pPlot.isCity():
				pPlot.getPlotCity().applyBuildEffects(newUnit)
			if pUnit.baseCombatStr() > 3:
				i = (pUnit.baseCombatStr() - 2) / 2
				newUnit.setBaseCombatStr(2 + i)
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_LOYALTY'), True)
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_IMMUNE_COLD'), True)
				pUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WINTERBORN'), True)


def spellWonder(caster):
	iCount = CyGame().getSorenRandNum(3, "Wonder") + 3
	pPlayer = gc.getPlayer(caster.getOwner())
	pPlot = caster.plot()
	bCity = False
	point = pPlot.getPoint()
	if pPlot.isCity():
		bCity = True
	for i in range (iCount):
		iRnd = CyGame().getSorenRandNum(72, "Wonder")
		iUnit = -1
		iSpell = -1
		if iRnd == 0:
			if reqBlaze(caster):
				iSpell = gc.getInfoTypeForString('SPELL_BLAZE')
			else:
				iCount += 1
		elif iRnd == 1:
			iSpell = gc.getInfoTypeForString('SPELL_BLESS')
		elif iRnd == 2:
			iSpell = gc.getInfoTypeForString('SPELL_BLINDING_LIGHT')
		elif iRnd == 3:
			if reqBloom(caster):
				iSpell = gc.getInfoTypeForString('SPELL_BLOOM')
			else:
				iCount += 1
		elif iRnd == 4:
			iSpell = gc.getInfoTypeForString('SPELL_BLUR')
		elif iRnd == 5:
			iSpell = gc.getInfoTypeForString('SPELL_CHARM_PERSON')
		elif iRnd == 6:
			iSpell = gc.getInfoTypeForString('SPELL_CONTAGION')
		elif iRnd == 7:
			iSpell = gc.getInfoTypeForString('SPELL_COURAGE')
		elif iRnd == 8:
			if reqCrush(caster):
				iSpell = gc.getInfoTypeForString('SPELL_CRUSH')
			else:
				iCount += 1
		elif iRnd == 9:
			if reqDestroyUndead(caster):
				iSpell = gc.getInfoTypeForString('SPELL_DESTROY_UNDEAD')
			else:
				iCount += 1
		elif iRnd == 10:
			if reqDispelMagic(caster):
				iSpell = gc.getInfoTypeForString('SPELL_DISPEL_MAGIC')
			else:
				iCount += 1
		elif iRnd == 11:
			if reqEarthquake(caster):
				iSpell = gc.getInfoTypeForString('SPELL_EARTHQUAKE')
			else:
				iCount += 1
		elif iRnd == 12:
			iSpell = gc.getInfoTypeForString('SPELL_ENCHANTED_BLADE')
		elif iRnd == 13:
			CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
			CyAudioGame().Play3DSound("AS3D_SPELL_DEFILE",point.x,point.y,point.z)
			for iX in range(pPlot.getX()-1, pPlot.getX()+2, 1):
				for iY in range(pPlot.getY()-1, pPlot.getY()+2, 1):
					pLoopPlot = CyMap().plot(iX,iY)
					if pLoopPlot.isNone() == False:
						pLoopPlot.changePlotCounter(100)
		elif iRnd == 14:
			iSpell = gc.getInfoTypeForString('SPELL_ENTANGLE')
		elif iRnd == 15:
			if reqEscape(caster):
				iSpell = gc.getInfoTypeForString('SPELL_ESCAPE')
			else:
				iCount += 1
		elif iRnd == 16:
			iSpell = gc.getInfoTypeForString('SPELL_FIREBALL')
		elif iRnd == 17:
			iSpell = gc.getInfoTypeForString('SPELL_FLAMING_ARROWS')
		elif iRnd == 18:
			iSpell = gc.getInfoTypeForString('SPELL_FLOATING_EYE')
		elif iRnd == 19:
			iSpell = gc.getInfoTypeForString('SPELL_HASTE')
		elif iRnd == 20:
			iSpell = gc.getInfoTypeForString('SPELL_HASTURS_RAZOR')
		elif iRnd == 21:
			if reqHeal(caster):
				iSpell = gc.getInfoTypeForString('SPELL_HEAL')
			else:
				iCount += 1
		elif iRnd == 22:
			if reqHide(caster):
				iSpell = gc.getInfoTypeForString('SPELL_HIDE')
			else:
				iCount += 1
		elif iRnd == 23:
			iSpell = gc.getInfoTypeForString('SPELL_LOYALTY')
		elif iRnd == 24:
			iSpell = gc.getInfoTypeForString('SPELL_MAELSTROM')
		elif iRnd == 25:
			iSpell = gc.getInfoTypeForString('SPELL_MORALE')
		elif iRnd == 26:
			iSpell = gc.getInfoTypeForString('SPELL_MUTATION')
		elif iRnd == 27:
			if reqPillarofFire(caster):
				iSpell = gc.getInfoTypeForString('SPELL_PILLAR_OF_FIRE')
			else:
				iCount += 1
		elif iRnd == 28:
			iSpell = gc.getInfoTypeForString('SPELL_POISONED_BLADE')
		elif iRnd == 29:
			if reqRevelation(caster):
				iSpell = gc.getInfoTypeForString('SPELL_REVELATION')
			else:
				iCount += 1
		elif iRnd == 30:
			iSpell = gc.getInfoTypeForString('SPELL_RING_OF_FLAMES_ASHEN')
		elif iRnd == 31:
			iSpell = gc.getInfoTypeForString('SPELL_RUST')
		elif iRnd == 32:
			if reqSanctify(caster):
				iSpell = gc.getInfoTypeForString('SPELL_SANCTIFY')
			else:
				iCount += 1
		elif iRnd == 33:
			if reqScorch(caster):
				iSpell = gc.getInfoTypeForString('SPELL_SCORCH')
			else:
				iCount += 1
		elif iRnd == 34:
			iSpell = gc.getInfoTypeForString('SPELL_SHADOWWALK')
		elif iRnd == 35:
			iSpell = gc.getInfoTypeForString('SPELL_SPORES')
		elif iRnd == 36:
			if reqSpring(caster):
				iSpell = gc.getInfoTypeForString('SPELL_SPRING')
			else:
				iCount += 1
		elif iRnd == 37:
			iSpell = gc.getInfoTypeForString('SPELL_STONESKIN')
		elif iRnd == 38:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_AIR_ELEMENTAL')
		elif iRnd == 39:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_AUREALIS')
		elif iRnd == 40:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_BALOR')
		elif iRnd == 41:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_DJINN')
		elif iRnd == 42:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_EARTH_ELEMENTAL')
		elif iRnd == 44:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_FIRE_ELEMENTAL')
		elif iRnd == 45:
			iUnit = gc.getInfoTypeForString('UNIT_KRAKEN')
		elif iRnd == 46:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_MISTFORM')
		elif iRnd == 47:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_PIT_BEAST')
		elif iRnd == 48:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_SAND_LION')
		elif iRnd == 49:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_SPECTRE')
		elif iRnd == 50:
			iUnit = gc.getInfoTypeForString('UNIT_GRIFFON')
		elif iRnd == 51:
			iUnit = gc.getInfoTypeForString('UNIT_TREANT')
		elif iRnd == 52:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_WATER_ELEMENTAL')
		elif iRnd == 53:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_WRAITH')
		elif iRnd == 54:
			if reqTsunami(caster):
				iSpell = gc.getInfoTypeForString('SPELL_TSUNAMI')
			else:
				iCount += 1
		elif iRnd == 55:
			iSpell = gc.getInfoTypeForString('SPELL_VALOR')
		elif iRnd == 56:
			if reqVitalize(caster):
				iSpell = gc.getInfoTypeForString('SPELL_VITALIZE')
			else:
				iCount += 1
		elif iRnd == 57:
			iSpell = gc.getInfoTypeForString('SPELL_WITHER')
		if iRnd == 58:
			if pPlot.getBonusType(-1) == -1:
				pPlot.setBonusType(gc.getInfoTypeForString('BONUS_PENGUINS'))
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_PENGUINS", ()),'',1,'Art/Interface/Buttons/Improvements/Penguins.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if iRnd == 59:
			if pPlot.getBonusType(-1) == -1:
				pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MUSHROOMS'))
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_MUSHROOMS", ()),'',1,'Art/Interface/Buttons/Improvements/Mushrooms.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
		if iRnd == 60:
			if caster.isAlive() and not isWorldUnitClass(caster.getUnitClassType()):
				CyInterface().addMessage(caster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_BABOON", ()),'',1,'Art/Interface/Buttons/Units/Margalard.dds',ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				for iProm in range(gc.getNumPromotionInfos()):
					if caster.isHasPromotion(iProm):
						if gc.getPromotionInfo(iProm).isRace():
							caster.setHasPromotion(iProm, False)
				newUnit = pPlayer.initUnit(gc.getInfoTypeForString('UNIT_BABOON'), caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit.convert(caster)
				if pPlayer.isHuman():
					t = "TROPHY_FEAT_BABOON"
					if not CyGame().isHasTrophy(t):
						CyGame().changeTrophyValue(t, 1)
		elif iRnd == 61:
			CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_SPELL1'),point)
			CyAudioGame().Play3DSound("AS3D_SPELL_SANCTIFY",point.x,point.y,point.z)
			for iX in range(pPlot.getX()-2, pPlot.getX()+3, 1):
				for iY in range(pPlot.getY()-2, pPlot.getY()+3, 1):
					pLoopPlot = CyMap().plot(iX,iY)
					if pLoopPlot.isNone() == False:
						pLoopPlot.changePlotCounter(-100)
		elif iRnd == 62:
			iUnit = gc.getInfoTypeForString('UNIT_SPIDERKIN')
			CyInterface().addMessage(caster.getOwner(), True, gc.getEVENT_MESSAGE_TIME(), CyTranslator().getText("TXT_KEY_MESSAGE_WONDER_SPIDERKIN", ()), '', InterfaceMessageTypes.MESSAGE_TYPE_INFO, 'Art/Interface/Buttons/Units/Spiderkin.dds',ColorTypes(8), pPlot.getX(), pPlot.getY(), True, True)
		elif iRnd == 63:
			iSpell = gc.getInfoTypeForString('SPELL_SLOW')
		elif iRnd == 64:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_ICE_ELEMENTAL')
		elif iRnd == 65:
			iSpell = gc.getInfoTypeForString('SPELL_SNOWFALL')
		elif iRnd == 66:
			iSpell = gc.getInfoTypeForString('SPELL_CALL_ANIMAL')
		elif iRnd == 67:
			iSpell = gc.getInfoTypeForString('SPELL_SUMMON_CHAOS_MARAUDER')
		elif iRnd == 68:
			if reqHastursRazor(caster):
				iSpell = gc.getInfoTypeForString('SPELL_SUMMON_DJINN')
			else:
				iCount += 1
		elif iRnd == 69:

			iBestValue = 0
			pBestPlot = -1
			for i in range (CyMap().numPlots()):
				iValue = 0
				pPlot2 = CyMap().plotByIndex(i)
				if not (pPlot2.getX()== 0  and pPlot2.getY() ==0):#I do not want any portal on the plot reserved for Sluaghs
					if pPlot.isWater() == pPlot2.isWater():
						if not pPlot2.isPeak():
							if pPlot2.getNumUnits() == 0:
								iValue = CyGame().getSorenRandNum(1000, "Portal")
								if not pPlot2.isOwned():
									iValue += 100
								iDistance = CyMap().calculatePathDistance(pPlot,pPlot2)
								if iDistance == -1:
									iValue += 500
								else:
									iValue += 10 * iDistance
								if iValue > iBestValue:
									iBestValue = iValue
									pBestPlot = pPlot2
			if pBestPlot != -1:
				pPlotPortal = cf.findClearPlotImprovement(pPlot)
				caster.setXY(pPlotPortal.getX(), pPlotPortal.getY(), false, true, true)
				CyInterface().addMessage(iPlayer,True,25,CyTranslator().getText("TXT_KEY_MESSAGE_EXPLORE_LAIR_PORTAL",()),'',1,'Art/Interface/Buttons/Spells/Explore Lair.dds',ColorTypes(8),pPlotPortal.getX(),pPlotPortal.getY(),True,True)

				pPlotPortal.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PORTAL'))
				pPlotPortal.setPortalExitX(pBestPlot.getX())
				pPlotPortal.setPortalExitY(pBestPlot.getY())

				pBestPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_PORTAL'))
				pBestPlot.setPortalExitX(pPlotPortal.getX())
				pBestPlot.setPortalExitY(pPlotPortal.getY())
			else:
				iCount += 1

		elif iRnd == 70:
			iSpell = gc.getInfoTypeForString('SPELL_RAGE')
		elif iRnd == 71:
			iSpell = gc.getInfoTypeForString('SPELL_SACRIFICE_ALTAR')

		if iUnit != -1:
			newUnit = pPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit.setSummoner(caster.getID())
			newUnit.setDuration(1+pPlayer.hasTrait(gc.getInfoTypeForString('TRAIT_SUMMONER')))
		if iSpell != -1:
			caster.cast(iSpell)


def onMoveTarch(pCaster, pPlot):
	pCaster.finishMoves()
	pCaster.doDamage(5, 40, pCaster, gc.getInfoTypeForString('DAMAGE_LIGHTNING'), False)
	CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_MAELSTROM'),pPlot.getPoint())
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_AIR'))
	pPlot.setPythonActive(False)




def atRangeCitadelOfLight(pCaster,pPlot):
	if not pCaster.isImmuneToMagic():
		if pPlot.isOwned():
			pPlayer = gc.getPlayer(pCaster.getOwner())
			pPlayer2 = gc.getPlayer(pPlot.getOwner())

			iNum = pPlayer2.getNumAvailableBonuses(gc.getInfoTypeForString('BONUS_MANA_SUN'))
			if iNum > 0:
				if pPlayer.getTeam() != pPlayer2.getTeam():
					if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')) or gc.getTeam(pPlayer.getTeam()).isAtWar(pPlayer2.getTeam()):
						pCaster.doDamageNoCaster(10*iNum, 90, gc.getInfoTypeForString('DAMAGE_FIRE'), False)
						pPlot = pCaster.plot()
						CyEngine().triggerEffect(gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE'),pPlot.getPoint())
						if pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_NEW') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_FOREST_ANCIENT') or pPlot.getFeatureType() == gc.getInfoTypeForString('FEATURE_JUNGLE'):
							pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_SMOKE'))
						iRnd = CyGame().getSorenRandNum(7, "Citadel")
						if pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_PLAINS'):
							pPlot.setTempTerrainType(gc.getInfoTypeForString('TERRAIN_DESERT'), iRnd)
						elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_TUNDRA'):
							pPlot.setTempTerrainType(gc.getInfoTypeForString('TERRAIN_PLAINS'), iRnd)
						elif pPlot.getTerrainType() == gc.getInfoTypeForString('TERRAIN_SNOW'):
							pPlot.setTempTerrainType(gc.getInfoTypeForString('TERRAIN_TUNDRA'), iRnd)


						iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
						iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
						iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
						iReflection = gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')
						iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')
						iBlur = gc.getInfoTypeForString('PROMOTION_BLUR')
						iShadow = gc.getInfoTypeForString('PROMOTION_SHADOWWALK')
						iBlind = gc.getInfoTypeForString('PROMOTION_BLIND')
						iVamp = gc.getInfoTypeForString('PROMOTION_VAMPIRE')


						if pCaster.isHasPromotion(iIllusion):
							pCaster.kill(True, pCaster.getOwner())
						if pCaster.isHasPromotion(iReflection):
							pCaster.kill(True, pCaster.getOwner())
						pCaster.setIgnoreHide(True)
						if pCaster.isHasPromotion(iInvisible):
							pCaster.setHasPromotion(iInvisible, False)
						if pCaster.isHasPromotion(iHidden):
							pCaster.setHasPromotion(iHidden, False)
						if pCaster.isHasPromotion(iHiddenNationality):
							pCaster.setHasPromotion(iHiddenNationality, False)
							pUnit.setBlockading(False)
						if pCaster.isHasPromotion(iBlur):
							pCaster.setHasPromotion(iBlur, False)
						if pCaster.isHasPromotion(iShadow):
							pCaster.setHasPromotion(iShadow, False)
						if pCaster.isHasPromotion(iVamp):
							pCaster.doDamageNoCaster(iNum, 30, gc.getInfoTypeForString('DAMAGE_HOLY'), False)

def atRangeSluaghPeace(pCaster,pPlot):
	if pPlot.getBonusType(-1) == -1:
		pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_CREATION'))
	if pCaster.getRace() == gc.getInfoTypeForString('PROMOTION_UNDEAD'):
		if pPlot.getBonusType(-1) == gc.getInfoTypeForString('BONUS_MANA_CREATION'):
			pCaster.cast(gc.getInfoTypeForString('SPELL_SANCTIFY'))
			pCaster.kill(True, PlayerTypes.NO_PLAYER)
		elif pPlot.getBonusType(-1) == gc.getInfoTypeForString('BONUS_MANA_DIMENSIONAL'):
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_UNHOLY_TAINT'), True)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PROMOTION_SCOURGE'), True)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STIGMATA'), True)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_SUNDERED'), True)
			pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)




def reqWorldbreak(caster):
	if CyGame().getGlobalCounter() == 0:
		return False
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isHuman() == False:
		if CyGame().getGlobalCounter() < 50:
			return False
	return True

def spellWorldbreak(caster):
	iCounter = CyGame().getGlobalCounter()
	iFire = gc.getInfoTypeForString('DAMAGE_FIRE')
	iForest = gc.getInfoTypeForString('FEATURE_FOREST')
	iJungle = gc.getInfoTypeForString('FEATURE_JUNGLE')
	iPillar = gc.getInfoTypeForString('EFFECT_PILLAR_OF_FIRE')
	iSmoke = gc.getInfoTypeForString('IMPROVEMENT_SMOKE')
	for i in range (CyMap().numPlots()):
		pPlot = CyMap().plotByIndex(i)
		bValid = True
		if pPlot.isOwned():
			if pPlot.getOwner() == caster.getOwner():
				bValid = False
		if bValid:
			if pPlot.isCity():
				if CyGame().getSorenRandNum(100, "Worldbreak") < (iCounter / 4):
					cf.doCityFire(pPlot.getPlotCity())
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					pUnit.doDamage(iCounter, 100, caster, iFire, False)
				CyEngine().triggerEffect(iPillar,pPlot.getPoint())
			if (pPlot.getFeatureType() == iForest or pPlot.getFeatureType() == iJungle):
				if pPlot.getImprovementType() == -1:
					if CyGame().getSorenRandNum(100, "Flames Spread") < (iCounter / 4):
						pPlot.setImprovementType(iSmoke)

def atRangeGuardian(pCaster, pPlot):

	if CyGame().getWBMapScript():
		iPlayer = pCaster.getOwner()
		if iPlayer != gc.getBARBARIAN_PLAYER():
			bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
			iUnit = gc.getInfoTypeForString('UNIT_GARGOYLE')
			newUnit1 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit1.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
			newUnit1.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
			newUnit2 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit2.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
			newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
			newUnit3 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
			newUnit3.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
			newUnit3.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GUARDIAN", ()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
			pPlot.setPythonActive(False)


	elif pPlot.getNumUnits() == 0:
		if CyGame().getStartTurn() + 20 < CyGame().getGameTurn(): #fixes a problem if units spawn next to the gargoyle
			iPlayer = pCaster.getOwner()
			if iPlayer != gc.getBARBARIAN_PLAYER():
				bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
				iUnit = gc.getInfoTypeForString('UNIT_GARGOYLE')
				newUnit1 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit1.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				newUnit1.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
				newUnit2 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit2.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				newUnit2.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
				newUnit3 = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit3.setUnitAIType(gc.getInfoTypeForString('UNITAI_ANIMAL'))
				newUnit3.setHasPromotion(gc.getInfoTypeForString('PROMOTION_STRONG'), False)
				CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_GUARDIAN", ()),'',1,gc.getUnitInfo(iUnit).getButton(),ColorTypes(8),pPlot.getX(),pPlot.getY(),True,True)
				pPlot.setPythonActive(False)
				pPlot.setPlotType(PlotTypes.PLOT_HILLS, True, True)
				pPlot.setRouteType(gc.getInfoTypeForString('ROUTE_ROAD'))




def atRangeJungleAltar(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.atRangeJungleAltar(pCaster, pPlot)

def atRangeNecrototem(pCaster, pPlot):
	if cf.doFear(pCaster, pPlot, -1, False):
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_FEAR", (gc.getUnitInfo(pCaster.getUnitType()).getDescription(), )),'',1,'Art/Interface/Buttons/Improvements/Necrototem.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)


def atRangePalus(pCaster, pPlot):
	if pPlot.getNumUnits() == 0:
		if CyGame().getStartTurn() + 20 < CyGame().getGameTurn(): #fixes a problem if units spawn next to the gargoyle
			iPlayer = pCaster.getOwner()
			if iPlayer != gc.getBARBARIAN_PLAYER():
				bPlayer = gc.getPlayer(gc.getBARBARIAN_PLAYER())
				iUnit = gc.getInfoTypeForString('UNIT_IRON_GOLEM')
				newUnit = bPlayer.initUnit(iUnit, pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
				newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_MAGIC_RESISTANCE'), True)
				newUnit.setUnitAIType(gc.getInfoTypeForString('UNITAI_LAIRGUARDIAN'))
				pPlot.setPythonActive(False)


def onMoveHomestead(pCaster,pPlot):
	if pPlot.isOwned():
		p2Player = gc.getPlayer(pPlot.getOwner())
		if p2Player.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_GRIGORI'):
			if pPlot.getNumUnits() == 1:
				if pCaster.isFlying() == False:
					iChance = gc.getDefineINT('TREANT_SPAWN_CHANCE')
					if pPlot.isBeingWorked():
						pCity = pPlot.getWorkingCity()
						if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_GRIGORI_TAVERN')) > 0:
							iChance = iChance * 3
						if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_ADVENTURERS_GUILD')) > 0:
							iChance = iChance * 3
					if CyGame().getSorenRandNum(100, "Homestead Defender Chance") < iChance:
						pPlayer = gc.getPlayer(pCaster.getOwner())
						eTeam = gc.getTeam(pPlayer.getTeam())
						i2Team = p2Player.getTeam()
						if eTeam.isAtWar(i2Team):
							iRnd = CyGame().getSorenRandNum(60, "Bob")
							iUnit = -1
							if iRnd <= 10:
								iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ANIMAL_HANDLING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_RANGER')
							elif iRnd <= 20:
								iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HUNTING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_HUNTER')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_POISONS')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_ASSASSIN')
							elif iRnd <= 30:
								iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_STIRRUPS')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_HORSE_ARCHER')
							elif iRnd <= 40:
								iUnit = gc.getInfoTypeForString('UNITCLASS_SCOUT')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_HORSEBACK_RIDING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_HORSEMAN')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_TRADE')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_CHARIOT')
							elif iRnd <= 50:
								iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BRONZE_WORKING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_AXEMAN')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_IRON_WORKING')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_CHAMPION')
							elif iRnd <= 60:
								iUnit = gc.getInfoTypeForString('UNITCLASS_WARRIOR')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_ARCHERY')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_ARCHER')
								if eTeam.isHasTech(gc.getInfoTypeForString('TECH_BOWYERS')):
									iUnit = gc.getInfoTypeForString('UNITCLASS_LONGBOWMAN')
							if iUnit != -1:
								infoCiv = gc.getCivilizationInfo(pPlayer.getCivilizationType())
								iUnit = infoCiv.getCivilizationUnits(iUnit)
								if iUnit != -1:
									newUnit = pPlayer.initUnit(iUnit, pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_NORTH)
									newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WEAK'), True)
									newUnit.setDuration(4)

def onMoveAncientForest(pCaster, pPlot):
	if pPlot.isOwned():
		if pPlot.getNumUnits() == 1:
			if pCaster.isFlying() == False:
				iChance = gc.getDefineINT('TREANT_SPAWN_CHANCE')
				if pPlot.isBeingWorked():
					pCity = pPlot.getWorkingCity()
					if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_TEMPLE_OF_LEAVES')) > 0:
						iChance = iChance * 3
					if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_GROVE')) > 0:
						iChance = iChance * 3
					if pCity.getNumBuilding(gc.getInfoTypeForString('BUILDING_SONG_OF_AUTUMN')) > 0:
						iChance = iChance * 3
				if CyGame().getSorenRandNum(100, "Treant Spawn Chance") < iChance:
					pPlayer = gc.getPlayer(pCaster.getOwner())
					p2Player = gc.getPlayer(pPlot.getOwner())
					eTeam = gc.getTeam(pPlayer.getTeam())
					i2Team = p2Player.getTeam()
					if (eTeam.isAtWar(i2Team) and p2Player.getStateReligion() == gc.getInfoTypeForString('RELIGION_FELLOWSHIP_OF_LEAVES')):
						for i in range(pPlot.getNumUnits()):
							p2Unit = pPlot.getUnit(i)
							p2Plot = cf.findClearPlot(p2Unit, -1)
							if p2Plot != -1:
								p2Unit.setXY(p2Plot.getX(),p2Plot.getY(), False, True, True)
								p2Unit.finishMoves()
						if pPlot.getNumUnits() == 0:
							newUnit = p2Player.initUnit(gc.getInfoTypeForString('UNIT_TREANT'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
							newUnit.setDuration(3)
							newUnit.AI_setGroupflag(43)	# 43=GROUPFLAG_SUICIDE_SUMMON
							CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TREANT_ENEMY",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Units/Treant.dds',ColorTypes(7),newUnit.getX(),newUnit.getY(),True,True)
							CyInterface().addMessage(pPlot.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_TREANT",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Units/Treant.dds',ColorTypes(8),newUnit.getX(),newUnit.getY(),True,True)

def onMoveTormentedSouls(pCaster, pPlot):
	if pPlot.getNumUnits() == 1:
		if pCaster.isAlive() and not pCaster.isFlying():
			if CyGame().getSorenRandNum(66, "Tormented Souls") <= 18:
				pPlayer = gc.getPlayer(pCaster.getOwner())
				p2Player = gc.getPlayer(gc.getBARBARIAN_PLAYER())
				eTeam = gc.getTeam(pPlayer.getTeam())
				i2Team = p2Player.getTeam()
				if eTeam.isAtWar(i2Team):
					for i in range(pPlot.getNumUnits()):
						p2Unit = pPlot.getUnit(i)
						p2Plot = cf.findClearPlot(p2Unit, -1)
						if p2Plot != -1:
							p2Unit.setXY(p2Plot.getX(),p2Plot.getY(), False, True, True)
							p2Unit.finishMoves()
					if pPlot.getNumUnits() == 0:
						newUnit = p2Player.initUnit(gc.getInfoTypeForString('UNIT_SPECTRE'), pPlot.getX(), pPlot.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
						newUnit.setDuration(3)
						newUnit.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), True)
						newUnit.AI_setGroupflag(43)	# 43=GROUPFLAG_SUICIDE_SUMMON
						CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_SPECTRE_ENEMY",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Units/Spectre.dds',ColorTypes(7),newUnit.getX(),newUnit.getY(),True,True)



def onMoveWeb(pCaster, pPlot):
	if pPlot.getNumUnits() == 1:
		if not (pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_GIANT_SPIDER') or pCaster.getUnitType() == gc.getInfoTypeForString('UNIT_BABY_SPIDER')):
			if pCaster.isFlying():
				if not (pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PERFECT_SIGHT')) or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SINISTER')) or pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_SHADOWWALK'))):
					if CyGame().getSorenRandNum(pCaster.getLevel(), "Caught in Spider Web") < 3:
						pCaster.changeImmobileTimer(2)






def onMoveBlizzard(pCaster, pPlot):
	if not pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WINTERBORN')):
		pCaster.doDamage(10, 50, pCaster, gc.getInfoTypeForString('DAMAGE_COLD'), False)



def onMoveMaelstrom(pCaster, pPlot):
	if CyGame().getSorenRandNum(100, "Maelstrom") < 25:
		CyInterface().addMessage(pCaster.getOwner(), True, gc.getEVENT_MESSAGE_TIME(), CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_KILL",()), 'AS2D_FEATUREGROWTH', InterfaceMessageTypes.MESSAGE_TYPE_INFO, 'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7), pPlot.getX(), pPlot.getY(), True, True)
		pCaster.kill(True, PlayerTypes.NO_PLAYER)
	else:
		iOcean = gc.getInfoTypeForString('TERRAIN_OCEAN')
		iBestValue = 0
		pBestPlot = -1
		for i in range (CyMap().numPlots()):
			iValue = 0
			pTargetPlot = CyMap().plotByIndex(i)
			if pTargetPlot.getTerrainType() == iOcean:
				iValue = CyGame().getSorenRandNum(1000, "Maelstrom")
				if pTargetPlot.isOwned() == False:
					iValue += 1000
				if pTargetPlot == pPlot:
					iValue = 0
				if iValue > iBestValue:
					iBestValue = iValue
					pBestPlot = pTargetPlot
		if pBestPlot != -1:
			pCaster.setXY(pBestPlot.getX(), pBestPlot.getY(), False, True, True)
			pCaster.setDamage(25, PlayerTypes.NO_PLAYER)
			CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_MAELSTROM_MOVE",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Maelstrom.dds',ColorTypes(7),pCaster.getX(),pCaster.getY(),True,True)

def onMoveMirrorOfHeaven(pCaster, pPlot):
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_SUN'))


	iHidden = gc.getInfoTypeForString('PROMOTION_HIDDEN')
	iHiddenNationality = gc.getInfoTypeForString('PROMOTION_HIDDEN_NATIONALITY')
	iIllusion = gc.getInfoTypeForString('PROMOTION_ILLUSION')
	iReflection = gc.getInfoTypeForString('PROMOTION_DARK_REFLECTION')
	iInvisible = gc.getInfoTypeForString('PROMOTION_INVISIBLE')

	pUnit = pCaster
	if pUnit.isHasPromotion(iHidden):
		pUnit.setHasPromotion(iHidden, False)
	if pUnit.isHasPromotion(iHiddenNationality):
		pUnit.setHasPromotion(iHiddenNationality, False)
	if pUnit.isHasPromotion(iInvisible):
		pUnit.setHasPromotion(iInvisible, False)
	if pUnit.isHasPromotion(iIllusion):
		pUnit.kill(True, pCaster.getOwner())
	if pUnit.isHasPromotion(iReflection):
		pUnit.kill(True, pCaster.getOwner())
	iX = pPlot.getX()
	iY = pPlot.getY()
	iTeam = gc.getPlayer(pCaster.getOwner()).getTeam()
	for iiX in range(iX-3, iX+4, 1):
		for iiY in range(iY-3, iY+4, 1):
			pPlot2 = CyMap().plot(iiX,iiY)
			if not pPlot2.isNone():
				pPlot2.setRevealed(iTeam, True, False, iTeam)

	iTech = gc.getInfoTypeForString('TECH_HONOR')
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(pCaster.getOwner())
	iReligion = pPlayer.getStateReligion()
	if iReligion == gc.getInfoTypeForString('RELIGION_THE_EMPYREAN'):
		eTeam = gc.getTeam(pPlayer.getTeam())
		if not eTeam.isHasTech(iTech):
			eTeam.setHasTech(iTech, True, iPlayer, True, False)
			pPlayer.initUnit(gc.getInfoTypeForString('UNIT_PROPHET'), pCaster.getX(), pCaster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)

	if CyGame().getWBMapScript():
		sf.onMoveMirrorOfHeaven(pCaster, pPlot)

def onMovePoolOfTears(pCaster, pPlot):
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_CRAZED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_CRAZED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)

	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_ENRAGED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_ENRAGED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)

	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_BURNING_BLOOD'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_BURNING_BLOOD",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)

	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_DISEASED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_DISEASED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_PLAGUED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_PLAGUED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_POISONED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_POISONED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	if pCaster.isHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED')):
		pCaster.setHasPromotion(gc.getInfoTypeForString('PROMOTION_WITHERED'), False)
		CyInterface().addMessage(pCaster.getOwner(),True,25,CyTranslator().getText("TXT_KEY_MESSAGE_POOL_OF_TEARS_WITHERED",()),'AS2D_FEATUREGROWTH',1,'Art/Interface/Buttons/Improvements/Pool of Tears.dds',ColorTypes(8),pCaster.getX(),pCaster.getY(),True,True)
	pPlot.setBonusType(gc.getInfoTypeForString('BONUS_MANA_SPIRIT'))


def onMoveJungleAltar(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMoveJungleAltar(pCaster, pPlot)

def onMovePortal(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMovePortal(pCaster, pPlot)

def onMoveWarningPost(pCaster, pPlot):
	if CyGame().getWBMapScript():
		sf.onMoveWarningPost(pCaster, pPlot)



def reqManaAllowed(pCaster,sVote):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString(sVote)):
			return False
	return True


def reqMountainMine(pCaster):
	pPlot = pCaster.plot()
	if pPlot.isPeak():
		if pPlot.getImprovementType() == -1:
			if pPlot.isOwned():
				if pPlot.getOwner() == pCaster.getOwner():
					return True
	return False

def spellMountainMine(pCaster):
	pPlot = pCaster.plot()
	pPlot.setImprovementType(gc.getInfoTypeForString('IMPROVEMENT_MINE'))


def reqBloom(pCaster):
	pPlot = pCaster.plot()
	if pPlot.isCity():
		return False
	if pPlot.getFeatureType() != -1 and pPlot.getFeatureType() != gc.getInfoTypeForString('FEATURE_FOREST_BURNT'):
		return False
	if not pPlot.canHaveFeature(gc.getInfoTypeForString('FEATURE_FOREST_NEW')):
		return False
	iImp = pPlot.getImprovementType()
	if iImp != -1 and iImp != gc.getInfoTypeForString('IMPROVEMENT_SEVEN_PINES') and iImp != gc.getInfoTypeForString('IMPROVEMENT_CAMP') and iImp != gc.getInfoTypeForString('IMPROVEMENT_LUMBERMILL') and iImp != gc.getInfoTypeForString('IMPROVEMENT_YGGDRASIL'):
		if not pPlot.isOwned():
			return False
		pPlotPlayer = gc.getPlayer(pPlot.getOwner())
		if not pPlotPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_LJOSALFAR') and not pPlotPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_SVARTALFAR') and not pPlotPlayer.getCivilizationType() == gc.getInfoTypeForString('CIVILIZATION_KURIOTATES'):
			return False
	iSpell = gc.getInfoTypeForString('SPELL_BLOOM')
	for iUnit in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(iUnit)
		if pUnit.getDelayedSpell() == iSpell:
			return False
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if not pPlayer.isHuman():
		if pPlot.isOwned():
			if pPlot.getOwner() != pCaster.getOwner():
				return False
	return True

def reqBlur(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False
	pPlot = pCaster.plot()
	iBlur = gc.getInfoTypeForString('PROMOTION_BLUR')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pCaster.getOwner() == pUnit.getOwner():
			if not pUnit.isHasPromotion(iBlur):
				return True
	return False
def reqShadowwalk(pCaster):
	pPlayer = gc.getPlayer(pCaster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False
	pPlot = pCaster.plot()
	iBlur = gc.getInfoTypeForString('PROMOTION_SHADOWWALK')
	for i in range(pPlot.getNumUnits()):
		pUnit = pPlot.getUnit(i)
		if pCaster.getOwner() == pUnit.getOwner():
			if not pUnit.isHasPromotion(iBlur):
				return True
	return False

def reqSummonBeastOfAgares(pCaster):
	iSummon = gc.getInfoTypeForString('UNIT_BEAST_OF_AGARES')
	casterID = pCaster.getID()
	iPlayer = pCaster.getOwner()
	pPlayer = gc.getPlayer(iPlayer)
	py = PyPlayer(iPlayer)
	for pUnit in py.getUnitList():
		if pUnit.getUnitType() == iSummon:
			if pUnit.getSummoner() == casterID:
				return False
	return True




def reqRust(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False
	iRust = gc.getInfoTypeForString('PROMOTION_RUSTED')
	iMithril = gc.getInfoTypeForString('PROMOTION_MITHRIL_WEAPONS')
	iIron = gc.getInfoTypeForString('PROMOTION_IRON_WEAPONS')
	iBronze = gc.getInfoTypeForString('PROMOTION_BRONZE_WEAPONS')
	iMelee = gc.getInfoTypeForString('UNITCOMBAT_MELEE')
	iX = caster.getX()
	iY = caster.getY()
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.isAlive():
						if eTeam.isAtWar(pUnit.getTeam()):
							if pUnit.isHasPromotion(iMithril):
								return True
							if pUnit.isHasPromotion(iIron):
								return True
							if pUnit.isHasPromotion(iBronze):
								return True
							if not pUnit.isHasPromotion(iRust):
								if pUnit.getUnitCombatType() == iMelee:
									return True
	return False

def reqWither(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	if pPlayer.isFullMember(gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')):
		if CyGame().isVotePassed(gc.getInfoTypeForString('VOTE_NO_SHADOW_MANA')):
			return False
	iWithered = gc.getInfoTypeForString('PROMOTION_WITHERED')
	iValor = gc.getInfoTypeForString('PROMOTION_VALOR')
	iCourage = gc.getInfoTypeForString('PROMOTION_COURAGE')
	iMorale = gc.getInfoTypeForString('PROMOTION_MORALE')
	iX = caster.getX()
	iY = caster.getY()
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iTeam)
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.isAlive():
						if eTeam.isAtWar(pUnit.getTeam()):
							if not pUnit.isHasPromotion(iWithered):
								return True
							if pUnit.isHasPromotion(iValor):
								return True
							if pUnit.isHasPromotion(iCourage):
								return True
							if pUnit.isHasPromotion(iMorale):
								return True
							if pUnit.getDamage() < 91:
								return True
	return False

def reqEvangelizeUnits(pCaster,sReligion,sPromo):
	iProm = gc.getInfoTypeForString(sPromo)
	iRel = gc.getInfoTypeForString(sReligion)
	iX = pCaster.getX()
	iY = pCaster.getY()
	for iiX in range(iX-1, iX+2, 1):
		for iiY in range(iY-1, iY+2, 1):
			pPlot = CyMap().plot(iiX,iiY)
			if not pPlot.isNone():
				for i in range(pPlot.getNumUnits()):
					pUnit = pPlot.getUnit(i)
					if pUnit.isAlive():
						if not pUnit.isHasPromotion(iProm) and pUnit.getReligion() != iRel:
							return True
	return False

def voteFundDissidents():
	iOvercouncil = gc.getInfoTypeForString('DIPLOVOTE_OVERCOUNCIL')
	for iPlayer in range(gc.getMAX_PLAYERS()):
		pPlayer = gc.getPlayer(iPlayer)
		if pPlayer.isAlive():
			if pPlayer.isFullMember(iOvercouncil):
				for pyCity in PyPlayer(iPlayer).getCityList() :
					if CyGame().getSorenRandNum(100, "Fund Dissidents") < 50:
						pCity = pyCity.GetCy()
						pCity.changeHurryAngerTimer(1 + CyGame().getSorenRandNum(3, "Fund Dissidents"))

def spellGreatGeneralSplit(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iCommander = gc.getInfoTypeForString('UNIT_GREAT_GENERAL')
	newUnit = pPlayer.initUnit(iCommander, caster.getX(), caster.getY(), UnitAITypes.NO_UNITAI, DirectionTypes.DIRECTION_SOUTH)
	newUnit.setHasCasted(True)


def reqDeclareBarbs(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	eTeam = gc.getTeam(gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam())
	iTeam = pPlayer.getTeam()
	if eTeam.isAtWar(iTeam) == False:
		return True
	return False

def spellDeclareBarbs(caster):
	pPlayer = gc.getPlayer(caster.getOwner())
	iBarb = gc.getPlayer(gc.getBARBARIAN_PLAYER()).getTeam()
	iTeam = pPlayer.getTeam()
	eTeam = gc.getTeam(iBarb)
	if eTeam.isAtWar(iTeam) == False:
		if pPlayer.isHuman():
			popupInfo = CyPopupInfo()
			popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON)
			popupInfo.setText(CyTranslator().getText("TXT_KEY_POPUP_DECLARE_BARBS",()))
			popupInfo.setData1(iBarb)
			popupInfo.setData2(iTeam)
			popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_YES", ()), "")
			popupInfo.addPythonButton(CyTranslator().getText("TXT_KEY_POPUP_NO", ()), "")
			popupInfo.setOnClickedPythonCallback("applyDeclareBarbs")
			popupInfo.setPythonModule("CvSpellInterface")
			popupInfo.addPopup(caster.getOwner())
		else:
			eTeam.declareWar(iTeam, false, WarPlanTypes.WARPLAN_TOTAL)
			cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_BARBARIAN_DECLARE_WAR",()), 'art/interface/popups/Barbarian.dds')

def applyDeclareBarbs(argsList):
	iButtonId, iBarb, iTeam, iData3, iFlags, szText, bOption1, bOption2 = argsList
	if iButtonId == 0:
		CyMessageControl().sendModNetMessage(CvUtil.BarbarianWar, iBarb, iTeam, 0, 0)
#		gc.getTeam(iBarb).declareWar(iTeam, false, WarPlanTypes.WARPLAN_TOTAL)
		cf.addPopup(CyTranslator().getText("TXT_KEY_POPUP_BARBARIAN_DECLARE_WAR",()), 'art/interface/popups/Barbarian.dds')