Patch: Advanced Terrain Schemes (r13191)

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

User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Patch: Advanced Terrain Schemes (r13191)

Post by CommanderZ »

DEVELOPMENT PAUSED
until I finish the BMB patch


I saw many players requesting increased map variability like seen in Civilization IV or Age of Empires during the short period I'm present on TT-F. So here it is.

Technology

Very soon I realized it is extremely simple to make a clean cut into the map, but for pretty long time I found it almost impossible to make it look naturally with various map settings. I restarted the project two times until I found a working and well-looking solution: I create a second height map, create the inverted shape on it, apply some noise on it (which is in fact third full featured height map) and then substract it from the original game height map. I had to adapt HeightMapGenerate, HeightMapNormalize and their subfunctions to be able to create the noise map for me, so the changes to the tgp.cpp are quite wide. The pros of this are clear - I only adapted several functions and the map shaping is then matter of several lines of code. The cons is slightly longer generation time, but it is still incomparable with ECS industries.

Current map schemes

Please note that current schemes work in cooperation with other map settings - everything is dynamic. See attached pictures.

Two continents
Variation on continents or shore-to-shore maps. Creates two large landmasses separated by a canal.

Crater lake
Usually known as "mediterranean", this scheme creates a map with large circular lake in the middle.

This is all for now. I have several more ideas, but you can of course post some ideas/proposals. The code as it is allows me to add more schemes very quickly (as long as the can be simply mathematically described).

Known issues
  • Small height map glitch in Two continents
Now I have to tame the GUI and SVN to share it with you.
Attachments
ATS two continents mountainous very low water very rough.png
Two continents, mountainous, very low water level, very rough (please note the transition from sea to terrain is much better in newer versions)
(496.02 KiB) Downloaded 1916 times
ATS two continents mountainous very low water smooth.png
Two continents, mountainous, very low water level, smooth (please note the transition from sea to terrain is much better in newer versions)
(653.71 KiB) Downloaded 1462 times
ATS two continents flat high water smooth.png
Two continents, flat, high water level, smooth. The look of smooth maps on Two continents vas siginificantly improved since I shot this, I'm just lazy to take a new shot. (please note the transition from sea to terrain is much better in newer versions)
(422.99 KiB) Downloaded 1448 times
Last edited by CommanderZ on 13 Oct 2008 19:29, edited 10 times in total.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Advanced Terrain Schemes

Post by CommanderZ »

Some Crater lake shots
Attachments
ATS crater lake flat very low water very smooth.png
Crater lake, flat, high water level, very smooth
(443.84 KiB) Downloaded 1106 times
ATS crater lake hilly very low water very rough.png
Crater lake, hilly, high water level, very rough
(597.68 KiB) Downloaded 888 times
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Advanced Terrain Schemes

Post by Zuu »

Nice work you've done!

I've never really get into into the OpenTTD GUI, but I wish you good luck, and as others have managed it I guess you will have good chances to make it. :)

Also nice to see someone else using headlines in their longer posts to give them clear structure. :)
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
el koeno
Route Supervisor
Route Supervisor
Posts: 454
Joined: 24 Sep 2004 15:47

Re: Advanced Terrain Schemes

Post by el koeno »

Looks awesome! Good job.

I don't know much about coding and such, but perhaps it might be useful if I make some suggestions for map scripts (or whatever you want to call them):
-It would be cool if you could set the number of continents, in you current two continent thing.
-Archipelago would be a challenge: lots of small islands. You would need ships trucks, and perhaps trains.
-Mountain pass: A huge mountain range with one low corridor. Not sure what this would look like actually.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Advanced Terrain Schemes

Post by CommanderZ »

Thanks for replies.
I don't know much about coding and such, but perhaps it might be useful if I make some suggestions for map scripts (or whatever you want to call them):
No. I have no idea how to do that.

