sprite.cpp

Go to the documentation of this file.
00001 /* $Id: sprite.cpp 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 #include "stdafx.h"
00013 #include "sprite.h"
00014 #include "tile_cmd.h"
00015 #include "viewport_func.h"
00016 #include "landscape.h"
00017 #include "spritecache.h"
00018 
00019 #include "table/sprites.h"
00020 
00031 void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned)
00032 {
00033   const DrawTileSeqStruct *dtss;
00034   foreach_draw_tile_seq(dtss, dts->seq) {
00035     SpriteID image = dtss->image.sprite;
00036 
00037     /* TTD sprite 0 means no sprite */
00038     if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
00039 
00040     /* Stop drawing sprite sequence once we meet a sprite that doesn't have to be opaque */
00041     if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
00042 
00043     image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00044 
00045     SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
00046 
00047     if ((byte)dtss->delta_z != 0x80) {
00048       AddSortableSpriteToDraw(
00049         image, pal,
00050         ti->x + dtss->delta_x, ti->y + dtss->delta_y,
00051         dtss->size_x, dtss->size_y,
00052         dtss->size_z, ti->z + dtss->delta_z,
00053         !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
00054       );
00055     } else {
00056       int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
00057       int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
00058       AddChildSpriteScreen(image, pal, offs_x, offs_y, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to));
00059     }
00060   }
00061 }
00062 
00073 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, SpriteID default_palette, bool child_offset_is_unsigned)
00074 {
00075   const DrawTileSeqStruct *dtss;
00076   Point child_offset = {0, 0};
00077 
00078   foreach_draw_tile_seq(dtss, dts->seq) {
00079     SpriteID image = dtss->image.sprite;
00080 
00081     /* TTD sprite 0 means no sprite */
00082     if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
00083 
00084     image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00085 
00086     SpriteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
00087 
00088     if ((byte)dtss->delta_z != 0x80) {
00089       Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
00090       DrawSprite(image, pal, x + pt.x, y + pt.y);
00091 
00092       const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
00093       child_offset.x = pt.x + spr->x_offs;
00094       child_offset.y = pt.y + spr->y_offs;
00095     } else {
00096       int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
00097       int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
00098       DrawSprite(image, pal, x + child_offset.x + offs_x, y + child_offset.y + offs_y);
00099     }
00100   }
00101 }

Generated on Wed Jan 20 23:38:39 2010 for OpenTTD by  doxygen 1.5.6