REPEATFEED RᴇᴘᴇᴀᴛFᴇᴇᴅ RepeatFeed

It’s been some time and I’m sure Discourse will tell you that too by inserting a snarky “1 MONTH LATER” comment right above this post.

Let’s get back on track. hohoho.

I’ve been paged to this little thread and I’ll write an answer over there as soon as this post is done, because I want to link to this post. Being prepared is everything.

Right, so how feasible are locomotives? Pretty. You’ve seen the (Unity3D-made) trailers and some obscure screens. What I haven’t posted up until now was the original video that I’ve sent to Tom the same day I’ve opened this thread, in fact. So here it is, For Tom With Love:

It’s a simple video showing three stages: Arrival, unloading, departure. The train arrives, is unloaded by workers, and then departs again. Both arrival and departure are currently triggered by console commands, but are also wired to (daily) timers. Let’s talk about structure.

Railroad Service

The core of the whole operation is the railroad service, responsible for about everything. At the beginning, only straight lines will be possible. Tunnels and bridges are supposed to be there, but curves are a bit difficult. The main issue with curves is, well, there’s no “round” thing, so trains themselves can’t really go around curves. It would look odd. Of course, this can be avoided by having huge curve radii, but that’s also odd. Plus, having a single, straight line makes things much easier.

Building the tracks

You can tell him “Build me a railroad starting at (X, Y, Z)” and it will build tracks properly until it runs out of map. In this example map, I’ve artificially added “more” to the map to get a better view of the arrival/departure process.

In the future, the service would also build bridges and dig tunnels. In an even further future, it wouldn’t just do it, but rather hand out tasks to an AI to do it.

Managing the trains

Trains are spawned by the service, currently one at a time. Trains can spawn at any side of the railway driving towards the opposite end. They’re spawned properly (i.e. no cart is “off the rails”) and they’re despawned properly (upon reaching the edge) so it doesn’t look “odd”.

Each train consists of one locomotive, one tender cart and a random amount of other carts. In the video above, only one type of cart is used, the open goods cart - there are multiple, including the passenger cart seen in the previous videos. This cart is special as it has goods loaded that can be unloaded. These can be locked however, so only certain goods can be unloaded - the others are only decoration (as of now).

Once the train has been created, it’s schedule is set (see below). This is adjusted so the locomotive precisely always stops at the same location.

The train component

The heart of the whole deal, the train component is stuck to an invisible entity that represents the train. This component is responsible for moving it and therefore keeps track of direction, velocity and acceleration. It also has a schedule, which contains orders in the form of “X meters into the track, do Y” - for example, “break with 1 m/s after 150m”. The schedule is usually set by the railroad service. The train component itself does nothing except respawning, all input comes from the outside.

The cart component

A rather simple component whose only real purpose is to tag along and make some neat collision boxes.

The goods cart component

More interesting, the goods cart component can load goods. The railroad service (or whatever is “filling” them) tells them what they should load (and where) and they’ll make sure the entity is kept there. Currently, this means they’re just creating the entity at said location.

Entities can then be unlocked after the train has stopped, becoming available to the player. In this case, the cart acts pretty much like a stockpile. So it’s possible to say “I want log #3 on cart #5 to become available to the player” over the API.


Tie that up with some AI tasks and that’s what you get. It’s not that difficult because trains themselves aren’t too complicated (at least, in theory). There’s some issues unsolved however:

  • Putting items on a cart is a bit more complicated than putting them on. Because that’s tied to the inventory stuff and they’re doing a rewrite of that just now, I’ve put that on hold.
  • Animations are a pain. Especially because there is currently little to no API available, all animations need to be synchronised with the velocity/acceleration the train is currently going at. It’s not (really) possible to just say “Alright, move the animation to frame X”. At least, I didn’t stumble across a way to do that.
  • Stonehearth, in its current state, is not big enough to warrant more than one train station, so the only real train destinations are all fictive (or “AI”, depending on your point of view).
  • The whole thing still has a few concept flaws.
16 Likes