Industry NewGRF How to limit production?

Discuss, get help with, or post new graphics for TTDPatch and OpenTTD, using the NewGRF system, here. Graphics for plain TTD also acceptable here.

Moderator: Graphics Moderators

Post Reply
ebla71
Transport Coordinator
Transport Coordinator
Posts: 344
Joined: 14 Apr 2021 21:48
Location: Earth

Industry NewGRF How to limit production?

Post by ebla71 »

Have a problem with an industry NewGRF I'm currently working on:

I want to limit the production of a cargo in the sense that if a certain amount of it is already waiting to be transported, no more is produced until the amount waiting has dropped again below some value, in order to avoid the sometimes ridiculously high amounts of cargo around at certain stations, in particular for the primary industries.

I'm trying to use the code fragment below, but nothing is produced at all :?

My problem is that I am not even sure if the problem is from the produce() function or the switch block, so that produce is never even reached?!?

Or is it already the produce_cargo_arrival function, since I also want to produce MILK also with no other cargo arriving, maybe just FMSP later to boost production.

(There is additional code in the property and graphics sections but I believe that is irrelevant here)

Code: Select all

produce(Cow_Farm_prod_cb1, [],	[MILK: 16;])

produce(Cow_Farm_empty_prod, [], [])

switch(FEAT_INDUSTRIES, SELF, Cow_Farm_prod_cb0, produced_cargo_waiting("MILK"))
 {
		0..10000: Cow_Farm_prod_cb1;
		Cow_Farm_empty_prod;
 }

item(FEAT_INDUSTRIES, Cow_Farm, 21) {
  property {
            cargo_types: [accept_cargo("FMSP"), produce_cargo("MILK",0), produce_cargo("LVST",0)];
  }
  graphics {
    		produce_cargo_arrival: 		Cow_Farm_prod_cb0;
  }
}

User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: Industry NewGRF How to limit production?

Post by PikkaBird »

produce_cargo_arrival will only activate when a cargo is delivered, so yes, if you want regular production (and then test for stockpiled FMSP for a potential boost), you'll want to use produce_256_ticks instead.

produced_cargo_waiting also does not do what you think it does - it's not checking for cargo on surrounding stations, just for produced cargo held within the industry itself (which I think only happens during the production callback, if you're running it multiple times). OTOH, the mechanic you're describing, to distribute less cargo to stations which are not efficiently carrying it away, already exists in the base game - stations with poor ratings get less cargo.
ebla71
Transport Coordinator
Transport Coordinator
Posts: 344
Joined: 14 Apr 2021 21:48
Location: Earth

Re: Industry NewGRF How to limit production?

Post by ebla71 »

PikkaBird wrote: 01 Apr 2024 04:41 produce_cargo_arrival will only activate when a cargo is delivered, so yes, if you want regular production (and then test for stockpiled FMSP for a potential boost), you'll want to use produce_256_ticks instead.
Thank you very much - with the other suggested function, it now generally works as intended (not to produce any more of a cargo if a certain threshold value waiting is exceeded), although I still have to optimize the parameters a bit further.

In that context another question:

Is it possible to individually adjust the "cargo aging" for each industry separately in the sense of "time in which a cargo disappears from a station if it is not picked up within a certain time interval"?!?

For example, coal and ore can be around without turning old and bad for years, if not decades while milk obviously will age within hours or days if not processed.

So I want certain "durable" cargos bascially to stay around forever if not picked up while others to "age" normally or even more quickly than in the standard game.
Post Reply

Return to “Graphics Development”

Who is online

Users browsing this forum: Bing [Bot] and 24 guests