OpenTTD Source: src/newgrf_object.cpp Source File

OpenTTD Source 12.2

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_class_func.h"
16 #include "newgrf_object.h"
17 #include "newgrf_sound.h"
18 #include "object_base.h"
19 #include "object_map.h"
20 #include "tile_cmd.h"
21 #include "town.h"
22 #include "water.h"
23 #include "newgrf_animation_base.h"
24
25 #include "safeguards.h"
26
28 ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE);
29
30 extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET];
32 ObjectSpec _object_specs[NUM_OBJECTS];
33
39 /* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
40 {
41 assert(index < NUM_OBJECTS);
42 return &_object_specs[index];
43 }
44
50 /* static */ const ObjectSpec *ObjectSpec::GetByTile(TileIndex tile)
51 {
52 return ObjectSpec::Get(GetObjectType(tile));
53 }
54
59 bool ObjectSpec::IsEverAvailable() const
60 {
61 return this->enabled && HasBit(this->climate, _settings_game.game_creation.landscape) &&
62 (this->flags & ((_game_mode != GM_EDITOR && !_generating_world) ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
63 }
64
69 bool ObjectSpec::WasEverAvailable() const
70 {
71 return this->IsEverAvailable() && _date > this->introduction_date;
72 }
73
78 bool ObjectSpec::IsAvailable() const
79 {
80 return this->WasEverAvailable() &&
81 (_date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365);
82 }
83
88 uint ObjectSpec::Index() const
89 {
90 return this - _object_specs;
91 }
92
94 void ResetObjects()
95 {
96 /* Clean the pool. */
97 for (uint16 i = 0; i < NUM_OBJECTS; i++) {
98 _object_specs[i] = {};
99 }
100
101 /* And add our originals. */
102 MemCpyT(_object_specs, _original_objects, lengthof(_original_objects));
103
104 for (uint16 i = 0; i < lengthof(_original_objects); i++) {
105 _object_specs[i].grf_prop.local_id = i;
106 }
107 }
108
109 template <typename Tspec, typename Tid, Tid Tmax>
110 /* static */ void NewGRFClass<Tspec, Tid, Tmax>::InsertDefaults()
111 {
112 ObjectClassID cls = ObjectClass::Allocate('LTHS');
113 ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS;
114 _object_specs[OBJECT_LIGHTHOUSE].cls_id = cls;
115 ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]);
116
117 cls = ObjectClass::Allocate('TRNS');
118 ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
119 _object_specs[OBJECT_TRANSMITTER].cls_id = cls;
120 ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
121 }
122
123 template <typename Tspec, typename Tid, Tid Tmax>
124 bool NewGRFClass<Tspec, Tid, Tmax>::IsUIAvailable(uint index) const
125 {
126 return this->GetSpec(index)->IsEverAvailable();
127 }
128
129 INSTANTIATE_NEWGRF_CLASS_METHODS(ObjectClass, ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX)
130
131 /* virtual */ uint32 ObjectScopeResolver::GetRandomBits() const
132 {
133 return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;
134 }
135
142 static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
143 {
144 if (!IsTileType(tile, MP_OBJECT)) {
145 return 0xFFFF;
146 }
147
148 const Object *o = Object::GetByTile(tile);
149 const ObjectSpec *spec = ObjectSpec::Get(o->type);
150
151 /* Default objects have no associated NewGRF file */
152 if (spec->grf_prop.grffile == nullptr) {
153 return 0xFFFE; // Defined in another grf file
154 }
155
156 if (spec->grf_prop.grffile->grfid == cur_grfid) { // same object, same grf ?
157 return spec->grf_prop.local_id | o->view << 16;
158 }
159
160 return 0xFFFE; // Defined in another grf file
161 }
162
171 static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
172 {
173 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
174 bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
175
176 return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
177 }
178
186 static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
187 {
188 uint32 best_dist = UINT32_MAX;
189 for (const Object *o : Object::Iterate()) {
190 if (o->type != type || o == current) continue;
191
192 best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
193 }
194
195 return best_dist;
196 }
197
206 static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
207 {
208 uint32 grf_id = GetRegister(0x100); // Get the GRFID of the definition to look for in register 100h
209 uint32 idx;
210
211 /* Determine what will be the object type to look for */
212 switch (grf_id) {
213 case 0: // this is a default object type
214 idx = local_id;
215 break;
216
217 case 0xFFFFFFFF: // current grf
218 grf_id = grfid;
219 FALLTHROUGH;
220
221 default: // use the grfid specified in register 100h
222 idx = _object_mngr.GetID(local_id, grf_id);
223 break;
224 }
225
226 /* If the object type is invalid, there is none and the closest is far away. */
227 if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
228
229 return Object::GetTypeCount(idx) << 16 | std::min(GetClosestObject(tile, idx, current), 0xFFFFu);
230 }
231
233 /* virtual */ uint32 ObjectScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
234 {
235 /* We get the town from the object, or we calculate the closest
236 * town if we need to when there's no object. */
237 const Town *t = nullptr;
238
239 if (this->obj == nullptr) {
240 switch (variable) {
241 /* Allow these when there's no object. */
242 case 0x41:
243 case 0x60:
244 case 0x61:
245 case 0x62:
246 case 0x64:
247 break;
248
249 /* Allow these, but find the closest town. */
250 case 0x45:
251 case 0x46:
252 if (!IsValidTile(this->tile)) goto unhandled;
253 t = ClosestTownFromTile(this->tile, UINT_MAX);
254 break;
255
256 /* Construction date */
257 case 0x42: return _date;
258
259 /* Object founder information */
260 case 0x44: return _current_company;
261
262 /* Object view */
263 case 0x48: return this->view;
264
265 /*
266 * Disallow the rest:
267 * 0x40: Relative position is passed as parameter during construction.
268 * 0x43: Animation counter is only for actual tiles.
269 * 0x47: Object colour is only valid when its built.
270 * 0x63: Animation counter of nearby tile, see above.
271 */
272 default:
273 goto unhandled;
274 }
275
276 /* If there's an invalid tile, then we don't have enough information at all. */
277 if (!IsValidTile(this->tile)) goto unhandled;
278 } else {
279 t = this->obj->town;
280 }
281
282 switch (variable) {
283 /* Relative position. */
284 case 0x40: {
285 uint offset = this->tile - this->obj->location.tile;
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;
289 }
290
291 /* Tile information. */
292 case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
293
294 /* Construction date */
295 case 0x42: return this->obj->build_date;
296
297 /* Animation counter */
298 case 0x43: return GetAnimationFrame(this->tile);
299
300 /* Object founder information */
301 case 0x44: return GetTileOwner(this->tile);
302
303 /* Get town zone and Manhattan distance of closest town */
304 case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | std::min(DistanceManhattan(this->tile, t->xy), 0xFFFFu);
305
306 /* Get square of Euclidian distance of closest town */
307 case 0x46: return DistanceSquare(this->tile, t->xy);
308
309 /* Object colour */
310 case 0x47: return this->obj->colour;
311
312 /* Object view */
313 case 0x48: return this->obj->view;
314
315 /* Get object ID at offset param */
316 case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
317
318 /* Get random tile bits at offset param */
319 case 0x61: {
320 TileIndex tile = GetNearbyTile(parameter, this->tile);
321 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
322 }
323
324 /* Land info of nearby tiles */
325 case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? INVALID_OBJECT : this->obj->index, this->ro.grffile->grf_version >= 8);
326
327 /* Animation counter of nearby tile */
328 case 0x63: {
329 TileIndex tile = GetNearbyTile(parameter, this->tile);
330 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
331 }
332
333 /* Count of object, distance of closest instance */
334 case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj);
335 }
336
337 unhandled:
338 Debug(grf, 1, "Unhandled object variable 0x{:X}", variable);
339
340 *available = false;
341 return UINT_MAX;
342 }
343
353 ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8 view,
354 CallbackID callback, uint32 param1, uint32 param2)
355 : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
356 {
357 this->town_scope = nullptr;
358 this->root_spritegroup = (obj == nullptr && spec->grf_prop.spritegroup[CT_PURCHASE_OBJECT] != nullptr) ?
359 spec->grf_prop.spritegroup[CT_PURCHASE_OBJECT] : spec->grf_prop.spritegroup[0];
360 }
361
362 ObjectResolverObject::~ObjectResolverObject()
363 {
364 delete this->town_scope;
365 }
366
372 TownScopeResolver *ObjectResolverObject::GetTown()
373 {
374 if (this->town_scope == nullptr) {
375 Town *t;
376 if (this->object_scope.obj != nullptr) {
377 t = this->object_scope.obj->town;
378 } else {
379 t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
380 }
381 if (t == nullptr) return nullptr;
382 this->town_scope = new TownScopeResolver(*this, t, this->object_scope.obj == nullptr);
383 }
384 return this->town_scope;
385 }
386
387 GrfSpecFeature ObjectResolverObject::GetFeature() const
388 {
389 return GSF_OBJECTS;
390 }
391
392 uint32 ObjectResolverObject::GetDebugID() const
393 {
394 return this->object_scope.spec->grf_prop.local_id;
395 }
396
408 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
409 {
410 ObjectResolverObject object(spec, o, tile, view, callback, param1, param2);
411 return object.ResolveCallback();
412 }
413
420 static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
421 {
422 const DrawTileSprites *dts = group->ProcessRegisters(nullptr);
423 PaletteID palette = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START) + Object::GetByTile(ti->tile)->colour;
424
425 SpriteID image = dts->ground.sprite;
426 PaletteID pal = dts->ground.pal;
427
428 if (GB(image, 0, SPRITE_WIDTH) != 0) {
429 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
430 * Do not do this if the tile's WaterClass is 'land'. */
431 if ((image == SPR_FLAT_WATER_TILE || spec->flags & OBJECT_FLAG_DRAW_WATER) && IsTileOnWater(ti->tile)) {
432 DrawWaterClassGround(ti);
433 } else {
434 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
435 }
436 }
437
438 DrawNewGRFTileSeq(ti, dts, TO_STRUCTURES, 0, palette);
439 }
440
446 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
447 {
448 Object *o = Object::GetByTile(ti->tile);
449 ObjectResolverObject object(spec, o, ti->tile);
450
451 const SpriteGroup *group = object.Resolve();
452 if (group == nullptr || group->type != SGT_TILELAYOUT) return;
453
454 DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec);
455 }
456
464 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
465 {
466 ObjectResolverObject object(spec, nullptr, INVALID_TILE, view);
467 const SpriteGroup *group = object.Resolve();
468 if (group == nullptr || group->type != SGT_TILELAYOUT) return;
469
470 const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(nullptr);
471
472 PaletteID palette;
473 if (Company::IsValidID(_local_company)) {
474 /* Get the colours of our company! */
475 if (spec->flags & OBJECT_FLAG_2CC_COLOUR) {
476 const Livery *l = Company::Get(_local_company)->livery;
477 palette = SPR_2CCMAP_BASE + l->colour1 + l->colour2 * 16;
478 } else {
479 palette = COMPANY_SPRITE_COLOUR(_local_company);
480 }
481 } else {
482 /* There's no company, so just take the base palette. */
483 palette = (spec->flags & OBJECT_FLAG_2CC_COLOUR) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START;
484 }
485
486 SpriteID image = dts->ground.sprite;
487 PaletteID pal = dts->ground.pal;
488
489 if (GB(image, 0, SPRITE_WIDTH) != 0) {
490 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
491 }
492
493 DrawNewGRFTileSeqInGUI(x, y, dts, 0, palette);
494 }
495
507 uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
508 {
509 return GetObjectCallback(callback, param1, param2, spec, o, tile);
510 }
511
513 struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback> {
514 static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED;
515 static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
516
517 static const ObjectCallbackMask cbm_animation_speed = CBM_OBJ_ANIMATION_SPEED;
518 static const ObjectCallbackMask cbm_animation_next_frame = CBM_OBJ_ANIMATION_NEXT_FRAME;
519 };
520
525 void AnimateNewObjectTile(TileIndex tile)
526 {
527 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
528 if (spec == nullptr || !(spec->flags & OBJECT_FLAG_ANIMATION)) return;
529
530 ObjectAnimationBase::AnimateTile(spec, Object::GetByTile(tile), tile, (spec->flags & OBJECT_FLAG_ANIM_RANDOM_BITS) != 0);
531 }
532
540 void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
541 {
542 if (!HasBit(spec->animation.triggers, trigger)) return;
543
544 ObjectAnimationBase::ChangeAnimationFrame(CBID_OBJECT_ANIMATION_START_STOP, spec, o, tile, Random(), trigger);
545 }
546
553 void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
554 {
555 if (!HasBit(spec->animation.triggers, trigger)) return;
556
557 for (TileIndex tile : o->location) {
558 TriggerObjectTileAnimation(o, tile, trigger, spec);
559 }
560 }
ObjectResolverObject
A resolver object to be used with feature 0F spritegroups.
Definition: newgrf_object.h:123
OBJECT_FLAG_ANIMATION
@ OBJECT_FLAG_ANIMATION
Object has animated tiles.
Definition: newgrf_object.h:32
Object::colour
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:28
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
CBM_OBJ_ANIMATION_SPEED
@ CBM_OBJ_ANIMATION_SPEED
decides animation speed
Definition: newgrf_callbacks.h:384
GetObjectType
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:62
OBJECT_FLAG_ONLY_IN_SCENEDIT
@ OBJECT_FLAG_ONLY_IN_SCENEDIT
Object can only be constructed in the scenario editor.
Definition: newgrf_object.h:26
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:337
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
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
OBJECT_FLAG_2CC_COLOUR
@ OBJECT_FLAG_2CC_COLOUR
Object wants 2CC colour mapping.
Definition: newgrf_object.h:34
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:58
GetObjectIDAtOffset
static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
Make an analysis of a tile and get the object type.
Definition: newgrf_object.cpp:142
ObjectSpec::grf_prop
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:60
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:3592
TileInfo
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
SPRITE_WIDTH
@ SPRITE_WIDTH
number of bits for the sprite number
Definition: sprites.h:1525
GameCreationSettings::landscape
byte landscape
the landscape we're currently in
Definition: settings_type.h:321
ObjectResolverObject::ObjectResolverObject
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.
Definition: newgrf_object.cpp:353
company_base.h
CBM_OBJ_ANIMATION_NEXT_FRAME
@ CBM_OBJ_ANIMATION_NEXT_FRAME
decides next animation frame
Definition: newgrf_callbacks.h:383
Object::location
TileArea location
Location of the object.
Definition: object_base.h:26
AnimationBase< ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback >::ChangeAnimationFrame
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.
Definition: newgrf_animation_base.h:117
ObjectAnimationTrigger
ObjectAnimationTrigger
Animation triggers for objects.
Definition: newgrf_animation_type.h:56
ObjectResolverObject::GetDebugID
uint32 GetDebugID() const override
Get an identifier for the item being resolved.
Definition: newgrf_object.cpp:392
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:235
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:51
ObjectScopeResolver::obj
struct Object * obj
The object the callback is ran for.
Definition: newgrf_object.h:101
ObjectSpec::IsAvailable
bool IsAvailable() const
Check whether the object is available at this time.
Definition: newgrf_object.cpp:78
StubGetObjectCallback
uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
Perform a callback for an object.
Definition: newgrf_object.cpp:507
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:216
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition: gfx_type.h:23
ObjectOverrideManager
Definition: newgrf_commons.h:279
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition: newgrf_spritegroup.h:307
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
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:540
newgrf_animation_base.h
DrawNewObjectTileInGUI
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
Definition: newgrf_object.cpp:464
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:25
ObjectSpec::end_of_life_date
Date end_of_life_date
When can't this object be built anymore.
Definition: newgrf_object.h:69
TileLayoutSpriteGroup::ProcessRegisters
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
Definition: newgrf_spritegroup.cpp:293
OverrideManagerBase::GetID
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
Definition: newgrf_commons.cpp:102
GetRegister
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
Definition: newgrf_spritegroup.h:29
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
AnimationBase< ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback >::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:38
town.h
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
newgrf_class_func.h
DrawNewObjectTile
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Definition: newgrf_object.cpp:446
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:59
ObjectAnimationBase
Helper class for animation control.
Definition: newgrf_object.cpp:513
MemCpyT
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition: mem_func.hpp:23
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition: newgrf_object.cpp:39
GetClosestObject
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
Definition: newgrf_object.cpp:186
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:553
GetNearbyObjectTileInformation
static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
Definition: newgrf_object.cpp:171
ObjectResolverObject::town_scope
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Definition: newgrf_object.h:125
ObjectScopeResolver::tile
TileIndex tile
The tile related to the object.
Definition: newgrf_object.h:103
ObjectResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition: newgrf_object.cpp:387
ObjectSpec::animation
AnimationInfo animation
Information about the animation.
Definition: newgrf_object.h:71
object_base.h
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition: settings_type.h:577
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:2257
SpriteID
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
ObjectSpec::introduction_date
Date introduction_date
From when can this object be built.
Definition: newgrf_object.h:68
IsTileOnWater
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:130
NEW_OBJECT_OFFSET
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition: object_type.h:24
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
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:79
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:157
GetAnimationFrame
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definition: tile_map.h:250
DrawNewGRFTileSeq
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:124
_date
Date _date
Current date in days (day counter)
Definition: date.cpp:28
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:69
ObjectClassID
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:46
ObjectType
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition: tile_type.h:56
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition: newgrf_spritegroup.h:336
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:34
_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:420
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:19
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
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:46
_original_objects
const ObjectSpec _original_objects[]
Specification of the original object structures.
safeguards.h
IsValidTile
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
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
DrawNewGRFTileSeqInGUI
static void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition: sprite.h:133
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:1042
TownScopeResolver
Scope resolver for a town.
Definition: newgrf_town.h:22
GetNearbyTileInformation
uint32 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:446
stdafx.h
ObjectSpec::enabled
bool enabled
Is this spec enabled?
Definition: newgrf_object.h:76
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition: newgrf_airport.cpp:70
IsTileType
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
GetTileOwner
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
ObjectScopeResolver::view
uint8 view
The view of the object.
Definition: newgrf_object.h:104
GroundSpritePaletteTransform
static 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
newgrf_object.h
object_map.h
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition: map.cpp:174
OBJECT_CLASS_MAX
@ OBJECT_CLASS_MAX
Maximum number of classes.
Definition: newgrf_object.h:48
GrfSpecFeature
GrfSpecFeature
Definition: newgrf.h:66
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Definition: newgrf_spritegroup.h:61
ObjectSpec::Index
uint Index() const
Gets the index of this spec.
Definition: newgrf_object.cpp:88
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1569
GetCountAndDistanceOfClosestInstance
static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
Implementation of var 65.
Definition: newgrf_object.cpp:206
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
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:386
GRFFilePropsBase::spritegroup
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Definition: newgrf_commons.h:321
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition: transparency.h:29
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
PaletteID
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
ObjectScopeResolver::GetVariable
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const override
Used by the resolver to get values for feature 0F deterministic spritegroups.
Definition: newgrf_object.cpp:233
ObjectSpec::GetByTile
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Definition: newgrf_object.cpp:50
ObjectResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
Definition: newgrf_object.cpp:372
CBID_OBJECT_ANIMATION_START_STOP
@ CBID_OBJECT_ANIMATION_START_STOP
Called for periodically starting or stopping the animation.
Definition: newgrf_callbacks.h:260
GetObjectCallback
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
Definition: newgrf_object.cpp:408
OBJECT_FLAG_ANIM_RANDOM_BITS
@ OBJECT_FLAG_ANIM_RANDOM_BITS
Object wants random bits in "next animation frame" callback.
Definition: newgrf_object.h:38
NewGRFClass::name
StringID name
Name of this class.
Definition: newgrf_class.h:39
ObjectScopeResolver
Object scope resolver.
Definition: newgrf_object.h:100
ObjectCallbackMask
ObjectCallbackMask
Callback masks for objects.
Definition: newgrf_callbacks.h:381
company_func.h
AnimationInfo::triggers
uint16 triggers
The triggers that trigger animation.
Definition: newgrf_animation_type.h:22
ObjectID
uint32 ObjectID
Unique identifier for an object.
Definition: object_type.h:29
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:26
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition: newgrf_animation_base.h:29
GetObjectRandomBits
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
Definition: object_map.h:59
Debug
#define Debug(name, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
ResetObjects
void ResetObjects()
This function initialize the spec arrays of objects.
Definition: newgrf_object.cpp:94
Town
Town data structure.
Definition: town.h:50
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
NewGRFClass::Get
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
Definition: newgrf_class_func.h:103
OBJECT_FLAG_DRAW_WATER
@ OBJECT_FLAG_DRAW_WATER
Object wants to be drawn on water.
Definition: newgrf_object.h:36
ObjectScopeResolver::spec
const ObjectSpec * spec
Specification of the object type.
Definition: newgrf_object.h:102
CT_PURCHASE_OBJECT
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
Definition: newgrf_object.h:159
GetNearbyTile
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition: newgrf_commons.cpp:423
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
GetObjectIndex
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:47
AnimateNewObjectTile
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Definition: newgrf_object.cpp:525
GRFFilePropsBase::local_id
uint16 local_id
id defined by the grf file for this entity
Definition: newgrf_commons.h:319
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:24
TileInfo::tile
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
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:326
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:320
ObjectSpec::climate
uint8 climate
In which climates is this object available?
Definition: newgrf_object.h:64
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
Object::build_date
Date build_date
Date of construction.
Definition: object_base.h:27
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
SpriteGroup
Definition: newgrf_spritegroup.h:57
Object::GetTypeCount
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition: object_base.h:65
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:581
GetTerrainType
uint32 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:348
ObjectSpec::cls_id
ObjectClassID cls_id
The class to which this spec belongs.
Definition: newgrf_object.h:61
debug.h
ObjectResolverObject::object_scope
ObjectScopeResolver object_scope
The object scope resolver.
Definition: newgrf_object.h:124
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition: newgrf_spritegroup.h:259
OBJECT_FLAG_ONLY_IN_GAME
@ OBJECT_FLAG_ONLY_IN_GAME
Object can only be built in game.
Definition: newgrf_object.h:33
Livery::colour2
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
ObjectSpec::flags
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:70
Livery::colour1
byte colour1
First colour, for all vehicles.
Definition: livery.h:80
_object_specs
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.
Definition: newgrf_object.cpp:32