Friday Facts #68 - The trains

Posted by kovarex on 2015-01-09

Albert is back from Spain and Cube is back from vacation, so the Wube is not lonely. Once Tomas gets back from India and Robert moves here, the place will feel fully populated again :)

0.11.9, 0.11.10 and future 0.11.11

We had 2 releases this week, as the 0.11.9 (released on monday) had some critical gui related crashes because ... well .. because I decided to do some gui refactoring and cleanup that I believed to be harmless, silly me. The 0.11.10 that we released on tuesday fixed these problems and it seems that this one is not as heavily broken as those before. So we can concentrate on the long term bug fixing, like fixing multiplayer communication corner cases, desyncs and the train bugs. The next batch of fixes can be expected next week.

We have high hopes of stabilising the 0.11 until the end of January as we really miss doing some other work than bug fixing.

The Train bugs

There were several train related bugs in our bug report queue, but we were avoiding these, as getting deep into the train logic is quite hardcore. I couldn't avoid it forever, so the time of train fixes have come.

The core problem with train logic was, that trains were updating the direction (left/right/straight) only once per logic update, but when the train moved fast, it could move past 2 or more junctions in one step, and get off the planned path. The result was confused train that didn't know what to do and a lot of reserved orange signals on the other path that he missed.

There were a lot of other problems related to train movement, path finding, train collision resolving etc. It didn't crash the game immediately, but led to non standard (buggy) behaviour.

The automated tests now contain some path finding and usage of super high speed locomotives, so the mods with fast trains should work correctly now as well.

Preserved train stations

The problem with train schedules was, that once the train station was removed and built again for whatever reason (to be repositioned, it was destroyed by biters but rebuilt by construction robots etc.), the station was removed from all the schedules. It is now just marked as inaccessible and the train skips it until it is rebuilt again (or removed from the schedule manually).

Better train path finding

The current train path finding had just one very primitive way of avoiding blocked segments directly in front of the train. Such paths were always considered as the worst paths possible, even re-routing 5000 tiles around all the huge map was considered better than waiting 5 seconds for the train in the station to get away. The current path finding puts penalties as addition to the path length when searching for the route:

  • When the rail block is occupied by a train -> penalty of 2 * length of the block divided by block distance from the start, so the far away occupied paths don't matter much.
  • When there is a train waiting in the station -> penalty of 6 tiles per every remaining second in the station (This also helps the train to choose the best station even when all of them are occupied).
We can add more logic here, but the trains are working fine now, so let's leave it for later.

P.S. By studying the train setups, I also realised that pre-signals are really needed, I will try to squeeze them into 0.12.

Screenshot from the fascinating rail centered savegame that I used for stress testing.

The regular comment thread at our forums is ready.