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 "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 "table/strings.h"
#include "table/industry_land.h"
#include "table/build_industry.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.

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 IndustrySpecGetIndustrySpec (IndustryType thistype)
 Accessor for array _industry_specs.
const IndustryTileSpecGetIndustryTileSpec (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 CommandCost CheckNewIndustry_NULL (TileIndex tile)
 Check the conditions of CHECK_NOTHING (Always succeeds).
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_OilRefinery (TileIndex tile)
 Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).
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_Farm (TileIndex tile)
 Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
static CommandCost CheckNewIndustry_Plantation (TileIndex tile)
 Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
static CommandCost CheckNewIndustry_Water (TileIndex tile)
 Check the conditions of CHECK_WATER (Industry should be in the desert).
static CommandCost CheckNewIndustry_Lumbermill (TileIndex tile)
 Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).
static CommandCost CheckNewIndustry_BubbleGen (TileIndex tile)
 Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
static CommandCost FindTownForIndustry (TileIndex tile, int type, const Town **t)
 Find a town for the industry, while checking for multiple industries in the same town.
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?
static CommandCost CheckIfIndustryIsAllowed (TileIndex tile, int type, const Town *t)
 Is the industry allowed to be built at this place for the town?
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.
void UpdateIndustryAcceptance (Industry *ind)
 Update the mask of always accepted cargos that are also produced.
