# industry.h File Reference

Base of all industries. More...

`#include "oldpool.h"`
`#include "core/random_func.hpp"`
`#include "newgrf_storage.h"`
`#include "cargo_type.h"`
`#include "economy_type.h"`
`#include "map_type.h"`
`#include "slope_type.h"`
`#include "date_type.h"`
`#include "town_type.h"`
`#include "industry_type.h"`
`#include "landscape_type.h"`

Go to the source code of this file.

## Data Structures
struct | Industry
| Defines the internal data of a functionnal industry. More...
struct | IndustryTileTable
struct | GRFFileProps
| Data related to the handling of grf files. More...
struct | IndustrySpec
| Defines the data structure for constructing industry. More...
struct | IndustryTileSpec
| Defines the data structure of each indivudual tile of an industry. More...
## Defines
#define | FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (i->IsValid())
#define | FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
## Enumerations
enum | { INVALID_INDUSTRY = 0xFFFF, NEW_INDUSTRYOFFSET = 37, NUM_INDUSTRYTYPES = 64, INDUSTRYTILE_NOANIM = 0xFF, NEW_INDUSTRYTILEOFFSET = 175, INVALID_INDUSTRYTYPE = NUM_INDUSTRYTYPES, NUM_INDUSTRYTILES = 512, INVALID_INDUSTRYTILE = NUM_INDUSTRYTILES, INDUSTRY_COMPLETED = 3 }
enum | { CLEAN_RANDOMSOUNDS, CLEAN_TILELSAYOUT }
enum | IndustryLifeType { INDUSTRYLIFE_BLACK_HOLE = 0, INDUSTRYLIFE_EXTRACTIVE = 1 << 0, INDUSTRYLIFE_ORGANIC = 1 << 1, INDUSTRYLIFE_PROCESSING = 1 << 2 }
enum | CheckProc { CHECK_NOTHING, CHECK_FOREST, CHECK_REFINERY, CHECK_FARM, CHECK_PLANTATION, CHECK_WATER, CHECK_LUMBERMILL, CHECK_BUBBLEGEN, CHECK_OIL_RIG, CHECK_END }
enum | IndustryConstructionType { ICT_UNKNOWN, ICT_NORMAL_GAMEPLAY, ICT_MAP_GENERATION, ICT_SCENARIO_EDITOR }
| How was the industry created. More...
enum | IndustryBehaviour { INDUSTRYBEH_NONE = 0, INDUSTRYBEH_PLANT_FIELDS = 1 << 0, INDUSTRYBEH_CUT_TREES = 1 << 1, INDUSTRYBEH_BUILT_ONWATER = 1 << 2, INDUSTRYBEH_TOWN1200_MORE = 1 << 3, INDUSTRYBEH_ONLY_INTOWN = 1 << 4, INDUSTRYBEH_ONLY_NEARTOWN = 1 << 5, INDUSTRYBEH_PLANT_ON_BUILT = 1 << 6, INDUSTRYBEH_DONT_INCR_PROD = 1 << 7, INDUSTRYBEH_BEFORE_1950 = 1 << 8, INDUSTRYBEH_AFTER_1960 = 1 << 9, INDUSTRYBEH_AI_AIRSHIP_ROUTES = 1 << 10, INDUSTRYBEH_AIRPLANE_ATTACKS = 1 << 11, INDUSTRYBEH_CHOPPER_ATTACKS = 1 << 12, INDUSTRYBEH_CAN_SUBSIDENCE = 1 << 13, INDUSTRYBEH_PROD_MULTI_HNDLING = 1 << 14, INDUSTRYBEH_PRODCALLBACK_RANDOM = 1 << 15, INDUSTRYBEH_NOBUILT_MAPCREATION = 1 << 16, INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17 }
## Functions
| DECLARE_ENUM_AS_BIT_SET (IndustryBehaviour)
const IndustrySpec * | GetIndustrySpec (IndustryType thistype)
| Array of industries data.
const IndustryTileSpec * | GetIndustryTileSpec (IndustryGfx gfx)
| Array of industry tiles data.
void | ResetIndustries ()
| This function initialize the spec arrays of both industry and industry tiles.
void | PlantRandomFarmField (const Industry *i)
void | ReleaseDisastersTargetingIndustry (IndustryID)
| Marks all disasters targeting this industry in such a way they won't call GetIndustry(v->dest_tile) on invalid industry anymore.
static IndustryGfx | GetTranslatedIndustryTileID (IndustryGfx gfx)
void | BuildIndustriesLegend ()
| Fills an array for the industries legends.
void | SetIndustryDailyChanges ()
static bool | IsValidIndustryID (IndustryID index)
| Check if an Industry exists whithin the pool of industries.
static IndustryID | GetMaxIndustryIndex ()
static uint | GetNumIndustries ()
static void | IncIndustryTypeCount (IndustryType type)
| Increment the count of industries for this type.
static void | DecIndustryTypeCount (IndustryType type)
| Decrement the count of industries for this type.
static uint8 | GetIndustryTypeCount (IndustryType type)
| get the count of industries for this type
static void | ResetIndustryCounts ()
| Resets both the total_industries and the _industry_counts This way, we centralize all counts activities.
static Industry * | GetRandomIndustry ()
| Return a random valid industry.
## Variables
IndustrySpec | _industry_specs [NUM_INDUSTRYTYPES]
IndustryTileSpec | _industry_tile_specs [NUM_INDUSTRYTILES]
int | _total_industries
| General counter.
uint16 | _industry_counts [NUM_INDUSTRYTYPES]
| Number of industries per type ingame.
static const uint8 | IT_INVALID = 255