EDIT: Sorry, I understood this as if you suggested to implement external map scripts - these are for me simply impossible to do. But map scheme suggestions? Of course!
-It would be cool if you could set the number of continents, in you current two continent thing.
You can generate multiple continent thing with original high water level setting. Maybe I will make 4 continents (4 corners), but some random continents...no. I'm substracting mathematically definable shapes from perlin noise map, Civ IV or AoE use a blob-based thing (I have no idea how to call it). The just say...put a randomly shaped blob of land here, put a blob of land there, I can't do that.
-Archipelago would be a challenge: lots of small islands. You would need ships trucks, and perhaps trains.
I thought about it. I think the easiest way will be to add fifth water level setting, with cca twice the water percentage value.
Mountain pass: A huge mountain range with one low corridor. Not sure what this would look like actually.
This is a job for later stage. Now I'm toying with shape of the landmasses, not their heights at all. But I can say this is planned. There are two limiting factors though: max. height is 16 and map border tiles must be water.
el koeno
Route Supervisor
Route Supervisor
Posts: 454
Joined: 24 Sep 2004 15:47

Re: Advanced Terrain Schemes

Post by el koeno »

CommanderZ wrote: EDIT: Sorry, I understood this as if you suggested to implement external map scripts - these are for me simply impossible to do. But map scheme suggestions? Of course!
Well, I was thinking about suggesting external map scripts. But then again, I figured that would be waaay more complex than what you're doing here (which is already too complex for me ;)), so it'll probably have to wait. It would be awesome though.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Advanced Terrain Schemes

Post by CommanderZ »

Uuuf, I must say the GUI system in OTTD is pretty confusing to work with. Took me several hours to add one stupid drop-down box.

I would post the diff as the code is now basically ready to use, but I'm still having no luck with the SVN.

