# industry_cmd.cpp File Reference

Handling of industry tiles. More...

`#include "stdafx.h"`
`#include "clear_map.h"`
`#include "industry.h"`
`#include "station_base.h"`
`#include "train.h"`
`#include "landscape.h"`
`#include "viewport_func.h"`
`#include "command_func.h"`
`#include "town.h"`
`#include "news_func.h"`
`#include "variables.h"`
`#include "cheat_type.h"`
`#include "genworld.h"`
`#include "tree_map.h"`
`#include "newgrf.h"`
`#include "newgrf_cargo.h"`
`#include "newgrf_commons.h"`
`#include "newgrf_industries.h"`
`#include "newgrf_industrytiles.h"`
`#include "autoslope.h"`
`#include "water.h"`
`#include "strings_func.h"`
`#include "functions.h"`
`#include "window_func.h"`
`#include "date_func.h"`
`#include "vehicle_func.h"`
`#include "sound_func.h"`
`#include "animated_tile_func.h"`
`#include "effectvehicle_func.h"`
`#include "effectvehicle_base.h"`
`#include "ai/ai.hpp"`
`#include "core/pool_func.hpp"`
`#include "subsidy_func.h"`
`#include "table/strings.h"`
`#include "table/industry_land.h"`
`#include "table/build_industry.h"`

Go to the source code of this file.

