# Surt Events Handler
from CvPythonExtensions import *
import sys
import Popup as PyPopup
from PyHelpers import PyPlayer
import pickle
import CvEventManager
from CvScreenEnums import *
from PyHelpers import *
import CvUtil
# globals
gc = CyGlobalContext()
localText = CyTranslator()
class CvSurtEvents(CvEventManager.CvEventManager):
def __init__(self):
CvEventManager.CvEventManager.__init__(self)
print "created surt event manager"
###########################################################################################
##################################### EVENT OVERRIDES #####################################
###########################################################################################
def onReligionFounded(self, argsList):
iReligion, iFounder = argsList
print "religion founded",iReligion,iFounder,argsList
CvEventManager.CvEventManager.onReligionFounded(self, argsList)
relJudaism = gc.getInfoTypeForString("RELIGION_JUDAISM")
relChristianity = gc.getInfoTypeForString("RELIGION_CHRISTIANITY")
relIslam = gc.getInfoTypeForString("RELIGION_ISLAM")
relHinduism = gc.getInfoTypeForString("RELIGION_HINDUISM")
relBuddhism = gc.getInfoTypeForString("RELIGION_BUDDHISM")
relConfucianism = gc.getInfoTypeForString("RELIGION_CONFUCIANISM")
relTaoism = gc.getInfoTypeForString("RELIGION_TAOISM")
religions = (relJudaism,relChristianity,relIslam,relHinduism,relBuddhism,relConfucianism,relTaoism)
print "religions",religions
techJudaism = gc.getInfoTypeForString("TECH_JUDAISM")
techChristianity = gc.getInfoTypeForString("TECH_CHRISTIANITY")
techIslam = gc.getInfoTypeForString("TECH_ISLAM")
techHinduism = gc.getInfoTypeForString("TECH_HINDUISM")
techBuddhism = gc.getInfoTypeForString("TECH_BUDDHISM")
techConfucianism = gc.getInfoTypeForString("TECH_CONFUCIANISM")
techTaoism = gc.getInfoTypeForString("TECH_TAOISM")
reltechs = (techJudaism,techChristianity,techIslam,techHinduism,techBuddhism,techConfucianism,techTaoism)
print "religion techs",reltechs
grantWheel = gc.getInfoTypeForString("TECH_THE_WHEEL")
grantFishing = gc.getInfoTypeForString("TECH_FISHING")
grantMysticism = gc.getInfoTypeForString("TECH_MYSTICISM")
grantPottery = gc.getInfoTypeForString("TECH_POTTERY")
grantPolytheism = gc.getInfoTypeForString("TECH_POLYTHEISM")
grantMasonry = gc.getInfoTypeForString("TECH_MASONRY")
grantMeditation = gc.getInfoTypeForString("TECH_MEDITATION")
grantPriesthood = gc.getInfoTypeForString("TECH_PRIESTHOOD")
grantMonotheism = gc.getInfoTypeForString("TECH_MONOTHEISM")
grantWriting = gc.getInfoTypeForString("TECH_WRITING")
grantReligion = gc.getInfoTypeForString("TECH_RELIGION")
grantTechs = (grantWheel,grantFishing,grantMysticism,grantPottery,grantPolytheism,grantMasonry,
grantMeditation,grantPriesthood,grantMonotheism,grantWriting,grantReligion)
print "grant techs",grantTechs
players = gc.getGame().countCivPlayersEverAlive()
targetRel = religions[iReligion]
targetTech = reltechs[iReligion]
print "targetRel",targetRel,"targetTech",targetTech
numRemainingReligionsDivisor = 2
for religion in religions:
if gc.getGame().isReligionFounded(religion):
numRemainingReligionsDivisor += 1
for playerIndex in range(players):
#don't have to do anything for founding player
if playerIndex == iFounder:
continue
wastedResearch = 0
player = gc.getPlayer(playerIndex)
if player.isAlive() == True and player.isBarbarian() == False:
teamNum = player.getTeam()
print "religion founding processing living player",playerIndex,"on team",teamNum
team = gc.getTeam(teamNum)
for grantTech in grantTechs:
if team.isHasTech(grantTech) == True:
continue
wastedResearch += team.getResearchProgress(grantTech)
team.setHasTech(grantTech,true,-1,False,False)
print "grant tech",grantTech,"to team",teamNum
wastedResearch += int(team.getResearchProgress(targetTech)/(7+numRemainingReligionsDivisor))
team.setHasTech(targetTech,true,-1,False,False)
print "wasted research on auto-grant techs for player",playerIndex,"had value",wastedResearch
#whenever one religion gets researched, the rest get easier for others
for tech in reltechs:
if tech == targetTech:
continue
if team.isHasTech(tech) == True:
continue
resPro = team.getResearchProgress(tech)
resMax = team.getResearchCost(tech)
resAdd = int(wastedResearch/numRemainingReligionsDivisor) + int(resMax/7)
print "boosting research for player",playerIndex,"tech",tech,"resadd",resAdd,"respro",resPro,"resmax",resMax
if resPro < resMax:
resPro += resAdd
if resPro > resMax:
resAdd = resMax - resPro
resPro = resMax
if resAdd < 0:
resAdd = 0
#this method adds (not replaces) the second argument to the research progress
team.changeResearchProgress(tech, resAdd, -1)
resPro = team.getResearchProgress(tech)
print "religion founded: changeResearchProgressTo", tech, resPro, teamNum