Game Option in XML

OrionVeteran

Deity
Joined
Dec 25, 2003
Messages
2,443
Location
Newport News VA
I would like to create a "Limited Religions" option based upon a value set in the GlobalDefinesAlt.xml file. For Example:

Code:
<Define>
	<DefineName>OC_LIMITED_RELIGIONS</DefineName>
	<iDefineIntVal>1</iDefineIntVal>
</Define>

What else do I need to do or create to call this value globally.

if (gc.getOC_LIMITED_RELIGIONS() == 1):

Note: I want to avoid any SDK changes, if possible, and limit the changes to Python and XML.

Respectfully,

Orion Veteran :cool:
 
To access your new option, I think you can use this:

Code:
if gc.getDefineINT("OC_LIMITED_RELIGIONS") == 1:
    ...

Defining a specific function for your option normally requires modifying the SDK, but Python is quite dynamic. You can try this out:

Code:
def getOC_LIMITED_RELIGIONS(self):
    return self.getOC_LIMITED_RELIGIONS()

CyGlobalContext.getOC_LIMITED_RELIGIONS = getOC_LIMITED_RELIGIONS

You'll have to run this code somewhere before you access the function, but Civ4 doesn't have a well-defined initialization routine. I worked it out for BUG, and it differs depending on whether you start Civ itself or load or start a new game, so it's a PITA.

I would stick with getDefineINT() or define a module function in a module that you create:

Code:
# MyMod.py

from CvExtenstions import *

gc = CyGlobalContext()
def isOC_LIMITED_RELIGIONS():
    return gc.getDefineINT("OC_LIMITED_RELIGIONS") != 0

# SomeOtherModule.py

import MyMod

if MyMod.isOC_LIMITED_RELIGIONS():
    ...
 
You want to avoid SDK completely? If so, I am not sure it is possible to add a new item to GlobalDefinesAlt.xml at all. Each entry in there needs to exist in the SDK file CvXMLLoadUtilitySet.cpp

EmperorFool's option 2 above worked beautifully. Simple and effective. Nothing had to be changed in SDK to make it work.

:thanx:

Orion Veteran :cool:
 
Now to go puzzle out why I got it wrong and learn something new about the DLL.

I think the reason it works is because you don't need a new function. The same is true when adding new variations of other XML objects that already exist, like units or buildings. You only need to do DLL work if you add XML tags or want to expose new functions.

This is why you must use getDefineINT instead of a accessor named for the option itself, though the trick I posted is a way to add it in Python directly. I really dig Python's dynamic nature for that.

It's at the heart of the new BUG Core's handling of options. I read in the options definitions from XML and create named accessors like isPleFilterBehavior() and isShowDeadCivs(). It's not all that different from passing in a string (in fact that's exactly what Python does under the hood), but it looks nicer when reading code.
 
Top Bottom