static void DoCreateNewIndustry (Industry *i, TileIndex tile, IndustryType type, const IndustryTileTable *it, byte layout, const Town *t, Owner founder, uint16 initial_random_bits)
 Put an industry on the map.
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.
CommandCost CmdBuildIndustry (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
 Build/Fund an industry.
static IndustryCreateNewIndustry (TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type)
 Create a new industry of random layout.
static uint32 GetScaledIndustryGenerationProbability (IndustryType it, bool *force_at_least_one)
 Compute the appearance probability for an industry during map creation.
static uint16 GetIndustryGamePlayProbability (IndustryType it, byte *min_number)
 Compute the probability for constructing a new industry during game play.
static uint GetNumberOfIndustries ()
 Get wanted number of industries on the map.
static void AdvertiseIndustryOpening (const Industry *ind)
 Advertise about a new industry opening.
static IndustryPlaceIndustry (IndustryType type, IndustryAvailabilityCallType creation_type, bool try_hard)
 Try to place the industry in the game.
static void PlaceInitialIndustry (IndustryType type, bool try_hard)
 Try to build a industry on the map.
static uint GetCurrentTotalNumberOfIndustries ()
 Get total number of industries existing in the game.
void GenerateIndustries ()
 This function will create random industries during game creation.
static void UpdateIndustryStatistics (Industry *i)
 Monthly update of industry statistics.
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
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.
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

Industrytype check function signature.

Parameters:
tile Tile to check.
Returns:
Succeeded or failed command.

Definition at line 1270 of file industry_cmd.cpp.


Function Documentation

static void AdvertiseIndustryOpening ( const Industry ind  )  [static]
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 2300 of file industry_cmd.cpp.

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

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 2421 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_CHANGE, Chance16(), Chance16I(), CheckIndustryCloseDownProtection(), Clamp(), ClampU(), IndustrySpec::closure_text, CT_INVALID, GameSettings::game_creation, GB(), GetIndustryCallback(), GetIndustrySpec(), GetRegister(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INDUSTRYBEH_BUILT_ONWATER, 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_MAXIMUM, PRODLEVEL_MINIMUM, Industry::produced_cargo, IndustrySpec::production_down_text, Industry::production_rate, IndustrySpec::production_up_text, Industry::RecomputeProductionMultipliers(), ReportNewsProductionChangeIndustry(), SetDParam(), TileArea::tile, TileDiffXY(), Industry::town, Industry::type, IndustrySpec::UsesSmoothEconomy(), and WhoCanServiceIndustry().

Referenced by IndustryDailyLoop().

static CommandCost CheckIfFarEnoughFromConflictingIndustry ( TileIndex  tile,
int  type 
) [static]

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

Parameters:
tile Tile to construct the industry.
type Type of the new industry.
Returns:
Succeeded or failed command.

Definition at line 1535 of file industry_cmd.cpp.

References IndustrySpec::conflicting, DistanceMax(), GetIndustrySpec(), Industry::location, return_cmd_error, TileArea::tile, and Industry::type.

Referenced by CreateNewIndustryHelper().

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:
tile Tile to construct the industry.
type Type of the industry.
t Town authority that the industry belongs to.
Returns:
Succeeded or failed command.

Definition at line 1419 of file industry_cmd.cpp.

References DistanceMax(), GetIndustrySpec(), INDUSTRYBEH_ONLY_NEARTOWN, INDUSTRYBEH_TOWN1200_MORE, and return_cmd_error.

Referenced by CreateNewIndustryHelper().

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:
tile Position to check.
it Industry tiles table.
itspec_index The index of the itsepc to build/fund
type Type of the industry.
initial_random_bits The random bits the industry is going to have after construction.
founder Industry founder
creation_type The circumstances the industry is created under.
[out] custom_shape_check Perform custom check for the site.
Returns:
Failed or succeeded command.

Definition at line 1341 of file industry_cmd.cpp.

References _current_company, _generating_world, _settings_game, IndustrySpec::behaviour, IndustryTileSpec::callback_mask, CBM_INDT_SHAPE_CHECK, CMD_LANDSCAPE_CLEAR, DC_NO_MODIFY_TOWN_RATING, DC_NO_TEST_TOWN_RATING, DC_NONE, DoCommand(), EnsureNoVehicleOnGround(), CommandCost::Failed(), GameSettings::game_creation, GetIndustrySpec(), GetIndustryTileSpec(), GetTileSlope(), GetTranslatedIndustryTileID(), GFX_WATERTILE_SPECIALCHECK, HasBit(), HasTileWaterClass(), INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_ONLY_INTOWN, INDUSTRYBEH_ONLY_NEARTOWN, INDUSTRYBEH_TOWN1200_MORE, IsBridgeAbove(), IsTileOnWater(), IsTileType(), IsValidTile(), GameCreationSettings::land_generator, LG_TERRAGENESIS, MayHaveBridgeAbove(), MP_HOUSE, MP_WATER, OWNER_TOWN, PerformIndustryTileSlopeCheck(), Backup< T >::Restore(), return_cmd_error, SLOPE_FLAT, IndustryTileSpec::slopes_refused, TileAddWrap(), TileIndexDiffC::x, and TileIndexDiffC::y.

Referenced by CreateNewIndustryHelper().

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

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

Referenced by ChangeIndustryProduction().

static CommandCost 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:
Succeeded or failed command.

Definition at line 1257 of file industry_cmd.cpp.

References GetTileZ(), return_cmd_error, and TILE_HEIGHT.

static CommandCost 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:
Succeeded or failed command.

Definition at line 1203 of file industry_cmd.cpp.

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

static CommandCost 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:
Succeeded or failed command.

Definition at line 1159 of file industry_cmd.cpp.

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

static CommandCost 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:
Succeeded or failed command.

Definition at line 1244 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, and TROPICZONE_RAINFOREST.

static CommandCost CheckNewIndustry_NULL ( TileIndex  tile  )  [static]

Check the conditions of CHECK_NOTHING (Always succeeds).

Parameters:
tile Tile to perform the checking.
Returns:
Succeeded or failed command.

Definition at line 1149 of file industry_cmd.cpp.

static CommandCost 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:
Succeeded or failed command.

Definition at line 1174 of file industry_cmd.cpp.

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

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:
tile Tile to perform the checking.
Returns:
Succeeded or failed command.

Definition at line 1189 of file industry_cmd.cpp.

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

static CommandCost 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:
Succeeded or failed command.

Definition at line 1218 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, and TROPICZONE_DESERT.

static CommandCost 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:
Succeeded or failed command.

Definition at line 1231 of file industry_cmd.cpp.

References GetTropicZone(), return_cmd_error, 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

Definition at line 1063 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 
)
static Industry* CreateNewIndustry ( TileIndex  tile,
IndustryType  type,
IndustryAvailabilityCallType  creation_type 
) [static]

Create a new industry of random layout.

Parameters:
tile The location to build the industry.
type The industry type to build.
creation_type The circumstances the industry is created under.
Returns:
the created industry or NULL if it failed.

Definition at line 1874 of file industry_cmd.cpp.

References CreateNewIndustryHelper(), CommandCost::Failed(), GB(), GetIndustrySpec(), IndustrySpec::num_table, and OWNER_NONE.

Referenced by PlaceIndustry().

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:
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
initial_random_bits The random bits the industry is going to have after construction.
founder Founder of the industry
creation_type The circumstances the industry is created under.
[out] ip Pointer 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 1723 of file industry_cmd.cpp.

References _generating_world, _settings_game, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::CanAllocateItem(), CBM_IND_LOCATION, IndustrySpec::check_proc, CheckIfCallBackAllowsCreation(), CheckIfCanLevelIndustryPlatform(), CheckIfFarEnoughFromConflictingIndustry(), CheckIfIndustryIsAllowed(), CheckIfIndustryTilesAreFree(), DC_NO_WATER, DoCreateNewIndustry(), CommandCost::Failed(), FindTownForIndustry(), GameSettings::game_creation, GetIndustrySpec(), HasBit(), GameCreationSettings::land_generator, LG_TERRAGENESIS, return_cmd_error, and IndustrySpec::table.

Referenced by CmdBuildIndustry(), and CreateNewIndustry().

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

Put an industry on the map.

Parameters:
i Just allocated poolitem, mostly empty.
tile North tile of the industry.
type Type of the industry.
it Industrylayout to build.
layout Number of the layout.
t Nearest town.
founder Founder of the industry; OWNER_NONE in case of random construction.
initial_random_bits Random bits for the industry.

Definition at line 1586 of file industry_cmd.cpp.

References _cur_year, _date, _generating_world, IndustrySpec::accepts_cargo, Industry::accepts_cargo, TileArea::Add(), AddAnimatedTile(), ANIM_STATUS_NO_ANIMATION, IndustryTileSpec::animation, IndustrySpec::behaviour, CALLBACK_FAILED, IndustrySpec::callback_mask, CBID_INDUSTRY_DECIDE_COLOUR, CBID_INDUSTRY_INPUT_CARGO_TYPES, CBID_INDUSTRY_OUTPUT_CARGO_TYPES, CBM_IND_DECIDE_COLOUR, CBM_IND_INPUT_CARGO_TYPES, CBM_IND_OUTPUT_CARGO_TYPES, CMD_LANDSCAPE_CLEAR, Industry::construction_date, Industry::construction_type, Industry::counter, CT_INVALID, DC_NO_MODIFY_TOWN_RATING, DC_NO_TEST_TOWN_RATING, DoCommand(), Industry::founder, GB(), GetIndustryCallback(), GetIndustrySpec(), GetIndustryTileSpec(), GetTranslatedIndustryTileID(), GetWaterClass(), GFX_WATERTILE_SPECIALCHECK, IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), ICT_MAP_GENERATION, ICT_NORMAL_GAMEPLAY, ICT_SCENARIO_EDITOR, Industry::IncIndustryTypeCount(), Industry::incoming_cargo_waiting, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INDUSTRYBEH_PLANT_ON_BUILT, INVALID_TILE, InvalidateWindowData(), IsWaterTile(), Industry::last_month_pct_transported, Industry::last_month_production, Industry::last_month_transported, Industry::last_prod_year, lengthof, Industry::location, MakeIndustry(), min(), Industry::owner, OWNER_NONE, Industry::prod_level, PRODLEVEL_DEFAULT, Industry::produced_cargo, Industry::produced_cargo_waiting, Industry::production_rate, Industry::random, Industry::random_colour, Station::RecomputeIndustriesNearForAll(), Industry::selected_layout, SetIndustryConstructionCounter(), SetIndustryConstructionStage(), AnimationInfo::status, Industry::this_month_production, Industry::this_month_transported, ToTileIndexDiff(), Industry::town, Industry::type, UpdateIndustryAcceptance(), IndustrySpec::UsesSmoothEconomy(), Industry::was_cargo_delivered, WATER_CLASS_INVALID, and TileInfo::x.

