Various NML related questions

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

Moderator: Graphics Moderators

Eddi
Tycoon
Tycoon
Posts: 7779
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
You might not exactly be interested in Ferion, but if you are, have fun :)
Bad_Brett
Transport Coordinator
Transport Coordinator
Posts: 351
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: 5421
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: 351
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: 1040
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: 5421
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: 1400
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: 1040
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.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 1 guest