sprite.h

Go to the documentation of this file.
00001 /* $Id$ */
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 "transparency.h"
00016 
00017 #include "table/sprites.h"
00018 
00019 #define GENERAL_SPRITE_COLOUR(colour) ((colour) + PALETTE_RECOLOUR_START)
00020 #define COMPANY_SPRITE_COLOUR(owner) (GENERAL_SPRITE_COLOUR(_company_colours[owner]))
00021 
00022 /* The following describes bunch of sprites to be drawn together in a single 3D
00023  * bounding box. Used especially for various multi-sprite buildings (like
00024  * depots or stations): */
00025 
00027 struct DrawTileSeqStruct {
00028   int8 delta_x; 
00029   int8 delta_y;
00030   int8 delta_z; 
00031   byte size_x;
00032   byte size_y;
00033   byte size_z;
00034   PalSpriteID image;
00035 
00037   void MakeTerminator()
00038   {
00039     this->delta_x = (int8)0x80;
00040   }
00041 
00043   bool IsTerminator() const
00044   {
00045     return (byte)this->delta_x == 0x80;
00046   }
00047 
00049   bool IsParentSprite() const
00050   {
00051     return (byte)this->delta_z != 0x80;
00052   }
00053 };
00054 
00055 const DrawTileSeqStruct *CopyDrawTileSeqStruct(const DrawTileSeqStruct *dtss);
00056 
00058 struct DrawTileSprites {
00059   PalSpriteID ground;           
00060   const DrawTileSeqStruct *seq; 
00061 };
00062 
00067 struct DrawBuildingsTileStruct {
00068   PalSpriteID ground;
00069   PalSpriteID building;
00070   byte subtile_x;
00071   byte subtile_y;
00072   byte width;
00073   byte height;
00074   byte dz;
00075   byte draw_proc;  // this allows to specify a special drawing procedure.
00076 };
00077 
00079 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
00080 
00081 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);
00082 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
00083 
00089 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
00090 {
00091   DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
00092 }
00093 
00099 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
00100 {
00101   DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
00102 }
00103 
00107 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
00108 {
00109   DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
00110 }
00111 
00115 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
00116 {
00117   DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
00118 }
00119 
00124 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
00125 {
00126   DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
00127 }
00128 
00133 static inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
00134 {
00135   DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
00136 }
00137 
00149 static inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
00150 {
00151   if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00152     return (pal != 0 ? pal : default_pal);
00153   } else {
00154     return PAL_NONE;
00155   }
00156 }
00157 
00168 static inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
00169 {
00170   if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00171     return (pal != 0 ? pal : default_pal);
00172   } else {
00173     return PAL_NONE;
00174   }
00175 }
00176 
00177 #endif /* SPRITE_H */

Generated on Sun May 8 07:30:19 2011 for OpenTTD by  doxygen 1.6.1