Industries

Industry variables

namevalue rangecomment
waiting_cargo_10..65535If IND_CBF_PROD_CB_CARGO_ARRIVE or IND_CBF_PROD_CB_256_TICKS are set in the callback_flags property, this variable will contain the amount of the first cargo type awaiting to be processed.
waiting_cargo_20..65535If IND_CBF_PROD_CB_CARGO_ARRIVE or IND_CBF_PROD_CB_256_TICKS are set in the callback_flags property, this variable will contain the amount of the second cargo type awaiting to be processed.
waiting_cargo_30..65535If IND_CBF_PROD_CB_CARGO_ARRIVE or IND_CBF_PROD_CB_256_TICKS are set in the callback_flags property, this variable will contain the amount of the third cargo type awaiting to be processed.
produced_last_month_10..65535The amount of 'output cargo type 1' that was produced last month.
produced_last_month_20..65535The amount of 'output cargo type 2' that was produced last month.
water_distanceDistance to the tileIf the industry is built on water, this variable gives the distance of the closest dry land tile, otherwise it gives the distance of the closest water tile.
layout_num1..255Number of the layout being used by the industry.
founder0..16Company number of the industry founder. It will be 16 (0x10) if the industry was generated randomly. TTDPatch only supports up to 8 companies (0..7).
founder_typePLAYERTYPE_XXPLAYERTYPE_HUMAN, PLAYERTYPE_AI, PLAYERTYPE_HUMAN_IN_AI (human managing AI company) or PLAYERTYPE_AI_IN_HUMAN (AI managing human company). OpenTTD only uses PLAYERTYPE_HUMAN and PLAYERTYPE_AI. If you cheat yourself to be part of an AI company OpenTTD will still report PLAYERTYPE_AI for the company with yourself and the AI and it'll report PLAYERTYPE_HUMAN for the now uncontrolled company.
founder_colour10..15Index of founding company's first colour. 0 if not founded by a company.
founder_colour20..15Index of founding company's second colour. It's the same as company_colour1, if no second company colour is chosen. 0 if not founded by a company.
colour0..15Random colour for this industry.
build_date0..1826212865Date of the industry foundation in days since year 0.
build_typeBUILDTYPE_XXBUILDTYPE_UNKNOWN (if created in an old version or with newindustries disabled), BUILDTYPE_GAMEPLAY (if founded or created by the in-game random industry generator), BUILDTYPE_GENERATION (if created during random map generation) or BUILDTYPE_EDITOR (if created with the scenario editor).

Variables that require some parameters.
nameargumentscomment
industry_countindustry_type, grfid = -1The value of this variable is the number of industries of a given type that are currently on the map. industry_type is either the ID of an industry. GRFid is the grf in which the industry was defined. The default value is -1, which means current newgrf. A grfid of 0 lets you check the number of default industries of a given type.
Warning: using this variable trashes the contents of temporary storage register 0x100
industry_distanceindustry_type, grfid = -1The value of this variable is the manhattan distance the closest instance of the given industry or 0xFFFF if not applicable. See industry_count for a description of the parameters.
Warning: using this variable trashes the contents of temporary storage register 0x100.
industry_layout_count / industry_layout_distanceindustry_type, layout, grfid = -1. See industry_count / industry_distance for description of industry_type, grfid and return value. The results are filtered to industries that have the given layout number.
Warning: using this variable trashes the contents of temporary storage registers 0x100 and 0x101.
industry_town_countindustry_type, grfid = -1. See industry_count / industry_distance for description of industry_type, grfid and return value. The results are filtered to industries that have the same town than the current industry.
Warning: using this variable trashes the contents of temporary storage registers 0x100 and 0x101.
town_manhattan_distx, yParameters indicate a signed offset relative to the northern tile. Returns the Manhattan distance (dx + dy) from the selected tile to the closest town
town_euclidean_distx, yParameters indicate a signed offset relative to the northern tile. Returns the squared Eucleidean distance (dx^2 + dy^2) from the selected tile to the closest town.
town_zonex, yParameters indicate a signed offset relative to the northern tile. Returns the town zone that the selected tile is in.
nearby_tile_random_bitsx, yParameters indicate an unsigned offset relative to the northern tile. Returns the random bits of the selected industry tile, or 0 if it is not an industry tile that's part of this industry.