Referenced by CreateNewIndustryHelper().

static CommandCost FindTownForIndustry ( TileIndex  tile,
int  type,
const Town **  t 
) [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] town Pointer to return town for the new industry, NULL is written if no good town can be found.
Returns:
Succeeded or failed command.

*t != NULL *t points to a town on success, and NULL on failure.

Definition at line 1295 of file industry_cmd.cpp.

References _settings_game, ClosestTownFromTile(), GameSettings::economy, EconomySettings::multiple_industry_per_town, return_cmd_error, 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 2059 of file industry_cmd.cpp.

References _industry_builder, _settings_game, GameSettings::difficulty, GetNumberOfIndustries(), GetScaledIndustryGenerationProbability(), GWP_INDUSTRY, ID_FUND_ONLY, DifficultySettings::industry_density, NUM_INDUSTRYTYPES, PlaceInitialIndustry(), IndustryBuildData::Reset(), and SetGeneratingWorldProgress().

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

static uint GetCurrentTotalNumberOfIndustries (  )  [static]

Get total number of industries existing in the game.

Returns:
Number of industries currently in the game.

Definition at line 2013 of file industry_cmd.cpp.

References Industry::GetIndustryTypeCount(), and NUM_INDUSTRYTYPES.

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

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

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

Parameters:
it Industry type to compute.
[out] min_number Minimal number of industries that should exist at the map.
Returns:
Relative probability for the industry to appear.

