How to display waiting cargo in industry window?

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

Moderator: Graphics Moderators

Post Reply
ebla71
Route Supervisor
Route Supervisor
Posts: 485
Joined: 14 Apr 2021 21:48
Location: Earth

How to display waiting cargo in industry window?

Post by ebla71 »

I'm working on an industry NewGRF with features related to "stockpiled industries".

In the industry window, I would like to show how much incoming cargo is waiting, as highlighted in red in the attached screenshot, which was taken from a game with BPSI v2.13

Unfortunately, this NewGRF was written in NFO which is something I don't understand and don't have time to dig into.

Does anybody have a good code example in NML how to achieve the same thing to share here, as I looked at a number of other NML-coded NewGRFs and could not find anythig similar to what I have in mind.

The main problem I have is to display more than one "dynamic value" (one that changes)

waiting_cargo_display.png
waiting_cargo_display.png (127.71 KiB) Viewed 5177 times
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5630
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: How to display waiting cargo in industry window?

Post by PikkaBird »

Your industry has to use a produce block to handle cargo processing. The text will automatically appear.

Printing dynamic values in a custom text (eg the "production rate 4%" in the example image) is achieved by using string codes to print values packed into the text stack.
ebla71
Route Supervisor
Route Supervisor
Posts: 485
Joined: 14 Apr 2021 21:48
Location: Earth

Re: How to display waiting cargo in industry window?

Post by ebla71 »

PikkaBird wrote: 30 Aug 2024 20:50 Your industry has to use a produce block to handle cargo processing. The text will automatically appear.
But only and exclusively when using a "produce" block, right?!?

Not with a statement like

Code: Select all

cargo_types: [accept_cargo("AORE"), accept_cargo("SCMT"), accept_cargo("ACID"), produce_cargo("ALUM",2), produce_cargo("SLAG",1)];
That was driving me mad why the second way to produce cargo did not show the expected text :?

Any other ways to make the text "disappear" when using "produce" by messing around with some additional code?!?
ebla71
Route Supervisor
Route Supervisor
Posts: 485
Joined: 14 Apr 2021 21:48
Location: Earth

Re: How to display waiting cargo in industry window?

Post by ebla71 »

PikkaBird wrote: 30 Aug 2024 20:50 Printing dynamic values in a custom text (eg the "production rate 4%" in the example image) is achieved by using string codes to print values packed into the text stack.
Additional question: The text stack starts at "storage position" 256 and if you want to display more than one value, you will just go on with 257 and further, putting more than one variable in the string code?!?
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5630
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: How to display waiting cargo in industry window?

Post by PikkaBird »

ebla71 wrote: 30 Aug 2024 21:16 Not with a statement like

Code: Select all

cargo_types: [accept_cargo("AORE"), accept_cargo("SCMT"), accept_cargo("ACID"), produce_cargo("ALUM",2), produce_cargo("SLAG",1)];
That was driving me mad why the second way to produce cargo did not show the expected text :?
If you're using that method (which is how the base game industries work), nothing is ever waiting, as incoming cargos are processed immediately. If you want, eg, the industry to not produce anything until all input cargos are present, you need to use a produce block.
Additional question: The text stack starts at "storage position" 256 and if you want to display more than one value, you will just go on with 257 and further, putting more than one variable in the string code?!?
Yes, although it also depends on the size of the "string parameter" you're using. Each storage is 4 bytes, so if you use {COMMA}, {COMMA} it will fill with the values from storage 256 then 257. But if you use {SIGNED_WORD}, {SIGNED_WORD}, it will use the low two, then the high two, bytes from 256, and you have to arithmetically pack the two values into the one storage. There are examples on the spec page.
ebla71
Route Supervisor
Route Supervisor
Posts: 485
Joined: 14 Apr 2021 21:48
Location: Earth

Re: How to display waiting cargo in industry window?

Post by ebla71 »

PikkaBird wrote: 31 Aug 2024 05:19 If you're using that method (which is how the base game industries work), nothing is ever waiting, as incoming cargos are processed immediately. If you want, eg, the industry to not produce anything until all input cargos are present, you need to use a produce block.
Yes, I know.

But the decision in the code to display the waiting cargo (or not) is based on the presence of the "produce" block and not whether something is waiting or not, right? That was want confused me so much, as it does not really seem to be documented.

Since when I simply don't deliver anything to an industry in a NewGRF with "produce", waiting cargo is still shown (as zero).
User avatar
2TallTyler
Director
Director
Posts: 570
Joined: 11 Aug 2019 18:15
Contact:

Re: How to display waiting cargo in industry window?

Post by 2TallTyler »

If either of the production callbacks are used, the stockpile amount is drawn. You can manually hide this text with the 'cargo_subtype_display' callback. Here's an example of how to do that, in the Bank in Improved Town Industries.

I also use procedures (switches which act like functions) to construct the text stack. Take a look at an example function, then see the corresponding string to see how I've aligned the string with the registers. Each register is a word, which is two bytes. The {SKIP} string code skips a single byte.

Here is an example industry that uses this string, as well as custom production code.

Note that I start the text stack at register 257 (I forget why, I wrote this code a while ago!).
ebla71
Route Supervisor
Route Supervisor
Posts: 485
Joined: 14 Apr 2021 21:48
Location: Earth

Re: How to display waiting cargo in industry window?

Post by ebla71 »

2TallTyler wrote: 31 Aug 2024 13:38 If either of the production callbacks are used, the stockpile amount is drawn. You can manually hide this text with the 'cargo_subtype_display' callback.
Ah, now the mystery slowly clears up :lol:

Yes, there was the "cargo_subtype_display" callback in the example code that I used which explains why there was not text on waiting cargo although "produce" was used.

Thanks to everybody who contributed with explanations, now it is clear to me.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 0 guests