rnd-20030417-1-src
[rocksndiamonds.git] / src / init.c
1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back!               *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment                      *
5 *               Holger Schemel                             *
6 *               Detmolder Strasse 189                      *
7 *               33604 Bielefeld                            *
8 *               Germany                                    *
9 *               e-mail: info@artsoft.org                   *
10 *----------------------------------------------------------*
11 * init.c                                                   *
12 ***********************************************************/
13
14 #include "libgame/libgame.h"
15
16 #include "init.h"
17 #include "events.h"
18 #include "screens.h"
19 #include "editor.h"
20 #include "game.h"
21 #include "tape.h"
22 #include "tools.h"
23 #include "files.h"
24 #include "network.h"
25 #include "netserv.h"
26 #include "cartoons.h"
27
28 #include "conf_e2g.c"   /* include auto-generated data structure definitions */
29 #include "conf_esg.c"   /* include auto-generated data structure definitions */
30 #include "conf_e2s.c"   /* include auto-generated data structure definitions */
31 #include "conf_fnt.c"   /* include auto-generated data structure definitions */
32
33
34 #define CONFIG_TOKEN_FONT_INITIAL               "font.initial"
35
36
37 struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
38
39
40 static void InitTileClipmasks()
41 {
42 #if 0
43 #if defined(TARGET_X11)
44   XGCValues clip_gc_values;
45   unsigned long clip_gc_valuemask;
46
47 #if defined(TARGET_X11_NATIVE)
48
49 #if 0
50   GC copy_clipmask_gc;
51
52   static struct
53   {
54     int start;
55     int count;
56   }
57   tile_needs_clipping[] =
58   {
59     { GFX_SPIELER1_UP, 4 },
60     { GFX_SPIELER1_DOWN, 4 },
61     { GFX_SPIELER1_LEFT, 4 },
62     { GFX_SPIELER1_RIGHT, 4 },
63     { GFX_SPIELER1_PUSH_LEFT, 4 },
64     { GFX_SPIELER1_PUSH_RIGHT, 4 },
65     { GFX_SPIELER2_UP, 4 },
66     { GFX_SPIELER2_DOWN, 4 },
67     { GFX_SPIELER2_LEFT, 4 },
68     { GFX_SPIELER2_RIGHT, 4 },
69     { GFX_SPIELER2_PUSH_LEFT, 4 },
70     { GFX_SPIELER2_PUSH_RIGHT, 4 },
71     { GFX_SPIELER3_UP, 4 },
72     { GFX_SPIELER3_DOWN, 4 },
73     { GFX_SPIELER3_LEFT, 4 },
74     { GFX_SPIELER3_RIGHT, 4 },
75     { GFX_SPIELER3_PUSH_LEFT, 4 },
76     { GFX_SPIELER3_PUSH_RIGHT, 4 },
77     { GFX_SPIELER4_UP, 4 },
78     { GFX_SPIELER4_DOWN, 4 },
79     { GFX_SPIELER4_LEFT, 4 },
80     { GFX_SPIELER4_RIGHT, 4 },
81     { GFX_SPIELER4_PUSH_LEFT, 4 },
82     { GFX_SPIELER4_PUSH_RIGHT, 4 },
83     { GFX_SP_MURPHY, 1 },
84     { GFX_MURPHY_GO_LEFT, 3 },
85     { GFX_MURPHY_GO_RIGHT, 3 },
86     { GFX_MURPHY_SNAP_UP, 1 },
87     { GFX_MURPHY_SNAP_DOWN, 1 },
88     { GFX_MURPHY_SNAP_RIGHT, 1 },
89     { GFX_MURPHY_SNAP_LEFT, 1 },
90     { GFX_MURPHY_PUSH_RIGHT, 1 },
91     { GFX_MURPHY_PUSH_LEFT, 1 },
92     { GFX_GEBLUBBER, 4 },
93     { GFX_DYNAMIT, 7 },
94     { GFX_DYNABOMB, 4 },
95     { GFX_EXPLOSION, 8 },
96     { GFX_SOKOBAN_OBJEKT, 1 },
97     { GFX_FUNKELN_BLAU, 3 },
98     { GFX_FUNKELN_WEISS, 3 },
99     { GFX2_SHIELD_PASSIVE, 3 },
100     { GFX2_SHIELD_ACTIVE, 3 },
101     { -1, 0 }
102   };
103 #endif
104
105 #endif /* TARGET_X11_NATIVE */
106 #endif /* TARGET_X11 */
107
108   int i;
109
110   /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
111   for (i=0; i<NUM_TILES; i++)
112     tile_clipmask[i] = None;
113
114 #if defined(TARGET_X11)
115   /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
116      often very slow when preparing a masked XCopyArea() for big Pixmaps.
117      To prevent this, create small (tile-sized) mask Pixmaps which will then
118      be set much faster with XSetClipOrigin() and speed things up a lot. */
119
120   clip_gc_values.graphics_exposures = False;
121   clip_gc_valuemask = GCGraphicsExposures;
122   tile_clip_gc = XCreateGC(display, window->drawable,
123                            clip_gc_valuemask, &clip_gc_values);
124
125 #if 0
126   for (i=0; i<NUM_BITMAPS; i++)
127   {
128     if (pix[i]->clip_mask)
129     {
130       clip_gc_values.graphics_exposures = False;
131       clip_gc_values.clip_mask = pix[i]->clip_mask;
132       clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
133       pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
134                                          clip_gc_valuemask, &clip_gc_values);
135     }
136   }
137 #endif
138
139 #if defined(TARGET_X11_NATIVE)
140
141 #if 0
142   /* create graphic context structures needed for clipping */
143   clip_gc_values.graphics_exposures = False;
144   clip_gc_valuemask = GCGraphicsExposures;
145   copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
146                                clip_gc_valuemask, &clip_gc_values);
147
148   /* create only those clipping Pixmaps we really need */
149   for (i=0; tile_needs_clipping[i].start>=0; i++)
150   {
151     int j;
152
153     for (j=0; j<tile_needs_clipping[i].count; j++)
154     {
155       int tile = tile_needs_clipping[i].start + j;
156       int graphic = tile;
157       int src_x, src_y;
158       Bitmap *src_bitmap;
159       Pixmap src_pixmap;
160
161       getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
162       src_pixmap = src_bitmap->clip_mask;
163
164       tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
165                                           TILEX, TILEY, 1);
166
167       XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
168                 src_x, src_y, TILEX, TILEY, 0, 0);
169     }
170   }
171
172   XFreeGC(display, copy_clipmask_gc);
173 #endif
174
175 #endif /* TARGET_X11_NATIVE */
176 #endif /* TARGET_X11 */
177 #endif
178 }
179
180 void FreeTileClipmasks()
181 {
182 #if 0
183 #if defined(TARGET_X11)
184   int i;
185
186   for (i=0; i<NUM_TILES; i++)
187   {
188     if (tile_clipmask[i] != None)
189     {
190       XFreePixmap(display, tile_clipmask[i]);
191       tile_clipmask[i] = None;
192     }
193   }
194
195   if (tile_clip_gc)
196     XFreeGC(display, tile_clip_gc);
197   tile_clip_gc = None;
198
199 #if 0
200   for (i=0; i<NUM_BITMAPS; i++)
201   {
202     if (pix[i] != NULL && pix[i]->stored_clip_gc)
203     {
204       XFreeGC(display, pix[i]->stored_clip_gc);
205       pix[i]->stored_clip_gc = None;
206     }
207   }
208 #endif
209
210 #endif /* TARGET_X11 */
211 #endif
212 }
213
214 void FreeGadgets()
215 {
216   FreeLevelEditorGadgets();
217   FreeGameButtons();
218   FreeTapeButtons();
219   FreeToolButtons();
220   FreeScreenGadgets();
221 }
222
223 void InitGadgets()
224 {
225   static boolean gadgets_initialized = FALSE;
226
227   if (gadgets_initialized)
228     FreeGadgets();
229
230   CreateLevelEditorGadgets();
231   CreateGameButtons();
232   CreateTapeButtons();
233   CreateToolButtons();
234   CreateScreenGadgets();
235
236   gadgets_initialized = TRUE;
237 }
238
239 void InitElementSmallImages()
240 {
241   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
242   int num_property_mappings = getImageListPropertyMappingSize();
243   int i;
244
245   /* initialize normal images from static configuration */
246   for (i=0; element_to_graphic[i].element > -1; i++)
247     CreateImageWithSmallImages(element_to_graphic[i].graphic);
248
249   /* initialize special images from static configuration */
250   for (i=0; element_to_special_graphic[i].element > -1; i++)
251     CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
252
253   /* initialize images from dynamic configuration */
254   for (i=0; i < num_property_mappings; i++)
255     if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
256       CreateImageWithSmallImages(property_mapping[i].artwork_index);
257 }
258
259 static int getFontBitmapID(int font_nr)
260 {
261   int special = -1;
262
263   if (game_status == MAINMENU || game_status == TYPENAME)
264     special = GFX_SPECIAL_ARG_MAIN;
265   else if (game_status == CHOOSELEVEL)
266     special = GFX_SPECIAL_ARG_LEVELS;
267   else if (game_status == HALLOFFAME)
268     special = GFX_SPECIAL_ARG_SCORES;
269   else if (game_status == LEVELED)
270     special = GFX_SPECIAL_ARG_EDITOR;
271   else if (game_status == HELPSCREEN)
272     special = GFX_SPECIAL_ARG_INFO;
273   else if (game_status == SETUP)
274     special = GFX_SPECIAL_ARG_SETUP;
275   else if (game_status == PSEUDO_PREVIEW)
276     special = GFX_SPECIAL_ARG_PREVIEW;
277   else if (game_status == PLAYING || game_status == PSEUDO_DOOR)
278     special = GFX_SPECIAL_ARG_DOOR;
279
280   if (special != -1)
281     return font_info[font_nr].special_bitmap_id[special];
282   else
283     return font_nr;
284 }
285
286 void InitFontGraphicInfo()
287 {
288   static struct FontBitmapInfo *font_bitmap_info = NULL;
289   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
290   int num_property_mappings = getImageListPropertyMappingSize();
291   int num_font_bitmaps = NUM_FONTS;
292   int i, j;
293
294   if (graphic_info == NULL)             /* still at startup phase */
295   {
296     InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
297
298     return;
299   }
300
301   /* ---------- initialize font graphic definitions ---------- */
302
303   /* always start with reliable default values (normal font graphics) */
304   for (i=0; i < NUM_FONTS; i++)
305     font_info[i].graphic = FONT_INITIAL_1;
306
307   /* initialize normal font/graphic mapping from static configuration */
308   for (i=0; font_to_graphic[i].font_nr > -1; i++)
309   {
310     int font_nr = font_to_graphic[i].font_nr;
311     int special = font_to_graphic[i].special;
312     int graphic = font_to_graphic[i].graphic;
313
314     if (special != -1)
315       continue;
316
317     font_info[font_nr].graphic = graphic;
318   }
319
320   /* always start with reliable default values (special font graphics) */
321   for (i=0; i < NUM_FONTS; i++)
322   {
323     for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
324     {
325       font_info[i].special_graphic[j] = font_info[i].graphic;
326       font_info[i].special_bitmap_id[j] = i;
327     }
328   }
329
330   /* initialize special font/graphic mapping from static configuration */
331   for (i=0; font_to_graphic[i].font_nr > -1; i++)
332   {
333     int font_nr = font_to_graphic[i].font_nr;
334     int special = font_to_graphic[i].special;
335     int graphic = font_to_graphic[i].graphic;
336
337     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
338     {
339       font_info[font_nr].special_graphic[special] = graphic;
340       font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
341       num_font_bitmaps++;
342     }
343   }
344
345   /* initialize special element/graphic mapping from dynamic configuration */
346   for (i=0; i < num_property_mappings; i++)
347   {
348     int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
349     int special = property_mapping[i].ext3_index;
350     int graphic = property_mapping[i].artwork_index;
351
352     if (font_nr < 0)
353       continue;
354
355     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
356     {
357       font_info[font_nr].special_graphic[special] = graphic;
358       font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
359       num_font_bitmaps++;
360     }
361   }
362
363   /* ---------- initialize font bitmap array ---------- */
364
365   if (font_bitmap_info != NULL)
366     FreeFontInfo(font_bitmap_info);
367
368   font_bitmap_info =
369     checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
370
371   /* ---------- initialize font bitmap definitions ---------- */
372
373   for (i=0; i < NUM_FONTS; i++)
374   {
375     if (i < NUM_INITIAL_FONTS)
376     {
377       font_bitmap_info[i] = font_initial[i];
378       continue;
379     }
380
381     for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
382     {
383       int font_bitmap_id = font_info[i].special_bitmap_id[j];
384       int graphic = font_info[i].special_graphic[j];
385
386       /* set 'graphic_info' for font entries, if uninitialized (guessed) */
387       if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
388       {
389         graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
390         graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
391       }
392
393       /* copy font relevant information from graphics information */
394       font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
395       font_bitmap_info[font_bitmap_id].src_x  = graphic_info[graphic].src_x;
396       font_bitmap_info[font_bitmap_id].src_y  = graphic_info[graphic].src_y;
397       font_bitmap_info[font_bitmap_id].width  = graphic_info[graphic].width;
398       font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
399       font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
400       font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
401
402       font_bitmap_info[font_bitmap_id].num_chars =
403         graphic_info[graphic].anim_frames;
404       font_bitmap_info[font_bitmap_id].num_chars_per_line =
405         graphic_info[graphic].anim_frames_per_line;
406     }
407   }
408
409   InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
410 }
411
412 void InitElementGraphicInfo()
413 {
414   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
415   int num_property_mappings = getImageListPropertyMappingSize();
416   int i, act, dir;
417
418   /* set values to -1 to identify later as "uninitialized" values */
419   for (i=0; i<MAX_NUM_ELEMENTS; i++)
420   {
421     for (act=0; act<NUM_ACTIONS; act++)
422     {
423       element_info[i].graphic[act] = -1;
424
425       for (dir=0; dir<NUM_DIRECTIONS; dir++)
426         element_info[i].direction_graphic[act][dir] = -1;
427     }
428   }
429
430   /* initialize normal element/graphic mapping from static configuration */
431   for (i=0; element_to_graphic[i].element > -1; i++)
432   {
433     int element   = element_to_graphic[i].element;
434     int action    = element_to_graphic[i].action;
435     int direction = element_to_graphic[i].direction;
436     int graphic   = element_to_graphic[i].graphic;
437
438     if (graphic_info[graphic].bitmap == NULL)
439       continue;
440
441     if (action < 0)
442       action = ACTION_DEFAULT;
443
444     if (direction > -1)
445       element_info[element].direction_graphic[action][direction] = graphic;
446     else
447       element_info[element].graphic[action] = graphic;
448   }
449
450   /* initialize normal element/graphic mapping from dynamic configuration */
451   for (i=0; i < num_property_mappings; i++)
452   {
453     int element   = property_mapping[i].base_index;
454     int action    = property_mapping[i].ext1_index;
455     int direction = property_mapping[i].ext2_index;
456     int special   = property_mapping[i].ext3_index;
457     int graphic   = property_mapping[i].artwork_index;
458
459     if (graphic_info[graphic].bitmap == NULL)
460       continue;
461
462     if (element >= MAX_NUM_ELEMENTS || special != -1)
463       continue;
464
465     if (action < 0)
466       action = ACTION_DEFAULT;
467
468     if (direction > -1)
469       element_info[element].direction_graphic[action][direction] = graphic;
470     else
471       element_info[element].graphic[action] = graphic;
472   }
473
474   /* now set all '-1' values to element specific default values */
475   for (i=0; i<MAX_NUM_ELEMENTS; i++)
476   {
477     int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
478     int default_action_direction_graphic[NUM_DIRECTIONS];
479
480     if (default_action_graphic == -1)
481       default_action_graphic = IMG_CHAR_QUESTION;
482
483     for (dir=0; dir<NUM_DIRECTIONS; dir++)
484     {
485       default_action_direction_graphic[dir] =
486         element_info[i].direction_graphic[ACTION_DEFAULT][dir];
487
488       if (default_action_direction_graphic[dir] == -1)
489         default_action_direction_graphic[dir] = default_action_graphic;
490     }
491
492     for (act=0; act<NUM_ACTIONS; act++)
493     {
494       boolean act_empty = (act == ACTION_DIGGING ||
495                            act == ACTION_SNAPPING ||
496                            act == ACTION_COLLECTING);
497
498       for (dir=0; dir<NUM_DIRECTIONS; dir++)
499       {
500         int default_direction_graphic = element_info[i].graphic[act];
501
502         /* no graphic for current action -- use default direction graphic */
503         if (default_direction_graphic == -1)
504           default_direction_graphic =
505             (act_empty ? IMG_EMPTY : default_action_direction_graphic[dir]);
506
507         if (element_info[i].direction_graphic[act][dir] == -1)
508           element_info[i].direction_graphic[act][dir] =
509             default_direction_graphic;
510       }
511
512       /* no graphic for this specific action -- use default action graphic */
513       if (element_info[i].graphic[act] == -1)
514         element_info[i].graphic[act] =
515           (act_empty ? IMG_EMPTY : default_action_graphic);
516     }
517   }
518
519 #if 0
520 #if DEBUG
521   if (options.verbose)
522   {
523     for (i=0; i<MAX_NUM_ELEMENTS; i++)
524       if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
525           i != EL_CHAR_QUESTION)
526         Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
527               element_info[i].token_name, i);
528   }
529 #endif
530 #endif
531 }
532
533 void InitElementSpecialGraphicInfo()
534 {
535   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
536   int num_property_mappings = getImageListPropertyMappingSize();
537   int i, j;
538
539   /* always start with reliable default values */
540   for (i=0; i < MAX_NUM_ELEMENTS; i++)
541     for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
542       element_info[i].special_graphic[j] =
543         element_info[i].graphic[ACTION_DEFAULT];
544
545   /* initialize special element/graphic mapping from static configuration */
546   for (i=0; element_to_special_graphic[i].element > -1; i++)
547   {
548     int element = element_to_special_graphic[i].element;
549     int special = element_to_special_graphic[i].special;
550     int graphic = element_to_special_graphic[i].graphic;
551     boolean base_redefined = getImageListEntry(el2img(element))->redefined;
552     boolean special_redefined = getImageListEntry(graphic)->redefined;
553
554     if (base_redefined && !special_redefined)
555       continue;
556
557     element_info[element].special_graphic[special] = graphic;
558   }
559
560   /* initialize special element/graphic mapping from dynamic configuration */
561   for (i=0; i < num_property_mappings; i++)
562   {
563     int element = property_mapping[i].base_index;
564     int special = property_mapping[i].ext3_index;
565     int graphic = property_mapping[i].artwork_index;
566
567     if (element >= MAX_NUM_ELEMENTS)
568       continue;
569
570     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
571       element_info[element].special_graphic[special] = graphic;
572   }
573 }
574
575 static void set_graphic_parameters(int graphic, char **parameter_raw)
576 {
577   Bitmap *src_bitmap = getBitmapFromImageID(graphic);
578   int parameter[NUM_GFX_ARGS];
579   int anim_frames_per_row = 1, anim_frames_per_col = 1;
580   int anim_frames_per_line = 1;
581   int i;
582
583   /* get integer values from string parameters */
584   for (i=0; i < NUM_GFX_ARGS; i++)
585     parameter[i] =
586       get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
587                           image_config_suffix[i].type);
588
589   graphic_info[graphic].bitmap = src_bitmap;
590
591   /* start with reliable default values */
592   graphic_info[graphic].src_x = 0;
593   graphic_info[graphic].src_y = 0;
594   graphic_info[graphic].width = TILEX;
595   graphic_info[graphic].height = TILEY;
596   graphic_info[graphic].offset_x = 0;   /* one or both of these values ... */
597   graphic_info[graphic].offset_y = 0;   /* ... will be corrected later */
598
599   /* optional x and y tile position of animation frame sequence */
600   if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
601     graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
602   if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
603     graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
604
605   /* optional x and y pixel position of animation frame sequence */
606   if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
607     graphic_info[graphic].src_x = parameter[GFX_ARG_X];
608   if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
609     graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
610
611   /* optional width and height of each animation frame */
612   if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
613     graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
614   if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
615     graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
616
617   if (src_bitmap)
618   {
619     anim_frames_per_row = src_bitmap->width  / graphic_info[graphic].width;
620     anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
621   }
622
623   /* correct x or y offset dependant of vertical or horizontal frame order */
624   if (parameter[GFX_ARG_VERTICAL])      /* frames are ordered vertically */
625   {
626     graphic_info[graphic].offset_y =
627       (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
628        parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
629     anim_frames_per_line = anim_frames_per_col;
630   }
631   else                                  /* frames are ordered horizontally */
632   {
633     graphic_info[graphic].offset_x =
634       (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
635        parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
636     anim_frames_per_line = anim_frames_per_row;
637   }
638
639   /* optionally, the x and y offset of frames can be specified directly */
640   if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
641     graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
642   if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
643     graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
644
645   /* automatically determine correct number of frames, if not defined */
646   if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
647     graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
648   else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
649     graphic_info[graphic].anim_frames = anim_frames_per_row;
650   else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
651     graphic_info[graphic].anim_frames = anim_frames_per_col;
652   else
653     graphic_info[graphic].anim_frames = 1;
654
655   graphic_info[graphic].anim_frames_per_line =
656     (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
657      parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
658
659   graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
660   if (graphic_info[graphic].anim_delay == 0)    /* delay must be at least 1 */
661     graphic_info[graphic].anim_delay = 1;
662
663   graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
664   if (graphic_info[graphic].anim_frames == 1)
665     graphic_info[graphic].anim_mode = ANIM_NONE;
666
667   /* automatically determine correct start frame, if not defined */
668   if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
669     graphic_info[graphic].anim_start_frame = 0;
670   else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
671     graphic_info[graphic].anim_start_frame =
672       graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
673   else
674     graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
675
676   /* animation synchronized with global frame counter, not move position */
677   graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
678
679   /* this is only used for toon animations */
680   graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
681   graphic_info[graphic].step_delay  = parameter[GFX_ARG_STEP_DELAY];
682
683   /* this is only used for drawing font characters */
684   graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
685   graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
686 }
687
688 static void InitGraphicInfo()
689 {
690   int fallback_graphic = IMG_CHAR_EXCLAM;
691   struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
692   Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
693   int num_images = getImageListSize();
694   int i;
695
696 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
697   static boolean clipmasks_initialized = FALSE;
698   Pixmap src_pixmap;
699   XGCValues clip_gc_values;
700   unsigned long clip_gc_valuemask;
701   GC copy_clipmask_gc = None;
702 #endif
703
704   if (graphic_info != NULL)
705     free(graphic_info);
706
707   graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
708
709 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
710   if (clipmasks_initialized)
711   {
712     for (i=0; i<num_images; i++)
713     {
714       if (graphic_info[i].clip_mask)
715         XFreePixmap(display, graphic_info[i].clip_mask);
716       if (graphic_info[i].clip_gc)
717         XFreeGC(display, graphic_info[i].clip_gc);
718
719       graphic_info[i].clip_mask = None;
720       graphic_info[i].clip_gc = None;
721     }
722   }
723 #endif
724
725   for (i=0; i<num_images; i++)
726   {
727     struct FileInfo *image = getImageListEntry(i);
728     Bitmap *src_bitmap;
729     int src_x, src_y;
730     int first_frame, last_frame;
731
732     set_graphic_parameters(i, image->parameter);
733
734     /* now check if no animation frames are outside of the loaded image */
735
736     if (graphic_info[i].bitmap == NULL)
737       continue;         /* skip check for optional images that are undefined */
738
739     first_frame = 0;
740     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
741     if (src_x < 0 || src_y < 0 ||
742         src_x + TILEX > src_bitmap->width ||
743         src_y + TILEY > src_bitmap->height)
744     {
745       Error(ERR_RETURN_LINE, "-");
746       Error(ERR_RETURN, "warning: error found in config file:");
747       Error(ERR_RETURN, "- config file: '%s'",
748             getImageConfigFilename());
749       Error(ERR_RETURN, "- config token: '%s'",
750             getTokenFromImageID(i));
751       Error(ERR_RETURN, "- image file: '%s'",
752             src_bitmap->source_filename);
753       Error(ERR_RETURN,
754             "error: first animation frame out of bounds (%d, %d)",
755             src_x, src_y);
756       Error(ERR_RETURN, "custom graphic rejected for this element/action");
757
758       if (i == fallback_graphic)
759         Error(ERR_EXIT, "fatal error: no fallback graphic available");
760
761       Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
762       Error(ERR_RETURN_LINE, "-");
763
764       set_graphic_parameters(i, fallback_image->default_parameter);
765       graphic_info[i].bitmap = fallback_bitmap;
766     }
767
768     last_frame = graphic_info[i].anim_frames - 1;
769     getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
770     if (src_x < 0 || src_y < 0 ||
771         src_x + TILEX > src_bitmap->width ||
772         src_y + TILEY > src_bitmap->height)
773     {
774       Error(ERR_RETURN_LINE, "-");
775       Error(ERR_RETURN, "warning: error found in config file:");
776       Error(ERR_RETURN, "- config file: '%s'",
777             getImageConfigFilename());
778       Error(ERR_RETURN, "- config token: '%s'",
779             getTokenFromImageID(i));
780       Error(ERR_RETURN, "- image file: '%s'",
781             src_bitmap->source_filename);
782       Error(ERR_RETURN,
783             "error: last animation frame (%d) out of bounds (%d, %d)",
784             last_frame, src_x, src_y);
785       Error(ERR_RETURN, "custom graphic rejected for this element/action");
786
787       if (i == fallback_graphic)
788         Error(ERR_EXIT, "fatal error: no fallback graphic available");
789
790       Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
791       Error(ERR_RETURN_LINE, "-");
792
793       set_graphic_parameters(i, fallback_image->default_parameter);
794       graphic_info[i].bitmap = fallback_bitmap;
795     }
796
797 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
798     /* currently we need only a tile clip mask from the first frame */
799     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
800
801     if (copy_clipmask_gc == None)
802     {
803       clip_gc_values.graphics_exposures = False;
804       clip_gc_valuemask = GCGraphicsExposures;
805       copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
806                                    clip_gc_valuemask, &clip_gc_values);
807     }
808
809     graphic_info[i].clip_mask =
810       XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
811
812     src_pixmap = src_bitmap->clip_mask;
813     XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
814               copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
815
816     clip_gc_values.graphics_exposures = False;
817     clip_gc_values.clip_mask = graphic_info[i].clip_mask;
818     clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
819
820     graphic_info[i].clip_gc =
821       XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
822 #endif
823   }
824
825 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
826   if (copy_clipmask_gc)
827     XFreeGC(display, copy_clipmask_gc);
828
829   clipmasks_initialized = TRUE;
830 #endif
831 }
832
833 static void InitElementSoundInfo()
834 {
835   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
836   int num_property_mappings = getSoundListPropertyMappingSize();
837   int i, j, act;
838
839   /* set values to -1 to identify later as "uninitialized" values */
840   for (i=0; i < MAX_NUM_ELEMENTS; i++)
841     for (act=0; act < NUM_ACTIONS; act++)
842       element_info[i].sound[act] = -1;
843
844   /* initialize element/sound mapping from static configuration */
845   for (i=0; element_to_sound[i].element > -1; i++)
846   {
847     int element      = element_to_sound[i].element;
848     int action       = element_to_sound[i].action;
849     int sound        = element_to_sound[i].sound;
850     boolean is_class = element_to_sound[i].is_class;
851
852     if (action < 0)
853       action = ACTION_DEFAULT;
854
855     if (!is_class)
856       element_info[element].sound[action] = sound;
857     else
858       for (j=0; j < MAX_NUM_ELEMENTS; j++)
859         if (strcmp(element_info[j].class_name,
860                    element_info[element].class_name) == 0)
861           element_info[j].sound[action] = sound;
862   }
863
864   /* initialize element/sound mapping from dynamic configuration */
865   for (i=0; i < num_property_mappings; i++)
866   {
867     int element = property_mapping[i].base_index;
868     int action  = property_mapping[i].ext1_index;
869     int sound   = property_mapping[i].artwork_index;
870
871     if (element >= MAX_NUM_ELEMENTS)
872       continue;
873
874     if (action < 0)
875       action = ACTION_DEFAULT;
876
877     element_info[element].sound[action] = sound;
878   }
879
880   /* initialize element class/sound mapping from dynamic configuration */
881   for (i=0; i < num_property_mappings; i++)
882   {
883     int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
884     int action        = property_mapping[i].ext1_index;
885     int sound         = property_mapping[i].artwork_index;
886
887     if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
888       continue;
889
890     if (action < 0)
891       action = ACTION_DEFAULT;
892
893     for (j=0; j < MAX_NUM_ELEMENTS; j++)
894       if (strcmp(element_info[j].class_name,
895                  element_info[element_class].class_name) == 0)
896         element_info[j].sound[action] = sound;
897   }
898
899   /* now set all '-1' values to element specific default values */
900   for (i=0; i<MAX_NUM_ELEMENTS; i++)
901   {
902     int default_action_sound = element_info[i].sound[ACTION_DEFAULT];
903
904     for (act=0; act < NUM_ACTIONS; act++)
905     {
906       /* no sound for this specific action -- use default action sound */
907       if (element_info[i].sound[act] == -1)
908         element_info[i].sound[act] = default_action_sound;
909     }
910   }
911 }
912
913 static void set_sound_parameters(int sound, char **parameter_raw)
914 {
915   int parameter[NUM_SND_ARGS];
916   int i;
917
918   /* get integer values from string parameters */
919   for (i=0; i < NUM_SND_ARGS; i++)
920     parameter[i] =
921       get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
922                           sound_config_suffix[i].type);
923
924   /* explicit loop mode setting in configuration overrides default value */
925   if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
926     sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
927 }
928
929 static void InitSoundInfo()
930 {
931   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
932   int num_property_mappings = getSoundListPropertyMappingSize();
933   int *sound_effect_properties;
934   int num_sounds = getSoundListSize();
935   int i, j;
936
937   if (sound_info != NULL)
938     free(sound_info);
939
940   sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
941   sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
942
943   /* initialize sound effect for all elements to "no sound" */
944   for (i=0; i<MAX_NUM_ELEMENTS; i++)
945     for (j=0; j<NUM_ACTIONS; j++)
946       element_info[i].sound[j] = SND_UNDEFINED;
947
948   for (i=0; i<num_sounds; i++)
949   {
950     struct FileInfo *sound = getSoundListEntry(i);
951     int len_effect_text = strlen(sound->token);
952
953     sound_effect_properties[i] = ACTION_OTHER;
954     sound_info[i].loop = FALSE;
955
956     /* determine all loop sounds and identify certain sound classes */
957
958     for (j=0; element_action_info[j].suffix; j++)
959     {
960       int len_action_text = strlen(element_action_info[j].suffix);
961
962       if (len_action_text < len_effect_text &&
963           strcmp(&sound->token[len_effect_text - len_action_text],
964                  element_action_info[j].suffix) == 0)
965       {
966         sound_effect_properties[i] = element_action_info[j].value;
967
968         if (element_action_info[j].is_loop_sound)
969           sound_info[i].loop = TRUE;
970       }
971     }
972
973     /* associate elements and some selected sound actions */
974
975     for (j=0; j<MAX_NUM_ELEMENTS; j++)
976     {
977       if (element_info[j].class_name)
978       {
979         int len_class_text = strlen(element_info[j].class_name);
980
981         if (len_class_text + 1 < len_effect_text &&
982             strncmp(sound->token,
983                     element_info[j].class_name, len_class_text) == 0 &&
984             sound->token[len_class_text] == '.')
985         {
986           int sound_action_value = sound_effect_properties[i];
987
988           element_info[j].sound[sound_action_value] = i;
989         }
990       }
991     }
992
993     set_sound_parameters(i, sound->parameter);
994   }
995
996   free(sound_effect_properties);
997
998   /* initialize element/sound mapping from dynamic configuration */
999   for (i=0; i < num_property_mappings; i++)
1000   {
1001     int element   = property_mapping[i].base_index;
1002     int action    = property_mapping[i].ext1_index;
1003     int sound     = property_mapping[i].artwork_index;
1004
1005     if (action < 0)
1006       action = ACTION_DEFAULT;
1007
1008     element_info[element].sound[action] = sound;
1009   }
1010
1011 #if 0
1012   /* TEST ONLY */
1013   {
1014     int element = EL_CUSTOM_11;
1015     int j = 0;
1016
1017     while (element_action_info[j].suffix)
1018     {
1019       printf("element %d, sound action '%s'  == %d\n",
1020              element, element_action_info[j].suffix,
1021              element_info[element].sound[j]);
1022       j++;
1023     }
1024   }
1025
1026   PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1027 #endif
1028
1029 #if 0
1030   /* TEST ONLY */
1031   {
1032     int element = EL_SAND;
1033     int sound_action = ACTION_DIGGING;
1034     int j = 0;
1035
1036     while (element_action_info[j].suffix)
1037     {
1038       if (element_action_info[j].value == sound_action)
1039         printf("element %d, sound action '%s'  == %d\n",
1040                element, element_action_info[j].suffix,
1041                element_info[element].sound[sound_action]);
1042       j++;
1043     }
1044   }
1045 #endif
1046 }
1047
1048 static void ReinitializeGraphics()
1049 {
1050   InitGraphicInfo();                    /* graphic properties mapping */
1051   InitElementGraphicInfo();             /* element game graphic mapping */
1052   InitElementSpecialGraphicInfo();      /* element special graphic mapping */
1053
1054   InitElementSmallImages();             /* create editor and preview images */
1055   InitFontGraphicInfo();                /* initialize text drawing functions */
1056
1057   SetMainBackgroundImage(IMG_BACKGROUND);
1058   SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1059
1060   InitGadgets();
1061   InitToons();
1062 }
1063
1064 static void ReinitializeSounds()
1065 {
1066   InitSoundInfo();              /* sound properties mapping */
1067   InitElementSoundInfo();       /* element game sound mapping */
1068
1069 #if 1
1070   InitElementSoundInfo();       /* element game sound mapping */
1071 #endif
1072
1073   InitPlaySoundLevel();         /* internal game sound settings */
1074 }
1075
1076 static void ReinitializeMusic()
1077 {
1078   /* currently nothing to do */
1079 }
1080
1081 void InitElementProperties()
1082 {
1083   int i, j;
1084
1085   static int ep_amoebalive[] =
1086   {
1087     EL_AMOEBA_WET,
1088     EL_AMOEBA_DRY,
1089     EL_AMOEBA_FULL,
1090     EL_BD_AMOEBA,
1091     -1
1092   };
1093
1094   static int ep_amoeboid[] =
1095   {
1096     EL_AMOEBA_DEAD,
1097     EL_AMOEBA_WET,
1098     EL_AMOEBA_DRY,
1099     EL_AMOEBA_FULL,
1100     EL_BD_AMOEBA,
1101     -1
1102   };
1103
1104   static int ep_can_be_crumbled[] =
1105   {
1106     EL_SAND,
1107     EL_LANDMINE,
1108     EL_TRAP,
1109     EL_TRAP_ACTIVE,
1110     -1
1111   };
1112
1113   static int ep_pforte[] =
1114   {
1115     EL_GATE_1,
1116     EL_GATE_2,
1117     EL_GATE_3,
1118     EL_GATE_4,
1119     EL_GATE_1_GRAY,
1120     EL_GATE_2_GRAY,
1121     EL_GATE_3_GRAY,
1122     EL_GATE_4_GRAY,
1123     EL_EM_GATE_1,
1124     EL_EM_GATE_2,
1125     EL_EM_GATE_3,
1126     EL_EM_GATE_4,
1127     EL_EM_GATE_1_GRAY,
1128     EL_EM_GATE_2_GRAY,
1129     EL_EM_GATE_3_GRAY,
1130     EL_EM_GATE_4_GRAY,
1131     EL_SWITCHGATE_OPEN,
1132     EL_SWITCHGATE_OPENING,
1133     EL_SWITCHGATE_CLOSED,
1134     EL_SWITCHGATE_CLOSING,
1135     EL_TIMEGATE_OPEN,
1136     EL_TIMEGATE_OPENING,
1137     EL_TIMEGATE_CLOSED,
1138     EL_TIMEGATE_CLOSING,
1139     EL_TUBE_ANY,
1140     EL_TUBE_VERTICAL,
1141     EL_TUBE_HORIZONTAL,
1142     EL_TUBE_VERTICAL_LEFT,
1143     EL_TUBE_VERTICAL_RIGHT,
1144     EL_TUBE_HORIZONTAL_UP,
1145     EL_TUBE_HORIZONTAL_DOWN,
1146     EL_TUBE_LEFT_UP,
1147     EL_TUBE_LEFT_DOWN,
1148     EL_TUBE_RIGHT_UP,
1149     EL_TUBE_RIGHT_DOWN,
1150     -1
1151   };
1152
1153   static int ep_solid[] =
1154   {
1155     EL_WALL,
1156     EL_EXPANDABLE_WALL,
1157     EL_EXPANDABLE_WALL_HORIZONTAL,
1158     EL_EXPANDABLE_WALL_VERTICAL,
1159     EL_EXPANDABLE_WALL_ANY,
1160     EL_BD_WALL,
1161     EL_WALL_CRUMBLED,
1162     EL_EXIT_CLOSED,
1163     EL_EXIT_OPENING,
1164     EL_EXIT_OPEN,
1165     EL_AMOEBA_DEAD,
1166     EL_AMOEBA_WET,
1167     EL_AMOEBA_DRY,
1168     EL_AMOEBA_FULL,
1169     EL_BD_AMOEBA,
1170     EL_QUICKSAND_EMPTY,
1171     EL_QUICKSAND_FULL,
1172     EL_QUICKSAND_FILLING,
1173     EL_QUICKSAND_EMPTYING,
1174     EL_MAGIC_WALL,
1175     EL_MAGIC_WALL_ACTIVE,
1176     EL_MAGIC_WALL_EMPTYING,
1177     EL_MAGIC_WALL_FILLING,
1178     EL_MAGIC_WALL_FULL,
1179     EL_MAGIC_WALL_DEAD,
1180     EL_BD_MAGIC_WALL,
1181     EL_BD_MAGIC_WALL_ACTIVE,
1182     EL_BD_MAGIC_WALL_EMPTYING,
1183     EL_BD_MAGIC_WALL_FULL,
1184     EL_BD_MAGIC_WALL_FILLING,
1185     EL_BD_MAGIC_WALL_DEAD,
1186     EL_GAME_OF_LIFE,
1187     EL_BIOMAZE,
1188     EL_SP_CHIP_SINGLE,
1189     EL_SP_CHIP_LEFT,
1190     EL_SP_CHIP_RIGHT,
1191     EL_SP_CHIP_TOP,
1192     EL_SP_CHIP_BOTTOM,
1193     EL_SP_TERMINAL,
1194     EL_SP_TERMINAL_ACTIVE,
1195     EL_SP_EXIT_CLOSED,
1196     EL_SP_EXIT_OPEN,
1197     EL_INVISIBLE_WALL,
1198     EL_INVISIBLE_WALL_ACTIVE,
1199     EL_SWITCHGATE_SWITCH_UP,
1200     EL_SWITCHGATE_SWITCH_DOWN,
1201     EL_TIMEGATE_SWITCH,
1202     EL_TIMEGATE_SWITCH_ACTIVE,
1203     EL_EMC_WALL_1,
1204     EL_EMC_WALL_2,
1205     EL_EMC_WALL_3,
1206     EL_EMC_WALL_4,
1207     EL_EMC_WALL_5,
1208     EL_EMC_WALL_6,
1209     EL_EMC_WALL_7,
1210     EL_EMC_WALL_8,
1211     EL_WALL_PEARL,
1212     EL_WALL_CRYSTAL,
1213
1214     /* the following elements are a direct copy of "indestructible" elements,
1215        except "EL_ACID", which is "indestructible", but not "solid"! */
1216 #if 0
1217     EL_ACID,
1218 #endif
1219     EL_STEELWALL,
1220     EL_ACID_POOL_TOPLEFT,
1221     EL_ACID_POOL_TOPRIGHT,
1222     EL_ACID_POOL_BOTTOMLEFT,
1223     EL_ACID_POOL_BOTTOM,
1224     EL_ACID_POOL_BOTTOMRIGHT,
1225     EL_SP_HARDWARE_GRAY,
1226     EL_SP_HARDWARE_GREEN,
1227     EL_SP_HARDWARE_BLUE,
1228     EL_SP_HARDWARE_RED,
1229     EL_SP_HARDWARE_YELLOW,
1230     EL_SP_HARDWARE_BASE_1,
1231     EL_SP_HARDWARE_BASE_2,
1232     EL_SP_HARDWARE_BASE_3,
1233     EL_SP_HARDWARE_BASE_4,
1234     EL_SP_HARDWARE_BASE_5,
1235     EL_SP_HARDWARE_BASE_6,
1236     EL_INVISIBLE_STEELWALL,
1237     EL_INVISIBLE_STEELWALL_ACTIVE,
1238     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1239     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1240     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1241     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1242     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1243     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1244     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1245     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1246     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1247     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1248     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1249     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1250     EL_LIGHT_SWITCH,
1251     EL_LIGHT_SWITCH_ACTIVE,
1252     EL_SIGN_EXCLAMATION,
1253     EL_SIGN_RADIOACTIVITY,
1254     EL_SIGN_STOP,
1255     EL_SIGN_WHEELCHAIR,
1256     EL_SIGN_PARKING,
1257     EL_SIGN_ONEWAY,
1258     EL_SIGN_HEART,
1259     EL_SIGN_TRIANGLE,
1260     EL_SIGN_ROUND,
1261     EL_SIGN_EXIT,
1262     EL_SIGN_YINYANG,
1263     EL_SIGN_OTHER,
1264     EL_STEELWALL_SLANTED,
1265     EL_EMC_STEELWALL_1,
1266     EL_EMC_STEELWALL_2,
1267     EL_EMC_STEELWALL_3,
1268     EL_EMC_STEELWALL_4,
1269     EL_CRYSTAL,
1270     EL_GATE_1,
1271     EL_GATE_2,
1272     EL_GATE_3,
1273     EL_GATE_4,
1274     EL_GATE_1_GRAY,
1275     EL_GATE_2_GRAY,
1276     EL_GATE_3_GRAY,
1277     EL_GATE_4_GRAY,
1278     EL_EM_GATE_1,
1279     EL_EM_GATE_2,
1280     EL_EM_GATE_3,
1281     EL_EM_GATE_4,
1282     EL_EM_GATE_1_GRAY,
1283     EL_EM_GATE_2_GRAY,
1284     EL_EM_GATE_3_GRAY,
1285     EL_EM_GATE_4_GRAY,
1286     EL_SWITCHGATE_OPEN,
1287     EL_SWITCHGATE_OPENING,
1288     EL_SWITCHGATE_CLOSED,
1289     EL_SWITCHGATE_CLOSING,
1290     EL_TIMEGATE_OPEN,
1291     EL_TIMEGATE_OPENING,
1292     EL_TIMEGATE_CLOSED,
1293     EL_TIMEGATE_CLOSING,
1294     EL_TUBE_ANY,
1295     EL_TUBE_VERTICAL,
1296     EL_TUBE_HORIZONTAL,
1297     EL_TUBE_VERTICAL_LEFT,
1298     EL_TUBE_VERTICAL_RIGHT,
1299     EL_TUBE_HORIZONTAL_UP,
1300     EL_TUBE_HORIZONTAL_DOWN,
1301     EL_TUBE_LEFT_UP,
1302     EL_TUBE_LEFT_DOWN,
1303     EL_TUBE_RIGHT_UP,
1304     EL_TUBE_RIGHT_DOWN,
1305     -1
1306   };
1307
1308   static int ep_indestructible[] =
1309   {
1310     EL_STEELWALL,
1311     EL_ACID,
1312     EL_ACID_POOL_TOPLEFT,
1313     EL_ACID_POOL_TOPRIGHT,
1314     EL_ACID_POOL_BOTTOMLEFT,
1315     EL_ACID_POOL_BOTTOM,
1316     EL_ACID_POOL_BOTTOMRIGHT,
1317     EL_SP_HARDWARE_GRAY,
1318     EL_SP_HARDWARE_GREEN,
1319     EL_SP_HARDWARE_BLUE,
1320     EL_SP_HARDWARE_RED,
1321     EL_SP_HARDWARE_YELLOW,
1322     EL_SP_HARDWARE_BASE_1,
1323     EL_SP_HARDWARE_BASE_2,
1324     EL_SP_HARDWARE_BASE_3,
1325     EL_SP_HARDWARE_BASE_4,
1326     EL_SP_HARDWARE_BASE_5,
1327     EL_SP_HARDWARE_BASE_6,
1328     EL_INVISIBLE_STEELWALL,
1329     EL_INVISIBLE_STEELWALL_ACTIVE,
1330     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1331     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1332     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1333     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1334     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1335     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1336     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1337     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1338     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1339     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1340     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1341     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1342     EL_LIGHT_SWITCH,
1343     EL_LIGHT_SWITCH_ACTIVE,
1344     EL_SIGN_EXCLAMATION,
1345     EL_SIGN_RADIOACTIVITY,
1346     EL_SIGN_STOP,
1347     EL_SIGN_WHEELCHAIR,
1348     EL_SIGN_PARKING,
1349     EL_SIGN_ONEWAY,
1350     EL_SIGN_HEART,
1351     EL_SIGN_TRIANGLE,
1352     EL_SIGN_ROUND,
1353     EL_SIGN_EXIT,
1354     EL_SIGN_YINYANG,
1355     EL_SIGN_OTHER,
1356     EL_STEELWALL_SLANTED,
1357     EL_EMC_STEELWALL_1,
1358     EL_EMC_STEELWALL_2,
1359     EL_EMC_STEELWALL_3,
1360     EL_EMC_STEELWALL_4,
1361     EL_CRYSTAL,
1362     EL_GATE_1,
1363     EL_GATE_2,
1364     EL_GATE_3,
1365     EL_GATE_4,
1366     EL_GATE_1_GRAY,
1367     EL_GATE_2_GRAY,
1368     EL_GATE_3_GRAY,
1369     EL_GATE_4_GRAY,
1370     EL_EM_GATE_1,
1371     EL_EM_GATE_2,
1372     EL_EM_GATE_3,
1373     EL_EM_GATE_4,
1374     EL_EM_GATE_1_GRAY,
1375     EL_EM_GATE_2_GRAY,
1376     EL_EM_GATE_3_GRAY,
1377     EL_EM_GATE_4_GRAY,
1378     EL_SWITCHGATE_OPEN,
1379     EL_SWITCHGATE_OPENING,
1380     EL_SWITCHGATE_CLOSED,
1381     EL_SWITCHGATE_CLOSING,
1382     EL_TIMEGATE_OPEN,
1383     EL_TIMEGATE_OPENING,
1384     EL_TIMEGATE_CLOSED,
1385     EL_TIMEGATE_CLOSING,
1386     EL_TUBE_ANY,
1387     EL_TUBE_VERTICAL,
1388     EL_TUBE_HORIZONTAL,
1389     EL_TUBE_VERTICAL_LEFT,
1390     EL_TUBE_VERTICAL_RIGHT,
1391     EL_TUBE_HORIZONTAL_UP,
1392     EL_TUBE_HORIZONTAL_DOWN,
1393     EL_TUBE_LEFT_UP,
1394     EL_TUBE_LEFT_DOWN,
1395     EL_TUBE_RIGHT_UP,
1396     EL_TUBE_RIGHT_DOWN,
1397     -1
1398   };
1399
1400   static int ep_slippery[] =
1401   {
1402     EL_WALL_CRUMBLED,
1403     EL_BD_WALL,
1404     EL_ROCK,
1405     EL_BD_ROCK,
1406     EL_EMERALD,
1407     EL_BD_DIAMOND,
1408     EL_EMERALD_YELLOW,
1409     EL_EMERALD_RED,
1410     EL_EMERALD_PURPLE,
1411     EL_DIAMOND,
1412     EL_BOMB,
1413     EL_NUT,
1414     EL_ROBOT_WHEEL_ACTIVE,
1415     EL_ROBOT_WHEEL,
1416     EL_TIME_ORB_FULL,
1417     EL_TIME_ORB_EMPTY,
1418     EL_LAMP_ACTIVE,
1419     EL_LAMP,
1420     EL_ACID_POOL_TOPLEFT,
1421     EL_ACID_POOL_TOPRIGHT,
1422     EL_SATELLITE,
1423     EL_SP_ZONK,
1424     EL_SP_INFOTRON,
1425     EL_SP_CHIP_SINGLE,
1426     EL_SP_CHIP_LEFT,
1427     EL_SP_CHIP_RIGHT,
1428     EL_SP_CHIP_TOP,
1429     EL_SP_CHIP_BOTTOM,
1430     EL_SPEED_PILL,
1431     EL_STEELWALL_SLANTED,
1432     EL_PEARL,
1433     EL_CRYSTAL,
1434     -1
1435   };
1436
1437   static int ep_enemy[] =
1438   {
1439     EL_BUG,
1440     EL_SPACESHIP,
1441     EL_BD_BUTTERFLY,
1442     EL_BD_FIREFLY,
1443     EL_YAMYAM,
1444     EL_DARK_YAMYAM,
1445     EL_ROBOT,
1446     EL_PACMAN,
1447     EL_SP_SNIKSNAK,
1448     EL_SP_ELECTRON,
1449     -1
1450   };
1451
1452   static int ep_mauer[] =
1453   {
1454     EL_STEELWALL,
1455     EL_GATE_1,
1456     EL_GATE_2,
1457     EL_GATE_3,
1458     EL_GATE_4,
1459     EL_GATE_1_GRAY,
1460     EL_GATE_2_GRAY,
1461     EL_GATE_3_GRAY,
1462     EL_GATE_4_GRAY,
1463     EL_EM_GATE_1,
1464     EL_EM_GATE_2,
1465     EL_EM_GATE_3,
1466     EL_EM_GATE_4,
1467     EL_EM_GATE_1_GRAY,
1468     EL_EM_GATE_2_GRAY,
1469     EL_EM_GATE_3_GRAY,
1470     EL_EM_GATE_4_GRAY,
1471     EL_EXIT_CLOSED,
1472     EL_EXIT_OPENING,
1473     EL_EXIT_OPEN,
1474     EL_WALL,
1475     EL_WALL_CRUMBLED,
1476     EL_EXPANDABLE_WALL,
1477     EL_EXPANDABLE_WALL_HORIZONTAL,
1478     EL_EXPANDABLE_WALL_VERTICAL,
1479     EL_EXPANDABLE_WALL_ANY,
1480     EL_EXPANDABLE_WALL_GROWING,
1481     EL_BD_WALL,
1482     EL_SP_CHIP_SINGLE,
1483     EL_SP_CHIP_LEFT,
1484     EL_SP_CHIP_RIGHT,
1485     EL_SP_CHIP_TOP,
1486     EL_SP_CHIP_BOTTOM,
1487     EL_SP_HARDWARE_GRAY,
1488     EL_SP_HARDWARE_GREEN,
1489     EL_SP_HARDWARE_BLUE,
1490     EL_SP_HARDWARE_RED,
1491     EL_SP_HARDWARE_YELLOW,
1492     EL_SP_HARDWARE_BASE_1,
1493     EL_SP_HARDWARE_BASE_2,
1494     EL_SP_HARDWARE_BASE_3,
1495     EL_SP_HARDWARE_BASE_4,
1496     EL_SP_HARDWARE_BASE_5,
1497     EL_SP_HARDWARE_BASE_6,
1498     EL_SP_TERMINAL,
1499     EL_SP_TERMINAL_ACTIVE,
1500     EL_SP_EXIT_CLOSED,
1501     EL_SP_EXIT_OPEN,
1502     EL_INVISIBLE_STEELWALL,
1503     EL_INVISIBLE_STEELWALL_ACTIVE,
1504     EL_INVISIBLE_WALL,
1505     EL_INVISIBLE_WALL_ACTIVE,
1506     EL_STEELWALL_SLANTED,
1507     EL_EMC_STEELWALL_1,
1508     EL_EMC_STEELWALL_2,
1509     EL_EMC_STEELWALL_3,
1510     EL_EMC_STEELWALL_4,
1511     EL_EMC_WALL_1,
1512     EL_EMC_WALL_2,
1513     EL_EMC_WALL_3,
1514     EL_EMC_WALL_4,
1515     EL_EMC_WALL_5,
1516     EL_EMC_WALL_6,
1517     EL_EMC_WALL_7,
1518     EL_EMC_WALL_8,
1519     -1
1520   };
1521
1522   static int ep_can_fall[] =
1523   {
1524     EL_ROCK,
1525     EL_BD_ROCK,
1526     EL_EMERALD,
1527     EL_BD_DIAMOND,
1528     EL_EMERALD_YELLOW,
1529     EL_EMERALD_RED,
1530     EL_EMERALD_PURPLE,
1531     EL_DIAMOND,
1532     EL_BOMB,
1533     EL_NUT,
1534     EL_AMOEBA_DROP,
1535     EL_QUICKSAND_FULL,
1536     EL_MAGIC_WALL_FULL,
1537     EL_BD_MAGIC_WALL_FULL,
1538     EL_TIME_ORB_FULL,
1539     EL_TIME_ORB_EMPTY,
1540     EL_SP_ZONK,
1541     EL_SP_INFOTRON,
1542     EL_SP_DISK_ORANGE,
1543     EL_PEARL,
1544     EL_CRYSTAL,
1545     EL_SPRING,
1546     EL_DX_SUPABOMB,
1547     -1
1548   };
1549
1550   static int ep_can_smash[] =
1551   {
1552     EL_ROCK,
1553     EL_BD_ROCK,
1554     EL_EMERALD,
1555     EL_BD_DIAMOND,
1556     EL_EMERALD_YELLOW,
1557     EL_EMERALD_RED,
1558     EL_EMERALD_PURPLE,
1559     EL_DIAMOND,
1560     EL_BOMB,
1561     EL_NUT,
1562     EL_AMOEBA_DROP,
1563     EL_TIME_ORB_FULL,
1564     EL_TIME_ORB_EMPTY,
1565     EL_SP_ZONK,
1566     EL_SP_INFOTRON,
1567     EL_SP_DISK_ORANGE,
1568     EL_PEARL,
1569     EL_CRYSTAL,
1570     EL_SPRING,
1571     EL_DX_SUPABOMB,
1572     -1
1573   };
1574
1575   static int ep_can_change[] =
1576   {
1577     EL_ROCK,
1578     EL_BD_ROCK,
1579     EL_EMERALD,
1580     EL_BD_DIAMOND,
1581     EL_EMERALD_YELLOW,
1582     EL_EMERALD_RED,
1583     EL_EMERALD_PURPLE,
1584     EL_DIAMOND,
1585     -1
1586   };
1587
1588   static int ep_can_move[] =
1589   {
1590     EL_BUG,
1591     EL_SPACESHIP,
1592     EL_BD_BUTTERFLY,
1593     EL_BD_FIREFLY,
1594     EL_YAMYAM,
1595     EL_DARK_YAMYAM,
1596     EL_ROBOT,
1597     EL_PACMAN,
1598     EL_MOLE,
1599     EL_PENGUIN,
1600     EL_PIG,
1601     EL_DRAGON,
1602     EL_SATELLITE,
1603     EL_SP_SNIKSNAK,
1604     EL_SP_ELECTRON,
1605     EL_BALLOON,
1606     EL_SPRING,
1607     -1
1608   };
1609
1610   static int ep_could_move[] =
1611   {
1612     EL_BUG_RIGHT,
1613     EL_BUG_UP,
1614     EL_BUG_LEFT,
1615     EL_BUG_DOWN,
1616     EL_SPACESHIP_RIGHT,
1617     EL_SPACESHIP_UP,
1618     EL_SPACESHIP_LEFT,
1619     EL_SPACESHIP_DOWN,
1620     EL_BD_BUTTERFLY_RIGHT,
1621     EL_BD_BUTTERFLY_UP,
1622     EL_BD_BUTTERFLY_LEFT,
1623     EL_BD_BUTTERFLY_DOWN,
1624     EL_BD_FIREFLY_RIGHT,
1625     EL_BD_FIREFLY_UP,
1626     EL_BD_FIREFLY_LEFT,
1627     EL_BD_FIREFLY_DOWN,
1628     EL_PACMAN_RIGHT,
1629     EL_PACMAN_UP,
1630     EL_PACMAN_LEFT,
1631     EL_PACMAN_DOWN,
1632     -1
1633   };
1634
1635   static int ep_dont_touch[] =
1636   {
1637     EL_BUG,
1638     EL_SPACESHIP,
1639     EL_BD_BUTTERFLY,
1640     EL_BD_FIREFLY,
1641     -1
1642   };
1643
1644   static int ep_dont_go_to[] =
1645   {
1646     EL_BUG,
1647     EL_SPACESHIP,
1648     EL_BD_BUTTERFLY,
1649     EL_BD_FIREFLY,
1650     EL_YAMYAM,
1651     EL_DARK_YAMYAM,
1652     EL_ROBOT,
1653     EL_PACMAN,
1654     EL_AMOEBA_DROP,
1655     EL_ACID,
1656     EL_SP_SNIKSNAK,
1657     EL_SP_ELECTRON,
1658     EL_SP_BUGGY_BASE_ACTIVE,
1659     EL_TRAP_ACTIVE,
1660     EL_LANDMINE,
1661     -1
1662   };
1663
1664   static int ep_food_dark_yamyam[] =
1665   {
1666     EL_SAND,
1667     EL_BUG,
1668     EL_SPACESHIP,
1669     EL_BD_BUTTERFLY,
1670     EL_BD_FIREFLY,
1671     EL_YAMYAM,
1672     EL_ROBOT,
1673     EL_PACMAN,
1674     EL_AMOEBA_DROP,
1675     EL_AMOEBA_DEAD,
1676     EL_AMOEBA_WET,
1677     EL_AMOEBA_DRY,
1678     EL_AMOEBA_FULL,
1679     EL_BD_AMOEBA,
1680     EL_EMERALD,
1681     EL_BD_DIAMOND,
1682     EL_EMERALD_YELLOW,
1683     EL_EMERALD_RED,
1684     EL_EMERALD_PURPLE,
1685     EL_DIAMOND,
1686     EL_PEARL,
1687     EL_CRYSTAL,
1688     -1
1689   };
1690
1691   static int ep_bd_element[] =
1692   {
1693     EL_EMPTY,
1694     EL_SAND,
1695     EL_WALL_CRUMBLED,
1696     EL_BD_WALL,
1697     EL_ROCK,
1698     EL_BD_ROCK,
1699     EL_BD_DIAMOND,
1700     EL_BD_MAGIC_WALL,
1701     EL_EXIT_CLOSED,
1702     EL_EXIT_OPEN,
1703     EL_STEELWALL,
1704     EL_PLAYER_1,
1705     EL_BD_FIREFLY,
1706     EL_BD_FIREFLY_1,
1707     EL_BD_FIREFLY_2,
1708     EL_BD_FIREFLY_3,
1709     EL_BD_FIREFLY_4,
1710     EL_BD_BUTTERFLY,
1711     EL_BD_BUTTERFLY_1,
1712     EL_BD_BUTTERFLY_2,
1713     EL_BD_BUTTERFLY_3,
1714     EL_BD_BUTTERFLY_4,
1715     EL_BD_AMOEBA,
1716     EL_CHAR_QUESTION,
1717     -1
1718   };
1719
1720   static int ep_sb_element[] =
1721   {
1722     EL_EMPTY,
1723     EL_STEELWALL,
1724     EL_SOKOBAN_OBJECT,
1725     EL_SOKOBAN_FIELD_EMPTY,
1726     EL_SOKOBAN_FIELD_FULL,
1727     EL_PLAYER_1,
1728     EL_INVISIBLE_STEELWALL,
1729     -1
1730   };
1731
1732   static int ep_gem[] =
1733   {
1734     EL_EMERALD,
1735     EL_BD_DIAMOND,
1736     EL_EMERALD_YELLOW,
1737     EL_EMERALD_RED,
1738     EL_EMERALD_PURPLE,
1739     EL_DIAMOND,
1740     -1
1741   };
1742
1743   static int ep_inactive[] =
1744   {
1745     EL_EMPTY,
1746     EL_SAND,
1747     EL_WALL,
1748     EL_BD_WALL,
1749     EL_WALL_CRUMBLED,
1750     EL_STEELWALL,
1751     EL_AMOEBA_DEAD,
1752     EL_QUICKSAND_EMPTY,
1753     EL_STONEBLOCK,
1754     EL_ROBOT_WHEEL,
1755     EL_KEY_1,
1756     EL_KEY_2,
1757     EL_KEY_3,
1758     EL_KEY_4,
1759     EL_EM_KEY_1,
1760     EL_EM_KEY_2,
1761     EL_EM_KEY_3,
1762     EL_EM_KEY_4,
1763     EL_GATE_1,
1764     EL_GATE_2,
1765     EL_GATE_3,
1766     EL_GATE_4,
1767     EL_GATE_1_GRAY,
1768     EL_GATE_2_GRAY,
1769     EL_GATE_3_GRAY,
1770     EL_GATE_4_GRAY,
1771     EL_EM_GATE_1,
1772     EL_EM_GATE_2,
1773     EL_EM_GATE_3,
1774     EL_EM_GATE_4,
1775     EL_EM_GATE_1_GRAY,
1776     EL_EM_GATE_2_GRAY,
1777     EL_EM_GATE_3_GRAY,
1778     EL_EM_GATE_4_GRAY,
1779     EL_DYNAMITE,
1780     EL_INVISIBLE_STEELWALL,
1781     EL_INVISIBLE_WALL,
1782     EL_INVISIBLE_SAND,
1783     EL_LAMP,
1784     EL_LAMP_ACTIVE,
1785     EL_WALL_EMERALD,
1786     EL_WALL_DIAMOND,
1787     EL_WALL_BD_DIAMOND,
1788     EL_WALL_EMERALD_YELLOW,
1789     EL_DYNABOMB_INCREASE_NUMBER,
1790     EL_DYNABOMB_INCREASE_SIZE,
1791     EL_DYNABOMB_INCREASE_POWER,
1792     EL_SOKOBAN_OBJECT,
1793     EL_SOKOBAN_FIELD_EMPTY,
1794     EL_SOKOBAN_FIELD_FULL,
1795     EL_WALL_EMERALD_RED,
1796     EL_WALL_EMERALD_PURPLE,
1797     EL_ACID_POOL_TOPLEFT,
1798     EL_ACID_POOL_TOPRIGHT,
1799     EL_ACID_POOL_BOTTOMLEFT,
1800     EL_ACID_POOL_BOTTOM,
1801     EL_ACID_POOL_BOTTOMRIGHT,
1802     EL_MAGIC_WALL,
1803     EL_MAGIC_WALL_DEAD,
1804     EL_BD_MAGIC_WALL,
1805     EL_BD_MAGIC_WALL_DEAD,
1806     EL_AMOEBA_TO_DIAMOND,
1807     EL_BLOCKED,
1808     EL_SP_EMPTY,
1809     EL_SP_BASE,
1810     EL_SP_PORT_RIGHT,
1811     EL_SP_PORT_DOWN,
1812     EL_SP_PORT_LEFT,
1813     EL_SP_PORT_UP,
1814     EL_SP_GRAVITY_PORT_RIGHT,
1815     EL_SP_GRAVITY_PORT_DOWN,
1816     EL_SP_GRAVITY_PORT_LEFT,
1817     EL_SP_GRAVITY_PORT_UP,
1818     EL_SP_PORT_HORIZONTAL,
1819     EL_SP_PORT_VERTICAL,
1820     EL_SP_PORT_ANY,
1821     EL_SP_DISK_RED,
1822     EL_SP_DISK_YELLOW,
1823     EL_SP_CHIP_SINGLE,
1824     EL_SP_CHIP_LEFT,
1825     EL_SP_CHIP_RIGHT,
1826     EL_SP_CHIP_TOP,
1827     EL_SP_CHIP_BOTTOM,
1828     EL_SP_HARDWARE_GRAY,
1829     EL_SP_HARDWARE_GREEN,
1830     EL_SP_HARDWARE_BLUE,
1831     EL_SP_HARDWARE_RED,
1832     EL_SP_HARDWARE_YELLOW,
1833     EL_SP_HARDWARE_BASE_1,
1834     EL_SP_HARDWARE_BASE_2,
1835     EL_SP_HARDWARE_BASE_3,
1836     EL_SP_HARDWARE_BASE_4,
1837     EL_SP_HARDWARE_BASE_5,
1838     EL_SP_HARDWARE_BASE_6,
1839     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1840     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1841     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1842     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1843     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1844     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1845     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1846     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1847     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1848     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1849     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1850     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1851     EL_SIGN_EXCLAMATION,
1852     EL_SIGN_RADIOACTIVITY,
1853     EL_SIGN_STOP,
1854     EL_SIGN_WHEELCHAIR,
1855     EL_SIGN_PARKING,
1856     EL_SIGN_ONEWAY,
1857     EL_SIGN_HEART,
1858     EL_SIGN_TRIANGLE,
1859     EL_SIGN_ROUND,
1860     EL_SIGN_EXIT,
1861     EL_SIGN_YINYANG,
1862     EL_SIGN_OTHER,
1863     EL_STEELWALL_SLANTED,
1864     EL_EMC_STEELWALL_1,
1865     EL_EMC_STEELWALL_2,
1866     EL_EMC_STEELWALL_3,
1867     EL_EMC_STEELWALL_4,
1868     EL_EMC_WALL_1,
1869     EL_EMC_WALL_2,
1870     EL_EMC_WALL_3,
1871     EL_EMC_WALL_4,
1872     EL_EMC_WALL_5,
1873     EL_EMC_WALL_6,
1874     EL_EMC_WALL_7,
1875     EL_EMC_WALL_8,
1876     -1
1877   };
1878
1879   static int ep_explosive[] =
1880   {
1881     EL_BOMB,
1882     EL_DYNAMITE_ACTIVE,
1883     EL_DYNAMITE,
1884     EL_DYNABOMB_PLAYER_1_ACTIVE,
1885     EL_DYNABOMB_PLAYER_2_ACTIVE,
1886     EL_DYNABOMB_PLAYER_3_ACTIVE,
1887     EL_DYNABOMB_PLAYER_4_ACTIVE,
1888     EL_DYNABOMB_INCREASE_NUMBER,
1889     EL_DYNABOMB_INCREASE_SIZE,
1890     EL_DYNABOMB_INCREASE_POWER,
1891     EL_SP_DISK_RED_ACTIVE,
1892     EL_BUG,
1893     EL_MOLE,
1894     EL_PENGUIN,
1895     EL_PIG,
1896     EL_DRAGON,
1897     EL_SATELLITE,
1898     EL_SP_DISK_RED,
1899     EL_SP_DISK_ORANGE,
1900     EL_SP_DISK_YELLOW,
1901     EL_SP_SNIKSNAK,
1902     EL_SP_ELECTRON,
1903     EL_DX_SUPABOMB,
1904     -1
1905   };
1906
1907   static int ep_food_penguin[] =
1908   {
1909     EL_EMERALD,
1910     EL_BD_DIAMOND,
1911     EL_EMERALD_YELLOW,
1912     EL_EMERALD_RED,
1913     EL_EMERALD_PURPLE,
1914     EL_DIAMOND,
1915     EL_PEARL,
1916     EL_CRYSTAL,
1917     -1
1918   };
1919
1920   static int ep_pushable[] =
1921   {
1922     EL_ROCK,
1923     EL_BD_ROCK,
1924     EL_BOMB,
1925     EL_NUT,
1926     EL_TIME_ORB_EMPTY,
1927     EL_SOKOBAN_FIELD_FULL,
1928     EL_SOKOBAN_OBJECT,
1929     EL_SATELLITE,
1930     EL_SP_ZONK,
1931     EL_SP_DISK_ORANGE,
1932     EL_SP_DISK_YELLOW,
1933     EL_BALLOON,
1934     EL_SPRING,
1935     EL_DX_SUPABOMB,
1936     -1
1937   };
1938
1939   static int ep_player[] =
1940   {
1941     EL_PLAYER_1,
1942     EL_PLAYER_2,
1943     EL_PLAYER_3,
1944     EL_PLAYER_4,
1945     -1
1946   };
1947
1948   static int ep_walkable_over[] =
1949   {
1950     EL_EMPTY_SPACE,
1951     EL_SP_EMPTY_SPACE,
1952     /* !!! EL_GATE_[1-4],    EL_GATE_[1-4]_GRAY    !!! */
1953     /* !!! EL_EM_GATE_[1-4], EL_EM_GATE_[1-4]_GRAY !!! */
1954     EL_SOKOBAN_FIELD_EMPTY,
1955     EL_EXIT_OPEN,
1956     EL_SP_EXIT_OPEN,
1957     -1
1958   };
1959
1960   static int ep_walkable_through[] =
1961   {
1962     EL_TUBE_ANY,
1963     EL_TUBE_VERTICAL,
1964     EL_TUBE_HORIZONTAL,
1965     EL_TUBE_VERTICAL_LEFT,
1966     EL_TUBE_VERTICAL_RIGHT,
1967     EL_TUBE_HORIZONTAL_UP,
1968     EL_TUBE_HORIZONTAL_DOWN,
1969     EL_TUBE_LEFT_UP,
1970     EL_TUBE_LEFT_DOWN,
1971     EL_TUBE_RIGHT_UP,
1972     EL_TUBE_RIGHT_DOWN,
1973     -1
1974   };
1975
1976   static int ep_walkable_under[] =
1977   {
1978     -1
1979   };
1980
1981   static int ep_passable_over[] =
1982   {
1983     EL_EM_GATE_1,
1984     EL_EM_GATE_2,
1985     EL_EM_GATE_3,
1986     EL_EM_GATE_4,
1987     EL_EM_GATE_1_GRAY,
1988     EL_EM_GATE_2_GRAY,
1989     EL_EM_GATE_3_GRAY,
1990     EL_EM_GATE_4_GRAY,
1991     EL_SWITCHGATE_OPEN,
1992     EL_TIMEGATE_OPEN,
1993     -1
1994   };
1995
1996   static int ep_passable_through[] =
1997   {
1998     EL_SP_PORT_LEFT,
1999     EL_SP_PORT_RIGHT,
2000     EL_SP_PORT_UP,
2001     EL_SP_PORT_DOWN,
2002     EL_SP_PORT_HORIZONTAL,
2003     EL_SP_PORT_VERTICAL,
2004     EL_SP_PORT_ANY,
2005     EL_SP_GRAVITY_PORT_LEFT,
2006     EL_SP_GRAVITY_PORT_RIGHT,
2007     EL_SP_GRAVITY_PORT_UP,
2008     EL_SP_GRAVITY_PORT_DOWN,
2009     -1
2010   };
2011
2012   static int ep_passable_under[] =
2013   {
2014     -1
2015   };
2016
2017   static int ep_diggable[] =
2018   {
2019     EL_SAND,
2020     EL_SP_BASE,
2021     EL_SP_BUGGY_BASE,
2022     EL_SP_BUGGY_BASE_ACTIVATING,
2023     EL_TRAP,
2024     EL_INVISIBLE_SAND,
2025     EL_INVISIBLE_SAND_ACTIVE,
2026 #if 0
2027     EL_LANDMINE,
2028     EL_SP_BUGGY_BASE_ACTIVE,
2029 #endif
2030     -1
2031   };
2032
2033   static int ep_collectible[] =
2034   {
2035     EL_BD_DIAMOND,
2036     EL_EMERALD,
2037     EL_DIAMOND,
2038     EL_EMERALD_YELLOW,
2039     EL_EMERALD_RED,
2040     EL_EMERALD_PURPLE,
2041     EL_KEY_1,
2042     EL_KEY_2,
2043     EL_KEY_3,
2044     EL_KEY_4,
2045     EL_EM_KEY_1,
2046     EL_EM_KEY_2,
2047     EL_EM_KEY_3,
2048     EL_EM_KEY_4,
2049     EL_DYNAMITE,
2050     EL_DYNABOMB_INCREASE_NUMBER,
2051     EL_DYNABOMB_INCREASE_SIZE,
2052     EL_DYNABOMB_INCREASE_POWER,
2053     EL_SP_INFOTRON,
2054     EL_SP_DISK_RED,
2055     EL_PEARL,
2056     EL_CRYSTAL,
2057     EL_KEY_WHITE,
2058     EL_SHIELD_NORMAL,
2059     EL_SHIELD_DEADLY,
2060     EL_EXTRA_TIME,
2061     EL_ENVELOPE,
2062     EL_SPEED_PILL,
2063     -1
2064   };
2065
2066   static int ep_over_player[] =
2067   {
2068     EL_SP_PORT_LEFT,
2069     EL_SP_PORT_RIGHT,
2070     EL_SP_PORT_UP,
2071     EL_SP_PORT_DOWN,
2072     EL_SP_PORT_HORIZONTAL,
2073     EL_SP_PORT_VERTICAL,
2074     EL_SP_PORT_ANY,
2075     EL_SP_GRAVITY_PORT_LEFT,
2076     EL_SP_GRAVITY_PORT_RIGHT,
2077     EL_SP_GRAVITY_PORT_UP,
2078     EL_SP_GRAVITY_PORT_DOWN,
2079     EL_TUBE_LEFT_UP,
2080     EL_TUBE_LEFT_DOWN,
2081     EL_TUBE_RIGHT_UP,
2082     EL_TUBE_RIGHT_DOWN,
2083     EL_TUBE_HORIZONTAL,
2084     EL_TUBE_HORIZONTAL_UP,
2085     EL_TUBE_HORIZONTAL_DOWN,
2086     EL_TUBE_VERTICAL,
2087     EL_TUBE_VERTICAL_LEFT,
2088     EL_TUBE_VERTICAL_RIGHT,
2089     EL_TUBE_ANY,
2090     -1
2091   };
2092
2093   static int ep_active_bomb[] =
2094   {
2095     EL_DYNAMITE_ACTIVE,
2096     EL_DYNABOMB_PLAYER_1_ACTIVE,
2097     EL_DYNABOMB_PLAYER_2_ACTIVE,
2098     EL_DYNABOMB_PLAYER_3_ACTIVE,
2099     EL_DYNABOMB_PLAYER_4_ACTIVE,
2100     EL_SP_DISK_RED_ACTIVE,
2101     -1
2102   };
2103
2104   static int ep_belt[] =
2105   {
2106     EL_CONVEYOR_BELT_1_LEFT,
2107     EL_CONVEYOR_BELT_1_MIDDLE,
2108     EL_CONVEYOR_BELT_1_RIGHT,
2109     EL_CONVEYOR_BELT_2_LEFT,
2110     EL_CONVEYOR_BELT_2_MIDDLE,
2111     EL_CONVEYOR_BELT_2_RIGHT,
2112     EL_CONVEYOR_BELT_3_LEFT,
2113     EL_CONVEYOR_BELT_3_MIDDLE,
2114     EL_CONVEYOR_BELT_3_RIGHT,
2115     EL_CONVEYOR_BELT_4_LEFT,
2116     EL_CONVEYOR_BELT_4_MIDDLE,
2117     EL_CONVEYOR_BELT_4_RIGHT,
2118     -1
2119   };
2120
2121   static int ep_belt_active[] =
2122   {
2123     EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
2124     EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
2125     EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
2126     EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
2127     EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
2128     EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
2129     EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
2130     EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
2131     EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
2132     EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
2133     EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
2134     EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
2135     -1
2136   };
2137
2138   static int ep_belt_switch[] =
2139   {
2140     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2141     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2142     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2143     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2144     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2145     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2146     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2147     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2148     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2149     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2150     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2151     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2152     -1
2153   };
2154
2155   static int ep_sp_element[] =
2156   {
2157     EL_SP_EMPTY,
2158     EL_SP_ZONK,
2159     EL_SP_BASE,
2160     EL_SP_MURPHY,
2161     EL_SP_INFOTRON,
2162     EL_SP_CHIP_SINGLE,
2163     EL_SP_HARDWARE_GRAY,
2164     EL_SP_EXIT_CLOSED,
2165     EL_SP_EXIT_OPEN,
2166     EL_SP_DISK_ORANGE,
2167     EL_SP_PORT_RIGHT,
2168     EL_SP_PORT_DOWN,
2169     EL_SP_PORT_LEFT,
2170     EL_SP_PORT_UP,
2171     EL_SP_GRAVITY_PORT_RIGHT,
2172     EL_SP_GRAVITY_PORT_DOWN,
2173     EL_SP_GRAVITY_PORT_LEFT,
2174     EL_SP_GRAVITY_PORT_UP,
2175     EL_SP_SNIKSNAK,
2176     EL_SP_DISK_YELLOW,
2177     EL_SP_TERMINAL,
2178     EL_SP_DISK_RED,
2179     EL_SP_PORT_VERTICAL,
2180     EL_SP_PORT_HORIZONTAL,
2181     EL_SP_PORT_ANY,
2182     EL_SP_ELECTRON,
2183     EL_SP_BUGGY_BASE,
2184     EL_SP_CHIP_LEFT,
2185     EL_SP_CHIP_RIGHT,
2186     EL_SP_HARDWARE_BASE_1,
2187     EL_SP_HARDWARE_GREEN,
2188     EL_SP_HARDWARE_BLUE,
2189     EL_SP_HARDWARE_RED,
2190     EL_SP_HARDWARE_YELLOW,
2191     EL_SP_HARDWARE_BASE_2,
2192     EL_SP_HARDWARE_BASE_3,
2193     EL_SP_HARDWARE_BASE_4,
2194     EL_SP_HARDWARE_BASE_5,
2195     EL_SP_HARDWARE_BASE_6,
2196     EL_SP_CHIP_TOP,
2197     EL_SP_CHIP_BOTTOM,
2198     /* additional elements that appeared in newer Supaplex levels */
2199     EL_INVISIBLE_WALL,
2200     /* more than one murphy in a level results in an inactive clone */
2201     EL_SP_MURPHY_CLONE,
2202     -1
2203   };
2204
2205   static int ep_has_content[] =
2206   {
2207     EL_YAMYAM,
2208     EL_AMOEBA_WET,
2209     EL_AMOEBA_DRY,
2210     EL_AMOEBA_FULL,
2211     EL_BD_AMOEBA,
2212     -1
2213   };
2214
2215   static int ep_tube[] =
2216   {
2217     EL_TUBE_LEFT_UP,
2218     EL_TUBE_LEFT_DOWN,
2219     EL_TUBE_RIGHT_UP,
2220     EL_TUBE_RIGHT_DOWN,
2221     EL_TUBE_HORIZONTAL,
2222     EL_TUBE_HORIZONTAL_UP,
2223     EL_TUBE_HORIZONTAL_DOWN,
2224     EL_TUBE_VERTICAL,
2225     EL_TUBE_VERTICAL_LEFT,
2226     EL_TUBE_VERTICAL_RIGHT,
2227     EL_TUBE_ANY,
2228     -1
2229   };
2230
2231   static struct
2232   {
2233     int *elements;
2234     int property;
2235   } element_properties[] =
2236   {
2237     { ep_amoebalive,            EP_AMOEBALIVE           },
2238     { ep_amoeboid,              EP_AMOEBOID             },
2239     { ep_can_be_crumbled,       EP_CAN_BE_CRUMBLED      },
2240     { ep_pforte,                EP_PFORTE               },
2241     { ep_solid,                 EP_SOLID                },
2242     { ep_indestructible,        EP_INDESTRUCTIBLE       },
2243     { ep_slippery,              EP_SLIPPERY             },
2244     { ep_enemy,                 EP_ENEMY                },
2245     { ep_mauer,                 EP_MAUER                },
2246     { ep_can_fall,              EP_CAN_FALL             },
2247     { ep_can_smash,             EP_CAN_SMASH            },
2248     { ep_can_change,            EP_CAN_CHANGE           },
2249     { ep_can_move,              EP_CAN_MOVE             },
2250     { ep_could_move,            EP_COULD_MOVE           },
2251     { ep_dont_touch,            EP_DONT_TOUCH           },
2252     { ep_dont_go_to,            EP_DONT_GO_TO           },
2253     { ep_food_dark_yamyam,      EP_FOOD_DARK_YAMYAM     },
2254     { ep_bd_element,            EP_BD_ELEMENT           },
2255     { ep_sb_element,            EP_SB_ELEMENT           },
2256     { ep_gem,                   EP_GEM                  },
2257     { ep_inactive,              EP_INACTIVE             },
2258     { ep_explosive,             EP_EXPLOSIVE            },
2259     { ep_food_penguin,          EP_FOOD_PENGUIN         },
2260     { ep_pushable,              EP_PUSHABLE             },
2261     { ep_player,                EP_PLAYER               },
2262     { ep_walkable_over,         EP_WALKABLE_OVER        },
2263     { ep_walkable_through,      EP_WALKABLE_THROUGH     },
2264     { ep_walkable_under,        EP_WALKABLE_UNDER       },
2265     { ep_passable_over,         EP_PASSABLE_OVER        },
2266     { ep_passable_through,      EP_PASSABLE_THROUGH     },
2267     { ep_passable_under,        EP_PASSABLE_UNDER       },
2268
2269     { ep_diggable,              EP_DIGGABLE             },
2270     { ep_collectible,           EP_COLLECTIBLE          },
2271     { ep_over_player,           EP_OVER_PLAYER          },
2272     { ep_active_bomb,           EP_ACTIVE_BOMB          },
2273     { ep_belt,                  EP_BELT                 },
2274     { ep_belt_active,           EP_BELT_ACTIVE          },
2275     { ep_belt_switch,           EP_BELT_SWITCH          },
2276     { ep_sp_element,            EP_SP_ELEMENT           },
2277     { ep_has_content,           EP_HAS_CONTENT          },
2278     { ep_tube,                  EP_TUBE                 },
2279     { NULL,                     -1                      }
2280   };
2281
2282 #if 0
2283   static int active_properties[] =
2284   {
2285     EP_AMOEBALIVE,
2286     EP_AMOEBOID,
2287     EP_PFORTE,
2288     EP_SOLID,
2289     EP_ENEMY,
2290     EP_MAUER,
2291     EP_CAN_FALL,
2292     EP_CAN_SMASH,
2293     EP_CAN_CHANGE,
2294     EP_CAN_MOVE,
2295     EP_COULD_MOVE,
2296     EP_DONT_TOUCH,
2297     EP_DONT_GO_TO,
2298     EP_GEM,
2299     EP_EXPLOSIVE,
2300     EP_PUSHABLE,
2301     EP_PLAYER,
2302     EP_HAS_CONTENT,
2303     EP_DIGGABLE,
2304     EP_PASSABLE_THROUGH,
2305     EP_OVER_PLAYER,
2306     EP_ACTIVE_BOMB,
2307
2308     EP_BELT,
2309     EP_BELT_ACTIVE,
2310     EP_BELT_SWITCH,
2311     EP_WALKABLE_UNDER,
2312     EP_EM_SLIPPERY_WALL,
2313     EP_CAN_BE_CRUMBLED,
2314   };
2315 #endif
2316
2317   /* always start with reliable default values (no properties) */
2318   for (i=0; i<MAX_NUM_ELEMENTS; i++)
2319     for (j=0; j<NUM_EP_BITFIELDS; j++)
2320       Properties[i][j] = EP_BITMASK_DEFAULT;
2321
2322   /* set all predefined element properties from above arrays */
2323   for (i=0; element_properties[i].elements != NULL; i++)
2324     for (j=0; (element_properties[i].elements)[j] != -1; j++)
2325       SET_PROPERTY((element_properties[i].elements)[j],
2326                    element_properties[i].property, TRUE);
2327
2328   /* set properties of character elements */
2329   for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2330     SET_PROPERTY(i, EP_INACTIVE, TRUE);
2331
2332   /* set properties derived from other properties */
2333   for (i=0; i<MAX_NUM_ELEMENTS; i++)
2334   {
2335     if (IS_WALKABLE_OVER(i) || IS_WALKABLE_THROUGH(i) || IS_WALKABLE_UNDER(i))
2336       SET_PROPERTY(i, EP_WALKABLE, TRUE);
2337
2338     if (IS_PASSABLE_OVER(i) || IS_PASSABLE_THROUGH(i) || IS_PASSABLE_UNDER(i))
2339       SET_PROPERTY(i, EP_PASSABLE, TRUE);
2340
2341     if (IS_WALKABLE_OVER(i) || IS_PASSABLE_OVER(i))
2342       SET_PROPERTY(i, EP_PLAYER_OVER, TRUE);
2343
2344     if (IS_WALKABLE_THROUGH(i) || IS_PASSABLE_THROUGH(i))
2345       SET_PROPERTY(i, EP_PLAYER_INSIDE, TRUE);
2346
2347     if (IS_WALKABLE_UNDER(i) || IS_PASSABLE_UNDER(i))
2348       SET_PROPERTY(i, EP_PLAYER_UNDER, TRUE);
2349   }
2350
2351 #if 0
2352   /* determine inactive elements (used for engine main loop optimization) */
2353   for (i=0; i < MAX_NUM_ELEMENTS; i++)
2354   {
2355     boolean active = FALSE;
2356
2357     for (j=0; i < NUM_ELEMENT_PROPERTIES; j++)
2358     {
2359       if (HAS_PROPERTY(i, j))
2360         active = TRUE;
2361     }
2362
2363 #if 0
2364     if (!active)
2365       SET_PROPERTY(i, EP_INACTIVE, TRUE);
2366 #endif
2367   }
2368 #endif
2369
2370 #if 0
2371   for (i=0; i < MAX_NUM_ELEMENTS; i++)
2372   {
2373     boolean element_is_solid = TRUE;
2374
2375     if (IS_DIGGABLE(i) ||
2376         IS_COLLECTIBLE(i) ||
2377         CAN_FALL(i) ||
2378         CAN_MOVE(i) ||
2379         IS_PUSHABLE(i))
2380       element_is_solid = FALSE;
2381
2382     if (IS_INDESTRUCTIBLE(i))
2383       element_is_solid = TRUE;
2384
2385     if (element_is_solid != HAS_PROPERTY(i, EP_SOLID))
2386       printf("::: '%s' should %s solid\n", element_info[i].token_name,
2387              (HAS_PROPERTY(i, EP_SOLID) ? "NOT be" : "be"));
2388   }
2389 #endif
2390 }
2391
2392 static void InitGlobal()
2393 {
2394   global.autoplay_leveldir = NULL;
2395
2396   global.frames_per_second = 0;
2397   global.fps_slowdown = FALSE;
2398   global.fps_slowdown_factor = 1;
2399 }
2400
2401 void Execute_Command(char *command)
2402 {
2403   if (strcmp(command, "print graphicsinfo.conf") == 0)
2404   {
2405     int i;
2406
2407     printf("# You can configure additional/alternative image files here.\n");
2408     printf("# (The images below are default and therefore commented out.)\n");
2409     printf("\n");
2410     printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2411     printf("\n");
2412     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2413     printf("\n");
2414
2415     for (i=0; image_config[i].token != NULL; i++)
2416       printf("# %s\n",
2417              getFormattedSetupEntry(image_config[i].token,
2418                                     image_config[i].value));
2419
2420     exit(0);
2421   }
2422   else if (strcmp(command, "print soundsinfo.conf") == 0)
2423   {
2424     int i;
2425
2426     printf("# You can configure additional/alternative sound files here.\n");
2427     printf("# (The sounds below are default and therefore commented out.)\n");
2428     printf("\n");
2429     printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2430     printf("\n");
2431     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2432     printf("\n");
2433
2434     for (i=0; sound_config[i].token != NULL; i++)
2435       printf("# %s\n",
2436              getFormattedSetupEntry(sound_config[i].token,
2437                                     sound_config[i].value));
2438
2439     exit(0);
2440   }
2441   else if (strcmp(command, "print musicinfo.conf") == 0)
2442   {
2443     printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2444     printf("\n");
2445     printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2446     printf("\n");
2447     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2448
2449     exit(0);
2450   }
2451   else if (strncmp(command, "dump level ", 11) == 0)
2452   {
2453     char *filename = &command[11];
2454
2455     if (access(filename, F_OK) != 0)
2456       Error(ERR_EXIT, "cannot open file '%s'", filename);
2457
2458     LoadLevelFromFilename(filename);
2459     DumpLevel(&level);
2460
2461     exit(0);
2462   }
2463   else if (strncmp(command, "dump tape ", 10) == 0)
2464   {
2465     char *filename = &command[10];
2466
2467     if (access(filename, F_OK) != 0)
2468       Error(ERR_EXIT, "cannot open file '%s'", filename);
2469
2470     LoadTapeFromFilename(filename);
2471     DumpTape(&tape);
2472
2473     exit(0);
2474   }
2475   else if (strncmp(command, "autoplay ", 9) == 0)
2476   {
2477     char *str_copy = getStringCopy(&command[9]);
2478     char *str_ptr = strchr(str_copy, ' ');
2479
2480     global.autoplay_leveldir = str_copy;
2481     global.autoplay_level_nr = -1;
2482
2483     if (str_ptr != NULL)
2484     {
2485       *str_ptr++ = '\0';                        /* terminate leveldir string */
2486       global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2487     }
2488   }
2489   else
2490   {
2491     Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2492   }
2493 }
2494
2495 static void InitSetup()
2496 {
2497   LoadSetup();                                  /* global setup info */
2498
2499   /* set some options from setup file */
2500
2501   if (setup.options.verbose)
2502     options.verbose = TRUE;
2503 }
2504
2505 static void InitPlayerInfo()
2506 {
2507   int i;
2508
2509   /* choose default local player */
2510   local_player = &stored_player[0];
2511
2512   for (i=0; i<MAX_PLAYERS; i++)
2513     stored_player[i].connected = FALSE;
2514
2515   local_player->connected = TRUE;
2516 }
2517
2518 static void InitArtworkInfo()
2519 {
2520   LoadArtworkInfo();
2521 }
2522
2523 static char *get_element_class_token(int element)
2524 {
2525   char *element_class_name = element_info[element].class_name;
2526   char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
2527
2528   sprintf(element_class_token, "[%s]", element_class_name);
2529
2530   return element_class_token;
2531 }
2532
2533 static void InitArtworkConfig()
2534 {
2535   static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
2536   static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1];
2537   static char *action_id_suffix[NUM_ACTIONS + 1];
2538   static char *direction_id_suffix[NUM_DIRECTIONS + 1];
2539   static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
2540   static char *dummy[1] = { NULL };
2541   static char *ignore_image_tokens[] =
2542   {
2543     "name",
2544     "sort_priority",
2545     "global.num_toons",
2546     "menu.draw_xoffset",
2547     "menu.draw_yoffset",
2548     "menu.draw_xoffset.MAIN",
2549     "menu.draw_yoffset.MAIN",
2550     "door.step_offset",
2551     "door.step_delay",
2552     NULL
2553   };
2554   static char *ignore_sound_tokens[] =
2555   {
2556     "name",
2557     "sort_priority",
2558     NULL
2559   };
2560   int i;
2561
2562   for (i=0; i<MAX_NUM_ELEMENTS; i++)
2563     image_id_prefix[i] = element_info[i].token_name;
2564   for (i=0; i<NUM_FONTS; i++)
2565     image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
2566   image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
2567
2568   for (i=0; i<MAX_NUM_ELEMENTS; i++)
2569     sound_id_prefix[i] = element_info[i].token_name;
2570   for (i=0; i<MAX_NUM_ELEMENTS; i++)
2571     sound_id_prefix[MAX_NUM_ELEMENTS + i] = get_element_class_token(i);
2572   sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS] = NULL;
2573
2574   for (i=0; i<NUM_ACTIONS; i++)
2575     action_id_suffix[i] = element_action_info[i].suffix;
2576   action_id_suffix[NUM_ACTIONS] = NULL;
2577
2578   for (i=0; i<NUM_DIRECTIONS; i++)
2579     direction_id_suffix[i] = element_direction_info[i].suffix;
2580   direction_id_suffix[NUM_DIRECTIONS] = NULL;
2581
2582   for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
2583     special_id_suffix[i] = special_suffix_info[i].suffix;
2584   special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
2585
2586   InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
2587                 image_id_prefix, action_id_suffix, direction_id_suffix,
2588                 special_id_suffix, ignore_image_tokens);
2589   InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
2590                 sound_id_prefix, action_id_suffix, dummy,
2591                 special_id_suffix, ignore_sound_tokens);
2592 }
2593
2594 static void InitMixer()
2595 {
2596   OpenAudio();
2597   StartMixer();
2598 }
2599
2600 void InitGfx()
2601 {
2602   char *filename_font_initial = NULL;
2603   Bitmap *bitmap_font_initial = NULL;
2604   int i, j;
2605
2606   /* determine settings for initial font (for displaying startup messages) */
2607   for (i=0; image_config[i].token != NULL; i++)
2608   {
2609     for (j=0; j < NUM_INITIAL_FONTS; j++)
2610     {
2611       char font_token[128];
2612       int len_font_token;
2613
2614       sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
2615       len_font_token = strlen(font_token);
2616
2617       if (strcmp(image_config[i].token, font_token) == 0)
2618         filename_font_initial = image_config[i].value;
2619       else if (strlen(image_config[i].token) > len_font_token &&
2620                strncmp(image_config[i].token, font_token, len_font_token) == 0)
2621       {
2622         if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
2623           font_initial[j].src_x = atoi(image_config[i].value);
2624         else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
2625           font_initial[j].src_y = atoi(image_config[i].value);
2626         else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
2627           font_initial[j].width = atoi(image_config[i].value);
2628         else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
2629           font_initial[j].height = atoi(image_config[i].value);
2630       }
2631     }
2632   }
2633
2634   for (j=0; j < NUM_INITIAL_FONTS; j++)
2635   {
2636     font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
2637     font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
2638   }
2639
2640   if (filename_font_initial == NULL)    /* should not happen */
2641     Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
2642
2643   /* create additional image buffers for double-buffering */
2644   bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
2645   bitmap_db_door  = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
2646
2647   /* initialize screen properties */
2648   InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
2649                    REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
2650                    bitmap_db_field);
2651   InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
2652   InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
2653   InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
2654
2655   bitmap_font_initial = LoadCustomImage(filename_font_initial);
2656
2657   for (j=0; j < NUM_INITIAL_FONTS; j++)
2658     font_initial[j].bitmap = bitmap_font_initial;
2659
2660   InitFontGraphicInfo();
2661
2662   DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
2663   DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
2664
2665   DrawInitText("Loading graphics:", 120, FC_GREEN);
2666
2667   InitTileClipmasks();
2668 }
2669
2670 void InitGfxBackground()
2671 {
2672   int x, y;
2673
2674   drawto = backbuffer;
2675   fieldbuffer = bitmap_db_field;
2676   SetDrawtoField(DRAW_BACKBUFFER);
2677
2678   BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
2679              0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2680   ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
2681   ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
2682
2683   for (x=0; x<MAX_BUF_XSIZE; x++)
2684     for (y=0; y<MAX_BUF_YSIZE; y++)
2685       redraw[x][y] = 0;
2686   redraw_tiles = 0;
2687   redraw_mask = REDRAW_ALL;
2688 }
2689
2690 static void InitLevelInfo()
2691 {
2692   LoadLevelInfo();                              /* global level info */
2693   LoadLevelSetup_LastSeries();                  /* last played series info */
2694   LoadLevelSetup_SeriesInfo();                  /* last played level info */
2695 }
2696
2697 void InitLevelArtworkInfo()
2698 {
2699   LoadLevelArtworkInfo();
2700 }
2701
2702 static void InitImages()
2703 {
2704   ReloadCustomImages();
2705
2706   LoadCustomElementDescriptions();
2707   LoadSpecialMenuDesignSettings();
2708
2709   ReinitializeGraphics();
2710 }
2711
2712 static void InitSound()
2713 {
2714   InitReloadCustomSounds(artwork.snd_current->identifier);
2715   ReinitializeSounds();
2716 }
2717
2718 static void InitMusic()
2719 {
2720   InitReloadCustomMusic(artwork.mus_current->identifier);
2721   ReinitializeMusic();
2722 }
2723
2724 void InitNetworkServer()
2725 {
2726 #if defined(PLATFORM_UNIX)
2727   int nr_wanted;
2728 #endif
2729
2730   if (!options.network)
2731     return;
2732
2733 #if defined(PLATFORM_UNIX)
2734   nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
2735
2736   if (!ConnectToServer(options.server_host, options.server_port))
2737     Error(ERR_EXIT, "cannot connect to network game server");
2738
2739   SendToServer_PlayerName(setup.player_name);
2740   SendToServer_ProtocolVersion();
2741
2742   if (nr_wanted)
2743     SendToServer_NrWanted(nr_wanted);
2744 #endif
2745 }
2746
2747 void ReloadCustomArtwork()
2748 {
2749   static char *leveldir_current_identifier = NULL;
2750   static boolean last_override_level_graphics = FALSE;
2751   static boolean last_override_level_sounds = FALSE;
2752   static boolean last_override_level_music = FALSE;
2753   /* identifier for new artwork; default: artwork configured in setup */
2754   char *gfx_new_identifier = artwork.gfx_current->identifier;
2755   char *snd_new_identifier = artwork.snd_current->identifier;
2756   char *mus_new_identifier = artwork.mus_current->identifier;
2757   boolean redraw_screen = FALSE;
2758
2759   if (leveldir_current_identifier == NULL)
2760     leveldir_current_identifier = leveldir_current->identifier;
2761
2762 #if 0
2763   printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
2764          leveldir_current->graphics_set);
2765   printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
2766          leveldir_current->identifier);
2767 #endif
2768
2769 #if 0
2770   printf("graphics --> '%s' ('%s')\n",
2771          artwork.gfx_current_identifier, artwork.gfx_current->filename);
2772   printf("sounds   --> '%s' ('%s')\n",
2773          artwork.snd_current_identifier, artwork.snd_current->filename);
2774   printf("music    --> '%s' ('%s')\n",
2775          artwork.mus_current_identifier, artwork.mus_current->filename);
2776 #endif
2777
2778   /* leveldir_current may be invalid (level group, parent link) */
2779   if (!validLevelSeries(leveldir_current))
2780     return;
2781
2782   /* when a new level series was selected, check if there was a change
2783      in custom artwork stored in level series directory */
2784   if (leveldir_current_identifier != leveldir_current->identifier)
2785   {
2786     char *identifier_old = leveldir_current_identifier;
2787     char *identifier_new = leveldir_current->identifier;
2788
2789     if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
2790         getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
2791       gfx_new_identifier = identifier_new;
2792     if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
2793         getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
2794       snd_new_identifier = identifier_new;
2795     if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
2796         getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
2797       mus_new_identifier = identifier_new;
2798
2799     leveldir_current_identifier = leveldir_current->identifier;
2800   }
2801
2802   /* custom level artwork configured in level series configuration file
2803      always overrides custom level artwork stored in level series directory
2804      and (level independant) custom artwork configured in setup menue */
2805   if (leveldir_current->graphics_set != NULL)
2806     gfx_new_identifier = leveldir_current->graphics_set;
2807   if (leveldir_current->sounds_set != NULL)
2808     snd_new_identifier = leveldir_current->sounds_set;
2809   if (leveldir_current->music_set != NULL)
2810     mus_new_identifier = leveldir_current->music_set;
2811
2812   if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
2813       last_override_level_graphics != setup.override_level_graphics)
2814   {
2815 #if 0
2816     printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
2817            artwork.gfx_current_identifier,
2818            artwork.gfx_current->identifier,
2819            gfx_new_identifier);
2820 #endif
2821
2822     setLevelArtworkDir(artwork.gfx_first);
2823
2824     ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
2825
2826     InitImages();
2827
2828     FreeTileClipmasks();
2829     InitTileClipmasks();
2830
2831     artwork.gfx_current_identifier = artwork.gfx_current->identifier;
2832     last_override_level_graphics = setup.override_level_graphics;
2833
2834     redraw_screen = TRUE;
2835   }
2836
2837   if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
2838       last_override_level_sounds != setup.override_level_sounds)
2839   {
2840 #if 0
2841     printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
2842            artwork.snd_current_identifier,
2843            artwork.snd_current->identifier,
2844            snd_new_identifier);
2845 #endif
2846
2847     /* set artwork path to send it to the sound server process */
2848     setLevelArtworkDir(artwork.snd_first);
2849
2850     InitReloadCustomSounds(snd_new_identifier);
2851     ReinitializeSounds();
2852
2853     artwork.snd_current_identifier = artwork.snd_current->identifier;
2854     last_override_level_sounds = setup.override_level_sounds;
2855
2856     redraw_screen = TRUE;
2857   }
2858
2859   if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
2860       last_override_level_music != setup.override_level_music)
2861   {
2862     /* set artwork path to send it to the sound server process */
2863     setLevelArtworkDir(artwork.mus_first);
2864
2865     InitReloadCustomMusic(mus_new_identifier);
2866     ReinitializeMusic();
2867
2868     artwork.mus_current_identifier = artwork.mus_current->identifier;
2869     last_override_level_music = setup.override_level_music;
2870
2871     redraw_screen = TRUE;
2872   }
2873
2874   if (redraw_screen)
2875   {
2876     InitGfxBackground();
2877
2878     /* force redraw of (open or closed) door graphics */
2879     SetDoorState(DOOR_OPEN_ALL);
2880     CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
2881   }
2882 }
2883
2884
2885 /* ========================================================================= */
2886 /* OpenAll()                                                                 */
2887 /* ========================================================================= */
2888
2889 void OpenAll()
2890 {
2891   InitGlobal();         /* initialize some global variables */
2892
2893   if (options.execute_command)
2894     Execute_Command(options.execute_command);
2895
2896   if (options.serveronly)
2897   {
2898 #if defined(PLATFORM_UNIX)
2899     NetworkServer(options.server_port, options.serveronly);
2900 #else
2901     Error(ERR_WARN, "networking only supported in Unix version");
2902 #endif
2903     exit(0);    /* never reached */
2904   }
2905
2906   InitSetup();
2907
2908   InitPlayerInfo();
2909   InitArtworkInfo();            /* needed before loading gfx, sound & music */
2910   InitArtworkConfig();          /* needed before forking sound child process */
2911   InitMixer();
2912
2913   InitCounter();
2914
2915   InitRND(NEW_RANDOMIZE);
2916   InitSimpleRND(NEW_RANDOMIZE);
2917
2918   InitJoysticks();
2919
2920   InitVideoDisplay();
2921   InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
2922                   setup.fullscreen);
2923
2924   InitEventFilter(FilterMouseMotionEvents);
2925
2926   InitElementProperties();
2927
2928   InitGfx();
2929
2930   InitLevelInfo();
2931   InitLevelArtworkInfo();
2932
2933   InitImages();                 /* needs to know current level directory */
2934   InitSound();                  /* needs to know current level directory */
2935   InitMusic();                  /* needs to know current level directory */
2936
2937   InitGfxBackground();
2938
2939   if (global.autoplay_leveldir)
2940   {
2941     AutoPlayTape();
2942     return;
2943   }
2944
2945   game_status = MAINMENU;
2946
2947   DrawMainMenu();
2948
2949   InitNetworkServer();
2950 }
2951
2952 void CloseAllAndExit(int exit_value)
2953 {
2954   StopSounds();
2955   FreeAllSounds();
2956   FreeAllMusic();
2957   CloseAudio();         /* called after freeing sounds (needed for SDL) */
2958
2959   FreeAllImages();
2960   FreeTileClipmasks();
2961
2962   CloseVideoDisplay();
2963   ClosePlatformDependantStuff();
2964
2965   exit(exit_value);
2966 }