Definition at line 1917 of file industry_cmd.cpp.

References _cur_year, _settings_game, IndustrySpec::appear_ingame, IndustrySpec::behaviour, CheckIfCallBackAllowsAvailability(), GameSettings::difficulty, IndustrySpec::enabled, GameSettings::game_creation, 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().

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(), AdvertiseIndustryOpening(), AfterLoadGame(), BuildIndustriesLegend(), AIIndustryType::BuildIndustry(), AIIndustryType::CanBuildIndustry(), AIIndustryType::CanProspectIndustry(), CcBuildIndustry(), ChangeIndustryProduction(), CheckIfCallBackAllowsAvailability(), CheckIfCallBackAllowsCreation(), CheckIfFarEnoughFromConflictingIndustry(), CheckIfIndustryIsAllowed(), CheckIfIndustryTilesAreFree(), CheckIndustryCloseDownProtection(), CmdBuildIndustry(), CMSAForest(), CMSAMine(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), CargoesRow::ConnectIndustryAccepted(), CargoesRow::ConnectIndustryProduced(), IndustryCargoesWindow::CountMatchingAcceptingIndustries(), IndustryCargoesWindow::CountMatchingProducingIndustries(), CreateNewIndustry(), CreateNewIndustryHelper(), Disaster_CoalMine_Init(), Disaster_Helicopter_Init(), DisasterTick_Aircraft(), DoCreateNewIndustry(), CargoesField::Draw(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), FindNearIndustryName(), FormatString(), AIIndustryType::GetAcceptedCargo(), GetAiPurchaseCallbackResult(), AIIndustryType::GetConstructionCost(), GetCountAndDistanceOfClosestInstance(), GetIndustryCallback(), GetIndustryGamePlayProbability(), IndustryDirectoryWindow::GetIndustryString(), AIIndustryType::GetName(), AIIndustryType::GetProducedCargo(), GetScaledIndustryGenerationProbability(), GetSmallMapIndustriesPixels(), GetSmallMapVegetationPixels(), NIHIndustry::GetSpec(), AIIndustryType::HasDock(), AIIndustry::HasDock(), AIIndustryType::HasHeliport(), AIIndustry::HasHeliport(), IndustryGetVariable(), IndustryProductionCallback(), IndustryTemporarilyRefusesCargo(), IndustryTypeNameSorter(), AIIndustryType::IsBuiltOnWater(), AIIndustry::IsBuiltOnWater(), NIHIndustry::IsInspectable(), AIIndustryType::IsRawIndustry(), AIIndustryType::IsValidIndustryType(), BuildIndustryWindow::OnClick(), IndustryCargoesWindow::OnInit(), IndustryViewWindow::OnInvalidateData(), BuildIndustryWindow::OnInvalidateData(), BuildIndustryWindow::OnPlaceObject(), BuildIndustryWindow::OnTick(), AIIndustryType::ProductionCanIncrease(), Industry::RecomputeProductionMultipliers(), IndustryCargoesWindow::SetStringParameters(), 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 CheckIfIndustryTilesAreFree(), DoCreateNewIndustry(), GetIndustryIDAtOffset(), NIHIndustryTile::GetSpec(), and NIHIndustryTile::IsInspectable().

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 AfterLoadGame(), and FindNearIndustryName().

