View Full Version : SettlerReligion Mod


Bhruic
Dec 04, 2005, 02:53 AM
SettlerReligion causes all Settlers created to have a religion based on the religions present in their creating city. The religion is chosen randomly from among the religions present in that city. For example, if a city has Hinduism and Christianity, a settler created in the city has a 50/50 chance of being Hindu or Christian. If there is a state religion, and an empire is operating under the Theocracy Civic, a Settler can only have the state religion. If the city does not have the state religion (even if it has other religions), the Settler will have no religion.

Once the Settler forms a city, that city will automatically get the religion of the Settler. So from the above example, if the Settler was Hindu, once it formed a city, that city would automatically gain Hinduism.

Settlers gained from goody huts, or created in cities with no religions will not have religions, and neither will the cities they create. Also, if this mod is used in a game in progress, any current Settlers will have no religions. Only Settlers created with this mod running will gain religions.

At present, there is no visual display of the religion of the Settler. Until the city is created you won't know what religion it has.

Installation:
SettlerReligion should NOT be installed in your main Civ IV location, as it will overwrite necessary files. Instead, it should be installed at: "My Documents\My Games\Civilization 4".

History:
v0.2
- restricted Settlers to state religion under Theocracy

v0.1
- first release

Bh

mamimo
Dec 04, 2005, 03:12 AM
Good Idea !

Bhruic
Dec 04, 2005, 03:23 AM
Updated to v0.2

- restricted Settlers to state religion under Theocracy

Bh

hIdDeN_eViL
Dec 04, 2005, 09:53 AM
quite a nice idea! have you game tested for balance etc?

niffweed17
Dec 04, 2005, 07:56 PM
that's precisely what i was going to say, this mod seems to kinda take away the religion spreading aspect, now doesn't it...

Aussie_Lurker
Dec 04, 2005, 08:06 PM
Actually, Bhruic, have you considered making all settlers (or at least a majority) of settlers under theocracy be of the NON-state religion, to simulate the kind of persecution that forces religious minorities to strike out and form their own colonies? Just a thought. Otherwise, looks kinda cool :)!

Yours,
Aussie_Lurker.

sinaarrgghh
Dec 05, 2005, 02:42 AM
This is a very good idea but if you could add the touch below (not all settlers though, just a few) that would really make it superb. Imagine how annoying that would be! :)

Actually, Bhruic, have you considered making all settlers (or at least a majority) of settlers under theocracy be of the NON-state religion, to simulate the kind of persecution that forces religious minorities to strike out and form their own colonies? Just a thought. Otherwise, looks kinda cool :)!

Yours,
Aussie_Lurker.

Bhruic
Dec 05, 2005, 04:29 AM
I really don't think that's a good idea. Gameplay should work in the way the end user expects - if you've selected a civic that says "No non-state religion spread", having settlers spread a non-state religion would be counter-intuitive.

Bh

Thalassicus
Dec 21, 2005, 09:11 PM
Could you make a version that has just a 25% chance to "catch" a religion? 100% is rather high if you found an early religion: you'll never have to spread it in your own empire.

RED DIAMOND
Jan 02, 2006, 03:55 AM
Could you make a version that has just a 25% chance to "catch" a religion? 100% is rather high if you found an early religion: you'll never have to spread it in your own empire.

Err, um I think that's the whole idea. :crazyeye:

AngryPants
Jan 02, 2006, 04:15 AM
Warning: Off Topic
Thalassicus, i hate to get all rorschach inkblot test here, but is your avatar a Christian fish humping a dinosaur skeleton? If so, what is the significance of such?

Thalassicus
Jan 02, 2006, 04:47 AM
Lol no, it's just a fish playing the guitar! :crazyeye:

I like classic guitar and piano, hence the subtitle "the musical fish". I picked up the avatar and nick when a freshman in high school...course, that was ten years ago... :lol:

jollyroger3
Jan 02, 2006, 06:14 AM
I'll try out your mod, Bhruic, as soon as possible - it sounds VERY nice, and I'm sure it's worth trying :D

