1 // ============================================================================
2 // Mirror Magic -- McDuffin's Revenge
3 // ----------------------------------------------------------------------------
4 // (c) 1994-2017 by Artsoft Entertainment
7 // https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
10 // ============================================================================
20 void SetDrawtoField_MM(int mode)
22 int full_xsize = lev_fieldx * TILESIZE_VAR;
23 int full_ysize = lev_fieldy * TILESIZE_VAR;
25 // distance (delta) from screen border (SX/SY) to centered level playfield
26 dSX = (full_xsize < SXSIZE ? (SXSIZE - full_xsize) / 2 : 0);
27 dSY = (full_ysize < SYSIZE ? (SYSIZE - full_ysize) / 2 : 0);
29 // for convenience, absolute screen position to centered level playfield
32 cSX2 = SX + dSX + 2; // including playfield border
33 cSY2 = SY + dSY + 2; // including playfield border
35 if (mode == DRAW_TO_BACKBUFFER)
41 SetTileCursorSXSY(cSX, cSY);
44 void ClearWindow(void)
46 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
48 SetDrawtoField(DRAW_TO_BACKBUFFER);
49 SetDrawtoField_MM(DRAW_TO_BACKBUFFER);
51 redraw_mask |= REDRAW_FIELD;
54 void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame)
59 getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y);
61 BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
62 cFX + x * TILEX, cFY + y * TILEY);
65 void DrawGraphic_MM(int x, int y, int graphic)
68 if (!IN_SCR_FIELD(x,y))
70 Debug("game:mm:DrawGraphic_MM", "x = %d, y = %d, graphic = %d",
72 Debug("game:mm:DrawGraphic_MM", "This should never happen!");
78 int frame = getGraphicAnimationFrameXY(graphic, x, y);
80 DrawGraphicAnimation_MM(x, y, graphic, frame);
85 void DrawGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
90 getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
92 BlitBitmap(bitmap, d, src_x, src_y, TILEX, TILEY, x, y);
95 void DrawGraphicThruMask_MM(int x, int y, int graphic, int frame)
98 if (!IN_SCR_FIELD(x,y))
100 Debug("game:mm:DrawGraphicThruMask_MM", "x = %d,y = %d, graphic = %d",
102 Debug("game:mm:DrawGraphicThruMask_MM", "This should never happen!");
108 DrawGraphicThruMaskExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY,
114 void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
115 int graphic, int frame)
120 if (graphic == IMG_EMPTY)
123 getGraphicSource(graphic, frame, &src_bitmap, &src_x, &src_y);
125 BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
128 void DrawMiniGraphic_MM(int x, int y, int graphic)
130 DrawMiniGraphicExt_MM(drawto, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY,
133 MarkTileDirty(x / 2, y / 2);
137 static void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
139 getSizedGraphicSource(graphic, 0, TILESIZE / 4, bitmap, x, y);
143 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
148 getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y);
150 BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
153 void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
154 int cut_mode, int mask_mode)
156 int width = TILEX, height = TILEY;
158 int src_x, src_y, dest_x, dest_y;
163 DrawGraphic_MM(x, y, graphic);
168 if (dx || dy) // Verschiebung der Grafik?
170 if (x < BX1) // Element kommt von links ins Bild
177 else if (x > BX2) // Element kommt von rechts ins Bild
183 else if (x==BX1 && dx < 0) // Element verläßt links das Bild
189 else if (x==BX2 && dx > 0) // Element verläßt rechts das Bild
191 else if (dx) // allg. Bewegung in x-Richtung
192 MarkTileDirty(x + SIGN(dx), y);
194 if (y < BY1) // Element kommt von oben ins Bild
196 if (cut_mode==CUT_BELOW) // Element oberhalb des Bildes
204 else if (y > BY2) // Element kommt von unten ins Bild
210 else if (y==BY1 && dy < 0) // Element verläßt oben das Bild
216 else if (dy > 0 && cut_mode == CUT_ABOVE)
218 if (y == BY2) // Element unterhalb des Bildes
224 MarkTileDirty(x, y + 1);
225 } // Element verläßt unten das Bild
226 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
230 else if (dy) // allg. Bewegung in y-Richtung
232 MarkTileDirty(x, y + SIGN(dy));
236 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
241 dest_x = cFX + x * TILEX + dx;
242 dest_y = cFY + y * TILEY + dy;
245 if (!IN_SCR_FIELD(x,y))
247 Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
249 Debug("game:mm:DrawGraphicShifted_MM", "This should never happen!");
255 if (mask_mode == USE_MASKING)
256 BlitBitmapMasked(src_bitmap, drawto_field,
257 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
259 BlitBitmap(src_bitmap, drawto_field,
260 src_x, src_y, width, height, dest_x, dest_y);
265 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
266 int cut_mode, int mask_mode)
268 int ux = LEVELX(x), uy = LEVELY(y);
269 int graphic = el2gfx(element);
270 int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8);
271 int phase2 = phase8 / 4;
272 int dir = MovDir[ux][uy];
274 if (element == EL_PACMAN)
276 graphic = (phase2 ? IMG_MM_PACMAN_RIGHT : IMG_MM_PACMAN_EATING_RIGHT);
280 else if (dir == MV_LEFT)
282 else if (dir == MV_DOWN)
287 DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
288 else if (mask_mode == USE_MASKING)
289 DrawGraphicThruMask_MM(x, y, graphic, 0);
291 DrawGraphic_MM(x, y, graphic);
294 void DrawLevelElementExt_MM(int x, int y, int dx, int dy, int element,
295 int cut_mode, int mask_mode)
297 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
298 DrawScreenElementExt_MM(SCREENX(x), SCREENY(y), dx, dy, element,
299 cut_mode, mask_mode);
302 void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
305 DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
308 void DrawScreenElement_MM(int x, int y, int element)
310 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
313 void DrawScreenField_MM(int x, int y)
315 int element = Tile[x][y];
317 if (!IN_LEV_FIELD(x, y))
322 int horiz_move = (MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT);
324 DrawScreenElement_MM(x, y, EL_EMPTY);
327 DrawScreenElementShifted_MM(x, y, MovPos[x][y], 0, element, NO_CUTTING);
329 DrawScreenElementShifted_MM(x, y, 0, MovPos[x][y], element, NO_CUTTING);
331 else if (IS_BLOCKED(x, y))
337 Blocked2Moving(x, y, &oldx, &oldy);
341 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
342 MovDir[oldx][oldy] == MV_RIGHT);
344 DrawScreenElement_MM(x, y, EL_EMPTY);
346 element = Tile[oldx][oldy];
349 DrawScreenElementShifted_MM(sx, sy, MovPos[oldx][oldy], 0, element,
352 DrawScreenElementShifted_MM(sx, sy, 0, MovPos[oldx][oldy], element,
355 else if (IS_DRAWABLE(element))
357 DrawScreenElement_MM(x, y, element);
361 DrawScreenElement_MM(x, y, EL_EMPTY);
365 void DrawLevelField_MM(int x, int y)
367 DrawScreenField_MM(x, y);
370 void DrawMiniElement_MM(int x, int y, int element)
376 DrawMiniGraphic_MM(x, y, IMG_EMPTY);
381 graphic = el2gfx(element);
383 DrawMiniGraphic_MM(x, y, graphic);
386 void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
388 int x = sx + scroll_x, y = sy + scroll_y;
390 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
391 DrawMiniElement_MM(sx, sy, EL_EMPTY);
392 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
393 DrawMiniElement_MM(sx, sy, Tile[x][y]);
396 void DrawField_MM(int x, int y)
398 int element = Tile[x][y];
400 DrawElement_MM(x, y, element);
403 void DrawLevel_MM(void)
409 for (x = 0; x < lev_fieldx; x++)
410 for (y = 0; y < lev_fieldy; y++)
413 redraw_mask |= REDRAW_FIELD;
416 void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
419 int graphic = el2gfx(WALL_BASE(element));
423 getMiniGraphicSource(graphic, &bitmap, &gx, &gy);
425 DrawGraphic_MM(x, y, IMG_EMPTY);
428 if (IS_WALL_WOOD(element) || IS_WALL_AMOEBA(element) ||
429 IS_DF_WALL_WOOD(element))
431 if (IS_WALL_ICE(element) || IS_WALL_AMOEBA(element))
435 for (i = 0; i < 4; i++)
437 int dest_x = cSX + x * TILEX + MINI_TILEX * (i % 2);
438 int dest_y = cSY + y * TILEY + MINI_TILEY * (i / 2);
440 if (!((1 << i) & draw_mask))
443 if (element & (1 << i))
444 BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
447 ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
453 void DrawWalls_MM(int x, int y, int element)
455 DrawWallsExt_MM(x, y, element, HIT_MASK_ALL);
458 void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
464 DrawWalls_MM(x, y, element);
469 for (i = 0; i < 4; i++)
471 if (element & (1 << i))
477 int dst_x = cSX + x * TILEX + (i % 2) * MINI_TILEX;
478 int dst_y = cSY + y * TILEY + (i / 2) * MINI_TILEY;
480 if (bit_mask & (1 << i))
482 graphic = (IS_WALL_AMOEBA(element) ?
483 IMG_MM_AMOEBA_WALL_GROWING :
484 IMG_MM_ICE_WALL_SHRINKING);
489 graphic = (IS_WALL_AMOEBA(element) ?
495 getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
498 BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
506 void DrawElement_MM(int x, int y, int element)
508 if (element == EL_EMPTY)
509 DrawGraphic_MM(x, y, IMG_EMPTY);
510 else if (IS_WALL(element))
511 DrawWalls_MM(x, y, element);
513 else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Tile[x][y]))
515 int wall_element = Tile[x][y] - EL_WALL_CHANGING + Store[x][y];
517 DrawWalls_MM(x, y, wall_element);
520 else if (element == EL_PACMAN)
521 DrawLevelField_MM(x, y);
522 else if (element == EL_FUSE_ON &&
526 DrawGraphic_MM(x, y, IMG_MM_FUSE);
527 else if (element == EL_GRAY_BALL_OPENING)
528 DrawGraphic_MM(x, y, el_act2gfx(EL_BALL_GRAY, MM_ACTION_OPENING));
530 DrawGraphic_MM(x, y, el2gfx(element));
534 static void DrawMicroWalls_MM(int x, int y, int element)
537 int graphic = el2gfx(WALL_BASE(element));
541 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
543 for (i = 0; i < 4; i++)
545 int xpos = MICROLEV_XPOS + x * MICRO_TILEX + MICRO_WALLX * (i % 2);
546 int ypos = MICROLEV_YPOS + y * MICRO_TILEY + MICRO_WALLY * (i / 2);
548 if (element & (1 << i))
549 BlitBitmap(bitmap, drawto, gx, gy, MICRO_WALLX, MICRO_WALLY, xpos, ypos);
551 ClearRectangle(drawto, xpos, ypos, MICRO_WALLX, MICRO_WALLY);
555 static void DrawMicroElement_MM(int x, int y, int element)
558 int graphic = el2gfx(element);
561 if (element == EL_EMPTY)
564 if (IS_WALL(element))
566 DrawMicroWalls_MM(x, y, element);
571 getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
573 BlitBitmap(bitmap, drawto, gx, gy, MICRO_TILEX, MICRO_TILEY,
574 MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
577 static void DrawMicroLevelExt_MM(int xpos, int ypos)
581 ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
583 for (x = 0; x < STD_LEV_FIELDX; x++)
584 for (y = 0; y < STD_LEV_FIELDY; y++)
585 DrawMicroElement_MM(x, y, Ur[x][y]);
587 redraw_mask |= REDRAW_FIELD;
592 // ----------------------------------------------------------------------------
594 // ----------------------------------------------------------------------------
596 #define XSN_RND(x) ((x) != 0 ? rand() % (x) : 0)
597 #define XSN_ALPHA_VALUE(x) (SDL_ALPHA_OPAQUE * (x) / 100)
599 #define XSN_MAX_ITEMS 100
600 #define XSN_MAX_HEIGHT 40
602 #define XSN_MAX_DY 10
603 #define XSN_CHECK_DELAY 3
604 #define XSN_START_DELAY 60
605 #define XSN_UPDATE_DELAY 50
606 #define XSN_GROWTH_DELAY 3
607 #define XSN_GROWTH_RATE 3
608 #define XSN_CHANGE_DELAY 30
609 #define XSN_CHANGE_FACTOR 3
610 #define XSN_ALPHA_DEFAULT XSN_ALPHA_VALUE(95)
611 #define XSN_ALPHA_VISIBLE XSN_ALPHA_VALUE(50)
612 #define XSN_DEBUG_STEPS 5
614 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
615 static byte xsn_bits_1[] = { 0x22, 0x6b, 0x14, 0x2a, 0x14, 0x6b, 0x22 };
616 static byte xsn_bits_2[] = { 0x14, 0x08, 0x49, 0x36, 0x49, 0x08, 0x14 };
618 char debug_xsn_mode[] = { 76,101,116,32,105,116,32,115,110,111,119,33,0 };
620 void setHideSetupEntry(void *);
621 void removeHideSetupEntry(void *);
631 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
632 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
633 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
634 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
635 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
636 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
637 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
639 static int num_xsn_data = ARRAY_SIZE(xsn_data);
668 struct XsnItem items[XSN_MAX_ITEMS];
675 static struct Xsn xsn = { 0 };
677 static int xsn_percent(void)
680 int xsn_m1 = xsn_m0 + 10;
681 int xsn_m2 = xsn_m1 + 10;
682 int xsn_m3 = xsn_m2 + 10;
683 time_t xsn_e0 = time(NULL);
684 struct tm *xsn_t0 = localtime(&xsn_e0);
685 struct tm xsn_t1 = { 0,0,0, xsn_m2*3, xsn_m3/3, xsn_t0->tm_year, 0,0,-1 };
686 time_t xsn_e1 = mktime(&xsn_t1);
687 int xsn_c0 = (25 * xsn_m3) << xsn_m1;
688 int xsn_c1 = (xsn_t1.tm_wday - xsn_m1) * !!xsn_t1.tm_wday;
690 for (xsn_m0 = 5; xsn_m0 > 0; xsn_m0--)
692 int xsn_c2 = (xsn_m0 > 4 ? 0 : xsn_c1) - xsn_m1 * xsn_m0;
693 int xsn_off = (xsn_m0 > 4 ? xsn_c0 : 0);
694 time_t xsn_e3 = xsn_e1 - xsn_c2 * xsn_c0;
696 if (xsn_e0 > xsn_e3 - xsn_off &&
697 xsn_e0 < xsn_e3 + xsn_off + xsn_c0)
698 return xsn_m0 * (xsn_m3 - xsn_m1);
704 static void xsn_init_item(int nr)
706 struct XsnItem *item = &xsn.items[nr];
708 item->type = XSN_RND(num_xsn_data);
710 if (xsn.change_type != 0)
712 int new_x = XSN_RND(xsn.area_xsize / 3);
714 item->x = (xsn.change_dir == 1 ? new_x : xsn.area_xsize - new_x);
715 item->y = XSN_RND(xsn.area_ysize);
719 item->x = XSN_RND(xsn.area_xsize - xsn_data[item->type].size);
720 item->y = XSN_RND(xsn.area_ysize / 10);
723 item->dy = XSN_RND(xsn.max_dy + 1) + 1;
724 item->dx = XSN_RND(item->dy / 4 + 1) * (XSN_RND(1000) > 500 ? -1 : 1);
729 static void xsn_update_item(int nr)
731 struct XsnItem *item = &xsn.items[nr];
736 if (xsn.change_type != 0)
738 int dx_new = ABS(item->dx) +
739 (xsn.change_type == 1 ?
740 XSN_RND(XSN_CHANGE_FACTOR + 1) - XSN_CHANGE_FACTOR / 2 :
743 item->dx = MIN(MAX(-50, dx_new * xsn.change_dir), 50);
746 int new_x = item->x + item->dx;
747 int new_y = item->y + item->dy;
749 item->active = (new_y < xsn.area_ysize);
751 if (xsn.change_type != 0)
752 item->active = (item->active && new_x > 0 && new_x < xsn.area_xsize);
754 int item_size = xsn_data[item->type].size;
755 int half_item_size = item_size / 2;
756 int mid_x = new_x + half_item_size;
757 int mid_y = new_y + half_item_size;
758 int upper_border = xsn.area_ysize - xsn.max_height;
761 new_y >= upper_border &&
763 new_x <= xsn.area_xsize - item_size &&
764 mid_y >= xsn.height[mid_x] &&
765 mid_y < xsn.area_ysize)
767 Bitmap *item_bitmap = xsn_data[item->type].bitmap;
768 SDL_Surface *surface = xsn.bitmap->surface;
769 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
770 int item_alpha = XSN_ALPHA_VALUE(81 + XSN_RND(20));
774 xsn.bitmap->surface = surface_masked;
776 SDLSetAlpha(item_bitmap->surface_masked, TRUE, item_alpha);
778 // blit to masked surface instead of opaque surface
779 BlitBitmapMasked(item_bitmap, xsn.bitmap, 0, 0, item_size, item_size,
780 new_x, new_y - upper_border);
782 SDLSetAlpha(item_bitmap->surface_masked, TRUE, XSN_ALPHA_DEFAULT);
784 for (i = -half_item_size; i <= half_item_size; i++)
786 int xpos = mid_x + i;
788 if (xpos >= 0 && xpos < xsn.area_xsize)
789 xsn.height[xpos] = MIN(new_y + ABS(i), xsn.height[xpos]);
792 if (xsn.height[mid_x] <= upper_border + shrink)
794 int xpos1 = MAX(0, new_x - half_item_size);
795 int xpos2 = MIN(new_x + 3 * half_item_size, xsn.area_xsize);
796 int xsize = xpos2 - xpos1;
797 int ysize1 = XSN_RND(xsn.max_height - shrink);
798 int ysize2 = xsn.max_height - ysize1;
800 SDLSetAlpha(surface_masked, FALSE, 0);
802 FillRectangle(xsn.bitmap, xpos1, xsn.max_height, xsize, xsn.max_height,
804 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, 0, xsize, ysize1,
805 xpos1, xsn.max_height + shrink);
806 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, ysize1, xsize, ysize2,
807 xpos1, xsn.max_height + ysize1);
808 FillRectangle(xsn.bitmap, xpos1, 0, xsize, xsn.max_height,
810 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
811 xsize, xsn.max_height, xpos1, 0);
813 SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
815 for (i = xpos1; i < xpos2; i++)
816 xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
819 SDLFreeBitmapTextures(xsn.bitmap);
820 SDLCreateBitmapTextures(xsn.bitmap);
822 xsn.bitmap->surface = surface;
827 item->dx += XSN_RND(XSN_CHANGE_FACTOR) * (XSN_RND(1000) > 500 ? -1 : 1);
829 if (xsn.change_type == 0)
830 item->dx = MIN(MAX(-xsn.max_dx, item->dx), xsn.max_dx);
836 static void xsn_update_change(void)
838 if (XSN_RND(100) > 65)
840 xsn.change_dir = (XSN_RND(10) > 4 ? 1 : -1);
841 xsn.change_delay = XSN_RND(5) + 1;
844 else if (xsn.change_type == 2)
846 xsn.change_delay = XSN_RND(3) + 1;
851 xsn.change_delay = XSN_CHANGE_DELAY;
856 static void DrawTileCursor_Xsn(int draw_target)
858 static boolean initialized = FALSE;
859 static boolean started = FALSE;
860 static boolean active = FALSE;
861 static boolean debug = FALSE;
862 static DelayCounter check_delay = { XSN_CHECK_DELAY * 1000 };
863 static DelayCounter start_delay = { 0 };
864 static DelayCounter growth_delay = { 0 };
865 static DelayCounter update_delay = { 0 };
866 static DelayCounter change_delay = { 0 };
867 static int percent = 0;
868 static int debug_value = 0;
869 boolean reinitialize = FALSE;
870 boolean active_last = active;
873 if (draw_target != DRAW_TO_SCREEN)
876 if (DelayReached(&check_delay))
878 percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
881 setup.debug.xsn_percent = percent;
883 if (setup.debug.xsn_mode != AUTO)
884 percent = setup.debug.xsn_percent;
886 setup.debug.xsn_percent = percent;
888 active = (percent > 0);
890 if ((active && !active_last) || setup.debug.xsn_mode != AUTO)
891 removeHideSetupEntry(&setup.debug.xsn_mode);
892 else if (!active && active_last)
893 setHideSetupEntry(&setup.debug.xsn_mode);
895 if (setup.debug.xsn_mode == FALSE)
898 else if (tile_cursor.xsn_debug)
900 debug_value = (active ? 0 : MIN(debug_value + 1, XSN_DEBUG_STEPS));
904 ResetDelayCounter(&check_delay);
906 setup.debug.xsn_mode = (debug_value > 0);
907 tile_cursor.xsn_debug = FALSE;
915 xsn.area_xsize = gfx.win_xsize;
916 xsn.area_ysize = gfx.win_ysize;
918 for (i = 0; i < num_xsn_data; i++)
920 int size = xsn_data[i].size;
921 byte *bits = xsn_data[i].bits;
922 Bitmap *bitmap = CreateBitmap(size, size, DEFAULT_DEPTH);
924 FillRectangle(bitmap, 0, 0, size, size, BLACK_PIXEL);
926 for (y = 0; y < size; y++)
927 for (x = 0; x < size; x++)
928 if ((bits[y] >> x) & 0x01)
929 SDLPutPixel(bitmap, x, y, WHITE_PIXEL);
931 SDL_Surface *surface = bitmap->surface;
933 if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
934 Fail("SDLGetNativeSurface() failed");
936 SDL_Surface *surface_masked = bitmap->surface_masked;
938 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
939 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
941 SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
942 SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
944 xsn_data[i].bitmap = bitmap;
947 srand((unsigned int)time(NULL));
954 start_delay.value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
955 (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
958 ResetDelayCounter(&start_delay);
966 xsn.max_items = percent * XSN_MAX_ITEMS / 100;
967 xsn.max_height = percent * XSN_MAX_HEIGHT / 100;
969 xsn.max_dx = XSN_MAX_DX;
970 xsn.max_dy = XSN_MAX_DY;
972 xsn.change_delay = XSN_CHANGE_DELAY;
976 xsn.alpha = XSN_ALPHA_DEFAULT;
978 for (i = 0; i < xsn.max_items; i++)
982 if (xsn.area_xsize != gfx.win_xsize ||
983 xsn.area_ysize != gfx.win_ysize ||
986 xsn.area_xsize = gfx.win_xsize;
987 xsn.area_ysize = gfx.win_ysize;
989 if (xsn.bitmap != NULL)
990 FreeBitmap(xsn.bitmap);
992 xsn.bitmap = CreateBitmap(xsn.area_xsize, xsn.max_height * 2,
995 FillRectangle(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
998 SDL_Surface *surface = xsn.bitmap->surface;
1000 if ((xsn.bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
1001 Fail("SDLGetNativeSurface() failed");
1003 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
1005 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
1006 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
1008 SDLSetAlpha(surface, TRUE, xsn.alpha);
1009 SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
1011 SDLCreateBitmapTextures(xsn.bitmap);
1013 for (i = 0; i < num_xsn_data; i++)
1015 SDLFreeBitmapTextures(xsn_data[i].bitmap);
1016 SDLCreateBitmapTextures(xsn_data[i].bitmap);
1019 if (xsn.height != NULL)
1020 checked_free(xsn.height);
1022 xsn.height = checked_calloc(xsn.area_xsize * sizeof(int));
1024 for (i = 0; i < xsn.area_xsize; i++)
1025 xsn.height[i] = xsn.area_ysize - 1;
1030 if (!DelayReached(&start_delay))
1033 update_delay.value = XSN_UPDATE_DELAY;
1034 growth_delay.value = XSN_GROWTH_DELAY * 1000;
1035 change_delay.value = XSN_CHANGE_DELAY * 1000;
1037 ResetDelayCounter(&growth_delay);
1038 ResetDelayCounter(&update_delay);
1039 ResetDelayCounter(&change_delay);
1044 if (xsn.num_items < xsn.max_items)
1046 if (DelayReached(&growth_delay))
1048 xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
1049 xsn.num_items = MIN(xsn.num_items, xsn.max_items);
1053 if (DelayReached(&update_delay))
1055 for (i = 0; i < xsn.num_items; i++)
1059 if (DelayReached(&change_delay))
1061 xsn_update_change();
1063 change_delay.value = xsn.change_delay * 1000;
1066 int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
1067 (xsn.alpha > XSN_ALPHA_VISIBLE ? -1 : 0) :
1068 (xsn.alpha < XSN_ALPHA_DEFAULT ? +1 : 0));
1070 if (xsn_alpha_dx != 0)
1072 xsn.alpha += xsn_alpha_dx;
1074 SDLSetAlpha(xsn.bitmap->surface_masked, TRUE, xsn.alpha);
1076 SDLFreeBitmapTextures(xsn.bitmap);
1077 SDLCreateBitmapTextures(xsn.bitmap);
1080 BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1081 0, xsn.area_ysize - xsn.max_height);
1083 for (i = 0; i < xsn.num_items; i++)
1085 int dst_x = xsn.items[i].x;
1086 int dst_y = xsn.items[i].y;
1087 int type = xsn.items[i].type;
1088 int size = xsn_data[type].size;
1089 Bitmap *bitmap = xsn_data[type].bitmap;
1091 BlitToScreenMasked(bitmap, 0, 0, size, size, dst_x, dst_y);
1095 void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
1097 if (program.headless)
1100 Bitmap *fade_bitmap;
1104 int graphic = IMG_GLOBAL_TILE_CURSOR;
1106 int tilesize = TILESIZE_VAR;
1107 int width = tilesize;
1108 int height = tilesize;
1110 DrawTileCursor_Xsn(draw_target);
1112 if (!tile_cursor.enabled ||
1113 !tile_cursor.active ||
1114 !tile_cursor_active)
1117 if (tile_cursor.moving)
1119 int step = TILESIZE_VAR / 4;
1120 int dx = tile_cursor.target_x - tile_cursor.x;
1121 int dy = tile_cursor.target_y - tile_cursor.y;
1124 tile_cursor.x = tile_cursor.target_x;
1126 tile_cursor.x += SIGN(dx) * step;
1129 tile_cursor.y = tile_cursor.target_y;
1131 tile_cursor.y += SIGN(dy) * step;
1133 if (tile_cursor.x == tile_cursor.target_x &&
1134 tile_cursor.y == tile_cursor.target_y)
1135 tile_cursor.moving = FALSE;
1138 dst_x = tile_cursor.x;
1139 dst_y = tile_cursor.y;
1141 frame = getGraphicAnimationFrame(graphic, -1);
1143 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1146 (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
1147 draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
1149 if (draw_target == DRAW_TO_SCREEN)
1150 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
1152 BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
1157 static int REQ_in_range(int x, int y)
1159 if (y > DY + 249 && y < DY + 278)
1161 if (x > DX + 1 && x < DX + 48)
1163 else if (x > DX + 51 && x < DX + 98)
1171 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
1173 return GetPixel(bitmap, x, y);
1176 void SetRGB(unsigned int pixel,
1177 unsigned short red, unsigned short green, unsigned short blue)
1181 int get_base_element(int element)
1183 if (IS_MIRROR(element))
1184 return EL_MIRROR_START;
1185 else if (IS_MIRROR_FIXED(element))
1186 return EL_MIRROR_FIXED_START;
1187 else if (IS_POLAR(element))
1188 return EL_POLAR_START;
1189 else if (IS_POLAR_CROSS(element))
1190 return EL_POLAR_CROSS_START;
1191 else if (IS_BEAMER(element))
1192 return EL_BEAMER_RED_START + BEAMER_NR(element) * 16;
1193 else if (IS_FIBRE_OPTIC(element))
1194 return EL_FIBRE_OPTIC_START + FIBRE_OPTIC_NR(element) * 2;
1195 else if (IS_MCDUFFIN(element))
1196 return EL_MCDUFFIN_START;
1197 else if (IS_LASER(element))
1198 return EL_LASER_START;
1199 else if (IS_RECEIVER(element))
1200 return EL_RECEIVER_START;
1201 else if (IS_DF_MIRROR(element))
1202 return EL_DF_MIRROR_START;
1203 else if (IS_DF_MIRROR_AUTO(element))
1204 return EL_DF_MIRROR_AUTO_START;
1205 else if (IS_PACMAN(element))
1206 return EL_PACMAN_START;
1207 else if (IS_GRID_STEEL(element))
1208 return EL_GRID_STEEL_START;
1209 else if (IS_GRID_WOOD(element))
1210 return EL_GRID_WOOD_START;
1211 else if (IS_GRID_STEEL_FIXED(element))
1212 return EL_GRID_STEEL_FIXED_START;
1213 else if (IS_GRID_WOOD_FIXED(element))
1214 return EL_GRID_WOOD_FIXED_START;
1215 else if (IS_GRID_STEEL_AUTO(element))
1216 return EL_GRID_STEEL_AUTO_START;
1217 else if (IS_GRID_WOOD_AUTO(element))
1218 return EL_GRID_WOOD_AUTO_START;
1219 else if (IS_WALL_STEEL(element))
1220 return EL_WALL_STEEL_START;
1221 else if (IS_WALL_WOOD(element))
1222 return EL_WALL_WOOD_START;
1223 else if (IS_WALL_ICE(element))
1224 return EL_WALL_ICE_START;
1225 else if (IS_WALL_AMOEBA(element))
1226 return EL_WALL_AMOEBA_START;
1227 else if (IS_DF_WALL_STEEL(element))
1228 return EL_DF_WALL_STEEL_START;
1229 else if (IS_DF_WALL_WOOD(element))
1230 return EL_DF_WALL_WOOD_START;
1231 else if (IS_CHAR(element))
1232 return EL_CHAR_START;
1237 int get_element_phase(int element)
1239 return element - get_base_element(element);
1242 int get_num_elements(int element)
1244 if (IS_MIRROR(element) ||
1245 IS_POLAR(element) ||
1246 IS_BEAMER(element) ||
1247 IS_DF_MIRROR(element) ||
1248 IS_DF_MIRROR_AUTO(element))
1250 else if (IS_GRID_STEEL_FIXED(element) ||
1251 IS_GRID_WOOD_FIXED(element) ||
1252 IS_GRID_STEEL_AUTO(element) ||
1253 IS_GRID_WOOD_AUTO(element))
1255 else if (IS_MIRROR_FIXED(element) ||
1256 IS_POLAR_CROSS(element) ||
1257 IS_MCDUFFIN(element) ||
1258 IS_LASER(element) ||
1259 IS_RECEIVER(element) ||
1260 IS_PACMAN(element) ||
1261 IS_GRID_STEEL(element) ||
1262 IS_GRID_WOOD(element))
1268 int get_rotated_element(int element, int step)
1270 int base_element = get_base_element(element);
1271 int num_elements = get_num_elements(element);
1272 int element_phase = element - base_element;
1274 return base_element + (element_phase + step + num_elements) % num_elements;
1277 static int map_element(int element)
1281 case EL_WALL_STEEL: return EL_STEEL_WALL;
1282 case EL_WALL_WOOD: return EL_WOODEN_WALL;
1283 case EL_WALL_ICE: return EL_ICE_WALL;
1284 case EL_WALL_AMOEBA: return EL_AMOEBA_WALL;
1285 case EL_DF_WALL_STEEL: return EL_DF_STEEL_WALL;
1286 case EL_DF_WALL_WOOD: return EL_DF_WOODEN_WALL;
1288 default: return element;
1292 int el2gfx(int element)
1294 return el2img_mm(map_element(element));
1297 int el_act2gfx(int element, int action)
1299 return el_act2img_mm(map_element(element), action);
1302 void RedrawPlayfield_MM(void)
1308 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
1310 BlitBitmap(drawto_field, target_bitmap,
1311 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);