# newgrf_industries.cpp File Reference

Handling of NewGRF industries. More...

`#include "stdafx.h"`
`#include "debug.h"`
`#include "tile_type.h"`
`#include "strings_type.h"`
`#include "company_type.h"`
`#include "industry_map.h"`
`#include "newgrf.h"`
`#include "newgrf_industries.h"`
`#include "newgrf_commons.h"`
`#include "newgrf_text.h"`
`#include "newgrf_town.h"`
`#include "window_func.h"`
`#include "town.h"`
`#include "company_base.h"`
`#include "command_func.h"`
`#include "gui.h"`
`#include "strings_func.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Functions
IndustryOverrideManager | _industry_mngr (NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE)
IndustryTileOverrideManager | _industile_mngr (NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE)
IndustryType | MapNewGRFIndustryType (IndustryType grf_type, uint32 grf_id)
static uint | GetClosestWaterDistance (TileIndex tile, bool water)
| Finds the distance for the closest tile with water/land given a tile.
uint32 | GetIndustryIDAtOffset (TileIndex tile, const Industry *i)
| Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.
static uint32 | GetClosestIndustry (TileIndex tile, IndustryType type, const Industry *current)
static uint32 | GetCountAndDistanceOfClosestInstance (byte param_setID, byte layout_filter, const Industry *current)
| Implementation of both var 67 and 68 since the mechanism is almost the same, it is easier to regroup them on the same function.
uint32 | IndustryGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
| This function implements the industries variables that newGRF defines.
static const SpriteGroup * | IndustryResolveReal (const ResolverObject *object, const SpriteGroup *group)
static uint32 | IndustryGetRandomBits (const ResolverObject *object)
static uint32 | IndustryGetTriggers (const ResolverObject *object)
static void | IndustrySetTriggers (const ResolverObject *object, int triggers)
static void | NewIndustryResolver (ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
uint16 | GetIndustryCallback (CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
uint32 | IndustryLocationGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
bool | CheckIfCallBackAllowsCreation (TileIndex tile, IndustryType type, uint itspec_index, uint32 seed)
bool | CheckIfCallBackAllowsAvailability (IndustryType type, IndustryAvailabilityCallType creation_type)
static int32 | DerefIndProd (uint field, bool use_register)
void | IndustryProductionCallback (Industry *ind, int reason)
| Get the industry production callback and apply it to the industry.
## Variables
static uint32 | _industry_creation_random_bits

## Detailed Description

Handling of NewGRF industries.

Definition in file newgrf_industries.cpp.

## Function Documentation

static uint GetClosestWaterDistance | ( | TileIndex | tile,
|  | bool | water |
| ) |  |  | `[static]`

Finds the distance for the closest tile with water/land given a tile.

Parameters:

  | tile | the tile to find the distance too
  | water | whether to find water or land

Returns:
  distance to nearest water (max 0x7F) / land (max 0x1FF; 0x200 if there is no land)

Note:
  FAILS when an industry should be seen as water

Definition at line 48 of file newgrf_industries.cpp.

References _settings_game, GameSettings::construction, DIAGDIR_BEGIN, DIAGDIR_END, ConstructionSettings::freeform_edges, IsInsideMM(), IsTileType(), MapMaxX(), MapMaxY(), MapSize(), MP_VOID, MP_WATER, TileX(), TileXY(), and TileY().

Referenced by IndustryGetVariable().

static uint32 GetCountAndDistanceOfClosestInstance | ( | byte | param_setID,
|  | byte | layout_filter,
|  | const Industry * | current |
| ) |  |  | `[static]`

Implementation of both var 67 and 68 since the mechanism is almost the same, it is easier to regroup them on the same function.

Parameters:

  | param_setID | parameter given to the callback, which is the set id, or the local id, in our terminology
  | layout_filter | on what layout do we filter?
  | current | Industry for which the inquiry is made

Returns:
  the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)

< Get the GRFID of the definition to look for in register 100h

Definition at line 160 of file newgrf_industries.cpp.

References DistanceManhattan(), GB(), GetIndustrySpec(), GetIndustryTypeCount(), GetRegister(), IndustrySpec::grf_prop, GRFFileProps::grffile, min(), Industry::selected_layout, SetBit(), Industry::type, and Industry::xy.

Referenced by IndustryGetVariable().

uint32 GetIndustryIDAtOffset | ( | TileIndex | tile,
|  | const Industry * | i |
| ) |  |  |

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

Returns:
  value encoded as per NFO specs

Definition at line 102 of file newgrf_industries.cpp.

References GetIndustryIndex(), GetIndustrySpec(), GetIndustryTileSpec(), IndustrySpec::grf_prop, IndustryTileSpec::grf_prop, GRFFileProps::grffile, PoolItem< T, Tid, Tpool >::index, INVALID_INDUSTRYTILE, IsTileType(), GRFFileProps::local_id, MP_INDUSTRY, NEW_INDUSTRYOFFSET, GRFFileProps::override, GRFFileProps::spritegroup, GRFFileProps::subst_id, and Industry::type.

Referenced by IndustryGetVariable().

uint32 IndustryGetVariable | ( | const ResolverObject * | object,
|  | byte | variable,
|  | byte | parameter,
|  | bool * | available |
| ) |  |  |

This function implements the industries variables that newGRF defines.

Parameters:

  | variable | that is queried
  | parameter | unused
  | available | will return false if ever the variable asked for does not exist
  | ind | is of course the industry we are inquiring

Returns:
  the value stored in the corresponding variable

Definition at line 209 of file newgrf_industries.cpp.

References Industry::accepts_cargo, IndustrySpec::behaviour, IndustrySpec::callback_flags, CBM_IND_PRODUCTION_256_TICKS, CBM_IND_PRODUCTION_CARGO_ARRIVAL, Clamp(), Industry::construction_date, Industry::construction_type, Industry::counter, DAYS_TILL_ORIGINAL_BASE_YEAR, DistanceManhattan(), DistanceSquare(), Industry::founder, GB(), GetClosestWaterDistance(), GetCountAndDistanceOfClosestInstance(), GetIndustryAnimationState(), GetIndustryByTile(), GetIndustryIDAtOffset(), GetIndustryRandomBits(), GetIndustrySpec(), GetNearbyIndustryTileInformation(), GetRegister(), GetTownRadiusGroup(), IndustrySpec::grf_prop, GRFFileProps::grffile, HasBit(), Industry::height, Industry::incoming_cargo_waiting, INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_PROD_MULTI_HNDLING, INVALID_INDUSTRYTILE, INVALID_TILE, IsTileType(), Industry::last_cargo_accepted_at, Industry::last_month_pct_transported, Industry::last_month_production, Industry::last_month_transported, Industry::last_prod_year, min(), MP_INDUSTRY, ORIGINAL_BASE_YEAR, Industry::prod_level, Industry::produced_cargo, Industry::produced_cargo_waiting, Industry::production_rate, Industry::psa, Industry::random_colour, Industry::selected_layout, Industry::this_month_production, Industry::this_month_transported, Industry::town, TownGetVariable(), Industry::type, Industry::was_cargo_delivered, Industry::width, and Industry::xy.

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 564 of file newgrf_industries.cpp.

References IndustrySpec::behaviour, Clamp(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFileProps::grffile, Industry::incoming_cargo_waiting, PoolItem< T, Tid, Tpool >::index, INDUSTRYBEH_PROD_MULTI_HNDLING, INDUSTRYBEH_PRODCALLBACK_RANDOM, InvalidateWindow(), max(), IndustrySpec::name, Industry::prod_level, Industry::produced_cargo_waiting, SB(), SetDParamStr(), GRFFileProps::spritegroup, Industry::type, and Industry::xy.

Referenced by TriggerIndustryProduction().