NML:Produce

From GRFSpecs
Revision as of 11:30, 21 August 2011 by FooBar (talk | contribs) (content of nml r1625)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

The produce block is only available for industries and describes how the industry consumes incoming and creates outgoing cargo. The syntax is:

produce (<ID>, <consume_1>, <consume_2>, <consume_3>, <produce_1>, <produce_2> [, run_again]);

where

  • ID is a unique name of the block
  • consume_1, consume_2, consume_3 are expressions which give the amount of the respective input cargo consumed during this call of the produce block. The given amounts are subtracted from the stockpile of cargo waiting to be processed.
  • produce_1, produce_2 are expressions which give the amount of the produced (outgoing) cargos in the produce block.
  • run_again is a boolean expression which evaluates to either 0 or 1. It indicates whether the produce block shall be called again. This is optional, with a default value of 0.

Note that industry variables can be used in the produce-block, so you can for example query the amount of waiting cargo directly and use that in your expression.

The produce block should be the result of the production callback of an industry. An example on how it can be used without actually processing cargo but counting the time an industry exists unserviced:

 /* Every month, the counter is increased. The counter is reset to zero whenever the power plant
  * receives cargo. When the counter reaches 61, the industry will close when the random production
  * change callback is called. */
 
 /* When we receive cargo, the counter is reset. */
 produce(power_plant_cargo_arrive_produce, 0, 0, 0, 0, STORE_PERM(0, 0x00));
 
 /* Every month the counter is increased. */
 switch (FEAT_INDUSTRIES, SELF, power_plant_monthly_prod_change_switch, STORE_PERM(LOAD_PERM(0x00) + 1, 0x00)) {
 	return CB_RESULT_IND_PROD_NO_CHANGE;
 }
 
 /* Only check industry closure if the counter is greater than 60. */
 switch (FEAT_INDUSTRIES, SELF, power_plant_random_prod_change_switch, LOAD_PERM(0x00)) {
 	0..60: return CB_RESULT_IND_PROD_NO_CHANGE;
 	return CB_RESULT_IND_PROD_CLOSE;
 }
 
 item(FEAT_INDUSTRIES, industry_power_plant, INDUSTRYTYPE_POWER_PLANT) {
 	graphics {
 		produce_cargo_arrival: power_plant_cargo_arrive_produce;
 		monthly_prod_change: power_plant_monthly_prod_change_switch;
 		random_prod_change: power_plant_random_prod_change_switch;
 	}
 }