Common variables

The following variables are available to both industries and industry tiles. All of them require an x, y offset. For industries, this offset is unsigned and relative to the northernmost tile. For industry tiles, it is signed and relative to the current tile.

namevalue rangecomment
nearby_tile_slopeWhich corners are raised on the given tile. Bit 0: west corner is above the lowest corner.
Bit 1: south corner is above the lowest corner.
Bit 2: east corner is above the lowest corner.
Bit 3: north corner is above the lowest corner.
Bit 4: this tile is a steep slope (the corner opposite to the lowest corner is 2 units higher).
See tile slopes for an illustration
nearby_tile_is_water1 if the tile is water, 0 otherwise
nearby_tile_terrain_typeTILETYPE_XXTILETYPE_NORMAL, TILETYPE_DESERT, TILETYPE_RAIN_FOREST, TILETYPE_SNOW
nearby_tile_height0..120The height of the lowest corner of the given tile.
nearby_tile_classTile class
nearby_tile_animation_frame0..255Animation frame of the given tile
nearby_tile_industrytile_id0x00aa, 0xFFbb, 0xFFFE or 0xFFFF 0x00aa: The tile is an industry tile that is part of this GRF, the tile id is aa.
0xFFbb: The tile is an original industry tile with id bb.
0xFFFE: The tile is an industry tile defined in another GRF.
0xFFFF: The tile is not an industry tile or it belongs to another GRF.

Industry tile variables

namevalue rangecomment
construction_state0..3Current construction state of the industry tile.
terrain_typeTILETYPE_XXTILETYPE_NORMAL, TILETYPE_DESERT, TILETYPE_RAIN_FOREST, TILETYPE_SNOW
town_zonetown zoneThe town zone of the current tile.
relative_x0..255X-coordinate (top right -> bottom left) of the tile relative to the northernmost tile.
relative_y0..255Y-coordinate (top left -> bottom right) of the tile relative to the northernmost tile.
relative_pos0xYYXXA combination of relative_x and relative_y in the format 0xYYXX. Useful if you want to check for a single position.
animation_frame0..255Current animation frame.

Industry tiles have access to the common variables described above. Additionally, they have access to the following:

nameargumentscomment
nearby_tile_is_same_industryx, yParameters indicate a signed tile offset relative to the current tile. Returns 1 if the tile is part of the same industry, 0 otherwise

Industry tile properties

propertyvalue rangecomment
substitute0..174Number of the default industry tile that replaces this one, if this industry tile is not available for some reason. This property must be set first, before any other properties or graphics. All properties of the old type are copied to your new house.
override0..174id of the default industry tile which this industry tile replaces. This will cause your industry tile to be placed instead of the default industry tile. This is ignored, if the default industry tile has already been overridden. You can define this property multiple times
accepted_cargosArray with up to 3 [cargo_id, amount]-pairs.The cargos that are accepted by this tile. CargoID is a cargo type from your cargo translation table, amount is the acceptance of the given cargo in 1/8 units.
Example: to make a tile accept both COAL and IORE you could use this: accepted_cargos: [[COAL, 8], [IORE, 8]];
Example: for a tile that doesn't any cargos at all you'd use: accepted_cargos: [];
land_shape_flagsbitmask(Land shape flags)
callback_flagsbitmask(INDTILE_CBF_XXX, INDTILE_CBF_YYY)XXX = ANIM_NEXT_FRAME | ANIM_SPEED | CARGO_AMOUNT_ACCEPT | CARGO_TYPE_ACCEPT | SLOPE_IS_SUITABLE | FOUNDATIONS | AUTOSLOPE
animation_infoArray [ANIMATION_XXX, frame-count]XXX = [LOOPING | NON_LOOPING], 1..253 frames
animation_speed0..16Speed of animation, see animation speed table for the meaning of the values.
animation_triggersbitmask(Animation control callback triggers)Triggers which control whether the animatin is started or stopped
special_flags0..1Set to 1 if INDTILE_CB_ANIM_NEXT_FRAME needs random bits

