Elevation feature

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

zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Elevation feature

Post by zifox »

Hi,

While creating a map with quite a lot of mountains, I've been wondering if it would be possible to have a new slope height (typically twice the standard elevation) ?
Unlike the default slope, this new one wouldn't be buildable, forcing players to find another route.

I'm thinking about this because I'm often trying to recreate some parts of the Alps, and the very steep slopes cannot really be done in the game, so deep valleys IRL are not really that deep, and it's not too much of a challenge.

Not knowing the insides of the game engine I have no idea if it's possible without breaking it, moreover I have no idea if it's something that would fit in the game design.
User avatar
MagicBuzz
Tycoon
Tycoon
Posts: 1301
Joined: 15 Feb 2003 17:32
Location: Vergezac, France

Re: Elevation feature

Post by MagicBuzz »

Hello zifox,

I don't think this could be done without a complete rework of almost any line of the game source code ;)

I believe this is a feature request that exists from the origin of TTDPatch about 25 years in the past now ;)
Eddi
Tycoon
Tycoon
Posts: 7987
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

MagicBuzz wrote: 21 Sep 2022 10:18 I don't think this could be done without a complete rework of almost any line of the game source code ;)
It's actually not THAT bad.

you only need 3 things:
  1. rework the map storage to store all corners of each tile, instead of just one
  2. rework the drawing code because now more tiles could potentially be on screen in need of drawing (possible performance impact)
  3. introduce a way to see tiles that could now be blocked by mountains and cliffs [note: this is usually the big showstopper]
You might not exactly be interested in Ferion, but if you are, have fun :)
User avatar
odisseus
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Nov 2017 21:19

Re: Elevation feature

Post by odisseus »

What about going the other way? Introduce a half-height slope and treat it as a normal slope, whereas the old type of slope would be considered a "cliff". I understand this doesn't affect the effort required to modify the map format and the rendering code, but at least the tile visibility won't be an issue.
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Eddi wrote: 21 Sep 2022 11:40
MagicBuzz wrote: 21 Sep 2022 10:18 I don't think this could be done without a complete rework of almost any line of the game source code ;)
It's actually not THAT bad.

you only need 3 things:
  1. rework the map storage to store all corners of each tile, instead of just one
  2. rework the drawing code because now more tiles could potentially be on screen in need of drawing (possible performance impact)
  3. introduce a way to see tiles that could now be blocked by mountains and cliffs [note: this is usually the big showstopper]
Hmmm that's quite interesting. I think I'll try to dig deeper into this. I need to clone the source repo first...
You seem to have a good understanding of the way the graphic engine work, could I bother you with some questions later ?
Last edited by zifox on 21 Sep 2022 19:44, edited 1 time in total.
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

odisseus wrote: 21 Sep 2022 16:31 What about going the other way? Introduce a half-height slope and treat it as a normal slope, whereas the old type of slope would be considered a "cliff". I understand this doesn't affect the effort required to modify the map format and the rendering code, but at least the tile visibility won't be an issue.
Yes that would solve the visibility issue, but the would not answer my question in the first place: have deep valleys and high cliffs ! :D
Eddi
Tycoon
Tycoon
Posts: 7987
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

zifox wrote: 21 Sep 2022 19:40 Hmmm that's quite interesting. I think I'll try to dig deeper into this. I need to clone the source repo first...
note that the word "only" is quite the understatement, each of these 3 tasks is quite complicated. and there are a lot of minor things to consider as well, like making sure a rail on top of a cliff isn't connected with a rail on the bottom of a cliff.
You seem to have a good understanding of the way the graphic engine work, could I bother you with some questions later ?
questions like that are better phrased openly to the public. nobody knows the whole code. different people know things better about certain parts of the code.
You might not exactly be interested in Ferion, but if you are, have fun :)
Auge
Director
Director
Posts: 522
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Elevation feature

Post by Auge »

Hello
zifox wrote: 21 Sep 2022 19:41
odisseus wrote: 21 Sep 2022 16:31 What about going the other way? Introduce a half-height slope and treat it as a normal slope, whereas the old type of slope would be considered a "cliff". I understand this doesn't affect the effort required to modify the map format and the rendering code, but at least the tile visibility won't be an issue.
Yes that would solve the visibility issue …
No it wouldn't. With greater height differences the problem of visibility will come back again.
zifox wrote: 21 Sep 2022 19:41 … but the would not answer my question in the first place: have deep valleys and high cliffs ! :D
Your question was answered. No, it isn't possible in the current state of the game. Yes, it would be possible, if and when the issues, named by Eddi (and maybe further issues), would be solved.

Tschö, Auge
User avatar
odisseus
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Nov 2017 21:19

Re: Elevation feature

Post by odisseus »

Auge wrote: 23 Sep 2022 09:14
zifox wrote: 21 Sep 2022 19:41 Yes that would solve the visibility issue …
No it wouldn't. With greater height differences the problem of visibility will come back again.
I beg to differ. The perspective in OpenTTD works in such a way that you can see the whole tile if you can see its front corner. In particular, a mountain's back slope is entirely visible, as are any flat tiles lying next to the slope. If some of the slope tiles were half the usual steepness, they would basically be an average between a normal slope and a flat tile. Such a tile could not possibly obscure the tiles that lie behind any more than a flat tile does.
Attachments
back-slope.png
back-slope.png (28.86 KiB) Viewed 392 times
Auge
Director
Director
Posts: 522
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Elevation feature

