44 return &_object_specs[index];
102 MemCpyT(_object_specs, _original_objects,
lengthof(_original_objects));
104 for (uint16 i = 0; i <
lengthof(_original_objects); i++) {
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;
191 if (o->
type != type || o == current)
continue;
238 const Town *t = NULL;
240 if (this->obj == NULL) {
258 case 0x42:
return _date;
264 case 0x48:
return this->view;
286 uint offset = this->tile - this->obj->location.tile;
287 uint offset_x =
TileX(offset);
288 uint offset_y =
TileY(offset);
289 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
296 case 0x42:
return this->obj->build_date;
311 case 0x47:
return this->obj->colour;
314 case 0x48:
return this->obj->view;
339 DEBUG(grf, 1,
"Unhandled object variable 0x%X", variable);
355 CallbackID callback, uint32 param1, uint32 param2)
363 ObjectResolverObject::~ObjectResolverObject()
382 if (t == NULL)
return NULL;
402 return object.ResolveCallback();
423 DrawWaterClassGround(ti);
443 if (group == NULL || group->type != SGT_TILELAYOUT)
return;
459 if (group == NULL || group->type != SGT_TILELAYOUT)
return;
Implementation of the NewGRF class' functions.
uint32 PaletteID
The number of the palette.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition of stuff that is very close to a company, like the company struct itself.
Maximum number of classes.
Object wants 2CC colour mapping.
ObjectFlags flags
Flags/settings related to the object.
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Tile information, used while rendering the tile.
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
bool IsAvailable() const
Check whether the object is available at this time.
byte landscape
the landscape we're currently in
decides next animation frame
uint16 triggers
The triggers that trigger animation.
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
static Titem * Get(size_t index)
Returns Titem with given index.
Town * town
Town the object is built in.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Functions related to debugging.
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
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 ...
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode...
static void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
Draw NewGRF object in GUI.
static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
Implementation of var 65.
static uint TileX(TileIndex tile)
Get the X component of a tile.
byte colour
Colour of the object, for display purpose.
Object wants to be drawn on water.
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
Force instantiation of the methods so we don't get linker errors.
Determine the next animation frame for a house.
Allow incrementing of ObjectClassID variables.
Date end_of_life_date
When can't this object be built anymore.
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Functions related to world/map generation.
Contains objects such as transmitters and owned land.
Date introduction_date
From when can this object be built.
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.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
static const ObjectID INVALID_OBJECT
An invalid object.
static void AnimateTile(const ObjectSpec *spec, Object *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to NewGRF objects.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
ObjectCallbackMask
Callback masks for objects.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold...
void ResetObjects()
This function initialize the spec arrays of objects.
ObjectScopeResolver object_scope
The object scope resolver.
Struct containing information relating to NewGRF classes for stations and airports.
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.
bool enabled
Is this spec enabled?
TileIndex xy
town center tile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a give tiletype.
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
TileIndex tile
Tile index.
Object can only be built in game.
struct Object * obj
The object the callback is ran for.
Ground palette sprite of a tile, together with its sprite layout.
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
TileIndex tile
The tile related to the object.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Object can only be constructed in the scenario editor.
AnimationInfo animation
Information about the animation.
uint Index() const
Gets the index of this spec.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
Function implementations related to NewGRF animation.
Map accessors for object tiles.
Called to indicate how long the current animation frame should last.
A number of safeguards to prevent using unsafe methods.
Scope resolver for a town.
static PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
An object, such as transmitter, on the map.
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Information about a particular livery.
static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
Make an analysis of a tile and get the object 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.
#define lengthof(x)
Return the length of an fixed size array.
static T min(const T a, const T b)
Returns the minimum of two values.
number of bits for the sprite number
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
uint16 ObjectType
Types of objects.
Object wants random bits in "next animation frame" callback.
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.
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
byte colour2
Second colour, for vehicles with 2CC support.
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Object has animated tiles.
uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
Perform a callback for an object.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
#define DEBUG(name, level,...)
Output a line of debugging information.
const ObjectSpec _original_objects[]
Specification of the original object structures.
TileIndex tile
The base tile of the area.
Functions related to companies.
PalSpriteID ground
Palette and sprite for the ground.
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
bool _generating_world
Whether we are generating the map or not.
uint32 ObjectID
Unique identifier for an object.
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
CompanyByte _current_company
Company currently doing an action.
uint32 TileIndex
The index/ID of a Tile.
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Helper class for a unified approach to NewGRF animation.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
static uint TileY(TileIndex tile)
Get the Y component of a tile.
TileArea location
Location of the object.
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.
ObjectType type
Type of the object.
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Used by the resolver to get values for feature 0F deterministic spritegroups.
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
other objects such as transmitters and lighthouses
ObjectAnimationTrigger
Animation triggers for objects.
Helper class for animation control.
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.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
uint16 local_id
id defined by the grf file for this entity
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
static void InsertDefaults()
Initialise the defaults.
A resolver object to be used with feature 0F spritegroups.
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.
Functions related to NewGRF provided sounds.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
byte colour1
First colour, for all vehicles.
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
byte view
The view setting for this object.
Functions related to water (management)
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
SpriteID sprite
The 'real' sprite.
ObjectClassID cls_id
The class to which this spec belongs.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Date _date
Current date in days (day counter)
uint8 climate
In which climates is this object available?
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Generic 'commands' that can be performed on all tiles.
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Called for periodically starting or stopping the animation.
static void MemSetT(T *ptr, byte value, size_t num=1)
Type-safe version of memset().
ObjectClassID
Class IDs for objects.
PaletteID pal
The palette (use PAL_NONE) if not needed)
StringID name
Name of this class.