FS#6468 - Loading savegame with AI loaded as specific version of that AI fails to load correct version of AI

Attached to Project: OpenTTD
Opened by Wormnest (Wormnest) - Wednesday, 25 May 2016, 15:38 GMT
Type Bug
Category Script → NoAI
Status New
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


I think there is a AI savegame bug.
Presuming you have both WormAI versions 4 and 5 available statt a new game, open console and do:
startai wormai.4

Run it for a while then save and reload the savegame.

Open console: it shows that savegame has an ai named ┬┤wormai.4┬┤ which is no longer available although obviously WormAI version 4 hasn't been deleted in the meantime.
It als shows that the latest version of the AI has been loaded instead but it didn't receive the savegame data because it's incompatible even though min version to load is 1. This might or might not be caused by the first error.

Note that version numbers are stored in the path inside the tar e.g. WormAI-v5, WormAI-v4 etc so this is not

It looks at first glance that it saves the dot and version number as part of the ai name which looks wrong.

Attached example savegame showing the bug.
This task depends upon

Comment by Wormnest (Wormnest) - Wednesday, 25 May 2016, 18:10 GMT
See also discussion on IRC:

Another savegame where I first removed WormAI v5 from content_download/ai and then started a game with the latest version of wormai (= 4).
Loading this again after adding v5 back loads version 5 but without the two complaints in the console. It also does load the savegame data for the AI in contrast to the other savegame.
Comment by Ricardo (Samu) - Wednesday, 25 May 2016, 23:10 GMT
Hi. From my limited understanding after dwelving into the code, the problem first arises in the console_cmds.cpp, line 1170.

config->Change(argv[1], -1, true);

It takes the value of argv[1], which is wormai.4 and uses that to find the correct version of the ai to start. That is fine, but this also sets the name of the AI, and this name is not corrected to the intended name that should have been retrieved from the ScriptInfo.

When the savegame function is asking for the name of the AI, it takes the wrong name, wormai.4, because it hasn't been corrected when it started via console. The savegame function also asks for the version of the AI, but there is no issue with this part: when the console found version 4 in the ScriptConfig, it also set the version to 4, the savegame functions retrieves version 4 as intended.
Comment by Ricardo (Samu) - Sunday, 29 May 2016, 23:53 GMT
Perhaps it is intended that it doesn't correct the name of the AI, according to documentation.

Comment by Ricardo (Samu) - Wednesday, 22 June 2016, 20:43 GMT
This fixes it, but my coding skills are horrible.