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 #include "core/alloc_func.hpp"
00018 #include "core/mem_func.hpp"
00019
00020
00031 void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
00032 {
00033 bool parent_sprite_encountered = false;
00034 const DrawTileSeqStruct *dtss;
00035 bool skip_childs = false;
00036 foreach_draw_tile_seq(dtss, dts->seq) {
00037 SpriteID image = dtss->image.sprite;
00038 PaletteID pal = dtss->image.pal;
00039
00040 if (skip_childs) {
00041 if (!dtss->IsParentSprite()) continue;
00042 skip_childs = false;
00043 }
00044
00045
00046 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
00047 skip_childs = dtss->IsParentSprite();
00048 continue;
00049 }
00050
00051
00052 if (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE)) return;
00053
00054 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00055 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
00056
00057 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
00058
00059 if (dtss->IsParentSprite()) {
00060 parent_sprite_encountered = true;
00061 AddSortableSpriteToDraw(
00062 image, pal,
00063 ti->x + dtss->delta_x, ti->y + dtss->delta_y,
00064 dtss->size_x, dtss->size_y,
00065 dtss->size_z, ti->z + dtss->delta_z,
00066 !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
00067 );
00068 } else {
00069 int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
00070 int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
00071 bool transparent = !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to);
00072 if (parent_sprite_encountered) {
00073 AddChildSpriteScreen(image, pal, offs_x, offs_y, transparent);
00074 } else {
00075 if (transparent) {
00076 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
00077 pal = PALETTE_TO_TRANSPARENT;
00078 }
00079 DrawGroundSprite(image, pal, NULL, offs_x, offs_y);
00080 }
00081 }
00082 }
00083 }
00084
00095 void DrawCommonTileSeqInGUI(int x, int y, const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
00096 {
00097 const DrawTileSeqStruct *dtss;
00098 Point child_offset = {0, 0};
00099
00100 bool skip_childs = false;
00101 foreach_draw_tile_seq(dtss, dts->seq) {
00102 SpriteID image = dtss->image.sprite;
00103 PaletteID pal = dtss->image.pal;
00104
00105 if (skip_childs) {
00106 if (!dtss->IsParentSprite()) continue;
00107 skip_childs = false;
00108 }
00109
00110
00111 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
00112 skip_childs = dtss->IsParentSprite();
00113 continue;
00114 }
00115
00116 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
00117 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
00118
00119 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
00120
00121 if (dtss->IsParentSprite()) {
00122 Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
00123 DrawSprite(image, pal, x + pt.x, y + pt.y);
00124
00125 const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
00126 child_offset.x = pt.x + spr->x_offs;
00127 child_offset.y = pt.y + spr->y_offs;
00128 } else {
00129 int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
00130 int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
00131 DrawSprite(image, pal, x + child_offset.x + offs_x, y + child_offset.y + offs_y);
00132 }
00133 }
00134 }