Action2/Industries

From GRFSpecs
< Action2
Revision as of 01:50, 15 July 2005 by dmccoy (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Defining the industry production callback

Industry Production Callback

Defining the industry production callback

Industries don't have graphics directly associated with them (they have graphics through their tiles), so they can't have a traditional action 2. However, they still can use action 2 for a special purpose: production callbacks. A production callback can define exactly how an industry is producing cargo, but this needs more than the 15 bits a normal callback can return.

When an industry has bits 1 or 2 set in property 21, its production is changed. Instead of processing the incoming cargo instantly, it remembers how many units are waiting, and uses the production callback mechanism to decide how much cargo must be produced.

-=Format=-

For the production callback, the action 2 data looks as follows:

 -+<Sprite-number> * <Length> 02 0A <set-id> <version> <subtract-in-1> <subtract-in-2> <subtract-in-3> <add-out-1> <add-out-2> <again>+- 

||Element|Size|Description

<Sprite-number>|dec|A sequential sprite number

<length>|dec|The total number of bytes used in this action

02|B|Defines action 02

0A|B|feature 0A=industries

<set-id>|B|ID for this definition

<version>|B|version of the production-callback format, currently must be 00

<subtract-in-1..3>|W|Amounts to be subtracted from the incoming cargoes waiting to be processed.

<add-out-1/2>|W|Amounts to be added to the produced cargoes.

<again>|B|Repeat callback if 01, do not repeat if 00||

-=Details=-

Subtract-in-1..3

The total amount of cargo waiting cannot go negative.  If you specify more than the amount actually waiting, the incoming amount will be zeroed instead.

During this callback, the lowest byte of variable 18 contains the reason the callback is called: 0 if it was called because of incoming cargo, 1 if it was called in the periodic processing. Bits 8-23 contain how many times the callback was already called in this loop, i.e. 0 for the first call, 1 for the second etc.)