SDK DoGold() function question

Kael

Deity
Joined
May 6, 2002
Messages
17,403
Location
Paris, France
Im not that sure what fassert is for, and google is not only not helping, but I believe its mocking me (the 3rd and 4th hit on a search on "fassert" and "c++" are both my threads, but im the one who doesnt know what it is!).

Anyway, the following is the SDK for the doGold function that runs on every player at the begining of his turn.

My question is, does the bolded line mean that an AI player (except the barbs) that has enough negative income to drop him below 0 is ignored?

Code:
void CvPlayer::doGold()
{
	bool bStrike;
	int iGoldChange;
	int iDisbandUnit;
	int iI;

	CyArgsList argsList;
	argsList.add(getID());
	long lResult=0;
	gDLL->getPythonIFace()->callFunction(PYGameModule, "doGold", argsList.makeFunctionArgs(), &lResult);
	if (lResult == 1)
	{
		return;
	}

	iGoldChange = calculateGoldRate();

[b]	FAssert(isHuman() || isBarbarian() || ((getGold() + iGoldChange) >= 0));[/b]

	changeGold(iGoldChange);

	bStrike = false;

	if (getGold() < 0)
	{
		setGold(0);

		if (!isBarbarian() && (getNumCities() > 0))
		{
			bStrike = true;
		}
	}

	if (bStrike)
	{
		setStrike(true);
		changeStrikeTurns(1);

		if (getStrikeTurns() > 1)
		{
			iDisbandUnit = (getStrikeTurns() / 2); // XXX mod?

			for (iI = 0; iI < iDisbandUnit; iI++)
			{
				disbandUnit(true);

				if (calculateGoldRate() >= 0)
				{
					break;
				}
			}
		}
	}
	else
	{
		setStrike(false);
	}
}
 
FAssert is Firaxis wraper around assert (googling for just "C++ assert statment" should get you way more relivent results), an Assert statment is a kind of Debugging check that the program dose to verify things are going according to plan. Basicaly if the statment is true the program continues running, if it evaluates to false the program halts. FAssert are common in any of the get functions which need to access an array, they make shure the requested index is not outofbounds. An FAssertMsg() function also prints out a message if it failes.
 
Impaler[WrG] said:
FAssert is Firaxis wraper around assert (googling for just "C++ assert statment" should get you way more relivent results), an Assert statment is a kind of Debugging check that the program dose to verify things are going according to plan. Basicaly if the statment is true the program continues running, if it evaluates to false the program halts. FAssert are common in any of the get functions which need to access an array, they make shure the requested index is not outofbounds. An FAssertMsg() function also prints out a message if it failes.

So my problem is that I have an AI player with 800 or so units. He has 26 gold and -682 per turn in income. But he never has to disband units and continues to build. If I am reading that line correctly the doGold function is skipped for a non-human player in that condition. Is that correct?
 
Yes, an AI is covered by the ((getGold() + iGoldChange) >= 0)) bit. Basically it's saying:

If CvPlayer refers to a human OR a barbarian OR any player that has more than or equal to zero gold after the change...........

The last bit would include AI players.

Dale

BTW, if you compiled a DEBUG version and linked it to the exe's code you would get a log file with a message for every fassert the code encountered. In other words, it helps determine where the code crashes. Pity we can't link to the exe's code to do it.
 
Doesnt that seem weird that AI Players with negative income large enough to drop them below 0 never go on strike or disband units? So they can grow their armies to any size regardless of maintenance costs.
 
Doesnt that seem weird that AI Players with negative income large enough to drop them below 0

I think that because the game does not allow a player to have negative gold reserves, it's just checking at this point to make sure that this hasn't happened.
 
PeteT said:
I think that because the game does not allow a player to have negative gold reserves, it's just checking at this point to make sure that this hasn't happened.

At that point in the code the player can have a negative gold reserve (that code would allow a human player to do it). A few lines down you see this:

Code:
	if (getGold() < 0)
	{
		setGold(0);

		if (!isBarbarian() && (getNumCities() > 0))
		{
			bStrike = true;
		}
	}

Which would keep the player from ending up with a negative gold amount. But since AI players with a negative income (that would take them below zero) are blocked before this they never get this far and never go on strike.
 
No it does not. It means that the AI should never be in that situation, and if it occurs (in a debug build only), the game will complain. It doesn't block it at all (unless you consider an error message blocking).
 
talchas said:
No it does not. It means that the AI should never be in that situation, and if it occurs (in a debug build only), the game will complain. It doesn't block it at all (unless you consider an error message blocking).

Ahh, that makes sense, thanks.
 
Back
Top Bottom