OpenTTD Source: src/newgrf_industries.h File Reference

OpenTTD Source 15.0-RC2

Data Structures | Enumerations | Functions
newgrf_industries.h File Reference

Functions for NewGRF industries. More...

`#include "newgrf_town.h"`

Go to the source code of this file.

## Data Structures
struct | IndustriesScopeResolver
| Resolver for industry scopes. More...
struct | IndustriesResolverObject
| Resolver for industries. More...

## Enumerations
enum | IndustryTrigger : uint8_t { INDUSTRY_TRIGGER_TILELOOP_PROCESS = 1 , INDUSTRY_TRIGGER_256_TICKS = 2 , INDUSTRY_TRIGGER_CARGO_DELIVERY = 4 }
| When should the industry(tile) be triggered for random bits? More...
enum | IndustryAvailabilityCallType : uint8_t { IACT_MAPGENERATION , IACT_RANDOMCREATION , IACT_USERCREATION , IACT_PROSPECTCREATION }
| From where has callback CBID_INDUSTRY_PROBABILITY been called. More...

## Functions
uint16_t | GetIndustryCallback (CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile, std::span< int32_t > regs100={})
| Perform an industry callback.
uint32_t | GetIndustryIDAtOffset (TileIndex new_tile, const Industry *i, uint32_t cur_grfid)
| Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.
void | IndustryProductionCallback (Industry *ind, int reason)
| Get the industry production callback and apply it to the industry.
CommandCost | CheckIfCallBackAllowsCreation (TileIndex tile, IndustryType type, size_t layout, uint32_t seed, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
| Check that the industry callback allows creation of the industry.
uint32_t | GetIndustryProbabilityCallback (IndustryType type, IndustryAvailabilityCallType creation_type, uint32_t default_prob)
| Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
bool | IndustryTemporarilyRefusesCargo (Industry *ind, CargoType cargo_type)
| Check whether an industry temporarily refuses to accept a certain cargo.
IndustryType | MapNewGRFIndustryType (IndustryType grf_type, uint32_t grf_id)
| Map the GRF local type to an industry type.
uint32_t | GetNearbyIndustryTileInformation (uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
| Based on newhouses equivalent, but adapted for newindustries.

## Detailed Description

Functions for NewGRF industries.

Definition in file newgrf_industries.h.

## Enumeration Type Documentation

## ◆ IndustryAvailabilityCallType

enum IndustryAvailabilityCallType : uint8_t

From where has callback CBID_INDUSTRY_PROBABILITY been called.

Enumerator
IACT_MAPGENERATION | during random map generation
IACT_RANDOMCREATION | during creation of random ingame industry
IACT_USERCREATION | from the Fund/build window
IACT_PROSPECTCREATION | from the Fund/build using prospecting

Definition at line 81 of file newgrf_industries.h.

## ◆ IndustryTrigger

enum IndustryTrigger : uint8_t

When should the industry(tile) be triggered for random bits?

Enumerator
INDUSTRY_TRIGGER_TILELOOP_PROCESS | Triggered each tile loop.
INDUSTRY_TRIGGER_256_TICKS | Triggered (whole industry) each 256 ticks.
INDUSTRY_TRIGGER_CARGO_DELIVERY | Triggered on cargo delivery.

Definition at line 71 of file newgrf_industries.h.

## Function Documentation

## ◆ CheckIfCallBackAllowsCreation()

CommandCost CheckIfCallBackAllowsCreation | ( | TileIndex | tile,
|  | IndustryType | type,
|  | size_t | layout,
|  | uint32_t | seed,
|  | uint16_t | initial_random_bits,
|  | Owner | founder,
|  | IndustryAvailabilityCallType | creation_type
| ) |  |

Check that the industry callback allows creation of the industry.

Parameters

  tile | Tile to build the industry.
  type | Type of industry to build.
  layout | Layout number.
  seed | Seed for the random generator.
  initial_random_bits | The random bits the industry is going to have after construction.
  founder | Industry founder
  creation_type | The circumstances the industry is created under.

Returns
  Succeeded or failed command.

Definition at line 545 of file newgrf_industries.cpp.

References CALLBACK_FAILED, CBID_INDUSTRY_LOCATION, ClosestTownFromTile(), Industry::founder, GetErrorMessageFromLocationCallbackResult(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase::grffile, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, Industry::location, Industry::psa, Industry::random, Industry::selected_layout, OrthogonalTileArea::tile, Industry::town, Industry::type, and OrthogonalTileArea::w.

Referenced by CreateNewIndustryHelper().

## ◆ GetIndustryCallback()

uint16_t GetIndustryCallback | ( | CallbackID | callback,
|  | uint32_t | param1,
|  | uint32_t | param2,
|  | Industry * | industry,
|  | IndustryType | type,
|  | TileIndex | tile,
|  | std::span< int32_t > | regs100
| ) |  |

Perform an industry callback.

Parameters

  | callback | The callback to perform.
  | param1 | The first parameter.
  | param2 | The second parameter.
  | industry | The industry to do the callback for.
  | type | The type of industry to do the callback for.
  | tile | The tile associated with the callback.
  [out] | regs100 | Additional result values from registers 100+

Returns
  The callback result.

Definition at line 528 of file newgrf_industries.cpp.

Referenced by ChangeIndustryProduction(), DoCreateNewIndustry(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), GetCargoSuffix(), GetIndustryProbabilityCallback(), and IndustryTemporarilyRefusesCargo().

## ◆ GetIndustryIDAtOffset()

uint32_t GetIndustryIDAtOffset | ( | TileIndex | tile,
|  | const Industry * | i,
|  | uint32_t | cur_grfid
| ) |  |

Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.

Parameters

  tile | TileIndex of the tile to query
  i | Industry to which to compare the tile to
  cur_grfid | GRFID of the current callback chain

Returns
  value encoded as per NFO specs

Definition at line 57 of file newgrf_industries.cpp.

References GetCleanIndustryGfx(), GetIndustryTileSpec(), IndustryTileSpec::grf_prop, GRFFilePropsBase::grfid, StandardGRFFileProps::HasSpriteGroups(), INVALID_INDUSTRYTILE, GRFFilePropsBase::local_id, NEW_INDUSTRYTILEOFFSET, SubstituteGRFFileProps::override_id, and Industry::TileBelongsToIndustry().

Referenced by IndustriesScopeResolver::GetVariable(), and IndustryTileScopeResolver::GetVariable().

## ◆ GetIndustryProbabilityCallback()

uint32_t GetIndustryProbabilityCallback | ( | IndustryType | type,
|  | IndustryAvailabilityCallType | creation_type,
|  | uint32_t | default_prob
| ) |  |

Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.

Parameters

  type | Industry type to check.
  creation_type | Reason to construct a new industry.

Returns
  If the industry has no callback or allows building, `true` is returned. Otherwise, `false` is returned.

Definition at line 577 of file newgrf_industries.cpp.

References CALLBACK_FAILED, IndustrySpec::callback_mask, CBID_INDUSTRY_PROBABILITY, ErrorUnknownCallbackResult(), GetIndustryCallback(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase::grffile, GRFFilePropsBase::grfid, INVALID_TILE, Probability, and BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test().

Referenced by CmdBuildIndustry(), GetIndustryGamePlayProbability(), and GetScaledIndustryGenerationProbability().

## ◆ GetNearbyIndustryTileInformation()

uint32_t GetNearbyIndustryTileInformation | ( | uint8_t | parameter,
|  | TileIndex | tile,
|  | IndustryID | index,
|  | bool | signed_offsets,
|  | bool | grf_version8
| ) |  |

Based on newhouses equivalent, but adapted for newindustries.

Parameters

  parameter | from callback. It's in fact a pair of coordinates
  tile | TileIndex from which the callback was initiated
  index | of the industry been queried for
  signed_offsets | Are the x and y offset encoded in parameter signed?
  grf_version8 | True, if we are dealing with a new NewGRF which uses GRF version >= 8.

Returns
  a construction of bits obeying the newgrf format

Definition at line 35 of file newgrf_industrytiles.cpp.

References GetIndustryIndex(), GetNearbyTile(), GetNearbyTileInformation(), IsTileType(), and MP_INDUSTRY.

Referenced by IndustriesScopeResolver::GetVariable(), and IndustryTileScopeResolver::GetVariable().

## ◆ IndustryProductionCallback()

void IndustryProductionCallback | ( | Industry * | ind,
|  | int | reason
| ) |  |

Get the industry production callback and apply it to the industry.

Parameters

  ind | the industry this callback has to be called for
  reason | the reason it is called (0 = incoming cargo, 1 = periodic tick callback)

Definition at line 605 of file newgrf_industries.cpp.

References Industry::accepted, IndustrySpec::behaviour, Industry::GetCargoAccepted(), Industry::GetCargoProduced(), GetEncodedString(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase::grffile, Pool< Titem, Tindex, Tgrowth_step, Tpool_type, Tcache >::PoolItem< Tpool >::index, IsValidCargoType(), Industry::location, IndustrySpec::name, Industry::prod_level, ProdCallbackRandom, ProdMultiHandling, Industry::produced, Random, SB(), SetWindowDirty(), ShowErrorMessage(), BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, Industry::type, WC_INDUSTRY_VIEW, and WL_WARNING.

Referenced by DoCreateNewIndustry(), and TriggerIndustryProduction().

## ◆ IndustryTemporarilyRefusesCargo()

bool IndustryTemporarilyRefusesCargo | ( | Industry * | ind,
|  | CargoType | cargo_type
| ) |  |

Check whether an industry temporarily refuses to accept a certain cargo.

Parameters

  ind | The industry to query.
  cargo_type | The cargo to get information about.

Precondition
  cargo_type is in ind->accepts_cargo.

Returns
  Whether the given industry refuses to accept this cargo type.

Definition at line 687 of file newgrf_industries.cpp.

References CALLBACK_FAILED, IndustrySpec::callback_mask, GRFFile::cargo_map, CBID_INDUSTRY_REFUSE_CARGO, ConvertBooleanCallback(), GetIndustryCallback(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase::grffile, Industry::IsCargoAccepted(), Industry::location, RefuseCargo, BaseBitSet< Timpl, Tvalue_type, Tstorage, Tmask >::Test(), OrthogonalTileArea::tile, and Industry::type.

Referenced by CanCargoServiceIndustry(), DeliverGoodsToIndustry(), and IndustryDirectoryWindow::DrawWidget().

## ◆ MapNewGRFIndustryType()

IndustryType MapNewGRFIndustryType | ( | IndustryType | grf_type,
|  | uint32_t | grf_id
| ) |  |

Map the GRF local type to an industry type.

Parameters

  grf_type | The GRF local type.
  grf_id | The GRF of the local type.

Returns
  The industry type in the global scope.

Definition at line 41 of file newgrf_industries.cpp.

References GB(), IndustryOverrideManager::GetID(), and HasBit().

Referenced by FinaliseIndustriesArray(), GetCountAndDistanceOfClosestInstance(), and IndustriesScopeResolver::GetVariable().