Need Python Help: Gods of Old Holy City code

Ekmek

on steam: ekmek_e
Joined
Aug 7, 2002
Messages
6,115
Location
San Diego, California
I know there are a lot of religion mods out there, but I just want a real basic mod where a great prophet founds a religion instead of tech. The old warlords true prophets mod was close but had too much other stuff like pagan temples etc. I just want prophets not techs.

so I added founding buildings etc from based on the old warlords mod True Prophets and saw it had warlords python to make holy city. I updated that with the code from gods of old. I know this part of the code works because I put all of gods of old python into my mod and added my changed building names and it worked.

Now I'm a python noob so I made the mistake thinking if i just replace this working part with a truncated python file from the true prophets warlords mod it would work. but it doesn't


So my first question is:
What does my python file need to look like? I think it CVEvents. Do I just copy the standard one from bts and stick this in there?

Do I need anything else?

my next harder question is how to get the leader's preferred religion be the one they choose and not the first option available.
My other question


Spoiler :

I identified this code:

Code:
if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_JEWISH_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_JUDAISM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_CHRISTIAN_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_CHRISTANITY")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_ISLAMIC_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_ISLAM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_HINDU_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_HINDUISM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_TOAISM_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_TAOISM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_BUDDHIST_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_BUDDHISM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)
		if iBuildingType == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), "BUILDING_TP2_CONFUCIAN_FOUNDING"):
			iReligion = CvUtil.findInfoTypeNum(gc.getReligionInfo, gc.getNumReligionInfos(), "RELIGION_CONFUCIANISM")
			gc.getGame( ).setHolyCity(iReligion, pCity, 1)



thanks for the help!
 
ok, I tried another approach. I took utils and events manager from the original game and added the holycity cod I posted above as well as anything new in godsof old that involved the holycity (except the inquisitor parts)

but when i start a game the interface is gone which I believe is a python problem. what causes this?


attached are my python files.
 
To answer the second question you maybe could try something like:
in gameutils cannotconstruct
Code:
pPlayer = gc.getPlayer(pCity.getOwner())
iCiv = pPlayer.getCivilizationType()
iLeader = pPlayer.getLeaderType(iCiv)
iReligion = gc.getLeaderHeadInfo(iLeader).getFavoriteReligion()
if pPlayer.isHuman() == False:
    if (something to return the prereqreligion of the shrine, to do for each shrine) != iReligion:
         return true
elif

    return false
this probably won't work as is as I'm totally stupid with code myself but maybe you get inspired:crazyeye:
 
but when i start a game the interface is gone which I believe is a python problem. what causes this?

This is a sure sign that there is a Python problem. When Civ4 encounters illegal Python code or other coding errors, it stops running the code. This usually ends up with all or parts of the interface failing to draw.

To see the problem, open the file "PythonErr.log" in your "My Games\Beyond the Sword\Logs" directory. If it's not there (not the 2.log file), you have to turn on python logging in CivilizationIV.ini.

If you can't figure out what's wrong from the error, post the relavent bits from the log file.
 
for reference this is what my error log says (is it always this big?) it looks like the city call failed?

Spoiler :
Traceback (most recent call last):
File "<string>", line 1, in ?
File "<string>", line 52, in load_module
File "CvEventInterface", line 13, in ?
File "<string>", line 52, in load_module
File "CvEventManager", line 12, in ?
File "<string>", line 52, in load_module
File "CvScreensInterface", line 19, in ?
File "<string>", line 52, in load_module
File "CvDanQuayle", line 8, in ?
File "<string>", line 35, in load_module
File "<string>", line 13, in _get_code
File "
CvGameUtils
", line
187


city = gc.getPlayer( pCity.getOwner() ).getCity( pCity.getID( ) )

^
SyntaxError
:
invalid syntax

Failed to load python module CvEventInterface.
ERR: Call function onEvent failed. Can't find module CvEventInterface
ERR: Call function onEvent failed. Can't find module CvEventInterface
....

and a lot of lines
 
Once it found the syntax error, it borked the Python interpreter in Civ4, so it keeps spitting out errors every time it calls that module. The line in the error looks fine, so can you post the file or at least some context around that line?
 
Python differs from a lot of other languages in that whitespace is important. Line 187 is indented with four tabs, but it should match the preceding line's two tabs. I'm surprised it didn't say indentation error instead of syntax error, but try fixing that and see what happens.
 
EmperorFool or anyone else I tried the code in BOLD but it seems that it was not called (the python loaded withut error though)

Code:
	def cannotConstruct(self,argsList):
		pCity = argsList[0]
		eBuilding = argsList[1]
		bContinue = argsList[2]
		bTestVisible = argsList[3]
		bIgnoreCost = argsList[4]
# TrueProphetsII		
		city = gc.getPlayer( pCity.getOwner() ).getCity( pCity.getID( ) )
		
# TrueProphetsII
		lShrines = ["BUILDING_TP2_BUDDHIST_FOUNDING", "BUILDING_TP2_JEWISH_FOUNDING", "BUILDING_TP2_CHRISTIAN_FOUNDING", "BUILDING_TP2_ISLAMIC_FOUNDING", "BUILDING_TP2_HINDU_FOUNDING", "BUILDING_TP2_TAOIST_FOUNDING", "BUILDING_TP2_CONFUCIAN_FOUNDING" ]
		
		for i in range( len( lShrines ) ):
			if eBuilding == CvUtil.findInfoTypeNum(gc.getBuildingInfo, gc.getNumBuildingInfos(), lShrines[i] ):
				if city.isHolyCity():
					return True
