TerraGenesis Perlin

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
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

TerraGenesis Perlin

Post by richk67 »

Here is the TerraGenesis patch with Perlin noise. It creates some really lovely terrains, and is a complete replacement for the current terrain generator. There is a new switch panel in the Configure Patches for "Terrain", letting you switch between the original and new terrain generator.

TerraGenesisP works in the Scenario Editor and the main "New Game" selection. I havent tried starting a new network game with it, but it should work there as well.

The terrain generation works off 4 main variables:
Random seed: TGP terrains are not truly random - but use a random seed between 0..65535. You can enter this directly, or press the "Random" button to get a new one.
Terrain Type: Very Flat - Mountainous. This sets the maximum amplitude permitted. Due to the way the Perlin noise is created, you may have a flat area for your mountainous terrain. If this is the case, try a different random seed.
Sea Level: Very Low - High. This raises or lowers the apparent sea level, and re-scales the land to match. Again, the Perlin noise generator may give you a massive ocean on "Very Low", or a mountainous plateau with no water on "High" (unlikely).
Smoothness: Very Smooth - Very Rough. This sets how much variation you will have from little variation, to many smaller variations.

I also include the Landscape type selection, and the map size dropdowns on the Landscape Generation screen.

The great thing about this in the Scenario Editor, is that you can keep the same random terrain but try it in SubArctic, Tropical, Toyland, etc. When you are happy with the terrain in the Scenario Editor, nip back to the main menu, and start a New Game with those terrain parameters.

Tropical has a special feature to ensure that some areas are desert. Starting at halfway across the map (diagonally), the maximum terrain height is reduced steadily (its actually a COSine wave), until the terrain is lower and flatter. This can have the effect of flattenning the only mountains in the map - I may add a ON/Off button for this feature later.

Also, as the randomness is predictable, you can "share" a map by just giving its seed number. Click on the blue seed, and enter a new number. Try it with the "8918" terrain in the example pictures.

Please Note: this code is still in development, and contains commented sections that will eventually be removed from the final patch.

Have fun with it. Please tell me of some really good terrains you find. (I like 55123 on a large map size - good variety of mountains and sea.)

[edit] Latest update, Mar 14, 2006. Much improved mountains and lakes handling, added map border randomisation. Pretty much there.

[edit] Mar 15, 2006: Further improvements on the coastline, bug fixes.

I have also changed the behaviour of the Desert terrain. It now produces a desert valley between two ranges of mountains (on mountainous/hilly). As usual, desert climate doesnt respond well to "flat" or "very flat", as the whole map tends to go desert.

[edit] further update: Added patch setting for "Max distance from edge for Oil Refineries". With the more indented / uneven map edges, it was finding it difficult to place the oil refineries. This lets you select how far from the edge they can be: range 12-48. (default 16).

Also made New Game pick a random number for the seed, but Scenario Editor keeps last used.

[edit] Mar 28. A few minor edits. Added ability to set random seed in config file. Also, if seed=0, TGP picks a random seed. Ideal for dedicated server.
Attachments
New Terrain Generation interface
New Terrain Generation interface
ss0TgenPv1.png (41.18 KiB) Viewed 18360 times
Desert terrain map. Mountains reduce smoothly to a desert valley, then back up to mountains. (on Mountainous of course!)
Desert terrain map. Mountains reduce smoothly to a desert valley, then back up to mountains. (on Mountainous of course!)
Unnamed, 1st Jan 1994.png (23.55 KiB) Viewed 17268 times
TerraGenesisPerlin_5048.patch
TGP at 5048
(50.38 KiB) Downloaded 699 times
Last edited by richk67 on 30 May 2006 21:44, edited 10 times in total.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
Gedemon
Traffic Manager
Traffic Manager
Posts: 150
Joined: 29 Apr 2004 21:53

Post by Gedemon »

E:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\Math.h(154) : error C2373: 'myabs' : redefinition; different type modifiers
E:\Open TTD Dev\Build terra genesis perlin\macros.h(135) : see declaration of 'myabs'
E:\Open TTD Dev\Build terra genesis perlin\landscape.c(680) : error C2065: 'M_PI' : undeclared identifier
:cry:

