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"
28 #include "conf_e2g.c" /* include auto-generated data structure definitions */
29 #include "conf_esg.c" /* include auto-generated data structure definitions */
30 #include "conf_e2s.c" /* include auto-generated data structure definitions */
31 #include "conf_fnt.c" /* include auto-generated data structure definitions */
34 #define CONFIG_TOKEN_FONT_INITIAL "font.initial"
37 struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
40 static void InitTileClipmasks()
43 #if defined(TARGET_X11)
44 XGCValues clip_gc_values;
45 unsigned long clip_gc_valuemask;
47 #if defined(TARGET_X11_NATIVE)
57 tile_needs_clipping[] =
59 { GFX_SPIELER1_UP, 4 },
60 { GFX_SPIELER1_DOWN, 4 },
61 { GFX_SPIELER1_LEFT, 4 },
62 { GFX_SPIELER1_RIGHT, 4 },
63 { GFX_SPIELER1_PUSH_LEFT, 4 },
64 { GFX_SPIELER1_PUSH_RIGHT, 4 },
65 { GFX_SPIELER2_UP, 4 },
66 { GFX_SPIELER2_DOWN, 4 },
67 { GFX_SPIELER2_LEFT, 4 },
68 { GFX_SPIELER2_RIGHT, 4 },
69 { GFX_SPIELER2_PUSH_LEFT, 4 },
70 { GFX_SPIELER2_PUSH_RIGHT, 4 },
71 { GFX_SPIELER3_UP, 4 },
72 { GFX_SPIELER3_DOWN, 4 },
73 { GFX_SPIELER3_LEFT, 4 },
74 { GFX_SPIELER3_RIGHT, 4 },
75 { GFX_SPIELER3_PUSH_LEFT, 4 },
76 { GFX_SPIELER3_PUSH_RIGHT, 4 },
77 { GFX_SPIELER4_UP, 4 },
78 { GFX_SPIELER4_DOWN, 4 },
79 { GFX_SPIELER4_LEFT, 4 },
80 { GFX_SPIELER4_RIGHT, 4 },
81 { GFX_SPIELER4_PUSH_LEFT, 4 },
82 { GFX_SPIELER4_PUSH_RIGHT, 4 },
84 { GFX_MURPHY_GO_LEFT, 3 },
85 { GFX_MURPHY_GO_RIGHT, 3 },
86 { GFX_MURPHY_SNAP_UP, 1 },
87 { GFX_MURPHY_SNAP_DOWN, 1 },
88 { GFX_MURPHY_SNAP_RIGHT, 1 },
89 { GFX_MURPHY_SNAP_LEFT, 1 },
90 { GFX_MURPHY_PUSH_RIGHT, 1 },
91 { GFX_MURPHY_PUSH_LEFT, 1 },
96 { GFX_SOKOBAN_OBJEKT, 1 },
97 { GFX_FUNKELN_BLAU, 3 },
98 { GFX_FUNKELN_WEISS, 3 },
99 { GFX2_SHIELD_PASSIVE, 3 },
100 { GFX2_SHIELD_ACTIVE, 3 },
105 #endif /* TARGET_X11_NATIVE */
106 #endif /* TARGET_X11 */
110 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
111 for (i=0; i<NUM_TILES; i++)
112 tile_clipmask[i] = None;
114 #if defined(TARGET_X11)
115 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
116 often very slow when preparing a masked XCopyArea() for big Pixmaps.
117 To prevent this, create small (tile-sized) mask Pixmaps which will then
118 be set much faster with XSetClipOrigin() and speed things up a lot. */
120 clip_gc_values.graphics_exposures = False;
121 clip_gc_valuemask = GCGraphicsExposures;
122 tile_clip_gc = XCreateGC(display, window->drawable,
123 clip_gc_valuemask, &clip_gc_values);
126 for (i=0; i<NUM_BITMAPS; i++)
128 if (pix[i]->clip_mask)
130 clip_gc_values.graphics_exposures = False;
131 clip_gc_values.clip_mask = pix[i]->clip_mask;
132 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
133 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
134 clip_gc_valuemask, &clip_gc_values);
139 #if defined(TARGET_X11_NATIVE)
142 /* create graphic context structures needed for clipping */
143 clip_gc_values.graphics_exposures = False;
144 clip_gc_valuemask = GCGraphicsExposures;
145 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
146 clip_gc_valuemask, &clip_gc_values);
148 /* create only those clipping Pixmaps we really need */
149 for (i=0; tile_needs_clipping[i].start>=0; i++)
153 for (j=0; j<tile_needs_clipping[i].count; j++)
155 int tile = tile_needs_clipping[i].start + j;
161 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
162 src_pixmap = src_bitmap->clip_mask;
164 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
167 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
168 src_x, src_y, TILEX, TILEY, 0, 0);
172 XFreeGC(display, copy_clipmask_gc);
175 #endif /* TARGET_X11_NATIVE */
176 #endif /* TARGET_X11 */
180 void FreeTileClipmasks()
183 #if defined(TARGET_X11)
186 for (i=0; i<NUM_TILES; i++)
188 if (tile_clipmask[i] != None)
190 XFreePixmap(display, tile_clipmask[i]);
191 tile_clipmask[i] = None;
196 XFreeGC(display, tile_clip_gc);
200 for (i=0; i<NUM_BITMAPS; i++)
202 if (pix[i] != NULL && pix[i]->stored_clip_gc)
204 XFreeGC(display, pix[i]->stored_clip_gc);
205 pix[i]->stored_clip_gc = None;
210 #endif /* TARGET_X11 */
216 FreeLevelEditorGadgets();
225 static boolean gadgets_initialized = FALSE;
227 if (gadgets_initialized)
230 CreateLevelEditorGadgets();
234 CreateScreenGadgets();
236 gadgets_initialized = TRUE;
239 void InitElementSmallImages()
241 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
242 int num_property_mappings = getImageListPropertyMappingSize();
245 /* initialize normal images from static configuration */
246 for (i=0; element_to_graphic[i].element > -1; i++)
247 CreateImageWithSmallImages(element_to_graphic[i].graphic);
249 /* initialize special images from static configuration */
250 for (i=0; element_to_special_graphic[i].element > -1; i++)
251 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
253 /* initialize images from dynamic configuration */
254 for (i=0; i < num_property_mappings; i++)
255 if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
256 CreateImageWithSmallImages(property_mapping[i].artwork_index);
259 static int getFontBitmapID(int font_nr)
263 if (game_status >= GAME_MODE_MAIN && game_status <= GAME_MODE_PSEUDO_PREVIEW)
264 special = game_status;
265 else if (game_status == GAME_MODE_PSEUDO_TYPENAME)
266 special = GFX_SPECIAL_ARG_MAIN;
267 else if (game_status == GAME_MODE_PLAYING)
268 special = GFX_SPECIAL_ARG_DOOR;
271 return font_info[font_nr].special_bitmap_id[special];
276 void InitFontGraphicInfo()
278 static struct FontBitmapInfo *font_bitmap_info = NULL;
279 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
280 int num_property_mappings = getImageListPropertyMappingSize();
281 int num_font_bitmaps = NUM_FONTS;
284 if (graphic_info == NULL) /* still at startup phase */
286 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
291 /* ---------- initialize font graphic definitions ---------- */
293 /* always start with reliable default values (normal font graphics) */
294 for (i=0; i < NUM_FONTS; i++)
295 font_info[i].graphic = FONT_INITIAL_1;
297 /* initialize normal font/graphic mapping from static configuration */
298 for (i=0; font_to_graphic[i].font_nr > -1; i++)
300 int font_nr = font_to_graphic[i].font_nr;
301 int special = font_to_graphic[i].special;
302 int graphic = font_to_graphic[i].graphic;
307 font_info[font_nr].graphic = graphic;
310 /* always start with reliable default values (special font graphics) */
311 for (i=0; i < NUM_FONTS; i++)
313 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
315 font_info[i].special_graphic[j] = font_info[i].graphic;
316 font_info[i].special_bitmap_id[j] = i;
320 /* initialize special font/graphic mapping from static configuration */
321 for (i=0; font_to_graphic[i].font_nr > -1; i++)
323 int font_nr = font_to_graphic[i].font_nr;
324 int special = font_to_graphic[i].special;
325 int graphic = font_to_graphic[i].graphic;
327 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
329 font_info[font_nr].special_graphic[special] = graphic;
330 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
335 /* initialize special element/graphic mapping from dynamic configuration */
336 for (i=0; i < num_property_mappings; i++)
338 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
339 int special = property_mapping[i].ext3_index;
340 int graphic = property_mapping[i].artwork_index;
345 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
347 font_info[font_nr].special_graphic[special] = graphic;
348 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
353 /* ---------- initialize font bitmap array ---------- */
355 if (font_bitmap_info != NULL)
356 FreeFontInfo(font_bitmap_info);
359 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
361 /* ---------- initialize font bitmap definitions ---------- */
363 for (i=0; i < NUM_FONTS; i++)
365 if (i < NUM_INITIAL_FONTS)
367 font_bitmap_info[i] = font_initial[i];
371 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
373 int font_bitmap_id = font_info[i].special_bitmap_id[j];
374 int graphic = font_info[i].special_graphic[j];
376 /* set 'graphic_info' for font entries, if uninitialized (guessed) */
377 if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
379 graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
380 graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
383 /* copy font relevant information from graphics information */
384 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
385 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
386 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
387 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
388 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
389 font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
390 font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
392 font_bitmap_info[font_bitmap_id].num_chars =
393 graphic_info[graphic].anim_frames;
394 font_bitmap_info[font_bitmap_id].num_chars_per_line =
395 graphic_info[graphic].anim_frames_per_line;
399 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
402 void InitElementGraphicInfo()
404 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
405 int num_property_mappings = getImageListPropertyMappingSize();
408 /* set values to -1 to identify later as "uninitialized" values */
409 for (i=0; i<MAX_NUM_ELEMENTS; i++)
411 for (act=0; act<NUM_ACTIONS; act++)
413 element_info[i].graphic[act] = -1;
415 for (dir=0; dir<NUM_DIRECTIONS; dir++)
416 element_info[i].direction_graphic[act][dir] = -1;
420 /* initialize normal element/graphic mapping from static configuration */
421 for (i=0; element_to_graphic[i].element > -1; i++)
423 int element = element_to_graphic[i].element;
424 int action = element_to_graphic[i].action;
425 int direction = element_to_graphic[i].direction;
426 int graphic = element_to_graphic[i].graphic;
428 if (graphic_info[graphic].bitmap == NULL)
432 action = ACTION_DEFAULT;
435 element_info[element].direction_graphic[action][direction] = graphic;
437 element_info[element].graphic[action] = graphic;
440 /* initialize normal element/graphic mapping from dynamic configuration */
441 for (i=0; i < num_property_mappings; i++)
443 int element = property_mapping[i].base_index;
444 int action = property_mapping[i].ext1_index;
445 int direction = property_mapping[i].ext2_index;
446 int special = property_mapping[i].ext3_index;
447 int graphic = property_mapping[i].artwork_index;
449 if (graphic_info[graphic].bitmap == NULL)
452 if (element >= MAX_NUM_ELEMENTS || special != -1)
456 action = ACTION_DEFAULT;
459 element_info[element].direction_graphic[action][direction] = graphic;
461 element_info[element].graphic[action] = graphic;
464 /* now set all '-1' values to element specific default values */
465 for (i=0; i<MAX_NUM_ELEMENTS; i++)
467 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
468 int default_action_direction_graphic[NUM_DIRECTIONS];
470 if (default_action_graphic == -1)
471 default_action_graphic = IMG_CHAR_QUESTION;
473 for (dir=0; dir<NUM_DIRECTIONS; dir++)
475 default_action_direction_graphic[dir] =
476 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
478 if (default_action_direction_graphic[dir] == -1)
479 default_action_direction_graphic[dir] = default_action_graphic;
482 for (act=0; act<NUM_ACTIONS; act++)
484 boolean act_empty = (act == ACTION_DIGGING ||
485 act == ACTION_SNAPPING ||
486 act == ACTION_COLLECTING);
488 for (dir=0; dir<NUM_DIRECTIONS; dir++)
490 int default_direction_graphic = element_info[i].graphic[act];
492 /* no graphic for current action -- use default direction graphic */
493 if (default_direction_graphic == -1)
494 default_direction_graphic =
495 (act_empty ? IMG_EMPTY : default_action_direction_graphic[dir]);
497 if (element_info[i].direction_graphic[act][dir] == -1)
498 element_info[i].direction_graphic[act][dir] =
499 default_direction_graphic;
502 /* no graphic for this specific action -- use default action graphic */
503 if (element_info[i].graphic[act] == -1)
504 element_info[i].graphic[act] =
505 (act_empty ? IMG_EMPTY : default_action_graphic);
513 for (i=0; i<MAX_NUM_ELEMENTS; i++)
514 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
515 i != EL_CHAR_QUESTION)
516 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
517 element_info[i].token_name, i);
523 void InitElementSpecialGraphicInfo()
525 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
526 int num_property_mappings = getImageListPropertyMappingSize();
529 /* always start with reliable default values */
530 for (i=0; i < MAX_NUM_ELEMENTS; i++)
531 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
532 element_info[i].special_graphic[j] =
533 element_info[i].graphic[ACTION_DEFAULT];
535 /* initialize special element/graphic mapping from static configuration */
536 for (i=0; element_to_special_graphic[i].element > -1; i++)
538 int element = element_to_special_graphic[i].element;
539 int special = element_to_special_graphic[i].special;
540 int graphic = element_to_special_graphic[i].graphic;
541 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
542 boolean special_redefined = getImageListEntry(graphic)->redefined;
544 if (base_redefined && !special_redefined)
547 element_info[element].special_graphic[special] = graphic;
550 /* initialize special element/graphic mapping from dynamic configuration */
551 for (i=0; i < num_property_mappings; i++)
553 int element = property_mapping[i].base_index;
554 int special = property_mapping[i].ext3_index;
555 int graphic = property_mapping[i].artwork_index;
557 if (element >= MAX_NUM_ELEMENTS)
560 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
561 element_info[element].special_graphic[special] = graphic;
565 static void set_graphic_parameters(int graphic, char **parameter_raw)
567 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
568 int parameter[NUM_GFX_ARGS];
569 int anim_frames_per_row = 1, anim_frames_per_col = 1;
570 int anim_frames_per_line = 1;
573 /* get integer values from string parameters */
574 for (i=0; i < NUM_GFX_ARGS; i++)
576 get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
577 image_config_suffix[i].type);
579 graphic_info[graphic].bitmap = src_bitmap;
581 /* start with reliable default values */
582 graphic_info[graphic].src_x = 0;
583 graphic_info[graphic].src_y = 0;
584 graphic_info[graphic].width = TILEX;
585 graphic_info[graphic].height = TILEY;
586 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
587 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
589 /* optional x and y tile position of animation frame sequence */
590 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
591 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
592 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
593 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
595 /* optional x and y pixel position of animation frame sequence */
596 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
597 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
598 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
599 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
601 /* optional width and height of each animation frame */
602 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
603 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
604 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
605 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
609 anim_frames_per_row = src_bitmap->width / graphic_info[graphic].width;
610 anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
613 /* correct x or y offset dependant of vertical or horizontal frame order */
614 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
616 graphic_info[graphic].offset_y =
617 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
618 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
619 anim_frames_per_line = anim_frames_per_col;
621 else /* frames are ordered horizontally */
623 graphic_info[graphic].offset_x =
624 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
625 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
626 anim_frames_per_line = anim_frames_per_row;
629 /* optionally, the x and y offset of frames can be specified directly */
630 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
631 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
632 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
633 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
635 /* automatically determine correct number of frames, if not defined */
636 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
637 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
638 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
639 graphic_info[graphic].anim_frames = anim_frames_per_row;
640 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
641 graphic_info[graphic].anim_frames = anim_frames_per_col;
643 graphic_info[graphic].anim_frames = 1;
645 graphic_info[graphic].anim_frames_per_line =
646 (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
647 parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
649 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
650 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
651 graphic_info[graphic].anim_delay = 1;
653 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
654 if (graphic_info[graphic].anim_frames == 1)
655 graphic_info[graphic].anim_mode = ANIM_NONE;
657 /* automatically determine correct start frame, if not defined */
658 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
659 graphic_info[graphic].anim_start_frame = 0;
660 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
661 graphic_info[graphic].anim_start_frame =
662 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
664 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
666 /* animation synchronized with global frame counter, not move position */
667 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
669 /* this is only used for toon animations */
670 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
671 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
673 /* this is only used for drawing font characters */
674 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
675 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
678 static void InitGraphicInfo()
680 int fallback_graphic = IMG_CHAR_EXCLAM;
681 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
682 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
683 int num_images = getImageListSize();
686 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
687 static boolean clipmasks_initialized = FALSE;
689 XGCValues clip_gc_values;
690 unsigned long clip_gc_valuemask;
691 GC copy_clipmask_gc = None;
694 if (graphic_info != NULL)
697 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
699 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
700 if (clipmasks_initialized)
702 for (i=0; i<num_images; i++)
704 if (graphic_info[i].clip_mask)
705 XFreePixmap(display, graphic_info[i].clip_mask);
706 if (graphic_info[i].clip_gc)
707 XFreeGC(display, graphic_info[i].clip_gc);
709 graphic_info[i].clip_mask = None;
710 graphic_info[i].clip_gc = None;
715 for (i=0; i<num_images; i++)
717 struct FileInfo *image = getImageListEntry(i);
720 int first_frame, last_frame;
722 set_graphic_parameters(i, image->parameter);
724 /* now check if no animation frames are outside of the loaded image */
726 if (graphic_info[i].bitmap == NULL)
727 continue; /* skip check for optional images that are undefined */
730 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
731 if (src_x < 0 || src_y < 0 ||
732 src_x + TILEX > src_bitmap->width ||
733 src_y + TILEY > src_bitmap->height)
735 Error(ERR_RETURN_LINE, "-");
736 Error(ERR_RETURN, "warning: error found in config file:");
737 Error(ERR_RETURN, "- config file: '%s'",
738 getImageConfigFilename());
739 Error(ERR_RETURN, "- config token: '%s'",
740 getTokenFromImageID(i));
741 Error(ERR_RETURN, "- image file: '%s'",
742 src_bitmap->source_filename);
744 "error: first animation frame out of bounds (%d, %d)",
746 Error(ERR_RETURN, "custom graphic rejected for this element/action");
748 if (i == fallback_graphic)
749 Error(ERR_EXIT, "fatal error: no fallback graphic available");
751 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
752 Error(ERR_RETURN_LINE, "-");
754 set_graphic_parameters(i, fallback_image->default_parameter);
755 graphic_info[i].bitmap = fallback_bitmap;
758 last_frame = graphic_info[i].anim_frames - 1;
759 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
760 if (src_x < 0 || src_y < 0 ||
761 src_x + TILEX > src_bitmap->width ||
762 src_y + TILEY > src_bitmap->height)
764 Error(ERR_RETURN_LINE, "-");
765 Error(ERR_RETURN, "warning: error found in config file:");
766 Error(ERR_RETURN, "- config file: '%s'",
767 getImageConfigFilename());
768 Error(ERR_RETURN, "- config token: '%s'",
769 getTokenFromImageID(i));
770 Error(ERR_RETURN, "- image file: '%s'",
771 src_bitmap->source_filename);
773 "error: last animation frame (%d) out of bounds (%d, %d)",
774 last_frame, src_x, src_y);
775 Error(ERR_RETURN, "custom graphic rejected for this element/action");
777 if (i == fallback_graphic)
778 Error(ERR_EXIT, "fatal error: no fallback graphic available");
780 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
781 Error(ERR_RETURN_LINE, "-");
783 set_graphic_parameters(i, fallback_image->default_parameter);
784 graphic_info[i].bitmap = fallback_bitmap;
787 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
788 /* currently we need only a tile clip mask from the first frame */
789 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
791 if (copy_clipmask_gc == None)
793 clip_gc_values.graphics_exposures = False;
794 clip_gc_valuemask = GCGraphicsExposures;
795 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
796 clip_gc_valuemask, &clip_gc_values);
799 graphic_info[i].clip_mask =
800 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
802 src_pixmap = src_bitmap->clip_mask;
803 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
804 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
806 clip_gc_values.graphics_exposures = False;
807 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
808 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
810 graphic_info[i].clip_gc =
811 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
815 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
816 if (copy_clipmask_gc)
817 XFreeGC(display, copy_clipmask_gc);
819 clipmasks_initialized = TRUE;
823 static void InitElementSoundInfo()
825 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
826 int num_property_mappings = getSoundListPropertyMappingSize();
829 /* set values to -1 to identify later as "uninitialized" values */
830 for (i=0; i < MAX_NUM_ELEMENTS; i++)
831 for (act=0; act < NUM_ACTIONS; act++)
832 element_info[i].sound[act] = -1;
834 /* initialize element/sound mapping from static configuration */
835 for (i=0; element_to_sound[i].element > -1; i++)
837 int element = element_to_sound[i].element;
838 int action = element_to_sound[i].action;
839 int sound = element_to_sound[i].sound;
840 boolean is_class = element_to_sound[i].is_class;
843 action = ACTION_DEFAULT;
846 element_info[element].sound[action] = sound;
848 for (j=0; j < MAX_NUM_ELEMENTS; j++)
849 if (strcmp(element_info[j].class_name,
850 element_info[element].class_name) == 0)
851 element_info[j].sound[action] = sound;
854 /* initialize element/sound mapping from dynamic configuration */
855 for (i=0; i < num_property_mappings; i++)
857 int element = property_mapping[i].base_index;
858 int action = property_mapping[i].ext1_index;
859 int sound = property_mapping[i].artwork_index;
861 if (element >= MAX_NUM_ELEMENTS)
865 action = ACTION_DEFAULT;
867 element_info[element].sound[action] = sound;
870 /* initialize element class/sound mapping from dynamic configuration */
871 for (i=0; i < num_property_mappings; i++)
873 int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
874 int action = property_mapping[i].ext1_index;
875 int sound = property_mapping[i].artwork_index;
877 if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
881 action = ACTION_DEFAULT;
883 for (j=0; j < MAX_NUM_ELEMENTS; j++)
884 if (strcmp(element_info[j].class_name,
885 element_info[element_class].class_name) == 0)
886 element_info[j].sound[action] = sound;
889 /* now set all '-1' values to element specific default values */
890 for (i=0; i<MAX_NUM_ELEMENTS; i++)
892 int default_action_sound = element_info[i].sound[ACTION_DEFAULT];
894 for (act=0; act < NUM_ACTIONS; act++)
896 /* no sound for this specific action -- use default action sound */
897 if (element_info[i].sound[act] == -1)
898 element_info[i].sound[act] = default_action_sound;
903 static void set_sound_parameters(int sound, char **parameter_raw)
905 int parameter[NUM_SND_ARGS];
908 /* get integer values from string parameters */
909 for (i=0; i < NUM_SND_ARGS; i++)
911 get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
912 sound_config_suffix[i].type);
914 /* explicit loop mode setting in configuration overrides default value */
915 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
916 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
919 static void InitSoundInfo()
921 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
922 int num_property_mappings = getSoundListPropertyMappingSize();
923 int *sound_effect_properties;
924 int num_sounds = getSoundListSize();
927 if (sound_info != NULL)
930 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
931 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
933 /* initialize sound effect for all elements to "no sound" */
934 for (i=0; i<MAX_NUM_ELEMENTS; i++)
935 for (j=0; j<NUM_ACTIONS; j++)
936 element_info[i].sound[j] = SND_UNDEFINED;
938 for (i=0; i<num_sounds; i++)
940 struct FileInfo *sound = getSoundListEntry(i);
941 int len_effect_text = strlen(sound->token);
943 sound_effect_properties[i] = ACTION_OTHER;
944 sound_info[i].loop = FALSE;
946 /* determine all loop sounds and identify certain sound classes */
948 for (j=0; element_action_info[j].suffix; j++)
950 int len_action_text = strlen(element_action_info[j].suffix);
952 if (len_action_text < len_effect_text &&
953 strcmp(&sound->token[len_effect_text - len_action_text],
954 element_action_info[j].suffix) == 0)
956 sound_effect_properties[i] = element_action_info[j].value;
958 if (element_action_info[j].is_loop_sound)
959 sound_info[i].loop = TRUE;
963 /* associate elements and some selected sound actions */
965 for (j=0; j<MAX_NUM_ELEMENTS; j++)
967 if (element_info[j].class_name)
969 int len_class_text = strlen(element_info[j].class_name);
971 if (len_class_text + 1 < len_effect_text &&
972 strncmp(sound->token,
973 element_info[j].class_name, len_class_text) == 0 &&
974 sound->token[len_class_text] == '.')
976 int sound_action_value = sound_effect_properties[i];
978 element_info[j].sound[sound_action_value] = i;
983 set_sound_parameters(i, sound->parameter);
986 free(sound_effect_properties);
988 /* initialize element/sound mapping from dynamic configuration */
989 for (i=0; i < num_property_mappings; i++)
991 int element = property_mapping[i].base_index;
992 int action = property_mapping[i].ext1_index;
993 int sound = property_mapping[i].artwork_index;
996 action = ACTION_DEFAULT;
998 element_info[element].sound[action] = sound;
1004 int element = EL_CUSTOM_11;
1007 while (element_action_info[j].suffix)
1009 printf("element %d, sound action '%s' == %d\n",
1010 element, element_action_info[j].suffix,
1011 element_info[element].sound[j]);
1016 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1022 int element = EL_SAND;
1023 int sound_action = ACTION_DIGGING;
1026 while (element_action_info[j].suffix)
1028 if (element_action_info[j].value == sound_action)
1029 printf("element %d, sound action '%s' == %d\n",
1030 element, element_action_info[j].suffix,
1031 element_info[element].sound[sound_action]);
1038 static void ReinitializeGraphics()
1040 InitGraphicInfo(); /* graphic properties mapping */
1041 InitElementGraphicInfo(); /* element game graphic mapping */
1042 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
1044 InitElementSmallImages(); /* create editor and preview images */
1045 InitFontGraphicInfo(); /* initialize text drawing functions */
1047 SetMainBackgroundImage(IMG_BACKGROUND);
1048 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1054 static void ReinitializeSounds()
1056 InitSoundInfo(); /* sound properties mapping */
1057 InitElementSoundInfo(); /* element game sound mapping */
1060 InitElementSoundInfo(); /* element game sound mapping */
1063 InitPlaySoundLevel(); /* internal game sound settings */
1066 static void ReinitializeMusic()
1068 /* currently nothing to do */
1071 void InitElementPropertiesStatic()
1073 static int ep_diggable[] =
1078 EL_SP_BUGGY_BASE_ACTIVATING,
1081 EL_INVISIBLE_SAND_ACTIVE,
1085 EL_SP_BUGGY_BASE_ACTIVE,
1090 static int ep_collectible[] =
1107 EL_DYNABOMB_INCREASE_NUMBER,
1108 EL_DYNABOMB_INCREASE_SIZE,
1109 EL_DYNABOMB_INCREASE_POWER,
1123 static int ep_indestructible[] =
1127 EL_ACID_POOL_TOPLEFT,
1128 EL_ACID_POOL_TOPRIGHT,
1129 EL_ACID_POOL_BOTTOMLEFT,
1130 EL_ACID_POOL_BOTTOM,
1131 EL_ACID_POOL_BOTTOMRIGHT,
1132 EL_SP_HARDWARE_GRAY,
1133 EL_SP_HARDWARE_GREEN,
1134 EL_SP_HARDWARE_BLUE,
1136 EL_SP_HARDWARE_YELLOW,
1137 EL_SP_HARDWARE_BASE_1,
1138 EL_SP_HARDWARE_BASE_2,
1139 EL_SP_HARDWARE_BASE_3,
1140 EL_SP_HARDWARE_BASE_4,
1141 EL_SP_HARDWARE_BASE_5,
1142 EL_SP_HARDWARE_BASE_6,
1143 EL_INVISIBLE_STEELWALL,
1144 EL_INVISIBLE_STEELWALL_ACTIVE,
1145 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1146 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1147 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1148 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1149 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1150 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1151 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1152 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1153 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1154 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1155 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1156 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1158 EL_LIGHT_SWITCH_ACTIVE,
1159 EL_SIGN_EXCLAMATION,
1160 EL_SIGN_RADIOACTIVITY,
1171 EL_STEELWALL_SLANTED,
1194 EL_SWITCHGATE_OPENING,
1195 EL_SWITCHGATE_CLOSED,
1196 EL_SWITCHGATE_CLOSING,
1198 EL_TIMEGATE_OPENING,
1200 EL_TIMEGATE_CLOSING,
1204 EL_TUBE_VERTICAL_LEFT,
1205 EL_TUBE_VERTICAL_RIGHT,
1206 EL_TUBE_HORIZONTAL_UP,
1207 EL_TUBE_HORIZONTAL_DOWN,
1215 static int ep_slippery[] =
1229 EL_ROBOT_WHEEL_ACTIVE,
1235 EL_ACID_POOL_TOPLEFT,
1236 EL_ACID_POOL_TOPRIGHT,
1246 EL_STEELWALL_SLANTED,
1252 static int ep_can_fall[] =
1267 EL_BD_MAGIC_WALL_FULL,
1280 static int ep_can_smash[] =
1305 static int ep_walkable_over[] =
1309 EL_SOKOBAN_FIELD_EMPTY,
1323 static int ep_walkable_inside[] =
1328 EL_TUBE_VERTICAL_LEFT,
1329 EL_TUBE_VERTICAL_RIGHT,
1330 EL_TUBE_HORIZONTAL_UP,
1331 EL_TUBE_HORIZONTAL_DOWN,
1339 static int ep_walkable_under[] =
1344 static int ep_passable_over[] =
1359 static int ep_passable_inside[] =
1365 EL_SP_PORT_HORIZONTAL,
1366 EL_SP_PORT_VERTICAL,
1368 EL_SP_GRAVITY_PORT_LEFT,
1369 EL_SP_GRAVITY_PORT_RIGHT,
1370 EL_SP_GRAVITY_PORT_UP,
1371 EL_SP_GRAVITY_PORT_DOWN,
1375 static int ep_passable_under[] =
1380 static int ep_pushable[] =
1387 EL_SOKOBAN_FIELD_FULL,
1399 static int ep_player[] =
1408 static int ep_can_be_crumbled[] =
1417 static int ep_can_move[] =
1419 /* only stored in level file */
1428 EL_BD_BUTTERFLY_RIGHT,
1430 EL_BD_BUTTERFLY_LEFT,
1431 EL_BD_BUTTERFLY_DOWN,
1432 EL_BD_FIREFLY_RIGHT,
1441 /* level file and runtime elements */
1462 static int ep_can_change[] =
1475 static int ep_dont_touch[] =
1484 static int ep_enemy[] =
1499 static int ep_dont_go_to[] =
1513 EL_SP_BUGGY_BASE_ACTIVE,
1519 static int ep_explosive[] =
1524 EL_DYNABOMB_PLAYER_1_ACTIVE,
1525 EL_DYNABOMB_PLAYER_2_ACTIVE,
1526 EL_DYNABOMB_PLAYER_3_ACTIVE,
1527 EL_DYNABOMB_PLAYER_4_ACTIVE,
1528 EL_DYNABOMB_INCREASE_NUMBER,
1529 EL_DYNABOMB_INCREASE_SIZE,
1530 EL_DYNABOMB_INCREASE_POWER,
1531 EL_SP_DISK_RED_ACTIVE,
1547 static int ep_bd_element[] =
1576 static int ep_sp_element[] =
1584 EL_SP_HARDWARE_GRAY,
1592 EL_SP_GRAVITY_PORT_RIGHT,
1593 EL_SP_GRAVITY_PORT_DOWN,
1594 EL_SP_GRAVITY_PORT_LEFT,
1595 EL_SP_GRAVITY_PORT_UP,
1600 EL_SP_PORT_VERTICAL,
1601 EL_SP_PORT_HORIZONTAL,
1607 EL_SP_HARDWARE_BASE_1,
1608 EL_SP_HARDWARE_GREEN,
1609 EL_SP_HARDWARE_BLUE,
1611 EL_SP_HARDWARE_YELLOW,
1612 EL_SP_HARDWARE_BASE_2,
1613 EL_SP_HARDWARE_BASE_3,
1614 EL_SP_HARDWARE_BASE_4,
1615 EL_SP_HARDWARE_BASE_5,
1616 EL_SP_HARDWARE_BASE_6,
1619 /* additional elements that appeared in newer Supaplex levels */
1621 /* more than one murphy in a level results in an inactive clone */
1626 static int ep_sb_element[] =
1631 EL_SOKOBAN_FIELD_EMPTY,
1632 EL_SOKOBAN_FIELD_FULL,
1634 EL_INVISIBLE_STEELWALL,
1638 static int ep_gem[] =
1649 static int ep_food_dark_yamyam[] =
1676 static int ep_food_penguin[] =
1689 static int ep_historic_wall[] =
1714 EL_EXPANDABLE_WALL_HORIZONTAL,
1715 EL_EXPANDABLE_WALL_VERTICAL,
1716 EL_EXPANDABLE_WALL_ANY,
1717 EL_EXPANDABLE_WALL_GROWING,
1724 EL_SP_HARDWARE_GRAY,
1725 EL_SP_HARDWARE_GREEN,
1726 EL_SP_HARDWARE_BLUE,
1728 EL_SP_HARDWARE_YELLOW,
1729 EL_SP_HARDWARE_BASE_1,
1730 EL_SP_HARDWARE_BASE_2,
1731 EL_SP_HARDWARE_BASE_3,
1732 EL_SP_HARDWARE_BASE_4,
1733 EL_SP_HARDWARE_BASE_5,
1734 EL_SP_HARDWARE_BASE_6,
1736 EL_SP_TERMINAL_ACTIVE,
1739 EL_INVISIBLE_STEELWALL,
1740 EL_INVISIBLE_STEELWALL_ACTIVE,
1742 EL_INVISIBLE_WALL_ACTIVE,
1743 EL_STEELWALL_SLANTED,
1759 static int ep_historic_solid[] =
1763 EL_EXPANDABLE_WALL_HORIZONTAL,
1764 EL_EXPANDABLE_WALL_VERTICAL,
1765 EL_EXPANDABLE_WALL_ANY,
1778 EL_QUICKSAND_FILLING,
1779 EL_QUICKSAND_EMPTYING,
1781 EL_MAGIC_WALL_ACTIVE,
1782 EL_MAGIC_WALL_EMPTYING,
1783 EL_MAGIC_WALL_FILLING,
1787 EL_BD_MAGIC_WALL_ACTIVE,
1788 EL_BD_MAGIC_WALL_EMPTYING,
1789 EL_BD_MAGIC_WALL_FULL,
1790 EL_BD_MAGIC_WALL_FILLING,
1791 EL_BD_MAGIC_WALL_DEAD,
1800 EL_SP_TERMINAL_ACTIVE,
1804 EL_INVISIBLE_WALL_ACTIVE,
1805 EL_SWITCHGATE_SWITCH_UP,
1806 EL_SWITCHGATE_SWITCH_DOWN,
1808 EL_TIMEGATE_SWITCH_ACTIVE,
1820 /* the following elements are a direct copy of "indestructible" elements,
1821 except "EL_ACID", which is "indestructible", but not "solid"! */
1826 EL_ACID_POOL_TOPLEFT,
1827 EL_ACID_POOL_TOPRIGHT,
1828 EL_ACID_POOL_BOTTOMLEFT,
1829 EL_ACID_POOL_BOTTOM,
1830 EL_ACID_POOL_BOTTOMRIGHT,
1831 EL_SP_HARDWARE_GRAY,
1832 EL_SP_HARDWARE_GREEN,
1833 EL_SP_HARDWARE_BLUE,
1835 EL_SP_HARDWARE_YELLOW,
1836 EL_SP_HARDWARE_BASE_1,
1837 EL_SP_HARDWARE_BASE_2,
1838 EL_SP_HARDWARE_BASE_3,
1839 EL_SP_HARDWARE_BASE_4,
1840 EL_SP_HARDWARE_BASE_5,
1841 EL_SP_HARDWARE_BASE_6,
1842 EL_INVISIBLE_STEELWALL,
1843 EL_INVISIBLE_STEELWALL_ACTIVE,
1844 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1845 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1846 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1847 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1848 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1849 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1850 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1851 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1852 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1853 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1854 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1855 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1857 EL_LIGHT_SWITCH_ACTIVE,
1858 EL_SIGN_EXCLAMATION,
1859 EL_SIGN_RADIOACTIVITY,
1870 EL_STEELWALL_SLANTED,
1893 EL_SWITCHGATE_OPENING,
1894 EL_SWITCHGATE_CLOSED,
1895 EL_SWITCHGATE_CLOSING,
1897 EL_TIMEGATE_OPENING,
1899 EL_TIMEGATE_CLOSING,
1903 EL_TUBE_VERTICAL_LEFT,
1904 EL_TUBE_VERTICAL_RIGHT,
1905 EL_TUBE_HORIZONTAL_UP,
1906 EL_TUBE_HORIZONTAL_DOWN,
1914 static int ep_belt[] =
1916 EL_CONVEYOR_BELT_1_LEFT,
1917 EL_CONVEYOR_BELT_1_MIDDLE,
1918 EL_CONVEYOR_BELT_1_RIGHT,
1919 EL_CONVEYOR_BELT_2_LEFT,
1920 EL_CONVEYOR_BELT_2_MIDDLE,
1921 EL_CONVEYOR_BELT_2_RIGHT,
1922 EL_CONVEYOR_BELT_3_LEFT,
1923 EL_CONVEYOR_BELT_3_MIDDLE,
1924 EL_CONVEYOR_BELT_3_RIGHT,
1925 EL_CONVEYOR_BELT_4_LEFT,
1926 EL_CONVEYOR_BELT_4_MIDDLE,
1927 EL_CONVEYOR_BELT_4_RIGHT,
1931 static int ep_belt_active[] =
1933 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
1934 EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
1935 EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
1936 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
1937 EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
1938 EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
1939 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
1940 EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
1941 EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
1942 EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
1943 EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
1944 EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
1948 static int ep_belt_switch[] =
1950 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1951 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1952 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1953 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1954 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1955 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1956 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1957 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1958 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1959 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1960 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1961 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1965 static int ep_tube[] =
1972 EL_TUBE_HORIZONTAL_UP,
1973 EL_TUBE_HORIZONTAL_DOWN,
1975 EL_TUBE_VERTICAL_LEFT,
1976 EL_TUBE_VERTICAL_RIGHT,
1981 static int ep_keygate[] =
2002 static int ep_amoeboid[] =
2012 static int ep_amoebalive[] =
2021 static int ep_has_content[] =
2031 static int ep_active_bomb[] =
2034 EL_DYNABOMB_PLAYER_1_ACTIVE,
2035 EL_DYNABOMB_PLAYER_2_ACTIVE,
2036 EL_DYNABOMB_PLAYER_3_ACTIVE,
2037 EL_DYNABOMB_PLAYER_4_ACTIVE,
2038 EL_SP_DISK_RED_ACTIVE,
2042 static int ep_inactive[] =
2079 EL_INVISIBLE_STEELWALL,
2087 EL_WALL_EMERALD_YELLOW,
2088 EL_DYNABOMB_INCREASE_NUMBER,
2089 EL_DYNABOMB_INCREASE_SIZE,
2090 EL_DYNABOMB_INCREASE_POWER,
2092 EL_SOKOBAN_FIELD_EMPTY,
2093 EL_SOKOBAN_FIELD_FULL,
2094 EL_WALL_EMERALD_RED,
2095 EL_WALL_EMERALD_PURPLE,
2096 EL_ACID_POOL_TOPLEFT,
2097 EL_ACID_POOL_TOPRIGHT,
2098 EL_ACID_POOL_BOTTOMLEFT,
2099 EL_ACID_POOL_BOTTOM,
2100 EL_ACID_POOL_BOTTOMRIGHT,
2104 EL_BD_MAGIC_WALL_DEAD,
2105 EL_AMOEBA_TO_DIAMOND,
2113 EL_SP_GRAVITY_PORT_RIGHT,
2114 EL_SP_GRAVITY_PORT_DOWN,
2115 EL_SP_GRAVITY_PORT_LEFT,
2116 EL_SP_GRAVITY_PORT_UP,
2117 EL_SP_PORT_HORIZONTAL,
2118 EL_SP_PORT_VERTICAL,
2127 EL_SP_HARDWARE_GRAY,
2128 EL_SP_HARDWARE_GREEN,
2129 EL_SP_HARDWARE_BLUE,
2131 EL_SP_HARDWARE_YELLOW,
2132 EL_SP_HARDWARE_BASE_1,
2133 EL_SP_HARDWARE_BASE_2,
2134 EL_SP_HARDWARE_BASE_3,
2135 EL_SP_HARDWARE_BASE_4,
2136 EL_SP_HARDWARE_BASE_5,
2137 EL_SP_HARDWARE_BASE_6,
2138 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2139 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2140 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2141 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2142 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2143 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2144 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2145 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2146 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2147 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2148 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2149 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2150 EL_SIGN_EXCLAMATION,
2151 EL_SIGN_RADIOACTIVITY,
2162 EL_STEELWALL_SLANTED,
2182 } element_properties[] =
2184 { ep_diggable, EP_DIGGABLE },
2185 { ep_collectible, EP_COLLECTIBLE },
2186 { ep_indestructible, EP_INDESTRUCTIBLE },
2187 { ep_slippery, EP_SLIPPERY },
2188 { ep_can_fall, EP_CAN_FALL },
2189 { ep_can_smash, EP_CAN_SMASH },
2190 { ep_walkable_over, EP_WALKABLE_OVER },
2191 { ep_walkable_inside, EP_WALKABLE_INSIDE },
2192 { ep_walkable_under, EP_WALKABLE_UNDER },
2193 { ep_passable_over, EP_PASSABLE_OVER },
2194 { ep_passable_inside, EP_PASSABLE_INSIDE },
2195 { ep_passable_under, EP_PASSABLE_UNDER },
2196 { ep_pushable, EP_PUSHABLE },
2198 { ep_player, EP_PLAYER },
2199 { ep_can_be_crumbled, EP_CAN_BE_CRUMBLED },
2200 { ep_can_move, EP_CAN_MOVE },
2201 { ep_can_change, EP_CAN_CHANGE },
2202 { ep_dont_touch, EP_DONT_TOUCH },
2203 { ep_enemy, EP_ENEMY },
2204 { ep_dont_go_to, EP_DONT_GO_TO },
2205 { ep_explosive, EP_EXPLOSIVE },
2206 { ep_bd_element, EP_BD_ELEMENT },
2207 { ep_sp_element, EP_SP_ELEMENT },
2208 { ep_sb_element, EP_SB_ELEMENT },
2210 { ep_food_dark_yamyam, EP_FOOD_DARK_YAMYAM },
2211 { ep_food_penguin, EP_FOOD_PENGUIN },
2212 { ep_historic_wall, EP_HISTORIC_WALL },
2213 { ep_historic_solid, EP_HISTORIC_SOLID },
2214 { ep_belt, EP_BELT },
2215 { ep_belt_active, EP_BELT_ACTIVE },
2216 { ep_belt_switch, EP_BELT_SWITCH },
2217 { ep_tube, EP_TUBE },
2218 { ep_keygate, EP_KEYGATE },
2219 { ep_amoeboid, EP_AMOEBOID },
2220 { ep_amoebalive, EP_AMOEBALIVE },
2221 { ep_has_content, EP_HAS_CONTENT },
2222 { ep_active_bomb, EP_ACTIVE_BOMB },
2223 { ep_inactive, EP_INACTIVE },
2230 /* always start with reliable default values (element has no properties) */
2231 for (i=0; i < MAX_NUM_ELEMENTS; i++)
2232 for (j=0; j < NUM_ELEMENT_PROPERTIES; j++)
2233 SET_PROPERTY(i, j, FALSE);
2235 /* set all base element properties from above array definitions */
2236 for (i=0; element_properties[i].elements != NULL; i++)
2237 for (j=0; (element_properties[i].elements)[j] != -1; j++)
2238 SET_PROPERTY((element_properties[i].elements)[j],
2239 element_properties[i].property, TRUE);
2242 void InitElementPropertiesEngine(int engine_version)
2245 static int active_properties[] =
2272 EP_EM_SLIPPERY_WALL,
2277 static int no_wall_properties[] =
2287 EP_FOOD_DARK_YAMYAM,
2304 /* set all special, combined or engine dependant element properties */
2305 for (i=0; i < MAX_NUM_ELEMENTS; i++)
2307 /* ---------- INACTIVE ------------------------------------------------- */
2308 if (i >= EL_CHAR_START && i <= EL_CHAR_END)
2309 SET_PROPERTY(i, EP_INACTIVE, TRUE);
2311 /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
2312 if (IS_WALKABLE_OVER(i) || IS_WALKABLE_INSIDE(i) || IS_WALKABLE_UNDER(i))
2313 SET_PROPERTY(i, EP_WALKABLE, TRUE);
2315 if (IS_PASSABLE_OVER(i) || IS_PASSABLE_INSIDE(i) || IS_PASSABLE_UNDER(i))
2316 SET_PROPERTY(i, EP_PASSABLE, TRUE);
2318 if (IS_WALKABLE_OVER(i) || IS_PASSABLE_OVER(i))
2319 SET_PROPERTY(i, EP_ACCESSIBLE_OVER, TRUE);
2321 if (IS_WALKABLE_INSIDE(i) || IS_PASSABLE_INSIDE(i))
2322 SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, TRUE);
2324 if (IS_WALKABLE_UNDER(i) || IS_PASSABLE_UNDER(i))
2325 SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, TRUE);
2327 if (IS_WALKABLE(i) || IS_PASSABLE(i))
2328 SET_PROPERTY(i, EP_ACCESSIBLE, TRUE);
2330 /* ---------- WALL ----------------------------------------------------- */
2331 SET_PROPERTY(i, EP_WALL, TRUE); /* default: element is wall */
2333 for (j=0; no_wall_properties[j] != -1; j++)
2334 if (HAS_PROPERTY(i, no_wall_properties[j]) ||
2335 i >= EL_FIRST_RUNTIME_UNREAL)
2336 SET_PROPERTY(i, EP_WALL, FALSE);
2338 if (IS_HISTORIC_WALL(i))
2339 SET_PROPERTY(i, EP_WALL, TRUE);
2341 /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */
2342 if (engine_version < VERSION_IDENT(2,2,0))
2343 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i));
2345 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) &&
2347 !IS_COLLECTIBLE(i)));
2349 /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
2350 if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION ||
2351 (IS_CUSTOM_ELEMENT(i) && IS_INDESTRUCTIBLE(i)))
2352 SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
2354 /* ---------- EXPLOSION_PROOF ------------------------------------------ */
2356 SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE);
2357 else if (engine_version < VERSION_IDENT(2,2,0))
2358 SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i));
2360 SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
2361 !IS_WALKABLE_OVER(i) &&
2362 !IS_WALKABLE_UNDER(i)));
2366 /* determine inactive elements (used for engine main loop optimization) */
2367 for (i=0; i < MAX_NUM_ELEMENTS; i++)
2369 boolean active = FALSE;
2371 for (j=0; i < NUM_ELEMENT_PROPERTIES; j++)
2373 if (HAS_PROPERTY(i, j))
2379 SET_PROPERTY(i, EP_INACTIVE, TRUE);
2384 /* dynamically adjust element properties according to game engine version */
2386 static int ep_em_slippery_wall[] =
2391 EL_EXPANDABLE_WALL_HORIZONTAL,
2392 EL_EXPANDABLE_WALL_VERTICAL,
2393 EL_EXPANDABLE_WALL_ANY,
2397 /* special EM style gems behaviour */
2398 for (i=0; ep_em_slippery_wall[i] != -1; i++)
2399 SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL,
2400 level.em_slippery_gems);
2402 /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */
2403 SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL,
2404 (level.em_slippery_gems &&
2405 engine_version > VERSION_IDENT(2,0,1)));
2409 static void InitGlobal()
2411 global.autoplay_leveldir = NULL;
2413 global.frames_per_second = 0;
2414 global.fps_slowdown = FALSE;
2415 global.fps_slowdown_factor = 1;
2418 void Execute_Command(char *command)
2420 if (strcmp(command, "print graphicsinfo.conf") == 0)
2424 printf("# You can configure additional/alternative image files here.\n");
2425 printf("# (The images below are default and therefore commented out.)\n");
2427 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2429 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2432 for (i=0; image_config[i].token != NULL; i++)
2434 getFormattedSetupEntry(image_config[i].token,
2435 image_config[i].value));
2439 else if (strcmp(command, "print soundsinfo.conf") == 0)
2443 printf("# You can configure additional/alternative sound files here.\n");
2444 printf("# (The sounds below are default and therefore commented out.)\n");
2446 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2448 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2451 for (i=0; sound_config[i].token != NULL; i++)
2453 getFormattedSetupEntry(sound_config[i].token,
2454 sound_config[i].value));
2458 else if (strcmp(command, "print musicinfo.conf") == 0)
2460 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2462 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2464 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2468 else if (strncmp(command, "dump level ", 11) == 0)
2470 char *filename = &command[11];
2472 if (access(filename, F_OK) != 0)
2473 Error(ERR_EXIT, "cannot open file '%s'", filename);
2475 LoadLevelFromFilename(filename);
2480 else if (strncmp(command, "dump tape ", 10) == 0)
2482 char *filename = &command[10];
2484 if (access(filename, F_OK) != 0)
2485 Error(ERR_EXIT, "cannot open file '%s'", filename);
2487 LoadTapeFromFilename(filename);
2492 else if (strncmp(command, "autoplay ", 9) == 0)
2494 char *str_copy = getStringCopy(&command[9]);
2495 char *str_ptr = strchr(str_copy, ' ');
2497 global.autoplay_leveldir = str_copy;
2498 global.autoplay_level_nr = -1;
2500 if (str_ptr != NULL)
2502 *str_ptr++ = '\0'; /* terminate leveldir string */
2503 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2508 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2512 static void InitSetup()
2514 LoadSetup(); /* global setup info */
2516 /* set some options from setup file */
2518 if (setup.options.verbose)
2519 options.verbose = TRUE;
2522 static void InitPlayerInfo()
2526 /* choose default local player */
2527 local_player = &stored_player[0];
2529 for (i=0; i<MAX_PLAYERS; i++)
2530 stored_player[i].connected = FALSE;
2532 local_player->connected = TRUE;
2535 static void InitArtworkInfo()
2540 static char *get_element_class_token(int element)
2542 char *element_class_name = element_info[element].class_name;
2543 char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
2545 sprintf(element_class_token, "[%s]", element_class_name);
2547 return element_class_token;
2550 static void InitArtworkConfig()
2552 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
2553 static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1];
2554 static char *action_id_suffix[NUM_ACTIONS + 1];
2555 static char *direction_id_suffix[NUM_DIRECTIONS + 1];
2556 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
2557 static char *dummy[1] = { NULL };
2558 static char *ignore_generic_tokens[] =
2564 static char **ignore_image_tokens, **ignore_sound_tokens;
2565 int num_ignore_generic_tokens;
2566 int num_ignore_image_tokens, num_ignore_sound_tokens;
2569 /* dynamically determine list of generic tokens to be ignored */
2570 num_ignore_generic_tokens = 0;
2571 for (i=0; ignore_generic_tokens[i] != NULL; i++)
2572 num_ignore_generic_tokens++;
2574 /* dynamically determine list of image tokens to be ignored */
2575 num_ignore_image_tokens = num_ignore_generic_tokens;
2576 for (i=0; image_config_vars[i].token != NULL; i++)
2577 num_ignore_image_tokens++;
2578 ignore_image_tokens =
2579 checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *));
2580 for (i=0; i < num_ignore_generic_tokens; i++)
2581 ignore_image_tokens[i] = ignore_generic_tokens[i];
2582 for (i=0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++)
2583 ignore_image_tokens[num_ignore_generic_tokens + i] =
2584 image_config_vars[i].token;
2585 ignore_image_tokens[num_ignore_image_tokens] = NULL;
2587 /* dynamically determine list of sound tokens to be ignored */
2588 num_ignore_sound_tokens = num_ignore_generic_tokens;
2589 ignore_sound_tokens =
2590 checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
2591 for (i=0; i < num_ignore_generic_tokens; i++)
2592 ignore_sound_tokens[i] = ignore_generic_tokens[i];
2593 ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
2595 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2596 image_id_prefix[i] = element_info[i].token_name;
2597 for (i=0; i<NUM_FONTS; i++)
2598 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
2599 image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
2601 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2602 sound_id_prefix[i] = element_info[i].token_name;
2603 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2604 sound_id_prefix[MAX_NUM_ELEMENTS + i] = get_element_class_token(i);
2605 sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS] = NULL;
2607 for (i=0; i<NUM_ACTIONS; i++)
2608 action_id_suffix[i] = element_action_info[i].suffix;
2609 action_id_suffix[NUM_ACTIONS] = NULL;
2611 for (i=0; i<NUM_DIRECTIONS; i++)
2612 direction_id_suffix[i] = element_direction_info[i].suffix;
2613 direction_id_suffix[NUM_DIRECTIONS] = NULL;
2615 for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
2616 special_id_suffix[i] = special_suffix_info[i].suffix;
2617 special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
2619 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
2620 image_id_prefix, action_id_suffix, direction_id_suffix,
2621 special_id_suffix, ignore_image_tokens);
2622 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
2623 sound_id_prefix, action_id_suffix, dummy,
2624 special_id_suffix, ignore_sound_tokens);
2627 static void InitMixer()
2635 char *filename_font_initial = NULL;
2636 Bitmap *bitmap_font_initial = NULL;
2639 /* determine settings for initial font (for displaying startup messages) */
2640 for (i=0; image_config[i].token != NULL; i++)
2642 for (j=0; j < NUM_INITIAL_FONTS; j++)
2644 char font_token[128];
2647 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
2648 len_font_token = strlen(font_token);
2650 if (strcmp(image_config[i].token, font_token) == 0)
2651 filename_font_initial = image_config[i].value;
2652 else if (strlen(image_config[i].token) > len_font_token &&
2653 strncmp(image_config[i].token, font_token, len_font_token) == 0)
2655 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
2656 font_initial[j].src_x = atoi(image_config[i].value);
2657 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
2658 font_initial[j].src_y = atoi(image_config[i].value);
2659 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
2660 font_initial[j].width = atoi(image_config[i].value);
2661 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
2662 font_initial[j].height = atoi(image_config[i].value);
2667 for (j=0; j < NUM_INITIAL_FONTS; j++)
2669 font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
2670 font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
2673 if (filename_font_initial == NULL) /* should not happen */
2674 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
2676 /* create additional image buffers for double-buffering */
2677 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
2678 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
2680 /* initialize screen properties */
2681 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
2682 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
2684 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
2685 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
2686 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
2688 bitmap_font_initial = LoadCustomImage(filename_font_initial);
2690 for (j=0; j < NUM_INITIAL_FONTS; j++)
2691 font_initial[j].bitmap = bitmap_font_initial;
2693 InitFontGraphicInfo();
2695 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
2696 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
2698 DrawInitText("Loading graphics:", 120, FC_GREEN);
2700 InitTileClipmasks();
2703 void InitGfxBackground()
2707 drawto = backbuffer;
2708 fieldbuffer = bitmap_db_field;
2709 SetDrawtoField(DRAW_BACKBUFFER);
2711 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
2712 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2713 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
2714 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
2716 for (x=0; x<MAX_BUF_XSIZE; x++)
2717 for (y=0; y<MAX_BUF_YSIZE; y++)
2720 redraw_mask = REDRAW_ALL;
2723 static void InitLevelInfo()
2725 LoadLevelInfo(); /* global level info */
2726 LoadLevelSetup_LastSeries(); /* last played series info */
2727 LoadLevelSetup_SeriesInfo(); /* last played level info */
2730 void InitLevelArtworkInfo()
2732 LoadLevelArtworkInfo();
2735 static void InitImages()
2737 ReloadCustomImages();
2739 LoadCustomElementDescriptions();
2740 LoadSpecialMenuDesignSettings();
2742 ReinitializeGraphics();
2745 static void InitSound()
2747 InitReloadCustomSounds(artwork.snd_current->identifier);
2748 ReinitializeSounds();
2751 static void InitMusic()
2753 InitReloadCustomMusic(artwork.mus_current->identifier);
2754 ReinitializeMusic();
2757 void InitNetworkServer()
2759 #if defined(PLATFORM_UNIX)
2763 if (!options.network)
2766 #if defined(PLATFORM_UNIX)
2767 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
2769 if (!ConnectToServer(options.server_host, options.server_port))
2770 Error(ERR_EXIT, "cannot connect to network game server");
2772 SendToServer_PlayerName(setup.player_name);
2773 SendToServer_ProtocolVersion();
2776 SendToServer_NrWanted(nr_wanted);
2780 void ReloadCustomArtwork()
2782 static char *leveldir_current_identifier = NULL;
2783 static boolean last_override_level_graphics = FALSE;
2784 static boolean last_override_level_sounds = FALSE;
2785 static boolean last_override_level_music = FALSE;
2786 /* identifier for new artwork; default: artwork configured in setup */
2787 char *gfx_new_identifier = artwork.gfx_current->identifier;
2788 char *snd_new_identifier = artwork.snd_current->identifier;
2789 char *mus_new_identifier = artwork.mus_current->identifier;
2790 boolean redraw_screen = FALSE;
2792 if (leveldir_current_identifier == NULL)
2793 leveldir_current_identifier = leveldir_current->identifier;
2796 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
2797 leveldir_current->graphics_set);
2798 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
2799 leveldir_current->identifier);
2803 printf("graphics --> '%s' ('%s')\n",
2804 artwork.gfx_current_identifier, artwork.gfx_current->filename);
2805 printf("sounds --> '%s' ('%s')\n",
2806 artwork.snd_current_identifier, artwork.snd_current->filename);
2807 printf("music --> '%s' ('%s')\n",
2808 artwork.mus_current_identifier, artwork.mus_current->filename);
2811 /* leveldir_current may be invalid (level group, parent link) */
2812 if (!validLevelSeries(leveldir_current))
2815 /* when a new level series was selected, check if there was a change
2816 in custom artwork stored in level series directory */
2817 if (leveldir_current_identifier != leveldir_current->identifier)
2819 char *identifier_old = leveldir_current_identifier;
2820 char *identifier_new = leveldir_current->identifier;
2822 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
2823 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
2824 gfx_new_identifier = identifier_new;
2825 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
2826 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
2827 snd_new_identifier = identifier_new;
2828 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
2829 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
2830 mus_new_identifier = identifier_new;
2832 leveldir_current_identifier = leveldir_current->identifier;
2835 /* custom level artwork configured in level series configuration file
2836 always overrides custom level artwork stored in level series directory
2837 and (level independant) custom artwork configured in setup menue */
2838 if (leveldir_current->graphics_set != NULL)
2839 gfx_new_identifier = leveldir_current->graphics_set;
2840 if (leveldir_current->sounds_set != NULL)
2841 snd_new_identifier = leveldir_current->sounds_set;
2842 if (leveldir_current->music_set != NULL)
2843 mus_new_identifier = leveldir_current->music_set;
2845 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
2846 last_override_level_graphics != setup.override_level_graphics)
2849 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
2850 artwork.gfx_current_identifier,
2851 artwork.gfx_current->identifier,
2852 gfx_new_identifier);
2855 setLevelArtworkDir(artwork.gfx_first);
2857 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
2861 FreeTileClipmasks();
2862 InitTileClipmasks();
2864 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
2865 last_override_level_graphics = setup.override_level_graphics;
2867 redraw_screen = TRUE;
2870 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
2871 last_override_level_sounds != setup.override_level_sounds)
2874 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
2875 artwork.snd_current_identifier,
2876 artwork.snd_current->identifier,
2877 snd_new_identifier);
2880 /* set artwork path to send it to the sound server process */
2881 setLevelArtworkDir(artwork.snd_first);
2883 InitReloadCustomSounds(snd_new_identifier);
2884 ReinitializeSounds();
2886 artwork.snd_current_identifier = artwork.snd_current->identifier;
2887 last_override_level_sounds = setup.override_level_sounds;
2889 redraw_screen = TRUE;
2892 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
2893 last_override_level_music != setup.override_level_music)
2895 /* set artwork path to send it to the sound server process */
2896 setLevelArtworkDir(artwork.mus_first);
2898 InitReloadCustomMusic(mus_new_identifier);
2899 ReinitializeMusic();
2901 artwork.mus_current_identifier = artwork.mus_current->identifier;
2902 last_override_level_music = setup.override_level_music;
2904 redraw_screen = TRUE;
2909 InitGfxBackground();
2911 /* force redraw of (open or closed) door graphics */
2912 SetDoorState(DOOR_OPEN_ALL);
2913 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
2918 /* ========================================================================= */
2920 /* ========================================================================= */
2924 InitGlobal(); /* initialize some global variables */
2926 if (options.execute_command)
2927 Execute_Command(options.execute_command);
2929 if (options.serveronly)
2931 #if defined(PLATFORM_UNIX)
2932 NetworkServer(options.server_port, options.serveronly);
2934 Error(ERR_WARN, "networking only supported in Unix version");
2936 exit(0); /* never reached */
2942 InitArtworkInfo(); /* needed before loading gfx, sound & music */
2943 InitArtworkConfig(); /* needed before forking sound child process */
2948 InitRND(NEW_RANDOMIZE);
2949 InitSimpleRND(NEW_RANDOMIZE);
2954 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
2957 InitEventFilter(FilterMouseMotionEvents);
2959 InitElementPropertiesStatic();
2964 InitLevelArtworkInfo();
2966 InitImages(); /* needs to know current level directory */
2967 InitSound(); /* needs to know current level directory */
2968 InitMusic(); /* needs to know current level directory */
2970 InitGfxBackground();
2972 if (global.autoplay_leveldir)
2978 game_status = GAME_MODE_MAIN;
2982 InitNetworkServer();
2985 void CloseAllAndExit(int exit_value)
2990 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2993 FreeTileClipmasks();
2995 CloseVideoDisplay();
2996 ClosePlatformDependantStuff();