Ideas for the track editor

This document is under construction.

Tracks

Tracks are basically a threedimensional grid of tiles. For every position in the grid, three integer values are defined: the ID of the tile, the rotation of the tile, and the height of the tile. Because of the third value, much greater height differences are possible than the vertical size of the grid.

Which tile ID refers to which tile file is defined in the track file. Also, some environmental values such as the light sources and the background pictures are set in the track.

Tiles

A tile is a 3D shape with a fixed size of 40x40x12 meter. The graphical geometry and the collision model are basic properties of the tile, which are defined in the tile's .gl file. Other properties that will be defined for tiles are game-rules data (like the direction of the road(s) in the tile, and the penalty time if the tile is skipped), and some validation data about the placement of the tile.

Game-rule data

The description of the road(s) in the tile will be like "there is a road in the tile that starts on the left side and ends on the front side". Every possible valid route should be described, and every route is bidirectional (the inverse direction is also valid). This information can be used to determine if a player follows a valid route.

Validation data

Validation data will be like "this tile can only be placed here if the tile on the left has these properties, and the tile on the back these properties", and so on. Every tile has six boundaries (left, right, front, back, bottom, top), and for every boundary a set of flags is set or unset. Two tiles can only be neighbours if their boundary flags don't contradict.

For example: look at the picture below. The tile on the left is a straight road. On the left and right boundary it has the flag "normal_road" set, so that only tiles with a normal road may be left and right neighbours. It also has the flag "horiz_grass" set, so that tiles with diagonal ground at the boundary or with no ground at all may not me next to it. The second tile has these flags on its left side, so this is a valid situation. On its right it has not set the "normal_road" flag, but it has set the "horiz_grass" and the "solid_bridge" flags. This ensures that the third tile on the base level is also of that type.

So far so good. The problem arises with the continuation of the road. Of course we want to validate that the road continues, but we do not yet have a way to check that, because the third tile on the top level does not have a boundary with the second tile on the base level. The solution is to let the second tile on the ground level have an additional restriction on the left boundary of the third tile on the top level, that it needs to have the "normal_road" flag set.

So, a generalisation is necessary. Every tile will have the possibility to put restrictions to the flags of any boundary, relative to its own position and orientation. For example, the second tile on the base level will have these restrictions:

(0,0)left: horiz_grass and normal_road
(0,0)top: air
(0,0)right: horiz_gras and solid_bridge
(0,1)right: normal_road

Editing

Brick-mode editing

In this mode, the user selects a tile from a list of tiles, and then places it somewhere in the track. The track editor will not refuse it if this creates an invalid situation, but it will complain when the user tries to save the track.

Road-mode editing

This mode is similar to the rollercoaster editing in Rollercoaster Tycoon. The placement cursor is located at the end of the road, and the user can place an extra tile at the cursor position to make the road longer. When a tile is added, the cursor will move automatically according to the route description in the tile (if the road splits, then the editor chooses one of the directions). All tiles around the new tile will be changed in such a way that the boundary requirements of the new tile are OK. This will be done recursively, so that for example if you are building a very high bridge, that all tiles below the road that are supposed to contain pillars, are actually created. A boundary condition for this changing is that existing locations of roads should not be changed, and that the landscape should not be changed. So a straight road can be changed into a straight road with a viaduct on top of it, but it cannot be converted into a tile without a road.

Of course these boundary conditions cannot always be met. A way to solve this is to only present the user the set of tiles that will not give problems when adding them at the cursor location. So the editor needs to simulate the recursive changes before the user chooses a tile, for every tile.

To try it out, I've made the following "before" and "after" pictures:


The blue rectangle is the cursor. The user decides to place a straight viaduct road. The straight viaduct road has the requirement that below it, there needs to be a solid bridge tile, and the present straight road tile does not meet those requirements. That tile needs to be replaced, with the boundary conditions that the road must not be changed, and that the ground must remain the same. One tile that fits the boundary conditions and the solid bridge requirement is the viaduct tile, so that tile is placed. It also fits the left boundary nicely.

Now you can also see why my pictures are wrong. After placing the viaduct tile, the boundary at the right of the viaduct tile is invalid, so in reality that tile should also be changed. One way to do this would be to place a road that goes downward. Of course, to make it completely valid, at the end of that road, another road tile should be placed, and after that another one, etc. etc.. This could grow to infinity, unless we have a "dead end" tile in our collection.

This recursive fixing of the track will be a very interesting, and complicated, programming excercise. It will be like finding the shortest path through a labyrinth. If there is no way to "exit the labyrinth", then the possibility to add the tile should not be presented to the user. If only one solution is possible, then that one should be added automatically, and the cursor should be moved automatically.

Landscape editing

TODO