on last SVN with just your patch...

is the bug coming from my Math.h ?
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Gedemon wrote:
E:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\Math.h(154) : error C2373: 'myabs' : redefinition; different type modifiers
E:\Open TTD Dev\Build terra genesis perlin\macros.h(135) : see declaration of 'myabs'
E:\Open TTD Dev\Build terra genesis perlin\landscape.c(680) : error C2065: 'M_PI' : undeclared identifier
:cry:

on last SVN with just your patch...

is the bug coming from my Math.h ?
Its probably the way that M$ mangles Math.h in MSVC.

Can someone else who knows MSVC help? Im really a fairly noobie at C/C++ and only have experience with Msys (& Cygwin a little).
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
Gedemon
Traffic Manager
Traffic Manager
Posts: 150
Joined: 29 Apr 2004 21:53

Post by Gedemon »

ok, I've removed

Code: Select all

#include "Math.h"
from landscape.c and added

Code: Select all

#define M_PI 3.1415926535897932384626433832795
in the same file, and it seems to work.

are you using math.h for something else than M_PI ?
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Gedemon wrote:ok, I've removed

Code: Select all

#include "Math.h"
from landscape.c and added

Code: Select all

#define M_PI 3.1415926535897932384626433832795
in the same file, and it seems to work.

are you using math.h for something else than M_PI ?
COS function, pow function. I think thats all. (Although the pow is experimental, I think I current raise to x^1. This is so I can change it to 1.1 or whatever in future.)
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
User avatar
Gedemon
Traffic Manager
Traffic Manager
Posts: 150
Joined: 29 Apr 2004 21:53

Post by Gedemon »

anyway, I like this patch :)
it will give great maps...
User avatar
XeryusTC
Tycoon
Tycoon
Posts: 15415
Joined: 02 May 2005 11:05
Skype: XeryusTC
Location: localhost

Post by XeryusTC »

It still doesn't make rivers or mountainious vs flat areas, it's only more generating options now :(
Don't panic - My YouTube channel - Follow me on twitter (@XeryusTC) - Play Tribes: Ascend - Tired of Dropbox? Try SpiderOak (use this link and we both get 1GB extra space)
Image
OpenTTD: manual #openttdcoop: blog | wiki | public server | NewGRF pack | DevZone
Image Image Image Image Image Image Image
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

XeryusTC wrote:It still doesn't make rivers or mountainious vs flat areas, it's only more generating options now :(
You're welcome to write your improved version ;)

Of course, its only 65536 terrains x 4 landscapes x 4 height levels x 4 sea levels x 4 smoothnesses. And when you increase the map size, more terrain appears. Millions of options, and more control and better quality than the current rectangular block terrain.

If there is something specific about terrain you want, be specific. Very specific. Do you want a generator that will give you a mountain, a flat bit, and some coast in each map? How do you recommend these are generated? What about when you dont want any mountains? etc.

As I said in the OP, the code is still in development. If you can help with specific and detailed suggestions - a river generator may be possible, for instance - then I may be able to code it.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
DeletedUser21
Tycoon
Tycoon
Posts: 11501
Joined: 20 Sep 2004 22:45

Post by DeletedUser21 »

OMG, when you told about
Do you want a generator that will give you a mountain, a flat bit, and some coast in each map? How do you recommend these are generated? What about when you dont want any mountains?
I immidiatly tought about the land generator of SimCity3000 (or 4 if you like) :wink:
Maybe how that terrain generator looks can be used as inspiration. :D
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2566
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Well done, Rich, that's clearly a huge piece of effort which appears to be finally paying off.
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Brianetta wrote:Well done, Rich, that's clearly a huge piece of effort which appears to be finally paying off.
LOL - the Perlin bit worked first time and since it was a modified version of an existing code, took only about 2-3 hours to do.

The user interface was an absolute nightmare... took many hours (10+) of fiddling!

I would really appreciate feedback as to whether the maps it generates are what you want as players. Or whether the 50/50 split mountain/flat terrains are preferable, but perhaps with more irregular non-rectangular bumps?

Ideas, as always, gratefully recieved... (then ignored ;) )
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

if you are not using myabs, you can alway do

Code: Select all

#undef myabs
#include <Math.h>
also I don't think the user should use non-random random seeds. It should just pick a random one when starting to generate a map
User avatar
prissi
Chief Executive
Chief Executive
Posts: 647
Joined: 15 Nov 2004 19:46
Location: Berlin, Germany
Contact:

Post by prissi »

However to transfer a so created map over the net, you would only need for parameters: random start and the three settings. Could not save much more than this.
Bjarni
Tycoon
Tycoon
Posts: 2088
Joined: 08 Mar 2004 13:10

Post by Bjarni »

prissi wrote:However to transfer a so created map over the net, you would only need for parameters: random start and the three settings. Could not save much more than this.
except how to store that the game already started and somebody did some terraforming to place a road or railroad with no hills and you are screwed if you only transfer so few parameters
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Post by richk67 »

Bjarni wrote:
prissi wrote:However to transfer a so created map over the net, you would only need for parameters: random start and the three settings. Could not save much more than this.
except how to store that the game already started and somebody did some terraforming to place a road or railroad with no hills and you are screwed if you only transfer so few parameters
I think its more for being able to discuss a map before hand... eg. "Look at map 55123 on 128x128, Mountainous. Shall we do that in Sub artic? Any prefs on sea-level?"

The one major hiccup at the moment is that I dont randomise the seed on first load, so it always starts at 0. I could have it that the seed is randomised for New Game, since you can always type in a preferred seed to override the random one.
OTTD NewGRF_ports. Add an airport design via newgrf.Superceded by Yexo's NewGrf Airports 2
Want to organise your trains? Try Routemarkers.
--- ==== --- === --- === ---
Firework Photography
tecxx
Engineer
Engineer
Posts: 106
Joined: 23 Jun 2003 19:31
Location: Tirol/Austria
Contact:

Post by tecxx »

whow. whow, whow, whow, whow. this is so awesome i can't describe it :=) it takes the feeling of the game to the next level. very cool patch!!!

now if someone would add support for all three climate types into one map ..... *dreaming of openttd future* :=)

