OpenTTD AI API: AIIndustry Class Reference

OpenTTD AI API 15.0-beta2

Public Types | Static Public Member Functions
AIIndustry Class Reference

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

`#include <script_industry.hpp>`

Inheritance diagram for AIIndustry:

## Public Types
enum | CargoAcceptState { CAS_NOT_ACCEPTED , CAS_ACCEPTED , CAS_TEMP_REFUSED }
| Ways for an industry to accept a cargo. More...

## Static Public Member Functions
static int | GetIndustryCount ()
| Gets the number of industries.
static bool | IsValidIndustry (IndustryID industry_id)
| Checks whether the given industry index is valid.
static IndustryID | GetIndustryID (TileIndex tile)
| Get the IndustryID of a tile, if there is an industry.
static string | GetName (IndustryID industry_id)
| Get the name of the industry.
static CargoAcceptState | IsCargoAccepted (IndustryID industry_id, CargoType cargo_type)
| See whether an industry currently accepts a certain cargo.
static int | GetStockpiledCargo (IndustryID industry_id, CargoType cargo_type)
| Get the amount of cargo stockpiled for processing.
static int | GetLastMonthProduction (IndustryID industry_id, CargoType cargo_type)
| Get the total last economy-month's production of the given cargo at an industry.
static int | GetLastMonthTransported (IndustryID industry_id, CargoType cargo_type)
| Get the total amount of cargo transported from an industry last economy-month.
static int | GetLastMonthTransportedPercentage (IndustryID industry_id, CargoType cargo_type)
| Get the percentage of cargo transported from an industry last economy-month.
static TileIndex | GetLocation (IndustryID industry_id)
| Gets the location of the industry.
static int | GetAmountOfStationsAround (IndustryID industry_id)
| Get the number of stations around an industry.
static int | GetDistanceManhattanToTile (IndustryID industry_id, TileIndex tile)
| Get the manhattan distance from the tile to the AIIndustry::GetLocation() of the industry.
static int | GetDistanceSquareToTile (IndustryID industry_id, TileIndex tile)
| Get the square distance from the tile to the AIIndustry::GetLocation() of the industry.
static bool | IsBuiltOnWater (IndustryID industry_id)
| Is this industry built on water.
static bool | HasHeliport (IndustryID industry_id)
| Does this industry have a heliport?
static TileIndex | GetHeliportLocation (IndustryID industry_id)
| Gets the location of the industry's heliport.
static bool | HasDock (IndustryID industry_id)
| Does this industry have a dock?
static TileIndex | GetDockLocation (IndustryID industry_id)
| Gets the location of the industry's dock.
static IndustryType | GetIndustryType (IndustryID industry_id)
| Get the IndustryType of the industry.
static AICompany::CompanyID | GetExclusiveSupplier (IndustryID industry_id)
| Find out which company currently has the exclusive rights to deliver cargo to the industry.
static AICompany::CompanyID | GetExclusiveConsumer (IndustryID industry_id)
| Find out which company currently has the exclusive rights to take cargo from the industry.

## Detailed Description

Class that handles all industry related functions.

## Member Enumeration Documentation

## ◆ CargoAcceptState

enum AIIndustry::CargoAcceptState

Ways for an industry to accept a cargo.

Enumerator
CAS_NOT_ACCEPTED | The CargoType is not accepted by this industry.
CAS_ACCEPTED | The industry currently accepts this CargoType.
CAS_TEMP_REFUSED | The industry temporarily refuses to accept this CargoType but may do so again in the future.

## Member Function Documentation

## ◆ GetAmountOfStationsAround()

static int AIIndustry::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_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  The number of stations around an industry.

## ◆ GetDistanceManhattanToTile()

static int AIIndustry::GetDistanceManhattanToTile | ( | IndustryID | industry_id,
|  | TileIndex | tile
| ) |  |
| static

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

Parameters

  industry_id | The industry to get the distance to.
  tile | The tile to get the distance to.

Precondition
  IsValidIndustry(industry_id).
  AIMap::IsValidTile(tile).

Returns
  The distance between industry and tile.

## ◆ GetDistanceSquareToTile()

static int AIIndustry::GetDistanceSquareToTile | ( | IndustryID | industry_id,
|  | TileIndex | tile
| ) |  |
| static

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

Parameters

  industry_id | The industry to get the distance to.
  tile | The tile to get the distance to.

Precondition
  IsValidIndustry(industry_id).
  AIMap::IsValidTile(tile).

Returns
  The distance between industry and tile.

## ◆ GetDockLocation()

static TileIndex AIIndustry::GetDockLocation | ( | IndustryID | industry_id | ) |
| static

Gets the location of the industry's dock.

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).
  HasDock(industry_id).

Returns
  The location of the industry's dock.

## ◆ GetExclusiveConsumer()

static AICompany::CompanyID AIIndustry::GetExclusiveConsumer | ( | IndustryID | industry_id | ) |
| static

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

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  The company that has the exclusive rights. The value AICompany::COMPANY_SPECTATOR means that there are currently no exclusive rights given out to anyone.

