OpenTTD Source: Industry Struct Reference

OpenTTD Source 12.0-beta1

Public Member Functions | Static Public Member Functions | Data Fields | Static Protected Attributes | Private Member Functions
Industry Struct Reference

Defines the internal data of a functional industry. More...

`#include <industry.h>`

Inheritance diagram for Industry:

## Public Member Functions
| Industry (TileIndex tile=INVALID_TILE)
void | RecomputeProductionMultipliers ()
| Recompute production_rate for current prod_level. More...
bool | TileBelongsToIndustry (TileIndex tile) const
| Check if a given tile belongs to this industry. More...
int | GetCargoProducedIndex (CargoID cargo) const
int | GetCargoAcceptedIndex (CargoID cargo) const
const char * | GetCachedName () const
Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >
void * | operator new (size_t size)
| Allocates space for new Titem. More...
void * | operator new (size_t size, size_t index)
| Allocates space for new Titem with given index. More...
void * | operator new (size_t size, void *ptr)
| Allocates space for new Titem at given memory address. More...
void | operator delete (void *p)
| Marks Titem as free. More...

## Static Public Member Functions
static Industry * | GetByTile (TileIndex tile)
| Get the industry of the given tile. More...
static Industry * | GetRandom ()
| Return a random valid industry. More...
static void | PostDestructor (size_t index)
| Invalidating some stuff after removing item from the pool. More...
static void | IncIndustryTypeCount (IndustryType type)
| Increment the count of industries for this type. More...
static void | DecIndustryTypeCount (IndustryType type)
| Decrement the count of industries for this type. More...
static uint16 | GetIndustryTypeCount (IndustryType type)
| Get the count of industries for this type. More...
static void | ResetIndustryCounts ()
| Resets industry counts.
Static Public Member Functions inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >
static bool | CanAllocateItem (size_t n=1)
| Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() More...
static bool | CleaningPool ()
| Returns current state of pool cleaning - yes or no. More...
static bool | IsValidID (size_t index)
| Tests whether given index can be used to get valid (non-nullptr) Titem. More...
static Titem * | Get (size_t index)
| Returns Titem with given index. More...
static Titem * | GetIfValid (size_t index)
| Returns Titem with given index. More...
static size_t | GetPoolSize ()
| Returns first unused index. More...
static size_t | GetNumItems ()
| Returns number of valid items in the pool. More...
static void | PostDestructor (size_t index)
| Dummy function called after destructor of each member. More...
static Pool::IterateWrapper< Titem > | Iterate (size_t from=0)
| Returns an iterable ensemble of all valid Titem. More...

## Data Fields
TileArea | location
| Location of the industry.
Town * | town
| Nearest town.
Station * | neutral_station
| Associated neutral station.
CargoID | produced_cargo [INDUSTRY_NUM_OUTPUTS]
| 16 production cargo slots
uint16 | produced_cargo_waiting [INDUSTRY_NUM_OUTPUTS]
| amount of cargo produced per cargo
uint16 | incoming_cargo_waiting [INDUSTRY_NUM_INPUTS]
| incoming cargo waiting to be processed
byte | production_rate [INDUSTRY_NUM_OUTPUTS]
| production rate for each cargo
byte | prod_level
| general production level
CargoID | accepts_cargo [INDUSTRY_NUM_INPUTS]
| 16 input cargo slots
uint16 | this_month_production [INDUSTRY_NUM_OUTPUTS]
| stats of this month's production per cargo
uint16 | this_month_transported [INDUSTRY_NUM_OUTPUTS]
| stats of this month's transport per cargo
byte | last_month_pct_transported [INDUSTRY_NUM_OUTPUTS]
| percentage transported per cargo in the last full month
uint16 | last_month_production [INDUSTRY_NUM_OUTPUTS]
| total units produced per cargo in the last full month
uint16 | last_month_transported [INDUSTRY_NUM_OUTPUTS]
| total units transported per cargo in the last full month
uint16 | counter
| used for animation and/or production (if available cargo)
IndustryType | type
| type of industry.
Owner | owner
| owner of the industry. Which SHOULD always be (imho) OWNER_NONE
byte | random_colour
| randomized colour of the industry, for display purpose
Year | last_prod_year
| last year of production
byte | was_cargo_delivered
| flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
IndustryControlFlags | ctlflags
| flags overriding standard behaviours
PartOfSubsidy | part_of_subsidy
| NOSAVE: is this industry a source/destination of a subsidy?
StationList | stations_near
| NOSAVE: List of nearby stations.
std::string | cached_name
| NOSAVE: Cache of the resolved name of the industry.
Owner | founder
| Founder of the industry.
Date | construction_date
| Date of the construction of the industry.
uint8 | construction_type
| Way the industry was constructed (. More...
Date | last_cargo_accepted_at [INDUSTRY_NUM_INPUTS]
| Last day each cargo type was accepted by this industry.
byte | selected_layout
| Which tile layout was used when creating the industry.
Owner | exclusive_supplier
| Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone)
Owner | exclusive_consumer
| Which company has exclusive rights to take cargo (INVALID_OWNER = anyone)
std::string | text
| General text with additional information.
uint16 | random
| Random value used for randomisation of all kinds of things.
PersistentStorage * | psa
| Persistent storage for NewGRF industries.
Data Fields inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >
Tindex | index
| Index of this pool item.

