Translations update
[openttd/fttd.git] / src / sprite.cpp
blob7b318e8c5fd22a846d76ff4e0bb2a36260ed2c25
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file sprite.cpp Handling of sprites */
12 #include "stdafx.h"
13 #include "sprite.h"
14 #include "viewport_func.h"
15 #include "landscape.h"
16 #include "spritecache.h"
17 #include "zoom_func.h"
20 /**
21 * Draws a tile sprite sequence.
22 * @param ti The tile to draw on
23 * @param dts Sprite and subsprites to draw
24 * @param to The transparency bit that toggles drawing of these sprites
25 * @param orig_offset Sprite-Offset for original sprites
26 * @param newgrf_offset Sprite-Offset for NewGRF defined sprites
27 * @param default_palette The default recolour sprite to use (typically company colour)
28 * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
30 void DrawCommonTileSeq(const TileInfo *ti, const DrawTileSprites *dts, TransparencyOption to, int32 orig_offset, uint32 newgrf_offset, PaletteID default_palette, bool child_offset_is_unsigned)
32 bool parent_sprite_encountered = false;
33 const DrawTileSeqStruct *dtss;
34 bool skip_childs = false;
35 foreach_draw_tile_seq(dtss, dts->seq) {
36 SpriteID image = dtss->image.sprite;
37 PaletteID pal = dtss->image.pal;
39 if (skip_childs) {
40 if (!dtss->IsParentSprite()) continue;
41 skip_childs = false;
44 /* TTD sprite 0 means no sprite */
45 if ((GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) ||
46 (IsInvisibilitySet(to) && !HasBit(image, SPRITE_MODIFIER_OPAQUE))) {
47 skip_childs = dtss->IsParentSprite();
48 continue;
51 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
52 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
54 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
56 if (dtss->IsParentSprite()) {
57 parent_sprite_encountered = true;
58 AddSortableSpriteToDraw (ti->vd,
59 image, pal,
60 ti->x + dtss->delta_x, ti->y + dtss->delta_y,
61 dtss->size_x, dtss->size_y,
62 dtss->size_z, ti->z + dtss->delta_z,
63 !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to)
65 } else {
66 int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
67 int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
68 bool transparent = !HasBit(image, SPRITE_MODIFIER_OPAQUE) && IsTransparencySet(to);
69 if (parent_sprite_encountered) {
70 AddChildSpriteScreen (ti->vd, image, pal, offs_x, offs_y, transparent);
71 } else {
72 if (transparent) {
73 SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
74 pal = PALETTE_TO_TRANSPARENT;
76 DrawGroundSprite (ti, image, pal, NULL, offs_x, offs_y);
82 /**
83 * Draws a tile sprite sequence in the GUI
84 * @param dpi Area to draw on.
85 * @param x X position to draw to
86 * @param y Y position to draw to
87 * @param dts Sprite and subsprites to draw
88 * @param orig_offset Sprite-Offset for original sprites
89 * @param newgrf_offset Sprite-Offset for NewGRF defined sprites
90 * @param default_palette The default recolour sprite to use (typically company colour)
91 * @param child_offset_is_unsigned Whether child sprite offsets are interpreted signed or unsigned
93 void DrawCommonTileSeqInGUI (BlitArea *dpi, int x, int y,
94 const DrawTileSprites *dts, int32 orig_offset, uint32 newgrf_offset,
95 PaletteID default_palette, bool child_offset_is_unsigned)
97 const DrawTileSeqStruct *dtss;
98 Point child_offset = {0, 0};
100 bool skip_childs = false;
101 foreach_draw_tile_seq(dtss, dts->seq) {
102 SpriteID image = dtss->image.sprite;
103 PaletteID pal = dtss->image.pal;
105 if (skip_childs) {
106 if (!dtss->IsParentSprite()) continue;
107 skip_childs = false;
110 /* TTD sprite 0 means no sprite */
111 if (GB(image, 0, SPRITE_WIDTH) == 0 && !HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) {
112 skip_childs = dtss->IsParentSprite();
113 continue;
116 image += (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE) ? newgrf_offset : orig_offset);
117 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += newgrf_offset;
119 pal = SpriteLayoutPaletteTransform(image, pal, default_palette);
121 if (dtss->IsParentSprite()) {
122 Point pt = RemapCoords(dtss->delta_x, dtss->delta_y, dtss->delta_z);
123 DrawSprite (dpi, image, pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y));
125 const Sprite *spr = GetSprite(image & SPRITE_MASK, ST_NORMAL);
126 child_offset.x = UnScaleGUI(pt.x + spr->x_offs);
127 child_offset.y = UnScaleGUI(pt.y + spr->y_offs);
128 } else {
129 int offs_x = child_offset_is_unsigned ? (uint8)dtss->delta_x : dtss->delta_x;
130 int offs_y = child_offset_is_unsigned ? (uint8)dtss->delta_y : dtss->delta_y;
131 DrawSprite (dpi, image, pal, x + child_offset.x + ScaleGUITrad(offs_x), y + child_offset.y + ScaleGUITrad(offs_y));