NoAI Documentation

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
User avatar
RailwAI
Engineer
Engineer
Posts: 40
Joined: 22 Jul 2018 20:30
Location: Headquarters

NoAI Documentation

Post by RailwAI »

Sometimes, I find a function in the NoAI Documentation that I want to use, but then it seems that it behaves different from what I expected.

In the following functions, could the behaviour be adjusted, or the documentation updated? I might add more things to the list by editing this post.
  1. AIVehicleList_Station(StationID station_id) - This function only works for the "own" company, but that is not stated. My AI would like to see if any vehicle has orders to a station of another company. Human players can do this by clicking a station of another company.
  2. AIRail.BuildSignal (TileIndex tile, TileIndex front, SignalType signal) - If there is already a signal, its direction will be turned, similar to building signals for human player.
  3. AIMarine.AreWaterTilesConnected (TileIndex tile_from, TileIndex tile_to) - Fails when two locks are built, blocking eachother. This function will return true between the lock tiles, despite the documentation says "whether a ship vehicle can travel from the center of the first tile to the center of the second tile."
  4. AIStation.GetLocation(StationID station_id), AIStation.GetName(StationID station_id) - Doesn't work for stations of another company
  5. AIStation.HasCargoRating(StationID station_id, CargoID cargo_id), AIStation.GetCargoRating(StationID station_id, CargoID cargo_id) - Doesn't work for stations of other companies either

User avatar
RailwAI
Engineer
Engineer
Posts: 40
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: NoAI Documentation

Post by RailwAI »

Another one:
- AIRail.RemoveRail - this function returns true, even if a train was on a part of the railway track that was requested to be removed. Then, all track parts that were not occupied by a train are removed, leaving the track parts with a train on it. The same behaviour happens when a human player tries to remove rail tracks that are partially occupied by a train.

User avatar
RailwAI
Engineer
Engineer
Posts: 40
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: NoAI Documentation

Post by RailwAI »

..and:
  • AITile.IsWaterTile - returns false when a buoy was placed on the tile.

User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9390
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: NoAI Documentation

Post by planetmaker »

Thank you for pointing out the non-obvious limitations :) Can you create amendments to the documentation and open a pull request on Github, please?

(it can certainly be discussed to change some behaviour - but that's a backward incompatible change, so needs consideration or new names for new functions)

User avatar
RailwAI
Engineer
Engineer
Posts: 40
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: NoAI Documentation

Post by RailwAI »

There is sometimes a difference between non-obvious things (like, expenses are negative) and the unexpected things (like, a buoy is no water according to the API).

Maybe there will be one day I'm going to start updating the NoAI documentation for you (not yet this week) :D

xarick
Transport Coordinator
Transport Coordinator
Posts: 283
Joined: 26 Feb 2015 00:52

Re: NoAI Documentation

Post by xarick »

AIMarine.AreWaterTilesConnected (TileIndex tile_from, TileIndex tile_to) - Fails when two locks are built, blocking eachother. This function will return true between the lock tiles, despite the documentation says "whether a ship vehicle can travel from the center of the first tile to the center of the second tile."
<Samu> I cannot reproduce point number 3 of this viewtopic.php?f=65&t=83631
<Samu> or i misunderstand the request
<Samu> "Fails when two locks are built, blocking eachother." - that's the intended behaviour
<Samu> "This function will return true between the lock tiles" - that's not true
<Samu> it returns false on my testings
- AIRail.RemoveRail - this function returns true, even if a train was on a part of the railway track that was requested to be removed. Then, all track parts that were not occupied by a train are removed, leaving the track parts with a train on it. The same behaviour happens when a human player tries to remove rail tracks that are partially occupied by a train.
<Samu> "- AIRail.RemoveRail - this function returns true, even if a train was on a part of the railway track that was requested to be removed." I couldn't reproduce this, I have a feeling he misused the function
<Samu> "Then, all track parts that were not occupied by a train are removed" - i think he removed the wrong track, that's why it returned true
<Samu> train was not on the track
EDIT: Nevermind, it was I who misused it. I thought it was only for single tracks, but it can remove a whole line of tracks. I confirm then, that only the unoccupied tracks are removed, and at the same time the function is returning true.
AITile.IsWaterTile - returns false when a buoy was placed on the tile.
<Samu> "AITile.IsWaterTile - returns false when a buoy was placed on the tile." this one is a bit tricky
<Samu> should be renamed perhaps?
<Samu> ah, I see where he's coming from
<Samu> on the AI side: return ::IsTileType(tile, MP_WATER) && !::IsCoast(tile);
<Samu> on OpenTTD side: return IsTileType(t, MP_WATER) && IsWater(t);
<Samu> that means a ship depot is true for AI side, and false for OpenTTD side
<Samu> and a buoy is false on both
<Samu> since it returns true for ship depot, maybe one would also expect it to return true for buoy
<Samu> it also returns true for locks
Formerly known as Samu

User avatar
RailwAI
Engineer
Engineer
Posts: 40
Joined: 22 Jul 2018 20:30
Location: Headquarters

Re: NoAI Documentation

Post by RailwAI »

Thanks for the feedback! Following the current documentation: for AITile.IsWaterTile I would expect true for any tile with water, including buoys and locks (docks could be questionable).
The error I found in 2018 with AIMarine.AreWaterTilesConnected seems indeed to be solved in openTTD 1.9.x

xarick
Transport Coordinator
Transport Coordinator
Posts: 283
Joined: 26 Feb 2015 00:52

Re: NoAI Documentation

Post by xarick »

It's better to use AITile.HasTransportType(tile, AITile.TRANSPORT_WATER) if you're looking for tiles in which ships can walk.
Formerly known as Samu

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: kamnet and 2 guests