(svn r27724) -Cleanup: Remove pointless usage of IsOpenTTDBaseGRF. System GRFs are...
[openttd.git] / src / sprite.h
blob16da834c75d29a1c5672ab886e6b23f023a8e227
1 /* $Id$ */
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 */
10 /** @file sprite.h Base for drawing complex sprites. */
12 #ifndef SPRITE_H
13 #define SPRITE_H
15 #include "transparency.h"
17 #include "table/sprites.h"
19 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
20 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
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): */
26 /** A tile child sprite and palette to draw for stations etc, with 3D bounding box */
27 struct DrawTileSeqStruct {
28 int8 delta_x; ///< \c 0x80 is sequence terminator
29 int8 delta_y;
30 int8 delta_z; ///< \c 0x80 identifies child sprites
31 byte size_x;
32 byte size_y;
33 byte size_z;
34 PalSpriteID image;
36 /** Make this struct a sequence terminator. */
37 void MakeTerminator()
39 this->delta_x = (int8)0x80;
42 /** Check whether this is a sequence terminator. */
43 bool IsTerminator() const
45 return (byte)this->delta_x == 0x80;
48 /** Check whether this is a parent sprite with a boundingbox. */
49 bool IsParentSprite() const
51 return (byte)this->delta_z != 0x80;
55 /**
56 * Ground palette sprite of a tile, together with its sprite layout.
57 * This struct is used for static sprite layouts in the code.
58 * For allocated ones from NewGRF see #NewGRFSpriteLayout.
60 struct DrawTileSprites {
61 PalSpriteID ground; ///< Palette and sprite for the ground
62 const DrawTileSeqStruct *seq; ///< Array of child sprites. Terminated with a terminator entry
65 /**
66 * This structure is the same for both Industries and Houses.
67 * Buildings here reference a general type of construction
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.
80 /** Iterate through all DrawTileSeqStructs in DrawTileSprites. */
81 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
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);
86 /**
87 * Draw tile sprite sequence on tile with railroad specifics.
88 * @param total_offset Spriteoffset from normal rail to current railtype.
89 * @param newgrf_offset Startsprite of the Action1 to use.
91 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
93 DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
96 /**
97 * Draw tile sprite sequence in GUI with railroad specifics.
98 * @param total_offset Spriteoffset from normal rail to current railtype.
99 * @param newgrf_offset Startsprite of the Action1 to use.
101 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
103 DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
107 * Draw TTD sprite sequence on tile.
109 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
111 DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
115 * Draw TTD sprite sequence in GUI.
117 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
119 DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
123 * Draw NewGRF industrytile or house sprite layout
124 * @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage.
126 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
128 DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
132 * Draw NewGRF object in GUI
133 * @param stage Sprite inside the Action1 spritesets to use, i.e. construction stage.
135 static inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
137 DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
141 * Applies PALETTE_MODIFIER_TRANSPARENT and PALETTE_MODIFIER_COLOUR to a palette entry of a sprite layout entry
142 * @note for ground sprites use #GroundSpritePaletteTransform
143 * @note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
144 * when to use the default palette.
146 * @param image The sprite to draw
147 * @param pal The palette from the sprite layout
148 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
149 * @return The palette to use
151 static inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
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;
161 * Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite
162 * @note Not useable for OTTD internal spritelayouts from table/xxx_land.h as PALETTE_MODIFIER_TRANSPARENT is only set
163 * when to use the default palette.
165 * @param image The sprite to draw
166 * @param pal The palette from the sprite layout
167 * @param default_pal The default recolour sprite to use (typically company colour resp. random industry/house colour)
168 * @return The palette to use
170 static inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
172 if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
173 return (pal != 0 ? pal : default_pal);
174 } else {
175 return PAL_NONE;
179 #endif /* SPRITE_H */