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