Callback: Random production change

From GRFSpecs
Revision as of 17:15, 28 April 2012 by Frosch (talk | contribs) (unify naming to "production level")
(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 Version Meaning
00 Supported by OpenTTD Supported by TTDPatch Do nothing
01 Supported by OpenTTD Supported by TTDPatch Halve industry production. If production goes below the quarter of the default, the industry is closed instead, as if you returned 03.
02 Supported by OpenTTD Supported by TTDPatch Double industry production if it hasn't reached eight times of the original yet.
03 Supported by OpenTTD Supported by TTDPatch The industry announces imminent closure, and is physically removed from the map next month.
04 Supported by OpenTTD Supported by TTDPatch Do the standard random production change as if this industry was a primary one.
05 Supported by OpenTTD Supported by TTDPatch Divide production by 4
06 Supported by OpenTTD Supported by TTDPatch Divide production by 8
07 Supported by OpenTTD Supported by TTDPatch Divide production by 16
08 Supported by OpenTTD Supported by TTDPatch Divide production by 32
09 Supported by OpenTTD Supported by TTDPatch Multiply production by 4
0A Supported by OpenTTD Supported by TTDPatch Multiply production by 8
0B Supported by OpenTTD Supported by TTDPatch Multiply production by 16
0C Supported by OpenTTD Supported by TTDPatch Multiply production by 32
0D Supported by OpenTTD 0.6 (r11532)0.6 Supported by TTDPatch 2.6 (r2046)2.6 Decrement production by 1
0E Supported by OpenTTD 0.6 (r11532)0.6 Supported by TTDPatch 2.6 (r2046)2.6 Increment production by 1
0F Supported by OpenTTD 0.7 (r14561)0.7 Supported by TTDPatch 2.6 (r2068)2.6 Set production as returned in bits 16..23 of register 0x100 (clamped to 4..128)

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 TTDPatch 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 level more smoothly. The production level 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.