New terrain generator

Can you help improve your favourite game? Hardcore C mages, talented artists, and players with any level of experience are welcome!
Hafting
Posts: 9
Joined: Wed Oct 09, 2019 2:54 pm

New terrain generator

Post by Hafting »

I made a new terrain generator, which can be downloaded from https://github.com/Hafting/tergen.

I got bored with the built-in terrain generation, and tried to improve. Tergen makes a height map with some continents, and then simulates plate tectonics to raise mountain ranges at plate boundaries.

Weather simulation is used to set up tile types. Water evaporate, clouds move on prevailing winds, rain falls and form rivers. After simulations, the tallest tiles become mountains, the wettest become swamps, the coldest ice, and so on.

Larger worlds seems to look better, but I usually use 12 opponents in 4 teams, so I need some room. Both hex and square maps can be generated. Maps without WRAPY will have ice at top and bottom, like a Mercator map of earth. Maps that wrap in all directions will have two round poles instead.
Molo_Parko
Hardened
Posts: 158
Joined: Fri Jul 02, 2021 4:00 pm

Re: New terrain generator

Post by Molo_Parko »

Thanks, it's always nice to have options! Perhaps add a sample game/scenario (.sav) file to the repository?

Code: Select all

> make
gcc  -march=native -g -O2 -lm -o tergen tergen.c
tergen.c:1532:4: warning: implicit declaration of function 'sincosf' is invalid
      in C99 [-Wimplicit-function-declaration]
                        sincosf(M_PI*np->angle/180.0, &np->dy, &np->dx);
                        ^
1 warning generated.
Undefined symbols for architecture x86_64:
  "_sincosf", referenced from:
      _init_neighpos in tergen-5d33f7.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [tergen] Error 1
^ Mac OS X and My IDE is out of date deliberately and I won't be upgrading for at least another year.

On a side note, at first glance at the image it appears to generate significantly more narrow strips of land than actual Earth has, which also occurs with the Freeciv (2.6.4) built-in generator, unless one increases the percentage of land dramatically with the Pseudo-Fractal generator. It would be fairly easy to compare that specific issue between an actual Earth scenario terrain map and a randomly generated map. Perhaps by counting the # of tiles which have adjacent or Cadjacent water tiles, or comparing the number of land-tile-strips that total less than say five contiguous land tiles in width, height, or diagonally to get a percentage indication of a map's "wispy-ness". I raise the issue because it is so common with the built-in generators that it is exactly that which drove me to start creating stand-alone generators (because I despise constantly being given a start position on a thin, wispy strip of land. :) )
Hafting
Posts: 9
Joined: Wed Oct 09, 2019 2:54 pm

Re: New terrain generator

Post by Hafting »

Thanks for testing. The compile error is strange. I include math.h, which defines sincosf. And the "-lm" ought to link math libraries. Perhaps Mac OS X does things differently? I don't have a mac, but I'll be happy to take som tips from anyone that do. sincosf() can be replaced with sincos(), if that is available. sincosf() is a speed optimization, as we don't need the double precision here.

The real world have some narrow stripes. There may very well be too many in my map though. Plate collisions raise a ridge. On land, this becomes a mountain range. If it happens in the sea, you get a stripe of shallow water or a land stripe. A better simulation of overlapping plates, could yield thicker ridges and wider land.
Molo_Parko
Hardened
Posts: 158
Joined: Fri Jul 02, 2021 4:00 pm

Re: New terrain generator

Post by Molo_Parko »

Same error for sincos as with sincosf.

Image

Earth does have a few thin strips of land, but those are exceptions to the vast majority of the land which is the seven continents. If all the wispy little strips of land on Earth were added together, they might equal Australia (our smallest continent) for total size. When Freeciv generates a map and the majority of land is in thin little strips, it doesn't look like a real "world" to me.

I'm still mulling over how to rate the wispiness of a map, and leaning toward it being dependent on the amount of wispy land features (or very small islands) as compared to the size of larger land masses (if there are any.) So if it is merely a very small scale rendering of a world (even Earth, as an example) then quite a bit of the land would be small, so to rate the wispy-factor would first require determining if there is any large land or if most/all of it is thin or very small.
Hafting
Posts: 9
Joined: Wed Oct 09, 2019 2:54 pm

