OpenTTD Source  20241108-master-g80f628063a
sprite.h
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 #ifndef SPRITE_H
11 #define SPRITE_H
12 
13 #include "transparency.h"
14 
15 #include "table/sprites.h"
16 
17 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
18 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
19 
20 /* The following describes bunch of sprites to be drawn together in a single 3D
21  * bounding box. Used especially for various multi-sprite buildings (like
22  * depots or stations): */
23 
26  int8_t delta_x;
27  int8_t delta_y;
28  int8_t delta_z;
29  uint8_t size_x;
30  uint8_t size_y;
31  uint8_t size_z;
32  PalSpriteID image;
33 
36  {
37  this->delta_x = (int8_t)0x80;
38  }
39 
41  bool IsTerminator() const
42  {
43  return (uint8_t)this->delta_x == 0x80;
44  }
45 
47  bool IsParentSprite() const
48  {
49  return (uint8_t)this->delta_z != 0x80;
50  }
51 };
52 
61 };
62 
68  PalSpriteID ground;
69  PalSpriteID building;
70  uint8_t subtile_x;
71  uint8_t subtile_y;
72  uint8_t width;
73  uint8_t height;
74  uint8_t dz;
75  uint8_t draw_proc; // this allows to specify a special drawing procedure.
76 };
77 
79 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
80 
81 void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
82 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
83 
89 inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
90 {
91  DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
92 }
93 
99 inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
100 {
101  DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
102 }
103 
107 inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
108 {
109  DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
110 }
111 
115 inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
116 {
117  DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
118 }
119 
124 inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
125 {
126  DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
127 }
128 
133 inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
134 {
135  DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
136 }
137 
150 {
152  return (pal != 0 ? pal : default_pal);
153  } else {
154  return PAL_NONE;
155  }
156 }
157 
169 {
170  if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
171  return (pal != 0 ? pal : default_pal);
172  } else {
173  return PAL_NONE;
174  }
175 }
176 
177 #endif /* SPRITE_H */
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:18
uint32_t PaletteID
The number of the palette.
Definition: gfx_type.h:19
void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence.
Definition: sprite.cpp:30
void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence in GUI with railroad specifics.
Definition: sprite.h:99
void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
Draw TTD sprite sequence in GUI.
Definition: sprite.h:115
void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32_t stage, PaletteID default_palette)
Draw NewGRF industrytile or house sprite layout.
Definition: sprite.h:124
void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
Draws a tile sprite sequence in the GUI.
Definition: sprite.cpp:92
void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
Draw TTD sprite sequence on tile.
Definition: sprite.h:107
PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layou...
Definition: sprite.h:149
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition: sprite.h:133
void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t total_offset, uint32_t newgrf_offset, PaletteID default_palette)
Draw tile sprite sequence on tile with railroad specifics.
Definition: sprite.h:89
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
This file contains all sprite-related enums and defines.
static constexpr uint8_t PALETTE_MODIFIER_TRANSPARENT
when a sprite is to be displayed transparently, this bit needs to be set.
Definition: sprites.h:1547
static constexpr uint8_t PALETTE_MODIFIER_COLOUR
this bit is set when a recolouring process is in action
Definition: sprites.h:1548
This structure is the same for both Industries and Houses.
Definition: sprite.h:67
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition: sprite.h:25
int8_t delta_z
0x80 identifies child sprites
Definition: sprite.h:28
bool IsParentSprite() const
Check whether this is a parent sprite with a boundingbox.
Definition: sprite.h:47
bool IsTerminator() const
Check whether this is a sequence terminator.
Definition: sprite.h:41
void MakeTerminator()
Make this struct a sequence terminator.
Definition: sprite.h:35
int8_t delta_x
0x80 is sequence terminator
Definition: sprite.h:26
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
Combination of a palette sprite and a 'real' sprite.
Definition: gfx_type.h:23
Tile information, used while rendering the tile.
Definition: tile_cmd.h:43
Functions related to transparency.
TransparencyOption
Transparency option bits: which position in _transparency_opt stands for which transparency.
Definition: transparency.h:22