1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
29 #include "conf_e2g.c" /* include auto-generated data structure definitions */
30 #include "conf_esg.c" /* include auto-generated data structure definitions */
33 static Bitmap *bitmap_font_initial = NULL;
35 static void InitGlobal();
36 static void InitSetup();
37 static void InitPlayerInfo();
38 static void InitLevelInfo();
39 static void InitArtworkInfo();
40 static void InitLevelArtworkInfo();
41 static void InitNetworkServer();
42 static void InitArtworkConfig();
43 static void InitImages();
44 static void InitMixer();
45 static void InitSound();
46 static void InitMusic();
47 static void InitGfx();
48 static void InitGfxBackground();
49 static void InitGadgets();
50 static void InitElementSmallImages();
51 static void InitElementGraphicInfo();
52 static void InitElementSpecialGraphicInfo();
53 static void InitElementSoundInfo();
54 static void InitElementProperties();
55 static void InitGraphicInfo();
56 static void InitSoundInfo();
57 static void Execute_Command(char *);
61 InitGlobal(); /* initialize some global variables */
63 if (options.execute_command)
64 Execute_Command(options.execute_command);
66 if (options.serveronly)
68 #if defined(PLATFORM_UNIX)
69 NetworkServer(options.server_port, options.serveronly);
71 Error(ERR_WARN, "networking only supported in Unix version");
73 exit(0); /* never reached */
76 InitProgramInfo(UNIX_USERDATA_DIRECTORY,
77 PROGRAM_TITLE_STRING, getWindowTitleString(),
78 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
79 MSDOS_POINTER_FILENAME,
80 COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
84 InitArtworkInfo(); /* needed before loading gfx, sound & music */
85 InitArtworkConfig(); /* needed before forking sound child process */
91 InitRND(NEW_RANDOMIZE);
94 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
97 InitEventFilter(FilterMouseMotionEvents);
99 InitElementProperties();
104 InitLevelArtworkInfo();
106 InitImages(); /* needs to know current level directory */
107 InitSound(); /* needs to know current level directory */
108 InitMusic(); /* needs to know current level directory */
112 if (global.autoplay_leveldir)
123 static void InitGlobal()
125 global.autoplay_leveldir = NULL;
127 global.frames_per_second = 0;
128 global.fps_slowdown = FALSE;
129 global.fps_slowdown_factor = 1;
132 static void InitSetup()
134 LoadSetup(); /* global setup info */
137 static void InitPlayerInfo()
141 /* choose default local player */
142 local_player = &stored_player[0];
144 for (i=0; i<MAX_PLAYERS; i++)
145 stored_player[i].connected = FALSE;
147 local_player->connected = TRUE;
150 static void InitLevelInfo()
152 LoadLevelInfo(); /* global level info */
153 LoadLevelSetup_LastSeries(); /* last played series info */
154 LoadLevelSetup_SeriesInfo(); /* last played level info */
157 static void InitArtworkInfo()
162 static void InitArtworkConfig()
164 static char *element_prefix[MAX_NUM_ELEMENTS + 1];
165 static char *sound_class_prefix[MAX_NUM_ELEMENTS + 1];
166 static char *action_suffix[NUM_ACTIONS + 1];
167 static char *direction_suffix[NUM_DIRECTIONS + 1];
168 static char *special_suffix[NUM_SPECIAL_GFX_ARGS + 1];
169 static char *dummy[1] = { NULL };
170 static char *ignore_image_tokens[] =
174 "menu.main.hide_static_text",
178 static char *ignore_sound_tokens[] =
186 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
187 element_prefix[i] = element_info[i].token_name;
188 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
189 sound_class_prefix[i] = element_info[i].sound_class_name;
190 for (i=0; i<NUM_ACTIONS + 1; i++)
191 action_suffix[i] = element_action_info[i].suffix;
192 for (i=0; i<NUM_DIRECTIONS + 1; i++)
193 direction_suffix[i] = element_direction_info[i].suffix;
194 for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
195 special_suffix[i] = special_suffix_info[i].suffix;
197 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
198 element_prefix, action_suffix, direction_suffix,
199 special_suffix, ignore_image_tokens);
200 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
201 sound_class_prefix, action_suffix, dummy,
202 dummy, ignore_sound_tokens);
205 void InitLevelArtworkInfo()
207 LoadLevelArtworkInfo();
210 void InitNetworkServer()
212 #if defined(PLATFORM_UNIX)
216 if (!options.network)
219 #if defined(PLATFORM_UNIX)
220 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
222 if (!ConnectToServer(options.server_host, options.server_port))
223 Error(ERR_EXIT, "cannot connect to network game server");
225 SendToServer_PlayerName(setup.player_name);
226 SendToServer_ProtocolVersion();
229 SendToServer_NrWanted(nr_wanted);
233 static void InitMixer()
239 static void ReinitializeGraphics()
241 InitElementGraphicInfo(); /* element game graphic mapping */
242 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
243 InitGraphicInfo(); /* graphic properties mapping */
245 InitElementSmallImages(); /* create editor and preview images */
247 InitFontInfo(bitmap_font_initial,
248 graphic_info[IMG_FONT_BIG].bitmap,
249 graphic_info[IMG_FONT_MEDIUM].bitmap,
250 graphic_info[IMG_FONT_SMALL].bitmap,
251 graphic_info[IMG_FONT_EM].bitmap);
253 SetMainBackgroundImage(IMG_BACKGROUND_DEFAULT);
254 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
260 static void ReinitializeSounds()
262 InitElementSoundInfo(); /* element game sound mapping */
263 InitSoundInfo(); /* sound properties mapping */
265 InitPlaySoundLevel(); /* internal game sound settings */
268 static void ReinitializeMusic()
270 /* currently nothing to do */
273 static void InitImages()
275 ReloadCustomImages();
277 LoadCustomElementDescriptions();
278 LoadSpecialMenuDesignSettings();
280 ReinitializeGraphics();
283 static void InitSound()
285 InitReloadCustomSounds(artwork.snd_current->identifier);
286 ReinitializeSounds();
289 static void InitMusic()
291 InitReloadCustomMusic(artwork.mus_current->identifier);
295 static void InitTileClipmasks()
298 #if defined(TARGET_X11)
299 XGCValues clip_gc_values;
300 unsigned long clip_gc_valuemask;
302 #if defined(TARGET_X11_NATIVE)
312 tile_needs_clipping[] =
314 { GFX_SPIELER1_UP, 4 },
315 { GFX_SPIELER1_DOWN, 4 },
316 { GFX_SPIELER1_LEFT, 4 },
317 { GFX_SPIELER1_RIGHT, 4 },
318 { GFX_SPIELER1_PUSH_LEFT, 4 },
319 { GFX_SPIELER1_PUSH_RIGHT, 4 },
320 { GFX_SPIELER2_UP, 4 },
321 { GFX_SPIELER2_DOWN, 4 },
322 { GFX_SPIELER2_LEFT, 4 },
323 { GFX_SPIELER2_RIGHT, 4 },
324 { GFX_SPIELER2_PUSH_LEFT, 4 },
325 { GFX_SPIELER2_PUSH_RIGHT, 4 },
326 { GFX_SPIELER3_UP, 4 },
327 { GFX_SPIELER3_DOWN, 4 },
328 { GFX_SPIELER3_LEFT, 4 },
329 { GFX_SPIELER3_RIGHT, 4 },
330 { GFX_SPIELER3_PUSH_LEFT, 4 },
331 { GFX_SPIELER3_PUSH_RIGHT, 4 },
332 { GFX_SPIELER4_UP, 4 },
333 { GFX_SPIELER4_DOWN, 4 },
334 { GFX_SPIELER4_LEFT, 4 },
335 { GFX_SPIELER4_RIGHT, 4 },
336 { GFX_SPIELER4_PUSH_LEFT, 4 },
337 { GFX_SPIELER4_PUSH_RIGHT, 4 },
338 { GFX_SP_MURPHY, 1 },
339 { GFX_MURPHY_GO_LEFT, 3 },
340 { GFX_MURPHY_GO_RIGHT, 3 },
341 { GFX_MURPHY_SNAP_UP, 1 },
342 { GFX_MURPHY_SNAP_DOWN, 1 },
343 { GFX_MURPHY_SNAP_RIGHT, 1 },
344 { GFX_MURPHY_SNAP_LEFT, 1 },
345 { GFX_MURPHY_PUSH_RIGHT, 1 },
346 { GFX_MURPHY_PUSH_LEFT, 1 },
347 { GFX_GEBLUBBER, 4 },
350 { GFX_EXPLOSION, 8 },
351 { GFX_SOKOBAN_OBJEKT, 1 },
352 { GFX_FUNKELN_BLAU, 3 },
353 { GFX_FUNKELN_WEISS, 3 },
354 { GFX2_SHIELD_PASSIVE, 3 },
355 { GFX2_SHIELD_ACTIVE, 3 },
360 #endif /* TARGET_X11_NATIVE */
361 #endif /* TARGET_X11 */
365 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
366 for (i=0; i<NUM_TILES; i++)
367 tile_clipmask[i] = None;
369 #if defined(TARGET_X11)
370 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
371 often very slow when preparing a masked XCopyArea() for big Pixmaps.
372 To prevent this, create small (tile-sized) mask Pixmaps which will then
373 be set much faster with XSetClipOrigin() and speed things up a lot. */
375 clip_gc_values.graphics_exposures = False;
376 clip_gc_valuemask = GCGraphicsExposures;
377 tile_clip_gc = XCreateGC(display, window->drawable,
378 clip_gc_valuemask, &clip_gc_values);
381 for (i=0; i<NUM_BITMAPS; i++)
383 if (pix[i]->clip_mask)
385 clip_gc_values.graphics_exposures = False;
386 clip_gc_values.clip_mask = pix[i]->clip_mask;
387 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
388 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
389 clip_gc_valuemask, &clip_gc_values);
394 #if defined(TARGET_X11_NATIVE)
397 /* create graphic context structures needed for clipping */
398 clip_gc_values.graphics_exposures = False;
399 clip_gc_valuemask = GCGraphicsExposures;
400 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
401 clip_gc_valuemask, &clip_gc_values);
403 /* create only those clipping Pixmaps we really need */
404 for (i=0; tile_needs_clipping[i].start>=0; i++)
408 for (j=0; j<tile_needs_clipping[i].count; j++)
410 int tile = tile_needs_clipping[i].start + j;
416 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
417 src_pixmap = src_bitmap->clip_mask;
419 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
422 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
423 src_x, src_y, TILEX, TILEY, 0, 0);
427 XFreeGC(display, copy_clipmask_gc);
430 #endif /* TARGET_X11_NATIVE */
431 #endif /* TARGET_X11 */
435 void FreeTileClipmasks()
438 #if defined(TARGET_X11)
441 for (i=0; i<NUM_TILES; i++)
443 if (tile_clipmask[i] != None)
445 XFreePixmap(display, tile_clipmask[i]);
446 tile_clipmask[i] = None;
451 XFreeGC(display, tile_clip_gc);
455 for (i=0; i<NUM_BITMAPS; i++)
457 if (pix[i] != NULL && pix[i]->stored_clip_gc)
459 XFreeGC(display, pix[i]->stored_clip_gc);
460 pix[i]->stored_clip_gc = None;
465 #endif /* TARGET_X11 */
471 char *config_token_font_initial = "font.small";
472 char *filename_font_initial = NULL;
475 /* determine filename for initial font (for displaying startup messages) */
476 for (i=0; image_config[i].token != NULL; i++)
477 if (strcmp(image_config[i].token, config_token_font_initial) == 0)
478 filename_font_initial = image_config[i].value;
480 if (filename_font_initial == NULL) /* should not happen */
481 Error(ERR_EXIT, "cannot get filename for '%s'", config_token_font_initial);
483 /* initialize screen properties */
484 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
485 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
486 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
487 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
488 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
490 /* create additional image buffers for double-buffering */
491 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
492 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
494 bitmap_font_initial = LoadCustomImage(filename_font_initial);
496 InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL);
498 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
499 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
501 DrawInitText("Loading graphics:", 120, FC_GREEN);
506 void InitGfxBackground()
511 fieldbuffer = bitmap_db_field;
512 SetDrawtoField(DRAW_BACKBUFFER);
514 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
515 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
516 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
517 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
519 for (x=0; x<MAX_BUF_XSIZE; x++)
520 for (y=0; y<MAX_BUF_YSIZE; y++)
523 redraw_mask = REDRAW_ALL;
526 void ReloadCustomArtwork()
528 static char *leveldir_current_identifier = NULL;
529 static boolean last_override_level_graphics = FALSE;
530 static boolean last_override_level_sounds = FALSE;
531 static boolean last_override_level_music = FALSE;
532 /* identifier for new artwork; default: artwork configured in setup */
533 char *gfx_new_identifier = artwork.gfx_current->identifier;
534 char *snd_new_identifier = artwork.snd_current->identifier;
535 char *mus_new_identifier = artwork.mus_current->identifier;
536 boolean redraw_screen = FALSE;
538 if (leveldir_current_identifier == NULL)
539 leveldir_current_identifier = leveldir_current->identifier;
542 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
543 leveldir_current->graphics_set);
544 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
545 leveldir_current->identifier);
549 printf("graphics --> '%s' ('%s')\n",
550 artwork.gfx_current_identifier, artwork.gfx_current->filename);
551 printf("sounds --> '%s' ('%s')\n",
552 artwork.snd_current_identifier, artwork.snd_current->filename);
553 printf("music --> '%s' ('%s')\n",
554 artwork.mus_current_identifier, artwork.mus_current->filename);
557 /* leveldir_current may be invalid (level group, parent link) */
558 if (!validLevelSeries(leveldir_current))
561 /* when a new level series was selected, check if there was a change
562 in custom artwork stored in level series directory */
563 if (leveldir_current_identifier != leveldir_current->identifier)
565 char *identifier_old = leveldir_current_identifier;
566 char *identifier_new = leveldir_current->identifier;
568 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
569 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
570 gfx_new_identifier = identifier_new;
571 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
572 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
573 snd_new_identifier = identifier_new;
574 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
575 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
576 mus_new_identifier = identifier_new;
578 leveldir_current_identifier = leveldir_current->identifier;
581 /* custom level artwork configured in level series configuration file
582 always overrides custom level artwork stored in level series directory
583 and (level independant) custom artwork configured in setup menue */
584 if (leveldir_current->graphics_set != NULL)
585 gfx_new_identifier = leveldir_current->graphics_set;
586 if (leveldir_current->sounds_set != NULL)
587 snd_new_identifier = leveldir_current->sounds_set;
588 if (leveldir_current->music_set != NULL)
589 mus_new_identifier = leveldir_current->music_set;
591 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
592 last_override_level_graphics != setup.override_level_graphics)
595 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
596 artwork.gfx_current_identifier,
597 artwork.gfx_current->identifier,
601 setLevelArtworkDir(artwork.gfx_first);
603 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
610 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
611 last_override_level_graphics = setup.override_level_graphics;
613 redraw_screen = TRUE;
616 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
617 last_override_level_sounds != setup.override_level_sounds)
620 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
621 artwork.snd_current_identifier,
622 artwork.snd_current->identifier,
626 /* set artwork path to send it to the sound server process */
627 setLevelArtworkDir(artwork.snd_first);
629 InitReloadCustomSounds(snd_new_identifier);
630 ReinitializeSounds();
632 artwork.snd_current_identifier = artwork.snd_current->identifier;
633 last_override_level_sounds = setup.override_level_sounds;
635 redraw_screen = TRUE;
638 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
639 last_override_level_music != setup.override_level_music)
641 /* set artwork path to send it to the sound server process */
642 setLevelArtworkDir(artwork.mus_first);
644 InitReloadCustomMusic(mus_new_identifier);
647 artwork.mus_current_identifier = artwork.mus_current->identifier;
648 last_override_level_music = setup.override_level_music;
650 redraw_screen = TRUE;
657 /* force redraw of (open or closed) door graphics */
658 SetDoorState(DOOR_OPEN_ALL);
659 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
665 FreeLevelEditorGadgets();
674 static boolean gadgets_initialized = FALSE;
676 if (gadgets_initialized)
679 CreateLevelEditorGadgets();
683 CreateScreenGadgets();
685 gadgets_initialized = TRUE;
688 void InitElementSmallImages()
690 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
691 int num_property_mappings = getImageListPropertyMappingSize();
694 /* initialize normal images from static configuration */
695 for (i=0; element_to_graphic[i].element > -1; i++)
696 CreateImageWithSmallImages(element_to_graphic[i].graphic);
698 /* initialize special images from static configuration */
699 for (i=0; element_to_special_graphic[i].element > -1; i++)
700 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
702 /* initialize images from dynamic configuration */
703 for (i=0; i < num_property_mappings; i++)
704 CreateImageWithSmallImages(property_mapping[i].artwork_index);
707 void InitElementGraphicInfo()
709 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
710 int num_property_mappings = getImageListPropertyMappingSize();
713 /* set values to -1 to identify later as "uninitialized" values */
714 for (i=0; i<MAX_NUM_ELEMENTS; i++)
716 for (act=0; act<NUM_ACTIONS; act++)
718 element_info[i].graphic[act] = -1;
720 for (dir=0; dir<NUM_DIRECTIONS; dir++)
721 element_info[i].direction_graphic[act][dir] = -1;
726 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
727 element_info[i].graphic[ACTION_DEFAULT] =
728 IMG_CHAR_START + (i - EL_CHAR_START);
730 for (i=EL_CUSTOM_START; i<=EL_CUSTOM_END; i++)
731 element_info[i].graphic[ACTION_DEFAULT] =
732 IMG_CUSTOM_START + (i - EL_CUSTOM_START);
735 /* initialize normal element/graphic mapping from static configuration */
736 for (i=0; element_to_graphic[i].element > -1; i++)
738 int element = element_to_graphic[i].element;
739 int action = element_to_graphic[i].action;
740 int direction = element_to_graphic[i].direction;
741 int graphic = element_to_graphic[i].graphic;
744 action = ACTION_DEFAULT;
747 element_info[element].direction_graphic[action][direction] = graphic;
749 element_info[element].graphic[action] = graphic;
752 /* initialize normal element/graphic mapping from dynamic configuration */
753 for (i=0; i < num_property_mappings; i++)
755 int element = property_mapping[i].base_index;
756 int action = property_mapping[i].ext1_index;
757 int direction = property_mapping[i].ext2_index;
758 int special = property_mapping[i].ext3_index;
759 int graphic = property_mapping[i].artwork_index;
765 action = ACTION_DEFAULT;
768 element_info[element].direction_graphic[action][direction] = graphic;
770 element_info[element].graphic[action] = graphic;
773 /* now set all '-1' values to element specific default values */
774 for (i=0; i<MAX_NUM_ELEMENTS; i++)
776 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
777 int default_action_direction_graphic[NUM_DIRECTIONS];
779 if (default_action_graphic == -1)
780 default_action_graphic = IMG_CHAR_QUESTION;
782 for (dir=0; dir<NUM_DIRECTIONS; dir++)
784 default_action_direction_graphic[dir] =
785 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
787 if (default_action_direction_graphic[dir] == -1)
788 default_action_direction_graphic[dir] = default_action_graphic;
791 for (act=0; act<NUM_ACTIONS; act++)
793 for (dir=0; dir<NUM_DIRECTIONS; dir++)
795 int default_direction_graphic = element_info[i].graphic[act];
797 /* no graphic for current action -- use default direction graphic */
798 if (default_direction_graphic == -1)
799 default_direction_graphic = default_action_direction_graphic[dir];
801 if (element_info[i].direction_graphic[act][dir] == -1)
802 element_info[i].direction_graphic[act][dir] =
803 default_direction_graphic;
806 /* no graphic for this specific action -- use default action graphic */
807 if (element_info[i].graphic[act] == -1)
808 element_info[i].graphic[act] = default_action_graphic;
816 for (i=0; i<MAX_NUM_ELEMENTS; i++)
817 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
818 i != EL_CHAR_QUESTION)
819 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
820 element_info[i].token_name, i);
826 void InitElementSpecialGraphicInfo()
828 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
829 int num_property_mappings = getImageListPropertyMappingSize();
832 /* always start with reliable default values */
833 for (i=0; i<MAX_NUM_ELEMENTS; i++)
835 element_info[i].editor_graphic = element_info[i].graphic[ACTION_DEFAULT];
836 element_info[i].preview_graphic = element_info[i].graphic[ACTION_DEFAULT];
839 /* initialize special element/graphic mapping from static configuration */
840 for (i=0; element_to_special_graphic[i].element > -1; i++)
842 int element = element_to_special_graphic[i].element;
843 int special = element_to_special_graphic[i].special;
844 int graphic = element_to_special_graphic[i].graphic;
845 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
846 boolean special_redefined = getImageListEntry(graphic)->redefined;
848 if (base_redefined && !special_redefined)
851 if (special == GFX_SPECIAL_ARG_EDITOR)
852 element_info[element].editor_graphic = graphic;
853 else if (special == GFX_SPECIAL_ARG_PREVIEW)
854 element_info[element].preview_graphic = graphic;
857 /* initialize special element/graphic mapping from dynamic configuration */
858 for (i=0; i < num_property_mappings; i++)
860 int element = property_mapping[i].base_index;
861 int special = property_mapping[i].ext3_index;
862 int graphic = property_mapping[i].artwork_index;
864 if (special == GFX_SPECIAL_ARG_EDITOR)
865 element_info[element].editor_graphic = graphic;
866 else if (special == GFX_SPECIAL_ARG_PREVIEW)
867 element_info[element].preview_graphic = graphic;
871 static void set_graphic_parameters(int graphic, char **parameter_raw)
873 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
874 int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
875 int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
876 int parameter[NUM_GFX_ARGS];
879 /* get integer values from string parameters */
880 for (i=0; i < NUM_GFX_ARGS; i++)
882 get_parameter_value(image_config_suffix[i].type, parameter_raw[i]);
884 graphic_info[graphic].bitmap = src_bitmap;
886 /* start with reliable default values */
887 graphic_info[graphic].src_x = 0;
888 graphic_info[graphic].src_y = 0;
889 graphic_info[graphic].width = TILEX;
890 graphic_info[graphic].height = TILEY;
891 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
892 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
894 /* optional x and y tile position of animation frame sequence */
895 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
896 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
897 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
898 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
900 /* optional x and y pixel position of animation frame sequence */
901 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
902 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
903 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
904 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
906 /* optional width and height of each animation frame */
907 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
908 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
909 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
910 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
912 /* correct x or y offset dependant of vertical or horizontal frame order */
913 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
915 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
916 graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
918 graphic_info[graphic].offset_y = graphic_info[graphic].height;
920 else /* frames are ordered horizontally */
922 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
923 graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
925 graphic_info[graphic].offset_x = graphic_info[graphic].width;
928 /* optionally, the x and y offset of frames can be specified directly */
929 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
930 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
931 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
932 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
934 /* automatically determine correct number of frames, if not defined */
935 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
936 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
937 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
938 graphic_info[graphic].anim_frames = num_xtiles;
939 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
940 graphic_info[graphic].anim_frames = num_ytiles;
942 graphic_info[graphic].anim_frames = 1;
944 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
945 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
946 graphic_info[graphic].anim_delay = 1;
948 /* set mode for animation frame order */
949 if (parameter[GFX_ARG_MODE_LOOP])
950 graphic_info[graphic].anim_mode = ANIM_LOOP;
951 else if (parameter[GFX_ARG_MODE_LINEAR])
952 graphic_info[graphic].anim_mode = ANIM_LINEAR;
953 else if (parameter[GFX_ARG_MODE_PINGPONG])
954 graphic_info[graphic].anim_mode = ANIM_PINGPONG;
955 else if (parameter[GFX_ARG_MODE_PINGPONG2])
956 graphic_info[graphic].anim_mode = ANIM_PINGPONG2;
957 else if (parameter[GFX_ARG_MODE_RANDOM])
958 graphic_info[graphic].anim_mode = ANIM_RANDOM;
959 else if (graphic_info[graphic].anim_frames > 1)
960 graphic_info[graphic].anim_mode = ANIM_LOOP;
962 graphic_info[graphic].anim_mode = ANIM_NONE;
964 /* set additional flag to play animation frames in reverse order */
965 if (parameter[GFX_ARG_MODE_REVERSE])
966 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
968 /* automatically determine correct start frame, if not defined */
969 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
970 graphic_info[graphic].anim_start_frame = 0;
971 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
972 graphic_info[graphic].anim_start_frame =
973 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
975 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
977 /* animation synchronized with global frame counter, not move position */
978 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
980 /* this is only used for toon animations */
981 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
982 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
985 static void InitGraphicInfo()
987 int fallback_graphic = IMG_CHAR_EXCLAM;
988 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
989 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
990 int num_images = getImageListSize();
993 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
994 static boolean clipmasks_initialized = FALSE;
996 XGCValues clip_gc_values;
997 unsigned long clip_gc_valuemask;
998 GC copy_clipmask_gc = None;
1001 if (graphic_info != NULL)
1004 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
1006 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1007 if (clipmasks_initialized)
1009 for (i=0; i<num_images; i++)
1011 if (graphic_info[i].clip_mask)
1012 XFreePixmap(display, graphic_info[i].clip_mask);
1013 if (graphic_info[i].clip_gc)
1014 XFreeGC(display, graphic_info[i].clip_gc);
1016 graphic_info[i].clip_mask = None;
1017 graphic_info[i].clip_gc = None;
1022 for (i=0; i<num_images; i++)
1024 struct FileInfo *image = getImageListEntry(i);
1027 int first_frame, last_frame;
1029 set_graphic_parameters(i, image->parameter);
1031 /* now check if no animation frames are outside of the loaded image */
1033 if (graphic_info[i].bitmap == NULL)
1034 continue; /* skip check for optional images that are undefined */
1037 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1038 if (src_x < 0 || src_y < 0 ||
1039 src_x + TILEX > src_bitmap->width ||
1040 src_y + TILEY > src_bitmap->height)
1042 Error(ERR_RETURN_LINE, "-");
1043 Error(ERR_RETURN, "warning: error found in config file:");
1044 Error(ERR_RETURN, "- config file: '%s'",
1045 getImageConfigFilename());
1046 Error(ERR_RETURN, "- config token: '%s'",
1047 getTokenFromImageID(i));
1048 Error(ERR_RETURN, "- image file: '%s'",
1049 src_bitmap->source_filename);
1051 "error: first animation frame out of bounds (%d, %d)",
1053 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1055 if (i == fallback_graphic)
1056 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1058 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1059 Error(ERR_RETURN_LINE, "-");
1061 set_graphic_parameters(i, fallback_image->default_parameter);
1062 graphic_info[i].bitmap = fallback_bitmap;
1065 last_frame = graphic_info[i].anim_frames - 1;
1066 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1067 if (src_x < 0 || src_y < 0 ||
1068 src_x + TILEX > src_bitmap->width ||
1069 src_y + TILEY > src_bitmap->height)
1071 Error(ERR_RETURN_LINE, "-");
1072 Error(ERR_RETURN, "warning: error found in config file:");
1073 Error(ERR_RETURN, "- config file: '%s'",
1074 getImageConfigFilename());
1075 Error(ERR_RETURN, "- config token: '%s'",
1076 getTokenFromImageID(i));
1077 Error(ERR_RETURN, "- image file: '%s'",
1078 src_bitmap->source_filename);
1080 "error: last animation frame (%d) out of bounds (%d, %d)",
1081 last_frame, src_x, src_y);
1082 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1084 if (i == fallback_graphic)
1085 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1087 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1088 Error(ERR_RETURN_LINE, "-");
1090 set_graphic_parameters(i, fallback_image->default_parameter);
1091 graphic_info[i].bitmap = fallback_bitmap;
1094 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1095 /* currently we need only a tile clip mask from the first frame */
1096 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1098 if (copy_clipmask_gc == None)
1100 clip_gc_values.graphics_exposures = False;
1101 clip_gc_valuemask = GCGraphicsExposures;
1102 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1103 clip_gc_valuemask, &clip_gc_values);
1106 graphic_info[i].clip_mask =
1107 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1109 src_pixmap = src_bitmap->clip_mask;
1110 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1111 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1113 clip_gc_values.graphics_exposures = False;
1114 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1115 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1117 graphic_info[i].clip_gc =
1118 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1122 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1123 if (copy_clipmask_gc)
1124 XFreeGC(display, copy_clipmask_gc);
1126 clipmasks_initialized = TRUE;
1130 static void InitElementSoundInfo()
1132 /* !!! soon to come !!! */
1135 static void set_sound_parameters(int sound, char **parameter_raw)
1137 int parameter[NUM_SND_ARGS];
1140 /* get integer values from string parameters */
1141 for (i=0; i < NUM_SND_ARGS; i++)
1143 get_parameter_value(sound_config_suffix[i].type, parameter_raw[i]);
1145 /* explicit loop mode setting in configuration overrides default value */
1146 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1147 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1150 static void InitSoundInfo()
1152 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1153 int num_property_mappings = getSoundListPropertyMappingSize();
1154 int *sound_effect_properties;
1155 int num_sounds = getSoundListSize();
1158 if (sound_info != NULL)
1161 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1162 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1164 /* initialize sound effect for all elements to "no sound" */
1165 for (i=0; i<MAX_NUM_ELEMENTS; i++)
1166 for (j=0; j<NUM_ACTIONS; j++)
1167 element_info[i].sound[j] = SND_UNDEFINED;
1169 for (i=0; i<num_sounds; i++)
1171 struct FileInfo *sound = getSoundListEntry(i);
1172 int len_effect_text = strlen(sound->token);
1174 sound_effect_properties[i] = ACTION_OTHER;
1175 sound_info[i].loop = FALSE;
1177 /* determine all loop sounds and identify certain sound classes */
1179 for (j=0; element_action_info[j].suffix; j++)
1181 int len_action_text = strlen(element_action_info[j].suffix);
1183 if (len_action_text < len_effect_text &&
1184 strcmp(&sound->token[len_effect_text - len_action_text],
1185 element_action_info[j].suffix) == 0)
1187 sound_effect_properties[i] = element_action_info[j].value;
1189 if (element_action_info[j].is_loop_sound)
1190 sound_info[i].loop = TRUE;
1194 /* associate elements and some selected sound actions */
1196 for (j=0; j<MAX_NUM_ELEMENTS; j++)
1198 if (element_info[j].sound_class_name)
1200 int len_class_text = strlen(element_info[j].sound_class_name);
1202 if (len_class_text + 1 < len_effect_text &&
1203 strncmp(sound->token,
1204 element_info[j].sound_class_name, len_class_text) == 0 &&
1205 sound->token[len_class_text] == '.')
1207 int sound_action_value = sound_effect_properties[i];
1209 element_info[j].sound[sound_action_value] = i;
1214 set_sound_parameters(i, sound->parameter);
1217 free(sound_effect_properties);
1219 /* initialize element/sound mapping from dynamic configuration */
1220 for (i=0; i < num_property_mappings; i++)
1222 int element = property_mapping[i].base_index;
1223 int action = property_mapping[i].ext1_index;
1224 int sound = property_mapping[i].artwork_index;
1227 action = ACTION_DEFAULT;
1229 element_info[element].sound[action] = sound;
1235 int element = EL_CUSTOM_11;
1238 while (element_action_info[j].suffix)
1240 printf("element %d, sound action '%s' == %d\n",
1241 element, element_action_info[j].suffix,
1242 element_info[element].sound[j]);
1247 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1253 int element = EL_SAND;
1254 int sound_action = ACTION_DIGGING;
1257 while (element_action_info[j].suffix)
1259 if (element_action_info[j].value == sound_action)
1260 printf("element %d, sound action '%s' == %d\n",
1261 element, element_action_info[j].suffix,
1262 element_info[element].sound[sound_action]);
1269 void InitElementProperties()
1273 static int ep_amoebalive[] =
1280 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
1282 static int ep_amoeboid[] =
1290 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
1292 static int ep_schluessel[] =
1303 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
1305 static int ep_pforte[] =
1324 EL_SWITCHGATE_OPENING,
1325 EL_SWITCHGATE_CLOSED,
1326 EL_SWITCHGATE_CLOSING,
1328 EL_TIMEGATE_OPENING,
1330 EL_TIMEGATE_CLOSING,
1334 EL_TUBE_VERTICAL_LEFT,
1335 EL_TUBE_VERTICAL_RIGHT,
1336 EL_TUBE_HORIZONTAL_UP,
1337 EL_TUBE_HORIZONTAL_DOWN,
1343 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
1345 static int ep_solid[] =
1364 EL_QUICKSAND_FILLING,
1365 EL_QUICKSAND_EMPTYING,
1367 EL_MAGIC_WALL_ACTIVE,
1368 EL_MAGIC_WALL_EMPTYING,
1369 EL_MAGIC_WALL_FILLING,
1373 EL_BD_MAGIC_WALL_ACTIVE,
1374 EL_BD_MAGIC_WALL_EMPTYING,
1375 EL_BD_MAGIC_WALL_FULL,
1376 EL_BD_MAGIC_WALL_FILLING,
1377 EL_BD_MAGIC_WALL_DEAD,
1386 EL_SP_TERMINAL_ACTIVE,
1390 EL_INVISIBLE_WALL_ACTIVE,
1391 EL_SWITCHGATE_SWITCH_UP,
1392 EL_SWITCHGATE_SWITCH_DOWN,
1394 EL_TIMEGATE_SWITCH_ACTIVE,
1395 EL_EMC_WALL_PILLAR_UPPER,
1396 EL_EMC_WALL_PILLAR_MIDDLE,
1397 EL_EMC_WALL_PILLAR_LOWER,
1406 /* the following elements are a direct copy of "indestructible" elements,
1407 except "EL_ACID", which is "indestructible", but not "solid"! */
1412 EL_ACIDPOOL_TOPLEFT,
1413 EL_ACIDPOOL_TOPRIGHT,
1414 EL_ACIDPOOL_BOTTOMLEFT,
1416 EL_ACIDPOOL_BOTTOMRIGHT,
1428 EL_INVISIBLE_STEELWALL,
1429 EL_INVISIBLE_STEELWALL_ACTIVE,
1430 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1431 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1432 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1433 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1434 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1435 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1436 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1437 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1438 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1439 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1440 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1441 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1443 EL_LIGHT_SWITCH_ACTIVE,
1444 EL_SIGN_EXCLAMATION,
1445 EL_SIGN_RADIOACTIVITY,
1456 EL_STEELWALL_SLANTED,
1479 EL_SWITCHGATE_OPENING,
1480 EL_SWITCHGATE_CLOSED,
1481 EL_SWITCHGATE_CLOSING,
1483 EL_TIMEGATE_OPENING,
1485 EL_TIMEGATE_CLOSING,
1489 EL_TUBE_VERTICAL_LEFT,
1490 EL_TUBE_VERTICAL_RIGHT,
1491 EL_TUBE_HORIZONTAL_UP,
1492 EL_TUBE_HORIZONTAL_DOWN,
1498 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1500 static int ep_indestructible[] =
1504 EL_ACIDPOOL_TOPLEFT,
1505 EL_ACIDPOOL_TOPRIGHT,
1506 EL_ACIDPOOL_BOTTOMLEFT,
1508 EL_ACIDPOOL_BOTTOMRIGHT,
1520 EL_INVISIBLE_STEELWALL,
1521 EL_INVISIBLE_STEELWALL_ACTIVE,
1522 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1523 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1524 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1525 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1526 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1527 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1528 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1529 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1530 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1531 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1532 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1533 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1535 EL_LIGHT_SWITCH_ACTIVE,
1536 EL_SIGN_EXCLAMATION,
1537 EL_SIGN_RADIOACTIVITY,
1548 EL_STEELWALL_SLANTED,
1571 EL_SWITCHGATE_OPENING,
1572 EL_SWITCHGATE_CLOSED,
1573 EL_SWITCHGATE_CLOSING,
1575 EL_TIMEGATE_OPENING,
1577 EL_TIMEGATE_CLOSING,
1581 EL_TUBE_VERTICAL_LEFT,
1582 EL_TUBE_VERTICAL_RIGHT,
1583 EL_TUBE_HORIZONTAL_UP,
1584 EL_TUBE_HORIZONTAL_DOWN,
1590 static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible);
1592 static int ep_slippery[] =
1606 EL_ROBOT_WHEEL_ACTIVE,
1612 EL_ACIDPOOL_TOPLEFT,
1613 EL_ACIDPOOL_TOPRIGHT,
1623 EL_STEELWALL_SLANTED,
1627 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1629 static int ep_enemy[] =
1642 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1644 static int ep_mauer[] =
1672 EL_WALL_GROWING_ACTIVE,
1691 EL_SP_TERMINAL_ACTIVE,
1694 EL_INVISIBLE_STEELWALL,
1695 EL_INVISIBLE_STEELWALL_ACTIVE,
1697 EL_INVISIBLE_WALL_ACTIVE,
1698 EL_STEELWALL_SLANTED,
1703 EL_EMC_WALL_PILLAR_UPPER,
1704 EL_EMC_WALL_PILLAR_MIDDLE,
1705 EL_EMC_WALL_PILLAR_LOWER,
1712 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1714 static int ep_can_fall[] =
1729 EL_BD_MAGIC_WALL_FULL,
1740 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1742 static int ep_can_smash[] =
1765 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1767 static int ep_can_change[] =
1778 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1780 static int ep_can_move[] =
1800 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1802 static int ep_could_move[] =
1812 EL_BD_BUTTERFLY_RIGHT,
1814 EL_BD_BUTTERFLY_LEFT,
1815 EL_BD_BUTTERFLY_DOWN,
1816 EL_BD_FIREFLY_RIGHT,
1825 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1827 static int ep_dont_touch[] =
1834 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1836 static int ep_dont_go_to[] =
1850 EL_SP_BUGGY_BASE_ACTIVE,
1854 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
1856 static int ep_mampf2[] =
1881 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1883 static int ep_bd_element[] =
1910 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1912 static int ep_sb_element[] =
1917 EL_SOKOBAN_FIELD_EMPTY,
1918 EL_SOKOBAN_FIELD_FULL,
1920 EL_INVISIBLE_STEELWALL
1922 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1924 static int ep_gem[] =
1933 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1935 static int ep_inactive[] =
1972 EL_INVISIBLE_STEELWALL,
1980 EL_WALL_EMERALD_YELLOW,
1985 EL_SOKOBAN_FIELD_EMPTY,
1986 EL_SOKOBAN_FIELD_FULL,
1987 EL_WALL_EMERALD_RED,
1988 EL_WALL_EMERALD_PURPLE,
1989 EL_ACIDPOOL_TOPLEFT,
1990 EL_ACIDPOOL_TOPRIGHT,
1991 EL_ACIDPOOL_BOTTOMLEFT,
1993 EL_ACIDPOOL_BOTTOMRIGHT,
1997 EL_BD_MAGIC_WALL_DEAD,
1998 EL_AMOEBA_TO_DIAMOND,
2031 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2032 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2033 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2034 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2035 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2036 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2037 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2038 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2039 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2040 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2041 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2042 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2043 EL_SIGN_EXCLAMATION,
2044 EL_SIGN_RADIOACTIVITY,
2055 EL_STEELWALL_SLANTED,
2060 EL_EMC_WALL_PILLAR_UPPER,
2061 EL_EMC_WALL_PILLAR_MIDDLE,
2062 EL_EMC_WALL_PILLAR_LOWER,
2069 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
2071 static int ep_explosive[] =
2076 EL_DYNABOMB_PLAYER1_ACTIVE,
2077 EL_DYNABOMB_PLAYER2_ACTIVE,
2078 EL_DYNABOMB_PLAYER3_ACTIVE,
2079 EL_DYNABOMB_PLAYER4_ACTIVE,
2096 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
2098 static int ep_mampf3[] =
2109 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
2111 static int ep_pushable[] =
2118 EL_SOKOBAN_FIELD_FULL,
2128 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
2130 static int ep_player[] =
2137 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
2139 static int ep_has_content[] =
2147 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
2149 static int ep_eatable[] =
2154 EL_SP_BUGGY_BASE_ACTIVATING,
2157 EL_INVISIBLE_SAND_ACTIVE
2159 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
2161 static int ep_sp_element[] =
2204 /* additional elements that appeared in newer Supaplex levels */
2206 /* more than one murphy in a level results in an inactive clone */
2209 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
2211 static int ep_quick_gate[] =
2235 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
2237 static int ep_over_player[] =
2253 EL_TUBE_VERTICAL_LEFT,
2254 EL_TUBE_VERTICAL_RIGHT,
2255 EL_TUBE_HORIZONTAL_UP,
2256 EL_TUBE_HORIZONTAL_DOWN,
2262 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
2264 static int ep_active_bomb[] =
2267 EL_DYNABOMB_PLAYER1_ACTIVE,
2268 EL_DYNABOMB_PLAYER2_ACTIVE,
2269 EL_DYNABOMB_PLAYER3_ACTIVE,
2270 EL_DYNABOMB_PLAYER4_ACTIVE
2272 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
2274 static int ep_belt[] =
2276 EL_CONVEYOR_BELT1_LEFT,
2277 EL_CONVEYOR_BELT1_MIDDLE,
2278 EL_CONVEYOR_BELT1_RIGHT,
2279 EL_CONVEYOR_BELT2_LEFT,
2280 EL_CONVEYOR_BELT2_MIDDLE,
2281 EL_CONVEYOR_BELT2_RIGHT,
2282 EL_CONVEYOR_BELT3_LEFT,
2283 EL_CONVEYOR_BELT3_MIDDLE,
2284 EL_CONVEYOR_BELT3_RIGHT,
2285 EL_CONVEYOR_BELT4_LEFT,
2286 EL_CONVEYOR_BELT4_MIDDLE,
2287 EL_CONVEYOR_BELT4_RIGHT,
2289 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
2291 static int ep_belt_active[] =
2293 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
2294 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
2295 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
2296 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
2297 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
2298 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
2299 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
2300 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
2301 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
2302 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
2303 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
2304 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
2306 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
2308 static int ep_belt_switch[] =
2310 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2311 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2312 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2313 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2314 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2315 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2316 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2317 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2318 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2319 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2320 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2321 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2323 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
2325 static int ep_tube[] =
2330 EL_TUBE_VERTICAL_LEFT,
2331 EL_TUBE_VERTICAL_RIGHT,
2332 EL_TUBE_HORIZONTAL_UP,
2333 EL_TUBE_HORIZONTAL_DOWN,
2339 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
2341 static long ep1_bit[] =
2348 EP_BIT_INDESTRUCTIBLE,
2375 static long ep2_bit[] =
2382 static int *ep1_array[] =
2416 static int *ep2_array[] =
2423 static int *ep1_num[] =
2430 &ep_indestructible_num,
2450 &ep_has_content_num,
2454 &ep_over_player_num,
2457 static int *ep2_num[] =
2460 &ep_belt_active_num,
2461 &ep_belt_switch_num,
2464 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2465 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2467 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2473 for (i=0; i<num_properties1; i++)
2474 for (j=0; j<*(ep1_num[i]); j++)
2475 Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
2476 for (i=0; i<num_properties2; i++)
2477 for (j=0; j<*(ep2_num[i]); j++)
2478 Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
2480 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2481 Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2484 void Execute_Command(char *command)
2486 if (strcmp(command, "print graphicsinfo.conf") == 0)
2490 printf("# You can configure additional/alternative image files here.\n");
2491 printf("# (The images below are default and therefore commented out.)\n");
2493 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2495 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2498 for (i=0; image_config[i].token != NULL; i++)
2500 getFormattedSetupEntry(image_config[i].token,
2501 image_config[i].value));
2505 else if (strcmp(command, "print soundsinfo.conf") == 0)
2509 printf("# You can configure additional/alternative sound files here.\n");
2510 printf("# (The sounds below are default and therefore commented out.)\n");
2512 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2514 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2517 for (i=0; sound_config[i].token != NULL; i++)
2519 getFormattedSetupEntry(sound_config[i].token,
2520 sound_config[i].value));
2524 else if (strcmp(command, "print musicinfo.conf") == 0)
2526 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2528 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2530 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2534 else if (strncmp(command, "dump level ", 11) == 0)
2536 char *filename = &command[11];
2538 if (access(filename, F_OK) != 0)
2539 Error(ERR_EXIT, "cannot open file '%s'", filename);
2541 LoadLevelFromFilename(filename);
2546 else if (strncmp(command, "dump tape ", 10) == 0)
2548 char *filename = &command[10];
2550 if (access(filename, F_OK) != 0)
2551 Error(ERR_EXIT, "cannot open file '%s'", filename);
2553 LoadTapeFromFilename(filename);
2558 else if (strncmp(command, "autoplay ", 9) == 0)
2560 char *str_copy = getStringCopy(&command[9]);
2561 char *str_ptr = strchr(str_copy, ' ');
2563 global.autoplay_leveldir = str_copy;
2564 global.autoplay_level_nr = -1;
2566 if (str_ptr != NULL)
2568 *str_ptr++ = '\0'; /* terminate leveldir string */
2569 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2574 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2578 void CloseAllAndExit(int exit_value)
2583 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2586 FreeTileClipmasks();
2588 if (bitmap_font_initial)
2589 FreeBitmap(bitmap_font_initial);
2591 CloseVideoDisplay();
2592 ClosePlatformDependantStuff();