FS#2802 - Inability to connect roads/tram tracks properly with NoAI

Attached to Project: OpenTTD
Opened by Bilbo (bilbo) - Friday, 03 April 2009, 20:31 GMT
Last edited by Thijs Marinussen (Yexo) - Thursday, 20 August 2009, 16:03 GMT
Type Feature Request
Category Script → NoAI
Status Closed
Assigned To No-one
Operating System All
Severity Low
Priority Normal
Reported Version trunk
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


NoAI API currently contains two functions for building roads: BuildRoad(start,end) and BuildRoadFull(start,end) (plus corresponding function for oneway roads)

Consider situation in the attached example:

AI builds road. Later, AI builds depot, but due to momentary traffic on the road, the connection from the depot to the road is not built. AI can detect this with AreRoadTilesConnected and after some time it tries to rebuild the part of road to connect to depot.

But BuildRoad builds from center to center and BuildRoadFull builds from edge to edge. There is no function to build from edge to center or from center to edge.

I also tried to build center-to-center, with one tile being the tile right before depot and second tile being the tile at which depot is placed. It failed (can't build road inside depot), as it would fail the same way for a human player.

I suggest either adding function to build from edge to center and from center to edge, or function to build one individual "halfpiece" of road on single tile (since you can use ordinary edge-to-edge or center-to-center call and then add your single missing piece with an extra call). Also, analogous function to remove road would be needed as well.

Without such possibility, the closest you have is full-to-full, which at best may just look ugly (road protrudes farther than you need to), at worst it may create some unwanted connection (you connect to some existing railway crossing and if the newly created route is shorter, your vehicles got smashed there sooner or later)

This can be even more issue with trams, as trams can turn around if the tile is a half-tile, but can't turn around if it is full tile and next tile does not contain connecting tram track. Ability to correctly place (or remove) only half of the tile can be very important with trams.
This task depends upon

Closed by  Thijs Marinussen (Yexo)
Thursday, 20 August 2009, 16:03 GMT
Reason for closing:  Implemented
Additional comments about closing:  In r17239. It's now possible to use AIRoad.BuildRoad(depot_tile, tile_in_front_of_depot).