OpenTTD GameScript API  20240426-master-ga60a81f34e
Public Types | Static Public Member Functions
GSIndustry Class Reference

Class that handles all industry related functions. More...

Inheritance diagram for GSIndustry:

Public Types

enum  CargoAcceptState {
  CAS_NOT_ACCEPTED,
  CAS_ACCEPTED,
  CAS_TEMP_REFUSED
}
 Ways for an industry to accept a cargo. More...
 
enum  IndustryControlFlags {
  INDCTL_NO_PRODUCTION_DECREASE,
  INDCTL_NO_PRODUCTION_INCREASE,
  INDCTL_NO_CLOSURE,
  INDCTL_EXTERNAL_PROD_LEVEL
}
 Control flags for industry. More...
 

Static Public Member Functions

static SQInteger GetIndustryCount ()
 Gets the number of industries. More...
 
static bool IsValidIndustry (IndustryID industry_id)
 Checks whether the given industry index is valid. More...
 
static IndustryID GetIndustryID (TileIndex tile)
 Get the IndustryID of a tile, if there is an industry. More...
 
static std::optional< std::string > GetName (IndustryID industry_id)
 Get the name of the industry. More...
 
static GSDate::Date GetConstructionDate (IndustryID industry_id)
 Get the construction date of an industry. More...
 
static bool SetText (IndustryID industry_id, Text *text)
 Set the custom text of an industry, shown in the GUI. More...
 
static CargoAcceptState IsCargoAccepted (IndustryID industry_id, CargoID cargo_id)
 See whether an industry currently accepts a certain cargo. More...
 
static SQInteger GetStockpiledCargo (IndustryID industry_id, CargoID cargo_id)
 Get the amount of cargo stockpiled for processing. More...
 
static SQInteger GetLastMonthProduction (IndustryID industry_id, CargoID cargo_id)
 Get the total last month's production of the given cargo at an industry. More...
 
static SQInteger GetLastMonthTransported (IndustryID industry_id, CargoID cargo_id)
 Get the total amount of cargo transported from an industry last month. More...
 
static SQInteger GetLastMonthTransportedPercentage (IndustryID industry_id, CargoID cargo_id)
 Get the percentage of cargo transported from an industry last month. More...
 
static TileIndex GetLocation (IndustryID industry_id)
 Gets the location of the industry. More...
 
static SQInteger GetAmountOfStationsAround (IndustryID industry_id)
 Get the number of stations around an industry. More...
 
static SQInteger GetDistanceManhattanToTile (IndustryID industry_id, TileIndex tile)
 Get the manhattan distance from the tile to the GSIndustry::GetLocation() of the industry. More...
 
static SQInteger GetDistanceSquareToTile (IndustryID industry_id, TileIndex tile)
 Get the square distance from the tile to the GSIndustry::GetLocation() of the industry. More...
 
static bool IsBuiltOnWater (IndustryID industry_id)
 Is this industry built on water. More...
 
static bool HasHeliport (IndustryID industry_id)
 Does this industry have a heliport? More...
 
static TileIndex GetHeliportLocation (IndustryID industry_id)
 Gets the location of the industry's heliport. More...
 
static bool HasDock (IndustryID industry_id)
 Does this industry have a dock? More...
 
static TileIndex GetDockLocation (IndustryID industry_id)
 Gets the location of the industry's dock. More...
 
static IndustryType GetIndustryType (IndustryID industry_id)
 Get the IndustryType of the industry. More...
 
static SQInteger GetLastProductionYear (IndustryID industry_id)
 Get the last year this industry had any production output. More...
 
static GSDate::Date GetCargoLastAcceptedDate (IndustryID industry_id, CargoID cargo_type)
 Get the last date this industry accepted any cargo delivery. More...
 
static SQInteger GetControlFlags (IndustryID industry_id)
 Get the current control flags for an industry. More...
 
static bool SetControlFlags (IndustryID industry_id, SQInteger control_flags)
 Change the control flags for an industry. More...
 
static GSCompany::CompanyID GetExclusiveSupplier (IndustryID industry_id)
 Find out which company currently has the exclusive rights to deliver cargo to the industry. More...
 
static bool SetExclusiveSupplier (IndustryID industry_id, GSCompany::CompanyID company_id)
 Sets or resets the company that has exclusive right to deliver cargo to the industry. More...
 
