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

User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Elevation feature

Post by ChillCore »

zifox wrote: 27 Sep 2022 19:23 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)
This link still works ... it seems.
http://bundles.openttdcoop.org/zbuild/push/LATEST/

Maybe give planetmaker a little poke about the bad gateway to the devzone?

Anyhoo I took the liberty to download the source tar while I was there and will attach it here.

If all else fails (and what I attached here is not the latest version) there is a link to a mirror on the last page of the zbase project thread too ... which may or may not still work.
Attachments
zbase-v5588-source.tar.xz
(136.13 KiB) Downloaded 71 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.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

zifox wrote: 27 Sep 2022 13:14TILE_HEIGHT = (TILE_SIZE)/2
[...] I thought both values were in "screen space".
no, those are map coordinates, not screen coordinates.

each tile is divided into 16 steps in X and Y directions, and 8 steps in Z direction (if sloped)

on default zoom, each Z step is 1 pixel up. and each X/Y step is 2 pixels left/right and 1 pixel down.
zifox
Engineer
Engineer
Posts: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Thanks Chillcore, I was headed to dev.openttdcoop...
Eddi wrote: 27 Sep 2022 19:58 no, those are map coordinates, not screen coordinates.

each tile is divided into 16 steps in X and Y directions, and 8 steps in Z direction (if sloped)

on default zoom, each Z step is 1 pixel up. and each X/Y step is 2 pixels left/right and 1 pixel down.
I'm a bit confused (maybe a vocabulary issue), I'll try to write what's coming to my mind. I was thinking, since it's a 2D game, that there was no polygons, no texture mapping. Simply sprites that we draw at specified coordinates on the buffer, and that the elevation was simply an vertical offset when drawing a sprite supposed to be at a higher level. From what I've seen in the code, each tile of the world stores the height level of its "south" corner (between 1 and MAX_TILE_HEIGHT), so initially I though this height level would simply be the offset to use when drawing.

I took a screenshot and did some pixel counting:
Sans titre.png
Sans titre.png (55.94 KiB) Viewed 2850 times
At default zoom:
- the white lines are 16 pixels wide, which make a tile 32 pixels wide, matching TILE_PIXELS.
- The blue and yellow lines are 8 pixels high, making a tile 16 pixels high
So I figure that the ratio used to give perspective is 2 to 1.

- The pink part is 4 pixels high, that's the extra height due to the slope.
This comment :

Code: Select all

///< Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
make me think that height in world and pixels is the same at default zoom level, which seems to be the case as the Z offset used to draw fences is tile->z plus the result of GetSlopePixelZInCorner, which returns either 0 or 1 times TILE_HEIGHT.

So, given the ratio perspective of 2 to 1, those 4 pink pixels would match the TILE_HEIGHT.

- there are 8 steps (2 px left and 1 px up ) red steps in a tile side. I'm trying to link this to your explanation about X/Y step, is that it ?

So did I understood correctly your comments if I say that the "physic" engine uses TILE_SIZE to compute positions of moving objects inside a tile. As you mentionned the tile is split in 16 parts, that would make the smallest movement (along the edge of a tile, that's what you call X/Y ?) 2 pixels horizontally (32/16) and 1 pixel vertically ((32/16)/2) ?
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

that sounds about right, except the point of reference is always the NORTH corner of a tile.
zifox
Engineer
Engineer
Posts: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

ChillCore wrote: 27 Sep 2022 19:35
zifox wrote: 27 Sep 2022 19:23 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)
This link still works ... it seems.
http://bundles.openttdcoop.org/zbuild/push/LATEST/

Maybe give planetmaker a little poke about the bad gateway to the devzone?

Anyhoo I took the liberty to download the source tar while I was there and will attach it here.

If all else fails (and what I attached here is not the latest version) there is a link to a mirror on the last page of the zbase project thread too ... which may or may not still work.
The link and the file provided contains zBuild, which seems to be the build system for zBase, but I can't find the sprites. The .nml files refers to "/sprites/png/...", but there is not png folder in sprites, I guess it's hosted somewhere else. The file talks about the mercurial repo for zBase, but it doesn't seem to be available anymore. :(
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Elevation feature

Post by ChillCore »

I see ... I did not check but in hindsight it seemed a bit lightweight in size ... my bad.

You have a few options ...

- Poke Zephyris and ask where he's hiding them sprites? best option IMHO as he would be the one to know best ... he still visits the site now and again.

- The same link has "zbase-v5588.zip" which has compiled grf you could decompile? Too big for me to upload here so you'll have to get that yourself if you so desire.

- The OpenGFX projext has terrain sprites, https://github.com/OpenTTD/OpenGFX/tree ... ng/terrain , but I do not know if that includes zoomed sprites or not.

- I found a modified version of zbase on github, https://github.com/gravitystorm/zbase , but I have no clue how the sprites are organised ... may require some exploring on your part to get a complete set (19 sprites per zoomlevel per type as shown here https://newgrf-specs.tt-wiki.net/wiki/N ... ile_slopes )

Alternatively ... you could ask in the graphics development forum is someone is willing to share a set of each zoomlevel for you to mess with?
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

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: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Thanks.
I've already sent a message to Zephyris, i'll wait for the moment.
I didn't know the GRF could be decompiled, i'll have a look into it, if I have no other option. I've seen that the openGFX repo has the sprites in the png folder, so that would be enough. That's for debugging purpose /research for the moment, I working with zBase would be better but that's not mandatory.
zifox
Engineer
Engineer
Posts: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Is there an automated way to find available id ranges for sprites ? I'm going to need a bunch of new sprites, I'll try to add them in a tweaked version of opengfx (if I can build it), but I need to find indices to use.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

