[SDK] Bug in AI_bestTech?

Iustus

King
Joined
Jul 18, 2006
Messages
609
Location
Sunnyvale, CA
I have been going through the AI routines in the SDK, trying to get a hold on things, and I ran across what I believe is a cut and paste bug in the code. It is not fixed in the Warlords version.

in CvPlayerAI.cpp, lines 2083-2094 (in the routine AI_bestTech)
Code:
for (iK = 0; iK < GC.getNumTerrainInfos(); iK++)
{
	iBuildValue += ((GC.getImprovementInfo(eImprovement).getTerrainMakesValid((TerrainTypes)iK)) ? 50 : 0);
}

for (iK = 0; iK < GC.getNumFeatureInfos(); iK++)
{
	iBuildValue += ((GC.getImprovementInfo(eImprovement).getTerrainMakesValid((FeatureTypes)iK)) ? 50 : 0);
}

I believe the second loop should be calling getFeatureMakesValid, as below:
Code:
for (iK = 0; iK < GC.getNumTerrainInfos(); iK++)
{
	iBuildValue += ((GC.getImprovementInfo(eImprovement).getTerrainMakesValid((TerrainTypes)iK)) ? 50 : 0);
}

for (iK = 0; iK < GC.getNumFeatureInfos(); iK++)
{
	iBuildValue += ((GC.getImprovementInfo(eImprovement).getFeatureMakesValid((FeatureTypes)iK)) ? 50 : 0);
}

I know, it is a somewhat obscure bug, but it seemed pretty clearly a bug.

If my analysis is correct, this bug would cause techs which enable builds (from Civ4BuildInfos.xml) which enable improvements (from Civ4ImprovementInfos.xml) to basically double count the terrain and not count the features.

In the default game, this would mean that the following get (slightly) higher than normal values:
Agriculture (+100)
Metal Casting (+100)
Pottery (+100)
Mathematics (+250)

And the following get (slightly) lower than normal values:
Replaceable Parts (-50)

Now, note, that there is a random factor of 0-2000 added to the value, so these are very small values, which is likely why the bug was never detected.

Even so, it does seem to be a bug to me, and with some mods, it could become significant.

-Iustus
 
I found another code bug. This one is in AI_foundValue which causes the AI to value coastal cities less than they should be valued (only for starting positions).

Does anyone know if there is a good location to post specific bugs in the SDK code?

Perhaps I should start a thread (here? or in the bug reports forum?) with the title "[SDK] Firaxis Bugs" or something like that?

The intent would be to only document specific code mistakes which in theory could be picked up by Firaxis in their next patch, to fix bugs.

-Iustus
 
I would suggest the Bug Reports forum would be the best place for it - it's where they're most likely to look.

I always thought the AI was suprisingly against settling coastal plots.
 
Top Bottom