cargo_input Industry Callback

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

Moderator: Graphics Moderators

Post Reply
NovaTwine
Engineer
Engineer
Posts: 2
Joined: 04 Feb 2022 04:54

cargo_input Industry Callback

Post by NovaTwine »

Hello everyone,

is cargo_input only called at gamestart?

Code: Select all

//Decide construction material acceptance depending on a variable
switch(FEAT_INDUSTRIES, SELF, NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_DECIDECARGOACCEPTANCECMAT, UCMP(last_month_production("COAL"), 20)) { 1..2: CMAT; }
//DummyCall
switch(FEAT_INDUSTRIES, SELF, NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_DUMMY, UCMP(0, 1)) { 0: CMAT; }
//Iterate through different cargotypes and decide in the next call
switch(FEAT_INDUSTRIES, SELF, NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_ITERATECARGOACCEPTANCE, extra_callback_info1)
{
    0: PASS;
    1: NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_DECIDECARGOACCEPTANCECMAT;
}
//Define the actual industry item
item(FEAT_INDUSTRIES, NCBI_INDUSTRY_COALMINE, -1)
{
    property 
    {
        substitute: 0;
        override: 0;
        map_colour: 160;
        life_type: IND_LIFE_TYPE_EXTRACTIVE;
        min_cargo_distr: 5;
        layouts: [NCBI_TILELAYOUT_COALMINE];
        name: string(NCBI_INDUSTRY_COALMINE_NAME);
        cargo_types: [accept_cargo("PASS"), accept_cargo("MAIL"), accept_cargo("CMAT"), produce_cargo("COAL", 0)];
        prob_map_gen: 14;
        prob_in_game: 14;
        prospect_chance: 1;
        fund_cost_multiplier: 1;
        nearby_station_name: string(NCBI_STRINGTEMPLATE_STATION_NAME, string(NCBI_STRINGTEMPLATE_TOWN_NAME), string(NCBI_INDUSTRY_COALMINE_STATIONNAME));
    } 
    graphics
    {
        produce_256_ticks: NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_CHECKPRODUCTIONREQUIREMENTS;
        cargo_input: NCBI_SWITCH_PRODUCTIONMECHANICS_COALMINE_ITERATECARGOACCEPTANCE;
    }
}
//Dummycall is working i verified that by testing. Looks to me like, the cargo_input is only called at gamestart, or the callback cant make use of industry variables, ive also tried incoming_cargo_waiting("PASS") for example. It just doesnt react to industry variables in general that can change during gameplay.

So to clarify what i want to do is have the industry accept new types of cargo depending on various factors, id also like to use LOAD_PERM() as a factor to decide.

Also i can see this question coming up, so ill preemptively answer it: have i tried using "stop_accept_cargo" ?
Yes i have, but what that callback actually does, is stopping additional delivered cargo from entering the industry stockpile, it DOES NOT stop the cargo from showing up in the industry window.
If i synchronize it with the industrytile "cargo_amount_accept" and "cargo_type_accept", it will indeed completely stop it from accepting that cargo, even the station nearby, BUT it will still show up in the industry window.
Thats hella confusing for players! Also since i want to use the indication what cargos are accepted in the industry window to telegraph to my players: now this industry can be upgraded since it accepts construction materials, this is not an option.
If "cargo_input" would work dynamically depending on variables, i could also get rid of the "stop_accept_cargo" and "cargo_amount_accept" callbacks! IndustryTile could use the property "special_flags: bitmask(INDTILE_FLAG_ACCEPT_ALL)" and id be done with it.
Also, the industry callback "cargo_subtype_display" will edit text AFTER a cargo indicator in the industry window, so setting that to an empty string is also NOT a solution.

So as you can see ive already tried a couple of things here, maybe someone has an idea how to do it differently, or can just correct me if i made a mistake, or know how this callback actually functions. thanks in advance

as a sidenote, if it really only gets called at gamestart, someone should explicitly mentiont hat in the nml wiki
also this forum wasnt able to let me search for cargo_input, it coulnt handle the underscore, instead it will split the search query to cargo and input
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: cargo_input Industry Callback

Post by PikkaBird »

Correct, you cannot dynamically change what cargos an industry processes. The callback is run only when the industry is created (either at game start or by funding/random chance during a running game).

As you've pointed out, you can change the tile and industry acceptances to start/stop the industry receiving particular cargos. You can also use extra_text_industry to communicate to players through the industry window. But - if you're using stockpile processing - you cannot prevent the industry from always having, and displaying, a stockpile for every cargo it will ever process.
NovaTwine
Engineer
Engineer
Posts: 2
Joined: 04 Feb 2022 04:54

Re: cargo_input Industry Callback

Post by NovaTwine »

very sad indeed, any chance that this will be possible at some point in the future? would i have to work on the OpenTTD source code or bribe someone to do it?
at least my instincts didnt fail me and i actually diagnosed whats wrong correctly.
Any chance we can get someone to update the wiki to mention that, so others wont go through the same procedure i have?
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: cargo_input Industry Callback

Post by PikkaBird »

NovaTwine wrote: 04 Feb 2022 06:01Any chance we can get someone to update the wiki to mention that, so others wont go through the same procedure i have?
I have done it.
User avatar
PikkaBird
Graphics Moderator
Graphics Moderator
Posts: 5602
Joined: 13 Sep 2004 13:21
Location: The Moon

Re: cargo_input Industry Callback

Post by PikkaBird »

NovaTwine wrote: 04 Feb 2022 06:01 very sad indeed, any chance that this will be possible at some point in the future? would i have to work on the OpenTTD source code or bribe someone to do it?
at least my instincts didnt fail me and i actually diagnosed whats wrong correctly.
Any chance we can get someone to update the wiki to mention that, so others wont go through the same procedure i have?
As 2TallTyler recently pointed out in a different thread, you can apparently hide a stockpile by using the Cargo sub-type display callback. So you may be able to achieve the effect you wanted after all!
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 16 guests