# sprite.h

Go to the documentation of this file.

    00001 /* $Id: sprite.h 18846 2010-01-17 15:05:25Z frosch $ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef SPRITE_H
    00013 #define SPRITE_H
    00014
    00015 #include "gfx_type.h"
    00016 #include "transparency.h"
    00017
    00018 #include "table/sprites.h"
    00019
    00020 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
    00021 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
    00022
    00023 /* The following describes bunch of sprites to be drawn together in a single 3D
    00024  * bounding box. Used especially for various multi-sprite buildings (like
    00025  * depots or stations): */
    00026
    00028 struct DrawTileSeqStruct {
    00029   int8 delta_x;
    00030   int8 delta_y;
    00031   int8 delta_z;
    00032   byte size_x;
    00033   byte size_y;
    00034   byte size_z;
    00035   PalSpriteID image;
    00036 };
    00037
    00039 struct DrawTileSprites {
    00040   PalSpriteID ground;
    00041   const DrawTileSeqStruct *seq;
    00042 };
    00043
    00048 struct DrawBuildingsTileStruct {
    00049   PalSpriteID ground;
    00050   PalSpriteID building;
    00051   byte subtile_x;
    00052   byte subtile_y;
    00053   byte width;
    00054   byte height;
    00055   byte dz;
    00056   byte draw_proc;  // this allows to specify a special drawing procedure.
    00057 };
    00058
    00060 #define foreach_draw_tile_seq(idx, list) for (idx = list; ((byte) idx->delta_x) != 0x80; idx++)
    00061
    00062 void DrawCommonTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned);
    00063 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned);
    00064
    00070 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette)
    00071 {
    00072   DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
    00073 }
    00074
    00080 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, SpriteID default_palette)
    00081 {
    00082   DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
    00083 }
    00084
    00088 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, SpriteID default_palette)
    00089 {
    00090   DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
    00091 }
    00092
    00096 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, SpriteID default_palette)
    00097 {
    00098   DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
    00099 }
    00100
    00105 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, SpriteID default_palette)
    00106 {
    00107   DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
    00108 }
    00109
    00121 static inline SpriteID SpriteLayoutPaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
    00122 {
    00123   if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
    00124     return (pal != 0 ? pal : default_pal);
    00125   } else {
    00126     return PAL_NONE;
    00127   }
    00128 }
    00129
    00140 static inline SpriteID GroundSpritePaletteTransform(SpriteID image, SpriteID pal, SpriteID default_pal)
    00141 {
    00142   if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
    00143     return (pal != 0 ? pal : default_pal);
    00144   } else {
    00145     return PAL_NONE;
    00146   }
    00147 }
    00148
    00149 #endif /* SPRITE_H */