Need help with some code

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
I'm going through and exposing all the civic revolutions information. For the most part it's been pretty easy, and once I get it done I will upload all of it here for you guys to incorporate into the RevDCM base mod. I've ran into a snag I need help with. The tag:
fRevIdxNationalityMod is giving me bizzare results. My code in CvGameTextMgr.cpp looks like so:
Code:
	//  Revolution Nationality City Modifier
	if (0 != GC.getCivicInfo(eCivic).getRevIdxNationalityMod())
	{
		szHelpText.append(NEWLINE);
		szHelpText.append(gDLL->getText("TXT_KEY_CIVIC_REV_NATIONALITY", GC.getCivicInfo(eCivic).getRevIdxNationalityMod()));
	}
And in the XML text I have this:
Code:
		<Tag>TXT_KEY_CIVIC_REV_NATIONALITY</Tag>
		<English>[ICON_BULLET]%D1% To Nationality Based Revolution Penalties</English>

Now so far this system has worked well for the integer values, but I suppose the code is tripping out on the float, but I don't know why, or how to fix it (originally I had multiplied it by 100, but removed that just to see what in the devil values I'd get just from the variable itself). Anyway it returns bizzare stuff like 105,982,435% (not exactly what it gives but you get the point). So how do I fix this?
 
Still wondering what's up with the floats. They give me garbage values when I call them in CvGameTextManager, the Integers display fine. Any help would be apreciated.

On a second point, I'm wanting to get the CityDistance modifiers from buildings and techs to display in the civilopedia. Here is my problem though, the values that are used in Revolution.py are in the XML, and are then ran in Revolution.py to set up the CityDistanceModifiers for techs and buildings. But if I call the values directly from the XML in CvGameTextManager and Revolution.py is changed, CvGameTextMgr wol't know and things wol't match up. What I'd really like is for these calculations to be done in the SDK so that they can be called directly from their functions and any alterations would be updated apropriately. Is it possible to move some of the stuff from Revolution.py into the SDK, or rather would you be willing to do that? I think doing this may make it easier to fix the issues in Multiplayer as well, and would also ease the process of exposing information. Anyway just wanted to run this by you guys (jdog and glider) and see your thoughts on the matter.
 
I got some help from EF and fixed the issue with floats.

Now I really need help on this, because only you would know jdog.

This call:
getRevViolentMod()

is not referenced anywhere I can find, the only instances of it are in CvInfos. Is it used at all? If so how? I'm trying to expose all the Rev stuff from civics, but I couldn't figure out what it put here, ie is a negative number good or bad? This is why I'm trying to expose stuff, alot of the revolution stuff isn't clear. Anyway I have no idea how this XML tag works or if it is even used.

Please respond.

Edit:

