top of page
Blog

Captain’s diary #45: Train tracks

Ahoy, everyone. Captain Marek here with more information about trains—our most anticipated feature coming in Update 3. This time, I will tell you all about the train track, design, and history. I also have some train concept art waiting for your feedback.


Trains concept art

We are collaborating with a designer on concept art for our train models. Our goal is to make our trains look like they were created by engineers who have seen trains before but didn't have access to any blueprints—in essence, reinventing them from scratch. This approach ensures that our trains have a unique look and don't resemble any existing models too closely.


Here are four concepts for a diesel train. One design is smaller and more modest, while the other is more "chonky." We are considering offering two of T1 diesel locomotives. The bigger one could be a powerful hill-climber with a lower maximum speed, perfect for tackling steep grades. They are all 10 meters long.

Second is a design for our modern steam engine. We are still not sure whether steam trains will be an option at the end, but we are trying to see how that would look so here are two variants. The first is more rounded which is a classic for steam engines, the second one is more rectangular.

Let us know which one you like and why. And if you have some examples of real-world locomotives that we should take some inspiration from, share them too!


Train track design

Design work for trains, especially train tracks, dates back to 2022, when we first started exploring the idea of trains in the game. This work was then put on a back burner because we had more important things to work on, but this year, we're developing it further.


Discrete vs. continuous

In the early prototype, we were already considering a key aspect of train track building: Do we want discrete or continuous train tracks? By “continuous,” I mean tracks that can be freely constructed using curves and are not limited by the grid. Discrete tracks would be individual, pre-defined, grid-aligned pieces.

Discrete (left) vs. continuous (right) train track example

We’ve been playing and studying many games with continuous track building. I enjoyed making nice and smooth train tracks, which allowed for any direction and turning radius and offered great freedom in designing railways.


However, I also remember times when creating intricate train track crossings with continuous rails was fiddly and frustrating due to imprecise collision detection and bad snapping. For example, building a segment from A to B was impossible, but the same segment from B to A was suddenly okay.


The advantage of discrete tracks is that they provide precise and repeatable construction rules, making it easier to design complex tracks consistently, especially when the palace is tight, and each tile matters. 


Captain of Industry is a grid-based game, and continuous elements often clash with other grid-based mechanics, such as collision detection, copy/pasting, and blueprints. While implementing continuous tracks is technically possible, we decided to go with discrete pieces.


Simple vs. complex pieces

Discrete track pieces have to be predefined, and they will ultimately determine what is possible to build. The question is, should we have fewer simpler pieces and allow their combinations to form more complex crossings, or provide a reasonable set of crossings and not allow tracks to cross?


Complexity-wise, having a set of predefined track pieces that cannot cross each other would be much better. It would allow us to make the tracks as regular entities and have existing game systems handle things like construction, collision detection, collapse, etc. Even our 3D artist was excited about the option of being able to model each switch and crossing manually to make them look more realistic (I guess he is still trying to increase his work security as if that’s even possible) so we investigated this option.

Our 3D artist referred to this picture when pitching how beautiful our crossings would look if they could be modeled manually. In case you didn’t know, these are called railroad diamonds, and you can learn all about them in this video.


So, we started designing different kinds of track pieces and intersections, which went quite well. Every track piece is represented by a curve that must start and end at a grid point, and its end direction must be a multiple of 45°. This would give us an 8-way rail network. We also prepared a similar set for double-track crossings.

The initial set of discrete train track pieces for 8-way travel. The black line is the center curve that needs to start and end on a grid point. Track ties and rails are omitted for simplicity.
An extended track set of double-track crossings.

Note that we can use 90° rotation and flip (reflection) to get all the other orientations that are not shown here.


Next we wanted to consider adding a less tight radius. And then there was a UI issue of how to let players select the correct piece.


And as if this was not enough, we were actually thinking of supporting more than 8 cardinal directions. Having the train network only able to do 45° increments felt too restrictive and not visually satisfying. So we did some prototypes and it turned out that a ratio x:y of 1:2 and 2:1 (27°) is possible and it would allow the track to be laid in 16 directions.

A prototype of half-circles using 16-directional pieces.

And this was the final nail in the coffin for non-overlapping track pieces. It would be completely infeasible to enumerate all the previously designed crossings now with respect to the 27° tracks.


Single but overlapping train tracks (the winner)

So, we scrapped all these prototypes and went back to the drawing board to design a minimal set of pieces that could be used to build all the previously designed intersections and more. Fortunately, it didn’t take too long to arrive at this set:

A minimal set of train track pieces (initial version). Using this set and allowing for 90° rotation and flip, it is possible to build in all 16 cardinal directions, and all previously shown crossings can be composed of these.

