OpenTTD Source 20250218-master-g53dd1258a7
newgrf_object.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "company_base.h"
12#include "company_func.h"
13#include "debug.h"
14#include "genworld.h"
15#include "newgrf_badge.h"
16#include "newgrf_object.h"
17#include "newgrf_class_func.h"
18#include "newgrf_sound.h"
19#include "object_base.h"
20#include "object_map.h"
22#include "tile_cmd.h"
23#include "town.h"
24#include "water.h"
26
27#include "safeguards.h"
28
31
32extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET];
34std::vector<ObjectSpec> _object_specs;
35
36const std::vector<ObjectSpec> &ObjectSpec::Specs()
37{
38 return _object_specs;
39}
40
41size_t ObjectSpec::Count()
42{
43 return _object_specs.size();
44}
45
51/* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
52{
53 /* Empty object if index is out of range -- this might happen if NewGRFs are changed. */
54 static ObjectSpec empty = {};
55
56 assert(index < NUM_OBJECTS);
57 if (index >= _object_specs.size()) return &empty;
58 return &_object_specs[index];
59}
60
67{
68 return ObjectSpec::Get(GetObjectType(tile));
69}
70
76{
78 !this->flags.Test((_game_mode != GM_EDITOR && !_generating_world) ? ObjectFlag::OnlyInScenedit : ObjectFlag::OnlyInGame);
79}
80
89
95{
96 return this->WasEverAvailable() &&
98}
99
105{
106 return this - _object_specs.data();
107}
108
112/* static */ void ObjectSpec::BindToClasses()
113{
114 for (auto &spec : _object_specs) {
115 if (spec.IsEnabled() && spec.class_index != INVALID_OBJECT_CLASS) {
116 ObjectClass::Assign(&spec);
117 }
118 }
119}
120
123{
124 /* Clean the pool. */
125 _object_specs.clear();
126
127 /* And add our originals. */
128 _object_specs.reserve(lengthof(_original_objects));
129
130 for (uint16_t i = 0; i < lengthof(_original_objects); i++) {
131 ObjectSpec &spec = _object_specs.emplace_back(_original_objects[i]);
132 spec.grf_prop.local_id = i;
133 }
134
135 /* Set class for originals. */
138}
139
140template <>
141/* static */ void ObjectClass::InsertDefaults()
142{
143 ObjectClass::Get(ObjectClass::Allocate('LTHS'))->name = STR_OBJECT_CLASS_LTHS;
144 ObjectClass::Get(ObjectClass::Allocate('TRNS'))->name = STR_OBJECT_CLASS_TRNS;
145}
146
147template <>
148bool ObjectClass::IsUIAvailable(uint index) const
149{
150 return this->GetSpec(index)->IsEverAvailable();
151}
152
153/* Instantiate ObjectClass. */
155
156/* virtual */ uint32_t ObjectScopeResolver::GetRandomBits() const
157{
158 return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;
159}
160
167static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
168{
169 if (!IsTileType(tile, MP_OBJECT)) {
170 return 0xFFFF;
171 }
172
173 const Object *o = Object::GetByTile(tile);
174 const ObjectSpec *spec = ObjectSpec::Get(o->type);
175
176 /* Default objects have no associated NewGRF file */
177 if (!spec->grf_prop.HasGrfFile()) {
178 return 0xFFFE; // Defined in another grf file
179 }
180
181 if (spec->grf_prop.grfid == cur_grfid) { // same object, same grf ?
182 return spec->grf_prop.local_id | o->view << 16;
183 }
184
185 return 0xFFFE; // Defined in another grf file
186}
187
196static uint32_t GetNearbyObjectTileInformation(uint8_t parameter, TileIndex tile, ObjectID index, bool grf_version8)
197{
198 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
199 bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
200
201 return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
202}
203
211static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
212{
213 uint32_t best_dist = UINT32_MAX;
214 for (const Object *o : Object::Iterate()) {
215 if (o->type != type || o == current) continue;
216
217 best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
218 }
219
220 return best_dist;
221}
222
231static uint32_t GetCountAndDistanceOfClosestInstance(uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current)
232{
233 uint32_t grf_id = GetRegister(0x100); // Get the GRFID of the definition to look for in register 100h
234 uint32_t idx;
235
236 /* Determine what will be the object type to look for */
237 switch (grf_id) {
238 case 0: // this is a default object type
239 idx = local_id;
240 break;
241
242 case 0xFFFFFFFF: // current grf
243 grf_id = grfid;
244 [[fallthrough]];
245
246 default: // use the grfid specified in register 100h
247 idx = _object_mngr.GetID(local_id, grf_id);
248 break;
249 }
250
251 /* If the object type is invalid, there is none and the closest is far away. */
252 if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
253
254 return Object::GetTypeCount(idx) << 16 | ClampTo<uint16_t>(GetClosestObject(tile, idx, current));
255}
256
258/* virtual */ uint32_t ObjectScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
259{
260 /* We get the town from the object, or we calculate the closest
261 * town if we need to when there's no object. */
262 const Town *t = nullptr;
263
264 if (this->obj == nullptr) {
265 switch (variable) {
266 /* Allow these when there's no object. */
267 case 0x41:
268 case 0x60:
269 case 0x61:
270 case 0x62:
271 case 0x64:
272 break;
273
274 /* Allow these, but find the closest town. */
275 case 0x45:
276 case 0x46:
277 if (!IsValidTile(this->tile)) goto unhandled;
278 t = ClosestTownFromTile(this->tile, UINT_MAX);
279 break;
280
281 /* Construction date */
282 case 0x42: return TimerGameCalendar::date.base();
283
284 /* Object founder information */
285 case 0x44: return _current_company.base();
286
287 /* Object view */
288 case 0x48: return this->view;
289
290 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
291
292 /*
293 * Disallow the rest:
294 * 0x40: Relative position is passed as parameter during construction.
295 * 0x43: Animation counter is only for actual tiles.
296 * 0x47: Object colour is only valid when its built.
297 * 0x63: Animation counter of nearby tile, see above.
298 */
299 default:
300 goto unhandled;
301 }
302
303 /* If there's an invalid tile, then we don't have enough information at all. */
304 if (!IsValidTile(this->tile)) goto unhandled;
305 } else {
306 t = this->obj->town;
307 }
308
309 switch (variable) {
310 /* Relative position. */
311 case 0x40: {
312 TileIndex offset = this->tile - this->obj->location.tile;
313 uint offset_x = TileX(offset);
314 uint offset_y = TileY(offset);
315 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
316 }
317
318 /* Tile information. */
319 case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
320
321 /* Construction date */
322 case 0x42: return this->obj->build_date.base();
323
324 /* Animation counter */
325 case 0x43: return GetAnimationFrame(this->tile);
326
327 /* Object founder information */
328 case 0x44: return GetTileOwner(this->tile).base();
329
330 /* Get town zone and Manhattan distance of closest town */
331 case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy));
332
333 /* Get square of Euclidean distance of closest town */
334 case 0x46: return DistanceSquare(this->tile, t->xy);
335
336 /* Object colour */
337 case 0x47: return this->obj->colour;
338
339 /* Object view */
340 case 0x48: return this->obj->view;
341
342 /* Get object ID at offset param */
343 case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
344
345 /* Get random tile bits at offset param */
346 case 0x61: {
347 TileIndex tile = GetNearbyTile(parameter, this->tile);
348 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
349 }
350
351 /* Land info of nearby tiles */
352 case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? ObjectID::Invalid() : this->obj->index, this->ro.grffile->grf_version >= 8);
353
354 /* Animation counter of nearby tile */
355 case 0x63: {
356 TileIndex tile = GetNearbyTile(parameter, this->tile);
357 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
358 }
359
360 /* Count of object, distance of closest instance */
361 case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj);
362
363 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
364 }
365
366unhandled:
367 Debug(grf, 1, "Unhandled object variable 0x{:X}", variable);
368
369 available = false;
370 return UINT_MAX;
371}
372
383 CallbackID callback, uint32_t param1, uint32_t param2)
384 : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
385{
386 this->root_spritegroup = (obj == nullptr) ? spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_PURCHASE) : nullptr;
387 if (this->root_spritegroup == nullptr) this->root_spritegroup = spec->grf_prop.GetSpriteGroup(OBJECT_SPRITE_GROUP_DEFAULT);
388}
389
396{
397 if (!this->town_scope.has_value()) {
398 Town *t;
399 if (this->object_scope.obj != nullptr) {
400 t = this->object_scope.obj->town;
401 } else {
402 t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
403 }
404 if (t == nullptr) return nullptr;
405 this->town_scope.emplace(*this, t, this->object_scope.obj == nullptr);
406 }
407 return &*this->town_scope;
408}
409
411{
412 return GSF_OBJECTS;
413}
414
416{
417 return this->object_scope.spec->grf_prop.local_id;
418}
419
431uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8_t view)
432{
433 ObjectResolverObject object(spec, o, tile, view, callback, param1, param2);
434 return object.ResolveCallback();
435}
436
443static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
444{
445 const DrawTileSprites *dts = group->ProcessRegisters(nullptr);
446 PaletteID palette = (spec->flags.Test(ObjectFlag::Uses2CC) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START) + Object::GetByTile(ti->tile)->colour;
447
448 SpriteID image = dts->ground.sprite;
449 PaletteID pal = dts->ground.pal;
450
451 if (GB(image, 0, SPRITE_WIDTH) != 0) {
452 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
453 * Do not do this if the tile's WaterClass is 'land'. */
454 if ((image == SPR_FLAT_WATER_TILE || spec->flags.Test(ObjectFlag::DrawWater)) && IsTileOnWater(ti->tile)) {
455 DrawWaterClassGround(ti);
456 } else {
457 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
458 }
459 }
460
461 DrawNewGRFTileSeq(ti, dts, TO_STRUCTURES, 0, palette);
462}
463
470{
471 Object *o = Object::GetByTile(ti->tile);
472 ObjectResolverObject object(spec, o, ti->tile);
473
474 const SpriteGroup *group = object.Resolve();
475 if (group == nullptr || group->type != SGT_TILELAYOUT) return;
476
477 DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec);
478}
479
487void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
488{
489 ObjectResolverObject object(spec, nullptr, INVALID_TILE, view);
490 const SpriteGroup *group = object.Resolve();
491 if (group == nullptr || group->type != SGT_TILELAYOUT) return;
492
493 const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr);
494
495 PaletteID palette;
497 /* Get the colours of our company! */
498 if (spec->flags.Test(ObjectFlag::Uses2CC)) {
499 const Livery *l = Company::Get(_local_company)->livery;
500 palette = SPR_2CCMAP_BASE + l->colour1 + l->colour2 * 16;
501 } else {
502 palette = COMPANY_SPRITE_COLOUR(_local_company);
503 }
504 } else {
505 /* There's no company, so just take the base palette. */
506 palette = spec->flags.Test(ObjectFlag::Uses2CC) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START;
507 }
508
509 SpriteID image = dts->ground.sprite;
510 PaletteID pal = dts->ground.pal;
511
512 if (GB(image, 0, SPRITE_WIDTH) != 0) {
513 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
514 }
515
516 DrawNewGRFTileSeqInGUI(x, y, dts, 0, palette);
517}
518
529uint16_t StubGetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, int)
530{
531 return GetObjectCallback(callback, param1, param2, spec, o, tile);
532}
533
542
548{
549 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
550 if (spec == nullptr || !spec->flags.Test(ObjectFlag::Animation)) return;
551
553}
554
563{
564 if (!HasBit(spec->animation.triggers, trigger)) return;
565
567}
568
576{
577 if (!HasBit(spec->animation.triggers, trigger)) return;
578
579 for (TileIndex tile : o->location) {
580 TriggerObjectTileAnimation(o, tile, trigger, spec);
581 }
582}
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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
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,...)
Output a line of debugging information.
Definition debug.h:37
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:72
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.
Definition gfx.cpp:988
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
@ Random
Randomise borders.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition map.cpp:160
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:143
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:424
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:414
GrfSpecFeature
Definition newgrf.h:69
Function implementations related to NewGRF animation.
ObjectAnimationTrigger
Animation triggers for objects.
uint32_t GetBadgeVariableResult(const GRFFile &grffile, std::span< const BadgeID > badges, uint32_t parameter)
Test for a matching badge in a list of badges, returning the number of matching bits.
Functions related to NewGRF badges.
@ DrawTileLayout
Use callback to select a tile layout to use when drawing.
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.
@ AnimationNextFrame
decides next animation frame
@ AnimationSpeed
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 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.
@ AnimRandomBits
Object wants random bits in "next animation frame" callback.
@ OnlyInScenedit
Object can only be constructed in the scenario editor.
@ OnlyInGame
Object can only be built in game.
@ DrawWater
Object wants to be drawn on water.
@ Uses2CC
Object wants 2CC colour mapping.
@ Animation
Object has animated tiles.
@ 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".
Base for all objects.
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.
Definition object_map.h:59
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition object_map.h:47
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition object_type.h:19
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition object_type.h:27
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition object_type.h:25
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition object_type.h:18
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition object_type.h:24
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:58
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition sprite.h:130
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:139
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:174
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition sprites.h:1574
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition sprites.h:1535
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:277
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.
Definition sprite.h:46
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:47
const struct SpriteGroup * GetSpriteGroup(size_t index=0) const
Get the SpriteGroup at the specified index.
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
LandscapeType landscape
the landscape we're currently in
GameCreationSettings game_creation
settings used during the creation of a game (map)
Information about a particular livery.
Definition livery.h:78
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:81
Colours colour1
First colour, for all vehicles.
Definition livery.h:80
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.
LandscapeTypes climate
In which climates is this object available?
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.
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.
ObjectFlags flags
Flags/settings related to the object.
FixedGRFFileProps< 2 > grf_prop
Properties related the the grf file.
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.
Definition object_base.h:23
ObjectType type
Type of the object.
Definition object_base.h:24
Town * town
Town the object is built in.
Definition object_base.h:25
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition object_base.h:65
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:27
uint8_t view
The view setting for this object.
Definition object_base.h:29
TileArea location
Location of the object.
Definition object_base.h:26
uint8_t colour
Colour of the object, for display purpose.
Definition object_base.h:28
TileIndex tile
The base tile of the area.
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Tindex index
Index of this pool item.
static Titem * Get(auto index)
Returns Titem with given index.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
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.
Definition tile_cmd.h:43
TileIndex tile
Tile index.
Definition tile_cmd.h:47
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.
Definition newgrf_town.h:22
Town data structure.
Definition town.h:52
TileIndex xy
town center tile
Definition town.h:53
Generic 'commands' that can be performed on all tiles.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
Definition of the game-calendar-timer.
Base of the town class.
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.
Definition viewport.cpp:587
Functions related to water (management)
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:136