OpenTTD
Typedefs | Functions | Variables
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 "landscape.h"
#include "viewport_func.h"
#include "command_func.h"
#include "town.h"
#include "news_func.h"
#include "cheat_type.h"
#include "genworld.h"
#include "tree_map.h"
#include "newgrf_cargo.h"
#include "newgrf_debug.h"
#include "newgrf_industrytiles.h"
#include "autoslope.h"
#include "water.h"
#include "strings_func.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 "core/backup_type.hpp"
#include "object_base.h"
#include "game/game.hpp"
#include "error.h"
#include "table/strings.h"
#include "table/industry_land.h"
#include "table/build_industry.h"
#include "safeguards.h"

Go to the source code of this file.

Typedefs

typedef void IndustryDrawTileProc(const TileInfo *ti)
 
typedef CommandCost CheckNewIndustryProc(TileIndex tile)
 Industrytype check function signature. More...
 

Functions

void ShowIndustryViewWindow (int industry)
 
void BuildOilRig (TileIndex tile)
 
void ResetIndustries ()
 This function initialize the spec arrays of both industry and industry tiles. More...
 
IndustryType GetIndustryType (TileIndex tile)
 Retrieve the type for this industry. More...
 
const IndustrySpecGetIndustrySpec (IndustryType thistype)
 Accessor for array _industry_specs. More...
 
const IndustryTileSpecGetIndustryTileSpec (IndustryGfx gfx)
 Accessor for array _industry_tile_specs. More...
 
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 int GetSlopePixelZ_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 bool TransportIndustryGoods (TileIndex tile)
 Move produced cargo from industry to nearby stations. More...
 
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)
 
bool IsTileForestIndustry (TileIndex tile)
 Check whether the tile is a forest. More...
 
static bool IsSuitableForFarmField (TileIndex tile, bool allow_fields)
 Check whether the tile can be replaced by a farm field. More...
 
static void SetupFarmFieldFence (TileIndex tile, int size, byte type, DiagDirection side)
 Build farm field fence. More...
 
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. More...
 
static void ChopLumberMillTrees (Industry *i)
 Perform a circular search around the Lumber Mill in order to find trees to cut. More...
 
static void ProduceIndustryGoods (Industry *i)
 
void OnTick_Industry ()
 
static CommandCost CheckNewIndustry_NULL (TileIndex tile)
 Check the conditions of CHECK_NOTHING (Always succeeds). More...
 
static CommandCost CheckNewIndustry_Forest (TileIndex tile)
 Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate). More...
 
static CommandCost CheckNewIndustry_OilRefinery (TileIndex tile)
 Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map). More...
 
static CommandCost CheckNewIndustry_OilRig (TileIndex tile)
 Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map). More...
 
static CommandCost CheckNewIndustry_Farm (TileIndex tile)
 Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic). More...
 
static CommandCost CheckNewIndustry_Plantation (TileIndex tile)
 Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert). More...
 
static CommandCost CheckNewIndustry_Water (TileIndex tile)
 Check the conditions of CHECK_WATER (Industry should be in the desert). More...
 
static CommandCost CheckNewIndustry_Lumbermill (TileIndex tile)
 Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest). More...
 
static CommandCost CheckNewIndustry_BubbleGen (TileIndex tile)
 Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land). More...
 
static CommandCost FindTownForIndustry (TileIndex tile, int type, Town **t)
 Find a town for the industry, while checking for multiple industries in the same town. More...
 
bool IsSlopeRefused (Slope current, Slope refused)
 
static CommandCost CheckIfIndustryTilesAreFree (TileIndex tile, const IndustryTileTable *it, uint itspec_index, int type, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=NULL)
 Are the tiles of the industry free? More...
 
static CommandCost CheckIfIndustryIsAllowed (TileIndex tile, int type, const Town *t)
 Is the industry allowed to be built at this place for the town? More...
 
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 CommandCost CheckIfFarEnoughFromConflictingIndustry (TileIndex tile, int type)
 Check that the new industry is far enough from conflicting industries. More...
 
