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);
136 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
141 getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y);
143 BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
146 void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
147 int cut_mode, int mask_mode)
149 int width = TILEX, height = TILEY;
151 int src_x, src_y, dest_x, dest_y;
156 DrawGraphic_MM(x, y, graphic);
161 if (dx || dy) // Verschiebung der Grafik?
163 if (x < BX1) // Element kommt von links ins Bild
170 else if (x > BX2) // Element kommt von rechts ins Bild
176 else if (x==BX1 && dx < 0) // Element verläßt links das Bild
182 else if (x==BX2 && dx > 0) // Element verläßt rechts das Bild
184 else if (dx) // allg. Bewegung in x-Richtung
185 MarkTileDirty(x + SIGN(dx), y);
187 if (y < BY1) // Element kommt von oben ins Bild
189 if (cut_mode==CUT_BELOW) // Element oberhalb des Bildes
197 else if (y > BY2) // Element kommt von unten ins Bild
203 else if (y==BY1 && dy < 0) // Element verläßt oben das Bild
209 else if (dy > 0 && cut_mode == CUT_ABOVE)
211 if (y == BY2) // Element unterhalb des Bildes
217 MarkTileDirty(x, y + 1);
218 } // Element verläßt unten das Bild
219 else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
223 else if (dy) // allg. Bewegung in y-Richtung
225 MarkTileDirty(x, y + SIGN(dy));
229 getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
234 dest_x = cFX + x * TILEX + dx;
235 dest_y = cFY + y * TILEY + dy;
238 if (!IN_SCR_FIELD(x,y))
240 Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
242 Debug("game:mm:DrawGraphicShifted_MM", "This should never happen!");
248 if (mask_mode == USE_MASKING)
249 BlitBitmapMasked(src_bitmap, drawto_field,
250 src_x, src_y, TILEX, TILEY, dest_x, dest_y);
252 BlitBitmap(src_bitmap, drawto_field,
253 src_x, src_y, width, height, dest_x, dest_y);
258 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
259 int cut_mode, int mask_mode)
261 int ux = LEVELX(x), uy = LEVELY(y);
262 int graphic = el2gfx(element);
263 int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8);
264 int phase2 = phase8 / 4;
265 int dir = MovDir[ux][uy];
267 if (element == EL_PACMAN)
269 graphic = (phase2 ? IMG_MM_PACMAN_RIGHT : IMG_MM_PACMAN_EATING_RIGHT);
273 else if (dir == MV_LEFT)
275 else if (dir == MV_DOWN)
280 DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
281 else if (mask_mode == USE_MASKING)
282 DrawGraphicThruMask_MM(x, y, graphic, 0);
284 DrawGraphic_MM(x, y, graphic);
287 void DrawLevelElementExt_MM(int x, int y, int dx, int dy, int element,
288 int cut_mode, int mask_mode)
290 if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
291 DrawScreenElementExt_MM(SCREENX(x), SCREENY(y), dx, dy, element,
292 cut_mode, mask_mode);
295 void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
298 DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
301 void DrawScreenElement_MM(int x, int y, int element)
303 DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
306 void DrawScreenField_MM(int x, int y)
308 int element = Tile[x][y];
310 if (!IN_LEV_FIELD(x, y))
315 int horiz_move = (MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT);
317 DrawScreenElement_MM(x, y, EL_EMPTY);
320 DrawScreenElementShifted_MM(x, y, MovPos[x][y], 0, element, NO_CUTTING);
322 DrawScreenElementShifted_MM(x, y, 0, MovPos[x][y], element, NO_CUTTING);
324 else if (IS_BLOCKED(x, y))
330 Blocked2Moving(x, y, &oldx, &oldy);
334 horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
335 MovDir[oldx][oldy] == MV_RIGHT);
337 DrawScreenElement_MM(x, y, EL_EMPTY);
339 element = Tile[oldx][oldy];
342 DrawScreenElementShifted_MM(sx, sy, MovPos[oldx][oldy], 0, element,
345 DrawScreenElementShifted_MM(sx, sy, 0, MovPos[oldx][oldy], element,
348 else if (IS_DRAWABLE(element))
350 DrawScreenElement_MM(x, y, element);
354 DrawScreenElement_MM(x, y, EL_EMPTY);
358 void DrawLevelField_MM(int x, int y)
360 DrawScreenField_MM(x, y);
363 void DrawMiniElement_MM(int x, int y, int element)
369 DrawMiniGraphic_MM(x, y, IMG_EMPTY);
374 graphic = el2gfx(element);
376 DrawMiniGraphic_MM(x, y, graphic);
379 void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
381 int x = sx + scroll_x, y = sy + scroll_y;
383 if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
384 DrawMiniElement_MM(sx, sy, EL_EMPTY);
385 else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
386 DrawMiniElement_MM(sx, sy, Tile[x][y]);
389 void DrawField_MM(int x, int y)
391 int element = Tile[x][y];
393 DrawElement_MM(x, y, element);
396 void DrawLevel_MM(void)
402 for (x = 0; x < lev_fieldx; x++)
403 for (y = 0; y < lev_fieldy; y++)
406 redraw_mask |= REDRAW_FIELD;
409 void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
412 int graphic = el2gfx(WALL_BASE(element));
416 getMiniGraphicSource(graphic, &bitmap, &gx, &gy);
418 DrawGraphic_MM(x, y, IMG_EMPTY);
421 if (IS_WALL_WOOD(element) || IS_WALL_AMOEBA(element) ||
422 IS_DF_WALL_WOOD(element))
424 if (IS_WALL_ICE(element) || IS_WALL_AMOEBA(element))
428 for (i = 0; i < 4; i++)
430 int dest_x = cSX + x * TILEX + MINI_TILEX * (i % 2);
431 int dest_y = cSY + y * TILEY + MINI_TILEY * (i / 2);
433 if (!((1 << i) & draw_mask))
436 if (element & (1 << i))
437 BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
440 ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
446 void DrawWalls_MM(int x, int y, int element)
448 DrawWallsExt_MM(x, y, element, HIT_MASK_ALL);
451 void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
457 DrawWalls_MM(x, y, element);
462 for (i = 0; i < 4; i++)
464 if (element & (1 << i))
470 int dst_x = cSX + x * TILEX + (i % 2) * MINI_TILEX;
471 int dst_y = cSY + y * TILEY + (i / 2) * MINI_TILEY;
473 if (bit_mask & (1 << i))
475 graphic = (IS_WALL_AMOEBA(element) ?
476 IMG_MM_AMOEBA_WALL_GROWING :
477 IMG_MM_ICE_WALL_SHRINKING);
482 graphic = (IS_WALL_AMOEBA(element) ?
488 getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
491 BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
499 void DrawElement_MM(int x, int y, int element)
501 if (element == EL_EMPTY)
502 DrawGraphic_MM(x, y, IMG_EMPTY);
503 else if (IS_WALL(element))
504 DrawWalls_MM(x, y, element);
506 else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Tile[x][y]))
508 int wall_element = Tile[x][y] - EL_WALL_CHANGING + Store[x][y];
510 DrawWalls_MM(x, y, wall_element);
513 else if (element == EL_PACMAN)
514 DrawLevelField_MM(x, y);
515 else if (element == EL_FUSE_ON &&
519 DrawGraphic_MM(x, y, IMG_MM_FUSE);
520 else if (element == EL_GRAY_BALL_ACTIVE)
521 DrawGraphic_MM(x, y, el_act2gfx(EL_GRAY_BALL, MM_ACTION_ACTIVE));
522 else if (element == EL_GRAY_BALL_OPENING)
523 DrawGraphic_MM(x, y, el_act2gfx(EL_GRAY_BALL, MM_ACTION_OPENING));
524 else if (element == EL_BOMB_ACTIVE)
525 DrawGraphic_MM(x, y, el_act2gfx(EL_BOMB, MM_ACTION_ACTIVE));
526 else if (element == EL_MINE_ACTIVE)
527 DrawGraphic_MM(x, y, el_act2gfx(EL_MINE, MM_ACTION_ACTIVE));
529 DrawGraphic_MM(x, y, el2gfx(element));
533 // ----------------------------------------------------------------------------
535 // ----------------------------------------------------------------------------
537 #define XSN_RND(x) ((x) != 0 ? rand() % (x) : 0)
538 #define XSN_ALPHA_VALUE(x) (SDL_ALPHA_OPAQUE * (x) / 100)
540 #define XSN_MAX_ITEMS 100
541 #define XSN_MAX_HEIGHT 40
543 #define XSN_MAX_DY 10
544 #define XSN_CHECK_DELAY 3
545 #define XSN_START_DELAY 60
546 #define XSN_UPDATE_DELAY 50
547 #define XSN_GROWTH_DELAY 3
548 #define XSN_GROWTH_RATE 3
549 #define XSN_CHANGE_DELAY 30
550 #define XSN_CHANGE_FACTOR 3
551 #define XSN_ALPHA_DEFAULT XSN_ALPHA_VALUE(95)
552 #define XSN_ALPHA_VISIBLE XSN_ALPHA_VALUE(50)
553 #define XSN_DEBUG_STEPS 5
555 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
556 static byte xsn_bits_1[] = { 0x22, 0x6b, 0x14, 0x2a, 0x14, 0x6b, 0x22 };
557 static byte xsn_bits_2[] = { 0x14, 0x08, 0x49, 0x36, 0x49, 0x08, 0x14 };
559 char debug_xsn_mode[] = { 76,101,116,32,105,116,32,115,110,111,119,33,0 };
561 void setHideSetupEntry(void *);
562 void removeHideSetupEntry(void *);
572 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
573 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
574 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
575 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
576 { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
577 { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
578 { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
580 static int num_xsn_data = ARRAY_SIZE(xsn_data);
609 struct XsnItem items[XSN_MAX_ITEMS];
616 static struct Xsn xsn = { 0 };
618 static int xsn_percent(void)
621 int xsn_m1 = xsn_m0 + 10;
622 int xsn_m2 = xsn_m1 + 10;
623 int xsn_m3 = xsn_m2 + 10;
624 time_t xsn_e0 = time(NULL);
625 struct tm *xsn_t0 = localtime(&xsn_e0);
626 struct tm xsn_t1 = { 0,0,0, xsn_m2*3, xsn_m3/3, xsn_t0->tm_year, 0,0,-1 };
627 time_t xsn_e1 = mktime(&xsn_t1);
628 int xsn_c0 = (25 * xsn_m3) << xsn_m1;
629 int xsn_c1 = (xsn_t1.tm_wday - xsn_m1) * !!xsn_t1.tm_wday;
631 for (xsn_m0 = 5; xsn_m0 > 0; xsn_m0--)
633 int xsn_c2 = (xsn_m0 > 4 ? 0 : xsn_c1) - xsn_m1 * xsn_m0;
634 int xsn_off = (xsn_m0 > 4 ? xsn_c0 : 0);
635 time_t xsn_e3 = xsn_e1 - xsn_c2 * xsn_c0;
637 if (xsn_e0 > xsn_e3 - xsn_off &&
638 xsn_e0 < xsn_e3 + xsn_off + xsn_c0)
639 return xsn_m0 * (xsn_m3 - xsn_m1);
645 static void xsn_init_item(int nr)
647 struct XsnItem *item = &xsn.items[nr];
649 item->type = XSN_RND(num_xsn_data);
651 if (xsn.change_type != 0)
653 int new_x = XSN_RND(xsn.area_xsize / 3);
655 item->x = (xsn.change_dir == 1 ? new_x : xsn.area_xsize - new_x);
656 item->y = XSN_RND(xsn.area_ysize);
660 item->x = XSN_RND(xsn.area_xsize - xsn_data[item->type].size);
661 item->y = XSN_RND(xsn.area_ysize / 10);
664 item->dy = XSN_RND(xsn.max_dy + 1) + 1;
665 item->dx = XSN_RND(item->dy / 4 + 1) * (XSN_RND(1000) > 500 ? -1 : 1);
670 static void xsn_update_item(int nr)
672 struct XsnItem *item = &xsn.items[nr];
677 if (xsn.change_type != 0)
679 int dx_new = ABS(item->dx) +
680 (xsn.change_type == 1 ?
681 XSN_RND(XSN_CHANGE_FACTOR + 1) - XSN_CHANGE_FACTOR / 2 :
684 item->dx = MIN(MAX(-50, dx_new * xsn.change_dir), 50);
687 int new_x = item->x + item->dx;
688 int new_y = item->y + item->dy;
690 item->active = (new_y < xsn.area_ysize);
692 if (xsn.change_type != 0)
693 item->active = (item->active && new_x > 0 && new_x < xsn.area_xsize);
695 int item_size = xsn_data[item->type].size;
696 int half_item_size = item_size / 2;
697 int mid_x = new_x + half_item_size;
698 int mid_y = new_y + half_item_size;
699 int upper_border = xsn.area_ysize - xsn.max_height;
702 new_y >= upper_border &&
704 new_x <= xsn.area_xsize - item_size &&
705 mid_y >= xsn.height[mid_x] &&
706 mid_y < xsn.area_ysize)
708 Bitmap *item_bitmap = xsn_data[item->type].bitmap;
709 SDL_Surface *surface = xsn.bitmap->surface;
710 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
711 int item_alpha = XSN_ALPHA_VALUE(81 + XSN_RND(20));
715 xsn.bitmap->surface = surface_masked;
717 SDLSetAlpha(item_bitmap->surface_masked, TRUE, item_alpha);
719 // blit to masked surface instead of opaque surface
720 BlitBitmapMasked(item_bitmap, xsn.bitmap, 0, 0, item_size, item_size,
721 new_x, new_y - upper_border);
723 SDLSetAlpha(item_bitmap->surface_masked, TRUE, XSN_ALPHA_DEFAULT);
725 for (i = -half_item_size; i <= half_item_size; i++)
727 int xpos = mid_x + i;
729 if (xpos >= 0 && xpos < xsn.area_xsize)
730 xsn.height[xpos] = MIN(new_y + ABS(i), xsn.height[xpos]);
733 if (xsn.height[mid_x] <= upper_border + shrink)
735 int xpos1 = MAX(0, new_x - half_item_size);
736 int xpos2 = MIN(new_x + 3 * half_item_size, xsn.area_xsize);
737 int xsize = xpos2 - xpos1;
738 int ysize1 = XSN_RND(xsn.max_height - shrink);
739 int ysize2 = xsn.max_height - ysize1;
741 SDLSetAlpha(surface_masked, FALSE, 0);
743 FillRectangle(xsn.bitmap, xpos1, xsn.max_height, xsize, xsn.max_height,
745 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, 0, xsize, ysize1,
746 xpos1, xsn.max_height + shrink);
747 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, ysize1, xsize, ysize2,
748 xpos1, xsn.max_height + ysize1);
749 FillRectangle(xsn.bitmap, xpos1, 0, xsize, xsn.max_height,
751 BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
752 xsize, xsn.max_height, xpos1, 0);
754 SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
756 for (i = xpos1; i < xpos2; i++)
757 xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
760 SDLFreeBitmapTextures(xsn.bitmap);
761 SDLCreateBitmapTextures(xsn.bitmap);
763 xsn.bitmap->surface = surface;
768 item->dx += XSN_RND(XSN_CHANGE_FACTOR) * (XSN_RND(1000) > 500 ? -1 : 1);
770 if (xsn.change_type == 0)
771 item->dx = MIN(MAX(-xsn.max_dx, item->dx), xsn.max_dx);
777 static void xsn_update_change(void)
779 if (XSN_RND(100) > 65)
781 xsn.change_dir = (XSN_RND(10) > 4 ? 1 : -1);
782 xsn.change_delay = XSN_RND(5) + 1;
785 else if (xsn.change_type == 2)
787 xsn.change_delay = XSN_RND(3) + 1;
792 xsn.change_delay = XSN_CHANGE_DELAY;
797 static void DrawTileCursor_Xsn(int draw_target)
799 static boolean initialized = FALSE;
800 static boolean started = FALSE;
801 static boolean active = FALSE;
802 static boolean debug = FALSE;
803 static DelayCounter check_delay = { XSN_CHECK_DELAY * 1000 };
804 static DelayCounter start_delay = { 0 };
805 static DelayCounter growth_delay = { 0 };
806 static DelayCounter update_delay = { 0 };
807 static DelayCounter change_delay = { 0 };
808 static int percent = 0;
809 static int debug_value = 0;
810 boolean reinitialize = FALSE;
811 boolean active_last = active;
814 if (draw_target != DRAW_TO_SCREEN)
817 if (DelayReached(&check_delay))
819 percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
822 setup.debug.xsn_percent = percent;
824 if (setup.debug.xsn_mode != AUTO)
825 percent = setup.debug.xsn_percent;
827 setup.debug.xsn_percent = percent;
829 active = (percent > 0);
831 if ((active && !active_last) || setup.debug.xsn_mode != AUTO)
832 removeHideSetupEntry(&setup.debug.xsn_mode);
833 else if (!active && active_last)
834 setHideSetupEntry(&setup.debug.xsn_mode);
836 if (setup.debug.xsn_mode == FALSE)
839 else if (tile_cursor.xsn_debug)
841 debug_value = (active ? 0 : MIN(debug_value + 1, XSN_DEBUG_STEPS));
845 ResetDelayCounter(&check_delay);
847 setup.debug.xsn_mode = (debug_value > 0);
848 tile_cursor.xsn_debug = FALSE;
856 xsn.area_xsize = gfx.win_xsize;
857 xsn.area_ysize = gfx.win_ysize;
859 for (i = 0; i < num_xsn_data; i++)
861 int size = xsn_data[i].size;
862 byte *bits = xsn_data[i].bits;
863 Bitmap *bitmap = CreateBitmap(size, size, DEFAULT_DEPTH);
865 FillRectangle(bitmap, 0, 0, size, size, BLACK_PIXEL);
867 for (y = 0; y < size; y++)
868 for (x = 0; x < size; x++)
869 if ((bits[y] >> x) & 0x01)
870 SDLPutPixel(bitmap, x, y, WHITE_PIXEL);
872 SDL_Surface *surface = bitmap->surface;
874 if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
875 Fail("SDLGetNativeSurface() failed");
877 SDL_Surface *surface_masked = bitmap->surface_masked;
879 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
880 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
882 SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
883 SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
885 xsn_data[i].bitmap = bitmap;
888 srand((unsigned int)time(NULL));
895 start_delay.value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
896 (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
899 ResetDelayCounter(&start_delay);
907 xsn.max_items = percent * XSN_MAX_ITEMS / 100;
908 xsn.max_height = percent * XSN_MAX_HEIGHT / 100;
910 xsn.max_dx = XSN_MAX_DX;
911 xsn.max_dy = XSN_MAX_DY;
913 xsn.change_delay = XSN_CHANGE_DELAY;
917 xsn.alpha = XSN_ALPHA_DEFAULT;
919 for (i = 0; i < xsn.max_items; i++)
923 if (xsn.area_xsize != gfx.win_xsize ||
924 xsn.area_ysize != gfx.win_ysize ||
927 xsn.area_xsize = gfx.win_xsize;
928 xsn.area_ysize = gfx.win_ysize;
930 if (xsn.bitmap != NULL)
931 FreeBitmap(xsn.bitmap);
933 xsn.bitmap = CreateBitmap(xsn.area_xsize, xsn.max_height * 2,
936 FillRectangle(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
939 SDL_Surface *surface = xsn.bitmap->surface;
941 if ((xsn.bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
942 Fail("SDLGetNativeSurface() failed");
944 SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
946 SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
947 SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
949 SDLSetAlpha(surface, TRUE, xsn.alpha);
950 SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
952 SDLCreateBitmapTextures(xsn.bitmap);
954 for (i = 0; i < num_xsn_data; i++)
956 SDLFreeBitmapTextures(xsn_data[i].bitmap);
957 SDLCreateBitmapTextures(xsn_data[i].bitmap);
960 if (xsn.height != NULL)
961 checked_free(xsn.height);
963 xsn.height = checked_calloc(xsn.area_xsize * sizeof(int));
965 for (i = 0; i < xsn.area_xsize; i++)
966 xsn.height[i] = xsn.area_ysize - 1;
971 if (!DelayReached(&start_delay))
974 update_delay.value = XSN_UPDATE_DELAY;
975 growth_delay.value = XSN_GROWTH_DELAY * 1000;
976 change_delay.value = XSN_CHANGE_DELAY * 1000;
978 ResetDelayCounter(&growth_delay);
979 ResetDelayCounter(&update_delay);
980 ResetDelayCounter(&change_delay);
985 if (xsn.num_items < xsn.max_items)
987 if (DelayReached(&growth_delay))
989 xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
990 xsn.num_items = MIN(xsn.num_items, xsn.max_items);
994 if (DelayReached(&update_delay))
996 for (i = 0; i < xsn.num_items; i++)
1000 if (DelayReached(&change_delay))
1002 xsn_update_change();
1004 change_delay.value = xsn.change_delay * 1000;
1007 int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
1008 (xsn.alpha > XSN_ALPHA_VISIBLE ? -1 : 0) :
1009 (xsn.alpha < XSN_ALPHA_DEFAULT ? +1 : 0));
1011 if (xsn_alpha_dx != 0)
1013 xsn.alpha += xsn_alpha_dx;
1015 SDLSetAlpha(xsn.bitmap->surface_masked, TRUE, xsn.alpha);
1017 SDLFreeBitmapTextures(xsn.bitmap);
1018 SDLCreateBitmapTextures(xsn.bitmap);
1021 BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1022 0, xsn.area_ysize - xsn.max_height);
1024 for (i = 0; i < xsn.num_items; i++)
1026 int dst_x = xsn.items[i].x;
1027 int dst_y = xsn.items[i].y;
1028 int type = xsn.items[i].type;
1029 int size = xsn_data[type].size;
1030 Bitmap *bitmap = xsn_data[type].bitmap;
1032 BlitToScreenMasked(bitmap, 0, 0, size, size, dst_x, dst_y);
1036 void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
1038 if (program.headless)
1041 Bitmap *fade_bitmap;
1045 int graphic = IMG_GLOBAL_TILE_CURSOR;
1047 int tilesize = TILESIZE_VAR;
1048 int width = tilesize;
1049 int height = tilesize;
1051 DrawTileCursor_Xsn(draw_target);
1053 if (!tile_cursor.enabled ||
1054 !tile_cursor.active ||
1055 !tile_cursor_active)
1058 if (tile_cursor.moving)
1060 int step = TILESIZE_VAR / 4;
1061 int dx = tile_cursor.target_x - tile_cursor.x;
1062 int dy = tile_cursor.target_y - tile_cursor.y;
1065 tile_cursor.x = tile_cursor.target_x;
1067 tile_cursor.x += SIGN(dx) * step;
1070 tile_cursor.y = tile_cursor.target_y;
1072 tile_cursor.y += SIGN(dy) * step;
1074 if (tile_cursor.x == tile_cursor.target_x &&
1075 tile_cursor.y == tile_cursor.target_y)
1076 tile_cursor.moving = FALSE;
1079 dst_x = tile_cursor.x;
1080 dst_y = tile_cursor.y;
1082 frame = getGraphicAnimationFrame(graphic, -1);
1084 getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1087 (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
1088 draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
1090 if (draw_target == DRAW_TO_SCREEN)
1091 BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
1093 BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
1097 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
1099 return GetPixel(bitmap, x, y);
1102 int get_base_element(int element)
1104 if (IS_MIRROR(element))
1105 return EL_MIRROR_START;
1106 else if (IS_MIRROR_FIXED(element))
1107 return EL_MIRROR_FIXED_START;
1108 else if (IS_POLAR(element))
1109 return EL_POLAR_START;
1110 else if (IS_POLAR_CROSS(element))
1111 return EL_POLAR_CROSS_START;
1112 else if (IS_BEAMER(element))
1113 return EL_BEAMER_RED_START + BEAMER_NR(element) * 16;
1114 else if (IS_FIBRE_OPTIC(element))
1115 return EL_FIBRE_OPTIC_START + FIBRE_OPTIC_NR(element) * 2;
1116 else if (IS_MCDUFFIN(element))
1117 return EL_MCDUFFIN_START;
1118 else if (IS_LASER(element))
1119 return EL_LASER_START;
1120 else if (IS_RECEIVER(element))
1121 return EL_RECEIVER_START;
1122 else if (IS_DF_MIRROR(element))
1123 return EL_DF_MIRROR_START;
1124 else if (IS_DF_MIRROR_AUTO(element))
1125 return EL_DF_MIRROR_AUTO_START;
1126 else if (IS_PACMAN(element))
1127 return EL_PACMAN_START;
1128 else if (IS_GRID_STEEL(element))
1129 return EL_GRID_STEEL_START;
1130 else if (IS_GRID_WOOD(element))
1131 return EL_GRID_WOOD_START;
1132 else if (IS_GRID_STEEL_FIXED(element))
1133 return EL_GRID_STEEL_FIXED_START;
1134 else if (IS_GRID_WOOD_FIXED(element))
1135 return EL_GRID_WOOD_FIXED_START;
1136 else if (IS_GRID_STEEL_AUTO(element))
1137 return EL_GRID_STEEL_AUTO_START;
1138 else if (IS_GRID_WOOD_AUTO(element))
1139 return EL_GRID_WOOD_AUTO_START;
1140 else if (IS_WALL_STEEL(element))
1141 return EL_WALL_STEEL_START;
1142 else if (IS_WALL_WOOD(element))
1143 return EL_WALL_WOOD_START;
1144 else if (IS_WALL_ICE(element))
1145 return EL_WALL_ICE_START;
1146 else if (IS_WALL_AMOEBA(element))
1147 return EL_WALL_AMOEBA_START;
1148 else if (IS_DF_WALL_STEEL(element))
1149 return EL_DF_WALL_STEEL_START;
1150 else if (IS_DF_WALL_WOOD(element))
1151 return EL_DF_WALL_WOOD_START;
1152 else if (IS_CHAR(element))
1153 return EL_CHAR_START;
1158 int get_element_phase(int element)
1160 return element - get_base_element(element);
1163 int get_num_elements(int element)
1165 if (IS_MIRROR(element) ||
1166 IS_POLAR(element) ||
1167 IS_BEAMER(element) ||
1168 IS_DF_MIRROR(element) ||
1169 IS_DF_MIRROR_AUTO(element))
1171 else if (IS_GRID_STEEL_FIXED(element) ||
1172 IS_GRID_WOOD_FIXED(element) ||
1173 IS_GRID_STEEL_AUTO(element) ||
1174 IS_GRID_WOOD_AUTO(element))
1176 else if (IS_MIRROR_FIXED(element) ||
1177 IS_POLAR_CROSS(element) ||
1178 IS_MCDUFFIN(element) ||
1179 IS_LASER(element) ||
1180 IS_RECEIVER(element) ||
1181 IS_PACMAN(element) ||
1182 IS_GRID_STEEL(element) ||
1183 IS_GRID_WOOD(element))
1189 int get_rotated_element(int element, int step)
1191 int base_element = get_base_element(element);
1192 int num_elements = get_num_elements(element);
1193 int element_phase = element - base_element;
1195 return base_element + (element_phase + step + num_elements) % num_elements;
1198 int map_wall_from_base_element(int element)
1202 case EL_WALL_STEEL_BASE: return EL_WALL_STEEL;
1203 case EL_WALL_WOOD_BASE: return EL_WALL_WOOD;
1204 case EL_WALL_ICE_BASE: return EL_WALL_ICE;
1205 case EL_WALL_AMOEBA_BASE: return EL_WALL_AMOEBA;
1206 case EL_DF_WALL_STEEL_BASE: return EL_DF_WALL_STEEL;
1207 case EL_DF_WALL_WOOD_BASE: return EL_DF_WALL_WOOD;
1209 default: return element;
1213 int map_wall_to_base_element(int element)
1217 case EL_WALL_STEEL: return EL_WALL_STEEL_BASE;
1218 case EL_WALL_WOOD: return EL_WALL_WOOD_BASE;
1219 case EL_WALL_ICE: return EL_WALL_ICE_BASE;
1220 case EL_WALL_AMOEBA: return EL_WALL_AMOEBA_BASE;
1221 case EL_DF_WALL_STEEL: return EL_DF_WALL_STEEL_BASE;
1222 case EL_DF_WALL_WOOD: return EL_DF_WALL_WOOD_BASE;
1224 default: return element;
1228 int el2gfx(int element)
1230 return el2img_mm(map_wall_from_base_element(element));
1233 int el_act2gfx(int element, int action)
1235 return el_act2img_mm(map_wall_from_base_element(element), action);
1238 void RedrawPlayfield_MM(void)
1244 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
1246 BlitBitmap(drawto_field, target_bitmap,
1247 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);