Attack Odds calculated incorrectly?

Kael

Deity
Joined
May 6, 2002
Messages
17,403
Location
Paris, France
This is from CvSelectionGroupAI.cpp. Where the AI checks to see what its odds are of attacking a an emeny stack. The following is exactly as the function appears in BtS escept the bold part which I have added.

Code:
int CvSelectionGroupAI::AI_attackOdds(const CvPlot* pPlot, bool bPotentialEnemy) const
{
	CvUnit* pAttacker;

	FAssert(getOwnerINLINE() != NO_PLAYER);

	if (pPlot->getBestDefender(NO_PLAYER, getOwnerINLINE(), NULL, !bPotentialEnemy, bPotentialEnemy) == NULL)
	{
		return 100;
	}

	int iOdds = 0;
	pAttacker = AI_getBestGroupAttacker(pPlot, bPotentialEnemy, iOdds);

	if (pAttacker == NULL)
	{
		return 0;
	}

	return iOdds;
}

According to how I read this the function returns 100% attack success probability to the AI if there isnt a unit that can defend in the tile. But otherwise it always returns 0% success odds.

As far as I can tell this would make the AI less aggresive than it should be and the function it should be the following:

Code:
int CvSelectionGroupAI::AI_attackOdds(const CvPlot* pPlot, bool bPotentialEnemy) const
{
	CvUnit* pAttacker;

	FAssert(getOwnerINLINE() != NO_PLAYER);

	if (pPlot->getBestDefender(NO_PLAYER, getOwnerINLINE(), NULL, !bPotentialEnemy, bPotentialEnemy) == NULL)
	{
		return 100;
	}

	int iOdds = 0;
	pAttacker = AI_getBestGroupAttacker(pPlot, bPotentialEnemy, iOdds);

	if (pAttacker == NULL)
	{
		return 0;
	}

[b]//FfH: Added by Kael 04/11/2008
    iOdds = pAttacker->AI_attackOdds(pPlot, bPotentialEnemy);
//FfH: End Add[/b]

	return iOdds;
}
 
Doesn't look like "0 or 100" from where I'm sitting. That call of AI_getBestGroupAttacker(pPlot, bPotentialEnemy, iOdds) apparently passes iOdds by reference, and there's code in AI_getBestGroupAttacker (check final lines) to return best combat odds via that variable.

Alternative reasoning: if the code were to show 0% attack odds against any non-empty plot, how many AI attacks would we see? :P

...to think this is to be my first post here... :P
 
Back
Top Bottom