rnd-19980907
[rocksndiamonds.git] / src / tools.c
1 /***********************************************************
2 *  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
3 *----------------------------------------------------------*
4 *  ©1995 Artsoft Development                               *
5 *        Holger Schemel                                    *
6 *        33659 Bielefeld-Senne                             *
7 *        Telefon: (0521) 493245                            *
8 *        eMail: aeglos@valinor.owl.de                      *
9 *               aeglos@uni-paderborn.de                    *
10 *               q99492@pbhrzx.uni-paderborn.de             *
11 *----------------------------------------------------------*
12 *  tools.c                                                 *
13 ***********************************************************/
14
15 #ifdef __FreeBSD__
16 #include <machine/joystick.h>
17 #endif
18
19 #include "tools.h"
20 #include "game.h"
21 #include "events.h"
22 #include "sound.h"
23 #include "misc.h"
24 #include "buttons.h"
25 #include "joystick.h"
26 #include "cartoons.h"
27
28 #include <math.h>
29
30 #ifdef MSDOS
31 extern BOOL wait_for_vsync;
32 #endif
33
34 void SetDrawtoField(int mode)
35 {
36   if (mode == DRAW_BUFFERED && soft_scrolling_on)
37   {
38     FX = TILEX;
39     FY = TILEY;
40     BX1 = -1;
41     BY1 = -1;
42     BX2 = SCR_FIELDX;
43     BY2 = SCR_FIELDY;
44     redraw_x1 = 1;
45     redraw_y1 = 1;
46
47     drawto_field = fieldbuffer;
48   }
49   else  /* DRAW_DIRECT, DRAW_BACKBUFFER */
50   {
51     FX = SX;
52     FY = SY;
53     BX1 = 0;
54     BY1 = 0;
55     BX2 = SCR_FIELDX - 1;
56     BY2 = SCR_FIELDY - 1;
57     redraw_x1 = 0;
58     redraw_y1 = 0;
59
60     drawto_field = (mode == DRAW_DIRECT ? window :  backbuffer);
61   }
62 }
63
64 void BackToFront()
65 {
66   int x,y;
67   Drawable buffer = (drawto_field != window ? drawto_field : backbuffer);
68
69   if (direct_draw_on && game_status == PLAYING)
70     redraw_mask &= ~REDRAW_MAIN;
71
72   if (redraw_mask & REDRAW_TILES && redraw_tiles > REDRAWTILES_THRESHOLD)
73     redraw_mask |= REDRAW_FIELD;
74
75   if (redraw_mask & REDRAW_FIELD || ScreenMovPos)
76     redraw_mask &= ~REDRAW_TILES;
77
78   if (!redraw_mask)
79     return;
80
81   if (redraw_mask & REDRAW_ALL)
82   {
83     XCopyArea(display,backbuffer,window,gc,
84               0,0, WIN_XSIZE,WIN_YSIZE,
85               0,0);
86     redraw_mask = 0;
87   }
88
89   if (redraw_mask & REDRAW_FIELD)
90   {
91 #ifdef MSDOS
92     wait_for_vsync = TRUE;
93 #endif
94     if (game_status != PLAYING || redraw_mask & REDRAW_FROM_BACKBUFFER)
95       XCopyArea(display,backbuffer,window,gc,
96                 REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE,
97                 REAL_SX,REAL_SY);
98     else
99     {
100       int fx = FX, fy = FY;
101
102       if (soft_scrolling_on)
103       {
104         fx += (PlayerMovDir & (MV_LEFT|MV_RIGHT) ? ScreenMovPos : 0);
105         fy += (PlayerMovDir & (MV_UP|MV_DOWN)    ? ScreenMovPos : 0);
106       }
107
108       XCopyArea(display,buffer,window,gc,
109                 fx,fy, SXSIZE,SYSIZE,
110                 SX,SY);
111     }
112     redraw_mask &= ~REDRAW_MAIN;
113   }
114
115   if (redraw_mask & REDRAW_DOORS)
116   {
117 #ifdef MSDOS
118     wait_for_vsync = TRUE;
119 #endif
120     if (redraw_mask & REDRAW_DOOR_1)
121       XCopyArea(display,backbuffer,window,gc,
122                 DX,DY, DXSIZE,DYSIZE,
123                 DX,DY);
124     if (redraw_mask & REDRAW_DOOR_2)
125     {
126       if ((redraw_mask & REDRAW_DOOR_2) == REDRAW_DOOR_2)
127         XCopyArea(display,backbuffer,window,gc,
128                   VX,VY, VXSIZE,VYSIZE,
129                   VX,VY);
130       else
131       {
132         if (redraw_mask & REDRAW_VIDEO_1)
133           XCopyArea(display,backbuffer,window,gc,
134                     VX+VIDEO_DISPLAY1_XPOS,VY+VIDEO_DISPLAY1_YPOS,
135                     VIDEO_DISPLAY_XSIZE,VIDEO_DISPLAY_YSIZE,
136                     VX+VIDEO_DISPLAY1_XPOS,VY+VIDEO_DISPLAY1_YPOS);
137         if (redraw_mask & REDRAW_VIDEO_2)
138           XCopyArea(display,backbuffer,window,gc,
139                     VX+VIDEO_DISPLAY2_XPOS,VY+VIDEO_DISPLAY2_YPOS,
140                     VIDEO_DISPLAY_XSIZE,VIDEO_DISPLAY_YSIZE,
141                     VX+VIDEO_DISPLAY2_XPOS,VY+VIDEO_DISPLAY2_YPOS);
142         if (redraw_mask & REDRAW_VIDEO_3)
143           XCopyArea(display,backbuffer,window,gc,
144                     VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS,
145                     VIDEO_CONTROL_XSIZE,VIDEO_CONTROL_YSIZE,
146                     VX+VIDEO_CONTROL_XPOS,VY+VIDEO_CONTROL_YPOS);
147       }
148     }
149     redraw_mask &= ~REDRAW_DOORS;
150   }
151
152   if (redraw_mask & REDRAW_MICROLEV)
153   {
154     XCopyArea(display,backbuffer,window,gc,
155               MICROLEV_XPOS,MICROLEV_YPOS, MICROLEV_XSIZE,MICROLEV_YSIZE,
156               MICROLEV_XPOS,MICROLEV_YPOS);
157     XCopyArea(display,backbuffer,window,gc,
158               SX,MICROLABEL_YPOS, SXSIZE,FONT4_YSIZE,
159               SX,MICROLABEL_YPOS);
160     redraw_mask &= ~REDRAW_MICROLEV;
161   }
162
163   if (redraw_mask & REDRAW_TILES)
164   {
165     for(x=0; x<SCR_FIELDX; x++)
166       for(y=0; y<SCR_FIELDY; y++)
167         if (redraw[redraw_x1 + x][redraw_y1 + y])
168           XCopyArea(display,buffer,window,gc,
169                     FX+x*TILEX,FX+y*TILEY, TILEX,TILEY,
170                     SX+x*TILEX,SY+y*TILEY);
171   }
172
173   XFlush(display);
174
175   for(x=0; x<MAX_BUF_XSIZE; x++)
176     for(y=0; y<MAX_BUF_YSIZE; y++)
177       redraw[x][y] = 0;
178   redraw_tiles = 0;
179   redraw_mask = 0;
180 }
181
182 void FadeToFront()
183 {
184 /*
185   long fading_delay = 300000;
186
187   if (fading_on && (redraw_mask & REDRAW_FIELD))
188   {
189 */
190
191 /*
192     int x,y;
193
194     XFillRectangle(display,window,gc,
195                    REAL_SX,REAL_SY,FULL_SXSIZE,FULL_SYSIZE);
196     XFlush(display);
197
198     for(i=0;i<2*FULL_SYSIZE;i++)
199     {
200       for(y=0;y<FULL_SYSIZE;y++)
201       {
202         XCopyArea(display,backbuffer,window,gc,
203                   REAL_SX,REAL_SY+i, FULL_SXSIZE,1, REAL_SX,REAL_SY+i);
204       }
205       XFlush(display);
206       Delay(10000);
207     }
208 */
209
210 /*
211     for(i=1;i<FULL_SYSIZE;i+=2)
212       XCopyArea(display,backbuffer,window,gc,
213                 REAL_SX,REAL_SY+i, FULL_SXSIZE,1, REAL_SX,REAL_SY+i);
214     XFlush(display);
215     Delay(fading_delay);
216 */
217
218 /*
219     XSetClipOrigin(display,clip_gc[PIX_FADEMASK],0,0);
220     XCopyArea(display,backbuffer,window,clip_gc[PIX_FADEMASK],
221               REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, REAL_SX,REAL_SY);
222     XFlush(display);
223     Delay(fading_delay);
224
225     XSetClipOrigin(display,clip_gc[PIX_FADEMASK],-1,-1);
226     XCopyArea(display,backbuffer,window,clip_gc[PIX_FADEMASK],
227               REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, REAL_SX,REAL_SY);
228     XFlush(display);
229     Delay(fading_delay);
230
231     XSetClipOrigin(display,clip_gc[PIX_FADEMASK],0,-1);
232     XCopyArea(display,backbuffer,window,clip_gc[PIX_FADEMASK],
233               REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, REAL_SX,REAL_SY);
234     XFlush(display);
235     Delay(fading_delay);
236
237     XSetClipOrigin(display,clip_gc[PIX_FADEMASK],-1,0);
238     XCopyArea(display,backbuffer,window,clip_gc[PIX_FADEMASK],
239               REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, REAL_SX,REAL_SY);
240     XFlush(display);
241     Delay(fading_delay);
242
243     redraw_mask &= ~REDRAW_MAIN;
244   }
245 */
246
247   BackToFront();
248 }
249
250 void ClearWindow()
251 {
252   XFillRectangle(display,backbuffer,gc,
253                  REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
254
255   if (soft_scrolling_on && game_status==PLAYING)
256   {
257     XFillRectangle(display,fieldbuffer,gc,
258                    0,0, FXSIZE,FYSIZE);
259     SetDrawtoField(DRAW_BUFFERED);
260   }
261   else
262     SetDrawtoField(DRAW_BACKBUFFER);
263
264   if (direct_draw_on && game_status==PLAYING)
265   {
266     XFillRectangle(display,window,gc,
267                    REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
268     SetDrawtoField(DRAW_DIRECT);
269   }
270
271   redraw_mask |= REDRAW_FIELD;
272 }
273
274 void DrawText(int x, int y, char *text, int font, int col)
275 {
276   DrawTextExt(drawto, gc, x, y, text, font, col);
277   if (x < DX)
278     redraw_mask |= REDRAW_FIELD;
279   else if (y < VY)
280     redraw_mask |= REDRAW_DOOR_1;
281 }
282
283 void DrawTextExt(Drawable d, GC gc, int x, int y,
284                  char *text, int font, int font_color)
285 {
286   int font_width, font_height, font_start;
287   int font_pixmap;
288
289   if (font!=FS_SMALL && font!=FS_BIG)
290     font = FS_SMALL;
291   if (font_color<FC_RED || font_color>FC_SPECIAL2)
292     font_color = FC_RED;
293
294   font_width =
295     (font==FS_BIG ? FONT1_XSIZE :
296      font_color<FC_SPECIAL1 ? FONT2_XSIZE :
297      font_color<FC_SPECIAL2 ? FONT3_XSIZE : FONT4_XSIZE);
298   font_height =
299     (font==FS_BIG ? FONT1_XSIZE :
300      font_color<FC_SPECIAL2 ? FONT2_XSIZE: FONT4_XSIZE);
301   font_pixmap = (font==FS_BIG ? PIX_BIGFONT : PIX_SMALLFONT);
302   font_start =
303     font_color*(font==FS_BIG ? FONT1_YSIZE : FONT2_YSIZE)*FONT_LINES_PER_FONT;
304
305   while(*text)
306   {
307     char c = *text++;
308
309     if (c>='a' && c<='z')
310       c = 'A' + (c - 'a');
311     else if (c=='ä' || c=='Ä')
312       c = 91;
313     else if (c=='ö' || c=='Ö')
314       c = 92;
315     else if (c=='ü' || c=='Ü')
316       c = 93;
317
318     if (c>=32 && c<=95)
319       XCopyArea(display,pix[font_pixmap],d,gc,
320                 ((c-32) % FONT_CHARS_PER_LINE)*font_width,
321                 ((c-32) / FONT_CHARS_PER_LINE)*font_height + font_start,
322                 font_width,font_height, x,y);
323
324     x += font_width;
325   }
326 }
327
328 void DrawPlayerField()
329 {
330   int x = JX, y = JY;
331   int sx = SCROLLX(x), sy = SCROLLY(y);
332
333   int sxx = 0, syy = 0;
334
335   int element = Feld[x][y];
336   int graphic, phase;
337   BOOL draw_thru_mask = FALSE;
338
339   if (PlayerGone)
340     return;
341
342 #if DEBUG
343   if (!IN_LEV_FIELD(x,y) || !IN_SCR_FIELD(sx,sy))
344   {
345     printf("DrawPlayerField(): x = %d, y = %d\n",x,y);
346     printf("DrawPlayerField(): sx = %d, sy = %d\n",sx,sy);
347     printf("DrawPlayerField(): This should never happen!\n");
348     return;
349   }
350 #endif
351
352   if (element == EL_EXPLODING)
353     return;
354
355   if (direct_draw_on)
356     SetDrawtoField(DRAW_BUFFERED);
357
358   /* draw things behind the player (EL_PFORTE* || mole/penguin/pig/dragon) */
359
360
361
362
363   DrawLevelField(x,y);
364
365
366
367   if (Store[x][y])
368   {
369     DrawGraphic(sx,sy, el2gfx(Store[x][y]));
370     draw_thru_mask = TRUE;
371   }
372   else if (element!=EL_DYNAMIT && element!=EL_DYNABOMB)
373   {
374     DrawLevelField(x,y);
375     draw_thru_mask = TRUE;
376   }
377
378   /*
379   else if (element!=EL_LEERRAUM && element!=EL_DYNAMIT && element!=EL_DYNABOMB)
380   {
381     DrawLevelField(x,y);
382     draw_thru_mask = TRUE;
383   }
384   */
385
386
387   draw_thru_mask = TRUE;
388
389
390
391
392   /* draw player himself */
393
394   if (PlayerMovDir==MV_LEFT)
395     graphic = (PlayerPushing ? GFX_SPIELER_PUSH_LEFT : GFX_SPIELER_LEFT);
396   else if (PlayerMovDir==MV_RIGHT)
397     graphic = (PlayerPushing ? GFX_SPIELER_PUSH_RIGHT : GFX_SPIELER_RIGHT);
398   else if (PlayerMovDir==MV_UP)
399     graphic = GFX_SPIELER_UP;
400   else  /* MV_DOWN || MV_NO_MOVING */
401     graphic = GFX_SPIELER_DOWN;
402
403   graphic += PlayerFrame;
404
405
406   if (PlayerGfxPos)
407   {
408     if (PlayerMovDir == MV_LEFT || PlayerMovDir == MV_RIGHT)
409       sxx = PlayerGfxPos;
410     else
411       syy = PlayerGfxPos;
412   }
413
414
415   if (!soft_scrolling_on && ScreenMovPos)
416     sxx = syy = 0;
417
418
419
420
421
422
423   if (draw_thru_mask)
424     DrawGraphicShiftedThruMask(sx,sy,sxx,syy,graphic,CUT_NO_CUTTING);
425     /*
426     DrawGraphicThruMask(sx, sy, graphic);
427     */
428   else
429     DrawGraphicShifted(sx,sy,sxx,syy,graphic,CUT_NO_CUTTING);
430   /*
431     DrawGraphic(sx, sy, graphic);
432     */
433
434
435
436   MarkTileDirty(sx,sy);
437
438
439
440   if (PlayerPushing && PlayerGfxPos)
441   {
442     int nextJX = JX + (JX - lastJX);
443     int nextJY = JY + (JY - lastJY);
444     int px = SCROLLX(nextJX), py = SCROLLY(nextJY);
445
446     if (Feld[JX][JY] == EL_SOKOBAN_FELD_LEER ||
447         Feld[nextJX][nextJY] == EL_SOKOBAN_FELD_VOLL)
448       DrawGraphicShiftedThruMask(px,py,sxx,syy,
449                                  GFX_SOKOBAN_OBJEKT,
450                                  CUT_NO_CUTTING);
451     else
452     {
453       int element = Feld[nextJX][nextJY];
454       int graphic = el2gfx(element);
455
456       if (element == EL_FELSBROCKEN && sxx)
457       {
458         int phase = (PlayerGfxPos / (TILEX/4));
459
460         if (PlayerMovDir == MV_LEFT)
461           graphic += phase;
462         else
463           graphic += (phase+4)%4;
464
465
466         /*
467         printf("----> (%d, %d, %d)\n",
468                PlayerGfxPos, phase, graphic);
469                */
470
471       }
472
473       DrawGraphicShifted(px,py, sxx,syy, graphic, CUT_NO_CUTTING);
474     }
475   }
476
477
478
479   /* draw things in front of player (EL_DYNAMIT || EL_DYNABOMB) */
480
481   if (element == EL_DYNAMIT || element == EL_DYNABOMB)
482   {
483     graphic = el2gfx(element);
484
485     if (element == EL_DYNAMIT)
486     {
487       if ((phase = (96-MovDelay[x][y])/12) > 6)
488         phase = 6;
489     }
490     else
491     {
492       if ((phase = ((96-MovDelay[x][y])/6) % 8) > 3)
493         phase = 7-phase;
494     }
495
496     DrawGraphicThruMask(sx,sy, graphic + phase);
497   }
498
499   if (direct_draw_on)
500   {
501     int dest_x = SX+SCROLLX(x)*TILEX;
502     int dest_y = SY+SCROLLY(y)*TILEY;
503     int x_size = TILEX;
504     int y_size = TILEY;
505
506     if (!ScreenMovPos)
507     {
508       dest_x = SX + SCROLLX(MIN(JX,lastJX))*TILEX;
509       dest_y = SY + SCROLLY(MIN(JY,lastJY))*TILEY;
510       x_size = TILEX * (1 + ABS(JX - lastJX));
511       y_size = TILEY * (1 + ABS(JY - lastJY));
512     }
513
514     XCopyArea(display,drawto_field,window,gc,
515               dest_x,dest_y, x_size,y_size, dest_x,dest_y);
516     SetDrawtoField(DRAW_DIRECT);
517   }
518 }
519
520 static int getGraphicAnimationPhase(int frames, int delay, int mode)
521 {
522   int phase;
523
524   if (mode == ANIM_OSCILLATE)
525   {
526     int max_anim_frames = frames*2 - 2;
527     phase = (FrameCounter % (delay * max_anim_frames)) / delay;
528     phase = (phase < frames ? phase : max_anim_frames - phase);
529   }
530   else
531     phase = (FrameCounter % (delay * frames)) / delay;
532
533   if (mode == ANIM_REVERSE)
534     phase = -phase;
535
536   return(phase);
537 }
538
539 void DrawGraphicAnimation(int x, int y, int graphic,
540                           int frames, int delay, int mode)
541 {
542   int phase = getGraphicAnimationPhase(frames, delay, mode);
543
544   if (!(FrameCounter % delay) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
545     DrawGraphic(SCROLLX(x),SCROLLY(y), graphic + phase);
546 }
547
548 void DrawGraphic(int x, int y, int graphic)
549 {
550
551 #if DEBUG
552   if (!IN_SCR_FIELD(x,y))
553   {
554     printf("DrawGraphic(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
555     printf("DrawGraphic(): This should never happen!\n");
556     return;
557   }
558 #endif
559
560   DrawGraphicExt(drawto_field, gc, x, y, graphic);
561   MarkTileDirty(x,y);
562 }
563
564 void DrawGraphicExt(Drawable d, GC gc, int x, int y, int graphic)
565 {
566   DrawGraphicExtHiRes(d, gc, FX+x*TILEX, FY+y*TILEY, graphic);
567 }
568
569 void DrawGraphicExtHiRes(Drawable d, GC gc, int x, int y, int graphic)
570 {
571   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
572   {
573     graphic -= GFX_START_ROCKSSCREEN;
574     XCopyArea(display,pix[PIX_BACK],d,gc,
575               SX+(graphic % GFX_PER_LINE)*TILEX,
576               SY+(graphic / GFX_PER_LINE)*TILEY,
577               TILEX,TILEY, x,y);
578   }
579   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
580   {
581     graphic -= GFX_START_ROCKSHEROES;
582     XCopyArea(display,pix[PIX_HEROES],d,gc,
583               (graphic % HEROES_PER_LINE)*TILEX,
584               (graphic / HEROES_PER_LINE)*TILEY,
585               TILEX,TILEY, x,y);
586   }
587   else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT)
588   {
589     graphic -= GFX_START_ROCKSFONT;
590     XCopyArea(display,pix[PIX_BIGFONT],d,gc,
591               (graphic % FONT_CHARS_PER_LINE)*TILEX,
592               (graphic / FONT_CHARS_PER_LINE)*TILEY +
593               FC_SPECIAL1*TILEY*FONT_LINES_PER_FONT,
594               TILEX,TILEY, x,y);
595   }
596   else
597     XFillRectangle(display,d,gc, x,y, TILEX,TILEY);
598 }
599
600 void DrawGraphicThruMask(int x, int y, int graphic)
601 {
602   int src_x,src_y, dest_x,dest_y;
603
604 #if DEBUG
605   if (!IN_SCR_FIELD(x,y))
606   {
607     printf("DrawGraphicThruMask(): x = %d, y = %d\n",x,y);
608     printf("DrawGraphicThruMask(): This should never happen!\n");
609     return;
610   }
611 #endif
612
613   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
614   {
615     graphic -= GFX_START_ROCKSSCREEN;
616     src_x  = SX+(graphic % GFX_PER_LINE)*TILEX;
617     src_y  = SY+(graphic / GFX_PER_LINE)*TILEY;
618     dest_x = FX+x*TILEX;
619     dest_y = FY+y*TILEY;
620
621     XSetClipOrigin(display,clip_gc[PIX_BACK],dest_x-src_x,dest_y-src_y);
622     XCopyArea(display,pix[PIX_BACK],drawto_field,clip_gc[PIX_BACK],
623               src_x,src_y, TILEX,TILEY, dest_x,dest_y);
624   }
625   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
626   {
627     graphic -= GFX_START_ROCKSHEROES;
628     src_x  = (graphic % HEROES_PER_LINE)*TILEX;
629     src_y  = (graphic / HEROES_PER_LINE)*TILEY;
630     dest_x = FX+x*TILEX;
631     dest_y = FY+y*TILEY;
632
633     XSetClipOrigin(display,clip_gc[PIX_HEROES],dest_x-src_x,dest_y-src_y);
634     XCopyArea(display,pix[PIX_HEROES],drawto_field,clip_gc[PIX_HEROES],
635               src_x,src_y, TILEX,TILEY, dest_x,dest_y);
636   }
637   else
638   {
639     DrawGraphic(x,y,graphic);
640     return;
641   }
642
643   MarkTileDirty(x,y);
644 }
645
646 void DrawElementThruMask(int x, int y, int element)
647 {
648   DrawGraphicThruMask(x,y,el2gfx(element));
649 }
650
651 void DrawMiniGraphic(int x, int y, int graphic)
652 {
653   DrawMiniGraphicExt(drawto, gc, x, y, graphic);
654   MarkTileDirty(x/2, y/2);
655 }
656
657 void DrawMiniGraphicExt(Drawable d, GC gc, int x, int y, int graphic)
658 {
659   DrawMiniGraphicExtHiRes(d,gc, SX+x*MINI_TILEX,SY+y*MINI_TILEY, graphic);
660 }
661
662 void DrawMiniGraphicExtHiRes(Drawable d, GC gc, int x, int y, int graphic)
663 {
664   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
665   {
666     graphic -= GFX_START_ROCKSSCREEN;
667     XCopyArea(display,pix[PIX_BACK],d,gc,
668               MINI_GFX_STARTX+(graphic % MINI_GFX_PER_LINE)*MINI_TILEX,
669               MINI_GFX_STARTY+(graphic / MINI_GFX_PER_LINE)*MINI_TILEY,
670               MINI_TILEX,MINI_TILEY, x,y);
671   }
672   else if (graphic >= GFX_START_ROCKSFONT && graphic <= GFX_END_ROCKSFONT)
673   {
674     graphic -= GFX_START_ROCKSFONT;
675     XCopyArea(display,pix[PIX_SMALLFONT],d,gc,
676               (graphic % FONT_CHARS_PER_LINE)*FONT4_XSIZE,
677               (graphic / FONT_CHARS_PER_LINE)*FONT4_YSIZE +
678               FC_SPECIAL2*FONT2_YSIZE*FONT_LINES_PER_FONT,
679               MINI_TILEX,MINI_TILEY, x,y);
680   }
681   else
682     XFillRectangle(display,d,gc, x,y, MINI_TILEX,MINI_TILEY);
683 }
684
685 void DrawGraphicShifted(int x,int y, int dx,int dy, int graphic, int cut_mode)
686 {
687   int width = TILEX, height = TILEY;
688   int cx = 0, cy = 0;
689
690   if (graphic < 0)
691   {
692     DrawGraphic(x,y,graphic);
693     return;
694   }
695
696   if (dx || dy)                 /* Verschiebung der Grafik? */
697   {
698     if (x < BX1)                /* Element kommt von links ins Bild */
699     {
700       x = BX1;
701       width = dx;
702       cx = TILEX - dx;
703       dx = 0;
704     }
705     else if (x > BX2)           /* Element kommt von rechts ins Bild */
706     {
707       x = BX2;
708       width = -dx;
709       dx = TILEX + dx;
710     }
711     else if (x==BX1 && dx<0)    /* Element verläßt links das Bild */
712     {
713       width += dx;
714       cx = -dx;
715       dx = 0;
716     }
717     else if (x==BX2 && dx>0)    /* Element verläßt rechts das Bild */
718       width -= dx;
719     else if (dx)                /* allg. Bewegung in x-Richtung */
720       MarkTileDirty(x + SIGN(dx), y);
721
722     if (y < BY1)                /* Element kommt von oben ins Bild */
723     {
724       if (cut_mode==CUT_BELOW)  /* Element oberhalb des Bildes */
725         return;
726
727       y = BY1;
728       height = dy;
729       cy = TILEY - dy;
730       dy = 0;
731     }
732     else if (y > BY2)           /* Element kommt von unten ins Bild */
733     {
734       y = BY2;
735       height = -dy;
736       dy = TILEY + dy;
737     }
738     else if (y==BY1 && dy<0)    /* Element verläßt oben das Bild */
739     {
740       height += dy;
741       cy = -dy;
742       dy = 0;
743     }
744     else if (dy > 0 && cut_mode==CUT_ABOVE)
745     {
746       if (y == BY2)             /* Element unterhalb des Bildes */
747         return;
748
749       height = dy;
750       cy = TILEY-dy;
751       dy = TILEY;
752       MarkTileDirty(x, y + 1);
753     }                           /* Element verläßt unten das Bild */
754     else if (dy > 0 && (y == BY2 || cut_mode==CUT_BELOW))
755       height -= dy;
756     else if (dy)                /* allg. Bewegung in y-Richtung */
757       MarkTileDirty(x, y + SIGN(dy));
758   }
759
760   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
761   {
762     graphic -= GFX_START_ROCKSSCREEN;
763     XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
764               SX+(graphic % GFX_PER_LINE)*TILEX+cx,
765               SY+(graphic / GFX_PER_LINE)*TILEY+cy,
766               width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
767   }
768   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
769   {
770     graphic -= GFX_START_ROCKSHEROES;
771     XCopyArea(display,pix[PIX_HEROES],drawto_field,gc,
772               (graphic % HEROES_PER_LINE)*TILEX+cx,
773               (graphic / HEROES_PER_LINE)*TILEY+cy,
774               width,height, FX+x*TILEX+dx,FY+y*TILEY+dy);
775   }
776
777 #if DEBUG
778   if (!IN_SCR_FIELD(x,y))
779   {
780     printf("DrawGraphicShifted(): x = %d, y = %d, graphic = %d\n",x,y,graphic);
781     printf("DrawGraphicShifted(): This should never happen!\n");
782     return;
783   }
784 #endif
785
786   MarkTileDirty(x,y);
787 }
788
789 void DrawElementShifted(int x, int y, int dx, int dy, int element,int cut_mode)
790 {
791   int ux = UNSCROLLX(x), uy = UNSCROLLY(y);
792   int graphic = el2gfx(element);
793   int phase4 = ABS(MovPos[ux][uy])/(TILEX/4);
794   int phase  = phase4 / 2;
795   int dir = MovDir[ux][uy];
796
797   if (element==EL_PACMAN || element==EL_KAEFER || element==EL_FLIEGER)
798   {
799     graphic += 4*!phase;
800
801     if (dir == MV_UP)
802       graphic += 1;
803     else if (dir == MV_LEFT)
804       graphic += 2;
805     else if (dir == MV_DOWN)
806       graphic += 3;
807   }
808   else if (element==EL_MAULWURF || element==EL_PINGUIN ||
809            element==EL_SCHWEIN || element==EL_DRACHE)
810   {
811     if (dir==MV_LEFT)
812       graphic = (element==EL_MAULWURF ? GFX_MAULWURF_LEFT :
813                  element==EL_PINGUIN ? GFX_PINGUIN_LEFT :
814                  element==EL_SCHWEIN ? GFX_SCHWEIN_LEFT : GFX_DRACHE_LEFT);
815     else if (dir==MV_RIGHT)
816       graphic = (element==EL_MAULWURF ? GFX_MAULWURF_RIGHT :
817                  element==EL_PINGUIN ? GFX_PINGUIN_RIGHT :
818                  element==EL_SCHWEIN ? GFX_SCHWEIN_RIGHT : GFX_DRACHE_RIGHT);
819     else if (dir==MV_UP)
820       graphic = (element==EL_MAULWURF ? GFX_MAULWURF_UP :
821                  element==EL_PINGUIN ? GFX_PINGUIN_UP :
822                  element==EL_SCHWEIN ? GFX_SCHWEIN_UP : GFX_DRACHE_UP);
823     else
824       graphic = (element==EL_MAULWURF ? GFX_MAULWURF_DOWN :
825                  element==EL_PINGUIN ? GFX_PINGUIN_DOWN :
826                  element==EL_SCHWEIN ? GFX_SCHWEIN_DOWN : GFX_DRACHE_DOWN);
827
828     graphic += phase4;
829   }
830   else if (element==EL_SONDE)
831   {
832     graphic = GFX_SONDE_START + getGraphicAnimationPhase(8, 2, ANIM_NORMAL);
833   }
834   else if (element==EL_BUTTERFLY || element==EL_FIREFLY)
835   {
836     graphic += !phase;
837   }
838   else if ((element==EL_FELSBROCKEN || IS_GEM(element)) && !cut_mode)
839   {
840     graphic += phase * (element==EL_FELSBROCKEN ? 2 : 1);
841   }
842   else if ((element==EL_SIEB_LEER || element==EL_SIEB2_LEER ||
843             element==EL_SIEB_VOLL || element==EL_SIEB2_VOLL) && SiebAktiv)
844   {
845     graphic += 3-(SiebAktiv%8)/2;
846   }
847   else if (IS_AMOEBOID(element))
848   {
849     graphic = (element==EL_AMOEBE_TOT ? GFX_AMOEBE_TOT : GFX_AMOEBE_LEBT);
850     graphic += (x+2*y) % 4;
851   }
852   else if (element==EL_MAUER_LEBT)
853   {
854     BOOL links_massiv = FALSE, rechts_massiv = FALSE;
855
856     if (!IN_LEV_FIELD(ux-1,uy) || IS_MAUER(Feld[ux-1][uy]))
857       links_massiv = TRUE;
858     if (!IN_LEV_FIELD(ux+1,uy) || IS_MAUER(Feld[ux+1][uy]))
859       rechts_massiv = TRUE;
860
861     if (links_massiv && rechts_massiv)
862       graphic = GFX_MAUERWERK;
863     else if (links_massiv)
864       graphic = GFX_MAUER_R;
865     else if (rechts_massiv)
866       graphic = GFX_MAUER_L;
867   }
868
869   if (dx || dy)
870     DrawGraphicShifted(x,y, dx,dy, graphic, cut_mode);
871   else
872     DrawGraphic(x,y, graphic);
873 }
874
875 void DrawGraphicShiftedThruMask(int x,int y, int dx,int dy, int graphic,
876                                 int cut_mode)
877 {
878   int width = TILEX, height = TILEY;
879   int cx = 0, cy = 0;
880   int src_x,src_y, dest_x,dest_y;
881
882   if (graphic < 0)
883   {
884     DrawGraphic(x,y,graphic);
885     return;
886   }
887
888   if (dx || dy)                 /* Verschiebung der Grafik? */
889   {
890     if (x < BX1)                /* Element kommt von links ins Bild */
891     {
892       x = BX1;
893       width = dx;
894       cx = TILEX - dx;
895       dx = 0;
896     }
897     else if (x > BX2)           /* Element kommt von rechts ins Bild */
898     {
899       x = BX2;
900       width = -dx;
901       dx = TILEX + dx;
902     }
903     else if (x==BX1 && dx<0)    /* Element verläßt links das Bild */
904     {
905       width += dx;
906       cx = -dx;
907       dx = 0;
908     }
909     else if (x==BX2 && dx>0)    /* Element verläßt rechts das Bild */
910       width -= dx;
911     else if (dx)                /* allg. Bewegung in x-Richtung */
912       MarkTileDirty(x + SIGN(dx), y);
913
914     if (y < BY1)                /* Element kommt von oben ins Bild */
915     {
916       if (cut_mode==CUT_BELOW)  /* Element oberhalb des Bildes */
917         return;
918
919       y = BY1;
920       height = dy;
921       cy = TILEY - dy;
922       dy = 0;
923     }
924     else if (y > BY2)           /* Element kommt von unten ins Bild */
925     {
926       y = BY2;
927       height = -dy;
928       dy = TILEY + dy;
929     }
930     else if (y==BY1 && dy<0)    /* Element verläßt oben das Bild */
931     {
932       height += dy;
933       cy = -dy;
934       dy = 0;
935     }
936     else if (dy > 0 && cut_mode==CUT_ABOVE)
937     {
938       if (y == BY2)             /* Element unterhalb des Bildes */
939         return;
940
941       height = dy;
942       cy = TILEY-dy;
943       dy = TILEY;
944       MarkTileDirty(x, y + 1);
945     }                           /* Element verläßt unten das Bild */
946     else if (dy > 0 && (y == BY2 || cut_mode==CUT_BELOW))
947       height -= dy;
948     else if (dy)                /* allg. Bewegung in y-Richtung */
949       MarkTileDirty(x, y + SIGN(dy));
950   }
951
952   if (graphic >= GFX_START_ROCKSSCREEN && graphic <= GFX_END_ROCKSSCREEN)
953   {
954     graphic -= GFX_START_ROCKSSCREEN;
955     src_x  = SX+(graphic % GFX_PER_LINE)*TILEX+cx;
956     src_y  = SY+(graphic / GFX_PER_LINE)*TILEY+cy;
957     dest_x = FX+x*TILEX+dx;
958     dest_y = FY+y*TILEY+dy;
959
960     XSetClipOrigin(display,clip_gc[PIX_BACK],dest_x-src_x,dest_y-src_y);
961     XCopyArea(display,pix[PIX_BACK],drawto_field,clip_gc[PIX_BACK],
962               src_x,src_y, width,height, dest_x,dest_y);
963   }
964   else if (graphic >= GFX_START_ROCKSHEROES && graphic <= GFX_END_ROCKSHEROES)
965   {
966     graphic -= GFX_START_ROCKSHEROES;
967     src_x  = (graphic % HEROES_PER_LINE)*TILEX+cx;
968     src_y  = (graphic / HEROES_PER_LINE)*TILEY+cy;
969     dest_x = FX+x*TILEX+dx;
970     dest_y = FY+y*TILEY+dy;
971
972     XSetClipOrigin(display,clip_gc[PIX_HEROES],dest_x-src_x,dest_y-src_y);
973     XCopyArea(display,pix[PIX_HEROES],drawto_field,clip_gc[PIX_HEROES],
974               src_x,src_y, width,height, dest_x,dest_y);
975   }
976
977 #if DEBUG
978   if (!IN_SCR_FIELD(x,y))
979   {
980     printf("DrawGraphicShiftedThruMask(): x = %d, y = %d, graphic = %d\n",
981            x,y,graphic);
982     printf("DrawGraphicShifted(): This should never happen!\n");
983     return;
984   }
985 #endif
986
987   MarkTileDirty(x,y);
988 }
989
990 void ErdreichAnbroeckeln(int x, int y)
991 {
992   int i, width, height, cx,cy;
993   int ux = UNSCROLLX(x), uy = UNSCROLLY(y);
994   int element, graphic;
995   int snip = 4;
996   static int xy[4][2] =
997   {
998     { 0,-1 },
999     { -1,0 },
1000     { +1,0 },
1001     { 0,+1 }
1002   };
1003
1004   if (!IN_LEV_FIELD(ux,uy))
1005     return;
1006
1007   element = Feld[ux][uy];
1008
1009   if (element==EL_ERDREICH)
1010   {
1011     if (!IN_SCR_FIELD(x,y))
1012       return;
1013
1014     graphic = GFX_ERDENRAND;
1015
1016     for(i=0;i<4;i++)
1017     {
1018       int uxx,uyy;
1019
1020       uxx = ux+xy[i][0];
1021       uyy = uy+xy[i][1];
1022       if (!IN_LEV_FIELD(uxx,uyy))
1023         element = EL_BETON;
1024       else
1025         element = Feld[uxx][uyy];
1026
1027 /*
1028       if (element==EL_ERDREICH || IS_SOLID(element))
1029         continue;
1030 */
1031       if (element==EL_ERDREICH)
1032         continue;
1033
1034       if (i==1 || i==2)
1035       {
1036         width = snip;
1037         height = TILEY;
1038         cx = (i==2 ? TILEX-snip : 0);
1039         cy = 0;
1040       }
1041       else
1042       {
1043         width = TILEX;
1044         height = snip;
1045         cx = 0;
1046         cy = (i==3 ? TILEY-snip : 0);
1047       }
1048
1049       XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
1050                 SX+(graphic % GFX_PER_LINE)*TILEX+cx,
1051                 SY+(graphic / GFX_PER_LINE)*TILEY+cy,
1052                 width,height, FX+x*TILEX+cx,FY+y*TILEY+cy);
1053     }
1054
1055     MarkTileDirty(x,y);
1056   }
1057   else
1058   {
1059     graphic = GFX_ERDENRAND;
1060
1061     for(i=0;i<4;i++)
1062     {
1063       int xx,yy,uxx,uyy;
1064
1065       xx = x+xy[i][0];
1066       yy = y+xy[i][1];
1067       uxx = ux+xy[i][0];
1068       uyy = uy+xy[i][1];
1069 /*
1070       if (!IN_LEV_FIELD(uxx,uyy) || Feld[uxx][uyy]!=EL_ERDREICH ||
1071           !IN_SCR_FIELD(xx,yy) || IS_SOLID(element))
1072         continue;
1073 */
1074
1075       if (!IN_LEV_FIELD(uxx,uyy) || Feld[uxx][uyy]!=EL_ERDREICH ||
1076           !IN_SCR_FIELD(xx,yy))
1077         continue;
1078
1079       if (i==1 || i==2)
1080       {
1081         width = snip;
1082         height = TILEY;
1083         cx = (i==1 ? TILEX-snip : 0);
1084         cy = 0;
1085       }
1086       else
1087       {
1088         width = TILEX;
1089         height = snip;
1090         cx = 0;
1091         cy = (i==0 ? TILEY-snip : 0);
1092       }
1093
1094       XCopyArea(display,pix[PIX_BACK],drawto_field,gc,
1095                 SX+(graphic % GFX_PER_LINE)*TILEX+cx,
1096                 SY+(graphic / GFX_PER_LINE)*TILEY+cy,
1097                 width,height, FX+xx*TILEX+cx,FY+yy*TILEY+cy);
1098
1099       MarkTileDirty(xx,yy);
1100     }
1101   }
1102 }
1103
1104 void DrawScreenElement(int x, int y, int element)
1105 {
1106   DrawElementShifted(x,y,0,0,element,CUT_NO_CUTTING);
1107   ErdreichAnbroeckeln(x,y);
1108 }
1109
1110 void DrawLevelElement(int x, int y, int element)
1111 {
1112   if (IN_LEV_FIELD(x,y) && IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
1113     DrawScreenElement(SCROLLX(x),SCROLLY(y),element);
1114 }
1115
1116 void DrawScreenField(int x, int y)
1117 {
1118   int ux = UNSCROLLX(x), uy = UNSCROLLY(y);
1119   int element;
1120
1121   if (!IN_LEV_FIELD(ux,uy))
1122   {
1123     DrawScreenElement(x,y,EL_BETON);
1124     return;
1125   }
1126
1127   element = Feld[ux][uy];
1128
1129   if (IS_MOVING(ux,uy))
1130   {
1131     int horiz_move = (MovDir[ux][uy]==MV_LEFT || MovDir[ux][uy]==MV_RIGHT);
1132     BOOL cut_mode = CUT_NO_CUTTING;
1133
1134     if (Store[ux][uy]==EL_MORAST_LEER ||
1135         Store[ux][uy]==EL_SIEB_LEER ||
1136         Store[ux][uy]==EL_SIEB2_LEER ||
1137         Store[ux][uy]==EL_AMOEBE_NASS)
1138       cut_mode = CUT_ABOVE;
1139     else if (Store[ux][uy]==EL_MORAST_VOLL ||
1140         Store[ux][uy]==EL_SIEB_VOLL ||
1141         Store[ux][uy]==EL_SIEB2_VOLL ||
1142         Store[ux][uy]==EL_SALZSAEURE)
1143       cut_mode = CUT_BELOW;
1144
1145     if (cut_mode==CUT_ABOVE)
1146       DrawElementShifted(x,y,0,0,Store[ux][uy],CUT_NO_CUTTING);
1147     else
1148       DrawScreenElement(x,y,EL_LEERRAUM);
1149
1150     if (horiz_move)
1151       DrawElementShifted(x,y,MovPos[ux][uy],0,element,CUT_NO_CUTTING);
1152     else
1153       DrawElementShifted(x,y,0,MovPos[ux][uy],element,cut_mode);
1154   }
1155   else if (IS_BLOCKED(ux,uy))
1156   {
1157     int oldx,oldy;
1158     int sx, sy;
1159     int horiz_move;
1160     BOOL cut_mode = CUT_NO_CUTTING;
1161
1162     Blocked2Moving(ux,uy,&oldx,&oldy);
1163     sx = SCROLLX(oldx);
1164     sy = SCROLLY(oldy);
1165     horiz_move = (MovDir[oldx][oldy]==MV_LEFT || MovDir[oldx][oldy]==MV_RIGHT);
1166
1167     if (Store[oldx][oldy]==EL_MORAST_LEER ||
1168         Store[oldx][oldy]==EL_SIEB_LEER ||
1169         Store[oldx][oldy]==EL_SIEB2_LEER ||
1170         Store[oldx][oldy]==EL_AMOEBE_NASS)
1171       cut_mode = CUT_ABOVE;
1172
1173     DrawScreenElement(x,y,EL_LEERRAUM);
1174     element = Feld[oldx][oldy];
1175
1176     if (horiz_move)
1177       DrawElementShifted(sx,sy,MovPos[oldx][oldy],0,element,CUT_NO_CUTTING);
1178     else
1179       DrawElementShifted(sx,sy,0,MovPos[oldx][oldy],element,cut_mode);
1180   }
1181   else if (IS_DRAWABLE(element))
1182     DrawScreenElement(x,y,element);
1183   else
1184     DrawScreenElement(x,y,EL_LEERRAUM);
1185 }
1186
1187 void DrawLevelField(int x, int y)
1188 {
1189   if (IN_SCR_FIELD(SCROLLX(x),SCROLLY(y)))
1190     DrawScreenField(SCROLLX(x),SCROLLY(y));
1191   else if (IS_MOVING(x,y))
1192   {
1193     int newx,newy;
1194
1195     Moving2Blocked(x,y,&newx,&newy);
1196     if (IN_SCR_FIELD(SCROLLX(newx),SCROLLY(newy)))
1197       DrawScreenField(SCROLLX(newx),SCROLLY(newy));
1198   }
1199   else if (IS_BLOCKED(x,y))
1200   {
1201     int oldx,oldy;
1202
1203     Blocked2Moving(x,y,&oldx,&oldy);
1204     if (IN_SCR_FIELD(SCROLLX(oldx),SCROLLY(oldy)))
1205       DrawScreenField(SCROLLX(oldx),SCROLLY(oldy));
1206   }
1207 }
1208
1209 void DrawMiniElement(int x, int y, int element)
1210 {
1211   int graphic;
1212
1213   if (!element)
1214   {
1215     DrawMiniGraphic(x,y,-1);
1216     return;
1217   }
1218
1219   graphic = el2gfx(element);
1220   DrawMiniGraphic(x,y,graphic);
1221 }
1222
1223 void DrawMiniElementOrWall(int x, int y, int scroll_x, int scroll_y)
1224 {
1225   if (x+scroll_x<-1 || x+scroll_x>lev_fieldx ||
1226       y+scroll_y<-1 || y+scroll_y>lev_fieldy)
1227     DrawMiniElement(x,y,EL_LEERRAUM);
1228   else if (x+scroll_x==-1 || x+scroll_x==lev_fieldx ||
1229            y+scroll_y==-1 || y+scroll_y==lev_fieldy)
1230     DrawMiniElement(x,y,EL_BETON);
1231   else
1232     DrawMiniElement(x,y,Feld[x+scroll_x][y+scroll_y]);
1233 }
1234
1235 void DrawMicroElement(int xpos, int ypos, int element)
1236 {
1237   int graphic;
1238
1239   if (element==EL_LEERRAUM)
1240     return;
1241
1242   graphic = el2gfx(element);
1243
1244   XCopyArea(display,pix[PIX_BACK],drawto,gc,
1245             MICRO_GFX_STARTX+(graphic % MICRO_GFX_PER_LINE)*MICRO_TILEX,
1246             MICRO_GFX_STARTY+(graphic / MICRO_GFX_PER_LINE)*MICRO_TILEY,
1247             MICRO_TILEX,MICRO_TILEY, xpos,ypos);
1248 }
1249
1250 void DrawLevel()
1251 {
1252   int x,y;
1253
1254   ClearWindow();
1255
1256   for(x=BX1; x<=BX2; x++)
1257     for(y=BY1; y<=BY2; y++)
1258       DrawScreenField(x,y);
1259
1260   if (soft_scrolling_on)
1261     XCopyArea(display,fieldbuffer,backbuffer,gc,
1262               FX,FY, SXSIZE,SYSIZE,
1263               SX,SY);
1264
1265   redraw_mask |= (REDRAW_FIELD | REDRAW_FROM_BACKBUFFER);
1266 }
1267
1268 void DrawMiniLevel(int scroll_x, int scroll_y)
1269 {
1270   int x,y;
1271
1272   ClearWindow();
1273
1274   for(x=0;x<2*SCR_FIELDX;x++)
1275     for(y=0;y<2*SCR_FIELDY;y++)
1276       DrawMiniElementOrWall(x,y,scroll_x,scroll_y);
1277
1278   redraw_mask |= REDRAW_FIELD;
1279 }
1280
1281 void DrawMicroLevel(int xpos, int ypos)
1282 {
1283   int x,y;
1284
1285   XFillRectangle(display,drawto,gc,
1286                  xpos-MICRO_TILEX,ypos-MICRO_TILEY,
1287                  MICRO_TILEX*(STD_LEV_FIELDX+2),
1288                  MICRO_TILEY*(STD_LEV_FIELDY+2));
1289   if (lev_fieldx < STD_LEV_FIELDX)
1290     xpos += (STD_LEV_FIELDX - lev_fieldx)/2 * MICRO_TILEX;
1291   if (lev_fieldy < STD_LEV_FIELDY)
1292     ypos += (STD_LEV_FIELDY - lev_fieldy)/2 * MICRO_TILEY;
1293
1294   for(x=-1;x<=STD_LEV_FIELDX;x++)
1295     for(y=-1;y<=STD_LEV_FIELDY;y++)
1296       if (x>=0 && x<lev_fieldx && y>=0 && y<lev_fieldy)
1297         DrawMicroElement(xpos+MICRO_TILEX*x,ypos+MICRO_TILEY*y,
1298                          Feld[x][y]=Ur[x][y]);
1299       else if (x>=-1 && x<lev_fieldx+1 && y>=-1 && y<lev_fieldy+1)
1300         DrawMicroElement(xpos+MICRO_TILEX*x,ypos+MICRO_TILEY*y,
1301                          EL_BETON);
1302
1303   XFillRectangle(display,drawto,gc, SX,MICROLABEL_YPOS, SXSIZE,FONT4_YSIZE);
1304
1305   if (level.name)
1306   {
1307     int len = strlen(level.name);
1308     int lxpos = SX+(SXSIZE-len*FONT4_XSIZE)/2;
1309     int lypos = MICROLABEL_YPOS;
1310
1311     DrawText(lxpos,lypos,level.name,FS_SMALL,FC_SPECIAL2);
1312   }
1313
1314   redraw_mask |= REDRAW_MICROLEV;
1315 }
1316
1317 int AYS_in_range(int x, int y)
1318 {
1319   if (y>DY+249 && y<DY+278)
1320   {
1321     if (x>DX+1 && x<DX+48)
1322       return(1);
1323     else if (x>DX+51 && x<DX+98) 
1324       return(2);
1325   }
1326   return(0);
1327 }
1328
1329 BOOL AreYouSure(char *text, unsigned int ays_state)
1330 {
1331   int mx,my, ty, result = -1;
1332   unsigned int old_door_state;
1333
1334   old_door_state = GetDoorState();
1335
1336   CloseDoor(DOOR_CLOSE_1);
1337
1338   /* Alten Türinhalt sichern */
1339   XCopyArea(display,pix[PIX_DB_DOOR],pix[PIX_DB_DOOR],gc,
1340             DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
1341             DOOR_GFX_PAGEX2,DOOR_GFX_PAGEY1);
1342
1343   /* Fragetext schreiben */
1344   XFillRectangle(display,pix[PIX_DB_DOOR],gc,
1345                  DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1,DXSIZE,DYSIZE);
1346
1347   for(ty=0;ty<13;ty++)
1348   {
1349     int tx,tl,tc;
1350     char txt[256];
1351
1352     if (!(*text))
1353       break;
1354     for(tl=0,tx=0;tx<7;tl++,tx++)
1355     {
1356       tc=*(text+tx);
1357       if (!tc || tc==32)
1358         break;
1359     }
1360     if (!tl)
1361     { 
1362       text++; 
1363       ty--; 
1364       continue; 
1365     }
1366     sprintf(txt,text); 
1367     txt[tl]=0;
1368     DrawTextExt(pix[PIX_DB_DOOR],gc,
1369                 DOOR_GFX_PAGEX1+51-(tl*14)/2,SY+ty*16,txt,FS_SMALL,FC_YELLOW);
1370     text+=(tl+(tc==32));
1371   }
1372
1373   if (ays_state & AYS_ASK)
1374     XCopyArea(display,pix[PIX_DOOR],pix[PIX_DB_DOOR],gc,
1375               DOOR_GFX_PAGEX4,OK_BUTTON_GFX_YPOS,
1376               DXSIZE,OK_BUTTON_YSIZE,
1377               DOOR_GFX_PAGEX1,OK_BUTTON_YPOS);
1378   else if (ays_state & AYS_CONFIRM)
1379     XCopyArea(display,pix[PIX_DOOR],pix[PIX_DB_DOOR],gc,
1380               DOOR_GFX_PAGEX4,CONFIRM_BUTTON_GFX_YPOS,
1381               DXSIZE,CONFIRM_BUTTON_YSIZE,
1382               DOOR_GFX_PAGEX1,CONFIRM_BUTTON_YPOS);
1383
1384   OpenDoor(DOOR_OPEN_1);
1385   ClearEventQueue();
1386
1387   if (!(ays_state & AYS_ASK) && !(ays_state & AYS_CONFIRM))
1388     return(FALSE);
1389
1390   if (game_status != MAINMENU)
1391     InitAnimation();
1392
1393   button_status = MB_RELEASED;
1394
1395   while(result<0)
1396   {
1397     DoAnimation();
1398     Delay(10000);
1399
1400     if (XPending(display))
1401     {
1402       XEvent event;
1403
1404       XNextEvent(display, &event);
1405       switch(event.type)
1406       {
1407         case Expose:
1408           HandleExposeEvent((XExposeEvent *) &event);
1409           break;
1410         case UnmapNotify:
1411           SleepWhileUnmapped();
1412           break;
1413         case ButtonPress:
1414         case ButtonRelease:
1415         case MotionNotify:
1416         {
1417           int choice;
1418
1419           if (event.type == MotionNotify)
1420           {
1421             motion_status = TRUE;
1422             mx = ((XMotionEvent *) &event)->x;
1423             my = ((XMotionEvent *) &event)->y;
1424           }
1425           else
1426           {
1427             motion_status = FALSE;
1428             mx = ((XButtonEvent *) &event)->x;
1429             my = ((XButtonEvent *) &event)->y;
1430             if (event.type==ButtonPress)
1431               button_status = ((XButtonEvent *) &event)->button;
1432             else
1433               button_status = MB_RELEASED;
1434           }
1435
1436           if (ays_state & AYS_ASK)
1437             choice = CheckChooseButtons(mx,my,button_status);
1438           else
1439             choice = CheckConfirmButton(mx,my,button_status);
1440
1441           switch(choice)
1442           {
1443             case BUTTON_OK:
1444               result = TRUE;
1445               break;
1446             case BUTTON_NO:
1447               result = FALSE;
1448               break;
1449             case BUTTON_CONFIRM:
1450               result = TRUE|FALSE;
1451               break;
1452             default:
1453               break;
1454           }
1455           break;
1456         }
1457         case KeyPress:
1458           switch(XLookupKeysym((XKeyEvent *)&event,
1459                                ((XKeyEvent *)&event)->state))
1460           {
1461             case XK_Return:
1462               result = 1;
1463               break;
1464             case XK_Escape:
1465               result = 0;
1466               break;
1467           }
1468           break;
1469         case KeyRelease:
1470           key_joystick_mapping = 0;
1471           break;
1472         case FocusIn:
1473         case FocusOut:
1474           HandleFocusEvent((XFocusChangeEvent *) &event);
1475           break;
1476         case ClientMessage:
1477           HandleClientMessageEvent((XClientMessageEvent *) &event);
1478           break;
1479         default:
1480           break;
1481       }
1482     }
1483     else if (JoystickButton() == JOY_BUTTON_NEW_PRESSED)
1484     {
1485       int joy=Joystick();
1486
1487       if (joy & JOY_BUTTON_1)
1488         result = 1;
1489       else if (joy & JOY_BUTTON_2)
1490         result = 0;
1491     }
1492   }
1493
1494   if (game_status != MAINMENU)
1495     StopAnimation();
1496
1497   if (!(ays_state & AYS_STAY_OPEN))
1498   {
1499     CloseDoor(DOOR_CLOSE_1);
1500
1501     if (!(ays_state & AYS_STAY_CLOSED) && (old_door_state & DOOR_OPEN_1))
1502     {
1503       XCopyArea(display,pix[PIX_DB_DOOR],pix[PIX_DB_DOOR],gc,
1504                 DOOR_GFX_PAGEX2,DOOR_GFX_PAGEY1, DXSIZE,DYSIZE,
1505                 DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1);
1506       OpenDoor(DOOR_OPEN_1);
1507     }
1508   }
1509
1510   return(result);
1511 }
1512
1513 unsigned int OpenDoor(unsigned int door_state)
1514 {
1515   unsigned int new_door_state;
1516
1517   if (door_state & DOOR_COPY_BACK)
1518   {
1519     XCopyArea(display,pix[PIX_DB_DOOR],pix[PIX_DB_DOOR],gc,
1520               DOOR_GFX_PAGEX2,DOOR_GFX_PAGEY1, DXSIZE,DYSIZE+VYSIZE,
1521               DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1);
1522     door_state &= ~DOOR_COPY_BACK;
1523   }
1524
1525   new_door_state = MoveDoor(door_state);
1526
1527 /*
1528   ClearEventQueue();
1529 */
1530
1531   return(new_door_state);
1532 }
1533
1534 unsigned int CloseDoor(unsigned int door_state)
1535 {
1536   unsigned int new_door_state;
1537
1538   XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,
1539             DX,DY, DXSIZE,DYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1);
1540   XCopyArea(display,backbuffer,pix[PIX_DB_DOOR],gc,
1541             VX,VY, VXSIZE,VYSIZE, DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2);
1542
1543   new_door_state = MoveDoor(door_state);
1544
1545 /*
1546   ClearEventQueue();
1547 */
1548
1549   return(new_door_state);
1550 }
1551
1552 unsigned int GetDoorState()
1553 {
1554   return(MoveDoor(DOOR_GET_STATE));
1555 }
1556
1557 unsigned int MoveDoor(unsigned int door_state)
1558 {
1559   static unsigned int door1 = DOOR_OPEN_1;
1560   static unsigned int door2 = DOOR_CLOSE_2;
1561   int x, start, stepsize = 4, door_anim_delay = stepsize*5000;
1562
1563 #ifdef MSDOS
1564   stepsize = 2;
1565 #endif
1566
1567   if (door_state == DOOR_GET_STATE)
1568     return(door1 | door2);
1569
1570   if (door1==DOOR_OPEN_1 && door_state & DOOR_OPEN_1)
1571     door_state &= ~DOOR_OPEN_1;
1572   else if (door1==DOOR_CLOSE_1 && door_state & DOOR_CLOSE_1)
1573     door_state &= ~DOOR_CLOSE_1;
1574   if (door2==DOOR_OPEN_2 && door_state & DOOR_OPEN_2)
1575     door_state &= ~DOOR_OPEN_2;
1576   else if (door2==DOOR_CLOSE_2 && door_state & DOOR_CLOSE_2)
1577     door_state &= ~DOOR_CLOSE_2;
1578
1579   if (quick_doors)
1580   {
1581     stepsize = 20;
1582     door_anim_delay = 0;
1583     StopSound(SND_OEFFNEN);
1584   }
1585
1586   if (door_state & DOOR_ACTION)
1587   {
1588     if (!(door_state & DOOR_NO_DELAY))
1589       PlaySoundStereo(SND_OEFFNEN,PSND_MAX_RIGHT);
1590
1591     start = ((door_state & DOOR_NO_DELAY) ? DXSIZE : 0);
1592
1593     for(x=start;x<=DXSIZE;x+=stepsize)
1594     {
1595       if (door_state & DOOR_ACTION_1)
1596       {
1597         int i = (door_state & DOOR_OPEN_1 ? DXSIZE-x : x);
1598         int j = (DXSIZE - i)/3;
1599
1600         XCopyArea(display,pix[PIX_DB_DOOR],drawto,gc,
1601                   DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY1+i/2,
1602                   DXSIZE,DYSIZE-i/2, DX,DY);
1603
1604         XFillRectangle(display,drawto,gc,DX,DY+DYSIZE-i/2,DXSIZE,i/2);
1605
1606         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1607                        DX-i,(DY+j)-DOOR_GFX_PAGEY1);
1608         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1609                   DXSIZE,DOOR_GFX_PAGEY1, i,77, DX+DXSIZE-i,DY+j);
1610         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1611                   DXSIZE,DOOR_GFX_PAGEY1+140, i,63, DX+DXSIZE-i,DY+140+j);
1612         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1613                        DX-DXSIZE+i,DY-(DOOR_GFX_PAGEY1+j));
1614         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1615                   DXSIZE-i,DOOR_GFX_PAGEY1+j, i,77-j, DX,DY);
1616         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1617                   DXSIZE-i,DOOR_GFX_PAGEY1+140, i,63, DX,DY+140-j);
1618
1619         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1620                   DXSIZE-i,DOOR_GFX_PAGEY1+77, i,63,
1621                   DX,DY+77-j);
1622         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1623                   DXSIZE-i,DOOR_GFX_PAGEY1+203, i,77,
1624                   DX,DY+203-j);
1625         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1626                        DX-i,(DY+j)-DOOR_GFX_PAGEY1);
1627         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1628                   DXSIZE,DOOR_GFX_PAGEY1+77, i,63,
1629                   DX+DXSIZE-i,DY+77+j);
1630         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1631                   DXSIZE,DOOR_GFX_PAGEY1+203, i,77-j,
1632                   DX+DXSIZE-i,DY+203+j);
1633
1634         redraw_mask |= REDRAW_DOOR_1;
1635       }
1636
1637       if (door_state & DOOR_ACTION_2)
1638       {
1639         int i = (door_state & DOOR_OPEN_2 ? VXSIZE-x : x);
1640         int j = (VXSIZE - i)/3;
1641
1642         XCopyArea(display,pix[PIX_DB_DOOR],drawto,gc,
1643                   DOOR_GFX_PAGEX1,DOOR_GFX_PAGEY2+i/2,
1644                   VXSIZE,VYSIZE-i/2, VX,VY);
1645
1646         XFillRectangle(display,drawto,gc,VX,VY+VYSIZE-i/2,VXSIZE,i/2);
1647
1648         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1649                        VX-i,(VY+j)-DOOR_GFX_PAGEY2);
1650         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1651                   VXSIZE,DOOR_GFX_PAGEY2, i,VYSIZE/2, VX+VXSIZE-i,VY+j);
1652         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1653                        VX-VXSIZE+i,VY-(DOOR_GFX_PAGEY2+j));
1654         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1655                   VXSIZE-i,DOOR_GFX_PAGEY2+j, i,VYSIZE/2-j, VX,VY);
1656
1657         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1658                   VXSIZE-i,DOOR_GFX_PAGEY2+VYSIZE/2, i,VYSIZE/2,
1659                   VX,VY+VYSIZE/2-j);
1660         XSetClipOrigin(display,clip_gc[PIX_DOOR],
1661                        VX-i,(VY+j)-DOOR_GFX_PAGEY2);
1662         XCopyArea(display,pix[PIX_DOOR],drawto,clip_gc[PIX_DOOR],
1663                   VXSIZE,DOOR_GFX_PAGEY2+VYSIZE/2, i,VYSIZE/2-j,
1664                   VX+VXSIZE-i,VY+VYSIZE/2+j);
1665
1666         redraw_mask |= REDRAW_DOOR_2;
1667       }
1668
1669       BackToFront();
1670 #ifndef MSDOS
1671       Delay(door_anim_delay);
1672 #endif
1673
1674       if (game_status==MAINMENU)
1675         DoAnimation();
1676     }
1677   }
1678
1679   if (door_state & DOOR_ACTION_1)
1680     door1 = door_state & DOOR_ACTION_1;
1681   if (door_state & DOOR_ACTION_2)
1682     door2 = door_state & DOOR_ACTION_2;
1683
1684   return(door1 | door2);
1685 }
1686
1687 int ReadPixel(Drawable d, int x, int y)
1688 {
1689   static XImage *pixelimage;
1690
1691   pixelimage = XGetImage(display, d, x,y, 1,1, AllPlanes, ZPixmap);
1692   return(XGetPixel(pixelimage,0,0));
1693 }
1694
1695 int el2gfx(int element)
1696 {
1697   switch(element)
1698   {
1699     case EL_LEERRAUM:           return(-1);
1700     case EL_ERDREICH:           return(GFX_ERDREICH);
1701     case EL_MAUERWERK:          return(GFX_MAUERWERK);
1702     case EL_FELSBODEN:          return(GFX_FELSBODEN);
1703     case EL_FELSBROCKEN:        return(GFX_FELSBROCKEN);
1704     case EL_SCHLUESSEL:         return(GFX_SCHLUESSEL);
1705     case EL_EDELSTEIN:          return(GFX_EDELSTEIN);
1706     case EL_AUSGANG_ZU:         return(GFX_AUSGANG_ZU);
1707     case EL_AUSGANG_ACT:        return(GFX_AUSGANG_ACT);
1708     case EL_AUSGANG_AUF:        return(GFX_AUSGANG_AUF);
1709     case EL_SPIELFIGUR:         return(GFX_SPIELFIGUR);
1710     case EL_SPIELER1:           return(GFX_SPIELER1);
1711     case EL_SPIELER2:           return(GFX_SPIELER2);
1712     case EL_SPIELER3:           return(GFX_SPIELER3);
1713     case EL_SPIELER4:           return(GFX_SPIELER4);
1714     case EL_KAEFER:             return(GFX_KAEFER);
1715     case EL_KAEFER_R:           return(GFX_KAEFER_R);
1716     case EL_KAEFER_O:           return(GFX_KAEFER_O);
1717     case EL_KAEFER_L:           return(GFX_KAEFER_L);
1718     case EL_KAEFER_U:           return(GFX_KAEFER_U);
1719     case EL_FLIEGER:            return(GFX_FLIEGER);
1720     case EL_FLIEGER_R:          return(GFX_FLIEGER_R);
1721     case EL_FLIEGER_O:          return(GFX_FLIEGER_O);
1722     case EL_FLIEGER_L:          return(GFX_FLIEGER_L);
1723     case EL_FLIEGER_U:          return(GFX_FLIEGER_U);
1724     case EL_BUTTERFLY:          return(GFX_BUTTERFLY);
1725     case EL_BUTTERFLY_R:        return(GFX_BUTTERFLY_R);
1726     case EL_BUTTERFLY_O:        return(GFX_BUTTERFLY_O);
1727     case EL_BUTTERFLY_L:        return(GFX_BUTTERFLY_L);
1728     case EL_BUTTERFLY_U:        return(GFX_BUTTERFLY_U);
1729     case EL_FIREFLY:            return(GFX_FIREFLY);
1730     case EL_FIREFLY_R:          return(GFX_FIREFLY_R);
1731     case EL_FIREFLY_O:          return(GFX_FIREFLY_O);
1732     case EL_FIREFLY_L:          return(GFX_FIREFLY_L);
1733     case EL_FIREFLY_U:          return(GFX_FIREFLY_U);
1734     case EL_MAMPFER:            return(GFX_MAMPFER);
1735     case EL_ROBOT:              return(GFX_ROBOT);
1736     case EL_BETON:              return(GFX_BETON);
1737     case EL_DIAMANT:            return(GFX_DIAMANT);
1738     case EL_MORAST_LEER:        return(GFX_MORAST_LEER);
1739     case EL_MORAST_VOLL:        return(GFX_MORAST_VOLL);
1740     case EL_TROPFEN:            return(GFX_TROPFEN);
1741     case EL_BOMBE:              return(GFX_BOMBE);
1742     case EL_SIEB_LEER:          return(GFX_SIEB_LEER);
1743     case EL_SIEB_VOLL:          return(GFX_SIEB_VOLL);
1744     case EL_SIEB_TOT:           return(GFX_SIEB_TOT);
1745     case EL_SALZSAEURE:         return(GFX_SALZSAEURE);
1746     case EL_AMOEBE_TOT:         return(GFX_AMOEBE_TOT);
1747     case EL_AMOEBE_NASS:        return(GFX_AMOEBE_NASS);
1748     case EL_AMOEBE_NORM:        return(GFX_AMOEBE_NORM);
1749     case EL_AMOEBE_VOLL:        return(GFX_AMOEBE_VOLL);
1750     case EL_AMOEBE_BD:          return(GFX_AMOEBE_BD);
1751     case EL_AMOEBA2DIAM:        return(GFX_AMOEBA2DIAM);
1752     case EL_KOKOSNUSS:          return(GFX_KOKOSNUSS);
1753     case EL_LIFE:               return(GFX_LIFE);
1754     case EL_LIFE_ASYNC:         return(GFX_LIFE_ASYNC);
1755     case EL_DYNAMIT:            return(GFX_DYNAMIT);
1756     case EL_BADEWANNE:          return(GFX_BADEWANNE);
1757     case EL_BADEWANNE1:         return(GFX_BADEWANNE1);
1758     case EL_BADEWANNE2:         return(GFX_BADEWANNE2);
1759     case EL_BADEWANNE3:         return(GFX_BADEWANNE3);
1760     case EL_BADEWANNE4:         return(GFX_BADEWANNE4);
1761     case EL_BADEWANNE5:         return(GFX_BADEWANNE5);
1762     case EL_ABLENK_AUS:         return(GFX_ABLENK_AUS);
1763     case EL_ABLENK_EIN:         return(GFX_ABLENK_EIN);
1764     case EL_SCHLUESSEL1:        return(GFX_SCHLUESSEL1);
1765     case EL_SCHLUESSEL2:        return(GFX_SCHLUESSEL2);
1766     case EL_SCHLUESSEL3:        return(GFX_SCHLUESSEL3);
1767     case EL_SCHLUESSEL4:        return(GFX_SCHLUESSEL4);
1768     case EL_PFORTE1:            return(GFX_PFORTE1);
1769     case EL_PFORTE2:            return(GFX_PFORTE2);
1770     case EL_PFORTE3:            return(GFX_PFORTE3);
1771     case EL_PFORTE4:            return(GFX_PFORTE4);
1772     case EL_PFORTE1X:           return(GFX_PFORTE1X);
1773     case EL_PFORTE2X:           return(GFX_PFORTE2X);
1774     case EL_PFORTE3X:           return(GFX_PFORTE3X);
1775     case EL_PFORTE4X:           return(GFX_PFORTE4X);
1776     case EL_DYNAMIT_AUS:        return(GFX_DYNAMIT_AUS);
1777     case EL_PACMAN:             return(GFX_PACMAN);
1778     case EL_PACMAN_R:           return(GFX_PACMAN_R);
1779     case EL_PACMAN_O:           return(GFX_PACMAN_O);
1780     case EL_PACMAN_L:           return(GFX_PACMAN_L);
1781     case EL_PACMAN_U:           return(GFX_PACMAN_U);
1782     case EL_UNSICHTBAR:         return(GFX_UNSICHTBAR);
1783     case EL_ERZ_EDEL:           return(GFX_ERZ_EDEL);
1784     case EL_ERZ_DIAM:           return(GFX_ERZ_DIAM);
1785     case EL_BIRNE_AUS:          return(GFX_BIRNE_AUS);
1786     case EL_BIRNE_EIN:          return(GFX_BIRNE_EIN);
1787     case EL_ZEIT_VOLL:          return(GFX_ZEIT_VOLL);
1788     case EL_ZEIT_LEER:          return(GFX_ZEIT_LEER);
1789     case EL_MAUER_LEBT:         return(GFX_MAUER_LEBT);
1790     case EL_EDELSTEIN_BD:       return(GFX_EDELSTEIN_BD);
1791     case EL_EDELSTEIN_GELB:     return(GFX_EDELSTEIN_GELB);
1792     case EL_EDELSTEIN_ROT:      return(GFX_EDELSTEIN_ROT);
1793     case EL_EDELSTEIN_LILA:     return(GFX_EDELSTEIN_LILA);
1794     case EL_ERZ_EDEL_BD:        return(GFX_ERZ_EDEL_BD);
1795     case EL_ERZ_EDEL_GELB:      return(GFX_ERZ_EDEL_GELB);
1796     case EL_ERZ_EDEL_ROT:       return(GFX_ERZ_EDEL_ROT);
1797     case EL_ERZ_EDEL_LILA:      return(GFX_ERZ_EDEL_LILA);
1798     case EL_MAMPFER2:           return(GFX_MAMPFER2);
1799     case EL_SIEB2_LEER:         return(GFX_SIEB2_LEER);
1800     case EL_SIEB2_VOLL:         return(GFX_SIEB2_VOLL);
1801     case EL_SIEB2_TOT:          return(GFX_SIEB2_TOT);
1802     case EL_DYNABOMB:           return(GFX_DYNABOMB);
1803     case EL_DYNABOMB_NR:        return(GFX_DYNABOMB_NR);
1804     case EL_DYNABOMB_SZ:        return(GFX_DYNABOMB_SZ);
1805     case EL_DYNABOMB_XL:        return(GFX_DYNABOMB_XL);
1806     case EL_SOKOBAN_OBJEKT:     return(GFX_SOKOBAN_OBJEKT);
1807     case EL_SOKOBAN_FELD_LEER:  return(GFX_SOKOBAN_FELD_LEER);
1808     case EL_SOKOBAN_FELD_VOLL:  return(GFX_SOKOBAN_FELD_VOLL);
1809     case EL_MAULWURF:           return(GFX_MAULWURF);
1810     case EL_PINGUIN:            return(GFX_PINGUIN);
1811     case EL_SCHWEIN:            return(GFX_SCHWEIN);
1812     case EL_DRACHE:             return(GFX_DRACHE);
1813     case EL_SONDE:              return(GFX_SONDE);
1814     case EL_PFEIL_L:            return(GFX_PFEIL_L);
1815     case EL_PFEIL_R:            return(GFX_PFEIL_R);
1816     case EL_PFEIL_O:            return(GFX_PFEIL_O);
1817     case EL_PFEIL_U:            return(GFX_PFEIL_U);
1818     default:
1819     {
1820       if (IS_CHAR(element))
1821         return(GFX_CHAR_START + (element-EL_CHAR_START));
1822       else
1823         return(-1);
1824     }
1825   }
1826 }