static GSCompany::CompanyID GetExclusiveConsumer (IndustryID industry_id)
 Find out which company currently has the exclusive rights to take cargo from the industry. More...
 
static bool SetExclusiveConsumer (IndustryID industry_id, GSCompany::CompanyID company_id)
 Sets or resets the company that has exclusive right to take cargo from the industry. More...
 
static SQInteger GetProductionLevel (IndustryID industry_id)
 Gets the current production level of an industry. More...
 
static bool SetProductionLevel (IndustryID industry_id, SQInteger prod_level, bool show_news, Text *custom_news)
 Sets the current production level of an industry. More...
 

Detailed Description

Class that handles all industry related functions.

Member Enumeration Documentation

◆ CargoAcceptState

Ways for an industry to accept a cargo.

Enumerator
CAS_NOT_ACCEPTED 

The CargoID is not accepted by this industry.

CAS_ACCEPTED 

The industry currently accepts this CargoID.

CAS_TEMP_REFUSED 

The industry temporarily refuses to accept this CargoID but may do so again in the future.

◆ IndustryControlFlags

Control flags for industry.

Enumerator
INDCTL_NO_PRODUCTION_DECREASE 

When industry production change is evaluated, rolls to decrease are ignored.

This also prevents industry closure due to production dropping to the lowest level.

INDCTL_NO_PRODUCTION_INCREASE 

When industry production change is evaluated, rolls to increase are ignored.

INDCTL_NO_CLOSURE 

Industry can not close regardless of production level or time since last delivery.

This does not prevent a closure already announced.

INDCTL_EXTERNAL_PROD_LEVEL 

Indicates that the production level of the industry is controlled by a game script.

Member Function Documentation

◆ GetAmountOfStationsAround()

static SQInteger GSIndustry::GetAmountOfStationsAround ( IndustryID  industry_id)
static

Get the number of stations around an industry.

All stations that can service the industry are counted, your own stations but also your opponents stations.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
The number of stations around an industry.

◆ GetCargoLastAcceptedDate()

static GSDate::Date GSIndustry::GetCargoLastAcceptedDate ( IndustryID  industry_id,
CargoID  cargo_type 
)
static

Get the last date this industry accepted any cargo delivery.

Parameters
industry_idThe index of the industry.
cargo_typeThe cargo to query, or INVALID_CARGO to query latest of all accepted cargoes.
Precondition
IsValidIndustry(industry_id).
IsValidCargo(cargo_type) || cargo_type == INVALID_CARGO.
Returns
Date the industry last received cargo from a delivery, or GSDate::DATE_INVALID on error.

◆ GetConstructionDate()

static GSDate::Date GSIndustry::GetConstructionDate ( IndustryID  industry_id)
static

Get the construction date of an industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
Date the industry was constructed.

◆ GetControlFlags()

static SQInteger GSIndustry::GetControlFlags ( IndustryID  industry_id)
static

Get the current control flags for an industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
Bit flags of the IndustryControlFlags enumeration.

◆ GetDistanceManhattanToTile()

static SQInteger GSIndustry::GetDistanceManhattanToTile ( IndustryID  industry_id,
TileIndex  tile 
)
static

Get the manhattan distance from the tile to the GSIndustry::GetLocation() of the industry.

Parameters
industry_idThe industry to get the distance to.
tileThe tile to get the distance to.
Precondition
IsValidIndustry(industry_id).
GSMap::IsValidTile(tile).
Returns
The distance between industry and tile.

◆ GetDistanceSquareToTile()

static SQInteger GSIndustry::GetDistanceSquareToTile ( IndustryID  industry_id,
TileIndex  tile 
)
static

Get the square distance from the tile to the GSIndustry::GetLocation() of the industry.

Parameters
industry_idThe industry to get the distance to.
tileThe tile to get the distance to.
Precondition
IsValidIndustry(industry_id).
GSMap::IsValidTile(tile).
Returns
The distance between industry and tile.

◆ GetDockLocation()

static TileIndex GSIndustry::GetDockLocation ( IndustryID  industry_id)
static

Gets the location of the industry's dock.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
HasDock(industry_id).
Returns
The location of the industry's dock.

◆ GetExclusiveConsumer()

