OpenTTD Source
20241108-master-g80f628063a
|
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 "company_base.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_internal.h"
#include "window_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 "string_func.h"
#include "industry_cmd.h"
#include "landscape_cmd.h"
#include "terraform_cmd.h"
#include "timer/timer.h"
#include "timer/timer_game_calendar.h"
#include "timer/timer_game_economy.h"
#include "timer/timer_game_tick.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) |
static int | WhoCanServiceIndustry (Industry *ind) |
Compute who can service the industry. More... | |
void | ResetIndustries () |
This function initialize the spec arrays of both industry and industry tiles. More... | |
IndustryType | GetIndustryType (Tile tile) |
Retrieve the type for this industry. More... | |
const IndustrySpec * | GetIndustrySpec (IndustryType thistype) |
Accessor for array _industry_specs. More... | |
const IndustryTileSpec * | GetIndustryTileSpec (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, uint, bool) |
static Foundation | GetFoundation_Industry (TileIndex tile, Slope tileh) |
static void | AddAcceptedCargo_Industry (TileIndex tile, CargoArray &acceptance, CargoTypes &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 | AnimateSugarSieve (TileIndex tile) |
static void | AnimateToffeeQuarry (TileIndex tile) |
static void | AnimateBubbleCatcher (TileIndex tile) |
static void | AnimatePowerPlantSparks (TileIndex tile) |
static void | AnimateToyFactory (TileIndex tile) |
static void | AnimatePlasticFountain (TileIndex tile, IndustryGfx gfx) |
static void | AnimateOilWell (TileIndex tile, IndustryGfx gfx) |
static void | AnimateMineTower (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, TransportType, uint, DiagDirection) |
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, uint8_t 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 *) |
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 | ProduceIndustryGoodsHelper (Industry *i, bool scale) |
Helper for ProduceIndustryGoods that scales and produces cargos. More... | |
static void | ProduceIndustryGoods (Industry *i) |
void | OnTick_Industry () |
static CommandCost | CheckNewIndustry_NULL (TileIndex) |
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 bool | CheckScaledDistanceFromEdge (TileIndex tile, uint maxdist) |
Check if a tile is within a distance from map edges, scaled by map dimensions independently. 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 IndustryTileLayout &layout, IndustryType type) |
Are the tiles of the industry free? More... | |
static CommandCost | CheckIfIndustryTileSlopes (TileIndex tile, const IndustryTileLayout &layout, size_t layout_index, int type, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type, bool *custom_shape_check=nullptr) |
Check slope requirements for industry tiles. 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 IndustryTileLayout &layout) |
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 | PopulateStationsNearby (Industry *ind) |
Populate an industry's list of nearby stations, and if it accepts any cargo, also add the industry to each station's nearby industry list. More... | |
static void | DoCreateNewIndustry (Industry *i, TileIndex tile, IndustryType type, const IndustryTileLayout &layout, size_t layout_index, Town *t, Owner founder, uint16_t initial_random_bits) |
Put an industry on the map. More... | |
static CommandCost | CreateNewIndustryHelper (TileIndex tile, IndustryType type, DoCommandFlag flags, const IndustrySpec *indspec, size_t layout_index, uint32_t random_var8f, uint16_t random_initial_bits, Owner founder, IndustryAvailabilityCallType creation_type, Industry **ip) |
Helper function for Build/Fund an industry. More... | |
CommandCost | CmdBuildIndustry (DoCommandFlag flags, TileIndex tile, IndustryType it, uint32_t first_layout, bool fund, uint32_t seed) |
Build/Fund an industry. More... | |
CommandCost | CmdIndustrySetFlags (DoCommandFlag flags, IndustryID ind_id, IndustryControlFlags ctlflags) |
Set industry control flags. More... | |
CommandCost | CmdIndustrySetProduction (DoCommandFlag flags, IndustryID ind_id, uint8_t prod_level, bool show_news, const std::string &custom_news) |
Set industry production. More... | |
CommandCost | CmdIndustrySetExclusivity (DoCommandFlag flags, IndustryID ind_id, Owner company_id, bool consumer) |
Change exclusive consumer or supplier for the industry. More... | |
CommandCost | CmdIndustrySetText (DoCommandFlag flags, IndustryID ind_id, const std::string &text) |
Change additional industry text. More... | |
static Industry * | CreateNewIndustry (TileIndex tile, IndustryType type, IndustryAvailabilityCallType creation_type) |
Create a new industry of random layout. More... | |
static uint32_t | GetScaledIndustryGenerationProbability (IndustryType it, bool *force_at_least_one) |
Compute the appearance probability for an industry during map creation. More... | |
static uint16_t | GetIndustryGamePlayProbability (IndustryType it, uint8_t *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 Industry * | PlaceIndustry (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... | |
void | ClearAllIndustryCachedNames () |
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 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 | InitializeIndustries () |
void | CheckIndustries () |
Verify whether the generated industries are complete, and warn the user if not. | |
static CommandCost | TerraformTile_Industry (TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new) |
void | TrimIndustryAcceptedProduced (Industry *ind) |
Remove unused industry accepted/produced slots – entries after the last slot with valid cargo. More... | |
Variables | |
IndustryPool | _industry_pool ("Industry") |
static uint8_t | _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 uint8_t | _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 |
static IntervalTimer< TimerGameEconomy > | _economy_industries_daily ({TimerGameEconomy::DAY, TimerGameEconomy::Priority::INDUSTRY}, [](auto) { _economy.industry_daily_change_counter+=_economy.industry_daily_increment;uint16_t change_loop=_economy.industry_daily_change_counter >> 16;_economy.industry_daily_change_counter &=0xFFFF;if(change_loop==0) { return;} Backup< CompanyID > cur_company(_current_company, OWNER_NONE);uint perc=3;if((_industry_builder.wanted_inds >> 16) > GetCurrentTotalNumberOfIndustries()) { perc=std::min(9u, perc+(_industry_builder.wanted_inds >> 16) - GetCurrentTotalNumberOfIndustries());} for(uint16_t j=0;j< change_loop;j++) { if(Chance16(perc, 100)) { _industry_builder.TryBuildNewIndustry();} else { Industry *i=Industry::GetRandom();if(i !=nullptr) { ChangeIndustryProduction(i, false);SetWindowDirty(WC_INDUSTRY_VIEW, i->index);} } } cur_company.Restore();InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);}) |
Every economy day 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... | |
static IntervalTimer< TimerGameEconomy > | _economy_industries_monthly ({TimerGameEconomy::MONTH, TimerGameEconomy::Priority::INDUSTRY}, [](auto) { Backup< CompanyID > cur_company(_current_company, OWNER_NONE);_industry_builder.EconomyMonthlyLoop();for(Industry *i :Industry::Iterate()) { UpdateIndustryStatistics(i);if(i->prod_level==PRODLEVEL_CLOSURE) { delete i;} else { ChangeIndustryProduction(i, true);SetWindowDirty(WC_INDUSTRY_VIEW, i->index);} } cur_company.Restore();InvalidateWindowData(WC_INDUSTRY_DIRECTORY, 0, IDIWD_PRODUCTION_CHANGE);}) |
const TileTypeProcs | _tile_type_industry_procs |
Handling of industry tiles.
Definition in file industry_cmd.cpp.
typedef CommandCost CheckNewIndustryProc(TileIndex tile) |
Industrytype check function signature.
tile | Tile to check. |
Definition at line 1406 of file industry_cmd.cpp.
|
static |
Advertise about a new industry opening.
ind | Industry being opened. |
Definition at line 1735 of file industry_cmd.cpp.
References GetIndustrySpec(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, IndustrySpec::name, IndustrySpec::new_industry_text, SetDParam(), Industry::town, and Industry::type.
Referenced by IndustryBuildData::TryBuildNewIndustry().
|
static |
Can given cargo type be accepted or produced by the industry?
cargo | Cargo type |
ind | Industry |
*c_accepts | Pointer to boolean for acceptance of cargo |
*c_produces | Pointer to boolean for production of cargo |
*c_accepts
is set when industry accepts the cargo type, *c_produces
is set when the industry produces the cargo type Definition at line 2705 of file industry_cmd.cpp.
References IndustryTemporarilyRefusesCargo(), Industry::IsCargoAccepted(), Industry::IsCargoProduced(), and IsValidCargoID().
|
static |
Change industry production or do closure.
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 2810 of file industry_cmd.cpp.
References IndustrySpec::callback_mask, CBM_IND_MONTHLYPROD_CHANGE, CBM_IND_PRODUCTION_CHANGE, GetIndustrySpec(), HasBit(), Industry::type, and IndustrySpec::UsesOriginalEconomy().
|
static |
Check that the new industry is far enough from conflicting industries.
tile | Tile to construct the industry. |
type | Type of the new industry. |
Definition at line 1692 of file industry_cmd.cpp.
References IndustrySpec::conflicting, DistanceMax(), OrthogonalTileArea::Expand(), Industry::GetByTile(), GetIndustrySpec(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetNumItems(), GetTileType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Iterate(), Industry::location, MP_INDUSTRY, return_cmd_error, OrthogonalTileArea::tile, and Industry::type.
|
static |
Is the industry allowed to be built at this place for the town?
tile | Tile to construct the industry. |
type | Type of the industry. |
t | Town authority that the industry belongs to. |
Definition at line 1575 of file industry_cmd.cpp.
References Town::cache, DistanceMax(), GetIndustrySpec(), INDUSTRYBEH_ONLY_NEARTOWN, INDUSTRYBEH_TOWN1200_MORE, TownCache::population, return_cmd_error, and Town::xy.
|
static |
Are the tiles of the industry free?
tile | Position to check. |
layout | Industry tiles table. |
type | Type of the industry. |
Definition at line 1471 of file industry_cmd.cpp.
References _current_company, IndustrySpec::behaviour, DC_AUTO, DC_NO_MODIFY_TOWN_RATING, DC_NO_TEST_TOWN_RATING, DC_NONE, EnsureNoVehicleOnGround(), CommandCost::Failed(), GetIndustrySpec(), GetIndustryTileSpec(), GetTranslatedIndustryTileID(), GFX_WATERTILE_SPECIALCHECK, HasBit(), HasTileWaterClass(), INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_ONLY_INTOWN, INDUSTRYBEH_ONLY_NEARTOWN, INDUSTRYBEH_TOWN1200_MORE, IsBridgeAbove(), IsTileFlat(), IsTileOnWater(), IsTileType(), IsValidTile(), IsWaterTile(), MP_HOUSE, OWNER_TOWN, Backup< T >::Restore(), return_cmd_error, IndustryTileSpec::slopes_refused, and TileAddWrap().
|
static |
Check slope requirements for industry tiles.
tile | Position to check. | |
layout | Industry tiles table. | |
layout_index | The index of the layout 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. |
Definition at line 1533 of file industry_cmd.cpp.
|
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.
type | IndustryType been queried |
Definition at line 2687 of file industry_cmd.cpp.
References _settings_game, IndustrySpec::behaviour, GameSettings::game_creation, GetIndustrySpec(), INDUSTRYBEH_DONT_INCR_PROD, and GameCreationSettings::landscape.
|
static |
Check the conditions of CHECK_BUBBLEGEN (Industry should be in low land).
tile | Tile to perform the checking. |
Definition at line 1393 of file industry_cmd.cpp.
References GetTileZ(), and return_cmd_error.
|
static |
Check the conditions of CHECK_FARM (Industry should be below snow-line in arctic).
tile | Tile to perform the checking. |
Definition at line 1339 of file industry_cmd.cpp.
References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.
|
static |
Check the conditions of CHECK_FOREST (Industry should be build above snow-line in arctic climate).
tile | Tile to perform the checking. |
Definition at line 1270 of file industry_cmd.cpp.
References _settings_game, GameSettings::game_creation, and GameCreationSettings::landscape.
|
static |
Check the conditions of CHECK_LUMBERMILL (Industry should be in the rain forest).
tile | Tile to perform the checking. |
Definition at line 1380 of file industry_cmd.cpp.
References GetTropicZone(), return_cmd_error, and TROPICZONE_RAINFOREST.
|
static |
Check the conditions of CHECK_NOTHING (Always succeeds).
Definition at line 1260 of file industry_cmd.cpp.
|
static |
Check the conditions of CHECK_REFINERY (Industry should be positioned near edge of the map).
tile | Tile to perform the checking. |
Definition at line 1308 of file industry_cmd.cpp.
|
static |
Check the conditions of CHECK_OIL_RIG (Industries at sea should be positioned near edge of the map).
tile | Tile to perform the checking. |
Definition at line 1324 of file industry_cmd.cpp.
|
static |
Check the conditions of CHECK_PLANTATION (Industry should NOT be in the desert).
tile | Tile to perform the checking. |
Definition at line 1354 of file industry_cmd.cpp.
References GetTropicZone(), return_cmd_error, and TROPICZONE_DESERT.
|
static |
Check the conditions of CHECK_WATER (Industry should be in the desert).
tile | Tile to perform the checking. |
Definition at line 1367 of file industry_cmd.cpp.
References GetTropicZone(), return_cmd_error, and TROPICZONE_DESERT.
|
static |
Check if a tile is within a distance from map edges, scaled by map dimensions independently.
Each dimension is checked independently, and dimensions smaller than 256 are not scaled.
tile | Which tile to check distance of. |
maxdist | Normal distance on a 256x256 map. |
Definition at line 1287 of file industry_cmd.cpp.
References DIAGDIR_NE, DIAGDIR_NW, DIAGDIR_SE, DIAGDIR_SW, DistanceFromEdgeDir(), Map::SizeX(), and Map::SizeY().
|
static |
Perform a circular search around the Lumber Mill in order to find trees to cut.
i | industry |
Definition at line 1127 of file industry_cmd.cpp.
References CircularTileSearch(), IsIndustryCompleted(), IsValidCargoID(), Industry::location, Industry::produced, ScaleByCargoScale(), SearchLumberMillTrees(), OrthogonalTileArea::tile, and Industry::TileBelongsToIndustry().
CommandCost CmdBuildIndustry | ( | DoCommandFlag | flags, |
TileIndex | tile, | ||
IndustryType | it, | ||
uint32_t | first_layout, | ||
bool | fund, | ||
uint32_t | seed | ||
) |
Build/Fund an industry.
flags | of operations to conduct |
tile | tile where industry is built |
it | industry type see build_industry.h and see industry.h |
first_layout | first layout to try |
fund | false = prospect, true = fund (only valid if current company is DEITY) |
seed | seed to use for desyncfree randomisations |
Definition at line 2065 of file industry_cmd.cpp.
References CMD_ERROR, IndustrySpec::enabled, GetIndustrySpec(), IndustrySpec::layouts, and NUM_INDUSTRYTYPES.
CommandCost CmdIndustrySetExclusivity | ( | DoCommandFlag | flags, |
IndustryID | ind_id, | ||
Owner | company_id, | ||
bool | consumer | ||
) |
Change exclusive consumer or supplier for the industry.
flags | Type of operation. |
ind_id | IndustryID |
company_id | CompanyID to set or INVALID_OWNER (available to everyone) or OWNER_NONE (neutral stations only) or OWNER_DEITY (no one) |
consumer | Set exclusive consumer if true, supplier if false. |
Definition at line 2235 of file industry_cmd.cpp.
References _current_company, CMD_ERROR, DC_EXEC, Industry::exclusive_consumer, Industry::exclusive_supplier, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetIfValid(), INVALID_OWNER, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::IsValidID(), OWNER_DEITY, and OWNER_NONE.
CommandCost CmdIndustrySetFlags | ( | DoCommandFlag | flags, |
IndustryID | ind_id, | ||
IndustryControlFlags | ctlflags | ||
) |
Set industry control flags.
flags | Type of operation. |
ind_id | IndustryID |
ctlflags | IndustryControlFlags |
Definition at line 2157 of file industry_cmd.cpp.
References _current_company, CMD_ERROR, Industry::ctlflags, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetIfValid(), INDCTL_MASK, and OWNER_DEITY.
CommandCost CmdIndustrySetProduction | ( | DoCommandFlag | flags, |
IndustryID | ind_id, | ||
uint8_t | prod_level, | ||
bool | show_news, | ||
const std::string & | custom_news | ||
) |
Set industry production.
flags | Type of operation. |
ind_id | IndustryID |
prod_level | Production level. |
show_news | Show a news message on production change. |
custom_news | Custom news message text. |
Definition at line 2178 of file industry_cmd.cpp.
References _current_company, CMD_ERROR, Industry::ctlflags, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetIfValid(), GetIndustrySpec(), INDCTL_EXTERNAL_PROD_LEVEL, NT_INDUSTRY_COMPANY, NT_INDUSTRY_NOBODY, NT_INDUSTRY_OTHER, OWNER_DEITY, Industry::prod_level, PRODLEVEL_MAXIMUM, IndustrySpec::production_down_text, IndustrySpec::production_up_text, Industry::RecomputeProductionMultipliers(), Industry::type, and WhoCanServiceIndustry().
CommandCost CmdIndustrySetText | ( | DoCommandFlag | flags, |
IndustryID | ind_id, | ||
const std::string & | text | ||
) |
Change additional industry text.
flags | Type of operation. |
ind_id | IndustryID |
text | - Additional industry text. |
Definition at line 2264 of file industry_cmd.cpp.
References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetIfValid(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), OWNER_DEITY, Industry::text, and WC_INDUSTRY_VIEW.
|
static |
Create a new industry of random layout.
tile | The location to build the industry. |
type | The industry type to build. |
creation_type | The circumstances the industry is created under. |
Definition at line 2287 of file industry_cmd.cpp.
References GetIndustrySpec().
Referenced by PlaceIndustry().
|
static |
Helper function for Build/Fund an industry.
tile | tile where industry is built | |
type | of industry to build | |
flags | of operations to conduct | |
indspec | pointer to industry specifications | |
layout_index | the index of the itsepc to build/fund | |
random_var8f | random seed (possibly) used by industries | |
random_initial_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. |
*ip
contains the newly created industry if all checks are successful and the flags request actual creation, else it contains nullptr
afterwards. Definition at line 2001 of file industry_cmd.cpp.
|
static |
Put an industry on the map.
i | Just allocated poolitem, mostly empty. |
tile | North tile of the industry. |
type | Type of the industry. |
layout | Industrylayout to build. |
layout_index | Number of the industry 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 1784 of file industry_cmd.cpp.
|
static |
Find a town for the industry, while checking for multiple industries in the same town.
tile | Position of the industry to build. | |
type | Industry type. | |
[out] | t | Pointer to return town for the new industry, nullptr is written if no good town can be found. |
*t
!= nullptr *t
points to a town on success, and nullptr
on failure. Definition at line 1431 of file industry_cmd.cpp.
References _settings_game, ClosestTownFromTile(), GameSettings::economy, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Iterate(), EconomySettings::multiple_industry_per_town, return_cmd_error, Industry::town, and Industry::type.
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 2460 of file industry_cmd.cpp.
|
static |
Get total number of industries existing in the game.
Definition at line 2414 of file industry_cmd.cpp.
References Industry::GetIndustryTypeCount(), and NUM_INDUSTRYTYPES.
Referenced by IndustryBuildData::EconomyMonthlyLoop(), and IndustryBuildData::Reset().
|
static |
Compute the probability for constructing a new industry during game play.
it | Industry type to compute. | |
[out] | min_number | Minimal number of industries that should exist at the map. |
Definition at line 2332 of file industry_cmd.cpp.
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.
thistype | of industry (which is the index in _industry_specs) |
Definition at line 123 of file industry_cmd.cpp.
References NUM_INDUSTRYTYPES.
Referenced by AdvertiseIndustryOpening(), BuildIndustriesLegend(), ChangeIndustryProduction(), CheckIfFarEnoughFromConflictingIndustry(), CheckIfIndustryIsAllowed(), CheckIfIndustryTilesAreFree(), CheckIndustries(), CheckIndustryCloseDownProtection(), CmdBuildIndustry(), CmdIndustrySetProduction(), CMSAMine(), IndustryCargoesWindow::ComputeCargoDisplay(), IndustryCargoesWindow::ComputeIndustryDisplay(), IndustryCargoesWindow::CountMatchingAcceptingIndustries(), IndustryCargoesWindow::CountMatchingProducingIndustries(), CreateNewIndustry(), Disaster_Helicopter_Init(), IndustryViewWindow::DrawInfo(), FindNearIndustryName(), GetCountAndDistanceOfClosestInstance(), IndustriesResolverObject::GetDebugID(), GetGrffile(), NIHIndustry::GetGRFID(), GetIndustryProbabilityCallback(), IndustryDirectoryWindow::GetIndustryString(), GetScaledIndustryGenerationProbability(), NIHIndustry::GetSpec(), IndustriesScopeResolver::GetVariable(), IndustriesResolverObject::IndustriesResolverObject(), IndustryProductionCallback(), IndustryTemporarilyRefusesCargo(), IndustryTypeNameSorter(), NIHIndustry::IsInspectable(), IsTileForestIndustry(), IndustryCargoesWindow::OnInit(), Industry::RecomputeProductionMultipliers(), ShowIndustryCargoesWindow(), TransportIndustryGoods(), and TriggerIndustryProduction().
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.
gfx | of industrytile (which is the index in _industry_tile_specs) |
Definition at line 137 of file industry_cmd.cpp.
References INVALID_INDUSTRYTILE.
Referenced by CheckIfIndustryTilesAreFree(), DoTriggerIndustryTile(), IndustryTileResolverObject::GetDebugID(), NIHIndustryTile::GetGRFID(), GetIndTileGrffile(), GetIndustryIDAtOffset(), NIHIndustryTile::GetSpec(), IndustryTileResolverObject::IndustryTileResolverObject(), and NIHIndustryTile::IsInspectable().
IndustryType GetIndustryType | ( | Tile | 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.
tile | that is queried |
Definition at line 106 of file industry_cmd.cpp.
References Industry::GetByTile(), IsTileType(), MP_INDUSTRY, and Industry::type.
Referenced by FindNearIndustryName().
|
static |
Get wanted number of industries on the map.
Definition at line 2356 of file industry_cmd.cpp.
|
static |
Compute the appearance probability for an industry during map creation.
it | Industry type to compute. | |
[out] | force_at_least_one | Returns whether at least one instance should be forced on map creation. |
Definition at line 2306 of file industry_cmd.cpp.
References _settings_game, IndustrySpec::appear_creation, IndustrySpec::enabled, GameSettings::game_creation, GetIndustrySpec(), GameCreationSettings::landscape, and IndustrySpec::layouts.
Referenced by CheckIndustries().
|
static |
Check whether the tile can be replaced by a farm field.
tile | the tile to investigate. |
allow_fields | if true, the method will return true even if the tile is a farm tile, otherwise the tile may not be a farm tile |
Definition at line 998 of file industry_cmd.cpp.
References CLEAR_DESERT, CLEAR_FIELDS, CLEAR_SNOW, GetTileType(), GetTreeGround(), IsClearGround(), MP_CLEAR, MP_TREES, and TREE_GROUND_SHORE.
bool IsTileForestIndustry | ( | TileIndex | tile | ) |
Check whether the tile is a forest.
tile | the tile to investigate. |
Definition at line 975 of file industry_cmd.cpp.
References Industry::GetByTile(), GetIndustrySpec(), INDUSTRYLIFE_ORGANIC, IsTileType(), IndustrySpec::life_type, MP_INDUSTRY, Industry::produced, and Industry::type.
|
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.
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.) |
nullptr
if creation failed. Definition at line 2385 of file industry_cmd.cpp.
References CreateNewIndustry(), and RandomTile.
Referenced by PlaceInitialIndustry(), and IndustryBuildData::TryBuildNewIndustry().
|
static |
Try to build a industry on the map.
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 2400 of file industry_cmd.cpp.
References _current_company, GWP_INDUSTRY, IACT_MAPGENERATION, IncreaseGeneratingWorldProgress(), OWNER_NONE, PlaceIndustry(), and Backup< T >::Restore().
|
static |
Populate an industry's list of nearby stations, and if it accepts any cargo, also add the industry to each station's nearby industry list.
ind | Industry |
Definition at line 1755 of file industry_cmd.cpp.
References _settings_game, ForAllStationsAroundTiles(), Station::industries_near, Industry::location, Industry::neutral_station, StationSettings::serve_neutral_industries, GameSettings::station, and Industry::stations_near.
|
static |
Helper for ProduceIndustryGoods that scales and produces cargos.
i | The industry |
scale | Should we scale production of this cargo directly? |
Definition at line 1151 of file industry_cmd.cpp.
References IsValidCargoID(), and Industry::produced.
Report news that industry production has changed significantly.
ind | Industry with changed production |
type | Cargo type that has changed |
percent | Percentage of change (>0 means increase, <0 means decrease) |
Definition at line 2782 of file industry_cmd.cpp.
References NT_INDUSTRY_COMPANY, NT_INDUSTRY_NOBODY, NT_INDUSTRY_OTHER, and WhoCanServiceIndustry().
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 80 of file industry_cmd.cpp.
|
static |
Search callback function for ChopLumberMillTrees.
tile | to test |
Definition at line 1104 of file industry_cmd.cpp.
References _current_company, GetTreeGrowth(), Grown, IsTileType(), MP_TREES, and OWNER_NONE.
Referenced by ChopLumberMillTrees().
|
static |
Build farm field fence.
tile | the tile to position the fence on |
size | the size of the field being planted in tiles |
type | type of fence to set |
side | the side of the tile to attempt placement |
Definition at line 1014 of file industry_cmd.cpp.
References Chance16(), CLEAR_FIELDS, DiagDirToAxis(), GetFence(), IsClearGround(), IsTileType(), MP_CLEAR, OtherAxis(), ReverseDiagDir(), SetFence(), TileOffsByAxis(), TileOffsByDiagDir(), and Map::WrapToMap().
|
static |
Move produced cargo from industry to nearby stations.
tile | Industry tile |
Definition at line 522 of file industry_cmd.cpp.
References EconomyIsInRecession(), Industry::GetByTile(), GetIndustrySpec(), IsValidCargoID(), IndustrySpec::minimal_cargo, Industry::produced, and Industry::type.
void TrimIndustryAcceptedProduced | ( | Industry * | ind | ) |
Remove unused industry accepted/produced slots – entries after the last slot with valid cargo.
ind | Industry to trim slots. |
Definition at line 3228 of file industry_cmd.cpp.
References Industry::accepted, and Industry::produced.
|
static |
Monthly update of industry statistics.
i | Industry to update. |
Definition at line 2511 of file industry_cmd.cpp.
References IsValidCargoID(), and Industry::produced.
|
static |
Compute who can service the industry.
Here, 'can service' means that they have trains and stations close enough to the industry with the right cargo type and the right orders (ie has the technical means).
ind | Industry being investigated. |
Definition at line 2729 of file industry_cmd.cpp.
References Industry::stations_near.
Referenced by CmdIndustrySetProduction(), and ReportNewsProductionChangeIndustry().
|
static |
Check functions for different types of industry.
Definition at line 1409 of file industry_cmd.cpp.
|
static |
Every economy day 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.
|
static |
Definition at line 315 of file industry_cmd.cpp.
|
extern |
Definition at line 56 of file landscape.cpp.