Land shape flags

FlagMeaning
LSF_CANNOT_LOWER_NW_EDGENorth-west edge cannot be lowered
LSF_CANNOT_LOWER_NE_EDGENorth-east edge cannot be lowered
LSF_CANNOT_LOWER_SW_EDGESouth-west edge cannot be lowered
LSF_CANNOT_LOWER_SE_EDGESouth-east edge cannot be lowered
LSF_ONLY_ON_FLAT_LANDThis tile can only be built on flat land
LSF_ALLOW_ON_WATERThe land/water check is disabled for this tile so it can be built on water. If you need more control over this use callback 0x2F.

Callbacks

CallbackValuesMeaning
INDTILE_CB_ANIM_STARTSTOPanimation frame or CB_RESULT_XXXCalled by a trigger. It decides upon the next animation frame. Special values: XXX=[STOP_ANIMATION | NEXT_FRAME | DO_NOTHING]
INDTILE_CB_ANIM_NEXT_FRAMEanimation frame or CB_RESULT_XXXCalled each animation frame. It decides upon the next animation frame. Special values: XXX=[STOP_ANIMATION | NEXT_FRAME]
INDTILE_CB_ANIM_SPEEDlengthLength of the animation frame as defined in the apendix. This is a very expensive callback and try to avoid it, if possible, by using identical animation frames.
INDTILE_CB_CARGO_AMOUNT_ACCEPTspecialaccepted cargo amounts in 1/8. Bits 0...3: 1st cargo, bits 4 ... 7: 2nd cargo, bits 8 ... 11: 3rd cargo
INDTILE_CB_CARGO_TYPE_ACCEPTspecialaccepted cargo types as entry in the CTT. Bits 0...4: 1st cargo, bits 5 ... 9: 2nd cargo, bits 10 ... 14: 3rd cargo
INDTILE_CB_SLOPE_IS_SUITABLEdecide whether the location is suitable for the tile (for build checks of the industry)
INDTILE_CB_FOUNDATIONSCB_RESULT_XXXwith XXX=[FOUNDATIONS | NO_FOUNDATIONS]
INDTILE_CB_AUTOSLOPECB_RESULT_XXXwith XXX=[AUTOSLOPE | NO_AUTOSLOPE]

Animation control callback triggers

TriggerMeaning
INDTILE_TRIGGER_CONSTRUCTION_STATEthe construction state changes
INDTILE_TRIGGER_TILE_LOOPthe tile is processed in the periodic processing loop
INDTILE_TRIGGER_INDUSTRY_LOOPthe industry of the tile is processed in the periodic processing loop (synchronized animation)
INDTILE_TRIGGER_INDUSTRY_RECEIVED_CARGOthe industry of the tile receives input cargo from a station
INDTILE_TRIGGER_INDUSTRY_DISTRIBUTES_CARGOthe industry distributes its output cargo to one of the stations nearby

Industry properties

Industry properties. Default industry type numbers can be found at default industries.

