* Draws a tile sprite sequence. * @param ti The tile to draw on * @param dts Sprite and subsprites to draw * @param to The transparency bit that toggles drawing of these sprites * @param orig_offset Sprite-Offset for original sprites * @param newgrf_offset Sprite-Offset for NewGRF defined sprites * @param default_palette The default recolour sprite to use (typically company colour) * @param
| 28 | * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned |
| 29 | */ |
| 30 | void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32_t orig_offset, uint32_t newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned) |
| 31 | { |
| 32 | bool parent_sprite_encountered = false; |
| 33 | bool skip_childs = false; |
| 34 | for (const DrawTileSeqStruct &dtss : dts->GetSequence()) { |
| 35 | SpriteID image = dtss.image.sprite; |
| 36 | PaletteID pal = dtss.image.pal; |
| 37 | |
| 38 | if (skip_childs) { |
| 39 | if (!dtss.IsParentSprite()) continue; |
| 40 | skip_childs = false; |
| 41 | } |
| 42 | |
| 43 | /* TTD sprite 0 means no sprite */ |
| 44 | if ((GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) || |
| 45 | (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE))) { |
| 46 | skip_childs = dtss.IsParentSprite(); |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset); |
| 51 | if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset; |
| 52 | |
| 53 | pal = SpriteLayoutPaletteTransform(image, pal, default_palette); |
| 54 | |
| 55 | if (dtss.IsParentSprite()) { |
| 56 | parent_sprite_encountered = true; |
| 57 | AddSortableSpriteToDraw(image, pal, *ti, dtss, !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to) |
| 58 | ); |
| 59 | } else { |
| 60 | int offs_x = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.x) : dtss.origin.x; |
| 61 | int offs_y = child_offset_is_unsigned ? static_cast<uint8_t>(dtss.origin.y) : dtss.origin.y; |
| 62 | bool transparent = !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to); |
| 63 | if (parent_sprite_encountered) { |
| 64 | AddChildSpriteScreen(image, pal, offs_x, offs_y, transparent); |
| 65 | } else { |
| 66 | if (transparent) { |
| 67 | SetBit(image, PALETTE_MODIFIER_TRANSPARENT); |
| 68 | pal = PALETTE_TO_TRANSPARENT; |
| 69 | } |
| 70 | DrawGroundSprite(image, pal, nullptr, offs_x, offs_y); |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Draws a tile sprite sequence in the GUI |
no test coverage detected