OpenTTD
newgrf_object.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "company_base.h"
14 #include "company_func.h"
15 #include "debug.h"
16 #include "genworld.h"
17 #include "newgrf_class_func.h"
18 #include "newgrf_object.h"
19 #include "newgrf_sound.h"
20 #include "object_base.h"
21 #include "object_map.h"
22 #include "tile_cmd.h"
23 #include "town.h"
24 #include "water.h"
25 #include "newgrf_animation_base.h"
26 
27 #include "safeguards.h"
28 
31 
35 
41 /* static */ const ObjectSpec *ObjectSpec::Get(ObjectType index)
42 {
43  assert(index < NUM_OBJECTS);
44  return &_object_specs[index];
45 }
46 
52 /* static */ const ObjectSpec *ObjectSpec::GetByTile(TileIndex tile)
53 {
54  return ObjectSpec::Get(GetObjectType(tile));
55 }
56 
62 {
63  return this->enabled && HasBit(this->climate, _settings_game.game_creation.landscape) &&
64  (this->flags & ((_game_mode != GM_EDITOR && !_generating_world) ? OBJECT_FLAG_ONLY_IN_SCENEDIT : OBJECT_FLAG_ONLY_IN_GAME)) == 0;
65 }
66 
72 {
73  return this->IsEverAvailable() && _date > this->introduction_date;
74 }
75 
81 {
82  return this->WasEverAvailable() &&
83  (_date < this->end_of_life_date || this->end_of_life_date < this->introduction_date + 365);
84 }
85 
90 uint ObjectSpec::Index() const
91 {
92  return this - _object_specs;
93 }
94 
97 {
98  /* Clean the pool. */
99  for (uint16 i = 0; i < NUM_OBJECTS; i++) {
100  _object_specs[i] = {};
101  }
102 
103  /* And add our originals. */
104  MemCpyT(_object_specs, _original_objects, lengthof(_original_objects));
105 
106  for (uint16 i = 0; i < lengthof(_original_objects); i++) {
107  _object_specs[i].grf_prop.local_id = i;
108  }
109 }
110 
111 template <typename Tspec, typename Tid, Tid Tmax>
113 {
114  ObjectClassID cls = ObjectClass::Allocate('LTHS');
115  ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_LTHS;
116  _object_specs[OBJECT_LIGHTHOUSE].cls_id = cls;
117  ObjectClass::Assign(&_object_specs[OBJECT_LIGHTHOUSE]);
118 
119  cls = ObjectClass::Allocate('TRNS');
120  ObjectClass::Get(cls)->name = STR_OBJECT_CLASS_TRNS;
121  _object_specs[OBJECT_TRANSMITTER].cls_id = cls;
122  ObjectClass::Assign(&_object_specs[OBJECT_TRANSMITTER]);
123 }
124 
125 template <typename Tspec, typename Tid, Tid Tmax>
127 {
128  return this->GetSpec(index)->IsEverAvailable();
129 }
130 
132 
133 /* virtual */ uint32 ObjectScopeResolver::GetRandomBits() const
134 {
135  return IsValidTile(this->tile) && IsTileType(this->tile, MP_OBJECT) ? GetObjectRandomBits(this->tile) : 0;
136 }
137 
144 static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
145 {
146  if (!IsTileType(tile, MP_OBJECT)) {
147  return 0xFFFF;
148  }
149 
150  const Object *o = Object::GetByTile(tile);
151  const ObjectSpec *spec = ObjectSpec::Get(o->type);
152 
153  /* Default objects have no associated NewGRF file */
154  if (spec->grf_prop.grffile == NULL) {
155  return 0xFFFE; // Defined in another grf file
156  }
157 
158  if (spec->grf_prop.grffile->grfid == cur_grfid) { // same object, same grf ?
159  return spec->grf_prop.local_id | o->view << 16;
160  }
161 
162  return 0xFFFE; // Defined in another grf file
163 }
164 
173 static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
174 {
175  if (parameter != 0) tile = GetNearbyTile(parameter, tile); // only perform if it is required
176  bool is_same_object = (IsTileType(tile, MP_OBJECT) && GetObjectIndex(tile) == index);
177 
178  return GetNearbyTileInformation(tile, grf_version8) | (is_same_object ? 1 : 0) << 8;
179 }
180 
188 static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
189 {
190  uint32 best_dist = UINT32_MAX;
191  const Object *o;
192  FOR_ALL_OBJECTS(o) {
193  if (o->type != type || o == current) continue;
194 
195  best_dist = min(best_dist, DistanceManhattan(tile, o->location.tile));
196  }
197 
198  return best_dist;
199 }
200 
209 static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
210 {
211  uint32 grf_id = GetRegister(0x100); // Get the GRFID of the definition to look for in register 100h
212  uint32 idx;
213 
214  /* Determine what will be the object type to look for */
215  switch (grf_id) {
216  case 0: // this is a default object type
217  idx = local_id;
218  break;
219 
220  case 0xFFFFFFFF: // current grf
221  grf_id = grfid;
222  FALLTHROUGH;
223 
224  default: // use the grfid specified in register 100h
225  idx = _object_mngr.GetID(local_id, grf_id);
226  break;
227  }
228 
229  /* If the object type is invalid, there is none and the closest is far away. */
230  if (idx >= NUM_OBJECTS) return 0 | 0xFFFF;
231 
232  return Object::GetTypeCount(idx) << 16 | min(GetClosestObject(tile, idx, current), 0xFFFF);
233 }
234 
236 /* virtual */ uint32 ObjectScopeResolver::GetVariable(byte variable, uint32 parameter, bool *available) const
237 {
238  /* We get the town from the object, or we calculate the closest
239  * town if we need to when there's no object. */
240  const Town *t = NULL;
241 
242  if (this->obj == NULL) {
243  switch (variable) {
244  /* Allow these when there's no object. */
245  case 0x41:
246  case 0x60:
247  case 0x61:
248  case 0x62:
249  case 0x64:
250  break;
251 
252  /* Allow these, but find the closest town. */
253  case 0x45:
254  case 0x46:
255  if (!IsValidTile(this->tile)) goto unhandled;
256  t = ClosestTownFromTile(this->tile, UINT_MAX);
257  break;
258 
259  /* Construction date */
260  case 0x42: return _date;
261 
262  /* Object founder information */
263  case 0x44: return _current_company;
264 
265  /* Object view */
266  case 0x48: return this->view;
267 
268  /*
269  * Disallow the rest:
270  * 0x40: Relative position is passed as parameter during construction.
271  * 0x43: Animation counter is only for actual tiles.
272  * 0x47: Object colour is only valid when its built.
273  * 0x63: Animation counter of nearby tile, see above.
274  */
275  default:
276  goto unhandled;
277  }
278 
279  /* If there's an invalid tile, then we don't have enough information at all. */
280  if (!IsValidTile(this->tile)) goto unhandled;
281  } else {
282  t = this->obj->town;
283  }
284 
285  switch (variable) {
286  /* Relative position. */
287  case 0x40: {
288  uint offset = this->tile - this->obj->location.tile;
289  uint offset_x = TileX(offset);
290  uint offset_y = TileY(offset);
291  return offset_y << 20 | offset_x << 16 | offset_y << 8 | offset_x;
292  }
293 
294  /* Tile information. */
295  case 0x41: return GetTileSlope(this->tile) << 8 | GetTerrainType(this->tile);
296 
297  /* Construction date */
298  case 0x42: return this->obj->build_date;
299 
300  /* Animation counter */
301  case 0x43: return GetAnimationFrame(this->tile);
302 
303  /* Object founder information */
304  case 0x44: return GetTileOwner(this->tile);
305 
306  /* Get town zone and Manhattan distance of closest town */
307  case 0x45: return GetTownRadiusGroup(t, this->tile) << 16 | min(DistanceManhattan(this->tile, t->xy), 0xFFFF);
308 
309  /* Get square of Euclidian distance of closes town */
310  case 0x46: return GetTownRadiusGroup(t, this->tile) << 16 | min(DistanceSquare(this->tile, t->xy), 0xFFFF);
311 
312  /* Object colour */
313  case 0x47: return this->obj->colour;
314 
315  /* Object view */
316  case 0x48: return this->obj->view;
317 
318  /* Get object ID at offset param */
319  case 0x60: return GetObjectIDAtOffset(GetNearbyTile(parameter, this->tile), this->ro.grffile->grfid);
320 
321  /* Get random tile bits at offset param */
322  case 0x61: {
323  TileIndex tile = GetNearbyTile(parameter, this->tile);
324  return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetObjectRandomBits(tile) : 0;
325  }
326 
327  /* Land info of nearby tiles */
328  case 0x62: return GetNearbyObjectTileInformation(parameter, this->tile, this->obj == NULL ? INVALID_OBJECT : this->obj->index, this->ro.grffile->grf_version >= 8);
329 
330  /* Animation counter of nearby tile */
331  case 0x63: {
332  TileIndex tile = GetNearbyTile(parameter, this->tile);
333  return (IsTileType(tile, MP_OBJECT) && Object::GetByTile(tile) == this->obj) ? GetAnimationFrame(tile) : 0;
334  }
335 
336  /* Count of object, distance of closest instance */
337  case 0x64: return GetCountAndDistanceOfClosestInstance(parameter, this->ro.grffile->grfid, this->tile, this->obj);
338  }
339 
340 unhandled:
341  DEBUG(grf, 1, "Unhandled object variable 0x%X", variable);
342 
343  *available = false;
344  return UINT_MAX;
345 }
346 
357  CallbackID callback, uint32 param1, uint32 param2)
358  : ResolverObject(spec->grf_prop.grffile, callback, param1, param2), object_scope(*this, obj, tile, view)
359 {
360  this->town_scope = NULL;
361  this->root_spritegroup = (obj == NULL && spec->grf_prop.spritegroup[CT_PURCHASE_OBJECT] != NULL) ?
363 }
364 
365 ObjectResolverObject::~ObjectResolverObject()
366 {
367  delete this->town_scope;
368 }
369 
376 {
377  if (this->town_scope == NULL) {
378  Town *t;
379  if (this->object_scope.obj != NULL) {
380  t = this->object_scope.obj->town;
381  } else {
382  t = ClosestTownFromTile(this->object_scope.tile, UINT_MAX);
383  }
384  if (t == NULL) return NULL;
385  this->town_scope = new TownScopeResolver(*this, t, this->object_scope.obj == NULL);
386  }
387  return this->town_scope;
388 }
389 
401 uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
402 {
403  ObjectResolverObject object(spec, o, tile, view, callback, param1, param2);
404  return object.ResolveCallback();
405 }
406 
413 static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
414 {
415  const DrawTileSprites *dts = group->ProcessRegisters(NULL);
416  PaletteID palette = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START) + Object::GetByTile(ti->tile)->colour;
417 
418  SpriteID image = dts->ground.sprite;
419  PaletteID pal = dts->ground.pal;
420 
421  if (GB(image, 0, SPRITE_WIDTH) != 0) {
422  /* If the ground sprite is the default flat water sprite, draw also canal/river borders
423  * Do not do this if the tile's WaterClass is 'land'. */
424  if ((image == SPR_FLAT_WATER_TILE || spec->flags & OBJECT_FLAG_DRAW_WATER) && IsTileOnWater(ti->tile)) {
425  DrawWaterClassGround(ti);
426  } else {
427  DrawGroundSprite(image, GroundSpritePaletteTransform(image, pal, palette));
428  }
429  }
430 
431  DrawNewGRFTileSeq(ti, dts, TO_STRUCTURES, 0, palette);
432 }
433 
439 void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
440 {
441  Object *o = Object::GetByTile(ti->tile);
442  ObjectResolverObject object(spec, o, ti->tile);
443 
444  const SpriteGroup *group = object.Resolve();
445  if (group == NULL || group->type != SGT_TILELAYOUT) return;
446 
447  DrawTileLayout(ti, (const TileLayoutSpriteGroup *)group, spec);
448 }
449 
457 void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
458 {
459  ObjectResolverObject object(spec, NULL, INVALID_TILE, view);
460  const SpriteGroup *group = object.Resolve();
461  if (group == NULL || group->type != SGT_TILELAYOUT) return;
462 
463  const DrawTileSprites *dts = ((const TileLayoutSpriteGroup *)group)->ProcessRegisters(NULL);
464 
465  PaletteID palette;
467  /* Get the colours of our company! */
468  if (spec->flags & OBJECT_FLAG_2CC_COLOUR) {
469  const Livery *l = Company::Get(_local_company)->livery;
470  palette = SPR_2CCMAP_BASE + l->colour1 + l->colour2 * 16;
471  } else {
472  palette = COMPANY_SPRITE_COLOUR(_local_company);
473  }
474  } else {
475  /* There's no company, so just take the base palette. */
476  palette = (spec->flags & OBJECT_FLAG_2CC_COLOUR) ? SPR_2CCMAP_BASE : PALETTE_RECOLOUR_START;
477  }
478 
479  SpriteID image = dts->ground.sprite;
480  PaletteID pal = dts->ground.pal;
481 
482  if (GB(image, 0, SPRITE_WIDTH) != 0) {
483  DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
484  }
485 
486  DrawNewGRFTileSeqInGUI(x, y, dts, 0, palette);
487 }
488 
500 uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
501 {
502  return GetObjectCallback(callback, param1, param2, spec, o, tile);
503 }
504 
506 struct ObjectAnimationBase : public AnimationBase<ObjectAnimationBase, ObjectSpec, Object, int, StubGetObjectCallback> {
507  static const CallbackID cb_animation_speed = CBID_OBJECT_ANIMATION_SPEED;
508  static const CallbackID cb_animation_next_frame = CBID_OBJECT_ANIMATION_NEXT_FRAME;
509 
510  static const ObjectCallbackMask cbm_animation_speed = CBM_OBJ_ANIMATION_SPEED;
511  static const ObjectCallbackMask cbm_animation_next_frame = CBM_OBJ_ANIMATION_NEXT_FRAME;
512 };
513 
519 {
520  const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
521  if (spec == NULL || !(spec->flags & OBJECT_FLAG_ANIMATION)) return;
522 
524 }
525 
534 {
535  if (!HasBit(spec->animation.triggers, trigger)) return;
536 
538 }
539 
547 {
548  if (!HasBit(spec->animation.triggers, trigger)) return;
549 
550  TILE_AREA_LOOP(tile, o->location) {
551  TriggerObjectTileAnimation(o, tile, trigger, spec);
552  }
553 }
Implementation of the NewGRF class&#39; functions.
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:20
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
Definition of stuff that is very close to a company, like the company struct itself.
Maximum number of classes.
Definition: newgrf_object.h:50
Object wants 2CC colour mapping.
Definition: newgrf_object.h:36
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:72
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:27
Tile information, used while rendering the tile.
Definition: tile_cmd.h:44
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition: object_type.h:18
bool IsAvailable() const
Check whether the object is available at this time.
byte landscape
the landscape we&#39;re currently in
decides next animation frame
uint16 triggers
The triggers that trigger animation.
decides animation speed
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
Town * town
Town the object is built in.
Definition: object_base.h:27
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definition: tile_map.h:252
Functions related to debugging.
static void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:126
Interface for SpriteGroup-s to access the gamestate.
uint32 GetTerrainType(TileIndex tile, TileContext context)
Function used by houses (and soon industries) to get information on type of "terrain" the tile it is ...
TownScopeResolver * GetTown()
Get the town resolver scope that belongs to this object resolver.
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:62
static byte GetObjectRandomBits(TileIndex t)
Get the random bits of this tile.
Definition: object_map.h:61
bool IsEverAvailable() const
Check whether the object might be available at some point in this game with the current game mode...
static void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition: sprite.h:135
static uint32 GetCountAndDistanceOfClosestInstance(byte local_id, uint32 grfid, TileIndex tile, const Object *current)
Implementation of var 65.
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:207
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:30
Object wants to be drawn on water.
Definition: newgrf_object.h:38
#define INSTANTIATE_NEWGRF_CLASS_METHODS(name, Tspec, Tid, Tmax)
Force instantiation of the methods so we don&#39;t get linker errors.
Determine the next animation frame for a house.
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:60
Date end_of_life_date
When can&#39;t this object be built anymore.
Definition: newgrf_object.h:71
static const CargoID CT_PURCHASE_OBJECT
Mapping of purchase for objects.
static void DrawTileLayout(const TileInfo *ti, const TileLayoutSpriteGroup *group, const ObjectSpec *spec)
Draw an group of sprites on the map.
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Functions related to world/map generation.
Contains objects such as transmitters and owned land.
Definition: tile_type.h:53
Date introduction_date
From when can this object be built.
Definition: newgrf_object.h:70
static void ChangeAnimationFrame(CallbackID cb, const ObjectSpec *spec, Object *obj, TileIndex tile, uint32 random_bits, uint32 trigger, int extra_data=0)
Check a callback to determine what the next animation step is and execute that step.
bool IsUIAvailable(uint index) const
Check whether the spec will be available to the user at some point in time.
static const ObjectID INVALID_OBJECT
An invalid object.
Definition: object_type.h:36
static void AnimateTile(const ObjectSpec *spec, Object *obj, TileIndex tile, bool random_animation, int extra_data=0)
Animate a single tile.
Object scope resolver.
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
ObjectSpec _object_specs[NUM_OBJECTS]
All the object specifications.
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Functions related to NewGRF objects.
const SpriteGroup * root_spritegroup
Root SpriteGroup to use for resolving.
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:61
ObjectCallbackMask
Callback masks for objects.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:163
virtual uint16 GetID(uint8 grf_local_id, uint32 grfid) const
Return the ID (if ever available) of a previously inserted entity.
Base for all objects.
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:3329
void ResetObjects()
This function initialize the spec arrays of objects.
ObjectScopeResolver object_scope
The object scope resolver.
Struct containing information relating to NewGRF classes for stations and airports.
Definition: newgrf_class.h:21
static uint32 GetRegister(uint i)
Gets the value of a so-called newgrf "register".
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
bool enabled
Is this spec enabled?
Definition: newgrf_object.h:78
TileIndex xy
town center tile
Definition: town.h:56
TileIndex GetNearbyTile(byte parameter, TileIndex tile, bool signed_offsets, Axis axis)
Get the tile at the given offset.
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:152
const DrawTileSprites * ProcessRegisters(uint8 *stage) const
Process registers and the construction stage into the sprite layout.
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
TileIndex tile
Tile index.
Definition: tile_cmd.h:48
Object can only be built in game.
Definition: newgrf_object.h:35
struct Object * obj
The object the callback is ran for.
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:60
void DrawNewObjectTileInGUI(int x, int y, const ObjectSpec *spec, uint8 view)
Draw representation of an object (tile) for GUI purposes.
TileIndex tile
The tile related to the object.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:180
Object can only be constructed in the scenario editor.
Definition: newgrf_object.h:28
AnimationInfo animation
Information about the animation.
Definition: newgrf_object.h:73
uint Index() const
Gets the index of this spec.
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
Function implementations related to NewGRF animation.
Map accessors for object tiles.
Called to indicate how long the current animation frame should last.
A number of safeguards to prevent using unsafe methods.
Scope resolver for a town.
Definition: newgrf_town.h:24
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:170
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
ObjectOverrideManager _object_mngr(NEW_OBJECT_OFFSET, NUM_OBJECTS, INVALID_OBJECT_TYPE)
The override manager for our objects.
An object, such as transmitter, on the map.
Definition: object_base.h:25
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition: object_type.h:26
Information about a particular livery.
Definition: livery.h:80
static uint32 GetObjectIDAtOffset(TileIndex tile, uint32 cur_grfid)
Make an analysis of a tile and get the object type.
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
static uint32 GetNearbyObjectTileInformation(byte parameter, TileIndex tile, ObjectID index, bool grf_version8)
Based on newhouses equivalent, but adapted for newobjects.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
static T min(const T a, const T b)
Returns the minimum of two values.
Definition: math_func.hpp:42
number of bits for the sprite number
Definition: sprites.h:1505
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
Returns the bit corresponding to the town zone of the specified tile.
Definition: town_cmd.cpp:2039
uint16 ObjectType
Types of objects.
Definition: object_type.h:16
Object wants random bits in "next animation frame" callback.
Definition: newgrf_object.h:40
ObjectResolverObject(const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view=0, CallbackID callback=CBID_NO_CALLBACK, uint32 param1=0, uint32 param2=0)
Constructor of the object resolver.
static uint32 GetClosestObject(TileIndex tile, ObjectType type, const Object *current)
Get the closest object of a given type.
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:83
const struct SpriteGroup * spritegroup[Tcnt]
pointer to the different sprites of the entity
Object has animated tiles.
Definition: newgrf_object.h:34
uint16 StubGetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, int extra_data)
Perform a callback for an object.
static void MemCpyT(T *destination, const T *source, size_t num=1)
Type-safe version of memcpy().
Definition: mem_func.hpp:25
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:36
const ObjectSpec _original_objects[]
Specification of the original object structures.
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:19
Functions related to companies.
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:61
static const PaletteID PALETTE_RECOLOUR_START
First recolour sprite for company colours.
Definition: sprites.h:1549
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:61
uint32 ObjectID
Unique identifier for an object.
Definition: object_type.h:31
static uint16 GetTypeCount(ObjectType type)
Get the count of objects for this type.
Definition: object_base.h:67
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
uint32 GetNearbyTileInformation(TileIndex tile, bool grf_version8)
Common part of station var 0x67, house var 0x62, indtile var 0x60, industry var 0x62.
CompanyByte _current_company
Company currently doing an action.
Definition: company_cmd.cpp:47
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
TownScopeResolver * town_scope
The town scope resolver (created on the first call).
Helper class for a unified approach to NewGRF animation.
uint DistanceManhattan(TileIndex t0, TileIndex t1)
Gets the Manhattan distance between the two given tiles.
Definition: map.cpp:159
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:217
TileArea location
Location of the object.
Definition: object_base.h:28
CallbackID callback
Callback being resolved.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
ObjectType type
Type of the object.
Definition: object_base.h:26
uint32 GetVariable(byte variable, uint32 parameter, bool *available) const
Used by the resolver to get values for feature 0F deterministic spritegroups.
Town data structure.
Definition: town.h:55
static NewGRFClass * Get(Tid cls_id)
Get a particular class.
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:49
other objects such as transmitters and lighthouses
Definition: transparency.h:31
ObjectAnimationTrigger
Animation triggers for objects.
Helper class for animation control.
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition: viewport.cpp:570
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-NULL) Titem.
Definition: pool_type.hpp:235
uint16 local_id
id defined by the grf file for this entity
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:52
static void InsertDefaults()
Initialise the defaults.
A resolver object to be used with feature 0F spritegroups.
const struct GRFFile * grffile
grf file that introduced this entity
CallbackID
List of implemented NewGRF callbacks.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Functions related to NewGRF provided sounds.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:85
Base of the town class.
byte colour1
First colour, for all vehicles.
Definition: livery.h:82
GameCreationSettings game_creation
settings used during the creation of a game (map)
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
uint DistanceSquare(TileIndex t0, TileIndex t1)
Gets the &#39;Square&#39; distance between the two given tiles.
Definition: map.cpp:176
byte view
The view setting for this object.
Definition: object_base.h:31
Functions related to water (management)
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:130
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:25
ObjectClassID cls_id
The class to which this spec belongs.
Definition: newgrf_object.h:63
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Date _date
Current date in days (day counter)
Definition: date.cpp:28
uint8 climate
In which climates is this object available?
Definition: newgrf_object.h:66
static const ObjectType INVALID_OBJECT_TYPE
An invalid object.
Definition: object_type.h:28
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition: object_type.h:19
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:834
Generic &#39;commands&#39; that can be performed on all tiles.
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:63
Called for periodically starting or stopping the animation.
ObjectClassID
Class IDs for objects.
Definition: newgrf_object.h:48
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition: gfx_type.h:26
StringID name
Name of this class.
Definition: newgrf_class.h:41