# AIIndustry Class Reference

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

`#include <ai_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 const char * | GetClassName ()
| Get the name of this class to identify it towards squirrel.
static int32 | 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 char * | GetName (IndustryID industry_id)
| Get the name of the industry.
static CargoAcceptState | IsCargoAccepted (IndustryID industry_id, CargoID cargo_id)
| See whether an industry currently accepts a certain cargo.
static int32 | GetStockpiledCargo (IndustryID industry_id, CargoID cargo_id)
| Get the amount of cargo stockpiled for processing.
static int32 | GetLastMonthProduction (IndustryID industry_id, CargoID cargo_id)
| Get the total last month's production of the given cargo at an industry.
static int32 | GetLastMonthTransported (IndustryID industry_id, CargoID cargo_id)
| Get the total amount of cargo transported from an industry last month.
static int32 | GetLastMonthTransportedPercentage (IndustryID industry_id, CargoID cargo_id)
| Get the percentage of cargo transported from an industry last month.
static TileIndex | GetLocation (IndustryID industry_id)
| Gets the location of the industry.
static int32 | GetAmountOfStationsAround (IndustryID industry_id)
| Get the number of stations around an industry.
static int32 | GetDistanceManhattanToTile (IndustryID industry_id, TileIndex tile)
| Get the manhattan distance from the tile to the AIIndustry::GetLocation() of the industry.
static int32 | 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.

## Detailed Description

Class that handles all industry related functions.

Definition at line 20 of file ai_industry.hpp.

## Member Enumeration Documentation

enum AIIndustry::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.

Definition at line 26 of file ai_industry.hpp.

## Member Function Documentation

int32 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.

Definition at line 132 of file ai_industry.cpp.

References FindStationsAroundTiles(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), IsValidIndustry(), and Industry::location.

static const char* AIIndustry::GetClassName | ( |  | ) | `[inline, static]`

Get the name of this class to identify it towards squirrel.

Definition at line 23 of file ai_industry.hpp.

int32 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.

Definition at line 142 of file ai_industry.cpp.

References DistanceManhattan(), GetLocation(), and IsValidIndustry().

int32 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.

Definition at line 149 of file ai_industry.cpp.

References DistanceSquare(), GetLocation(), and IsValidIndustry().

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.

Definition at line 192 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), HasDock(), INVALID_TILE, IsOilRig(), IsTileType(), IsValidIndustry(), Industry::location, MP_STATION, and TILE_AREA_LOOP.

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.

Definition at line 170 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), HasHeliport(), INVALID_TILE, IsOilRig(), IsTileType(), IsValidIndustry(), Industry::location, MP_STATION, and TILE_AREA_LOOP.

int32 AIIndustry::GetIndustryCount | ( |  | ) | `[static]`

Gets the number of industries.

Returns:
  The number of industries.

Postcondition:
  Return value is always non-negative.

Note:
  The maximum valid IndustryID can be higher than the value returned.

Definition at line 22 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::GetNumItems().

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.

Definition at line 32 of file ai_industry.cpp.

References GetIndustryIndex(), IsTileType(), IsValidTile(), and MP_INDUSTRY.

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.

Definition at line 207 of file ai_industry.cpp.

References INVALID_INDUSTRYTYPE, and IsValidIndustry().

int32 AIIndustry::GetLastMonthProduction | ( | IndustryID | industry_id,
|  | CargoID | cargo_id |
| ) |  |  | `[static]`

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

Parameters:

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

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

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

Definition at line 83 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), AICargo::IsValidCargo(), IsValidIndustry(), Industry::last_month_production, lengthof, and Industry::produced_cargo.

int32 AIIndustry::GetLastMonthTransported | ( | IndustryID | industry_id,
|  | CargoID | cargo_id |
| ) |  |  | `[static]`

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

Parameters:

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

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

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

Definition at line 97 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), AICargo::IsValidCargo(), IsValidIndustry(), Industry::last_month_transported, lengthof, and Industry::produced_cargo.

int32 AIIndustry::GetLastMonthTransportedPercentage | ( | IndustryID | industry_id,
|  | CargoID | cargo_id |
| ) |  |  | `[static]`

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

Parameters:

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

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

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

Definition at line 111 of file ai_industry.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), AICargo::IsValidCargo(), IsValidIndustry(), Industry::last_month_pct_transported, lengthof, Industry::produced_cargo, and ToPercent8().

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.

Definition at line 125 of file ai_industry.cpp.

References INVALID_TILE, and IsValidIndustry().

Referenced by GetDistanceManhattanToTile(), and GetDistanceSquareToTile().

char * 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.

Definition at line 38 of file ai_industry.cpp.

References IsValidIndustry(), and SetDParam().

int32 AIIndustry::GetStockpiledCargo | ( | IndustryID | industry_id,
|  | CargoID | cargo_id |
| ) |  |  | `[static]`

Get the amount of cargo stockpiled for processing.

Parameters:

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

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

Returns:
  The amount of cargo that is waiting for processing.

Definition at line 67 of file ai_industry.cpp.

References Industry::accepts_cargo, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Industry::incoming_cargo_waiting, AICargo::IsValidCargo(), IsValidIndustry(), and lengthof.

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.

Definition at line 185 of file ai_industry.cpp.

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

Referenced by GetDockLocation().

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.

Definition at line 163 of file ai_industry.cpp.

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

Referenced by GetHeliportLocation().

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.

Definition at line 156 of file ai_industry.cpp.

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

AIIndustry::CargoAcceptState AIIndustry::IsCargoAccepted | ( | IndustryID | industry_id,
|  | CargoID | cargo_id |
| ) |  |  | `[static]`

See whether an industry currently accepts a certain cargo.

Parameters:

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

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

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

Definition at line 50 of file ai_industry.cpp.

References Industry::accepts_cargo, CAS_ACCEPTED, CAS_NOT_ACCEPTED, CAS_TEMP_REFUSED, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), IndustryTemporarilyRefusesCargo(), AICargo::IsValidCargo(), IsValidIndustry(), and lengthof.

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.

Definition at line 27 of file ai_industry.cpp.

Referenced by AICargoList_IndustryAccepting::AICargoList_IndustryAccepting(), AICargoList_IndustryProducing::AICargoList_IndustryProducing(), AITileList_IndustryAccepting::AITileList_IndustryAccepting(), AITileList_IndustryProducing::AITileList_IndustryProducing(), GetAmountOfStationsAround(), GetDistanceManhattanToTile(), GetDistanceSquareToTile(), GetDockLocation(), GetHeliportLocation(), GetIndustryType(), GetLastMonthProduction(), GetLastMonthTransported(), GetLastMonthTransportedPercentage(), GetLocation(), GetName(), GetStockpiledCargo(), HasDock(), HasHeliport(), IsBuiltOnWater(), and IsCargoAccepted().

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

- src/ai/api/ai_industry.hpp
- src/ai/api/ai_industry.cpp