OpenTTD Source 20260206-master-g4d4e37dbf1
Industry Struct Reference

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

#include <industry.h>

Inheritance diagram for Industry:

Data Structures

struct  ProducedHistory
struct  ProducedCargo
struct  AcceptedHistory
struct  AcceptedCargo

Public Types

using ProducedCargoes = std::vector<ProducedCargo>
using AcceptedCargoes = std::vector<AcceptedCargo>

Public Member Functions

 Industry (IndustryID index, TileIndex tile=INVALID_TILE)
void RecomputeProductionMultipliers ()
 Recompute #production_rate for current prod_level.
bool TileBelongsToIndustry (TileIndex tile) const
 Check if a given tile belongs to this industry.
const ProducedCargoGetProduced (size_t slot) const
 Safely get a produced cargo slot, or an empty data if the slot does not exist.
const AcceptedCargoGetAccepted (size_t slot) const
 Safely get an accepted cargo slot, or an empty data if the slot does not exist.
ProducedCargoes::iterator GetCargoProduced (CargoType cargo)
 Get produced cargo slot for a specific cargo type.
ProducedCargoes::const_iterator GetCargoProduced (CargoType cargo) const
 Get produced cargo slot for a specific cargo type (const-variant).
AcceptedCargoes::iterator GetCargoAccepted (CargoType cargo)
 Get accepted cargo slot for a specific cargo type.
AcceptedCargoes::const_iterator GetCargoAccepted (CargoType cargo) const
 Get accepted cargo slot for a specific cargo type (const-variant).
bool IsCargoAccepted () const
 Test if this industry accepts any cargo.
bool IsCargoProduced () const
 Test if this industry produces any cargo.
bool IsCargoAccepted (CargoType cargo) const
 Test if this industry accepts a specific cargo.
bool IsCargoProduced (CargoType cargo) const
 Test if this industry produces a specific cargo.
const std::string & GetCachedName () const

Static Public Member Functions

static IndustryGetByTile (TileIndex tile)
 Get the industry of the given tile.
static IndustryGetRandom ()
 Return a random valid industry.
static void PostDestructor (size_t index)
 Invalidating some stuff after removing item from the pool.
static uint16_t GetIndustryTypeCount (IndustryType type)
 Get the count of industries for this type.

Data Fields

TileArea location {INVALID_TILE, 0, 0}
 Location of the industry.
Towntown = nullptr
 Nearest town.
Stationneutral_station = nullptr
 Associated neutral station.
ValidHistoryMask valid_history = 0
 Mask of valid history records.
ProducedCargoes produced {}
 produced cargo slots
AcceptedCargoes accepted {}
 accepted cargo slots
uint8_t prod_level = 0
 general production level
uint16_t counter = 0
 used for animation and/or production (if available cargo)
IndustryType type = 0
 type of industry.
Owner owner = INVALID_OWNER
 owner of the industry. Which SHOULD always be (imho) OWNER_NONE
Colours random_colour = COLOUR_BEGIN
 randomized colour of the industry, for display purpose
TimerGameEconomy::Year last_prod_year {}
 last economy year of production
uint8_t was_cargo_delivered = 0
 flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry
IndustryControlFlags ctlflags {}
 flags overriding standard behaviours
PartsOfSubsidy 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 = INVALID_OWNER
 Founder of the industry.
TimerGameCalendar::Date construction_date {}
 Date of the construction of the industry.
uint8_t construction_type = 0
 Way the industry was constructed (.
uint8_t selected_layout = 0
 Which tile layout was used when creating the industry.
Owner exclusive_supplier = INVALID_OWNER
 Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone).
Owner exclusive_consumer = INVALID_OWNER
 Which company has exclusive rights to take cargo (INVALID_OWNER = anyone).
EncodedString text {}
 General text with additional information.
uint16_t random = 0
 Random value used for randomisation of all kinds of things.
PersistentStoragepsa = nullptr
 Persistent storage for NewGRF industries.

Static Public Attributes

static std::array< FlatSet< IndustryID >, NUM_INDUSTRYTYPESindustries
 List of industries of each type.