Post by Auge »

Hello
odisseus wrote: 23 Sep 2022 15:33
Auge wrote: 23 Sep 2022 09:14
zifox wrote: 21 Sep 2022 19:41 Yes that would solve the visibility issue …
No it wouldn't. With greater height differences the problem of visibility will come back again.
I beg to differ. The perspective in OpenTTD works in such a way that you can see the whole tile if you can see its front corner.
I agree to your argumentation in the limits of your idea. But if the OP writes about cliffs and you offer to define only the current steepness as cliff whereas the "normal" steepness would be halved, this is a IMHO not convincing solution (neither optically nor functionally).

When the "normal" height difference is halved, the game would need graphics for all infrastructure tiles as tracks, roads, etc. that are affected by this change (beside the landscape sprites in itself). The movement of up- and downhill moving vehicles would need adaption, the position of trees on these tiles must be adapted, etc. pp. And last but not least the developer of this feature has to decide if roads and tracks should be buildable on tiles that are then cliffs or not (with the then presumably upcoming discussions).

And in the end someone would ask for steeper and higher cliffs like in Locomotion (where this is possible) and then your solution would break. In that moment the backside would be invisible, at least in case of the backside of a vertical cliff. In Locomotion you can turn around the map in 90-degree-steps. In TTD/OpenTTD you cannot and if this should get implemented, the game would need a lot more graphics because of the now unnecessary but then needed, visible backsites of anything.

As said, for me this is a not convincing idea.

Tschö, Auge
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

I took a quick look at the code, and as I understand it, everything is hardcoded. Indeed, it won't be easy to change anything. Not easy, but possible. I'm optimistic.

A piece of good news visually speaking. The TILE_HEIGHT is exactly half the TILE_SIZE, meaning that doubling the TILE_HEIGHT would not actually hide anything, in theory. We wouldn't see the slope opposite the view anymore, but nothing would be hidden by the slope. (that would be an issue if we could build road/tracks in the diagonale line on slopes, which we can't.)

I need to configure the project properly, I'd like to try and see how the game reacts if I set TILE_HEIGHT to 16, visually. If the result is acceptable, i'll dig deeper into this matter. I'll drop the idea if it is not, from what I've seen, as mentionned before, that would be a show stopper, the whole drawing engine would need to be rewritten.
Eddi
Tycoon
Tycoon
Posts: 7987
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

TILE_HEIGHT is probably not a thing that you should change.
You might not exactly be interested in Ferion, but if you are, have fun :)
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Indeed that was not, the title screen would not even load, I had a crash because a train couldn't find a track, apparently.
Weird that the path finding could be impacted by this variable.

Is there a way to load the game without any background scene ?
Eddi
Tycoon
Tycoon
Posts: 7987
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

yes, if you delete opntitle.dat, an empty map is created on game start.
You might not exactly be interested in Ferion, but if you are, have fun :)
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Thanks, that did the trick.

I did a few tests, and I'm surprised. As the following screenshot shows, with a tile height of 16px, once I created a slope, the cursor snaps higher than the tile displayed, which is expected.
openttd1.png
openttd1.png (492.72 KiB) Viewed 188 times
What's not expected is the low height difference: naïvely I thought the space between the ball and the top of the tile under it would be exactly the height of the tile. But that's not the case.

Nevermind, I raised the terrain again, to see where the next tile woud be drawn.
openttd2.png
openttd2.png (568.54 KiB) Viewed 188 times
As expected, it's not touching the tile below, but like in the screenshot above, it's not as high as I'd thought it would. (both screenshots of coherent)

Ok, so I called the bluff and raised again:
openttd3.png
openttd3.png (543.23 KiB) Viewed 188 times
Again, not what I expected, but coherent with the other two.
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

I'm quite puzzled. The gap between the tiles is a third of the height of the tile.
openttd4.png
openttd4.png (343.91 KiB) Viewed 186 times
But the code clearly states:
///< Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
I'm missing something, but I don't know what.
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

A positive thing: the code already handles "steep slopes" (height difference equal to 2 between two corners), that why we can't build in the steepest direction of a slope. So handling even higher differences shouldn't need extra code.

I'm intrigued... :lol:
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2709
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Elevation feature

Post by ChillCore »

zifox wrote: 26 Sep 2022 21:51 I'm missing something, but I don't know what.
Your measurement is wrong ...

I attached a picture to more easily explain.

- The yellow lines represent the edges of a flat tile if one would be there (not very accurate I admit)
- you are measuring from the center of a lower tile to the corner of a higher located tile ... this is not correct and leads to your confusion.
- The orange scriblings is where you should be measuring from.


Anyhoo ... good luck with your project.
Attachments
tileheight.png
tileheight.png (314.41 KiB) Viewed 152 times
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

Playing with my patchpack? Ask questions on usage and report bugs in the correct thread first, please.
All included patches have been modified and are no longer 100% original.
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Thanks for pointing that out !

It does make sense, but then I'm having difficulties linking the size of the tile to its height. At the beginning, seeing in the code that TILE_HEIGHT = (TILE_SIZE)/2 and the seeing the result on the screen, I thought both values were in "screen space". There must be a ratio applied somewhere when drawing.

More research needed on my side !
zifox
Engineer
Engineer
Posts: 17
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Does anybody know where I could find the source for zBase ? I'd like to try and make a few sprites for double elevation slopes, but the openttd coop website doesn't answer anymore (bad gateway)
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 3 guests