## Detailed Description

Base of all industries.

Definition in file industry.h.

## Enumeration Type Documentation

anonymous enum

Enumerator:

  NEW_INDUSTRYOFFSET | original number of industries
  NUM_INDUSTRYTYPES | total number of industries, new and old
  INDUSTRYTILE_NOANIM | flag to mark industry tiles as having no animation
  NEW_INDUSTRYTILEOFFSET | original number of tiles
  INVALID_INDUSTRYTYPE | one above amount is considered invalid
  NUM_INDUSTRYTILES | total number of industry tiles, new and old
  INVALID_INDUSTRYTILE | one above amount is considered invalid
  INDUSTRY_COMPLETED | final stage of industry construction.

Definition at line 20 of file industry.h.

anonymous enum

Enumerator:

  CLEAN_RANDOMSOUNDS | Free the dynamically allocated sounds table.
  CLEAN_TILELSAYOUT | Free the dynamically allocated tile layout structure.

Definition at line 32 of file industry.h.

enum IndustryBehaviour

Enumerator:

  INDUSTRYBEH_PLANT_FIELDS | periodically plants fileds around itself (temp and artic farms)
  INDUSTRYBEH_CUT_TREES | cuts trees and produce first output cargo from them (lumber mill)
  INDUSTRYBEH_BUILT_ONWATER | is built on water (oil rig)
  INDUSTRYBEH_TOWN1200_MORE | can only be built in towns larger than 1200 inhabitants (temperate bank)
  INDUSTRYBEH_ONLY_INTOWN | can only be built in towns (arctic/tropic banks, water tower)
  INDUSTRYBEH_ONLY_NEARTOWN | is always built near towns (toy shop)
  INDUSTRYBEH_PLANT_ON_BUILT | Fields are planted around when built (all farms).
  INDUSTRYBEH_DONT_INCR_PROD | do not increase production (oil wells) in the temperate climate
  INDUSTRYBEH_BEFORE_1950 | can only be built before 1950 (oil wells)
  INDUSTRYBEH_AFTER_1960 | can only be built after 1960 (oil rigs)
  INDUSTRYBEH_AI_AIRSHIP_ROUTES | ai will attempt to establish air/ship routes to this industry (oil rig)
  INDUSTRYBEH_AIRPLANE_ATTACKS | can be exploded by a military airplane (oil refinery)
  INDUSTRYBEH_CHOPPER_ATTACKS | can be exploded by a military helicopter (factory)
  INDUSTRYBEH_CAN_SUBSIDENCE | can cause a subsidence (coal mine, shaft that collapses)
  INDUSTRYBEH_PROD_MULTI_HNDLING | Automatic production multiplier handling.
  INDUSTRYBEH_PRODCALLBACK_RANDOM | Production callback needs random bits in var 10.
  INDUSTRYBEH_NOBUILT_MAPCREATION | Do not force one instance of this type to appear on map generation.
  INDUSTRYBEH_CANCLOSE_LASTINSTANCE | Allow closing down the last instance of this type.

Definition at line 67 of file industry.h.

enum IndustryConstructionType

How was the industry created.

Enumerator:

  ICT_UNKNOWN | in previous game version or without newindustries activated
  ICT_NORMAL_GAMEPLAY | either by user or random creation proccess
  ICT_MAP_GENERATION | during random map creation
  ICT_SCENARIO_EDITOR | while scenarion edition

Definition at line 60 of file industry.h.

enum IndustryLifeType

Enumerator:

  INDUSTRYLIFE_BLACK_HOLE | Like power plants and banks.
  INDUSTRYLIFE_EXTRACTIVE | Like mines.
  INDUSTRYLIFE_ORGANIC | Like forests.
  INDUSTRYLIFE_PROCESSING | Like factories.

Definition at line 37 of file industry.h.

## Function Documentation

static void DecIndustryTypeCount | ( | IndustryType | type | ) | `[inline, static]`

