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 
00060 struct DrawTileSprites {
00061   PalSpriteID ground;           
00062   const DrawTileSeqStruct *seq; 
00063 };
00064 
00069 struct DrawBuildingsTileStruct {
00070   PalSpriteID ground;
00071   PalSpriteID building;
00072   byte subtile_x;
00073   byte subtile_y;
00074   byte width;
00075   byte height;
00076   byte dz;
00077   byte draw_proc;  // this allows to specify a special drawing procedure.
00078 };
00079 
00081 #define foreach_draw_tile_seq(idx, list) for (idx = list; !idx->IsTerminator(); idx++)
00082 
00083 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);
00084 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned);
00085 
00091 static inline void DrawRailTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
00092 {
00093   DrawCommonTileSeq(ti, dts, to, total_offset, newgrf_offset, default_palette, false);
00094 }
00095 
00101 static inline void DrawRailTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 total_offset, uint32 newgrf_offset, PaletteID default_palette)
00102 {
00103   DrawCommonTileSeqInGUI(x, y, dts, total_offset, newgrf_offset, default_palette, false);
00104 }
00105 
00109 static inline void DrawOrigTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, PaletteID default_palette)
00110 {
00111   DrawCommonTileSeq(ti, dts, to, 0, 0, default_palette, false);
00112 }
00113 
00117 static inline void DrawOrigTileSeqInGUI(int x, int y, const DrawTileSprites *dts, PaletteID default_palette)
00118 {
00119   DrawCommonTileSeqInGUI(x, y, dts, 0, 0, default_palette, false);
00120 }
00121 
00126 static inline void DrawNewGRFTileSeq(const struct TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, uint32 stage, PaletteID default_palette)
00127 {
00128   DrawCommonTileSeq(ti, dts, to, 0, stage, default_palette, true);
00129 }
00130 
00135 static inline void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32 stage, PaletteID default_palette)
00136 {
00137   DrawCommonTileSeqInGUI(x, y, dts, 0, stage, default_palette, true);
00138 }
00139 
00151 static inline PaletteID SpriteLayoutPaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
00152 {
00153   if (HasBit(image, PALETTE_MODIFIER_TRANSPARENT) || HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00154     return (pal != 0 ? pal : default_pal);
00155   } else {
00156     return PAL_NONE;
00157   }
00158 }
00159 
00170 static inline PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
00171 {
00172   if (HasBit(image, PALETTE_MODIFIER_COLOUR)) {
00173     return (pal != 0 ? pal : default_pal);
00174   } else {
00175     return PAL_NONE;
00176   }
00177 }
00178 
00179 #endif /* SPRITE_H */

Generated on Fri Jun 3 05:18:58 2011 for OpenTTD by  doxygen 1.6.1