Avoid Growth and the AI

TC01

Deity
Joined
Jun 28, 2009
Messages
2,216
Location
Irregularly Online
So in Final Frontier, the AI doesn't seem to do anything when it turns Avoid Growth on.

I am assuming this is likely the same in unmodded BTS, since Final Frontier is DLL-less. While Final Frontier Plus is not DLL-less, I have not modified the code that handles Avoid Growth. If it's not the same, then oh well.

Because of the way population and growing works in Final Frontier, it may be more noticeable there- after a certain amount of time the city can't assign any more population to work (since there are no specialists) and so they just clutter up space, causing unhealthiness and unhappiness.

The bug seems to be in the way that CvCity::doGrowth() checks for

Here is God-Emperor's quoted post on the subject:

I'm not positive that in FF+ the AI still sets the AI_avoidGrowth to True, but I know it did in regular FF. It looks like CvCityAI.cpp has not been modified in FF+ so I assume it still does set it. Based on my perusal of the code it looks like the way it is set up now it will only set it if the unit being produced uses food in its production (colony ship and construction ship, since there is no civic that activates this for military units) or there are unhappy citizens, and in the unhappy citizen case it should always set it unless the city is set to emphasize food yield or great people (I didn't look to see if FF+ is likely to ever have these set). For the check for the AI_isEmphasizeAvoidGrowth() value, it looks to me like won't be set to True in FF+, or even in regular BtS, but I'm not sure. That's my interpretation of what CvCityAI::AI_avoidGrowth() will do in FF+.

[After this point, he figured out what was wrong...]

I just noticed that in CvCity::doGrowth() the function that it checks is AI_isEmphasizeAvoidGrowth(), not AI_avoidGrowth().

As I mentioned in the first paragraph, it seems to me that this is not likely to get set. The function AI_isEmphasizeAvoidGrowth() returns True if the value of m_iEmphasizeAvoidGrowthCount is > 0. The value m_iEmphasizeAvoidGrowthCount is only changed in CvCityAI::AI_setEmphasize() and that is only called in CvCityAI::AI_doEmphasize() and CvCity::doTask() (which is rather mysterious - I think this is what is called if the human clicks on the emphasis buttons, as well as the various other city related buttons in the interface, which explains why this works for the human). CvCityAI::AI_doEmphasize() was gutted at some point in Civ4 development, the comments say as much, so there are some checks that do nothing. To me it is looking like this can't actually cause m_iEmphasizeAvoidGrowthCount to be incremented. It doesn't have any check for happiness levels and the conditions under which it can call AI_setEmphasize() with the second argument set to True are quite limited.

So since CvCity::doGrowth() uses AI_isEmphasizeAvoidGrowth() it doesn't do anything for the AI if the AI is not actually incrementing m_iEmphasizeAvoidGrowthCount via CvCityAI::AI_setEmphasize().

The value you get in Python via PyCity.AI_avoidGrowth() is the return from the AI_avoidGrowth() fucntion, not AI_isEmphasizeAvoidGrowth(). There is a PyCity.AI_isEmphasize (INT iEmphasizeType) which could presumably get the avoid growth emphasis setting, although this actually accesses a completely different variable (the boolean array m_pbEmphasize) and doesn't check m_iEmphasizeAvoidGrowthCount (maintaining multiple values for these things seems like a bad plan).

Net result:

It seems to me that line 11285 in CvCity.cpp should use AI_avoidGrowth() if the player is an AI. That would have it actually avoid growth when there are unhappy citizens. Perhaps this:

Code:
if ((isHuman() && AI_isEmphasizeAvoidGrowth()) || (!isHuman() && AI_avoidGrowth()))

since AI_avoidGrowth() already checks AI_isEmphasizeAvoidGrowth(), plus the other stuff like happiness.

Or something like that.

If this is correct for vanilla BTS, even if the unofficial patch isn't being actively worked on anymore, at least other people can see this bug and maybe fix it in their own mods.
 
Top Bottom