IncredibleHannes / TPF2-Timetables

The Timetable mod for Transport Fever 2
GNU General Public License v3.0
32 stars 18 forks source link

Support multiple trains in the same station #97

Closed Gregory365 closed 1 year ago

Gregory365 commented 2 years ago

Features

  1. Timetables supports the ability to have multiple trains from the same line in the same station and the same time.
  2. Vehicles pick the nearest arrival time on the timetable (could be in the past or the future)
  3. Vehicles pick the next consecutive available arrival time when the nearest time slot is being used by another vehicle
  4. Updated colors to support the new Spring Update line colors

Example

Timetable is (in format [arrive, depart]): [01:00, 04:00], [03:00, 06:00], [05:00, 08:00], [07:00, 10:00]

A vehicle arrives at 02:45 and picks the [03:00, 06:00] slot as its the closest and will depart at 6:00.

Another vehicle arrives at 03:30 and picks the [05:00, 08:00] slot as it is the next consecutive available slot after the nearest slot of [03:00, 06:00]. This train will depart at 8:00.

Issues

Causing the game to crash for some

Vehicles will forget their time slot upon a Save and Load cycle as currently waiting vehicles aren't stored. Therefore, lines with large gaps between arrival and departure times and high frequency may have vehicles with longer than ideal wait times after initially loading into a world. Not an issue. Currently waiting vehicles are stored (only on the develop branch)

Vehicles depart too late as they pick a timetable slot that is later than expected. Resolved. Issues was caused by arrival time only being calculated once passenger loading/unloading was complete. Arrival time now calculated instantly

Vehicles fail to be held for departure and departs without ever being stopped. Resolved. Issue was caused by a vehicle calculating its departure time before arriving at the next station. Departure time now calculated at the same time as arrival time.

Technical Info

Gregory365 commented 2 years ago

Added 3 commits in response to #99.

  1. Cleaned up default state by adding in currentlyWaiting object to it.
  2. Made the timetable.waitingRequired() method more robust to a timetable object in a bad state.
  3. Updated how coroutines are resumed to reduce the number of unnecessary calls to coroutine.resume() and subsequent error messages in the games log.