lordroy
Jan 02, 2006, 07:48 AM
Im gonna try this out as well...

It seems to me that, if a city makes a settler, the people who make up the settler(that will make the new city) will be of that religion, thus they would automatically spread that religion to the new city.

The spread of religion thru monastery/culture/missionaries would then just to spread to newly captured cities.

Personally, I have always thought this is the way it should have been from the get.


-=R=-

Grave
Jan 06, 2006, 10:15 AM
Is this compatable with 1.52?

I'm having problems making it work.

RobO
Jan 21, 2006, 11:22 AM
I changed it so that when you are not in Theocracy, there's a chance that a settler will not have a religion. For example, if a city has christianity and hinduism, there wil be 1/3 chance for each of these and 1/3 chance for no religion.
There is a risk that I interpreted the code wrongly and that the actual probabilities wil be different. I don't think so, however.
The changed code (in SetterReligion.py) is shown here and is also enclosed:
else:
dice = gc.getGame().getMapRand()
# Change by RobO: Allow a chance for the settler to not have a religion
# Each religion in the city and "no religion" has the same probability
iRandReligion = dice.get(len(listReligions)+1, "Religion Selection - AlterReligion PYTHON")
if(iRandReligion < len(listReligions)+1):
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())
else:
unit.setScriptData("NO_RELIGION")
# Original code:
# iRandReligion = dice.get(len(listReligions), "Religion Selection - AlterReligion PYTHON")
# iSelectedReligion = listReligions[iRandReligion]
# unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())

mayonaise
Jan 25, 2006, 09:28 PM
is this compatible with 1.52?

Saarlaender
Jan 27, 2006, 05:35 AM
I get an exception call with RobO's modofication to the mod:
in onUnitBuilt,
Index error: list index out of range,
and that's in:
iSelectedReligion = listReligions[iRandReligion]

now, I'm a newbie, can't tell why...

RobO
Jan 27, 2006, 10:42 AM
I get an exception call with RobO's modofication to the mod:
in onUnitBuilt,
Index error: list index out of range,
and that's in:
iSelectedReligion = listReligions[iRandReligion]

now, I'm a newbie, can't tell why...
Try the original code. It ought to crash as well. If it does, then you'e encountered a situation that isn't covered by eny of the versions, and it would be interesting to know what triggers it. It seems to be happening when you build a settler.
Then try the enclosed version and tell me if it works for that savegame.
I'm really guessing here - the documentation of the API is limited.

grazwell
Jan 27, 2006, 07:59 PM
RobO, thanks for the change (and of course for the original idea, Bhruic) it's just what I was looking for.

Please help me though....How can I use it with Alerum's Unaltered gameplay mod?

RobO
Jan 28, 2006, 01:56 AM
RobO, thanks for the change (and of course for the original idea, Bhruic) it's just what I was looking for.

Please help me though....How can I use it with Alerum's Unaltered gameplay mod?
That's not difficult, but you need to use a text editor, like Notepad. I use Editpad lite (it's free). You need to merge the CustomEventManager used in the two mods.

Step 1: Copy SettlerReligion.py to the Python directory in Alerum's mod.

Step 2: Open CvCustomEventManager.py from the Python directory in Alerum's mod and from the SettlerReligion mod in separate tabs or windows.

Step 3: Copy the following lines from the top of the SettlerReligion CustomEventManager to Alerum's:
import SettlerReligion
sr = SettlerReligion.SettlerReligion()

Step 4: Copy the three events onUnitBuilt, onUnitLost, onCityBuilt from the bottom of the SettlerReligion CustomEventManager to the bottom of Alerum's.

Step 5: Save the modified CvCustomEventManager.py from Alerum's mod.

That's it. You do not need to change Python\entrypoints\CvEventInterface.py - the same file is included in both mods.

