1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
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 */
37 #define CONFIG_TOKEN_FONT_INITIAL "font.initial"
40 struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
43 static void InitTileClipmasks()
46 #if defined(TARGET_X11)
47 XGCValues clip_gc_values;
48 unsigned long clip_gc_valuemask;
50 #if defined(TARGET_X11_NATIVE)
60 tile_needs_clipping[] =
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 },
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 },
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 },
108 #endif /* TARGET_X11_NATIVE */
109 #endif /* TARGET_X11 */
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;
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. */
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);
129 for (i = 0; i < NUM_BITMAPS; i++)
131 if (pix[i]->clip_mask)
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);
142 #if defined(TARGET_X11_NATIVE)
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);
151 /* create only those clipping Pixmaps we really need */
152 for (i = 0; tile_needs_clipping[i].start >= 0; i++)
156 for (j = 0; j < tile_needs_clipping[i].count; j++)
158 int tile = tile_needs_clipping[i].start + j;
164 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
165 src_pixmap = src_bitmap->clip_mask;
167 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
170 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
171 src_x, src_y, TILEX, TILEY, 0, 0);
175 XFreeGC(display, copy_clipmask_gc);
178 #endif /* TARGET_X11_NATIVE */
179 #endif /* TARGET_X11 */
183 void FreeTileClipmasks()
186 #if defined(TARGET_X11)
189 for (i = 0; i < NUM_TILES; i++)
191 if (tile_clipmask[i] != None)
193 XFreePixmap(display, tile_clipmask[i]);
194 tile_clipmask[i] = None;
199 XFreeGC(display, tile_clip_gc);
203 for (i = 0; i < NUM_BITMAPS; i++)
205 if (pix[i] != NULL && pix[i]->stored_clip_gc)
207 XFreeGC(display, pix[i]->stored_clip_gc);
208 pix[i]->stored_clip_gc = None;
213 #endif /* TARGET_X11 */
219 FreeLevelEditorGadgets();
228 static boolean gadgets_initialized = FALSE;
230 if (gadgets_initialized)
233 CreateLevelEditorGadgets();
237 CreateScreenGadgets();
239 gadgets_initialized = TRUE;
242 void InitElementSmallImages()
244 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
245 int num_property_mappings = getImageListPropertyMappingSize();
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);
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);
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);
262 static int getFontBitmapID(int font_nr)
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;
274 return font_info[font_nr].special_bitmap_id[special];
279 void InitFontGraphicInfo()
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;
287 if (graphic_info == NULL) /* still at startup phase */
289 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
294 /* ---------- initialize font graphic definitions ---------- */
296 /* always start with reliable default values (normal font graphics) */
298 for (i = 0; i < NUM_FONTS; i++)
299 font_info[i].graphic = IMG_FONT_INITIAL_1;
301 for (i = 0; i < NUM_FONTS; i++)
302 font_info[i].graphic = FONT_INITIAL_1;
305 /* initialize normal font/graphic mapping from static configuration */
306 for (i = 0; font_to_graphic[i].font_nr > -1; i++)
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;
315 font_info[font_nr].graphic = graphic;
318 /* always start with reliable default values (special font graphics) */
319 for (i = 0; i < NUM_FONTS; i++)
321 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
323 font_info[i].special_graphic[j] = font_info[i].graphic;
324 font_info[i].special_bitmap_id[j] = i;
328 /* initialize special font/graphic mapping from static configuration */
329 for (i = 0; font_to_graphic[i].font_nr > -1; i++)
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;
335 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
337 font_info[font_nr].special_graphic[special] = graphic;
338 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
343 /* initialize special element/graphic mapping from dynamic configuration */
344 for (i = 0; i < num_property_mappings; i++)
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;
353 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
355 font_info[font_nr].special_graphic[special] = graphic;
356 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
361 /* ---------- initialize font bitmap array ---------- */
363 if (font_bitmap_info != NULL)
364 FreeFontInfo(font_bitmap_info);
367 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
369 /* ---------- initialize font bitmap definitions ---------- */
371 for (i = 0; i < NUM_FONTS; i++)
373 if (i < NUM_INITIAL_FONTS)
375 font_bitmap_info[i] = font_initial[i];
379 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
381 int font_bitmap_id = font_info[i].special_bitmap_id[j];
382 int graphic = font_info[i].special_graphic[j];
384 /* set 'graphic_info' for font entries, if uninitialized (guessed) */
385 if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
387 graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
388 graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
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;
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;
407 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
410 void InitElementGraphicInfo()
412 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
413 int num_property_mappings = getImageListPropertyMappingSize();
416 if (graphic_info == NULL) /* still at startup phase */
419 /* set values to -1 to identify later as "uninitialized" values */
420 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
422 for (act = 0; act < NUM_ACTIONS; act++)
424 element_info[i].graphic[act] = -1;
425 element_info[i].crumbled[act] = -1;
427 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
429 element_info[i].direction_graphic[act][dir] = -1;
430 element_info[i].direction_crumbled[act][dir] = -1;
435 /* initialize normal element/graphic mapping from static configuration */
436 for (i = 0; element_to_graphic[i].element > -1; i++)
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;
444 if (graphic_info[graphic].bitmap == NULL)
447 if ((action > -1 || direction > -1 || crumbled == TRUE) &&
448 el2img(element) != -1)
450 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
451 boolean act_dir_redefined = getImageListEntry(graphic)->redefined;
453 /* if the base graphic ("emerald", for example) has been redefined,
454 but not the action graphic ("emerald.falling", for example), do not
455 use an existing (in this case considered obsolete) action graphic
456 anymore, but use the automatically determined default graphic */
457 if (base_redefined && !act_dir_redefined)
462 action = ACTION_DEFAULT;
467 element_info[element].direction_crumbled[action][direction] = graphic;
469 element_info[element].crumbled[action] = graphic;
474 element_info[element].direction_graphic[action][direction] = graphic;
476 element_info[element].graphic[action] = graphic;
480 /* initialize normal element/graphic mapping from dynamic configuration */
481 for (i = 0; i < num_property_mappings; i++)
483 int element = property_mapping[i].base_index;
484 int action = property_mapping[i].ext1_index;
485 int direction = property_mapping[i].ext2_index;
486 int special = property_mapping[i].ext3_index;
487 int graphic = property_mapping[i].artwork_index;
488 boolean crumbled = FALSE;
490 if (special == GFX_SPECIAL_ARG_CRUMBLED)
496 if (graphic_info[graphic].bitmap == NULL)
499 if (element >= MAX_NUM_ELEMENTS || special != -1)
503 action = ACTION_DEFAULT;
508 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
509 element_info[element].direction_crumbled[action][dir] = -1;
512 element_info[element].direction_crumbled[action][direction] = graphic;
514 element_info[element].crumbled[action] = graphic;
519 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
520 element_info[element].direction_graphic[action][dir] = -1;
523 element_info[element].direction_graphic[action][direction] = graphic;
525 element_info[element].graphic[action] = graphic;
529 /* now copy all graphics that are defined to be cloned from other graphics */
530 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
532 int graphic = element_info[i].graphic[ACTION_DEFAULT];
533 int crumbled_like, diggable_like;
538 crumbled_like = graphic_info[graphic].crumbled_like;
539 diggable_like = graphic_info[graphic].diggable_like;
541 if (crumbled_like != -1 && element_info[i].crumbled[ACTION_DEFAULT] == -1)
543 for (act = 0; act < NUM_ACTIONS; act++)
544 element_info[i].crumbled[act] =
545 element_info[crumbled_like].crumbled[act];
546 for (act = 0; act < NUM_ACTIONS; act++)
547 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
548 element_info[i].direction_crumbled[act][dir] =
549 element_info[crumbled_like].direction_crumbled[act][dir];
552 if (diggable_like != -1 && element_info[i].graphic[ACTION_DIGGING] == -1)
554 element_info[i].graphic[ACTION_DIGGING] =
555 element_info[diggable_like].graphic[ACTION_DIGGING];
556 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
557 element_info[i].direction_graphic[ACTION_DIGGING][dir] =
558 element_info[diggable_like].direction_graphic[ACTION_DIGGING][dir];
563 /* now set all undefined/invalid graphics to -1 to set to default after it */
564 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
566 for (act = 0; act < NUM_ACTIONS; act++)
570 graphic = element_info[i].graphic[act];
571 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
572 element_info[i].graphic[act] = -1;
574 graphic = element_info[i].crumbled[act];
575 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
576 element_info[i].crumbled[act] = -1;
578 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
580 graphic = element_info[i].direction_graphic[act][dir];
581 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
582 element_info[i].direction_graphic[act][dir] = -1;
584 graphic = element_info[i].direction_crumbled[act][dir];
585 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
586 element_info[i].direction_crumbled[act][dir] = -1;
592 /* now set all '-1' values to element specific default values */
593 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
595 int default_graphic = element_info[i].graphic[ACTION_DEFAULT];
596 int default_crumbled = element_info[i].crumbled[ACTION_DEFAULT];
597 int default_direction_graphic[NUM_DIRECTIONS];
598 int default_direction_crumbled[NUM_DIRECTIONS];
600 if (default_graphic == -1)
601 default_graphic = IMG_UNKNOWN;
602 if (default_crumbled == -1)
603 default_crumbled = IMG_EMPTY;
605 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
607 default_direction_graphic[dir] =
608 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
609 default_direction_crumbled[dir] =
610 element_info[i].direction_crumbled[ACTION_DEFAULT][dir];
612 if (default_direction_graphic[dir] == -1)
613 default_direction_graphic[dir] = default_graphic;
614 if (default_direction_crumbled[dir] == -1)
615 default_direction_crumbled[dir] = default_crumbled;
618 for (act = 0; act < NUM_ACTIONS; act++)
620 boolean act_remove = ((IS_DIGGABLE(i) && act == ACTION_DIGGING) ||
621 (IS_SNAPPABLE(i) && act == ACTION_SNAPPING) ||
622 (IS_COLLECTIBLE(i) && act == ACTION_COLLECTING));
623 boolean act_turning = (act == ACTION_TURNING_FROM_LEFT ||
624 act == ACTION_TURNING_FROM_RIGHT ||
625 act == ACTION_TURNING_FROM_UP ||
626 act == ACTION_TURNING_FROM_DOWN);
628 /* generic default action graphic (defined by "[default]" directive) */
629 int default_action_graphic = element_info[EL_DEFAULT].graphic[act];
630 int default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
632 /* look for special default action graphic (classic game specific) */
633 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].graphic[act] != -1)
634 default_action_graphic = element_info[EL_BD_DEFAULT].graphic[act];
635 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].graphic[act] != -1)
636 default_action_graphic = element_info[EL_SP_DEFAULT].graphic[act];
637 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].graphic[act] != -1)
638 default_action_graphic = element_info[EL_SB_DEFAULT].graphic[act];
640 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].crumbled[act] != -1)
641 default_action_crumbled = element_info[EL_BD_DEFAULT].crumbled[act];
642 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].crumbled[act] != -1)
643 default_action_crumbled = element_info[EL_SP_DEFAULT].crumbled[act];
644 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].crumbled[act] != -1)
645 default_action_crumbled = element_info[EL_SB_DEFAULT].crumbled[act];
648 /* !!! make this better !!! */
649 if (i == EL_EMPTY_SPACE)
651 default_action_graphic = element_info[EL_DEFAULT].graphic[act];
652 default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
656 if (default_action_graphic == -1)
657 default_action_graphic = default_graphic;
658 if (default_action_crumbled == -1)
659 default_action_crumbled = default_crumbled;
661 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
663 int default_action_direction_graphic = element_info[i].graphic[act];
664 int default_action_direction_crumbled = element_info[i].crumbled[act];
666 /* no graphic for current action -- use default direction graphic */
667 if (default_action_direction_graphic == -1)
668 default_action_direction_graphic =
669 (act_remove ? IMG_EMPTY :
671 element_info[i].direction_graphic[ACTION_TURNING][dir] :
672 default_direction_graphic[dir]);
673 if (default_action_direction_crumbled == -1)
674 default_action_direction_crumbled =
675 (act_remove ? IMG_EMPTY :
677 element_info[i].direction_crumbled[ACTION_TURNING][dir] :
678 default_direction_crumbled[dir]);
680 if (element_info[i].direction_graphic[act][dir] == -1)
681 element_info[i].direction_graphic[act][dir] =
682 default_action_direction_graphic;
683 if (element_info[i].direction_crumbled[act][dir] == -1)
684 element_info[i].direction_crumbled[act][dir] =
685 default_action_direction_crumbled;
688 /* no graphic for this specific action -- use default action graphic */
689 if (element_info[i].graphic[act] == -1)
690 element_info[i].graphic[act] =
691 (act_remove ? IMG_EMPTY :
692 act_turning ? element_info[i].graphic[ACTION_TURNING] :
693 default_action_graphic);
694 if (element_info[i].crumbled[act] == -1)
695 element_info[i].crumbled[act] =
696 (act_remove ? IMG_EMPTY :
697 act_turning ? element_info[i].crumbled[ACTION_TURNING] :
698 default_action_crumbled);
703 /* set animation mode to "none" for each graphic with only 1 frame */
704 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
706 for (act = 0; act < NUM_ACTIONS; act++)
708 int graphic = element_info[i].graphic[act];
709 int crumbled = element_info[i].crumbled[act];
711 if (graphic_info[graphic].anim_frames == 1)
712 graphic_info[graphic].anim_mode = ANIM_NONE;
713 if (graphic_info[crumbled].anim_frames == 1)
714 graphic_info[crumbled].anim_mode = ANIM_NONE;
716 for (dir = 0; dir < NUM_DIRECTIONS; dir++)
718 graphic = element_info[i].direction_graphic[act][dir];
719 crumbled = element_info[i].direction_crumbled[act][dir];
721 if (graphic_info[graphic].anim_frames == 1)
722 graphic_info[graphic].anim_mode = ANIM_NONE;
723 if (graphic_info[crumbled].anim_frames == 1)
724 graphic_info[crumbled].anim_mode = ANIM_NONE;
734 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
735 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_UNKNOWN &&
737 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
738 element_info[i].token_name, i);
744 void InitElementSpecialGraphicInfo()
746 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
747 int num_property_mappings = getImageListPropertyMappingSize();
750 /* always start with reliable default values */
751 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
752 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
753 element_info[i].special_graphic[j] =
754 element_info[i].graphic[ACTION_DEFAULT];
756 /* initialize special element/graphic mapping from static configuration */
757 for (i = 0; element_to_special_graphic[i].element > -1; i++)
759 int element = element_to_special_graphic[i].element;
760 int special = element_to_special_graphic[i].special;
761 int graphic = element_to_special_graphic[i].graphic;
762 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
763 boolean special_redefined = getImageListEntry(graphic)->redefined;
765 /* if the base graphic ("emerald", for example) has been redefined,
766 but not the special graphic ("emerald.EDITOR", for example), do not
767 use an existing (in this case considered obsolete) special graphic
768 anymore, but use the automatically created (down-scaled) graphic */
769 if (base_redefined && !special_redefined)
772 element_info[element].special_graphic[special] = graphic;
775 /* initialize special element/graphic mapping from dynamic configuration */
776 for (i = 0; i < num_property_mappings; i++)
778 int element = property_mapping[i].base_index;
779 int special = property_mapping[i].ext3_index;
780 int graphic = property_mapping[i].artwork_index;
782 if (element >= MAX_NUM_ELEMENTS)
785 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
786 element_info[element].special_graphic[special] = graphic;
790 /* now set all undefined/invalid graphics to default */
791 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
792 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
793 if (graphic_info[element_info[i].special_graphic[j]].bitmap == NULL)
794 element_info[i].special_graphic[j] =
795 element_info[i].graphic[ACTION_DEFAULT];
799 static int get_element_from_token(char *token)
803 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
804 if (strcmp(element_info[i].token_name, token) == 0)
810 static void set_graphic_parameters(int graphic, char **parameter_raw)
812 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
813 int parameter[NUM_GFX_ARGS];
814 int anim_frames_per_row = 1, anim_frames_per_col = 1;
815 int anim_frames_per_line = 1;
818 /* get integer values from string parameters */
819 for (i = 0; i < NUM_GFX_ARGS; i++)
822 get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
823 image_config_suffix[i].type);
825 if (image_config_suffix[i].type == TYPE_TOKEN)
826 parameter[i] = get_element_from_token(parameter_raw[i]);
829 graphic_info[graphic].bitmap = src_bitmap;
831 /* start with reliable default values */
832 graphic_info[graphic].src_x = 0;
833 graphic_info[graphic].src_y = 0;
834 graphic_info[graphic].width = TILEX;
835 graphic_info[graphic].height = TILEY;
836 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
837 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
838 graphic_info[graphic].crumbled_like = -1; /* do not use clone element */
839 graphic_info[graphic].diggable_like = -1; /* do not use clone element */
840 graphic_info[graphic].border_size = TILEX / 8; /* "CRUMBLED" border size */
841 graphic_info[graphic].anim_delay_fixed = 0;
842 graphic_info[graphic].anim_delay_random = 0;
843 graphic_info[graphic].post_delay_fixed = 0;
844 graphic_info[graphic].post_delay_random = 0;
846 /* optional x and y tile position of animation frame sequence */
847 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
848 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
849 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
850 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
852 /* optional x and y pixel position of animation frame sequence */
853 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
854 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
855 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
856 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
858 /* optional width and height of each animation frame */
859 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
860 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
861 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
862 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
866 anim_frames_per_row = src_bitmap->width / graphic_info[graphic].width;
867 anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
870 /* correct x or y offset dependent of vertical or horizontal frame order */
871 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
873 graphic_info[graphic].offset_y =
874 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
875 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
876 anim_frames_per_line = anim_frames_per_col;
878 else /* frames are ordered horizontally */
880 graphic_info[graphic].offset_x =
881 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
882 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
883 anim_frames_per_line = anim_frames_per_row;
886 /* optionally, the x and y offset of frames can be specified directly */
887 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
888 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
889 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
890 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
892 /* automatically determine correct number of frames, if not defined */
893 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
894 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
895 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
896 graphic_info[graphic].anim_frames = anim_frames_per_row;
897 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
898 graphic_info[graphic].anim_frames = anim_frames_per_col;
900 graphic_info[graphic].anim_frames = 1;
902 graphic_info[graphic].anim_frames_per_line =
903 (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
904 parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
906 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
907 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
908 graphic_info[graphic].anim_delay = 1;
910 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
912 if (graphic_info[graphic].anim_frames == 1)
913 graphic_info[graphic].anim_mode = ANIM_NONE;
916 /* automatically determine correct start frame, if not defined */
917 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
918 graphic_info[graphic].anim_start_frame = 0;
919 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
920 graphic_info[graphic].anim_start_frame =
921 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
923 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
925 /* animation synchronized with global frame counter, not move position */
926 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
928 /* optional element for cloning crumble graphics */
929 if (parameter[GFX_ARG_CRUMBLED_LIKE] != ARG_UNDEFINED_VALUE)
930 graphic_info[graphic].crumbled_like = parameter[GFX_ARG_CRUMBLED_LIKE];
932 /* optional element for cloning digging graphics */
933 if (parameter[GFX_ARG_DIGGABLE_LIKE] != ARG_UNDEFINED_VALUE)
934 graphic_info[graphic].diggable_like = parameter[GFX_ARG_DIGGABLE_LIKE];
936 /* optional border size for "crumbling" diggable graphics */
937 if (parameter[GFX_ARG_BORDER_SIZE] != ARG_UNDEFINED_VALUE)
938 graphic_info[graphic].border_size = parameter[GFX_ARG_BORDER_SIZE];
940 /* this is only used for player "boring" and "sleeping" actions */
941 if (parameter[GFX_ARG_ANIM_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
942 graphic_info[graphic].anim_delay_fixed =
943 parameter[GFX_ARG_ANIM_DELAY_FIXED];
944 if (parameter[GFX_ARG_ANIM_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
945 graphic_info[graphic].anim_delay_random =
946 parameter[GFX_ARG_ANIM_DELAY_RANDOM];
947 if (parameter[GFX_ARG_POST_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
948 graphic_info[graphic].post_delay_fixed =
949 parameter[GFX_ARG_POST_DELAY_FIXED];
950 if (parameter[GFX_ARG_POST_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
951 graphic_info[graphic].post_delay_random =
952 parameter[GFX_ARG_POST_DELAY_RANDOM];
954 /* this is only used for toon animations */
955 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
956 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
958 /* this is only used for drawing font characters */
959 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
960 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
962 /* this is only used for drawing envelope graphics */
963 graphic_info[graphic].draw_masked = parameter[GFX_ARG_DRAW_MASKED];
966 static void InitGraphicInfo()
968 int fallback_graphic = IMG_CHAR_EXCLAM;
969 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
970 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
971 int num_images = getImageListSize();
974 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
975 static boolean clipmasks_initialized = FALSE;
977 XGCValues clip_gc_values;
978 unsigned long clip_gc_valuemask;
979 GC copy_clipmask_gc = None;
982 checked_free(graphic_info);
984 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
987 printf("::: graphic_info: %d entries\n", num_images);
990 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
991 if (clipmasks_initialized)
993 for (i = 0; i < num_images; i++)
995 if (graphic_info[i].clip_mask)
996 XFreePixmap(display, graphic_info[i].clip_mask);
997 if (graphic_info[i].clip_gc)
998 XFreeGC(display, graphic_info[i].clip_gc);
1000 graphic_info[i].clip_mask = None;
1001 graphic_info[i].clip_gc = None;
1006 for (i = 0; i < num_images; i++)
1008 struct FileInfo *image = getImageListEntry(i);
1011 int first_frame, last_frame;
1014 printf("::: image: '%s' [%d]\n", image->token, i);
1018 printf("::: image # %d: '%s' ['%s']\n",
1020 getTokenFromImageID(i));
1023 set_graphic_parameters(i, image->parameter);
1025 /* now check if no animation frames are outside of the loaded image */
1027 if (graphic_info[i].bitmap == NULL)
1028 continue; /* skip check for optional images that are undefined */
1031 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1032 if (src_x < 0 || src_y < 0 ||
1033 src_x + TILEX > src_bitmap->width ||
1034 src_y + TILEY > src_bitmap->height)
1036 Error(ERR_RETURN_LINE, "-");
1037 Error(ERR_RETURN, "warning: error found in config file:");
1038 Error(ERR_RETURN, "- config file: '%s'",
1039 getImageConfigFilename());
1040 Error(ERR_RETURN, "- config token: '%s'",
1041 getTokenFromImageID(i));
1042 Error(ERR_RETURN, "- image file: '%s'",
1043 src_bitmap->source_filename);
1045 "error: first animation frame out of bounds (%d, %d)",
1047 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1049 if (i == fallback_graphic)
1050 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1052 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1053 Error(ERR_RETURN_LINE, "-");
1055 set_graphic_parameters(i, fallback_image->default_parameter);
1056 graphic_info[i].bitmap = fallback_bitmap;
1059 last_frame = graphic_info[i].anim_frames - 1;
1060 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1061 if (src_x < 0 || src_y < 0 ||
1062 src_x + TILEX > src_bitmap->width ||
1063 src_y + TILEY > src_bitmap->height)
1065 Error(ERR_RETURN_LINE, "-");
1066 Error(ERR_RETURN, "warning: error found in config file:");
1067 Error(ERR_RETURN, "- config file: '%s'",
1068 getImageConfigFilename());
1069 Error(ERR_RETURN, "- config token: '%s'",
1070 getTokenFromImageID(i));
1071 Error(ERR_RETURN, "- image file: '%s'",
1072 src_bitmap->source_filename);
1074 "error: last animation frame (%d) out of bounds (%d, %d)",
1075 last_frame, src_x, src_y);
1076 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1078 if (i == fallback_graphic)
1079 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1081 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1082 Error(ERR_RETURN_LINE, "-");
1084 set_graphic_parameters(i, fallback_image->default_parameter);
1085 graphic_info[i].bitmap = fallback_bitmap;
1088 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1089 /* currently we need only a tile clip mask from the first frame */
1090 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1092 if (copy_clipmask_gc == None)
1094 clip_gc_values.graphics_exposures = False;
1095 clip_gc_valuemask = GCGraphicsExposures;
1096 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1097 clip_gc_valuemask, &clip_gc_values);
1100 graphic_info[i].clip_mask =
1101 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1103 src_pixmap = src_bitmap->clip_mask;
1104 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1105 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1107 clip_gc_values.graphics_exposures = False;
1108 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1109 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1111 graphic_info[i].clip_gc =
1112 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1116 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1117 if (copy_clipmask_gc)
1118 XFreeGC(display, copy_clipmask_gc);
1120 clipmasks_initialized = TRUE;
1124 static void InitElementSoundInfo()
1126 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1127 int num_property_mappings = getSoundListPropertyMappingSize();
1130 /* set values to -1 to identify later as "uninitialized" values */
1131 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1132 for (act = 0; act < NUM_ACTIONS; act++)
1133 element_info[i].sound[act] = -1;
1135 /* initialize element/sound mapping from static configuration */
1136 for (i = 0; element_to_sound[i].element > -1; i++)
1138 int element = element_to_sound[i].element;
1139 int action = element_to_sound[i].action;
1140 int sound = element_to_sound[i].sound;
1141 boolean is_class = element_to_sound[i].is_class;
1144 action = ACTION_DEFAULT;
1147 element_info[element].sound[action] = sound;
1149 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1150 if (strcmp(element_info[j].class_name,
1151 element_info[element].class_name) == 0)
1152 element_info[j].sound[action] = sound;
1155 /* initialize element class/sound mapping from dynamic configuration */
1156 for (i = 0; i < num_property_mappings; i++)
1158 int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
1159 int action = property_mapping[i].ext1_index;
1160 int sound = property_mapping[i].artwork_index;
1162 if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
1166 action = ACTION_DEFAULT;
1168 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1169 if (strcmp(element_info[j].class_name,
1170 element_info[element_class].class_name) == 0)
1171 element_info[j].sound[action] = sound;
1174 /* initialize element/sound mapping from dynamic configuration */
1175 for (i = 0; i < num_property_mappings; i++)
1177 int element = property_mapping[i].base_index;
1178 int action = property_mapping[i].ext1_index;
1179 int sound = property_mapping[i].artwork_index;
1181 if (element >= MAX_NUM_ELEMENTS)
1185 action = ACTION_DEFAULT;
1187 element_info[element].sound[action] = sound;
1190 /* now set all '-1' values to element specific default values */
1191 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1193 for (act = 0; act < NUM_ACTIONS; act++)
1195 /* generic default action sound (defined by "[default]" directive) */
1196 int default_action_sound = element_info[EL_DEFAULT].sound[act];
1198 /* look for special default action sound (classic game specific) */
1199 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].sound[act] != -1)
1200 default_action_sound = element_info[EL_BD_DEFAULT].sound[act];
1201 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].sound[act] != -1)
1202 default_action_sound = element_info[EL_SP_DEFAULT].sound[act];
1203 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].sound[act] != -1)
1204 default_action_sound = element_info[EL_SB_DEFAULT].sound[act];
1206 /* !!! there's no such thing as a "default action sound" !!! */
1208 /* look for element specific default sound (independent from action) */
1209 if (element_info[i].sound[ACTION_DEFAULT] != -1)
1210 default_action_sound = element_info[i].sound[ACTION_DEFAULT];
1213 /* no sound for this specific action -- use default action sound */
1214 if (element_info[i].sound[act] == -1)
1215 element_info[i].sound[act] = default_action_sound;
1220 static void InitGameModeSoundInfo()
1224 /* set values to -1 to identify later as "uninitialized" values */
1225 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1228 /* initialize gamemode/sound mapping from static configuration */
1229 for (i = 0; gamemode_to_sound[i].sound > -1; i++)
1231 int gamemode = gamemode_to_sound[i].gamemode;
1232 int sound = gamemode_to_sound[i].sound;
1235 gamemode = GAME_MODE_DEFAULT;
1237 menu.sound[gamemode] = sound;
1240 /* now set all '-1' values to levelset specific default values */
1241 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1242 if (menu.sound[i] == -1)
1243 menu.sound[i] = menu.sound[GAME_MODE_DEFAULT];
1247 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1248 if (menu.sound[i] != -1)
1249 printf("::: menu.sound[%d] == %d\n", i, menu.sound[i]);
1253 static void set_sound_parameters(int sound, char **parameter_raw)
1255 int parameter[NUM_SND_ARGS];
1258 /* get integer values from string parameters */
1259 for (i = 0; i < NUM_SND_ARGS; i++)
1261 get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
1262 sound_config_suffix[i].type);
1264 /* explicit loop mode setting in configuration overrides default value */
1265 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1266 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1269 static void InitSoundInfo()
1272 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1273 int num_property_mappings = getSoundListPropertyMappingSize();
1275 int *sound_effect_properties;
1276 int num_sounds = getSoundListSize();
1279 checked_free(sound_info);
1281 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1282 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1284 /* initialize sound effect for all elements to "no sound" */
1285 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1286 for (j = 0; j < NUM_ACTIONS; j++)
1287 element_info[i].sound[j] = SND_UNDEFINED;
1289 for (i = 0; i < num_sounds; i++)
1291 struct FileInfo *sound = getSoundListEntry(i);
1292 int len_effect_text = strlen(sound->token);
1294 sound_effect_properties[i] = ACTION_OTHER;
1295 sound_info[i].loop = FALSE; /* default: play sound only once */
1298 printf("::: sound %d: '%s'\n", i, sound->token);
1301 /* determine all loop sounds and identify certain sound classes */
1303 for (j = 0; element_action_info[j].suffix; j++)
1305 int len_action_text = strlen(element_action_info[j].suffix);
1307 if (len_action_text < len_effect_text &&
1308 strcmp(&sound->token[len_effect_text - len_action_text],
1309 element_action_info[j].suffix) == 0)
1311 sound_effect_properties[i] = element_action_info[j].value;
1312 sound_info[i].loop = element_action_info[j].is_loop_sound;
1319 if (strcmp(sound->token, "custom_42") == 0)
1320 printf("::: '%s' -> %d\n", sound->token, sound_info[i].loop);
1323 /* associate elements and some selected sound actions */
1325 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1327 if (element_info[j].class_name)
1329 int len_class_text = strlen(element_info[j].class_name);
1331 if (len_class_text + 1 < len_effect_text &&
1332 strncmp(sound->token,
1333 element_info[j].class_name, len_class_text) == 0 &&
1334 sound->token[len_class_text] == '.')
1336 int sound_action_value = sound_effect_properties[i];
1338 element_info[j].sound[sound_action_value] = i;
1343 set_sound_parameters(i, sound->parameter);
1346 free(sound_effect_properties);
1349 /* !!! now handled in InitElementSoundInfo() !!! */
1350 /* initialize element/sound mapping from dynamic configuration */
1351 for (i = 0; i < num_property_mappings; i++)
1353 int element = property_mapping[i].base_index;
1354 int action = property_mapping[i].ext1_index;
1355 int sound = property_mapping[i].artwork_index;
1358 action = ACTION_DEFAULT;
1360 printf("::: %d: %d, %d, %d ['%s']\n",
1361 i, element, action, sound, element_info[element].token_name);
1363 element_info[element].sound[action] = sound;
1370 int element = EL_CUSTOM_11;
1373 while (element_action_info[j].suffix)
1375 printf("element %d, sound action '%s' == %d\n",
1376 element, element_action_info[j].suffix,
1377 element_info[element].sound[j]);
1382 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1388 int element = EL_SAND;
1389 int sound_action = ACTION_DIGGING;
1392 while (element_action_info[j].suffix)
1394 if (element_action_info[j].value == sound_action)
1395 printf("element %d, sound action '%s' == %d\n",
1396 element, element_action_info[j].suffix,
1397 element_info[element].sound[sound_action]);
1404 static void InitGameModeMusicInfo()
1406 struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
1407 int num_property_mappings = getMusicListPropertyMappingSize();
1408 int default_levelset_music = -1;
1411 /* set values to -1 to identify later as "uninitialized" values */
1412 for (i = 0; i < MAX_LEVELS; i++)
1413 levelset.music[i] = -1;
1414 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1417 /* initialize gamemode/music mapping from static configuration */
1418 for (i = 0; gamemode_to_music[i].music > -1; i++)
1420 int gamemode = gamemode_to_music[i].gamemode;
1421 int music = gamemode_to_music[i].music;
1424 printf("::: gamemode == %d, music == %d\n", gamemode, music);
1428 gamemode = GAME_MODE_DEFAULT;
1430 menu.music[gamemode] = music;
1433 /* initialize gamemode/music mapping from dynamic configuration */
1434 for (i = 0; i < num_property_mappings; i++)
1436 int prefix = property_mapping[i].base_index;
1437 int gamemode = property_mapping[i].ext1_index;
1438 int level = property_mapping[i].ext2_index;
1439 int music = property_mapping[i].artwork_index;
1442 printf("::: prefix == %d, gamemode == %d, level == %d, music == %d\n",
1443 prefix, gamemode, level, music);
1446 if (prefix < 0 || prefix >= NUM_MUSIC_PREFIXES)
1450 gamemode = GAME_MODE_DEFAULT;
1452 /* level specific music only allowed for in-game music */
1453 if (level != -1 && gamemode == GAME_MODE_DEFAULT)
1454 gamemode = GAME_MODE_PLAYING;
1459 default_levelset_music = music;
1462 if (gamemode == GAME_MODE_PLAYING || gamemode == GAME_MODE_DEFAULT)
1463 levelset.music[level] = music;
1464 if (gamemode != GAME_MODE_PLAYING)
1465 menu.music[gamemode] = music;
1468 /* now set all '-1' values to menu specific default values */
1469 /* (undefined values of "levelset.music[]" might stay at "-1" to
1470 allow dynamic selection of music files from music directory!) */
1471 for (i = 0; i < MAX_LEVELS; i++)
1472 if (levelset.music[i] == -1)
1473 levelset.music[i] = default_levelset_music;
1474 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1475 if (menu.music[i] == -1)
1476 menu.music[i] = menu.music[GAME_MODE_DEFAULT];
1480 for (i = 0; i < MAX_LEVELS; i++)
1481 if (levelset.music[i] != -1)
1482 printf("::: levelset.music[%d] == %d\n", i, levelset.music[i]);
1483 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1484 if (menu.music[i] != -1)
1485 printf("::: menu.music[%d] == %d\n", i, menu.music[i]);
1489 static void set_music_parameters(int music, char **parameter_raw)
1491 int parameter[NUM_MUS_ARGS];
1494 /* get integer values from string parameters */
1495 for (i = 0; i < NUM_MUS_ARGS; i++)
1497 get_parameter_value(music_config_suffix[i].token, parameter_raw[i],
1498 music_config_suffix[i].type);
1500 /* explicit loop mode setting in configuration overrides default value */
1501 if (parameter[MUS_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1502 music_info[music].loop = parameter[MUS_ARG_MODE_LOOP];
1505 static void InitMusicInfo()
1507 int num_music = getMusicListSize();
1510 checked_free(music_info);
1512 music_info = checked_calloc(num_music * sizeof(struct MusicInfo));
1514 for (i = 0; i < num_music; i++)
1516 struct FileInfo *music = getMusicListEntry(i);
1517 int len_music_text = strlen(music->token);
1519 music_info[i].loop = TRUE; /* default: play music in loop mode */
1521 /* determine all loop music */
1523 for (j = 0; music_prefix_info[j].prefix; j++)
1525 int len_prefix_text = strlen(music_prefix_info[j].prefix);
1527 if (len_prefix_text < len_music_text &&
1528 strncmp(music->token,
1529 music_prefix_info[j].prefix, len_prefix_text) == 0)
1531 music_info[i].loop = music_prefix_info[j].is_loop_music;
1537 set_music_parameters(i, music->parameter);
1541 static void ReinitializeGraphics()
1543 InitGraphicInfo(); /* graphic properties mapping */
1544 InitElementGraphicInfo(); /* element game graphic mapping */
1545 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
1547 InitElementSmallImages(); /* create editor and preview images */
1548 InitFontGraphicInfo(); /* initialize text drawing functions */
1550 SetMainBackgroundImage(IMG_BACKGROUND);
1551 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1557 static void ReinitializeSounds()
1559 InitSoundInfo(); /* sound properties mapping */
1560 InitElementSoundInfo(); /* element game sound mapping */
1561 InitGameModeSoundInfo(); /* game mode sound mapping */
1563 InitPlayLevelSound(); /* internal game sound settings */
1566 static void ReinitializeMusic()
1568 InitMusicInfo(); /* music properties mapping */
1569 InitGameModeMusicInfo(); /* game mode music mapping */
1572 static int get_special_property_bit(int element, int base_property_bit)
1578 } pb_can_move_into_acid[] =
1582 { EL_BUG_RIGHT, 0 },
1585 { EL_SPACESHIP, 0 },
1586 { EL_SPACESHIP_LEFT, 0 },
1587 { EL_SPACESHIP_RIGHT, 0 },
1588 { EL_SPACESHIP_UP, 0 },
1589 { EL_SPACESHIP_DOWN, 0 },
1590 { EL_BD_BUTTERFLY, 1 },
1591 { EL_BD_BUTTERFLY_LEFT, 1 },
1592 { EL_BD_BUTTERFLY_RIGHT, 1 },
1593 { EL_BD_BUTTERFLY_UP, 1 },
1594 { EL_BD_BUTTERFLY_DOWN, 1 },
1595 { EL_BD_FIREFLY, 1 },
1596 { EL_BD_FIREFLY_LEFT, 1 },
1597 { EL_BD_FIREFLY_RIGHT, 1 },
1598 { EL_BD_FIREFLY_UP, 1 },
1599 { EL_BD_FIREFLY_DOWN, 1 },
1601 { EL_DARK_YAMYAM, 2 },
1604 { EL_PACMAN_LEFT, 4 },
1605 { EL_PACMAN_RIGHT, 4 },
1606 { EL_PACMAN_UP, 4 },
1607 { EL_PACMAN_DOWN, 4 },
1609 { EL_MOLE_LEFT, 4 },
1610 { EL_MOLE_RIGHT, 4 },
1612 { EL_MOLE_DOWN, 4 },
1616 { EL_SATELLITE, 7 },
1617 { EL_SP_SNIKSNAK, 8 },
1618 { EL_SP_ELECTRON, 8 },
1625 if (base_property_bit != EP_CAN_MOVE_INTO_ACID)
1628 for (i = 0; pb_can_move_into_acid[i].element != -1; i++)
1629 if (pb_can_move_into_acid[i].element == element)
1630 return pb_can_move_into_acid[i].bit_nr;
1635 void setMoveIntoAcidProperty(struct LevelInfo *level, int element, boolean set)
1637 int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
1641 level->can_move_into_acid &= ~(1 << bit_nr);
1644 level->can_move_into_acid |= (1 << bit_nr);
1648 boolean getMoveIntoAcidProperty(struct LevelInfo *level, int element)
1650 int bit_nr = get_special_property_bit(element, EP_CAN_MOVE_INTO_ACID);
1653 return ((level->can_move_into_acid & (1 << bit_nr)) != 0);
1658 void InitElementPropertiesStatic()
1660 static int ep_diggable[] =
1665 EL_SP_BUGGY_BASE_ACTIVATING,
1668 EL_INVISIBLE_SAND_ACTIVE,
1670 /* !!! currently not diggable, but handled by 'ep_dont_run_into' !!! */
1674 EL_SP_BUGGY_BASE_ACTIVE,
1679 static int ep_collectible_only[] =
1696 EL_DYNABOMB_INCREASE_NUMBER,
1697 EL_DYNABOMB_INCREASE_SIZE,
1698 EL_DYNABOMB_INCREASE_POWER,
1715 static int ep_dont_run_into[] =
1717 /* same elements as in 'ep_dont_touch' */
1723 /* same elements as in 'ep_dont_collide_with' */
1735 /* !!! maybe this should better be handled by 'ep_diggable' !!! */
1739 EL_SP_BUGGY_BASE_ACTIVE,
1744 static int ep_dont_collide_with[] =
1746 /* same elements as in 'ep_dont_touch' */
1762 static int ep_dont_touch[] =
1771 static int ep_indestructible[] =
1775 EL_ACID_POOL_TOPLEFT,
1776 EL_ACID_POOL_TOPRIGHT,
1777 EL_ACID_POOL_BOTTOMLEFT,
1778 EL_ACID_POOL_BOTTOM,
1779 EL_ACID_POOL_BOTTOMRIGHT,
1780 EL_SP_HARDWARE_GRAY,
1781 EL_SP_HARDWARE_GREEN,
1782 EL_SP_HARDWARE_BLUE,
1784 EL_SP_HARDWARE_YELLOW,
1785 EL_SP_HARDWARE_BASE_1,
1786 EL_SP_HARDWARE_BASE_2,
1787 EL_SP_HARDWARE_BASE_3,
1788 EL_SP_HARDWARE_BASE_4,
1789 EL_SP_HARDWARE_BASE_5,
1790 EL_SP_HARDWARE_BASE_6,
1791 EL_INVISIBLE_STEELWALL,
1792 EL_INVISIBLE_STEELWALL_ACTIVE,
1793 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1794 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1795 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1796 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1797 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1798 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1799 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1800 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1801 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1802 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1803 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1804 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1806 EL_LIGHT_SWITCH_ACTIVE,
1807 EL_SIGN_EXCLAMATION,
1808 EL_SIGN_RADIOACTIVITY,
1819 EL_STEELWALL_SLIPPERY,
1842 EL_SWITCHGATE_OPENING,
1843 EL_SWITCHGATE_CLOSED,
1844 EL_SWITCHGATE_CLOSING,
1846 EL_SWITCHGATE_SWITCH_UP,
1847 EL_SWITCHGATE_SWITCH_DOWN,
1850 EL_TIMEGATE_OPENING,
1852 EL_TIMEGATE_CLOSING,
1855 EL_TIMEGATE_SWITCH_ACTIVE,
1860 EL_TUBE_VERTICAL_LEFT,
1861 EL_TUBE_VERTICAL_RIGHT,
1862 EL_TUBE_HORIZONTAL_UP,
1863 EL_TUBE_HORIZONTAL_DOWN,
1871 static int ep_slippery[] =
1885 EL_ROBOT_WHEEL_ACTIVE,
1891 EL_ACID_POOL_TOPLEFT,
1892 EL_ACID_POOL_TOPRIGHT,
1902 EL_STEELWALL_SLIPPERY,
1908 static int ep_can_change[] =
1913 static int ep_can_move[] =
1935 static int ep_can_fall[] =
1950 EL_BD_MAGIC_WALL_FULL,
1963 static int ep_can_smash_player[] =
1988 static int ep_can_smash_enemies[] =
1996 static int ep_can_smash_everything[] =
2004 static int ep_can_explode_by_fire[] =
2006 /* same elements as in 'ep_can_explode_impact' */
2011 /* same elements as in 'ep_can_explode_smashed' */
2020 EL_DYNABOMB_PLAYER_1_ACTIVE,
2021 EL_DYNABOMB_PLAYER_2_ACTIVE,
2022 EL_DYNABOMB_PLAYER_3_ACTIVE,
2023 EL_DYNABOMB_PLAYER_4_ACTIVE,
2024 EL_DYNABOMB_INCREASE_NUMBER,
2025 EL_DYNABOMB_INCREASE_SIZE,
2026 EL_DYNABOMB_INCREASE_POWER,
2027 EL_SP_DISK_RED_ACTIVE,
2040 static int ep_can_explode_smashed[] =
2042 /* same elements as in 'ep_can_explode_impact' */
2055 static int ep_can_explode_impact[] =
2063 static int ep_walkable_over[] =
2067 EL_SOKOBAN_FIELD_EMPTY,
2085 static int ep_walkable_inside[] =
2090 EL_TUBE_VERTICAL_LEFT,
2091 EL_TUBE_VERTICAL_RIGHT,
2092 EL_TUBE_HORIZONTAL_UP,
2093 EL_TUBE_HORIZONTAL_DOWN,
2101 static int ep_walkable_under[] =
2106 static int ep_passable_over[] =
2121 static int ep_passable_inside[] =
2127 EL_SP_PORT_HORIZONTAL,
2128 EL_SP_PORT_VERTICAL,
2130 EL_SP_GRAVITY_PORT_LEFT,
2131 EL_SP_GRAVITY_PORT_RIGHT,
2132 EL_SP_GRAVITY_PORT_UP,
2133 EL_SP_GRAVITY_PORT_DOWN,
2137 static int ep_passable_under[] =
2142 static int ep_droppable[] =
2147 static int ep_can_explode_1x1[] =
2152 static int ep_pushable[] =
2164 EL_SOKOBAN_FIELD_FULL,
2171 static int ep_can_explode_dyna[] =
2176 static int ep_protected[] =
2191 static int ep_player[] =
2201 static int ep_can_pass_magic_wall[] =
2214 static int ep_switchable[] =
2218 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2219 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2220 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2221 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2222 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2223 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2224 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2225 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2226 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2227 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2228 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2229 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2230 EL_SWITCHGATE_SWITCH_UP,
2231 EL_SWITCHGATE_SWITCH_DOWN,
2233 EL_LIGHT_SWITCH_ACTIVE,
2235 EL_BALLOON_SWITCH_LEFT,
2236 EL_BALLOON_SWITCH_RIGHT,
2237 EL_BALLOON_SWITCH_UP,
2238 EL_BALLOON_SWITCH_DOWN,
2239 EL_BALLOON_SWITCH_ANY,
2245 static int ep_bd_element[] =
2275 static int ep_sp_element[] =
2277 /* should always be valid */
2286 EL_SP_HARDWARE_GRAY,
2294 EL_SP_GRAVITY_PORT_RIGHT,
2295 EL_SP_GRAVITY_PORT_DOWN,
2296 EL_SP_GRAVITY_PORT_LEFT,
2297 EL_SP_GRAVITY_PORT_UP,
2302 EL_SP_PORT_VERTICAL,
2303 EL_SP_PORT_HORIZONTAL,
2309 EL_SP_HARDWARE_BASE_1,
2310 EL_SP_HARDWARE_GREEN,
2311 EL_SP_HARDWARE_BLUE,
2313 EL_SP_HARDWARE_YELLOW,
2314 EL_SP_HARDWARE_BASE_2,
2315 EL_SP_HARDWARE_BASE_3,
2316 EL_SP_HARDWARE_BASE_4,
2317 EL_SP_HARDWARE_BASE_5,
2318 EL_SP_HARDWARE_BASE_6,
2321 /* additional elements that appeared in newer Supaplex levels */
2323 /* more than one murphy in a level results in an inactive clone */
2325 /* runtime elements*/
2326 EL_SP_DISK_RED_ACTIVE,
2327 EL_SP_TERMINAL_ACTIVE,
2328 EL_SP_BUGGY_BASE_ACTIVATING,
2329 EL_SP_BUGGY_BASE_ACTIVE,
2335 static int ep_sb_element[] =
2340 EL_SOKOBAN_FIELD_EMPTY,
2341 EL_SOKOBAN_FIELD_FULL,
2343 EL_INVISIBLE_STEELWALL,
2347 static int ep_gem[] =
2358 static int ep_food_dark_yamyam[] =
2385 static int ep_food_penguin[] =
2398 static int ep_food_pig[] =
2409 static int ep_historic_wall[] =
2434 EL_EXPANDABLE_WALL_HORIZONTAL,
2435 EL_EXPANDABLE_WALL_VERTICAL,
2436 EL_EXPANDABLE_WALL_ANY,
2437 EL_EXPANDABLE_WALL_GROWING,
2444 EL_SP_HARDWARE_GRAY,
2445 EL_SP_HARDWARE_GREEN,
2446 EL_SP_HARDWARE_BLUE,
2448 EL_SP_HARDWARE_YELLOW,
2449 EL_SP_HARDWARE_BASE_1,
2450 EL_SP_HARDWARE_BASE_2,
2451 EL_SP_HARDWARE_BASE_3,
2452 EL_SP_HARDWARE_BASE_4,
2453 EL_SP_HARDWARE_BASE_5,
2454 EL_SP_HARDWARE_BASE_6,
2456 EL_SP_TERMINAL_ACTIVE,
2459 EL_INVISIBLE_STEELWALL,
2460 EL_INVISIBLE_STEELWALL_ACTIVE,
2462 EL_INVISIBLE_WALL_ACTIVE,
2463 EL_STEELWALL_SLIPPERY,
2479 static int ep_historic_solid[] =
2483 EL_EXPANDABLE_WALL_HORIZONTAL,
2484 EL_EXPANDABLE_WALL_VERTICAL,
2485 EL_EXPANDABLE_WALL_ANY,
2498 EL_QUICKSAND_FILLING,
2499 EL_QUICKSAND_EMPTYING,
2501 EL_MAGIC_WALL_ACTIVE,
2502 EL_MAGIC_WALL_EMPTYING,
2503 EL_MAGIC_WALL_FILLING,
2507 EL_BD_MAGIC_WALL_ACTIVE,
2508 EL_BD_MAGIC_WALL_EMPTYING,
2509 EL_BD_MAGIC_WALL_FULL,
2510 EL_BD_MAGIC_WALL_FILLING,
2511 EL_BD_MAGIC_WALL_DEAD,
2520 EL_SP_TERMINAL_ACTIVE,
2524 EL_INVISIBLE_WALL_ACTIVE,
2525 EL_SWITCHGATE_SWITCH_UP,
2526 EL_SWITCHGATE_SWITCH_DOWN,
2528 EL_TIMEGATE_SWITCH_ACTIVE,
2540 /* the following elements are a direct copy of "indestructible" elements,
2541 except "EL_ACID", which is "indestructible", but not "solid"! */
2546 EL_ACID_POOL_TOPLEFT,
2547 EL_ACID_POOL_TOPRIGHT,
2548 EL_ACID_POOL_BOTTOMLEFT,
2549 EL_ACID_POOL_BOTTOM,
2550 EL_ACID_POOL_BOTTOMRIGHT,
2551 EL_SP_HARDWARE_GRAY,
2552 EL_SP_HARDWARE_GREEN,
2553 EL_SP_HARDWARE_BLUE,
2555 EL_SP_HARDWARE_YELLOW,
2556 EL_SP_HARDWARE_BASE_1,
2557 EL_SP_HARDWARE_BASE_2,
2558 EL_SP_HARDWARE_BASE_3,
2559 EL_SP_HARDWARE_BASE_4,
2560 EL_SP_HARDWARE_BASE_5,
2561 EL_SP_HARDWARE_BASE_6,
2562 EL_INVISIBLE_STEELWALL,
2563 EL_INVISIBLE_STEELWALL_ACTIVE,
2564 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2565 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2566 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2567 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2568 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2569 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2570 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2571 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2572 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2573 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2574 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2575 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2577 EL_LIGHT_SWITCH_ACTIVE,
2578 EL_SIGN_EXCLAMATION,
2579 EL_SIGN_RADIOACTIVITY,
2590 EL_STEELWALL_SLIPPERY,
2613 EL_SWITCHGATE_OPENING,
2614 EL_SWITCHGATE_CLOSED,
2615 EL_SWITCHGATE_CLOSING,
2617 EL_TIMEGATE_OPENING,
2619 EL_TIMEGATE_CLOSING,
2623 EL_TUBE_VERTICAL_LEFT,
2624 EL_TUBE_VERTICAL_RIGHT,
2625 EL_TUBE_HORIZONTAL_UP,
2626 EL_TUBE_HORIZONTAL_DOWN,
2634 static int ep_classic_enemy[] =
2650 static int ep_belt[] =
2652 EL_CONVEYOR_BELT_1_LEFT,
2653 EL_CONVEYOR_BELT_1_MIDDLE,
2654 EL_CONVEYOR_BELT_1_RIGHT,
2655 EL_CONVEYOR_BELT_2_LEFT,
2656 EL_CONVEYOR_BELT_2_MIDDLE,
2657 EL_CONVEYOR_BELT_2_RIGHT,
2658 EL_CONVEYOR_BELT_3_LEFT,
2659 EL_CONVEYOR_BELT_3_MIDDLE,
2660 EL_CONVEYOR_BELT_3_RIGHT,
2661 EL_CONVEYOR_BELT_4_LEFT,
2662 EL_CONVEYOR_BELT_4_MIDDLE,
2663 EL_CONVEYOR_BELT_4_RIGHT,
2667 static int ep_belt_active[] =
2669 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
2670 EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
2671 EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
2672 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
2673 EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
2674 EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
2675 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
2676 EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
2677 EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
2678 EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
2679 EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
2680 EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
2684 static int ep_belt_switch[] =
2686 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2687 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2688 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2689 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2690 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2691 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2692 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2693 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2694 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2695 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2696 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2697 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2701 static int ep_tube[] =
2708 EL_TUBE_HORIZONTAL_UP,
2709 EL_TUBE_HORIZONTAL_DOWN,
2711 EL_TUBE_VERTICAL_LEFT,
2712 EL_TUBE_VERTICAL_RIGHT,
2717 static int ep_keygate[] =
2738 static int ep_amoeboid[] =
2748 static int ep_amoebalive[] =
2757 static int ep_has_content[] =
2767 static int ep_active_bomb[] =
2770 EL_DYNABOMB_PLAYER_1_ACTIVE,
2771 EL_DYNABOMB_PLAYER_2_ACTIVE,
2772 EL_DYNABOMB_PLAYER_3_ACTIVE,
2773 EL_DYNABOMB_PLAYER_4_ACTIVE,
2774 EL_SP_DISK_RED_ACTIVE,
2778 static int ep_inactive[] =
2815 EL_INVISIBLE_STEELWALL,
2823 EL_WALL_EMERALD_YELLOW,
2824 EL_DYNABOMB_INCREASE_NUMBER,
2825 EL_DYNABOMB_INCREASE_SIZE,
2826 EL_DYNABOMB_INCREASE_POWER,
2830 EL_SOKOBAN_FIELD_EMPTY,
2831 EL_SOKOBAN_FIELD_FULL,
2832 EL_WALL_EMERALD_RED,
2833 EL_WALL_EMERALD_PURPLE,
2834 EL_ACID_POOL_TOPLEFT,
2835 EL_ACID_POOL_TOPRIGHT,
2836 EL_ACID_POOL_BOTTOMLEFT,
2837 EL_ACID_POOL_BOTTOM,
2838 EL_ACID_POOL_BOTTOMRIGHT,
2842 EL_BD_MAGIC_WALL_DEAD,
2843 EL_AMOEBA_TO_DIAMOND,
2851 EL_SP_GRAVITY_PORT_RIGHT,
2852 EL_SP_GRAVITY_PORT_DOWN,
2853 EL_SP_GRAVITY_PORT_LEFT,
2854 EL_SP_GRAVITY_PORT_UP,
2855 EL_SP_PORT_HORIZONTAL,
2856 EL_SP_PORT_VERTICAL,
2867 EL_SP_HARDWARE_GRAY,
2868 EL_SP_HARDWARE_GREEN,
2869 EL_SP_HARDWARE_BLUE,
2871 EL_SP_HARDWARE_YELLOW,
2872 EL_SP_HARDWARE_BASE_1,
2873 EL_SP_HARDWARE_BASE_2,
2874 EL_SP_HARDWARE_BASE_3,
2875 EL_SP_HARDWARE_BASE_4,
2876 EL_SP_HARDWARE_BASE_5,
2877 EL_SP_HARDWARE_BASE_6,
2878 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2879 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2880 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2881 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2882 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2883 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2884 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2885 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2886 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2887 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2888 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2889 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2890 EL_SIGN_EXCLAMATION,
2891 EL_SIGN_RADIOACTIVITY,
2902 EL_STEELWALL_SLIPPERY,
2918 static int ep_em_slippery_wall[] =
2923 static int ep_gfx_crumbled[] =
2936 } element_properties[] =
2938 { ep_diggable, EP_DIGGABLE },
2939 { ep_collectible_only, EP_COLLECTIBLE_ONLY },
2940 { ep_dont_run_into, EP_DONT_RUN_INTO },
2941 { ep_dont_collide_with, EP_DONT_COLLIDE_WITH },
2942 { ep_dont_touch, EP_DONT_TOUCH },
2943 { ep_indestructible, EP_INDESTRUCTIBLE },
2944 { ep_slippery, EP_SLIPPERY },
2945 { ep_can_change, EP_CAN_CHANGE },
2946 { ep_can_move, EP_CAN_MOVE },
2947 { ep_can_fall, EP_CAN_FALL },
2948 { ep_can_smash_player, EP_CAN_SMASH_PLAYER },
2949 { ep_can_smash_enemies, EP_CAN_SMASH_ENEMIES },
2950 { ep_can_smash_everything, EP_CAN_SMASH_EVERYTHING },
2951 { ep_can_explode_by_fire, EP_CAN_EXPLODE_BY_FIRE },
2952 { ep_can_explode_smashed, EP_CAN_EXPLODE_SMASHED },
2953 { ep_can_explode_impact, EP_CAN_EXPLODE_IMPACT },
2954 { ep_walkable_over, EP_WALKABLE_OVER },
2955 { ep_walkable_inside, EP_WALKABLE_INSIDE },
2956 { ep_walkable_under, EP_WALKABLE_UNDER },
2957 { ep_passable_over, EP_PASSABLE_OVER },
2958 { ep_passable_inside, EP_PASSABLE_INSIDE },
2959 { ep_passable_under, EP_PASSABLE_UNDER },
2960 { ep_droppable, EP_DROPPABLE },
2961 { ep_can_explode_1x1, EP_CAN_EXPLODE_1X1 },
2962 { ep_pushable, EP_PUSHABLE },
2963 { ep_can_explode_dyna, EP_CAN_EXPLODE_DYNA },
2964 { ep_protected, EP_PROTECTED },
2966 { ep_player, EP_PLAYER },
2967 { ep_can_pass_magic_wall, EP_CAN_PASS_MAGIC_WALL },
2968 { ep_switchable, EP_SWITCHABLE },
2969 { ep_bd_element, EP_BD_ELEMENT },
2970 { ep_sp_element, EP_SP_ELEMENT },
2971 { ep_sb_element, EP_SB_ELEMENT },
2973 { ep_food_dark_yamyam, EP_FOOD_DARK_YAMYAM },
2974 { ep_food_penguin, EP_FOOD_PENGUIN },
2975 { ep_food_pig, EP_FOOD_PIG },
2976 { ep_historic_wall, EP_HISTORIC_WALL },
2977 { ep_historic_solid, EP_HISTORIC_SOLID },
2978 { ep_classic_enemy, EP_CLASSIC_ENEMY },
2979 { ep_belt, EP_BELT },
2980 { ep_belt_active, EP_BELT_ACTIVE },
2981 { ep_belt_switch, EP_BELT_SWITCH },
2982 { ep_tube, EP_TUBE },
2983 { ep_keygate, EP_KEYGATE },
2984 { ep_amoeboid, EP_AMOEBOID },
2985 { ep_amoebalive, EP_AMOEBALIVE },
2986 { ep_has_content, EP_HAS_CONTENT },
2987 { ep_active_bomb, EP_ACTIVE_BOMB },
2988 { ep_inactive, EP_INACTIVE },
2990 { ep_em_slippery_wall, EP_EM_SLIPPERY_WALL },
2992 { ep_gfx_crumbled, EP_GFX_CRUMBLED },
2997 static int copy_properties[][5] =
3001 EL_BUG_LEFT, EL_BUG_RIGHT,
3002 EL_BUG_UP, EL_BUG_DOWN
3006 EL_SPACESHIP_LEFT, EL_SPACESHIP_RIGHT,
3007 EL_SPACESHIP_UP, EL_SPACESHIP_DOWN
3011 EL_BD_BUTTERFLY_LEFT, EL_BD_BUTTERFLY_RIGHT,
3012 EL_BD_BUTTERFLY_UP, EL_BD_BUTTERFLY_DOWN
3016 EL_BD_FIREFLY_LEFT, EL_BD_FIREFLY_RIGHT,
3017 EL_BD_FIREFLY_UP, EL_BD_FIREFLY_DOWN
3021 EL_PACMAN_LEFT, EL_PACMAN_RIGHT,
3022 EL_PACMAN_UP, EL_PACMAN_DOWN
3026 EL_MOLE_LEFT, EL_MOLE_RIGHT,
3027 EL_MOLE_UP, EL_MOLE_DOWN
3037 /* always start with reliable default values (element has no properties) */
3038 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3039 for (j = 0; j < NUM_ELEMENT_PROPERTIES; j++)
3040 SET_PROPERTY(i, j, FALSE);
3042 /* set all base element properties from above array definitions */
3043 for (i = 0; element_properties[i].elements != NULL; i++)
3044 for (j = 0; (element_properties[i].elements)[j] != -1; j++)
3045 SET_PROPERTY((element_properties[i].elements)[j],
3046 element_properties[i].property, TRUE);
3048 /* copy properties to some elements that are only stored in level file */
3049 for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
3050 for (j = 0; copy_properties[j][0] != -1; j++)
3051 if (HAS_PROPERTY(copy_properties[j][0], i))
3052 for (k = 1; k <= 4; k++)
3053 SET_PROPERTY(copy_properties[j][k], i, TRUE);
3056 void InitElementPropertiesEngine(int engine_version)
3059 static int active_properties[] =
3064 EP_DONT_COLLIDE_WITH,
3068 EP_CAN_PASS_MAGIC_WALL,
3073 EP_CAN_EXPLODE_BY_FIRE,
3086 EP_EM_SLIPPERY_WALL,
3090 static int no_wall_properties[] =
3093 EP_COLLECTIBLE_ONLY,
3095 EP_DONT_COLLIDE_WITH,
3098 EP_CAN_SMASH_PLAYER,
3099 EP_CAN_SMASH_ENEMIES,
3100 EP_CAN_SMASH_EVERYTHING,
3105 EP_FOOD_DARK_YAMYAM,
3122 InitElementPropertiesStatic();
3125 /* set all special, combined or engine dependent element properties */
3126 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3129 for (j = EP_ACCESSIBLE_OVER; j < NUM_ELEMENT_PROPERTIES; j++)
3130 SET_PROPERTY(i, j, FALSE);
3133 /* ---------- INACTIVE ------------------------------------------------- */
3134 if (i >= EL_CHAR_START && i <= EL_CHAR_END)
3135 SET_PROPERTY(i, EP_INACTIVE, TRUE);
3137 /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
3138 SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) ||
3139 IS_WALKABLE_INSIDE(i) ||
3140 IS_WALKABLE_UNDER(i)));
3142 SET_PROPERTY(i, EP_PASSABLE, (IS_PASSABLE_OVER(i) ||
3143 IS_PASSABLE_INSIDE(i) ||
3144 IS_PASSABLE_UNDER(i)));
3146 SET_PROPERTY(i, EP_ACCESSIBLE_OVER, (IS_WALKABLE_OVER(i) ||
3147 IS_PASSABLE_OVER(i)));
3149 SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, (IS_WALKABLE_INSIDE(i) ||
3150 IS_PASSABLE_INSIDE(i)));
3152 SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, (IS_WALKABLE_UNDER(i) ||
3153 IS_PASSABLE_UNDER(i)));
3155 SET_PROPERTY(i, EP_ACCESSIBLE, (IS_WALKABLE(i) ||
3158 /* ---------- COLLECTIBLE ---------------------------------------------- */
3159 SET_PROPERTY(i, EP_COLLECTIBLE, (IS_COLLECTIBLE_ONLY(i) ||
3162 /* ---------- SNAPPABLE ------------------------------------------------ */
3163 SET_PROPERTY(i, EP_SNAPPABLE, (IS_DIGGABLE(i) ||
3164 IS_COLLECTIBLE(i) ||
3168 /* ---------- WALL ----------------------------------------------------- */
3169 SET_PROPERTY(i, EP_WALL, TRUE); /* default: element is wall */
3171 for (j = 0; no_wall_properties[j] != -1; j++)
3172 if (HAS_PROPERTY(i, no_wall_properties[j]) ||
3173 i >= EL_FIRST_RUNTIME_UNREAL)
3174 SET_PROPERTY(i, EP_WALL, FALSE);
3176 if (IS_HISTORIC_WALL(i))
3177 SET_PROPERTY(i, EP_WALL, TRUE);
3179 /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */
3180 if (engine_version < VERSION_IDENT(2,2,0,0))
3181 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i));
3183 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) &&
3185 !IS_COLLECTIBLE(i)));
3187 /* ---------- PROTECTED ------------------------------------------------ */
3188 if (IS_ACCESSIBLE_INSIDE(i))
3189 SET_PROPERTY(i, EP_PROTECTED, TRUE);
3191 /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
3193 if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION)
3194 SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
3196 SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_CUSTOM_ELEMENT(i) &&
3197 IS_INDESTRUCTIBLE(i)));
3199 /* ---------- EXPLOSION_PROOF ------------------------------------------ */
3201 SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE);
3202 else if (engine_version < VERSION_IDENT(2,2,0,0))
3203 SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i));
3206 SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3211 SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3212 !IS_WALKABLE_OVER(i) &&
3213 !IS_WALKABLE_UNDER(i)));
3215 SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
3220 if (IS_CUSTOM_ELEMENT(i))
3222 /* ---------- DONT_COLLIDE_WITH / DONT_RUN_INTO ---------------------- */
3224 SET_PROPERTY(i, EP_DONT_COLLIDE_WITH, TRUE);
3225 if (DONT_COLLIDE_WITH(i))
3226 SET_PROPERTY(i, EP_DONT_RUN_INTO, TRUE);
3228 /* ---------- CAN_SMASH_ENEMIES / CAN_SMASH_PLAYER ------------------- */
3229 if (CAN_SMASH_EVERYTHING(i))
3230 SET_PROPERTY(i, EP_CAN_SMASH_ENEMIES, TRUE);
3231 if (CAN_SMASH_ENEMIES(i))
3232 SET_PROPERTY(i, EP_CAN_SMASH_PLAYER, TRUE);
3235 /* ---------- CAN_SMASH ------------------------------------------------ */
3236 SET_PROPERTY(i, EP_CAN_SMASH, (CAN_SMASH_PLAYER(i) ||
3237 CAN_SMASH_ENEMIES(i) ||
3238 CAN_SMASH_EVERYTHING(i)));
3240 /* ---------- CAN_EXPLODE ---------------------------------------------- */
3241 SET_PROPERTY(i, EP_CAN_EXPLODE, (CAN_EXPLODE_BY_FIRE(i) ||
3242 CAN_EXPLODE_SMASHED(i) ||
3243 CAN_EXPLODE_IMPACT(i)));
3245 /* ---------- CAN_EXPLODE_3X3 ------------------------------------------ */
3246 SET_PROPERTY(i, EP_CAN_EXPLODE_3X3, (CAN_EXPLODE(i) &&
3247 !CAN_EXPLODE_1X1(i) &&
3248 !CAN_EXPLODE_DYNA(i)));
3250 /* ---------- CAN_EXPLODE_BY_DRAGONFIRE -------------------------------- */
3251 SET_PROPERTY(i, EP_CAN_EXPLODE_BY_DRAGONFIRE, CAN_EXPLODE_BY_FIRE(i));
3253 /* ---------- CAN_EXPLODE_BY_EXPLOSION --------------------------------- */
3254 SET_PROPERTY(i, EP_CAN_EXPLODE_BY_EXPLOSION, (CAN_EXPLODE_BY_FIRE(i) ||
3255 i == EL_BLACK_ORB));
3257 /* ---------- COULD_MOVE_INTO_ACID ------------------------------------- */
3258 SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, ((CAN_MOVE(i) && i != EL_SPRING)||
3259 IS_CUSTOM_ELEMENT(i)));
3261 /* ---------- CAN_MOVE_INTO_ACID --------------------------------------- */
3262 if (getMoveIntoAcidProperty(&level, i))
3263 SET_PROPERTY(i, EP_CAN_MOVE_INTO_ACID, TRUE);
3265 /* ---------- SP_PORT -------------------------------------------------- */
3266 SET_PROPERTY(i, EP_SP_PORT, (IS_SP_ELEMENT(i) &&
3267 IS_PASSABLE_INSIDE(i)));
3270 if (i == EL_CUSTOM_START + 253)
3271 printf("::: %d, %d, %d -> %d\n",
3274 CAN_EXPLODE_DYNA(i),
3278 /* ---------- CAN_CHANGE ----------------------------------------------- */
3279 SET_PROPERTY(i, EP_CAN_CHANGE, FALSE); /* default: cannot change */
3280 for (j = 0; j < element_info[i].num_change_pages; j++)
3281 if (element_info[i].change_page[j].can_change)
3282 SET_PROPERTY(i, EP_CAN_CHANGE, TRUE);
3284 /* ---------- GFX_CRUMBLED --------------------------------------------- */
3285 SET_PROPERTY(i, EP_GFX_CRUMBLED,
3286 element_info[i].crumbled[ACTION_DEFAULT] != IMG_EMPTY);
3290 /* determine inactive elements (used for engine main loop optimization) */
3291 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3293 boolean active = FALSE;
3295 for (j = 0; i < NUM_ELEMENT_PROPERTIES; j++)
3297 if (HAS_PROPERTY(i, j))
3303 SET_PROPERTY(i, EP_INACTIVE, TRUE);
3308 /* dynamically adjust element properties according to game engine version */
3310 static int ep_em_slippery_wall[] =
3315 EL_EXPANDABLE_WALL_HORIZONTAL,
3316 EL_EXPANDABLE_WALL_VERTICAL,
3317 EL_EXPANDABLE_WALL_ANY,
3321 /* special EM style gems behaviour */
3322 for (i = 0; ep_em_slippery_wall[i] != -1; i++)
3323 SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL,
3324 level.em_slippery_gems);
3326 /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */
3327 SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL,
3328 (level.em_slippery_gems &&
3329 engine_version > VERSION_IDENT(2,0,1,0)));
3333 /* set default push delay values (corrected since version 3.0.7-1) */
3334 if (engine_version < VERSION_IDENT(3,0,7,1))
3336 game.default_push_delay_fixed = 2;
3337 game.default_push_delay_random = 8;
3341 game.default_push_delay_fixed = 8;
3342 game.default_push_delay_random = 8;
3345 /* set uninitialized push delay values of custom elements in older levels */
3346 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
3348 int element = EL_CUSTOM_START + i;
3350 if (element_info[element].push_delay_fixed == -1)
3351 element_info[element].push_delay_fixed = game.default_push_delay_fixed;
3352 if (element_info[element].push_delay_random == -1)
3353 element_info[element].push_delay_random = game.default_push_delay_random;
3356 /* set some other uninitialized values of custom elements in older levels */
3357 if (engine_version < VERSION_IDENT(3,0,9,0))
3359 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
3361 int element = EL_CUSTOM_START + i;
3363 element_info[element].access_direction = MV_ALL_DIRECTIONS;
3365 element_info[element].explosion_delay = 18;
3366 element_info[element].ignition_delay = 8;
3371 /* this is needed because some graphics depend on element properties */
3372 if (game_status == GAME_MODE_PLAYING)
3373 InitElementGraphicInfo();
3376 static void InitGlobal()
3378 global.autoplay_leveldir = NULL;
3380 global.frames_per_second = 0;
3381 global.fps_slowdown = FALSE;
3382 global.fps_slowdown_factor = 1;
3385 void Execute_Command(char *command)
3389 if (strcmp(command, "print graphicsinfo.conf") == 0)
3391 printf("# You can configure additional/alternative image files here.\n");
3392 printf("# (The entries below are default and therefore commented out.)\n");
3394 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
3396 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3399 for (i = 0; image_config[i].token != NULL; i++)
3400 printf("# %s\n", getFormattedSetupEntry(image_config[i].token,
3401 image_config[i].value));
3405 else if (strcmp(command, "print soundsinfo.conf") == 0)
3407 printf("# You can configure additional/alternative sound files here.\n");
3408 printf("# (The entries below are default and therefore commented out.)\n");
3410 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
3412 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3415 for (i = 0; sound_config[i].token != NULL; i++)
3416 printf("# %s\n", getFormattedSetupEntry(sound_config[i].token,
3417 sound_config[i].value));
3421 else if (strcmp(command, "print musicinfo.conf") == 0)
3423 printf("# You can configure additional/alternative music files here.\n");
3424 printf("# (The entries below are default and therefore commented out.)\n");
3426 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
3428 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
3431 for (i = 0; music_config[i].token != NULL; i++)
3432 printf("# %s\n", getFormattedSetupEntry(music_config[i].token,
3433 music_config[i].value));
3437 else if (strcmp(command, "print editorsetup.conf") == 0)
3439 printf("# You can configure your personal editor element list here.\n");
3440 printf("# (The entries below are default and therefore commented out.)\n");
3443 PrintEditorElementList();
3447 else if (strcmp(command, "print helpanim.conf") == 0)
3449 printf("# You can configure different element help animations here.\n");
3450 printf("# (The entries below are default and therefore commented out.)\n");
3453 for (i = 0; helpanim_config[i].token != NULL; i++)
3455 printf("# %s\n", getFormattedSetupEntry(helpanim_config[i].token,
3456 helpanim_config[i].value));
3458 if (strcmp(helpanim_config[i].token, "end") == 0)
3464 else if (strcmp(command, "print helptext.conf") == 0)
3466 printf("# You can configure different element help text here.\n");
3467 printf("# (The entries below are default and therefore commented out.)\n");
3470 for (i = 0; helptext_config[i].token != NULL; i++)
3471 printf("# %s\n", getFormattedSetupEntry(helptext_config[i].token,
3472 helptext_config[i].value));
3476 else if (strncmp(command, "dump level ", 11) == 0)
3478 char *filename = &command[11];
3480 if (access(filename, F_OK) != 0)
3481 Error(ERR_EXIT, "cannot open file '%s'", filename);
3483 LoadLevelFromFilename(&level, filename);
3488 else if (strncmp(command, "dump tape ", 10) == 0)
3490 char *filename = &command[10];
3492 if (access(filename, F_OK) != 0)
3493 Error(ERR_EXIT, "cannot open file '%s'", filename);
3495 LoadTapeFromFilename(filename);
3500 else if (strncmp(command, "autoplay ", 9) == 0)
3502 char *str_copy = getStringCopy(&command[9]);
3503 char *str_ptr = strchr(str_copy, ' ');
3505 global.autoplay_leveldir = str_copy;
3506 global.autoplay_level_nr = -1;
3508 if (str_ptr != NULL)
3510 *str_ptr++ = '\0'; /* terminate leveldir string */
3511 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
3516 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
3520 static void InitSetup()
3522 LoadSetup(); /* global setup info */
3524 /* set some options from setup file */
3526 if (setup.options.verbose)
3527 options.verbose = TRUE;
3530 static void InitPlayerInfo()
3534 /* choose default local player */
3535 local_player = &stored_player[0];
3537 for (i = 0; i < MAX_PLAYERS; i++)
3538 stored_player[i].connected = FALSE;
3540 local_player->connected = TRUE;
3543 static void InitArtworkInfo()
3548 static char *get_string_in_brackets(char *string)
3550 char *string_in_brackets = checked_malloc(strlen(string) + 3);
3552 sprintf(string_in_brackets, "[%s]", string);
3554 return string_in_brackets;
3557 static char *get_level_id_suffix(int id_nr)
3559 char *id_suffix = checked_malloc(1 + 3 + 1);
3561 if (id_nr < 0 || id_nr > 999)
3564 sprintf(id_suffix, ".%03d", id_nr);
3570 static char *get_element_class_token(int element)
3572 char *element_class_name = element_info[element].class_name;
3573 char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
3575 sprintf(element_class_token, "[%s]", element_class_name);
3577 return element_class_token;
3580 static char *get_action_class_token(int action)
3582 char *action_class_name = &element_action_info[action].suffix[1];
3583 char *action_class_token = checked_malloc(strlen(action_class_name) + 3);
3585 sprintf(action_class_token, "[%s]", action_class_name);
3587 return action_class_token;
3591 static void InitArtworkConfig()
3593 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
3594 static char *sound_id_prefix[2 * MAX_NUM_ELEMENTS + 1];
3595 static char *music_id_prefix[NUM_MUSIC_PREFIXES + 1];
3596 static char *action_id_suffix[NUM_ACTIONS + 1];
3597 static char *direction_id_suffix[NUM_DIRECTIONS + 1];
3598 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
3599 static char *level_id_suffix[MAX_LEVELS + 1];
3600 static char *dummy[1] = { NULL };
3601 static char *ignore_generic_tokens[] =
3607 static char **ignore_image_tokens;
3608 static char **ignore_sound_tokens;
3609 static char **ignore_music_tokens;
3610 int num_ignore_generic_tokens;
3611 int num_ignore_image_tokens;
3612 int num_ignore_sound_tokens;
3613 int num_ignore_music_tokens;
3616 /* dynamically determine list of generic tokens to be ignored */
3617 num_ignore_generic_tokens = 0;
3618 for (i = 0; ignore_generic_tokens[i] != NULL; i++)
3619 num_ignore_generic_tokens++;
3621 /* dynamically determine list of image tokens to be ignored */
3622 num_ignore_image_tokens = num_ignore_generic_tokens;
3623 for (i = 0; image_config_vars[i].token != NULL; i++)
3624 num_ignore_image_tokens++;
3625 ignore_image_tokens =
3626 checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *));
3627 for (i = 0; i < num_ignore_generic_tokens; i++)
3628 ignore_image_tokens[i] = ignore_generic_tokens[i];
3629 for (i = 0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++)
3630 ignore_image_tokens[num_ignore_generic_tokens + i] =
3631 image_config_vars[i].token;
3632 ignore_image_tokens[num_ignore_image_tokens] = NULL;
3634 /* dynamically determine list of sound tokens to be ignored */
3635 num_ignore_sound_tokens = num_ignore_generic_tokens;
3636 ignore_sound_tokens =
3637 checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
3638 for (i = 0; i < num_ignore_generic_tokens; i++)
3639 ignore_sound_tokens[i] = ignore_generic_tokens[i];
3640 ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
3642 /* dynamically determine list of music tokens to be ignored */
3643 num_ignore_music_tokens = num_ignore_generic_tokens;
3644 ignore_music_tokens =
3645 checked_malloc((num_ignore_music_tokens + 1) * sizeof(char *));
3646 for (i = 0; i < num_ignore_generic_tokens; i++)
3647 ignore_music_tokens[i] = ignore_generic_tokens[i];
3648 ignore_music_tokens[num_ignore_music_tokens] = NULL;
3650 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3651 image_id_prefix[i] = element_info[i].token_name;
3652 for (i = 0; i < NUM_FONTS; i++)
3653 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
3654 image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
3656 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3657 sound_id_prefix[i] = element_info[i].token_name;
3658 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3659 sound_id_prefix[MAX_NUM_ELEMENTS + i] =
3660 get_string_in_brackets(element_info[i].class_name);
3661 sound_id_prefix[2 * MAX_NUM_ELEMENTS] = NULL;
3663 for (i = 0; i < NUM_MUSIC_PREFIXES; i++)
3664 music_id_prefix[i] = music_prefix_info[i].prefix;
3665 music_id_prefix[MAX_LEVELS] = NULL;
3667 for (i = 0; i < NUM_ACTIONS; i++)
3668 action_id_suffix[i] = element_action_info[i].suffix;
3669 action_id_suffix[NUM_ACTIONS] = NULL;
3671 for (i = 0; i < NUM_DIRECTIONS; i++)
3672 direction_id_suffix[i] = element_direction_info[i].suffix;
3673 direction_id_suffix[NUM_DIRECTIONS] = NULL;
3675 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
3676 special_id_suffix[i] = special_suffix_info[i].suffix;
3677 special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
3679 for (i = 0; i < MAX_LEVELS; i++)
3680 level_id_suffix[i] = get_level_id_suffix(i);
3681 level_id_suffix[MAX_LEVELS] = NULL;
3683 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
3684 image_id_prefix, action_id_suffix, direction_id_suffix,
3685 special_id_suffix, ignore_image_tokens);
3686 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
3687 sound_id_prefix, action_id_suffix, dummy,
3688 special_id_suffix, ignore_sound_tokens);
3689 InitMusicList(music_config, NUM_MUSIC_FILES, music_config_suffix,
3690 music_id_prefix, special_id_suffix, level_id_suffix,
3691 dummy, ignore_music_tokens);
3694 static void InitMixer()
3702 char *filename_font_initial = NULL;
3703 Bitmap *bitmap_font_initial = NULL;
3706 /* determine settings for initial font (for displaying startup messages) */
3707 for (i = 0; image_config[i].token != NULL; i++)
3709 for (j = 0; j < NUM_INITIAL_FONTS; j++)
3711 char font_token[128];
3714 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
3715 len_font_token = strlen(font_token);
3717 if (strcmp(image_config[i].token, font_token) == 0)
3718 filename_font_initial = image_config[i].value;
3719 else if (strlen(image_config[i].token) > len_font_token &&
3720 strncmp(image_config[i].token, font_token, len_font_token) == 0)
3722 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
3723 font_initial[j].src_x = atoi(image_config[i].value);
3724 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
3725 font_initial[j].src_y = atoi(image_config[i].value);
3726 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
3727 font_initial[j].width = atoi(image_config[i].value);
3728 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
3729 font_initial[j].height = atoi(image_config[i].value);
3734 for (j = 0; j < NUM_INITIAL_FONTS; j++)
3736 font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
3737 font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
3740 if (filename_font_initial == NULL) /* should not happen */
3741 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
3743 /* create additional image buffers for double-buffering */
3744 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
3745 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
3747 /* initialize screen properties */
3748 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
3749 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
3751 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
3752 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
3753 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
3755 bitmap_font_initial = LoadCustomImage(filename_font_initial);
3757 for (j = 0; j < NUM_INITIAL_FONTS; j++)
3758 font_initial[j].bitmap = bitmap_font_initial;
3760 InitFontGraphicInfo();
3762 DrawInitText(getProgramInitString(), 20, FC_YELLOW);
3763 DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED);
3765 DrawInitText("Loading graphics:", 120, FC_GREEN);
3767 InitTileClipmasks();
3770 void InitGfxBackground()
3774 drawto = backbuffer;
3775 fieldbuffer = bitmap_db_field;
3776 SetDrawtoField(DRAW_BACKBUFFER);
3778 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
3779 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
3780 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
3781 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
3783 for (x = 0; x < MAX_BUF_XSIZE; x++)
3784 for (y = 0; y < MAX_BUF_YSIZE; y++)
3787 redraw_mask = REDRAW_ALL;
3790 static void InitLevelInfo()
3792 LoadLevelInfo(); /* global level info */
3793 LoadLevelSetup_LastSeries(); /* last played series info */
3794 LoadLevelSetup_SeriesInfo(); /* last played level info */
3797 void InitLevelArtworkInfo()
3799 LoadLevelArtworkInfo();
3802 static void InitImages()
3805 setLevelArtworkDir(artwork.gfx_first);
3809 printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
3810 leveldir_current->identifier,
3811 artwork.gfx_current_identifier,
3812 artwork.gfx_current->identifier,
3813 leveldir_current->graphics_set,
3814 leveldir_current->graphics_path);
3817 ReloadCustomImages();
3819 LoadCustomElementDescriptions();
3820 LoadSpecialMenuDesignSettings();
3822 ReinitializeGraphics();
3825 static void InitSound(char *identifier)
3827 if (identifier == NULL)
3828 identifier = artwork.snd_current->identifier;
3831 /* set artwork path to send it to the sound server process */
3832 setLevelArtworkDir(artwork.snd_first);
3835 InitReloadCustomSounds(identifier);
3836 ReinitializeSounds();
3839 static void InitMusic(char *identifier)
3841 if (identifier == NULL)
3842 identifier = artwork.mus_current->identifier;
3845 /* set artwork path to send it to the sound server process */
3846 setLevelArtworkDir(artwork.mus_first);
3849 InitReloadCustomMusic(identifier);
3850 ReinitializeMusic();
3853 void InitNetworkServer()
3855 #if defined(PLATFORM_UNIX)
3859 if (!options.network)
3862 #if defined(PLATFORM_UNIX)
3863 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
3865 if (!ConnectToServer(options.server_host, options.server_port))
3866 Error(ERR_EXIT, "cannot connect to network game server");
3868 SendToServer_PlayerName(setup.player_name);
3869 SendToServer_ProtocolVersion();
3872 SendToServer_NrWanted(nr_wanted);
3876 static char *getNewArtworkIdentifier(int type)
3878 static char *leveldir_current_identifier[3] = { NULL, NULL, NULL };
3879 static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE };
3880 static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE };
3881 static boolean initialized[3] = { FALSE, FALSE, FALSE };
3882 TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
3883 boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type);
3884 char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type);
3885 char *leveldir_identifier = leveldir_current->identifier;
3887 /* !!! setLevelArtworkDir() should be moved to an earlier stage !!! */
3888 char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node);
3890 char *leveldir_artwork_set = LEVELDIR_ARTWORK_SET(leveldir_current, type);
3892 boolean has_level_artwork_set = (leveldir_artwork_set != NULL);
3893 char *artwork_current_identifier;
3894 char *artwork_new_identifier = NULL; /* default: nothing has changed */
3896 /* leveldir_current may be invalid (level group, parent link) */
3897 if (!validLevelSeries(leveldir_current))
3900 /* 1st step: determine artwork set to be activated in descending order:
3901 --------------------------------------------------------------------
3902 1. setup artwork (when configured to override everything else)
3903 2. artwork set configured in "levelinfo.conf" of current level set
3904 (artwork in level directory will have priority when loading later)
3905 3. artwork in level directory (stored in artwork sub-directory)
3906 4. setup artwork (currently configured in setup menu) */
3908 if (setup_override_artwork)
3909 artwork_current_identifier = setup_artwork_set;
3910 else if (leveldir_artwork_set != NULL)
3911 artwork_current_identifier = leveldir_artwork_set;
3912 else if (getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier))
3913 artwork_current_identifier = leveldir_identifier;
3915 artwork_current_identifier = setup_artwork_set;
3918 /* 2nd step: check if it is really needed to reload artwork set
3919 ------------------------------------------------------------ */
3922 if (type == ARTWORK_TYPE_GRAPHICS)
3923 printf("::: 0: '%s' ['%s', '%s'] ['%s' ('%s')]\n",
3924 artwork_new_identifier,
3925 ARTWORK_CURRENT_IDENTIFIER(artwork, type),
3926 artwork_current_identifier,
3927 leveldir_current->graphics_set,
3928 leveldir_current->identifier);
3931 /* ---------- reload if level set and also artwork set has changed ------- */
3932 if (leveldir_current_identifier[type] != leveldir_identifier &&
3933 (last_has_level_artwork_set[type] || has_level_artwork_set))
3934 artwork_new_identifier = artwork_current_identifier;
3936 leveldir_current_identifier[type] = leveldir_identifier;
3937 last_has_level_artwork_set[type] = has_level_artwork_set;
3940 if (type == ARTWORK_TYPE_GRAPHICS)
3941 printf("::: 1: '%s'\n", artwork_new_identifier);
3944 /* ---------- reload if "override artwork" setting has changed ----------- */
3945 if (last_override_level_artwork[type] != setup_override_artwork)
3946 artwork_new_identifier = artwork_current_identifier;
3948 last_override_level_artwork[type] = setup_override_artwork;
3951 if (type == ARTWORK_TYPE_GRAPHICS)
3952 printf("::: 2: '%s'\n", artwork_new_identifier);
3955 /* ---------- reload if current artwork identifier has changed ----------- */
3956 if (strcmp(ARTWORK_CURRENT_IDENTIFIER(artwork, type),
3957 artwork_current_identifier) != 0)
3958 artwork_new_identifier = artwork_current_identifier;
3960 *(&(ARTWORK_CURRENT_IDENTIFIER(artwork, type))) = artwork_current_identifier;
3963 if (type == ARTWORK_TYPE_GRAPHICS)
3964 printf("::: 3: '%s'\n", artwork_new_identifier);
3967 /* ---------- do not reload directly after starting ---------------------- */
3968 if (!initialized[type])
3969 artwork_new_identifier = NULL;
3971 initialized[type] = TRUE;
3974 if (type == ARTWORK_TYPE_GRAPHICS)
3975 printf("::: 4: '%s'\n", artwork_new_identifier);
3979 if (type == ARTWORK_TYPE_GRAPHICS)
3980 printf("CHECKING OLD/NEW GFX:\n- OLD: %s\n- NEW: %s ['%s', '%s'] ['%s']\n",
3981 artwork.gfx_current_identifier, artwork_current_identifier,
3982 artwork.gfx_current->identifier, leveldir_current->graphics_set,
3983 artwork_new_identifier);
3986 return artwork_new_identifier;
3989 void ReloadCustomArtwork(int force_reload)
3991 char *gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS);
3992 char *snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS);
3993 char *mus_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_MUSIC);
3994 boolean force_reload_gfx = (force_reload & (1 << ARTWORK_TYPE_GRAPHICS));
3995 boolean force_reload_snd = (force_reload & (1 << ARTWORK_TYPE_SOUNDS));
3996 boolean force_reload_mus = (force_reload & (1 << ARTWORK_TYPE_MUSIC));
3997 boolean redraw_screen = FALSE;
3999 if (gfx_new_identifier != NULL || force_reload_gfx)
4002 printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n",
4003 artwork.gfx_current_identifier,
4005 artwork.gfx_current->identifier,
4006 leveldir_current->graphics_set);
4009 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4014 printf("... '%s'\n",
4015 leveldir_current->graphics_set);
4018 FreeTileClipmasks();
4019 InitTileClipmasks();
4021 redraw_screen = TRUE;
4024 if (snd_new_identifier != NULL || force_reload_snd)
4026 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4028 InitSound(snd_new_identifier);
4030 redraw_screen = TRUE;
4033 if (mus_new_identifier != NULL || force_reload_mus)
4035 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4037 InitMusic(mus_new_identifier);
4039 redraw_screen = TRUE;
4044 InitGfxBackground();
4046 /* force redraw of (open or closed) door graphics */
4047 SetDoorState(DOOR_OPEN_ALL);
4048 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
4052 void KeyboardAutoRepeatOffUnlessAutoplay()
4054 if (global.autoplay_leveldir == NULL)
4055 KeyboardAutoRepeatOff();
4059 /* ========================================================================= */
4061 /* ========================================================================= */
4065 InitGlobal(); /* initialize some global variables */
4067 if (options.execute_command)
4068 Execute_Command(options.execute_command);
4070 if (options.serveronly)
4072 #if defined(PLATFORM_UNIX)
4073 NetworkServer(options.server_port, options.serveronly);
4075 Error(ERR_WARN, "networking only supported in Unix version");
4077 exit(0); /* never reached */
4083 InitArtworkInfo(); /* needed before loading gfx, sound & music */
4084 InitArtworkConfig(); /* needed before forking sound child process */
4089 InitRND(NEW_RANDOMIZE);
4090 InitSimpleRND(NEW_RANDOMIZE);
4095 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
4098 InitEventFilter(FilterMouseMotionEvents);
4100 InitElementPropertiesStatic();
4101 InitElementPropertiesEngine(GAME_VERSION_ACTUAL);
4106 InitLevelArtworkInfo();
4108 InitImages(); /* needs to know current level directory */
4109 InitSound(NULL); /* needs to know current level directory */
4110 InitMusic(NULL); /* needs to know current level directory */
4112 InitGfxBackground();
4114 if (global.autoplay_leveldir)
4120 game_status = GAME_MODE_MAIN;
4124 InitNetworkServer();
4127 void CloseAllAndExit(int exit_value)
4132 CloseAudio(); /* called after freeing sounds (needed for SDL) */
4135 FreeTileClipmasks();
4137 CloseVideoDisplay();
4138 ClosePlatformDependentStuff();