Also, the bug with Crater lake is fixed and the one with Continents is not severe (I'm even starting to think it looks cool).
Attachments
Altered landscape generator gui
Altered landscape generator gui
ATS gui.png (46.02 KiB) Viewed 10872 times
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Advanced Terrain Schemes

Post by Roujin »

As a workaround until you figure out a way to do it yourself, you could give me the files you altered, plus tell me what revision it is based on and I can make a .diff out of it for you..
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
el koeno
Route Supervisor
Route Supervisor
Posts: 454
Joined: 24 Sep 2004 15:47

Re: Advanced Terrain Schemes

Post by el koeno »

What's the atoll map scheme?
User avatar
doktorhonig
Tycoon
Tycoon
Posts: 1104
Joined: 22 Aug 2006 11:03
Location: Austria
Contact:

Re: Advanced Terrain Schemes

Post by doktorhonig »

I'd love something like "mountain ridge", with lines of mountains. I've only managed to create them with heightmaps up to now.
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Advanced Terrain Schemes

Post by CommanderZ »

Thanks to Roujin, I now have first releasable patch file. Please ignore Atoll in the game/ATS_ATOLL in the code, it is WIP.

I'm also attaching emodded executable and english lang file. Copy it over r13191 with game data.
I'd love something like "mountain ridge", with lines of mountains. I've only managed to create them with heightmaps up to now.
Could you please post example of such height map? I will have a look at it and see if it could be procedurally generated. I'm open to more scheme ideas!


I also got one more idea, how to use my code in order to improve TGen maps. The crappiest thing on current maps are the areas along map borders. They are created with not-smoothed 2d perlin noise. I could apply my noise map on them instead exactly in the same way I'm doing it with my templates. This would make the edges look smooth/rough depending on map settings and would fit perfectly with my templates. Do you like this idea? I heard devs want patches to do only one thing at time...
Attachments
ATS_080530.7z
Compiled Win32 executable and lang file for r13191
(742.32 KiB) Downloaded 159 times
ats_080530.patch
Patch for r13191
(117.09 KiB) Downloaded 134 times
richk67
Tycoon
Tycoon
Posts: 2363
Joined: 05 Jun 2003 16:21
Location: Up North
Contact:

Re: Patch: Advanced Terrain Schemes (r13191)

Post by richk67 »

If you could create a totally separate patch that did a nice / better job of handling the map edges (at all scales from 64x64 up to 2048+), then Im sure it would be well received by the devs. Its a known area of weakness, where the current code does an adequate job - if your patch could visibly improve it, Im sure it would be appreciated.
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
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Patch: Advanced Terrain Schemes (r13191)

Post by CommanderZ »

I could seperate it, but i would have to copy the most invasive changes I did to the TGen code - deglobalizing nearly all the functions TGen uses (all are inside tgp.cpp).

I got one idea now though. I could make a Better Edges patch and then ATS would be only its extension using its functions.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Patch: Advanced Terrain Schemes (r13191)

Post by Roujin »

CommanderZ wrote:I could seperate it, but i would have to copy the most invasive changes I did to the TGen code - deglobalizing nearly all the functions TGen uses (all are inside tgp.cpp).

I got one idea now though. I could make a Better Edges patch and then ATS would be only its extension using its functions.
Advice: Do the code changing even seperately. Or, even better, get in contact with the devs first, and tell them that you're planning to clean up the functions of TGen. Then start making the changes in logical and small steps.
If your changes are reasonable and acceptable, i think that's the best way to have them accepted. First do the codechanges, without introducing any new feature yet. If you're done with that, you can make the "better edges" fix on top of that, then the new feature (advanced schemes) on top of that.

edit: you didn't change the revision number in your .patch file...
edit: argh, seems i can't read. you wrote the revision number in your post...

one more thing: patches should be based on /trunk, not /src.

more edit: don't know what you're compiling with, but my gcc gives some warnings. Some double to int conversion, comparing unsigned with signed, and one that reads "warning: taking address of temporary" which can't be good :?

oh and I didn't ignore that "Atoll" option like you said, but tried it out. Gives nice results already if you set mountains and sea level to high :)

My suggestion for a setting would be "multiple continents" (like 4 or 5), for bigger maps, but I guess that will already be covered by Atoll?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Patch: Advanced Terrain Schemes (r13191)

Post by CommanderZ »

Advice: Do the code changing even seperately. Or, even better, get in contact with the devs first, and tell them that you're planning to clean up the functions of TGen. Then start making the changes in logical and small steps.
If your changes are reasonable and acceptable, i think that's the best way to have them accepted. First do the codechanges, without introducing any new feature yet. If you're done with that, you can make the "better edges" fix on top of that, then the new feature (advanced schemes) on top of that.
I will try to make the code as clean as possible. I will consider contacting devs once I have at least something to show. I don't have time this weekend anyways.
edit: you didn't change the revision number in your .patch file...
Revision numbers are quite weird, I'm creating the patches offline...is it problem? Is it possible to set rev number on my SVN? If it matters, I can always grab text exitor and replace all occurences of "Revison 7" with "Revision 13191". It is not that much work.

one more thing: patches should be based on /trunk, not /src.
Src is my local dir with code...I will change it to trunk to prevent errors. I thought it will take the files inside the dir, not the dir itself. I renamed the trunk to src in order to fit with the MSVS project file which is packed with the source.

more edit: don't know what you're compiling with, but my gcc gives some warnings. Some double to int conversion, comparing unsigned with signed, and one that reads "warning: taking address of temporary" which can't be good
I'm using MSVC++ 2008 Express and I'm getting no warnings.
oh and I didn't ignore that "Atoll" option like you said, but tried it out. Gives nice results already if you set mountains and sea level to high
Atoll should be a narrow circle of small flat circular/slightly elliptic islets. I'm still nowhere near result I imagine as ideal.
My suggestion for a setting would be "multiple continents" (like 4 or 5), for bigger maps, but I guess that will already be covered by Atoll?
I see this gonna be popular request...it seems I will have to look into it.
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Patch: Advanced Terrain Schemes (r13191)

Post by Roujin »

CommanderZ wrote:
edit: you didn't change the revision number in your .patch file...
Revision numbers are quite weird, I'm creating the patches offline...is it problem? Is it possible to set rev number on my SVN? If it matters, I can always grab text exitor and replace all occurences of "Revison 7" with "Revision 13191". It is not that much work.
Of course the numbers are resembling your local repository (rev7~ish) instead of the openttd repository. It's not a problem, but it would help people know what revision to apply it to if the numbers match 8) It should be fine if you do that with editor->replace like you said.
Also the automatic building tool BuildOTTD relies on those numbers, so people who can't compile on their own, only with that tool will only be able to test your patch if the correct revision stands in the file. ;)

one more thing: patches should be based on /trunk, not /src.
Src is my local dir with code...I will change it to trunk to prevent errors. I thought it will take the files inside the dir, not the dir itself. I renamed the trunk to src in order to fit with the MSVS project file which is packed with the source.
Uhm, normally there is a directory structure like this:
[base dir] (often called trunk)
[base dir]/src
[base dir]/docs
[base dir]/{some other directories...}
the makefile should be located in the base dir for example, and the source files .c(pp)/.h(pp) are in /src or subdirectories of it

Now it is, lets say a standard, to base the patch on the base dir, to allow changes not only in the /src/* files, but also for example on the /docs/* files. So if you're using TurtoiseSVN just right click on your base dir (the one the src dir is in) and then on "create patch", instead of doing this in the src dir.

that should result in your patch file showing

Code: Select all

--- src/genworld_gui.cpp	(revision 7)
+++ src/genworld_gui.cpp	(working copy)
instead of

Code: Select all

--- genworld_gui.cpp	(revision 7)
+++ genworld_gui.cpp	(working copy)

more edit: don't know what you're compiling with, but my gcc gives some warnings. Some double to int conversion, comparing unsigned with signed, and one that reads "warning: taking address of temporary" which can't be good
I'm using MSVC++ 2008 Express and I'm getting no warnings.
yes, c++ compilers are quite different on what they give warnings.. as long as they're not errors it's not that critical though :roll:
My suggestion for a setting would be "multiple continents" (like 4 or 5), for bigger maps, but I guess that will already be covered by Atoll?
I see this gonna be popular request...it seems I will have to look into it.
I guess it is popular because the real world is like this with multiple continents, and maybe because maps in (O)TTD have always been one big land mass and it may be interesting and a new challenge if we can have multiple continents. Then you can't just connect everything with rail anymore, but also have to use planes/ships. 8)
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Youri219
Traffic Manager
Traffic Manager
Posts: 191
Joined: 28 Apr 2007 11:53

Re: Patch: Advanced Terrain Schemes (r13191)

Post by Youri219 »

Just downloaded this to generate a map which I then wanted to load in a recent nightly. Why does this patch break savegame compatibility when (by the looks of it) it doesn't have to change anything in a game at all?
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Patch: Advanced Terrain Schemes (r13191)

Post by CommanderZ »

There was a slight bump affecting how game settings are stored somewhere in 133** (which could possibly also affect savegames), I was fixing this in BMB today. I will jump back on ATS once BMB is finished. ATS will be slightly rewritten to be an extension of BMB, so I need it finished first.
Sarin
Engineer
Engineer
Posts: 76
Joined: 18 Jun 2008 20:01

Re: Patch: Advanced Terrain Schemes (r13191)

Post by Sarin »

Some map suggestions from me:

Satelites: one large islands with several smaller around. Primary industries are on satelite islands, secondary are on the central one.
High and low: half map highland, half lowland. Quite similar to TTDX scenario of same name (does anyone remember that?)
None Shall Pass: two highlands separated by pass going through whole map.
Spiral: spiral of land with all secondary industries in the middle.
River Delta: I don't think it needs describing.
Streams: a map with a lot of small lakes and dozens of thin rivers going from one edge to another.

Also, is it possible to make some map affect towns/industries layout? Like having primary industries near one edge, secondary on the other side etc...
User avatar
CommanderZ
Tycoon
Tycoon
Posts: 1872
Joined: 07 Apr 2008 18:29
Location: Czech Republic
Contact:

Re: Patch: Advanced Terrain Schemes (r13191)

Post by CommanderZ »

Satelites: one large islands with several smaller around. Primary industries are on satelite islands, secondary are on the central one.
I'm planning this.
High and low: half map highland, half lowland. Quite similar to TTDX scenario of same name (does anyone remember that?)
Nice and simple, be sure this will be implemented once I get back to ATS.
None Shall Pass: two highlands separated by pass going through whole map.
This was already suggested and I must say I dream about it myself, but I'm very limited by the count of height levels (16) which prevents me from more detailed layouts like this.
Spiral: spiral of land with all secondary industries in the middle.
You mean the milky-way spiral shape? It would be really nice. But it would be very hard to make unless I found a nice formula how to calculate the beams.
River Delta: I don't think it needs describing.
I like this, but it has very complicated layout and also - it would look weird unless we had possibility to create land on map edges. All maps must be in fact islands now.
Streams: a map with a lot of small lakes and dozens of thin rivers going from one edge to another.
I'm planning something like this.
Also, is it possible to make some map affect towns/industries layout? Like having primary industries near one edge, secondary on the other side etc...
It surely is. I have an idea - it would be nice, if there were several different items (layouts) to define - I mean height/landmass distribution (that's what I'm doing now), population distribution, industry distribution and humidity distribution for tropical climate. I'm afraid of overcomplicating the patch though.

Thanks for feedback
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 5 guests