Sid Meier's Civilization V

Sid Meier's Civilization V

Not enough ratings
Religion Snippets [for mod makers]
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
5.404 KB
7 Jun, 2014 @ 9:49am
30 Jul, 2014 @ 3:49pm
3 Change Notes ( view )

Subscribe to download
Religion Snippets [for mod makers]

In 1 collection by Machiavelli
Machiavelli's snippets for mod makers
6 items
Description
For mod makers.

What it does
This mod contains code that defines two lua events and a new XML table:

LuaEvents.CityAdoptsReligionEvent(iOwner, iX, iY, eOldReligion, eNewReligion, bFirstConversion)
A LUA event that fires when a city adopts a religion.

LuaEvents.ReligionFoundedEvent(founderID, iX, iY, eOldReligion, eNewReligion)
A LUA event that fires when a religion is founded.

Belief_FounderFreeBuildingClassCapital: <BeliefType, BuildingClassType>
A table that will grant the building to the player's capital if they have the founder belief. If their capital moves (due to conquest) than the building automatically moves.

Each snippet depend on the snippets above it. Meaning you must use "CityAdoptsReligionEvent" for either of the other snippets to work. And you must be using "ReligionFoundedEvent" for the Belief_FounderFreeBuildingClassCapital table to work.

If an end-user is playing with multiple mods that use this snippet it will work properly.

Compatibility
This code is compatible with Gods & Kings and Brave New World.

This code is identical to what is used in "Race for Religion".

How to incorporate into your mod
CityAdoptsReligionEvent
Copy the "CityAdoptsReligionEvent" directory and all its contents to your mod. Have the SQL file update the database (via the Action tab) and set the LUA file as an "InGameUIAddin" (via the Content tab).

Make sure the XML files from this snippet that create the table update the database before any files attempt to add entries into the tables for this snippet.

ReligionFoundedEvent
Will only work if you are also using CityAdoptsReligionEvent code. Copy the "ReligionFoundedEvent" directory and all its contents to your mod. Set the LUA file as an "InGameUIAddin" (via the Content tab).

Belief_FounderFreeBuildingClassCapital
Will only work if you are also using both the CityAdoptsReligionEvent code and ReligionFoundedEvent code. Copy the "Belief_FounderFreeBuildingClassCapital" directory and all its contents to your mod. Have the SQL file update the database (via the Action tab) and set the LUA file as an "InGameUIAddin" (via the Content tab).

How to use
Add your functions to the "LuaEvents.CityAdoptsReligionEvent" event, "LuaEvents.ReligionFoundedEvent" or add entires to the Belief_FounderFreeBuildingClassCapital table.

How it works
The CityAdoptsReligionEvent is the where 90% of the work is done. The other snippets are small extensions of it. The code starts with GameEvents.CityConvertsReligion a built in event that fires when a city changes religion or its follower count changes. It does some filtering logic to determine when a city has changed religion and if so, fires off the LUA event.

Required for this filtering logic are a pair of "marker" buildings for each religion. These buildings follow the naming convention "BUILDING_RELIGION_XXX" and "BUILDING_HAS_BEEN_RELIGION_XXX". For example, for "RELIGION_ISLAM" the marker buildings are: "BUILDING_RELIGION_ISLAM" and "BUILDING_HAS_BEEN_RELIGION_ISLAM".

BUILDING_RELIGION_ISLAM
When a city's majority religion is Islam it will have this building. If the city's majority religion changes to another religion (say Bhuddhism) then this building would be removed and replaced with "BUILDING_RELIGION_BHUDDHISM".

BUILDING_HAS_BEEN_RELIGION_ISLAM
This building will be given to a city when its majority religion is Islam but unlike the "BUILDING_RELIGION_ISLAM" this one is never removed when the city changes religion. If a city has this building than you know at some point in the city's history its majority religion was Islam.

Using "BUILDING_RELIGION_XXX" and "BUILDING_HAS_BEEN_RELIGION_XXX".
First make sure what you want to do can't simply be done with Religions grant buildings.

