Page 1 of 1

API Request: AIController::StopAI()

Posted: 01 Jan 2012 10:23
by DeletedUser6
AIs need a function that stops the AI safely. (AroAI, and AIAI atm uses a division by zero error to get that effect, and we need something a little safer).

Though you probably think that by just passing a flag to the AI Start() function, you could achieve the same effect, if you have a fatal condition that occurs in the middle of a 5 function thick function call, you would have to parse the return value, to make sure that you got a correct value, and if not return, leaving, say a half finished road route, and repeat for the other 5 functions.

If you made a call to the proposed AIController.StopAI() function it would guide it safely through the functions, and at the root function it would stop the AI.

You could have it print to the Debug Panel:
The AI has been stopped by request.
And, yes, I am an over optimistic idiot.

Matthew:out

Re: API Request: AIController::StopAI()

Posted: 01 Jan 2012 10:32
by TrueBrain

Code: Select all

function Start() {
(..)
this.stop_ai = true;
(..)
if (this.stop_ai) return;
}
Returning from your Start() function makes your AI terminate. If you don't want to use a boolean, you can use an exception chain too.

All in all: it is not the idea of an AI to ever terminate; it should always try to recover as best as it can and continue. So I think adding a Stop() would be a very bad idea. Rather spend some time in making sure your AI keeps on running no matter what?

Re: API Request: AIController::StopAI()

Posted: 02 Jan 2012 19:15
by Kogut
AIAI terminates with 0/0 on detecting internal error (poor man's asserts), so crash with bug report request is intended.

Re: API Request: AIController::StopAI()

Posted: 02 Jan 2012 19:22
by Zuu
I have some instances where I call a function that doesn't exist with a name that clearly states that it was intentional to crash the AI. Eg KABOOOOM_THERE_WAS_A_PROBLEM_WITH_XYZ().

Re: API Request: AIController::StopAI()

Posted: 21 Mar 2012 01:11
by Core Xii
I like to place debug signs on the map, but when an AI crashes and re-starts, those signs are in the control of another company and cannot be cleaned up by the new AI instance. For this I'd love a Stop() function, just so I could delete all my debug signs.

Re: API Request: AIController::StopAI()

Posted: 21 Mar 2012 07:15
by Zuu
Upgrade to 1.2, and you'll find a new feature in OpenTTD which allow you to hide all competitor signs. It doesn't remove those signs, but make sure you don't see them. Its found in the same menu as you find game settings etc. from within a running game.

Note however, that this feature does not only hide sign signs, but also signs of stations and waypoints. Also you must use the company cheat and move yourself into the AI company so that it becomes the "local company" and have its signs not hided as "competitor signs".


This feature I implemented and submitted as a patch for the same scenario as you have. With lots of restarts of a AI with debug signs enabled, you easily get zillions of signs in the way.

Re: API Request: AIController::StopAI()

Posted: 21 Mar 2012 18:28
by Yexo
Put a try/catch in the main loop of your AI and remove all signs in the catch-block.