static GSCompany::CompanyID GSIndustry::GetExclusiveConsumer ( IndustryID  industry_id)
static

Find out which company currently has the exclusive rights to take cargo from the industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
The company that has the exclusive rights. The value GSCompany::COMPANY_SPECTATOR means that there are currently no exclusive rights given out to anyone.

◆ GetExclusiveSupplier()

static GSCompany::CompanyID GSIndustry::GetExclusiveSupplier ( IndustryID  industry_id)
static

Find out which company currently has the exclusive rights to deliver cargo to the industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
The company that has the exclusive rights. The value GSCompany::COMPANY_INVALID means that there are currently no exclusive rights given out to anyone.

◆ GetHeliportLocation()

static TileIndex GSIndustry::GetHeliportLocation ( IndustryID  industry_id)
static

Gets the location of the industry's heliport.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
HasHeliport(industry_id).
Returns
The location of the industry's heliport.

◆ GetIndustryCount()

static SQInteger GSIndustry::GetIndustryCount ( )
static

Gets the number of industries.

Returns
The number of industries.
Note
The maximum valid IndustryID can be higher than the value returned.

◆ GetIndustryID()

static IndustryID GSIndustry::GetIndustryID ( TileIndex  tile)
static

Get the IndustryID of a tile, if there is an industry.

Parameters
tileThe tile to find the IndustryID of.
Returns
IndustryID of the industry.
Postcondition
Use IsValidIndustry() to see if the industry is valid.
Note
GetIndustryID will return an invalid IndustryID for the station tile of industries with a dock/heliport.

◆ GetIndustryType()

static IndustryType GSIndustry::GetIndustryType ( IndustryID  industry_id)
static

Get the IndustryType of the industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
The IndustryType of the industry.

◆ GetLastMonthProduction()

static SQInteger GSIndustry::GetLastMonthProduction ( IndustryID  industry_id,
CargoID  cargo_id 
)
static

Get the total last month's production of the given cargo at an industry.

Parameters
industry_idThe index of the industry.
cargo_idThe index of the cargo.
Precondition
IsValidIndustry(industry_id).
GSCargo::IsValidCargo(cargo_id).
Returns
The last month's production of the given cargo for this industry.

◆ GetLastMonthTransported()

static SQInteger GSIndustry::GetLastMonthTransported ( IndustryID  industry_id,
CargoID  cargo_id 
)
static

Get the total amount of cargo transported from an industry last month.

Parameters
industry_idThe index of the industry.
cargo_idThe index of the cargo.
Precondition
IsValidIndustry(industry_id).
GSCargo::IsValidCargo(cargo_id).
Returns
The amount of given cargo transported from this industry last month.

◆ GetLastMonthTransportedPercentage()

static SQInteger GSIndustry::GetLastMonthTransportedPercentage ( IndustryID  industry_id,
CargoID  cargo_id 
)
static

Get the percentage of cargo transported from an industry last month.

Parameters
industry_idThe index of the industry.
cargo_idThe index of the cargo.
Precondition
IsValidIndustry(industry_id).
GSCargo::IsValidCargo(cargo_id).
Returns
The percentage of given cargo transported from this industry last month.

◆ GetLastProductionYear()

static SQInteger GSIndustry::GetLastProductionYear ( IndustryID  industry_id)
static

Get the last year this industry had any production output.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
Year the industry last had production, 0 if error.

◆ GetLocation()

static TileIndex GSIndustry::GetLocation ( IndustryID  industry_id)
static

Gets the location of the industry.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
The location of the industry.

◆ GetName()

static std::optional<std::string> GSIndustry::GetName ( IndustryID  industry_id)
static

Get the name of the industry.

Parameters
industry_idThe industry to get the name of.
Precondition
IsValidIndustry(industry_id).
Returns
The name of the industry.

◆ GetProductionLevel()

static SQInteger GSIndustry::GetProductionLevel ( IndustryID  industry_id)
static

Gets the current production level of an industry.

Parameters
industry_idThe index of the industry.
Returns
The current production level of the industry.

◆ GetStockpiledCargo()

static SQInteger GSIndustry::GetStockpiledCargo ( IndustryID  industry_id,
CargoID  cargo_id 
)
static

Get the amount of cargo stockpiled for processing.