the most future proof way to add new sprites, is to add a new action5 type
zifox
Engineer
Engineer
Posts: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

I've had a look that newgrf.cpp, from what i've seen if I'm to create a new action5_types for steep slopes ,I'll still need a sprite ID to use as sprite_base.

From sprites.h I get that I could insert my sprites near "the end", meaning after all the "extra" sprites which are incrementally computer. But where exactly ? After SPR_PALETTE_BASE and before SPR_NEWGRFS_BASE ? Would that work ? Are sprites in newgrfs numbered dynamically from that ID ?

Unless I'm totally mistaken and sprites from opengfx/zbase are already using the newgrf format, so I don't need to bother with them ? But then, how could I retrieves their IDs to display them correctly when drawing a tile ? Doesn't seem so, give the IDs found in opengfx sources.
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: Elevation feature

Post by Eddi »

here's an old example i have lying around: https://github.com/OpenTTD/OpenTTD/comm ... a53a753f64

(Disclaimer: i don't remember why i chose that exact spot to insert the sprite IDs, and no guarantees that the devs will think that's a correct choice)
zifox
Engineer
Engineer
Posts: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Thanks.

I've look deeper into this, and by comparing the base/newgrf code and the sources from GRFs, it seems my first guess was right: newgrfs have "dynamic" ID (the "base" offset plus the internal ID), so I should be safe if I insert my new ids just before the SPR_NEWGRFS_BASE id.
Not sure exactly why you inserted your sprites and changed the 2CC_MAP_BASE offset, maybe because you changed indices in the base grf (by inserting your sprites between others) ? I'm not going to do this, i don't want to change the actual IDs in the grf files, i'm too afraid to break everything.

I'll try to make some rocky sprites and load them.
Last edited by zifox on 07 Oct 2022 06:41, edited 1 time in total.
User avatar
ChillCore
Tycoon
Tycoon
Posts: 2822
Joined: 04 Oct 2008 23:05
Location: Lost in spaces

Re: Elevation feature

Post by ChillCore »

zifox wrote: 06 Oct 2022 21:32 Thanks.

I've look deeper into this, and by comparing the base/newgrf code and the sources from GRFs, it seems my first guess was right: newgrfs avec "dynamic" ID (the "base" offset plus the internal ID), so I should be safe if I insert my new ids just before the SPR_NEWGRFS_BASE id.
Not sure exactly why you inserted your sprites and changed the 2CC_MAP_BASE offset, maybe because you changed indices in the base grf (by inserting your sprites between others) ? I'm not going to do this, i don't want to change the actual IDs in the grf files, i'm too afraid to break everything.

I'll try to make some rocky sprites and load them.
Are you looking to replace sprites?
Or add some?
You entered deep waters ... not sprite wise but by changing TILE_HEIGHT ... enable newgrf_deloper _tools (and/or other devolper tools) in the config file to get some additional tools under the question mark (@see the question sprite on the toolbar)... as Eddi said ... action 5 .. I mean I ignored that too and hardcoded the tiles way back when I needed them .. but I suck at sprite coding ...
-- .- -.-- / - .... . / ..-. --- .-. -.-. . / -... . / .-- .. - .... / -.-- --- ..- .-.-.-
--- .... / -.-- . .- .... --..-- / .- -. -.. / .--. .-. .- .. ... . / - .... . / .-.. --- .-. -.. / ..-. --- .-. / .... . / --. .- ...- . / ..- ... / -.-. .... --- --- -.-. .... --- --- ... .-.-.- / ---... .--.

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: 47
Joined: 26 Jan 2011 14:43
Location: France

Re: Elevation feature

Post by zifox »

Nope I'm looking to add to sprites.

My TILE_HEIGHT replacement was a test to see how the tiles were drawn, I've reverted that and have authorized a height difference of 2 instead of 1 between to tile corners.
Now I need to create news sprites to be able to actually draw these types of tiles.

Next in line:
- create a map with a lot of elevation from a heightmap, see how it behaves
- play with the terraforming tools to see if things work
- try to fix everything that could be broken and hope that the STEEP_SLOPE flag of the tiles is enough to keep the AI, the building tools from breaking.

I'm not sure what the action 5 does, what's for sure is that I need new Sprite IDs (a hardcoded range of them in sprites.h) to be able to display the correct tiles when drawing the ground. Like the base tiles, i'll need one ID for each tile configuration.
User avatar
wallyweb
Tycoon
Tycoon
Posts: 6102
Joined: 27 Nov 2004 15:05
Location: Canada

Re: Elevation feature

Post by wallyweb »

zifox wrote: 07 Oct 2022 06:46 I'm not sure what the action 5 does
Action 5 is used to define graphics for several new features of OpenTTD and TTDPatch.

Probably the most obvious in game example of Action 5 are the canals and rivers provided via the Waterways Construction GUI.
User avatar
Snail
Tycoon
Tycoon
Posts: 1283
Joined: 28 Apr 2003 18:52
Contact:

Re: Elevation feature

Post by Snail »

Having a steeper slope where you could only build rackrail tracks would be a great addition to the game!
The French Narrow Gauge Train Set is now released! Get it here
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: eboss128, piratescooby and 34 guests