I've included my own CvCustomEventManager.py so you can see how I do it. Don't use it with your mods - my mod selection is not identical to Alerum's and it may not be compatible with your mod selection.

grazwell
Feb 01, 2006, 09:15 AM
Thanks, I think I forgot about the 'import SettlerReligion' bit when I tried it myself. A bit silly really.

SonOfMars
Feb 07, 2006, 05:17 AM
Hi RobO, and everyone else too. I like the whole ioea and your improvement too. However you might like this small cvhange to your code

if(iRandReligion > len(listReligions)):
unit.setScriptData("NO_RELIGION")
else:
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())

SonOfMars
Feb 07, 2006, 05:21 AM
Sorry was trying to format the text and sent instead, this would prevent making the original test which got you too this piece of code and also any value outside of the range would mean no religion. Grat work all the same.

lordroy
Feb 07, 2006, 07:05 AM
if you want to post code, use the /code tags

-=R=-

[to_xp]Gekko
Feb 07, 2006, 08:10 AM
Hi SonofMars, what would change with the code you posted?

SonOfMars
Feb 07, 2006, 09:41 AM
First sorry for posting code directly into the forum I'll need to find out how to do that correctly.

The explanation for the change is as follows.

The function (onUnitBuilt) which sets the religion works as follows in laymans speak.

1) - Check this unit is a Settler if not leave the function.

2) - Establish the city it was created in has religion/s and create a list (array).

3) - If there are no elements in the list/array set the Settler to "NO_RELIGION" and leave the function.

4) - To get here there are religions and here the process finds out if there is a state religion.

For ease and to get to my code suggestion quickly, there is no state religion.

5) - The process rolls a dice with the number of religions plus 1. e.g. If the number of religions is 3 the roll dice has four choices either 0 to 3 or 1 to 4

Once the number has been assigned my suggestion merely says if this number is greater than the number elements in the religions list/array then the settler has "NO_RELIGION" and there is no chance of the selection being out of range.

This is not meant as a knock to the code written just stops retesting what has already been tested and deals with the out of range error.

[to_xp]Gekko
Feb 07, 2006, 09:53 AM
so basically this does exactly the same as the tweak RobO made, but this has no chances to cause issues?
has it been already tested btw? I was about to add RobO's tweak to my mod...

lordroy
Feb 07, 2006, 10:52 AM
First sorry for posting code directly into the forum I'll need to find out how to do that correctly.



I told you...

use the "code" & "/code" around your code (with the [] instead of "")

so it would look something like:


if(iRandReligion > len(listReligions)):
unit.setScriptData("NO_RELIGION")
else:
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())



-=R=-

RobO
Feb 07, 2006, 11:31 AM
Hi RobO, and everyone else too. I like the whole ioea and your improvement too. However you might like this small cvhange to your code

if(iRandReligion > len(listReligions)):
unit.setScriptData("NO_RELIGION")
else:
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())
I don't see why your code shoule be safer than mine:
if(iRandReligion < len(listReligions)+1):
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gcgetReligionInfo(iSelectedReli gion).getType())
else:
unit.setScriptData("NO_RELIGION")
In order to make it safe, I really need to know what dice.get(n, "text") returns. Is it a value in the range 0 to n-1 or is it a value from 1 to n?

Does anyone know this, or know how to check it?

lordroy
Feb 07, 2006, 01:22 PM
I don't see why your code shoule be safer than mine:
if(iRandReligion < len(listReligions)+1):
iSelectedReligion = listReligions[iRandReligion]
unit.setScriptData(gcgetReligionInfo(iSelectedReli gion).getType())
else:
unit.setScriptData("NO_RELIGION") In order to make it safe, I really need to know what dice.get(n, "text") returns. Is it a value in the range 0 to n-1 or is it a value from 1 to n?

Does anyone know this, or know how to check it?


Im not sure how to check that, but it looks like both thoes codes do exactly the same thing.

However, having the "No Religion" fire first bypasses the rest of the code all together, which, is supposedly faster... maybe less prone to errors.