## ◆ GetExclusiveSupplier()

static AICompany::CompanyID AIIndustry::GetExclusiveSupplier | ( | IndustryID | industry_id | ) |
| static

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

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  The company that has the exclusive rights. The value AICompany::COMPANY_INVALID means that there are currently no exclusive rights given out to anyone.

## ◆ GetHeliportLocation()

static TileIndex AIIndustry::GetHeliportLocation | ( | IndustryID | industry_id | ) |
| static

Gets the location of the industry's heliport.

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).
  HasHeliport(industry_id).

Returns
  The location of the industry's heliport.

## ◆ GetIndustryCount()

static int AIIndustry::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 AIIndustry::GetIndustryID | ( | TileIndex | tile | ) |
| static

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

Parameters

  tile | The 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 AIIndustry::GetIndustryType | ( | IndustryID | industry_id | ) |
| static

Get the IndustryType of the industry.

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  The IndustryType of the industry.

## ◆ GetLastMonthProduction()

static int AIIndustry::GetLastMonthProduction | ( | IndustryID | industry_id,
|  | CargoType | cargo_type
| ) |  |
| static

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

Parameters

  industry_id | The index of the industry.
  cargo_type | The index of the cargo.

Precondition
  IsValidIndustry(industry_id).
  AICargo::IsValidCargo(cargo_type).

Returns
  The last economy-month's production of the given cargo for this industry.

See also
  AIEconomyTime

## ◆ GetLastMonthTransported()

static int AIIndustry::GetLastMonthTransported | ( | IndustryID | industry_id,
|  | CargoType | cargo_type
| ) |  |
| static

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

Parameters

  industry_id | The index of the industry.
  cargo_type | The index of the cargo.

Precondition
  IsValidIndustry(industry_id).
  AICargo::IsValidCargo(cargo_type).

Returns
  The amount of given cargo transported from this industry last economy-month.

See also
  AIEconomyTime

## ◆ GetLastMonthTransportedPercentage()

static int AIIndustry::GetLastMonthTransportedPercentage | ( | IndustryID | industry_id,
|  | CargoType | cargo_type
| ) |  |
| static

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

Parameters

  industry_id | The index of the industry.
  cargo_type | The index of the cargo.

Precondition
  IsValidIndustry(industry_id).
  AICargo::IsValidCargo(cargo_type).

Returns
  The percentage of given cargo transported from this industry last economy-month.

See also
  AIEconomyTime

## ◆ GetLocation()

static TileIndex AIIndustry::GetLocation | ( | IndustryID | industry_id | ) |
| static

Gets the location of the industry.

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  The location of the industry.

## ◆ GetName()

static string AIIndustry::GetName | ( | IndustryID | industry_id | ) |
| static

Get the name of the industry.

Parameters

  industry_id | The industry to get the name of.

Precondition
  IsValidIndustry(industry_id).

Returns
  The name of the industry.

## ◆ GetStockpiledCargo()

static int AIIndustry::GetStockpiledCargo | ( | IndustryID | industry_id,
|  | CargoType | cargo_type
| ) |  |
| static

Get the amount of cargo stockpiled for processing.

Parameters

  industry_id | The index of the industry.
  cargo_type | The index of the cargo.

Precondition
  IsValidIndustry(industry_id).
  AICargo::IsValidCargo(cargo_type).

Returns
  The amount of cargo that is waiting for processing.

## ◆ HasDock()

static bool AIIndustry::HasDock | ( | IndustryID | industry_id | ) |
| static

Does this industry have a dock?

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  True when the industry has a dock.

## ◆ HasHeliport()

static bool AIIndustry::HasHeliport | ( | IndustryID | industry_id | ) |
| static

Does this industry have a heliport?

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  True when the industry has a heliport.

## ◆ IsBuiltOnWater()

static bool AIIndustry::IsBuiltOnWater | ( | IndustryID | industry_id | ) |
| static

Is this industry built on water.

Parameters

  industry_id | The index of the industry.

Precondition
  IsValidIndustry(industry_id).

Returns
  True when the industry is built on water.

## ◆ IsCargoAccepted()

static CargoAcceptState AIIndustry::IsCargoAccepted | ( | IndustryID | industry_id,
|  | CargoType | cargo_type
| ) |  |
| static

See whether an industry currently accepts a certain cargo.

Parameters

  industry_id | The index of the industry.
  cargo_type | The index of the cargo.

Precondition
  IsValidIndustry(industry_id).
  AICargo::IsValidCargo(cargo_type).

Returns
  Whether the industry accepts, temporarily refuses or never accepts this cargo.

## ◆ IsValidIndustry()

static bool AIIndustry::IsValidIndustry | ( | IndustryID | industry_id | ) |
| static

Checks whether the given industry index is valid.

Parameters

  industry_id | The index to check.

Returns
  True if and only if the industry is valid.