OpenTTD Source 20241224-master-gf74b0cf984
|
Handling of NewGRF industries. More...
#include "stdafx.h"
#include "debug.h"
#include "industry.h"
#include "newgrf_industries.h"
#include "newgrf_town.h"
#include "newgrf_cargo.h"
#include "window_func.h"
#include "town.h"
#include "company_base.h"
#include "error.h"
#include "strings_func.h"
#include "core/random_func.hpp"
#include "timer/timer_game_calendar.h"
#include "table/strings.h"
#include "safeguards.h"
Go to the source code of this file.
Functions | |
IndustryType | MapNewGRFIndustryType (IndustryType grf_type, uint32_t grf_id) |
Map the GRF local type to an industry type. | |
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. | |
static uint32_t | GetClosestIndustry (TileIndex tile, IndustryType type, const Industry *current) |
static uint32_t | GetCountAndDistanceOfClosestInstance (uint8_t param_setID, uint8_t layout_filter, bool town_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. | |
static const GRFFile * | GetGrffile (IndustryType type) |
Get the grf file associated with the given industry type. | |
uint16_t | GetIndustryCallback (CallbackID callback, uint32_t param1, uint32_t param2, Industry *industry, IndustryType type, TileIndex tile) |
Perform an industry callback. | |
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. | |
static int32_t | DerefIndProd (int field, bool use_register) |
void | IndustryProductionCallback (Industry *ind, int reason) |
Get the industry production callback and apply it to the industry. | |
bool | IndustryTemporarilyRefusesCargo (Industry *ind, CargoID cargo_type) |
Check whether an industry temporarily refuses to accept a certain cargo. | |
Variables | |
IndustryOverrideManager | _industry_mngr (NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE) |
IndustryTileOverrideManager | _industile_mngr (NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE) |
Handling of NewGRF industries.
Definition in file newgrf_industries.cpp.
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.
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. |
Definition at line 540 of file newgrf_industries.cpp.
References CALLBACK_FAILED, CBID_INDUSTRY_LOCATION, ClosestTownFromTile(), Industry::founder, GetErrorMessageFromLocationCallbackResult(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::location, Industry::psa, Industry::random, Industry::selected_layout, OrthogonalTileArea::tile, Industry::town, Industry::type, and OrthogonalTileArea::w.
Referenced by CreateNewIndustryHelper().
|
static |
Definition at line 594 of file newgrf_industries.cpp.
|
static |
Definition at line 92 of file newgrf_industries.cpp.
|
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.
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? |
town_filter | Do we filter on the same town as the current industry? |
current | Industry for which the inquiry is made |
< Get the GRFID of the definition to look for in register 100h
Definition at line 115 of file newgrf_industries.cpp.
References DistanceManhattan(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), GetIndustrySpec(), Industry::GetIndustryTypeCount(), GetRegister(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grfid, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::industries, Industry::location, MapNewGRFIndustryType(), NUM_INDUSTRYTYPES, Industry::selected_layout, SetBit(), OrthogonalTileArea::tile, Industry::town, and Industry::type.
Referenced by IndustriesScopeResolver::GetVariable(), and ObjectScopeResolver::GetVariable().
|
static |
Get the grf file associated with the given industry type.
type | Industry type to query. |
Definition at line 458 of file newgrf_industries.cpp.
References GetIndustrySpec(), IndustrySpec::grf_prop, and GRFFilePropsBase< Tcnt >::grffile.
uint16_t GetIndustryCallback | ( | CallbackID | callback, |
uint32_t | param1, | ||
uint32_t | param2, | ||
Industry * | industry, | ||
IndustryType | type, | ||
TileIndex | tile | ||
) |
Perform an industry callback.
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. |
Definition at line 523 of file newgrf_industries.cpp.
Referenced by ChangeIndustryProduction(), DoCreateNewIndustry(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), GetCargoSuffix(), GetIndustryProbabilityCallback(), and IndustryTemporarilyRefusesCargo().
Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.
tile | TileIndex of the tile to query |
i | Industry to which to compare the tile to |
cur_grfid | GRFID of the current callback chain |
Definition at line 56 of file newgrf_industries.cpp.
References GetCleanIndustryGfx(), GetIndustryTileSpec(), IndustryTileSpec::grf_prop, GRFFilePropsBase< Tcnt >::grfid, INVALID_INDUSTRYTILE, GRFFilePropsBase< Tcnt >::local_id, NEW_INDUSTRYTILEOFFSET, GRFFileProps::override, GRFFilePropsBase< Tcnt >::spritegroup, and Industry::TileBelongsToIndustry().
Referenced by IndustriesScopeResolver::GetVariable(), and IndustryTileScopeResolver::GetVariable().
uint32_t GetIndustryProbabilityCallback | ( | IndustryType | type, |
IndustryAvailabilityCallType | creation_type, | ||
uint32_t | default_prob | ||
) |
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
type | Industry type to check. |
creation_type | Reason to construct a new industry. |
true
is returned. Otherwise, false
is returned. Definition at line 571 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, GRFFilePropsBase< Tcnt >::grfid, HasBit(), and INVALID_TILE.
Referenced by CmdBuildIndustry(), GetIndustryGamePlayProbability(), and GetScaledIndustryGenerationProbability().
void IndustryProductionCallback | ( | Industry * | ind, |
int | reason | ||
) |
Get the industry production callback and apply it to the industry.
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 604 of file newgrf_industries.cpp.
References Industry::accepted, IndustryProductionSpriteGroup::add_output, IndustrySpec::behaviour, IndustryProductionSpriteGroup::cargo_input, IndustryProductionSpriteGroup::cargo_output, Industry::GetCargoAccepted(), Industry::GetCargoProduced(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INDUSTRYBEH_PROD_MULTI_HNDLING, INDUSTRYBEH_PRODCALLBACK_RANDOM, IsValidCargoID(), Industry::location, IndustrySpec::name, IndustryProductionSpriteGroup::num_input, IndustryProductionSpriteGroup::num_output, Industry::prod_level, Industry::produced, SpriteGroup::Resolve(), SB(), SetDParam(), SetDParamStr(), SetWindowDirty(), ShowErrorMessage(), IndustryProductionSpriteGroup::subtract_input, OrthogonalTileArea::tile, Industry::type, IndustryProductionSpriteGroup::version, WC_INDUSTRY_VIEW, and WL_WARNING.
Referenced by DoCreateNewIndustry(), and TriggerIndustryProduction().
Check whether an industry temporarily refuses to accept a certain cargo.
ind | The industry to query. |
cargo_type | The cargo to get information about. |
Definition at line 684 of file newgrf_industries.cpp.
References CALLBACK_FAILED, IndustrySpec::callback_mask, GRFFile::cargo_map, CBID_INDUSTRY_REFUSE_CARGO, CBM_IND_REFUSE_CARGO, ConvertBooleanCallback(), GetIndustryCallback(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), Industry::IsCargoAccepted(), Industry::location, OrthogonalTileArea::tile, and Industry::type.
Referenced by CanCargoServiceIndustry(), DeliverGoodsToIndustry(), and IndustryDirectoryWindow::DrawWidget().
IndustryType MapNewGRFIndustryType | ( | IndustryType | grf_type, |
uint32_t | grf_id | ||
) |
Map the GRF local type to an industry type.
grf_type | The GRF local type. |
grf_id | The GRF of the local type. |
Definition at line 40 of file newgrf_industries.cpp.
References GB(), IndustryOverrideManager::GetID(), and HasBit().
Referenced by FinaliseIndustriesArray(), GetCountAndDistanceOfClosestInstance(), and IndustriesScopeResolver::GetVariable().