## Static Protected Attributes
static uint16 | counts [NUM_INDUSTRYTYPES]
| Number of industries per type ingame.

## Private Member Functions
void | FillCachedName () const

## Additional Inherited Members
Public Types inherited from Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >
typedef struct Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero > | Pool
| Type of the pool this item is going to be part of.

## Detailed Description

Defines the internal data of a functional industry.

Definition at line 66 of file industry.h.

## Member Function Documentation

## ◆ DecIndustryTypeCount()

static void Industry::DecIndustryTypeCount | ( | IndustryType | type | ) |
| inlinestatic

Decrement the count of industries for this type.

Parameters

  type | IndustryType to decrement

Precondition
  type < NUM_INDUSTRYTYPES

Definition at line 168 of file industry.h.

References counts, NUM_INDUSTRYTYPES, and type.

## ◆ GetByTile()

static Industry* Industry::GetByTile | ( | TileIndex | tile | ) |
| inlinestatic

Get the industry of the given tile.

Parameters

  tile | the tile to get the industry from

Precondition
  IsTileType(t, MP_INDUSTRY)

Returns
  the industry

Definition at line 144 of file industry.h.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), and GetIndustryIndex().

Referenced by CheckForDockingTile(), CheckIfFarEnoughFromConflictingIndustry(), CMSAMine(), GetAcceptanceAroundTiles(), GetIndustryType(), GetOrderCmdFromTile(), SmallMapWindow::GetTileColours(), IsShipDestinationTile(), IsTileForestIndustry(), Station::RecomputeCatchment(), NIHIndustryTile::Resolve(), TransportIndustryGoods(), and TriggerIndustryTile().

## ◆ GetIndustryTypeCount()

static uint16 Industry::GetIndustryTypeCount | ( | IndustryType | type | ) |
| inlinestatic

Get the count of industries for this type.

Parameters

  type | IndustryType to query

Precondition
  type < NUM_INDUSTRYTYPES

Definition at line 179 of file industry.h.

References counts, NUM_INDUSTRYTYPES, and type.

Referenced by CheckIndustries(), GetCurrentTotalNumberOfIndustries(), and IndustryBuildData::TryBuildNewIndustry().

## ◆ GetRandom()

Industry * Industry::GetRandom | ( |  | ) |
| static

Return a random valid industry.

Returns
  random industry, nullptr if there are no industries

Definition at line 218 of file industry_cmd.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetNumItems(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::GetPoolSize(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::IsValidID(), MAX_UVALUE, and RandomRange().

Referenced by FindSubsidyIndustryCargoRoute().

## ◆ IncIndustryTypeCount()

static void Industry::IncIndustryTypeCount | ( | IndustryType | type | ) |
| inlinestatic

Increment the count of industries for this type.

Parameters

  type | IndustryType to increment

Precondition
  type < NUM_INDUSTRYTYPES

Definition at line 157 of file industry.h.

References counts, NUM_INDUSTRYTYPES, and type.

Referenced by DoCreateNewIndustry().

## ◆ PostDestructor()

void Industry::PostDestructor | ( | size_t | index | ) |
| static

Invalidating some stuff after removing item from the pool.

Parameters

  index | index of deleted item

Definition at line 208 of file industry_cmd.cpp.

References InvalidateWindowData(), and WC_INDUSTRY_DIRECTORY.

## ◆ RecomputeProductionMultipliers()

void Industry::RecomputeProductionMultipliers | ( |  | ) |

Recompute production_rate for current prod_level.

This function is only valid when not using smooth economy.

Definition at line 2378 of file industry_cmd.cpp.

References CeilDiv(), GetIndustrySpec(), lengthof, PRODLEVEL_DEFAULT, production_rate, and IndustrySpec::UsesOriginalEconomy().

## ◆ TileBelongsToIndustry()

bool Industry::TileBelongsToIndustry | ( | TileIndex | tile | ) | const
| inline

Check if a given tile belongs to this industry.

Parameters

  tile | The tile to check.

Returns
  True if the tile is part of this industry.

Definition at line 117 of file industry.h.

References GetIndustryIndex(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::index, IsTileType(), and MP_INDUSTRY.

Referenced by ChopLumberMillTrees(), GetIndustryIDAtOffset(), and TriggerIndustry().

## Field Documentation

## ◆ construction_type

uint8 Industry::construction_type

Way the industry was constructed (.

See also
  IndustryConstructionType)

Definition at line 96 of file industry.h.

The documentation for this struct was generated from the following files:

- src/industry.h
- src/industry_cmd.cpp