I want to try out vehicle simulation with:
- grid layout
- grid paths
- larger-than-one-tile objects
- in-between-grid movement
- acceleration and deceleration curves
This means I need to store positions that aren’t on a grid, but maybe reserve the grid blocks so that nobody else can take them. A 2⨉1 object may end up taking 3⨉1 tiles if it’s moving horizontally. But maybe even more if it’s moving along a curved path.
This page is primarily about the size and alignment.
1 Size and alignment#
I’d like trucks and their containers to be sized to match the grid. Here was my initial thought:
A 1 TEU truck would use two grid tiles and a 2 TEU truck would use three grid tiles.
I would like cargo storage to fit the grid, so I will fit 20⨉10 foot containers in a 20⨉20 grid tile. A normal TEU container is 20⨉8 but 20⨉10 works better here.
I can also make container ships line up with the grid.
How about trains? This is where things get trickier.
If containers are 1 tile wide, then train cars are 2 tiles wide, but the gap between train cars means the cars don’t align with the grid anymore.
To fix this I can make containers 7/8 tile wide instead of 1 tile wide:
Now the trains are aligned with the grid but the containers are no longer sized with the grid. This means container ships don’t quite line up anymore:
I would need to add gaps to the container ships:
This isn’t too bad, but it doesn’t look as nice as the gapless version. I’d also need gaps in the storage areas:
That isn’t too bad either, but I think the gapless version looks better.
Either I make the containers smaller to handle the gap between train cars (but then I don’t like the gaps in storage and ships), or I deal with train car gaps. I decided to make the train cars longer so that they line up with the grid again. In real life, these “well cars”[1] are 68ft long to store a 53 ft container, so they have 15 ft of extra length. If I shrink those cars to fit only 40 ft containers, that’d be 55ft long. Making the gap between cars[2] 5 ft would give us 1-tile-wide containers that align with the grid:
Wikipedia says a “flat car”[3] might be 92 ft long to hold four 20ft containers, so adding an 8 ft gap would give us:
In real life, the well car is double-stacked so it can store 4 TEU in 55ft while the flat car is single-stacked so it can store 4 TEU in 92ft. I’m not sure what I want to do about stacking. Container ships and container storage are typically stacked, but that makes it much harder to see everything on the screen. See the Scale section for why I’m not necessarily following real scales.
I think this would be the best solution to keep the storage, ships, and other systems simpler. When vehicles are stopped, the containers should all be aligned with the grid. That means trucks will be:
All containers are 20⨉10, which is 1 tile long ⨉ ½ tile wide.
2 Tracks#
My plan is to have tracks running east-west. No north-south tracks, no 90° turns, no diagonals. Trains are out of the player’s control. They come in from the outside.
But it might be useful to have some switches so that there can be multiple parallel tracks. I made a diagram for this[4] to help me calculate the shape.
3 Roads#
I think roads are going to be more complicated than tracks. One lane will fit inside a tile.
All road tiles need to be one-way. How will vehicles move along them? I think paths get assigned to routes instead of running pathfinding for vehicles on the fly. If there’s something in the way, they’ll stop and wait, not try to move around. I won’t be sure until I try it.
4 Vehicles#
The initial setting will have vehicles from the outside world and also vehicles that serve the station. I’m thinking the 2teu trucks and the trains and the ships will come from the outside world. The station vehicles will be 1teu trucks, and these:
For example, one design would be to use a container crane to move containers off of a train onto 1teu trucks, then have them drive to a container storage area, where a gantry crane picks them up from the truck and moves them into storage.
{I think things will get more complicated if I allow storage to keep containers vertically, because that means I will need both parallel and perpendicular style gantry cranes, but that may be what I need. What if the gantry crane can rotate it at the end? Maybe that would simplify things.}
Other vehicles I see listed in the literature:
- Automated Guided Vehicle (AGV) is similar to a straddler carrier in its capabilties, but it’s self-driving and doesn’t have the human driver with a cab above the container.
- Shuttle Carrier: like a Straddle Carrier, but can stack two high
- Ro-Ro Cassette: haven’t quite found a definitive answer but it seems like it’s a way to make it faster to load the container onto a truck, by having it already attached to the cassette that allows easy connections
5 Scale#
Real life trains and container ships are much larger than what I want in this game. I wrote about this on this blog post[5]. I want to use an unrealistic scale to make the interesting parts of the game larger and the uninteresting parts smaller. I think a 200-car train is not 20 times as interesting/fun as a 10-car train. I’d rather have more 10-car trains. I think a 20,000 TEU ship may be interesting but I think I’ll have to wait and see. I suspect a 2,000 TEU ship will be more fun than a 20,000 TEU ship.
6 Data representation#
This seems like it “should” be easy but I always work with discrete grid movement or with continuous non-grid movement. I haven’t worked with this type of movement before, so I’m going to take it slow and think through the problem before coding. I try to break things down into simpler problems before trying to combine them into a larger solution.
- What are the rules for placing tracks+roads?, except I need to handle road+road crossings and road+track crossings.
- Tracks. This project may be a little simpler than a general simcity-style simulation because I have only east-west train tracks. But it’s a little more complex because those train tracks can have 3x2 branch sections, and some of those may overlap.
- Roads. The roads seem like they’ll be relatively straightforward. They’re all one way sections, each taking up one tile. I’m going to assume no multi-lane roads, so no lane changes.
- Road+track crossings.
- Road+road crossings. For example, an east-moving road crossing a south-moving road. Are turns always allowed, or is that optional?
- What are the rules for vehicle movement?
- Trucks. The path is predetermined, so a vehicle can only move forwards on its path. The main thing to figure out is how a vehicle knows that the road ahead is occupied. It may be simplest for a vehicle to reserve the tiles it’s on plus the tile it’s about to move onto, and then a vehicle that can’t reserve the next tile will have to stop.
- Trains. The tile reservation system may work for trains too. I think OpenTTD implements path signals with reservation.
I will start with a straight line road, no curves or branches. After I sketch out some ideas, I can implement something, then go back to sketching out how to handle curves and branches.
Track: shape: EW | branch NE | branch SE size: derived from shape, 1⨉1 | 3⨉2 | 3⨉2 position: of top left corner length xy(offset) → returns the xy position of any value from 0 to length
There’s a set of track objects.
Vehicle: length wheel positions: [offset, …] relative to head = 0 car positions: ? position: [(track, offset), (track, offset), (track, offset), …] when moving onto a new tile, push a new (track, 0) onto the head when moving off an old tile, pop a (track, track.length) off of the tail to draw each car:
- need to calculate the wheel positions at 2*car, 2*car+1
- rotate the rectangle to make sure xy matches those wheel positions
- draw the rectangle beyond the wheel positions
Then derived from that is a Map of which tracks (there can be more than one) are at that location. Do I need this?
7 Game ideas#
Right now my goal is to produce an animation, and then if I like it, I can work on a simulation. If I were to someday turn this into a game:
You’re given a train station / container port / warehouse to manage. The trains, ships, and trailer trucks are not under your control. The tiles where they come in and out is not under your control. Your job is to design the station to efficiently unload and reload the trains (ships). You can build roads, trucks, cranes, storage areas for this.
I want this game to be about updating the design over time. It’s not about planning everything ahead of time and then building it, then moving on to a new area to build something new. Think of Stardew Valley — you live in the same area and keep revisiting and changing things. It’s not like Minecraft where you build stuff and then move on to a new area.
As time goes on, the needs of the world change. Maybe the public wants beanie babies, and there’s a new train line shipping them. Maybe the world stops using coal, so your coal train stops coming through, but instead there are wind turbine blades that need to be stored differently. Maybe there’s a war, and the war mobilization effort requires a lot more trains for a short amount of time. I want you to be adapting to the needs of the world rather than planning out the perfect layout ahead of time.
My experiences with other building games:
- OpenTTD: I do change tracks and routes over time. It’s harder to change stations over time, but I do that too. In the original Transport Tycoon, stations were not easy to change.
- Train Fever / Transport Fever: game concept is similar to OpenTTD but because it’s not on a grid, it’s much harder to change tracks and stations over time. Instead, if I want to change something, I delete the track and build a new one. Transport Fever 2 does have station customization, which I love, and that’s the aspect of the game I want to capture here. But because the world is not on a grid, things don’t always fit, and I have to delete the station and start over at times. I thought it was just me but I watched videos of other people playing, and they do the same — delete and rebuild instead of updating over time.
- Factorio: not only because of the grid but also because there’s 100% rebate for removing someting, it encourages me to change things over time. I also love that the train stations aren’t single objects, but made up of lots of parts (tracks, inserters, chests, sorters, etc.). I really love designing train stations. However because the optimal designs are independent of the world, once you find a really nice layout, you just copy/paste/blueprint it. That takes away a lot of the fun for me.
- Prison Architect: because so many rooms are needed at the start, I tend to plan everything at the beginning, build it, and then mostly watch the game.
- Cities in Motion / Cities Skylines: impressive non-grid road + track construction ui. The stations are fixed sized objects; you can’t upgrade them over time. Most of the time I felt like I was expanding my city instead of upgrading the existing areas.
- Tropico series: non-grid. Not a lot of transportation, but like many other games, I felt like I was spending my time expanding my city instead of upgrading the existing areas.
- StationFlow: non-grid, polygonal. Focus on transportation. I spend most of my time expanding to new lines and platforms.
- Civilization: I love that the game involves exploration and reacting to things and not all planning ahead of time. The early game feels a bit slow. The late game feels hectic, where I just don’t care about the details of the cities. The mid game is nice. I think there’s a “level of detail” problem here, where the early game has too little to pay attention to, so I’m spending my time waiting for the next turn, while the late game has too many things to pay attention to, so I’m spending my time visiting the cities and telling them to build whatever because I don’t care. This is something I need to keep in mind if I want to focus on upgrading — I don’t want to sit around waiting on fast forward (like many games) or have too many things to pay attention to.
8 Other#
Top-down is what I’d do but I think this kind of game would probably benefit from 3d models with an almost top-down view, so you can see a little bit of the front side of each container and vehicle.
Right now I have square tiles. Would it be interesting to have rectangular tiles, wider than they are high?
- http://www.diva-portal.se/smash/get/diva2:830221/FULLTEXT01.pdf[6]
- - Long Island diagram showing a truck/rail facility - trucks pull up alongside the trains, and then rubber-tyred gantry cranes move containers to the truck
Hm, someone has a video showing vehicle simulation in a container port https://www.youtube.com/watch?v=DQM-4yZVe0c[7] but their truck drivers are scary!
https://www.youtube.com/watch?v=KCwdrB6Q5fY[8] - incoming trucks get a ticket telling them which line to go in, then when they go through, the gantry crane knows which truck is arriving so it can get everything ready; trucks are parallel to the storage
ASC yard? E-RTG yard?
Bram Stolk explains how he represented trains in his hex grid game https://gamedev.stackexchange.com/a/177040/2472[9]