[Patch] [Update:v3] A Simplistic Approach to Creating Shoreline at Map Edges

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
coherently_olive
Engineer
Engineer
Posts: 14
Joined: 24 Apr 2015 17:16

[Patch] [Update:v3] A Simplistic Approach to Creating Shoreline at Map Edges

Post by coherently_olive »

Hey there,

I wanted to play a game on a map containing a coast line, but I found OpenTTD's map generator a bit lacking for that purpose. In particular, setting map edges to "water" will not really influence how TGP behaves, it will just "cut" into the landmass at the map edges no matter the terrain altitude, and it will do so after the water level has already been determined. This will lead to steep cliffs at the map edges instead of a shoreline. Additionally, and especially for large maps, TGP will create multiple rather evenly sized, evenly spaced lakes on the map instead of a real shoreline.

The attached patch changes this behavior by replacing the default "create water at edges" algorithm with a linear bias rooted at the map edges that have "water" selected to be placed there in the terrain generation window. My algorithm is very simplistic. It is executed after the terrain has been generated and before the water level is selected and works as follows:
Two parameters are configurable, "bias strength" and "bias range". Bias strength allows to influence the maximum altitude change that will be applied to the terrain. Bias range influences how far from the map edges to the center the bias will extend. Bias strength is configured as a number between 0 and 80, where a value of 40 will result in no bias at all. Setting the bias strength to a value below 40 will raise the terrain at the map edges that have "water" selected (so it's kind of a misnomer, but whatever). Setting the bias strength to a value above 40 will lower the terrain at the map edges that have "water" selected. Raising and lowering in this case is not to be understood in absolute terms, but rather as relative to the rest of the terrain, as the bias algorithm is applied before TGP compands the terrain and computes the resulting absolute height levels. Specifically, the maximum bias will be applied at the map edges and will be computed as:

Code: Select all

(average_amplitude - min_amplitude) * ((bias_strength - 40) / 10)
Bias range is an integer between 0 and 16 and configures, in 1/16ths of the map size in that direction, how far the bias extends inwards from the map edge. Maximum bias will be added to the terrain height at the map edges. The bias will then linearly decrease inwards, until the point where we hit the distance from the map edge that is configured by the bias range parameter, at which point the bias applied to the map will be 0.

If multiple edges are selected to have water, then it is ensured that each two directions that are perpendicular to one another don't both apply to the same fields. The way how this is done may or may not lead to odd behavior on non-square maps (but really only if multiple edges are selected to have water), though I have not really tested it (Update: this works now with v3).

I have bumped the savegame version really high in the patch to account for the entries added for table/settings.ini. The actual SV magic number can be configured in a variable that I added to saveload.h

Update: v3
  • Fixed behavior on non-square maps. The bias range in squares is now no longer calculated by using the map length in that direction, but for all edges it uses the map length in the smaller direction.
  • Fixed behavior for SW/SE corners
  • Added a button to switch between builtin / linear bias map edge algorithms in the world creation window
  • Fixed alignment of labels / buttons and dropdowns in the left column in the world creation window
  • Bumped savegame magic number to account for the additional setting in the world generation window
Some Images:
Note that this patch really only shows its strengths in larger maps, but those are a pain to resize and upload. These screenshots were created using a 512x512 map. Also, there's no comparison images to the builtin algorithm, because that one eats some random bits while the linear bias algorithm does not. This will lead to different variety distribution being applied after the different map edge algorithms, making the maps inherently uncomparable.

A sub-tropical coastline that I liked, unfortunately don't remember the settings (water set at the NE corner for sure, the rest are freeform):
sub-tropical.png
sub-tropical.png (370.29 KiB) Viewed 214 times
A "river-valley" situation. Settings: Hilly, Low variety distribution, Medium sea level, Water at NE, SW edges, Smoothness: Rough, No rivers, Coast bias strength 5, Coast bias range 8
scaled-small-river-map.png
(1.07 MiB) Not downloaded yet
Uploading the rest of these on some image hoster because only three attachments allowed.

The following three use basically the same settings as "river-valey", but with a bias strength of 60, water only on NE edge, and different bias ranges to show how the range influences the map:

Bias range 4:
http://imgur.com/UHOVcK1

Bias range 8:
http://imgur.com/5d3vcRb

Bias range 16:
http://imgur.com/O6x6LEv

Some comments on usage

Users may want to try a few random seeds, as the maps generated are not always perfect. In my opinion, the maps above are pretty decent, and every single one of them didn't need more than five tries to generate.
Concerning the two parameters bias strength and bias range: These work together to form the map that you want, one parameter can be set to try and counter-act the negative effects of the other.

Generally speaking (and for single map edges selected), a larger bias range will result in more islands, less lakes and smoother terrain near the coast, but rougher terrain inland (due to the way how absolute height is calculated from the relative height that we work with). Smaller bias range will result in a straighter coast line, less ocean, less islands and more lakes.
A higher bias strength has the opposite effect of a higher bias range and vice versa.
Attachments
linear-shoreline-bias-v3-r27669.patch
(50.86 KiB) Downloaded 79 times
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 24 guests