21#include "table/strings.h"
36 if (parameter != 0) tile =
GetNearbyTile(parameter, tile, signed_offsets);
58 return ((y & 0xF) << 20) | ((x & 0xF) << 16) | (y << 8) | x;
96 Debug(grf, 1,
"Unhandled industry tile variable 0x{:X}", variable);
139 CallbackID callback, uint32_t callback_param1, uint32_t callback_param2)
141 indtile_scope(*this, indus, tile),
142 ind_scope(*this, tile, indus, indus->type),
150 return GSF_INDUSTRYTILES;
172 DrawWaterClassGround(ti);
181uint16_t GetIndustryTileCallback(
CallbackID callback, uint32_t param1, uint32_t param2, IndustryGfx gfx_id,
Industry *industry,
TileIndex tile)
187 return object.ResolveCallback();
193 bool draw_old_one =
true;
206 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return false;
211 IndustryDrawTileLayout(ti, tlgroup, i->
random_colour, stage);
215extern bool IsSlopeRefused(
Slope current,
Slope refused);
233 ind.
index = INVALID_INDUSTRY;
237 ind.
random = initial_random_bits;
240 uint16_t callback_res = GetIndustryTileCallback(
CBID_INDTILE_SHAPE_CHECK, 0, creation_type << 8 | (uint32_t)layout_index, gfx, &ind, ind_tile);
256 return GetIndustryTileCallback(callback, param1, param2, spec -
GetIndustryTileSpec(0), ind, tile);
260struct IndustryAnimationBase :
public AnimationBase<IndustryAnimationBase, IndustryTileSpec, Industry, int, GetSimpleIndustryCallback, TileAnimationFrameAnimationHelper<Industry> > {
268void AnimateNewIndustryTile(
TileIndex tile)
271 if (itspec ==
nullptr)
return;
289 uint32_t random = Random();
292 if (StartStopIndustryTileAnimation(tile, iat, random)) {
293 SB(random, 0, 16, Random());
324 if (group ==
nullptr)
return;
330 uint8_t new_random_bits = Random();
347 if (reseed == 0 || ind ==
nullptr)
return;
349 uint16_t random_bits = Random();
351 ind->
random |= random_bits & reseed;
361 uint32_t reseed_industry = 0;
374 uint32_t reseed_industry = 0;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Common return value for all commands.
Functions related to commands.
Owner
Enum for all companies/owners.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32_t PaletteID
The number of the palette.
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
const IndustryTileSpec * GetIndustryTileSpec(IndustryGfx gfx)
Accessor for array _industry_tile_specs.
uint8_t GetIndustryRandomBits(Tile tile)
Get the random bits for this tile.
IndustryGfx GetIndustryGfx(Tile t)
Get the industry graphics ID for the given industry tile.
void SetIndustryTriggers(Tile tile, uint8_t triggers)
Set the activated triggers bits for this industry tile Used for grf callbacks.
IndustryID GetIndustryIndex(Tile t)
Get the industry ID of the given tile.
void SetIndustryRandomBits(Tile tile, uint8_t bits)
Set the random bits for this tile.
uint8_t GetIndustryTriggers(Tile tile)
Get the activated triggers bits for this industry tile Used for grf callbacks.
uint8_t GetIndustryConstructionStage(Tile tile)
Returns the industry construction stage of the specified tile.
@ INDTILE_SPECIAL_NEXTFRAME_RANDOMBITS
Callback 0x26 needs random bits.
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Functions related to OTTD's landscape.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
This is the position of the tile relative to the northernmost tile of the industry.
Function implementations related to NewGRF animation.
IndustryAnimationTrigger
Animation triggers of the industries.
IndustryTileCallbackMask
Callback masks for industry tiles.
@ CBM_INDT_ANIM_SPEED
decides animation speed
@ CBM_INDT_ANIM_NEXT_FRAME
decides next animation frame
@ CBM_INDT_DRAW_FOUNDATIONS
decides if default foundations need to be drawn
CallbackID
List of implemented NewGRF callbacks.
@ CBID_INDTILE_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
@ CBID_INDTILE_ANIM_START_STOP
Called for periodically starting or stopping the animation.
@ CBID_INDTILE_ANIM_NEXT_FRAME
Called to determine industry tile next animation frame.
@ CBID_INDTILE_SHAPE_CHECK
Called to determine if the given industry tile can be built on specific tile.
@ CBID_INDTILE_DRAW_FOUNDATIONS
Called to determine the type (if any) of foundation to draw for industry tile.
@ CBID_RANDOM_TRIGGER
Set when calling a randomizing trigger (almost undocumented).
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
uint32_t GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
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...
IndustryAvailabilityCallType
From where has callback CBID_INDUSTRY_PROBABILITY been called.
uint32_t GetNearbyIndustryTileInformation(uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
void TriggerIndustry(Industry *ind, IndustryTileTrigger trigger)
Trigger a random trigger for all industry tiles.
static void DoTriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger, Industry *ind, uint32_t &reseed_industry)
Trigger random triggers for an industry tile and reseed its random bits.
uint32_t GetRelativePosition(TileIndex tile, TileIndex ind_tile)
This is the position of the tile relative to the northernmost tile of the industry.
CommandCost PerformIndustryTileSlopeCheck(TileIndex ind_base_tile, TileIndex ind_tile, const IndustryTileSpec *its, IndustryType type, IndustryGfx gfx, size_t layout_index, uint16_t initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
Check the slope of a tile of a new industry.
static const GRFFile * GetIndTileGrffile(IndustryGfx gfx)
Get the associated NewGRF file from the industry graphics.
static void DoReseedIndustry(Industry *ind, uint32_t reseed)
Reseeds the random bits of an industry.
void TriggerIndustryTile(TileIndex tile, IndustryTileTrigger trigger)
Trigger a random trigger for a single industry tile.
uint32_t GetNearbyIndustryTileInformation(uint8_t parameter, TileIndex tile, IndustryID index, bool signed_offsets, bool grf_version8)
Based on newhouses equivalent, but adapted for newindustries.
NewGRF handling of industry tiles.
IndustryTileTrigger
Available industry tile triggers.
Functions related to NewGRF provided sounds.
@ VSG_SCOPE_SELF
Resolved object itself.
@ VSG_SCOPE_PARENT
Related object of the resolved one.
A number of safeguards to prevent using unsafe methods.
Slope
Enumeration for the slope-type.
@ FOUNDATION_LEVELED
The tile is leveled up to a flat slope.
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition of base types and functions in a cross-platform compatible way.
Helper class for a unified approach to NewGRF animation.
static void AnimateTile(const IndustryTileSpec *spec, Industry *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
static void ChangeAnimationFrame(CallbackID cb, const IndustryTileSpec *spec, Industry *obj, TileIndex tile, uint32_t random_bits, uint32_t trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
uint16_t triggers
The triggers that trigger animation.
Ground palette sprite of a tile, together with its sprite layout.
PalSpriteID ground
Palette and sprite for the ground.
uint16_t local_id
id defined by the grf file for this entity
const struct GRFFile * grffile
grf file that introduced this entity
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
Dynamic data of a loaded NewGRF.
Helper class for animation control.
Resolver for industry tiles.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
IndustryTileResolverObject(IndustryGfx gfx, TileIndex tile, Industry *indus, CallbackID callback=CBID_NO_CALLBACK, uint32_t callback_param1=0, uint32_t callback_param2=0)
Constructor of the industry tiles scope resolver.
uint32_t GetTriggers() const override
Get the triggers.
uint32_t GetRandomBits() const override
Get a few random bits.
Industry * industry
Industry owning the tiles.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Get a variable value.
TileIndex tile
Tile being resolved.
Defines the data structure of each individual tile of an industry.
IndustryTileSpecialFlags special_flags
Bitmask of extra flags used by the tile.
GRFFileProps grf_prop
properties related to the grf file
Slope slopes_refused
slope pattern on which this tile cannot be built
AnimationInfo animation
Information about the animation (is it looping, how many loops etc)
uint8_t callback_mask
Bitmask of industry tile callbacks that have to be called.
Defines the internal data of a functional industry.
IndustryType type
type of industry.
Colours random_colour
randomized colour of the industry, for display purpose
uint16_t random
Random value used for randomisation of all kinds of things.
Owner founder
Founder of the industry.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
TileArea location
Location of the industry.
bool TileBelongsToIndustry(TileIndex tile) const
Check if a given tile belongs to this industry.
uint16_t w
The width of the area.
TileIndex tile
The base tile of the area.
SpriteID sprite
The 'real' sprite.
PaletteID pal
The palette (use PAL_NONE) if not needed)
Tindex index
Index of this pool item.
Interface for SpriteGroup-s to access the gamestate.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
ResolverObject & ro
Surrounding resolver object.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Tile information, used while rendering the tile.
Slope tileh
Slope of the tile.
TileIndex tile
Tile index.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
const DrawTileSprites * ProcessRegisters(uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
bool IsValidTile(Tile tile)
Checks if a tile is valid.
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
@ MP_INDUSTRY
Part of an industry.
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
@ TO_INDUSTRIES
industries
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Functions related to water (management)
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.