improved visibility of tile selection cursor for MM game engine
[rocksndiamonds.git] / src / game_mm / mm_tools.c
1 // ============================================================================
2 // Mirror Magic -- McDuffin's Revenge
3 // ----------------------------------------------------------------------------
4 // (c) 1994-2017 by Artsoft Entertainment
5 //                  Holger Schemel
6 //                  info@artsoft.org
7 //                  https://www.artsoft.org/
8 // ----------------------------------------------------------------------------
9 // mm_tools.c
10 // ============================================================================
11
12 #include <time.h>
13
14 #include "main_mm.h"
15
16 #include "mm_main.h"
17 #include "mm_tools.h"
18
19
20 void SetDrawtoField_MM(int mode)
21 {
22   int full_xsize = lev_fieldx * TILESIZE_VAR;
23   int full_ysize = lev_fieldy * TILESIZE_VAR;
24
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);
28
29   // for convenience, absolute screen position to centered level playfield
30   cSX = SX + dSX;
31   cSY = SY + dSY;
32   cSX2 = SX + dSX + 2;  // including playfield border
33   cSY2 = SY + dSY + 2;  // including playfield border
34
35   if (mode == DRAW_TO_BACKBUFFER)
36   {
37     cFX = FX + dSX;
38     cFY = FY + dSY;
39   }
40
41   SetTileCursorSXSY(cSX, cSY);
42 }
43
44 void ClearWindow(void)
45 {
46   ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
47
48   SetDrawtoField(DRAW_TO_BACKBUFFER);
49   SetDrawtoField_MM(DRAW_TO_BACKBUFFER);
50
51   redraw_mask |= REDRAW_FIELD;
52 }
53
54 void DrawGraphicAnimation_MM(int x, int y, int graphic, int frame)
55 {
56   Bitmap *bitmap;
57   int src_x, src_y;
58
59   getGraphicSource(graphic, frame, &bitmap, &src_x, &src_y);
60
61   BlitBitmap(bitmap, drawto_field, src_x, src_y, TILEX, TILEY,
62              cFX + x * TILEX, cFY + y * TILEY);
63 }
64
65 void DrawGraphic_MM(int x, int y, int graphic)
66 {
67 #if DEBUG
68   if (!IN_SCR_FIELD(x,y))
69   {
70     Debug("game:mm:DrawGraphic_MM", "x = %d, y = %d, graphic = %d",
71           x, y, graphic);
72     Debug("game:mm:DrawGraphic_MM", "This should never happen!");
73
74     return;
75   }
76 #endif
77
78   DrawGraphicExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY, graphic);
79
80   MarkTileDirty(x, y);
81 }
82
83 void DrawGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
84 {
85   Bitmap *bitmap;
86   int src_x, src_y;
87
88   getGraphicSource(graphic, 0, &bitmap, &src_x, &src_y);
89
90   BlitBitmap(bitmap, d, src_x, src_y, TILEX, TILEY, x, y);
91 }
92
93 void DrawGraphicThruMask_MM(int x, int y, int graphic)
94 {
95 #if DEBUG
96   if (!IN_SCR_FIELD(x,y))
97   {
98     Debug("game:mm:DrawGraphicThruMask_MM", "x = %d,y = %d, graphic = %d",
99           x, y, graphic);
100     Debug("game:mm:DrawGraphicThruMask_MM", "This should never happen!");
101
102     return;
103   }
104 #endif
105
106   DrawGraphicThruMaskExt_MM(drawto_field, cFX + x * TILEX, cFY + y * TILEY,
107                             graphic);
108
109   MarkTileDirty(x,y);
110 }
111
112 void DrawGraphicThruMaskExt_MM(DrawBuffer *d, int dest_x, int dest_y,
113                                int graphic)
114 {
115   int src_x, src_y;
116   Bitmap *src_bitmap;
117
118   if (graphic == IMG_EMPTY)
119     return;
120
121   getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
122
123   BlitBitmapMasked(src_bitmap, d, src_x, src_y, TILEX, TILEY, dest_x, dest_y);
124 }
125
126 void DrawMiniGraphic_MM(int x, int y, int graphic)
127 {
128   DrawMiniGraphicExt_MM(drawto, cSX + x * MINI_TILEX, cSY + y * MINI_TILEY,
129                         graphic);
130
131   MarkTileDirty(x / 2, y / 2);
132 }
133
134 #if 0
135 static void getMicroGraphicSource(int graphic, Bitmap **bitmap, int *x, int *y)
136 {
137   getSizedGraphicSource(graphic, 0, TILESIZE / 4, bitmap, x, y);
138 }
139 #endif
140
141 void DrawMiniGraphicExt_MM(DrawBuffer *d, int x, int y, int graphic)
142 {
143   Bitmap *bitmap;
144   int src_x, src_y;
145
146   getMiniGraphicSource(graphic, &bitmap, &src_x, &src_y);
147
148   BlitBitmap(bitmap, d, src_x, src_y, MINI_TILEX, MINI_TILEY, x, y);
149 }
150
151 void DrawGraphicShifted_MM(int x,int y, int dx,int dy, int graphic,
152                         int cut_mode, int mask_mode)
153 {
154   int width = TILEX, height = TILEY;
155   int cx = 0, cy = 0;
156   int src_x, src_y, dest_x, dest_y;
157   Bitmap *src_bitmap;
158
159   if (graphic < 0)
160   {
161     DrawGraphic_MM(x, y, graphic);
162
163     return;
164   }
165
166   if (dx || dy)                 // Verschiebung der Grafik?
167   {
168     if (x < BX1)                // Element kommt von links ins Bild
169     {
170       x = BX1;
171       width = dx;
172       cx = TILEX - dx;
173       dx = 0;
174     }
175     else if (x > BX2)           // Element kommt von rechts ins Bild
176     {
177       x = BX2;
178       width = -dx;
179       dx = TILEX + dx;
180     }
181     else if (x==BX1 && dx < 0)  // Element verläßt links das Bild
182     {
183       width += dx;
184       cx = -dx;
185       dx = 0;
186     }
187     else if (x==BX2 && dx > 0)  // Element verläßt rechts das Bild
188       width -= dx;
189     else if (dx)                // allg. Bewegung in x-Richtung
190       MarkTileDirty(x + SIGN(dx), y);
191
192     if (y < BY1)                // Element kommt von oben ins Bild
193     {
194       if (cut_mode==CUT_BELOW)  // Element oberhalb des Bildes
195         return;
196
197       y = BY1;
198       height = dy;
199       cy = TILEY - dy;
200       dy = 0;
201     }
202     else if (y > BY2)           // Element kommt von unten ins Bild
203     {
204       y = BY2;
205       height = -dy;
206       dy = TILEY + dy;
207     }
208     else if (y==BY1 && dy < 0)  // Element verläßt oben das Bild
209     {
210       height += dy;
211       cy = -dy;
212       dy = 0;
213     }
214     else if (dy > 0 && cut_mode == CUT_ABOVE)
215     {
216       if (y == BY2)             // Element unterhalb des Bildes
217         return;
218
219       height = dy;
220       cy = TILEY - dy;
221       dy = TILEY;
222       MarkTileDirty(x, y + 1);
223     }                           // Element verläßt unten das Bild
224     else if (dy > 0 && (y == BY2 || cut_mode == CUT_BELOW))
225     {
226       height -= dy;
227     }
228     else if (dy)                // allg. Bewegung in y-Richtung
229     {
230       MarkTileDirty(x, y + SIGN(dy));
231     }
232   }
233
234   getGraphicSource(graphic, 0, &src_bitmap, &src_x, &src_y);
235
236   src_x += cx;
237   src_y += cy;
238
239   dest_x = cFX + x * TILEX + dx;
240   dest_y = cFY + y * TILEY + dy;
241
242 #if DEBUG
243   if (!IN_SCR_FIELD(x,y))
244   {
245     Debug("game:mm:DrawGraphicShifted_MM", "x = %d, y = %d, graphic = %d",
246           x, y, graphic);
247     Debug("game:mm:DrawGraphicShifted_MM", "This should never happen!");
248
249     return;
250   }
251 #endif
252
253   if (mask_mode == USE_MASKING)
254     BlitBitmapMasked(src_bitmap, drawto_field,
255                      src_x, src_y, TILEX, TILEY, dest_x, dest_y);
256   else
257     BlitBitmap(src_bitmap, drawto_field,
258                src_x, src_y, width, height, dest_x, dest_y);
259
260   MarkTileDirty(x,y);
261 }
262
263 void DrawGraphicShiftedThruMask_MM(int x,int y, int dx,int dy, int graphic,
264                                 int cut_mode)
265 {
266   DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, USE_MASKING);
267 }
268
269 void DrawScreenElementExt_MM(int x, int y, int dx, int dy, int element,
270                           int cut_mode, int mask_mode)
271 {
272   int ux = LEVELX(x), uy = LEVELY(y);
273   int graphic = el2gfx(element);
274   int phase8 = ABS(MovPos[ux][uy]) / (TILEX / 8);
275   int phase2  = phase8 / 4;
276   int dir = MovDir[ux][uy];
277
278   if (element == EL_PACMAN)
279   {
280     graphic = (phase2 ? IMG_MM_PACMAN_RIGHT : IMG_MM_PACMAN_EATING_RIGHT);
281
282     if (dir == MV_UP)
283       graphic += 1;
284     else if (dir == MV_LEFT)
285       graphic += 2;
286     else if (dir == MV_DOWN)
287       graphic += 3;
288   }
289
290   if (dx || dy)
291     DrawGraphicShifted_MM(x, y, dx, dy, graphic, cut_mode, mask_mode);
292   else if (mask_mode == USE_MASKING)
293     DrawGraphicThruMask_MM(x, y, graphic);
294   else
295     DrawGraphic_MM(x, y, graphic);
296 }
297
298 void DrawLevelElementExt_MM(int x, int y, int dx, int dy, int element,
299                          int cut_mode, int mask_mode)
300 {
301   if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
302     DrawScreenElementExt_MM(SCREENX(x), SCREENY(y), dx, dy, element,
303                          cut_mode, mask_mode);
304 }
305
306 void DrawScreenElementShifted_MM(int x, int y, int dx, int dy, int element,
307                               int cut_mode)
308 {
309   DrawScreenElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
310 }
311
312 void DrawLevelElementShifted_MM(int x, int y, int dx, int dy, int element,
313                              int cut_mode)
314 {
315   DrawLevelElementExt_MM(x, y, dx, dy, element, cut_mode, NO_MASKING);
316 }
317
318 void DrawScreenElementThruMask_MM(int x, int y, int element)
319 {
320   DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
321 }
322
323 void DrawLevelElementThruMask_MM(int x, int y, int element)
324 {
325   DrawLevelElementExt_MM(x, y, 0, 0, element, NO_CUTTING, USE_MASKING);
326 }
327
328 void DrawLevelFieldThruMask_MM(int x, int y)
329 {
330   DrawLevelElementExt_MM(x, y, 0, 0, Tile[x][y], NO_CUTTING, USE_MASKING);
331 }
332
333 void DrawScreenElement_MM(int x, int y, int element)
334 {
335   DrawScreenElementExt_MM(x, y, 0, 0, element, NO_CUTTING, NO_MASKING);
336 }
337
338 void DrawLevelElement_MM(int x, int y, int element)
339 {
340   if (IN_LEV_FIELD(x, y) && IN_SCR_FIELD(SCREENX(x), SCREENY(y)))
341     DrawScreenElement_MM(SCREENX(x), SCREENY(y), element);
342 }
343
344 void DrawScreenField_MM(int x, int y)
345 {
346   int element = Tile[x][y];
347
348   if (!IN_LEV_FIELD(x, y))
349     return;
350
351   if (IS_MOVING(x, y))
352   {
353     int horiz_move = (MovDir[x][y] == MV_LEFT || MovDir[x][y] == MV_RIGHT);
354
355     DrawScreenElement_MM(x, y, EL_EMPTY);
356
357     if (horiz_move)
358       DrawScreenElementShifted_MM(x, y, MovPos[x][y], 0, element, NO_CUTTING);
359     else
360       DrawScreenElementShifted_MM(x, y, 0, MovPos[x][y], element, NO_CUTTING);
361   }
362   else if (IS_BLOCKED(x, y))
363   {
364     int oldx, oldy;
365     int sx, sy;
366     int horiz_move;
367
368     Blocked2Moving(x, y, &oldx, &oldy);
369
370     sx = SCREENX(oldx);
371     sy = SCREENY(oldy);
372     horiz_move = (MovDir[oldx][oldy] == MV_LEFT ||
373                   MovDir[oldx][oldy] == MV_RIGHT);
374
375     DrawScreenElement_MM(x, y, EL_EMPTY);
376
377     element = Tile[oldx][oldy];
378
379     if (horiz_move)
380       DrawScreenElementShifted_MM(sx, sy, MovPos[oldx][oldy], 0, element,
381                                   NO_CUTTING);
382     else
383       DrawScreenElementShifted_MM(sx, sy, 0, MovPos[oldx][oldy], element,
384                                   NO_CUTTING);
385   }
386   else if (IS_DRAWABLE(element))
387   {
388     DrawScreenElement_MM(x, y, element);
389   }
390   else
391   {
392     DrawScreenElement_MM(x, y, EL_EMPTY);
393   }
394 }
395
396 void DrawLevelField_MM(int x, int y)
397 {
398   DrawScreenField_MM(x, y);
399 }
400
401 void DrawMiniElement_MM(int x, int y, int element)
402 {
403   int graphic;
404
405   if (!element)
406   {
407     DrawMiniGraphic_MM(x, y, IMG_EMPTY);
408
409     return;
410   }
411
412   graphic = el2gfx(element);
413
414   DrawMiniGraphic_MM(x, y, graphic);
415 }
416
417 void DrawMiniElementOrWall_MM(int sx, int sy, int scroll_x, int scroll_y)
418 {
419   int x = sx + scroll_x, y = sy + scroll_y;
420
421   if (x < -1 || x > lev_fieldx || y < -1 || y > lev_fieldy)
422     DrawMiniElement_MM(sx, sy, EL_EMPTY);
423   else if (x > -1 && x < lev_fieldx && y > -1 && y < lev_fieldy)
424     DrawMiniElement_MM(sx, sy, Tile[x][y]);
425 }
426
427 void DrawField_MM(int x, int y)
428 {
429   int element = Tile[x][y];
430
431   DrawElement_MM(x, y, element);
432 }
433
434 void DrawLevel_MM(void)
435 {
436   int x,y;
437
438   ClearWindow();
439
440   for (x = 0; x < lev_fieldx; x++)
441     for (y = 0; y < lev_fieldy; y++)
442       DrawField_MM(x, y);
443
444   redraw_mask |= REDRAW_FIELD;
445 }
446
447 void DrawWallsExt_MM(int x, int y, int element, int draw_mask)
448 {
449   Bitmap *bitmap;
450   int graphic = el2gfx(WALL_BASE(element));
451   int gx, gy;
452   int i;
453
454   getMiniGraphicSource(graphic, &bitmap, &gx, &gy);
455
456   DrawGraphic_MM(x, y, IMG_EMPTY);
457
458   /*
459   if (IS_WALL_WOOD(element) || IS_WALL_AMOEBA(element) ||
460       IS_DF_WALL_WOOD(element))
461     gx += MINI_TILEX;
462   if (IS_WALL_ICE(element) || IS_WALL_AMOEBA(element))
463     gy += MINI_TILEY;
464   */
465
466   for (i = 0; i < 4; i++)
467   {
468     int dest_x = cSX + x * TILEX + MINI_TILEX * (i % 2);
469     int dest_y = cSY + y * TILEY + MINI_TILEY * (i / 2);
470
471     if (!((1 << i) & draw_mask))
472       continue;
473
474     if (element & (1 << i))
475       BlitBitmap(bitmap, drawto, gx, gy, MINI_TILEX, MINI_TILEY,
476                  dest_x, dest_y);
477     else
478       ClearRectangle(drawto, dest_x, dest_y, MINI_TILEX, MINI_TILEY);
479   }
480
481   MarkTileDirty(x, y);
482 }
483
484 void DrawWalls_MM(int x, int y, int element)
485 {
486   DrawWallsExt_MM(x, y, element, HIT_MASK_ALL);
487 }
488
489 void DrawWallsAnimation_MM(int x, int y, int element, int phase, int bit_mask)
490 {
491   int i;
492
493   if (phase == 0)
494   {
495     DrawWalls_MM(x, y, element);
496
497     return;
498   }
499
500   for (i = 0; i < 4; i++)
501   {
502     if (element & (1 << i))
503     {
504       int graphic;
505       int frame;
506       Bitmap *bitmap;
507       int src_x, src_y;
508       int dst_x = cSX + x * TILEX + (i % 2) * MINI_TILEX;
509       int dst_y = cSY + y * TILEY + (i / 2) * MINI_TILEY;
510
511       if (bit_mask & (1 << i))
512       {
513         graphic = (IS_WALL_AMOEBA(element) ?
514                    IMG_MM_AMOEBA_WALL_GROWING :
515                    IMG_MM_ICE_WALL_SHRINKING);
516         frame = phase;
517       }
518       else
519       {
520         graphic = (IS_WALL_AMOEBA(element) ?
521                    IMG_MM_AMOEBA_WALL :
522                    IMG_MM_ICE_WALL);
523         frame = 0;
524       }
525
526       getSizedGraphicSource(graphic, frame, MINI_TILESIZE, &bitmap,
527                             &src_x, &src_y);
528
529       BlitBitmap(bitmap, drawto, src_x, src_y, MINI_TILEX, MINI_TILEY,
530                  dst_x, dst_y);
531     }
532   }
533
534   MarkTileDirty(x, y);
535 }
536
537 void DrawElement_MM(int x, int y, int element)
538 {
539   if (element == EL_EMPTY)
540     DrawGraphic_MM(x, y, IMG_EMPTY);
541   else if (IS_WALL(element))
542     DrawWalls_MM(x, y, element);
543 #if 0
544   else if (IS_WALL_CHANGING(element) && IS_WALL_CHANGING(Tile[x][y]))
545   {
546     int wall_element = Tile[x][y] - EL_WALL_CHANGING + Store[x][y];
547
548     DrawWalls_MM(x, y, wall_element);
549   }
550 #endif
551   else if (element == EL_PACMAN)
552     DrawLevelField_MM(x, y);
553   else if (element == EL_FUSE_ON &&
554            laser.fuse_off &&
555            laser.fuse_x == x &&
556            laser.fuse_y == y)
557     DrawGraphic_MM(x, y, IMG_MM_FUSE);
558   else
559     DrawGraphic_MM(x, y, el2gfx(element));
560 }
561
562 #if 0
563 static void DrawMicroWalls_MM(int x, int y, int element)
564 {
565   Bitmap *bitmap;
566   int graphic = el2gfx(WALL_BASE(element));
567   int gx, gy;
568   int i;
569
570   getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
571
572   for (i = 0; i < 4; i++)
573   {
574     int xpos = MICROLEV_XPOS + x * MICRO_TILEX + MICRO_WALLX * (i % 2);
575     int ypos = MICROLEV_YPOS + y * MICRO_TILEY + MICRO_WALLY * (i / 2);
576
577     if (element & (1 << i))
578       BlitBitmap(bitmap, drawto, gx, gy, MICRO_WALLX, MICRO_WALLY, xpos, ypos);
579     else
580       ClearRectangle(drawto, xpos, ypos, MICRO_WALLX, MICRO_WALLY);
581   }
582 }
583
584 static void DrawMicroElement_MM(int x, int y, int element)
585 {
586   Bitmap *bitmap;
587   int graphic = el2gfx(element);
588   int gx, gy;
589
590   if (element == EL_EMPTY)
591     return;
592
593   if (IS_WALL(element))
594   {
595     DrawMicroWalls_MM(x, y, element);
596
597     return;
598   }
599
600   getMicroGraphicSource(graphic, &bitmap, &gx, &gy);
601
602   BlitBitmap(bitmap, drawto, gx, gy, MICRO_TILEX, MICRO_TILEY,
603              MICROLEV_XPOS + x * MICRO_TILEX, MICROLEV_YPOS + y * MICRO_TILEY);
604 }
605
606 static void DrawMicroLevelExt_MM(int xpos, int ypos)
607 {
608   int x, y;
609
610   ClearRectangle(drawto, xpos, ypos, MICROLEV_XSIZE, MICROLEV_YSIZE);
611
612   for (x = 0; x < STD_LEV_FIELDX; x++)
613     for (y = 0; y < STD_LEV_FIELDY; y++)
614       DrawMicroElement_MM(x, y, Ur[x][y]);
615
616   redraw_mask |= REDRAW_FIELD;
617 }
618 #endif
619
620 void DrawMiniLevel_MM(int size_x, int size_y, int scroll_x, int scroll_y)
621 {
622   int x, y;
623
624   for (x = 0; x < size_x; x++)
625     for (y = 0; y < size_y; y++)
626       DrawMiniElementOrWall_MM(x, y, scroll_x, scroll_y);
627
628   redraw_mask |= REDRAW_FIELD;
629 }
630
631
632 // ----------------------------------------------------------------------------
633 // XSN
634 // ----------------------------------------------------------------------------
635
636 #define XSN_RND(x)              ((x) != 0 ? rand() % (x) : 0)
637 #define XSN_ALPHA_VALUE(x)      (SDL_ALPHA_OPAQUE * (x) / 100)
638
639 #define XSN_MAX_ITEMS           100
640 #define XSN_MAX_HEIGHT          40
641 #define XSN_MAX_DX              2
642 #define XSN_MAX_DY              10
643 #define XSN_CHECK_DELAY         3
644 #define XSN_START_DELAY         60
645 #define XSN_UPDATE_DELAY        50
646 #define XSN_GROWTH_DELAY        3
647 #define XSN_GROWTH_RATE         3
648 #define XSN_CHANGE_DELAY        30
649 #define XSN_CHANGE_FACTOR       3
650 #define XSN_ALPHA_DEFAULT       XSN_ALPHA_VALUE(95)
651 #define XSN_ALPHA_VISIBLE       XSN_ALPHA_VALUE(50)
652 #define XSN_DEBUG_STEPS         5
653
654 static byte xsn_bits_0[] = { 0x05, 0x02, 0x05 };
655 static byte xsn_bits_1[] = { 0x22, 0x6b, 0x14, 0x2a, 0x14, 0x6b, 0x22 };
656 static byte xsn_bits_2[] = { 0x14, 0x08, 0x49, 0x36, 0x49, 0x08, 0x14 };
657
658 char debug_xsn_mode[] = { 76,101,116,32,105,116,32,115,110,111,119,33,0 };
659
660 void setHideSetupEntry(void *);
661 void removeHideSetupEntry(void *);
662
663 static struct
664 {
665   int size;
666   byte *bits;
667   Bitmap *bitmap;
668 }
669 xsn_data[] =
670 {
671   { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
672   { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
673   { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
674   { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
675   { ARRAY_SIZE(xsn_bits_1), xsn_bits_1 },
676   { ARRAY_SIZE(xsn_bits_2), xsn_bits_2 },
677   { ARRAY_SIZE(xsn_bits_0), xsn_bits_0 },
678 };
679 static int num_xsn_data = ARRAY_SIZE(xsn_data);
680
681 struct XsnItem
682 {
683   int x;
684   int y;
685   int dx;
686   int dy;
687   int type;
688   int active;
689 };
690
691 struct Xsn
692 {
693   int area_xsize;
694   int area_ysize;
695
696   int num_items;
697   int max_items;
698   int max_height;
699   int max_dx;
700   int max_dy;
701
702   int change_delay;
703   int change_type;
704   int change_dir;
705
706   int *height;
707
708   struct XsnItem items[XSN_MAX_ITEMS];
709
710   Bitmap *bitmap;
711
712   int alpha;
713 };
714
715 static struct Xsn xsn = { 0 };
716
717 static int xsn_percent(void)
718 {
719   int xsn_m0 = -3;
720   int xsn_m1 = xsn_m0 + 10;
721   int xsn_m2 = xsn_m1 + 10;
722   int xsn_m3 = xsn_m2 + 10;
723   time_t xsn_e0 = time(NULL);
724   struct tm *xsn_t0 = localtime(&xsn_e0);
725   struct tm xsn_t1 = { 0,0,0, xsn_m2*3, xsn_m3/3, xsn_t0->tm_year, 0,0,-1 };
726   time_t xsn_e1 = mktime(&xsn_t1);
727   int xsn_c0 = (25 * xsn_m3) << xsn_m1;
728   int xsn_c1 = (xsn_t1.tm_wday - xsn_m1) * !!xsn_t1.tm_wday;
729
730   for (xsn_m0 = 5; xsn_m0 > 0; xsn_m0--)
731   {
732     int xsn_c2 = (xsn_m0 > 4 ? 0 : xsn_c1) - xsn_m1 * xsn_m0;
733     int xsn_off = (xsn_m0 > 4 ? xsn_c0 : 0);
734     time_t xsn_e3 = xsn_e1 - xsn_c2 * xsn_c0;
735
736     if (xsn_e0 > xsn_e3 - xsn_off &&
737         xsn_e0 < xsn_e3 + xsn_off + xsn_c0)
738       return xsn_m0 * (xsn_m3 - xsn_m1);
739   }
740
741   return xsn_m0;
742 }
743
744 static void xsn_init_item(int nr)
745 {
746   struct XsnItem *item = &xsn.items[nr];
747
748   item->type = XSN_RND(num_xsn_data);
749
750   if (xsn.change_type != 0)
751   {
752     int new_x = XSN_RND(xsn.area_xsize / 3);
753
754     item->x = (xsn.change_dir == 1 ? new_x : xsn.area_xsize - new_x);
755     item->y = XSN_RND(xsn.area_ysize);
756   }
757   else
758   {
759     item->x = XSN_RND(xsn.area_xsize - xsn_data[item->type].size);
760     item->y = XSN_RND(xsn.area_ysize / 10);
761   }
762
763   item->dy = XSN_RND(xsn.max_dy + 1) + 1;
764   item->dx = XSN_RND(item->dy / 4 + 1) * (XSN_RND(1000) > 500 ? -1 : 1);
765
766   item->active = 1;
767 }
768
769 static void xsn_update_item(int nr)
770 {
771   struct XsnItem *item = &xsn.items[nr];
772
773   if (!item->active)
774     xsn_init_item(nr);
775
776   if (xsn.change_type != 0)
777   {
778     int dx_new = ABS(item->dx) +
779       (xsn.change_type == 1 ?
780        XSN_RND(XSN_CHANGE_FACTOR + 1) - XSN_CHANGE_FACTOR / 2 :
781        XSN_RND(20));
782
783     item->dx = MIN(MAX(-50, dx_new * xsn.change_dir), 50);
784   }
785
786   int new_x = item->x + item->dx;
787   int new_y = item->y + item->dy;
788
789   item->active = (new_y < xsn.area_ysize);
790
791   if (xsn.change_type != 0)
792     item->active = (item->active && new_x > 0 && new_x < xsn.area_xsize);
793
794   int item_size = xsn_data[item->type].size;
795   int half_item_size = item_size / 2;
796   int mid_x = new_x + half_item_size;
797   int mid_y = new_y + half_item_size;
798   int upper_border = xsn.area_ysize - xsn.max_height;
799
800   if (item->active &&
801       new_y >= upper_border &&
802       new_x >= 0 &&
803       new_x <= xsn.area_xsize - item_size &&
804       mid_y >= xsn.height[mid_x] &&
805       mid_y < xsn.area_ysize)
806   {
807     Bitmap *item_bitmap = xsn_data[item->type].bitmap;
808     SDL_Surface *surface = xsn.bitmap->surface;
809     SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
810     int item_alpha = XSN_ALPHA_VALUE(81 + XSN_RND(20));
811     int shrink = 1;
812     int i;
813
814     xsn.bitmap->surface = surface_masked;
815
816     SDLSetAlpha(item_bitmap->surface_masked, TRUE, item_alpha);
817
818     // blit to masked surface instead of opaque surface
819     BlitBitmapMasked(item_bitmap, xsn.bitmap, 0, 0, item_size, item_size,
820                      new_x, new_y - upper_border);
821
822     SDLSetAlpha(item_bitmap->surface_masked, TRUE, XSN_ALPHA_DEFAULT);
823
824     for (i = -half_item_size; i <= half_item_size; i++)
825     {
826       int xpos = mid_x + i;
827
828       if (xpos >= 0 && xpos < xsn.area_xsize)
829         xsn.height[xpos] = MIN(new_y + ABS(i), xsn.height[xpos]);
830     }
831
832     if (xsn.height[mid_x] <= upper_border + shrink)
833     {
834       int xpos1 = MAX(0, new_x - half_item_size);
835       int xpos2 = MIN(new_x + 3 * half_item_size, xsn.area_xsize);
836       int xsize = xpos2 - xpos1;
837       int ysize1 = XSN_RND(xsn.max_height - shrink);
838       int ysize2 = xsn.max_height - ysize1;
839
840       SDLSetAlpha(surface_masked, FALSE, 0);
841
842       FillRectangle(xsn.bitmap, xpos1, xsn.max_height, xsize, xsn.max_height,
843                     BLACK_PIXEL);
844       BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, 0, xsize, ysize1,
845                        xpos1, xsn.max_height + shrink);
846       BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, ysize1, xsize, ysize2,
847                        xpos1, xsn.max_height + ysize1);
848       FillRectangle(xsn.bitmap, xpos1, 0, xsize, xsn.max_height,
849                     BLACK_PIXEL);
850       BlitBitmapMasked(xsn.bitmap, xsn.bitmap, xpos1, xsn.max_height,
851                        xsize, xsn.max_height, xpos1, 0);
852
853       SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
854
855       for (i = xpos1; i < xpos2; i++)
856         xsn.height[i] = MIN(xsn.height[i] + shrink, xsn.area_ysize - 1);
857     }
858
859     SDLFreeBitmapTextures(xsn.bitmap);
860     SDLCreateBitmapTextures(xsn.bitmap);
861
862     xsn.bitmap->surface = surface;
863
864     item->active = 0;
865   }
866
867   item->dx += XSN_RND(XSN_CHANGE_FACTOR) * (XSN_RND(1000) > 500 ? -1 : 1);
868
869   if (xsn.change_type == 0)
870     item->dx = MIN(MAX(-xsn.max_dx, item->dx), xsn.max_dx);
871
872   item->x = new_x;
873   item->y = new_y;
874 }
875
876 static void xsn_update_change(void)
877 {
878   if (XSN_RND(100) > 65)
879   {
880     xsn.change_dir = (XSN_RND(10) > 4 ? 1 : -1);
881     xsn.change_delay = XSN_RND(5) + 1;
882     xsn.change_type = 2;
883   }
884   else if (xsn.change_type == 2)
885   {
886     xsn.change_delay = XSN_RND(3) + 1;
887     xsn.change_type = 1;
888   }
889   else
890   {
891     xsn.change_delay = XSN_CHANGE_DELAY;
892     xsn.change_type = 0;
893   }
894 }
895
896 static void DrawTileCursor_Xsn(int draw_target)
897 {
898   static boolean initialized = FALSE;
899   static boolean started = FALSE;
900   static boolean active = FALSE;
901   static boolean debug = FALSE;
902   static unsigned int check_delay = 0;
903   static unsigned int start_delay = 0;
904   static unsigned int growth_delay = 0;
905   static unsigned int update_delay = 0;
906   static unsigned int change_delay = 0;
907   static unsigned int check_delay_value = XSN_CHECK_DELAY * 1000;
908   static unsigned int start_delay_value = 0;
909   static unsigned int growth_delay_value = 0;
910   static unsigned int update_delay_value = 0;
911   static unsigned int change_delay_value = 0;
912   static int percent = 0;
913   static int debug_value = 0;
914   boolean reinitialize = FALSE;
915   boolean active_last = active;
916   int i, x, y;
917
918   if (draw_target != DRAW_TO_SCREEN)
919     return;
920
921   if (DelayReached(&check_delay, check_delay_value))
922   {
923     percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
924
925     if (debug)
926       setup.debug.xsn_percent = percent;
927
928     if (setup.debug.xsn_mode != AUTO)
929       percent = setup.debug.xsn_percent;
930
931     setup.debug.xsn_percent = percent;
932
933     active = (percent > 0);
934
935     if ((active && !active_last) || setup.debug.xsn_mode != AUTO)
936       removeHideSetupEntry(&setup.debug.xsn_mode);
937     else if (!active && active_last)
938       setHideSetupEntry(&setup.debug.xsn_mode);
939
940     if (setup.debug.xsn_mode == FALSE)
941       active = FALSE;
942   }
943   else if (tile_cursor.xsn_debug)
944   {
945     debug_value = (active ? 0 : MIN(debug_value + 1, XSN_DEBUG_STEPS));
946     debug = TRUE;
947     active = FALSE;
948
949     DelayReached(&check_delay, 0);
950
951     setup.debug.xsn_mode = (debug_value > 0);
952     tile_cursor.xsn_debug = FALSE;
953   }
954
955   if (!active)
956     return;
957
958   if (!initialized)
959   {
960     xsn.area_xsize = gfx.win_xsize;
961     xsn.area_ysize = gfx.win_ysize;
962
963     for (i = 0; i < num_xsn_data; i++)
964     {
965       int size = xsn_data[i].size;
966       byte *bits = xsn_data[i].bits;
967       Bitmap *bitmap = CreateBitmap(size, size, DEFAULT_DEPTH);
968
969       FillRectangle(bitmap, 0, 0, size, size, BLACK_PIXEL);
970
971       for (y = 0; y < size; y++)
972         for (x = 0; x < size; x++)
973           if ((bits[y] >> x) & 0x01)
974             SDLPutPixel(bitmap, x, y, WHITE_PIXEL);
975
976       SDL_Surface *surface = bitmap->surface;
977
978       if ((bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
979         Fail("SDLGetNativeSurface() failed");
980
981       SDL_Surface *surface_masked = bitmap->surface_masked;
982
983       SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
984                       SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
985
986       SDLSetAlpha(surface, TRUE, XSN_ALPHA_DEFAULT);
987       SDLSetAlpha(surface_masked, TRUE, XSN_ALPHA_DEFAULT);
988
989       xsn_data[i].bitmap = bitmap;
990     }
991
992     srand((unsigned int)time(NULL));
993
994     initialized = TRUE;
995   }
996
997   if (!active_last)
998   {
999     start_delay_value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
1000                          (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
1001     started = FALSE;
1002
1003     DelayReached(&start_delay, 0);
1004
1005     reinitialize = TRUE;
1006   }
1007
1008   if (reinitialize)
1009   {
1010     xsn.num_items  = 0;
1011     xsn.max_items  = percent * XSN_MAX_ITEMS / 100;
1012     xsn.max_height = percent * XSN_MAX_HEIGHT / 100;
1013
1014     xsn.max_dx = XSN_MAX_DX;
1015     xsn.max_dy = XSN_MAX_DY;
1016
1017     xsn.change_delay = XSN_CHANGE_DELAY;
1018     xsn.change_type  = 0;
1019     xsn.change_dir   = 0;
1020
1021     xsn.alpha = XSN_ALPHA_DEFAULT;
1022
1023     for (i = 0; i < xsn.max_items; i++)
1024       xsn_init_item(i);
1025   }
1026
1027   if (xsn.area_xsize != gfx.win_xsize ||
1028       xsn.area_ysize != gfx.win_ysize ||
1029       reinitialize)
1030   {
1031     xsn.area_xsize = gfx.win_xsize;
1032     xsn.area_ysize = gfx.win_ysize;
1033
1034     if (xsn.bitmap != NULL)
1035       FreeBitmap(xsn.bitmap);
1036
1037     xsn.bitmap = CreateBitmap(xsn.area_xsize, xsn.max_height * 2,
1038                               DEFAULT_DEPTH);
1039
1040     FillRectangle(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1041                   BLACK_PIXEL);
1042
1043     SDL_Surface *surface = xsn.bitmap->surface;
1044
1045     if ((xsn.bitmap->surface_masked = SDLGetNativeSurface(surface)) == NULL)
1046       Fail("SDLGetNativeSurface() failed");
1047
1048     SDL_Surface *surface_masked = xsn.bitmap->surface_masked;
1049
1050     SDL_SetColorKey(surface_masked, SET_TRANSPARENT_PIXEL,
1051                     SDL_MapRGB(surface_masked->format, 0x00, 0x00, 0x00));
1052
1053     SDLSetAlpha(surface, TRUE, xsn.alpha);
1054     SDLSetAlpha(surface_masked, TRUE, xsn.alpha);
1055
1056     SDLCreateBitmapTextures(xsn.bitmap);
1057
1058     for (i = 0; i < num_xsn_data; i++)
1059     {
1060       SDLFreeBitmapTextures(xsn_data[i].bitmap);
1061       SDLCreateBitmapTextures(xsn_data[i].bitmap);
1062     }
1063
1064     if (xsn.height != NULL)
1065       checked_free(xsn.height);
1066
1067     xsn.height = checked_calloc(xsn.area_xsize * sizeof(int));
1068
1069     for (i = 0; i < xsn.area_xsize; i++)
1070       xsn.height[i] = xsn.area_ysize - 1;
1071   }
1072
1073   if (!started)
1074   {
1075     if (!DelayReached(&start_delay, start_delay_value))
1076       return;
1077
1078     update_delay_value = XSN_UPDATE_DELAY;
1079     growth_delay_value = XSN_GROWTH_DELAY * 1000;
1080     change_delay_value = XSN_CHANGE_DELAY * 1000;
1081
1082     DelayReached(&growth_delay, 0);
1083     DelayReached(&update_delay, 0);
1084     DelayReached(&change_delay, 0);
1085
1086     started = TRUE;
1087   }
1088
1089   if (xsn.num_items < xsn.max_items)
1090   {
1091     if (DelayReached(&growth_delay, growth_delay_value))
1092     {
1093       xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
1094       xsn.num_items = MIN(xsn.num_items, xsn.max_items);
1095     }
1096   }
1097
1098   if (DelayReached(&update_delay, update_delay_value))
1099   {
1100     for (i = 0; i < xsn.num_items; i++)
1101       xsn_update_item(i);
1102   }
1103
1104   if (DelayReached(&change_delay, change_delay_value))
1105   {
1106     xsn_update_change();
1107
1108     change_delay_value = xsn.change_delay * 1000;
1109   }
1110
1111   int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
1112                       (xsn.alpha > XSN_ALPHA_VISIBLE ? -1 : 0) :
1113                       (xsn.alpha < XSN_ALPHA_DEFAULT ? +1 : 0));
1114
1115   if (xsn_alpha_dx != 0)
1116   {
1117     xsn.alpha += xsn_alpha_dx;
1118
1119     SDLSetAlpha(xsn.bitmap->surface_masked, TRUE, xsn.alpha);
1120
1121     SDLFreeBitmapTextures(xsn.bitmap);
1122     SDLCreateBitmapTextures(xsn.bitmap);
1123   }
1124
1125   BlitToScreenMasked(xsn.bitmap, 0, 0, xsn.area_xsize, xsn.max_height,
1126                      0, xsn.area_ysize - xsn.max_height);
1127
1128   for (i = 0; i < xsn.num_items; i++)
1129   {
1130     int dst_x = xsn.items[i].x;
1131     int dst_y = xsn.items[i].y;
1132     int type = xsn.items[i].type;
1133     int size = xsn_data[type].size;
1134     Bitmap *bitmap = xsn_data[type].bitmap;
1135
1136     BlitToScreenMasked(bitmap, 0, 0, size, size, dst_x, dst_y);
1137   }
1138 }
1139
1140 void DrawTileCursor_MM(int draw_target, boolean tile_cursor_active)
1141 {
1142   if (program.headless)
1143     return;
1144
1145   Bitmap *fade_bitmap;
1146   Bitmap *src_bitmap;
1147   int src_x, src_y;
1148   int dst_x, dst_y;
1149   int graphic = IMG_GLOBAL_TILE_CURSOR;
1150   int frame = 0;
1151   int tilesize = TILESIZE_VAR;
1152   int width = tilesize;
1153   int height = tilesize;
1154
1155   DrawTileCursor_Xsn(draw_target);
1156
1157   if (!tile_cursor.enabled ||
1158       !tile_cursor.active ||
1159       !tile_cursor_active)
1160     return;
1161
1162   if (tile_cursor.moving)
1163   {
1164     int step = TILESIZE_VAR / 4;
1165     int dx = tile_cursor.target_x - tile_cursor.x;
1166     int dy = tile_cursor.target_y - tile_cursor.y;
1167
1168     if (ABS(dx) < step)
1169       tile_cursor.x = tile_cursor.target_x;
1170     else
1171       tile_cursor.x += SIGN(dx) * step;
1172
1173     if (ABS(dy) < step)
1174       tile_cursor.y = tile_cursor.target_y;
1175     else
1176       tile_cursor.y += SIGN(dy) * step;
1177
1178     if (tile_cursor.x == tile_cursor.target_x &&
1179         tile_cursor.y == tile_cursor.target_y)
1180       tile_cursor.moving = FALSE;
1181   }
1182
1183   dst_x = tile_cursor.x;
1184   dst_y = tile_cursor.y;
1185
1186   frame = getGraphicAnimationFrame(graphic, -1);
1187
1188   getSizedGraphicSource(graphic, frame, tilesize, &src_bitmap, &src_x, &src_y);
1189
1190   fade_bitmap =
1191     (draw_target == DRAW_TO_FADE_SOURCE ? gfx.fade_bitmap_source :
1192      draw_target == DRAW_TO_FADE_TARGET ? gfx.fade_bitmap_target : NULL);
1193
1194   if (draw_target == DRAW_TO_SCREEN)
1195     BlitToScreenMasked(src_bitmap, src_x, src_y, width, height, dst_x, dst_y);
1196   else
1197     BlitBitmapMasked(src_bitmap, fade_bitmap, src_x, src_y, width, height,
1198                      dst_x, dst_y);
1199 }
1200
1201 #if 0
1202 static int REQ_in_range(int x, int y)
1203 {
1204   if (y > DY + 249 && y < DY + 278)
1205   {
1206     if (x > DX + 1 && x < DX + 48)
1207       return 1;
1208     else if (x > DX + 51 && x < DX + 98)
1209       return 2;
1210   }
1211
1212   return 0;
1213 }
1214 #endif
1215
1216 Pixel ReadPixel(DrawBuffer *bitmap, int x, int y)
1217 {
1218   return GetPixel(bitmap, x, y);
1219 }
1220
1221 void SetRGB(unsigned int pixel,
1222             unsigned short red, unsigned short green, unsigned short blue)
1223 {
1224 }
1225
1226 int get_base_element(int element)
1227 {
1228   if (IS_MIRROR(element))
1229     return EL_MIRROR_START;
1230   else if (IS_MIRROR_FIXED(element))
1231     return EL_MIRROR_FIXED_START;
1232   else if (IS_POLAR(element))
1233     return EL_POLAR_START;
1234   else if (IS_POLAR_CROSS(element))
1235     return EL_POLAR_CROSS_START;
1236   else if (IS_BEAMER(element))
1237     return EL_BEAMER_RED_START + BEAMER_NR(element) * 16;
1238   else if (IS_FIBRE_OPTIC(element))
1239     return EL_FIBRE_OPTIC_START + FIBRE_OPTIC_NR(element) * 2;
1240   else if (IS_MCDUFFIN(element))
1241     return EL_MCDUFFIN_START;
1242   else if (IS_LASER(element))
1243     return EL_LASER_START;
1244   else if (IS_RECEIVER(element))
1245     return EL_RECEIVER_START;
1246   else if (IS_DF_MIRROR(element))
1247     return EL_DF_MIRROR_START;
1248   else if (IS_DF_MIRROR_AUTO(element))
1249     return EL_DF_MIRROR_AUTO_START;
1250   else if (IS_PACMAN(element))
1251     return EL_PACMAN_START;
1252   else if (IS_GRID_STEEL(element))
1253     return EL_GRID_STEEL_START;
1254   else if (IS_GRID_WOOD(element))
1255     return EL_GRID_WOOD_START;
1256   else if (IS_GRID_STEEL_FIXED(element))
1257     return EL_GRID_STEEL_FIXED_START;
1258   else if (IS_GRID_WOOD_FIXED(element))
1259     return EL_GRID_WOOD_FIXED_START;
1260   else if (IS_GRID_STEEL_AUTO(element))
1261     return EL_GRID_STEEL_AUTO_START;
1262   else if (IS_GRID_WOOD_AUTO(element))
1263     return EL_GRID_WOOD_AUTO_START;
1264   else if (IS_WALL_STEEL(element))
1265     return EL_WALL_STEEL_START;
1266   else if (IS_WALL_WOOD(element))
1267     return EL_WALL_WOOD_START;
1268   else if (IS_WALL_ICE(element))
1269     return EL_WALL_ICE_START;
1270   else if (IS_WALL_AMOEBA(element))
1271     return EL_WALL_AMOEBA_START;
1272   else if (IS_DF_WALL_STEEL(element))
1273     return EL_DF_WALL_STEEL_START;
1274   else if (IS_DF_WALL_WOOD(element))
1275     return EL_DF_WALL_WOOD_START;
1276   else if (IS_CHAR(element))
1277     return EL_CHAR_START;
1278   else
1279     return element;
1280 }
1281
1282 int get_element_phase(int element)
1283 {
1284   return element - get_base_element(element);
1285 }
1286
1287 int get_num_elements(int element)
1288 {
1289   if (IS_MIRROR(element) ||
1290       IS_POLAR(element) ||
1291       IS_BEAMER(element) ||
1292       IS_DF_MIRROR(element) ||
1293       IS_DF_MIRROR_AUTO(element))
1294     return 16;
1295   else if (IS_GRID_STEEL_FIXED(element) ||
1296            IS_GRID_WOOD_FIXED(element) ||
1297            IS_GRID_STEEL_AUTO(element) ||
1298            IS_GRID_WOOD_AUTO(element))
1299     return 8;
1300   else if (IS_MIRROR_FIXED(element) ||
1301            IS_POLAR_CROSS(element) ||
1302            IS_MCDUFFIN(element) ||
1303            IS_LASER(element) ||
1304            IS_RECEIVER(element) ||
1305            IS_PACMAN(element) ||
1306            IS_GRID_STEEL(element) ||
1307            IS_GRID_WOOD(element))
1308     return 4;
1309   else
1310     return 1;
1311 }
1312
1313 int get_rotated_element(int element, int step)
1314 {
1315   int base_element = get_base_element(element);
1316   int num_elements = get_num_elements(element);
1317   int element_phase = element - base_element;
1318
1319   return base_element + (element_phase + step + num_elements) % num_elements;
1320 }
1321
1322 static int map_element(int element)
1323 {
1324   switch (element)
1325   {
1326     case EL_WALL_STEEL:         return EL_STEEL_WALL;
1327     case EL_WALL_WOOD:          return EL_WOODEN_WALL;
1328     case EL_WALL_ICE:           return EL_ICE_WALL;
1329     case EL_WALL_AMOEBA:        return EL_AMOEBA_WALL;
1330     case EL_DF_WALL_STEEL:      return EL_DF_STEEL_WALL;
1331     case EL_DF_WALL_WOOD:       return EL_DF_WOODEN_WALL;
1332
1333     default:                    return element;
1334   }
1335 }
1336
1337 int el2gfx(int element)
1338 {
1339   element = map_element(element);
1340
1341   switch (element)
1342   {
1343     case EL_LIGHTBALL:
1344       return IMG_MM_LIGHTBALL_RED + RND(3);
1345
1346     default:
1347       return el2img_mm(element);
1348   }
1349 }
1350
1351 void RedrawPlayfield_MM(void)
1352 {
1353   DrawLevel_MM();
1354   DrawLaser_MM();
1355 }
1356
1357 void BlitScreenToBitmap_MM(Bitmap *target_bitmap)
1358 {
1359   BlitBitmap(drawto_field, target_bitmap,
1360              REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE, REAL_SX, REAL_SY);
1361 }