By default these buildings have no gameplay effects and are only used by the internal logic of the CityAdoptsReligionEvent. However, you can modify these buildings with anything that can give buildings yields (such as policies, beliefs or other buildings via the "Building_BuildingClassYieldChanges" and "Building_BuildingClassHappiness" tables).

For example, Race for Religion has a follower belief called "Religious Diversity: +1 Science per Religion the city has ever followed." This effect is implemented by having the belief provide +1 Science from every "BUILDING_HAS_BEEN_RELIGION_XXX".

CivFanatics Download[forums.civfanatics.com]
10 Comments
梁稚子 24 Apr, 2018 @ 10:29pm 
Hey Machiavelli could you make mod which all countries could have a extra belief like Byzantium. Idk where the code describe that part. Thanks.
Gilga ™ |Yonaguni| 31 Jul, 2014 @ 1:17pm 
Hey Machiavelli thanks for the code i will include it into CCTP when i got time, sure with full credit :cybereye:
lshipp 11 Jun, 2014 @ 2:56pm 
I may end up using the code in the link if I finish thinking through the rest of what I need.

But it struck me that the code you are showing here could be used to create a unit(s) special to each religion, and then allow your code shown here to control which of thee units can be trained within an individual city at any given time. So if a city went from Islam to Catholicism that city would no longer be able to train the Islam unit(s) but would be able to train the Catholicism unit(s) instead.

This just happened to synergize with a project I've been thinking about for a while. So I wondered if I could use this to control and keep track of which Religion-based unit(s) can be trained within a city at any given time. But the other code methods you suggest may look to be 'cleaner' so far as units are concerned. Though I do like the idea of extra side-benefits to a city (such as 10% more GPP) based on which religion it has.
Machiavelli  [author] 11 Jun, 2014 @ 11:05am 
If your objective is to make a unit that can only be trained in cities that are majority Islam, that is not difficult and does not require this snippet.

The second part of this post [forums.civfanatics.com] has code for a building that can only be built in majority Buddhism city. There is a CityCanTrain event that you would need to use instead but the code is 95% the same.
lshipp 11 Jun, 2014 @ 10:48am 
So if I'm following all this correctly I could add updates for each of the religion buildings that would allow training of specific units in a city based on which majority religion is in the city. I would use the <Unit_BuildingClassRequireds> table rather than a direct update of the <Buildings> definition in such a case, and I would make the required building-class be the one for each appropriate Religion. If I added a line of units for Islam and a line of units for Buddhism in this way, only cities that have Islam as their majority religion would be able to build the 'Islam' line of units, and only cities that have Buddhism as thier majority religion would be able to build the 'Buddhism' units.
Machiavelli  [author] 7 Jun, 2014 @ 2:39pm 
Sure, I've edited my most recent post in your civFanatics thread to include an example for limiting building the Stupa to majority Buddhism cities.
Ulixes 7 Jun, 2014 @ 2:15pm 
Yes, exactly. But as I said to you on civfanatics, I have almost no lua skills. If I don't ask too much, do you think you could post an example of that (maybe on civfanatics or wherever you want) when you have time?
Machiavelli  [author] 7 Jun, 2014 @ 2:00pm 
If I understand your question correctly, you plan to create a new building (Stupa for example) which will only be buildable in cities that where Buddhism is the majority. If so, that should be easy (and won't require this snippet).

You can use a "CityCanBuild" check for the Stupa that returns false unless the city.GetMajorityReligion is Buddhism.
Ulixes 7 Jun, 2014 @ 1:20pm 
I have a question: Do you know how to make a building who require a specific religion (in lua of course). For example Mosque require Islam, Mandir require Hinduism, Stupa require Buddhism X building require Catholicism and so on... I didn't find anything on civfanatics or on Steam. I thought you were the right person to ask. Thank you in advance for your time.
Ulixes 7 Jun, 2014 @ 1:12pm 
Thank you again Machiavelli, this will be very useful for all modders. I wish there were more like you.