What would take to implement diagonal rivers and canals on main trunk?

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
speeder
Engineer
Engineer
Posts: 28
Joined: 16 Jul 2014 05:57

What would take to implement diagonal rivers and canals on main trunk?

Post by speeder »

So... I am making a map, possible because of the new height limits (I started it in 2014, before the height limit increase, result was super crappy and I gave up, now I am trying again).

One thing is bothering me is that my map to look good would require diagonal rivers... and seemly those doesn't exist (yet?).

I am a professional C++ coder, so if I decide to make a patch, would it be allowed? And what I would need to do?
LaChupacabra
Route Supervisor
Route Supervisor
Posts: 389
Joined: 08 Nov 2019 23:54

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by LaChupacabra »

When it comes to graphics issues:
OpenGFX + Landscape has diagonally rivers.
OpenGFX+Landscape - diagonall rivers.PNG
OpenGFX+Landscape - diagonall rivers.PNG (282.23 KiB) Viewed 2545 times
Regarding diagonally canals:
I haven't seen it anywhere, but I have pre-made such graphics.
Diagonally canals.gif
Diagonally canals.gif (375.85 KiB) Viewed 2511 times
I could finish them, but I would need a template that I couldn't find. This is nothing special, it would certainly be more difficult to code it, although it might be possible to adapt the code for diagonally rivers from OpenGFX. This code is not perfect, not everything looks good (especially wider rivers and lakes) so it could be improved a bit. As for the river graphics themselves, I also have their improved version.
OpenGFX+Landscape - diagonall rivers + improvements.png
OpenGFX+Landscape - diagonall rivers + improvements.png (45.4 KiB) Viewed 2545 times
They're not perfect, but at least you can't see those horns.

Regarding construction of diagonally rivers and canals:
I have graphics for the construction of such elements. This is also nothing special, but it might be useful (or maybe not). Most of the graphics I did about a year ago, when I was working on a map, where there were a lot of such diagonally rivers - building point by point was a arduous. I wanted to post a suggestion to improve the editor, which would be very useful...

Edit: I am not entirely convinced to change the graphics in the main version of the game. But it can always be an addon or even a new base graphics set.
User avatar
kamnet
Moderator
Moderator
Posts: 8582
Joined: 28 Sep 2009 17:15
Location: Eastern KY
Contact:

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by kamnet »

LaChupacabra wrote: 19 May 2020 16:26 Edit: I am not entirely convinced to change the graphics in the main version of the game. But it can always be an addon or even a new base graphics set.
These would be a great contribution to OpenGFX+ Landscapes.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by planetmaker »

I always wondered whether that should be done - and it definitely is a good addition to OpenGFX+Landscape. And tbh, I forgot why I didn't include the diagonal rivers in the OpenGFX base set itself... or if it was just lazyness and/or a desire to keep one unique feature to OpenGFX+Landscape or some technical limitation for base sets.

Rivers and canals are technically the same and the only difference is the waterclass which is used to decide which sprites are being drawn. Thus technically the very same code could be duplicated and canals would have the same feature.

The source of OpenGFX+Landscape is freely available under GPL v2+. You find the river (and canal) code at https://kallithea.openttdcoop.org/ogfx- ... ivers.pnml - I might soonish migrate that to a GitHub repository.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by wallyweb »

I have been toying with diagonal rivers using newobjects since way back in TTDPatch days. One of the advantages of TDDPatch is that it used the same "water" for seas, rivers and canals. With this, one could use diagonal steep slope sea tiles as <groundsprite> and draw a diagonal half steep slope/half river tile as a <buildingsprite> for some interesting canyon/fjord effects. Unfortunately this is not currently possible with OpenTTD.

planetmaker has done some amazing Action5 work with OpenGFX+Landscape but to be honest, this should be generally available throughout the game (steep slope/water included). I took a look at his code a while ago and to be honest I found it to be quite complicated. Perhaps I need to take another look at it when I complete some of my current projects. The pity is that it is currently a GRF solution to add to an existing feature. Hopefully somebody can develop a way to expand the feature itself.
LaChupacabra
Route Supervisor
Route Supervisor
Posts: 389
Joined: 08 Nov 2019 23:54

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by LaChupacabra »

planetmaker wrote: 19 May 2020 22:50 The source of OpenGFX+Landscape...
I assumed that the code for these rivers could be quite extensive. But I didn't think that is so much.

With these river templates ... this division is a bit scary. I have the impression that some of the graphics found there are not used at all.
River riddle.png
River riddle.png (6.13 KiB) Viewed 2277 times
Template for others, however, I still can't find. There are only graphics of rivers running along the field lines: \ NE, / NW, / SE, \ SW. I don't see those that run diagonally across the fields: (N, S, | W, | E), or small pieces of land in the corners of the field.