## Data Structures
struct | ProbabilityHelper
| Simple helper that will collect data for the generation of industries. More...
## Typedefs
typedef void | IndustryDrawTileProc (const TileInfo *ti)
typedef bool | CheckNewIndustryProc (TileIndex tile)
| Industrytype check function signature.
## Enumerations
enum | ProductionLevels { PRODLEVEL_CLOSURE = 0x00, PRODLEVEL_MINIMUM = 0x04, PRODLEVEL_DEFAULT = 0x10, PRODLEVEL_MAXIMUM = 0x80 }
| Production level maximum, minimum and default values. More...
enum | { PERCENT_TRANSPORTED_60 = 153, PERCENT_TRANSPORTED_80 = 204 }
## Functions
void | ShowIndustryViewWindow (int industry)
void | BuildOilRig (TileIndex tile)
void | ResetIndustries ()
| This function initialize the spec arrays of both industry and industry tiles.
IndustryType | GetIndustryType (TileIndex tile)
| Retrieve the type for this industry.
const IndustrySpec * | GetIndustrySpec (IndustryType thistype)
| Accessor for array _industry_specs.
const IndustryTileSpec * | GetIndustryTileSpec (IndustryGfx gfx)
| Accessor for array _industry_tile_specs.
static void | IndustryDrawSugarMine (const TileInfo *ti)
static void | IndustryDrawToffeeQuarry (const TileInfo *ti)
static void | IndustryDrawBubbleGenerator (const TileInfo *ti)
static void | IndustryDrawToyFactory (const TileInfo *ti)
static void | IndustryDrawCoalPlantSparks (const TileInfo *ti)
static void | DrawTile_Industry (TileInfo *ti)
static uint | GetSlopeZ_Industry (TileIndex tile, uint x, uint y)
static Foundation | GetFoundation_Industry (TileIndex tile, Slope tileh)
static void | AddAcceptedCargo_Industry (TileIndex tile, CargoArray &acceptance, uint32 *always_accepted)
static void | GetTileDesc_Industry (TileIndex tile, TileDesc *td)
static CommandCost | ClearTile_Industry (TileIndex tile, DoCommandFlag flags)
static void | TransportIndustryGoods (TileIndex tile)
static void | AnimateTile_Industry (TileIndex tile)
static void | CreateChimneySmoke (TileIndex tile)
static void | MakeIndustryTileBigger (TileIndex tile)
static void | TileLoopIndustry_BubbleGenerator (TileIndex tile)
static void | TileLoop_Industry (TileIndex tile)
static bool | ClickTile_Industry (TileIndex tile)
static TrackStatus | GetTileTrackStatus_Industry (TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
static void | ChangeTileOwner_Industry (TileIndex tile, Owner old_owner, Owner new_owner)
static bool | IsBadFarmFieldTile (TileIndex tile)
static bool | IsBadFarmFieldTile2 (TileIndex tile)
static void | SetupFarmFieldFence (TileIndex tile, int size, byte type, Axis direction)
static void | PlantFarmField (TileIndex tile, IndustryID industry)
void | PlantRandomFarmField (const Industry *i)
static bool | SearchLumberMillTrees (TileIndex tile, void *user_data)
| Search callback function for ChopLumberMillTrees.
static void | ChopLumberMillTrees (Industry *i)
| Perform a circular search around the Lumber Mill in order to find trees to cut.
static void | ProduceIndustryGoods (Industry *i)
void | OnTick_Industry ()
static bool | CheckNewIndustry_NULL (TileIndex tile)
| Check the conditions of CHECK_NOTHING.
static bool | CheckNewIndustry_Forest (TileIndex tile)
| Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate).
static bool | CheckNewIndustry_OilRefinery (TileIndex tile)
| Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).
static bool | CheckNewIndustry_OilRig (TileIndex tile)
| Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
static bool | CheckNewIndustry_Farm (TileIndex tile)
| Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
static bool | CheckNewIndustry_Plantation (TileIndex tile)
| Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
static bool | CheckNewIndustry_Water (TileIndex tile)
| Check the conditions of CHECK_WATER (Industry should be in the desert).
static bool | CheckNewIndustry_Lumbermill (TileIndex tile)
| Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).
static bool | CheckNewIndustry_BubbleGen (TileIndex tile)
| Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
static const Town * | FindTownForIndustry (TileIndex tile, int type)
| Find a town for the industry, while checking for multiple industries in the same town.
bool | IsSlopeRefused (Slope current, Slope refused)
static bool | CheckIfIndustryTilesAreFree (TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, bool *custom_shape_check=NULL)
static bool | CheckIfIndustryIsAllowed (TileIndex tile, int type, const Town *t)
static bool | CheckCanTerraformSurroundingTiles (TileIndex tile, uint height, int internal)
static bool | CheckIfCanLevelIndustryPlatform (TileIndex tile, DoCommandFlag flags, const IndustryTileTable *it, int type)
| This function tries to flatten out the land below an industry, without damaging the surroundings too much.
static bool | CheckIfFarEnoughFromConflictingIndustry (TileIndex tile, int type)
static void | DoCreateNewIndustry (Industry *i, TileIndex tile, int type, const IndustryTileTable *it, byte layout, const Town *t, Owner owner, Owner founder)
static Industry * | CreateNewIndustryHelper (TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 seed, Owner founder)
| Helper function for Build/Fund an industry.
CommandCost | CmdBuildIndustry (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
| Build/Fund an industry.
static Industry * | CreateNewIndustry (TileIndex tile, IndustryType type)
static uint32 | GetScaledIndustryProbability (IndustryType it, bool *force_at_least_one)
| Compute the appearance probability for an industry during map creation.
static void | PlaceInitialIndustry (IndustryType type, bool try_hard)
| Try to build a industry on the map.
void | GenerateIndustries ()
| This function will create random industries during game creation.
static void | UpdateIndustryStatistics (Industry *i)
static void | MaybeNewIndustry ()
| Try to create a random industry, during gameplay.
static bool | CheckIndustryCloseDownProtection (IndustryType type)
| Protects an industry from closure if the appropriate flags and conditions are met INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the count of industries of this type must one (or lower) in order to be protected against closure.
static void | CanCargoServiceIndustry (CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
| Can given cargo type be accepted or produced by the industry?
static int | WhoCanServiceIndustry (Industry *ind)
| Compute who can service the industry.
static void | ReportNewsProductionChangeIndustry (Industry *ind, CargoID type, int percent)
| Report news that industry production has changed significantly.
static void | ChangeIndustryProduction (Industry *i, bool monthly)
| Change industry production or do closure.
void | IndustryDailyLoop ()
| Daily handler for the industry changes Taking the original map size of 256*256, the number of random changes was always of just one unit.
void | IndustryMonthlyLoop ()
void | InitializeIndustries ()
static CommandCost | TerraformTile_Industry (TileIndex tile, DoCommandFlag flags, uint z_new, Slope tileh_new)
## Variables
IndustryPool | _industry_pool ("Industry")
static byte | _industry_sound_ctr
static TileIndex | _industry_sound_tile
uint16 | _industry_counts [NUM_INDUSTRYTYPES]
| Number of industries per type ingame.
IndustrySpec | _industry_specs [NUM_INDUSTRYTYPES]
IndustryTileSpec | _industry_tile_specs [NUM_INDUSTRYTILES]
static IndustryDrawTileProc *const | _industry_draw_tile_procs [5]
static const byte | _plantfarmfield_type [] = {1, 1, 1, 1, 1, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6}
bool | _ignore_restrictions
static CheckNewIndustryProc *const | _check_new_industry_procs [CHECK_END]
| Check functions for different types of industry.
static const byte | _numof_industry_table []
| Number of industries on a 256x256 map.
const TileTypeProcs | _tile_type_industry_procs

## Detailed Description

Handling of industry tiles.

Definition in file industry_cmd.cpp.

## Typedef Documentation

typedef bool CheckNewIndustryProc(TileIndex tile)

Industrytype check function signature.

Parameters:

  | tile | Tile to check.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1265 of file industry_cmd.cpp.

## Enumeration Type Documentation

enum ProductionLevels

Production level maximum, minimum and default values.

It is not a value been really used in order to change, but rather an indicator of how the industry is behaving.

Enumerator:

  PRODLEVEL_CLOSURE | signal set to actually close the industry
  PRODLEVEL_MINIMUM | below this level, the industry is set to be closing
  PRODLEVEL_DEFAULT | default level set when the industry is created
  PRODLEVEL_MAXIMUM | the industry is running at full speed

Definition at line 1538 of file industry_cmd.cpp.

## Function Documentation

static void CanCargoServiceIndustry | ( | CargoID | cargo,
|  | Industry * | ind,
|  | bool * | c_accepts,
|  | bool * | c_produces |
| ) |  |  | `[static]`

Can given cargo type be accepted or produced by the industry?

Parameters:

  | cargo,: | Cargo type
  | ind,: | Industry
  | *c_accepts,: | Pointer to boolean for acceptance of cargo
  | *c_produces,: | Pointer to boolean for production of cargo

Returns:
  : `*c_accepts` is set when industry accepts the cargo type, `*c_produces` is set when the industry produces the cargo type

Definition at line 2025 of file industry_cmd.cpp.

References Industry::accepts_cargo, IndustrySpec::callback_mask, CBID_INDUSTRY_REFUSE_CARGO, CBM_IND_REFUSE_CARGO, CT_INVALID, GetIndustrySpec(), IndustrySpec::grf_prop, GRFFileProps::grffile, HasBit(), lengthof, Industry::location, Industry::produced_cargo, TileArea::tile, and Industry::type.

Referenced by WhoCanServiceIndustry().

static void ChangeIndustryProduction | ( | Industry * | i,
|  | bool | monthly |
| ) |  |  | `[static]`

Change industry production or do closure.

Parameters:

  | i | Industry for which changes are performed
  | monthly | true if it's the monthly call, false if it's the random call

< reinitialize production_rate to match prod_level

Definition at line 2155 of file industry_cmd.cpp.

References _cur_year, _settings_game, abs(), AddNewsItem(), IndustrySpec::behaviour, AI::BroadcastNewEvent(), CALLBACK_FAILED, IndustrySpec::callback_mask, CBID_INDUSTRY_MONTHLYPROD_CHANGE, CBID_INDUSTRY_PRODUCTION_CHANGE, CBM_IND_MONTHLYPROD_CHANGE, CBM_IND_PRODUCTION_256_TICKS, CBM_IND_PRODUCTION_CARGO_ARRIVAL, CBM_IND_PRODUCTION_CHANGE, Chance16(), Chance16I(), CheckIndustryCloseDownProtection(), Clamp(), ClampU(), IndustrySpec::closure_text, CT_INVALID, GameSettings::economy, GameSettings::game_creation, GB(), GetIndustrySpec(), GetRegister(), IndustrySpec::grf_prop, GRFFileProps::grffile, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, INDUSTRYBEH_DONT_INCR_PROD, INDUSTRYLIFE_BLACK_HOLE, INDUSTRYLIFE_EXTRACTIVE, INDUSTRYLIFE_ORGANIC, INDUSTRYLIFE_PROCESSING, GameCreationSettings::landscape, Industry::last_month_pct_transported, Industry::last_prod_year, lengthof, IndustrySpec::life_type, Industry::location, MapGRFStringID(), max(), min(), IndustrySpec::name, NR_INDUSTRY, NR_TILE, NS_INDUSTRY_CLOSE, NS_INDUSTRY_COMPANY, NS_INDUSTRY_NOBODY, NS_INDUSTRY_OTHER, Industry::prod_level, PRODLEVEL_CLOSURE, PRODLEVEL_DEFAULT, PRODLEVEL_MAXIMUM, PRODLEVEL_MINIMUM, Industry::produced_cargo, IndustrySpec::production_down_text, Industry::production_rate, IndustrySpec::production_up_text, ReportNewsProductionChangeIndustry(), SetDParam(), EconomySettings::smooth_economy, TileArea::tile, TileDiffXY(), Industry::town, Industry::type, and WhoCanServiceIndustry().

Referenced by IndustryDailyLoop().

static bool CheckIndustryCloseDownProtection | ( | IndustryType | type | ) | `[static]`

Protects an industry from closure if the appropriate flags and conditions are met INDUSTRYBEH_CANCLOSE_LASTINSTANCE must be set (which, by default, it is not) and the count of industries of this type must one (or lower) in order to be protected against closure.

Parameters:

  | type | IndustryType been queried

Returns:
  true if protection is on, false otherwise (except for oil wells)

Definition at line 2007 of file industry_cmd.cpp.

References _settings_game, IndustrySpec::behaviour, GameSettings::game_creation, GetIndustrySpec(), GetIndustryTypeCount(), INDUSTRYBEH_CANCLOSE_LASTINSTANCE, INDUSTRYBEH_DONT_INCR_PROD, and GameCreationSettings::landscape.

Referenced by ChangeIndustryProduction().

static bool CheckNewIndustry_BubbleGen | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1252 of file industry_cmd.cpp.

References GetTileZ(), and TILE_HEIGHT.

static bool CheckNewIndustry_Farm | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1196 of file industry_cmd.cpp.

References _settings_game, GameSettings::game_creation, GetTileZ(), HighestSnowLine(), GameCreationSettings::landscape, and TILE_HEIGHT.

static bool CheckNewIndustry_Forest | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1152 of file industry_cmd.cpp.

References _settings_game, GameSettings::game_creation, GetTileZ(), HighestSnowLine(), GameCreationSettings::landscape, and TILE_HEIGHT.

static bool CheckNewIndustry_Lumbermill | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1239 of file industry_cmd.cpp.

References GetTropicZone(), and TROPICZONE_RAINFOREST.

static bool CheckNewIndustry_NULL | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_NOTHING.

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1143 of file industry_cmd.cpp.

static bool CheckNewIndustry_OilRefinery | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1167 of file industry_cmd.cpp.

References _settings_game, DistanceFromEdge(), GameSettings::game_creation, GameCreationSettings::oil_refinery_limit, and TILE_ADDXY.

static bool CheckNewIndustry_OilRig | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1182 of file industry_cmd.cpp.

References _settings_game, DistanceFromEdge(), GameSettings::game_creation, GameCreationSettings::oil_refinery_limit, TILE_ADDXY, and TileHeight().

static bool CheckNewIndustry_Plantation | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1211 of file industry_cmd.cpp.

References GetTropicZone(), and TROPICZONE_DESERT.

static bool CheckNewIndustry_Water | ( | TileIndex | tile | ) | `[static]`

Check the conditions of CHECK_WATER (Industry should be in the desert).

Parameters:

  | tile | Tile to perform the checking.

Returns:
  `true` if industry may be build, `false` otherwise.

Definition at line 1225 of file industry_cmd.cpp.

References GetTropicZone(), and TROPICZONE_DESERT.

static void ChopLumberMillTrees | ( | Industry * | i | ) | `[static]`

Perform a circular search around the Lumber Mill in order to find trees to cut.

Parameters:

  | i | industry

< Can't proceed if not completed

< 40x40 tiles to search

< Found a tree, add according value to waiting cargo

Definition at line 1058 of file industry_cmd.cpp.

References CircularTileSearch(), IsIndustryCompleted(), Industry::location, min(), Industry::produced_cargo_waiting, SearchLumberMillTrees(), and TileArea::tile.

CommandCost CmdBuildIndustry | ( | TileIndex | tile,
|  | DoCommandFlag | flags,
|  | uint32 | p1,
|  | uint32 | p2,
|  | const char * | text |
| ) |  |  |

Build/Fund an industry.

Parameters:

  | tile | tile where industry is built
  | flags | of operations to conduct
  | p1 | various bitstuffed elements p1 = (bit 0 - 7) - industry type see build_industry.h and see industry.h p1 = (bit 8 - 15) - first layout to try
  | p2 | seed to use for variable 8F
  | text | unused

Returns:
  the cost of this operation or an error

Definition at line 1723 of file industry_cmd.cpp.

References _settings_game, AI::BroadcastNewEvent(), CMD_ERROR, GameSettings::construction, CreateNewIndustryHelper(), IndustrySpec::enabled, EXPENSES_OTHER, GB(), IndustrySpec::GetConstructionCost(), GetIndustrySpec(), IACT_USERCREATION, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, IndustrySpec::IsRawIndustry(), IndustrySpec::name, IndustrySpec::new_industry_text, NS_INDUSTRY_OPEN, NUM_INDUSTRYTYPES, IndustrySpec::num_table, OWNER_TOWN, IndustrySpec::prospecting_chance, RandomTile, ConstructionSettings::raw_industry_construction, SetDParam(), IndustrySpec::table, and Industry::town.

static Industry* CreateNewIndustryHelper | ( | TileIndex | tile,
|  | IndustryType | type,
|  | DoCommandFlag | flags,
|  | const IndustrySpec * | indspec,
|  | uint | itspec_index,
|  | uint32 | seed,
|  | Owner | founder |
| ) |  |  | `[static]`

Helper function for Build/Fund an industry.

Parameters:

  | tile | tile where industry is built
  | type | of industry to build
  | flags | of operations to conduct
  | indspec | pointer to industry specifications
  | itspec_index | the index of the itsepc to build/fund
  | seed | random seed (possibly) used by industries
  | founder | Founder of the industry

Returns:
  the pointer of the newly created industry, or NULL if it failed

Definition at line 1676 of file industry_cmd.cpp.

References _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::CanAllocateItem(), CBM_IND_LOCATION, IndustrySpec::check_proc, CheckIfCanLevelIndustryPlatform(), DC_NO_WATER, FindTownForIndustry(), GameSettings::game_creation, GetIndustrySpec(), HasBit(), GameCreationSettings::land_generator, LG_TERRAGENESIS, OWNER_NONE, and IndustrySpec::table.

Referenced by CmdBuildIndustry().

static const Town* FindTownForIndustry | ( | TileIndex | tile,
|  | int | type |
| ) |  |  | `[static]`

Find a town for the industry, while checking for multiple industries in the same town.

Parameters:

  | tile | Position of the industry to build.
  | type | Industry type.
  `[out]` | err_mesg | Error message, if any.

Returns:
  Town for the new industry, `NULL` if no good town can be found.

Definition at line 1286 of file industry_cmd.cpp.

References _settings_game, GameSettings::economy, EconomySettings::multiple_industry_per_town, Industry::town, and Industry::type.

Referenced by CreateNewIndustryHelper().

void GenerateIndustries | ( |  | ) |

This function will create random industries during game creation.

It will scale the amount of industries by mapsize and difficulty level.

Definition at line 1862 of file industry_cmd.cpp.

References _settings_game, GameSettings::difficulty, GetScaledIndustryProbability(), GWP_INDUSTRY, lengthof, NUM_INDUSTRYTYPES, DifficultySettings::number_industries, PlaceInitialIndustry(), ScaleByMapSize(), and SetGeneratingWorldProgress().

Referenced by _GenerateWorld(), and BuildIndustryWindow::OnClick().

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

Accessor for array _industry_specs.

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 112 of file industry_cmd.cpp.

References NUM_INDUSTRYTYPES.

Referenced by IndustryOverrideManager::AddEntityID(), BuildIndustriesLegend(), AIIndustryType::BuildIndustry(), AIIndustryType::CanBuildIndustry(), CanCargoServiceIndustry(), AIIndustryType::CanProspectIndustry(), ChangeIndustryProduction(), CheckIndustryCloseDownProtection(), CmdBuildIndustry(), CMSAForest(), CMSAMine(), CreateNewIndustryHelper(), DeliverGoodsToIndustry(), Disaster_CoalMine_Init(), Disaster_Helicopter_Init(), DisasterTick_Aircraft(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), FindNearIndustryName(), AIIndustryType::GetAcceptedCargo(), AIIndustryType::GetConstructionCost(), GetCountAndDistanceOfClosestInstance(), IndustryDirectoryWindow::GetIndustryString(), AIIndustryType::GetName(), AIIndustryType::GetProducedCargo(), GetScaledIndustryProbability(), GetSmallMapIndustriesPixels(), GetSmallMapVegetationPixels(), AIIndustryType::HasDock(), AIIndustry::HasDock(), AIIndustryType::HasHeliport(), AIIndustry::HasHeliport(), IndustryGetVariable(), IndustryProductionCallback(), AIIndustryType::IsBuiltOnWater(), AIIndustry::IsBuiltOnWater(), AIIndustryType::IsRawIndustry(), AIIndustryType::IsValidIndustryType(), MaybeNewIndustry(), BuildIndustryWindow::OnClick(), BuildIndustryWindow::OnInvalidateData(), BuildIndustryWindow::OnPlaceObject(), BuildIndustryWindow::OnTick(), AIIndustryType::ProductionCanIncrease(), BuildIndustryWindow::SetStringParameters(), TriggerIndustryProduction(), and BuildIndustryWindow::UpdateWidgetSize().

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

Accessor for array _industry_tile_specs.

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 126 of file industry_cmd.cpp.

References INVALID_INDUSTRYTILE.

Referenced by GetIndustryIDAtOffset().

IndustryType GetIndustryType | ( | TileIndex | tile | ) |

Retrieve the type for this industry.

Although it is accessed by a tile, it will return the general type of industry, and not the sprite index as would do GetIndustryGfx.

Parameters:

  | tile | that is queried

Precondition:
  IsTileType(tile, MP_INDUSTRY)

Returns:
  general type for this industry, as defined in industry.h

Definition at line 95 of file industry_cmd.cpp.

References Industry::GetByTile(), IsTileType(), MP_INDUSTRY, and Industry::type.

Referenced by FindNearIndustryName().

static uint32 GetScaledIndustryProbability | ( | IndustryType | it,
|  | bool * | force_at_least_one |
| ) |  |  | `[static]`

Compute the appearance probability for an industry during map creation.

Parameters:

  | it | Industrytype to compute for
  | force_at_least_one | Returns whether at least one instance should be forced on map creation

Returns:
  relative probability for the industry to appear

Definition at line 1812 of file industry_cmd.cpp.

References _settings_game, IndustrySpec::appear_creation, IndustrySpec::behaviour, CHECK_OIL_RIG, IndustrySpec::check_proc, CHECK_REFINERY, GameSettings::difficulty, IndustrySpec::enabled, GameSettings::game_creation, GetIndustrySpec(), IACT_MAPGENERATION, INDUSTRYBEH_NOBUILT_MAPCREATION, GameCreationSettings::landscape, IndustrySpec::num_table, DifficultySettings::number_industries, ScaleByMapSize(), and ScaleByMapSize1D().

Referenced by GenerateIndustries().

void IndustryDailyLoop | ( |  | ) |

Daily handler for the industry changes Taking the original map size of 256*256, the number of random changes was always of just one unit.

But it cannot be the same on smaller or bigger maps. That number has to be scaled up or down. For small maps, it implies that less than one change per month is required, while on bigger maps, it would be way more. The daily loop handles those changes.

Definition at line 2357 of file industry_cmd.cpp.

References Chance16(), ChangeIndustryProduction(), Industry::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, Economy::industry_daily_change_counter, Economy::industry_daily_increment, InvalidateWindowData(), MaybeNewIndustry(), OWNER_NONE, and SetWindowDirty().

Referenced by OnNewDay().

static void PlaceInitialIndustry | ( | IndustryType | type,
|  | bool | try_hard |
| ) |  |  | `[static]`

Try to build a industry on the map.

Parameters:

  | type | IndustryType of the desired industry
  | try_hard | Try very hard to find a place. (Used to place at least one industry per type)

Definition at line 1844 of file industry_cmd.cpp.

References GWP_INDUSTRY, IncreaseGeneratingWorldProgress(), OWNER_NONE, and RandomTile.

Referenced by GenerateIndustries().

static void ReportNewsProductionChangeIndustry | ( | Industry * | ind,
|  | CargoID | type,
|  | int | percent |
| ) |  |  | `[static]`

Report news that industry production has changed significantly.

Parameters:

  | ind,: | Industry with changed production
  | type,: | Cargo type that has changed
  | percent,: | Percentage of change (>0 means increase, <0 means decrease)

Definition at line 2126 of file industry_cmd.cpp.

References abs(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem< Tpool >::index, NS_INDUSTRY_COMPANY, NS_INDUSTRY_NOBODY, NS_INDUSTRY_OTHER, SetDParam(), and WhoCanServiceIndustry().

Referenced by ChangeIndustryProduction().

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 68 of file industry_cmd.cpp.

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

Referenced by ResetNewGRFData().

static bool SearchLumberMillTrees | ( | TileIndex | tile,
|  | void * | user_data |
| ) |  |  | `[static]`

Search callback function for ChopLumberMillTrees.

Parameters:

  | tile | to test
  | user_data | that is passed by the caller. In this case, nothing

Returns:
  the result of the test

< 3 and up means all fully grown trees

Definition at line 1035 of file industry_cmd.cpp.

References CMD_LANDSCAPE_CLEAR, DoCommand(), GetTreeGrowth(), IsTileType(), MP_TREES, and OWNER_NONE.

Referenced by ChopLumberMillTrees().

static int WhoCanServiceIndustry | ( | Industry * | ind | ) | `[static]`

Compute who can service the industry.

Here, 'can service' means that he/she has trains and stations close enough to the industry with the right cargo type and the right orders (ie has the technical means).

Parameters:

  | ind,: | Industry being investigated.

Returns:
  : 0 if nobody can service the industry, 2 if the local company can service the industry, and 1 otherwise (only competitors can service the industry)

Definition at line 2067 of file industry_cmd.cpp.

References CanCargoServiceIndustry(), Vehicle::cargo_type, SmallVector< T, S >::Contains(), FindStationsAroundTiles(), SpecializedVehicle< Train, VEH_TRAIN >::From(), SpecializedStation< Station, false >::Get(), Order::GetDestination(), Order::GetUnloadType(), Train::IsFrontEngine(), Order::IsType(), SmallVector< T, S >::Length(), Industry::location, Vehicle::Next(), OUFB_TRANSFER, OUFB_UNLOAD, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by ChangeIndustryProduction(), and ReportNewsProductionChangeIndustry().

## Variable Documentation

CheckNewIndustryProc* const _check_new_industry_procs[CHECK_END]`[static]`

Initial value:

     {
      CheckNewIndustry_NULL,
      CheckNewIndustry_Forest,
      CheckNewIndustry_OilRefinery,
      CheckNewIndustry_Farm,
      CheckNewIndustry_Plantation,
      CheckNewIndustry_Water,
      CheckNewIndustry_Lumbermill,
      CheckNewIndustry_BubbleGen,
      CheckNewIndustry_OilRig,
    }

Check functions for different types of industry.

Definition at line 1268 of file industry_cmd.cpp.

IndustryDrawTileProc* const _industry_draw_tile_procs[5]`[static]`

Initial value:

     {
      IndustryDrawSugarMine,
      IndustryDrawToffeeQuarry,
      IndustryDrawBubbleGenerator,
      IndustryDrawToyFactory,
      IndustryDrawCoalPlantSparks,
    }

Definition at line 293 of file industry_cmd.cpp.

const byte _numof_industry_table[]`[static]`

Initial value:

     {
      0,
      10,
      25,
      55,
      80,
    }

Number of industries on a 256x256 map.

Definition at line 1831 of file industry_cmd.cpp.

const TileTypeProcs _tile_type_industry_procs

Initial value:

     {
      DrawTile_Industry,
      GetSlopeZ_Industry,
      ClearTile_Industry,
      AddAcceptedCargo_Industry,
      GetTileDesc_Industry,
      GetTileTrackStatus_Industry,
      ClickTile_Industry,
      AnimateTile_Industry,
      TileLoop_Industry,
      ChangeTileOwner_Industry,
      NULL,
      NULL,
      GetFoundation_Industry,
      TerraformTile_Industry,
    }