Fix #6468: don't store version of AIs-started-via-console in name
You can do: "startai myai.3", which starts version 3 of "myai". This is very useful for testing save/load code between different versions of your AI. However, when using this syntax, the AI got saved as "myai.3" as name of the AI, instead of "myai". This caused several problems, like indicating to the user the AI could not be found, but still load the AI. But in all cases, the AI never got the chance to load the saved data, making the whole reason this exists pointless. By splitting the name and version already in the console command, the code becomes simpler and AIs started this way now follow the normal flow after initialization.
This commit is contained in:

committed by
Patric Stout

parent
29e3331055
commit
4319d31036
@@ -1172,7 +1172,24 @@ DEF_CONSOLE_CMD(ConStartAI)
|
||||
|
||||
AIConfig *config = AIConfig::GetConfig((CompanyID)n);
|
||||
if (argc >= 2) {
|
||||
config->Change(argv[1], -1, true);
|
||||
config->Change(argv[1], -1, false);
|
||||
|
||||
/* If the name is not found, and there is a dot in the name,
|
||||
* try again with the assumption everything right of the dot is
|
||||
* the version the user wants to load. */
|
||||
if (!config->HasScript()) {
|
||||
char *name = stredup(argv[1]);
|
||||
char *e = strrchr(name, '.');
|
||||
if (e != nullptr) {
|
||||
*e = '\0';
|
||||
e++;
|
||||
|
||||
int version = atoi(e);
|
||||
config->Change(name, version, true);
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
|
||||
if (!config->HasScript()) {
|
||||
IConsoleWarning("Failed to load the specified AI");
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user