UNITAI_MISSIONARY causes CTD at end of turn

Joined
Jan 21, 2006
Messages
737
This one's for Blake.

Edit: this bug also occurs in the vanilla game and should thus have a higher priority. For more details and fix, see next post.

I hope he doesn't mind the fact that the savegame is not from the vanilla game, but from the beta version of a mod (45 MB): http://www.maxriga.com/downloads/BTS1.zip

There are two confucian missionaries in Shanghai. The game crashes at the end of the turn unless you do either of the following:

- delete both missionaries

- delete confucianism from at least two chinese cities

- change the UNITAI of both misssionaries to something other than UNITAI_MISSIONARY (I tried UNITAI_CITY_DEFENSE)

Hence, I'm pretty sure that there is a general bug in the AI and that the crash is not mod-specific.
 

Attachments

I got some more info on this. Apparently, it's not the UNITAI_MISSIONARY that's the culprit, but the UNITAI_MISSIONARY_SEA of another unit that wants to carry the missionaries somewhere. Only problem: this other unit has a cargo capacity of 0. I could fix the bug by adding a check at the beginning of AI_pickup, but I guess it would be better if a non-cargo unit didn't get the UNITAI_MISSIONARY_SEA in the first place, which was an error in the XML files of the mod.

problem line:
(division by 0, since cargoSpace() = 0 in this case)

Code:
						if (GET_PLAYER(getOwnerINLINE()).AI_plotTargetMissionAIs(pLoopCity->plot(), MISSIONAI_PICKUP, getGroup()) < ((iCount + (cargoSpace() - 1)) / cargoSpace()))

solution: AI_pickup (bool CvUnitAI::AI_pickup(UnitAITypes eUnitAI)) should return false if cargoSpace = 0. Add this to the beginning of the function:

Code:
	if (cargoSpace() == 0)
	{
	    return false;
    }
 
After seeing some more CTDs, I can now confirm that this issue is more widespread than I originally thought. It even occurs when the XML file is correct, and more importantly, even in the vanilla game. This crash could be fixed with the modification of ai_pickup from the last post.
 
Back
Top Bottom