25 #include "table/strings.h" 43 if (grf_type == IT_INVALID)
return IT_INVALID;
44 if (!
HasBit(grf_type, 7))
return GB(grf_type, 0, 7);
46 return _industry_mngr.
GetID(
GB(grf_type, 0, 7), grf_id);
70 return 0xFF << 8 | gfx;
90 return 0xFF << 8 | indtsp->
grf_prop.subst_id;
93 static uint32 GetClosestIndustry(
TileIndex tile, IndustryType type,
const Industry *current)
95 uint32 best_dist = UINT32_MAX;
97 FOR_ALL_INDUSTRIES(i) {
98 if (i->
type != type || i == current)
continue;
119 IndustryType ind_index;
120 uint32 closest_dist = UINT32_MAX;
126 ind_index = param_setID;
142 if (layout_filter == 0 && !town_filter) {
145 closest_dist = GetClosestIndustry(current->
location.
tile, ind_index, current);
151 FOR_ALL_INDUSTRIES(i) {
152 if (i->
type == ind_index && i != current && (i->
selected_layout == layout_filter || layout_filter == 0) && (!town_filter || i->
town == current->
town)) {
159 return count << 16 |
GB(closest_dist, 0, 16);
168 case 0x80:
return this->
tile;
169 case 0x81:
return GB(this->
tile, 8, 8);
175 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
206 DEBUG(grf, 1,
"Unhandled variable 0x%X (no available industry) in callback 0x%x", variable, this->
ro.
callback);
244 const Livery *l = &c->livery[LS_DEFAULT];
250 return this->
industry->
founder | (is_ai ? 0x10000 : 0) | (colours << 24);
297 byte layout_filter = 0;
298 bool town_filter =
false;
299 if (variable == 0x68) {
301 layout_filter =
GB(reg, 0, 8);
302 town_filter =
HasBit(reg, 8);
317 case 0x85:
DEBUG(grf, 0,
"NewGRFs shouldn't be doing pointer magic");
break;
370 DEBUG(grf, 1,
"Unhandled industry variable 0x%X", variable);
392 if (value == 0)
return;
426 CallbackID callback, uint32 callback_param1, uint32 callback_param2)
428 industries_scope(*this, tile, indus, type, random_bits),
434 IndustriesResolverObject::~IndustriesResolverObject()
447 bool readonly =
true;
454 if (t == NULL)
return NULL;
473 return object.ResolveCallback();
492 ind.
index = INVALID_INDUSTRY;
498 ind.
random = initial_random_bits;
503 uint16 result =
object.ResolveCallback();
527 if (res != 0) default_prob = 0;
532 }
else if (res > 0x100) {
541 static int32 DerefIndProd(
int field,
bool use_register)
543 return use_register ? (int32)
GetRegister(field) : field;
558 object.callback_param2 = reason;
560 for (uint loop = 0;; loop++) {
563 if (loop >= 0x10000) {
575 if (tgroup == NULL || tgroup->type != SGT_INDUSTRY_PRODUCTION)
break;
578 bool deref = (group->version == 1);
580 for (uint i = 0; i < 3; i++) {
583 for (uint i = 0; i < 2; i++) {
587 int32 again = DerefIndProd(group->again, deref);
588 if (again == 0)
break;
590 SB(
object.callback_param2, 24, 8, again);
Functions related to OTTD's strings.
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.
uint32 GetTriggers() const
Get the triggers.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
ResolverObject & ro
Surrounding resolver object.
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)'.
OwnerByte founder
Founder of the industry.
Functions for NewGRF industries.
uint16 last_month_production[2]
total units produced per cargo in the last full month
uint16 this_month_transported[2]
stats of this month's transport per cargo
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
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.
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.
uint8 construction_type
Way the industry was constructed (.
TownScopeResolver * town_scope
Scope resolver for the associated town (if needed and available, else NULL).
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.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Get a variable value.
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 incoming_cargo_waiting[3]
incoming cargo waiting to be processed
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.
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.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=NULL, uint textref_stack_size=0, const uint32 *textref_stack=NULL)
Display an error message in a window.
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.
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.
uint16 produced_cargo_waiting[2]
amount of cargo produced per cargo
Called to determine if the given industry type is available.
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.
uint16 this_month_production[2]
stats of this month's production per cargo
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
CargoID accepts_cargo[3]
3 input cargo slots
TileArea location
Location of the industry.
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.
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
CargoID produced_cargo[2]
2 production cargo slots
IndustryType type
Type of the industry.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
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)
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
byte last_month_pct_transported[2]
percentage transported per cargo in the last full month
uint16 last_month_transported[2]
total units transported per cargo in the last full month
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.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
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
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.
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.
byte production_rate[2]
production rate for each cargo
uint16 local_id
id defined by the grf file for this entity
uint32 GetRandomBits() const
Get a few random bits.
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.
Date last_cargo_accepted_at
Last day cargo was accepted by this industry.
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.
Owner
Enum for all companies/owners.
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 ...
void StorePSA(uint pos, int32 value)
Store a value into the persistent storage area (PSA).
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.
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.