propertyvalue rangecomment
substituteindustry typeNumber of the original industry type that replaces this one, should it not be available for some reason (e.g. missing NewGRF). This must be the first property to be set, before any other properties or graphics. All properties of the old type are copied to your new industry.
overrideindustry typeNumber of the original industry type overridden. This will cause other grfs / industries to consider your industry type the same as the old type. Only set this property if your type is (more or less) the same as the old type.
layoutsArray of tilelayoutsSee Tilelayout syntax.
life_typeOne of IND_LIFE_TYPE_XXX, XXX = BLACK_HOLE | EXTRACTIVE | ORGANIC | PROCESSINGThe generic type of industry. This determines the production changes that occur by default (when not using the callback). Examples are respectively power plants, coal mines, forests en steel mills.
closure_msgstringMessage displayed when the industry announces closure.
prod_increase_msgstringMessage displayed when industry increases production.
prod_decrease_msgstringMessage displayed when industry decreases production.
fund_cost_multiplier0..255Fund cost multiplier. Note that in OpenTTD the unmodified base cost is 8x higher for building (not prospecting) raw (=extractive / organic, see life_type) industries.
prod_cargo_typesarray of up to 2 intsTypes of cargo produced. Use the cargotype(<label>) built-in function to specify a label from the cargotable.
accept_cargo_types array of up to 3 intsTypes of cargo accepted. Use the cargotype(<label>) built-in function to specify a label from the cargotable
prod_multiplierarray of up to 2 ints (0..255)Amount of each output cargo to produce every 256 ticks (8 or 9 times a month)
min_cargo_distr0..255Minimal amount of cargo before transporting to stations.
random_sound_effectsarray of intsSound effect numbers that are played some times.
conflicting_ind_typesarray of up to 3x industry_type(IND_TYPE_OLD | IND_TYPE_NEW, id)Three industry types that should not be nearby. Use the builtin-function industry_type(..) to define either an old industry (using the global ID) or a new industry from your grf (using the grf-local ID).
prob_random0..10Probability of occurring while generating initial industries.
prob_in_game0..10Probability of occurring while creating industries during the game.
map_colour0..255Colour index from the DOS palette to use on the minimap for this industry.
spec_flagsbitmask(flags)for flag values see Industry special flags
new_ind_msgstringMessage displayed when industry gets built during game play.
input_multiplier_1array of up to 2 floats (0..255)Output cargo multiplication factors for getting a unit of the first accepted cargo.
input_multiplier_2array of up to 2 floats (0..255)Output cargo multiplication factors for getting a unit of the second accepted cargo.
input_multiplier_3array of up to 2 floats (0..255)Output cargo multiplication factors for getting a unit of the third accepted cargo.
namestringName of the industry
prospect_chanceFraction between 0 and 1Chance of successful prospecting.
callback_flagsbitmask(flags)for flag values see Industry callback flags
remove_cost_multiplierintCost multiplier for removing the industry (currently only possible with magic bulldozer).
nearby_station_namestringDefault additional name for a nearby station

Industry callback flags

