Holy Cities

Xyth

History Rewritten
Joined
Jul 14, 2004
Messages
4,106
Location
Aotearoa
I'm still in the planning stage so I haven't put together any code yet but I wanted to check in here and see if what I want to do is possible via Python. SDK is not an option as I'm on Mac BTS.

The rough idea is that I want to remove the founding of religions from the tech tree and instead tie them to culture (or something else, still deciding). At the moment I'm thinking of there being a % chance each time a city's cultural borders expand to trigger the foundation of a religion and for that city to become it's holy city. That % might be modified by various factors but I'll worry about that later. For now these are my questions:

1) What python function(s) do I use to set a city as a holy city?
2) Will this automatically found the religion as well or should it be done in the reverse order
3) Can this be done using the Choose Religion interface?
4) How do I code the % chance bit?
5) Anything else I should be aware of?
 
You probably can do this with Python only, but a good place to start would be to learn Python itself. Because you will be using pretty much all the basic programming procedures, like assignment, importing, iteration, conditions and so on. It is also important to understand how indentation works and what it does. This is a very good place to start, and I also wrote a tutorial that puts the textbook into a modding context.

You will pretty much be able to figure the answers to the actual questions yourself once you know how to make a Python mod. The CivIV Python API is the place you need to look for functions (methods) for your mod. But someone would of course be able to point you to the exact thing you need, but it wouldn't do you much good before you know programming.

Whatever you do, don't try to "figure out" Python. Its a high-level programming language and the short-cut is actually to pick up a textbook. You'll be modding with Python in no time at all if you just take it in strides. I'd be glad to help you out with this - once you're able to understand any instructions or utilize any help given in the form of code. Otherwise it would be easier to just do the mod for you to your specifications... (Which of course is an option if you're not gonna bother with learning how to program.)

And if you already know programming you can of course just ignore everything I said. :blush:
 
I have a decent knowledge of the basics of programming and I've been pretty successful at borrowing code from other mods and adapting it to my needs (with some help from this forum). Python is starting to make sense to me but mostly I just don't know all the nuances of the Civ4 API.
 
1) What python function(s) do I use to set a city as a holy city?
2) Will this automatically found the religion as well or should it be done in the reverse order
3) Can this be done using the Choose Religion interface?
4) How do I code the % chance bit?
5) Anything else I should be aware of?

1) CyPlayer, foundReligion(ReligionNumber, SlotNumber, True)
2) Will found
3) No idea :dunno:. I guess you can trigger the interface, but no idea how.
4) Are you asking how to rnd in python?
5) That stuff will (i think) automatically turn on the choose Religion option. Additionally, if you found a religion in this way, and a civ researches the associated tech, that civ will still have the option to found a religion.
 
The big challenge for this project would probably be to keep track of the culture. Right of the bat I'd actually advice against it as it does seem like a SDK job.

But if you're gonna attempt it with Python you'd firstly need a reliable way of fetching and calculate what I suppose would be the total amount of culture for each player/team (depending on the context you're using this). You might have to go to such lengths as to loop though all cities for all players on every single turn to fetch the accumulated culture points, then sum it all up and compare to what the value was the turn before. Then you would have how much culture the players actually amassed since the last turn. But it would come at some cost as far as lag is concerned.

But, you also need to store these values somewhere so that they aren't reset once the game is resumed. This would involve using scriptData - preferably in each CyPlayer/CyTeam instance. This is where understanding Python and Object-Oriented Programming becomes helpful.

The API isn't something you can or need to memorize - or even to "figure out". If you understand OOP it is actually pretty self-explanatory. It contains classes and class methods. Each class corresponds to one aspect of the game, and each class instance has its own attributes, and so on. A good way to learn how to use the API - besides using it - is actually to read up on classes and their use.
 
I see now that I was reading the OP carelessly. There is actually a CultureExpansion call from the SDK making this rather easy to implement. :goodjob:

To answer the random change question the way to get a random integer value with CivIV Python is the CyGame.getSorenRandNum() method. Look it up in the API.

So you pretty much only have to be able to lookup what religions are already present in the game and what religions aren't. Then, any time a city pops its borders you have a if statement check some probability against a random number. Chances are that you won't even need to save any custom data, to do any pickling or any of that nonsense.
 
I think that this is pretty much what your Python mod would look like:
Code:
# constants - go at the top of the module
[B]iReligionFoundPropability = 1
iNumReligions = gc.getNumReligionInfos()
lReligions = range(iNumReligions)[/B]
# later in the same module...
	def onCultureExpansion(self, argsList):
		'City Culture Expansion'
		pCity = argsList[0]
		iPlayer = argsList[1]
[B]		iRandNum = gc.getGame().getSorenRandNum(100, "religion")
		if iRandNum < iReligionFoundPropability:
			for iReligion in lReligions:
				if not gc.isReligionFounded(iReligion):
					pPlayer = gc.getPlayer(iPlayer)
					pPlayer.foundReligion(iReligion, iReligion, True)
					gc.getGame().setHolyCity(iReligion, pCity, True)[/B]
This is how you'd go about adding the code directly into the CvEventManager.py file. I haven't tested any of it so there is no warranty included, but this is my suggestion anyway. The exact implementation is of course up to you but I think you have most of the stuff covered above.

My own addition would probably be to replace the constant value for iReligionFoundPropability with pCity.getCultureLevel() ** 2. Like this:
Code:
		iReligionFoundPropability = pCity.getCultureLevel() ** 2
		if iRandNum < iReligionFoundPropability:
This way the chance of spawning a religion increases with the amount of culture in the city. Anything would need to be properly balanced though, so chances are that this is no good. :p

Another idea would be to give each religion an individual percentile found chance. It would look something like this:
Code:
# at constants:
iNumReligions = 5
lReligionFoundPropability = [
5, #religion 0
5, #religion 1
10, #religion 2
10, #religion 3
15, #religion 4
]
# at onCultureExpansion
		if iRandNum < lReligionFoundPropability[iReligion]:
This setup of course makes the mod less dynamical as the religions would have to be pre-defined. (This example only has five, for example.) But it will give you the option to fine-tune the religion founding for a specific scenario/mod.
 
Back
Top Bottom