I dont know if either would be more stable than the other tho.


-=R=-

RogerBacon
Feb 07, 2006, 01:39 PM
Does anyone know this, or know how to check it?

The range is 0 to n-1 at least it is for gc.getGame().getMapRand().get(...)

I've never used Dice.get(). Actually, it seems like there are at least three methods for getting random number in the Civ API. Strange.

Roger Bacon

[to_xp]Gekko
Feb 07, 2006, 01:42 PM
my guess with the dice function would be that it goes from 1 to n.
that's how a dice works after all. I've never seen a dice rolling up with a zero. one is the smallest number available on a dice.

SonOfMars
Feb 07, 2006, 02:45 PM
Hi RobO, and everyone else too,

As soon as I posted the explanation I realised the problem was not knowing the lower limit of the list and I have looked thru the python documation and can't find any easy solution for that. However it seems that the default base is 0.

So this may be a better solution

After you make this declaration


listReligions = []


Make this assignment


listReligions = ["NO_RELIGION"]


Then you append any other religions to the list as is.

The test for "NO_RELIGION" would be


if (len(listReligions) == 1):


The random code would be as follows because "NO_RELIGION" is an element of the list


iRandReligion = dice.get(len(listReligions), "Religion Selection - AlterReligion PYTHON")


Finally there would be no need for an if statement


iSelectedReligion = listReligions[iRandReligion - 1]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())


None of this is tested and I have only being using Python for the last few hours. Just love coding.

Anyway what do you think. This should drop the error.

RobO
Feb 07, 2006, 03:06 PM
I haven't got time to test this now. However, there is at least one unanswered question more:
If you use the assignment listReligions = ["NO_RELIGION"] then the first element on listReligions will be just that. Which may be a good idea, but it does not necessarily remove the need for an if statement, as the remaining elements of listReligions will have a different nature. But is this first element referenced as listReligions[0] or as listReligions[1]?

I clearly need to check a basic python manual.

SonOfMars
Feb 07, 2006, 04:28 PM
Hi RobO

Done some small tests and "list" starts at zero(0). You need to need to use "range" to start at 1 or some other point, incidently range defaults to zero(0). So with the assignment listReligions = ["NO_RELIGION"] if your next line were print listReligions(0) you would see NO_RELIGION in the results screen. The len() function gets the number of elements so obviously if this is greater than 1 the city has religions. This value len(listReligions) is used by the dice so the value returned needs to have 1 subtracted to get the correct index in the list. And since the list contains all the religions plus no religion there can be no "out of range error" therefore you can use this value directly, in fact it might be possible to drop another line instead of


iSelectedReligion = listReligions[iRandReligion - 1]
unit.setScriptData(gc.getReligionInfo(iSelectedRel igion).getType())


You could use

unit.setScriptData(gc.getReligionInfo(listReligion s[iRandReligion - 1]).getType())


Actually I am sure the square brackets are wrong it should be


unit.setScriptData(gc.getReligionInfo(listReligion s(iRandReligion - 1)).getType())


Hope this helps, would test this here but don't have a computer here powerful enough to run Civ4 only runs on my sons laptop and no prizes for guessing where that is.

I guess the religion should also be influenced populatione of the individual religions. More fun later plus I need assess to the API. Where is the API for when I do get CIV4 plus comp.

Cheers

Caesium
May 14, 2006, 05:59 PM
Is this mod dead?
Or is it still alive and somebody here to bring it to 1.61?

Osymandias
May 14, 2006, 08:05 PM
it works just fine with 1.61 :D

Caesium
May 15, 2006, 03:43 AM
it works just fine with 1.61 :DIn my modcompilation it doesn't work at all.

Osymandias
May 15, 2006, 04:47 AM
hmmm.....in mine it does without probs....:confused:

Houman
May 15, 2006, 03:46 PM
There were lots of suggestions, maybe somebody should take over this mod and make an update with all these recent suggestions.

