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 == MAINMENU || game_status == TYPENAME)
264 special = GFX_SPECIAL_ARG_MAIN;
265 else if (game_status == CHOOSELEVEL)
266 special = GFX_SPECIAL_ARG_LEVELS;
267 else if (game_status == HALLOFFAME)
268 special = GFX_SPECIAL_ARG_SCORES;
269 else if (game_status == LEVELED)
270 special = GFX_SPECIAL_ARG_EDITOR;
271 else if (game_status == HELPSCREEN)
272 special = GFX_SPECIAL_ARG_INFO;
273 else if (game_status == SETUP)
274 special = GFX_SPECIAL_ARG_SETUP;
275 else if (game_status == PSEUDO_PREVIEW)
276 special = GFX_SPECIAL_ARG_PREVIEW;
277 else if (game_status == PLAYING || game_status == PSEUDO_DOOR)
278 special = GFX_SPECIAL_ARG_DOOR;
281 return font_info[font_nr].special_bitmap_id[special];
286 void InitFontGraphicInfo()
288 static struct FontBitmapInfo *font_bitmap_info = NULL;
289 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
290 int num_property_mappings = getImageListPropertyMappingSize();
291 int num_font_bitmaps = NUM_FONTS;
294 if (graphic_info == NULL) /* still at startup phase */
296 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
301 /* ---------- initialize font graphic definitions ---------- */
303 /* always start with reliable default values (normal font graphics) */
304 for (i=0; i < NUM_FONTS; i++)
305 font_info[i].graphic = FONT_INITIAL_1;
307 /* initialize normal font/graphic mapping from static configuration */
308 for (i=0; font_to_graphic[i].font_nr > -1; i++)
310 int font_nr = font_to_graphic[i].font_nr;
311 int special = font_to_graphic[i].special;
312 int graphic = font_to_graphic[i].graphic;
317 font_info[font_nr].graphic = graphic;
320 /* always start with reliable default values (special font graphics) */
321 for (i=0; i < NUM_FONTS; i++)
323 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
325 font_info[i].special_graphic[j] = font_info[i].graphic;
326 font_info[i].special_bitmap_id[j] = i;
330 /* initialize special font/graphic mapping from static configuration */
331 for (i=0; font_to_graphic[i].font_nr > -1; i++)
333 int font_nr = font_to_graphic[i].font_nr;
334 int special = font_to_graphic[i].special;
335 int graphic = font_to_graphic[i].graphic;
337 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
339 font_info[font_nr].special_graphic[special] = graphic;
340 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
345 /* initialize special element/graphic mapping from dynamic configuration */
346 for (i=0; i < num_property_mappings; i++)
348 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
349 int special = property_mapping[i].ext3_index;
350 int graphic = property_mapping[i].artwork_index;
355 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
357 font_info[font_nr].special_graphic[special] = graphic;
358 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
363 /* ---------- initialize font bitmap array ---------- */
365 if (font_bitmap_info != NULL)
366 FreeFontInfo(font_bitmap_info);
369 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
371 /* ---------- initialize font bitmap definitions ---------- */
373 for (i=0; i < NUM_FONTS; i++)
375 if (i < NUM_INITIAL_FONTS)
377 font_bitmap_info[i] = font_initial[i];
381 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
383 int font_bitmap_id = font_info[i].special_bitmap_id[j];
384 int graphic = font_info[i].special_graphic[j];
386 /* set 'graphic_info' for font entries, if uninitialized (guessed) */
387 if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
389 graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
390 graphic_info[graphic].anim_frames_per_line= DEFAULT_NUM_CHARS_PER_LINE;
393 /* copy font relevant information from graphics information */
394 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
395 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
396 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
397 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
398 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
399 font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
400 font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
402 font_bitmap_info[font_bitmap_id].num_chars =
403 graphic_info[graphic].anim_frames;
404 font_bitmap_info[font_bitmap_id].num_chars_per_line =
405 graphic_info[graphic].anim_frames_per_line;
409 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
412 void InitElementGraphicInfo()
414 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
415 int num_property_mappings = getImageListPropertyMappingSize();
418 /* set values to -1 to identify later as "uninitialized" values */
419 for (i=0; i<MAX_NUM_ELEMENTS; i++)
421 for (act=0; act<NUM_ACTIONS; act++)
423 element_info[i].graphic[act] = -1;
425 for (dir=0; dir<NUM_DIRECTIONS; dir++)
426 element_info[i].direction_graphic[act][dir] = -1;
430 /* initialize normal element/graphic mapping from static configuration */
431 for (i=0; element_to_graphic[i].element > -1; i++)
433 int element = element_to_graphic[i].element;
434 int action = element_to_graphic[i].action;
435 int direction = element_to_graphic[i].direction;
436 int graphic = element_to_graphic[i].graphic;
438 if (graphic_info[graphic].bitmap == NULL)
442 action = ACTION_DEFAULT;
445 element_info[element].direction_graphic[action][direction] = graphic;
447 element_info[element].graphic[action] = graphic;
450 /* initialize normal element/graphic mapping from dynamic configuration */
451 for (i=0; i < num_property_mappings; i++)
453 int element = property_mapping[i].base_index;
454 int action = property_mapping[i].ext1_index;
455 int direction = property_mapping[i].ext2_index;
456 int special = property_mapping[i].ext3_index;
457 int graphic = property_mapping[i].artwork_index;
459 if (graphic_info[graphic].bitmap == NULL)
462 if (element >= MAX_NUM_ELEMENTS || special != -1)
466 action = ACTION_DEFAULT;
469 element_info[element].direction_graphic[action][direction] = graphic;
471 element_info[element].graphic[action] = graphic;
474 /* now set all '-1' values to element specific default values */
475 for (i=0; i<MAX_NUM_ELEMENTS; i++)
477 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
478 int default_action_direction_graphic[NUM_DIRECTIONS];
480 if (default_action_graphic == -1)
481 default_action_graphic = IMG_CHAR_QUESTION;
483 for (dir=0; dir<NUM_DIRECTIONS; dir++)
485 default_action_direction_graphic[dir] =
486 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
488 if (default_action_direction_graphic[dir] == -1)
489 default_action_direction_graphic[dir] = default_action_graphic;
492 for (act=0; act<NUM_ACTIONS; act++)
494 boolean act_empty = (act == ACTION_DIGGING ||
495 act == ACTION_SNAPPING ||
496 act == ACTION_COLLECTING);
498 for (dir=0; dir<NUM_DIRECTIONS; dir++)
500 int default_direction_graphic = element_info[i].graphic[act];
502 /* no graphic for current action -- use default direction graphic */
503 if (default_direction_graphic == -1)
504 default_direction_graphic =
505 (act_empty ? IMG_EMPTY : default_action_direction_graphic[dir]);
507 if (element_info[i].direction_graphic[act][dir] == -1)
508 element_info[i].direction_graphic[act][dir] =
509 default_direction_graphic;
512 /* no graphic for this specific action -- use default action graphic */
513 if (element_info[i].graphic[act] == -1)
514 element_info[i].graphic[act] =
515 (act_empty ? IMG_EMPTY : default_action_graphic);
523 for (i=0; i<MAX_NUM_ELEMENTS; i++)
524 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
525 i != EL_CHAR_QUESTION)
526 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
527 element_info[i].token_name, i);
533 void InitElementSpecialGraphicInfo()
535 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
536 int num_property_mappings = getImageListPropertyMappingSize();
539 /* always start with reliable default values */
540 for (i=0; i < MAX_NUM_ELEMENTS; i++)
541 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
542 element_info[i].special_graphic[j] =
543 element_info[i].graphic[ACTION_DEFAULT];
545 /* initialize special element/graphic mapping from static configuration */
546 for (i=0; element_to_special_graphic[i].element > -1; i++)
548 int element = element_to_special_graphic[i].element;
549 int special = element_to_special_graphic[i].special;
550 int graphic = element_to_special_graphic[i].graphic;
551 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
552 boolean special_redefined = getImageListEntry(graphic)->redefined;
554 if (base_redefined && !special_redefined)
557 element_info[element].special_graphic[special] = graphic;
560 /* initialize special element/graphic mapping from dynamic configuration */
561 for (i=0; i < num_property_mappings; i++)
563 int element = property_mapping[i].base_index;
564 int special = property_mapping[i].ext3_index;
565 int graphic = property_mapping[i].artwork_index;
567 if (element >= MAX_NUM_ELEMENTS)
570 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
571 element_info[element].special_graphic[special] = graphic;
575 static void set_graphic_parameters(int graphic, char **parameter_raw)
577 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
578 int parameter[NUM_GFX_ARGS];
579 int anim_frames_per_row = 1, anim_frames_per_col = 1;
580 int anim_frames_per_line = 1;
583 /* get integer values from string parameters */
584 for (i=0; i < NUM_GFX_ARGS; i++)
586 get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
587 image_config_suffix[i].type);
589 graphic_info[graphic].bitmap = src_bitmap;
591 /* start with reliable default values */
592 graphic_info[graphic].src_x = 0;
593 graphic_info[graphic].src_y = 0;
594 graphic_info[graphic].width = TILEX;
595 graphic_info[graphic].height = TILEY;
596 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
597 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
599 /* optional x and y tile position of animation frame sequence */
600 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
601 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
602 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
603 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
605 /* optional x and y pixel position of animation frame sequence */
606 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
607 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
608 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
609 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
611 /* optional width and height of each animation frame */
612 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
613 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
614 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
615 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
619 anim_frames_per_row = src_bitmap->width / graphic_info[graphic].width;
620 anim_frames_per_col = src_bitmap->height / graphic_info[graphic].height;
623 /* correct x or y offset dependant of vertical or horizontal frame order */
624 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
626 graphic_info[graphic].offset_y =
627 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
628 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
629 anim_frames_per_line = anim_frames_per_col;
631 else /* frames are ordered horizontally */
633 graphic_info[graphic].offset_x =
634 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
635 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
636 anim_frames_per_line = anim_frames_per_row;
639 /* optionally, the x and y offset of frames can be specified directly */
640 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
641 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
642 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
643 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
645 /* automatically determine correct number of frames, if not defined */
646 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
647 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
648 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
649 graphic_info[graphic].anim_frames = anim_frames_per_row;
650 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
651 graphic_info[graphic].anim_frames = anim_frames_per_col;
653 graphic_info[graphic].anim_frames = 1;
655 graphic_info[graphic].anim_frames_per_line =
656 (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
657 parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
659 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
660 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
661 graphic_info[graphic].anim_delay = 1;
663 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
664 if (graphic_info[graphic].anim_frames == 1)
665 graphic_info[graphic].anim_mode = ANIM_NONE;
667 /* automatically determine correct start frame, if not defined */
668 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
669 graphic_info[graphic].anim_start_frame = 0;
670 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
671 graphic_info[graphic].anim_start_frame =
672 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
674 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
676 /* animation synchronized with global frame counter, not move position */
677 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
679 /* this is only used for toon animations */
680 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
681 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
683 /* this is only used for drawing font characters */
684 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
685 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
688 static void InitGraphicInfo()
690 int fallback_graphic = IMG_CHAR_EXCLAM;
691 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
692 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
693 int num_images = getImageListSize();
696 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
697 static boolean clipmasks_initialized = FALSE;
699 XGCValues clip_gc_values;
700 unsigned long clip_gc_valuemask;
701 GC copy_clipmask_gc = None;
704 if (graphic_info != NULL)
707 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
709 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
710 if (clipmasks_initialized)
712 for (i=0; i<num_images; i++)
714 if (graphic_info[i].clip_mask)
715 XFreePixmap(display, graphic_info[i].clip_mask);
716 if (graphic_info[i].clip_gc)
717 XFreeGC(display, graphic_info[i].clip_gc);
719 graphic_info[i].clip_mask = None;
720 graphic_info[i].clip_gc = None;
725 for (i=0; i<num_images; i++)
727 struct FileInfo *image = getImageListEntry(i);
730 int first_frame, last_frame;
732 set_graphic_parameters(i, image->parameter);
734 /* now check if no animation frames are outside of the loaded image */
736 if (graphic_info[i].bitmap == NULL)
737 continue; /* skip check for optional images that are undefined */
740 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
741 if (src_x < 0 || src_y < 0 ||
742 src_x + TILEX > src_bitmap->width ||
743 src_y + TILEY > src_bitmap->height)
745 Error(ERR_RETURN_LINE, "-");
746 Error(ERR_RETURN, "warning: error found in config file:");
747 Error(ERR_RETURN, "- config file: '%s'",
748 getImageConfigFilename());
749 Error(ERR_RETURN, "- config token: '%s'",
750 getTokenFromImageID(i));
751 Error(ERR_RETURN, "- image file: '%s'",
752 src_bitmap->source_filename);
754 "error: first animation frame out of bounds (%d, %d)",
756 Error(ERR_RETURN, "custom graphic rejected for this element/action");
758 if (i == fallback_graphic)
759 Error(ERR_EXIT, "fatal error: no fallback graphic available");
761 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
762 Error(ERR_RETURN_LINE, "-");
764 set_graphic_parameters(i, fallback_image->default_parameter);
765 graphic_info[i].bitmap = fallback_bitmap;
768 last_frame = graphic_info[i].anim_frames - 1;
769 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
770 if (src_x < 0 || src_y < 0 ||
771 src_x + TILEX > src_bitmap->width ||
772 src_y + TILEY > src_bitmap->height)
774 Error(ERR_RETURN_LINE, "-");
775 Error(ERR_RETURN, "warning: error found in config file:");
776 Error(ERR_RETURN, "- config file: '%s'",
777 getImageConfigFilename());
778 Error(ERR_RETURN, "- config token: '%s'",
779 getTokenFromImageID(i));
780 Error(ERR_RETURN, "- image file: '%s'",
781 src_bitmap->source_filename);
783 "error: last animation frame (%d) out of bounds (%d, %d)",
784 last_frame, src_x, src_y);
785 Error(ERR_RETURN, "custom graphic rejected for this element/action");
787 if (i == fallback_graphic)
788 Error(ERR_EXIT, "fatal error: no fallback graphic available");
790 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
791 Error(ERR_RETURN_LINE, "-");
793 set_graphic_parameters(i, fallback_image->default_parameter);
794 graphic_info[i].bitmap = fallback_bitmap;
797 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
798 /* currently we need only a tile clip mask from the first frame */
799 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
801 if (copy_clipmask_gc == None)
803 clip_gc_values.graphics_exposures = False;
804 clip_gc_valuemask = GCGraphicsExposures;
805 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
806 clip_gc_valuemask, &clip_gc_values);
809 graphic_info[i].clip_mask =
810 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
812 src_pixmap = src_bitmap->clip_mask;
813 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
814 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
816 clip_gc_values.graphics_exposures = False;
817 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
818 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
820 graphic_info[i].clip_gc =
821 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
825 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
826 if (copy_clipmask_gc)
827 XFreeGC(display, copy_clipmask_gc);
829 clipmasks_initialized = TRUE;
833 static void InitElementSoundInfo()
835 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
836 int num_property_mappings = getSoundListPropertyMappingSize();
839 /* set values to -1 to identify later as "uninitialized" values */
840 for (i=0; i < MAX_NUM_ELEMENTS; i++)
841 for (act=0; act < NUM_ACTIONS; act++)
842 element_info[i].sound[act] = -1;
844 /* initialize element/sound mapping from static configuration */
845 for (i=0; element_to_sound[i].element > -1; i++)
847 int element = element_to_sound[i].element;
848 int action = element_to_sound[i].action;
849 int sound = element_to_sound[i].sound;
850 boolean is_class = element_to_sound[i].is_class;
853 action = ACTION_DEFAULT;
856 element_info[element].sound[action] = sound;
858 for (j=0; j < MAX_NUM_ELEMENTS; j++)
859 if (strcmp(element_info[j].class_name,
860 element_info[element].class_name) == 0)
861 element_info[j].sound[action] = sound;
864 /* initialize element/sound mapping from dynamic configuration */
865 for (i=0; i < num_property_mappings; i++)
867 int element = property_mapping[i].base_index;
868 int action = property_mapping[i].ext1_index;
869 int sound = property_mapping[i].artwork_index;
871 if (element >= MAX_NUM_ELEMENTS)
875 action = ACTION_DEFAULT;
877 element_info[element].sound[action] = sound;
880 /* initialize element class/sound mapping from dynamic configuration */
881 for (i=0; i < num_property_mappings; i++)
883 int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
884 int action = property_mapping[i].ext1_index;
885 int sound = property_mapping[i].artwork_index;
887 if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
891 action = ACTION_DEFAULT;
893 for (j=0; j < MAX_NUM_ELEMENTS; j++)
894 if (strcmp(element_info[j].class_name,
895 element_info[element_class].class_name) == 0)
896 element_info[j].sound[action] = sound;
899 /* now set all '-1' values to element specific default values */
900 for (i=0; i<MAX_NUM_ELEMENTS; i++)
902 int default_action_sound = element_info[i].sound[ACTION_DEFAULT];
904 for (act=0; act < NUM_ACTIONS; act++)
906 /* no sound for this specific action -- use default action sound */
907 if (element_info[i].sound[act] == -1)
908 element_info[i].sound[act] = default_action_sound;
913 static void set_sound_parameters(int sound, char **parameter_raw)
915 int parameter[NUM_SND_ARGS];
918 /* get integer values from string parameters */
919 for (i=0; i < NUM_SND_ARGS; i++)
921 get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
922 sound_config_suffix[i].type);
924 /* explicit loop mode setting in configuration overrides default value */
925 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
926 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
929 static void InitSoundInfo()
931 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
932 int num_property_mappings = getSoundListPropertyMappingSize();
933 int *sound_effect_properties;
934 int num_sounds = getSoundListSize();
937 if (sound_info != NULL)
940 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
941 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
943 /* initialize sound effect for all elements to "no sound" */
944 for (i=0; i<MAX_NUM_ELEMENTS; i++)
945 for (j=0; j<NUM_ACTIONS; j++)
946 element_info[i].sound[j] = SND_UNDEFINED;
948 for (i=0; i<num_sounds; i++)
950 struct FileInfo *sound = getSoundListEntry(i);
951 int len_effect_text = strlen(sound->token);
953 sound_effect_properties[i] = ACTION_OTHER;
954 sound_info[i].loop = FALSE;
956 /* determine all loop sounds and identify certain sound classes */
958 for (j=0; element_action_info[j].suffix; j++)
960 int len_action_text = strlen(element_action_info[j].suffix);
962 if (len_action_text < len_effect_text &&
963 strcmp(&sound->token[len_effect_text - len_action_text],
964 element_action_info[j].suffix) == 0)
966 sound_effect_properties[i] = element_action_info[j].value;
968 if (element_action_info[j].is_loop_sound)
969 sound_info[i].loop = TRUE;
973 /* associate elements and some selected sound actions */
975 for (j=0; j<MAX_NUM_ELEMENTS; j++)
977 if (element_info[j].class_name)
979 int len_class_text = strlen(element_info[j].class_name);
981 if (len_class_text + 1 < len_effect_text &&
982 strncmp(sound->token,
983 element_info[j].class_name, len_class_text) == 0 &&
984 sound->token[len_class_text] == '.')
986 int sound_action_value = sound_effect_properties[i];
988 element_info[j].sound[sound_action_value] = i;
993 set_sound_parameters(i, sound->parameter);
996 free(sound_effect_properties);
998 /* initialize element/sound mapping from dynamic configuration */
999 for (i=0; i < num_property_mappings; i++)
1001 int element = property_mapping[i].base_index;
1002 int action = property_mapping[i].ext1_index;
1003 int sound = property_mapping[i].artwork_index;
1006 action = ACTION_DEFAULT;
1008 element_info[element].sound[action] = sound;
1014 int element = EL_CUSTOM_11;
1017 while (element_action_info[j].suffix)
1019 printf("element %d, sound action '%s' == %d\n",
1020 element, element_action_info[j].suffix,
1021 element_info[element].sound[j]);
1026 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1032 int element = EL_SAND;
1033 int sound_action = ACTION_DIGGING;
1036 while (element_action_info[j].suffix)
1038 if (element_action_info[j].value == sound_action)
1039 printf("element %d, sound action '%s' == %d\n",
1040 element, element_action_info[j].suffix,
1041 element_info[element].sound[sound_action]);
1048 static void ReinitializeGraphics()
1050 InitGraphicInfo(); /* graphic properties mapping */
1051 InitElementGraphicInfo(); /* element game graphic mapping */
1052 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
1054 InitElementSmallImages(); /* create editor and preview images */
1055 InitFontGraphicInfo(); /* initialize text drawing functions */
1057 SetMainBackgroundImage(IMG_BACKGROUND);
1058 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1064 static void ReinitializeSounds()
1066 InitSoundInfo(); /* sound properties mapping */
1067 InitElementSoundInfo(); /* element game sound mapping */
1070 InitElementSoundInfo(); /* element game sound mapping */
1073 InitPlaySoundLevel(); /* internal game sound settings */
1076 static void ReinitializeMusic()
1078 /* currently nothing to do */
1081 void InitElementProperties()
1085 static int ep_amoebalive[] =
1094 static int ep_amoeboid[] =
1104 static int ep_can_be_crumbled[] =
1113 static int ep_pforte[] =
1132 EL_SWITCHGATE_OPENING,
1133 EL_SWITCHGATE_CLOSED,
1134 EL_SWITCHGATE_CLOSING,
1136 EL_TIMEGATE_OPENING,
1138 EL_TIMEGATE_CLOSING,
1142 EL_TUBE_VERTICAL_LEFT,
1143 EL_TUBE_VERTICAL_RIGHT,
1144 EL_TUBE_HORIZONTAL_UP,
1145 EL_TUBE_HORIZONTAL_DOWN,
1153 static int ep_solid[] =
1157 EL_EXPANDABLE_WALL_HORIZONTAL,
1158 EL_EXPANDABLE_WALL_VERTICAL,
1159 EL_EXPANDABLE_WALL_ANY,
1172 EL_QUICKSAND_FILLING,
1173 EL_QUICKSAND_EMPTYING,
1175 EL_MAGIC_WALL_ACTIVE,
1176 EL_MAGIC_WALL_EMPTYING,
1177 EL_MAGIC_WALL_FILLING,
1181 EL_BD_MAGIC_WALL_ACTIVE,
1182 EL_BD_MAGIC_WALL_EMPTYING,
1183 EL_BD_MAGIC_WALL_FULL,
1184 EL_BD_MAGIC_WALL_FILLING,
1185 EL_BD_MAGIC_WALL_DEAD,
1194 EL_SP_TERMINAL_ACTIVE,
1198 EL_INVISIBLE_WALL_ACTIVE,
1199 EL_SWITCHGATE_SWITCH_UP,
1200 EL_SWITCHGATE_SWITCH_DOWN,
1202 EL_TIMEGATE_SWITCH_ACTIVE,
1214 /* the following elements are a direct copy of "indestructible" elements,
1215 except "EL_ACID", which is "indestructible", but not "solid"! */
1220 EL_ACID_POOL_TOPLEFT,
1221 EL_ACID_POOL_TOPRIGHT,
1222 EL_ACID_POOL_BOTTOMLEFT,
1223 EL_ACID_POOL_BOTTOM,
1224 EL_ACID_POOL_BOTTOMRIGHT,
1225 EL_SP_HARDWARE_GRAY,
1226 EL_SP_HARDWARE_GREEN,
1227 EL_SP_HARDWARE_BLUE,
1229 EL_SP_HARDWARE_YELLOW,
1230 EL_SP_HARDWARE_BASE_1,
1231 EL_SP_HARDWARE_BASE_2,
1232 EL_SP_HARDWARE_BASE_3,
1233 EL_SP_HARDWARE_BASE_4,
1234 EL_SP_HARDWARE_BASE_5,
1235 EL_SP_HARDWARE_BASE_6,
1236 EL_INVISIBLE_STEELWALL,
1237 EL_INVISIBLE_STEELWALL_ACTIVE,
1238 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1239 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1240 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1241 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1242 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1243 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1244 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1245 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1246 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1247 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1248 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1249 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1251 EL_LIGHT_SWITCH_ACTIVE,
1252 EL_SIGN_EXCLAMATION,
1253 EL_SIGN_RADIOACTIVITY,
1264 EL_STEELWALL_SLANTED,
1287 EL_SWITCHGATE_OPENING,
1288 EL_SWITCHGATE_CLOSED,
1289 EL_SWITCHGATE_CLOSING,
1291 EL_TIMEGATE_OPENING,
1293 EL_TIMEGATE_CLOSING,
1297 EL_TUBE_VERTICAL_LEFT,
1298 EL_TUBE_VERTICAL_RIGHT,
1299 EL_TUBE_HORIZONTAL_UP,
1300 EL_TUBE_HORIZONTAL_DOWN,
1308 static int ep_indestructible[] =
1312 EL_ACID_POOL_TOPLEFT,
1313 EL_ACID_POOL_TOPRIGHT,
1314 EL_ACID_POOL_BOTTOMLEFT,
1315 EL_ACID_POOL_BOTTOM,
1316 EL_ACID_POOL_BOTTOMRIGHT,
1317 EL_SP_HARDWARE_GRAY,
1318 EL_SP_HARDWARE_GREEN,
1319 EL_SP_HARDWARE_BLUE,
1321 EL_SP_HARDWARE_YELLOW,
1322 EL_SP_HARDWARE_BASE_1,
1323 EL_SP_HARDWARE_BASE_2,
1324 EL_SP_HARDWARE_BASE_3,
1325 EL_SP_HARDWARE_BASE_4,
1326 EL_SP_HARDWARE_BASE_5,
1327 EL_SP_HARDWARE_BASE_6,
1328 EL_INVISIBLE_STEELWALL,
1329 EL_INVISIBLE_STEELWALL_ACTIVE,
1330 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1331 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1332 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1333 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1334 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1335 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1336 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1337 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1338 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1339 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1340 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1341 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1343 EL_LIGHT_SWITCH_ACTIVE,
1344 EL_SIGN_EXCLAMATION,
1345 EL_SIGN_RADIOACTIVITY,
1356 EL_STEELWALL_SLANTED,
1379 EL_SWITCHGATE_OPENING,
1380 EL_SWITCHGATE_CLOSED,
1381 EL_SWITCHGATE_CLOSING,
1383 EL_TIMEGATE_OPENING,
1385 EL_TIMEGATE_CLOSING,
1389 EL_TUBE_VERTICAL_LEFT,
1390 EL_TUBE_VERTICAL_RIGHT,
1391 EL_TUBE_HORIZONTAL_UP,
1392 EL_TUBE_HORIZONTAL_DOWN,
1400 static int ep_slippery[] =
1414 EL_ROBOT_WHEEL_ACTIVE,
1420 EL_ACID_POOL_TOPLEFT,
1421 EL_ACID_POOL_TOPRIGHT,
1431 EL_STEELWALL_SLANTED,
1437 static int ep_enemy[] =
1452 static int ep_mauer[] =
1477 EL_EXPANDABLE_WALL_HORIZONTAL,
1478 EL_EXPANDABLE_WALL_VERTICAL,
1479 EL_EXPANDABLE_WALL_ANY,
1480 EL_EXPANDABLE_WALL_GROWING,
1487 EL_SP_HARDWARE_GRAY,
1488 EL_SP_HARDWARE_GREEN,
1489 EL_SP_HARDWARE_BLUE,
1491 EL_SP_HARDWARE_YELLOW,
1492 EL_SP_HARDWARE_BASE_1,
1493 EL_SP_HARDWARE_BASE_2,
1494 EL_SP_HARDWARE_BASE_3,
1495 EL_SP_HARDWARE_BASE_4,
1496 EL_SP_HARDWARE_BASE_5,
1497 EL_SP_HARDWARE_BASE_6,
1499 EL_SP_TERMINAL_ACTIVE,
1502 EL_INVISIBLE_STEELWALL,
1503 EL_INVISIBLE_STEELWALL_ACTIVE,
1505 EL_INVISIBLE_WALL_ACTIVE,
1506 EL_STEELWALL_SLANTED,
1522 static int ep_can_fall[] =
1537 EL_BD_MAGIC_WALL_FULL,
1550 static int ep_can_smash[] =
1575 static int ep_can_change[] =
1588 static int ep_can_move[] =
1610 static int ep_could_move[] =
1620 EL_BD_BUTTERFLY_RIGHT,
1622 EL_BD_BUTTERFLY_LEFT,
1623 EL_BD_BUTTERFLY_DOWN,
1624 EL_BD_FIREFLY_RIGHT,
1635 static int ep_dont_touch[] =
1644 static int ep_dont_go_to[] =
1658 EL_SP_BUGGY_BASE_ACTIVE,
1664 static int ep_food_dark_yamyam[] =
1691 static int ep_bd_element[] =
1720 static int ep_sb_element[] =
1725 EL_SOKOBAN_FIELD_EMPTY,
1726 EL_SOKOBAN_FIELD_FULL,
1728 EL_INVISIBLE_STEELWALL,
1732 static int ep_gem[] =
1743 static int ep_inactive[] =
1780 EL_INVISIBLE_STEELWALL,
1788 EL_WALL_EMERALD_YELLOW,
1789 EL_DYNABOMB_INCREASE_NUMBER,
1790 EL_DYNABOMB_INCREASE_SIZE,
1791 EL_DYNABOMB_INCREASE_POWER,
1793 EL_SOKOBAN_FIELD_EMPTY,
1794 EL_SOKOBAN_FIELD_FULL,
1795 EL_WALL_EMERALD_RED,
1796 EL_WALL_EMERALD_PURPLE,
1797 EL_ACID_POOL_TOPLEFT,
1798 EL_ACID_POOL_TOPRIGHT,
1799 EL_ACID_POOL_BOTTOMLEFT,
1800 EL_ACID_POOL_BOTTOM,
1801 EL_ACID_POOL_BOTTOMRIGHT,
1805 EL_BD_MAGIC_WALL_DEAD,
1806 EL_AMOEBA_TO_DIAMOND,
1814 EL_SP_GRAVITY_PORT_RIGHT,
1815 EL_SP_GRAVITY_PORT_DOWN,
1816 EL_SP_GRAVITY_PORT_LEFT,
1817 EL_SP_GRAVITY_PORT_UP,
1818 EL_SP_PORT_HORIZONTAL,
1819 EL_SP_PORT_VERTICAL,
1828 EL_SP_HARDWARE_GRAY,
1829 EL_SP_HARDWARE_GREEN,
1830 EL_SP_HARDWARE_BLUE,
1832 EL_SP_HARDWARE_YELLOW,
1833 EL_SP_HARDWARE_BASE_1,
1834 EL_SP_HARDWARE_BASE_2,
1835 EL_SP_HARDWARE_BASE_3,
1836 EL_SP_HARDWARE_BASE_4,
1837 EL_SP_HARDWARE_BASE_5,
1838 EL_SP_HARDWARE_BASE_6,
1839 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
1840 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
1841 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
1842 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
1843 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
1844 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
1845 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
1846 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
1847 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
1848 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
1849 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
1850 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
1851 EL_SIGN_EXCLAMATION,
1852 EL_SIGN_RADIOACTIVITY,
1863 EL_STEELWALL_SLANTED,
1879 static int ep_explosive[] =
1884 EL_DYNABOMB_PLAYER_1_ACTIVE,
1885 EL_DYNABOMB_PLAYER_2_ACTIVE,
1886 EL_DYNABOMB_PLAYER_3_ACTIVE,
1887 EL_DYNABOMB_PLAYER_4_ACTIVE,
1888 EL_DYNABOMB_INCREASE_NUMBER,
1889 EL_DYNABOMB_INCREASE_SIZE,
1890 EL_DYNABOMB_INCREASE_POWER,
1891 EL_SP_DISK_RED_ACTIVE,
1907 static int ep_food_penguin[] =
1920 static int ep_pushable[] =
1927 EL_SOKOBAN_FIELD_FULL,
1939 static int ep_player[] =
1948 static int ep_walkable_over[] =
1952 EL_SOKOBAN_FIELD_EMPTY,
1956 /* !!! CHANGE THIS TO "EL_GATE_1_OPEN" etc. !!! */
1969 static int ep_walkable_inside[] =
1974 EL_TUBE_VERTICAL_LEFT,
1975 EL_TUBE_VERTICAL_RIGHT,
1976 EL_TUBE_HORIZONTAL_UP,
1977 EL_TUBE_HORIZONTAL_DOWN,
1985 static int ep_walkable_under[] =
1990 static int ep_passable_over[] =
2005 static int ep_passable_inside[] =
2011 EL_SP_PORT_HORIZONTAL,
2012 EL_SP_PORT_VERTICAL,
2014 EL_SP_GRAVITY_PORT_LEFT,
2015 EL_SP_GRAVITY_PORT_RIGHT,
2016 EL_SP_GRAVITY_PORT_UP,
2017 EL_SP_GRAVITY_PORT_DOWN,
2021 static int ep_passable_under[] =
2026 static int ep_diggable[] =
2031 EL_SP_BUGGY_BASE_ACTIVATING,
2034 EL_INVISIBLE_SAND_ACTIVE,
2037 EL_SP_BUGGY_BASE_ACTIVE,
2042 static int ep_collectible[] =
2059 EL_DYNABOMB_INCREASE_NUMBER,
2060 EL_DYNABOMB_INCREASE_SIZE,
2061 EL_DYNABOMB_INCREASE_POWER,
2075 static int ep_active_bomb[] =
2078 EL_DYNABOMB_PLAYER_1_ACTIVE,
2079 EL_DYNABOMB_PLAYER_2_ACTIVE,
2080 EL_DYNABOMB_PLAYER_3_ACTIVE,
2081 EL_DYNABOMB_PLAYER_4_ACTIVE,
2082 EL_SP_DISK_RED_ACTIVE,
2086 static int ep_belt[] =
2088 EL_CONVEYOR_BELT_1_LEFT,
2089 EL_CONVEYOR_BELT_1_MIDDLE,
2090 EL_CONVEYOR_BELT_1_RIGHT,
2091 EL_CONVEYOR_BELT_2_LEFT,
2092 EL_CONVEYOR_BELT_2_MIDDLE,
2093 EL_CONVEYOR_BELT_2_RIGHT,
2094 EL_CONVEYOR_BELT_3_LEFT,
2095 EL_CONVEYOR_BELT_3_MIDDLE,
2096 EL_CONVEYOR_BELT_3_RIGHT,
2097 EL_CONVEYOR_BELT_4_LEFT,
2098 EL_CONVEYOR_BELT_4_MIDDLE,
2099 EL_CONVEYOR_BELT_4_RIGHT,
2103 static int ep_belt_active[] =
2105 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
2106 EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
2107 EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
2108 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
2109 EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
2110 EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
2111 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
2112 EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
2113 EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
2114 EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
2115 EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
2116 EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
2120 static int ep_belt_switch[] =
2122 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2123 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2124 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2125 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2126 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2127 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2128 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2129 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2130 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2131 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2132 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2133 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2137 static int ep_sp_element[] =
2145 EL_SP_HARDWARE_GRAY,
2153 EL_SP_GRAVITY_PORT_RIGHT,
2154 EL_SP_GRAVITY_PORT_DOWN,
2155 EL_SP_GRAVITY_PORT_LEFT,
2156 EL_SP_GRAVITY_PORT_UP,
2161 EL_SP_PORT_VERTICAL,
2162 EL_SP_PORT_HORIZONTAL,
2168 EL_SP_HARDWARE_BASE_1,
2169 EL_SP_HARDWARE_GREEN,
2170 EL_SP_HARDWARE_BLUE,
2172 EL_SP_HARDWARE_YELLOW,
2173 EL_SP_HARDWARE_BASE_2,
2174 EL_SP_HARDWARE_BASE_3,
2175 EL_SP_HARDWARE_BASE_4,
2176 EL_SP_HARDWARE_BASE_5,
2177 EL_SP_HARDWARE_BASE_6,
2180 /* additional elements that appeared in newer Supaplex levels */
2182 /* more than one murphy in a level results in an inactive clone */
2187 static int ep_has_content[] =
2197 static int ep_tube[] =
2204 EL_TUBE_HORIZONTAL_UP,
2205 EL_TUBE_HORIZONTAL_DOWN,
2207 EL_TUBE_VERTICAL_LEFT,
2208 EL_TUBE_VERTICAL_RIGHT,
2217 } element_properties[] =
2219 { ep_amoebalive, EP_AMOEBALIVE },
2220 { ep_amoeboid, EP_AMOEBOID },
2221 { ep_can_be_crumbled, EP_CAN_BE_CRUMBLED },
2222 { ep_pforte, EP_PFORTE },
2223 { ep_solid, EP_SOLID },
2224 { ep_indestructible, EP_INDESTRUCTIBLE },
2225 { ep_slippery, EP_SLIPPERY },
2226 { ep_enemy, EP_ENEMY },
2227 { ep_mauer, EP_MAUER },
2228 { ep_can_fall, EP_CAN_FALL },
2229 { ep_can_smash, EP_CAN_SMASH },
2230 { ep_can_change, EP_CAN_CHANGE },
2231 { ep_can_move, EP_CAN_MOVE },
2232 { ep_could_move, EP_COULD_MOVE },
2233 { ep_dont_touch, EP_DONT_TOUCH },
2234 { ep_dont_go_to, EP_DONT_GO_TO },
2235 { ep_food_dark_yamyam, EP_FOOD_DARK_YAMYAM },
2236 { ep_bd_element, EP_BD_ELEMENT },
2237 { ep_sb_element, EP_SB_ELEMENT },
2239 { ep_inactive, EP_INACTIVE },
2240 { ep_explosive, EP_EXPLOSIVE },
2241 { ep_food_penguin, EP_FOOD_PENGUIN },
2242 { ep_pushable, EP_PUSHABLE },
2243 { ep_player, EP_PLAYER },
2244 { ep_walkable_over, EP_WALKABLE_OVER },
2245 { ep_walkable_inside, EP_WALKABLE_INSIDE },
2246 { ep_walkable_under, EP_WALKABLE_UNDER },
2247 { ep_passable_over, EP_PASSABLE_OVER },
2248 { ep_passable_inside, EP_PASSABLE_INSIDE },
2249 { ep_passable_under, EP_PASSABLE_UNDER },
2251 { ep_diggable, EP_DIGGABLE },
2252 { ep_collectible, EP_COLLECTIBLE },
2253 { ep_active_bomb, EP_ACTIVE_BOMB },
2254 { ep_belt, EP_BELT },
2255 { ep_belt_active, EP_BELT_ACTIVE },
2256 { ep_belt_switch, EP_BELT_SWITCH },
2257 { ep_sp_element, EP_SP_ELEMENT },
2258 { ep_has_content, EP_HAS_CONTENT },
2259 { ep_tube, EP_TUBE },
2264 static int active_properties[] =
2293 EP_EM_SLIPPERY_WALL,
2298 /* always start with reliable default values (no properties) */
2299 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2300 for (j=0; j<NUM_EP_BITFIELDS; j++)
2301 Properties[i][j] = EP_BITMASK_DEFAULT;
2303 /* set all predefined element properties from above arrays */
2304 for (i=0; element_properties[i].elements != NULL; i++)
2305 for (j=0; (element_properties[i].elements)[j] != -1; j++)
2306 SET_PROPERTY((element_properties[i].elements)[j],
2307 element_properties[i].property, TRUE);
2309 /* set properties of character elements */
2310 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2311 SET_PROPERTY(i, EP_INACTIVE, TRUE);
2313 /* set properties derived from other properties */
2314 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2316 if (IS_WALKABLE_OVER(i) || IS_WALKABLE_INSIDE(i) || IS_WALKABLE_UNDER(i))
2317 SET_PROPERTY(i, EP_WALKABLE, TRUE);
2319 if (IS_PASSABLE_OVER(i) || IS_PASSABLE_INSIDE(i) || IS_PASSABLE_UNDER(i))
2320 SET_PROPERTY(i, EP_PASSABLE, TRUE);
2322 if (IS_WALKABLE_OVER(i) || IS_PASSABLE_OVER(i))
2323 SET_PROPERTY(i, EP_ACCESSIBLE_OVER, TRUE);
2325 if (IS_WALKABLE_INSIDE(i) || IS_PASSABLE_INSIDE(i))
2326 SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, TRUE);
2328 if (IS_WALKABLE_UNDER(i) || IS_PASSABLE_UNDER(i))
2329 SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, TRUE);
2331 if (IS_WALKABLE(i) || IS_PASSABLE(i))
2332 SET_PROPERTY(i, EP_ACCESSIBLE, TRUE);
2336 /* determine inactive elements (used for engine main loop optimization) */
2337 for (i=0; i < MAX_NUM_ELEMENTS; i++)
2339 boolean active = FALSE;
2341 for (j=0; i < NUM_ELEMENT_PROPERTIES; j++)
2343 if (HAS_PROPERTY(i, j))
2349 SET_PROPERTY(i, EP_INACTIVE, TRUE);
2355 for (i=0; i < MAX_NUM_ELEMENTS; i++)
2357 boolean element_is_solid = TRUE;
2359 if (IS_DIGGABLE(i) ||
2360 IS_COLLECTIBLE(i) ||
2364 element_is_solid = FALSE;
2366 if (IS_INDESTRUCTIBLE(i))
2367 element_is_solid = TRUE;
2369 if (element_is_solid != HAS_PROPERTY(i, EP_SOLID))
2370 printf("::: '%s' should %s solid\n", element_info[i].token_name,
2371 (HAS_PROPERTY(i, EP_SOLID) ? "NOT be" : "be"));
2376 static void InitGlobal()
2378 global.autoplay_leveldir = NULL;
2380 global.frames_per_second = 0;
2381 global.fps_slowdown = FALSE;
2382 global.fps_slowdown_factor = 1;
2385 void Execute_Command(char *command)
2387 if (strcmp(command, "print graphicsinfo.conf") == 0)
2391 printf("# You can configure additional/alternative image files here.\n");
2392 printf("# (The images below are default and therefore commented out.)\n");
2394 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2396 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2399 for (i=0; image_config[i].token != NULL; i++)
2401 getFormattedSetupEntry(image_config[i].token,
2402 image_config[i].value));
2406 else if (strcmp(command, "print soundsinfo.conf") == 0)
2410 printf("# You can configure additional/alternative sound files here.\n");
2411 printf("# (The sounds below are default and therefore commented out.)\n");
2413 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2415 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2418 for (i=0; sound_config[i].token != NULL; i++)
2420 getFormattedSetupEntry(sound_config[i].token,
2421 sound_config[i].value));
2425 else if (strcmp(command, "print musicinfo.conf") == 0)
2427 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2429 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2431 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2435 else if (strncmp(command, "dump level ", 11) == 0)
2437 char *filename = &command[11];
2439 if (access(filename, F_OK) != 0)
2440 Error(ERR_EXIT, "cannot open file '%s'", filename);
2442 LoadLevelFromFilename(filename);
2447 else if (strncmp(command, "dump tape ", 10) == 0)
2449 char *filename = &command[10];
2451 if (access(filename, F_OK) != 0)
2452 Error(ERR_EXIT, "cannot open file '%s'", filename);
2454 LoadTapeFromFilename(filename);
2459 else if (strncmp(command, "autoplay ", 9) == 0)
2461 char *str_copy = getStringCopy(&command[9]);
2462 char *str_ptr = strchr(str_copy, ' ');
2464 global.autoplay_leveldir = str_copy;
2465 global.autoplay_level_nr = -1;
2467 if (str_ptr != NULL)
2469 *str_ptr++ = '\0'; /* terminate leveldir string */
2470 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2475 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2479 static void InitSetup()
2481 LoadSetup(); /* global setup info */
2483 /* set some options from setup file */
2485 if (setup.options.verbose)
2486 options.verbose = TRUE;
2489 static void InitPlayerInfo()
2493 /* choose default local player */
2494 local_player = &stored_player[0];
2496 for (i=0; i<MAX_PLAYERS; i++)
2497 stored_player[i].connected = FALSE;
2499 local_player->connected = TRUE;
2502 static void InitArtworkInfo()
2507 static char *get_element_class_token(int element)
2509 char *element_class_name = element_info[element].class_name;
2510 char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
2512 sprintf(element_class_token, "[%s]", element_class_name);
2514 return element_class_token;
2517 static void InitArtworkConfig()
2519 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
2520 static char *sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS + 1];
2521 static char *action_id_suffix[NUM_ACTIONS + 1];
2522 static char *direction_id_suffix[NUM_DIRECTIONS + 1];
2523 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
2524 static char *dummy[1] = { NULL };
2525 static char *ignore_image_tokens[] =
2530 "menu.draw_xoffset",
2531 "menu.draw_yoffset",
2532 "menu.draw_xoffset.MAIN",
2533 "menu.draw_yoffset.MAIN",
2538 static char *ignore_sound_tokens[] =
2546 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2547 image_id_prefix[i] = element_info[i].token_name;
2548 for (i=0; i<NUM_FONTS; i++)
2549 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
2550 image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
2552 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2553 sound_id_prefix[i] = element_info[i].token_name;
2554 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2555 sound_id_prefix[MAX_NUM_ELEMENTS + i] = get_element_class_token(i);
2556 sound_id_prefix[MAX_NUM_ELEMENTS + MAX_NUM_ELEMENTS] = NULL;
2558 for (i=0; i<NUM_ACTIONS; i++)
2559 action_id_suffix[i] = element_action_info[i].suffix;
2560 action_id_suffix[NUM_ACTIONS] = NULL;
2562 for (i=0; i<NUM_DIRECTIONS; i++)
2563 direction_id_suffix[i] = element_direction_info[i].suffix;
2564 direction_id_suffix[NUM_DIRECTIONS] = NULL;
2566 for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
2567 special_id_suffix[i] = special_suffix_info[i].suffix;
2568 special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
2570 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
2571 image_id_prefix, action_id_suffix, direction_id_suffix,
2572 special_id_suffix, ignore_image_tokens);
2573 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
2574 sound_id_prefix, action_id_suffix, dummy,
2575 special_id_suffix, ignore_sound_tokens);
2578 static void InitMixer()
2586 char *filename_font_initial = NULL;
2587 Bitmap *bitmap_font_initial = NULL;
2590 /* determine settings for initial font (for displaying startup messages) */
2591 for (i=0; image_config[i].token != NULL; i++)
2593 for (j=0; j < NUM_INITIAL_FONTS; j++)
2595 char font_token[128];
2598 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
2599 len_font_token = strlen(font_token);
2601 if (strcmp(image_config[i].token, font_token) == 0)
2602 filename_font_initial = image_config[i].value;
2603 else if (strlen(image_config[i].token) > len_font_token &&
2604 strncmp(image_config[i].token, font_token, len_font_token) == 0)
2606 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
2607 font_initial[j].src_x = atoi(image_config[i].value);
2608 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
2609 font_initial[j].src_y = atoi(image_config[i].value);
2610 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
2611 font_initial[j].width = atoi(image_config[i].value);
2612 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
2613 font_initial[j].height = atoi(image_config[i].value);
2618 for (j=0; j < NUM_INITIAL_FONTS; j++)
2620 font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
2621 font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
2624 if (filename_font_initial == NULL) /* should not happen */
2625 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
2627 /* create additional image buffers for double-buffering */
2628 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
2629 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
2631 /* initialize screen properties */
2632 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
2633 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
2635 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
2636 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
2637 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
2639 bitmap_font_initial = LoadCustomImage(filename_font_initial);
2641 for (j=0; j < NUM_INITIAL_FONTS; j++)
2642 font_initial[j].bitmap = bitmap_font_initial;
2644 InitFontGraphicInfo();
2646 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
2647 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
2649 DrawInitText("Loading graphics:", 120, FC_GREEN);
2651 InitTileClipmasks();
2654 void InitGfxBackground()
2658 drawto = backbuffer;
2659 fieldbuffer = bitmap_db_field;
2660 SetDrawtoField(DRAW_BACKBUFFER);
2662 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
2663 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
2664 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
2665 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
2667 for (x=0; x<MAX_BUF_XSIZE; x++)
2668 for (y=0; y<MAX_BUF_YSIZE; y++)
2671 redraw_mask = REDRAW_ALL;
2674 static void InitLevelInfo()
2676 LoadLevelInfo(); /* global level info */
2677 LoadLevelSetup_LastSeries(); /* last played series info */
2678 LoadLevelSetup_SeriesInfo(); /* last played level info */
2681 void InitLevelArtworkInfo()
2683 LoadLevelArtworkInfo();
2686 static void InitImages()
2688 ReloadCustomImages();
2690 LoadCustomElementDescriptions();
2691 LoadSpecialMenuDesignSettings();
2693 ReinitializeGraphics();
2696 static void InitSound()
2698 InitReloadCustomSounds(artwork.snd_current->identifier);
2699 ReinitializeSounds();
2702 static void InitMusic()
2704 InitReloadCustomMusic(artwork.mus_current->identifier);
2705 ReinitializeMusic();
2708 void InitNetworkServer()
2710 #if defined(PLATFORM_UNIX)
2714 if (!options.network)
2717 #if defined(PLATFORM_UNIX)
2718 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
2720 if (!ConnectToServer(options.server_host, options.server_port))
2721 Error(ERR_EXIT, "cannot connect to network game server");
2723 SendToServer_PlayerName(setup.player_name);
2724 SendToServer_ProtocolVersion();
2727 SendToServer_NrWanted(nr_wanted);
2731 void ReloadCustomArtwork()
2733 static char *leveldir_current_identifier = NULL;
2734 static boolean last_override_level_graphics = FALSE;
2735 static boolean last_override_level_sounds = FALSE;
2736 static boolean last_override_level_music = FALSE;
2737 /* identifier for new artwork; default: artwork configured in setup */
2738 char *gfx_new_identifier = artwork.gfx_current->identifier;
2739 char *snd_new_identifier = artwork.snd_current->identifier;
2740 char *mus_new_identifier = artwork.mus_current->identifier;
2741 boolean redraw_screen = FALSE;
2743 if (leveldir_current_identifier == NULL)
2744 leveldir_current_identifier = leveldir_current->identifier;
2747 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
2748 leveldir_current->graphics_set);
2749 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
2750 leveldir_current->identifier);
2754 printf("graphics --> '%s' ('%s')\n",
2755 artwork.gfx_current_identifier, artwork.gfx_current->filename);
2756 printf("sounds --> '%s' ('%s')\n",
2757 artwork.snd_current_identifier, artwork.snd_current->filename);
2758 printf("music --> '%s' ('%s')\n",
2759 artwork.mus_current_identifier, artwork.mus_current->filename);
2762 /* leveldir_current may be invalid (level group, parent link) */
2763 if (!validLevelSeries(leveldir_current))
2766 /* when a new level series was selected, check if there was a change
2767 in custom artwork stored in level series directory */
2768 if (leveldir_current_identifier != leveldir_current->identifier)
2770 char *identifier_old = leveldir_current_identifier;
2771 char *identifier_new = leveldir_current->identifier;
2773 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
2774 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
2775 gfx_new_identifier = identifier_new;
2776 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
2777 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
2778 snd_new_identifier = identifier_new;
2779 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
2780 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
2781 mus_new_identifier = identifier_new;
2783 leveldir_current_identifier = leveldir_current->identifier;
2786 /* custom level artwork configured in level series configuration file
2787 always overrides custom level artwork stored in level series directory
2788 and (level independant) custom artwork configured in setup menue */
2789 if (leveldir_current->graphics_set != NULL)
2790 gfx_new_identifier = leveldir_current->graphics_set;
2791 if (leveldir_current->sounds_set != NULL)
2792 snd_new_identifier = leveldir_current->sounds_set;
2793 if (leveldir_current->music_set != NULL)
2794 mus_new_identifier = leveldir_current->music_set;
2796 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
2797 last_override_level_graphics != setup.override_level_graphics)
2800 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
2801 artwork.gfx_current_identifier,
2802 artwork.gfx_current->identifier,
2803 gfx_new_identifier);
2806 setLevelArtworkDir(artwork.gfx_first);
2808 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
2812 FreeTileClipmasks();
2813 InitTileClipmasks();
2815 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
2816 last_override_level_graphics = setup.override_level_graphics;
2818 redraw_screen = TRUE;
2821 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
2822 last_override_level_sounds != setup.override_level_sounds)
2825 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
2826 artwork.snd_current_identifier,
2827 artwork.snd_current->identifier,
2828 snd_new_identifier);
2831 /* set artwork path to send it to the sound server process */
2832 setLevelArtworkDir(artwork.snd_first);
2834 InitReloadCustomSounds(snd_new_identifier);
2835 ReinitializeSounds();
2837 artwork.snd_current_identifier = artwork.snd_current->identifier;
2838 last_override_level_sounds = setup.override_level_sounds;
2840 redraw_screen = TRUE;
2843 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
2844 last_override_level_music != setup.override_level_music)
2846 /* set artwork path to send it to the sound server process */
2847 setLevelArtworkDir(artwork.mus_first);
2849 InitReloadCustomMusic(mus_new_identifier);
2850 ReinitializeMusic();
2852 artwork.mus_current_identifier = artwork.mus_current->identifier;
2853 last_override_level_music = setup.override_level_music;
2855 redraw_screen = TRUE;
2860 InitGfxBackground();
2862 /* force redraw of (open or closed) door graphics */
2863 SetDoorState(DOOR_OPEN_ALL);
2864 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
2869 /* ========================================================================= */
2871 /* ========================================================================= */
2875 InitGlobal(); /* initialize some global variables */
2877 if (options.execute_command)
2878 Execute_Command(options.execute_command);
2880 if (options.serveronly)
2882 #if defined(PLATFORM_UNIX)
2883 NetworkServer(options.server_port, options.serveronly);
2885 Error(ERR_WARN, "networking only supported in Unix version");
2887 exit(0); /* never reached */
2893 InitArtworkInfo(); /* needed before loading gfx, sound & music */
2894 InitArtworkConfig(); /* needed before forking sound child process */
2899 InitRND(NEW_RANDOMIZE);
2900 InitSimpleRND(NEW_RANDOMIZE);
2905 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
2908 InitEventFilter(FilterMouseMotionEvents);
2910 InitElementProperties();
2915 InitLevelArtworkInfo();
2917 InitImages(); /* needs to know current level directory */
2918 InitSound(); /* needs to know current level directory */
2919 InitMusic(); /* needs to know current level directory */
2921 InitGfxBackground();
2923 if (global.autoplay_leveldir)
2929 game_status = MAINMENU;
2933 InitNetworkServer();
2936 void CloseAllAndExit(int exit_value)
2941 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2944 FreeTileClipmasks();
2946 CloseVideoDisplay();
2947 ClosePlatformDependantStuff();