Private Member Functions

void FillCachedName () const

Detailed Description

Defines the internal data of a functional industry.

Definition at line 62 of file industry.h.

Member Typedef Documentation

◆ AcceptedCargoes

using Industry::AcceptedCargoes = std::vector<AcceptedCargo>

Definition at line 104 of file industry.h.

◆ ProducedCargoes

using Industry::ProducedCargoes = std::vector<ProducedCargo>

Definition at line 103 of file industry.h.

Constructor & Destructor Documentation

◆ Industry()

Industry::Industry ( IndustryID index,
TileIndex tile = INVALID_TILE )
inline

Definition at line 138 of file industry.h.

◆ ~Industry()

Industry::~Industry ( )

Definition at line 146 of file industry_cmd.cpp.

Member Function Documentation

◆ FillCachedName()

void Industry::FillCachedName ( ) const
private

Definition at line 2605 of file industry_cmd.cpp.

◆ GetAccepted()

const AcceptedCargo & Industry::GetAccepted ( size_t slot) const
inline

Safely get an accepted cargo slot, or an empty data if the slot does not exist.

Parameters
slotaccepted cargo slot to retrieve.
Returns
the real slot, or an empty slot.

Definition at line 169 of file industry.h.

◆ GetByTile()

Industry * Industry::GetByTile ( TileIndex tile)
inlinestatic

◆ GetCachedName()

const std::string & Industry::GetCachedName ( ) const
inline

Definition at line 270 of file industry.h.

◆ GetCargoAccepted() [1/2]

AcceptedCargoes::iterator Industry::GetCargoAccepted ( CargoType cargo)
inline

Get accepted cargo slot for a specific cargo type.

Parameters
cargoCargoType to find.
Returns
Iterator pointing to accepted cargo slot if it exists, or the end iterator.

Definition at line 202 of file industry.h.

References Industry::AcceptedCargo::cargo, and IsValidCargoType().

Referenced by DeliverGoodsToIndustry(), and IndustryProductionCallback().

◆ GetCargoAccepted() [2/2]

AcceptedCargoes::const_iterator Industry::GetCargoAccepted ( CargoType cargo) const
inline

Get accepted cargo slot for a specific cargo type (const-variant).

Parameters
cargoCargoType to find.
Returns
Iterator pointing to accepted cargo slot if it exists, or the end iterator.

Definition at line 213 of file industry.h.

References Industry::AcceptedCargo::cargo, and IsValidCargoType().

◆ GetCargoProduced() [1/2]

ProducedCargoes::iterator Industry::GetCargoProduced ( CargoType cargo)
inline

Get produced cargo slot for a specific cargo type.

Parameters
cargoCargoType to find.
Returns
Iterator pointing to produced cargo slot if it exists, or the end iterator.

Definition at line 180 of file industry.h.

References Industry::ProducedCargo::cargo, and IsValidCargoType().

Referenced by IndustryProductionCallback(), and IndustryDirectoryWindow::IndustryProductionSorter().

◆ GetCargoProduced() [2/2]

ProducedCargoes::const_iterator Industry::GetCargoProduced ( CargoType cargo) const
inline

Get produced cargo slot for a specific cargo type (const-variant).

Parameters
cargoCargoType to find.
Returns
Iterator pointing to produced cargo slot if it exists, or the end iterator.

Definition at line 191 of file industry.h.

References Industry::ProducedCargo::cargo, and IsValidCargoType().

◆ GetIndustryTypeCount()

uint16_t Industry::GetIndustryTypeCount ( IndustryType type)
inlinestatic

Get the count of industries for this type.

Parameters
typeIndustryType to query
Precondition
type < NUM_INDUSTRYTYPES

Definition at line 264 of file industry.h.

References industries, NUM_INDUSTRYTYPES, and type.

Referenced by CheckIndustries(), CheckIndustryCloseDownProtection(), BuildIndustryWindow::DrawWidget(), SmallMapWindow::DrawWidget(), GetCountAndDistanceOfClosestInstance(), and IndustryBuildData::TryBuildNewIndustry().