edit:
here's a compiled win32 binary if you want to check it out...
http://rrs.at/m/openttd.zip
to everyone who's coding on openttd: YOU ROCK !!!
Singaporekid
Tycoon
Tycoon
Posts: 1966
Joined: 21 May 2004 07:39
Location: Singapore

Post by Singaporekid »

I don't know, I like the current version in the intergrated build more than this, was more hilly and "unpredictable" than this one.
Makes for better hilly routes :P
<+Raichase> ugh, I just ate some of my beard D:
User avatar
bobingabout
Tycoon
Tycoon
Posts: 1850
Joined: 21 May 2005 15:10
Location: Hull, England

Post by bobingabout »

i kinda like the look of this, not tried it yet, but maybe i should.
JPG SUX!!! USE PNG!!!
There are times when JPG is useful, TTD screenshots is not one of them. Please use PNG instead.

[/url]
sc79
Director
Director
Posts: 586
Joined: 22 Feb 2005 09:51

Post by sc79 »

The generator in the IN is certainly more unpredictable heh. It practically forces you to level large areas just to lay track because of the randomness.

This is much smoother, much more realistic; and should allow even large networks without having to make huge changes to the land.

Biggest problem i have with it after playing a bit, is that its probably too smooth in a lot of cases. Even with it set to mountainous/very rough, I struggled to get defined mountain/valleys in most cases (pic1).

Whatever you're using for the coastlines works great though (pic2).
Attachments
screenshot2.png
(79.31 KiB) Downloaded 870 times
screenshot1.png
(84.09 KiB) Downloaded 925 times
User avatar
AlienDNA
Engineer
Engineer
Posts: 97
Joined: 12 Apr 2004 08:53
Location: Leiden, Netherlands

Post by AlienDNA »

I tried it as well, and with the temperate terrain it generated a lot of antenna's, like 1 in every 10x10 square. So that has to be finetuned...

Other than that, the terrain looks absolutely smahsing, a really nice map to play on, and I wouldn't want it any other way!
"I'm gonna rip his leg off and kick him with it!", Sanjuro, Shogo-MAD
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 13 guests