Various NML related questions

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

Moderator: Graphics Moderators

Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

i don't think that info is exposed to NewGRFs, at least i didn't find it
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

Eddi wrote: 31 Aug 2021 23:59 i don't think that info is exposed to NewGRFs, at least i didn't find it
Hm as I suspected then. It would have been a nice variable to have though, especially if the "length" callback is used. I wonder how much work it would take to expose it?
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5649
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Various NML related questions

Post by andythenorth »

Bad_Brett wrote: 01 Sep 2021 05:31 Hm as I suspected then. It would have been a nice variable to have though, especially if the "length" callback is used. I wonder how much work it would take to expose it?
If you're happy to only support trains from your own grf, you could:

* inject the length of each vehicle as a compile time var, via your compile (return the lengths from a procedure, using the vehicle ID as a parameter)
* use var 60 https://newgrf-specs.tt-wiki.net/wiki/V ... e_.2860.29 to count up the number of each vehicle type in the consist
* multiply the number of each vehicle type by the length of that vehicle
* sum the results, and divide by 16

This assumes you have a templated compile, and aren't just writing nml by hand or something.

Or there might be an 80+ var you can use, but they generally come with a health warning. I can't see one in here but eh http://marcin.ttdpatch.net/sv1codec/TTD-locations.html

It's probably not that hard to add it as a var to OpenTTD, but it's very unlikely that will happen, as there is currently nobody who is comfortable reviewing newgrf spec extensions.
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 355
Joined: 01 Feb 2007 17:59
Location: Stockholm, Sweden

Re: Various NML related questions

Post by Bad_Brett »

andythenorth wrote: 01 Sep 2021 12:20 If you're happy to only support trains from your own grf, you could:

* inject the length of each vehicle as a compile time var, via your compile (return the lengths from a procedure, using the vehicle ID as a parameter)
* use var 60 https://newgrf-specs.tt-wiki.net/wiki/V ... e_.2860.29 to count up the number of each vehicle type in the consist
* multiply the number of each vehicle type by the length of that vehicle
* sum the results, and divide by 16

This assumes you have a templated compile, and aren't just writing nml by hand or something.

Or there might be an 80+ var you can use, but they generally come with a health warning. I can't see one in here but eh http://marcin.ttdpatch.net/sv1codec/TTD-locations.html
Thank you for your input, really appreciated! :)

In my case, if I only support trains from my NewGRF, it's probably even easier since all my engines and cars have been splitted in equal parts. So all I have to do is to multiply the number of parts with the standard part length... But like you said, this won't work together with other NewGRF's. On the other hand, since the vehicle count will be much higher in my NewGRF than in most others, the worst thing that can happen is that the callbacks won't work properly (which means that the game will run "as expected").
It's probably not that hard to add it as a var to OpenTTD, but it's very unlikely that will happen, as there is currently nobody who is comfortable reviewing newgrf spec extensions.
I see...That's a pity. I just want to let you know that I'm completely blown away by the latest additions to nml. It really feels as the game is about to reach it's full potential when it comes to modding capabilities and I'm really thankful for all the work you've put into it. :)
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

In regard to "incoming_cargo_waiting("WOOD") (for example), is it possible for NML to access this value for changing the value?

I can manipulate a reduction by using PRODUCE but I also wish to add to this value (not for the purposes of cheating) but to be able to manipulate stockpile quantities.

I have some code that can do it at the moment but it's not very good. If I could gain access to the actual variable/register then I could do something quite useful (I'm hoping...) but I'm guessing that NML can't access this.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5649
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Various NML related questions

Post by andythenorth »

3iff wrote: 28 Sep 2021 09:24 In regard to "incoming_cargo_waiting("WOOD") (for example), is it possible for NML to access this value for changing the value?
What happens if you return negative values from PRODUCE? (genuine question) :)

There's no other direct manipulation. In a nutshell, properties/vars are modified by callbacks, PRODUCE is the callback for modifying stockpile.

Alternatively you can maintain a shadow implementation of stockpiles using industry permanent storage, but you can't then use the industry window text default handling for display of stockpile amounts. You could probably write your own though.
User avatar
jfs
Tycoon
Tycoon
Posts: 1743
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: Various NML related questions

Post by jfs »

I was about to write that no you can't subtract negative consumption of input cargo, but it looks like you're supposed to be able to, actually.

The comment here newgrf_spritegroup.h:273 says "Take this much of the input cargo (can be negative)", so try it out.
User avatar
3iff
Tycoon
Tycoon
Posts: 1093
Joined: 21 Oct 2005 09:26
Location: Birmingham, England

Re: Various NML related questions

Post by 3iff »