The waterfeatures.png template scared me a bit again. ;) I really don't know where that all sprites goes. Earlier I thought it will be simpler separated. For example, for the new canals graphics (straight and diagonal) I anticipated the creation of 25 graphics for each climate in the version with and without dividing lines. In total, 25x12 = 300 graphics would be created. The same amount of graphics would apply to rivers on a flat surface. A lot, but much less than around 1180, which would only apply to rivers. I assumed that the canals graphics would be created by superimposing layers of water + waterfront with ground. I didn't anticipate any additional overlays because I thought it would significantly complicate the code... Although in some places such overlays could be useful, but not so many.

I don't know if you would like my versions of rivers and canals at all, but even if yes, I am afraid I won't be able to divide them properly and assign them to these templates. :(

I also don't know what your opinion is about the canals and rivers near to the slopes - will anyone want to add such a possibility. I think it would be worth it.
This is how it would look in the game ...
Diagonally rivers & canals with deep level mini.png
Diagonally rivers & canals with deep level mini.png (718.92 KiB) Viewed 2277 times
Diagonally rivers & canals with deep level.png
(2.04 MiB) Not downloaded yet
On the occasion a small sample of deep water ;)
I hope that jfs will not abandon his project. Here I used an additional two shades from outside the palette.
I am sorry for may English. I know is bed.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by planetmaker »

LaChupacabra wrote: 24 May 2020 22:48
planetmaker wrote: 19 May 2020 22:50 The source of OpenGFX+Landscape...
I assumed that the code for these rivers could be quite extensive. But I didn't think that is so much.

With these river templates ... this division is a bit scary. I have the impression that some of the graphics found there are not used at all.
River riddle.png

Template for others, however, I still can't find. There are only graphics of rivers running along the field lines: \ NE, / NW, / SE, \ SW. I don't see those that run diagonally across the fields: (N, S, | W, | E), or small pieces of land in the corners of the field.
Yes, indeed. Not each sprite in the png files is being used (anymore). Other sprites used are not found as png files in the repository at all. Most (all? I forgot) ground sprites are generated by exporting the appropriate layers during the build process from the Gimp files found in the repository in the gfx-source directory. You want to look at gfx-source/terrain.xcf. Then see the xcf2png files which layers are exported to create the png files requested by the templates in the code (for the rivers it's src/gfx/water/waterfeatures.xcf2png). Their structure is simple:
src/gfx/water/riverbank_grid_temperate_ne.gimp.png gfx-source/terrain.xcf White BlueForShore GroundTemperate GridTemperate RiverbankMask RiverbankNE
Thus it is "generated png file (to be used/referenced by the nml)" (TAB) "file to read from" (TAB) "Names of the layers to be active during export"

These xcf2png files are used to create gimp scripts which in turn are used to automatically export the proper layers. Using these layered files and scripted layer export allows a consistent look and ensures that bug fixes or changes are propagated to all sprites of similar type. That is especially important when it comes to changes at tile borders to make sure transitions look smooth in all cases and you avoid the need to fix all road and rail and river and coast sprites afterwards manually when you modify the way the grass looks.

If you want to go and add / modify terrain sprites I very strongly suggest you to use these Gimp GFX source files and do modifications therein or at least use another graphics programme which supports layers.

Even better, clone the whole repository to your computer. Get to build it unmodified initially (it needs a few dev tools... nml, make, awk, grep, python3, bash). Then you will see also all intermediate files generated during the build process.
LaChupacabra
Route Supervisor
Route Supervisor
Posts: 389
Joined: 08 Nov 2019 23:54

Re: What would take to implement diagonal rivers and canals on main trunk?

Post by LaChupacabra »

LaChupacabra wrote: 24 May 2020 22:48 I have the impression that some of the graphics found there are not used at all.
I already know what these sprites are for ... I forgot that rivers can flow across the slopes... Logic :lol:

planetmaker wrote: 25 May 2020 10:32 xcf2png files (...) it needs a few dev tools... nml, make, awk, grep, python3, bash (...) Their structure is simple
It all sounds very simple :D ... for someone who has already do it. :(

I looked at these xcf files a bit and it seemed sensible at first. Later I looked in the xcf2png file and broke down because it is not simpler at all ... or at least I think so at this moment.
I can manage the canals. Rivers maybe too. I didn't coding, except for minor script changes, so here I temporarily doubt that I will succeed.

Before I move anything, I would have a few questions:
1. How do you see the possibility for each river embankment to have two versions? The choice of graphics could depend on the field coordinates. I ask in theory.

2. Would you be able to smooth the river banks? This pretty badly spoils the end result.
Ugly edges 1.png
Ugly edges 1.png (68.31 KiB) Viewed 2187 times
This could work so that the river corner graphics would only be displayed when the field is adjacent to 2 or 3 other water fields in the specified layout, otherwise the diagonally river graphic would be displayed.
Ugly edges 2.PNG
Ugly edges 2.PNG (92.63 KiB) Viewed 2187 times
3. Would you be able to add the possibility to change the graphics of the river or canal as it is in the case of objects? In the case of point 2, this would make it possible to change the corner canal or river into an diagonally one or vice versa (more important). In the case of point 1, this would allow the graphic version to be changed to a different one (less important).

4. And the question about canals and rivers near the slopes is still valid.
I am sorry for may English. I know is bed.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Semrush [Bot] and 26 guests