static void AdvertiseIndustryOpening (const Industry *ind)
 Advertise about a new industry opening. More...
 
static void DoCreateNewIndustry (Industry *i, TileIndex tile, IndustryType type, const IndustryTileTable *it, byte layout, Town *t, Owner founder, uint16 initial_random_bits)
 Put an industry on the map. More...
 
static CommandCost CreateNewIndustryHelper (TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, uint itspec_index, uint32 random_var8f, uint16 random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip)
 Helper function for Build/Fund an industry. More...
 
CommandCost CmdBuildIndustry (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build/Fund an industry. More...
 
static IndustryCreateNewIndustry (TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
 Create a new industry of random layout. More...
 
static uint32 GetScaledIndustryGenerationProbability (IndustryType it, bool *force_at_least_one)
 Compute the appearance probability for an industry during map creation. More...
 
static uint16 GetIndustryGamePlayProbability (IndustryType it, byte *min_number)
 Compute the probability for constructing a new industry during game play. More...
 
static uint GetNumberOfIndustries ()
 Get wanted number of industries on the map. More...
 
static IndustryPlaceIndustry (IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
 Try to place the industry in the game. More...
 
static void PlaceInitialIndustry (IndustryType type, bool try_hard)
 Try to build a industry on the map. More...
 
static uint GetCurrentTotalNumberOfIndustries ()
 Get total number of industries existing in the game. More...
 
void GenerateIndustries ()
 This function will create random industries during game creation. More...
 
static void UpdateIndustryStatistics (Industry *i)
 Monthly update of industry statistics. More...
 
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. More...
 
static void CanCargoServiceIndustry (CargoID cargo, Industry *ind, bool *c_accepts, bool *c_produces)
 Can given cargo type be accepted or produced by the industry? More...
 
static int WhoCanServiceIndustry (Industry *ind)
 Compute who can service the industry. More...
 
static void ReportNewsProductionChangeIndustry (Industry *ind, CargoID type, int percent)
 Report news that industry production has changed significantly. More...
 
static void ChangeIndustryProduction (Industry *i, bool monthly)
 Change industry production or do closure. More...
 
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. More...
 
void IndustryMonthlyLoop ()
 
void InitializeIndustries ()
 
void CheckIndustries ()
 Verify whether the generated industries are complete, and warn the user if not. More...
 
static CommandCost TerraformTile_Industry (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
 

Variables

IndustryPool _industry_pool ("Industry")
 
static byte _industry_sound_ctr
 
static TileIndex _industry_sound_tile
 
IndustrySpec _industry_specs [NUM_INDUSTRYTYPES]
 
IndustryTileSpec _industry_tile_specs [NUM_INDUSTRYTILES]
 
IndustryBuildData _industry_builder
 In-game manager of industries.
 
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. More...
 
static const uint PERCENT_TRANSPORTED_60 = 153
 
static const uint PERCENT_TRANSPORTED_80 = 204
 
const TileTypeProcs _tile_type_industry_procs
 

Detailed Description

Handling of industry tiles.

Definition in file industry_cmd.cpp.

Typedef Documentation

◆ CheckNewIndustryProc

typedef CommandCost CheckNewIndustryProc(TileIndex tile)

Industrytype check function signature.

Parameters
tileTile to check.
Returns
Succeeded or failed command.

Definition at line 1307 of file industry_cmd.cpp.

Function Documentation

◆ AdvertiseIndustryOpening()

static void AdvertiseIndustryOpening ( const Industry ind)
static

◆ CanCargoServiceIndustry()

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
cargoCargo type
indIndustry
*c_acceptsPointer to boolean for acceptance of cargo
*c_producesPointer 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 2354 of file industry_cmd.cpp.

References Industry::accepts_cargo, CT_INVALID, IndustryTemporarilyRefusesCargo(), lengthof, and Industry::produced_cargo.

Referenced by WhoCanServiceIndustry().

◆ ChangeIndustryProduction()

static void ChangeIndustryProduction ( Industry i,
bool  monthly 
)
static

Change industry production or do closure.

Parameters
iIndustry for which changes are performed
monthlytrue if it's the monthly call, false if it's the random call

< reinitialize production_rate to match prod_level

Definition at line 2475 of file industry_cmd.cpp.

References IndustrySpec::callback_mask, CBID_INDUSTRY_MONTHLYPROD_CHANGE, CBID_INDUSTRY_PRODUCTION_CHANGE, CBM_IND_MONTHLYPROD_CHANGE, CBM_IND_PRODUCTION_CHANGE, GetIndustryCallback(), GetIndustrySpec(), HasBit(), Industry::type, and IndustrySpec::UsesSmoothEconomy().

◆ CheckIfFarEnoughFromConflictingIndustry()

static CommandCost CheckIfFarEnoughFromConflictingIndustry ( TileIndex  tile,
int  type 
)
static

Check that the new industry is far enough from conflicting industries.

Parameters
tileTile to construct the industry.
typeType of the new industry.
Returns
Succeeded or failed command.

Definition at line 1572 of file industry_cmd.cpp.

References IndustrySpec::conflicting, DistanceMax(), Industry::GetByTile(), GetIndustrySpec(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetNumItems(), GetTileType(), Industry::location, MapMaxX(), MapMaxY(), max(), min(), MP_INDUSTRY, return_cmd_error, OrthogonalTileArea::tile, TILE_AREA_LOOP, TileX(), TileXY(), TileY(), and Industry::type.

◆ CheckIfIndustryIsAllowed()

static CommandCost CheckIfIndustryIsAllowed ( TileIndex  tile,
int  type,
const Town t 
)
static

Is the industry allowed to be built at this place for the town?

Parameters
tileTile to construct the industry.
typeType of the industry.
tTown authority that the industry belongs to.
Returns
Succeeded or failed command.

Definition at line 1456 of file industry_cmd.cpp.

References Town::cache, DistanceMax(), GetIndustrySpec(), INDUSTRYBEH_ONLY_NEARTOWN, INDUSTRYBEH_TOWN1200_MORE, TownCache::population, return_cmd_error, and Town::xy.

◆ CheckIfIndustryTilesAreFree()

static CommandCost CheckIfIndustryTilesAreFree ( TileIndex  tile,
const IndustryTileTable it,
uint  itspec_index,
int  type,
uint16  initial_random_bits,
Owner  founder,
IndustryAvailabilityCallType  creation_type,
bool *  custom_shape_check = NULL 
)
static

Are the tiles of the industry free?

Parameters
tilePosition to check.
itIndustry tiles table.
itspec_indexThe index of the itsepc to build/fund
typeType of the industry.
initial_random_bitsThe random bits the industry is going to have after construction.
founderIndustry founder
creation_typeThe circumstances the industry is created under.
[out]custom_shape_checkPerform custom check for the site.
Returns
Failed or succeeded command.

Definition at line 1378 of file industry_cmd.cpp.

References IndustrySpec::behaviour, IndustryTileSpec::callback_mask, CBM_INDT_SHAPE_CHECK, EnsureNoVehicleOnGround(), CommandCost::Failed(), GetIndustrySpec(), GetIndustryTileSpec(), GetTileSlope(), GetTranslatedIndustryTileID(), GFX_WATERTILE_SPECIALCHECK, HasBit(), HasTileWaterClass(), INDUSTRYBEH_BUILT_ONWATER, IsBridgeAbove(), IsTileFlat(), IsTileOnWater(), IsValidTile(), IsWaterTile(), PerformIndustryTileSlopeCheck(), return_cmd_error, IndustryTileSpec::slopes_refused, TileAddWrap(), TileIndexDiffC::x, and TileIndexDiffC::y.

◆ CheckIndustries()

void CheckIndustries ( )

Verify whether the generated industries are complete, and warn the user if not.

Definition at line 2752 of file industry_cmd.cpp.

References GetIndustrySpec(), Industry::GetIndustryTypeCount(), GetScaledIndustryGenerationProbability(), IndustrySpec::name, NUM_INDUSTRYTYPES, SetDParam(), ShowErrorMessage(), and WL_WARNING.

◆ CheckIndustryCloseDownProtection()

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
typeIndustryType been queried
Returns
true if protection is on, false otherwise (except for oil wells)

Definition at line 2336 of file industry_cmd.cpp.

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

◆ CheckNewIndustry_BubbleGen()

static CommandCost CheckNewIndustry_BubbleGen ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1294 of file industry_cmd.cpp.

References GetTileZ(), and return_cmd_error.

◆ CheckNewIndustry_Farm()

static CommandCost CheckNewIndustry_Farm ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1240 of file industry_cmd.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.

◆ CheckNewIndustry_Forest()

static CommandCost CheckNewIndustry_Forest ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1196 of file industry_cmd.cpp.

References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.

◆ CheckNewIndustry_Lumbermill()

static CommandCost CheckNewIndustry_Lumbermill ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1281 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, and TROPICZONE_RAINFOREST.

◆ CheckNewIndustry_NULL()

static CommandCost CheckNewIndustry_NULL ( TileIndex  tile)
static

Check the conditions of CHECK_NOTHING (Always succeeds).

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1186 of file industry_cmd.cpp.

◆ CheckNewIndustry_OilRefinery()

static CommandCost CheckNewIndustry_OilRefinery ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1211 of file industry_cmd.cpp.

◆ CheckNewIndustry_OilRig()

static CommandCost CheckNewIndustry_OilRig ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1226 of file industry_cmd.cpp.

◆ CheckNewIndustry_Plantation()

static CommandCost CheckNewIndustry_Plantation ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1255 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, and TROPICZONE_DESERT.

◆ CheckNewIndustry_Water()

static CommandCost CheckNewIndustry_Water ( TileIndex  tile)
static

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

Parameters
tileTile to perform the checking.
Returns
Succeeded or failed command.

Definition at line 1268 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, and TROPICZONE_DESERT.

◆ ChopLumberMillTrees()

static void ChopLumberMillTrees ( Industry i)
static

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

Parameters
iindustry

Definition at line 1084 of file industry_cmd.cpp.

References CircularTileSearch(), IsIndustryCompleted(), Industry::location, min(), Industry::produced_cargo_waiting, SearchLumberMillTrees(), OrthogonalTileArea::tile, TILE_AREA_LOOP, and Industry::TileBelongsToIndustry().

◆ CmdBuildIndustry()

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

Build/Fund an industry.

Parameters
tiletile where industry is built
flagsof operations to conduct
p1various bitstuffed elements
  • p1 = (bit 0 - 7) - industry type see build_industry.h and see industry.h
  • p1 = (bit 8 - 15) - first layout to try
  • p1 = (bit 16 ) - 0 = prospect, 1 = fund (only valid if current company is DEITY)
p2seed to use for desyncfree randomisations
textunused
Returns
the cost of this operation or an error

Definition at line 1864 of file industry_cmd.cpp.

References CMD_ERROR, IndustrySpec::enabled, GB(), GetIndustrySpec(), NUM_INDUSTRYTYPES, and IndustrySpec::num_table.

◆ CreateNewIndustry()

static Industry* CreateNewIndustry ( TileIndex  tile,
IndustryType  type,
IndustryAvailabilityCallType  creation_type 
)
static

Create a new industry of random layout.

Parameters
tileThe location to build the industry.
typeThe industry type to build.
creation_typeThe circumstances the industry is created under.
Returns
the created industry or NULL if it failed.

Definition at line 1949 of file industry_cmd.cpp.

References GetIndustrySpec().

Referenced by PlaceIndustry().

◆ CreateNewIndustryHelper()

static CommandCost CreateNewIndustryHelper ( TileIndex  tile,
IndustryType  type,
DoCommandFlag  flags,
const IndustrySpec indspec,
uint  itspec_index,
uint32  random_var8f,
uint16  random_initial_bits,
Owner  founder,
IndustryAvailabilityCallType  creation_type,
Industry **  ip 
)
static

Helper function for Build/Fund an industry.

Parameters
tiletile where industry is built
typeof industry to build
flagsof operations to conduct
indspecpointer to industry specifications
itspec_indexthe index of the itsepc to build/fund
seedrandom seed (possibly) used by industries
initial_random_bitsThe random bits the industry is going to have after construction.
founderFounder of the industry
creation_typeThe circumstances the industry is created under.
[out]ipPointer to store newly created industry.
Returns
Succeeded or failed command.
Postcondition
*ip contains the newly created industry if all checks are successful and the flags request actual creation, else it contains NULL afterwards.

Definition at line 1805 of file industry_cmd.cpp.

◆ DoCreateNewIndustry()

static void DoCreateNewIndustry ( Industry i,
TileIndex  tile,
IndustryType  type,
const IndustryTileTable it,
byte  layout,
Town t,
Owner  founder,
uint16  initial_random_bits 
)
static

Put an industry on the map.

Parameters
iJust allocated poolitem, mostly empty.
tileNorth tile of the industry.
typeType of the industry.
itIndustrylayout to build.
layoutNumber of the layout.
tNearest town.
founderFounder of the industry; OWNER_NONE in case of random construction.
initial_random_bitsRandom bits for the industry.

Definition at line 1643 of file industry_cmd.cpp.

References Industry::accepts_cargo, IndustrySpec::accepts_cargo, GetIndustrySpec(), Industry::IncIndustryTypeCount(), Industry::location, min(), Industry::owner, OWNER_NONE, Industry::produced_cargo, Industry::production_rate, RandomRange(), Industry::town, Industry::type, and IndustrySpec::UsesSmoothEconomy().

◆ FindTownForIndustry()

static CommandCost FindTownForIndustry ( TileIndex  tile,
int  type,
Town **  t 
)
static

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

Parameters
tilePosition of the industry to build.
typeIndustry type.
[out]townPointer to return town for the new industry, NULL is written if no good town can be found.
Returns
Succeeded or failed command.
Precondition
*t != NULL
Postcondition
*t points to a town on success, and NULL on failure.

Definition at line 1332 of file industry_cmd.cpp.

References _settings_game, ClosestTownFromTile(), GameSettings::economy, and EconomySettings::multiple_industry_per_town.

◆ GenerateIndustries()

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

◆ GetCurrentTotalNumberOfIndustries()

static uint GetCurrentTotalNumberOfIndustries ( )
static

Get total number of industries existing in the game.

Returns
Number of industries currently in the game.

Definition at line 2070 of file industry_cmd.cpp.

References Industry::GetIndustryTypeCount(), and NUM_INDUSTRYTYPES.

Referenced by IndustryBuildData::MonthlyLoop(), and IndustryBuildData::Reset().

◆ GetIndustryGamePlayProbability()

static uint16 GetIndustryGamePlayProbability ( IndustryType  it,
byte *  min_number 
)
static

Compute the probability for constructing a new industry during game play.

Parameters
itIndustry type to compute.
[out]min_numberMinimal number of industries that should exist at the map.
Returns
Relative probability for the industry to appear.

Definition at line 1992 of file industry_cmd.cpp.

References _cur_year, _settings_game, IndustrySpec::appear_ingame, IndustrySpec::behaviour, GameSettings::difficulty, IndustrySpec::enabled, GameSettings::game_creation, GetIndustryProbabilityCallback(), GetIndustrySpec(), IACT_RANDOMCREATION, ID_FUND_ONLY, DifficultySettings::industry_density, INDUSTRYBEH_AFTER_1960, INDUSTRYBEH_BEFORE_1950, INDUSTRYBEH_CANCLOSE_LASTINSTANCE, GameCreationSettings::landscape, and IndustrySpec::num_table.

Referenced by IndustryTypeBuildData::GetIndustryTypeData().

◆ GetIndustrySpec()

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
thistypeof industry (which is the index in _industry_specs)
Precondition
thistype < NUM_INDUSTRYTYPES
Returns
a pointer to the corresponding industry spec

Definition at line 116 of file industry_cmd.cpp.

Referenced by IndustryOverrideManager::AddEntityID(), AdvertiseIndustryOpening(), BuildIndustriesLegend(), CcBuildIndustry(), ChangeIndustryProduction(), CheckIfCallBackAllowsCreation(), CheckIfFarEnoughFromConflictingIndustry(), CheckIfIndustryIsAllowed(), CheckIfIndustryTilesAreFree(), CheckIndustries(), CheckIndustryCloseDownProtection(), CmdBuildIndustry(), CMSAMine(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), IndustryCargoesWindow::CountMatchingAcceptingIndustries(), IndustryCargoesWindow::CountMatchingProducingIndustries(), CreateNewIndustry(), DoCreateNewIndustry(), IndustryViewWindow::DrawInfo(), FindNearIndustryName(), GetAiPurchaseCallbackResult(), GetGrffile(), NIHIndustry::GetGRFID(), GetIndustryGamePlayProbability(), GetIndustryProbabilityCallback(), IndustryDirectoryWindow::GetIndustryString(), GetScaledIndustryGenerationProbability(), NIHIndustry::GetSpec(), IndustriesScopeResolver::GetVariable(), IndustriesResolverObject::IndustriesResolverObject(), IndustryProductionCallback(), IndustryTypeNameSorter(), NIHIndustry::IsInspectable(), IsTileForestIndustry(), IndustryCargoesWindow::OnInit(), BuildIndustryWindow::OnInvalidateData(), BuildIndustryWindow::OnPlaceObject(), BuildIndustryWindow::OnTick(), Industry::RecomputeProductionMultipliers(), IndustryCargoesWindow::SetStringParameters(), ShowIndustryCargoesWindow(), TransportIndustryGoods(), TriggerIndustryProduction(), and BuildIndustryWindow::UpdateWidgetSize().

◆ GetIndustryTileSpec()

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
gfxof industrytile (which is the index in _industry_tile_specs)
Precondition
gfx < INVALID_INDUSTRYTILE
Returns
a pointer to the corresponding industrytile spec

Definition at line 130 of file industry_cmd.cpp.

Referenced by CheckIfIndustryTilesAreFree(), NIHIndustryTile::GetGRFID(), GetIndTileGrffile(), GetIndustryIDAtOffset(), NIHIndustryTile::GetSpec(), IndustryTileResolverObject::IndustryTileResolverObject(), and NIHIndustryTile::IsInspectable().

◆ GetIndustryType()

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
tilethat is queried
Precondition
IsTileType(tile, MP_INDUSTRY)
Returns
general type for this industry, as defined in industry.h

Definition at line 99 of file industry_cmd.cpp.

Referenced by FindNearIndustryName().

◆ GetNumberOfIndustries()

static uint GetNumberOfIndustries ( )
static

Get wanted number of industries on the map.

Returns
Wanted number of industries at the map.

Definition at line 2016 of file industry_cmd.cpp.

◆ GetScaledIndustryGenerationProbability()

static uint32 GetScaledIndustryGenerationProbability ( IndustryType  it,
bool *  force_at_least_one 
)
static

Compute the appearance probability for an industry during map creation.

Parameters
itIndustry type to compute.
[out]force_at_least_oneReturns whether at least one instance should be forced on map creation.
Returns
Relative probability for the industry to appear.

Definition at line 1967 of file industry_cmd.cpp.

References _settings_game, IndustrySpec::appear_creation, IndustrySpec::enabled, GameSettings::game_creation, GetIndustrySpec(), GameCreationSettings::landscape, and IndustrySpec::num_table.

Referenced by CheckIndustries().

◆ IndustryDailyLoop()

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

◆ IsSuitableForFarmField()

static bool IsSuitableForFarmField ( TileIndex  tile,
bool  allow_fields 
)
static

Check whether the tile can be replaced by a farm field.

Parameters
tilethe tile to investigate.
allow_fieldsif true, the method will return true even if the tile is a farm tile, otherwise the tile may not be a farm tile
Returns
true if the tile can become a farm field

Definition at line 959 of file industry_cmd.cpp.

References CLEAR_DESERT, CLEAR_FIELDS, CLEAR_SNOW, GetTileType(), GetTreeGround(), IsClearGround(), MP_CLEAR, MP_TREES, and TREE_GROUND_SHORE.

◆ IsTileForestIndustry()

bool IsTileForestIndustry ( TileIndex  tile)

Check whether the tile is a forest.

Parameters
tilethe tile to investigate.
Returns
true if and only if the tile is a forest

Definition at line 931 of file industry_cmd.cpp.

References CT_INVALID, CargoSpec::Get(), Industry::GetByTile(), GetIndustrySpec(), INDUSTRYLIFE_ORGANIC, IsTileType(), CargoSpec::label, lengthof, IndustrySpec::life_type, MP_INDUSTRY, Industry::produced_cargo, and Industry::type.

◆ PlaceIndustry()

static Industry* PlaceIndustry ( IndustryType  type,
IndustryAvailabilityCallType  creation_type,
bool  try_hard 
)
static

Try to place the industry in the game.

Since there is no feedback why placement fails, there is no other option than to try a few times before concluding it does not work.

Parameters
typeIndustry type of the desired industry.
try_hardTry very hard to find a place. (Used to place at least one industry per type.)
Returns
Pointer to created industry, or NULL if creation failed.

Definition at line 2041 of file industry_cmd.cpp.

References CreateNewIndustry(), and RandomTile.

Referenced by IndustryCargoesWindow::ComputeCargoDisplay(), and IndustryCargoesWindow::ComputeIndustryDisplay().

◆ PlaceInitialIndustry()

static void PlaceInitialIndustry ( IndustryType  type,
bool  try_hard 
)
static

Try to build a industry on the map.

Parameters
typeIndustryType of the desired industry
try_hardTry very hard to find a place. (Used to place at least one industry per type)

Definition at line 2056 of file industry_cmd.cpp.

References _current_company, and OWNER_NONE.

◆ ReportNewsProductionChangeIndustry()

static void ReportNewsProductionChangeIndustry ( Industry ind,
CargoID  type,
int  percent 
)
static

Report news that industry production has changed significantly.

Parameters
indIndustry with changed production
typeCargo type that has changed
percentPercentage of change (>0 means increase, <0 means decrease)

Definition at line 2447 of file industry_cmd.cpp.

References NT_INDUSTRY_COMPANY, NT_INDUSTRY_NOBODY, NT_INDUSTRY_OTHER, and WhoCanServiceIndustry().

◆ ResetIndustries()

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

◆ SearchLumberMillTrees()

static bool SearchLumberMillTrees ( TileIndex  tile,
void *  user_data 
)
static

Search callback function for ChopLumberMillTrees.

Parameters
tileto test
user_datathat 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 1061 of file industry_cmd.cpp.

References _current_company, GetTreeGrowth(), IsTileType(), MP_TREES, and OWNER_NONE.

Referenced by ChopLumberMillTrees().

◆ SetupFarmFieldFence()

static void SetupFarmFieldFence ( TileIndex  tile,
int  size,
byte  type,
DiagDirection  side 
)
static

Build farm field fence.

Parameters
tilethe tile to position the fence on
sizethe size of the field being planted in tiles
typetype of fence to set
sidethe side of the tile to attempt placement

Definition at line 975 of file industry_cmd.cpp.

References AXIS_Y, Chance16(), CLEAR_FIELDS, DiagDirToAxis(), IsClearGround(), IsTileType(), MP_CLEAR, SetFence(), TILE_MASK, TileDiffXY(), and Industry::type.

◆ TransportIndustryGoods()

static bool TransportIndustryGoods ( TileIndex  tile)
static

Move produced cargo from industry to nearby stations.

Parameters
tileIndustry tile
Returns
true if any cargo was moved.

Definition at line 499 of file industry_cmd.cpp.

References CT_INVALID, EconomyIsInRecession(), Industry::GetByTile(), GetIndustrySpec(), lengthof, Industry::location, min(), IndustrySpec::minimal_cargo, Industry::produced_cargo, Industry::produced_cargo_waiting, Industry::this_month_production, and Industry::type.

◆ UpdateIndustryStatistics()

static void UpdateIndustryStatistics ( Industry i)
static

◆ WhoCanServiceIndustry()

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

References _local_company, CanCargoServiceIndustry(), Vehicle::cargo_type, FindStationsAroundTiles(), FOR_ALL_VEHICLES, Vehicle::IsFrontEngine(), SmallVector< T, S >::Length(), Industry::location, Vehicle::Next(), Vehicle::owner, BaseVehicle::type, VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.

Referenced by ReportNewsProductionChangeIndustry().

Variable Documentation

◆ _check_new_industry_procs

CheckNewIndustryProc* const _check_new_industry_procs[CHECK_END]
static
Initial value:
= {
}
static CommandCost CheckNewIndustry_Lumbermill(TileIndex tile)
Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest). ...
static CommandCost CheckNewIndustry_Farm(TileIndex tile)
Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
static CommandCost CheckNewIndustry_BubbleGen(TileIndex tile)
Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
static CommandCost CheckNewIndustry_Water(TileIndex tile)
Check the conditions of CHECK_WATER (Industry should be in the desert).
static CommandCost CheckNewIndustry_Plantation(TileIndex tile)
Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
static CommandCost CheckNewIndustry_OilRig(TileIndex tile)
Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map)...
static CommandCost CheckNewIndustry_OilRefinery(TileIndex tile)
Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map)...
static CommandCost CheckNewIndustry_Forest(TileIndex tile)
Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate)...
static CommandCost CheckNewIndustry_NULL(TileIndex tile)
Check the conditions of CHECK_NOTHING (Always succeeds).

Check functions for different types of industry.

Definition at line 1310 of file industry_cmd.cpp.

◆ _industry_draw_tile_procs

IndustryDrawTileProc* const _industry_draw_tile_procs[5]
static
Initial value:
= {
IndustryDrawSugarMine,
IndustryDrawToffeeQuarry,
IndustryDrawBubbleGenerator,
IndustryDrawToyFactory,
IndustryDrawCoalPlantSparks,
}

Definition at line 296 of file industry_cmd.cpp.

◆ _tile_type_industry_procs

const TileTypeProcs _tile_type_industry_procs
Initial value:
= {
DrawTile_Industry,
GetSlopePixelZ_Industry,
ClearTile_Industry,
AddAcceptedCargo_Industry,
GetTileDesc_Industry,
GetTileTrackStatus_Industry,
ClickTile_Industry,
AnimateTile_Industry,
TileLoop_Industry,
ChangeTileOwner_Industry,
NULL,
NULL,
GetFoundation_Industry,
TerraformTile_Industry,
}