Bug in CvGameInterface.py

Bringa

King
Joined
Jan 23, 2006
Messages
678
Hi,

part of the AI's decision making progress when it comes to research is invoking CvGameInterface.py. All that FFH does in there is tell certain civs to research certain techs (Khazad beeline Runes etc). Finally, if the civ doesn't have exploration, it's pushed onto the queue (why? it's not THAT important, is it? Workers having trouble when they can't build roads?) So far, so good.

Now comes the interesting bit.

Code:
	if iTech != -1:
		if eTeam.isHasTech(iTech) == False:
			pPlayer.pushResearch(iTech, False)
			return 1

The problem is with the return 1. Everything up to that point is just fine; if a tech was selected and if the player's team doesn't have it, push it onto the queue. But then the function returns a one. Let's look at where it's called:

(this is CvPlayerAI.cpp)

Code:
	if (getCurrentResearch() == NO_TECH)
	{
		CyArgsList argsList;
		long lResult;
		argsList.add(getID());
		argsList.add(false);
		lResult = -1;
		gDLL->getPythonIFace()->callFunction(PYGameModule, "AI_chooseTech", argsList.makeFunctionArgs(), &lResult);
		eBestTech = ((TechTypes)lResult);
		if (eBestTech == NO_TECH)
		{
			eBestTech = AI_bestTech((isHuman()) ? 1 : 3);
		}

		if (eBestTech != NO_TECH)
		{
			pushResearch(eBestTech);
		}
	}

What happens is that AI_chooseTech is called as it should be and pushes what it should push (mostly that's exploration), but then lResult is 1. (TechTypes)1 is not NO_TECH; it's Alchemy. So eBestTech is not NO_TECH, it is TECH_ALCHEMY, and that gets pushed as well.

I am reasonably sure this is not the intended behaviour :)
 
Very interesting, I'll just return iTech to the function. Thanks!
 
I've always wondered why so many AI civs always end up getting alchemy so early in all the games that I play. I can't think of the last time I was actually able to build Typhoid Mary because the AI builds her like 100 years before I even get around to reseraching alchemy. If this is indeed a bug, then that would explain it. Great find.
 
Hadrian: if you look at the threat "Once more: FfH and the AI", you'll find more discussion on this. Basically, though, we were wrong: none of these things caused the AI to go for Alchemy quite that soon (and this frustrated me: when I debugged, Alchemy never showed up in my logs when the AI took it so early; now I know why: it wasn't chosen in the C++ code at all).

Kael: that would indeed be the least convoluted way to go about things. I was a little confused why you'd call pushResearch both from Python and C++, but I was sure you had a good reason.

And have I mentioned how much I love this mod recently? I've actually cancelled my rpg this weekend to play fire. Thank you for your continued work on this!
 
Kael: that would indeed be the least convoluted way to go about things. I was a little confused why you'd call pushResearch both from Python and C++, but I was sure you had a good reason.

I assumed incorrectly. I thought it worked like the ai move function where you return 1 to tell C++ that you will handle the selection from python. But as you notes you dont need to set it from python, you can just pass it back to the SDK.
 
Back
Top Bottom