Go to the documentation of this file.
109 template <
typename Tspec,
typename T
id, T
id Tmax>
117 cls = ObjectClass::Allocate(
'TRNS');
123 template <
typename Tspec,
typename T
id, T
id Tmax>
126 return this->GetSpec(index)->IsEverAvailable();
188 uint32 best_dist = UINT32_MAX;
190 if (o->type != type || o == current)
continue;
237 const Town *t =
nullptr;
239 if (this->
obj ==
nullptr) {
257 case 0x42:
return _date;
263 case 0x48:
return this->
view;
286 uint offset_x =
TileX(offset);
287 uint offset_y =
TileY(offset);
288 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
313 case 0x48:
return this->
obj->
view;
338 DEBUG(grf, 1,
"Unhandled object variable 0x%X", variable);
354 CallbackID callback, uint32 param1, uint32 param2)
355 :
ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
362 ObjectResolverObject::~ObjectResolverObject()
381 if (t ==
nullptr)
return nullptr;
411 return object.ResolveCallback();
432 DrawWaterClassGround(ti);
452 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
468 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
A resolver object to be used with feature 0F spritegroups.
@ OBJECT_FLAG_ANIMATION
Object has animated tiles.
byte colour
Colour of the object, for display purpose.
uint32 TileIndex
The index/ID of a Tile.
@ CBM_OBJ_ANIMATION_SPEED
decides animation speed
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
@ OBJECT_FLAG_ONLY_IN_SCENEDIT
Object can only be constructed in the scenario editor.
static Titem * Get(size_t index)
Returns Titem with given index.
@ CBID_OBJECT_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
@ OBJECT_FLAG_2CC_COLOUR
Object wants 2CC colour mapping.
Allow incrementing of ObjectClassID variables.
static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
Make an analysis of a tile and get the object type.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Tile information, used while rendering the tile.
@ SPRITE_WIDTH
number of bits for the sprite number
byte landscape
the landscape we're currently in
ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view=0, CallbackID callback=CBID_NO_CALLBACK, uint32 param1=0, uint32 param2=0)
Constructor of the object resolver.
@ CBM_OBJ_ANIMATION_NEXT_FRAME
decides next animation frame
TileArea location
Location of the object.
static void ChangeAnimationFrame(CallbackID cb, const ObjectSpec *spec, Object *obj, TileIndex tile, uint32 random_bits, uint32 trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
ObjectAnimationTrigger
Animation triggers for objects.
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Tindex index
Index of this pool item.
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
struct Object * obj
The object the callback is ran for.
bool IsAvailable() const
Check whether the object is available at this time.
uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
Perform a callback for an object.
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
Force instantiation of the methods so we don't get linker errors.
SpriteID sprite
The 'real' sprite.
Interface for SpriteGroup-s to access the gamestate.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Date end_of_life_date
When can't this object be built anymore.
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
TileIndex xy
town center tile
static void AnimateTile(const ObjectSpec *spec, Object *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
CallbackID
List of implemented NewGRF callbacks.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
Helper class for animation control.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
TileIndex tile
The tile related to the object.
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
AnimationInfo animation
Information about the animation.
static uint TileX(TileIndex tile)
Get the X component of a tile.
GameCreationSettings game_creation
settings used during the creation of a game (map)
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Date introduction_date
From when can this object be built.
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
PalSpriteID ground
Palette and sprite for the ground.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
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.
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Date _date
Current date in days (day counter)
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
ObjectClassID
Class IDs for objects.
#define DEBUG(name, level,...)
Output a line of debugging information.
uint16 ObjectType
Types of objects.
@ MP_OBJECT
Contains objects such as transmitters and owned land.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
byte view
The view setting for this object.
static const ObjectID INVALID_OBJECT
An invalid object.
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
An object, such as transmitter, on the map.
Struct containing information relating to NewGRF classes for stations and airports.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ObjectType type
Type of the object.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
const ObjectSpec _original_objects[]
Specification of the original object structures.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Ground palette sprite of a tile, together with its sprite layout.
static void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
Draw NewGRF object in GUI.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Scope resolver for a town.
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
bool enabled
Is this spec enabled?
static void InsertDefaults()
Initialise the defaults.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
uint8 view
The view of the object.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
bool _generating_world
Whether we are generating the map or not.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
@ OBJECT_CLASS_MAX
Maximum number of classes.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
uint Index() const
Gets the index of this spec.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
Implementation of var 65.
CompanyID _current_company
Company currently doing an action.
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
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
TileIndex tile
The base tile of the area.
uint32 PaletteID
The number of the palette.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Used by the resolver to get values for feature 0F deterministic spritegroups.
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
@ CBID_OBJECT_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
@ OBJECT_FLAG_ANIM_RANDOM_BITS
Object wants random bits in "next animation frame" callback.
StringID name
Name of this class.
ObjectCallbackMask
Callback masks for objects.
uint16 triggers
The triggers that trigger animation.
uint32 ObjectID
Unique identifier for an object.
@ CBID_OBJECT_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Helper class for a unified approach to NewGRF animation.
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
void ResetObjects()
This function initialize the spec arrays of objects.
#define lengthof(x)
Return the length of an fixed size array.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
@ OBJECT_FLAG_DRAW_WATER
Object wants to be drawn on water.
const ObjectSpec * spec
Specification of the object type.
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
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.
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
uint16 local_id
id defined by the grf file for this entity
PaletteID pal
The palette (use PAL_NONE) if not needed)
TileIndex tile
Tile index.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
ResolverObject & ro
Surrounding resolver object.
const struct GRFFile * grffile
grf file that introduced this entity
uint8 climate
In which climates is this object available?
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Date build_date
Date of construction.
Information about a particular livery.
Town * town
Town the object is built in.
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
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.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
ObjectClassID cls_id
The class to which this spec belongs.
ObjectScopeResolver object_scope
The object scope resolver.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
@ OBJECT_FLAG_ONLY_IN_GAME
Object can only be built in game.
byte colour2
Second colour, for vehicles with 2CC support.
ObjectFlags flags
Flags/settings related to the object.
byte colour1
First colour, for all vehicles.
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.