NoAI Framework

NoAI Main Page


Development milestones
Suggested API changes

AI Programming

API Documentation
info.nut file
main.nut file
Using the road pathfinder
Using the rail pathfinder
Saving / Loading data
Things you need to know
Home page
Common mistakes
Coping with OTTD errors
AI Libraries
Forum FAQ
AI Behavior
ShortNames in use


Comparison of AIs
See forum
See BaNaNaS
All articles in NoAI category

WrightAI is a simple example AI. Currently there are many better AIs available, but if you want to start with writing you own AI this is a nice starting point. WrightAI was the first working AI for the NoAI framework that actually builds something useful and that is where the name came from (wright is archaic English for craftsman or builder).

Working Description

The first thing it does after starting is sleeping one tick, this is because creating an AI company is seen as a DoCommand, so you can not execute any other DoCommands on that tick. But if you do, OpenTTD throws an assertion failure and crashes.

After that, it names itself to WrightAI #x (where x is a free number) and prints out a welcome message:

  /* Give the boy a name */
  if (!AICompany.SetCompanyName("WrightAI")) {
     local i = 2;
     while (!AICompany.SetCompanyName("WrightAI #" + i)) {
  this.name = AICompany.GetCompanyName(AICompany.MY_COMPANY);
  /* Say hello to the user */
  print(this.name + ": Welcome to WrightAI. I will be building airports all day long.");

It then takes a loan, makes a ticker system and calculates the time it may sleep every time and makes the loop:

  while(true) {
     /* Loop is executed here */
     ticker += sleepingtime;

The loop contains the following things:

To check where an airport can be build, it constructs a grid over the best 10 towns with over 500 population, and checks if it can build an airport on any of that grid tiles.

See also