1. When to start decelerating due to issues ahead (stop, signal, slower vehicle).
2. Best way to track position (I'm presently doing a coordinate system for vehicles and another for map tiles with a 1:24 relationship).
3. Curve to take through turns.
4. Rate at which to accelerate/decelerate.
5. Is it best to hold all map squares for the path with the vehicle, or just ones where it has to make a choice?
1. Vehicles only look a single tile ahead. They stop very quickly when encountering a signal or the end of the line. The only exception are stations: When a vehicle is on a station tile and it wants to stop at that station, it looks ahead the complete platform for the end. If the platform is very short, the train will again stop very quickly.
2. OpenTTD does the same. A tile is divided into 16 subunits.
3. Road vehicles just have table of positions (and directions) on a tile. The vehicle knows in what state it is, and at what state it enters the next tile. Deviating from the table is only possible at the border of tiles. There road vehicle can decide to turn around, or to pick one of the routes on the next tile.
4. Today vehicles have weight, power, a maximum tractive effort and a maximum speed. This controls acceleration according to usual (simplified) physics.
5. There are two different methods for this in OpenTTD.
- Generally vehicles don't store any path. They decide upon entering a tile which direction to take.
- If there is only one direction they continue along that.
- If there is a junction they ask the pathfinder what direction to take, which computes the complete path from the current point to the destination using A*, and a cost function.
- The input of the A* is the complete track network, but with stretches of track contracted, if there is no junction on the track. The static track cost is cached per stretch.
- This type of pathfinding works fine, if there are not many junctions. For ships where every water tile on an ocean is a junction, it works quite bad
- For trains there is a different method. The pathfinder is not asked at junctions, but at signals. It then stores the path up to the next signal on the map, i.e. at every junction it marks which choice to take.
- This generally works only if there is only one vehicle between signals.
So, to summarize:
- Vehicles only make choices between tiles.
- While traveling over a tile, the vehicle has time to decide what to do at the end of the tile, whether to stop, reverse or enter the next tile. This decision usually only makes use of the current and the next tile.