callback and callback flag
IND_CB_XXX and IND_CBF_XXX
return valuesmeaning
IND_CBF_AVAILABILITYCB_RESULT_IND_ALLOW
CB_RESULT_IND_DISALLOW
decide upon availability of the industry type.
extra_callback_info_2 allows to get information on how the industry is being built:
0: during map generation
1: random generation ingame
2: user trying to fund or prospect the industry
IND_CBF_PROD_CB_CARGO_ARRIVE
(no callback, use produce block)
n/a (use produce block) handle production when cargo is delivered. See produce block
IND_CBF_PROD_CB_256_TICKS
(no callback, use produce block)
n/a (use produce block) handle production every 256 ticks. See produce block
IND_CBF_LOCATION_CHECKstring
CB_RESULT_IND_ALLOW_LOCATION
CB_RESULT_IND_DISALLOW_UNSUITABLE
CB_RESULT_IND_DISALLOW_ONLY_RAINFOREST
CB_RESULT_IND_DISALLOW_ONLY_DESERT
handle check for permissible build locations
extra_callback_info_2 allows to get information on how the industry is being built:
0: during map generation
1: random generation ingame
2: user trying to fund the industry
3: user trying to prospect the industry
IND_CBF_RANDOM_PROD_CHANGEsee monthly production changes belowhandle random production changes
IND_CBF_MONTHLY_PROD_CHANGECB_RESULT_IND_PROD_NO_CHANGE
CB_RESULT_IND_PROD_HALF
CB_RESULT_IND_PROD_DOUBLE
CB_RESULT_IND_PROD_CLOSE
CB_RESULT_IND_PROD_RANDOM
CB_RESULT_IND_PROD_DIVIDE_BY_4
CB_RESULT_IND_PROD_DIVIDE_BY_8
CB_RESULT_IND_PROD_DIVIDE_BY_16
CB_RESULT_IND_PROD_DIVIDE_BY_32
CB_RESULT_IND_PROD_MULTIPLY_BY_4
CB_RESULT_IND_PROD_MULTIPLY_BY_8
CB_RESULT_IND_PROD_MULTIPLY_BY_16
CB_RESULT_IND_PROD_MULTIPLY_BY_32
CB_RESULT_IND_PROD_DECREMENT_BY_1
CB_RESULT_IND_PROD_INCREMENT_BY_1
CB_RESULT_IND_PROD_SET_BY_0x100
handle monthly production changes
IND_CBF_CARGO_SUBTYPE_DISPLAYstringdecide on displayed cargo subtypes
IND_CBF_EXTRA_TEXT_FUNDstringdecide on extra text displayed in industry funding window
IND_CBF_EXTRA_TEXT_INDUSTRYstringdecide on extra text in the industry window
IND_CBF_CONTROL_SPECIALCB_RESULT_IND_DO_NOT_USE_SPECIAL
CB_RESULT_IND_USE_SPECIAL
decide whether the special defined in spec_flags shall be used or not
IND_CBF_STOP_ACCEPT_CARGOdecide on cargo acceptance
IND_CBF_COLOUR0...15decide on industry colour. See also the palettes. DARK_BLUE (#775) corresponds to the colour 0.
IND_CBF_CARGO_INPUTcargo labeldecide on accepted cargo types. extra_callback_info_1 gives the input cargo number. Return 0xFF for any other value than 0, 1 or 2 for extra_callback_info_1.
IND_CBF_CARGO_OUTPUTcargo labeldecide on output cargo types. extra_callback_info_1 gives the output cargo number. Return 0xFF for any other value than 0 or 1 for extra_callback_info_1.

Industry special flags

flagmeaning
IND_FLAG_PLANT_FIELDS_PERIODICALLYThe industry periodically plants fields around itself (temperate and arctic farms)
IND_FLAG_CUT_TREESThe industry cuts trees around itself and produces its first output cargo from them (lumber mill)
IND_FLAG_BUILT_ON_WATERThe industry is built on water (oil rig)
IND_FLAG_ONLY_IN_LARGE_TOWNSThe industry can only be built in towns (i.e. it has to replace houses) with population larger than 1200 (temperate bank)
IND_FLAG_ONLY_IN_TOWNSThe industry can only be built in towns (i.e. it has to replace houses) (arctic and tropic banks, water tower)
IND_FLAG_BUILT_NEAR_TOWNThe industry is always built near towns (i.e. near town sign; additionally the industry is allowed to replace houses) (toy shop)
IND_FLAG_PLANT_FIELDS_WHEN_BUILTFields are planted around the industry when it's built (all farms)
IND_FLAG_NO_PRODUCTION_INCREASEThe industry cannot increase its production on the temperate climate (oil wells)
IND_FLAG_BUILT_ONLY_BEFORE_1950The industry is built only before 1950 (oil wells)
IND_FLAG_BUILT_ONLY_AFTER_1960The industry is built only after 1960 (oil rig)
IND_FLAG_AI_CREATES_AIR_AND_SHIP_ROUTESAI players will attempt to establish air and ship routes going to this industry (oil rig)
IND_FLAG_MILITARY_AIRPLANE_CAN_EXPLODEThe industry can be exploded by a military airplane (oil refinery)
IND_FLAG_MILITARY_HELICOPTER_CAN_EXPLODEThe industry can be exploded by a military helicopter (factory)
IND_FLAG_CAN_CAUSE_SUBSIDENCEThe industry can cause a subsidence (coal mine)
IND_FLAG_AUTOMATIC_PRODUCTION_MULTIPLIERAutomatic production multiplier handing (No industry has this bit set by default.).
IND_FLAG_RANDOM_BITS_IN_PRODUCTION_CALLBACKThe production callback needs random bits in var. 10 (No industry has this bit set by default.)
IND_FLAG_DO_NOT_FORCE_INSTANCE_AT_MAP_GENERATIONDo not force one instance of this type to appear during initial map generation (No industry has this bit set by default.)
IND_FLAG_ALLOW_CLOSING_LAST_INSTANCEAllow closing down the last instance of this type (No industry has this bit set by default.)