◆ GetProduced()

const ProducedCargo & Industry::GetProduced ( size_t slot) const
inline

Safely get a produced cargo slot, or an empty data if the slot does not exist.

Parameters
slotproduced cargo slot to retrieve.
Returns
the real slot, or an empty slot.

Definition at line 158 of file industry.h.

Referenced by ChangeIndustryProduction().

◆ GetRandom()

Industry * Industry::GetRandom ( )
static

Return a random valid industry.

Returns
random industry, nullptr if there are no industries

Definition at line 227 of file industry_cmd.cpp.

References RandomRange().

Referenced by FindSubsidyCargoDestination(), and FindSubsidyIndustryCargoRoute().

◆ IsCargoAccepted() [1/2]

bool Industry::IsCargoAccepted ( ) const
inline

Test if this industry accepts any cargo.

Returns
true iff the industry accepts any cargo.

Definition at line 223 of file industry.h.

References IsValidCargoType().

Referenced by Station::AddIndustryToDeliver(), CanCargoServiceIndustry(), FindSubsidyCargoDestination(), and IndustryTemporarilyRefusesCargo().

◆ IsCargoAccepted() [2/2]

bool Industry::IsCargoAccepted ( CargoType cargo) const
inline

Test if this industry accepts a specific cargo.

Parameters
cargoCargo type to test.
Returns
true iff the industry accepts the given cargo type.

Definition at line 236 of file industry.h.

◆ IsCargoProduced() [1/2]

bool Industry::IsCargoProduced ( ) const
inline

Test if this industry produces any cargo.

Returns
true iff the industry produces any cargo.

Definition at line 229 of file industry.h.

References IsValidCargoType().

Referenced by CanCargoServiceIndustry().

◆ IsCargoProduced() [2/2]

bool Industry::IsCargoProduced ( CargoType cargo) const
inline

Test if this industry produces a specific cargo.

Parameters
cargoCargo type to test.
Returns
true iff the industry produces the given cargo types.

Definition at line 243 of file industry.h.

◆ PostDestructor()

void Industry::PostDestructor ( size_t index)
static

Invalidating some stuff after removing item from the pool.

Parameters
indexindex of deleted item

Definition at line 216 of file industry_cmd.cpp.

References InvalidateWindowData(), SetWindowDirty(), WC_BUILD_INDUSTRY, 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 2594 of file industry_cmd.cpp.

References CeilDiv(), ClampTo(), GetIndustrySpec(), PRODLEVEL_DEFAULT, produced, and IndustrySpec::UsesOriginalEconomy().

Referenced by ChangeIndustryProduction(), CmdIndustrySetProduction(), and DoCreateNewIndustry().

◆ TileBelongsToIndustry()

bool Industry::TileBelongsToIndustry ( TileIndex tile) const
inline

Check if a given tile belongs to this industry.

Parameters
tileThe tile to check.
Returns
True if the tile is part of this industry.

Definition at line 148 of file industry.h.

References GetIndustryIndex(), Industry, and IsTileType().

Referenced by ChopLumberMillTrees(), DoCreateNewIndustry(), GetIndustryIDAtOffset(), and TriggerIndustryRandomisation().

Field Documentation

◆ accepted

◆ cached_name

std::string Industry::cached_name {}
mutable

NOSAVE: Cache of the resolved name of the industry.

Definition at line 124 of file industry.h.

◆ construction_date

TimerGameCalendar::Date Industry::construction_date {}

Date of the construction of the industry.

Definition at line 127 of file industry.h.

Referenced by DoCreateNewIndustry().

◆ construction_type

uint8_t Industry::construction_type = 0

Way the industry was constructed (.

See also
IndustryConstructionType)

Definition at line 128 of file industry.h.

Referenced by DoCreateNewIndustry().

◆ counter

uint16_t Industry::counter = 0

used for animation and/or production (if available cargo)

Definition at line 113 of file industry.h.

Referenced by DoCreateNewIndustry().

◆ ctlflags

IndustryControlFlags Industry::ctlflags {}

