6. Guide to Python in Civ IV: Civ Function Assignment

Merely checking values is only part of modding - programmers are also able to change certain values in Civ IV (though not as many as I'd like).

There are a great many functions in a variety of classes that allow you to change things about the game, but I will only cover a few here. Later I will make a massive catalogue of the most useful classes and functions as a reference, so specifics now are less important than the general structure of things.

One of the more tricky assignments that I had to hunt down was the ability to change the religions present in a city. Using Python you can add or subtract any religion in a city, as well as set each religion's influence in said city.

The function in the City class to set a city's religion info is ".setHasReligion(int Religion ID, int Religion Influence, bool Announce)"

This means that the setHasReligion() function accepts 3 arguments, two integers and a boolean. Religion ID 0 is Judaism, so any time you're dealing with a TYPE of religion of "0" that means you're working with Judaism. I will use it for my following example. A religion's influence is how strong a religion is in this city - an influence of 0 means it's not present. The third argument determines whether or not the game announces to the player that the city has converted to this religion (if you go from 0 influence to any other positive integer), and it used in the normal game to announce when a religion spreads to a new city. Setting it to 1 or 0 makes no difference when removing a religion from a city.

This following example can be easily done in the CIV Python console. To enter it, press Ctrl-Shift-C. To make this work, you need to found your first city:

GC = CyGlobalContext()
Player = GC.getPlayer(0)
City = Player.getCity(0)

Entering this in line-by-line will make your first/capital city Jewish with an influence of 10, and additionally a message will pop up on the screen.

This next part will remove Judaism from your capital, by making its influence in this city 0:


That concludes this section. I'll take things a bit farther in the next section.


1. Guide to Python in Civ IV: Introduction
2. Guide to Python in Civ IV: Basic Python
3. Guide to Python in Civ IV: Classes in Python
4. Guide to Python in Civ IV: Python in Civ IV
5. Guide to Python in Civ IV: Iteration (Looping)
6. Guide to Python in Civ IV: Civ IV Function Assignment
7. Guide to Python in Civ IV: Creating a Unit in Civ IV
8. Guide to Python in Civ IV: Class Reference (by Locutus)
9. Further Class Reference (by Solver)

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License