Callback: Random production change

From GRFSpecs
Revision as of 18:57, 16 June 2011 by Pm-bot (talk | contribs) (Create a separate page for each callback)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Random production change (29)

Called when TTD chooses the industry for a random production change. Variable 18 contains 32 random bits to help randomizing the decision. The callback must return one of the following results:

Value Meaning Min. Version
00 Do nothing
01 Halve industry production. If production goes below the quarter of the default, the industry is closed instead, as if you returned 03.
02 Double industry production if it hasn't reached eight times of the original yet.
03 The industry announces imminent closure, and is physically removed from the map next month.
04 Do the standard random production change as if this industry was a primary one.
05 Divide production by 4
06 Divide production by 8
07 Divide production by 16
08 Divide production by 32
09 Multiply production by 4
0A Multiply production by 8
0B Multiply production by 16
0C Multiply production by 32
0D Decrement production by 1 OpenTTD r11532, TTDPatch 2.6 r2046
0E Increment production by 1 OpenTTD r11532, TTDPatch 2.6 r2046
0F Set production as returned in bits 16..23 of register 0x100 (clamped to 4..128) OpenTTD r14561, TTDPatch 2.6 r2068

Since TTDPatch 2.5 beta 1, you can set bit 7 of this value to suppress the news message announcing the production change. Be careful with this, especially for closedown messages; most players wouldn't like those being suppressed.

For return values 05..0C, the double/halve news messages are displayed. You should probably replace the defaults with some text that doesn't explicitly say "double" or "halve", or use the message override feature (see below). If a divide operation brings the production below the quarter of the default, the industry is closed down instead. Multiply operations that would bring the production above 8 times of the original will only increase it to that value.

Since r1306, you can override the default news messages that appear after production changes. To do this, you must set bit 8 of the returned result, and put the textID into the low word of GRF register 100h (the high word of the register is ignored). The textID can be of a default TTD text or a DCxx text; it cannot be a D0xx text. If the given action generates a message, it will be the one you specified. It may, however, not generate messages at all; for example, operation 04 may decide not to change the production, and then your message won't be shown. There is one exception: operation 00 would never generate a message, but it still will when bit 8 is set. This is useful in conjunction with callback 35, to tell the player about things that don't change the production multiplier, but are still important enough to require a news message.

Using return values 0Dh, 0Eh and 0Fh you can adjust production rates more smoothly. The production rate is a value between 04h and 80h (initial value 10h). Returning 0Dh when the production is at 4 will close the industry. But returning 0Fh will never close the industry, instead the value is clamped to the allowed range. Note that OpenTTD before r15103 did not properly updated production rates provided by properties 12 and 13.