[B]# TrueProphetsII - TEST - didnt work
		pPlayer = gc.getPlayer(pCity.getOwner())
		iCiv = pPlayer.getCivilizationType()
		iLeader = pPlayer.getLeaderType(iCiv)
		iReligion = gc.getLeaderHeadInfo(iLeader).getFavoriteReligion()
		if pPlayer.isHuman() == False:
			if pBldgInfo.getReligionType() != iReligion:
				return True
			else:
				return False[/B]
# TrueProphetsII
		return False
 
Your code uses "pBldgInfo", but I don't see it being set in the function. This should result in a python exception. Check the PythonErr.log to see if there's an exception in it.
 
if gc.getNumBuildingInfos(eBuilding).getReligionType() != iReligion:

Well, that's not legal Python either (getNumBuildingInfos returns an integer which has no getReligionType function), so it must mean that your code is being bypassed entirely.

I suspect the code immediately above it is always finding a building and thus returning True out of the function.
 
I moved and still didn't get an error...hmmm

Also how do I add a global variable? I want to have an integer that counts the total religions founded. I put TotalReligionsFound = 0 after:

Code:
gc = CyGlobalContext()
localText = CyTranslator()
PyPlayer = PyHelpers.PyPlayer
PyInfo = PyHelpers.PyInfo
#TrueProphetsII - start
TotalReligionsFound = 0
#TrueProphetsII - end

and before #globals


I tied to have it add 1 each time a religion is founded:
Code:
	def onReligionFounded(self, argsList):
		'Religion Founded'
		iReligion, iFounder = argsList
		player = PyPlayer(iFounder)
		
		iCityId = gc.getGame().getHolyCity(iReligion).getID()
		if (gc.getGame().isFinalInitialized() and not gc.getGame().GetWorldBuilderMode()):
			if ((not gc.getGame().isNetworkMultiPlayer()) and (iFounder == gc.getGame().getActivePlayer())):
				popupInfo = CyPopupInfo()
				popupInfo.setButtonPopupType(ButtonPopupTypes.BUTTONPOPUP_PYTHON_SCREEN)
				popupInfo.setData1(iReligion)
				popupInfo.setData2(iCityId)
				popupInfo.setData3(1)
				popupInfo.setText(u"showWonderMovie")
				popupInfo.addPopup(iFounder)
#TrueProphetsII start

				TotalReligionsFound += 1

#trueProphetsII end
		
		if (not self.__LOG_RELIGION):
			return
		CvUtil.pyPrint('Player %d Civilization %s has founded %s'
			%(iFounder, player.getCivilizationName(), gc.getReligionInfo(iReligion).getDescription()))


but I got this error:
Code:
Traceback (most recent call last):

  File "CvEventInterface", line 23, in onEvent

  File "CvEventManager", line 189, in handleEvent

  File "CvEventManager", line 733, in onReligionFounded

UnboundLocalError: local variable 'TotalReligionsFound' referenced before assignment
ERR: Python function onEvent failed, module CvEventInterface


Lastly I looked in the GoldsOfOld python's inquisitor code. How do you add a new button for a unit. I want to add a found religion button that will found the leader's preferred religion if its the AI or give the religionchooser pop-up if its human. I think its better than forcing a building. I found some code in zebra's Religion Limiter that does the pop-up but I cant tell if the unit button goes in one or more place.

thx
 
When you want to modify the value of TotalReligionsFound in a function, you must tell Python that it is a global variable using the statement

PHP:
global TotalReligionsFound

before the first use of the variable in the function.
 
Hey, I'll look into this more in depth when I have more time...

For now I can point you to the MainInterface python file in the screens folder to add a button to the unit. You need to attach it to a widget though, which can be annoying.
 
I found thos code in Zebra's zReligions

Spoiler :
Code:
	def doHolyCityTech(self,argsList):
		eTeam = argsList[0]
		ePlayer = argsList[1]
		eTech = argsList[2]
		bFirst = argsList[3]

		pPlayer = gc.getPlayer(ePlayer)
		pTeam = gc.getTeam(eTeam)

		for i in range(gc.getNumReligionInfos()):
			if gc.getReligionInfo(i).getTechPrereq() == eTech and (not religionInfo.disabledTechs.has_key(gc.getReligionInfo(i).getType()) or not religionInfo.disabledTechs[gc.getReligionInfo(i).getType()]):
				iBestValue = 100000
				eBestPlayer = -1

				for j in range(gc.getMAX_PLAYERS()):
					if gc.getPlayer(j).isAlive():
						if gc.getPlayer(j).getTeam() == eTeam:
							iValue = 10

							iValue += CyGame().getSorenRandNum(10, "Found Religion (Player)")

							for k in range(gc.getNumReligionInfos()):
								iValue += gc.getPlayer(j).getHasReligionCount(k) * 10

							if gc.getPlayer(j).getCurrentResearch() != eTech:
								iValue *= 10

							if iValue < iBestValue:
								iBestValue = iValue
								eBestPlayer = j

				if eBestPlayer > -1:
					if CyGame().isOption(GameOptionTypes.GAMEOPTION_PICK_RELIGION):
						if gc.getPlayer(eBestPlayer).isHuman():
							self.doPickReligionPopup(eBestPlayer, i)
						else:
							eReligion = self.AI_chooseReligion(eBestPlayer, i)
							if eReligion > -1:
								gc.getPlayer(eBestPlayer).foundReligion(eReligion, i, True)
					else:
						gc.getPlayer(eBestPlayer).foundReligion(i, i, True)
		return True


my question is, is this how the religion chooser is called because the default python code for thos function is just the header and tru/false.. the second questionis how do i make the pop-up part be called by a buttin for the great prophet and make the AI use it?
 
Back
Top Bottom