OpenTTD
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 { 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 { IACT_MAPGENERATION, IACT_RANDOMCREATION, IACT_USERCREATION, IACT_PROSPECTCREATION }
 From where has callback CBID_INDUSTRY_PROBABILITY been called. More...
 

Functions

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

Detailed Description

Functions for NewGRF industries.

Definition in file newgrf_industries.h.

Enumeration Type Documentation

◆ IndustryAvailabilityCallType

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

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,
uint  layout,
uint32  seed,
uint16  initial_random_bits,
Owner  founder,
IndustryAvailabilityCallType  creation_type 
)

Check that the industry callback allows creation of the industry.

Parameters
tileTile to build the industry.
typeType of industry to build.
layoutLayout number.
seedSeed for the random generator.
initial_random_bitsThe random bits the industry is going to have after construction.
founderIndustry founder
creation_typeThe circumstances the industry is created under.
Returns
Succeeded or failed command.

Definition at line 487 of file newgrf_industries.cpp.

References GetIndustrySpec(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index.

◆ GetIndustryCallback()

uint16 GetIndustryCallback ( CallbackID  callback,
uint32  param1,
uint32  param2,
Industry industry,
IndustryType  type,
TileIndex  tile 
)

Perform an industry callback.

Parameters
callbackThe callback to perform.
param1The first parameter.
param2The second parameter.
industryThe industry to do the callback for.
typeThe type of industry to do the callback for.
tileThe tile associated with the callback.
Returns
The callback result.

Definition at line 470 of file newgrf_industries.cpp.

Referenced by ChangeIndustryProduction(), GetCargoSuffix(), and GetIndustryProbabilityCallback().

◆ GetIndustryIDAtOffset()

uint32 GetIndustryIDAtOffset ( TileIndex  tile,
const Industry i,
uint32  cur_grfid 
)

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

Parameters
tileTileIndex of the tile to query
iIndustry to which to compare the tile to
cur_grfidGRFID 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< Tcnt >::grffile, INVALID_INDUSTRYTILE, GRFFilePropsBase< Tcnt >::local_id, NEW_INDUSTRYTILEOFFSET, GRFFileProps::override, GRFFilePropsBase< Tcnt >::spritegroup, and Industry::TileBelongsToIndustry().

◆ GetIndustryProbabilityCallback()

uint32 GetIndustryProbabilityCallback ( IndustryType  type,
IndustryAvailabilityCallType  creation_type,
uint32  default_prob 
)

Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.

Parameters
typeIndustry type to check.
creation_typeReason 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 518 of file newgrf_industries.cpp.

References CALLBACK_FAILED, IndustrySpec::callback_mask, CBID_INDUSTRY_PROBABILITY, CBM_IND_PROBABILITY, ErrorUnknownCallbackResult(), GetIndustryCallback(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), and INVALID_TILE.

Referenced by GetIndustryGamePlayProbability(), and BuildIndustryWindow::OnTick().

◆ GetNearbyIndustryTileInformation()

uint32 GetNearbyIndustryTileInformation ( byte  parameter,
TileIndex  tile,
IndustryID  index,
bool  signed_offsets,
bool  grf_version8 
)

Based on newhouses equivalent, but adapted for newindustries.

Parameters
parameterfrom callback. It's in fact a pair of coordinates
tileTileIndex from which the callback was initiated
indexof the industry been queried for
signed_offsetsAre the x and y offset encoded in parameter signed?
grf_version8True, 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 36 of file newgrf_industrytiles.cpp.

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

Referenced by IndustryTileScopeResolver::GetVariable().

◆ IndustryProductionCallback()

void IndustryProductionCallback ( Industry ind,
int  reason 
)

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

Parameters
indthe industry this callback has to be called for
reasonthe reason it is called (0 = incoming cargo, 1 = periodic tick callback)

Definition at line 551 of file newgrf_industries.cpp.

References IndustrySpec::behaviour, GetIndustrySpec(), INDUSTRYBEH_PRODCALLBACK_RANDOM, Industry::location, OrthogonalTileArea::tile, and Industry::type.

Referenced by TriggerIndustryProduction().

◆ IndustryTemporarilyRefusesCargo()

bool IndustryTemporarilyRefusesCargo ( Industry ind,
CargoID  cargo_type 
)

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

Parameters
indThe industry to query.
cargo_typeThe 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 603 of file newgrf_industries.cpp.

Referenced by CanCargoServiceIndustry(), and DeliverGoodsToIndustry().

◆ MapNewGRFIndustryType()

IndustryType MapNewGRFIndustryType ( IndustryType  grf_type,
uint32  grf_id 
)

Map the GRF local type to an industry type.

Parameters
grf_typeThe GRF local type.
grf_idThe GRF of the local type.
Returns
The industry type in the global scope.

Definition at line 41 of file newgrf_industries.cpp.