Go to the documentation of this file.
23 #include "table/strings.h"
41 if (grf_type == IT_INVALID)
return IT_INVALID;
42 if (!
HasBit(grf_type, 7))
return GB(grf_type, 0, 7);
44 return _industry_mngr.
GetID(
GB(grf_type, 0, 7), grf_id);
68 return 0xFF << 8 | gfx;
88 return 0xFF << 8 | indtsp->
grf_prop.subst_id;
91 static uint32 GetClosestIndustry(
TileIndex tile, IndustryType type,
const Industry *current)
93 uint32 best_dist = UINT32_MAX;
95 if (i->type != type || i == current)
continue;
116 IndustryType ind_index;
117 uint32 closest_dist = UINT32_MAX;
123 ind_index = param_setID;
139 if (layout_filter == 0 && !town_filter) {
142 closest_dist = GetClosestIndustry(current->
location.
tile, ind_index, current);
148 if (i->type == ind_index && i != current && (i->selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->town == current->
town)) {
155 return count << 16 |
GB(closest_dist, 0, 16);
164 case 0x80:
return this->
tile;
165 case 0x81:
return GB(this->tile, 8, 8);
171 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
202 DEBUG(grf, 1,
"Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->
ro.
callback);
240 const Livery *l = &c->livery[LS_DEFAULT];
246 return this->
industry->
founder | (is_ai ? 0x10000 : 0) | (colours << 24);
300 byte layout_filter = 0;
301 bool town_filter =
false;
302 if (variable == 0x68) {
304 layout_filter =
GB(reg, 0, 8);
305 town_filter =
HasBit(reg, 8);
319 int index = this->
industry->GetCargoProducedIndex(cargo);
320 if (index < 0)
return 0;
329 default: NOT_REACHED();
338 int index = this->
industry->GetCargoAcceptedIndex(cargo);
339 if (index < 0)
return 0;
355 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
411 DEBUG(grf, 1,
"Unhandled industry variable 0x%X", variable);
433 if (value == 0)
return;
467 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
469 industries_scope(*this, tile, indus, type, random_bits),
475 IndustriesResolverObject::~IndustriesResolverObject()
488 bool readonly =
true;
495 if (t ==
nullptr)
return nullptr;
503 return GSF_INDUSTRIES;
524 return object.ResolveCallback();
543 ind.
index = INVALID_INDUSTRY;
549 ind.
random = initial_random_bits;
554 uint16 result =
object.ResolveCallback();
578 if (res != 0) default_prob = 0;
583 }
else if (res > 0x100) {
592 static int32 DerefIndProd(
int field,
bool use_register)
594 return use_register ? (int32)
GetRegister(field) : field;
609 object.callback_param2 = reason;
611 for (uint loop = 0;; loop++) {
614 if (loop >= 0x10000) {
624 SB(
object.callback_param2, 8, 16, loop);
626 if (tgroup ==
nullptr || tgroup->type != SGT_INDUSTRY_PRODUCTION)
break;
640 bool deref = (group->
version >= 1);
644 for (uint i = 0; i < group->
num_input; i++) {
647 for (uint i = 0; i < group->
num_output; i++) {
652 for (uint i = 0; i < group->
num_input; i++) {
653 int cargo_index = ind->GetCargoAcceptedIndex(group->
cargo_input[i]);
654 if (cargo_index < 0)
continue;
657 for (uint i = 0; i < group->
num_output; i++) {
658 int cargo_index = ind->GetCargoProducedIndex(group->
cargo_output[i]);
659 if (cargo_index < 0)
continue;
664 int32 again = DerefIndProd(group->again, deref);
665 if (again == 0)
break;
667 SB(
object.callback_param2, 24, 8, again);
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
uint32 TileIndex
The index/ID of a Tile.
@ CBM_IND_PRODUCTION_CARGO_ARRIVAL
call production callback when cargo arrives at the industry
uint16 override
id of the entity been replaced by
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
uint16 this_month_production[INDUSTRY_NUM_OUTPUTS]
stats of this month's production per cargo
TileIndex tile
Tile owned by the industry.
uint32 GetTriggers() const override
Get the triggers.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
int16 subtract_input[INDUSTRY_NUM_INPUTS]
Take this much of the input cargo (can be negative, is indirect in cb version 1+)
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
@ WL_WARNING
Other information.
TownScopeResolver * GetTown()
Get or create the town scope object associated with the industry.
uint16 this_month_transported[INDUSTRY_NUM_OUTPUTS]
stats of this month's transport per cargo
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]
total units transported per cargo in the last full month
@ WC_INDUSTRY_VIEW
Industry view; Window numbers:
Tindex index
Index of this pool item.
uint8 num_input
How many subtract_input values are valid.
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station....
void StorePSA(uint pos, int32 value) override
Store a value into the persistent storage area (PSA).
Interface for SpriteGroup-s to access the gamestate.
Industry * industry
Industry being resolved.
uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS]
amount of cargo produced per cargo
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
@ CBID_INDUSTRY_PROBABILITY
Called to determine if the given industry type is available.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
TownScopeResolver * town_scope
Scope resolver for the associated town (if needed and available, else nullptr).
uint8 construction_type
Way the industry was constructed (.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
TileIndex xy
town center tile
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
@ CBM_IND_PRODUCTION_256_TICKS
call production callback every 256 ticks
Date construction_date
Date of the construction of the industry.
CallbackID
List of implemented NewGRF callbacks.
Defines the internal data of a functional industry.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
Owner
Enum for all companies/owners.
IndustryControlFlags ctlflags
flags overriding standard behaviours
static uint32 GetCountAndDistanceOfClosestInstance(byte param_setID, byte 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 ...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
uint16 GetID(uint8 grf_local_id, uint32 grfid) const override
Return the ID (if ever available) of a previously inserted entity.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
@ CBM_IND_PROBABILITY
industry availability/probability callback
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
@ CBID_INDUSTRY_LOCATION
Called to determine if the given industry can be built on specific area.
uint8 num_output
How many add_output values are valid.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
uint32 random_bits
Random bits of the new industry.
Common return value for all commands.
uint16 random
Random value used for randomisation of all kinds of things.
TileArea location
Location of the industry.
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
IndustryType type
type of industry.
#define DEBUG(name, level,...)
Output a line of debugging information.
TYPE GetValue(uint pos) const
Gets the value from a given position.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
Class for pooled persistent storage of data.
uint16 w
The width of the area.
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
@ INDUSTRYBEH_BUILT_ONWATER
is built on water (oil rig)
int32 Date
The type to store our dates in.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
Map the GRF local type to an industry type.
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
@ INDUSTRYBEH_PRODCALLBACK_RANDOM
Production callback needs random bits in var 10.
Scope resolver for a town.
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Defines the data structure for constructing industry.
GRFFileProps grf_prop
properties related to the grf file
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...
uint16 h
The height of the area.
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
uint16 add_output[INDUSTRY_NUM_OUTPUTS]
Add this much output cargo when successful (unsigned, is indirect in cb version 1+)
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
uint32 GetRandomBits() const override
Get a few random bits.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ CBID_INDUSTRY_REFUSE_CARGO
Called to determine if the industry can still accept or refuse more cargo arrival.
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
byte selected_layout
Which tile layout was used when creating the industry.
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
static const GRFFile * GetGrffile(IndustryType type)
Get the grf file associated with the given industry type.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
@ INDUSTRYBEH_PROD_MULTI_HNDLING
Automatic production multiplier handling.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
Owner founder
Founder of the industry.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
TileIndex tile
The base tile of the area.
#define endof(x)
Get the end element of an fixed size array.
Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]
Last day each cargo type was accepted by this industry.
@ CBM_IND_REFUSE_CARGO
option out of accepting cargo
GRFFileProps grf_prop
properties related to the grf file
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Year last_prod_year
last year of production
CallbackID callback
Callback being resolved.
IndustriesResolverObject(TileIndex tile, Industry *indus, IndustryType type, uint32 random_bits=0, CallbackID callback=CBID_NO_CALLBACK, uint32 callback_param1=0, uint32 callback_param2=0)
Constructor of the industries resolver.
uint8 version
Production callback version used, or 0xFF if marked invalid.
IndustryType type
Type of the industry.
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
CommandCost CheckIfCallBackAllowsCreation(TileIndex tile, IndustryType type, size_t layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check that the industry callback allows creation of the industry.
byte random_colour
randomized colour of the industry, for display purpose
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
byte CargoID
Cargo slots to indicate a cargo type within a game.
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
CargoID cargo_output[INDUSTRY_NUM_OUTPUTS]
Which output cargoes to add to (only cb version 2)
static byte GetIndustryRandomBits(TileIndex tile)
Get the random bits for this tile.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
uint16 local_id
id defined by the grf file for this entity
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
StringID name
Displayed name of the industry.
ResolverObject & ro
Surrounding resolver object.
CargoID cargo_input[INDUSTRY_NUM_INPUTS]
Which input cargoes to take from (only cb version 2)
const struct GRFFile * grffile
grf file that introduced this entity
byte prod_level
general production level
static IndustryGfx GetCleanIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile as stored in the without translation.
PersistentStorage * psa
Persistent storage for NewGRF industries.
@ CT_INVALID
Invalid cargo type.
Defines the data structure of each individual tile of an industry.
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
Information about a particular livery.
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
Dynamic data of a loaded NewGRF.
uint16 counter
used for animation and/or production (if available cargo)
IndustriesScopeResolver industries_scope
Scope resolver for the industry.
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR,...
byte colour2
Second colour, for vehicles with 2CC support.
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
byte colour1
First colour, for all vehicles.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.