OpenTTD Source: src/newgrf_object.cpp Source File

OpenTTD Source 14.1

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_object.h"
16 #include "newgrf_class_func.h"
17 #include "newgrf_sound.h"
18 #include "object_base.h"
19 #include "object_map.h"
20 #include "timer/timer_game_calendar.h"
21 #include "tile_cmd.h"
22 #include "town.h"
23 #include "water.h"
24 #include "newgrf_animation_base.h"
25
26 #include "safeguards.h"
27
29 ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE);
30
31 extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET];
33 std::vector<ObjectSpec> _object_specs;
34
35 const std::vector<ObjectSpec> &ObjectSpec::Specs()
36 {
37 return _object_specs;
38 }
39
40 size_t ObjectSpec::Count()
41 {
42 return _object_specs.size();
43 }
44
50 /* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
51 {
52 /* Empty object if index is out of range -- this might happen if NewGRFs are changed. */
53 static ObjectSpec empty = {};
54
55 assert(index < NUM_OBJECTS);
56 if (index >= _object_specs.size()) return &empty;
57 return &_object_specs[index];
58 }
59
65 /* static */ const ObjectSpec *ObjectSpec::GetByTile(TileIndex tile)
66 {
67 return ObjectSpec::Get(GetObjectType(tile));
68 }
69
74 bool ObjectSpec::IsEverAvailable() const
75 {
76 return this->IsEnabled() && HasBit(this->climate, _settings_game.game_creation.landscape) &&
77 (this->flags & ((_game_mode != GM_EDITOR && !_generating_world) ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
78 }
79
84 bool ObjectSpec::WasEverAvailable() const
85 {
86 return this->IsEverAvailable() && TimerGameCalendar::date > this->introduction_date;
87 }
88
93 bool ObjectSpec::IsAvailable() const
94 {
95 return this->WasEverAvailable() &&
96 (TimerGameCalendar::date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365);
97 }
98
103 uint ObjectSpec::Index() const
104 {
105 return this - _object_specs.data();
106 }
107
111 /* static */ void ObjectSpec::BindToClasses()
112 {
113 for (auto &spec : _object_specs) {
114 if (spec.IsEnabled() && spec.cls_id != INVALID_OBJECT_CLASS) {
115 ObjectClass::Assign(&spec);
116 }
117 }
118 }
119
121 void ResetObjects()
122 {
123 /* Clean the pool. */
124 _object_specs.clear();
125
126 /* And add our originals. */
127 _object_specs.reserve(lengthof(_original_objects));
128
129 for (uint16_t i = 0; i < lengthof(_original_objects); i++) {
130 ObjectSpec &spec = _object_specs.emplace_back(_original_objects[i]);
131 spec.grf_prop.local_id = i;
132 }
133
134 /* Set class for originals. */
135 _object_specs[OBJECT_LIGHTHOUSE].cls_id = ObjectClass::Allocate('LTHS');
136 _object_specs[OBJECT_TRANSMITTER].cls_id = ObjectClass::Allocate('TRNS');
137 }
138
139 template <typename Tspec, typename Tid, Tid Tmax>
140 /* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
141 {
142 ObjectClass::Get(ObjectClass::Allocate('LTHS'))->name = STR_OBJECT_CLASS_LTHS;
143 ObjectClass::Get(ObjectClass::Allocate('TRNS'))->name = STR_OBJECT_CLASS_TRNS;
144 }
145
146 template <typename Tspec, typename Tid, Tid Tmax>
147 bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
148 {
149 return this->GetSpec(index)->IsEverAvailable();
150 }
151
152 INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX)
153
154 /* virtual */ uint32_t ObjectScopeResolver::GetRandomBits() const
155 {
156 return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;
157 }
158
165 static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
166 {
167 if (!IsTileType(tile, MP_OBJECT)) {
168 return 0xFFFF;
169 }
170
171 const Object *o = Object::GetByTile(tile);
172 const ObjectSpec *spec = ObjectSpec::Get(o->type);
173
174 /* Default objects have no associated NewGRF file */
175 if (spec->grf_prop.grffile == nullptr) {
176 return 0xFFFE; // Defined in another grf file
177 }
178
179 if (spec->grf_prop.grffile->grfid == cur_grfid) { // same object, same grf ?
180 return spec->grf_prop.local_id | o->view << 16;
181 }
182
183 return 0xFFFE; // Defined in another grf file
184 }
185
194 static uint32_t GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
195 {
196 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
197 bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
198
199 return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
200 }
201
209 static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
210 {
211 uint32_t best_dist = UINT32_MAX;
212 for (const Object *o : Object::Iterate()) {
213 if (o->type != type || o == current) continue;
214
215 best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
216 }
217
218 return best_dist;
219 }
220
229 static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grfid, TileIndex tile, const Object *current)
230 {
231 uint32_t grf_id = GetRegister(0x100); // Get the GRFID of the definition to look for in register 100h
232 uint32_t idx;
233
234 /* Determine what will be the object type to look for */
235 switch (grf_id) {
236 case 0: // this is a default object type
237 idx = local_id;
238 break;
239
240 case 0xFFFFFFFF: // current grf
241 grf_id = grfid;
242 [[fallthrough]];
243
244 default: // use the grfid specified in register 100h
245 idx = _object_mngr.GetID(local_id, grf_id);
246 break;
247 }
248
249 /* If the object type is invalid, there is none and the closest is far away. */
250 if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
251
252 return Object::GetTypeCount(idx) << 16 | ClampTo<uint16_t>(GetClosestObject(tile, idx, current));
253 }
254
256 /* virtual */ uint32_t ObjectScopeResolver::GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const
257 {
258 /* We get the town from the object, or we calculate the closest
259 * town if we need to when there's no object. */
260 const Town *t = nullptr;
261
262 if (this->obj == nullptr) {
263 switch (variable) {
264 /* Allow these when there's no object. */
265 case 0x41:
266 case 0x60:
267 case 0x61:
268 case 0x62:
269 case 0x64:
270 break;
271
272 /* Allow these, but find the closest town. */
273 case 0x45:
274 case 0x46:
275 if (!IsValidTile(this->tile)) goto unhandled;
276 t = ClosestTownFromTile(this->tile, UINT_MAX);
277 break;
278
279 /* Construction date */
280 case 0x42: return TimerGameCalendar::date.base();
281
282 /* Object founder information */
283 case 0x44: return _current_company;
284
285 /* Object view */
286 case 0x48: return this->view;
287
288 /*
289 * Disallow the rest:
290 * 0x40: Relative position is passed as parameter during construction.
291 * 0x43: Animation counter is only for actual tiles.
292 * 0x47: Object colour is only valid when its built.
293 * 0x63: Animation counter of nearby tile, see above.
294 */
295 default:
296 goto unhandled;
297 }
298
299 /* If there's an invalid tile, then we don't have enough information at all. */
300 if (!IsValidTile(this->tile)) goto unhandled;
301 } else {
302 t = this->obj->town;
303 }
304
305 switch (variable) {
306 /* Relative position. */
307 case 0x40: {
308 TileIndex offset = this->tile - this->obj->location.tile;
309 uint offset_x = TileX(offset);
310 uint offset_y = TileY(offset);
311 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
312 }
313
314 /* Tile information. */
315 case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
316
317 /* Construction date */
318 case 0x42: return this->obj->build_date.base();
319
320 /* Animation counter */
321 case 0x43: return GetAnimationFrame(this->tile);
322
323 /* Object founder information */
324 case 0x44: return GetTileOwner(this->tile);
325
326 /* Get town zone and Manhattan distance of closest town */
327 case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy));
328
329 /* Get square of Euclidian distance of closest town */
330 case 0x46: return DistanceSquare(this->tile, t->xy);
331
332 /* Object colour */
333 case 0x47: return this->obj->colour;
334
335 /* Object view */
336 case 0x48: return this->obj->view;
337
338 /* Get object ID at offset param */
339 case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
340
341 /* Get random tile bits at offset param */
342 case 0x61: {
343 TileIndex tile = GetNearbyTile(parameter, this->tile);
344 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
345 }
346
347 /* Land info of nearby tiles */
348 case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? INVALID_OBJECT : this->obj->index, this->ro.grffile->grf_version >= 8);
349
350 /* Animation counter of nearby tile */
351 case 0x63: {
352 TileIndex tile = GetNearbyTile(parameter, this->tile);
353 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
354 }
355
356 /* Count of object, distance of closest instance */
357 case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj);
358 }
359
360 unhandled:
361 Debug(grf, 1, "Unhandled object variable 0x{:X}", variable);
362
363 *available = false;
364 return UINT_MAX;
365 }
366
376 ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8_t view,
377 CallbackID callback, uint32_t param1, uint32_t param2)
378 : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
379 {
380 this->town_scope = nullptr;
381 this->root_spritegroup = (obj == nullptr && spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_PURCHASE] != nullptr) ?
382 spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_PURCHASE] : spec->grf_prop.spritegroup[OBJECT_SPRITE_GROUP_DEFAULT];
383 }
384
385 ObjectResolverObject::~ObjectResolverObject()
386 {
387 delete this->town_scope;
388 }
389
395 TownScopeResolver *ObjectResolverObject::GetTown()
396 {
397 if (this->town_scope == nullptr) {
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 = new TownScopeResolver(*this, t, this->object_scope.obj == nullptr);
406 }
407 return this->town_scope;
408 }
409
410 GrfSpecFeature ObjectResolverObject::GetFeature() const
411 {
412 return GSF_OBJECTS;
413 }
414
415 uint32_t ObjectResolverObject::GetDebugID() const
416 {
417 return this->object_scope.spec->grf_prop.local_id;
418 }
419
431 uint16_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
443 static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
444 {
445 const DrawTileSprites *dts = group->ProcessRegisters(nullptr);
446 PaletteID palette = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? 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 & OBJECT_FLAG_DRAW_WATER) && 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
469 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
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
487 void 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;
496 if (Company::IsValidID(_local_company)) {
497 /* Get the colours of our company! */
498 if (spec->flags & OBJECT_FLAG_2CC_COLOUR) {
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 & OBJECT_FLAG_2CC_COLOUR) ? 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
529 uint16_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
535 struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback, TileAnimationFrameAnimationHelper<Object> > {
536 static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED;
537 static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
538
539 static const ObjectCallbackMask cbm_animation_speed = CBM_OBJ_ANIMATION_SPEED;
540 static const ObjectCallbackMask cbm_animation_next_frame = CBM_OBJ_ANIMATION_NEXT_FRAME;
541 };
542
547 void AnimateNewObjectTile(TileIndex tile)
548 {
549 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
550 if (spec == nullptr || !(spec->flags & OBJECT_FLAG_ANIMATION)) return;
551
552 ObjectAnimationBase::AnimateTile(spec, Object::GetByTile(tile), tile, (spec->flags & OBJECT_FLAG_ANIM_RANDOM_BITS) != 0);
553 }
554
562 void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
563 {
564 if (!HasBit(spec->animation.triggers, trigger)) return;
565
566 ObjectAnimationBase::ChangeAnimationFrame(CBID_OBJECT_ANIMATION_START_STOP, spec, o, tile, Random(), trigger);
567 }
568
575 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
576 {
577 if (!HasBit(spec->animation.triggers, trigger)) return;
578
579 for (TileIndex tile : o->location) {
580 TriggerObjectTileAnimation(o, tile, trigger, spec);
581 }
582 }
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
ObjectResolverObject
A resolver object to be used with feature 0F spritegroups.
Definition: newgrf_object.h:134
Object::colour
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:28
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition: sprite.h:168
CBM_OBJ_ANIMATION_SPEED
@ CBM_OBJ_ANIMATION_SPEED
decides animation speed
Definition: newgrf_callbacks.h:400
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:339
OBJECT_FLAG_2CC_COLOUR
@ OBJECT_FLAG_2CC_COLOUR
Object wants 2CC colour mapping.
Definition: newgrf_object.h:34
water.h
CBID_OBJECT_ANIMATION_NEXT_FRAME
@ CBID_OBJECT_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
Definition: newgrf_callbacks.h:257
DrawNewGRFTileSeqInGUI
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition: sprite.h:133
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
ObjectSpec::grf_prop
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:62
GetObjectCallback
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.
Definition: newgrf_object.cpp:431
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3783
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
SPRITE_WIDTH
@ SPRITE_WIDTH
number of bits for the sprite number
Definition: sprites.h:1527
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:355
company_base.h
timer_game_calendar.h
CBM_OBJ_ANIMATION_NEXT_FRAME
@ CBM_OBJ_ANIMATION_NEXT_FRAME
decides next animation frame
Definition: newgrf_callbacks.h:399
AnimationInfo::triggers
uint16_t triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:22
Object::location
TileArea location
Location of the object.
Definition: object_base.h:26
GB
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
ObjectAnimationTrigger
ObjectAnimationTrigger
Animation triggers for objects.
Definition: newgrf_animation_type.h:56
GetRegister
uint32_t GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:55
ObjectScopeResolver::obj
struct Object * obj
The object the callback is ran for.
Definition: newgrf_object.h:112
ObjectSpec::IsAvailable
bool IsAvailable() const
Check whether the object is available at this time.
Definition: newgrf_object.cpp:93
INSTANTIATE_NEWGRF_CLASS_METHODS
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
Force instantiation of the methods so we don't get linker errors.
Definition: newgrf_class_func.h:212
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
ObjectOverrideManager
Definition: newgrf_commons.h:278
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition: newgrf_spritegroup.h:335
TriggerObjectTileAnimation
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
Definition: newgrf_object.cpp:562
newgrf_animation_base.h
OBJECT_FLAG_ONLY_IN_GAME
@ OBJECT_FLAG_ONLY_IN_GAME
Object can only be built in game.
Definition: newgrf_object.h:33
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:23
OBJECT_FLAG_ANIM_RANDOM_BITS
@ OBJECT_FLAG_ANIM_RANDOM_BITS
Object wants random bits in "next animation frame" callback.
Definition: newgrf_object.h:38
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
town.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
newgrf_class_func.h
GetTerrainType
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 ...
Definition: newgrf_commons.cpp:331
DrawNewObjectTile
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Definition: newgrf_object.cpp:469
GetClosestObject
static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
Definition: newgrf_object.cpp:209
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition: newgrf_callbacks.h:20
ObjectSpec::IsEverAvailable
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode.
Definition: newgrf_object.cpp:74
_object_specs
std::vector< ObjectSpec > _object_specs
All the object specifications.
Definition: newgrf_object.cpp:33
ObjectAnimationBase
Helper class for animation control.
Definition: newgrf_object.cpp:535
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition: newgrf_object.cpp:50
PaletteID
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:18
genworld.h
TriggerObjectAnimation
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
Definition: newgrf_object.cpp:575
ObjectResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_object.h:136
ObjectScopeResolver::tile
TileIndex tile
The tile related to the object.
Definition: newgrf_object.h:114
ObjectResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_object.cpp:410
ObjectSpec::animation
AnimationInfo animation
Information about the animation.
Definition: newgrf_object.h:63
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
object_base.h
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:618
tile_cmd.h
GetTownRadiusGroup
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition: town_cmd.cpp:2425
NEW_OBJECT_OFFSET
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition: object_type.h:22
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
ObjectID
uint32_t ObjectID
Unique identifier for an object.
Definition: object_type.h:28
OBJECT_FLAG_DRAW_WATER
@ OBJECT_FLAG_DRAW_WATER
Object wants to be drawn on water.
Definition: newgrf_object.h:36
NewGRFClass::IsUIAvailable
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
Definition: newgrf_airport.cpp:36
ObjectSpec::BindToClasses
static void BindToClasses()
Tie all ObjectSpecs to their class.
Definition: newgrf_object.cpp:111
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
ObjectType
uint16_t ObjectType
Types of objects.
Definition: object_type.h:14
ObjectClassID
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:48
ObjectSpec::WasEverAvailable
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Definition: newgrf_object.cpp:84
OBJECT_FLAG_ANIMATION
@ OBJECT_FLAG_ANIMATION
Object has animated tiles.
Definition: newgrf_object.h:32
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:58
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:336
GetObjectIDAtOffset
static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
Make an analysis of a tile and get the object type.
Definition: newgrf_object.cpp:165
ObjectSpec::end_of_life_date
TimerGameCalendar::Date end_of_life_date
When can't this object be built anymore.
Definition: newgrf_object.h:72
Object::view
byte view
The view setting for this object.
Definition: object_base.h:29
INVALID_OBJECT
static const ObjectID INVALID_OBJECT
An invalid object.
Definition: object_type.h:33
GetCountAndDistanceOfClosestInstance
static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grfid, TileIndex tile, const Object *current)
Implementation of var 65.
Definition: newgrf_object.cpp:229
_object_mngr
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
DrawTileLayout
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
Definition: newgrf_object.cpp:443
Object
An object, such as transmitter, on the map.
Definition: object_base.h:23
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:20
ObjectSpec::IsEnabled
bool IsEnabled() const
Test if this object is enabled.
Definition: newgrf_object.h:83
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition: water_map.h:139
GetNearbyTileInformation
uint32_t GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
Definition: newgrf_commons.cpp:429
Object::type
ObjectType type
Type of the object.
Definition: object_base.h:24
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
_original_objects
const ObjectSpec _original_objects[]
Specification of the original object structures.
safeguards.h
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
Object::GetTypeCount
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition: object_base.h:65
GetTileSlope
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition: tile_map.h:178
DrawSprite
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:1003
AnimationBase< ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback, TileAnimationFrameAnimationHelper< Object > >::ChangeAnimationFrame
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.
Definition: newgrf_animation_base.h:124
ObjectSpec::introduction_date
TimerGameCalendar::Date introduction_date
From when can this object be built.
Definition: newgrf_object.h:71
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
stdafx.h
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition: newgrf_airport.cpp:27
ObjectScopeResolver::view
uint8_t view
The view of the object.
Definition: newgrf_object.h:115
OBJECT_FLAG_ONLY_IN_SCENEDIT
@ OBJECT_FLAG_ONLY_IN_SCENEDIT
Object can only be constructed in the scenario editor.
Definition: newgrf_object.h:26
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:318
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition: tile_map.h:161
newgrf_object.h
object_map.h
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:62
DrawNewGRFTileSeq
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:124
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:176
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
GetObjectType
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:66
ObjectSpec::Index
uint Index() const
Gets the index of this spec.
Definition: newgrf_object.cpp:103
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1571
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
newgrf_sound.h
Pool::PoolItem<&_object_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:388
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:320
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition: transparency.h:29
StubGetObjectCallback
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.
Definition: newgrf_object.cpp:529
GetNearbyObjectTileInformation
static uint32_t GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
Definition: newgrf_object.cpp:194
ObjectSpec::climate
uint8_t climate
In which climates is this object available?
Definition: newgrf_object.h:67
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition: livery.h:80
ObjectSpec::GetByTile
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Definition: newgrf_object.cpp:65
ObjectResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
Definition: newgrf_object.cpp:395
ObjectResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_object.cpp:415
CBID_OBJECT_ANIMATION_START_STOP
@ CBID_OBJECT_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
Definition: newgrf_callbacks.h:260
NewGRFClass::name
StringID name
Name of this class.
Definition: newgrf_class.h:39
ObjectScopeResolver
Object scope resolver.
Definition: newgrf_object.h:111
ObjectCallbackMask
ObjectCallbackMask
Callback masks for objects.
Definition: newgrf_callbacks.h:397
GetObjectRandomBits
byte GetObjectRandomBits(Tile t)
Get the random bits of this tile.
Definition: object_map.h:59
company_func.h
AnimationBase< ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback, TileAnimationFrameAnimationHelper< Object > >::AnimateTile
static void AnimateTile(const ObjectSpec *spec, Object *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
Definition: newgrf_animation_base.h:45
CBID_OBJECT_ANIMATION_SPEED
@ CBID_OBJECT_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition: newgrf_callbacks.h:263
INVALID_OBJECT_TYPE
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition: object_type.h:25
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition: newgrf_animation_base.h:36
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve([[maybe_unused]] ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
ResetObjects
void ResetObjects()
This function initialize the spec arrays of objects.
Definition: newgrf_object.cpp:121
Town
Town data structure.
Definition: town.h:50
GetAnimationFrame
byte GetAnimationFrame(Tile t)
Get the current animation frame.
Definition: tile_map.h:250
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:98
ObjectScopeResolver::spec
const ObjectSpec * spec
Specification of the object type.
Definition: newgrf_object.h:113
GetObjectIndex
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition: object_map.h:47
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:406
AnimateNewObjectTile
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Definition: newgrf_object.cpp:547
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition: timer_game_calendar.h:34
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:47
ObjectScopeResolver::GetVariable
uint32_t GetVariable(byte variable, [[maybe_unused]] uint32_t parameter, bool *available) const override
Used by the resolver to get values for feature 0F deterministic spritegroups.
Definition: newgrf_object.cpp:256
OBJECT_CLASS_MAX
@ OBJECT_CLASS_MAX
Maximum number of classes.
Definition: newgrf_object.h:50
DrawNewObjectTileInGUI
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
Draw representation of an object (tile) for GUI purposes.
Definition: newgrf_object.cpp:487
Object::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition: object_base.h:27
IsTileType
static debug_inline bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:328
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition: newgrf_spritegroup.h:289
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition: newgrf_commons.h:319
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
OBJECT_TRANSMITTER
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition: object_type.h:16
OBJECT_LIGHTHOUSE
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition: object_type.h:17
ObjectResolverObject::ObjectResolverObject
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.
Definition: newgrf_object.cpp:376
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
TileLayoutSpriteGroup::ProcessRegisters
const DrawTileSprites * ProcessRegisters(uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Definition: newgrf_spritegroup.cpp:289
Livery
Information about a particular livery.
Definition: livery.h:78
Object::town
Town * town
Town the object is built in.
Definition: object_base.h:25
INVALID_OBJECT_CLASS
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
Definition: newgrf_object.h:51
SpriteGroup
Definition: newgrf_spritegroup.h:57
DrawGroundSprite
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:589
debug.h
OverrideManagerBase::GetID
virtual uint16_t GetID(uint16_t grf_local_id, uint32_t grfid) const
Return the ID (if ever available) of a previously inserted entity.
Definition: newgrf_commons.cpp:90
ObjectResolverObject::object_scope
ObjectScopeResolver object_scope
The object scope resolver.
Definition: newgrf_object.h:135
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition: newgrf_spritegroup.h:259
ObjectSpec::flags
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:73
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103