00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "sprite.h"
00014 #include "viewport_func.h"
00015 #include "landscape.h"
00016 #include "spritecache.h"
00017
00018
00029 void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
00030 {
00031 bool parent_sprite_encountered = false;
00032 const DrawTileSeqStruct *dtss;
00033 foreach_draw_tile_seq(dtss, dts->seq) {
00034 SpriteID image = dtss->image.sprite;
00035
00036
00037 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
00038
00039
00040 if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
00041
00042 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00043
00044 PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
00045
00046 if ((byte)dtss->delta_z != 0x80) {
00047 parent_sprite_encountered = true;
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 bool transparent = !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to);
00059 if (parent_sprite_encountered) {
00060 AddChildSpriteScreen(image, pal, offs_x, offs_y, transparent);
00061 } else {
00062 if (transparent) {
00063 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
00064 pal = PALETTE_TO_TRANSPARENT;
00065 }
00066 DrawGroundSprite(image, pal, NULL, offs_x, offs_y);
00067 }
00068 }
00069 }
00070 }
00071
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 {
00084 const DrawTileSeqStruct *dtss;
00085 Point child_offset = {0, 0};
00086
00087 foreach_draw_tile_seq(dtss, dts->seq) {
00088 SpriteID image = dtss->image.sprite;
00089
00090
00091 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) continue;
00092
00093 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00094
00095 PaletteID pal = SpriteLayoutPaletteTransform(image, dtss->image.pal, default_palette);
00096
00097 if ((byte)dtss->delta_z != 0x80) {
00098 Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
00099 DrawSprite(image, pal, x + pt.x, y + pt.y);
00100
00101 const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
00102 child_offset.x = pt.x + spr->x_offs;
00103 child_offset.y = pt.y + spr->y_offs;
00104 } else {
00105 int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
00106 int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
00107 DrawSprite(image, pal, x + child_offset.x + offs_x, y + child_offset.y + offs_y);
00108 }
00109 }
00110 }