I did think of that (adding a negative value), and it doesn't work. I'd guess there's a check somewhere that treats -ve values as 0. So, no it doesn't work.

I currently DO use industry internal registers as a virtual storage but it's messy so I've disabled it for now (and it has an oversight on my part so it doesn't work perfectly yet). I could display this value but I already use all the available registers TEMP( 256-261) for displaying other stuff.

I'd like a few more printable variables, but I'm unlikely to get those either...but if negative produce values did actually work then I could use 256-261 for displaying storage quantities for what I have in mind.
paritcl3s
Engineer
Engineer
Posts: 28
Joined: 15 Jun 2020 08:01

Re: Various NML related questions

Post by paritcl3s »

I am writing a town_name.grf.

It encounters a compile error at about 700 lines of text, removing some lines fixes it.
Is it a invisible cap limit?

Code: Select all

Not enough random bits for the town name generation (34 needed, 32 available)
Image
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

You have (as the message says) 32 random bits available. each independent random decision uses up one or more of these. you can try reorganizing your code that some random decisions share the same bits (they won't be independent anymore)
User avatar
Quast65
Tycoon
Tycoon
Posts: 2642
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: Various NML related questions

Post by Quast65 »

Hi all,

I have noticed that in several house-sets some sort of recolour is used, so that one single graphic has different appearences ingame.
For example an awning of a shop can have different colors.
I believe it is somehow done by (possibly random) recoloring of the blue Company Colors of the palette.

Can this also be done for objects?

And, if so, how?
As I have not yet found the sources of a NML-coded house-set that has this feature.
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
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Various NML related questions

Post by PikkaBird »

Quast65 wrote: 17 Jan 2022 08:17 Can this also be done for objects?
Yes, using the "colour" callback.
User avatar
Quast65
Tycoon
Tycoon
Posts: 2642
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: Various NML related questions

Post by Quast65 »

PikkaBird wrote: 17 Jan 2022 09:29
Quast65 wrote: 17 Jan 2022 08:17 Can this also be done for objects?
Yes, using the "colour" callback.
Good to know!

Do you possibly know of any GRF's that use this feature (doesnt have to be objects), that have sources for me to look at?
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
2TallTyler
Route Supervisor
Route Supervisor
Posts: 490
Joined: 11 Aug 2019 18:15
Contact:

Re: Various NML related questions

Post by 2TallTyler »

Improved Town Layouts uses random recolouring for sub-arctic houses. It needs a few different pieces to work:

1. The spritelayout needs to specify that the sprite can be recoloured. ITL uses baseset sprites which are referred to by number, but the code is the same for new sprites which use a spriteset.

Code: Select all

spritelayout sprite_arctic_48_house {
	ground		{ sprite: terrain_type == TILETYPE_SNOW ? 4429 : 4428; }
	building	{
		sprite: (construction_state == 0 ? 4430 : (construction_state == 3 ? (terrain_type == TILETYPE_SNOW ? 4433 : 4432) : 4431)); 
		recolour_mode: RECOLOUR_REMAP;
		palette: PALETTE_USE_DEFAULT;
}
}
2. The house needs the `colour` callback.

Code: Select all

graphics {
		default: sprite_arctic_48_house;
		construction_check: switch_arctic_house_a;
		colour: RandomColourArcticHouses();
	}
3. A random colour is chosen by a random switch. (A regular switch also works if you want to choose colours based on your own logic — I do this with my land value algorithm for sub-tropic houses.)

Code: Select all

random_switch (FEAT_HOUSES, SELF, RandomColourArcticHouses) {
	1: return PALETTE_CC_DARK_BLUE;
	1: return PALETTE_CC_PALE_GREEN;
	1: return PALETTE_CC_PINK;
	1: return PALETTE_CC_LIGHT_BLUE;
	1: return PALETTE_CC_DARK_GREEN;
	1: return PALETTE_CC_CREAM;
	1: return PALETTE_CC_MAUVE;
	1: return PALETTE_CC_ORANGE;
	1: return PALETTE_CC_BROWN;
}
User avatar
Quast65
Tycoon
Tycoon
Posts: 2642
Joined: 09 Oct 2011 13:51
Location: The Netherlands

Re: Various NML related questions

Post by Quast65 »

Thank you for your reply!
2TallTyler wrote: 18 Jan 2022 22:26 It needs a few different pieces to work:
Sadly that doesnt do the trick for Objects...
If I use the above code, with changing

Code: Select all

FEAT_HOUSES
to

Code: Select all

FEAT_OBJECTS
offcourse,
I get an error message like this:
Example710.png
Example710.png (4.05 KiB) Viewed 9386 times
the number (0x308 in this case) corresponds with the first color in the list (in this case I put PALETTE_CC_PALE_GREEN on top).
Also no recoloring (at least none to the color at the top of the list) and certainly no random recoloring when placing the object more times.

But, if I change the color list to for example this:

Code: Select all

random_switch (FEAT_OBJECTS, SELF, RandomColour_2x1_Random01) {
	1: return COLOUR_YELLOW;
	1: return COLOUR_RED;
	1: return COLOUR_GREEN;
	1: return COLOUR_BLUE;
}
I dont get an error message anymore, but the recoloring is only to the first color of the list...
?( ?( ?(
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.
Auge
Director
Director
Posts: 632
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Various NML related questions

Post by Auge »

Hello

I have a few questions.

1. When replacing base set sprites the NML-specification for replace speaks about a "list of real sprites" and shows an example with a few sprite definitions. Is it also possible to replace a base graphic sprite with only the ID of another base set sprite? Purpose: I want to replace the sidewalk sprites with the grass-only sprite from the matching landscape type from the base set used in the game without knowing the positions and dimensions of the sprites.

2. I studied the code of many NRT sets and came across definitions like the following (actually taken from docklands but present in many sets).

Code: Select all

template tmpl_underlay_roadtypes() {
    tmpl_underlay_straight()
    tmpl_underlay_junctions()
    tmpl_underlay_corners()
    tmpl_underlay_slope()
    tmpl_underlay_half_tiles()
    /* X-crossing */
    ground_tile(0, 120)
    /* underlay for crossings w/o tracks */
    ground_tile(  0, 130)
    ground_tile(225, 130)
    ground_tile(150, 130)
    ground_tile( 75, 130)
}
Beside the fact, that this code is resampled in many sets and the in many sets not matching pixel positions provided to the function ground_tile, the question for me is, what purpose have the definitions after the comments " /* X-crossing */" and "/* underlay for crossings w/o tracks */"? "X-crossing" could imho only mean the crossroad because this is the only sprite without a mirrored or turned counterpart. But the crossroad sprite is already defined in the template tmpl_underlay_junctions together with the four branches.

Also the definitions after the comment "underlay for crossings w/o tracks" makes no sense to me. I assumed these are the sprites for rail crossings or tunnel entrances and exits but a test with plain coloured sprites did not make anything. The rail crossing as well as the tunnel sprites was displayed with the "normal" straight road sprites and not with the coloured. Does these definitions do anything or are they made at a time when the feature set of NRT was not finalised and try to do anything, NRT isn't able to?

Tschö, Auge
Eddi
Tycoon
Tycoon
Posts: 8254
Joined: 17 Jan 2007 00:14

Re: Various NML related questions

Post by Eddi »

the rail crossing underlays are only visible if you use a railtype with enabled crossing overlay, otherwise the combined crossing sprite from the railtype is used, which will completely cover the underlay sprite
Auge
Director
Director
Posts: 632
Joined: 23 Oct 2006 02:07
Location: Berlin

Re: Various NML related questions

Post by Auge »

Hello

quote=Eddi post_id=1252118 time=1646092992 user_id=15964]
the rail crossing underlays are only visible if you use a railtype with enabled crossing overlay, otherwise the combined crossing sprite from the railtype is used, which will completely cover the underlay sprite
[/quote]

Are you sure? In the following screenshot the right rail track is the default ingame track without a crossing overlay. It uses the normal rail and the level crossing lights. The left one is the abandoned rail type from useless-tracks-GRF which provides an overlay. Both level crossings does display the normal straight road. After your reply I expected the level crossing of the abandoned track (the one with the overlay) to display one of the unicoloured sprites I mentioned in my previous posting.
nrt-rail-crossings.png
nrt-rail-crossings.png (37.66 KiB) Viewed 8674 times
My problem with this is my poor understandig of it because the NML-specs for roadtypes does not mention any of the sprite definitions in question, that I see in so many sets. So I'm kind of lost here.

Thank you nevertheless, tschö, Auge
User avatar
colossal404
Chief Executive
Chief Executive
Posts: 652
Joined: 07 Mar 2009 12:48
Location: Szeged, Hungary

Re: Various NML related questions

Post by colossal404 »

Hai guise!
I'd like to ask about sprite stacking, is it currently limited to max 4 layers / articulated part by nml, or by OTTD itself? I would like to use more of it, so I could spare time on making sprites (and waste time to write the code to a grf I will never finish :lol: )
Image
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5601
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Various NML related questions

Post by PikkaBird »

Yes, four is the maximum in OpenTTD, regardless of how the NewGRF is coded.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 5 guests