1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2006 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
29 #include "conf_e2g.c" /* include auto-generated data structure definitions */
30 #include "conf_esg.c" /* include auto-generated data structure definitions */
31 #include "conf_e2s.c" /* include auto-generated data structure definitions */
32 #include "conf_fnt.c" /* include auto-generated data structure definitions */
33 #include "conf_g2s.c" /* include auto-generated data structure definitions */
34 #include "conf_g2m.c" /* include auto-generated data structure definitions */
37 #define CONFIG_TOKEN_FONT_INITIAL "font.initial"
40 static struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
42 static int copy_properties[][5] =
46 EL_BUG_LEFT, EL_BUG_RIGHT,
47 EL_BUG_UP, EL_BUG_DOWN
51 EL_SPACESHIP_LEFT, EL_SPACESHIP_RIGHT,
52 EL_SPACESHIP_UP, EL_SPACESHIP_DOWN
56 EL_BD_BUTTERFLY_LEFT, EL_BD_BUTTERFLY_RIGHT,
57 EL_BD_BUTTERFLY_UP, EL_BD_BUTTERFLY_DOWN
61 EL_BD_FIREFLY_LEFT, EL_BD_FIREFLY_RIGHT,
62 EL_BD_FIREFLY_UP, EL_BD_FIREFLY_DOWN
66 EL_PACMAN_LEFT, EL_PACMAN_RIGHT,
67 EL_PACMAN_UP, EL_PACMAN_DOWN
71 EL_YAMYAM_LEFT, EL_YAMYAM_RIGHT,
72 EL_YAMYAM_UP, EL_YAMYAM_DOWN
76 EL_MOLE_LEFT, EL_MOLE_RIGHT,
77 EL_MOLE_UP, EL_MOLE_DOWN
87 FreeLevelEditorGadgets();
96 static boolean gadgets_initialized = FALSE;
98 if (gadgets_initialized)
101 CreateLevelEditorGadgets();
105 CreateScreenGadgets();
107 InitGadgetsSoundCallback(PlaySoundActivating, PlaySoundSelecting);
109 gadgets_initialized = TRUE;
112 inline void InitElementSmallImagesScaledUp(int graphic)
114 CreateImageWithSmallImages(graphic, graphic_info[graphic].scale_up_factor);
117 void InitElementSmallImages()
119 static int special_graphics[] =
121 IMG_EDITOR_ELEMENT_BORDER,
122 IMG_EDITOR_ELEMENT_BORDER_INPUT,
123 IMG_EDITOR_CASCADE_LIST,
124 IMG_EDITOR_CASCADE_LIST_ACTIVE,
127 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
128 int num_property_mappings = getImageListPropertyMappingSize();
131 /* initialize normal images from static configuration */
132 for (i = 0; element_to_graphic[i].element > -1; i++)
133 InitElementSmallImagesScaledUp(element_to_graphic[i].graphic);
135 /* initialize special images from static configuration */
136 for (i = 0; element_to_special_graphic[i].element > -1; i++)
137 InitElementSmallImagesScaledUp(element_to_special_graphic[i].graphic);
139 /* initialize images from dynamic configuration (may be elements or other) */
140 for (i = 0; i < num_property_mappings; i++)
141 InitElementSmallImagesScaledUp(property_mapping[i].artwork_index);
143 /* initialize special images from above list (non-element images) */
144 for (i = 0; special_graphics[i] > -1; i++)
145 InitElementSmallImagesScaledUp(special_graphics[i]);
148 void InitScaledImages()
152 /* scale normal images from static configuration, if not already scaled */
153 for (i = 0; i < NUM_IMAGE_FILES; i++)
154 ScaleImage(i, graphic_info[i].scale_up_factor);
158 /* !!! FIX THIS (CHANGE TO USING NORMAL ELEMENT GRAPHIC DEFINITIONS) !!! */
159 void SetBitmaps_EM(Bitmap **em_bitmap)
161 em_bitmap[0] = graphic_info[IMG_EMC_OBJECT].bitmap;
162 em_bitmap[1] = graphic_info[IMG_EMC_SPRITE].bitmap;
166 static int getFontBitmapID(int font_nr)
170 if (game_status >= GAME_MODE_TITLE && game_status <= GAME_MODE_PSEUDO_PREVIEW)
171 special = game_status;
172 else if (game_status == GAME_MODE_PSEUDO_TYPENAME)
173 special = GFX_SPECIAL_ARG_MAIN;
174 else if (game_status == GAME_MODE_PLAYING)
175 special = GFX_SPECIAL_ARG_DOOR;
178 return font_info[font_nr].special_bitmap_id[special];
183 void InitFontGraphicInfo()
185 static struct FontBitmapInfo *font_bitmap_info = NULL;
186 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
187 int num_property_mappings = getImageListPropertyMappingSize();
188 int num_font_bitmaps = NUM_FONTS;
191 if (graphic_info == NULL) /* still at startup phase */
193 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
198 /* ---------- initialize font graphic definitions ---------- */
200 /* always start with reliable default values (normal font graphics) */
201 for (i = 0; i < NUM_FONTS; i++)
202 font_info[i].graphic = IMG_FONT_INITIAL_1;
204 /* initialize normal font/graphic mapping from static configuration */
205 for (i = 0; font_to_graphic[i].font_nr > -1; i++)
207 int font_nr = font_to_graphic[i].font_nr;
208 int special = font_to_graphic[i].special;
209 int graphic = font_to_graphic[i].graphic;
214 font_info[font_nr].graphic = graphic;
217 /* always start with reliable default values (special font graphics) */
218 for (i = 0; i < NUM_FONTS; i++)
220 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
222 font_info[i].special_graphic[j] = font_info[i].graphic;
223 font_info[i].special_bitmap_id[j] = i;
227 /* initialize special font/graphic mapping from static configuration */
228 for (i = 0; font_to_graphic[i].font_nr > -1; i++)
230 int font_nr = font_to_graphic[i].font_nr;
231 int special = font_to_graphic[i].special;
232 int graphic = font_to_graphic[i].graphic;
233 int base_graphic = font2baseimg(font_nr);
235 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
237 boolean base_redefined =
238 getImageListEntryFromImageID(base_graphic)->redefined;
239 boolean special_redefined =
240 getImageListEntryFromImageID(graphic)->redefined;
242 /* if the base font ("font.title_1", for example) has been redefined,
243 but not the special font ("font.title_1.LEVELS", for example), do not
244 use an existing (in this case considered obsolete) special font
245 anymore, but use the automatically determined default font */
246 if (base_redefined && !special_redefined)
249 font_info[font_nr].special_graphic[special] = graphic;
250 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
255 /* initialize special font/graphic mapping from dynamic configuration */
256 for (i = 0; i < num_property_mappings; i++)
258 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
259 int special = property_mapping[i].ext3_index;
260 int graphic = property_mapping[i].artwork_index;
265 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
267 font_info[font_nr].special_graphic[special] = graphic;
268 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
273 /* reset non-redefined ".active" font graphics if normal font is redefined */
274 /* (this different treatment is needed because normal and active fonts are
275 independently defined ("active" is not a property of font definitions!) */
276 for (i = 0; i < NUM_FONTS; i++)
278 int font_nr_base = i;
279 int font_nr_active = FONT_ACTIVE(font_nr_base);
281 /* check only those fonts with exist as normal and ".active" variant */
282 if (font_nr_base != font_nr_active)
284 int base_graphic = font_info[font_nr_base].graphic;
285 int active_graphic = font_info[font_nr_active].graphic;
286 boolean base_redefined =
287 getImageListEntryFromImageID(base_graphic)->redefined;
288 boolean active_redefined =
289 getImageListEntryFromImageID(active_graphic)->redefined;
291 /* if the base font ("font.menu_1", for example) has been redefined,
292 but not the active font ("font.menu_1.active", for example), do not
293 use an existing (in this case considered obsolete) active font
294 anymore, but use the automatically determined default font */
295 if (base_redefined && !active_redefined)
296 font_info[font_nr_active].graphic = base_graphic;
298 /* now also check each "special" font (which may be the same as above) */
299 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
301 int base_graphic = font_info[font_nr_base].special_graphic[j];
302 int active_graphic = font_info[font_nr_active].special_graphic[j];
303 boolean base_redefined =
304 getImageListEntryFromImageID(base_graphic)->redefined;
305 boolean active_redefined =
306 getImageListEntryFromImageID(active_graphic)->redefined;
308 /* same as above, but check special graphic definitions, for example:
309 redefined "font.menu_1.MAIN" invalidates "font.menu_1.active.MAIN" */
310 if (base_redefined && !active_redefined)
312 font_info[font_nr_active].special_graphic[j] =
313 font_info[font_nr_base].special_graphic[j];
314 font_info[font_nr_active].special_bitmap_id[j] =
315 font_info[font_nr_base].special_bitmap_id[j];
321 /* ---------- initialize font bitmap array ---------- */
323 if (font_bitmap_info != NULL)
324 FreeFontInfo(font_bitmap_info);
327 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
329 /* ---------- initialize font bitmap definitions ---------- */
331 for (i = 0; i < NUM_FONTS; i++)
333 if (i < NUM_INITIAL_FONTS)
335 font_bitmap_info[i] = font_initial[i];
339 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
341 int font_bitmap_id = font_info[i].special_bitmap_id[j];
342 int graphic = font_info[i].special_graphic[j];
344 /* set 'graphic_info' for font entries, if uninitialized (guessed) */
345 if (graphic_info[graphic].anim_frames < MIN_NUM_CHARS_PER_FONT)
347 graphic_info[graphic].anim_frames = DEFAULT_NUM_CHARS_PER_FONT;
348 graphic_info[graphic].anim_frames_per_line = DEFAULT_NUM_CHARS_PER_LINE;
351 /* copy font relevant information from graphics information */
352 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
353 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
354 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
355 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
356 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
358 font_bitmap_info[font_bitmap_id].draw_xoffset =
359 graphic_info[graphic].draw_xoffset;
360 font_bitmap_info[font_bitmap_id].draw_yoffset =
361 graphic_info[graphic].draw_yoffset;
363 font_bitmap_info[font_bitmap_id].num_chars =
364 graphic_info[graphic].anim_frames;
365 font_bitmap_info[font_bitmap_id].num_chars_per_line =
366 graphic_info[graphic].anim_frames_per_line;
370 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
373 void InitElementGraphicInfo()
375 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
376 int num_property_mappings = getImageListPropertyMappingSize();
379 if (graphic_info == NULL) /* still at startup phase */
382 /* set values to -1 to identify later as "uninitialized" values */
383 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
385 for (act = 0; act < NUM_ACTIONS; act++)
387 element_info[i].graphic[act] = -1;
388 element_info[i].crumbled[act] = -1;
390 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
392 element_info[i].direction_graphic[act][dir] = -1;
393 element_info[i].direction_crumbled[act][dir] = -1;
398 /* initialize normal element/graphic mapping from static configuration */
399 for (i = 0; element_to_graphic[i].element > -1; i++)
401 int element = element_to_graphic[i].element;
402 int action = element_to_graphic[i].action;
403 int direction = element_to_graphic[i].direction;
404 boolean crumbled = element_to_graphic[i].crumbled;
405 int graphic = element_to_graphic[i].graphic;
406 int base_graphic = el2baseimg(element);
408 if (graphic_info[graphic].bitmap == NULL)
411 if ((action > -1 || direction > -1 || crumbled == TRUE) &&
414 boolean base_redefined =
415 getImageListEntryFromImageID(base_graphic)->redefined;
416 boolean act_dir_redefined =
417 getImageListEntryFromImageID(graphic)->redefined;
419 /* if the base graphic ("emerald", for example) has been redefined,
420 but not the action graphic ("emerald.falling", for example), do not
421 use an existing (in this case considered obsolete) action graphic
422 anymore, but use the automatically determined default graphic */
423 if (base_redefined && !act_dir_redefined)
428 action = ACTION_DEFAULT;
433 element_info[element].direction_crumbled[action][direction] = graphic;
435 element_info[element].crumbled[action] = graphic;
440 element_info[element].direction_graphic[action][direction] = graphic;
442 element_info[element].graphic[action] = graphic;
446 /* initialize normal element/graphic mapping from dynamic configuration */
447 for (i = 0; i < num_property_mappings; i++)
449 int element = property_mapping[i].base_index;
450 int action = property_mapping[i].ext1_index;
451 int direction = property_mapping[i].ext2_index;
452 int special = property_mapping[i].ext3_index;
453 int graphic = property_mapping[i].artwork_index;
454 boolean crumbled = FALSE;
456 if (special == GFX_SPECIAL_ARG_CRUMBLED)
462 if (graphic_info[graphic].bitmap == NULL)
465 if (element >= MAX_NUM_ELEMENTS || special != -1)
469 action = ACTION_DEFAULT;
474 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
475 element_info[element].direction_crumbled[action][dir] = -1;
478 element_info[element].direction_crumbled[action][direction] = graphic;
480 element_info[element].crumbled[action] = graphic;
485 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
486 element_info[element].direction_graphic[action][dir] = -1;
489 element_info[element].direction_graphic[action][direction] = graphic;
491 element_info[element].graphic[action] = graphic;
495 /* now copy all graphics that are defined to be cloned from other graphics */
496 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
498 int graphic = element_info[i].graphic[ACTION_DEFAULT];
499 int crumbled_like, diggable_like;
504 crumbled_like = graphic_info[graphic].crumbled_like;
505 diggable_like = graphic_info[graphic].diggable_like;
507 if (crumbled_like != -1 && element_info[i].crumbled[ACTION_DEFAULT] == -1)
509 for (act = 0; act < NUM_ACTIONS; act++)
510 element_info[i].crumbled[act] =
511 element_info[crumbled_like].crumbled[act];
512 for (act = 0; act < NUM_ACTIONS; act++)
513 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
514 element_info[i].direction_crumbled[act][dir] =
515 element_info[crumbled_like].direction_crumbled[act][dir];
518 if (diggable_like != -1 && element_info[i].graphic[ACTION_DIGGING] == -1)
520 element_info[i].graphic[ACTION_DIGGING] =
521 element_info[diggable_like].graphic[ACTION_DIGGING];
522 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
523 element_info[i].direction_graphic[ACTION_DIGGING][dir] =
524 element_info[diggable_like].direction_graphic[ACTION_DIGGING][dir];
529 /* set hardcoded definitions for some runtime elements without graphic */
530 element_info[EL_AMOEBA_TO_DIAMOND].graphic[ACTION_DEFAULT] = IMG_AMOEBA_DEAD;
534 /* set hardcoded definitions for some internal elements without graphic */
535 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
537 if (IS_EDITOR_CASCADE_INACTIVE(i))
538 element_info[i].graphic[ACTION_DEFAULT] = IMG_EDITOR_CASCADE_LIST;
539 else if (IS_EDITOR_CASCADE_ACTIVE(i))
540 element_info[i].graphic[ACTION_DEFAULT] = IMG_EDITOR_CASCADE_LIST_ACTIVE;
544 /* now set all undefined/invalid graphics to -1 to set to default after it */
545 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
547 for (act = 0; act < NUM_ACTIONS; act++)
551 graphic = element_info[i].graphic[act];
552 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
553 element_info[i].graphic[act] = -1;
555 graphic = element_info[i].crumbled[act];
556 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
557 element_info[i].crumbled[act] = -1;
559 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
561 graphic = element_info[i].direction_graphic[act][dir];
562 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
563 element_info[i].direction_graphic[act][dir] = -1;
565 graphic = element_info[i].direction_crumbled[act][dir];
566 if (graphic > 0 && graphic_info[graphic].bitmap == NULL)
567 element_info[i].direction_crumbled[act][dir] = -1;
572 /* adjust graphics with 2nd tile for movement according to direction
573 (do this before correcting '-1' values to minimize calculations) */
574 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
576 for (act = 0; act < NUM_ACTIONS; act++)
578 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
580 int graphic = element_info[i].direction_graphic[act][dir];
581 int move_dir = (act == ACTION_FALLING ? MV_BIT_DOWN : dir);
583 if (act == ACTION_FALLING) /* special case */
584 graphic = element_info[i].graphic[act];
587 graphic_info[graphic].double_movement &&
588 graphic_info[graphic].swap_double_tiles != 0)
590 struct GraphicInfo *g = &graphic_info[graphic];
591 int src_x_front = g->src_x;
592 int src_y_front = g->src_y;
593 int src_x_back = g->src_x + g->offset2_x;
594 int src_y_back = g->src_y + g->offset2_y;
595 boolean frames_are_ordered_diagonally = (g->offset_x != 0 &&
597 boolean front_is_left_or_upper = (src_x_front < src_x_back ||
598 src_y_front < src_y_back);
599 boolean swap_movement_tiles_always = (g->swap_double_tiles == 1);
600 boolean swap_movement_tiles_autodetected =
601 (!frames_are_ordered_diagonally &&
602 ((move_dir == MV_BIT_LEFT && !front_is_left_or_upper) ||
603 (move_dir == MV_BIT_UP && !front_is_left_or_upper) ||
604 (move_dir == MV_BIT_RIGHT && front_is_left_or_upper) ||
605 (move_dir == MV_BIT_DOWN && front_is_left_or_upper)));
608 /* swap frontside and backside graphic tile coordinates, if needed */
609 if (swap_movement_tiles_always || swap_movement_tiles_autodetected)
611 /* get current (wrong) backside tile coordinates */
612 getGraphicSourceExt(graphic, 0, &dummy, &src_x_back, &src_y_back,
615 /* set frontside tile coordinates to backside tile coordinates */
616 g->src_x = src_x_back;
617 g->src_y = src_y_back;
619 /* invert tile offset to point to new backside tile coordinates */
623 /* do not swap front and backside tiles again after correction */
624 g->swap_double_tiles = 0;
631 /* now set all '-1' values to element specific default values */
632 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
634 int default_graphic = element_info[i].graphic[ACTION_DEFAULT];
635 int default_crumbled = element_info[i].crumbled[ACTION_DEFAULT];
636 int default_direction_graphic[NUM_DIRECTIONS_FULL];
637 int default_direction_crumbled[NUM_DIRECTIONS_FULL];
639 if (default_graphic == -1)
640 default_graphic = IMG_UNKNOWN;
642 if (default_crumbled == -1)
643 default_crumbled = default_graphic;
645 /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */
646 if (default_crumbled == -1)
647 default_crumbled = IMG_EMPTY;
650 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
652 default_direction_graphic[dir] =
653 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
654 default_direction_crumbled[dir] =
655 element_info[i].direction_crumbled[ACTION_DEFAULT][dir];
657 if (default_direction_graphic[dir] == -1)
658 default_direction_graphic[dir] = default_graphic;
660 if (default_direction_crumbled[dir] == -1)
661 default_direction_crumbled[dir] = default_direction_graphic[dir];
663 /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */
664 if (default_direction_crumbled[dir] == -1)
665 default_direction_crumbled[dir] = default_crumbled;
669 for (act = 0; act < NUM_ACTIONS; act++)
671 boolean act_remove = ((IS_DIGGABLE(i) && act == ACTION_DIGGING) ||
672 (IS_SNAPPABLE(i) && act == ACTION_SNAPPING) ||
673 (IS_COLLECTIBLE(i) && act == ACTION_COLLECTING));
674 boolean act_turning = (act == ACTION_TURNING_FROM_LEFT ||
675 act == ACTION_TURNING_FROM_RIGHT ||
676 act == ACTION_TURNING_FROM_UP ||
677 act == ACTION_TURNING_FROM_DOWN);
679 /* generic default action graphic (defined by "[default]" directive) */
680 int default_action_graphic = element_info[EL_DEFAULT].graphic[act];
681 int default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
682 int default_remove_graphic = IMG_EMPTY;
684 if (act_remove && default_action_graphic != -1)
685 default_remove_graphic = default_action_graphic;
687 /* look for special default action graphic (classic game specific) */
688 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].graphic[act] != -1)
689 default_action_graphic = element_info[EL_BD_DEFAULT].graphic[act];
690 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].graphic[act] != -1)
691 default_action_graphic = element_info[EL_SP_DEFAULT].graphic[act];
692 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].graphic[act] != -1)
693 default_action_graphic = element_info[EL_SB_DEFAULT].graphic[act];
695 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].crumbled[act] != -1)
696 default_action_crumbled = element_info[EL_BD_DEFAULT].crumbled[act];
697 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].crumbled[act] != -1)
698 default_action_crumbled = element_info[EL_SP_DEFAULT].crumbled[act];
699 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].crumbled[act] != -1)
700 default_action_crumbled = element_info[EL_SB_DEFAULT].crumbled[act];
703 /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */
704 /* !!! make this better !!! */
705 if (i == EL_EMPTY_SPACE)
707 default_action_graphic = element_info[EL_DEFAULT].graphic[act];
708 default_action_crumbled = element_info[EL_DEFAULT].crumbled[act];
712 if (default_action_graphic == -1)
713 default_action_graphic = default_graphic;
715 if (default_action_crumbled == -1)
716 default_action_crumbled = default_action_graphic;
718 /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */
719 if (default_action_crumbled == -1)
720 default_action_crumbled = default_crumbled;
723 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
725 /* use action graphic as the default direction graphic, if undefined */
726 int default_action_direction_graphic = element_info[i].graphic[act];
727 int default_action_direction_crumbled = element_info[i].crumbled[act];
729 /* no graphic for current action -- use default direction graphic */
730 if (default_action_direction_graphic == -1)
731 default_action_direction_graphic =
732 (act_remove ? default_remove_graphic :
734 element_info[i].direction_graphic[ACTION_TURNING][dir] :
735 default_action_graphic != default_graphic ?
736 default_action_graphic :
737 default_direction_graphic[dir]);
739 if (element_info[i].direction_graphic[act][dir] == -1)
740 element_info[i].direction_graphic[act][dir] =
741 default_action_direction_graphic;
744 if (default_action_direction_crumbled == -1)
745 default_action_direction_crumbled =
746 element_info[i].direction_graphic[act][dir];
748 if (default_action_direction_crumbled == -1)
749 default_action_direction_crumbled =
750 (act_remove ? default_remove_graphic :
752 element_info[i].direction_crumbled[ACTION_TURNING][dir] :
753 default_action_crumbled != default_crumbled ?
754 default_action_crumbled :
755 default_direction_crumbled[dir]);
758 if (element_info[i].direction_crumbled[act][dir] == -1)
759 element_info[i].direction_crumbled[act][dir] =
760 default_action_direction_crumbled;
763 /* no graphic for this specific action -- use default action graphic */
764 if (element_info[i].graphic[act] == -1)
765 element_info[i].graphic[act] =
766 (act_remove ? default_remove_graphic :
767 act_turning ? element_info[i].graphic[ACTION_TURNING] :
768 default_action_graphic);
770 if (element_info[i].crumbled[act] == -1)
771 element_info[i].crumbled[act] = element_info[i].graphic[act];
773 if (element_info[i].crumbled[act] == -1)
774 element_info[i].crumbled[act] =
775 (act_remove ? default_remove_graphic :
776 act_turning ? element_info[i].crumbled[ACTION_TURNING] :
777 default_action_crumbled);
783 /* !!! THIS ALSO CLEARS SPECIAL FLAGS (AND IS NOT NEEDED ANYWAY) !!! */
784 /* set animation mode to "none" for each graphic with only 1 frame */
785 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
787 for (act = 0; act < NUM_ACTIONS; act++)
789 int graphic = element_info[i].graphic[act];
790 int crumbled = element_info[i].crumbled[act];
792 if (graphic_info[graphic].anim_frames == 1)
793 graphic_info[graphic].anim_mode = ANIM_NONE;
794 if (graphic_info[crumbled].anim_frames == 1)
795 graphic_info[crumbled].anim_mode = ANIM_NONE;
797 for (dir = 0; dir < NUM_DIRECTIONS_FULL; dir++)
799 graphic = element_info[i].direction_graphic[act][dir];
800 crumbled = element_info[i].direction_crumbled[act][dir];
802 if (graphic_info[graphic].anim_frames == 1)
803 graphic_info[graphic].anim_mode = ANIM_NONE;
804 if (graphic_info[crumbled].anim_frames == 1)
805 graphic_info[crumbled].anim_mode = ANIM_NONE;
815 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
816 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_UNKNOWN &&
818 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
819 element_info[i].token_name, i);
825 void InitElementSpecialGraphicInfo()
827 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
828 int num_property_mappings = getImageListPropertyMappingSize();
831 /* always start with reliable default values */
832 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
833 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
834 element_info[i].special_graphic[j] =
835 element_info[i].graphic[ACTION_DEFAULT];
837 /* initialize special element/graphic mapping from static configuration */
838 for (i = 0; element_to_special_graphic[i].element > -1; i++)
840 int element = element_to_special_graphic[i].element;
841 int special = element_to_special_graphic[i].special;
842 int graphic = element_to_special_graphic[i].graphic;
843 int base_graphic = el2baseimg(element);
844 boolean base_redefined =
845 getImageListEntryFromImageID(base_graphic)->redefined;
846 boolean special_redefined =
847 getImageListEntryFromImageID(graphic)->redefined;
849 /* if the base graphic ("emerald", for example) has been redefined,
850 but not the special graphic ("emerald.EDITOR", for example), do not
851 use an existing (in this case considered obsolete) special graphic
852 anymore, but use the automatically created (down-scaled) graphic */
853 if (base_redefined && !special_redefined)
856 element_info[element].special_graphic[special] = graphic;
859 /* initialize special element/graphic mapping from dynamic configuration */
860 for (i = 0; i < num_property_mappings; i++)
862 int element = property_mapping[i].base_index;
863 int special = property_mapping[i].ext3_index;
864 int graphic = property_mapping[i].artwork_index;
866 if (element >= MAX_NUM_ELEMENTS)
869 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
870 element_info[element].special_graphic[special] = graphic;
873 /* now set all undefined/invalid graphics to default */
874 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
875 for (j = 0; j < NUM_SPECIAL_GFX_ARGS; j++)
876 if (graphic_info[element_info[i].special_graphic[j]].bitmap == NULL)
877 element_info[i].special_graphic[j] =
878 element_info[i].graphic[ACTION_DEFAULT];
881 static int get_graphic_parameter_value(char *value_raw, char *suffix, int type)
886 if (type != TYPE_TOKEN)
887 return get_parameter_value(value_raw, suffix, type);
889 if (strEqual(value_raw, ARG_UNDEFINED))
890 return ARG_UNDEFINED_VALUE;
892 /* !!! OPTIMIZE THIS BY USING HASH !!! */
893 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
894 if (strEqual(element_info[i].token_name, value_raw))
897 /* !!! OPTIMIZE THIS BY USING HASH !!! */
898 for (i = 0; image_config[i].token != NULL; i++)
900 int len_config_value = strlen(image_config[i].value);
902 if (!strEqual(&image_config[i].value[len_config_value - 4], ".pcx") &&
903 !strEqual(&image_config[i].value[len_config_value - 4], ".wav") &&
904 !strEqual(image_config[i].value, UNDEFINED_FILENAME))
907 if (strEqual(image_config[i].token, value_raw))
916 static int get_scaled_graphic_width(int graphic)
918 int original_width = getOriginalImageWidthFromImageID(graphic);
919 int scale_up_factor = graphic_info[graphic].scale_up_factor;
921 return original_width * scale_up_factor;
924 static int get_scaled_graphic_height(int graphic)
926 int original_height = getOriginalImageHeightFromImageID(graphic);
927 int scale_up_factor = graphic_info[graphic].scale_up_factor;
929 return original_height * scale_up_factor;
932 static void set_graphic_parameters(int graphic)
934 struct FileInfo *image = getImageListEntryFromImageID(graphic);
935 char **parameter_raw = image->parameter;
936 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
937 int parameter[NUM_GFX_ARGS];
938 int anim_frames_per_row = 1, anim_frames_per_col = 1;
939 int anim_frames_per_line = 1;
942 /* if fallback to default artwork is done, also use the default parameters */
943 if (image->fallback_to_default)
944 parameter_raw = image->default_parameter;
946 /* get integer values from string parameters */
947 for (i = 0; i < NUM_GFX_ARGS; i++)
948 parameter[i] = get_graphic_parameter_value(parameter_raw[i],
949 image_config_suffix[i].token,
950 image_config_suffix[i].type);
952 graphic_info[graphic].bitmap = src_bitmap;
954 /* always start with reliable default values */
955 graphic_info[graphic].src_image_width = 0;
956 graphic_info[graphic].src_image_height = 0;
957 graphic_info[graphic].src_x = 0;
958 graphic_info[graphic].src_y = 0;
959 graphic_info[graphic].width = TILEX; /* default for element graphics */
960 graphic_info[graphic].height = TILEY; /* default for element graphics */
961 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
962 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
963 graphic_info[graphic].offset2_x = 0; /* one or both of these values ... */
964 graphic_info[graphic].offset2_y = 0; /* ... will be corrected later */
965 graphic_info[graphic].swap_double_tiles = -1; /* auto-detect tile swapping */
966 graphic_info[graphic].crumbled_like = -1; /* do not use clone element */
967 graphic_info[graphic].diggable_like = -1; /* do not use clone element */
968 graphic_info[graphic].border_size = TILEX / 8; /* "CRUMBLED" border size */
969 graphic_info[graphic].scale_up_factor = 1; /* default: no scaling up */
970 graphic_info[graphic].clone_from = -1; /* do not use clone graphic */
971 graphic_info[graphic].anim_delay_fixed = 0;
972 graphic_info[graphic].anim_delay_random = 0;
973 graphic_info[graphic].post_delay_fixed = 0;
974 graphic_info[graphic].post_delay_random = 0;
975 graphic_info[graphic].fade_delay = -1;
976 graphic_info[graphic].post_delay = -1;
977 graphic_info[graphic].auto_delay = -1;
980 /* optional zoom factor for scaling up the image to a larger size */
981 if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE)
982 graphic_info[graphic].scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR];
983 if (graphic_info[graphic].scale_up_factor < 1)
984 graphic_info[graphic].scale_up_factor = 1; /* no scaling */
988 if (graphic_info[graphic].use_image_size)
990 /* set new default bitmap size (with scaling, but without small images) */
991 graphic_info[graphic].width = get_scaled_graphic_width(graphic);
992 graphic_info[graphic].height = get_scaled_graphic_height(graphic);
996 /* optional x and y tile position of animation frame sequence */
997 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
998 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
999 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
1000 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
1002 /* optional x and y pixel position of animation frame sequence */
1003 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
1004 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
1005 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
1006 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
1008 /* optional width and height of each animation frame */
1009 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
1010 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
1011 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
1012 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
1015 /* optional zoom factor for scaling up the image to a larger size */
1016 if (parameter[GFX_ARG_SCALE_UP_FACTOR] != ARG_UNDEFINED_VALUE)
1017 graphic_info[graphic].scale_up_factor = parameter[GFX_ARG_SCALE_UP_FACTOR];
1018 if (graphic_info[graphic].scale_up_factor < 1)
1019 graphic_info[graphic].scale_up_factor = 1; /* no scaling */
1024 /* get final bitmap size (with scaling, but without small images) */
1025 int src_image_width = get_scaled_graphic_width(graphic);
1026 int src_image_height = get_scaled_graphic_height(graphic);
1028 anim_frames_per_row = src_image_width / graphic_info[graphic].width;
1029 anim_frames_per_col = src_image_height / graphic_info[graphic].height;
1031 graphic_info[graphic].src_image_width = src_image_width;
1032 graphic_info[graphic].src_image_height = src_image_height;
1035 /* correct x or y offset dependent of vertical or horizontal frame order */
1036 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
1038 graphic_info[graphic].offset_y =
1039 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
1040 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].height);
1041 anim_frames_per_line = anim_frames_per_col;
1043 else /* frames are ordered horizontally */
1045 graphic_info[graphic].offset_x =
1046 (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE ?
1047 parameter[GFX_ARG_OFFSET] : graphic_info[graphic].width);
1048 anim_frames_per_line = anim_frames_per_row;
1051 /* optionally, the x and y offset of frames can be specified directly */
1052 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
1053 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
1054 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
1055 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
1057 /* optionally, moving animations may have separate start and end graphics */
1058 graphic_info[graphic].double_movement = parameter[GFX_ARG_2ND_MOVEMENT_TILE];
1060 if (parameter[GFX_ARG_2ND_VERTICAL] == ARG_UNDEFINED_VALUE)
1061 parameter[GFX_ARG_2ND_VERTICAL] = !parameter[GFX_ARG_VERTICAL];
1063 /* correct x or y offset2 dependent of vertical or horizontal frame order */
1064 if (parameter[GFX_ARG_2ND_VERTICAL]) /* frames are ordered vertically */
1065 graphic_info[graphic].offset2_y =
1066 (parameter[GFX_ARG_2ND_OFFSET] != ARG_UNDEFINED_VALUE ?
1067 parameter[GFX_ARG_2ND_OFFSET] : graphic_info[graphic].height);
1068 else /* frames are ordered horizontally */
1069 graphic_info[graphic].offset2_x =
1070 (parameter[GFX_ARG_2ND_OFFSET] != ARG_UNDEFINED_VALUE ?
1071 parameter[GFX_ARG_2ND_OFFSET] : graphic_info[graphic].width);
1073 /* optionally, the x and y offset of 2nd graphic can be specified directly */
1074 if (parameter[GFX_ARG_2ND_XOFFSET] != ARG_UNDEFINED_VALUE)
1075 graphic_info[graphic].offset2_x = parameter[GFX_ARG_2ND_XOFFSET];
1076 if (parameter[GFX_ARG_2ND_YOFFSET] != ARG_UNDEFINED_VALUE)
1077 graphic_info[graphic].offset2_y = parameter[GFX_ARG_2ND_YOFFSET];
1079 /* optionally, the second movement tile can be specified as start tile */
1080 if (parameter[GFX_ARG_2ND_SWAP_TILES] != ARG_UNDEFINED_VALUE)
1081 graphic_info[graphic].swap_double_tiles= parameter[GFX_ARG_2ND_SWAP_TILES];
1083 /* automatically determine correct number of frames, if not defined */
1084 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
1085 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
1086 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
1087 graphic_info[graphic].anim_frames = anim_frames_per_row;
1088 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
1089 graphic_info[graphic].anim_frames = anim_frames_per_col;
1091 graphic_info[graphic].anim_frames = 1;
1093 if (graphic_info[graphic].anim_frames == 0) /* frames must be at least 1 */
1094 graphic_info[graphic].anim_frames = 1;
1096 graphic_info[graphic].anim_frames_per_line =
1097 (parameter[GFX_ARG_FRAMES_PER_LINE] != ARG_UNDEFINED_VALUE ?
1098 parameter[GFX_ARG_FRAMES_PER_LINE] : anim_frames_per_line);
1100 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
1101 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
1102 graphic_info[graphic].anim_delay = 1;
1104 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
1106 if (graphic_info[graphic].anim_frames == 1)
1107 graphic_info[graphic].anim_mode = ANIM_NONE;
1110 /* automatically determine correct start frame, if not defined */
1111 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
1112 graphic_info[graphic].anim_start_frame = 0;
1113 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
1114 graphic_info[graphic].anim_start_frame =
1115 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
1117 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
1119 /* animation synchronized with global frame counter, not move position */
1120 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
1122 /* optional element for cloning crumble graphics */
1123 if (parameter[GFX_ARG_CRUMBLED_LIKE] != ARG_UNDEFINED_VALUE)
1124 graphic_info[graphic].crumbled_like = parameter[GFX_ARG_CRUMBLED_LIKE];
1126 /* optional element for cloning digging graphics */
1127 if (parameter[GFX_ARG_DIGGABLE_LIKE] != ARG_UNDEFINED_VALUE)
1128 graphic_info[graphic].diggable_like = parameter[GFX_ARG_DIGGABLE_LIKE];
1130 /* optional border size for "crumbling" diggable graphics */
1131 if (parameter[GFX_ARG_BORDER_SIZE] != ARG_UNDEFINED_VALUE)
1132 graphic_info[graphic].border_size = parameter[GFX_ARG_BORDER_SIZE];
1134 /* this is only used for player "boring" and "sleeping" actions */
1135 if (parameter[GFX_ARG_ANIM_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
1136 graphic_info[graphic].anim_delay_fixed =
1137 parameter[GFX_ARG_ANIM_DELAY_FIXED];
1138 if (parameter[GFX_ARG_ANIM_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
1139 graphic_info[graphic].anim_delay_random =
1140 parameter[GFX_ARG_ANIM_DELAY_RANDOM];
1141 if (parameter[GFX_ARG_POST_DELAY_FIXED] != ARG_UNDEFINED_VALUE)
1142 graphic_info[graphic].post_delay_fixed =
1143 parameter[GFX_ARG_POST_DELAY_FIXED];
1144 if (parameter[GFX_ARG_POST_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
1145 graphic_info[graphic].post_delay_random =
1146 parameter[GFX_ARG_POST_DELAY_RANDOM];
1148 /* this is only used for toon animations */
1149 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
1150 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
1152 /* this is only used for drawing font characters */
1153 graphic_info[graphic].draw_xoffset = parameter[GFX_ARG_DRAW_XOFFSET];
1154 graphic_info[graphic].draw_yoffset = parameter[GFX_ARG_DRAW_YOFFSET];
1156 /* this is only used for drawing envelope graphics */
1157 graphic_info[graphic].draw_masked = parameter[GFX_ARG_DRAW_MASKED];
1159 /* optional graphic for cloning all graphics settings */
1160 if (parameter[GFX_ARG_CLONE_FROM] != ARG_UNDEFINED_VALUE)
1161 graphic_info[graphic].clone_from = parameter[GFX_ARG_CLONE_FROM];
1163 /* optional settings for drawing title screens */
1164 if (parameter[GFX_ARG_FADE_DELAY] != ARG_UNDEFINED_VALUE)
1165 graphic_info[graphic].fade_delay = parameter[GFX_ARG_FADE_DELAY];
1166 if (parameter[GFX_ARG_POST_DELAY] != ARG_UNDEFINED_VALUE)
1167 graphic_info[graphic].post_delay = parameter[GFX_ARG_POST_DELAY];
1168 if (parameter[GFX_ARG_AUTO_DELAY] != ARG_UNDEFINED_VALUE)
1169 graphic_info[graphic].auto_delay = parameter[GFX_ARG_AUTO_DELAY];
1172 static void set_cloned_graphic_parameters(int graphic)
1174 int fallback_graphic = IMG_CHAR_EXCLAM;
1175 int max_num_images = getImageListSize();
1176 int clone_graphic = graphic_info[graphic].clone_from;
1177 int num_references_followed = 1;
1179 while (graphic_info[clone_graphic].clone_from != -1 &&
1180 num_references_followed < max_num_images)
1182 clone_graphic = graphic_info[clone_graphic].clone_from;
1184 num_references_followed++;
1187 if (num_references_followed >= max_num_images)
1189 Error(ERR_RETURN_LINE, "-");
1190 Error(ERR_RETURN, "warning: error found in config file:");
1191 Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
1192 Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(graphic));
1193 Error(ERR_RETURN, "error: loop discovered when resolving cloned graphics");
1194 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1196 if (graphic == fallback_graphic)
1197 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1199 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1200 Error(ERR_RETURN_LINE, "-");
1202 graphic_info[graphic] = graphic_info[fallback_graphic];
1206 graphic_info[graphic] = graphic_info[clone_graphic];
1207 graphic_info[graphic].clone_from = clone_graphic;
1211 static void InitGraphicInfo()
1213 int fallback_graphic = IMG_CHAR_EXCLAM;
1214 int num_images = getImageListSize();
1217 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1218 static boolean clipmasks_initialized = FALSE;
1220 XGCValues clip_gc_values;
1221 unsigned long clip_gc_valuemask;
1222 GC copy_clipmask_gc = None;
1225 /* use image size as default values for width and height for these images */
1226 static int full_size_graphics[] =
1231 IMG_BACKGROUND_ENVELOPE_1,
1232 IMG_BACKGROUND_ENVELOPE_2,
1233 IMG_BACKGROUND_ENVELOPE_3,
1234 IMG_BACKGROUND_ENVELOPE_4,
1237 IMG_BACKGROUND_TITLE,
1238 IMG_BACKGROUND_MESSAGE,
1239 IMG_BACKGROUND_MAIN,
1240 IMG_BACKGROUND_LEVELS,
1241 IMG_BACKGROUND_SCORES,
1242 IMG_BACKGROUND_EDITOR,
1243 IMG_BACKGROUND_INFO,
1244 IMG_BACKGROUND_INFO_ELEMENTS,
1245 IMG_BACKGROUND_INFO_MUSIC,
1246 IMG_BACKGROUND_INFO_CREDITS,
1247 IMG_BACKGROUND_INFO_PROGRAM,
1248 IMG_BACKGROUND_INFO_LEVELSET,
1249 IMG_BACKGROUND_SETUP,
1250 IMG_BACKGROUND_DOOR,
1252 IMG_TITLESCREEN_INITIAL_1,
1253 IMG_TITLESCREEN_INITIAL_2,
1254 IMG_TITLESCREEN_INITIAL_3,
1255 IMG_TITLESCREEN_INITIAL_4,
1256 IMG_TITLESCREEN_INITIAL_5,
1266 checked_free(graphic_info);
1268 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
1271 /* initialize "use_image_size" flag with default value */
1272 for (i = 0; i < num_images; i++)
1273 graphic_info[i].use_image_size = FALSE;
1275 /* initialize "use_image_size" flag from static configuration above */
1276 for (i = 0; full_size_graphics[i] != -1; i++)
1277 graphic_info[full_size_graphics[i]].use_image_size = TRUE;
1280 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1281 if (clipmasks_initialized)
1283 for (i = 0; i < num_images; i++)
1285 if (graphic_info[i].clip_mask)
1286 XFreePixmap(display, graphic_info[i].clip_mask);
1287 if (graphic_info[i].clip_gc)
1288 XFreeGC(display, graphic_info[i].clip_gc);
1290 graphic_info[i].clip_mask = None;
1291 graphic_info[i].clip_gc = None;
1296 /* first set all graphic paramaters ... */
1297 for (i = 0; i < num_images; i++)
1298 set_graphic_parameters(i);
1300 /* ... then copy these parameters for cloned graphics */
1301 for (i = 0; i < num_images; i++)
1302 if (graphic_info[i].clone_from != -1)
1303 set_cloned_graphic_parameters(i);
1305 for (i = 0; i < num_images; i++)
1310 int first_frame, last_frame;
1311 int src_bitmap_width, src_bitmap_height;
1313 /* now check if no animation frames are outside of the loaded image */
1315 if (graphic_info[i].bitmap == NULL)
1316 continue; /* skip check for optional images that are undefined */
1318 /* get image size (this can differ from the standard element tile size!) */
1319 width = graphic_info[i].width;
1320 height = graphic_info[i].height;
1322 /* get final bitmap size (with scaling, but without small images) */
1323 src_bitmap_width = graphic_info[i].src_image_width;
1324 src_bitmap_height = graphic_info[i].src_image_height;
1326 /* check if first animation frame is inside specified bitmap */
1329 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1332 /* this avoids calculating wrong start position for out-of-bounds frame */
1333 src_x = graphic_info[i].src_x;
1334 src_y = graphic_info[i].src_y;
1337 if (src_x < 0 || src_y < 0 ||
1338 src_x + width > src_bitmap_width ||
1339 src_y + height > src_bitmap_height)
1341 Error(ERR_RETURN_LINE, "-");
1342 Error(ERR_RETURN, "warning: error found in config file:");
1343 Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
1344 Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(i));
1345 Error(ERR_RETURN, "- image file: '%s'", src_bitmap->source_filename);
1347 "error: first animation frame out of bounds (%d, %d) [%d, %d]",
1348 src_x, src_y, src_bitmap_width, src_bitmap_height);
1349 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1351 if (i == fallback_graphic)
1352 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1354 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1355 Error(ERR_RETURN_LINE, "-");
1357 graphic_info[i] = graphic_info[fallback_graphic];
1360 /* check if last animation frame is inside specified bitmap */
1362 last_frame = graphic_info[i].anim_frames - 1;
1363 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1365 if (src_x < 0 || src_y < 0 ||
1366 src_x + width > src_bitmap_width ||
1367 src_y + height > src_bitmap_height)
1369 Error(ERR_RETURN_LINE, "-");
1370 Error(ERR_RETURN, "warning: error found in config file:");
1371 Error(ERR_RETURN, "- config file: '%s'", getImageConfigFilename());
1372 Error(ERR_RETURN, "- config token: '%s'", getTokenFromImageID(i));
1373 Error(ERR_RETURN, "- image file: '%s'", src_bitmap->source_filename);
1375 "error: last animation frame (%d) out of bounds (%d, %d) [%d, %d]",
1376 last_frame, src_x, src_y, src_bitmap_width, src_bitmap_height);
1377 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1379 if (i == fallback_graphic)
1380 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1382 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1383 Error(ERR_RETURN_LINE, "-");
1385 graphic_info[i] = graphic_info[fallback_graphic];
1388 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1389 /* currently we only need a tile clip mask from the first frame */
1390 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1392 if (copy_clipmask_gc == None)
1394 clip_gc_values.graphics_exposures = False;
1395 clip_gc_valuemask = GCGraphicsExposures;
1396 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1397 clip_gc_valuemask, &clip_gc_values);
1400 graphic_info[i].clip_mask =
1401 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1403 src_pixmap = src_bitmap->clip_mask;
1404 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1405 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1407 clip_gc_values.graphics_exposures = False;
1408 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1409 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1411 graphic_info[i].clip_gc =
1412 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1416 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1417 if (copy_clipmask_gc)
1418 XFreeGC(display, copy_clipmask_gc);
1420 clipmasks_initialized = TRUE;
1424 static void InitElementSoundInfo()
1426 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1427 int num_property_mappings = getSoundListPropertyMappingSize();
1430 /* set values to -1 to identify later as "uninitialized" values */
1431 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1432 for (act = 0; act < NUM_ACTIONS; act++)
1433 element_info[i].sound[act] = -1;
1435 /* initialize element/sound mapping from static configuration */
1436 for (i = 0; element_to_sound[i].element > -1; i++)
1438 int element = element_to_sound[i].element;
1439 int action = element_to_sound[i].action;
1440 int sound = element_to_sound[i].sound;
1441 boolean is_class = element_to_sound[i].is_class;
1444 action = ACTION_DEFAULT;
1447 element_info[element].sound[action] = sound;
1449 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1450 if (strEqual(element_info[j].class_name,
1451 element_info[element].class_name))
1452 element_info[j].sound[action] = sound;
1455 /* initialize element class/sound mapping from dynamic configuration */
1456 for (i = 0; i < num_property_mappings; i++)
1458 int element_class = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
1459 int action = property_mapping[i].ext1_index;
1460 int sound = property_mapping[i].artwork_index;
1462 if (element_class < 0 || element_class >= MAX_NUM_ELEMENTS)
1466 action = ACTION_DEFAULT;
1468 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1469 if (strEqual(element_info[j].class_name,
1470 element_info[element_class].class_name))
1471 element_info[j].sound[action] = sound;
1474 /* initialize element/sound mapping from dynamic configuration */
1475 for (i = 0; i < num_property_mappings; i++)
1477 int element = property_mapping[i].base_index;
1478 int action = property_mapping[i].ext1_index;
1479 int sound = property_mapping[i].artwork_index;
1481 if (element >= MAX_NUM_ELEMENTS)
1485 action = ACTION_DEFAULT;
1487 element_info[element].sound[action] = sound;
1490 /* now set all '-1' values to element specific default values */
1491 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1493 for (act = 0; act < NUM_ACTIONS; act++)
1495 /* generic default action sound (defined by "[default]" directive) */
1496 int default_action_sound = element_info[EL_DEFAULT].sound[act];
1498 /* look for special default action sound (classic game specific) */
1499 if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].sound[act] != -1)
1500 default_action_sound = element_info[EL_BD_DEFAULT].sound[act];
1501 if (IS_SP_ELEMENT(i) && element_info[EL_SP_DEFAULT].sound[act] != -1)
1502 default_action_sound = element_info[EL_SP_DEFAULT].sound[act];
1503 if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].sound[act] != -1)
1504 default_action_sound = element_info[EL_SB_DEFAULT].sound[act];
1506 /* !!! there's no such thing as a "default action sound" !!! */
1508 /* look for element specific default sound (independent from action) */
1509 if (element_info[i].sound[ACTION_DEFAULT] != -1)
1510 default_action_sound = element_info[i].sound[ACTION_DEFAULT];
1514 /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */
1515 /* !!! make this better !!! */
1516 if (i == EL_EMPTY_SPACE)
1517 default_action_sound = element_info[EL_DEFAULT].sound[act];
1520 /* no sound for this specific action -- use default action sound */
1521 if (element_info[i].sound[act] == -1)
1522 element_info[i].sound[act] = default_action_sound;
1526 /* copy sound settings to some elements that are only stored in level file
1527 in native R'n'D levels, but are used by game engine in native EM levels */
1528 for (i = 0; copy_properties[i][0] != -1; i++)
1529 for (j = 1; j <= 4; j++)
1530 for (act = 0; act < NUM_ACTIONS; act++)
1531 element_info[copy_properties[i][j]].sound[act] =
1532 element_info[copy_properties[i][0]].sound[act];
1535 static void InitGameModeSoundInfo()
1539 /* set values to -1 to identify later as "uninitialized" values */
1540 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1543 /* initialize gamemode/sound mapping from static configuration */
1544 for (i = 0; gamemode_to_sound[i].sound > -1; i++)
1546 int gamemode = gamemode_to_sound[i].gamemode;
1547 int sound = gamemode_to_sound[i].sound;
1550 gamemode = GAME_MODE_DEFAULT;
1552 menu.sound[gamemode] = sound;
1555 /* now set all '-1' values to levelset specific default values */
1556 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1557 if (menu.sound[i] == -1)
1558 menu.sound[i] = menu.sound[GAME_MODE_DEFAULT];
1561 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1562 if (menu.sound[i] != -1)
1563 printf("::: menu.sound[%d] == %d\n", i, menu.sound[i]);
1567 static void set_sound_parameters(int sound, char **parameter_raw)
1569 int parameter[NUM_SND_ARGS];
1572 /* get integer values from string parameters */
1573 for (i = 0; i < NUM_SND_ARGS; i++)
1575 get_parameter_value(parameter_raw[i],
1576 sound_config_suffix[i].token,
1577 sound_config_suffix[i].type);
1579 /* explicit loop mode setting in configuration overrides default value */
1580 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1581 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1583 /* sound volume to change the original volume when loading the sound file */
1584 sound_info[sound].volume = parameter[SND_ARG_VOLUME];
1586 /* sound priority to give certain sounds a higher or lower priority */
1587 sound_info[sound].volume = parameter[SND_ARG_VOLUME];
1590 static void InitSoundInfo()
1592 int *sound_effect_properties;
1593 int num_sounds = getSoundListSize();
1596 checked_free(sound_info);
1598 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1599 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1601 /* initialize sound effect for all elements to "no sound" */
1602 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
1603 for (j = 0; j < NUM_ACTIONS; j++)
1604 element_info[i].sound[j] = SND_UNDEFINED;
1606 for (i = 0; i < num_sounds; i++)
1608 struct FileInfo *sound = getSoundListEntry(i);
1609 int len_effect_text = strlen(sound->token);
1611 sound_effect_properties[i] = ACTION_OTHER;
1612 sound_info[i].loop = FALSE; /* default: play sound only once */
1615 printf("::: sound %d: '%s'\n", i, sound->token);
1618 /* determine all loop sounds and identify certain sound classes */
1620 for (j = 0; element_action_info[j].suffix; j++)
1622 int len_action_text = strlen(element_action_info[j].suffix);
1624 if (len_action_text < len_effect_text &&
1625 strEqual(&sound->token[len_effect_text - len_action_text],
1626 element_action_info[j].suffix))
1628 sound_effect_properties[i] = element_action_info[j].value;
1629 sound_info[i].loop = element_action_info[j].is_loop_sound;
1635 /* associate elements and some selected sound actions */
1637 for (j = 0; j < MAX_NUM_ELEMENTS; j++)
1639 if (element_info[j].class_name)
1641 int len_class_text = strlen(element_info[j].class_name);
1643 if (len_class_text + 1 < len_effect_text &&
1644 strncmp(sound->token,
1645 element_info[j].class_name, len_class_text) == 0 &&
1646 sound->token[len_class_text] == '.')
1648 int sound_action_value = sound_effect_properties[i];
1650 element_info[j].sound[sound_action_value] = i;
1655 set_sound_parameters(i, sound->parameter);
1658 free(sound_effect_properties);
1661 static void InitGameModeMusicInfo()
1663 struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
1664 int num_property_mappings = getMusicListPropertyMappingSize();
1665 int default_levelset_music = -1;
1668 /* set values to -1 to identify later as "uninitialized" values */
1669 for (i = 0; i < MAX_LEVELS; i++)
1670 levelset.music[i] = -1;
1671 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1674 /* initialize gamemode/music mapping from static configuration */
1675 for (i = 0; gamemode_to_music[i].music > -1; i++)
1677 int gamemode = gamemode_to_music[i].gamemode;
1678 int music = gamemode_to_music[i].music;
1681 printf("::: gamemode == %d, music == %d\n", gamemode, music);
1685 gamemode = GAME_MODE_DEFAULT;
1687 menu.music[gamemode] = music;
1690 /* initialize gamemode/music mapping from dynamic configuration */
1691 for (i = 0; i < num_property_mappings; i++)
1693 int prefix = property_mapping[i].base_index;
1694 int gamemode = property_mapping[i].ext1_index;
1695 int level = property_mapping[i].ext2_index;
1696 int music = property_mapping[i].artwork_index;
1699 printf("::: prefix == %d, gamemode == %d, level == %d, music == %d\n",
1700 prefix, gamemode, level, music);
1703 if (prefix < 0 || prefix >= NUM_MUSIC_PREFIXES)
1707 gamemode = GAME_MODE_DEFAULT;
1709 /* level specific music only allowed for in-game music */
1710 if (level != -1 && gamemode == GAME_MODE_DEFAULT)
1711 gamemode = GAME_MODE_PLAYING;
1716 default_levelset_music = music;
1719 if (gamemode == GAME_MODE_PLAYING || gamemode == GAME_MODE_DEFAULT)
1720 levelset.music[level] = music;
1721 if (gamemode != GAME_MODE_PLAYING)
1722 menu.music[gamemode] = music;
1725 /* now set all '-1' values to menu specific default values */
1726 /* (undefined values of "levelset.music[]" might stay at "-1" to
1727 allow dynamic selection of music files from music directory!) */
1728 for (i = 0; i < MAX_LEVELS; i++)
1729 if (levelset.music[i] == -1)
1730 levelset.music[i] = default_levelset_music;
1731 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1732 if (menu.music[i] == -1)
1733 menu.music[i] = menu.music[GAME_MODE_DEFAULT];
1736 for (i = 0; i < MAX_LEVELS; i++)
1737 if (levelset.music[i] != -1)
1738 printf("::: levelset.music[%d] == %d\n", i, levelset.music[i]);
1739 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
1740 if (menu.music[i] != -1)
1741 printf("::: menu.music[%d] == %d\n", i, menu.music[i]);
1745 static void set_music_parameters(int music, char **parameter_raw)
1747 int parameter[NUM_MUS_ARGS];
1750 /* get integer values from string parameters */
1751 for (i = 0; i < NUM_MUS_ARGS; i++)
1753 get_parameter_value(parameter_raw[i],
1754 music_config_suffix[i].token,
1755 music_config_suffix[i].type);
1757 /* explicit loop mode setting in configuration overrides default value */
1758 if (parameter[MUS_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1759 music_info[music].loop = parameter[MUS_ARG_MODE_LOOP];
1762 static void InitMusicInfo()
1764 int num_music = getMusicListSize();
1767 checked_free(music_info);
1769 music_info = checked_calloc(num_music * sizeof(struct MusicInfo));
1771 for (i = 0; i < num_music; i++)
1773 struct FileInfo *music = getMusicListEntry(i);
1774 int len_music_text = strlen(music->token);
1776 music_info[i].loop = TRUE; /* default: play music in loop mode */
1778 /* determine all loop music */
1780 for (j = 0; music_prefix_info[j].prefix; j++)
1782 int len_prefix_text = strlen(music_prefix_info[j].prefix);
1784 if (len_prefix_text < len_music_text &&
1785 strncmp(music->token,
1786 music_prefix_info[j].prefix, len_prefix_text) == 0)
1788 music_info[i].loop = music_prefix_info[j].is_loop_music;
1794 set_music_parameters(i, music->parameter);
1798 static void ReinitializeGraphics()
1800 InitGraphicInfo(); /* graphic properties mapping */
1801 InitElementGraphicInfo(); /* element game graphic mapping */
1802 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
1804 InitElementSmallImages(); /* scale elements to all needed sizes */
1805 InitScaledImages(); /* scale all other images, if needed */
1806 InitFontGraphicInfo(); /* initialize text drawing functions */
1808 InitGraphicInfo_EM(); /* graphic mapping for EM engine */
1810 SetMainBackgroundImage(IMG_BACKGROUND);
1811 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
1817 static void ReinitializeSounds()
1819 InitSoundInfo(); /* sound properties mapping */
1820 InitElementSoundInfo(); /* element game sound mapping */
1821 InitGameModeSoundInfo(); /* game mode sound mapping */
1823 InitPlayLevelSound(); /* internal game sound settings */
1826 static void ReinitializeMusic()
1828 InitMusicInfo(); /* music properties mapping */
1829 InitGameModeMusicInfo(); /* game mode music mapping */
1832 static int get_special_property_bit(int element, int property_bit_nr)
1834 struct PropertyBitInfo
1840 static struct PropertyBitInfo pb_can_move_into_acid[] =
1842 /* the player may be able fall into acid when gravity is activated */
1847 { EL_SP_MURPHY, 0 },
1848 { EL_SOKOBAN_FIELD_PLAYER, 0 },
1850 /* all elements that can move may be able to also move into acid */
1853 { EL_BUG_RIGHT, 1 },
1856 { EL_SPACESHIP, 2 },
1857 { EL_SPACESHIP_LEFT, 2 },
1858 { EL_SPACESHIP_RIGHT, 2 },
1859 { EL_SPACESHIP_UP, 2 },
1860 { EL_SPACESHIP_DOWN, 2 },
1861 { EL_BD_BUTTERFLY, 3 },
1862 { EL_BD_BUTTERFLY_LEFT, 3 },
1863 { EL_BD_BUTTERFLY_RIGHT, 3 },
1864 { EL_BD_BUTTERFLY_UP, 3 },
1865 { EL_BD_BUTTERFLY_DOWN, 3 },
1866 { EL_BD_FIREFLY, 4 },
1867 { EL_BD_FIREFLY_LEFT, 4 },
1868 { EL_BD_FIREFLY_RIGHT, 4 },
1869 { EL_BD_FIREFLY_UP, 4 },
1870 { EL_BD_FIREFLY_DOWN, 4 },
1872 { EL_YAMYAM_LEFT, 5 },
1873 { EL_YAMYAM_RIGHT, 5 },
1874 { EL_YAMYAM_UP, 5 },
1875 { EL_YAMYAM_DOWN, 5 },
1876 { EL_DARK_YAMYAM, 6 },
1879 { EL_PACMAN_LEFT, 8 },
1880 { EL_PACMAN_RIGHT, 8 },
1881 { EL_PACMAN_UP, 8 },
1882 { EL_PACMAN_DOWN, 8 },
1884 { EL_MOLE_LEFT, 9 },
1885 { EL_MOLE_RIGHT, 9 },
1887 { EL_MOLE_DOWN, 9 },
1891 { EL_SATELLITE, 13 },
1892 { EL_SP_SNIKSNAK, 14 },
1893 { EL_SP_ELECTRON, 15 },
1896 { EL_EMC_ANDROID, 18 },
1901 static struct PropertyBitInfo pb_dont_collide_with[] =
1903 { EL_SP_SNIKSNAK, 0 },
1904 { EL_SP_ELECTRON, 1 },
1912 struct PropertyBitInfo *pb_info;
1915 { EP_CAN_MOVE_INTO_ACID, pb_can_move_into_acid },
1916 { EP_DONT_COLLIDE_WITH, pb_dont_collide_with },
1921 struct PropertyBitInfo *pb_info = NULL;
1924 for (i = 0; pb_definition[i].bit_nr != -1; i++)
1925 if (pb_definition[i].bit_nr == property_bit_nr)
1926 pb_info = pb_definition[i].pb_info;
1928 if (pb_info == NULL)
1931 for (i = 0; pb_info[i].element != -1; i++)
1932 if (pb_info[i].element == element)
1933 return pb_info[i].bit_nr;
1938 void setBitfieldProperty(int *bitfield, int property_bit_nr, int element,
1939 boolean property_value)
1941 int bit_nr = get_special_property_bit(element, property_bit_nr);
1946 *bitfield |= (1 << bit_nr);
1948 *bitfield &= ~(1 << bit_nr);
1952 boolean getBitfieldProperty(int *bitfield, int property_bit_nr, int element)
1954 int bit_nr = get_special_property_bit(element, property_bit_nr);
1957 return ((*bitfield & (1 << bit_nr)) != 0);
1962 static void resolve_group_element(int group_element, int recursion_depth)
1964 static int group_nr;
1965 static struct ElementGroupInfo *group;
1966 struct ElementGroupInfo *actual_group = element_info[group_element].group;
1969 if (actual_group == NULL) /* not yet initialized */
1972 if (recursion_depth > NUM_GROUP_ELEMENTS) /* recursion too deep */
1974 Error(ERR_WARN, "recursion too deep when resolving group element %d",
1975 group_element - EL_GROUP_START + 1);
1977 /* replace element which caused too deep recursion by question mark */
1978 group->element_resolved[group->num_elements_resolved++] = EL_UNKNOWN;
1983 if (recursion_depth == 0) /* initialization */
1985 group = actual_group;
1986 group_nr = group_element - EL_GROUP_START;
1988 group->num_elements_resolved = 0;
1989 group->choice_pos = 0;
1992 for (i = 0; i < actual_group->num_elements; i++)
1994 int element = actual_group->element[i];
1996 if (group->num_elements_resolved == NUM_FILE_ELEMENTS)
1999 if (IS_GROUP_ELEMENT(element))
2000 resolve_group_element(element, recursion_depth + 1);
2003 group->element_resolved[group->num_elements_resolved++] = element;
2004 element_info[element].in_group[group_nr] = TRUE;
2009 void InitElementPropertiesStatic()
2011 static int ep_diggable[] =
2016 EL_SP_BUGGY_BASE_ACTIVATING,
2019 EL_INVISIBLE_SAND_ACTIVE,
2022 /* !!! currently not diggable, but handled by 'ep_dont_run_into' !!! */
2023 /* (if amoeba can grow into anything diggable, maybe keep these out) */
2028 EL_SP_BUGGY_BASE_ACTIVE,
2035 static int ep_collectible_only[] =
2057 EL_DYNABOMB_INCREASE_NUMBER,
2058 EL_DYNABOMB_INCREASE_SIZE,
2059 EL_DYNABOMB_INCREASE_POWER,
2077 /* !!! handle separately !!! */
2078 EL_DC_LANDMINE, /* deadly when running into, but can be snapped */
2084 static int ep_dont_run_into[] =
2086 /* same elements as in 'ep_dont_touch' */
2092 /* same elements as in 'ep_dont_collide_with' */
2104 /* !!! maybe this should better be handled by 'ep_diggable' !!! */
2109 EL_SP_BUGGY_BASE_ACTIVE,
2116 static int ep_dont_collide_with[] =
2118 /* same elements as in 'ep_dont_touch' */
2135 static int ep_dont_touch[] =
2145 static int ep_indestructible[] =
2149 EL_ACID_POOL_TOPLEFT,
2150 EL_ACID_POOL_TOPRIGHT,
2151 EL_ACID_POOL_BOTTOMLEFT,
2152 EL_ACID_POOL_BOTTOM,
2153 EL_ACID_POOL_BOTTOMRIGHT,
2154 EL_SP_HARDWARE_GRAY,
2155 EL_SP_HARDWARE_GREEN,
2156 EL_SP_HARDWARE_BLUE,
2158 EL_SP_HARDWARE_YELLOW,
2159 EL_SP_HARDWARE_BASE_1,
2160 EL_SP_HARDWARE_BASE_2,
2161 EL_SP_HARDWARE_BASE_3,
2162 EL_SP_HARDWARE_BASE_4,
2163 EL_SP_HARDWARE_BASE_5,
2164 EL_SP_HARDWARE_BASE_6,
2165 EL_INVISIBLE_STEELWALL,
2166 EL_INVISIBLE_STEELWALL_ACTIVE,
2167 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2168 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2169 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2170 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2171 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2172 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2173 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2174 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2175 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2176 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2177 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2178 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2180 EL_LIGHT_SWITCH_ACTIVE,
2181 EL_SIGN_EXCLAMATION,
2182 EL_SIGN_RADIOACTIVITY,
2189 EL_SIGN_ENTRY_FORBIDDEN,
2190 EL_SIGN_EMERGENCY_EXIT,
2198 EL_STEEL_EXIT_CLOSED,
2200 EL_DC_STEELWALL_1_LEFT,
2201 EL_DC_STEELWALL_1_RIGHT,
2202 EL_DC_STEELWALL_1_TOP,
2203 EL_DC_STEELWALL_1_BOTTOM,
2204 EL_DC_STEELWALL_1_HORIZONTAL,
2205 EL_DC_STEELWALL_1_VERTICAL,
2206 EL_DC_STEELWALL_1_TOPLEFT,
2207 EL_DC_STEELWALL_1_TOPRIGHT,
2208 EL_DC_STEELWALL_1_BOTTOMLEFT,
2209 EL_DC_STEELWALL_1_BOTTOMRIGHT,
2210 EL_DC_STEELWALL_1_TOPLEFT_2,
2211 EL_DC_STEELWALL_1_TOPRIGHT_2,
2212 EL_DC_STEELWALL_1_BOTTOMLEFT_2,
2213 EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
2214 EL_DC_STEELWALL_2_LEFT,
2215 EL_DC_STEELWALL_2_RIGHT,
2216 EL_DC_STEELWALL_2_TOP,
2217 EL_DC_STEELWALL_2_BOTTOM,
2218 EL_DC_STEELWALL_2_HORIZONTAL,
2219 EL_DC_STEELWALL_2_VERTICAL,
2220 EL_DC_STEELWALL_2_MIDDLE,
2221 EL_DC_STEELWALL_2_SINGLE,
2222 EL_STEELWALL_SLIPPERY,
2236 EL_GATE_1_GRAY_ACTIVE,
2237 EL_GATE_2_GRAY_ACTIVE,
2238 EL_GATE_3_GRAY_ACTIVE,
2239 EL_GATE_4_GRAY_ACTIVE,
2248 EL_EM_GATE_1_GRAY_ACTIVE,
2249 EL_EM_GATE_2_GRAY_ACTIVE,
2250 EL_EM_GATE_3_GRAY_ACTIVE,
2251 EL_EM_GATE_4_GRAY_ACTIVE,
2260 EL_EMC_GATE_5_GRAY_ACTIVE,
2261 EL_EMC_GATE_6_GRAY_ACTIVE,
2262 EL_EMC_GATE_7_GRAY_ACTIVE,
2263 EL_EMC_GATE_8_GRAY_ACTIVE,
2265 EL_SWITCHGATE_OPENING,
2266 EL_SWITCHGATE_CLOSED,
2267 EL_SWITCHGATE_CLOSING,
2269 EL_DC_SWITCHGATE_SWITCH_UP,
2270 EL_DC_SWITCHGATE_SWITCH_DOWN,
2273 EL_TIMEGATE_OPENING,
2275 EL_TIMEGATE_CLOSING,
2277 EL_DC_TIMEGATE_SWITCH,
2278 EL_DC_TIMEGATE_SWITCH_ACTIVE,
2283 EL_TUBE_VERTICAL_LEFT,
2284 EL_TUBE_VERTICAL_RIGHT,
2285 EL_TUBE_HORIZONTAL_UP,
2286 EL_TUBE_HORIZONTAL_DOWN,
2291 EL_EXPANDABLE_STEELWALL_HORIZONTAL,
2292 EL_EXPANDABLE_STEELWALL_VERTICAL,
2293 EL_EXPANDABLE_STEELWALL_ANY,
2298 static int ep_slippery[] =
2312 EL_ROBOT_WHEEL_ACTIVE,
2318 EL_ACID_POOL_TOPLEFT,
2319 EL_ACID_POOL_TOPRIGHT,
2329 EL_STEELWALL_SLIPPERY,
2332 EL_EMC_WALL_SLIPPERY_1,
2333 EL_EMC_WALL_SLIPPERY_2,
2334 EL_EMC_WALL_SLIPPERY_3,
2335 EL_EMC_WALL_SLIPPERY_4,
2337 EL_EMC_MAGIC_BALL_ACTIVE,
2342 static int ep_can_change[] =
2347 static int ep_can_move[] =
2349 /* same elements as in 'pb_can_move_into_acid' */
2372 static int ep_can_fall[] =
2387 EL_BD_MAGIC_WALL_FULL,
2401 static int ep_can_smash_player[] =
2427 static int ep_can_smash_enemies[] =
2436 static int ep_can_smash_everything[] =
2445 static int ep_explodes_by_fire[] =
2447 /* same elements as in 'ep_explodes_impact' */
2452 /* same elements as in 'ep_explodes_smashed' */
2462 EL_EM_DYNAMITE_ACTIVE,
2463 EL_DYNABOMB_PLAYER_1_ACTIVE,
2464 EL_DYNABOMB_PLAYER_2_ACTIVE,
2465 EL_DYNABOMB_PLAYER_3_ACTIVE,
2466 EL_DYNABOMB_PLAYER_4_ACTIVE,
2467 EL_DYNABOMB_INCREASE_NUMBER,
2468 EL_DYNABOMB_INCREASE_SIZE,
2469 EL_DYNABOMB_INCREASE_POWER,
2470 EL_SP_DISK_RED_ACTIVE,
2484 static int ep_explodes_smashed[] =
2486 /* same elements as in 'ep_explodes_impact' */
2500 static int ep_explodes_impact[] =
2509 static int ep_walkable_over[] =
2513 EL_SOKOBAN_FIELD_EMPTY,
2526 EL_GATE_1_GRAY_ACTIVE,
2527 EL_GATE_2_GRAY_ACTIVE,
2528 EL_GATE_3_GRAY_ACTIVE,
2529 EL_GATE_4_GRAY_ACTIVE,
2537 static int ep_walkable_inside[] =
2542 EL_TUBE_VERTICAL_LEFT,
2543 EL_TUBE_VERTICAL_RIGHT,
2544 EL_TUBE_HORIZONTAL_UP,
2545 EL_TUBE_HORIZONTAL_DOWN,
2554 static int ep_walkable_under[] =
2559 static int ep_passable_over[] =
2569 EL_EM_GATE_1_GRAY_ACTIVE,
2570 EL_EM_GATE_2_GRAY_ACTIVE,
2571 EL_EM_GATE_3_GRAY_ACTIVE,
2572 EL_EM_GATE_4_GRAY_ACTIVE,
2581 EL_EMC_GATE_5_GRAY_ACTIVE,
2582 EL_EMC_GATE_6_GRAY_ACTIVE,
2583 EL_EMC_GATE_7_GRAY_ACTIVE,
2584 EL_EMC_GATE_8_GRAY_ACTIVE,
2591 static int ep_passable_inside[] =
2597 EL_SP_PORT_HORIZONTAL,
2598 EL_SP_PORT_VERTICAL,
2600 EL_SP_GRAVITY_PORT_LEFT,
2601 EL_SP_GRAVITY_PORT_RIGHT,
2602 EL_SP_GRAVITY_PORT_UP,
2603 EL_SP_GRAVITY_PORT_DOWN,
2604 EL_SP_GRAVITY_ON_PORT_LEFT,
2605 EL_SP_GRAVITY_ON_PORT_RIGHT,
2606 EL_SP_GRAVITY_ON_PORT_UP,
2607 EL_SP_GRAVITY_ON_PORT_DOWN,
2608 EL_SP_GRAVITY_OFF_PORT_LEFT,
2609 EL_SP_GRAVITY_OFF_PORT_RIGHT,
2610 EL_SP_GRAVITY_OFF_PORT_UP,
2611 EL_SP_GRAVITY_OFF_PORT_DOWN,
2616 static int ep_passable_under[] =
2621 static int ep_droppable[] =
2626 static int ep_explodes_1x1_old[] =
2631 static int ep_pushable[] =
2643 EL_SOKOBAN_FIELD_FULL,
2652 static int ep_explodes_cross_old[] =
2657 static int ep_protected[] =
2659 /* same elements as in 'ep_walkable_inside' */
2663 EL_TUBE_VERTICAL_LEFT,
2664 EL_TUBE_VERTICAL_RIGHT,
2665 EL_TUBE_HORIZONTAL_UP,
2666 EL_TUBE_HORIZONTAL_DOWN,
2672 /* same elements as in 'ep_passable_over' */
2681 EL_EM_GATE_1_GRAY_ACTIVE,
2682 EL_EM_GATE_2_GRAY_ACTIVE,
2683 EL_EM_GATE_3_GRAY_ACTIVE,
2684 EL_EM_GATE_4_GRAY_ACTIVE,
2693 EL_EMC_GATE_5_GRAY_ACTIVE,
2694 EL_EMC_GATE_6_GRAY_ACTIVE,
2695 EL_EMC_GATE_7_GRAY_ACTIVE,
2696 EL_EMC_GATE_8_GRAY_ACTIVE,
2700 /* same elements as in 'ep_passable_inside' */
2705 EL_SP_PORT_HORIZONTAL,
2706 EL_SP_PORT_VERTICAL,
2708 EL_SP_GRAVITY_PORT_LEFT,
2709 EL_SP_GRAVITY_PORT_RIGHT,
2710 EL_SP_GRAVITY_PORT_UP,
2711 EL_SP_GRAVITY_PORT_DOWN,
2712 EL_SP_GRAVITY_ON_PORT_LEFT,
2713 EL_SP_GRAVITY_ON_PORT_RIGHT,
2714 EL_SP_GRAVITY_ON_PORT_UP,
2715 EL_SP_GRAVITY_ON_PORT_DOWN,
2716 EL_SP_GRAVITY_OFF_PORT_LEFT,
2717 EL_SP_GRAVITY_OFF_PORT_RIGHT,
2718 EL_SP_GRAVITY_OFF_PORT_UP,
2719 EL_SP_GRAVITY_OFF_PORT_DOWN,
2724 static int ep_throwable[] =
2729 static int ep_can_explode[] =
2731 /* same elements as in 'ep_explodes_impact' */
2736 /* same elements as in 'ep_explodes_smashed' */
2742 /* elements that can explode by explosion or by dragonfire */
2746 EL_EM_DYNAMITE_ACTIVE,
2747 EL_DYNABOMB_PLAYER_1_ACTIVE,
2748 EL_DYNABOMB_PLAYER_2_ACTIVE,
2749 EL_DYNABOMB_PLAYER_3_ACTIVE,
2750 EL_DYNABOMB_PLAYER_4_ACTIVE,
2751 EL_DYNABOMB_INCREASE_NUMBER,
2752 EL_DYNABOMB_INCREASE_SIZE,
2753 EL_DYNABOMB_INCREASE_POWER,
2754 EL_SP_DISK_RED_ACTIVE,
2762 /* elements that can explode only by explosion */
2768 static int ep_gravity_reachable[] =
2774 EL_INVISIBLE_SAND_ACTIVE,
2779 EL_SP_PORT_HORIZONTAL,
2780 EL_SP_PORT_VERTICAL,
2782 EL_SP_GRAVITY_PORT_LEFT,
2783 EL_SP_GRAVITY_PORT_RIGHT,
2784 EL_SP_GRAVITY_PORT_UP,
2785 EL_SP_GRAVITY_PORT_DOWN,
2786 EL_SP_GRAVITY_ON_PORT_LEFT,
2787 EL_SP_GRAVITY_ON_PORT_RIGHT,
2788 EL_SP_GRAVITY_ON_PORT_UP,
2789 EL_SP_GRAVITY_ON_PORT_DOWN,
2790 EL_SP_GRAVITY_OFF_PORT_LEFT,
2791 EL_SP_GRAVITY_OFF_PORT_RIGHT,
2792 EL_SP_GRAVITY_OFF_PORT_UP,
2793 EL_SP_GRAVITY_OFF_PORT_DOWN,
2799 static int ep_player[] =
2806 EL_SOKOBAN_FIELD_PLAYER,
2812 static int ep_can_pass_magic_wall[] =
2826 static int ep_switchable[] =
2830 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
2831 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
2832 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
2833 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
2834 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
2835 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
2836 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
2837 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
2838 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
2839 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
2840 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
2841 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
2842 EL_SWITCHGATE_SWITCH_UP,
2843 EL_SWITCHGATE_SWITCH_DOWN,
2844 EL_DC_SWITCHGATE_SWITCH_UP,
2845 EL_DC_SWITCHGATE_SWITCH_DOWN,
2847 EL_LIGHT_SWITCH_ACTIVE,
2849 EL_DC_TIMEGATE_SWITCH,
2850 EL_BALLOON_SWITCH_LEFT,
2851 EL_BALLOON_SWITCH_RIGHT,
2852 EL_BALLOON_SWITCH_UP,
2853 EL_BALLOON_SWITCH_DOWN,
2854 EL_BALLOON_SWITCH_ANY,
2855 EL_BALLOON_SWITCH_NONE,
2858 EL_EMC_MAGIC_BALL_SWITCH,
2859 EL_EMC_MAGIC_BALL_SWITCH_ACTIVE,
2864 static int ep_bd_element[] =
2898 static int ep_sp_element[] =
2900 /* should always be valid */
2903 /* standard classic Supaplex elements */
2910 EL_SP_HARDWARE_GRAY,
2918 EL_SP_GRAVITY_PORT_RIGHT,
2919 EL_SP_GRAVITY_PORT_DOWN,
2920 EL_SP_GRAVITY_PORT_LEFT,
2921 EL_SP_GRAVITY_PORT_UP,
2926 EL_SP_PORT_VERTICAL,
2927 EL_SP_PORT_HORIZONTAL,
2933 EL_SP_HARDWARE_BASE_1,
2934 EL_SP_HARDWARE_GREEN,
2935 EL_SP_HARDWARE_BLUE,
2937 EL_SP_HARDWARE_YELLOW,
2938 EL_SP_HARDWARE_BASE_2,
2939 EL_SP_HARDWARE_BASE_3,
2940 EL_SP_HARDWARE_BASE_4,
2941 EL_SP_HARDWARE_BASE_5,
2942 EL_SP_HARDWARE_BASE_6,
2946 /* additional elements that appeared in newer Supaplex levels */
2949 /* additional gravity port elements (not switching, but setting gravity) */
2950 EL_SP_GRAVITY_ON_PORT_LEFT,
2951 EL_SP_GRAVITY_ON_PORT_RIGHT,
2952 EL_SP_GRAVITY_ON_PORT_UP,
2953 EL_SP_GRAVITY_ON_PORT_DOWN,
2954 EL_SP_GRAVITY_OFF_PORT_LEFT,
2955 EL_SP_GRAVITY_OFF_PORT_RIGHT,
2956 EL_SP_GRAVITY_OFF_PORT_UP,
2957 EL_SP_GRAVITY_OFF_PORT_DOWN,
2959 /* more than one Murphy in a level results in an inactive clone */
2962 /* runtime Supaplex elements */
2963 EL_SP_DISK_RED_ACTIVE,
2964 EL_SP_TERMINAL_ACTIVE,
2965 EL_SP_BUGGY_BASE_ACTIVATING,
2966 EL_SP_BUGGY_BASE_ACTIVE,
2973 static int ep_sb_element[] =
2978 EL_SOKOBAN_FIELD_EMPTY,
2979 EL_SOKOBAN_FIELD_FULL,
2980 EL_SOKOBAN_FIELD_PLAYER,
2985 EL_INVISIBLE_STEELWALL,
2990 static int ep_gem[] =
3002 static int ep_food_dark_yamyam[] =
3030 static int ep_food_penguin[] =
3044 static int ep_food_pig[] =
3056 static int ep_historic_wall[] =
3067 EL_GATE_1_GRAY_ACTIVE,
3068 EL_GATE_2_GRAY_ACTIVE,
3069 EL_GATE_3_GRAY_ACTIVE,
3070 EL_GATE_4_GRAY_ACTIVE,
3079 EL_EM_GATE_1_GRAY_ACTIVE,
3080 EL_EM_GATE_2_GRAY_ACTIVE,
3081 EL_EM_GATE_3_GRAY_ACTIVE,
3082 EL_EM_GATE_4_GRAY_ACTIVE,
3089 EL_EXPANDABLE_WALL_HORIZONTAL,
3090 EL_EXPANDABLE_WALL_VERTICAL,
3091 EL_EXPANDABLE_WALL_ANY,
3092 EL_EXPANDABLE_WALL_GROWING,
3093 EL_BD_EXPANDABLE_WALL,
3100 EL_SP_HARDWARE_GRAY,
3101 EL_SP_HARDWARE_GREEN,
3102 EL_SP_HARDWARE_BLUE,
3104 EL_SP_HARDWARE_YELLOW,
3105 EL_SP_HARDWARE_BASE_1,
3106 EL_SP_HARDWARE_BASE_2,
3107 EL_SP_HARDWARE_BASE_3,
3108 EL_SP_HARDWARE_BASE_4,
3109 EL_SP_HARDWARE_BASE_5,
3110 EL_SP_HARDWARE_BASE_6,
3112 EL_SP_TERMINAL_ACTIVE,
3115 EL_INVISIBLE_STEELWALL,
3116 EL_INVISIBLE_STEELWALL_ACTIVE,
3118 EL_INVISIBLE_WALL_ACTIVE,
3119 EL_STEELWALL_SLIPPERY,
3136 static int ep_historic_solid[] =
3140 EL_EXPANDABLE_WALL_HORIZONTAL,
3141 EL_EXPANDABLE_WALL_VERTICAL,
3142 EL_EXPANDABLE_WALL_ANY,
3143 EL_BD_EXPANDABLE_WALL,
3156 EL_QUICKSAND_FILLING,
3157 EL_QUICKSAND_EMPTYING,
3159 EL_MAGIC_WALL_ACTIVE,
3160 EL_MAGIC_WALL_EMPTYING,
3161 EL_MAGIC_WALL_FILLING,
3165 EL_BD_MAGIC_WALL_ACTIVE,
3166 EL_BD_MAGIC_WALL_EMPTYING,
3167 EL_BD_MAGIC_WALL_FULL,
3168 EL_BD_MAGIC_WALL_FILLING,
3169 EL_BD_MAGIC_WALL_DEAD,
3178 EL_SP_TERMINAL_ACTIVE,
3182 EL_INVISIBLE_WALL_ACTIVE,
3183 EL_SWITCHGATE_SWITCH_UP,
3184 EL_SWITCHGATE_SWITCH_DOWN,
3185 EL_DC_SWITCHGATE_SWITCH_UP,
3186 EL_DC_SWITCHGATE_SWITCH_DOWN,
3188 EL_TIMEGATE_SWITCH_ACTIVE,
3189 EL_DC_TIMEGATE_SWITCH,
3190 EL_DC_TIMEGATE_SWITCH_ACTIVE,
3202 /* the following elements are a direct copy of "indestructible" elements,
3203 except "EL_ACID", which is "indestructible", but not "solid"! */
3208 EL_ACID_POOL_TOPLEFT,
3209 EL_ACID_POOL_TOPRIGHT,
3210 EL_ACID_POOL_BOTTOMLEFT,
3211 EL_ACID_POOL_BOTTOM,
3212 EL_ACID_POOL_BOTTOMRIGHT,
3213 EL_SP_HARDWARE_GRAY,
3214 EL_SP_HARDWARE_GREEN,
3215 EL_SP_HARDWARE_BLUE,
3217 EL_SP_HARDWARE_YELLOW,
3218 EL_SP_HARDWARE_BASE_1,
3219 EL_SP_HARDWARE_BASE_2,
3220 EL_SP_HARDWARE_BASE_3,
3221 EL_SP_HARDWARE_BASE_4,
3222 EL_SP_HARDWARE_BASE_5,
3223 EL_SP_HARDWARE_BASE_6,
3224 EL_INVISIBLE_STEELWALL,
3225 EL_INVISIBLE_STEELWALL_ACTIVE,
3226 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3227 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
3228 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
3229 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3230 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
3231 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
3232 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3233 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
3234 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
3235 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
3236 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
3237 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
3239 EL_LIGHT_SWITCH_ACTIVE,
3240 EL_SIGN_EXCLAMATION,
3241 EL_SIGN_RADIOACTIVITY,
3248 EL_SIGN_ENTRY_FORBIDDEN,
3249 EL_SIGN_EMERGENCY_EXIT,
3257 EL_STEEL_EXIT_CLOSED,
3259 EL_DC_STEELWALL_1_LEFT,
3260 EL_DC_STEELWALL_1_RIGHT,
3261 EL_DC_STEELWALL_1_TOP,
3262 EL_DC_STEELWALL_1_BOTTOM,
3263 EL_DC_STEELWALL_1_HORIZONTAL,
3264 EL_DC_STEELWALL_1_VERTICAL,
3265 EL_DC_STEELWALL_1_TOPLEFT,
3266 EL_DC_STEELWALL_1_TOPRIGHT,
3267 EL_DC_STEELWALL_1_BOTTOMLEFT,
3268 EL_DC_STEELWALL_1_BOTTOMRIGHT,
3269 EL_DC_STEELWALL_1_TOPLEFT_2,
3270 EL_DC_STEELWALL_1_TOPRIGHT_2,
3271 EL_DC_STEELWALL_1_BOTTOMLEFT_2,
3272 EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
3273 EL_DC_STEELWALL_2_LEFT,
3274 EL_DC_STEELWALL_2_RIGHT,
3275 EL_DC_STEELWALL_2_TOP,
3276 EL_DC_STEELWALL_2_BOTTOM,
3277 EL_DC_STEELWALL_2_HORIZONTAL,
3278 EL_DC_STEELWALL_2_VERTICAL,
3279 EL_DC_STEELWALL_2_MIDDLE,
3280 EL_DC_STEELWALL_2_SINGLE,
3281 EL_STEELWALL_SLIPPERY,
3295 EL_GATE_1_GRAY_ACTIVE,
3296 EL_GATE_2_GRAY_ACTIVE,
3297 EL_GATE_3_GRAY_ACTIVE,
3298 EL_GATE_4_GRAY_ACTIVE,
3307 EL_EM_GATE_1_GRAY_ACTIVE,
3308 EL_EM_GATE_2_GRAY_ACTIVE,
3309 EL_EM_GATE_3_GRAY_ACTIVE,
3310 EL_EM_GATE_4_GRAY_ACTIVE,
3312 EL_SWITCHGATE_OPENING,
3313 EL_SWITCHGATE_CLOSED,
3314 EL_SWITCHGATE_CLOSING,
3316 EL_TIMEGATE_OPENING,
3318 EL_TIMEGATE_CLOSING,
3322 EL_TUBE_VERTICAL_LEFT,
3323 EL_TUBE_VERTICAL_RIGHT,
3324 EL_TUBE_HORIZONTAL_UP,
3325 EL_TUBE_HORIZONTAL_DOWN,
3334 static int ep_classic_enemy[] =
3351 static int ep_belt[] =
3353 EL_CONVEYOR_BELT_1_LEFT,
3354 EL_CONVEYOR_BELT_1_MIDDLE,
3355 EL_CONVEYOR_BELT_1_RIGHT,
3356 EL_CONVEYOR_BELT_2_LEFT,
3357 EL_CONVEYOR_BELT_2_MIDDLE,
3358 EL_CONVEYOR_BELT_2_RIGHT,
3359 EL_CONVEYOR_BELT_3_LEFT,
3360 EL_CONVEYOR_BELT_3_MIDDLE,
3361 EL_CONVEYOR_BELT_3_RIGHT,
3362 EL_CONVEYOR_BELT_4_LEFT,
3363 EL_CONVEYOR_BELT_4_MIDDLE,
3364 EL_CONVEYOR_BELT_4_RIGHT,
3369 static int ep_belt_active[] =
3371 EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
3372 EL_CONVEYOR_BELT_1_MIDDLE_ACTIVE,
3373 EL_CONVEYOR_BELT_1_RIGHT_ACTIVE,
3374 EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
3375 EL_CONVEYOR_BELT_2_MIDDLE_ACTIVE,
3376 EL_CONVEYOR_BELT_2_RIGHT_ACTIVE,
3377 EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
3378 EL_CONVEYOR_BELT_3_MIDDLE_ACTIVE,
3379 EL_CONVEYOR_BELT_3_RIGHT_ACTIVE,
3380 EL_CONVEYOR_BELT_4_LEFT_ACTIVE,
3381 EL_CONVEYOR_BELT_4_MIDDLE_ACTIVE,
3382 EL_CONVEYOR_BELT_4_RIGHT_ACTIVE,
3387 static int ep_belt_switch[] =
3389 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3390 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
3391 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
3392 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3393 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
3394 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
3395 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3396 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
3397 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
3398 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
3399 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
3400 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
3405 static int ep_tube[] =
3412 EL_TUBE_HORIZONTAL_UP,
3413 EL_TUBE_HORIZONTAL_DOWN,
3415 EL_TUBE_VERTICAL_LEFT,
3416 EL_TUBE_VERTICAL_RIGHT,
3422 static int ep_keygate[] =
3432 EL_GATE_1_GRAY_ACTIVE,
3433 EL_GATE_2_GRAY_ACTIVE,
3434 EL_GATE_3_GRAY_ACTIVE,
3435 EL_GATE_4_GRAY_ACTIVE,
3444 EL_EM_GATE_1_GRAY_ACTIVE,
3445 EL_EM_GATE_2_GRAY_ACTIVE,
3446 EL_EM_GATE_3_GRAY_ACTIVE,
3447 EL_EM_GATE_4_GRAY_ACTIVE,
3456 EL_EMC_GATE_5_GRAY_ACTIVE,
3457 EL_EMC_GATE_6_GRAY_ACTIVE,
3458 EL_EMC_GATE_7_GRAY_ACTIVE,
3459 EL_EMC_GATE_8_GRAY_ACTIVE,
3464 static int ep_amoeboid[] =
3476 static int ep_amoebalive[] =
3487 static int ep_has_editor_content[] =
3509 static int ep_can_turn_each_move[] =
3511 /* !!! do something with this one !!! */
3515 static int ep_can_grow[] =
3529 static int ep_active_bomb[] =
3532 EL_EM_DYNAMITE_ACTIVE,
3533 EL_DYNABOMB_PLAYER_1_ACTIVE,
3534 EL_DYNABOMB_PLAYER_2_ACTIVE,
3535 EL_DYNABOMB_PLAYER_3_ACTIVE,
3536 EL_DYNABOMB_PLAYER_4_ACTIVE,
3537 EL_SP_DISK_RED_ACTIVE,
3542 static int ep_inactive[] =
3574 EL_GATE_1_GRAY_ACTIVE,
3575 EL_GATE_2_GRAY_ACTIVE,
3576 EL_GATE_3_GRAY_ACTIVE,
3577 EL_GATE_4_GRAY_ACTIVE,
3586 EL_EM_GATE_1_GRAY_ACTIVE,
3587 EL_EM_GATE_2_GRAY_ACTIVE,
3588 EL_EM_GATE_3_GRAY_ACTIVE,
3589 EL_EM_GATE_4_GRAY_ACTIVE,
3598 EL_EMC_GATE_5_GRAY_ACTIVE,
3599 EL_EMC_GATE_6_GRAY_ACTIVE,
3600 EL_EMC_GATE_7_GRAY_ACTIVE,
3601 EL_EMC_GATE_8_GRAY_ACTIVE,
3604 EL_INVISIBLE_STEELWALL,
3612 EL_WALL_EMERALD_YELLOW,
3613 EL_DYNABOMB_INCREASE_NUMBER,
3614 EL_DYNABOMB_INCREASE_SIZE,
3615 EL_DYNABOMB_INCREASE_POWER,
3619 EL_SOKOBAN_FIELD_EMPTY,
3620 EL_SOKOBAN_FIELD_FULL,
3621 EL_WALL_EMERALD_RED,
3622 EL_WALL_EMERALD_PURPLE,
3623 EL_ACID_POOL_TOPLEFT,
3624 EL_ACID_POOL_TOPRIGHT,
3625 EL_ACID_POOL_BOTTOMLEFT,
3626 EL_ACID_POOL_BOTTOM,
3627 EL_ACID_POOL_BOTTOMRIGHT,
3631 EL_BD_MAGIC_WALL_DEAD,
3632 EL_AMOEBA_TO_DIAMOND,
3640 EL_SP_GRAVITY_PORT_RIGHT,
3641 EL_SP_GRAVITY_PORT_DOWN,
3642 EL_SP_GRAVITY_PORT_LEFT,
3643 EL_SP_GRAVITY_PORT_UP,
3644 EL_SP_PORT_HORIZONTAL,
3645 EL_SP_PORT_VERTICAL,
3656 EL_SP_HARDWARE_GRAY,
3657 EL_SP_HARDWARE_GREEN,
3658 EL_SP_HARDWARE_BLUE,
3660 EL_SP_HARDWARE_YELLOW,
3661 EL_SP_HARDWARE_BASE_1,
3662 EL_SP_HARDWARE_BASE_2,
3663 EL_SP_HARDWARE_BASE_3,
3664 EL_SP_HARDWARE_BASE_4,
3665 EL_SP_HARDWARE_BASE_5,
3666 EL_SP_HARDWARE_BASE_6,
3667 EL_SP_GRAVITY_ON_PORT_LEFT,
3668 EL_SP_GRAVITY_ON_PORT_RIGHT,
3669 EL_SP_GRAVITY_ON_PORT_UP,
3670 EL_SP_GRAVITY_ON_PORT_DOWN,
3671 EL_SP_GRAVITY_OFF_PORT_LEFT,
3672 EL_SP_GRAVITY_OFF_PORT_RIGHT,
3673 EL_SP_GRAVITY_OFF_PORT_UP,
3674 EL_SP_GRAVITY_OFF_PORT_DOWN,
3675 EL_CONVEYOR_BELT_1_SWITCH_LEFT,
3676 EL_CONVEYOR_BELT_1_SWITCH_MIDDLE,
3677 EL_CONVEYOR_BELT_1_SWITCH_RIGHT,
3678 EL_CONVEYOR_BELT_2_SWITCH_LEFT,
3679 EL_CONVEYOR_BELT_2_SWITCH_MIDDLE,
3680 EL_CONVEYOR_BELT_2_SWITCH_RIGHT,
3681 EL_CONVEYOR_BELT_3_SWITCH_LEFT,
3682 EL_CONVEYOR_BELT_3_SWITCH_MIDDLE,
3683 EL_CONVEYOR_BELT_3_SWITCH_RIGHT,
3684 EL_CONVEYOR_BELT_4_SWITCH_LEFT,
3685 EL_CONVEYOR_BELT_4_SWITCH_MIDDLE,
3686 EL_CONVEYOR_BELT_4_SWITCH_RIGHT,
3687 EL_SIGN_EXCLAMATION,
3688 EL_SIGN_RADIOACTIVITY,
3695 EL_SIGN_ENTRY_FORBIDDEN,
3696 EL_SIGN_EMERGENCY_EXIT,
3704 EL_DC_STEELWALL_1_LEFT,
3705 EL_DC_STEELWALL_1_RIGHT,
3706 EL_DC_STEELWALL_1_TOP,
3707 EL_DC_STEELWALL_1_BOTTOM,
3708 EL_DC_STEELWALL_1_HORIZONTAL,
3709 EL_DC_STEELWALL_1_VERTICAL,
3710 EL_DC_STEELWALL_1_TOPLEFT,
3711 EL_DC_STEELWALL_1_TOPRIGHT,
3712 EL_DC_STEELWALL_1_BOTTOMLEFT,
3713 EL_DC_STEELWALL_1_BOTTOMRIGHT,
3714 EL_DC_STEELWALL_1_TOPLEFT_2,
3715 EL_DC_STEELWALL_1_TOPRIGHT_2,
3716 EL_DC_STEELWALL_1_BOTTOMLEFT_2,
3717 EL_DC_STEELWALL_1_BOTTOMRIGHT_2,
3718 EL_DC_STEELWALL_2_LEFT,
3719 EL_DC_STEELWALL_2_RIGHT,
3720 EL_DC_STEELWALL_2_TOP,
3721 EL_DC_STEELWALL_2_BOTTOM,
3722 EL_DC_STEELWALL_2_HORIZONTAL,
3723 EL_DC_STEELWALL_2_VERTICAL,
3724 EL_DC_STEELWALL_2_MIDDLE,
3725 EL_DC_STEELWALL_2_SINGLE,
3726 EL_STEELWALL_SLIPPERY,
3731 EL_EMC_WALL_SLIPPERY_1,
3732 EL_EMC_WALL_SLIPPERY_2,
3733 EL_EMC_WALL_SLIPPERY_3,
3734 EL_EMC_WALL_SLIPPERY_4,
3755 static int ep_em_slippery_wall[] =
3760 static int ep_gfx_crumbled[] =
3771 static int ep_editor_cascade_active[] =
3773 EL_INTERNAL_CASCADE_BD_ACTIVE,
3774 EL_INTERNAL_CASCADE_EM_ACTIVE,
3775 EL_INTERNAL_CASCADE_EMC_ACTIVE,
3776 EL_INTERNAL_CASCADE_RND_ACTIVE,
3777 EL_INTERNAL_CASCADE_SB_ACTIVE,
3778 EL_INTERNAL_CASCADE_SP_ACTIVE,
3779 EL_INTERNAL_CASCADE_DC_ACTIVE,
3780 EL_INTERNAL_CASCADE_DX_ACTIVE,
3781 EL_INTERNAL_CASCADE_CHARS_ACTIVE,
3782 EL_INTERNAL_CASCADE_STEEL_CHARS_ACTIVE,
3783 EL_INTERNAL_CASCADE_CE_ACTIVE,
3784 EL_INTERNAL_CASCADE_GE_ACTIVE,
3785 EL_INTERNAL_CASCADE_REF_ACTIVE,
3786 EL_INTERNAL_CASCADE_USER_ACTIVE,
3787 EL_INTERNAL_CASCADE_DYNAMIC_ACTIVE,
3792 static int ep_editor_cascade_inactive[] =
3794 EL_INTERNAL_CASCADE_BD,
3795 EL_INTERNAL_CASCADE_EM,
3796 EL_INTERNAL_CASCADE_EMC,
3797 EL_INTERNAL_CASCADE_RND,
3798 EL_INTERNAL_CASCADE_SB,
3799 EL_INTERNAL_CASCADE_SP,
3800 EL_INTERNAL_CASCADE_DC,
3801 EL_INTERNAL_CASCADE_DX,
3802 EL_INTERNAL_CASCADE_CHARS,
3803 EL_INTERNAL_CASCADE_STEEL_CHARS,
3804 EL_INTERNAL_CASCADE_CE,
3805 EL_INTERNAL_CASCADE_GE,
3806 EL_INTERNAL_CASCADE_REF,
3807 EL_INTERNAL_CASCADE_USER,
3808 EL_INTERNAL_CASCADE_DYNAMIC,
3813 static int ep_obsolete[] =
3817 EL_EM_KEY_1_FILE_OBSOLETE,
3818 EL_EM_KEY_2_FILE_OBSOLETE,
3819 EL_EM_KEY_3_FILE_OBSOLETE,
3820 EL_EM_KEY_4_FILE_OBSOLETE,
3821 EL_ENVELOPE_OBSOLETE,
3830 } element_properties[] =
3832 { ep_diggable, EP_DIGGABLE },
3833 { ep_collectible_only, EP_COLLECTIBLE_ONLY },
3834 { ep_dont_run_into, EP_DONT_RUN_INTO },
3835 { ep_dont_collide_with, EP_DONT_COLLIDE_WITH },
3836 { ep_dont_touch, EP_DONT_TOUCH },
3837 { ep_indestructible, EP_INDESTRUCTIBLE },
3838 { ep_slippery, EP_SLIPPERY },
3839 { ep_can_change, EP_CAN_CHANGE },
3840 { ep_can_move, EP_CAN_MOVE },
3841 { ep_can_fall, EP_CAN_FALL },
3842 { ep_can_smash_player, EP_CAN_SMASH_PLAYER },
3843 { ep_can_smash_enemies, EP_CAN_SMASH_ENEMIES },
3844 { ep_can_smash_everything, EP_CAN_SMASH_EVERYTHING },
3845 { ep_explodes_by_fire, EP_EXPLODES_BY_FIRE },
3846 { ep_explodes_smashed, EP_EXPLODES_SMASHED },
3847 { ep_explodes_impact, EP_EXPLODES_IMPACT },
3848 { ep_walkable_over, EP_WALKABLE_OVER },
3849 { ep_walkable_inside, EP_WALKABLE_INSIDE },
3850 { ep_walkable_under, EP_WALKABLE_UNDER },
3851 { ep_passable_over, EP_PASSABLE_OVER },
3852 { ep_passable_inside, EP_PASSABLE_INSIDE },
3853 { ep_passable_under, EP_PASSABLE_UNDER },
3854 { ep_droppable, EP_DROPPABLE },
3855 { ep_explodes_1x1_old, EP_EXPLODES_1X1_OLD },
3856 { ep_pushable, EP_PUSHABLE },
3857 { ep_explodes_cross_old, EP_EXPLODES_CROSS_OLD },
3858 { ep_protected, EP_PROTECTED },
3859 { ep_throwable, EP_THROWABLE },
3860 { ep_can_explode, EP_CAN_EXPLODE },
3861 { ep_gravity_reachable, EP_GRAVITY_REACHABLE },
3863 { ep_player, EP_PLAYER },
3864 { ep_can_pass_magic_wall, EP_CAN_PASS_MAGIC_WALL },
3865 { ep_switchable, EP_SWITCHABLE },
3866 { ep_bd_element, EP_BD_ELEMENT },
3867 { ep_sp_element, EP_SP_ELEMENT },
3868 { ep_sb_element, EP_SB_ELEMENT },
3870 { ep_food_dark_yamyam, EP_FOOD_DARK_YAMYAM },
3871 { ep_food_penguin, EP_FOOD_PENGUIN },
3872 { ep_food_pig, EP_FOOD_PIG },
3873 { ep_historic_wall, EP_HISTORIC_WALL },
3874 { ep_historic_solid, EP_HISTORIC_SOLID },
3875 { ep_classic_enemy, EP_CLASSIC_ENEMY },
3876 { ep_belt, EP_BELT },
3877 { ep_belt_active, EP_BELT_ACTIVE },
3878 { ep_belt_switch, EP_BELT_SWITCH },
3879 { ep_tube, EP_TUBE },
3880 { ep_keygate, EP_KEYGATE },
3881 { ep_amoeboid, EP_AMOEBOID },
3882 { ep_amoebalive, EP_AMOEBALIVE },
3883 { ep_has_editor_content, EP_HAS_EDITOR_CONTENT },
3884 { ep_can_turn_each_move, EP_CAN_TURN_EACH_MOVE },
3885 { ep_can_grow, EP_CAN_GROW },
3886 { ep_active_bomb, EP_ACTIVE_BOMB },
3887 { ep_inactive, EP_INACTIVE },
3889 { ep_em_slippery_wall, EP_EM_SLIPPERY_WALL },
3891 { ep_gfx_crumbled, EP_GFX_CRUMBLED },
3893 { ep_editor_cascade_active, EP_EDITOR_CASCADE_ACTIVE },
3894 { ep_editor_cascade_inactive, EP_EDITOR_CASCADE_INACTIVE },
3896 { ep_obsolete, EP_OBSOLETE },
3903 /* always start with reliable default values (element has no properties) */
3904 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3905 for (j = 0; j < NUM_ELEMENT_PROPERTIES; j++)
3906 SET_PROPERTY(i, j, FALSE);
3908 /* set all base element properties from above array definitions */
3909 for (i = 0; element_properties[i].elements != NULL; i++)
3910 for (j = 0; (element_properties[i].elements)[j] != -1; j++)
3911 SET_PROPERTY((element_properties[i].elements)[j],
3912 element_properties[i].property, TRUE);
3914 /* copy properties to some elements that are only stored in level file */
3915 for (i = 0; i < NUM_ELEMENT_PROPERTIES; i++)
3916 for (j = 0; copy_properties[j][0] != -1; j++)
3917 if (HAS_PROPERTY(copy_properties[j][0], i))
3918 for (k = 1; k <= 4; k++)
3919 SET_PROPERTY(copy_properties[j][k], i, TRUE);
3921 /* set static element properties that are not listed in array definitions */
3922 for (i = EL_STEEL_CHAR_START; i <= EL_STEEL_CHAR_END; i++)
3923 SET_PROPERTY(i, EP_INDESTRUCTIBLE, TRUE);
3926 void InitElementPropertiesEngine(int engine_version)
3928 static int no_wall_properties[] =
3931 EP_COLLECTIBLE_ONLY,
3933 EP_DONT_COLLIDE_WITH,
3936 EP_CAN_SMASH_PLAYER,
3937 EP_CAN_SMASH_ENEMIES,
3938 EP_CAN_SMASH_EVERYTHING,
3943 EP_FOOD_DARK_YAMYAM,
3959 /* important: after initialization in InitElementPropertiesStatic(), the
3960 elements are not again initialized to a default value; therefore all
3961 changes have to make sure that they leave the element with a defined
3962 property (which means that conditional property changes must be set to
3963 a reliable default value before) */
3965 /* ---------- recursively resolve group elements ------------------------- */
3967 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3968 for (j = 0; j < NUM_GROUP_ELEMENTS; j++)
3969 element_info[i].in_group[j] = FALSE;
3971 for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
3972 resolve_group_element(EL_GROUP_START + i, 0);
3974 /* set all special, combined or engine dependent element properties */
3975 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
3977 /* ---------- INACTIVE ------------------------------------------------- */
3978 SET_PROPERTY(i, EP_INACTIVE, ((i >= EL_CHAR_START &&
3979 i <= EL_CHAR_END) ||
3980 (i >= EL_STEEL_CHAR_START &&
3981 i <= EL_STEEL_CHAR_END)));
3983 /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
3984 SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) ||
3985 IS_WALKABLE_INSIDE(i) ||
3986 IS_WALKABLE_UNDER(i)));
3988 SET_PROPERTY(i, EP_PASSABLE, (IS_PASSABLE_OVER(i) ||
3989 IS_PASSABLE_INSIDE(i) ||
3990 IS_PASSABLE_UNDER(i)));
3992 SET_PROPERTY(i, EP_ACCESSIBLE_OVER, (IS_WALKABLE_OVER(i) ||
3993 IS_PASSABLE_OVER(i)));
3995 SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, (IS_WALKABLE_INSIDE(i) ||
3996 IS_PASSABLE_INSIDE(i)));
3998 SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, (IS_WALKABLE_UNDER(i) ||
3999 IS_PASSABLE_UNDER(i)));
4001 SET_PROPERTY(i, EP_ACCESSIBLE, (IS_WALKABLE(i) ||
4004 /* ---------- COLLECTIBLE ---------------------------------------------- */
4005 SET_PROPERTY(i, EP_COLLECTIBLE, (IS_COLLECTIBLE_ONLY(i) ||
4009 /* ---------- SNAPPABLE ------------------------------------------------ */
4010 SET_PROPERTY(i, EP_SNAPPABLE, (IS_DIGGABLE(i) ||
4011 IS_COLLECTIBLE(i) ||
4015 /* ---------- WALL ----------------------------------------------------- */
4016 SET_PROPERTY(i, EP_WALL, TRUE); /* default: element is wall */
4018 for (j = 0; no_wall_properties[j] != -1; j++)
4019 if (HAS_PROPERTY(i, no_wall_properties[j]) ||
4020 i >= EL_FIRST_RUNTIME_UNREAL)
4021 SET_PROPERTY(i, EP_WALL, FALSE);
4023 if (IS_HISTORIC_WALL(i))
4024 SET_PROPERTY(i, EP_WALL, TRUE);
4026 /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */
4027 if (engine_version < VERSION_IDENT(2,2,0,0))
4028 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i));
4030 SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) &&
4032 !IS_COLLECTIBLE(i)));
4034 /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
4035 if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION)
4036 SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
4038 SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_CUSTOM_ELEMENT(i) &&
4039 IS_INDESTRUCTIBLE(i)));
4041 /* ---------- EXPLOSION_PROOF ------------------------------------------ */
4043 SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE);
4044 else if (engine_version < VERSION_IDENT(2,2,0,0))
4045 SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i));
4047 SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
4051 if (IS_CUSTOM_ELEMENT(i))
4053 /* these are additional properties which are initially false when set */
4055 /* ---------- DONT_COLLIDE_WITH / DONT_RUN_INTO ---------------------- */
4057 SET_PROPERTY(i, EP_DONT_COLLIDE_WITH, TRUE);
4058 if (DONT_COLLIDE_WITH(i))
4059 SET_PROPERTY(i, EP_DONT_RUN_INTO, TRUE);
4061 /* ---------- CAN_SMASH_ENEMIES / CAN_SMASH_PLAYER ------------------- */
4062 if (CAN_SMASH_EVERYTHING(i))
4063 SET_PROPERTY(i, EP_CAN_SMASH_ENEMIES, TRUE);
4064 if (CAN_SMASH_ENEMIES(i))
4065 SET_PROPERTY(i, EP_CAN_SMASH_PLAYER, TRUE);
4068 /* ---------- CAN_SMASH ------------------------------------------------ */
4069 SET_PROPERTY(i, EP_CAN_SMASH, (CAN_SMASH_PLAYER(i) ||
4070 CAN_SMASH_ENEMIES(i) ||
4071 CAN_SMASH_EVERYTHING(i)));
4073 /* ---------- CAN_EXPLODE_BY_FIRE -------------------------------------- */
4074 SET_PROPERTY(i, EP_CAN_EXPLODE_BY_FIRE, (CAN_EXPLODE(i) &&
4075 EXPLODES_BY_FIRE(i)));
4077 /* ---------- CAN_EXPLODE_SMASHED -------------------------------------- */
4078 SET_PROPERTY(i, EP_CAN_EXPLODE_SMASHED, (CAN_EXPLODE(i) &&
4079 EXPLODES_SMASHED(i)));
4081 /* ---------- CAN_EXPLODE_IMPACT --------------------------------------- */
4082 SET_PROPERTY(i, EP_CAN_EXPLODE_IMPACT, (CAN_EXPLODE(i) &&
4083 EXPLODES_IMPACT(i)));
4085 /* ---------- CAN_EXPLODE_BY_DRAGONFIRE -------------------------------- */
4086 SET_PROPERTY(i, EP_CAN_EXPLODE_BY_DRAGONFIRE, CAN_EXPLODE_BY_FIRE(i));
4088 /* ---------- CAN_EXPLODE_BY_EXPLOSION --------------------------------- */
4089 SET_PROPERTY(i, EP_CAN_EXPLODE_BY_EXPLOSION, (CAN_EXPLODE_BY_FIRE(i) ||
4090 i == EL_BLACK_ORB));
4092 /* ---------- COULD_MOVE_INTO_ACID ------------------------------------- */
4093 SET_PROPERTY(i, EP_COULD_MOVE_INTO_ACID, (ELEM_IS_PLAYER(i) ||
4095 IS_CUSTOM_ELEMENT(i)));
4097 /* ---------- MAYBE_DONT_COLLIDE_WITH ---------------------------------- */
4098 SET_PROPERTY(i, EP_MAYBE_DONT_COLLIDE_WITH, (i == EL_SP_SNIKSNAK ||
4099 i == EL_SP_ELECTRON));
4101 /* ---------- CAN_MOVE_INTO_ACID --------------------------------------- */
4102 if (COULD_MOVE_INTO_ACID(i) && !IS_CUSTOM_ELEMENT(i))
4103 SET_PROPERTY(i, EP_CAN_MOVE_INTO_ACID,
4104 getMoveIntoAcidProperty(&level, i));
4106 /* ---------- DONT_COLLIDE_WITH ---------------------------------------- */
4107 if (MAYBE_DONT_COLLIDE_WITH(i))
4108 SET_PROPERTY(i, EP_DONT_COLLIDE_WITH,
4109 getDontCollideWithProperty(&level, i));
4111 /* ---------- SP_PORT -------------------------------------------------- */
4112 SET_PROPERTY(i, EP_SP_PORT, (IS_SP_ELEMENT(i) &&
4113 IS_PASSABLE_INSIDE(i)));
4115 /* ---------- CAN_BE_CLONED_BY_ANDROID --------------------------------- */
4116 for (j = 0; j < level.num_android_clone_elements; j++)
4117 SET_PROPERTY(i, EP_CAN_BE_CLONED_BY_ANDROID,
4119 IS_EQUAL_OR_IN_GROUP(i, level.android_clone_element[j])));
4121 /* ---------- CAN_CHANGE ----------------------------------------------- */
4122 SET_PROPERTY(i, EP_CAN_CHANGE, FALSE); /* default: cannot change */
4123 for (j = 0; j < element_info[i].num_change_pages; j++)
4124 if (element_info[i].change_page[j].can_change)
4125 SET_PROPERTY(i, EP_CAN_CHANGE, TRUE);
4127 /* ---------- HAS_ACTION ----------------------------------------------- */
4128 SET_PROPERTY(i, EP_HAS_ACTION, FALSE); /* default: has no action */
4129 for (j = 0; j < element_info[i].num_change_pages; j++)
4130 if (element_info[i].change_page[j].has_action)
4131 SET_PROPERTY(i, EP_HAS_ACTION, TRUE);
4133 /* ---------- CAN_CHANGE_OR_HAS_ACTION --------------------------------- */
4134 SET_PROPERTY(i, EP_CAN_CHANGE_OR_HAS_ACTION, (CAN_CHANGE(i) ||
4137 /* ---------- GFX_CRUMBLED --------------------------------------------- */
4139 SET_PROPERTY(i, EP_GFX_CRUMBLED,
4140 element_info[i].crumbled[ACTION_DEFAULT] !=
4141 element_info[i].graphic[ACTION_DEFAULT]);
4143 /* !!! THIS LOOKS CRAPPY FOR SAND ETC. WITHOUT CRUMBLED GRAPHICS !!! */
4144 SET_PROPERTY(i, EP_GFX_CRUMBLED,
4145 element_info[i].crumbled[ACTION_DEFAULT] != IMG_EMPTY);
4148 /* ---------- EDITOR_CASCADE ------------------------------------------- */
4149 SET_PROPERTY(i, EP_EDITOR_CASCADE, (IS_EDITOR_CASCADE_ACTIVE(i) ||
4150 IS_EDITOR_CASCADE_INACTIVE(i)));
4153 /* dynamically adjust element properties according to game engine version */
4155 static int ep_em_slippery_wall[] =
4160 EL_EXPANDABLE_WALL_HORIZONTAL,
4161 EL_EXPANDABLE_WALL_VERTICAL,
4162 EL_EXPANDABLE_WALL_ANY,
4163 EL_EXPANDABLE_STEELWALL_HORIZONTAL,
4164 EL_EXPANDABLE_STEELWALL_VERTICAL,
4165 EL_EXPANDABLE_STEELWALL_ANY,
4166 EL_EXPANDABLE_STEELWALL_GROWING,
4170 /* special EM style gems behaviour */
4171 for (i = 0; ep_em_slippery_wall[i] != -1; i++)
4172 SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL,
4173 level.em_slippery_gems);
4175 /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */
4176 SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL,
4177 (level.em_slippery_gems &&
4178 engine_version > VERSION_IDENT(2,0,1,0)));
4181 /* this is needed because some graphics depend on element properties */
4182 if (game_status == GAME_MODE_PLAYING)
4183 InitElementGraphicInfo();
4186 void InitElementPropertiesAfterLoading(int engine_version)
4190 /* set some other uninitialized values of custom elements in older levels */
4191 if (engine_version < VERSION_IDENT(3,1,0,0))
4193 for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
4195 int element = EL_CUSTOM_START + i;
4197 element_info[element].access_direction = MV_ALL_DIRECTIONS;
4199 element_info[element].explosion_delay = 17;
4200 element_info[element].ignition_delay = 8;
4205 static void InitGlobal()
4209 for (i = 0; i < MAX_NUM_ELEMENTS + 1; i++)
4211 /* check if element_name_info entry defined for each element in "main.h" */
4212 if (i < MAX_NUM_ELEMENTS && element_name_info[i].token_name == NULL)
4213 Error(ERR_EXIT, "undefined 'element_name_info' entry for element %d", i);
4215 element_info[i].token_name = element_name_info[i].token_name;
4216 element_info[i].class_name = element_name_info[i].class_name;
4217 element_info[i].editor_description=element_name_info[i].editor_description;
4220 printf("%04d: %s\n", i, element_name_info[i].token_name);
4224 global.autoplay_leveldir = NULL;
4225 global.convert_leveldir = NULL;
4227 global.frames_per_second = 0;
4228 global.fps_slowdown = FALSE;
4229 global.fps_slowdown_factor = 1;
4232 void Execute_Command(char *command)
4236 if (strEqual(command, "print graphicsinfo.conf"))
4238 printf("# You can configure additional/alternative image files here.\n");
4239 printf("# (The entries below are default and therefore commented out.)\n");
4241 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
4243 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
4246 for (i = 0; image_config[i].token != NULL; i++)
4247 printf("# %s\n", getFormattedSetupEntry(image_config[i].token,
4248 image_config[i].value));
4252 else if (strEqual(command, "print soundsinfo.conf"))
4254 printf("# You can configure additional/alternative sound files here.\n");
4255 printf("# (The entries below are default and therefore commented out.)\n");
4257 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
4259 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
4262 for (i = 0; sound_config[i].token != NULL; i++)
4263 printf("# %s\n", getFormattedSetupEntry(sound_config[i].token,
4264 sound_config[i].value));
4268 else if (strEqual(command, "print musicinfo.conf"))
4270 printf("# You can configure additional/alternative music files here.\n");
4271 printf("# (The entries below are default and therefore commented out.)\n");
4273 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
4275 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
4278 for (i = 0; music_config[i].token != NULL; i++)
4279 printf("# %s\n", getFormattedSetupEntry(music_config[i].token,
4280 music_config[i].value));
4284 else if (strEqual(command, "print editorsetup.conf"))
4286 printf("# You can configure your personal editor element list here.\n");
4287 printf("# (The entries below are default and therefore commented out.)\n");
4290 /* this is needed to be able to check element list for cascade elements */
4291 InitElementPropertiesStatic();
4292 InitElementPropertiesEngine(GAME_VERSION_ACTUAL);
4294 PrintEditorElementList();
4298 else if (strEqual(command, "print helpanim.conf"))
4300 printf("# You can configure different element help animations here.\n");
4301 printf("# (The entries below are default and therefore commented out.)\n");
4304 for (i = 0; helpanim_config[i].token != NULL; i++)
4306 printf("# %s\n", getFormattedSetupEntry(helpanim_config[i].token,
4307 helpanim_config[i].value));
4309 if (strEqual(helpanim_config[i].token, "end"))
4315 else if (strEqual(command, "print helptext.conf"))
4317 printf("# You can configure different element help text here.\n");
4318 printf("# (The entries below are default and therefore commented out.)\n");
4321 for (i = 0; helptext_config[i].token != NULL; i++)
4322 printf("# %s\n", getFormattedSetupEntry(helptext_config[i].token,
4323 helptext_config[i].value));
4327 else if (strncmp(command, "dump level ", 11) == 0)
4329 char *filename = &command[11];
4331 if (!fileExists(filename))
4332 Error(ERR_EXIT, "cannot open file '%s'", filename);
4334 LoadLevelFromFilename(&level, filename);
4339 else if (strncmp(command, "dump tape ", 10) == 0)
4341 char *filename = &command[10];
4343 if (!fileExists(filename))
4344 Error(ERR_EXIT, "cannot open file '%s'", filename);
4346 LoadTapeFromFilename(filename);
4351 else if (strncmp(command, "autoplay ", 9) == 0)
4353 char *str_ptr = getStringCopy(&command[9]); /* read command parameters */
4355 while (*str_ptr != '\0') /* continue parsing string */
4357 /* cut leading whitespace from string, replace it by string terminator */
4358 while (*str_ptr == ' ' || *str_ptr == '\t')
4361 if (*str_ptr == '\0') /* end of string reached */
4364 if (global.autoplay_leveldir == NULL) /* read level set string */
4366 global.autoplay_leveldir = str_ptr;
4367 global.autoplay_all = TRUE; /* default: play all tapes */
4369 for (i = 0; i < MAX_TAPES_PER_SET; i++)
4370 global.autoplay_level[i] = FALSE;
4372 else /* read level number string */
4374 int level_nr = atoi(str_ptr); /* get level_nr value */
4376 if (level_nr >= 0 && level_nr < MAX_TAPES_PER_SET)
4377 global.autoplay_level[level_nr] = TRUE;
4379 global.autoplay_all = FALSE;
4382 /* advance string pointer to the next whitespace (or end of string) */
4383 while (*str_ptr != ' ' && *str_ptr != '\t' && *str_ptr != '\0')
4387 else if (strncmp(command, "convert ", 8) == 0)
4389 char *str_copy = getStringCopy(&command[8]);
4390 char *str_ptr = strchr(str_copy, ' ');
4392 global.convert_leveldir = str_copy;
4393 global.convert_level_nr = -1;
4395 if (str_ptr != NULL) /* level number follows */
4397 *str_ptr++ = '\0'; /* terminate leveldir string */
4398 global.convert_level_nr = atoi(str_ptr); /* get level_nr value */
4403 #if defined(TARGET_SDL)
4404 else if (strEqual(command, "SDL_ListModes"))
4409 SDL_Init(SDL_INIT_VIDEO);
4411 /* get available fullscreen/hardware modes */
4412 modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE);
4414 /* check if there are any modes available */
4417 printf("No modes available!\n");
4422 /* check if our resolution is restricted */
4423 if (modes == (SDL_Rect **)-1)
4425 printf("All resolutions available.\n");
4429 printf("Available Modes:\n");
4431 for(i = 0; modes[i]; i++)
4432 printf(" %d x %d\n", modes[i]->w, modes[i]->h);
4442 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
4446 static void InitSetup()
4448 LoadSetup(); /* global setup info */
4450 /* set some options from setup file */
4452 if (setup.options.verbose)
4453 options.verbose = TRUE;
4456 static void InitGameInfo()
4458 game.restart_level = FALSE;
4461 static void InitPlayerInfo()
4465 /* choose default local player */
4466 local_player = &stored_player[0];
4468 for (i = 0; i < MAX_PLAYERS; i++)
4469 stored_player[i].connected = FALSE;
4471 local_player->connected = TRUE;
4474 static void InitArtworkInfo()
4479 static char *get_string_in_brackets(char *string)
4481 char *string_in_brackets = checked_malloc(strlen(string) + 3);
4483 sprintf(string_in_brackets, "[%s]", string);
4485 return string_in_brackets;
4488 static char *get_level_id_suffix(int id_nr)
4490 char *id_suffix = checked_malloc(1 + 3 + 1);
4492 if (id_nr < 0 || id_nr > 999)
4495 sprintf(id_suffix, ".%03d", id_nr);
4501 static char *get_element_class_token(int element)
4503 char *element_class_name = element_info[element].class_name;
4504 char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
4506 sprintf(element_class_token, "[%s]", element_class_name);
4508 return element_class_token;
4511 static char *get_action_class_token(int action)
4513 char *action_class_name = &element_action_info[action].suffix[1];
4514 char *action_class_token = checked_malloc(strlen(action_class_name) + 3);
4516 sprintf(action_class_token, "[%s]", action_class_name);
4518 return action_class_token;
4522 static void InitArtworkConfig()
4524 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
4525 static char *sound_id_prefix[2 * MAX_NUM_ELEMENTS + 1];
4526 static char *music_id_prefix[NUM_MUSIC_PREFIXES + 1];
4527 static char *action_id_suffix[NUM_ACTIONS + 1];
4528 static char *direction_id_suffix[NUM_DIRECTIONS_FULL + 1];
4529 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
4530 static char *level_id_suffix[MAX_LEVELS + 1];
4531 static char *dummy[1] = { NULL };
4532 static char *ignore_generic_tokens[] =
4538 static char **ignore_image_tokens;
4539 static char **ignore_sound_tokens;
4540 static char **ignore_music_tokens;
4541 int num_ignore_generic_tokens;
4542 int num_ignore_image_tokens;
4543 int num_ignore_sound_tokens;
4544 int num_ignore_music_tokens;
4547 /* dynamically determine list of generic tokens to be ignored */
4548 num_ignore_generic_tokens = 0;
4549 for (i = 0; ignore_generic_tokens[i] != NULL; i++)
4550 num_ignore_generic_tokens++;
4552 /* dynamically determine list of image tokens to be ignored */
4553 num_ignore_image_tokens = num_ignore_generic_tokens;
4554 for (i = 0; image_config_vars[i].token != NULL; i++)
4555 num_ignore_image_tokens++;
4556 ignore_image_tokens =
4557 checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *));
4558 for (i = 0; i < num_ignore_generic_tokens; i++)
4559 ignore_image_tokens[i] = ignore_generic_tokens[i];
4560 for (i = 0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++)
4561 ignore_image_tokens[num_ignore_generic_tokens + i] =
4562 image_config_vars[i].token;
4563 ignore_image_tokens[num_ignore_image_tokens] = NULL;
4565 /* dynamically determine list of sound tokens to be ignored */
4566 num_ignore_sound_tokens = num_ignore_generic_tokens;
4567 ignore_sound_tokens =
4568 checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
4569 for (i = 0; i < num_ignore_generic_tokens; i++)
4570 ignore_sound_tokens[i] = ignore_generic_tokens[i];
4571 ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
4573 /* dynamically determine list of music tokens to be ignored */
4574 num_ignore_music_tokens = num_ignore_generic_tokens;
4575 ignore_music_tokens =
4576 checked_malloc((num_ignore_music_tokens + 1) * sizeof(char *));
4577 for (i = 0; i < num_ignore_generic_tokens; i++)
4578 ignore_music_tokens[i] = ignore_generic_tokens[i];
4579 ignore_music_tokens[num_ignore_music_tokens] = NULL;
4581 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
4582 image_id_prefix[i] = element_info[i].token_name;
4583 for (i = 0; i < NUM_FONTS; i++)
4584 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
4585 image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
4587 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
4588 sound_id_prefix[i] = element_info[i].token_name;
4589 for (i = 0; i < MAX_NUM_ELEMENTS; i++)
4590 sound_id_prefix[MAX_NUM_ELEMENTS + i] =
4591 get_string_in_brackets(element_info[i].class_name);
4592 sound_id_prefix[2 * MAX_NUM_ELEMENTS] = NULL;
4594 for (i = 0; i < NUM_MUSIC_PREFIXES; i++)
4595 music_id_prefix[i] = music_prefix_info[i].prefix;
4596 music_id_prefix[NUM_MUSIC_PREFIXES] = NULL;
4598 for (i = 0; i < NUM_ACTIONS; i++)
4599 action_id_suffix[i] = element_action_info[i].suffix;
4600 action_id_suffix[NUM_ACTIONS] = NULL;
4602 for (i = 0; i < NUM_DIRECTIONS_FULL; i++)
4603 direction_id_suffix[i] = element_direction_info[i].suffix;
4604 direction_id_suffix[NUM_DIRECTIONS_FULL] = NULL;
4606 for (i = 0; i < NUM_SPECIAL_GFX_ARGS; i++)
4607 special_id_suffix[i] = special_suffix_info[i].suffix;
4608 special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
4610 for (i = 0; i < MAX_LEVELS; i++)
4611 level_id_suffix[i] = get_level_id_suffix(i);
4612 level_id_suffix[MAX_LEVELS] = NULL;
4614 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
4615 image_id_prefix, action_id_suffix, direction_id_suffix,
4616 special_id_suffix, ignore_image_tokens);
4617 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
4618 sound_id_prefix, action_id_suffix, dummy,
4619 special_id_suffix, ignore_sound_tokens);
4620 InitMusicList(music_config, NUM_MUSIC_FILES, music_config_suffix,
4621 music_id_prefix, special_id_suffix, level_id_suffix,
4622 dummy, ignore_music_tokens);
4625 static void InitMixer()
4633 char *filename_font_initial = NULL;
4634 Bitmap *bitmap_font_initial = NULL;
4638 /* determine settings for initial font (for displaying startup messages) */
4639 for (i = 0; image_config[i].token != NULL; i++)
4641 for (j = 0; j < NUM_INITIAL_FONTS; j++)
4643 char font_token[128];
4646 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
4647 len_font_token = strlen(font_token);
4649 if (strEqual(image_config[i].token, font_token))
4650 filename_font_initial = image_config[i].value;
4651 else if (strlen(image_config[i].token) > len_font_token &&
4652 strncmp(image_config[i].token, font_token, len_font_token) == 0)
4654 if (strEqual(&image_config[i].token[len_font_token], ".x"))
4655 font_initial[j].src_x = atoi(image_config[i].value);
4656 else if (strEqual(&image_config[i].token[len_font_token], ".y"))
4657 font_initial[j].src_y = atoi(image_config[i].value);
4658 else if (strEqual(&image_config[i].token[len_font_token], ".width"))
4659 font_initial[j].width = atoi(image_config[i].value);
4660 else if (strEqual(&image_config[i].token[len_font_token],".height"))
4661 font_initial[j].height = atoi(image_config[i].value);
4666 for (j = 0; j < NUM_INITIAL_FONTS; j++)
4668 font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
4669 font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
4672 if (filename_font_initial == NULL) /* should not happen */
4673 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
4675 /* create additional image buffers for double-buffering and cross-fading */
4676 bitmap_db_cross = CreateBitmap(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH);
4677 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
4678 bitmap_db_panel = CreateBitmap(DXSIZE, DYSIZE, DEFAULT_DEPTH);
4679 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
4681 /* initialize screen properties */
4682 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
4683 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
4685 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
4686 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
4687 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
4689 bitmap_font_initial = LoadCustomImage(filename_font_initial);
4691 for (j = 0; j < NUM_INITIAL_FONTS; j++)
4692 font_initial[j].bitmap = bitmap_font_initial;
4694 InitFontGraphicInfo();
4696 font_height = getFontHeight(FC_RED);
4699 DrawInitText(getWindowTitleString(), 20, FC_YELLOW);
4701 DrawInitText(getProgramInitString(), 20, FC_YELLOW);
4703 DrawInitText(PROGRAM_COPYRIGHT_STRING, 50, FC_RED);
4704 DrawInitText(PROGRAM_WEBSITE_STRING, WIN_YSIZE - 20 - font_height, FC_RED);
4706 DrawInitText("Loading graphics", 120, FC_GREEN);
4709 void RedrawBackground()
4711 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
4712 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
4714 redraw_mask = REDRAW_ALL;
4717 void InitGfxBackground()
4721 fieldbuffer = bitmap_db_field;
4722 SetDrawtoField(DRAW_BACKBUFFER);
4726 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
4727 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
4729 for (x = 0; x < MAX_BUF_XSIZE; x++)
4730 for (y = 0; y < MAX_BUF_YSIZE; y++)
4733 redraw_mask = REDRAW_ALL;
4736 static void InitLevelInfo()
4738 LoadLevelInfo(); /* global level info */
4739 LoadLevelSetup_LastSeries(); /* last played series info */
4740 LoadLevelSetup_SeriesInfo(); /* last played level info */
4743 void InitLevelArtworkInfo()
4745 LoadLevelArtworkInfo();
4748 static void InitImages()
4750 setLevelArtworkDir(artwork.gfx_first);
4753 printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
4754 leveldir_current->identifier,
4755 artwork.gfx_current_identifier,
4756 artwork.gfx_current->identifier,
4757 leveldir_current->graphics_set,
4758 leveldir_current->graphics_path);
4761 ReloadCustomImages();
4763 LoadCustomElementDescriptions();
4764 LoadSpecialMenuDesignSettings();
4766 ReinitializeGraphics();
4769 static void InitSound(char *identifier)
4771 if (identifier == NULL)
4772 identifier = artwork.snd_current->identifier;
4774 /* set artwork path to send it to the sound server process */
4775 setLevelArtworkDir(artwork.snd_first);
4777 InitReloadCustomSounds(identifier);
4778 ReinitializeSounds();
4781 static void InitMusic(char *identifier)
4783 if (identifier == NULL)
4784 identifier = artwork.mus_current->identifier;
4786 /* set artwork path to send it to the sound server process */
4787 setLevelArtworkDir(artwork.mus_first);
4789 InitReloadCustomMusic(identifier);
4790 ReinitializeMusic();
4793 void InitNetworkServer()
4795 #if defined(NETWORK_AVALIABLE)
4799 if (!options.network)
4802 #if defined(NETWORK_AVALIABLE)
4803 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
4805 if (!ConnectToServer(options.server_host, options.server_port))
4806 Error(ERR_EXIT, "cannot connect to network game server");
4808 SendToServer_PlayerName(setup.player_name);
4809 SendToServer_ProtocolVersion();
4812 SendToServer_NrWanted(nr_wanted);
4816 static char *getNewArtworkIdentifier(int type)
4818 static char *leveldir_current_identifier[3] = { NULL, NULL, NULL };
4819 static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE };
4820 static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE };
4821 static boolean initialized[3] = { FALSE, FALSE, FALSE };
4822 TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
4823 boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type);
4824 char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type);
4825 char *leveldir_identifier = leveldir_current->identifier;
4827 /* !!! setLevelArtworkDir() should be moved to an earlier stage !!! */
4828 char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node);
4830 char *leveldir_artwork_set = LEVELDIR_ARTWORK_SET(leveldir_current, type);
4832 boolean has_level_artwork_set = (leveldir_artwork_set != NULL);
4833 char *artwork_current_identifier;
4834 char *artwork_new_identifier = NULL; /* default: nothing has changed */
4836 /* leveldir_current may be invalid (level group, parent link) */
4837 if (!validLevelSeries(leveldir_current))
4840 /* 1st step: determine artwork set to be activated in descending order:
4841 --------------------------------------------------------------------
4842 1. setup artwork (when configured to override everything else)
4843 2. artwork set configured in "levelinfo.conf" of current level set
4844 (artwork in level directory will have priority when loading later)
4845 3. artwork in level directory (stored in artwork sub-directory)
4846 4. setup artwork (currently configured in setup menu) */
4848 if (setup_override_artwork)
4849 artwork_current_identifier = setup_artwork_set;
4850 else if (leveldir_artwork_set != NULL)
4851 artwork_current_identifier = leveldir_artwork_set;
4852 else if (getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier))
4853 artwork_current_identifier = leveldir_identifier;
4855 artwork_current_identifier = setup_artwork_set;
4858 /* 2nd step: check if it is really needed to reload artwork set
4859 ------------------------------------------------------------ */
4862 if (type == ARTWORK_TYPE_GRAPHICS)
4863 printf("::: 0: '%s' ['%s', '%s'] ['%s' ('%s')]\n",
4864 artwork_new_identifier,
4865 ARTWORK_CURRENT_IDENTIFIER(artwork, type),
4866 artwork_current_identifier,
4867 leveldir_current->graphics_set,
4868 leveldir_current->identifier);
4871 /* ---------- reload if level set and also artwork set has changed ------- */
4872 if (leveldir_current_identifier[type] != leveldir_identifier &&
4873 (last_has_level_artwork_set[type] || has_level_artwork_set))
4874 artwork_new_identifier = artwork_current_identifier;
4876 leveldir_current_identifier[type] = leveldir_identifier;
4877 last_has_level_artwork_set[type] = has_level_artwork_set;
4880 if (type == ARTWORK_TYPE_GRAPHICS)
4881 printf("::: 1: '%s'\n", artwork_new_identifier);
4884 /* ---------- reload if "override artwork" setting has changed ----------- */
4885 if (last_override_level_artwork[type] != setup_override_artwork)
4886 artwork_new_identifier = artwork_current_identifier;
4888 last_override_level_artwork[type] = setup_override_artwork;
4891 if (type == ARTWORK_TYPE_GRAPHICS)
4892 printf("::: 2: '%s'\n", artwork_new_identifier);
4895 /* ---------- reload if current artwork identifier has changed ----------- */
4896 if (!strEqual(ARTWORK_CURRENT_IDENTIFIER(artwork, type),
4897 artwork_current_identifier))
4898 artwork_new_identifier = artwork_current_identifier;
4900 *(ARTWORK_CURRENT_IDENTIFIER_PTR(artwork, type))= artwork_current_identifier;
4903 if (type == ARTWORK_TYPE_GRAPHICS)
4904 printf("::: 3: '%s'\n", artwork_new_identifier);
4907 /* ---------- do not reload directly after starting ---------------------- */
4908 if (!initialized[type])
4909 artwork_new_identifier = NULL;
4911 initialized[type] = TRUE;
4914 if (type == ARTWORK_TYPE_GRAPHICS)
4915 printf("::: 4: '%s'\n", artwork_new_identifier);
4919 if (type == ARTWORK_TYPE_GRAPHICS)
4920 printf("CHECKING OLD/NEW GFX:\n- OLD: %s\n- NEW: %s ['%s', '%s'] ['%s']\n",
4921 artwork.gfx_current_identifier, artwork_current_identifier,
4922 artwork.gfx_current->identifier, leveldir_current->graphics_set,
4923 artwork_new_identifier);
4926 return artwork_new_identifier;
4929 void ReloadCustomArtwork(int force_reload)
4931 char *gfx_new_identifier;
4932 char *snd_new_identifier;
4933 char *mus_new_identifier;
4934 boolean force_reload_gfx = (force_reload & (1 << ARTWORK_TYPE_GRAPHICS));
4935 boolean force_reload_snd = (force_reload & (1 << ARTWORK_TYPE_SOUNDS));
4936 boolean force_reload_mus = (force_reload & (1 << ARTWORK_TYPE_MUSIC));
4937 boolean redraw_screen = FALSE;
4939 force_reload_gfx |= AdjustGraphicsForEMC();
4941 gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS);
4942 snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS);
4943 mus_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_MUSIC);
4945 if (gfx_new_identifier != NULL || force_reload_gfx)
4948 printf("RELOADING GRAPHICS '%s' -> '%s' ['%s', '%s']\n",
4949 artwork.gfx_current_identifier,
4951 artwork.gfx_current->identifier,
4952 leveldir_current->graphics_set);
4955 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4959 redraw_screen = TRUE;
4962 if (snd_new_identifier != NULL || force_reload_snd)
4964 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4966 InitSound(snd_new_identifier);
4968 redraw_screen = TRUE;
4971 if (mus_new_identifier != NULL || force_reload_mus)
4973 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
4975 InitMusic(mus_new_identifier);
4977 redraw_screen = TRUE;
4984 /* force redraw of (open or closed) door graphics */
4985 SetDoorState(DOOR_OPEN_ALL);
4986 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
4990 void KeyboardAutoRepeatOffUnlessAutoplay()
4992 if (global.autoplay_leveldir == NULL)
4993 KeyboardAutoRepeatOff();
4997 /* ========================================================================= */
4999 /* ========================================================================= */
5003 InitGlobal(); /* initialize some global variables */
5005 if (options.execute_command)
5006 Execute_Command(options.execute_command);
5008 if (options.serveronly)
5010 #if defined(PLATFORM_UNIX)
5011 NetworkServer(options.server_port, options.serveronly);
5013 Error(ERR_WARN, "networking only supported in Unix version");
5016 exit(0); /* never reached, server loops forever */
5023 InitArtworkInfo(); /* needed before loading gfx, sound & music */
5024 InitArtworkConfig(); /* needed before forking sound child process */
5029 InitRND(NEW_RANDOMIZE);
5030 InitSimpleRandom(NEW_RANDOMIZE);
5035 InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
5037 InitEventFilter(FilterMouseMotionEvents);
5039 InitElementPropertiesStatic();
5040 InitElementPropertiesEngine(GAME_VERSION_ACTUAL);
5044 // debug_print_timestamp(0, "INIT");
5046 // debug_print_timestamp(0, "TIME InitLevelInfo: ");
5047 InitLevelArtworkInfo();
5048 // debug_print_timestamp(0, "TIME InitLevelArtworkInfo: ");
5050 InitImages(); /* needs to know current level directory */
5051 InitSound(NULL); /* needs to know current level directory */
5052 InitMusic(NULL); /* needs to know current level directory */
5054 InitGfxBackground();
5060 if (global.autoplay_leveldir)
5065 else if (global.convert_leveldir)
5071 game_status = GAME_MODE_MAIN;
5075 InitNetworkServer();
5078 void CloseAllAndExit(int exit_value)
5083 CloseAudio(); /* called after freeing sounds (needed for SDL) */
5091 #if defined(TARGET_SDL)
5092 if (network_server) /* terminate network server */
5093 SDL_KillThread(server_thread);
5096 CloseVideoDisplay();
5097 ClosePlatformDependentStuff();
5099 if (exit_value != 0)
5100 NotifyUserAboutErrorFile();