Industry Tiles use 'correct' terrain sprite, minimise ID use

Discussions about the technical aspects of graphics development, including NewGRF tools and utilities.

Moderator: Graphics Moderators

Post Reply
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by andythenorth »

I have this sandpit industry that needs to allow the ground tile to show through at the edges (replacing the current green grass, which I drew, and looks wrong in non-temperate climate).

This could be done by providing multiple action 2s for each tile, with different ground sprites for each terrain type, then
using a varaction 2 checking tile variable 41.

However to preserve total industry tile IDs, all tiles for this industry are the same ID, and use a position check varaction 2 to decide which graphics to show.

My concern is that
(a) we end up with a lot of code just to define the different ground tiles (waste, possibility of errors)
(b) might run out of action 2 IDs (extremely likely if we animate this industry)
(c) it's a pain.

I wondered if there was / should be a way to specify 'make the ground tile whatever the current ground tile would be'? The information must be in the map, or var 41 wouldn't be able to get it.

Or, if a branching varaction chain is the only way to do this, then I'd better get on with it - and add extra tile IDs if I run out of action 2 IDs :o
sand_pit_9.png
sand_pit_9.png (35.48 KiB) Viewed 4089 times
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by Yexo »

This patch draws the landscape ground tile under the industry ground tile if bit 1 of industry tile prop 12 (special flags) is set. It's untested and just a demonstration of how it could be implemented.

I have no idea if this is the way to go or if a special value for groundsprite in the industry tile action2 would be better.

Planetmaker said the same should be done for houses. It's easy to code whenI have a bit to check, maybe prop 19 (extra flags) bit 4?
Attachments
ground_under_industrytile.diff
(1.72 KiB) Downloaded 140 times
User avatar
DJ Nekkid
Tycoon
Tycoon
Posts: 2141
Joined: 30 Nov 2006 20:33

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by DJ Nekkid »

abit off topic, but the same would be quite awsome for tracks and streets of all kinds... just an "overlay" of the terrain...
Member of the
ImageImage
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by Yexo »

DJ Nekkid wrote:abit off topic, but the same would be quite awsome for tracks and streets of all kinds... just an "overlay" of the terrain...
For that I'll refer you to petern and his railtypes branch (wiki, mercurial branch).
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by Zephyris »

I really support this idea, any way to make coding houses, industries, infrastructure etc. more flexible with respect to ground tiles is an excellent idea.

On a side note do you know if (the default) airport tiles are drawn over the normal ground tiles? I know in the past this was not the case, but if the latest versions of OpenTTD do then it would make a nice little improvement to OpenGFX.
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by planetmaker »

Zephyris wrote:I really support this idea, any way to make coding houses, industries, infrastructure etc. more flexible with respect to ground tiles is an excellent idea.

On a side note do you know if (the default) airport tiles are drawn over the normal ground tiles? I know in the past this was not the case, but if the latest versions of OpenTTD do then it would make a nice little improvement to OpenGFX.
And if they don't: adding that flag there would seem reasonable, too ;-)
Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by Yexo »

planetmaker wrote:
Zephyris wrote:I really support this idea, any way to make coding houses, industries, infrastructure etc. more flexible with respect to ground tiles is an excellent idea.

On a side note do you know if (the default) airport tiles are drawn over the normal ground tiles? I know in the past this was not the case, but if the latest versions of OpenTTD do then it would make a nice little improvement to OpenGFX.
And if they don't: adding that flag there would seem reasonable, too ;-)
In OpenTTD trunk they are not drawn over normal ground tiles, in my newgrf airports branch they are always drawn over normal ground tiles (so no flag), although depending on the outcome of this topic maybe I'll at a flag to draw the normal ground conditionally.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2890
Joined: 16 May 2007 16:59

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by Zephyris »

... maybe I'll at a flag to draw the normal ground conditionally.
If (when ;) ) the newairports gets to this stage drawing ground tiles under the original airport by default would be good...
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by planetmaker »

Yexo wrote:In OpenTTD trunk they are not drawn over normal ground tiles, in my newgrf airports branch they are always drawn over normal ground tiles (so no flag), although depending on the outcome of this topic maybe I'll at a flag to draw the normal ground conditionally.
Ah, thanks for the info. In that case I'd propose the same approach as for industry and house tiles; it would allow to define your own airport ground sprites making their location also stick out even, if stations are set to invisible.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by frosch »

Hmm, I don't get this :p

I think andy starts from wrong assumptions.

