FS#2837 - Allow reloading AI without removing the controlled company

Attached to Project: OpenTTD
Opened by Bilbo (bilbo) - Tuesday, 14 April 2009, 11:39 GMT
Last edited by andythenorth (andythenorth) - Saturday, 19 August 2017, 18:00 GMT
Type Patch
Category Script → NoAI
Status Closed
Assigned To andythenorth (andythenorth)
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 4
Private No


Currently, if you reload AI, everything that the AI have built is removed too. This is very annoying with AI development, as if you write new code and want to change it while the company is running (or if you want to reload fixed AI code after it have crashed), you can't do it without erasing everything the AI built.

I suggest to add feature that will allow only to reload the AI code without removing the company (similarly as it is loaded "into" existing company when loading game)

It could work like this:

call Save() on old AI, if it is not crashed (optionally)
remove ald AI code
load new AI code
call Load() on new AI, giving it the data from Save() (optionally)

This task depends upon

Closed by  andythenorth (andythenorth)
Saturday, 19 August 2017, 18:00 GMT
Reason for closing:  Won't implement
Additional comments about closing:  Mass closure of patch tickets with no commentary for >5 years. Goal is to reduce patch queue as an experiment to see if it aids faster reviewing and rejection/acceptance (it may not). If this offends you and the patch is maintained and compiles with current trunk, discuss with andythenorth in irc. (andythenorth has no ability to review patches but can re-open tickets).
Comment by Bilbo (bilbo) - Tuesday, 14 April 2009, 14:02 GMT
Patch for this - current reload_ai command is renamed to restart_ai (it is IMHO more appropriate name for that, as it kills an AI and then starts a new one) and new reload_ai is added - first parameter is company to reload, extra parameters can be used to load different AI instead of reloading the current (they are same as for the start_ai command). In both cases, the company infrastructure and vehicles are kept intact.

What could maybe need to be changed for consistency if the patch is applied:

the "Reload AI" button in console - either rename to "Restart AI", or change its functionality to really only reload the AI. The "second" function (reload/restart) could be available by ctrl-clicking the button.

I briefly tested the patch in singleplayer, reloading works both for reloading same or different company and for reloading AI that is alive or crashed.

The only case that is not properly tested is reloading AI when user specifies invalid AI name on commandline. The new AI is not loaded (reloading fails and current AI is kept intact) and I return name of old AI to AIConfig, though I am not sure whether this does not have any unwanted side effects.

If anybody have idea how this case should be handled properly, I can change the current behavior.
Comment by Bilbo (bilbo) - Wednesday, 14 April 2010, 14:02 GMT
Updated the patch to r19627.