Parameters
industry_idThe index of the industry.
cargo_idThe index of the cargo.
Precondition
IsValidIndustry(industry_id).
GSCargo::IsValidCargo(cargo_id).
Returns
The amount of cargo that is waiting for processing.

◆ HasDock()

static bool GSIndustry::HasDock ( IndustryID  industry_id)
static

Does this industry have a dock?

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
True when the industry has a dock.

◆ HasHeliport()

static bool GSIndustry::HasHeliport ( IndustryID  industry_id)
static

Does this industry have a heliport?

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
True when the industry has a heliport.

◆ IsBuiltOnWater()

static bool GSIndustry::IsBuiltOnWater ( IndustryID  industry_id)
static

Is this industry built on water.

Parameters
industry_idThe index of the industry.
Precondition
IsValidIndustry(industry_id).
Returns
True when the industry is built on water.

◆ IsCargoAccepted()

static CargoAcceptState GSIndustry::IsCargoAccepted ( IndustryID  industry_id,
CargoID  cargo_id 
)
static

See whether an industry currently accepts a certain cargo.

Parameters
industry_idThe index of the industry.
cargo_idThe index of the cargo.
Precondition
IsValidIndustry(industry_id).
GSCargo::IsValidCargo(cargo_id).
Returns
Whether the industry accepts, temporarily refuses or never accepts this cargo.

◆ IsValidIndustry()

static bool GSIndustry::IsValidIndustry ( IndustryID  industry_id)
static

Checks whether the given industry index is valid.

Parameters
industry_idThe index to check.
Returns
True if and only if the industry is valid.

◆ SetControlFlags()

static bool GSIndustry::SetControlFlags ( IndustryID  industry_id,
SQInteger  control_flags 
)
static

Change the control flags for an industry.

Parameters
industry_idThe index of the industry.
control_flagsNew flags as a combination of IndustryControlFlags values.
Precondition
IsValidIndustry(industry_id).
GSCompanyMode::IsDeity().
Returns
True if the action succeeded.

◆ SetExclusiveConsumer()

static bool GSIndustry::SetExclusiveConsumer ( IndustryID  industry_id,
GSCompany::CompanyID  company_id 
)
static

Sets or resets the company that has exclusive right to take cargo from the industry.

Parameters
industry_idThe index of the industry.
company_idThe company to set (GSCompany::COMPANY_INVALID to reset).
Precondition
IsValidIndustry(industry_id).
GSCompanyMode::IsDeity().
Returns
True if the action succeeded.

◆ SetExclusiveSupplier()

static bool GSIndustry::SetExclusiveSupplier ( IndustryID  industry_id,
GSCompany::CompanyID  company_id 
)
static

Sets or resets the company that has exclusive right to deliver cargo to the industry.

Parameters
industry_idThe index of the industry.
company_idThe company to set (GSCompany::COMPANY_INVALID to reset).
Precondition
IsValidIndustry(industry_id).
GSCompanyMode::IsDeity().
Returns
True if the action succeeded.

◆ SetProductionLevel()

static bool GSIndustry::SetProductionLevel ( IndustryID  industry_id,
SQInteger  prod_level,
bool  show_news,
Text *  custom_news 
)
static

Sets the current production level of an industry.

Note
Setting the production level automatically sets the control flag INDCTL_EXTERNAL_PROD_LEVEL if it wasn't already set. Normal production behaviour can be restored by clearing the control flag.
Parameters
industry_idThe index of the industry.
prod_levelThe production level to set.
show_newsIf set to true and the production changed, generate a production change news message. If set to false, no news message is shown.
custom_newsCustom news message text to override the default news text with. Pass null to use the default text. Only used if show_news is set to true.
Precondition
IsValidIndustry(industry_id).
GSCompanyMode::IsDeity().
prod_level >= 4 && prod_level <= 128.
Returns
True if the action succeeded.

◆ SetText()

static bool GSIndustry::SetText ( IndustryID  industry_id,
Text *  text 
)
static

Set the custom text of an industry, shown in the GUI.

Parameters
industry_idThe industry to set the custom text of.
textThe text to set it to (can be either a raw string, or a GSText object). If null, or an empty string, is passed, the text will be removed.
Precondition
GSCompanyMode::IsDeity().
IsValidIndustry(industry_id).
Returns
True if the action succeeded.