OpenTTD: src/sprite.h Source File

OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

sprite.h
Go to the documentation of this file.
1 /* $Id: sprite.h 23706 2012-01-01 17:36:19Z smatz $ */
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 #ifndef SPRITE_H
13 #define SPRITE_H
14
15 #include "transparency.h"
16
17 #include "table/sprites.h"
18
19 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
20 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
21
22 /* The following describes bunch of sprites to be drawn together in a single 3D
23 * bounding box. Used especially for various multi-sprite buildings (like
24 * depots or stations): */
25
27 struct DrawTileSeqStruct {
28 int8 delta_x;
29 int8 delta_y;
30 int8 delta_z;
31 byte size_x;
32 byte size_y;
33 byte size_z;
34 PalSpriteID image;
35
37 void MakeTerminator()
38 {
39 this->delta_x = (int8)0x80;
40 }
41
43 bool IsTerminator() const
44 {
45 return (byte)this->delta_x == 0x80;
46 }
47
49 bool IsParentSprite() const
50 {
51 return (byte)this->delta_z != 0x80;
52 }
53 };
54
60 struct DrawTileSprites {
61 PalSpriteID ground;
62 const DrawTileSeqStruct *seq;
63 };
64
69 struct DrawBuildingsTileStruct {
70 PalSpriteID ground;
71 PalSpriteID building;
72 byte subtile_x;
73 byte subtile_y;
74 byte width;
75 byte height;
76 byte dz;
77 byte draw_proc; // this allows to specify a special drawing procedure.
78 };
79
81 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
82
83 void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
84 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
85
91 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
92 {
93 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
94 }
95
101 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
102 {
103 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
104 }
105
109 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
110 {
111 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
112 }
113
117 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
118 {
119 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
120 }
121
126 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
127 {
128 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
129 }
130
135 static inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
136 {
137 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
138 }
139
151 static inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
152 {
153 if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
154 return (pal != 0 ? pal : default_pal);
155 } else {
156 return PAL_NONE;
157 }
158 }
159
170 static inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
171 {
172 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
173 return (pal != 0 ? pal : default_pal);
174 } else {
175 return PAL_NONE;
176 }
177 }
178
179 #endif /* SPRITE_H */