Seeing such a small set of tracks was so satisfying compared to the previous sea of pieces, despite being on the hook for custom collision detection to allow their overlap.


This set of tracks was really powerful. The new 16-th of a turn allows for things like shift-by-two-tiles without any additional pieces, and adding a straight piece allows for shifting by any number of tiles. The only special piece needed is shift-by-one-tile.

An example of shift-by-two-tiles being composed by two 27° turns.

Designing turns on a discrete grid

Having 16 directions is fantastic, but it presents a problem regarding turns. Remember, every piece needs to start and end on a grid point. Now, let's think about turns.


Pop quiz: If you draw a circle on a rectangular grid with a radius of, say, 14, how many integer coordinates (grid points) will the circle intersect exactly? Hint: It's going to be at least 4, right? At 0°, 90°, 180°, and 270°, where the point is precisely 14 units from the center. Are there any more? Maybe at 45°? Nope. There are no more exact intersections. The x and y coordinates of a point at 45° will be r * sin(45°), which will never be an integer.


This means that snapping a circle to 8 grid points at 45° increments along its perimeter will result in distortion. Even worse, if we snap a circle to 16 grid points, it will become what we call a “potato” shape. How much of a potato shape you get depends on the radius. Some radii are lucky, resulting in relatively little potato-ation. But some are unlucky, where the perfect circle happens to go right in between grid points, resulting in a true potato.

An example of snapping a circle to 8 and 16 points around its perimeter to the integer grid. Notice that for a radius of 14 units, the distortion is not as bad as for a radius of 18.

From the above diagram, you can see that more grid-aligned subdivisions result in greater distortion. We are still considering offering both 45° and 27° segments to provide a choice between flexibility and smoothness, depending on the player's preference. We might even add 90° turns for completely distortion-free turnarounds. Would you want to use them?

Comparison of 8 (left) vs. 16 (right) subdivisions of a circle. The 16-way is noticeably more potato-shaped but offers twice as many connection points for potential forks.

We examined all even radii from 14 to 30 to determine which worked best when divided into 16 grid-aligned segments. About half of the tested radii were acceptable, but we aimed to limit the available radius options to 2 or 3 to reduce the number of unique train track pieces. Ultimately, we selected 14, 22, and 30 tiles. This decision was made in conjunction with slope constraints, so keep reading to learn more.


Grade

Grade (slope) was important when designing the train train pieces. Dynamic terrain and work with elevation are two of the great features of Captain of Industry, so we need tracks to traverse different heights. As explained in the previous Captain’s diary #44, we decided to go with the steepest slope of 1:8 (12.5% grade), which is on the steeper side but works well in the game. We also decided to include less steep grade options of 1:16 (6%) and 1:24 (3%) to increase depth in the railway design and mechanics (some trains might be too weak to climb steep grades). There were other reasons for these grade options that will be more apparent after you read about grade-turns, but let’s not get too ahead of ourselves.


Slope on straight track pieces is relatively simple, we need 3 types. First is a “ramp start” piece that changes the slope from flat to the 12% grade. Second is the “ramp” piece that just continues this slope. And the third piece is the “ramp end” that starts on a grade and ends flat.


One trick that we use is that the ramp-start and ramp-end pieces increase elevation by only 0.5 tile, while the ramp piece has a delta height of 1 tile. This seemingly arbitrary rule has two benefits. First, the ramp start/end pieces can be only half as long since they don’t need to go as high, saving space. Second, this eliminates a fourth piece that would start and end flat but change elevation by one tile. We can now compose this piece from ramp start and ramp end.

Example of how ramps ending at half-tile heights make ramp start/end pieces shorter and eliminates the up-by-one-tile piece.

To hit the target grade of 1:8, the ramp piece has to be 8 tiles long, which is easy for the 0° piece, but the 27° and 45° straights have to be approximated. The 45° piece length is √2=1.41 and the closest we can get to 8 is by doing 6 √2 = 8.49. The 27° piece has a length of √5=2.24 and the closest we can get to 8 is by doing 4 √5 = 8.94. This means that the diagonal ramp pieces’ grade is not exactly constant 12.5%, but it fluctuates a little. Fortunately, this is not too noticeable.


Curved slopes

And finally, the endgame boss of the train tracks discretization, the curved slopes. As we established in the previous chapter, sloped pieces need to have a length of 8 (or close to it) in order to conform to the standard slope of 12.5%, but the radius dictates the length of turn pieces, and not every radius is suitable due to the “potato-shape” issue.