Re: New terrain generator

Post by Hafting »

Here is a working sincosf().

void sincosf(float x, float *sin, float *cos) {
*sin = sinf(x);
*cos = cosf(x);
}

As for terrain realism; I agree that my terrain is not perfectly realistic. I have some ideas for improvements, but I also have real work to do. It could take some time.

When you say that most of the terrain is thin stripes, do you mean 1-tile thick stripes of land, or that the continents are much wider than they are tall?

Are you using an isometric view? (ISO or ISO+HEX) ? In these views, freeciv makes the map half has high and twice as wide. A terrain not made with this in mind, will be very stretched. I believe I made this mistake; I wrote the terrain generator for non-hex non-iso first, and added the rest later. For a quick fix, don't use the isometric view. The continents will be less stretched. Or wait, I will look into this.
Molo_Parko
Hardened
Posts: 158
Joined: Fri Jul 02, 2021 4:00 pm

Re: New terrain generator

Post by Molo_Parko »

Adding the sincosf worked. The (default) generated scenario is for v3 of Freeciv and not recognized by v2.6.4 (which I use.) I transferred the map over to a v2.6.4 file which is attached to this post.

Image

By wispiness, I mean that the land areas tend to be narrow strips such that it is difficult to find a 5x5 (city radius) area that is entirely land. The vast majority of cities on such a map would include water tiles. Neither of those two conditions is even remotely close to the planet on which we live, and thus all such maps look "wrong" to me. I tend to use the classic layout for maps, but am also familiar with the iso, hex, etc. I don't like them as much as the original square tile map view.
Attachments
Tergen26.sav.zip
(11.11 KiB) Downloaded 112 times
Hafting
Posts: 9
Joined: Wed Oct 09, 2019 2:54 pm

Re: New terrain generator

Post by Hafting »

I have fixed some bugs that gave flat continents with isometric topologies, as well as some other bugs. If you want mostly landlocked cities and realism - well, the real world has about 71% oceans. If you want to keep a realistic amount of oceans too, you need to make rather large maps. Or you could increase the land percentage a lot. A map with little or no sea is not "realistic", but may perhaps be seen as a partial planet suitable for your style of gaming?

I have made some demo scenarios and put them on github. The bigworld file is a 150x300 tile world. It has a couple of large continents where you can put quite a few cities away from the sea tiles. There is also bigworld screenshot where you see one of the better spots for a land civilization.

Bigworld was generated with these parameters:
tergen Bigworld 3 2 150 300 2 30

For a world with square tiles and a bit less sea:
tergen Bigsquare 0 1 200 200 2 40

As you see, there is now a parameter for naming the map. The name show up in the scenario list in the freeciv GUI.
Molo_Parko
Hardened
Posts: 158
Joined: Fri Jul 02, 2021 4:00 pm

Re: New terrain generator

Post by Molo_Parko »

Well, as I said, it is good to have options. My "style" of gameplay vis a vis Freeciv is "vive la difference", which is to say some sort of fundamental difference between any map and the next to the extent that one must constantly modify one's strategy to overcome some situational issue. The built-in Freeciv generator tends to produce very similar maps unless the options are shifted from one extreme to the other, and even then the results amount to only two fundamentally different map styles -- one mostly water, the other mostly land and always mixed terrain (setting the values for hills and mountains to 0, as example, does not result in a map without hills or mountains, so there is never an extreme difference such as a complete lack of hills and mountains vs a complete lack of "flat" land tiles. It is a difference in degree instead of a major change, and that does not affect gameplay radically, thus one may play any Freeciv generated world map using the same strategy, and with the same result (winning) and that is simply boring to me.) In short, I like maps with major fundamental differences from one to another (an "X factor", if you will), which disrupt a player's "usual" strategy. Far from saying that every world must be like Earth, I am saying that Freeciv (built-in) generated worlds are simply too similar to one another, and thus each lacks any truly distinctive "character", and that quickly becomes boring.
Molo_Parko
Hardened
Posts: 158
Joined: Fri Jul 02, 2021 4:00 pm

Re: New terrain generator

Post by Molo_Parko »

