Industry - production change cb on consruction (patch)

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

Moderator: Graphics Moderators

Post Reply
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Industry - production change cb on consruction (patch)

Post by andythenorth »

It would be useful to be able to run the production change cb when an industry is constructed.
- set / randomise initial production
- convenient and sensible place to initialise local storage (can return 'no change' as the cb result)

Wondering if it would be acceptable to:
- define a bit on cb flags (prop 22),
- if bit set, call IndustryMonthlyLoop() from DoCreateNewIndustry()

[EDIT - that was a silly approach, sensible patch in next post.]

This is same way colour / cargo callbacks are called, and avoids duplicating IndustryMonthlyLoop, but I don't know if it's sane.

I favour this approach because it solves the problem, won't break existing newgrfs, involves very little new code, and won't require many (if any) changes in renum/nml.

industry_cmd.cpp, lines around 2681, 1656
Last edited by andythenorth on 22 Apr 2012 06:17, edited 1 time in total.
User avatar
andythenorth
Tycoon
Tycoon
Posts: 5705
Joined: 31 Mar 2007 14:23
Location: Lost in Music

Re: Industry - production change cb on consruction

Post by andythenorth »

Patch adds callback 15F, called on industry construction.
(Patch updated to address various issues, also adding cb to newgrf debug, also fix comments)

Return 4-128 to set production level (prod_level).

Patch for nml to add cb 15F.

Version of FIRS where Arable Farm uses cb 15F.
cb_15f.patch
(2.91 KiB) Downloaded 178 times
nml_cb_15f.patch
(590 Bytes) Downloaded 136 times
firs-r2752M.zip
(341.12 KiB) Downloaded 126 times
-- Possible extension --
Authors using production cb for primary production (or other purposes) might want to set 'previous month production' accurately using their production algorithm. Values for last_month_production[0] and last_month_production[1] could be optionally set by cb 15F. Pass absolute values for these in registers 0x100 and 0x101?

EDIT - irc discussion suggested that authors using production cb for production can still set initial prod_level via cb 15F to adjust the value of 'previous month production' to one suiting the industry.
Post Reply

Return to “NewGRF Technical Discussions”

Who is online

Users browsing this forum: No registered users and 8 guests