35const std::vector<ObjectSpec> &ObjectSpec::Specs()
40size_t ObjectSpec::Count()
129 for (uint16_t i = 0; i <
lengthof(_original_objects); i++) {
149 return this->
GetSpec(index)->IsEverAvailable();
212 uint32_t best_dist = UINT32_MAX;
214 if (o->type != type || o == current)
continue;
261 const Town *t =
nullptr;
263 if (this->
obj ==
nullptr) {
287 case 0x48:
return this->
view;
310 uint offset_x =
TileX(offset);
311 uint offset_y =
TileY(offset);
312 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
337 case 0x48:
return this->
obj->
view;
362 Debug(grf, 1,
"Unhandled object variable 0x{:X}", variable);
378 CallbackID callback, uint32_t param1, uint32_t param2)
379 :
ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
399 if (t ==
nullptr)
return nullptr;
429 return object.ResolveCallback();
450 DrawWaterClassGround(ti);
470 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
486 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
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.
Struct containing information relating to NewGRF classes for stations and airports.
static void Assign(Tspec *spec)
Assign a spec to one of the classes.
StringID name
Name of this class.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
static void InsertDefaults()
Initialise the defaults.
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
static Date date
Current date in days (day counter).
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
CompanyID _current_company
Company currently doing an action.
Functions related to companies.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32_t PaletteID
The number of the palette.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
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.
Function implementations related to NewGRF animation.
ObjectAnimationTrigger
Animation triggers for objects.
CallbackID
List of implemented NewGRF callbacks.
@ CBID_OBJECT_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
@ CBID_OBJECT_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
@ CBID_OBJECT_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
ObjectCallbackMask
Callback masks for objects.
@ CBM_OBJ_ANIMATION_NEXT_FRAME
decides next animation frame
@ CBM_OBJ_ANIMATION_SPEED
decides animation speed
Implementation of the NewGRF class' functions.
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
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.
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 ...
std::vector< ObjectSpec > _object_specs
All the object specifications.
void ResetObjects()
This function initialize the spec arrays of objects.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
Make an analysis of a tile and get the object type.
uint16_t StubGetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, int)
Perform a callback for an object.
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view)
Perform a callback for an object.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current)
Implementation of var 65.
static uint32_t GetNearbyObjectTileInformation(uint8_t parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Functions related to NewGRF objects.
@ OBJECT_FLAG_2CC_COLOUR
Object wants 2CC colour mapping.
@ OBJECT_FLAG_ANIMATION
Object has animated tiles.
@ OBJECT_FLAG_ANIM_RANDOM_BITS
Object wants random bits in "next animation frame" callback.
@ OBJECT_FLAG_ONLY_IN_GAME
Object can only be built in game.
@ OBJECT_FLAG_DRAW_WATER
Object wants to be drawn on water.
@ OBJECT_FLAG_ONLY_IN_SCENEDIT
Object can only be constructed in the scenario editor.
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
Functions related to NewGRF provided sounds.
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Map accessors for object tiles.
uint8_t GetObjectRandomBits(Tile t)
Get the random bits of this tile.
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
uint16_t ObjectType
Types of objects.
uint32_t ObjectID
Unique identifier for an object.
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
static const ObjectID INVALID_OBJECT
An invalid object.
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
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.
#define lengthof(array)
Return the length of an fixed size array.
Helper class for a unified approach to NewGRF animation.
static void AnimateTile(const ObjectSpec *spec, Object *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
static void ChangeAnimationFrame(CallbackID cb, const ObjectSpec *spec, Object *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.
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
uint8_t landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
Information about a particular livery.
Colours colour2
Second colour, for vehicles with 2CC support.
Colours colour1
First colour, for all vehicles.
uint16_t index
Index within class of this spec, invalid until inserted into class.
Helper class for animation control.
A resolver object to be used with feature 0F spritegroups.
ObjectScopeResolver object_scope
The object scope resolver.
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view=0, CallbackID callback=CBID_NO_CALLBACK, uint32_t param1=0, uint32_t param2=0)
Constructor of the object resolver.
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
uint32_t GetVariable(uint8_t variable, uint32_t parameter, bool &available) const override
Used by the resolver to get values for feature 0F deterministic spritegroups.
TileIndex tile
The tile related to the object.
uint8_t view
The view of the object.
uint32_t GetRandomBits() const override
Get a few random bits.
const ObjectSpec * spec
Specification of the object type.
struct Object * obj
The object the callback is ran for.
Allow incrementing of ObjectClassID variables.
AnimationInfo animation
Information about the animation.
bool IsEnabled() const
Test if this object is enabled.
TimerGameCalendar::Date introduction_date
From when can this object be built.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
bool IsAvailable() const
Check whether the object is available at this time.
uint Index() const
Gets the index of this spec.
static void BindToClasses()
Tie all ObjectSpecs to their class.
uint8_t climate
In which climates is this object available?
ObjectFlags flags
Flags/settings related to the object.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
TimerGameCalendar::Date end_of_life_date
When can't this object be built anymore.
An object, such as transmitter, on the map.
ObjectType type
Type of the object.
Town * town
Town the object is built in.
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
TimerGameCalendar::Date build_date
Date of construction.
uint8_t view
The view setting for this object.
TileArea location
Location of the object.
uint8_t colour
Colour of the object, for display purpose.
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.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(size_t index)
Returns Titem with given index.
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.
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.
Scope resolver for a town.
TileIndex xy
town center tile
Generic 'commands' that can be performed on all tiles.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
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.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition of the game-calendar-timer.
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_STRUCTURES
other objects such as transmitters and lighthouses
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.