OpenTTD Source: src/newgrf_object.cpp Source File

OpenTTD Source 15.0-RC2

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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
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_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 "table/strings.h"
27
28#include "newgrf_class_func.h"
29
30#include "safeguards.h"
31
33 ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE);
34
35extern const ObjectSpec _original_objects[NEW_OBJECT_OFFSET];
37std::vector<ObjectSpec> _object_specs;
38
39const std::vector<ObjectSpec> &ObjectSpec::Specs()
40{
41 return _object_specs;
42}
43
44size_t ObjectSpec::Count()
45{
46 return _object_specs.size();
47}
48
54/* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
55{
56 /* Empty object if index is out of range -- this might happen if NewGRFs are changed. */
57 static ObjectSpec empty = {};
58
59 assert(index < NUM_OBJECTS);
60 if (index >= _object_specs.size()) return &empty;
61 return &_object_specs[index];
62}
63
69/* static */ const ObjectSpec *ObjectSpec::GetByTile(TileIndex tile)
70{
71 return ObjectSpec::Get(GetObjectType(tile));
72}
73
78 bool ObjectSpec::IsEverAvailable() const
79{
80 return this->IsEnabled() && this->climate.Test(_settings_game.game_creation.landscape) &&
81 !this->flags.Test((_game_mode != GM_EDITOR && !_generating_world) ? ObjectFlag::OnlyInScenedit : ObjectFlag::OnlyInGame);
82}
83
88 bool ObjectSpec::WasEverAvailable() const
89{
90 return this->IsEverAvailable() && TimerGameCalendar::date > this->introduction_date;
91}
92
97 bool ObjectSpec::IsAvailable() const
98{
99 return this->WasEverAvailable() &&
100 (TimerGameCalendar::date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365);
101}
102
107uint ObjectSpec::Index() const
108{
109 return this - _object_specs.data();
110}
111
115/* static */ void ObjectSpec::BindToClasses()
116{
117 for (auto &spec : _object_specs) {
118 if (spec.IsEnabled() && spec.class_index != INVALID_OBJECT_CLASS) {
119 ObjectClass::Assign(&spec);
120 }
121 }
122}
123
125 void ResetObjects()
126{
127 /* Clean the pool. */
128 _object_specs.clear();
129
130 /* And add our originals. */
131 _object_specs.reserve(lengthof(_original_objects));
132
133 for (uint16_t i = 0; i < lengthof(_original_objects); i++) {
134 ObjectSpec &spec = _object_specs.emplace_back(_original_objects[i]);
135 spec.grf_prop.local_id = i;
136 }
137
138 /* Set class for originals. */
139 _object_specs[OBJECT_LIGHTHOUSE].class_index = ObjectClass::Allocate('LTHS');
140 _object_specs[OBJECT_TRANSMITTER].class_index = ObjectClass::Allocate('TRNS');
141}
142
143template <>
144/* static */ void ObjectClass::InsertDefaults()
145{
146 ObjectClass::Get(ObjectClass::Allocate('LTHS'))->name = STR_OBJECT_CLASS_LTHS;
147 ObjectClass::Get(ObjectClass::Allocate('TRNS'))->name = STR_OBJECT_CLASS_TRNS;
148}
149
150template <>
151bool ObjectClass::IsUIAvailable(uint index) const
152{
153 return this->GetSpec(index)->IsEverAvailable();
154}
155
156/* Instantiate ObjectClass. */
157template class NewGRFClass<ObjectSpec, ObjectClassID, OBJECT_CLASS_MAX>;
158
159/* virtual */ uint32_t ObjectScopeResolver::GetRandomBits() const
160{
161 return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;
162}
163
170 static uint32_t GetObjectIDAtOffset(TileIndex tile, uint32_t cur_grfid)
171{
172 if (!IsTileType(tile, MP_OBJECT)) {
173 return 0xFFFF;
174 }
175
176 const Object *o = Object::GetByTile(tile);
177 const ObjectSpec *spec = ObjectSpec::Get(o->type);
178
179 /* Default objects have no associated NewGRF file */
180 if (!spec->grf_prop.HasGrfFile()) {
181 return 0xFFFE; // Defined in another grf file
182 }
183
184 if (spec->grf_prop.grfid == cur_grfid) { // same object, same grf ?
185 return spec->grf_prop.local_id | o->view << 16;
186 }
187
188 return 0xFFFE; // Defined in another grf file
189}
190
199 static uint32_t GetNearbyObjectTileInformation(uint8_t parameter, TileIndex tile, ObjectID index, bool grf_version8)
200{
201 if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
202 bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
203
204 return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
205}
206
214 static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
215{
216 uint32_t best_dist = UINT32_MAX;
217 for (const Object *o : Object::Iterate()) {
218 if (o->type != type || o == current) continue;
219
220 best_dist = std::min(best_dist, DistanceManhattan(tile, o->location.tile));
221 }
222
223 return best_dist;
224}
225
235 static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &object, uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current)
236{
237 uint32_t grf_id = static_cast<uint32_t>(object.GetRegister(0x100)); // Get the GRFID of the definition to look for in register 100h
238 uint32_t idx;
239
240 /* Determine what will be the object type to look for */
241 switch (grf_id) {
242 case 0: // this is a default object type
243 idx = local_id;
244 break;
245
246 case 0xFFFFFFFF: // current grf
247 grf_id = grfid;
248 [[fallthrough]];
249
250 default: // use the grfid specified in register 100h
251 idx = _object_mngr.GetID(local_id, grf_id);
252 break;
253 }
254
255 /* If the object type is invalid, there is none and the closest is far away. */
256 if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
257
258 return Object::GetTypeCount(idx) << 16 | ClampTo<uint16_t>(GetClosestObject(tile, idx, current));
259}
260
262/* virtual */ uint32_t ObjectScopeResolver::GetVariable(uint8_t variable, [[maybe_unused]] uint32_t parameter, bool &available) const
263{
264 /* We get the town from the object, or we calculate the closest
265 * town if we need to when there's no object. */
266 const Town *t = nullptr;
267
268 if (this->obj == nullptr) {
269 switch (variable) {
270 /* Allow these when there's no object. */
271 case 0x41:
272 case 0x60:
273 case 0x61:
274 case 0x62:
275 case 0x64:
276 break;
277
278 /* Allow these, but find the closest town. */
279 case 0x45:
280 case 0x46:
281 if (!IsValidTile(this->tile)) goto unhandled;
282 t = ClosestTownFromTile(this->tile, UINT_MAX);
283 break;
284
285 /* Construction date */
286 case 0x42: return TimerGameCalendar::date.base();
287
288 /* Object founder information */
289 case 0x44: return _current_company.base();
290
291 /* Object view */
292 case 0x48: return this->view;
293
294 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
295
296 /*
297 * Disallow the rest:
298 * 0x40: Relative position is passed as parameter during construction.
299 * 0x43: Animation counter is only for actual tiles.
300 * 0x47: Object colour is only valid when its built.
301 * 0x63: Animation counter of nearby tile, see above.
302 */
303 default:
304 goto unhandled;
305 }
306
307 /* If there's an invalid tile, then we don't have enough information at all. */
308 if (!IsValidTile(this->tile)) goto unhandled;
309 } else {
310 t = this->obj->town;
311 }
312
313 switch (variable) {
314 /* Relative position. */
315 case 0x40: {
316 TileIndex offset = this->tile - this->obj->location.tile;
317 uint offset_x = TileX(offset);
318 uint offset_y = TileY(offset);
319 return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
320 }
321
322 /* Tile information. */
323 case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
324
325 /* Construction date */
326 case 0x42: return this->obj->build_date.base();
327
328 /* Animation counter */
329 case 0x43: return GetAnimationFrame(this->tile);
330
331 /* Object founder information */
332 case 0x44: return GetTileOwner(this->tile).base();
333
334 /* Get town zone and Manhattan distance of closest town */
335 case 0x45: return to_underlying(GetTownRadiusGroup(t, this->tile)) << 16 | ClampTo<uint16_t>(DistanceManhattan(this->tile, t->xy));
336
337 /* Get square of Euclidean distance of closest town */
338 case 0x46: return DistanceSquare(this->tile, t->xy);
339
340 /* Object colour */
341 case 0x47: return this->obj->colour;
342
343 /* Object view */
344 case 0x48: return this->obj->view;
345
346 /* Get object ID at offset param */
347 case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
348
349 /* Get random tile bits at offset param */
350 case 0x61: {
351 TileIndex tile = GetNearbyTile(parameter, this->tile);
352 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
353 }
354
355 /* Land info of nearby tiles */
356 case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == nullptr ? ObjectID::Invalid() : this->obj->index, this->ro.grffile->grf_version >= 8);
357
358 /* Animation counter of nearby tile */
359 case 0x63: {
360 TileIndex tile = GetNearbyTile(parameter, this->tile);
361 return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
362 }
363
364 /* Count of object, distance of closest instance */
365 case 0x64: return GetCountAndDistanceOfClosestInstance(this->ro, parameter, this->ro.grffile->grfid, this->tile, this->obj);
366
367 case 0x7A: return GetBadgeVariableResult(*this->ro.grffile, this->spec->badges, parameter);
368 }
369
370unhandled:
371 Debug(grf, 1, "Unhandled object variable 0x{:X}", variable);
372
373 available = false;
374 return UINT_MAX;
375}
376
386ObjectResolverObject::ObjectResolverObject(const ObjectSpec *spec, Object *obj, TileIndex tile, uint8_t view,
387 CallbackID callback, uint32_t param1, uint32_t param2)
388 : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, spec, tile, view)
389{
390 this->root_spritegroup = spec->grf_prop.GetSpriteGroup(obj != nullptr);
391}
392
398 TownScopeResolver *ObjectResolverObject::GetTown()
399{
400 if (!this->town_scope.has_value()) {
401 Town *t;
402 if (this->object_scope.obj != nullptr) {
403 t = this->object_scope.obj->town;
404 } else {
405 t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
406 }
407 if (t == nullptr) return nullptr;
408 this->town_scope.emplace(*this, t, this->object_scope.obj == nullptr);
409 }
410 return &*this->town_scope;
411}
412
413 GrfSpecFeature ObjectResolverObject::GetFeature() const
414{
415 return GSF_OBJECTS;
416}
417
418uint32_t ObjectResolverObject::GetDebugID() const
419{
420 return this->object_scope.spec->grf_prop.local_id;
421}
422
435uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span<int32_t> regs100, uint8_t view)
436{
437 ObjectResolverObject object(spec, o, tile, view, callback, param1, param2);
438 return object.ResolveCallback(regs100);
439}
440
447 static void DrawTileLayout(const TileInfo *ti, const DrawTileSpriteSpan &dts, const ObjectSpec *spec)
448{
449 PaletteID palette = (spec->flags.Test(ObjectFlag::Uses2CC) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START) + Object::GetByTile(ti->tile)->colour;
450
451 SpriteID image = dts.ground.sprite;
452 PaletteID pal = dts.ground.pal;
453
454 if (GB(image, 0, SPRITE_WIDTH) != 0) {
455 /* If the ground sprite is the default flat water sprite, draw also canal/river borders
456 * Do not do this if the tile's WaterClass is 'land'. */
457 if ((image == SPR_FLAT_WATER_TILE || spec->flags.Test(ObjectFlag::DrawWater)) && IsTileOnWater(ti->tile)) {
458 DrawWaterClassGround(ti);
459 } else {
460 DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
461 }
462 }
463
464 DrawNewGRFTileSeq(ti, &dts, TO_STRUCTURES, 0, palette);
465}
466
472 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
473{
474 Object *o = Object::GetByTile(ti->tile);
475 ObjectResolverObject object(spec, o, ti->tile);
476
477 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
478 if (group == nullptr) return;
479
480 auto processor = group->ProcessRegisters(object, nullptr);
481 auto dts = processor.GetLayout();
482 DrawTileLayout(ti, dts, spec);
483}
484
492 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8_t view)
493{
494 ObjectResolverObject object(spec, nullptr, INVALID_TILE, view);
495 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
496 if (group == nullptr) return;
497
498 auto processor = group->ProcessRegisters(object, nullptr);
499 auto dts = processor.GetLayout();
500
501 PaletteID palette;
502 if (Company::IsValidID(_local_company)) {
503 /* Get the colours of our company! */
504 if (spec->flags.Test(ObjectFlag::Uses2CC)) {
505 const Livery &l = Company::Get(_local_company)->livery[0];
506 palette = SPR_2CCMAP_BASE + l.colour1 + l.colour2 * 16;
507 } else {
508 palette = GetCompanyPalette(_local_company);
509 }
510 } else {
511 /* There's no company, so just take the base palette. */
512 palette = spec->flags.Test(ObjectFlag::Uses2CC) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START;
513 }
514
515 SpriteID image = dts.ground.sprite;
516 PaletteID pal = dts.ground.pal;
517
518 if (GB(image, 0, SPRITE_WIDTH) != 0) {
519 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
520 }
521
522 DrawNewGRFTileSeqInGUI(x, y, &dts, 0, palette);
523}
524
535uint16_t StubGetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, int)
536{
537 return GetObjectCallback(callback, param1, param2, spec, o, tile);
538}
539
541 struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback, TileAnimationFrameAnimationHelper<Object> > {
542 static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED;
543 static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
544
545 static const ObjectCallbackMask cbm_animation_speed = ObjectCallbackMask::AnimationSpeed;
546 static const ObjectCallbackMask cbm_animation_next_frame = ObjectCallbackMask::AnimationNextFrame;
547};
548
553 void AnimateNewObjectTile(TileIndex tile)
554{
555 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
556 if (spec == nullptr || !spec->flags.Test(ObjectFlag::Animation)) return;
557
558 ObjectAnimationBase::AnimateTile(spec, Object::GetByTile(tile), tile, spec->flags.Test(ObjectFlag::AnimRandomBits));
559}
560
561static bool DoTriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec, uint32_t random, uint32_t var18_extra = 0)
562{
563 if (!spec->animation.triggers.Test(trigger)) return false;
564
565 ObjectAnimationBase::ChangeAnimationFrame(CBID_OBJECT_ANIMATION_TRIGGER, spec, o, tile, random, to_underlying(trigger) | var18_extra);
566 return true;
567}
568
576 bool TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
577{
578 return DoTriggerObjectTileAnimation(o, tile, trigger, spec, Random());
579}
580
587 bool TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
588{
589 if (!spec->animation.triggers.Test(trigger)) return false;
590
591 bool ret = true;
592 uint32_t random = Random();
593 for (TileIndex tile : o->location) {
594 if (DoTriggerObjectTileAnimation(o, tile, trigger, spec, random)) {
595 SB(random, 0, 16, Random());
596 } else {
597 ret = false;
598 }
599 }
600
601 return ret;
602}
SB
constexpr T SB(T &x, const uint8_t s, const uint8_t n, const U d)
Set n bits in x starting at bit s to d.
Definition bitmath_func.hpp:58
GB
static constexpr 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
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
NewGRFClass
Struct containing information relating to NewGRF classes for stations and airports.
Definition newgrf_class.h:26
NewGRFClass::Assign
static void Assign(Tspec *spec)
Assign a spec to one of the classes.
Definition newgrf_class_func.h:70
NewGRFClass::name
StringID name
Name of this class.
Definition newgrf_class.h:49
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:40
NewGRFClass::Get
static NewGRFClass * Get(Tindex class_index)
Get a particular class.
Definition newgrf_class_func.h:82
NewGRFClass::Allocate
static Tindex Allocate(uint32_t global_id)
Allocate a class with a given global class ID.
Definition newgrf_class_func.h:32
NewGRFClass::InsertDefaults
static void InsertDefaults()
Initialise the defaults.
Definition newgrf_airport.cpp:31
NewGRFClass::GetSpec
const Tspec * GetSpec(uint index) const
Get a spec from the class at a given index.
Definition newgrf_class_func.h:114
ObjectOverrideManager
Definition newgrf_commons.h:285
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:91
SpriteLayoutProcessor::GetLayout
DrawTileSpriteSpan GetLayout() const
Returns the result spritelayout after preprocessing.
Definition newgrf_commons.h:167
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:55
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
debug.h
Functions related to debugging.
Debug
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:74
genworld.h
Functions related to world/map generation.
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:1031
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:17
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
BorderFlag::Random
@ Random
Randomise borders.
DistanceSquare
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the 'Square' distance between the two given tiles.
Definition map.cpp:175
DistanceManhattan
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition map.cpp:158
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
GrfSpecFeature
GrfSpecFeature
Definition newgrf.h:68
newgrf_animation_base.h
Function implementations related to NewGRF animation.
GetBadgeVariableResult
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.
Definition newgrf_badge.cpp:225
newgrf_badge.h
Functions related to NewGRF badges.
StationCallbackMask::DrawTileLayout
@ DrawTileLayout
Use callback to select a tile layout to use when drawing.
CallbackID
CallbackID
List of implemented NewGRF callbacks.
Definition newgrf_callbacks.h:22
CBID_OBJECT_ANIMATION_TRIGGER
@ CBID_OBJECT_ANIMATION_TRIGGER
Called for periodically starting or stopping the animation.
Definition newgrf_callbacks.h:262
CBID_OBJECT_ANIMATION_NEXT_FRAME
@ CBID_OBJECT_ANIMATION_NEXT_FRAME
Determine the next animation frame for a house.
Definition newgrf_callbacks.h:259
CBID_OBJECT_ANIMATION_SPEED
@ CBID_OBJECT_ANIMATION_SPEED
Called to indicate how long the current animation frame should last.
Definition newgrf_callbacks.h:265
ObjectCallbackMask
ObjectCallbackMask
Callback masks for objects.
Definition newgrf_callbacks.h:414
ObjectCallbackMask::AnimationNextFrame
@ AnimationNextFrame
decides next animation frame
ObjectCallbackMask::AnimationSpeed
@ AnimationSpeed
decides animation speed
newgrf_class_func.h
Implementation of the NewGRF class' functions.
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:434
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:336
GetNearbyTile
TileIndex GetNearbyTile(uint8_t parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
Definition newgrf_commons.cpp:411
GetCountAndDistanceOfClosestInstance
static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &object, uint8_t param_set_id, 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 ...
Definition newgrf_industries.cpp:117
_object_specs
std::vector< ObjectSpec > _object_specs
All the object specifications.
Definition newgrf_object.cpp:37
ResetObjects
void ResetObjects()
This function initialize the spec arrays of objects.
Definition newgrf_object.cpp:125
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:492
_object_mngr
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
DrawNewObjectTile
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Definition newgrf_object.cpp:472
GetClosestObject
static uint32_t GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
Definition newgrf_object.cpp:214
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:170
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:535
TriggerObjectAnimation
bool TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
Definition newgrf_object.cpp:587
GetCountAndDistanceOfClosestInstance
static uint32_t GetCountAndDistanceOfClosestInstance(const ResolverObject &object, uint8_t local_id, uint32_t grfid, TileIndex tile, const Object *current)
Implementation of var 65.
Definition newgrf_object.cpp:235
GetNearbyObjectTileInformation
static uint32_t GetNearbyObjectTileInformation(uint8_t parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
Definition newgrf_object.cpp:199
TriggerObjectTileAnimation
bool TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
Definition newgrf_object.cpp:576
AnimateNewObjectTile
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Definition newgrf_object.cpp:553
GetObjectCallback
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span< int32_t > regs100, uint8_t view)
Perform a callback for an object.
Definition newgrf_object.cpp:435
newgrf_object.h
Functions related to NewGRF objects.
ObjectFlag::AnimRandomBits
@ AnimRandomBits
Object wants random bits in "next animation frame" callback.
ObjectFlag::OnlyInScenedit
@ OnlyInScenedit
Object can only be constructed in the scenario editor.
ObjectFlag::OnlyInGame
@ OnlyInGame
Object can only be built in game.
ObjectFlag::DrawWater
@ DrawWater
Object wants to be drawn on water.
ObjectFlag::Uses2CC
@ Uses2CC
Object wants 2CC colour mapping.
ObjectFlag::Animation
@ Animation
Object has animated tiles.
INVALID_OBJECT_CLASS
@ INVALID_OBJECT_CLASS
Class for the less fortunate.
Definition newgrf_object.h:51
newgrf_sound.h
Functions related to NewGRF provided sounds.
object_base.h
Base for all objects.
GetObjectType
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Definition object_cmd.cpp:66
object_map.h
Map accessors for object tiles.
GetObjectRandomBits
uint8_t GetObjectRandomBits(Tile t)
Get the random bits of this tile.
Definition object_map.h:59
GetObjectIndex
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition object_map.h:47
OBJECT_LIGHTHOUSE
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition object_type.h:19
ObjectType
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
INVALID_OBJECT_TYPE
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition object_type.h:27
NUM_OBJECTS
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition object_type.h:25
OBJECT_TRANSMITTER
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition object_type.h:18
ObjectAnimationTrigger
ObjectAnimationTrigger
Animation triggers for objects.
Definition object_type.h:36
NEW_OBJECT_OFFSET
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition object_type.h:24
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
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:130
DrawNewGRFTileSeqInGUI
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:139
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:174
PALETTE_RECOLOUR_START
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition sprites.h:1588
SPRITE_WIDTH
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition sprites.h:1549
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271
AnimationBase
Helper class for a unified approach to NewGRF animation.
Definition newgrf_animation_base.h:43
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:52
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:131
DrawTileSpriteSpan
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:67
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:316
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:326
GameCreationSettings::landscape
LandscapeType landscape
the landscape we're currently in
Definition settings_type.h:395
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition settings_type.h:634
Livery
Information about a particular livery.
Definition livery.h:79
Livery::colour2
Colours colour2
Second colour, for vehicles with 2CC support.
Definition livery.h:88
Livery::colour1
Colours colour1
First colour, for all vehicles.
Definition livery.h:87
NewGRFSpecBase< ObjectClassID >::index
uint16_t index
Index within class of this spec, invalid until inserted into class.
Definition newgrf_class.h:19
ObjectAnimationBase
Helper class for animation control.
Definition newgrf_object.cpp:541
ObjectResolverObject
A resolver object to be used with feature 0F spritegroups.
Definition newgrf_object.h:134
ObjectResolverObject::object_scope
ObjectScopeResolver object_scope
The object scope resolver.
Definition newgrf_object.h:135
ObjectResolverObject::town_scope
std::optional< TownScopeResolver > town_scope
The town scope resolver (created on the first call).
Definition newgrf_object.h:136
ObjectResolverObject::GetTown
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
Definition newgrf_object.cpp:398
ObjectResolverObject::GetFeature
GrfSpecFeature GetFeature() const override
Get the feature number being resolved for.
Definition newgrf_object.cpp:413
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:386
ObjectResolverObject::GetDebugID
uint32_t GetDebugID() const override
Get an identifier for the item being resolved.
Definition newgrf_object.cpp:418
ObjectScopeResolver::GetVariable
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.
Definition newgrf_object.cpp:262
ObjectScopeResolver::tile
TileIndex tile
The tile related to the object.
Definition newgrf_object.h:114
ObjectScopeResolver::view
uint8_t view
The view of the object.
Definition newgrf_object.h:115
ObjectScopeResolver::GetRandomBits
uint32_t GetRandomBits() const override
Get a few random bits.
Definition newgrf_object.cpp:159
ObjectScopeResolver::spec
const ObjectSpec * spec
Specification of the object type.
Definition newgrf_object.h:113
ObjectScopeResolver::obj
struct Object * obj
The object the callback is ran for.
Definition newgrf_object.h:112
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
ObjectSpec::IsEnabled
bool IsEnabled() const
Test if this object is enabled.
Definition newgrf_object.h:83
ObjectSpec::introduction_date
TimerGameCalendar::Date introduction_date
From when can this object be built.
Definition newgrf_object.h:70
ObjectSpec::grf_prop
StandardGRFFileProps grf_prop
Properties related the the grf file.
Definition newgrf_object.h:61
ObjectSpec::climate
LandscapeTypes climate
In which climates is this object available?
Definition newgrf_object.h:66
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:78
ObjectSpec::GetByTile
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Definition newgrf_object.cpp:69
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition newgrf_object.cpp:54
ObjectSpec::IsAvailable
bool IsAvailable() const
Check whether the object is available at this time.
Definition newgrf_object.cpp:97
ObjectSpec::Index
uint Index() const
Gets the index of this spec.
Definition newgrf_object.cpp:107
ObjectSpec::BindToClasses
static void BindToClasses()
Tie all ObjectSpecs to their class.
Definition newgrf_object.cpp:115
ObjectSpec::animation
AnimationInfo< ObjectAnimationTriggers > animation
Information about the animation.
Definition newgrf_object.h:63
ObjectSpec::flags
ObjectFlags flags
Flags/settings related to the object.
Definition newgrf_object.h:72
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:88
ObjectSpec::end_of_life_date
TimerGameCalendar::Date end_of_life_date
When can't this object be built anymore.
Definition newgrf_object.h:71
Object
An object, such as transmitter, on the map.
Definition object_base.h:23
Object::type
ObjectType type
Type of the object.
Definition object_base.h:24
Object::town
Town * town
Town the object is built in.
Definition object_base.h:25
Object::GetTypeCount
static uint16_t GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition object_base.h:67
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition object_cmd.cpp:55
Object::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:27
Object::view
uint8_t view
The view setting for this object.
Definition object_base.h:29
Object::location
TileArea location
Location of the object.
Definition object_base.h:26
Object::colour
uint8_t colour
Colour of the object, for display purpose.
Definition object_base.h:28
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:24
PoolID
Templated helper to make a PoolID a single POD value.
Definition pool_type.hpp:43
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:436
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:376
ResolverObject
Interface for SpriteGroup-s to access the gamestate.
Definition newgrf_spritegroup.h:288
ResolverObject::grffile
const GRFFile * grffile
GRFFile the resolved SpriteGroup belongs to.
Definition newgrf_spritegroup.h:352
ResolverObject::root_spritegroup
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Definition newgrf_spritegroup.h:353
ScopeResolver::ro
ResolverObject & ro
Surrounding resolver object.
Definition newgrf_spritegroup.h:270
StandardGRFFileProps::GetSpriteGroup
const struct SpriteGroup * GetSpriteGroup(bool entity_exists) const
Get the standard sprite group.
Definition newgrf_commons.h:394
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition newgrf_spritegroup.h:236
TileLayoutSpriteGroup::ProcessRegisters
SpriteLayoutProcessor ProcessRegisters(const ResolverObject &object, uint8_t *stage) const
Process registers and the construction stage into the sprite layout.
Definition newgrf_spritegroup.cpp:290
TownScopeResolver
Scope resolver for a town.
Definition newgrf_town.h:22
Town
Town data structure.
Definition town.h:63
Town::xy
TileIndex xy
town center tile
Definition town.h:64
tile_cmd.h
Generic 'commands' that can be performed on all tiles.
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
timer_game_calendar.h
Definition of the game-calendar-timer.
town.h
Base of the town class.
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:3952
GetTownRadiusGroup
HouseZone GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition town_cmd.cpp:2507
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition transparency.h:30
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:579
water.h
Functions related to water (management)
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:138