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);
293 byte layout_filter = 0;
294 bool town_filter =
false;
295 if (variable == 0x68) {
297 layout_filter =
GB(reg, 0, 8);
298 town_filter =
HasBit(reg, 8);
311 int index = this->
industry->GetCargoProducedIndex(cargo);
312 if (index < 0)
return 0;
321 default: NOT_REACHED();
329 int index = this->
industry->GetCargoAcceptedIndex(cargo);
330 if (index < 0)
return 0;
346 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
402 DEBUG(grf, 1,
"Unhandled industry variable 0x%X", variable);
424 if (value == 0)
return;
458 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
460 industries_scope(*this, tile, indus, type, random_bits),
466 IndustriesResolverObject::~IndustriesResolverObject()
479 bool readonly =
true;
486 if (t ==
nullptr)
return nullptr;
505 return object.ResolveCallback();
524 ind.
index = INVALID_INDUSTRY;
530 ind.
random = initial_random_bits;
535 uint16 result =
object.ResolveCallback();
559 if (res != 0) default_prob = 0;
564 }
else if (res > 0x100) {
573 static int32 DerefIndProd(
int field,
bool use_register)
575 return use_register ? (int32)
GetRegister(field) : field;
590 object.callback_param2 = reason;
592 for (uint loop = 0;; loop++) {
595 if (loop >= 0x10000) {
607 if (tgroup ==
nullptr || tgroup->type != SGT_INDUSTRY_PRODUCTION)
break;
621 bool deref = (group->
version >= 1);
625 for (uint i = 0; i < group->
num_input; i++) {
628 for (uint i = 0; i < group->
num_output; i++) {
633 for (uint i = 0; i < group->
num_input; i++) {
634 int cargo_index = ind->GetCargoAcceptedIndex(group->
cargo_input[i]);
635 if (cargo_index < 0)
continue;
638 for (uint i = 0; i < group->
num_output; i++) {
639 int cargo_index = ind->GetCargoProducedIndex(group->
cargo_output[i]);
640 if (cargo_index < 0)
continue;
645 int32 again = DerefIndProd(group->again, deref);
646 if (again == 0)
break;
648 SB(
object.callback_param2, 24, 8, again);
Functions related to OTTD's strings.
Owner
Enum for all companies/owners.
static IndustryGfx GetCleanIndustryGfx(TileIndex t)
Get the industry graphics ID for the given industry tile as stored in the without translation...
Called to determine if the given industry can be built on specific area.
Definition of stuff that is very close to a company, like the company struct itself.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
CargoID cargo_output[INDUSTRY_NUM_OUTPUTS]
Which output cargoes to add to (only cb version 2)
byte production_rate[INDUSTRY_NUM_OUTPUTS]
production rate for each cargo
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
int16 subtract_input[INDUSTRY_NUM_INPUTS]
Take this much of the input cargo (can be negative, is indirect in cb version 1+) ...
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
uint32 GetRandomBits() const override
Get a few random bits.
ResolverObject & ro
Surrounding resolver object.
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.
uint16 counter
used for animation and/or production (if available cargo)
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR, 0, 1)'.
Functions for NewGRF industries.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const IndustryGfx INVALID_INDUSTRYTILE
one above amount is considered invalid
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
Interface for SpriteGroup-s to access the gamestate.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
uint32 GetIndustryProbabilityCallback(IndustryType type, IndustryAvailabilityCallType creation_type, uint32 default_prob)
Check with callback CBID_INDUSTRY_PROBABILITY whether the industry can be built.
byte selected_layout
Which tile layout was used when creating the industry.
uint8 construction_type
Way the industry was constructed (.
uint32 GetTriggers() const override
Get the triggers.
TownScopeResolver * town_scope
Scope resolver for the associated town (if needed and available, else nullptr).
uint16 callback_mask
Bitmask of industry callbacks that have to be called.
Defines the internal data of a functional industry.
uint32 GetNearbyIndustryTileInformation(byte parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
Tindex index
Index of this pool item.
void IndustryProductionCallback(Industry *ind, int reason)
Get the industry production callback and apply it to the industry.
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.
Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]
Last day each cargo type was accepted by this industry.
byte was_cargo_delivered
flag that indicate this has been the closest industry chosen for cargo delivery by a station...
uint16 random
Random value used for randomisation of all kinds of things.
Common return value for all commands.
static T max(const T a, const T b)
Returns the maximum of two values.
uint16 w
The width of the area.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
byte random_colour
randomized colour of the industry, for display purpose
StringID name
Displayed name of the industry.
Automatic production multiplier handling.
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.
bool IndustryTemporarilyRefusesCargo(Industry *ind, CargoID cargo_type)
Check whether an industry temporarily refuses to accept a certain cargo.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Get a variable value.
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Date construction_date
Date of the construction of the industry.
Pseudo random number generator.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
uint16 GetID(uint8 grf_local_id, uint32 grfid) const override
Return the ID (if ever available) of a previously inserted entity.
uint16 add_output[INDUSTRY_NUM_OUTPUTS]
Add this much output cargo when successful (unsigned, is indirect in cb version 1+) ...
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
uint16 this_month_production[INDUSTRY_NUM_OUTPUTS]
stats of this month's production per cargo
uint8 num_output
How many add_output values are valid.
uint32 callback_param2
Second parameter (var 18) of the callback.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
TileIndex xy
town center tile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
TYPE GetValue(uint pos) const
Gets the value from a given position.
Functions related to errors.
PersistentStorage * psa
Persistent storage for NewGRF industries.
Called to determine if the given industry type is available.
uint16 this_month_transported[INDUSTRY_NUM_OUTPUTS]
stats of this month's transport per cargo
void StoreValue(uint pos, int32 value)
Stores some value at a given position.
Year last_prod_year
last year of production
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Scope resolver for a town.
IndustryType type
type of industry.
IndustryType MapNewGRFIndustryType(IndustryType grf_type, uint32 grf_id)
Map the GRF local type to an industry type.
static const IndustryGfx NEW_INDUSTRYTILEOFFSET
original number of tiles
TileArea location
Location of the industry.
uint16 last_month_production[INDUSTRY_NUM_OUTPUTS]
total units produced per cargo in the last full month
static const uint TILE_HEIGHT
Height of a height level in world coordinate AND in pixels in #ZOOM_LVL_BASE.
Information about a particular livery.
CargoID produced_cargo[INDUSTRY_NUM_OUTPUTS]
16 production cargo slots
Class for pooled persistent storage of data.
static const IndustryGfx NUM_INDUSTRYTILES
total number of industry tiles, new and old
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...
Defines the data structure for constructing industry.
static uint16 GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
bool is_ai
If true, the company is (also) controlled by the computer (a NoAI program).
GRFFileProps grf_prop
properties related to the grf file
IndustryType type
Type of the industry.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
CargoID accepts_cargo[INDUSTRY_NUM_INPUTS]
16 input cargo slots
void StorePSA(uint pos, int32 value) override
Store a value into the persistent storage area (PSA).
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
Industry view; Window numbers:
uint8 cargo_map[NUM_CARGO]
Inverse cargo translation table (CargoID -> local ID)
uint16 incoming_cargo_waiting[INDUSTRY_NUM_INPUTS]
incoming cargo waiting to be processed
IndustryBehaviour behaviour
How this industry will behave, and how others entities can use it.
byte prod_level
general production level
GRFFileProps grf_prop
properties related to the grf file
static T min(const T a, const T b)
Returns the minimum of two values.
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Called to determine if the industry can still accept or refuse more cargo arrival.
static const Year ORIGINAL_BASE_YEAR
The minimum starting year/base year of the original TTD.
byte colour2
Second colour, for vehicles with 2CC support.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
industry availability/probability callback
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
static const GRFFile * GetGrffile(IndustryType type)
Get the grf file associated with the given industry type.
#define DEBUG(name, level,...)
Output a line of debugging information.
uint16 override
id of the entity been replaced by
TileIndex tile
The base tile of the area.
uint GetClosestWaterDistance(TileIndex tile, bool water)
Finds the distance for the closest tile with water/land given a tile.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
uint16 produced_cargo_waiting[INDUSTRY_NUM_OUTPUTS]
amount of cargo produced per cargo
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
is built on water (oil rig)
uint32 TileIndex
The index/ID of a Tile.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Cargo support for NewGRFs.
option out of accepting cargo
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
TownScopeResolver * GetTown()
Get or create the town scope object associated with the industry.
CallbackID callback
Callback being resolved.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
uint8 version
Production callback version used, or 0xFF if marked invalid.
#define endof(x)
Get the end element of an fixed size array.
call production callback when cargo arrives at the industry
static const IndustryType NEW_INDUSTRYOFFSET
original number of industry types
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
static byte GetIndustryRandomBits(TileIndex tile)
Get the random bits for this tile.
Owner founder
Founder of the industry.
uint16 local_id
id defined by the grf file for this entity
uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]
total units transported per cargo in the last full month
int32 Date
The type to store our dates in.
const struct GRFFile * grffile
grf file that introduced this entity
CallbackID
List of implemented NewGRF callbacks.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
byte colour1
First colour, for all vehicles.
Functions to handle the town part of NewGRF towns.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
byte CargoID
Cargo slots to indicate a cargo type within a game.
Defines the data structure of each individual tile of an industry.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Window functions not directly related to making/drawing windows.
uint32 random_bits
Random bits of the new industry.
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 ...
byte last_month_pct_transported[INDUSTRY_NUM_OUTPUTS]
percentage transported per cargo in the last full month
uint8 num_input
How many subtract_input values are valid.
call production callback every 256 ticks
Industry * industry
Industry being resolved.
Production callback needs random bits in var 10.
uint16 h
The height of the area.
IndustriesScopeResolver industries_scope
Scope resolver for the industry.
CargoID cargo_input[INDUSTRY_NUM_INPUTS]
Which input cargoes to take from (only cb version 2)
TileIndex tile
Tile owned by the industry.
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.
uint16 GetIndustryCallback(CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
Perform an industry callback.
Dynamic data of a loaded NewGRF.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.