rnd-20040423-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 #include "config.h"
28
29 #include "conf_e2g.c"   /* include auto-generated data structure definitions */
30 #include "conf_esg.c"   /* include auto-generated data structure definitions */
31 #include "conf_e2s.c"   /* include auto-generated data structure definitions */
32 #include "conf_fnt.c"   /* include auto-generated data structure definitions */
33 #include "conf_g2s.c"   /* include auto-generated data structure definitions */
34 #include "conf_g2m.c"   /* include auto-generated data structure definitions */
35
36
37 #define CONFIG_TOKEN_FONT_INITIAL               "font.initial"
38
39
40 struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
41
42
43 static void InitTileClipmasks()
44 {
45 #if 0
46 #if defined(TARGET_X11)
47   XGCValues clip_gc_values;
48   unsigned long clip_gc_valuemask;
49
50 #if defined(TARGET_X11_NATIVE)
51
52 #if 0
53   GC copy_clipmask_gc;
54
55   static struct
56   {
57     int start;
58     int count;
59   }
60   tile_needs_clipping[] =
61   {
62     { GFX_SPIELER1_UP, 4 },
63     { GFX_SPIELER1_DOWN, 4 },
64     { GFX_SPIELER1_LEFT, 4 },
65     { GFX_SPIELER1_RIGHT, 4 },
66     { GFX_SPIELER1_PUSH_LEFT, 4 },
67     { GFX_SPIELER1_PUSH_RIGHT, 4 },
68     { GFX_SPIELER2_UP, 4 },
69     { GFX_SPIELER2_DOWN, 4 },
70     { GFX_SPIELER2_LEFT, 4 },
71     { GFX_SPIELER2_RIGHT, 4 },
72     { GFX_SPIELER2_PUSH_LEFT, 4 },
73     { GFX_SPIELER2_PUSH_RIGHT, 4 },
74     { GFX_SPIELER3_UP, 4 },
75     { GFX_SPIELER3_DOWN, 4 },
76     { GFX_SPIELER3_LEFT, 4 },
77     { GFX_SPIELER3_RIGHT, 4 },
78     { GFX_SPIELER3_PUSH_LEFT, 4 },
79     { GFX_SPIELER3_PUSH_RIGHT, 4 },
80     { GFX_SPIELER4_UP, 4 },
81     { GFX_SPIELER4_DOWN, 4 },
82     { GFX_SPIELER4_LEFT, 4 },
83     { GFX_SPIELER4_RIGHT, 4 },
84     { GFX_SPIELER4_PUSH_LEFT, 4 },
85     { GFX_SPIELER4_PUSH_RIGHT, 4 },
86     { GFX_SP_MURPHY, 1 },
87     { GFX_MURPHY_GO_LEFT, 3 },
88     { GFX_MURPHY_GO_RIGHT, 3 },
89     { GFX_MURPHY_SNAP_UP, 1 },
90     { GFX_MURPHY_SNAP_DOWN, 1 },
91     { GFX_MURPHY_SNAP_RIGHT, 1 },
92     { GFX_MURPHY_SNAP_LEFT, 1 },
93     { GFX_MURPHY_PUSH_RIGHT, 1 },
94     { GFX_MURPHY_PUSH_LEFT, 1 },
95     { GFX_GEBLUBBER, 4 },
96     { GFX_DYNAMIT, 7 },
97     { GFX_DYNABOMB, 4 },
98     { GFX_EXPLOSION, 8 },
99     { GFX_SOKOBAN_OBJEKT, 1 },
100     { GFX_FUNKELN_BLAU, 3 },
101     { GFX_FUNKELN_WEISS, 3 },
102     { GFX2_SHIELD_PASSIVE, 3 },
103     { GFX2_SHIELD_ACTIVE, 3 },
104     { -1, 0 }
105   };
106 #endif
107
108 #endif /* TARGET_X11_NATIVE */
109 #endif /* TARGET_X11 */
110
111   int i;
112
113   /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
114   for (i = 0; i < NUM_TILES; i++)
115     tile_clipmask[i] = None;
116
117 #if defined(TARGET_X11)
118   /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
119      often very slow when preparing a masked XCopyArea() for big Pixmaps.
120      To prevent this, create small (tile-sized) mask Pixmaps which will then
121      be set much faster with XSetClipOrigin() and speed things up a lot. */
122
123   clip_gc_values.graphics_exposures = False;
124   clip_gc_valuemask = GCGraphicsExposures;
125   tile_clip_gc = XCreateGC(display, window->drawable,
126                            clip_gc_valuemask, &clip_gc_values);
127
128 #if 0
129   for (i = 0; i < NUM_BITMAPS; i++)
130   {
131     if (pix[i]->clip_mask)
132     {
133       clip_gc_values.graphics_exposures = False;
134       clip_gc_values.clip_mask = pix[i]->clip_mask;
135       clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
136       pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
137                                          clip_gc_valuemask, &clip_gc_values);
138     }
139   }
140 #endif
141
142 #if defined(TARGET_X11_NATIVE)
143
144 #if 0
145   /* create graphic context structures needed for clipping */
146   clip_gc_values.graphics_exposures = False;
147   clip_gc_valuemask = GCGraphicsExposures;
148   copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
149                                clip_gc_valuemask, &clip_gc_values);
150
151   /* create only those clipping Pixmaps we really need */
152   for (i = 0; tile_needs_clipping[i].start >= 0; i++)
153   {
154     int j;
155
156     for (j = 0; j < tile_needs_clipping[i].count; j++)
157     {
158       int tile = tile_needs_clipping[i].start + j;
159       int graphic = tile;
160       int src_x, src_y;
161       Bitmap *src_bitmap;
162       Pixmap src_pixmap;
163
164       getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
165       src_pixmap = src_bitmap->clip_mask;
166
167       tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
168                                           TILEX, TILEY, 1);
169
170       XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
171                 src_x, src_y, TILEX, TILEY, 0, 0);
172     }
173   }
174
175   XFreeGC(display, copy_clipmask_gc);
176 #endif
177
178 #endif /* TARGET_X11_NATIVE */
179 #endif /* TARGET_X11 */
180 #endif
181 }
182
183 void FreeTileClipmasks()
184 {
185 #if 0
186 #if defined(TARGET_X11)
187   int i;
188
189   for (i = 0; i < NUM_TILES; i++)
190   {
191     if (tile_clipmask[i] != None)
192     {
193       XFreePixmap(display, tile_clipmask[i]);
194       tile_clipmask[i] = None;
195     }
196   }
197
198   if (tile_clip_gc)
199     XFreeGC(display, tile_clip_gc);
200   tile_clip_gc = None;
201
202 #if 0
203   for (i = 0; i < NUM_BITMAPS; i++)
204   {
205     if (pix[i] != NULL && pix[i]->stored_clip_gc)
206     {
207       XFreeGC(display, pix[i]->stored_clip_gc);
208       pix[i]->stored_clip_gc = None;
209     }
210   }
211 #endif
212
213 #endif /* TARGET_X11 */
214 #endif
215 }
216
217 void FreeGadgets()
218 {
219   FreeLevelEditorGadgets();
220   FreeGameButtons();
221   FreeTapeButtons();
222   FreeToolButtons();
223   FreeScreenGadgets();
224 }
225
226 void InitGadgets()
227 {
228   static boolean gadgets_initialized = FALSE;
229
230   if (gadgets_initialized)
231     FreeGadgets();
232
233   CreateLevelEditorGadgets();
234   CreateGameButtons();
235   CreateTapeButtons();
236   CreateToolButtons();
237   CreateScreenGadgets();
238
239   gadgets_initialized = TRUE;
240 }
241
242 void InitElementSmallImages()
243 {
244   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
245   int num_property_mappings = getImageListPropertyMappingSize();
246   int i;
247
248   /* initialize normal images from static configuration */
249   for (i = 0; element_to_graphic[i].element > -1; i++)
250     CreateImageWithSmallImages(element_to_graphic[i].graphic);
251
252   /* initialize special images from static configuration */
253   for (i = 0; element_to_special_graphic[i].element > -1; i++)
254     CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
255
256   /* initialize images from dynamic configuration */
257   for (i = 0; i < num_property_mappings; i++)
258     if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
259       CreateImageWithSmallImages(property_mapping[i].artwork_index);
260 }
261
262 static int getFontBitmapID(int font_nr)
263 {
264   int special = -1;
265
266   if (game_status >= GAME_MODE_MAIN && game_status <= GAME_MODE_PSEUDO_PREVIEW)
267     special = game_status;
268   else if (game_status == GAME_MODE_PSEUDO_TYPENAME)
269     special = GFX_SPECIAL_ARG_MAIN;
270   else if (game_status == GAME_MODE_PLAYING)
271     special = GFX_SPECIAL_ARG_DOOR;
272
273   if (special != -1)
274     return font_info[font_nr].special_bitmap_id[special];
275   else
276     return font_nr;
277 }
278
279 void InitFontGraphicInfo()
280 {
281   static struct FontBitmapInfo *font_bitmap_info = NULL;
282   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
283   int num_property_mappings = getImageListPropertyMappingSize();
284   int num_font_bitmaps = NUM_FONTS;
285   int i, j;
286
287   if (graphic_info == NULL)             /* still at startup phase */
288   {
289     InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
290
291     return;
292   }
293
294   /* ---------- initialize font graphic definitions ---------- */
295
296   /* always start with reliable default values (normal font graphics) */
297 #if 1
298   for (i = 0; i < NUM_FONTS; i++)
299     font_info[i].graphic = IMG_FONT_INITIAL_1;
300 #else
301   for (i = 0; i < NUM_FONTS; i++)
302     font_info[i].graphic = FONT_INITIAL_1;
303 #endif
304
305   /* initialize normal font/graphic mapping from static configuration */
306   for (i = 0; font_to_graphic[i].font_nr > -1; i++)
307   {
308     int font_nr = font_to_graphic[i].font_nr;
309     int special = font_to_graphic[i].special;
310     int graphic = font_to_graphic[i].graphic;
311
312     if (special != -1)
313       continue;
314
315     font_info[font_nr].graphic = graphic;
316   }
317
318   /* always start with reliable default values (special font graphics) */
319   for (i = 0; i < NUM_FONTS; i++)
320   {
321     for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
322     {
323       font_info[i].special_graphic[j] = font_info[i].graphic;
324       font_info[i].special_bitmap_id[j] = i;
325     }
326   }
327
328   /* initialize special font/graphic mapping from static configuration */
329   for (i = 0; font_to_graphic[i].font_nr > -1; i++)
330   {
331     int font_nr = font_to_graphic[i].font_nr;
332     int special = font_to_graphic[i].special;
333     int graphic = font_to_graphic[i].graphic;
334
335     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
336     {
337       font_info[font_nr].special_graphic[special] = graphic;
338       font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
339       num_font_bitmaps++;
340     }
341   }
342
343   /* initialize special element/graphic mapping from dynamic configuration */
344   for (i = 0; i < num_property_mappings; i++)
345   {
346     int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
347     int special = property_mapping[i].ext3_index;
348     int graphic = property_mapping[i].artwork_index;
349
350     if (font_nr < 0)
351       continue;
352
353     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
354     {
355       font_info[font_nr].special_graphic[special] = graphic;
356       font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
357       num_font_bitmaps++;
358     }
359   }
360
361   /* ---------- initialize font bitmap array ---------- */
362
363   if (font_bitmap_info != NULL)
364     FreeFontInfo(font_bitmap_info);
365
366   font_bitmap_info =
367     checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
368
369   /* ---------- initialize font bitmap definitions ---------- */
370
371   for (i = 0; i < NUM_FONTS; i++)
372   {
373     if (i < NUM_INITIAL_FONTS)
374     {
375       font_bitmap_info[i] = font_initial[i];
376       continue;
377     }
378
379     for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
380     {
381       int font_bitmap_id = font_info[i].special_bitmap_id[j];
382       int graphic = font_info[i].special_graphic[j];
383
384       /* set 'graphic_info' for font entries, if uninitialized (guessed) */
385       if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
386       {
387         graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
388         graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
389       }
390
391       /* copy font relevant information from graphics information */
392       font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
393       font_bitmap_info[font_bitmap_id].src_x  = graphic_info[graphic].src_x;
394       font_bitmap_info[font_bitmap_id].src_y  = graphic_info[graphic].src_y;
395       font_bitmap_info[font_bitmap_id].width  = graphic_info[graphic].width;
396       font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
397       font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
398       font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
399
400       font_bitmap_info[font_bitmap_id].num_chars =
401         graphic_info[graphic].anim_frames;
402       font_bitmap_info[font_bitmap_id].num_chars_per_line =
403         graphic_info[graphic].anim_frames_per_line;
404     }
405   }
406
407   InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
408 }
409
410 void InitElementGraphicInfo()
411 {
412   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
413   int num_property_mappings = getImageListPropertyMappingSize();
414   int i, act, dir;
415
416   if (graphic_info == NULL)             /* still at startup phase */
417     return;
418
419   /* set values to -1 to identify later as "uninitialized" values */
420   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
421   {
422     for (act = 0; act < NUM_ACTIONS; act++)
423     {
424       element_info[i].graphic[act] = -1;
425       element_info[i].crumbled[act] = -1;
426
427       for (dir = 0; dir < NUM_DIRECTIONS; dir++)
428       {
429         element_info[i].direction_graphic[act][dir] = -1;
430         element_info[i].direction_crumbled[act][dir] = -1;
431       }
432     }
433   }
434
435   /* initialize normal element/graphic mapping from static configuration */
436   for (i = 0; element_to_graphic[i].element > -1; i++)
437   {
438     int element      = element_to_graphic[i].element;
439     int action       = element_to_graphic[i].action;
440     int direction    = element_to_graphic[i].direction;
441     boolean crumbled = element_to_graphic[i].crumbled;
442     int graphic      = element_to_graphic[i].graphic;
443     int base_graphic = el2baseimg(element);
444
445     if (graphic_info[graphic].bitmap == NULL)
446       continue;
447
448     if ((action > -1 || direction > -1 || crumbled == TRUE) &&
449         base_graphic != -1)
450     {
451       boolean base_redefined = getImageListEntry(base_graphic)->redefined;
452       boolean act_dir_redefined = getImageListEntry(graphic)->redefined;
453
454       /* if the base graphic ("emerald", for example) has been redefined,
455          but not the action graphic ("emerald.falling", for example), do not
456          use an existing (in this case considered obsolete) action graphic
457          anymore, but use the automatically determined default graphic */
458       if (base_redefined && !act_dir_redefined)
459         continue;
460     }
461
462     if (action < 0)
463       action = ACTION_DEFAULT;
464
465     if (crumbled)
466     {
467       if (direction > -1)
468         element_info[element].direction_crumbled[action][direction] = graphic;
469       else
470         element_info[element].crumbled[action] = graphic;
471     }
472     else
473     {
474       if (direction > -1)
475         element_info[element].direction_graphic[action][direction] = graphic;
476       else
477         element_info[element].graphic[action] = graphic;
478     }
479   }
480
481   /* initialize normal element/graphic mapping from dynamic configuration */
482   for (i = 0; i < num_property_mappings; i++)
483   {
484     int element   = property_mapping[i].base_index;
485     int action    = property_mapping[i].ext1_index;
486     int direction = property_mapping[i].ext2_index;
487     int special   = property_mapping[i].ext3_index;
488     int graphic   = property_mapping[i].artwork_index;
489     boolean crumbled = FALSE;
490
491     if (special == GFX_SPECIAL_ARG_CRUMBLED)
492     {
493       special = -1;
494       crumbled = TRUE;
495     }
496
497     if (graphic_info[graphic].bitmap == NULL)
498       continue;
499
500     if (element >= MAX_NUM_ELEMENTS || special != -1)
501       continue;
502
503     if (action < 0)
504       action = ACTION_DEFAULT;
505
506     if (crumbled)
507     {
508       if (direction < 0)
509         for (dir = 0; dir < NUM_DIRECTIONS; dir++)
510           element_info[element].direction_crumbled[action][dir] = -1;
511
512       if (direction > -1)
513         element_info[element].direction_crumbled[action][direction] = graphic;
514       else
515         element_info[element].crumbled[action] = graphic;
516     }
517     else
518     {
519       if (direction < 0)
520         for (dir = 0; dir < NUM_DIRECTIONS; dir++)
521           element_info[element].direction_graphic[action][dir] = -1;
522
523       if (direction > -1)
524         element_info[element].direction_graphic[action][direction] = graphic;
525       else
526         element_info[element].graphic[action] = graphic;
527     }
528   }
529
530   /* now copy all graphics that are defined to be cloned from other graphics */
531   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
532   {
533     int graphic = element_info[i].graphic[ACTION_DEFAULT];
534     int crumbled_like, diggable_like;
535
536     if (graphic == -1)
537       continue;
538
539     crumbled_like = graphic_info[graphic].crumbled_like;
540     diggable_like = graphic_info[graphic].diggable_like;
541
542     if (crumbled_like != -1 && element_info[i].crumbled[ACTION_DEFAULT] == -1)
543     {
544       for (act = 0; act < NUM_ACTIONS; act++)
545         element_info[i].crumbled[act] =
546           element_info[crumbled_like].crumbled[act];
547       for (act = 0; act < NUM_ACTIONS; act++)
548         for (dir = 0; dir < NUM_DIRECTIONS; dir++)
549           element_info[i].direction_crumbled[act][dir] =
550             element_info[crumbled_like].direction_crumbled[act][dir];
551     }
552
553     if (diggable_like != -1 && element_info[i].graphic[ACTION_DIGGING] == -1)
554     {
555       element_info[i].graphic[ACTION_DIGGING] =
556         element_info[diggable_like].graphic[ACTION_DIGGING];
557       for (dir = 0; dir < NUM_DIRECTIONS; dir++)
558         element_info[i].direction_graphic[ACTION_DIGGING][dir] =
559           element_info[diggable_like].direction_graphic[ACTION_DIGGING][dir];
560     }
561   }
562
563 #if 1
564   /* now set all undefined/invalid graphics to -1 to set to default after it */
565   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
566   {
567     for (act = 0; act < NUM_ACTIONS; act++)
568     {
569       int graphic;
570
571       graphic = element_info[i].graphic[act];
572       if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
573         element_info[i].graphic[act] = -1;
574
575       graphic = element_info[i].crumbled[act];
576       if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
577         element_info[i].crumbled[act] = -1;
578
579       for (dir = 0; dir < NUM_DIRECTIONS; dir++)
580       {
581         graphic = element_info[i].direction_graphic[act][dir];
582         if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
583           element_info[i].direction_graphic[act][dir] = -1;
584
585         graphic = element_info[i].direction_crumbled[act][dir];
586         if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
587           element_info[i].direction_crumbled[act][dir] = -1;
588       }
589     }
590   }
591 #endif
592
593   /* now set all '-1' values to element specific default values */
594   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
595   {
596     int default_graphic = element_info[i].graphic[ACTION_DEFAULT];
597     int default_crumbled = element_info[i].crumbled[ACTION_DEFAULT];
598     int default_direction_graphic[NUM_DIRECTIONS];
599     int default_direction_crumbled[NUM_DIRECTIONS];
600
601     if (default_graphic == -1)
602       default_graphic = IMG_UNKNOWN;
603     if (default_crumbled == -1)
604       default_crumbled = IMG_EMPTY;
605
606     for (dir = 0; dir < NUM_DIRECTIONS; dir++)
607     {
608       default_direction_graphic[dir] =
609         element_info[i].direction_graphic[ACTION_DEFAULT][dir];
610       default_direction_crumbled[dir] =
611         element_info[i].direction_crumbled[ACTION_DEFAULT][dir];
612
613       if (default_direction_graphic[dir] == -1)
614         default_direction_graphic[dir] = default_graphic;
615       if (default_direction_crumbled[dir] == -1)
616         default_direction_crumbled[dir] = default_crumbled;
617     }
618
619     for (act = 0; act < NUM_ACTIONS; act++)
620     {
621       boolean act_remove = ((IS_DIGGABLE(i)    && act == ACTION_DIGGING)  ||
622                             (IS_SNAPPABLE(i)   && act == ACTION_SNAPPING) ||
623                             (IS_COLLECTIBLE(i) && act == ACTION_COLLECTING));
624       boolean act_turning = (act == ACTION_TURNING_FROM_LEFT ||
625                              act == ACTION_TURNING_FROM_RIGHT ||
626                              act == ACTION_TURNING_FROM_UP ||
627                              act == ACTION_TURNING_FROM_DOWN);
628
629       /* generic default action graphic (defined by "[default]" directive) */
630       int default_action_graphic = element_info[EL_DEFAULT].graphic[act];
631       int default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
632
633       /* look for special default action graphic (classic game specific) */
634       if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].graphic[act] != -1)
635         default_action_graphic = element_info[EL_BD_DEFAULT].graphic[act];
636       if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].graphic[act] != -1)
637         default_action_graphic = element_info[EL_SP_DEFAULT].graphic[act];
638       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].graphic[act] != -1)
639         default_action_graphic = element_info[EL_SB_DEFAULT].graphic[act];
640
641       if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].crumbled[act] != -1)
642         default_action_crumbled = element_info[EL_BD_DEFAULT].crumbled[act];
643       if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].crumbled[act] != -1)
644         default_action_crumbled = element_info[EL_SP_DEFAULT].crumbled[act];
645       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].crumbled[act] != -1)
646         default_action_crumbled = element_info[EL_SB_DEFAULT].crumbled[act];
647
648 #if 1
649       /* !!! make this better !!! */
650       if (i == EL_EMPTY_SPACE)
651       {
652         default_action_graphic = element_info[EL_DEFAULT].graphic[act];
653         default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
654       }
655 #endif
656
657       if (default_action_graphic == -1)
658         default_action_graphic = default_graphic;
659       if (default_action_crumbled == -1)
660         default_action_crumbled = default_crumbled;
661
662       for (dir = 0; dir < NUM_DIRECTIONS; dir++)
663       {
664         int default_action_direction_graphic = element_info[i].graphic[act];
665         int default_action_direction_crumbled = element_info[i].crumbled[act];
666
667         /* no graphic for current action -- use default direction graphic */
668         if (default_action_direction_graphic == -1)
669           default_action_direction_graphic =
670             (act_remove ? IMG_EMPTY :
671              act_turning ?
672              element_info[i].direction_graphic[ACTION_TURNING][dir] :
673              default_direction_graphic[dir]);
674         if (default_action_direction_crumbled == -1)
675           default_action_direction_crumbled =
676             (act_remove ? IMG_EMPTY :
677              act_turning ?
678              element_info[i].direction_crumbled[ACTION_TURNING][dir] :
679              default_direction_crumbled[dir]);
680
681         if (element_info[i].direction_graphic[act][dir] == -1)
682           element_info[i].direction_graphic[act][dir] =
683             default_action_direction_graphic;
684         if (element_info[i].direction_crumbled[act][dir] == -1)
685           element_info[i].direction_crumbled[act][dir] =
686             default_action_direction_crumbled;
687       }
688
689       /* no graphic for this specific action -- use default action graphic */
690       if (element_info[i].graphic[act] == -1)
691         element_info[i].graphic[act] =
692           (act_remove ? IMG_EMPTY :
693            act_turning ? element_info[i].graphic[ACTION_TURNING] :
694            default_action_graphic);
695       if (element_info[i].crumbled[act] == -1)
696         element_info[i].crumbled[act] =
697           (act_remove ? IMG_EMPTY :
698            act_turning ? element_info[i].crumbled[ACTION_TURNING] :
699            default_action_crumbled);
700     }
701   }
702
703 #if 1
704   /* set animation mode to "none" for each graphic with only 1 frame */
705   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
706   {
707     for (act = 0; act < NUM_ACTIONS; act++)
708     {
709       int graphic = element_info[i].graphic[act];
710       int crumbled = element_info[i].crumbled[act];
711
712       if (graphic_info[graphic].anim_frames == 1)
713         graphic_info[graphic].anim_mode = ANIM_NONE;
714       if (graphic_info[crumbled].anim_frames == 1)
715         graphic_info[crumbled].anim_mode = ANIM_NONE;
716
717       for (dir = 0; dir < NUM_DIRECTIONS; dir++)
718       {
719         graphic = element_info[i].direction_graphic[act][dir];
720         crumbled = element_info[i].direction_crumbled[act][dir];
721
722         if (graphic_info[graphic].anim_frames == 1)
723           graphic_info[graphic].anim_mode = ANIM_NONE;
724         if (graphic_info[crumbled].anim_frames == 1)
725           graphic_info[crumbled].anim_mode = ANIM_NONE;
726       }
727     }
728   }
729 #endif
730
731 #if 0
732 #if DEBUG
733   if (options.verbose)
734   {
735     for (i = 0; i < MAX_NUM_ELEMENTS; i++)
736       if (element_info[i].graphic[ACTION_DEFAULT] == IMG_UNKNOWN &&
737           i != EL_UNKNOWN)
738         Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
739               element_info[i].token_name, i);
740   }
741 #endif
742 #endif
743 }
744
745 void InitElementSpecialGraphicInfo()
746 {
747   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
748   int num_property_mappings = getImageListPropertyMappingSize();
749   int i, j;
750
751   /* always start with reliable default values */
752   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
753     for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
754       element_info[i].special_graphic[j] =
755         element_info[i].graphic[ACTION_DEFAULT];
756
757   /* initialize special element/graphic mapping from static configuration */
758   for (i = 0; element_to_special_graphic[i].element > -1; i++)
759   {
760     int element = element_to_special_graphic[i].element;
761     int special = element_to_special_graphic[i].special;
762     int graphic = element_to_special_graphic[i].graphic;
763     int base_graphic = el2baseimg(element);
764     boolean base_redefined = getImageListEntry(base_graphic)->redefined;
765     boolean special_redefined = getImageListEntry(graphic)->redefined;
766
767     /* if the base graphic ("emerald", for example) has been redefined,
768        but not the special graphic ("emerald.EDITOR", for example), do not
769        use an existing (in this case considered obsolete) special graphic
770        anymore, but use the automatically created (down-scaled) graphic */
771     if (base_redefined && !special_redefined)
772       continue;
773
774     element_info[element].special_graphic[special] = graphic;
775   }
776
777   /* initialize special element/graphic mapping from dynamic configuration */
778   for (i = 0; i < num_property_mappings; i++)
779   {
780     int element = property_mapping[i].base_index;
781     int special = property_mapping[i].ext3_index;
782     int graphic = property_mapping[i].artwork_index;
783
784     if (element >= MAX_NUM_ELEMENTS)
785       continue;
786
787     if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
788       element_info[element].special_graphic[special] = graphic;
789   }
790
791 #if 1
792   /* now set all undefined/invalid graphics to default */
793   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
794     for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
795       if (graphic_info[element_info[i].special_graphic[j]].bitmap == NULL)
796         element_info[i].special_graphic[j] =
797           element_info[i].graphic[ACTION_DEFAULT];
798 #endif
799 }
800
801 static int get_element_from_token(char *token)
802 {
803   int i;
804
805   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
806     if (strcmp(element_info[i].token_name, token) == 0)
807       return i;
808
809   return -1;
810 }
811
812 static void set_graphic_parameters(int graphic, char **parameter_raw)
813 {
814   Bitmap *src_bitmap = getBitmapFromImageID(graphic);
815   int parameter[NUM_GFX_ARGS];
816   int anim_frames_per_row = 1, anim_frames_per_col = 1;
817   int anim_frames_per_line = 1;
818   int i;
819
820   /* get integer values from string parameters */
821   for (i = 0; i < NUM_GFX_ARGS; i++)
822   {
823     parameter[i] =
824       get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
825                           image_config_suffix[i].type);
826
827     if (image_config_suffix[i].type == TYPE_TOKEN)
828       parameter[i] = get_element_from_token(parameter_raw[i]);
829   }
830
831   graphic_info[graphic].bitmap = src_bitmap;
832
833   /* start with reliable default values */
834   graphic_info[graphic].src_x = 0;
835   graphic_info[graphic].src_y = 0;
836   graphic_info[graphic].width = TILEX;
837   graphic_info[graphic].height = TILEY;
838   graphic_info[graphic].offset_x = 0;   /* one or both of these values ... */
839   graphic_info[graphic].offset_y = 0;   /* ... will be corrected later */
840   graphic_info[graphic].crumbled_like = -1;     /* do not use clone element */
841   graphic_info[graphic].diggable_like = -1;     /* do not use clone element */
842   graphic_info[graphic].border_size = TILEX / 8;  /* "CRUMBLED" border size */
843   graphic_info[graphic].anim_delay_fixed = 0;
844   graphic_info[graphic].anim_delay_random = 0;
845   graphic_info[graphic].post_delay_fixed = 0;
846   graphic_info[graphic].post_delay_random = 0;
847
848   /* optional x and y tile position of animation frame sequence */
849   if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
850     graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
851   if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
852     graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
853
854   /* optional x and y pixel position of animation frame sequence */
855   if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
856     graphic_info[graphic].src_x = parameter[GFX_ARG_X];
857   if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
858     graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
859
860   /* optional width and height of each animation frame */
861   if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
862     graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
863   if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
864     graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
865
866   if (src_bitmap)
867   {
868     anim_frames_per_row = src_bitmap->width  / graphic_info[graphic].width;
869     anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
870   }
871
872   /* correct x or y offset dependent of vertical or horizontal frame order */
873   if (parameter[GFX_ARG_VERTICAL])      /* frames are ordered vertically */
874   {
875     graphic_info[graphic].offset_y =
876       (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
877        parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
878     anim_frames_per_line = anim_frames_per_col;
879   }
880   else                                  /* frames are ordered horizontally */
881   {
882     graphic_info[graphic].offset_x =
883       (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
884        parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
885     anim_frames_per_line = anim_frames_per_row;
886   }
887
888   /* optionally, the x and y offset of frames can be specified directly */
889   if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
890     graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
891   if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
892     graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
893
894   /* automatically determine correct number of frames, if not defined */
895   if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
896     graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
897   else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
898     graphic_info[graphic].anim_frames = anim_frames_per_row;
899   else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
900     graphic_info[graphic].anim_frames = anim_frames_per_col;
901   else
902     graphic_info[graphic].anim_frames = 1;
903
904   graphic_info[graphic].anim_frames_per_line =
905     (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
906      parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
907
908   graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
909   if (graphic_info[graphic].anim_delay == 0)    /* delay must be at least 1 */
910     graphic_info[graphic].anim_delay = 1;
911
912   graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
913 #if 0
914   if (graphic_info[graphic].anim_frames == 1)
915     graphic_info[graphic].anim_mode = ANIM_NONE;
916 #endif
917
918   /* automatically determine correct start frame, if not defined */
919   if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
920     graphic_info[graphic].anim_start_frame = 0;
921   else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
922     graphic_info[graphic].anim_start_frame =
923       graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
924   else
925     graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
926
927   /* animation synchronized with global frame counter, not move position */
928   graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
929
930   /* optional element for cloning crumble graphics */
931   if (parameter[GFX_ARG_CRUMBLED_LIKE] != ARG_UNDEFINED_VALUE)
932     graphic_info[graphic].crumbled_like = parameter[GFX_ARG_CRUMBLED_LIKE];
933
934   /* optional element for cloning digging graphics */
935   if (parameter[GFX_ARG_DIGGABLE_LIKE] != ARG_UNDEFINED_VALUE)
936     graphic_info[graphic].diggable_like = parameter[GFX_ARG_DIGGABLE_LIKE];
937
938   /* optional border size for "crumbling" diggable graphics */
939   if (parameter[GFX_ARG_BORDER_SIZE] != ARG_UNDEFINED_VALUE)
940     graphic_info[graphic].border_size = parameter[GFX_ARG_BORDER_SIZE];
941
942   /* this is only used for player "boring" and "sleeping" actions */
943   if (parameter[GFX_ARG_ANIM_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
944     graphic_info[graphic].anim_delay_fixed =
945       parameter[GFX_ARG_ANIM_DELAY_FIXED];
946   if (parameter[GFX_ARG_ANIM_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
947     graphic_info[graphic].anim_delay_random =
948       parameter[GFX_ARG_ANIM_DELAY_RANDOM];
949   if (parameter[GFX_ARG_POST_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
950     graphic_info[graphic].post_delay_fixed =
951       parameter[GFX_ARG_POST_DELAY_FIXED];
952   if (parameter[GFX_ARG_POST_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
953     graphic_info[graphic].post_delay_random =
954       parameter[GFX_ARG_POST_DELAY_RANDOM];
955
956   /* this is only used for toon animations */
957   graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
958   graphic_info[graphic].step_delay  = parameter[GFX_ARG_STEP_DELAY];
959
960   /* this is only used for drawing font characters */
961   graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
962   graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
963
964   /* this is only used for drawing envelope graphics */
965   graphic_info[graphic].draw_masked = parameter[GFX_ARG_DRAW_MASKED];
966 }
967
968 static void InitGraphicInfo()
969 {
970   int fallback_graphic = IMG_CHAR_EXCLAM;
971   struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
972   Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
973   int num_images = getImageListSize();
974   int i;
975
976 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
977   static boolean clipmasks_initialized = FALSE;
978   Pixmap src_pixmap;
979   XGCValues clip_gc_values;
980   unsigned long clip_gc_valuemask;
981   GC copy_clipmask_gc = None;
982 #endif
983
984   checked_free(graphic_info);
985
986   graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
987
988 #if 0
989   printf("::: graphic_info: %d entries\n", num_images);
990 #endif
991
992 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
993   if (clipmasks_initialized)
994   {
995     for (i = 0; i < num_images; i++)
996     {
997       if (graphic_info[i].clip_mask)
998         XFreePixmap(display, graphic_info[i].clip_mask);
999       if (graphic_info[i].clip_gc)
1000         XFreeGC(display, graphic_info[i].clip_gc);
1001
1002       graphic_info[i].clip_mask = None;
1003       graphic_info[i].clip_gc = None;
1004     }
1005   }
1006 #endif
1007
1008   for (i = 0; i < num_images; i++)
1009   {
1010     struct FileInfo *image = getImageListEntry(i);
1011     Bitmap *src_bitmap;
1012     int src_x, src_y;
1013     int first_frame, last_frame;
1014
1015 #if 0
1016     printf("::: image: '%s' [%d]\n", image->token, i);
1017 #endif
1018
1019 #if 0
1020     printf("::: image # %d: '%s' ['%s']\n",
1021            i, image->token,
1022            getTokenFromImageID(i));
1023 #endif
1024
1025     set_graphic_parameters(i, image->parameter);
1026
1027     /* now check if no animation frames are outside of the loaded image */
1028
1029     if (graphic_info[i].bitmap == NULL)
1030       continue;         /* skip check for optional images that are undefined */
1031
1032     first_frame = 0;
1033     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1034     if (src_x < 0 || src_y < 0 ||
1035         src_x + TILEX > src_bitmap->width ||
1036         src_y + TILEY > src_bitmap->height)
1037     {
1038       Error(ERR_RETURN_LINE, "-");
1039       Error(ERR_RETURN, "warning: error found in config file:");
1040       Error(ERR_RETURN, "- config file: '%s'",
1041             getImageConfigFilename());
1042       Error(ERR_RETURN, "- config token: '%s'",
1043             getTokenFromImageID(i));
1044       Error(ERR_RETURN, "- image file: '%s'",
1045             src_bitmap->source_filename);
1046       Error(ERR_RETURN,
1047             "error: first animation frame out of bounds (%d, %d)",
1048             src_x, src_y);
1049       Error(ERR_RETURN, "custom graphic rejected for this element/action");
1050
1051       if (i == fallback_graphic)
1052         Error(ERR_EXIT, "fatal error: no fallback graphic available");
1053
1054       Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1055       Error(ERR_RETURN_LINE, "-");
1056
1057       set_graphic_parameters(i, fallback_image->default_parameter);
1058       graphic_info[i].bitmap = fallback_bitmap;
1059     }
1060
1061     last_frame = graphic_info[i].anim_frames - 1;
1062     getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1063     if (src_x < 0 || src_y < 0 ||
1064         src_x + TILEX > src_bitmap->width ||
1065         src_y + TILEY > src_bitmap->height)
1066     {
1067       Error(ERR_RETURN_LINE, "-");
1068       Error(ERR_RETURN, "warning: error found in config file:");
1069       Error(ERR_RETURN, "- config file: '%s'",
1070             getImageConfigFilename());
1071       Error(ERR_RETURN, "- config token: '%s'",
1072             getTokenFromImageID(i));
1073       Error(ERR_RETURN, "- image file: '%s'",
1074             src_bitmap->source_filename);
1075       Error(ERR_RETURN,
1076             "error: last animation frame (%d) out of bounds (%d, %d)",
1077             last_frame, src_x, src_y);
1078       Error(ERR_RETURN, "custom graphic rejected for this element/action");
1079
1080       if (i == fallback_graphic)
1081         Error(ERR_EXIT, "fatal error: no fallback graphic available");
1082
1083       Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1084       Error(ERR_RETURN_LINE, "-");
1085
1086       set_graphic_parameters(i, fallback_image->default_parameter);
1087       graphic_info[i].bitmap = fallback_bitmap;
1088     }
1089
1090 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1091     /* currently we need only a tile clip mask from the first frame */
1092     getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1093
1094     if (copy_clipmask_gc == None)
1095     {
1096       clip_gc_values.graphics_exposures = False;
1097       clip_gc_valuemask = GCGraphicsExposures;
1098       copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1099                                    clip_gc_valuemask, &clip_gc_values);
1100     }
1101
1102     graphic_info[i].clip_mask =
1103       XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1104
1105     src_pixmap = src_bitmap->clip_mask;
1106     XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1107               copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1108
1109     clip_gc_values.graphics_exposures = False;
1110     clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1111     clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1112
1113     graphic_info[i].clip_gc =
1114       XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1115 #endif
1116   }
1117
1118 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1119   if (copy_clipmask_gc)
1120     XFreeGC(display, copy_clipmask_gc);
1121
1122   clipmasks_initialized = TRUE;
1123 #endif
1124 }
1125
1126 static void InitElementSoundInfo()
1127 {
1128   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1129   int num_property_mappings = getSoundListPropertyMappingSize();
1130   int i, j, act;
1131
1132   /* set values to -1 to identify later as "uninitialized" values */
1133   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1134     for (act = 0; act < NUM_ACTIONS; act++)
1135       element_info[i].sound[act] = -1;
1136
1137   /* initialize element/sound mapping from static configuration */
1138   for (i = 0; element_to_sound[i].element > -1; i++)
1139   {
1140     int element      = element_to_sound[i].element;
1141     int action       = element_to_sound[i].action;
1142     int sound        = element_to_sound[i].sound;
1143     boolean is_class = element_to_sound[i].is_class;
1144
1145     if (action < 0)
1146       action = ACTION_DEFAULT;
1147
1148     if (!is_class)
1149       element_info[element].sound[action] = sound;
1150     else
1151       for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1152         if (strcmp(element_info[j].class_name,
1153                    element_info[element].class_name) == 0)
1154           element_info[j].sound[action] = sound;
1155   }
1156
1157   /* initialize element class/sound mapping from dynamic configuration */
1158   for (i = 0; i < num_property_mappings; i++)
1159   {
1160     int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
1161     int action        = property_mapping[i].ext1_index;
1162     int sound         = property_mapping[i].artwork_index;
1163
1164     if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
1165       continue;
1166
1167     if (action < 0)
1168       action = ACTION_DEFAULT;
1169
1170     for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1171       if (strcmp(element_info[j].class_name,
1172                  element_info[element_class].class_name) == 0)
1173         element_info[j].sound[action] = sound;
1174   }
1175
1176   /* initialize element/sound mapping from dynamic configuration */
1177   for (i = 0; i < num_property_mappings; i++)
1178   {
1179     int element = property_mapping[i].base_index;
1180     int action  = property_mapping[i].ext1_index;
1181     int sound   = property_mapping[i].artwork_index;
1182
1183     if (element >= MAX_NUM_ELEMENTS)
1184       continue;
1185
1186     if (action < 0)
1187       action = ACTION_DEFAULT;
1188
1189     element_info[element].sound[action] = sound;
1190   }
1191
1192   /* now set all '-1' values to element specific default values */
1193   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1194   {
1195     for (act = 0; act < NUM_ACTIONS; act++)
1196     {
1197       /* generic default action sound (defined by "[default]" directive) */
1198       int default_action_sound = element_info[EL_DEFAULT].sound[act];
1199
1200       /* look for special default action sound (classic game specific) */
1201       if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].sound[act] != -1)
1202         default_action_sound = element_info[EL_BD_DEFAULT].sound[act];
1203       if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].sound[act] != -1)
1204         default_action_sound = element_info[EL_SP_DEFAULT].sound[act];
1205       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].sound[act] != -1)
1206         default_action_sound = element_info[EL_SB_DEFAULT].sound[act];
1207
1208       /* !!! there's no such thing as a "default action sound" !!! */
1209 #if 0
1210       /* look for element specific default sound (independent from action) */
1211       if (element_info[i].sound[ACTION_DEFAULT] != -1)
1212         default_action_sound = element_info[i].sound[ACTION_DEFAULT];
1213 #endif
1214
1215       /* no sound for this specific action -- use default action sound */
1216       if (element_info[i].sound[act] == -1)
1217         element_info[i].sound[act] = default_action_sound;
1218     }
1219   }
1220 }
1221
1222 static void InitGameModeSoundInfo()
1223 {
1224   int i;
1225
1226   /* set values to -1 to identify later as "uninitialized" values */
1227   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1228     menu.sound[i] = -1;
1229
1230   /* initialize gamemode/sound mapping from static configuration */
1231   for (i = 0; gamemode_to_sound[i].sound > -1; i++)
1232   {
1233     int gamemode = gamemode_to_sound[i].gamemode;
1234     int sound    = gamemode_to_sound[i].sound;
1235
1236     if (gamemode < 0)
1237       gamemode = GAME_MODE_DEFAULT;
1238
1239     menu.sound[gamemode] = sound;
1240   }
1241
1242   /* now set all '-1' values to levelset specific default values */
1243   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1244     if (menu.sound[i] == -1)
1245       menu.sound[i] = menu.sound[GAME_MODE_DEFAULT];
1246
1247 #if 0
1248   /* TEST ONLY */
1249   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1250     if (menu.sound[i] != -1)
1251       printf("::: menu.sound[%d] == %d\n", i, menu.sound[i]);
1252 #endif
1253 }
1254
1255 static void set_sound_parameters(int sound, char **parameter_raw)
1256 {
1257   int parameter[NUM_SND_ARGS];
1258   int i;
1259
1260   /* get integer values from string parameters */
1261   for (i = 0; i < NUM_SND_ARGS; i++)
1262     parameter[i] =
1263       get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
1264                           sound_config_suffix[i].type);
1265
1266   /* explicit loop mode setting in configuration overrides default value */
1267   if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1268     sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1269 }
1270
1271 static void InitSoundInfo()
1272 {
1273 #if 0
1274   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1275   int num_property_mappings = getSoundListPropertyMappingSize();
1276 #endif
1277   int *sound_effect_properties;
1278   int num_sounds = getSoundListSize();
1279   int i, j;
1280
1281   checked_free(sound_info);
1282
1283   sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1284   sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1285
1286   /* initialize sound effect for all elements to "no sound" */
1287   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1288     for (j = 0; j < NUM_ACTIONS; j++)
1289       element_info[i].sound[j] = SND_UNDEFINED;
1290
1291   for (i = 0; i < num_sounds; i++)
1292   {
1293     struct FileInfo *sound = getSoundListEntry(i);
1294     int len_effect_text = strlen(sound->token);
1295
1296     sound_effect_properties[i] = ACTION_OTHER;
1297     sound_info[i].loop = FALSE;         /* default: play sound only once */
1298
1299 #if 0
1300     printf("::: sound %d: '%s'\n", i, sound->token);
1301 #endif
1302
1303     /* determine all loop sounds and identify certain sound classes */
1304
1305     for (j = 0; element_action_info[j].suffix; j++)
1306     {
1307       int len_action_text = strlen(element_action_info[j].suffix);
1308
1309       if (len_action_text < len_effect_text &&
1310           strcmp(&sound->token[len_effect_text - len_action_text],
1311                  element_action_info[j].suffix) == 0)
1312       {
1313         sound_effect_properties[i] = element_action_info[j].value;
1314         sound_info[i].loop = element_action_info[j].is_loop_sound;
1315
1316         break;
1317       }
1318     }
1319
1320 #if 0
1321     if (strcmp(sound->token, "custom_42") == 0)
1322       printf("::: '%s' -> %d\n", sound->token, sound_info[i].loop);
1323 #endif
1324
1325     /* associate elements and some selected sound actions */
1326
1327     for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1328     {
1329       if (element_info[j].class_name)
1330       {
1331         int len_class_text = strlen(element_info[j].class_name);
1332
1333         if (len_class_text + 1 < len_effect_text &&
1334             strncmp(sound->token,
1335                     element_info[j].class_name, len_class_text) == 0 &&
1336             sound->token[len_class_text] == '.')
1337         {
1338           int sound_action_value = sound_effect_properties[i];
1339
1340           element_info[j].sound[sound_action_value] = i;
1341         }
1342       }
1343     }
1344
1345     set_sound_parameters(i, sound->parameter);
1346   }
1347
1348   free(sound_effect_properties);
1349
1350 #if 0
1351   /* !!! now handled in InitElementSoundInfo() !!! */
1352   /* initialize element/sound mapping from dynamic configuration */
1353   for (i = 0; i < num_property_mappings; i++)
1354   {
1355     int element   = property_mapping[i].base_index;
1356     int action    = property_mapping[i].ext1_index;
1357     int sound     = property_mapping[i].artwork_index;
1358
1359     if (action < 0)
1360       action = ACTION_DEFAULT;
1361
1362     printf("::: %d: %d, %d, %d ['%s']\n",
1363            i, element, action, sound, element_info[element].token_name);
1364
1365     element_info[element].sound[action] = sound;
1366   }
1367 #endif
1368
1369 #if 0
1370   /* TEST ONLY */
1371   {
1372     int element = EL_CUSTOM_11;
1373     int j = 0;
1374
1375     while (element_action_info[j].suffix)
1376     {
1377       printf("element %d, sound action '%s'  == %d\n",
1378              element, element_action_info[j].suffix,
1379              element_info[element].sound[j]);
1380       j++;
1381     }
1382   }
1383
1384   PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1385 #endif
1386
1387 #if 0
1388   /* TEST ONLY */
1389   {
1390     int element = EL_SAND;
1391     int sound_action = ACTION_DIGGING;
1392     int j = 0;
1393
1394     while (element_action_info[j].suffix)
1395     {
1396       if (element_action_info[j].value == sound_action)
1397         printf("element %d, sound action '%s'  == %d\n",
1398                element, element_action_info[j].suffix,
1399                element_info[element].sound[sound_action]);
1400       j++;
1401     }
1402   }
1403 #endif
1404 }
1405
1406 static void InitGameModeMusicInfo()
1407 {
1408   struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
1409   int num_property_mappings = getMusicListPropertyMappingSize();
1410   int default_levelset_music = -1;
1411   int i;
1412
1413   /* set values to -1 to identify later as "uninitialized" values */
1414   for (i = 0; i < MAX_LEVELS; i++)
1415     levelset.music[i] = -1;
1416   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1417     menu.music[i] = -1;
1418
1419   /* initialize gamemode/music mapping from static configuration */
1420   for (i = 0; gamemode_to_music[i].music > -1; i++)
1421   {
1422     int gamemode = gamemode_to_music[i].gamemode;
1423     int music    = gamemode_to_music[i].music;
1424
1425 #if 0
1426     printf("::: gamemode == %d, music == %d\n", gamemode, music);
1427 #endif
1428
1429     if (gamemode < 0)
1430       gamemode = GAME_MODE_DEFAULT;
1431
1432     menu.music[gamemode] = music;
1433   }
1434
1435   /* initialize gamemode/music mapping from dynamic configuration */
1436   for (i = 0; i < num_property_mappings; i++)
1437   {
1438     int prefix   = property_mapping[i].base_index;
1439     int gamemode = property_mapping[i].ext1_index;
1440     int level    = property_mapping[i].ext2_index;
1441     int music    = property_mapping[i].artwork_index;
1442
1443 #if 0
1444     printf("::: prefix == %d, gamemode == %d, level == %d, music == %d\n",
1445            prefix, gamemode, level, music);
1446 #endif
1447
1448     if (prefix < 0 || prefix >= NUM_MUSIC_PREFIXES)
1449       continue;
1450
1451     if (gamemode < 0)
1452       gamemode = GAME_MODE_DEFAULT;
1453
1454     /* level specific music only allowed for in-game music */
1455     if (level != -1 && gamemode == GAME_MODE_DEFAULT)
1456       gamemode = GAME_MODE_PLAYING;
1457
1458     if (level == -1)
1459     {
1460       level = 0;
1461       default_levelset_music = music;
1462     }
1463
1464     if (gamemode == GAME_MODE_PLAYING || gamemode == GAME_MODE_DEFAULT)
1465       levelset.music[level] = music;
1466     if (gamemode != GAME_MODE_PLAYING)
1467       menu.music[gamemode] = music;
1468   }
1469
1470   /* now set all '-1' values to menu specific default values */
1471   /* (undefined values of "levelset.music[]" might stay at "-1" to
1472      allow dynamic selection of music files from music directory!) */
1473   for (i = 0; i < MAX_LEVELS; i++)
1474     if (levelset.music[i] == -1)
1475       levelset.music[i] = default_levelset_music;
1476   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1477     if (menu.music[i] == -1)
1478       menu.music[i] = menu.music[GAME_MODE_DEFAULT];
1479
1480 #if 0
1481   /* TEST ONLY */
1482   for (i = 0; i < MAX_LEVELS; i++)
1483     if (levelset.music[i] != -1)
1484       printf("::: levelset.music[%d] == %d\n", i, levelset.music[i]);
1485   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1486     if (menu.music[i] != -1)
1487       printf("::: menu.music[%d] == %d\n", i, menu.music[i]);
1488 #endif
1489 }
1490
1491 static void set_music_parameters(int music, char **parameter_raw)
1492 {
1493   int parameter[NUM_MUS_ARGS];
1494   int i;
1495
1496   /* get integer values from string parameters */
1497   for (i = 0; i < NUM_MUS_ARGS; i++)
1498     parameter[i] =
1499       get_parameter_value(music_config_suffix[i].token, parameter_raw[i],
1500                           music_config_suffix[i].type);
1501
1502   /* explicit loop mode setting in configuration overrides default value */
1503   if (parameter[MUS_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1504     music_info[music].loop = parameter[MUS_ARG_MODE_LOOP];
1505 }
1506
1507 static void InitMusicInfo()
1508 {
1509   int num_music = getMusicListSize();
1510   int i, j;
1511
1512   checked_free(music_info);
1513
1514   music_info = checked_calloc(num_music * sizeof(struct MusicInfo));
1515
1516   for (i = 0; i < num_music; i++)
1517   {
1518     struct FileInfo *music = getMusicListEntry(i);
1519     int len_music_text = strlen(music->token);
1520
1521     music_info[i].loop = TRUE;          /* default: play music in loop mode */
1522
1523     /* determine all loop music */
1524
1525     for (j = 0; music_prefix_info[j].prefix; j++)
1526     {
1527       int len_prefix_text = strlen(music_prefix_info[j].prefix);
1528
1529       if (len_prefix_text < len_music_text &&
1530           strncmp(music->token,
1531                   music_prefix_info[j].prefix, len_prefix_text) == 0)
1532       {
1533         music_info[i].loop = music_prefix_info[j].is_loop_music;
1534
1535         break;
1536       }
1537     }
1538
1539     set_music_parameters(i, music->parameter);
1540   }
1541 }
1542
1543 static void ReinitializeGraphics()
1544 {
1545   InitGraphicInfo();                    /* graphic properties mapping */
1546   InitElementGraphicInfo();             /* element game graphic mapping */
1547   InitElementSpecialGraphicInfo();      /* element special graphic mapping */
1548
1549   InitElementSmallImages();             /* create editor and preview images */
1550   InitFontGraphicInfo();                /* initialize text drawing functions */
1551
1552   SetMainBackgroundImage(IMG_BACKGROUND);
1553   SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1554
1555   InitGadgets();
1556   InitToons();
1557 }
1558
1559 static void ReinitializeSounds()
1560 {
1561   InitSoundInfo();              /* sound properties mapping */
1562   InitElementSoundInfo();       /* element game sound mapping */
1563   InitGameModeSoundInfo();      /* game mode sound mapping */
1564
1565   InitPlayLevelSound();         /* internal game sound settings */
1566 }
1567
1568 static void ReinitializeMusic()
1569 {
1570   InitMusicInfo();              /* music properties mapping */
1571   InitGameModeMusicInfo();      /* game mode music mapping */
1572 }
1573
1574 static int get_special_property_bit(int element, int property_bit_nr)
1575 {
1576   struct PropertyBitInfo
1577   {
1578     int element;
1579     int bit_nr;
1580   };
1581
1582   static struct PropertyBitInfo pb_can_move_into_acid[] =
1583   {
1584     /* the player may be able fall into acid when gravity is activated */
1585     { EL_PLAYER_1,              0       },
1586     { EL_PLAYER_2,              0       },
1587     { EL_PLAYER_3,              0       },
1588     { EL_PLAYER_4,              0       },
1589     { EL_SP_MURPHY,             0       },
1590     { EL_SOKOBAN_FIELD_PLAYER,  0       },
1591
1592     /* all element that can move may be able to also move into acid */
1593     { EL_BUG,                   1       },
1594     { EL_BUG_LEFT,              1       },
1595     { EL_BUG_RIGHT,             1       },
1596     { EL_BUG_UP,                1       },
1597     { EL_BUG_DOWN,              1       },
1598     { EL_SPACESHIP,             2       },
1599     { EL_SPACESHIP_LEFT,        2       },
1600     { EL_SPACESHIP_RIGHT,       2       },
1601     { EL_SPACESHIP_UP,          2       },
1602     { EL_SPACESHIP_DOWN,        2       },
1603     { EL_BD_BUTTERFLY,          3       },
1604     { EL_BD_BUTTERFLY_LEFT,     3       },
1605     { EL_BD_BUTTERFLY_RIGHT,    3       },
1606     { EL_BD_BUTTERFLY_UP,       3       },
1607     { EL_BD_BUTTERFLY_DOWN,     3       },
1608     { EL_BD_FIREFLY,            4       },
1609     { EL_BD_FIREFLY_LEFT,       4       },
1610     { EL_BD_FIREFLY_RIGHT,      4       },
1611     { EL_BD_FIREFLY_UP,         4       },
1612     { EL_BD_FIREFLY_DOWN,       4       },
1613     { EL_YAMYAM,                5       },
1614     { EL_DARK_YAMYAM,           6       },
1615     { EL_ROBOT,                 7       },
1616     { EL_PACMAN,                8       },
1617     { EL_PACMAN_LEFT,           8       },
1618     { EL_PACMAN_RIGHT,          8       },
1619     { EL_PACMAN_UP,             8       },
1620     { EL_PACMAN_DOWN,           8       },
1621     { EL_MOLE,                  9       },
1622     { EL_MOLE_LEFT,             9       },
1623     { EL_MOLE_RIGHT,            9       },
1624     { EL_MOLE_UP,               9       },
1625     { EL_MOLE_DOWN,             9       },
1626     { EL_PENGUIN,               10      },
1627     { EL_PIG,                   11      },
1628     { EL_DRAGON,                12      },
1629     { EL_SATELLITE,             13      },
1630     { EL_SP_SNIKSNAK,           14      },
1631     { EL_SP_ELECTRON,           15      },
1632     { EL_BALLOON,               16      },
1633     { EL_SPRING,                17      },
1634
1635     { -1,                       -1      },
1636   };
1637
1638   static struct PropertyBitInfo pb_dont_collide_with[] =
1639   {
1640     { EL_SP_SNIKSNAK,           0       },
1641     { EL_SP_ELECTRON,           1       },
1642
1643     { -1,                       -1      },
1644   };
1645
1646   static struct
1647   {
1648     int bit_nr;
1649     struct PropertyBitInfo *pb_info;
1650   } pb_definition[] =
1651   {
1652     { EP_CAN_MOVE_INTO_ACID,    pb_can_move_into_acid   },
1653     { EP_DONT_COLLIDE_WITH,     pb_dont_collide_with    },
1654
1655     { -1,                       NULL                    },
1656   };
1657
1658   struct PropertyBitInfo *pb_info = NULL;
1659   int i;
1660
1661   for (i = 0; pb_definition[i].bit_nr != -1; i++)
1662     if (pb_definition[i].bit_nr == property_bit_nr)
1663       pb_info = pb_definition[i].pb_info;
1664
1665   if (pb_info == NULL)
1666     return -1;
1667
1668   for (i = 0; pb_info[i].element != -1; i++)
1669     if (pb_info[i].element == element)
1670       return pb_info[i].bit_nr;
1671
1672   return -1;
1673 }
1674
1675 #if 1
1676 void setBitfieldProperty(int *bitfield, int property_bit_nr, int element,
1677                          boolean property_value)
1678 {
1679   int bit_nr = get_special_property_bit(element, property_bit_nr);
1680
1681   if (bit_nr > -1)
1682   {
1683     if (property_value)
1684       *bitfield |=  (1 << bit_nr);
1685     else
1686       *bitfield &= ~(1 << bit_nr);
1687   }
1688 }
1689
1690 boolean getBitfieldProperty(int *bitfield, int property_bit_nr, int element)
1691 {
1692   int bit_nr = get_special_property_bit(element, property_bit_nr);
1693
1694   if (bit_nr > -1)
1695     return ((*bitfield & (1 << bit_nr)) != 0);
1696
1697   return FALSE;
1698 }
1699
1700 #else
1701
1702 void setMoveIntoAcidProperty(struct LevelInfo *level, int element, boolean set)
1703 {
1704   int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
1705
1706   if (bit_nr > -1)
1707   {
1708     level->can_move_into_acid_bits &= ~(1 << bit_nr);
1709
1710     if (set)
1711       level->can_move_into_acid_bits |= (1 << bit_nr);
1712   }
1713 }
1714
1715 boolean getMoveIntoAcidProperty(struct LevelInfo *level, int element)
1716 {
1717   int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
1718
1719   if (bit_nr > -1)
1720     return ((level->can_move_into_acid_bits & (1 << bit_nr)) != 0);
1721
1722   return FALSE;
1723 }
1724 #endif
1725
1726 void InitElementPropertiesStatic()
1727 {
1728   static int ep_diggable[] =
1729   {
1730     EL_SAND,
1731     EL_SP_BASE,
1732     EL_SP_BUGGY_BASE,
1733     EL_SP_BUGGY_BASE_ACTIVATING,
1734     EL_TRAP,
1735     EL_INVISIBLE_SAND,
1736     EL_INVISIBLE_SAND_ACTIVE,
1737
1738     /* !!! currently not diggable, but handled by 'ep_dont_run_into' !!! */
1739     /* (if amoeba can grow into anything diggable, maybe keep these out) */
1740 #if 0
1741     EL_LANDMINE,
1742     EL_TRAP_ACTIVE,
1743     EL_SP_BUGGY_BASE_ACTIVE,
1744 #endif
1745     -1
1746   };
1747
1748   static int ep_collectible_only[] =
1749   {
1750     EL_BD_DIAMOND,
1751     EL_EMERALD,
1752     EL_DIAMOND,
1753     EL_EMERALD_YELLOW,
1754     EL_EMERALD_RED,
1755     EL_EMERALD_PURPLE,
1756     EL_KEY_1,
1757     EL_KEY_2,
1758     EL_KEY_3,
1759     EL_KEY_4,
1760     EL_EM_KEY_1,
1761     EL_EM_KEY_2,
1762     EL_EM_KEY_3,
1763     EL_EM_KEY_4,
1764     EL_DYNAMITE,
1765     EL_DYNABOMB_INCREASE_NUMBER,
1766     EL_DYNABOMB_INCREASE_SIZE,
1767     EL_DYNABOMB_INCREASE_POWER,
1768     EL_SP_INFOTRON,
1769     EL_SP_DISK_RED,
1770     EL_PEARL,
1771     EL_CRYSTAL,
1772     EL_KEY_WHITE,
1773     EL_SHIELD_NORMAL,
1774     EL_SHIELD_DEADLY,
1775     EL_EXTRA_TIME,
1776     EL_ENVELOPE_1,
1777     EL_ENVELOPE_2,
1778     EL_ENVELOPE_3,
1779     EL_ENVELOPE_4,
1780     EL_SPEED_PILL,
1781     -1
1782   };
1783
1784   static int ep_dont_run_into[] =
1785   {
1786     /* same elements as in 'ep_dont_touch' */
1787     EL_BUG,
1788     EL_SPACESHIP,
1789     EL_BD_BUTTERFLY,
1790     EL_BD_FIREFLY,
1791
1792     /* same elements as in 'ep_dont_collide_with' */
1793     EL_YAMYAM,
1794     EL_DARK_YAMYAM,
1795     EL_ROBOT,
1796     EL_PACMAN,
1797     EL_SP_SNIKSNAK,
1798     EL_SP_ELECTRON,
1799
1800     /* new elements */
1801     EL_AMOEBA_DROP,
1802     EL_ACID,
1803
1804     /* !!! maybe this should better be handled by 'ep_diggable' !!! */
1805 #if 1
1806     EL_LANDMINE,
1807     EL_TRAP_ACTIVE,
1808     EL_SP_BUGGY_BASE_ACTIVE,
1809 #endif
1810     -1
1811   };
1812
1813   static int ep_dont_collide_with[] =
1814   {
1815     /* same elements as in 'ep_dont_touch' */
1816     EL_BUG,
1817     EL_SPACESHIP,
1818     EL_BD_BUTTERFLY,
1819     EL_BD_FIREFLY,
1820
1821     /* new elements */
1822     EL_YAMYAM,
1823     EL_DARK_YAMYAM,
1824     EL_ROBOT,
1825     EL_PACMAN,
1826     EL_SP_SNIKSNAK,
1827     EL_SP_ELECTRON,
1828     -1
1829   };
1830
1831   static int ep_dont_touch[] =
1832   {
1833     EL_BUG,
1834     EL_SPACESHIP,
1835     EL_BD_BUTTERFLY,
1836     EL_BD_FIREFLY,
1837     -1
1838   };
1839
1840   static int ep_indestructible[] =
1841   {
1842     EL_STEELWALL,
1843     EL_ACID,
1844     EL_ACID_POOL_TOPLEFT,
1845     EL_ACID_POOL_TOPRIGHT,
1846     EL_ACID_POOL_BOTTOMLEFT,
1847     EL_ACID_POOL_BOTTOM,
1848     EL_ACID_POOL_BOTTOMRIGHT,
1849     EL_SP_HARDWARE_GRAY,
1850     EL_SP_HARDWARE_GREEN,
1851     EL_SP_HARDWARE_BLUE,
1852     EL_SP_HARDWARE_RED,
1853     EL_SP_HARDWARE_YELLOW,
1854     EL_SP_HARDWARE_BASE_1,
1855     EL_SP_HARDWARE_BASE_2,
1856     EL_SP_HARDWARE_BASE_3,
1857     EL_SP_HARDWARE_BASE_4,
1858     EL_SP_HARDWARE_BASE_5,
1859     EL_SP_HARDWARE_BASE_6,
1860     EL_INVISIBLE_STEELWALL,
1861     EL_INVISIBLE_STEELWALL_ACTIVE,
1862     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1863     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1864     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1865     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1866     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1867     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1868     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1869     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1870     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1871     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1872     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1873     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1874     EL_LIGHT_SWITCH,
1875     EL_LIGHT_SWITCH_ACTIVE,
1876     EL_SIGN_EXCLAMATION,
1877     EL_SIGN_RADIOACTIVITY,
1878     EL_SIGN_STOP,
1879     EL_SIGN_WHEELCHAIR,
1880     EL_SIGN_PARKING,
1881     EL_SIGN_ONEWAY,
1882     EL_SIGN_HEART,
1883     EL_SIGN_TRIANGLE,
1884     EL_SIGN_ROUND,
1885     EL_SIGN_EXIT,
1886     EL_SIGN_YINYANG,
1887     EL_SIGN_OTHER,
1888     EL_STEELWALL_SLIPPERY,
1889     EL_EMC_STEELWALL_1,
1890     EL_EMC_STEELWALL_2,
1891     EL_EMC_STEELWALL_3,
1892     EL_EMC_STEELWALL_4,
1893     EL_CRYSTAL,
1894     EL_GATE_1,
1895     EL_GATE_2,
1896     EL_GATE_3,
1897     EL_GATE_4,
1898     EL_GATE_1_GRAY,
1899     EL_GATE_2_GRAY,
1900     EL_GATE_3_GRAY,
1901     EL_GATE_4_GRAY,
1902     EL_EM_GATE_1,
1903     EL_EM_GATE_2,
1904     EL_EM_GATE_3,
1905     EL_EM_GATE_4,
1906     EL_EM_GATE_1_GRAY,
1907     EL_EM_GATE_2_GRAY,
1908     EL_EM_GATE_3_GRAY,
1909     EL_EM_GATE_4_GRAY,
1910     EL_SWITCHGATE_OPEN,
1911     EL_SWITCHGATE_OPENING,
1912     EL_SWITCHGATE_CLOSED,
1913     EL_SWITCHGATE_CLOSING,
1914 #if 0
1915     EL_SWITCHGATE_SWITCH_UP,
1916     EL_SWITCHGATE_SWITCH_DOWN,
1917 #endif
1918     EL_TIMEGATE_OPEN,
1919     EL_TIMEGATE_OPENING,
1920     EL_TIMEGATE_CLOSED,
1921     EL_TIMEGATE_CLOSING,
1922 #if 0
1923     EL_TIMEGATE_SWITCH,
1924     EL_TIMEGATE_SWITCH_ACTIVE,
1925 #endif
1926     EL_TUBE_ANY,
1927     EL_TUBE_VERTICAL,
1928     EL_TUBE_HORIZONTAL,
1929     EL_TUBE_VERTICAL_LEFT,
1930     EL_TUBE_VERTICAL_RIGHT,
1931     EL_TUBE_HORIZONTAL_UP,
1932     EL_TUBE_HORIZONTAL_DOWN,
1933     EL_TUBE_LEFT_UP,
1934     EL_TUBE_LEFT_DOWN,
1935     EL_TUBE_RIGHT_UP,
1936     EL_TUBE_RIGHT_DOWN,
1937     -1
1938   };
1939
1940   static int ep_slippery[] =
1941   {
1942     EL_WALL_SLIPPERY,
1943     EL_BD_WALL,
1944     EL_ROCK,
1945     EL_BD_ROCK,
1946     EL_EMERALD,
1947     EL_BD_DIAMOND,
1948     EL_EMERALD_YELLOW,
1949     EL_EMERALD_RED,
1950     EL_EMERALD_PURPLE,
1951     EL_DIAMOND,
1952     EL_BOMB,
1953     EL_NUT,
1954     EL_ROBOT_WHEEL_ACTIVE,
1955     EL_ROBOT_WHEEL,
1956     EL_TIME_ORB_FULL,
1957     EL_TIME_ORB_EMPTY,
1958     EL_LAMP_ACTIVE,
1959     EL_LAMP,
1960     EL_ACID_POOL_TOPLEFT,
1961     EL_ACID_POOL_TOPRIGHT,
1962     EL_SATELLITE,
1963     EL_SP_ZONK,
1964     EL_SP_INFOTRON,
1965     EL_SP_CHIP_SINGLE,
1966     EL_SP_CHIP_LEFT,
1967     EL_SP_CHIP_RIGHT,
1968     EL_SP_CHIP_TOP,
1969     EL_SP_CHIP_BOTTOM,
1970     EL_SPEED_PILL,
1971     EL_STEELWALL_SLIPPERY,
1972     EL_PEARL,
1973     EL_CRYSTAL,
1974     -1
1975   };
1976
1977   static int ep_can_change[] =
1978   {
1979     -1
1980   };
1981
1982   static int ep_can_move[] =
1983   {
1984     /* same elements as in 'pb_can_move_into_acid' */
1985     EL_BUG,
1986     EL_SPACESHIP,
1987     EL_BD_BUTTERFLY,
1988     EL_BD_FIREFLY,
1989     EL_YAMYAM,
1990     EL_DARK_YAMYAM,
1991     EL_ROBOT,
1992     EL_PACMAN,
1993     EL_MOLE,
1994     EL_PENGUIN,
1995     EL_PIG,
1996     EL_DRAGON,
1997     EL_SATELLITE,
1998     EL_SP_SNIKSNAK,
1999     EL_SP_ELECTRON,
2000     EL_BALLOON,
2001     EL_SPRING,
2002     -1
2003   };
2004
2005   static int ep_can_fall[] =
2006   {
2007     EL_ROCK,
2008     EL_BD_ROCK,
2009     EL_EMERALD,
2010     EL_BD_DIAMOND,
2011     EL_EMERALD_YELLOW,
2012     EL_EMERALD_RED,
2013     EL_EMERALD_PURPLE,
2014     EL_DIAMOND,
2015     EL_BOMB,
2016     EL_NUT,
2017     EL_AMOEBA_DROP,
2018     EL_QUICKSAND_FULL,
2019     EL_MAGIC_WALL_FULL,
2020     EL_BD_MAGIC_WALL_FULL,
2021     EL_TIME_ORB_FULL,
2022     EL_TIME_ORB_EMPTY,
2023     EL_SP_ZONK,
2024     EL_SP_INFOTRON,
2025     EL_SP_DISK_ORANGE,
2026     EL_PEARL,
2027     EL_CRYSTAL,
2028     EL_SPRING,
2029     EL_DX_SUPABOMB,
2030     -1
2031   };
2032
2033   static int ep_can_smash_player[] =
2034   {
2035     EL_ROCK,
2036     EL_BD_ROCK,
2037     EL_EMERALD,
2038     EL_BD_DIAMOND,
2039     EL_EMERALD_YELLOW,
2040     EL_EMERALD_RED,
2041     EL_EMERALD_PURPLE,
2042     EL_DIAMOND,
2043     EL_BOMB,
2044     EL_NUT,
2045     EL_AMOEBA_DROP,
2046     EL_TIME_ORB_FULL,
2047     EL_TIME_ORB_EMPTY,
2048     EL_SP_ZONK,
2049     EL_SP_INFOTRON,
2050     EL_SP_DISK_ORANGE,
2051     EL_PEARL,
2052     EL_CRYSTAL,
2053     EL_SPRING,
2054     EL_DX_SUPABOMB,
2055     -1
2056   };
2057
2058   static int ep_can_smash_enemies[] =
2059   {
2060     EL_ROCK,
2061     EL_BD_ROCK,
2062     EL_SP_ZONK,
2063     -1
2064   };
2065
2066   static int ep_can_smash_everything[] =
2067   {
2068     EL_ROCK,
2069     EL_BD_ROCK,
2070     EL_SP_ZONK,
2071     -1
2072   };
2073
2074   static int ep_can_explode_by_fire[] =
2075   {
2076     /* same elements as in 'ep_can_explode_impact' */
2077     EL_BOMB,
2078     EL_SP_DISK_ORANGE,
2079     EL_DX_SUPABOMB,
2080
2081     /* same elements as in 'ep_can_explode_smashed' */
2082     EL_SATELLITE,
2083     EL_PIG,
2084     EL_DRAGON,
2085     EL_MOLE,
2086
2087     /* new elements */
2088     EL_DYNAMITE_ACTIVE,
2089     EL_DYNAMITE,
2090     EL_DYNABOMB_PLAYER_1_ACTIVE,
2091     EL_DYNABOMB_PLAYER_2_ACTIVE,
2092     EL_DYNABOMB_PLAYER_3_ACTIVE,
2093     EL_DYNABOMB_PLAYER_4_ACTIVE,
2094     EL_DYNABOMB_INCREASE_NUMBER,
2095     EL_DYNABOMB_INCREASE_SIZE,
2096     EL_DYNABOMB_INCREASE_POWER,
2097     EL_SP_DISK_RED_ACTIVE,
2098     EL_BUG,
2099     EL_PENGUIN,
2100     EL_SP_DISK_RED,
2101     EL_SP_DISK_YELLOW,
2102     EL_SP_SNIKSNAK,
2103     EL_SP_ELECTRON,
2104 #if 0
2105     EL_BLACK_ORB,
2106 #endif
2107     -1
2108   };
2109
2110   static int ep_can_explode_smashed[] =
2111   {
2112     /* same elements as in 'ep_can_explode_impact' */
2113     EL_BOMB,
2114     EL_SP_DISK_ORANGE,
2115     EL_DX_SUPABOMB,
2116
2117     /* new elements */
2118     EL_SATELLITE,
2119     EL_PIG,
2120     EL_DRAGON,
2121     EL_MOLE,
2122     -1
2123   };
2124
2125   static int ep_can_explode_impact[] =
2126   {
2127     EL_BOMB,
2128     EL_SP_DISK_ORANGE,
2129     EL_DX_SUPABOMB,
2130     -1
2131   };
2132
2133   static int ep_walkable_over[] =
2134   {
2135     EL_EMPTY_SPACE,
2136     EL_SP_EMPTY_SPACE,
2137     EL_SOKOBAN_FIELD_EMPTY,
2138     EL_EXIT_OPEN,
2139     EL_SP_EXIT_OPEN,
2140     EL_SP_EXIT_OPENING,
2141     EL_GATE_1,
2142     EL_GATE_2,
2143     EL_GATE_3,
2144     EL_GATE_4,
2145     EL_GATE_1_GRAY,
2146     EL_GATE_2_GRAY,
2147     EL_GATE_3_GRAY,
2148     EL_GATE_4_GRAY,
2149     EL_PENGUIN,
2150     EL_PIG,
2151     EL_DRAGON,
2152     -1
2153   };
2154
2155   static int ep_walkable_inside[] =
2156   {
2157     EL_TUBE_ANY,
2158     EL_TUBE_VERTICAL,
2159     EL_TUBE_HORIZONTAL,
2160     EL_TUBE_VERTICAL_LEFT,
2161     EL_TUBE_VERTICAL_RIGHT,
2162     EL_TUBE_HORIZONTAL_UP,
2163     EL_TUBE_HORIZONTAL_DOWN,
2164     EL_TUBE_LEFT_UP,
2165     EL_TUBE_LEFT_DOWN,
2166     EL_TUBE_RIGHT_UP,
2167     EL_TUBE_RIGHT_DOWN,
2168     -1
2169   };
2170
2171   static int ep_walkable_under[] =
2172   {
2173     -1
2174   };
2175
2176   static int ep_passable_over[] =
2177   {
2178     EL_EM_GATE_1,
2179     EL_EM_GATE_2,
2180     EL_EM_GATE_3,
2181     EL_EM_GATE_4,
2182     EL_EM_GATE_1_GRAY,
2183     EL_EM_GATE_2_GRAY,
2184     EL_EM_GATE_3_GRAY,
2185     EL_EM_GATE_4_GRAY,
2186     EL_SWITCHGATE_OPEN,
2187     EL_TIMEGATE_OPEN,
2188     -1
2189   };
2190
2191   static int ep_passable_inside[] =
2192   {
2193     EL_SP_PORT_LEFT,
2194     EL_SP_PORT_RIGHT,
2195     EL_SP_PORT_UP,
2196     EL_SP_PORT_DOWN,
2197     EL_SP_PORT_HORIZONTAL,
2198     EL_SP_PORT_VERTICAL,
2199     EL_SP_PORT_ANY,
2200     EL_SP_GRAVITY_PORT_LEFT,
2201     EL_SP_GRAVITY_PORT_RIGHT,
2202     EL_SP_GRAVITY_PORT_UP,
2203     EL_SP_GRAVITY_PORT_DOWN,
2204     -1
2205   };
2206
2207   static int ep_passable_under[] =
2208   {
2209     -1
2210   };
2211
2212   static int ep_droppable[] =
2213   {
2214     -1
2215   };
2216
2217   static int ep_can_explode_1x1[] =
2218   {
2219     -1
2220   };
2221
2222   static int ep_pushable[] =
2223   {
2224     EL_ROCK,
2225     EL_BOMB,
2226     EL_DX_SUPABOMB,
2227     EL_NUT,
2228     EL_TIME_ORB_EMPTY,
2229     EL_SP_ZONK,
2230     EL_SP_DISK_ORANGE,
2231     EL_SPRING,
2232     EL_BD_ROCK,
2233     EL_SOKOBAN_OBJECT,
2234     EL_SOKOBAN_FIELD_FULL,
2235     EL_SATELLITE,
2236     EL_SP_DISK_YELLOW,
2237     EL_BALLOON,
2238     -1
2239   };
2240
2241   static int ep_can_explode_cross[] =
2242   {
2243     -1
2244   };
2245
2246   static int ep_protected[] =
2247   {
2248     EL_EM_GATE_1,
2249     EL_EM_GATE_2,
2250     EL_EM_GATE_3,
2251     EL_EM_GATE_4,
2252     EL_EM_GATE_1_GRAY,
2253     EL_EM_GATE_2_GRAY,
2254     EL_EM_GATE_3_GRAY,
2255     EL_EM_GATE_4_GRAY,
2256     EL_SWITCHGATE_OPEN,
2257     EL_TIMEGATE_OPEN,
2258     -1
2259   };
2260
2261   static int ep_throwable[] =
2262   {
2263     -1
2264   };
2265
2266   static int ep_player[] =
2267   {
2268     EL_PLAYER_1,
2269     EL_PLAYER_2,
2270     EL_PLAYER_3,
2271     EL_PLAYER_4,
2272     EL_SP_MURPHY,
2273     EL_SOKOBAN_FIELD_PLAYER,
2274     EL_TRIGGER_PLAYER,
2275     -1
2276   };
2277
2278   static int ep_can_pass_magic_wall[] =
2279   {
2280     EL_ROCK,
2281     EL_BD_ROCK,
2282     EL_EMERALD,
2283     EL_BD_DIAMOND,
2284     EL_EMERALD_YELLOW,
2285     EL_EMERALD_RED,
2286     EL_EMERALD_PURPLE,
2287     EL_DIAMOND,
2288     -1
2289   };
2290
2291   static int ep_switchable[] =
2292   {
2293     EL_ROBOT_WHEEL,
2294     EL_SP_TERMINAL,
2295     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2296     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2297     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2298     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2299     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2300     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2301     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2302     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2303     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2304     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2305     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2306     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2307     EL_SWITCHGATE_SWITCH_UP,
2308     EL_SWITCHGATE_SWITCH_DOWN,
2309     EL_LIGHT_SWITCH,
2310     EL_LIGHT_SWITCH_ACTIVE,
2311     EL_TIMEGATE_SWITCH,
2312     EL_BALLOON_SWITCH_LEFT,
2313     EL_BALLOON_SWITCH_RIGHT,
2314     EL_BALLOON_SWITCH_UP,
2315     EL_BALLOON_SWITCH_DOWN,
2316     EL_BALLOON_SWITCH_ANY,
2317     EL_LAMP,
2318     EL_TIME_ORB_FULL,
2319     -1
2320   };
2321
2322   static int ep_bd_element[] =
2323   {
2324     EL_EMPTY,
2325     EL_SAND,
2326     EL_WALL_SLIPPERY,
2327     EL_BD_WALL,
2328     EL_ROCK,
2329     EL_BD_ROCK,
2330     EL_BD_DIAMOND,
2331     EL_BD_MAGIC_WALL,
2332     EL_EXIT_CLOSED,
2333     EL_EXIT_OPEN,
2334     EL_STEELWALL,
2335     EL_PLAYER_1,
2336     EL_PLAYER_2,
2337     EL_PLAYER_3,
2338     EL_PLAYER_4,
2339     EL_BD_FIREFLY,
2340     EL_BD_FIREFLY_1,
2341     EL_BD_FIREFLY_2,
2342     EL_BD_FIREFLY_3,
2343     EL_BD_FIREFLY_4,
2344     EL_BD_BUTTERFLY,
2345     EL_BD_BUTTERFLY_1,
2346     EL_BD_BUTTERFLY_2,
2347     EL_BD_BUTTERFLY_3,
2348     EL_BD_BUTTERFLY_4,
2349     EL_BD_AMOEBA,
2350     EL_CHAR_QUESTION,
2351     EL_UNKNOWN,
2352     -1
2353   };
2354
2355   static int ep_sp_element[] =
2356   {
2357     /* should always be valid */
2358     EL_EMPTY,
2359
2360     EL_SP_EMPTY,
2361     EL_SP_ZONK,
2362     EL_SP_BASE,
2363     EL_SP_MURPHY,
2364     EL_SP_INFOTRON,
2365     EL_SP_CHIP_SINGLE,
2366     EL_SP_HARDWARE_GRAY,
2367     EL_SP_EXIT_CLOSED,
2368     EL_SP_EXIT_OPEN,
2369     EL_SP_DISK_ORANGE,
2370     EL_SP_PORT_RIGHT,
2371     EL_SP_PORT_DOWN,
2372     EL_SP_PORT_LEFT,
2373     EL_SP_PORT_UP,
2374     EL_SP_GRAVITY_PORT_RIGHT,
2375     EL_SP_GRAVITY_PORT_DOWN,
2376     EL_SP_GRAVITY_PORT_LEFT,
2377     EL_SP_GRAVITY_PORT_UP,
2378     EL_SP_SNIKSNAK,
2379     EL_SP_DISK_YELLOW,
2380     EL_SP_TERMINAL,
2381     EL_SP_DISK_RED,
2382     EL_SP_PORT_VERTICAL,
2383     EL_SP_PORT_HORIZONTAL,
2384     EL_SP_PORT_ANY,
2385     EL_SP_ELECTRON,
2386     EL_SP_BUGGY_BASE,
2387     EL_SP_CHIP_LEFT,
2388     EL_SP_CHIP_RIGHT,
2389     EL_SP_HARDWARE_BASE_1,
2390     EL_SP_HARDWARE_GREEN,
2391     EL_SP_HARDWARE_BLUE,
2392     EL_SP_HARDWARE_RED,
2393     EL_SP_HARDWARE_YELLOW,
2394     EL_SP_HARDWARE_BASE_2,
2395     EL_SP_HARDWARE_BASE_3,
2396     EL_SP_HARDWARE_BASE_4,
2397     EL_SP_HARDWARE_BASE_5,
2398     EL_SP_HARDWARE_BASE_6,
2399     EL_SP_CHIP_TOP,
2400     EL_SP_CHIP_BOTTOM,
2401     /* additional elements that appeared in newer Supaplex levels */
2402     EL_INVISIBLE_WALL,
2403     /* more than one murphy in a level results in an inactive clone */
2404     EL_SP_MURPHY_CLONE,
2405     /* runtime elements*/
2406     EL_SP_DISK_RED_ACTIVE,
2407     EL_SP_TERMINAL_ACTIVE,
2408     EL_SP_BUGGY_BASE_ACTIVATING,
2409     EL_SP_BUGGY_BASE_ACTIVE,
2410     EL_SP_EXIT_OPENING,
2411     EL_SP_EXIT_CLOSING,
2412     -1
2413   };
2414
2415   static int ep_sb_element[] =
2416   {
2417     EL_EMPTY,
2418     EL_STEELWALL,
2419     EL_SOKOBAN_OBJECT,
2420     EL_SOKOBAN_FIELD_EMPTY,
2421     EL_SOKOBAN_FIELD_FULL,
2422     EL_SOKOBAN_FIELD_PLAYER,
2423     EL_PLAYER_1,
2424     EL_PLAYER_2,
2425     EL_PLAYER_3,
2426     EL_PLAYER_4,
2427     EL_INVISIBLE_STEELWALL,
2428     -1
2429   };
2430
2431   static int ep_sp_buggy_base[] =
2432   {
2433     EL_SP_BUGGY_BASE,
2434     EL_SP_BUGGY_BASE_ACTIVATING,
2435     EL_SP_BUGGY_BASE_ACTIVE,
2436     -1
2437   };
2438
2439   static int ep_gem[] =
2440   {
2441     EL_BD_DIAMOND,
2442     EL_EMERALD,
2443     EL_EMERALD_YELLOW,
2444     EL_EMERALD_RED,
2445     EL_EMERALD_PURPLE,
2446     EL_DIAMOND,
2447     -1
2448   };
2449
2450   static int ep_food_dark_yamyam[] =
2451   {
2452     EL_SAND,
2453     EL_BUG,
2454     EL_SPACESHIP,
2455     EL_BD_BUTTERFLY,
2456     EL_BD_FIREFLY,
2457     EL_YAMYAM,
2458     EL_ROBOT,
2459     EL_PACMAN,
2460     EL_AMOEBA_DROP,
2461     EL_AMOEBA_DEAD,
2462     EL_AMOEBA_WET,
2463     EL_AMOEBA_DRY,
2464     EL_AMOEBA_FULL,
2465     EL_BD_AMOEBA,
2466     EL_EMERALD,
2467     EL_BD_DIAMOND,
2468     EL_EMERALD_YELLOW,
2469     EL_EMERALD_RED,
2470     EL_EMERALD_PURPLE,
2471     EL_DIAMOND,
2472     EL_PEARL,
2473     EL_CRYSTAL,
2474     -1
2475   };
2476
2477   static int ep_food_penguin[] =
2478   {
2479     EL_EMERALD,
2480     EL_BD_DIAMOND,
2481     EL_EMERALD_YELLOW,
2482     EL_EMERALD_RED,
2483     EL_EMERALD_PURPLE,
2484     EL_DIAMOND,
2485     EL_PEARL,
2486     EL_CRYSTAL,
2487     -1
2488   };
2489
2490   static int ep_food_pig[] =
2491   {
2492     EL_EMERALD,
2493     EL_BD_DIAMOND,
2494     EL_EMERALD_YELLOW,
2495     EL_EMERALD_RED,
2496     EL_EMERALD_PURPLE,
2497     EL_DIAMOND,
2498     -1
2499   };
2500
2501   static int ep_historic_wall[] =
2502   {
2503     EL_STEELWALL,
2504     EL_GATE_1,
2505     EL_GATE_2,
2506     EL_GATE_3,
2507     EL_GATE_4,
2508     EL_GATE_1_GRAY,
2509     EL_GATE_2_GRAY,
2510     EL_GATE_3_GRAY,
2511     EL_GATE_4_GRAY,
2512     EL_EM_GATE_1,
2513     EL_EM_GATE_2,
2514     EL_EM_GATE_3,
2515     EL_EM_GATE_4,
2516     EL_EM_GATE_1_GRAY,
2517     EL_EM_GATE_2_GRAY,
2518     EL_EM_GATE_3_GRAY,
2519     EL_EM_GATE_4_GRAY,
2520     EL_EXIT_CLOSED,
2521     EL_EXIT_OPENING,
2522     EL_EXIT_OPEN,
2523     EL_WALL,
2524     EL_WALL_SLIPPERY,
2525     EL_EXPANDABLE_WALL,
2526     EL_EXPANDABLE_WALL_HORIZONTAL,
2527     EL_EXPANDABLE_WALL_VERTICAL,
2528     EL_EXPANDABLE_WALL_ANY,
2529     EL_EXPANDABLE_WALL_GROWING,
2530     EL_BD_WALL,
2531     EL_SP_CHIP_SINGLE,
2532     EL_SP_CHIP_LEFT,
2533     EL_SP_CHIP_RIGHT,
2534     EL_SP_CHIP_TOP,
2535     EL_SP_CHIP_BOTTOM,
2536     EL_SP_HARDWARE_GRAY,
2537     EL_SP_HARDWARE_GREEN,
2538     EL_SP_HARDWARE_BLUE,
2539     EL_SP_HARDWARE_RED,
2540     EL_SP_HARDWARE_YELLOW,
2541     EL_SP_HARDWARE_BASE_1,
2542     EL_SP_HARDWARE_BASE_2,
2543     EL_SP_HARDWARE_BASE_3,
2544     EL_SP_HARDWARE_BASE_4,
2545     EL_SP_HARDWARE_BASE_5,
2546     EL_SP_HARDWARE_BASE_6,
2547     EL_SP_TERMINAL,
2548     EL_SP_TERMINAL_ACTIVE,
2549     EL_SP_EXIT_CLOSED,
2550     EL_SP_EXIT_OPEN,
2551     EL_INVISIBLE_STEELWALL,
2552     EL_INVISIBLE_STEELWALL_ACTIVE,
2553     EL_INVISIBLE_WALL,
2554     EL_INVISIBLE_WALL_ACTIVE,
2555     EL_STEELWALL_SLIPPERY,
2556     EL_EMC_STEELWALL_1,
2557     EL_EMC_STEELWALL_2,
2558     EL_EMC_STEELWALL_3,
2559     EL_EMC_STEELWALL_4,
2560     EL_EMC_WALL_1,
2561     EL_EMC_WALL_2,
2562     EL_EMC_WALL_3,
2563     EL_EMC_WALL_4,
2564     EL_EMC_WALL_5,
2565     EL_EMC_WALL_6,
2566     EL_EMC_WALL_7,
2567     EL_EMC_WALL_8,
2568     -1
2569   };
2570
2571   static int ep_historic_solid[] =
2572   {
2573     EL_WALL,
2574     EL_EXPANDABLE_WALL,
2575     EL_EXPANDABLE_WALL_HORIZONTAL,
2576     EL_EXPANDABLE_WALL_VERTICAL,
2577     EL_EXPANDABLE_WALL_ANY,
2578     EL_BD_WALL,
2579     EL_WALL_SLIPPERY,
2580     EL_EXIT_CLOSED,
2581     EL_EXIT_OPENING,
2582     EL_EXIT_OPEN,
2583     EL_AMOEBA_DEAD,
2584     EL_AMOEBA_WET,
2585     EL_AMOEBA_DRY,
2586     EL_AMOEBA_FULL,
2587     EL_BD_AMOEBA,
2588     EL_QUICKSAND_EMPTY,
2589     EL_QUICKSAND_FULL,
2590     EL_QUICKSAND_FILLING,
2591     EL_QUICKSAND_EMPTYING,
2592     EL_MAGIC_WALL,
2593     EL_MAGIC_WALL_ACTIVE,
2594     EL_MAGIC_WALL_EMPTYING,
2595     EL_MAGIC_WALL_FILLING,
2596     EL_MAGIC_WALL_FULL,
2597     EL_MAGIC_WALL_DEAD,
2598     EL_BD_MAGIC_WALL,
2599     EL_BD_MAGIC_WALL_ACTIVE,
2600     EL_BD_MAGIC_WALL_EMPTYING,
2601     EL_BD_MAGIC_WALL_FULL,
2602     EL_BD_MAGIC_WALL_FILLING,
2603     EL_BD_MAGIC_WALL_DEAD,
2604     EL_GAME_OF_LIFE,
2605     EL_BIOMAZE,
2606     EL_SP_CHIP_SINGLE,
2607     EL_SP_CHIP_LEFT,
2608     EL_SP_CHIP_RIGHT,
2609     EL_SP_CHIP_TOP,
2610     EL_SP_CHIP_BOTTOM,
2611     EL_SP_TERMINAL,
2612     EL_SP_TERMINAL_ACTIVE,
2613     EL_SP_EXIT_CLOSED,
2614     EL_SP_EXIT_OPEN,
2615     EL_INVISIBLE_WALL,
2616     EL_INVISIBLE_WALL_ACTIVE,
2617     EL_SWITCHGATE_SWITCH_UP,
2618     EL_SWITCHGATE_SWITCH_DOWN,
2619     EL_TIMEGATE_SWITCH,
2620     EL_TIMEGATE_SWITCH_ACTIVE,
2621     EL_EMC_WALL_1,
2622     EL_EMC_WALL_2,
2623     EL_EMC_WALL_3,
2624     EL_EMC_WALL_4,
2625     EL_EMC_WALL_5,
2626     EL_EMC_WALL_6,
2627     EL_EMC_WALL_7,
2628     EL_EMC_WALL_8,
2629     EL_WALL_PEARL,
2630     EL_WALL_CRYSTAL,
2631
2632     /* the following elements are a direct copy of "indestructible" elements,
2633        except "EL_ACID", which is "indestructible", but not "solid"! */
2634 #if 0
2635     EL_ACID,
2636 #endif
2637     EL_STEELWALL,
2638     EL_ACID_POOL_TOPLEFT,
2639     EL_ACID_POOL_TOPRIGHT,
2640     EL_ACID_POOL_BOTTOMLEFT,
2641     EL_ACID_POOL_BOTTOM,
2642     EL_ACID_POOL_BOTTOMRIGHT,
2643     EL_SP_HARDWARE_GRAY,
2644     EL_SP_HARDWARE_GREEN,
2645     EL_SP_HARDWARE_BLUE,
2646     EL_SP_HARDWARE_RED,
2647     EL_SP_HARDWARE_YELLOW,
2648     EL_SP_HARDWARE_BASE_1,
2649     EL_SP_HARDWARE_BASE_2,
2650     EL_SP_HARDWARE_BASE_3,
2651     EL_SP_HARDWARE_BASE_4,
2652     EL_SP_HARDWARE_BASE_5,
2653     EL_SP_HARDWARE_BASE_6,
2654     EL_INVISIBLE_STEELWALL,
2655     EL_INVISIBLE_STEELWALL_ACTIVE,
2656     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2657     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2658     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2659     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2660     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2661     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2662     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2663     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2664     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2665     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2666     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2667     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2668     EL_LIGHT_SWITCH,
2669     EL_LIGHT_SWITCH_ACTIVE,
2670     EL_SIGN_EXCLAMATION,
2671     EL_SIGN_RADIOACTIVITY,
2672     EL_SIGN_STOP,
2673     EL_SIGN_WHEELCHAIR,
2674     EL_SIGN_PARKING,
2675     EL_SIGN_ONEWAY,
2676     EL_SIGN_HEART,
2677     EL_SIGN_TRIANGLE,
2678     EL_SIGN_ROUND,
2679     EL_SIGN_EXIT,
2680     EL_SIGN_YINYANG,
2681     EL_SIGN_OTHER,
2682     EL_STEELWALL_SLIPPERY,
2683     EL_EMC_STEELWALL_1,
2684     EL_EMC_STEELWALL_2,
2685     EL_EMC_STEELWALL_3,
2686     EL_EMC_STEELWALL_4,
2687     EL_CRYSTAL,
2688     EL_GATE_1,
2689     EL_GATE_2,
2690     EL_GATE_3,
2691     EL_GATE_4,
2692     EL_GATE_1_GRAY,
2693     EL_GATE_2_GRAY,
2694     EL_GATE_3_GRAY,
2695     EL_GATE_4_GRAY,
2696     EL_EM_GATE_1,
2697     EL_EM_GATE_2,
2698     EL_EM_GATE_3,
2699     EL_EM_GATE_4,
2700     EL_EM_GATE_1_GRAY,
2701     EL_EM_GATE_2_GRAY,
2702     EL_EM_GATE_3_GRAY,
2703     EL_EM_GATE_4_GRAY,
2704     EL_SWITCHGATE_OPEN,
2705     EL_SWITCHGATE_OPENING,
2706     EL_SWITCHGATE_CLOSED,
2707     EL_SWITCHGATE_CLOSING,
2708     EL_TIMEGATE_OPEN,
2709     EL_TIMEGATE_OPENING,
2710     EL_TIMEGATE_CLOSED,
2711     EL_TIMEGATE_CLOSING,
2712     EL_TUBE_ANY,
2713     EL_TUBE_VERTICAL,
2714     EL_TUBE_HORIZONTAL,
2715     EL_TUBE_VERTICAL_LEFT,
2716     EL_TUBE_VERTICAL_RIGHT,
2717     EL_TUBE_HORIZONTAL_UP,
2718     EL_TUBE_HORIZONTAL_DOWN,
2719     EL_TUBE_LEFT_UP,
2720     EL_TUBE_LEFT_DOWN,
2721     EL_TUBE_RIGHT_UP,
2722     EL_TUBE_RIGHT_DOWN,
2723     -1
2724   };
2725
2726   static int ep_classic_enemy[] =
2727   {
2728     EL_BUG,
2729     EL_SPACESHIP,
2730     EL_BD_BUTTERFLY,
2731     EL_BD_FIREFLY,
2732
2733     EL_YAMYAM,
2734     EL_DARK_YAMYAM,
2735     EL_ROBOT,
2736     EL_PACMAN,
2737     EL_SP_SNIKSNAK,
2738     EL_SP_ELECTRON,
2739     -1
2740   };
2741
2742   static int ep_belt[] =
2743   {
2744     EL_CONVEYOR_BELT_1_LEFT,
2745     EL_CONVEYOR_BELT_1_MIDDLE,
2746     EL_CONVEYOR_BELT_1_RIGHT,
2747     EL_CONVEYOR_BELT_2_LEFT,
2748     EL_CONVEYOR_BELT_2_MIDDLE,
2749     EL_CONVEYOR_BELT_2_RIGHT,
2750     EL_CONVEYOR_BELT_3_LEFT,
2751     EL_CONVEYOR_BELT_3_MIDDLE,
2752     EL_CONVEYOR_BELT_3_RIGHT,
2753     EL_CONVEYOR_BELT_4_LEFT,
2754     EL_CONVEYOR_BELT_4_MIDDLE,
2755     EL_CONVEYOR_BELT_4_RIGHT,
2756     -1
2757   };
2758
2759   static int ep_belt_active[] =
2760   {
2761     EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
2762     EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
2763     EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
2764     EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
2765     EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
2766     EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
2767     EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
2768     EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
2769     EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
2770     EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
2771     EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
2772     EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
2773     -1
2774   };
2775
2776   static int ep_belt_switch[] =
2777   {
2778     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2779     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2780     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2781     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2782     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2783     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2784     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2785     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2786     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2787     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2788     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2789     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2790     -1
2791   };
2792
2793   static int ep_tube[] =
2794   {
2795     EL_TUBE_LEFT_UP,
2796     EL_TUBE_LEFT_DOWN,
2797     EL_TUBE_RIGHT_UP,
2798     EL_TUBE_RIGHT_DOWN,
2799     EL_TUBE_HORIZONTAL,
2800     EL_TUBE_HORIZONTAL_UP,
2801     EL_TUBE_HORIZONTAL_DOWN,
2802     EL_TUBE_VERTICAL,
2803     EL_TUBE_VERTICAL_LEFT,
2804     EL_TUBE_VERTICAL_RIGHT,
2805     EL_TUBE_ANY,
2806     -1
2807   };
2808
2809   static int ep_keygate[] =
2810   {
2811     EL_GATE_1,
2812     EL_GATE_2,
2813     EL_GATE_3,
2814     EL_GATE_4,
2815     EL_GATE_1_GRAY,
2816     EL_GATE_2_GRAY,
2817     EL_GATE_3_GRAY,
2818     EL_GATE_4_GRAY,
2819     EL_EM_GATE_1,
2820     EL_EM_GATE_2,
2821     EL_EM_GATE_3,
2822     EL_EM_GATE_4,
2823     EL_EM_GATE_1_GRAY,
2824     EL_EM_GATE_2_GRAY,
2825     EL_EM_GATE_3_GRAY,
2826     EL_EM_GATE_4_GRAY,
2827     -1
2828   };
2829
2830   static int ep_amoeboid[] =
2831   {
2832     EL_AMOEBA_DEAD,
2833     EL_AMOEBA_WET,
2834     EL_AMOEBA_DRY,
2835     EL_AMOEBA_FULL,
2836     EL_BD_AMOEBA,
2837     -1
2838   };
2839
2840   static int ep_amoebalive[] =
2841   {
2842     EL_AMOEBA_WET,
2843     EL_AMOEBA_DRY,
2844     EL_AMOEBA_FULL,
2845     EL_BD_AMOEBA,
2846     -1
2847   };
2848
2849   static int ep_has_content[] =
2850   {
2851     EL_YAMYAM,
2852     EL_AMOEBA_WET,
2853     EL_AMOEBA_DRY,
2854     EL_AMOEBA_FULL,
2855     EL_BD_AMOEBA,
2856     -1
2857   };
2858
2859   static int ep_can_turn_each_move[] =
2860   {
2861     /* !!! do something with this one !!! */
2862     -1
2863   };
2864
2865   static int ep_can_grow[] =
2866   {
2867     EL_BD_AMOEBA,
2868     EL_AMOEBA_DROP,
2869     EL_AMOEBA_WET,
2870     EL_AMOEBA_DRY,
2871     EL_AMOEBA_FULL,
2872     EL_GAME_OF_LIFE,
2873     EL_BIOMAZE,
2874     -1
2875   };
2876
2877   static int ep_active_bomb[] =
2878   {
2879     EL_DYNAMITE_ACTIVE,
2880     EL_DYNABOMB_PLAYER_1_ACTIVE,
2881     EL_DYNABOMB_PLAYER_2_ACTIVE,
2882     EL_DYNABOMB_PLAYER_3_ACTIVE,
2883     EL_DYNABOMB_PLAYER_4_ACTIVE,
2884     EL_SP_DISK_RED_ACTIVE,
2885     -1
2886   };
2887
2888   static int ep_inactive[] =
2889   {
2890     EL_EMPTY,
2891     EL_SAND,
2892     EL_WALL,
2893     EL_BD_WALL,
2894     EL_WALL_SLIPPERY,
2895     EL_STEELWALL,
2896     EL_AMOEBA_DEAD,
2897     EL_QUICKSAND_EMPTY,
2898     EL_STONEBLOCK,
2899     EL_ROBOT_WHEEL,
2900     EL_KEY_1,
2901     EL_KEY_2,
2902     EL_KEY_3,
2903     EL_KEY_4,
2904     EL_EM_KEY_1,
2905     EL_EM_KEY_2,
2906     EL_EM_KEY_3,
2907     EL_EM_KEY_4,
2908     EL_GATE_1,
2909     EL_GATE_2,
2910     EL_GATE_3,
2911     EL_GATE_4,
2912     EL_GATE_1_GRAY,
2913     EL_GATE_2_GRAY,
2914     EL_GATE_3_GRAY,
2915     EL_GATE_4_GRAY,
2916     EL_EM_GATE_1,
2917     EL_EM_GATE_2,
2918     EL_EM_GATE_3,
2919     EL_EM_GATE_4,
2920     EL_EM_GATE_1_GRAY,
2921     EL_EM_GATE_2_GRAY,
2922     EL_EM_GATE_3_GRAY,
2923     EL_EM_GATE_4_GRAY,
2924     EL_DYNAMITE,
2925     EL_INVISIBLE_STEELWALL,
2926     EL_INVISIBLE_WALL,
2927     EL_INVISIBLE_SAND,
2928     EL_LAMP,
2929     EL_LAMP_ACTIVE,
2930     EL_WALL_EMERALD,
2931     EL_WALL_DIAMOND,
2932     EL_WALL_BD_DIAMOND,
2933     EL_WALL_EMERALD_YELLOW,
2934     EL_DYNABOMB_INCREASE_NUMBER,
2935     EL_DYNABOMB_INCREASE_SIZE,
2936     EL_DYNABOMB_INCREASE_POWER,
2937 #if 0
2938     EL_SOKOBAN_OBJECT,
2939 #endif
2940     EL_SOKOBAN_FIELD_EMPTY,
2941     EL_SOKOBAN_FIELD_FULL,
2942     EL_WALL_EMERALD_RED,
2943     EL_WALL_EMERALD_PURPLE,
2944     EL_ACID_POOL_TOPLEFT,
2945     EL_ACID_POOL_TOPRIGHT,
2946     EL_ACID_POOL_BOTTOMLEFT,
2947     EL_ACID_POOL_BOTTOM,
2948     EL_ACID_POOL_BOTTOMRIGHT,
2949     EL_MAGIC_WALL,
2950     EL_MAGIC_WALL_DEAD,
2951     EL_BD_MAGIC_WALL,
2952     EL_BD_MAGIC_WALL_DEAD,
2953     EL_AMOEBA_TO_DIAMOND,
2954     EL_BLOCKED,
2955     EL_SP_EMPTY,
2956     EL_SP_BASE,
2957     EL_SP_PORT_RIGHT,
2958     EL_SP_PORT_DOWN,
2959     EL_SP_PORT_LEFT,
2960     EL_SP_PORT_UP,
2961     EL_SP_GRAVITY_PORT_RIGHT,
2962     EL_SP_GRAVITY_PORT_DOWN,
2963     EL_SP_GRAVITY_PORT_LEFT,
2964     EL_SP_GRAVITY_PORT_UP,
2965     EL_SP_PORT_HORIZONTAL,
2966     EL_SP_PORT_VERTICAL,
2967     EL_SP_PORT_ANY,
2968     EL_SP_DISK_RED,
2969 #if 0
2970     EL_SP_DISK_YELLOW,
2971 #endif
2972     EL_SP_CHIP_SINGLE,
2973     EL_SP_CHIP_LEFT,
2974     EL_SP_CHIP_RIGHT,
2975     EL_SP_CHIP_TOP,
2976     EL_SP_CHIP_BOTTOM,
2977     EL_SP_HARDWARE_GRAY,
2978     EL_SP_HARDWARE_GREEN,
2979     EL_SP_HARDWARE_BLUE,
2980     EL_SP_HARDWARE_RED,
2981     EL_SP_HARDWARE_YELLOW,
2982     EL_SP_HARDWARE_BASE_1,
2983     EL_SP_HARDWARE_BASE_2,
2984     EL_SP_HARDWARE_BASE_3,
2985     EL_SP_HARDWARE_BASE_4,
2986     EL_SP_HARDWARE_BASE_5,
2987     EL_SP_HARDWARE_BASE_6,
2988     EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2989     EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2990     EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2991     EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2992     EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2993     EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2994     EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2995     EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2996     EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2997     EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2998     EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2999     EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
3000     EL_SIGN_EXCLAMATION,
3001     EL_SIGN_RADIOACTIVITY,
3002     EL_SIGN_STOP,
3003     EL_SIGN_WHEELCHAIR,
3004     EL_SIGN_PARKING,
3005     EL_SIGN_ONEWAY,
3006     EL_SIGN_HEART,
3007     EL_SIGN_TRIANGLE,
3008     EL_SIGN_ROUND,
3009     EL_SIGN_EXIT,
3010     EL_SIGN_YINYANG,
3011     EL_SIGN_OTHER,
3012     EL_STEELWALL_SLIPPERY,
3013     EL_EMC_STEELWALL_1,
3014     EL_EMC_STEELWALL_2,
3015     EL_EMC_STEELWALL_3,
3016     EL_EMC_STEELWALL_4,
3017     EL_EMC_WALL_1,
3018     EL_EMC_WALL_2,
3019     EL_EMC_WALL_3,
3020     EL_EMC_WALL_4,
3021     EL_EMC_WALL_5,
3022     EL_EMC_WALL_6,
3023     EL_EMC_WALL_7,
3024     EL_EMC_WALL_8,
3025     -1
3026   };
3027
3028   static int ep_em_slippery_wall[] =
3029   {
3030     -1
3031   };
3032
3033   static int ep_gfx_crumbled[] =
3034   {
3035     EL_SAND,
3036     EL_LANDMINE,
3037     EL_TRAP,
3038     EL_TRAP_ACTIVE,
3039     -1
3040   };
3041
3042   static struct
3043   {
3044     int *elements;
3045     int property;
3046   } element_properties[] =
3047   {
3048     { ep_diggable,              EP_DIGGABLE             },
3049     { ep_collectible_only,      EP_COLLECTIBLE_ONLY     },
3050     { ep_dont_run_into,         EP_DONT_RUN_INTO        },
3051     { ep_dont_collide_with,     EP_DONT_COLLIDE_WITH    },
3052     { ep_dont_touch,            EP_DONT_TOUCH           },
3053     { ep_indestructible,        EP_INDESTRUCTIBLE       },
3054     { ep_slippery,              EP_SLIPPERY             },
3055     { ep_can_change,            EP_CAN_CHANGE           },
3056     { ep_can_move,              EP_CAN_MOVE             },
3057     { ep_can_fall,              EP_CAN_FALL             },
3058     { ep_can_smash_player,      EP_CAN_SMASH_PLAYER     },
3059     { ep_can_smash_enemies,     EP_CAN_SMASH_ENEMIES    },
3060     { ep_can_smash_everything,  EP_CAN_SMASH_EVERYTHING },
3061     { ep_can_explode_by_fire,   EP_CAN_EXPLODE_BY_FIRE  },
3062     { ep_can_explode_smashed,   EP_CAN_EXPLODE_SMASHED  },
3063     { ep_can_explode_impact,    EP_CAN_EXPLODE_IMPACT   },
3064     { ep_walkable_over,         EP_WALKABLE_OVER        },
3065     { ep_walkable_inside,       EP_WALKABLE_INSIDE      },
3066     { ep_walkable_under,        EP_WALKABLE_UNDER       },
3067     { ep_passable_over,         EP_PASSABLE_OVER        },
3068     { ep_passable_inside,       EP_PASSABLE_INSIDE      },
3069     { ep_passable_under,        EP_PASSABLE_UNDER       },
3070     { ep_droppable,             EP_DROPPABLE            },
3071     { ep_can_explode_1x1,       EP_CAN_EXPLODE_1X1      },
3072     { ep_pushable,              EP_PUSHABLE             },
3073     { ep_can_explode_cross,     EP_CAN_EXPLODE_CROSS    },
3074     { ep_protected,             EP_PROTECTED            },
3075     { ep_throwable,             EP_THROWABLE            },
3076
3077     { ep_player,                EP_PLAYER               },
3078     { ep_can_pass_magic_wall,   EP_CAN_PASS_MAGIC_WALL  },
3079     { ep_switchable,            EP_SWITCHABLE           },
3080     { ep_bd_element,            EP_BD_ELEMENT           },
3081     { ep_sp_element,            EP_SP_ELEMENT           },
3082     { ep_sb_element,            EP_SB_ELEMENT           },
3083     { ep_sp_buggy_base,         EP_SP_BUGGY_BASE        },
3084     { ep_gem,                   EP_GEM                  },
3085     { ep_food_dark_yamyam,      EP_FOOD_DARK_YAMYAM     },
3086     { ep_food_penguin,          EP_FOOD_PENGUIN         },
3087     { ep_food_pig,              EP_FOOD_PIG             },
3088     { ep_historic_wall,         EP_HISTORIC_WALL        },
3089     { ep_historic_solid,        EP_HISTORIC_SOLID       },
3090     { ep_classic_enemy,         EP_CLASSIC_ENEMY        },
3091     { ep_belt,                  EP_BELT                 },
3092     { ep_belt_active,           EP_BELT_ACTIVE          },
3093     { ep_belt_switch,           EP_BELT_SWITCH          },
3094     { ep_tube,                  EP_TUBE                 },
3095     { ep_keygate,               EP_KEYGATE              },
3096     { ep_amoeboid,              EP_AMOEBOID             },
3097     { ep_amoebalive,            EP_AMOEBALIVE           },
3098     { ep_has_content,           EP_HAS_CONTENT          },
3099     { ep_can_turn_each_move,    EP_CAN_TURN_EACH_MOVE   },
3100     { ep_can_grow,              EP_CAN_GROW             },
3101     { ep_active_bomb,           EP_ACTIVE_BOMB          },
3102     { ep_inactive,              EP_INACTIVE             },
3103
3104     { ep_em_slippery_wall,      EP_EM_SLIPPERY_WALL     },
3105
3106     { ep_gfx_crumbled,          EP_GFX_CRUMBLED         },
3107
3108     { NULL,                     -1                      }
3109   };
3110
3111   static int copy_properties[][5] =
3112   {
3113     {
3114       EL_BUG,
3115       EL_BUG_LEFT,              EL_BUG_RIGHT,
3116       EL_BUG_UP,                EL_BUG_DOWN
3117     },
3118     {
3119       EL_SPACESHIP,
3120       EL_SPACESHIP_LEFT,        EL_SPACESHIP_RIGHT,
3121       EL_SPACESHIP_UP,          EL_SPACESHIP_DOWN
3122     },
3123     {
3124       EL_BD_BUTTERFLY,
3125       EL_BD_BUTTERFLY_LEFT,     EL_BD_BUTTERFLY_RIGHT,
3126       EL_BD_BUTTERFLY_UP,       EL_BD_BUTTERFLY_DOWN
3127     },
3128     {
3129       EL_BD_FIREFLY,
3130       EL_BD_FIREFLY_LEFT,       EL_BD_FIREFLY_RIGHT,
3131       EL_BD_FIREFLY_UP,         EL_BD_FIREFLY_DOWN
3132     },
3133     {
3134       EL_PACMAN,
3135       EL_PACMAN_LEFT,           EL_PACMAN_RIGHT,
3136       EL_PACMAN_UP,             EL_PACMAN_DOWN
3137     },
3138     {
3139       EL_MOLE,
3140       EL_MOLE_LEFT,             EL_MOLE_RIGHT,
3141       EL_MOLE_UP,               EL_MOLE_DOWN
3142     },
3143     {
3144       -1,
3145       -1, -1, -1, -1
3146     }
3147   };
3148
3149   int i, j, k;
3150
3151   /* always start with reliable default values (element has no properties) */
3152   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3153     for (j = 0; j < NUM_ELEMENT_PROPERTIES; j++)
3154       SET_PROPERTY(i, j, FALSE);
3155
3156   /* set all base element properties from above array definitions */
3157   for (i = 0; element_properties[i].elements != NULL; i++)
3158     for (j = 0; (element_properties[i].elements)[j] != -1; j++)
3159       SET_PROPERTY((element_properties[i].elements)[j],
3160                    element_properties[i].property, TRUE);
3161
3162   /* copy properties to some elements that are only stored in level file */
3163   for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
3164     for (j = 0; copy_properties[j][0] != -1; j++)
3165       if (HAS_PROPERTY(copy_properties[j][0], i))
3166         for (k = 1; k <= 4; k++)
3167           SET_PROPERTY(copy_properties[j][k], i, TRUE);
3168 }
3169
3170 void InitElementPropertiesEngine(int engine_version)
3171 {
3172 #if 0
3173   static int active_properties[] =
3174   {
3175     EP_AMOEBALIVE,
3176     EP_AMOEBOID,
3177     EP_PFORTE,
3178     EP_DONT_COLLIDE_WITH,
3179     EP_MAUER,
3180     EP_CAN_FALL,
3181     EP_CAN_SMASH,
3182     EP_CAN_PASS_MAGIC_WALL,
3183     EP_CAN_MOVE,
3184     EP_DONT_TOUCH,
3185     EP_DONT_RUN_INTO,
3186     EP_GEM,
3187     EP_CAN_EXPLODE_BY_FIRE,
3188     EP_PUSHABLE,
3189     EP_PLAYER,
3190     EP_HAS_CONTENT,
3191     EP_DIGGABLE,
3192     EP_PASSABLE_INSIDE,
3193     EP_OVER_PLAYER,
3194     EP_ACTIVE_BOMB,
3195
3196     EP_BELT,
3197     EP_BELT_ACTIVE,
3198     EP_BELT_SWITCH,
3199     EP_WALKABLE_UNDER,
3200     EP_EM_SLIPPERY_WALL,
3201   };
3202 #endif
3203
3204   static int no_wall_properties[] =
3205   {
3206     EP_DIGGABLE,
3207     EP_COLLECTIBLE_ONLY,
3208     EP_DONT_RUN_INTO,
3209     EP_DONT_COLLIDE_WITH,
3210     EP_CAN_MOVE,
3211     EP_CAN_FALL,
3212     EP_CAN_SMASH_PLAYER,
3213     EP_CAN_SMASH_ENEMIES,
3214     EP_CAN_SMASH_EVERYTHING,
3215     EP_PUSHABLE,
3216
3217     EP_PLAYER,
3218     EP_GEM,
3219     EP_FOOD_DARK_YAMYAM,
3220     EP_FOOD_PENGUIN,
3221     EP_BELT,
3222     EP_BELT_ACTIVE,
3223     EP_TUBE,
3224     EP_AMOEBOID,
3225     EP_AMOEBALIVE,
3226     EP_ACTIVE_BOMB,
3227
3228     EP_ACCESSIBLE,
3229
3230     -1
3231   };
3232
3233   int i, j;
3234
3235 #if 0
3236   InitElementPropertiesStatic();
3237 #endif
3238
3239   /* important: after initialization in InitElementPropertiesStatic(), the
3240      elements are not again initialized to a default value; therefore all
3241      changes have to make sure that they leave the element with a defined
3242      property (which means that conditional property changes must be set to
3243      a reliable default value before) */
3244
3245   /* set all special, combined or engine dependent element properties */
3246   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3247   {
3248 #if 0
3249     for (j = EP_ACCESSIBLE_OVER; j < NUM_ELEMENT_PROPERTIES; j++)
3250       SET_PROPERTY(i, j, FALSE);
3251 #endif
3252
3253     /* ---------- INACTIVE ------------------------------------------------- */
3254     SET_PROPERTY(i, EP_INACTIVE, (i >= EL_CHAR_START && i <= EL_CHAR_END));
3255
3256     /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
3257     SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) ||
3258                                   IS_WALKABLE_INSIDE(i) ||
3259                                   IS_WALKABLE_UNDER(i)));
3260
3261     SET_PROPERTY(i, EP_PASSABLE, (IS_PASSABLE_OVER(i) ||
3262                                   IS_PASSABLE_INSIDE(i) ||
3263                                   IS_PASSABLE_UNDER(i)));
3264
3265     SET_PROPERTY(i, EP_ACCESSIBLE_OVER, (IS_WALKABLE_OVER(i) ||
3266                                          IS_PASSABLE_OVER(i)));
3267
3268     SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, (IS_WALKABLE_INSIDE(i) ||
3269                                            IS_PASSABLE_INSIDE(i)));
3270
3271     SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, (IS_WALKABLE_UNDER(i) ||
3272                                           IS_PASSABLE_UNDER(i)));
3273
3274     SET_PROPERTY(i, EP_ACCESSIBLE, (IS_WALKABLE(i) ||
3275                                     IS_PASSABLE(i)));
3276
3277     /* ---------- COLLECTIBLE ---------------------------------------------- */
3278     SET_PROPERTY(i, EP_COLLECTIBLE, (IS_COLLECTIBLE_ONLY(i) ||
3279                                      IS_DROPPABLE(i) ||
3280                                      IS_THROWABLE(i)));
3281
3282     /* ---------- SNAPPABLE ------------------------------------------------ */
3283     SET_PROPERTY(i, EP_SNAPPABLE, (IS_DIGGABLE(i) ||
3284                                    IS_COLLECTIBLE(i) ||
3285                                    IS_SWITCHABLE(i) ||
3286                                    i == EL_BD_ROCK));
3287
3288     /* ---------- WALL ----------------------------------------------------- */
3289     SET_PROPERTY(i, EP_WALL, TRUE);     /* default: element is wall */
3290
3291     for (j = 0; no_wall_properties[j] != -1; j++)
3292       if (HAS_PROPERTY(i, no_wall_properties[j]) ||
3293           i >= EL_FIRST_RUNTIME_UNREAL)
3294         SET_PROPERTY(i, EP_WALL, FALSE);
3295
3296     if (IS_HISTORIC_WALL(i))
3297       SET_PROPERTY(i, EP_WALL, TRUE);
3298
3299     /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */
3300     if (engine_version < VERSION_IDENT(2,2,0,0))
3301       SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i));
3302     else
3303       SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) &&
3304                                              !IS_DIGGABLE(i) &&
3305                                              !IS_COLLECTIBLE(i)));
3306
3307 #if 1
3308     /* ---------- PROTECTED ------------------------------------------------ */
3309     if (IS_ACCESSIBLE_INSIDE(i))
3310       SET_PROPERTY(i, EP_PROTECTED, TRUE);
3311 #endif
3312
3313     /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
3314
3315     if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION)
3316       SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
3317     else
3318       SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_CUSTOM_ELEMENT(i) &&
3319                                             IS_INDESTRUCTIBLE(i)));
3320
3321     /* ---------- EXPLOSION_PROOF ------------------------------------------ */
3322     if (i == EL_FLAMES)
3323       SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE);
3324     else if (engine_version < VERSION_IDENT(2,2,0,0))
3325       SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i));
3326     else
3327 #if 1
3328       SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3329                                            (!IS_WALKABLE(i) ||
3330                                             IS_PROTECTED(i))));
3331 #else
3332 #if 1
3333       SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3334                                            !IS_WALKABLE_OVER(i) &&
3335                                            !IS_WALKABLE_UNDER(i)));
3336 #else
3337       SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3338                                            IS_PROTECTED(i)));
3339 #endif
3340 #endif
3341
3342     if (IS_CUSTOM_ELEMENT(i))
3343     {
3344       /* these are additional properties which are initially false when set */
3345
3346       /* ---------- DONT_COLLIDE_WITH / DONT_RUN_INTO ---------------------- */
3347       if (DONT_TOUCH(i))
3348         SET_PROPERTY(i, EP_DONT_COLLIDE_WITH, TRUE);
3349       if (DONT_COLLIDE_WITH(i))
3350         SET_PROPERTY(i, EP_DONT_RUN_INTO, TRUE);
3351
3352       /* ---------- CAN_SMASH_ENEMIES / CAN_SMASH_PLAYER ------------------- */
3353       if (CAN_SMASH_EVERYTHING(i))
3354         SET_PROPERTY(i, EP_CAN_SMASH_ENEMIES, TRUE);
3355       if (CAN_SMASH_ENEMIES(i))
3356         SET_PROPERTY(i, EP_CAN_SMASH_PLAYER, TRUE);
3357     }
3358
3359     /* ---------- CAN_SMASH ------------------------------------------------ */
3360     SET_PROPERTY(i, EP_CAN_SMASH, (CAN_SMASH_PLAYER(i) ||
3361                                    CAN_SMASH_ENEMIES(i) ||
3362                                    CAN_SMASH_EVERYTHING(i)));
3363
3364     /* ---------- CAN_EXPLODE ---------------------------------------------- */
3365     SET_PROPERTY(i, EP_CAN_EXPLODE, (CAN_EXPLODE_BY_FIRE(i) ||
3366                                      CAN_EXPLODE_SMASHED(i) ||
3367                                      CAN_EXPLODE_IMPACT(i)));
3368
3369     /* ---------- CAN_EXPLODE_3X3 ------------------------------------------ */
3370     SET_PROPERTY(i, EP_CAN_EXPLODE_3X3, (CAN_EXPLODE(i) &&
3371                                          !CAN_EXPLODE_1X1(i) &&
3372                                          !CAN_EXPLODE_CROSS(i)));
3373
3374     /* ---------- CAN_EXPLODE_BY_DRAGONFIRE -------------------------------- */
3375     SET_PROPERTY(i, EP_CAN_EXPLODE_BY_DRAGONFIRE, CAN_EXPLODE_BY_FIRE(i));
3376
3377     /* ---------- CAN_EXPLODE_BY_EXPLOSION --------------------------------- */
3378     SET_PROPERTY(i, EP_CAN_EXPLODE_BY_EXPLOSION, (CAN_EXPLODE_BY_FIRE(i) ||
3379                                                   i == EL_BLACK_ORB));
3380
3381     /* ---------- COULD_MOVE_INTO_ACID ------------------------------------- */
3382     SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (ELEM_IS_PLAYER(i) ||
3383                                               CAN_MOVE(i) ||
3384                                               IS_CUSTOM_ELEMENT(i)));
3385
3386     /* ---------- MAYBE_DONT_COLLIDE_WITH ---------------------------------- */
3387     SET_PROPERTY(i, EP_MAYBE_DONT_COLLIDE_WITH, (i == EL_SP_SNIKSNAK ||
3388                                                  i == EL_SP_ELECTRON));
3389
3390     /* ---------- DIGGABLE_WITH_GRAVITY ------------------------------------ */
3391     SET_PROPERTY(i, EP_DIGGABLE_WITH_GRAVITY, (IS_DIGGABLE(i) &&
3392                                                !IS_SP_BUGGY_BASE(i)));
3393
3394     /* ---------- CAN_MOVE_INTO_ACID --------------------------------------- */
3395     if (COULD_MOVE_INTO_ACID(i) && !IS_CUSTOM_ELEMENT(i))
3396       SET_PROPERTY(i, EP_CAN_MOVE_INTO_ACID,
3397                    getMoveIntoAcidProperty(&level, i));
3398
3399     /* ---------- DONT_COLLIDE_WITH ---------------------------------------- */
3400     if (MAYBE_DONT_COLLIDE_WITH(i))
3401       SET_PROPERTY(i, EP_DONT_COLLIDE_WITH,
3402                    getDontCollideWithProperty(&level, i));
3403
3404     /* ---------- SP_PORT -------------------------------------------------- */
3405     SET_PROPERTY(i, EP_SP_PORT, (IS_SP_ELEMENT(i) &&
3406                                  IS_PASSABLE_INSIDE(i)));
3407
3408 #if 0
3409     if (i == EL_CUSTOM_START + 253)
3410       printf("::: %d, %d, %d -> %d\n",
3411              CAN_EXPLODE_1X1(i),
3412              CAN_EXPLODE_3X3(i),
3413              CAN_EXPLODE_CROSS(i),
3414              CAN_EXPLODE(i));
3415 #endif
3416
3417     /* ---------- CAN_CHANGE ----------------------------------------------- */
3418     SET_PROPERTY(i, EP_CAN_CHANGE, FALSE);      /* default: cannot change */
3419     for (j = 0; j < element_info[i].num_change_pages; j++)
3420       if (element_info[i].change_page[j].can_change)
3421         SET_PROPERTY(i, EP_CAN_CHANGE, TRUE);
3422
3423     /* ---------- GFX_CRUMBLED --------------------------------------------- */
3424     SET_PROPERTY(i, EP_GFX_CRUMBLED,
3425                  element_info[i].crumbled[ACTION_DEFAULT] != IMG_EMPTY);
3426   }
3427
3428 #if 0
3429   /* determine inactive elements (used for engine main loop optimization) */
3430   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3431   {
3432     boolean active = FALSE;
3433
3434     for (j = 0; i < NUM_ELEMENT_PROPERTIES; j++)
3435     {
3436       if (HAS_PROPERTY(i, j))
3437         active = TRUE;
3438     }
3439
3440 #if 0
3441     if (!active)
3442       SET_PROPERTY(i, EP_INACTIVE, TRUE);
3443 #endif
3444   }
3445 #endif
3446
3447   /* dynamically adjust element properties according to game engine version */
3448   {
3449     static int ep_em_slippery_wall[] =
3450     {
3451       EL_STEELWALL,
3452       EL_WALL,
3453       EL_EXPANDABLE_WALL,
3454       EL_EXPANDABLE_WALL_HORIZONTAL,
3455       EL_EXPANDABLE_WALL_VERTICAL,
3456       EL_EXPANDABLE_WALL_ANY,
3457       -1
3458     };
3459
3460     /* special EM style gems behaviour */
3461     for (i = 0; ep_em_slippery_wall[i] != -1; i++)
3462       SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL,
3463                    level.em_slippery_gems);
3464
3465     /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */
3466     SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL,
3467                  (level.em_slippery_gems &&
3468                   engine_version > VERSION_IDENT(2,0,1,0)));
3469   }
3470
3471 #if 1
3472   /* set default push delay values (corrected since version 3.0.7-1) */
3473   if (engine_version < VERSION_IDENT(3,0,7,1))
3474   {
3475     game.default_push_delay_fixed = 2;
3476     game.default_push_delay_random = 8;
3477   }
3478   else
3479   {
3480     game.default_push_delay_fixed = 8;
3481     game.default_push_delay_random = 8;
3482   }
3483
3484   /* set uninitialized push delay values of custom elements in older levels */
3485   for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
3486   {
3487     int element = EL_CUSTOM_START + i;
3488
3489     if (element_info[element].push_delay_fixed == -1)
3490       element_info[element].push_delay_fixed = game.default_push_delay_fixed;
3491     if (element_info[element].push_delay_random == -1)
3492       element_info[element].push_delay_random = game.default_push_delay_random;
3493   }
3494
3495   /* set some other uninitialized values of custom elements in older levels */
3496   if (engine_version < VERSION_IDENT(3,1,0,0))
3497   {
3498     for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
3499     {
3500       int element = EL_CUSTOM_START + i;
3501
3502       element_info[element].access_direction = MV_ALL_DIRECTIONS;
3503
3504       element_info[element].explosion_delay = 17;
3505       element_info[element].ignition_delay = 8;
3506     }
3507   }
3508
3509 #if 0
3510   /* set element properties that were handled incorrectly in older levels */
3511   if (engine_version < VERSION_IDENT(3,1,0,0))
3512   {
3513     SET_PROPERTY(EL_SP_SNIKSNAK, EP_DONT_COLLIDE_WITH, FALSE);
3514     SET_PROPERTY(EL_SP_ELECTRON, EP_DONT_COLLIDE_WITH, FALSE);
3515   }
3516 #endif
3517
3518 #endif
3519
3520   /* this is needed because some graphics depend on element properties */
3521   if (game_status == GAME_MODE_PLAYING)
3522     InitElementGraphicInfo();
3523 }
3524
3525 static void InitGlobal()
3526 {
3527   global.autoplay_leveldir = NULL;
3528
3529   global.frames_per_second = 0;
3530   global.fps_slowdown = FALSE;
3531   global.fps_slowdown_factor = 1;
3532 }
3533
3534 void Execute_Command(char *command)
3535 {
3536   int i;
3537
3538   if (strcmp(command, "print graphicsinfo.conf") == 0)
3539   {
3540     printf("# You can configure additional/alternative image files here.\n");
3541     printf("# (The entries below are default and therefore commented out.)\n");
3542     printf("\n");
3543     printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
3544     printf("\n");
3545     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3546     printf("\n");
3547
3548     for (i = 0; image_config[i].token != NULL; i++)
3549       printf("# %s\n", getFormattedSetupEntry(image_config[i].token,
3550                                               image_config[i].value));
3551
3552     exit(0);
3553   }
3554   else if (strcmp(command, "print soundsinfo.conf") == 0)
3555   {
3556     printf("# You can configure additional/alternative sound files here.\n");
3557     printf("# (The entries below are default and therefore commented out.)\n");
3558     printf("\n");
3559     printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
3560     printf("\n");
3561     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3562     printf("\n");
3563
3564     for (i = 0; sound_config[i].token != NULL; i++)
3565       printf("# %s\n", getFormattedSetupEntry(sound_config[i].token,
3566                                               sound_config[i].value));
3567
3568     exit(0);
3569   }
3570   else if (strcmp(command, "print musicinfo.conf") == 0)
3571   {
3572     printf("# You can configure additional/alternative music files here.\n");
3573     printf("# (The entries below are default and therefore commented out.)\n");
3574     printf("\n");
3575     printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
3576     printf("\n");
3577     printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3578     printf("\n");
3579
3580     for (i = 0; music_config[i].token != NULL; i++)
3581       printf("# %s\n", getFormattedSetupEntry(music_config[i].token,
3582                                               music_config[i].value));
3583
3584     exit(0);
3585   }
3586   else if (strcmp(command, "print editorsetup.conf") == 0)
3587   {
3588     printf("# You can configure your personal editor element list here.\n");
3589     printf("# (The entries below are default and therefore commented out.)\n");
3590     printf("\n");
3591
3592     PrintEditorElementList();
3593
3594     exit(0);
3595   }
3596   else if (strcmp(command, "print helpanim.conf") == 0)
3597   {
3598     printf("# You can configure different element help animations here.\n");
3599     printf("# (The entries below are default and therefore commented out.)\n");
3600     printf("\n");
3601
3602     for (i = 0; helpanim_config[i].token != NULL; i++)
3603     {
3604       printf("# %s\n", getFormattedSetupEntry(helpanim_config[i].token,
3605                                               helpanim_config[i].value));
3606
3607       if (strcmp(helpanim_config[i].token, "end") == 0)
3608         printf("#\n");
3609     }
3610
3611     exit(0);
3612   }
3613   else if (strcmp(command, "print helptext.conf") == 0)
3614   {
3615     printf("# You can configure different element help text here.\n");
3616     printf("# (The entries below are default and therefore commented out.)\n");
3617     printf("\n");
3618
3619     for (i = 0; helptext_config[i].token != NULL; i++)
3620       printf("# %s\n", getFormattedSetupEntry(helptext_config[i].token,
3621                                               helptext_config[i].value));
3622
3623     exit(0);
3624   }
3625   else if (strncmp(command, "dump level ", 11) == 0)
3626   {
3627     char *filename = &command[11];
3628
3629     if (access(filename, F_OK) != 0)
3630       Error(ERR_EXIT, "cannot open file '%s'", filename);
3631
3632     LoadLevelFromFilename(&level, filename);
3633     DumpLevel(&level);
3634
3635     exit(0);
3636   }
3637   else if (strncmp(command, "dump tape ", 10) == 0)
3638   {
3639     char *filename = &command[10];
3640
3641     if (access(filename, F_OK) != 0)
3642       Error(ERR_EXIT, "cannot open file '%s'", filename);
3643
3644     LoadTapeFromFilename(filename);
3645     DumpTape(&tape);
3646
3647     exit(0);
3648   }
3649   else if (strncmp(command, "autoplay ", 9) == 0)
3650   {
3651     char *str_copy = getStringCopy(&command[9]);
3652     char *str_ptr = strchr(str_copy, ' ');
3653
3654     global.autoplay_leveldir = str_copy;
3655     global.autoplay_level_nr = -1;
3656
3657     if (str_ptr != NULL)
3658     {
3659       *str_ptr++ = '\0';                        /* terminate leveldir string */
3660       global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
3661     }
3662   }
3663   else
3664   {
3665     Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
3666   }
3667 }
3668
3669 static void InitSetup()
3670 {
3671   LoadSetup();                                  /* global setup info */
3672
3673   /* set some options from setup file */
3674
3675   if (setup.options.verbose)
3676     options.verbose = TRUE;
3677 }
3678
3679 static void InitPlayerInfo()
3680 {
3681   int i;
3682
3683   /* choose default local player */
3684   local_player = &stored_player[0];
3685
3686   for (i = 0; i < MAX_PLAYERS; i++)
3687     stored_player[i].connected = FALSE;
3688
3689   local_player->connected = TRUE;
3690 }
3691
3692 static void InitArtworkInfo()
3693 {
3694   LoadArtworkInfo();
3695 }
3696
3697 static char *get_string_in_brackets(char *string)
3698 {
3699   char *string_in_brackets = checked_malloc(strlen(string) + 3);
3700
3701   sprintf(string_in_brackets, "[%s]", string);
3702
3703   return string_in_brackets;
3704 }
3705
3706 static char *get_level_id_suffix(int id_nr)
3707 {
3708   char *id_suffix = checked_malloc(1 + 3 + 1);
3709
3710   if (id_nr < 0 || id_nr > 999)
3711     id_nr = 0;
3712
3713   sprintf(id_suffix, ".%03d", id_nr);
3714
3715   return id_suffix;
3716 }
3717
3718 #if 0
3719 static char *get_element_class_token(int element)
3720 {
3721   char *element_class_name = element_info[element].class_name;
3722   char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
3723
3724   sprintf(element_class_token, "[%s]", element_class_name);
3725
3726   return element_class_token;
3727 }
3728
3729 static char *get_action_class_token(int action)
3730 {
3731   char *action_class_name = &element_action_info[action].suffix[1];
3732   char *action_class_token = checked_malloc(strlen(action_class_name) + 3);
3733
3734   sprintf(action_class_token, "[%s]", action_class_name);
3735
3736   return action_class_token;
3737 }
3738 #endif
3739
3740 static void InitArtworkConfig()
3741 {
3742   static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
3743   static char *sound_id_prefix[2 * MAX_NUM_ELEMENTS + 1];
3744   static char *music_id_prefix[NUM_MUSIC_PREFIXES + 1];
3745   static char *action_id_suffix[NUM_ACTIONS + 1];
3746   static char *direction_id_suffix[NUM_DIRECTIONS + 1];
3747   static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
3748   static char *level_id_suffix[MAX_LEVELS + 1];
3749   static char *dummy[1] = { NULL };
3750   static char *ignore_generic_tokens[] =
3751   {
3752     "name",
3753     "sort_priority",
3754     NULL
3755   };
3756   static char **ignore_image_tokens;
3757   static char **ignore_sound_tokens;
3758   static char **ignore_music_tokens;
3759   int num_ignore_generic_tokens;
3760   int num_ignore_image_tokens;
3761   int num_ignore_sound_tokens;
3762   int num_ignore_music_tokens;
3763   int i;
3764
3765   /* dynamically determine list of generic tokens to be ignored */
3766   num_ignore_generic_tokens = 0;
3767   for (i = 0; ignore_generic_tokens[i] != NULL; i++)
3768     num_ignore_generic_tokens++;
3769
3770   /* dynamically determine list of image tokens to be ignored */
3771   num_ignore_image_tokens = num_ignore_generic_tokens;
3772   for (i = 0; image_config_vars[i].token != NULL; i++)
3773     num_ignore_image_tokens++;
3774   ignore_image_tokens =
3775     checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *));
3776   for (i = 0; i < num_ignore_generic_tokens; i++)
3777     ignore_image_tokens[i] = ignore_generic_tokens[i];
3778   for (i = 0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++)
3779     ignore_image_tokens[num_ignore_generic_tokens + i] =
3780       image_config_vars[i].token;
3781   ignore_image_tokens[num_ignore_image_tokens] = NULL;
3782
3783   /* dynamically determine list of sound tokens to be ignored */
3784   num_ignore_sound_tokens = num_ignore_generic_tokens;
3785   ignore_sound_tokens =
3786     checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
3787   for (i = 0; i < num_ignore_generic_tokens; i++)
3788     ignore_sound_tokens[i] = ignore_generic_tokens[i];
3789   ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
3790
3791   /* dynamically determine list of music tokens to be ignored */
3792   num_ignore_music_tokens = num_ignore_generic_tokens;
3793   ignore_music_tokens =
3794     checked_malloc((num_ignore_music_tokens + 1) * sizeof(char *));
3795   for (i = 0; i < num_ignore_generic_tokens; i++)
3796     ignore_music_tokens[i] = ignore_generic_tokens[i];
3797   ignore_music_tokens[num_ignore_music_tokens] = NULL;
3798
3799   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3800     image_id_prefix[i] = element_info[i].token_name;
3801   for (i = 0; i < NUM_FONTS; i++)
3802     image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
3803   image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
3804
3805   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3806     sound_id_prefix[i] = element_info[i].token_name;
3807   for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3808     sound_id_prefix[MAX_NUM_ELEMENTS + i] =
3809       get_string_in_brackets(element_info[i].class_name);
3810   sound_id_prefix[2 * MAX_NUM_ELEMENTS] = NULL;
3811
3812   for (i = 0; i < NUM_MUSIC_PREFIXES; i++)
3813     music_id_prefix[i] = music_prefix_info[i].prefix;
3814   music_id_prefix[MAX_LEVELS] = NULL;
3815
3816   for (i = 0; i < NUM_ACTIONS; i++)
3817     action_id_suffix[i] = element_action_info[i].suffix;
3818   action_id_suffix[NUM_ACTIONS] = NULL;
3819
3820   for (i = 0; i < NUM_DIRECTIONS; i++)
3821     direction_id_suffix[i] = element_direction_info[i].suffix;
3822   direction_id_suffix[NUM_DIRECTIONS] = NULL;
3823
3824   for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
3825     special_id_suffix[i] = special_suffix_info[i].suffix;
3826   special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
3827
3828   for (i = 0; i < MAX_LEVELS; i++)
3829     level_id_suffix[i] = get_level_id_suffix(i);
3830   level_id_suffix[MAX_LEVELS] = NULL;
3831
3832   InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
3833                 image_id_prefix, action_id_suffix, direction_id_suffix,
3834                 special_id_suffix, ignore_image_tokens);
3835   InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
3836                 sound_id_prefix, action_id_suffix, dummy,
3837                 special_id_suffix, ignore_sound_tokens);
3838   InitMusicList(music_config, NUM_MUSIC_FILES, music_config_suffix,
3839                 music_id_prefix, special_id_suffix, level_id_suffix,
3840                 dummy, ignore_music_tokens);
3841 }
3842
3843 static void InitMixer()
3844 {
3845   OpenAudio();
3846   StartMixer();
3847 }
3848
3849 void InitGfx()
3850 {
3851   char *filename_font_initial = NULL;
3852   Bitmap *bitmap_font_initial = NULL;
3853   int i, j;
3854
3855   /* determine settings for initial font (for displaying startup messages) */
3856   for (i = 0; image_config[i].token != NULL; i++)
3857   {
3858     for (j = 0; j < NUM_INITIAL_FONTS; j++)
3859     {
3860       char font_token[128];
3861       int len_font_token;
3862
3863       sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
3864       len_font_token = strlen(font_token);
3865
3866       if (strcmp(image_config[i].token, font_token) == 0)
3867         filename_font_initial = image_config[i].value;
3868       else if (strlen(image_config[i].token) > len_font_token &&
3869                strncmp(image_config[i].token, font_token, len_font_token) == 0)
3870       {
3871         if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
3872           font_initial[j].src_x = atoi(image_config[i].value);
3873         else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
3874           font_initial[j].src_y = atoi(image_config[i].value);
3875         else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
3876           font_initial[j].width = atoi(image_config[i].value);
3877         else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
3878           font_initial[j].height = atoi(image_config[i].value);
3879       }
3880     }
3881   }
3882
3883   for (j = 0; j < NUM_INITIAL_FONTS; j++)
3884   {
3885     font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
3886     font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
3887   }
3888
3889   if (filename_font_initial == NULL)    /* should not happen */
3890     Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
3891
3892   /* create additional image buffers for double-buffering */
3893   bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
3894   bitmap_db_door  = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
3895
3896   /* initialize screen properties */
3897   InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
3898                    REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
3899                    bitmap_db_field);
3900   InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
3901   InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
3902   InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
3903
3904   bitmap_font_initial = LoadCustomImage(filename_font_initial);
3905
3906   for (j = 0; j < NUM_INITIAL_FONTS; j++)
3907     font_initial[j].bitmap = bitmap_font_initial;
3908
3909   InitFontGraphicInfo();
3910
3911   DrawInitText(getProgramInitString(), 20, FC_YELLOW);
3912   DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED);
3913
3914   DrawInitText("Loading graphics:", 120, FC_GREEN);
3915
3916   InitTileClipmasks();
3917 }
3918
3919 void InitGfxBackground()
3920 {
3921   int x, y;
3922
3923   drawto = backbuffer;
3924   fieldbuffer = bitmap_db_field;
3925   SetDrawtoField(DRAW_BACKBUFFER);
3926
3927   BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
3928              0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3929   ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
3930   ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
3931
3932   for (x = 0; x < MAX_BUF_XSIZE; x++)
3933     for (y = 0; y < MAX_BUF_YSIZE; y++)
3934       redraw[x][y] = 0;
3935   redraw_tiles = 0;
3936   redraw_mask = REDRAW_ALL;
3937 }
3938
3939 static void InitLevelInfo()
3940 {
3941   LoadLevelInfo();                              /* global level info */
3942   LoadLevelSetup_LastSeries();                  /* last played series info */
3943   LoadLevelSetup_SeriesInfo();                  /* last played level info */
3944 }
3945
3946 void InitLevelArtworkInfo()
3947 {
3948   LoadLevelArtworkInfo();
3949 }
3950
3951 static void InitImages()
3952 {
3953 #if 1
3954   setLevelArtworkDir(artwork.gfx_first);
3955 #endif
3956
3957 #if 0
3958   printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
3959          leveldir_current->identifier,
3960          artwork.gfx_current_identifier,
3961          artwork.gfx_current->identifier,
3962          leveldir_current->graphics_set,
3963          leveldir_current->graphics_path);
3964 #endif
3965
3966   ReloadCustomImages();
3967
3968   LoadCustomElementDescriptions();
3969   LoadSpecialMenuDesignSettings();
3970
3971   ReinitializeGraphics();
3972 }
3973
3974 static void InitSound(char *identifier)
3975 {
3976   if (identifier == NULL)
3977     identifier = artwork.snd_current->identifier;
3978
3979 #if 1
3980   /* set artwork path to send it to the sound server process */
3981   setLevelArtworkDir(artwork.snd_first);
3982 #endif
3983
3984   InitReloadCustomSounds(identifier);
3985   ReinitializeSounds();
3986 }
3987
3988 static void InitMusic(char *identifier)
3989 {
3990   if (identifier == NULL)
3991     identifier = artwork.mus_current->identifier;
3992
3993 #if 1
3994   /* set artwork path to send it to the sound server process */
3995   setLevelArtworkDir(artwork.mus_first);
3996 #endif
3997
3998   InitReloadCustomMusic(identifier);
3999   ReinitializeMusic();
4000 }
4001
4002 void InitNetworkServer()
4003 {
4004 #if defined(PLATFORM_UNIX)
4005   int nr_wanted;
4006 #endif
4007
4008   if (!options.network)
4009     return;
4010
4011 #if defined(PLATFORM_UNIX)
4012   nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
4013
4014   if (!ConnectToServer(options.server_host, options.server_port))
4015     Error(ERR_EXIT, "cannot connect to network game server");
4016
4017   SendToServer_PlayerName(setup.player_name);
4018   SendToServer_ProtocolVersion();
4019
4020   if (nr_wanted)
4021     SendToServer_NrWanted(nr_wanted);
4022 #endif
4023 }
4024
4025 static char *getNewArtworkIdentifier(int type)
4026 {
4027   static char *leveldir_current_identifier[3] = { NULL, NULL, NULL };
4028   static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE };
4029   static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE };
4030   static boolean initialized[3] = { FALSE, FALSE, FALSE };
4031   TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
4032   boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type);
4033   char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type);
4034   char *leveldir_identifier = leveldir_current->identifier;
4035 #if 1
4036   /* !!! setLevelArtworkDir() should be moved to an earlier stage !!! */
4037   char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node);
4038 #else
4039   char *leveldir_artwork_set = LEVELDIR_ARTWORK_SET(leveldir_current, type);
4040 #endif
4041   boolean has_level_artwork_set = (leveldir_artwork_set != NULL);
4042   char *artwork_current_identifier;
4043   char *artwork_new_identifier = NULL;  /* default: nothing has changed */
4044
4045   /* leveldir_current may be invalid (level group, parent link) */
4046   if (!validLevelSeries(leveldir_current))
4047     return NULL;
4048
4049   /* 1st step: determine artwork set to be activated in descending order:
4050      --------------------------------------------------------------------
4051      1. setup artwork (when configured to override everything else)
4052      2. artwork set configured in "levelinfo.conf" of current level set
4053         (artwork in level directory will have priority when loading later)
4054      3. artwork in level directory (stored in artwork sub-directory)
4055      4. setup artwork (currently configured in setup menu) */
4056
4057   if (setup_override_artwork)
4058     artwork_current_identifier = setup_artwork_set;
4059   else if (leveldir_artwork_set != NULL)
4060     artwork_current_identifier = leveldir_artwork_set;
4061   else if (getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier))
4062     artwork_current_identifier = leveldir_identifier;
4063   else
4064     artwork_current_identifier = setup_artwork_set;
4065
4066
4067   /* 2nd step: check if it is really needed to reload artwork set
4068      ------------------------------------------------------------ */
4069
4070 #if 0
4071   if (type == ARTWORK_TYPE_GRAPHICS)
4072     printf("::: 0: '%s' ['%s', '%s'] ['%s' ('%s')]\n",
4073            artwork_new_identifier,
4074            ARTWORK_CURRENT_IDENTIFIER(artwork, type),
4075            artwork_current_identifier,
4076            leveldir_current->graphics_set,
4077            leveldir_current->identifier);
4078 #endif
4079
4080   /* ---------- reload if level set and also artwork set has changed ------- */
4081   if (leveldir_current_identifier[type] != leveldir_identifier &&
4082       (last_has_level_artwork_set[type] || has_level_artwork_set))
4083     artwork_new_identifier = artwork_current_identifier;
4084
4085   leveldir_current_identifier[type] = leveldir_identifier;
4086   last_has_level_artwork_set[type] = has_level_artwork_set;
4087
4088 #if 0
4089   if (type == ARTWORK_TYPE_GRAPHICS)
4090     printf("::: 1: '%s'\n", artwork_new_identifier);
4091 #endif
4092
4093   /* ---------- reload if "override artwork" setting has changed ----------- */
4094   if (last_override_level_artwork[type] != setup_override_artwork)
4095     artwork_new_identifier = artwork_current_identifier;
4096
4097   last_override_level_artwork[type] = setup_override_artwork;
4098
4099 #if 0
4100   if (type == ARTWORK_TYPE_GRAPHICS)
4101     printf("::: 2: '%s'\n", artwork_new_identifier);
4102 #endif
4103
4104   /* ---------- reload if current artwork identifier has changed ----------- */
4105   if (strcmp(ARTWORK_CURRENT_IDENTIFIER(artwork, type),
4106              artwork_current_identifier) != 0)
4107     artwork_new_identifier = artwork_current_identifier;
4108
4109   *(&(ARTWORK_CURRENT_IDENTIFIER(artwork, type))) = artwork_current_identifier;
4110
4111 #if 0
4112   if (type == ARTWORK_TYPE_GRAPHICS)
4113     printf("::: 3: '%s'\n", artwork_new_identifier);
4114 #endif
4115
4116   /* ---------- do not reload directly after starting ---------------------- */
4117   if (!initialized[type])
4118     artwork_new_identifier = NULL;
4119
4120   initialized[type] = TRUE;
4121
4122 #if 0
4123   if (type == ARTWORK_TYPE_GRAPHICS)
4124     printf("::: 4: '%s'\n", artwork_new_identifier);
4125 #endif
4126
4127 #if 0
4128   if (type == ARTWORK_TYPE_GRAPHICS)
4129     printf("CHECKING OLD/NEW GFX:\n- OLD: %s\n- NEW: %s ['%s', '%s'] ['%s']\n",
4130            artwork.gfx_current_identifier, artwork_current_identifier,
4131            artwork.gfx_current->identifier, leveldir_current->graphics_set,
4132            artwork_new_identifier);
4133 #endif
4134
4135   return artwork_new_identifier;
4136 }
4137
4138 void ReloadCustomArtwork(int force_reload)
4139 {
4140   char *gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS);
4141   char *snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS);
4142   char *mus_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_MUSIC);
4143   boolean force_reload_gfx = (force_reload & (1 << ARTWORK_TYPE_GRAPHICS));
4144   boolean force_reload_snd = (force_reload & (1 << ARTWORK_TYPE_SOUNDS));
4145   boolean force_reload_mus = (force_reload & (1 << ARTWORK_TYPE_MUSIC));
4146   boolean redraw_screen = FALSE;
4147
4148   if (gfx_new_identifier != NULL || force_reload_gfx)
4149   {
4150 #if 0
4151     printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n",
4152            artwork.gfx_current_identifier,
4153            gfx_new_identifier,
4154            artwork.gfx_current->identifier,
4155            leveldir_current->graphics_set);
4156 #endif
4157
4158     ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4159
4160     InitImages();
4161
4162 #if 0
4163     printf("... '%s'\n",
4164            leveldir_current->graphics_set);
4165 #endif
4166
4167     FreeTileClipmasks();
4168     InitTileClipmasks();
4169
4170     redraw_screen = TRUE;
4171   }
4172
4173   if (snd_new_identifier != NULL || force_reload_snd)
4174   {
4175     ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4176
4177     InitSound(snd_new_identifier);
4178
4179     redraw_screen = TRUE;
4180   }
4181
4182   if (mus_new_identifier != NULL || force_reload_mus)
4183   {
4184     ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4185
4186     InitMusic(mus_new_identifier);
4187
4188     redraw_screen = TRUE;
4189   }
4190
4191   if (redraw_screen)
4192   {
4193     InitGfxBackground();
4194
4195     /* force redraw of (open or closed) door graphics */
4196     SetDoorState(DOOR_OPEN_ALL);
4197     CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
4198   }
4199 }
4200
4201 void KeyboardAutoRepeatOffUnlessAutoplay()
4202 {
4203   if (global.autoplay_leveldir == NULL)
4204     KeyboardAutoRepeatOff();
4205 }
4206
4207
4208 /* ========================================================================= */
4209 /* OpenAll()                                                                 */
4210 /* ========================================================================= */
4211
4212 void OpenAll()
4213 {
4214   InitGlobal();         /* initialize some global variables */
4215
4216   if (options.execute_command)
4217     Execute_Command(options.execute_command);
4218
4219   if (options.serveronly)
4220   {
4221 #if defined(PLATFORM_UNIX)
4222     NetworkServer(options.server_port, options.serveronly);
4223 #else
4224     Error(ERR_WARN, "networking only supported in Unix version");
4225 #endif
4226     exit(0);    /* never reached */
4227   }
4228
4229   InitSetup();
4230
4231   InitPlayerInfo();
4232   InitArtworkInfo();            /* needed before loading gfx, sound & music */
4233   InitArtworkConfig();          /* needed before forking sound child process */
4234   InitMixer();
4235
4236   InitCounter();
4237
4238   InitRND(NEW_RANDOMIZE);
4239   InitSimpleRND(NEW_RANDOMIZE);
4240
4241   InitJoysticks();
4242
4243   InitVideoDisplay();
4244   InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
4245                   setup.fullscreen);
4246
4247   InitEventFilter(FilterMouseMotionEvents);
4248
4249   InitElementPropertiesStatic();
4250   InitElementPropertiesEngine(GAME_VERSION_ACTUAL);
4251
4252   InitGfx();
4253
4254   InitLevelInfo();
4255   InitLevelArtworkInfo();
4256
4257   InitImages();                 /* needs to know current level directory */
4258   InitSound(NULL);              /* needs to know current level directory */
4259   InitMusic(NULL);              /* needs to know current level directory */
4260
4261   InitGfxBackground();
4262
4263   if (global.autoplay_leveldir)
4264   {
4265     AutoPlayTape();
4266     return;
4267   }
4268
4269   game_status = GAME_MODE_MAIN;
4270
4271   DrawMainMenu();
4272
4273   InitNetworkServer();
4274 }
4275
4276 void CloseAllAndExit(int exit_value)
4277 {
4278   StopSounds();
4279   FreeAllSounds();
4280   FreeAllMusic();
4281   CloseAudio();         /* called after freeing sounds (needed for SDL) */
4282
4283   FreeAllImages();
4284   FreeTileClipmasks();
4285
4286   CloseVideoDisplay();
4287   ClosePlatformDependentStuff();
4288
4289   exit(exit_value);
4290 }