SettlerReligion Mod

grazwell said:
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:
Code:
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.
 

Attachments

  • CvCustomEventManager.zip
    745 bytes · Views: 118
Thanks, I think I forgot about the 'import SettlerReligion' bit when I tried it myself. A bit silly really.
 
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(iSelectedReligion).getType())
 
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.
 
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.
 
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...
 
SonOfMars said:
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:

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


-=R=-
 
SonOfMars said:
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(iSelectedReligion).getType())
I don't see why your code shoule be safer than mine:
Code:
if(iRandReligion < len(listReligions)+1):
	iSelectedReligion = listReligions[iRandReligion]
	unit.setScriptData(gcgetReligionInfo(iSelectedReligion).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?
 
RobO said:
I don't see why your code shoule be safer than mine:
Code:
if(iRandReligion < len(listReligions)+1):
    iSelectedReligion = listReligions[iRandReligion]
    unit.setScriptData(gcgetReligionInfo(iSelectedReligion).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=-
 
RobO said:
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
 
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.
 
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

Code:
listReligions = []

Make this assignment

Code:
listReligions = ["NO_RELIGION"]

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

The test for "NO_RELIGION" would be

Code:
if (len(listReligions) == 1):

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

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

Finally there would be no need for an if statement

Code:
iSelectedReligion = listReligions[iRandReligion - 1]
unit.setScriptData(gc.getReligionInfo(iSelectedReligion).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.
 
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.
 
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

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

You could use
Code:
unit.setScriptData(gc.getReligionInfo(listReligions[iRandReligion - 1]).getType())

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

Code:
unit.setScriptData(gc.getReligionInfo(listReligions(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
 
Is this mod dead?
Or is it still alive and somebody here to bring it to 1.61?
 
it works just fine with 1.61 :D
 
hmmm.....in mine it does without probs....:confused:
 
Top Bottom