NML - a Newgrf Meta Language

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

Moderator: Graphics Moderators

Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: NML - a Newgrf Meta Language

Post by Transportman »

Eddi wrote:no, articulated parts must have IDs below 16384 (0x4000), i.e. a 14 bit number. this is because the callback has 15 bits and the highest bit has special meaning (reverse the vehicle). there is no way to circumvent this.

also, as a corner case, the highest possible vehicle ID (0x3FFF) cannot be reversed, as the value 0x7FFF means "no more vehicles"
Thank you very much, it is clear now. I will reshuffle the IDs in the set a bit to get everything below ID 16384.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

Are there any pieces of example codes in NML for slope-aware landscape objects?
So that when you place a landscape object on a slope the graphic automatically changes to a graphic that has the shape of that slope.
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch »

Try with OGFX+Landscape: https://dev.openttdcoop.org/projects/og ... t.pnml#L28

The key items are:
* "OBJ_FLAG_NO_FOUNDATIONS"
* "tile_check" to allow on only some slopes
* "slope_to_sprite_offset(nearby_tile_slope(0, 0))"
* The "var_groundsprite" and "DECIDE_GROUND_ARCTIC" stuff is about drawing snowy/deserty/coasty-groundtiles.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

Thnx!! And also many thnx to the developers of the OGFX+Landscape grf for making such clear examples!! :bow:
Auz59.png
Auz59.png (358.15 KiB) Viewed 898 times
Also managed to make the tiles themselves snow-hight aware (so not only the groundsprite) and gave them a customisable purchase-menu sprite (rather than the automatically chosen flat sprite) .
Will post examples with 1 view and 4 views later when finished.

EDIT:
Here are the examples (all GPLv2), they include a GRF, the NML, the Languagefile and the Graphics:
SLOPE_AWARE_1VIEW.rar
(20.22 KiB) Downloaded 76 times
SLOPE_AWARE_4VIEWS.rar
(62.74 KiB) Downloaded 82 times
EDIT-2:

Credits:
Coded by Quast65
Graphics of the 1view.grf by Quast65
Graphics of the 4view.grf by Wallyweb (from his Titlegrid-grf), alterations to those by Quast65
Also many thanks to: Pyoro, Planetmaker, Frosch and the Developers of the OGFX+Landscape-grf, for their help in creating this code.
Last edited by Quast65 on 24 Apr 2016 12:53, edited 1 time in total.
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

Sorry for the doublepost, but I do have one more question (and I cant add any more attachments in my previous post)

I am using this piece of code for the groundsprite:

Code: Select all