Comparing 3 maps. The first is from the "Earth V2 Classic Large" scenario file. One is Freeciv 2.6.4 generated, the other is tergen generated.

All 3 are the same size and dimensions, same number of total tiles, same topology, etc. I extracted all possible 5x5 tile areas and checked for quantity of land tiles vs water tiles (actually water +i +a since settlers can't build cities on arctic/glacier or inaccessible tile types.)

Then for comparison, I gathered the data from each map, which helped me to figure-out the best indicators of "wispiness", which are:
1] # of 5x5 grids containing only land tiles. Higher # is less wispy.
2] # of land tiles adjacent water (horizontal and vertical only, not diagonal.) Lower # is less wispy.
3] The higher the # of "only land" and "no land" (only water) 5x5 grids, the more likely that land is gathered into large continents rather than intermixed wispy strips of land and water.

All 3 maps have the following few stats in common:
xSize=160
ySize=90
# of tiles 14,400
# of 5x5 grids (without overlap): 576
# of 5x5 grids (with overlap, except partial areas at edges of map): 13260
terrain tile types on which a city may be built: dfghjmpst (hereafter called "land")
terrain tile types on which a city may not be built: ai :+ (hereafter called "water")


###############
Earth v2 classic large 160x90 scenario

Tiles
land tiles: 4266 (30% of total tiles)
water tiles: 10134 (70% of total tiles)

longest contiguous row of land tiles:69 on line:17
longest contiguous column of land tiles:42 at column:74

Land tile adjacent water tile:1320

Grids:
majority land: 3935 29%
minority land: 3153 23%

only land: 1824 (subset of majorityLand) 13%

no land: 6172 46%
some land: 7088 53%




###############
Fc gen 160x90 defaults (except topo and size)

Tiles:
land tiles: 4387 (30% of total tiles)
water tiles: 10013 (70% of total tiles)

longest contiguous row of land tiles:39 on line:45
longest contiguous column of land tiles:33 at column:56

Land tile adjacent water tile:1744

Grids:
majority land: 4039 30%
minority land: 4435 33%

only land: 1193 (subset of majorityLand) 9%

no land: 4786 36%
some land: 8474 64%




###############
Tergen 0 0 160 90

Tiles:
land tiles: 3773 (26% of total tiles)
water tiles: 10627 (74% of total tiles)

longest contiguous row of land tiles:48 on line:57
longest contiguous column of land tiles:28 at column:100

Land tile adjacent water tile:2278

Grids:
majority land: 3331 25%
minority land: 5156 38%

only land: 497 (subset of majorityLand) 3%

no land: 4773 36%
some land: 8487 64%




Image
^ Freeciv 2.6.4 generated map

Image
^ Earth v2 Classic Large scenario map

Image
^ Tergen generated map
Last edited by Molo_Parko on Sun Oct 15, 2023 5:04 pm, edited 2 times in total.
Hafting
Posts: 9
Joined: Wed Oct 09, 2019 2:54 pm

Re: New terrain generator

Post by Hafting »

Interesting comparison of maps. If you want more city-friendly terrain, consider increasing the "temperate" parameter. That way, you get less icy regions. Obviously, increasing the land percentage will also help. For example:
tergen testmap 0 0 160 90 0 40 30 70

The 40% land setting thickens the continents a bit, pulling more continent out of the shallow waters. The 70% temperate thaws a belt of ice for more useful land.

To get different placement of random-generated continents & ridges, change the random seed (the "0" between 90 and 40). You may get a completely different world, but with the same ratios of mountains, hills, low land and seas.

I found the freeciv terrains a bit boring and repetitive, so I made this generator. It may be repetitive in its own way, but at least it is different from standard freeciv. The hillmountain percentage can be varied from 0 to 100, getting everything from completely flat to only hills & mountains.

For me, the sea transport (and food from fishing) is important, so I often put my cities at the coast. If the game gets too easy, I arrange to have several AI opponents in teams. That way, I cannot out-research them immediately.

You seems to want continents with room for many land-only cities? Currently, the number of continents does not vary much with size, so a larger map have bigger continents. (If the map is too big, consider more opponents :-) I should perhaps have a way of varying the initial continent generation, in order to have either a few big or many small ones. Some wants every player to have his own island too.
Post Reply