log #3: schedules

Time interval: 2023-01-23/2023-01-28


This week I started working on the schedules, which trains follow. Currently they are specified in a json. Since I don’t want to specify every single time a train will pass through the station, they are specified using a start time, an interval and either a limit time or a count. For example:

    "start": { "dir": "Coal Mine", "idx": 0 },
    "end": { "dir": "Harbor", "idx": 0 },
    "first": [ 4, 21 ],
    "interval": [ 18, 0 ],
    "count": 2,
    "departure": 0,
    "consist": "coal-train"

Will produce two trains, one at 4:21 and the second one at 22:21.

    "start": { "dir": "City", "idx": 0 },
    "end": { "dir": "Harbor", "idx": 0 },
    "first": [ 6, 35 ],
    "interval": [ 2, 0 ],
    "limit": [ 21, 0 ],
    "departure": 5,
    "consist": "passenger-train"

Will produce trains every 2 hours, starting at 6:35 and ending at 20:35.

When I load a schedule, I put all the events in an array, which I then sort. Then I can just check if it’s the correct time to spawn a train.

I plan on adding some kind of randomness to the schedules. There will still be regular passenger service, but some randomly spawned special cargo trains would be cool to have and could make the game more fun.

time travel

I added a an ability to speed up the time by pressing space while having the pocket watch open.


Another item was added - a book. I can put arbitrary text there which can then be read by the player. Currently it can only show plain text, but I’m already thinking of a way to show complex stuff. There are multiple ways to do this:

dispatching trains from platforms

Last week, when a train stopped at a platform, it was the same as if it stopped at a signal. Now the locomotive will become interactable and if you interact with it, it will leave.

In this video you can see the player picking up a book with the schedule and the pocket watch. A signal and a switch is adjusted so two trains don’t collide. Then when the passenger train passes, the cargo train can continue.