View Full Version : Units and PrereqReligion/StateReligion/etc.


Andrew_Jay
Apr 23, 2007, 08:23 AM
Question about the several religion tags in UnitInfos.XML . . .

I'm trying to create a mechanic where civilizations can only build military units in cities that contain their state religion.

For example, if you have Hinduism as your state religion, it has to be present to train most units. If there is a city with Islam present (but not Hinduism), a conversion to Islam would allow you to train units (but only in Islamic cities), etc. I want to make this general - there aren't any "Islamic" units, the only thing is to match the religion with your state religion.

However, looking at the tags available, this doesn't seem easy to do:

PrereqReligion - I can define a unit as requiring a specific religion
StateReligion - I can define a unit as requiring a specific state religion

To make this work, am I going to have to create seven separate units, each using the above tags, for example:

<StateReligion>RELIGION_ISLAM</StateReligion>
<PrereqReligion>RELIGION_ISLAM</PrereqReligion>

<StateReligion>RELIGION_TAOISM</StateReligion>
<PrereqReligion>RELIGION_TAOISM</PrereqReligion>

<StateReligion>RELIGION_HINDUISM</StateReligion>
<PrereqReligion>RELIGION_HINDUISM</PrereqReligion>

etc.?

Or are am I missing the utility of one of the other religion tags, such as "ReligionType" or "bPrereqReligion"?

Dom Pedro II
Apr 23, 2007, 08:44 AM
AFAIK, there is no way to do what you want... You'd literally have to create a set of units for every religion if you want this to work. You'd need a new tag like <bCityMustHaveStateReligion/> or whatever you'd want to call it.. so there'd have to be some changes in the SDK. It could be done in python too, but it wouldn't have the nice easy XML tags for it.

Sto
Apr 23, 2007, 10:12 AM
If you want to do it by python , here a solution that can help you if you have no skill in python . But , as Dom Pedro II said , the units will simply don't appear in the city menu , and don't appear in grey with a note like "require state religion" .

You can do that by editing "CvGameUtils.py" in the python folder of the MOD :

Here , an example where just warrior and scout can only be built without state religion . It's perhaps better to check the unitClass of the unit instead of the type , or make a list of the only state religion buildable units ( if shorter ).


def cannotTrain(self,argsList):
pCity = argsList[0]
eUnit = argsList[1]
bContinue = argsList[2]
bTestVisible = argsList[3]
if pCity.getOwner()!=gc.getBARBARIAN_PLAYER():
listUnitAlwaysTrainable=[gc.getInfoTypeForString('UNIT_WARRIOR'),gc.getInfo TypeForString('UNIT_SCOUT')]
if gc.getUnitInfo(eUnit).isMilitaryProduction() and not eUnit in listUnitAlwaysTrainable:
iStateReligion=gc.getPlayer(pCity.getOwner()).getS tateReligion()
if iStateReligion==-1:
return True
elif not pCity.isHasReligion(iStateReligion):
return True
return False


Tcho !

Andrew_Jay
Apr 23, 2007, 10:57 AM
Thanks for the help.

Actually, the units not showing up in the city screen (unless they are buildable) is preferred - one of my worries about the XML is that the city screen will be cluttered with seven of the same unit, six of them (or all seven) grey'd out - I'm going to make a quick test with my XML method later, and give the python a try too.

strategyonly
Apr 23, 2007, 02:16 PM
You might want to check out FfH1 for vanilla, or mine for Warlords, if i am reading you right(course i could be wrong), best bet is just to ask Kael, if he's not too busy that is!!

Sto
Apr 23, 2007, 07:09 PM
I don't know if this is the easiest way . But with your set of units for each religion , there is a way to customize the main screen to make it only appear the unit that is referered to your state religion . In this case , what should appear if you have no state religion ? tell me if you're interested in , it's not very hard to do .

Tcho !