Assert error in CvPlayerAI::AI_unitValue

Horatius

Prince
Joined
Sep 30, 2006
Messages
579
All of the sudden, I'm getting an consistent assert error that pretty much does not let the game advance between turns.
Its in CvPlayerAI::AI_unitValue (line in bold below).

Its puzzling me because I did not make a single change to that function:confused:. Could someone explain me a little bit about this and possible causes? Can I just comment that line out?

Spoiler :
Code:
		case UNITAI_ATTACK_CITY_LEMMING:
			bValid = false;
			break;

		default:
			[B]FAssert(false);[/B]
			break;
		}
	}

	if (!bValid)
	{
		return 0;
	}

	iCombatValue = GC.getGameINLINE().AI_combatValue(eUnit);

	iValue = 1;

	iValue += GC.getUnitInfo(eUnit).getAIWeight();
	
	int iFastMoverMultiplier;

	switch (eUnitAI)
	{
	case UNITAI_UNKNOWN:
	case UNITAI_ANIMAL:
		break;
 
Nevermind, I still don't understand debugging.

A unit was not being initiated properly by an old SDK function and I was getting that assert error instead of something that could lead me to the root cause of the freeze. I just got there eventually.

I don't get debugging. Hopefully first and last time to do it (yeah, right....).
 
You are getting the assertion thrown because the unit does not have an AI type that is recognised by the function. This is only a warning that there is probably something wrong in the code somewhere.

If you look at the top of the function you will see the a block of code starting with the following:

PHP:
bValid = GC.getUnitInfo(eUnit).getUnitAIType(eUnitAI);
if (!bValid)
{
	switch (eUnitAI)
	{
	case UNITAI_UNKNOWN:
		break;
	case UNITAI_ANIMAL:
		if (GC.getUnitInfo(eUnit).isAnimal())
		{
			bValid = true;
		}
		break;
        .....
        .....
        .....
	case UNITAI_ATTACK_CITY_LEMMING:
		bValid = false;
		break;

	default:
		FAssert(false);
		break;
	}
}
The first line is checking if the AI type associated with the unit is one it expects from the UnitType XML file.

If not then the switch(eUnitAI) line is looking at what AI type the unit is associated with. It then looks through all the case UNITAI_XXXX: lines to see if it can find one where the UNITAI_XXXX matches the AI associated with the unit. If none match then it jumps to the default: case which is to throw the assertion you are seeing.

You will only ever see this dialog box when you are running a debug dll, it will not be displayed when you compile a Release version so don't comment the line out.

I would suggest that the first place to look is in your CIV4UnitInfos.xml to see if there is a unit with a <DefaultUnitAI> that does not appear in the long list of case UNITAI_XXX values in the function. You should also check the list of <UnitAIs> to make sure they all exist.
 
Back
Top Bottom