Well I've ran into another snag. I was attempting to clone some of the Civic Revolutions tags into TraitInfos, but the thing is all the civics tags don't opperate in the SDK, instead they are referenced by RevCivicsUtils. :(

I can't figure out how to clone these functions into traits because it's done in an esoteric way through RevCivicsUtils. Any help would be greatly apreciated. Again though, I think in the longrun it would just work better to move alot of this code into the SDK. Create a new CvRevolution.cpp and h file where alot of this stuff could be handled, would probably make fixing multiplayer easier and also increase performance.
 
getRevViolentMod is intended to allow revolts to be more likely to be violent under certain civics than others. There was apparently a copy and paste bug in RevCivicUtils, the getCivicsViolentRevMod function should have called getRevViolentMod.

Anyway, to get the tags working in TraitInfos, what you'd need to do is of course add the tags to traits and then expose them to Python in the same way the civics tags are done. Then, in the relevant RevCivicsUtils functions, you would add a loop over traits similar to the existing loop over civics in each function. When the player has the trait in question, then you would add the getRevViolentMod or whatever for the trait to the total.

Hope that helps.
 
OK. So RevCivicUtils can read traits, it's not limited to Civics? That helps alot, with this knowledge I should be able to move forward.

One question though, the civic tags, I can't find where they are exposed to python. The only instances of them Notepad++ finds is in CvInfos, what Cy file are you using to expose them to python?

Thanks for the reply.
 
I have a question related to this: I am looking to add a trait effect that lessens the chance of revolutions occurring. Would the easiest way to go about this be a modifier to the RevolutionIndex or is there another way you would suggest?

Cheers,
ripple01
 
phungus -

The Revolution civic variables are exposed in CyInfoInterface1.cpp.


ripple -

There are a bunch of different ways you could go for different traits, as they could easily be made to have any of the benefits currently given to civics in the same way I described above. So, you could have traits that acted like Representation and reduced distance penalties for large civs, you could have traits made good religion effects even better or made bad religion effects less of a problem.

Simply effecting rev index directly would do what you want too, but there are many equally easy options.
 
OK jdog. How do I make a trait list. From RevCivicsUtils we have this:

Code:
# civicsList[0] is a list of all civics of option type 0
civicsList = list()


def initCivicsList( ) :

    CvUtil.pyPrint("  Rev - Initializing Civics List")

    global civicsList

    for i in range(0,gc.getNumCivicOptionInfos()) :
        civicsList.append(list())

    for i in range(0,gc.getNumCivicInfos()) :
        civicInfo = gc.getCivicInfo(i)
        civicsList[civicInfo.getCivicOptionType()].append(i)

I'm assuming I need to clone this, and have it apply to traits, but I doubt replacing Civic with Trait is going to work. What do I need to do here to make a trait list to draw from?

I've started a thread on this in the Python/SDK forum if you want to help out there, I'm kind of at a loss now of where to start, with the Python I mean, I have the XML tags loading and all that jazz, the SDK stuff was easy:
http://forums.civfanatics.com/showthread.php?p=8310356#post8310356
 
Thanks to some help from EF I've gotten started. Here is what I have for RevCivicUtils.py:

Code:
########################## Traits effect helper functions #####################

def getTraitsRevIdxLocal( iPlayer ) :
	pPlayer = gc.getPlayer(iPlayer)

	if( pPlayer.isNone() ) :
		return [0,list(),list()]

	if( pPlayer.getNumCities() == 0 ) :
		return [0,list(),list()]

	localRevIdx = 0
	posList = list()
	negList = list()

	for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
			traitEffect = traitInfo.getRevIdxLocal()
			if( traitEffect > 0 ) :
				negList.append( (traitEffect, civicInfo.getDescription()) )
			elif( traitEffect < 0 ) :
				posList.append( (traitEffect, civicInfo.getDescription()) )

			#CvUtil.pyPrint("  Rev - %s local effect: %d"%(traitInfo.getDescription(),traitEffect))

			localRevIdx += traitEffect

	return [localRevIdx,posList,negList]


def getTraitsRevIdxNational( iPlayer ) :
	pPlayer = gc.getPlayer(iPlayer)

	if( pPlayer.isNone() ) :
		return [0,list(),list()]

	if( pPlayer.getNumCities() == 0 ) :
		return [0,list(),list()]

	localRevIdx = 0
	posList = list()
	negList = list()

	for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
			traitEffect = traitInfo.getRevIdxNational()
			if( traitEffect > 0 ) :
				negList.append( (traitEffect, civicInfo.getDescription()) )
			elif( traitEffect < 0 ) :
				posList.append( (traitEffect, civicInfo.getDescription()) )

			#CvUtil.pyPrint("  Rev - %s local effect: %d"%(traitInfo.getDescription(),traitEffect))

			localRevIdx += traitEffect

	return [localRevIdx,posList,negList]


def getTraitsHolyCityEffects( iPlayer ) :

    pPlayer = gc.getPlayer(iPlayer)

    if( pPlayer.isNone() ) :
        return [0,0]

    if( pPlayer.getNumCities() == 0 ) :
        return [0,0]

    goodEffect = 0
    badEffect = 0

    for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
			
            goodEffect += traitInfo.getRevIdxHolyCityGood()
            badEffect += traitInfo.getRevIdxHolyCityBad()

    return [goodEffect,badEffect]


def getTraitsNationalityMod( iPlayer ) :

    pPlayer = gc.getPlayer(iPlayer)

    if( pPlayer.isNone() ) :
        return 0

    if( pPlayer.getNumCities() == 0 ) :
        return 0

    natMod = 0

    for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
            natMod += traitInfo.getRevIdxNationalityMod()

    return natMod


def getTraitsReligionMods( iPlayer ) :

    pPlayer = gc.getPlayer(iPlayer)

    if( pPlayer.isNone() ) :
        return [0,0]

    if( pPlayer.getNumCities() == 0 ) :
        return [0,0]

    goodMod = 0
    badMod = 0

    for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
            goodMod += traitInfo.getRevIdxGoodReligionMod()
            badMod += traitInfo.getRevIdxBadReligionMod()

    return [goodMod,badMod]


def getTraitsDistanceMod( iPlayer ) :

    pPlayer = gc.getPlayer(iPlayer)

    if( pPlayer.isNone() ) :
        return 0

    if( pPlayer.getNumCities() == 0 ) :
        return 0

    distMod = 0

    for i in range(gc.getNumTraitInfos()):
		if pPlayer.hasTrait(i):
			traitInfo = gc.getTraitInfo(i)
            distMod += traitInfo.getRevIdxDistanceMod()

    return distMod

I've piggybacked this on the end of RevCivicUtils. Now here is the thing. I'm thinking that the return functions are going to just overwrite the variables like distmod set up by civic functions. Obviously I don't want this I want to add them. Any advice on how to get this functioning correctly?
 
I've piggybacked this on the end of RevCivicUtils. Now here is the thing. I'm thinking that the return functions are going to just overwrite the variables like distmod set up by civic functions.

???

Not sure what you mean by that ... your functions look just fine to me, if you use them in the same places and in the same way as the Civics versions, then it should work just fine.

So, you'd want something like:

Code:
        [traitIdx,traitPosList,traitNegList] = RevUtils.getTraitsRevIdxNational( iPlayer )
        civRevIdx += -traitIdx

        posList.extend( traitPosList )
        negList.extend( traitNegList )

Just after the similar usage for civics.
 
Looking at Civic numbers in cheatmode, it doesn't appear that the Revolution effects in CivicInfos is taken into account.

Where is the logic where Civic preferences are calculated, specifically does anyone have a good idea of where it would be a good idea to teach the AI about Revolution modifiers from different civics?
 
I imagine you're talking about getCivicsRevIdxLocal or getCivicsRevIdxNational?

I just double-checked, and the modifiers are all used properly. These two direct Rev index effects, however, are currently invisible ... they're there, but with the way they're done right now you wouldn't see them in cheat mode because of the issues with visibility of some civ-wide effects.

For the next version, I'll move getCivicsRevIdxLocal to a more visible place (it was more efficient where it was, but then didn't show up in city displays ...). Also, getCivicsRevIdxNational is obsolete and I will be removing it in the next version ... the new system for national level effects is getCivicsCivStabilityIndex.
 
The AI doesn't seem to take any Revolution Civic tag into account when choosing civics. Give a Civic an insane value like 10 (+1000%) for city distance penalty to a civic, and then press Ctrl while in cheatmode over AI territories and the values given for civic peferences don't change, even though such a civic would destroy the AI's empire.

Also glad to hear you will be exposing Rev Stability effects to the player. These hidden Rev Stability factors is the main issue I still have with revolutions, so knowing these will be exposed is great. Now any chance you could clone some of the more useful Revolution Civic tags into Trait Infos :deal:
 
Back
Top Bottom