//calculate ground sprite for object
switch (FEAT_OBJECTS, SELF, switch_slope_aware_001_object, [
    STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP(terrain_type == TILETYPE_DESERT ? GROUNDSPRITE_DESERT : LOAD_TEMP(1), 1),
    STORE_TEMP(terrain_type == TILETYPE_SNOW   ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
    STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
    STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
        ]) {
    switch_slope_aware_001_view;
}
For Arctic climate this shows all the different snowy groundsprites under the object depending on the hightlevel.
However, for Tropical I am missing the groundsprite at the transition from grass to desert:
Example16.png
Example16.png (55.71 KiB) Viewed 4827 times
Is there a line of code I could/should add to get the correct groundsprite at the transition?
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch »

Sadly, testing for half-desert is hillariously complicated. You need to check all four surrounding tiles for desert.
Again, see OGFX+Landscape :p (DECIDE_GROUND_TROPICAL)
https://dev.openttdcoop.org/projects/og ... d.pnml#L27
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

Thnx again for your help!!! :bow:

I replaced this line of code:

Code: Select all

STORE_TEMP(terrain_type == TILETYPE_DESERT ? GROUNDSPRITE_DESERT : LOAD_TEMP(1), 1),
With:

Code: Select all

    STORE_TEMP( (nearby_tile_terrain_type(0,0) == TILETYPE_DESERT) * GROUNDSPRITE_DESERT, 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type(-1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0, 1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0,-1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * GROUNDSPRITE_NORMAL, 1),
So the complete block of code now looks like this:

Code: Select all

//calculate ground sprite for object
switch (FEAT_OBJECTS, SELF, switch_slope_aware_001_object, [
    STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP( (nearby_tile_terrain_type(0,0) == TILETYPE_DESERT) * GROUNDSPRITE_DESERT, 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type(-1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0, 1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0,-1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP(terrain_type == TILETYPE_SNOW   ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
    STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
    STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
        ]) {
    switch_slope_aware_001_view;
}
And this is the result :P
Example17.png
Example17.png (103.61 KiB) Viewed 4720 times
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5891
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Just a question .. can you make a Industry for the game that also has a overlapping tile?

Some of the Industries I have made for AuzInd, I like to overlap some so closer to railway lines and roads.

Players can then using the flat platforms from ISR/DWE and other sets so these can be hidden under a part of Industry.

This sample using Object Silos.


Thought I ask before I try.

Thanks kindly

Garry
Attachments
NewSilosOverlap1.png
NewSilosOverlap1.png (459.09 KiB) Viewed 4177 times
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
frosch
OpenTTD Developer
OpenTTD Developer
Posts: 988
Joined: 20 Dec 2006 13:31
Location: Aschaffenburg

Re: NML - a Newgrf Meta Language

Post by frosch »

No, that is not possible. Graphics can only overlap with the tiles behind them.

Put the track in front of the industry on foundations to discover the issues.
⢇⡸⢸⠢⡇⡇⢎⡁⢎⡱⢸⡱⢸⣭⠀⢸⢜⢸⢸⣀⢸⣀⢸⣭⢸⡱⠀⢰⠭⡆⣫⠰⣉⢸⢸⠀⢰⠭⡆⡯⡆⢹⠁⠀⢐⠰⡁
User avatar
GarryG
Tycoon
Tycoon
Posts: 5891
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

frosch wrote:No, that is not possible. Graphics can only overlap with the tiles behind them.

Put the track in front of the industry on foundations to discover the issues.
Thanks for your reply. Glad I found out before I tried as save unnecessary work.

Cheers
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

Some industries seem to be coded in such a way that they leave room for a track or road:
Auz61.png
Auz61.png (103 KiB) Viewed 4054 times
This one even has a sky-bridge over the road.

That could be the solution to Garry's issue. Dont know how that is done by the way, have never done anything with industries ;-)
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
User avatar
3iff
Tycoon
Tycoon
Posts: 1094
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: NML - a Newgrf Meta Language

Post by 3iff »

That's a feature from FIRS (and maybe others but). Basically, some industries are built in 2 blocks with a gap in the middle (to accommodate a road or rail. I'm not 100% sure about the 'bridge' between the 2 blocks...it might be an illusion where the bridge doesn't actually extend into the gap (but just looks like it does).

Farms, forests and oil wells from FIRS also do the same thing. It's very easy to do. It must be because I've done it...

Code: Select all

  XXX   XXXX
  XXX   XXXX
  XXX   XXX
That's what the industry layout might look like. It's all one industry but just in 2 or more blocks. If you're so inclined, you can even have a 2 tile gap to allow road and rail or double rail.
User avatar
GarryG
Tycoon
Tycoon
Posts: 5891
Joined: 14 Feb 2015 00:44
Location: Newcastle, Australia

Re: NML - a Newgrf Meta Language

Post by GarryG »

Hi Fellas,

It not actually a gap I want .. it a overlap to make the Truck Loading Bay look different then the actual one .. A bit like overlapping roads.

What I think I will look at is making a Object with a Overlap that matches the Industry .. a bit like the Grain Silos.

We have lots of choices with railway stations for both passengers and freight .. but only one for road vehicles. So I kinda looking at idea making I guess we could call them fake Truck Loading Bays.

Thanks for those trying to help .. appreciated.

Cheers
Soot Happens
Screenshot Of The Month Winner March 2020
All my projects are GPLv2 License unless stated.
Auz Road Sets: viewtopic.php?f=29&t=87335
Auz Project Releases: viewtopic.php?f=67&t=84725
Auz Trains: http://www.tt-forums.net/viewtopic.php?f=26&t=74193
Auz Industry Sets: http://www.tt-forums.net/viewtopic.php?f=26&t=74471
Auz Objects: viewtopic.php?f=26&t=75657
Auz Bridges: viewtopic.php?f=26&t=75248
Auz Stations: viewtopic.php?f=26&t=76390
Auz Tracks: viewtopic.php?f=26&t=82691
Auz Subway Stations: viewtopic.php?f=26&t=85335
Auz Eyecandy TramTracks: viewtopic.php?t=89908
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

In that case, a good way to go is to make a separate GRF that replaces the truckloading bay graphics with just a flat tile.
That way you dont have to worry about the buildings anymore and you can just add various graphics via objects.
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: NML - a Newgrf Meta Language

Post by Eddi »

GarryG wrote:it a overlap to make the Truck Loading Bay look different then the actual one .. A bit like overlapping roads.
this sort of thing you cannot reasonably implement with industries.

you can get away with it for objects, because the player can work around the glitches if necessary, but industries are more or less fixed, and the player has not as much flexibility.

also, AI players which try to serve the industry will have no clue about what looks good and what not.
Silverx50
Route Supervisor
Route Supervisor
Posts: 430
Joined: 13 Apr 2007 19:52
Location: Den Haag, The Netherlands

Re: NML - a Newgrf Meta Language

Post by Silverx50 »

I've been attempting to undertand NML and the way I'm supposed to code grf's.
following the wiki I think I understand what is happening until it comes to the templating of image

Code: Select all

//templates
template template_MN_Building(x,y,filename) {
	[x,		y,		128,		191,	-?,		-?,	filename]
so I think I understand the X and the Y values but I don't understand how I'm supposed to measure the "minus" values. it's been driving me mad the last few weeks trying to figure it out on my own.
or am I going about it the wrong way?
Attachments
MN_Building.png
MN_Building.png (6.19 KiB) Viewed 3910 times
All my projects are GPLv2 License.

Dutch landmark Object Set Workshop viewtopic.php?f=26&t=75071
My stations workshop viewtopic.php?f=26&t=74749
User avatar
FLHerne
Tycoon
Tycoon
Posts: 1543
Joined: 12 Jul 2011 12:09
Location: St Ives, Cambs, UK

Re: NML - a Newgrf Meta Language

Post by FLHerne »

It's the offset (x, y) from the north corner of the object's base to the top-left corner of your sprite.

The easiest way to find it is to use the 'Sprite Aligner' tool (under the (?) menu) in OpenTTD - create the grf with 0 offsets initially, build the object, then poke the offsets in the sprite aligner until it looks right and put those values into your NML.

Sketched on your image:
MN_Building.png
MN_Building.png (4.24 KiB) Viewed 3897 times
And yes, the offset is relative to the corner that's almost always hidden behind something, and in the direction that makes it always negative. Very helpful. :roll:
Temporary Permanent signature filling text. Content coming soon delayed indefinitely! Oh, and I have had a screenshot thread.
Linux user (XMonad DWM/KDE, Arch), IRC obsessive and rail enthusiast. No longer building robots; now I ring church bells.
Author of an incredibly boring stickied post about NewGRFs.
Silverx50
Route Supervisor
Route Supervisor
Posts: 430
Joined: 13 Apr 2007 19:52
Location: Den Haag, The Netherlands

Re: NML - a Newgrf Meta Language

Post by Silverx50 »

thank you very much.
All my projects are GPLv2 License.

Dutch landmark Object Set Workshop viewtopic.php?f=26&t=75071
My stations workshop viewtopic.php?f=26&t=74749
Silverx50
Route Supervisor
Route Supervisor
Posts: 430
Joined: 13 Apr 2007 19:52
Location: Den Haag, The Netherlands

Re: NML - a Newgrf Meta Language

Post by Silverx50 »

I've gotten further than ever before. my sprites now show up in the game, but I've made a mistake somewhere and am not sure what it is that I've done
that has caused this issue. instead of drawing the building once when you buy it it builds it 4 times on top of each other. I followed the wiki and I think that's where the problem stems from as
looking at that grf that is used as an example it looks like it draws over it self.

Code: Select all

//templates
template template_MN_Building(x,y,filename) {
    [x,     y,      128,     191,     -64,    -128,    filename]
    [x+134,  y,      128,     191,     -64,    -128,    filename]
    [x+268,  y,      128,     191,     -64,    -128,    filename]
    [x+401,  y,      128,     191,     -64,    -128,    filename]

Code: Select all

//spriteset with four directions
spriteset (spriteset_MN_Building_3) {
    template_MN_Building(0,0,"gfx/MN_Building.png")
}

Code: Select all

//south east
spritelayout spritelayout_MN_Building_3_SE {
    ground {
        sprite: GROUNDSPRITE_NORMAL;
    }
    building {
        sprite: spriteset_MN_Building_3(0);
        xextent: 16;
        yextent: 16;
        zextent: 16;
        xoffset: 0; //from NE edge
        yoffset: 0; //from NW edge
        zoffset: 0;
    }
}
this is copied 3 more times changing the SE and the (0) accordingly.

Not sure what other pieces of code I'm supposed to put up. I've added a screenshot of what happens ingame and the spritesheet that I've used.

thanks
Attachments
triple building.png
triple building.png (135.7 KiB) Viewed 898 times
MN_Building.png
MN_Building.png (7.18 KiB) Viewed 3831 times
All my projects are GPLv2 License.

Dutch landmark Object Set Workshop viewtopic.php?f=26&t=75071
My stations workshop viewtopic.php?f=26&t=74749
User avatar
Quast65
Tycoon
Tycoon
Posts: 2664
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: NML - a Newgrf Meta Language

Post by Quast65 »

I may not explain it entirely correct (so please correct me where needed), but the spritesorter thinks in single tiles.
So, in this case for a 2x2 building you need to cut it up into 4 single-tile graphics and tell the spritesorter via the code how to arrange these 4 tiles in such a way that a complete building shows up.

I havent experimented yet with large multitile objects, however some time ago I did make a test-GRF for a 2x1 object. Maybe this will help to see what parts of the code you were missing (the

Code: Select all

//select correct sprites for tile position for this view
part is very important in this case), here is a .rar with all the files (graphics, code and GRF):
2x1.rar
(10.95 KiB) Downloaded 92 times
In this case I have already included the option for snow-graphics, it may be handy to already include those too, even though you dont have snow-graphics yet (so in this case just have the exact same graphics for no-snow and snow).
That way, later on, you only need to replace the graphics-file, if you or someone else picks up your graphics to make them snowy.

And finally just note that this block:

Code: Select all

//calculate ground sprite for object
switch (FEAT_OBJECTS, SELF, switch_template_2x1_001_object, [
    STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP(terrain_type == TILETYPE_DESERT ? GROUNDSPRITE_DESERT : LOAD_TEMP(1), 1),
    STORE_TEMP(terrain_type == TILETYPE_SNOW   ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
    STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
    STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
        ]) {
    switch_template_2x1_001_view;
}
Should be changed into this:

Code: Select all

//calculate ground sprite for object
switch (FEAT_OBJECTS, SELF, switch_template_2x1_001_object, [
    STORE_TEMP(GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP( (nearby_tile_terrain_type(0,0) == TILETYPE_DESERT) * GROUNDSPRITE_DESERT, 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type(-1, 0) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0, 1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * 4512 * (nearby_tile_terrain_type( 0,-1) == TILETYPE_DESERT), 1),
    STORE_TEMP( LOAD_TEMP(1) + (LOAD_TEMP(1) == 0) * GROUNDSPRITE_NORMAL, 1),
    STORE_TEMP(terrain_type == TILETYPE_SNOW   ? GROUNDSPRITE_SNOW : LOAD_TEMP(1), 1),
    STORE_TEMP(snowline_height == 0xFF ? 0xFF : nearby_tile_height(0,0) - snowline_height, 255),
    STORE_TEMP((LOAD_TEMP(255) == -1) ? GROUNDSPRITE_SNOW_1_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  0) ? GROUNDSPRITE_SNOW_2_4 : LOAD_TEMP(1), 1),
    STORE_TEMP((LOAD_TEMP(255) ==  1) ? GROUNDSPRITE_SNOW_3_4 : LOAD_TEMP(1), 1)
        ]) {
    switch_template_2x1_001_object;
}
Not that important for you right now, but it will be when you have objects where you still can see some parts of the base ground-tile. This piece of code will make sure that the correct desert-tile or snow-tile is drawn.

Good luck! Good to see that you are also trying to learn to code! :bow:
Projects: http://www.tt-forums.net/viewtopic.php?f=26&t=57266
Screenshots: http://www.tt-forums.net/viewtopic.php?f=47&t=56959
Scenario of The Netherlands: viewtopic.php?f=60&t=87604

Winner of the following screenshot competitions:
sep 2012, jan 2013, apr 2013, aug 2013, mar 2014, mar 2016, oct 2020
All my work is released under GPL-license (either V2 or V3), if not clearly stated otherwise.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: GarryG, Google Adsense [Bot] and 23 guests