flags overriding standard behaviours

Definition at line 120 of file industry.h.

Referenced by ChangeIndustryProduction(), CmdIndustrySetFlags(), CmdIndustrySetProduction(), and DoCreateNewIndustry().

◆ exclusive_consumer

Owner Industry::exclusive_consumer = INVALID_OWNER

Which company has exclusive rights to take cargo (INVALID_OWNER = anyone).

Definition at line 131 of file industry.h.

Referenced by CmdIndustrySetExclusivity(), DoCreateNewIndustry(), and TransportIndustryGoods().

◆ exclusive_supplier

Owner Industry::exclusive_supplier = INVALID_OWNER

Which company has exclusive rights to deliver cargo (INVALID_OWNER = anyone).

Definition at line 130 of file industry.h.

Referenced by CmdIndustrySetExclusivity(), DeliverGoodsToIndustry(), and DoCreateNewIndustry().

◆ founder

Owner Industry::founder = INVALID_OWNER

Founder of the industry.

Definition at line 126 of file industry.h.

Referenced by CheckIfCallBackAllowsCreation(), DoCreateNewIndustry(), and PerformIndustryTileSlopeCheck().

◆ industries

◆ last_prod_year

TimerGameEconomy::Year Industry::last_prod_year {}

last economy year of production

Definition at line 118 of file industry.h.

Referenced by ChangeIndustryProduction(), DoCreateNewIndustry(), and UpdateIndustryStatistics().

◆ location

◆ neutral_station

Station* Industry::neutral_station = nullptr

◆ owner

Owner Industry::owner = INVALID_OWNER

owner of the industry. Which SHOULD always be (imho) OWNER_NONE

Definition at line 116 of file industry.h.

Referenced by DoCreateNewIndustry().

◆ part_of_subsidy

PartsOfSubsidy Industry::part_of_subsidy {}

NOSAVE: is this industry a source/destination of a subsidy?

Definition at line 122 of file industry.h.

◆ prod_level

◆ produced

◆ psa

PersistentStorage* Industry::psa = nullptr

Persistent storage for NewGRF industries.

Definition at line 136 of file industry.h.

Referenced by CheckIfCallBackAllowsCreation(), NIHIndustry::GetPSA(), and INDYChunkHandler::Load().

◆ random

uint16_t Industry::random = 0

Random value used for randomisation of all kinds of things.

Definition at line 134 of file industry.h.

Referenced by CheckIfCallBackAllowsCreation(), DoCreateNewIndustry(), DoReseedIndustry(), and PerformIndustryTileSlopeCheck().

◆ random_colour

Colours Industry::random_colour = COLOUR_BEGIN

randomized colour of the industry, for display purpose

Definition at line 117 of file industry.h.

Referenced by DoCreateNewIndustry().

◆ selected_layout

uint8_t Industry::selected_layout = 0

Which tile layout was used when creating the industry.

Definition at line 129 of file industry.h.

Referenced by CheckIfCallBackAllowsCreation(), DoCreateNewIndustry(), and GetCountAndDistanceOfClosestInstance().

◆ stations_near

StationList Industry::stations_near {}

NOSAVE: List of nearby stations.

Definition at line 123 of file industry.h.

Referenced by PopulateStationsNearby(), Station::RecomputeCatchment(), TransportIndustryGoods(), and WhoCanServiceIndustry().

◆ text

EncodedString Industry::text {}

General text with additional information.

Definition at line 132 of file industry.h.

Referenced by CmdIndustrySetText(), and IndustryViewWindow::DrawInfo().

◆ town

◆ type

◆ valid_history

ValidHistoryMask Industry::valid_history = 0

Mask of valid history records.

Definition at line 109 of file industry.h.

Referenced by DoCreateNewIndustry(), INDYChunkHandler::Load(), and UpdateIndustryStatistics().

◆ was_cargo_delivered

uint8_t Industry::was_cargo_delivered = 0

flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry

Definition at line 119 of file industry.h.

Referenced by DoCreateNewIndustry(), and TriggerIndustryProduction().


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