Decrement the count of industries for this type.

Parameters:

  | type | IndustryType to decrement

Precondition:
  type < INVALID_INDUSTRYTYPE

Definition at line 310 of file industry.h.

References INVALID_INDUSTRYTYPE.

const IndustrySpec* GetIndustrySpec | ( | IndustryType | thistype | ) |

Array of industries data.

Array of industries data.

This will ensure at once : proper access and not allowing modifications of it.

Parameters:

  | thistype | of industry (which is the index in _industry_specs)

Precondition:
  thistype < NUM_INDUSTRYTYPES

Returns:
  a pointer to the corresponding industry spec

Definition at line 109 of file industry_cmd.cpp.

References NUM_INDUSTRYTYPES.

Referenced by BuildIndustriesLegend(), AIIndustryType::BuildIndustry(), AIIndustryType::CanBuildIndustry(), CanCargoServiceIndustry(), AIIndustryType::CanProspectIndustry(), ChangeIndustryProduction(), CheckIndustryCloseDownProtection(), CmdBuildIndustry(), CMSAForest(), CMSAMine(), CreateNewIndustryHelper(), Disaster_CoalMine_Init(), Disaster_Helicopter_Init(), DisasterTick_Airplane(), DisasterTick_Helicopter(), FindNearIndustryName(), GenerateIndustries(), AIIndustryType::GetAcceptedCargo(), AIIndustryType::GetConstructionCost(), GetCountAndDistanceOfClosestInstance(), GetIndustryIDAtOffset(), AIIndustryType::GetName(), AIIndustryType::GetProducedCargo(), GetSmallMapIndustriesPixels(), AIIndustryType::HasDock(), AIIndustry::HasDock(), AIIndustryType::HasHeliport(), AIIndustry::HasHeliport(), IndustryGetVariable(), IndustryProductionCallback(), AIIndustryType::IsBuiltOnWater(), AIIndustry::IsBuiltOnWater(), AIIndustryType::IsRawIndustry(), AIIndustryType::IsValidIndustryType(), MaybeNewIndustry(), IndustryDirectoryWindow::OnPaint(), PlaceInitialIndustry(), AIIndustryType::ProductionCanIncrease(), and TriggerIndustryProduction().

const IndustryTileSpec* GetIndustryTileSpec | ( | IndustryGfx | gfx | ) |

Array of industry tiles data.

Array of industry tiles data.

This will ensure at once : proper access and not allowing modifications of it.

Parameters:

  | gfx | of industrytile (which is the index in _industry_tile_specs)

Precondition:
  gfx < INVALID_INDUSTRYTILE

Returns:
  a pointer to the corresponding industrytile spec

Definition at line 123 of file industry_cmd.cpp.

References INVALID_INDUSTRYTILE.

Referenced by GetIndustryIDAtOffset().

static uint8 GetIndustryTypeCount | ( | IndustryType | type | ) | `[inline, static]`

get the count of industries for this type

Parameters:

  | type | IndustryType to query

Precondition:
  type < INVALID_INDUSTRYTYPE

Definition at line 320 of file industry.h.

References INVALID_INDUSTRYTYPE, and min().

Referenced by CheckIndustryCloseDownProtection(), and GetCountAndDistanceOfClosestInstance().

static void IncIndustryTypeCount | ( | IndustryType | type | ) | `[inline, static]`

Increment the count of industries for this type.

Parameters:

  | type | IndustryType to increment

Precondition:
  type < INVALID_INDUSTRYTYPE

Definition at line 300 of file industry.h.

References INVALID_INDUSTRYTYPE.

static bool IsValidIndustryID | ( | IndustryID | index | ) | `[inline, static]`

Check if an Industry exists whithin the pool of industries.

Parameters:

  | index | of the desired industry

Returns:
  true if it is inside the pool

Definition at line 273 of file industry.h.

Referenced by GetRandomIndustry(), and AIIndustry::IsValidIndustry().

void ReleaseDisastersTargetingIndustry | ( | IndustryID | i | ) |

Marks all disasters targeting this industry in such a way they won't call GetIndustry(v->dest_tile) on invalid industry anymore.

Parameters:

  | i | deleted industry

Definition at line 1016 of file disaster_cmd.cpp.

void ResetIndustries | ( |  | ) |

This function initialize the spec arrays of both industry and industry tiles.

It adjusts the enabling of the industry too, based on climate availability. This will allow for clearer testings

Definition at line 58 of file industry_cmd.cpp.

References _settings_game, IndustrySpec::enabled, GameSettings::game_creation, HasBit(), GameCreationSettings::landscape, NEW_INDUSTRYOFFSET, and NUM_INDUSTRYTYPES.

Referenced by ResetNewGRFData().