static uint GetNumberOfIndustries (  )  [static]

Get wanted number of industries on the map.

Returns:
Wanted number of industries at the map.

Definition at line 1941 of file industry_cmd.cpp.

References _settings_game, GameSettings::difficulty, ID_END, ID_VERY_LOW, DifficultySettings::industry_density, lengthof, and ScaleByMapSize().

Referenced by GenerateIndustries().

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

Compute the appearance probability for an industry during map creation.

Parameters:
it Industry type to compute.
[out] 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 1892 of file industry_cmd.cpp.

References _settings_game, IndustrySpec::appear_creation, IndustrySpec::behaviour, CHECK_OIL_RIG, IndustrySpec::check_proc, CHECK_REFINERY, CheckIfCallBackAllowsAvailability(), GameSettings::difficulty, IndustrySpec::enabled, GameSettings::game_creation, GetIndustrySpec(), IACT_MAPGENERATION, ID_FUND_ONLY, DifficultySettings::industry_density, INDUSTRYBEH_NOBUILT_MAPCREATION, GameCreationSettings::landscape, IndustrySpec::num_table, 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 2620 of file industry_cmd.cpp.

References _current_company, _industry_builder, Chance16(), ChangeIndustryProduction(), GetCurrentTotalNumberOfIndustries(), Industry::GetRandom(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Economy::industry_daily_change_counter, Economy::industry_daily_increment, InvalidateWindowData(), min(), OWNER_NONE, Backup< T >::Restore(), SetWindowDirty(), IndustryBuildData::TryBuildNewIndustry(), and IndustryBuildData::wanted_inds.

Referenced by OnNewDay().

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:
type Industry type of the desired industry.
try_hard Try 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 1984 of file industry_cmd.cpp.

References CreateNewIndustry(), and RandomTile.

Referenced by PlaceInitialIndustry(), and IndustryBuildData::TryBuildNewIndustry().

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

References _current_company, GWP_INDUSTRY, IACT_MAPGENERATION, IncreaseGeneratingWorldProgress(), OWNER_NONE, PlaceIndustry(), and Backup< T >::Restore().

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

References abs(), CargoSpec::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, 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 1040 of file industry_cmd.cpp.

References _current_company, CMD_LANDSCAPE_CLEAR, DoCommand(), GetTreeGrowth(), IsTileType(), MP_TREES, OWNER_NONE, and Backup< T >::Restore().

Referenced by ChopLumberMillTrees().

void UpdateIndustryAcceptance ( Industry ind  ) 
static void UpdateIndustryStatistics ( Industry i  )  [static]
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 2334 of file industry_cmd.cpp.

References _local_company, CanCargoServiceIndustry(), Vehicle::cargo_type, SmallVector< T, S >::Contains(), FindStationsAroundTiles(), FOR_ALL_VEHICLES, SpecializedStation< Station, false >::Get(), Order::GetDestination(), Order::GetUnloadType(), Vehicle::IsFrontEngine(), Order::IsType(), SmallVector< T, S >::Length(), Industry::location, Vehicle::Next(), OUFB_TRANSFER, OUFB_UNLOAD, Vehicle::owner, 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]
IndustryDrawTileProc* const _industry_draw_tile_procs[5] [static]
Initial value:
 {
  IndustryDrawSugarMine,
  IndustryDrawToffeeQuarry,
  IndustryDrawBubbleGenerator,
  IndustryDrawToyFactory,
  IndustryDrawCoalPlantSparks,
}

Definition at line 311 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,      
}

Generated on Fri Jun 3 05:19:05 2011 for OpenTTD by  doxygen 1.6.1