API Request: AIController::StopAI()

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
DeletedUser6
Transport Coordinator
Transport Coordinator
Posts: 294
Joined: 23 Jul 2007 15:13
Location: Somewhere in this page

API Request: AIController::StopAI()

Post 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
Last edited by DeletedUser6 on 01 Jan 2012 10:34, edited 1 time in total.
Yay! I'm back! Did you miss me?


...


I thought not.
TrueBrain
OpenTTD Developer
OpenTTD Developer
Posts: 1370
Joined: 31 May 2004 09:21

Re: API Request: AIController::StopAI()

Post 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?
The only thing necessary for the triumph of evil is for good men to do nothing.
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: API Request: AIController::StopAI()

Post by Kogut »

AIAI terminates with 0/0 on detecting internal error (poor man's asserts), so crash with bug report request is intended.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: API Request: AIController::StopAI()

Post 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().
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
User avatar
Core Xii
Traffic Manager
Traffic Manager
Posts: 228
Joined: 08 Apr 2008 09:47
Location: Finland

Re: API Request: AIController::StopAI()

Post 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.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: API Request: AIController::StopAI()

Post 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.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: API Request: AIController::StopAI()

Post by Yexo »

Put a try/catch in the main loop of your AI and remove all signs in the catch-block.
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 9 guests