Our tightest radius in the game is 14 tiles since train and wagon models would start intersecting in corners and it would look too unrealistic to have tighter turns. If we do some quick math, a circle of radius 14 has a circumference of 88. If we want to have 16 subdivisions, that’s 88/16 = 5.5. Well, that’s nowhere near 8, 5.5 distance would result in a grade of 18%. To make matters even worse, our 16 subdivisions are actually not even; they are 27° and 18°, not twice 22.5°, so sloped curves at the 16 subdivisions are a no-go, regardless of radius.


But wait, there's still hope! Let’s consider the 8-way circle subdivision resulting in 45° segments. They are all the same length, and it’s 88/8 = 11. Bummer, that’s also not near 8, but maybe we could make this work since it would be beneficial to have sloped curves. To make a turn of length 11 conform to the 12.5% grade, we need to start at that grade exactly, and then make it slightly less steep, but end right at the 12.5% again. This makes the ramp turn a little “wavy” but turns out it’s not that bad, so we went with it.

Example of 14-tile radius ramp turn that is slightly uneven due to the segment being too long for its slope. Don’t mind the floating track, it’s work-in-progress.

There is actually a way to eliminate the arc length issue. We could simply match the grade to the arc length. For example, our segment is 11 tiles long; we could make it a grade of 1:11 (9%), resulting in a perfectly smooth ramp-turn. The disadvantage of this approach is that it would no longer be possible to connect other pieces to it as it has a unique slope. For example, you could not attach a piece with a different radius. We considered having unique grades to remove slight waviness but ultimately decided against it and to keep a standardized set of grades to maximize track piece compatibility.


And now, after all these explanations, I am finally ready to fully explain why we chose turn radii of 14, 22, and 30 tiles. 14 is the minimum that still kind of works with slopes, but see what happens for the next one. The arc length of a 45° segment with radius of 22 tiles is 138 / 8 = 17, which is pretty much two times 8! This means that the ramp turn of 22 tiles will climb two tiles up at the grade of 12.5%. Even better, it will climb one tile at the half-slope of 6%.


We can do similar math for the radius of 30 tiles and the 45° segment has length of 23.5, which is three-times the standard grade! We can do a ramp turn that climbs three tiles up at the standard grade or one tile up at third-grade. And this is not a coincidence. Now you can fully appreciate why we have slopes of 1:8, 1:16, and 1:24 with radii of 14, 22, and 30 tiles.


Here is a handy table that summarizes the curved slopes support.


Radius 14

Radius 22

Radius 30

45° segment length

11 tiles

17 tiles

23.5 tiles

Supports grade 12.5% (1:8)

yes (+1 height)

yes (+2 height)

yes (+3 height)

Supports grade 6% (1:16)


yes (+1 height)


Supports grade 3% (1:24)



yes (+1 height)

List of track pieces

Finally, let’s enumerate all the unique train track pieces that we currently have (subject to change).

  • [3] three straights, at 0°, 27°, and 45°

  • [3] 45° turns, one for each supported radius of 14, 22, and 30 tiles

  • [2 * 3] 27°/18° turns, one for each supported radius of 14, 22, and 30 tiles

  • [3 3 3] ramp-start, ramp-continue, and ramp-end for all three grades for all three directions

  • [2 * 5] 45° ramp turns (enumerated in a table above), we need two variants of each, one from ramp up and one for ramp down

  • [4] shift by 1 tile, one for 0° and 45°, and two kinds for the 27°/18°


If you sum it up, this results in 35 unique pieces! And don’t forget that all pieces can be rotated by 90° and flipped, resulting in even higher numbers.

All track flat track pieces laid out in a pattern we internally call the “sun”. Note that this does not include straight and curved ramps.

Rail construction tool

Many players were asking us how train tracks would be constructed. We are working on an automated tool that works similarly to the conveyor/pipe construction tool by searching for the best path to the cursor. This diary is getting a little too long, so we will tell you more about this tool in one of the future entries.

An example of an automated track laying tool snapping to an existing rail.

Conclusion

In conclusion, we’ve developed a grid-based train track system that supports 16 cardinal directions, three curve radii, and three grades. The tracks can be freely connected to form complex intersections and train networks. If you’d like to learn even more about the topic of trains in Captain of Industry, you can watch our live-stream recording where I go into more detail. All discussed chapters are time-stamped for easier navigation.

We'd love to hear from you on our Discord if you have any questions or feedback about this topic. I am also streaming (nearly) every week on Saturdays at 10:30 PDT on YouTube and Twitch, so you can also reach out with questions there.


Next time, we will talk about how we handle signaling (train traffic rules); we are actually working on signal-free train routing, so stay tuned!


Captain Marek out.


PS: Captain Marek will be in Tokyo around the 14th of August, conducting research on high-speed trains. If you want to hang out and talk trains (or anything else), shoot me a DM on Discord!

Comentários


bottom of page