Caesium
May 15, 2006, 04:38 PM
I know, where my problem lies. It depends on the UnitStatisticsMod, because it uses the same way to store informations as are used in SettlerReligion.
UnitStatisticsMod overwrites the SettlerReligion infos. Does anybody know, how to get rid of this problem?

Jeckel
May 16, 2006, 12:16 PM
Hmm, I just stumbled across this and sounds very interesting, I'll take a look at it today and see what I can find. :)

Caesium
May 16, 2006, 01:37 PM
I made a workaround for this.
Now, for my modification the settlers get a promotion depending on the religion, and depending on the promotion the new city will get a religion.

Jeckel
May 16, 2006, 02:17 PM
Well I took a look and I see that it stores its data in the scriptdata of the unit, but the last version of the unitstatistics mod I looked at used SDToolKit to store its data, so I don't see how that could conflict. This mod is pretty straight forward, I will take some spare time in the next couple days and rewrite this and post and updated version. :)

So you made one with promotions? That sounds very interesting, promotions being the best way to handle things in this game imo. Could you post up zip of your modifications, I would love to look through it.

EDIT: I was just thinking a little, and how does Unit Religion sound instead of just settler religion.. well, I'm going to get this started, I'll put somthing up by tomorrow night. :D

Caesium
May 16, 2006, 02:34 PM
The SDToolKit, and also the SDToolKitAdvanced, uses also the scriptdata of the unit, I lokked through the code. Do you want my complete modifcation or just the settler religion recoding?

Jeckel
May 16, 2006, 03:37 PM
The sdtoolkits may use scriptdata, but the way it stores stuff, as long as you use unique strings to name your storage area you should be able to store as much data as you want from as many sourses as needed. I think the prob came because this mod directly stored into the scriptdata and overwrote what the sdtoolkit was storing for unitstatistics.

I rewrote this mod a little to use Dr Elmer Jiggle's customeventmanager and the sdtoolkit. I changed it a little so all units get a religion when built, I will finish it up tonight and put it out there for those that want it.

As for your mod, the religion recoding would be fine, but if you want to share your complete modifications I would love to look at it. :)

Jeckel
May 18, 2006, 03:30 AM
As I said, I rewrote this mod. I added in some config.ini options to control the chance that Settlers will get a religion. Here is the link..

JUnitReligion Mod Thread (http://forums.civfanatics.com/showthread.php?p=4060400#post4060400)

If you have ideas for this mod and can't get ahold of Bhruic, let me know and I see what I can do in later versions of my mod. :)

meatwad4289
May 25, 2006, 01:40 AM
does this work with custom religions???

Caesium
May 25, 2006, 02:00 PM
Yes it works, because it "looks" into the xml-files and searches for religions, so it'll find modded religions, too.

CCJ39
Jul 30, 2007, 10:33 AM
I've used this mod-comp in my own little civ-color-mod (changes the color of some civs, as the name says :D ) with Warlords up to last weekend... now I've updated my mod for BtS and copied the old settler-religion-files from my Warlords-modversion to my BtS-modversion, but the settler-religion isn't working now... anyone else can confirm this problem or any solution/fix for BtS? :confused:

Grave
Jul 30, 2007, 11:18 PM
The Python is gonna have to be converted over to BtS standards in order for it to work. Don't ask me though, I don't know how! :(

CCJ39
Jul 31, 2007, 02:30 AM
ok, thx... I'll have a look to the new standards and maybe I'm able to figure it out

I'm not very experienced in python, but some basic skills from scientific-projects... so it would be welcome if any other like to try to update

The Navy Seal
Aug 01, 2007, 08:54 AM
Are you going to update for BtS I think I could use this in one of my Mod COMPs.

CCJ39
Aug 13, 2007, 04:10 AM
ok, I don't know any more to try and it still isn't working :(

anyone else is able to update this mod for BtS?

artemisarrow
Nov 14, 2007, 12:09 AM
i tried to covert this to bts 3.13...failed miserably any luck?