To make a tile capable of all climates you do not need 6 tiles for temperate grass, arctic grass, arctic snow, tropic grass, tropic desert, toyland grass. Two are enough. All grass tiles share the same spritenumber, and desert and snow also share the same.
So you might safe two tile definitions. But IMO that is not true either. I cannot imagine any tile where the ground is affected by snow, but the buildings on it are not.

So the only case remaining is a tile which is pure grass/snow/desert without any building on it. But OTOH, this only requires two layouts for the whole file, as they can be shared for all industries with such tiles. (Though the snowtiles will look ugly as industries have only one snow density, while normal tiles have four)

On a sidenote: Simliar is possible with water tiles. IIRC drawing watertiles as groundsprites makes them even look canalish/riverish if the industry was built on such a tile.

Second sidenote: A related task is that you cannot use corner shores or certain foundations in spritelayouts as they are only defined by Action5 and have no fixed TTD sprite. There is some FS task about that. (I guess by george)

Third sidenote: A sandpit in the desert? Sounds like big business :p
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by PikkaBird »

andythenorth wrote: (b) might run out of action 2 IDs (extremely likely if we animate this industry)
I fail to see how you can even come close to running out of action 2 IDs, unless you're branching your action 2s in a really weird way. Every time you branch you can reuse the same block of IDs for the same mirrored part; in fact, it makes sense to do so.

For an industry tile with 24 different position graphics each with 8 frames of animation (192 tile sprites):

24 tiles (* 8 )
branches to ^
8 position check
branches to ^
1 animation check

= 201 action 2s with 33 IDs used (and there's no reason you can't reuse the animation check ID as one of the position check IDs, so 32 IDs used).

Add an extra variation (say, 4 completely different layouts resulting in 768 tile sprites):

24 tiles (*8*4)
branches to ^
8 position check (*4)
branches to ^
4 animation check
branches to ^
1 layout check

= 805 action 2s, 36 IDs used.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5656
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Industry Tiles use 'correct' terrain sprite, minimise ID use

Post by andythenorth »

My Sand Pit is now more snow / desert terrain aware :)

This isn't 100% perfect, transition tiles are still a problem. Far as I can see, that's not solvable using existing var 41. I think the existing results are good enough though.

There will be snow sprites for the industry later.
sandpit_snow_aware.png
sandpit_snow_aware.png (196.44 KiB) Viewed 3914 times
sandpit_desert_aware.png
sandpit_desert_aware.png (176.12 KiB) Viewed 3914 times
Code relies on some preprocessor includes, these reduce duplication and generally make the code easier to work with.

Code: Select all

// include tiles and layouts, ! Action 2 IDs here are deliberately repeated by the various tile includes
#include "i_sandpit_tiles_layouts/sandpit_tiles_standard.pnfo"
#include "i_sandpit_tiles_layouts/sandpit_layouts.pnfo"

-1 * 0 02 09 A1
	82 44 //check layout number (lowest byte of related industry)
	00 FF //don't shift, don't mask
	\b2 //number of ranges to check (number of layouts)
    \wxB0 \b1 \b1 //<set-id \w> <low-range> <high-range>
    \wxB1 \b2 \b2 //<set-id \w> <low-range> <high-range>
	\wx00 //<default> (first tile layout available)

#include "i_sandpit_tiles_layouts/sandpit_tiles_desert.pnfo"
#include "i_sandpit_tiles_layouts/sandpit_layouts.pnfo"

-1 * 0 02 09 A2 
	82 44 //check layout number (lowest byte of related industry)
	00 FF //don't shift, don't mask
	\b2 //number of ranges to check (number of layouts)
    \wxB0 \b1 \b1 //<set-id \w> <low-range> <high-range>
    \wxB1 \b2 \b2 //<set-id \w> <low-range> <high-range>
	\wx00 //<default> (first tile layout available)


#include "i_sandpit_tiles_layouts/sandpit_tiles_snow.pnfo"
#include "i_sandpit_tiles_layouts/sandpit_layouts.pnfo"

-1 * 0 02 09 A3 
	82 44 //check layout number (lowest byte of related industry)
	00 FF //don't shift, don't mask
	\b2 //number of ranges to check (number of layouts)
    \wxB0 \b1 \b1 //<set-id \w> <low-range> <high-range>
    \wxB1 \b2 \b2 //<set-id \w> <low-range> <high-range>
	\wx00 //<default> (first tile layout available)
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 4 guests