cargo_types and making specific "recipes"

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

Moderator: Graphics Moderators

Post Reply
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

cargo_types and making specific "recipes"

Post by Erato »

Hey guys!

I'm working on a challenge scenario for OpenTTD with custom industry and some custom vehicles. The goal of the scenario would be to deliver 1 X to a certain industry before a certain date. I'm new to industries so I'm not quite sure how I'd get this to work:
In the NML documentation it mentions that, in the cargo_types array, the following code

Code: Select all

accept_cargo("IORE", produce_cargo("STEL", 1), produce_cargo("SLAG", 0.25))
would produce 4 STEL and 1 SLAG for every 4 IORE delivered. Is it also possible to make it so it would produce 1 IORE, for every 4 STEL and 1 SLAG you deliver? Would excess be ignored. i.e. if I were to deliver 9 STEL and 3 SLAG would you leave with 2 IORE, with 1 STEL and 1 SLAG remaining in the industry?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
jfs
Tycoon
Tycoon
Posts: 1758
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: cargo_types and making specific "recipes"

Post by jfs »

If you want to make rules that require two cargo types to both be delivered before any production happens, you need to use the production callbacks, the default production rules are not enough.

Production callbacks require a bit of planning and deciding which kind of rules you want exactly. There's two production callbacks, "on delivery" and "on production tick". The "on delivery" one happens every time the industry receives a cargo delivery from a station, the "on production tick" one happens every 256 ticks (approx. 3.5 days).
You also need to figure out how you want to handle the "both cargo types delivered" condition, whether to use the built-in stockpiling mechanic, or keep track of some variables yourself.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: cargo_types and making specific "recipes"

Post by Erato »

jfs wrote: 16 Jun 2019 22:01 If you want to make rules that require two cargo types to both be delivered before any production happens, you need to use the production callbacks, the default production rules are not enough.

Production callbacks require a bit of planning and deciding which kind of rules you want exactly. There's two production callbacks, "on delivery" and "on production tick". The "on delivery" one happens every time the industry receives a cargo delivery from a station, the "on production tick" one happens every 256 ticks (approx. 3.5 days).
You also need to figure out how you want to handle the "both cargo types delivered" condition, whether to use the built-in stockpiling mechanic, or keep track of some variables yourself.
Thanks! I think I can get this to work.
No pics no clicks. Seriously.
ImageImageImageImageImageImage
Eddi
Tycoon
Tycoon
Posts: 8267
Joined: 17 Jan 2007 00:14

Re: cargo_types and making specific "recipes"

Post by Eddi »

Erato wrote: 16 Jun 2019 19:27if I were to deliver 9 STEL and 3 SLAG would you leave with 2 IORE, with 1 STEL and 1 SLAG remaining in the industry?
you can store the remainder in a register (STORE_PERM), and use that in the next iteration (LOAD_PERM) of the production callback. but it is up to you to do that, the game won't do it for you.
User avatar
Erato
Chief Executive
Chief Executive
Posts: 740
Joined: 25 May 2015 09:09
Location: The Netherlands

Re: cargo_types and making specific "recipes"

Post by Erato »

Eddi wrote: 16 Jun 2019 22:51
Erato wrote: 16 Jun 2019 19:27if I were to deliver 9 STEL and 3 SLAG would you leave with 2 IORE, with 1 STEL and 1 SLAG remaining in the industry?
you can store the remainder in a register (STORE_PERM), and use that in the next iteration (LOAD_PERM) of the production callback. but it is up to you to do that, the game won't do it for you.
Wouldn't this be handled by the produce block?
No pics no clicks. Seriously.
ImageImageImageImageImageImage
User avatar
jfs
Tycoon
Tycoon
Posts: 1758
Joined: 08 Jan 2003 23:09
Location: Denmark

Re: cargo_types and making specific "recipes"

Post by jfs »

Eddi wrote: 16 Jun 2019 22:51
Erato wrote: 16 Jun 2019 19:27if I were to deliver 9 STEL and 3 SLAG would you leave with 2 IORE, with 1 STEL and 1 SLAG remaining in the industry?
you can store the remainder in a register (STORE_PERM), and use that in the next iteration (LOAD_PERM) of the production callback. but it is up to you to do that, the game won't do it for you.
It actually will. If you don't process all the received cargo in your on-delivery production callback the built-in stockpiling mode will be active and the industry will keep track of how much unprocessed incoming cargo it has of each type, available through the standard "incoming cargo waiting" variables.
Where you may need to do manual management of stored cargo is if you want some kind of "decay" mechanic, where unused cargo disappears after a while. (I think this will be difficult to implement well.)
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 28 guests