1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
29 #include "conf_e2g.c" /* include auto-generated data structure definitions */
30 #include "conf_esg.c" /* include auto-generated data structure definitions */
31 #include "conf_fnt.c" /* include auto-generated data structure definitions */
33 #define CONFIG_TOKEN_FONT_INITIAL "font.initial"
35 struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
37 static void InitGlobal();
38 static void InitSetup();
39 static void InitPlayerInfo();
40 static void InitLevelInfo();
41 static void InitArtworkInfo();
42 static void InitLevelArtworkInfo();
43 static void InitNetworkServer();
44 static void InitArtworkConfig();
45 static void InitImages();
46 static void InitMixer();
47 static void InitSound();
48 static void InitMusic();
49 static void InitGfx();
50 static void InitGfxBackground();
51 static void InitGadgets();
52 static void InitFontGraphicInfo();
53 static void InitElementSmallImages();
54 static void InitElementGraphicInfo();
55 static void InitElementSpecialGraphicInfo();
56 static void InitElementSoundInfo();
57 static void InitElementProperties();
58 static void InitGraphicInfo();
59 static void InitSoundInfo();
60 static void Execute_Command(char *);
64 InitGlobal(); /* initialize some global variables */
66 if (options.execute_command)
67 Execute_Command(options.execute_command);
69 if (options.serveronly)
71 #if defined(PLATFORM_UNIX)
72 NetworkServer(options.server_port, options.serveronly);
74 Error(ERR_WARN, "networking only supported in Unix version");
76 exit(0); /* never reached */
79 InitProgramInfo(UNIX_USERDATA_DIRECTORY,
80 PROGRAM_TITLE_STRING, getWindowTitleString(),
81 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
82 MSDOS_POINTER_FILENAME,
83 COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
87 InitArtworkInfo(); /* needed before loading gfx, sound & music */
88 InitArtworkConfig(); /* needed before forking sound child process */
94 InitRND(NEW_RANDOMIZE);
97 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
100 InitEventFilter(FilterMouseMotionEvents);
102 InitElementProperties();
107 InitLevelArtworkInfo();
109 InitImages(); /* needs to know current level directory */
110 InitSound(); /* needs to know current level directory */
111 InitMusic(); /* needs to know current level directory */
115 if (global.autoplay_leveldir)
121 game_status = MAINMENU;
128 static void InitGlobal()
130 global.autoplay_leveldir = NULL;
132 global.frames_per_second = 0;
133 global.fps_slowdown = FALSE;
134 global.fps_slowdown_factor = 1;
137 static void InitSetup()
139 LoadSetup(); /* global setup info */
142 static void InitPlayerInfo()
146 /* choose default local player */
147 local_player = &stored_player[0];
149 for (i=0; i<MAX_PLAYERS; i++)
150 stored_player[i].connected = FALSE;
152 local_player->connected = TRUE;
155 static void InitLevelInfo()
157 LoadLevelInfo(); /* global level info */
158 LoadLevelSetup_LastSeries(); /* last played series info */
159 LoadLevelSetup_SeriesInfo(); /* last played level info */
162 static void InitArtworkInfo()
167 static void InitArtworkConfig()
169 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
170 static char *sound_id_prefix[MAX_NUM_ELEMENTS + 1];
171 static char *action_id_suffix[NUM_ACTIONS + 1];
172 static char *direction_id_suffix[NUM_DIRECTIONS + 1];
173 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
174 static char *dummy[1] = { NULL };
175 static char *ignore_image_tokens[] =
179 "menu.main.hide_static_text",
183 static char *ignore_sound_tokens[] =
191 for (i=0; i<MAX_NUM_ELEMENTS; i++)
192 image_id_prefix[i] = element_info[i].token_name;
193 for (i=0; i<NUM_FONTS + 1; i++)
194 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
196 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
197 sound_id_prefix[i] = element_info[i].sound_class_name;
199 for (i=0; i<NUM_ACTIONS + 1; i++)
200 action_id_suffix[i] = element_action_info[i].suffix;
202 for (i=0; i<NUM_DIRECTIONS + 1; i++)
203 direction_id_suffix[i] = element_direction_info[i].suffix;
205 for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
206 special_id_suffix[i] = special_suffix_info[i].suffix;
208 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
209 image_id_prefix, action_id_suffix, direction_id_suffix,
210 special_id_suffix, ignore_image_tokens);
211 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
212 sound_id_prefix, action_id_suffix, dummy,
213 dummy, ignore_sound_tokens);
216 void InitLevelArtworkInfo()
218 LoadLevelArtworkInfo();
221 void InitNetworkServer()
223 #if defined(PLATFORM_UNIX)
227 if (!options.network)
230 #if defined(PLATFORM_UNIX)
231 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
233 if (!ConnectToServer(options.server_host, options.server_port))
234 Error(ERR_EXIT, "cannot connect to network game server");
236 SendToServer_PlayerName(setup.player_name);
237 SendToServer_ProtocolVersion();
240 SendToServer_NrWanted(nr_wanted);
244 static void InitMixer()
250 static void ReinitializeGraphics()
252 InitElementGraphicInfo(); /* element game graphic mapping */
253 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
254 InitGraphicInfo(); /* graphic properties mapping */
256 InitElementSmallImages(); /* create editor and preview images */
257 InitFontGraphicInfo(); /* initialize text drawing functions */
259 SetMainBackgroundImage(IMG_BACKGROUND);
260 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
266 static void ReinitializeSounds()
268 InitElementSoundInfo(); /* element game sound mapping */
269 InitSoundInfo(); /* sound properties mapping */
271 InitPlaySoundLevel(); /* internal game sound settings */
274 static void ReinitializeMusic()
276 /* currently nothing to do */
279 static void InitImages()
281 ReloadCustomImages();
283 LoadCustomElementDescriptions();
284 LoadSpecialMenuDesignSettings();
286 ReinitializeGraphics();
289 static void InitSound()
291 InitReloadCustomSounds(artwork.snd_current->identifier);
292 ReinitializeSounds();
295 static void InitMusic()
297 InitReloadCustomMusic(artwork.mus_current->identifier);
301 static void InitTileClipmasks()
304 #if defined(TARGET_X11)
305 XGCValues clip_gc_values;
306 unsigned long clip_gc_valuemask;
308 #if defined(TARGET_X11_NATIVE)
318 tile_needs_clipping[] =
320 { GFX_SPIELER1_UP, 4 },
321 { GFX_SPIELER1_DOWN, 4 },
322 { GFX_SPIELER1_LEFT, 4 },
323 { GFX_SPIELER1_RIGHT, 4 },
324 { GFX_SPIELER1_PUSH_LEFT, 4 },
325 { GFX_SPIELER1_PUSH_RIGHT, 4 },
326 { GFX_SPIELER2_UP, 4 },
327 { GFX_SPIELER2_DOWN, 4 },
328 { GFX_SPIELER2_LEFT, 4 },
329 { GFX_SPIELER2_RIGHT, 4 },
330 { GFX_SPIELER2_PUSH_LEFT, 4 },
331 { GFX_SPIELER2_PUSH_RIGHT, 4 },
332 { GFX_SPIELER3_UP, 4 },
333 { GFX_SPIELER3_DOWN, 4 },
334 { GFX_SPIELER3_LEFT, 4 },
335 { GFX_SPIELER3_RIGHT, 4 },
336 { GFX_SPIELER3_PUSH_LEFT, 4 },
337 { GFX_SPIELER3_PUSH_RIGHT, 4 },
338 { GFX_SPIELER4_UP, 4 },
339 { GFX_SPIELER4_DOWN, 4 },
340 { GFX_SPIELER4_LEFT, 4 },
341 { GFX_SPIELER4_RIGHT, 4 },
342 { GFX_SPIELER4_PUSH_LEFT, 4 },
343 { GFX_SPIELER4_PUSH_RIGHT, 4 },
344 { GFX_SP_MURPHY, 1 },
345 { GFX_MURPHY_GO_LEFT, 3 },
346 { GFX_MURPHY_GO_RIGHT, 3 },
347 { GFX_MURPHY_SNAP_UP, 1 },
348 { GFX_MURPHY_SNAP_DOWN, 1 },
349 { GFX_MURPHY_SNAP_RIGHT, 1 },
350 { GFX_MURPHY_SNAP_LEFT, 1 },
351 { GFX_MURPHY_PUSH_RIGHT, 1 },
352 { GFX_MURPHY_PUSH_LEFT, 1 },
353 { GFX_GEBLUBBER, 4 },
356 { GFX_EXPLOSION, 8 },
357 { GFX_SOKOBAN_OBJEKT, 1 },
358 { GFX_FUNKELN_BLAU, 3 },
359 { GFX_FUNKELN_WEISS, 3 },
360 { GFX2_SHIELD_PASSIVE, 3 },
361 { GFX2_SHIELD_ACTIVE, 3 },
366 #endif /* TARGET_X11_NATIVE */
367 #endif /* TARGET_X11 */
371 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
372 for (i=0; i<NUM_TILES; i++)
373 tile_clipmask[i] = None;
375 #if defined(TARGET_X11)
376 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
377 often very slow when preparing a masked XCopyArea() for big Pixmaps.
378 To prevent this, create small (tile-sized) mask Pixmaps which will then
379 be set much faster with XSetClipOrigin() and speed things up a lot. */
381 clip_gc_values.graphics_exposures = False;
382 clip_gc_valuemask = GCGraphicsExposures;
383 tile_clip_gc = XCreateGC(display, window->drawable,
384 clip_gc_valuemask, &clip_gc_values);
387 for (i=0; i<NUM_BITMAPS; i++)
389 if (pix[i]->clip_mask)
391 clip_gc_values.graphics_exposures = False;
392 clip_gc_values.clip_mask = pix[i]->clip_mask;
393 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
394 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
395 clip_gc_valuemask, &clip_gc_values);
400 #if defined(TARGET_X11_NATIVE)
403 /* create graphic context structures needed for clipping */
404 clip_gc_values.graphics_exposures = False;
405 clip_gc_valuemask = GCGraphicsExposures;
406 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
407 clip_gc_valuemask, &clip_gc_values);
409 /* create only those clipping Pixmaps we really need */
410 for (i=0; tile_needs_clipping[i].start>=0; i++)
414 for (j=0; j<tile_needs_clipping[i].count; j++)
416 int tile = tile_needs_clipping[i].start + j;
422 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
423 src_pixmap = src_bitmap->clip_mask;
425 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
428 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
429 src_x, src_y, TILEX, TILEY, 0, 0);
433 XFreeGC(display, copy_clipmask_gc);
436 #endif /* TARGET_X11_NATIVE */
437 #endif /* TARGET_X11 */
441 void FreeTileClipmasks()
444 #if defined(TARGET_X11)
447 for (i=0; i<NUM_TILES; i++)
449 if (tile_clipmask[i] != None)
451 XFreePixmap(display, tile_clipmask[i]);
452 tile_clipmask[i] = None;
457 XFreeGC(display, tile_clip_gc);
461 for (i=0; i<NUM_BITMAPS; i++)
463 if (pix[i] != NULL && pix[i]->stored_clip_gc)
465 XFreeGC(display, pix[i]->stored_clip_gc);
466 pix[i]->stored_clip_gc = None;
471 #endif /* TARGET_X11 */
477 char *filename_font_initial = NULL;
478 Bitmap *bitmap_font_initial = NULL;
481 /* determine settings for initial font (for displaying startup messages) */
482 for (i=0; image_config[i].token != NULL; i++)
484 for (j=0; j < NUM_INITIAL_FONTS; j++)
486 char font_token[128];
489 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
490 len_font_token = strlen(font_token);
492 if (strcmp(image_config[i].token, font_token) == 0)
493 filename_font_initial = image_config[i].value;
494 else if (strlen(image_config[i].token) > len_font_token &&
495 strncmp(image_config[i].token, font_token, len_font_token) == 0)
497 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
498 font_initial[j].src_x = atoi(image_config[i].value);
499 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
500 font_initial[j].src_y = atoi(image_config[i].value);
501 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
502 font_initial[j].width = atoi(image_config[i].value);
503 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
504 font_initial[j].height = atoi(image_config[i].value);
509 if (filename_font_initial == NULL) /* should not happen */
510 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
512 /* initialize screen properties */
513 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
514 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
515 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
516 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
517 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
519 /* create additional image buffers for double-buffering */
520 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
521 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
523 bitmap_font_initial = LoadCustomImage(filename_font_initial);
525 for (j=0; j < NUM_INITIAL_FONTS; j++)
526 font_initial[j].bitmap = bitmap_font_initial;
528 InitFontGraphicInfo();
530 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
531 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
533 DrawInitText("Loading graphics:", 120, FC_GREEN);
538 void InitGfxBackground()
543 fieldbuffer = bitmap_db_field;
544 SetDrawtoField(DRAW_BACKBUFFER);
546 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
547 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
548 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
549 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
551 for (x=0; x<MAX_BUF_XSIZE; x++)
552 for (y=0; y<MAX_BUF_YSIZE; y++)
555 redraw_mask = REDRAW_ALL;
558 void ReloadCustomArtwork()
560 static char *leveldir_current_identifier = NULL;
561 static boolean last_override_level_graphics = FALSE;
562 static boolean last_override_level_sounds = FALSE;
563 static boolean last_override_level_music = FALSE;
564 /* identifier for new artwork; default: artwork configured in setup */
565 char *gfx_new_identifier = artwork.gfx_current->identifier;
566 char *snd_new_identifier = artwork.snd_current->identifier;
567 char *mus_new_identifier = artwork.mus_current->identifier;
568 boolean redraw_screen = FALSE;
570 if (leveldir_current_identifier == NULL)
571 leveldir_current_identifier = leveldir_current->identifier;
574 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
575 leveldir_current->graphics_set);
576 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
577 leveldir_current->identifier);
581 printf("graphics --> '%s' ('%s')\n",
582 artwork.gfx_current_identifier, artwork.gfx_current->filename);
583 printf("sounds --> '%s' ('%s')\n",
584 artwork.snd_current_identifier, artwork.snd_current->filename);
585 printf("music --> '%s' ('%s')\n",
586 artwork.mus_current_identifier, artwork.mus_current->filename);
589 /* leveldir_current may be invalid (level group, parent link) */
590 if (!validLevelSeries(leveldir_current))
593 /* when a new level series was selected, check if there was a change
594 in custom artwork stored in level series directory */
595 if (leveldir_current_identifier != leveldir_current->identifier)
597 char *identifier_old = leveldir_current_identifier;
598 char *identifier_new = leveldir_current->identifier;
600 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
601 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
602 gfx_new_identifier = identifier_new;
603 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
604 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
605 snd_new_identifier = identifier_new;
606 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
607 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
608 mus_new_identifier = identifier_new;
610 leveldir_current_identifier = leveldir_current->identifier;
613 /* custom level artwork configured in level series configuration file
614 always overrides custom level artwork stored in level series directory
615 and (level independant) custom artwork configured in setup menue */
616 if (leveldir_current->graphics_set != NULL)
617 gfx_new_identifier = leveldir_current->graphics_set;
618 if (leveldir_current->sounds_set != NULL)
619 snd_new_identifier = leveldir_current->sounds_set;
620 if (leveldir_current->music_set != NULL)
621 mus_new_identifier = leveldir_current->music_set;
623 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
624 last_override_level_graphics != setup.override_level_graphics)
627 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
628 artwork.gfx_current_identifier,
629 artwork.gfx_current->identifier,
633 setLevelArtworkDir(artwork.gfx_first);
635 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
642 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
643 last_override_level_graphics = setup.override_level_graphics;
645 redraw_screen = TRUE;
648 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
649 last_override_level_sounds != setup.override_level_sounds)
652 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
653 artwork.snd_current_identifier,
654 artwork.snd_current->identifier,
658 /* set artwork path to send it to the sound server process */
659 setLevelArtworkDir(artwork.snd_first);
661 InitReloadCustomSounds(snd_new_identifier);
662 ReinitializeSounds();
664 artwork.snd_current_identifier = artwork.snd_current->identifier;
665 last_override_level_sounds = setup.override_level_sounds;
667 redraw_screen = TRUE;
670 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
671 last_override_level_music != setup.override_level_music)
673 /* set artwork path to send it to the sound server process */
674 setLevelArtworkDir(artwork.mus_first);
676 InitReloadCustomMusic(mus_new_identifier);
679 artwork.mus_current_identifier = artwork.mus_current->identifier;
680 last_override_level_music = setup.override_level_music;
682 redraw_screen = TRUE;
689 /* force redraw of (open or closed) door graphics */
690 SetDoorState(DOOR_OPEN_ALL);
691 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
697 FreeLevelEditorGadgets();
706 static boolean gadgets_initialized = FALSE;
708 if (gadgets_initialized)
711 CreateLevelEditorGadgets();
715 CreateScreenGadgets();
717 gadgets_initialized = TRUE;
720 void InitElementSmallImages()
722 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
723 int num_property_mappings = getImageListPropertyMappingSize();
726 /* initialize normal images from static configuration */
727 for (i=0; element_to_graphic[i].element > -1; i++)
728 CreateImageWithSmallImages(element_to_graphic[i].graphic);
730 /* initialize special images from static configuration */
731 for (i=0; element_to_special_graphic[i].element > -1; i++)
732 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
734 /* initialize images from dynamic configuration */
735 for (i=0; i < num_property_mappings; i++)
736 if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
737 CreateImageWithSmallImages(property_mapping[i].artwork_index);
740 static int getFontBitmapID(int font_nr)
744 if (game_status == MAINMENU || game_status == TYPENAME)
745 special = GFX_SPECIAL_ARG_MAIN;
746 else if (game_status == CHOOSELEVEL)
747 special = GFX_SPECIAL_ARG_LEVELS;
748 else if (game_status == HALLOFFAME)
749 special = GFX_SPECIAL_ARG_SCORES;
750 else if (game_status == LEVELED)
751 special = GFX_SPECIAL_ARG_EDITOR;
752 else if (game_status == HELPSCREEN)
753 special = GFX_SPECIAL_ARG_INFO;
754 else if (game_status == SETUP)
755 special = GFX_SPECIAL_ARG_SETUP;
756 else if (game_status == PSEUDO_PREVIEW)
757 special = GFX_SPECIAL_ARG_PREVIEW;
758 else if (game_status == PLAYING || game_status == PSEUDO_DOOR)
759 special = GFX_SPECIAL_ARG_DOOR;
762 return font_info[font_nr].special_bitmap_id[special];
767 void InitFontGraphicInfo()
769 static struct FontBitmapInfo *font_bitmap_info = NULL;
770 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
771 int num_property_mappings = getImageListPropertyMappingSize();
772 int num_font_bitmaps = NUM_FONTS;
775 if (graphic_info == NULL) /* still at startup phase */
777 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
782 /* ---------- initialize font graphic definitions ---------- */
784 /* always start with reliable default values (normal font graphics) */
785 for (i=0; i < NUM_FONTS; i++)
786 font_info[i].graphic = FONT_INITIAL_1;
788 /* initialize normal font/graphic mapping from static configuration */
789 for (i=0; font_to_graphic[i].font_nr > -1; i++)
791 int font_nr = font_to_graphic[i].font_nr;
792 int special = font_to_graphic[i].special;
793 int graphic = font_to_graphic[i].graphic;
798 font_info[font_nr].graphic = graphic;
801 /* always start with reliable default values (special font graphics) */
802 for (i=0; i < NUM_FONTS; i++)
804 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
806 font_info[i].special_graphic[j] = font_info[i].graphic;
807 font_info[i].special_bitmap_id[j] = i;
811 /* initialize special font/graphic mapping from static configuration */
812 for (i=0; font_to_graphic[i].font_nr > -1; i++)
814 int font_nr = font_to_graphic[i].font_nr;
815 int special = font_to_graphic[i].special;
816 int graphic = font_to_graphic[i].graphic;
818 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
820 font_info[font_nr].special_graphic[special] = graphic;
821 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
826 /* initialize special element/graphic mapping from dynamic configuration */
827 for (i=0; i < num_property_mappings; i++)
829 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
830 int special = property_mapping[i].ext3_index;
831 int graphic = property_mapping[i].artwork_index;
836 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
838 font_info[font_nr].special_graphic[special] = graphic;
839 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
844 /* ---------- initialize font bitmap array ---------- */
846 if (font_bitmap_info != NULL)
847 free(font_bitmap_info);
850 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
852 /* ---------- initialize font bitmap definitions ---------- */
854 for (i=0; i < NUM_FONTS; i++)
856 if (i < NUM_INITIAL_FONTS)
858 font_bitmap_info[i] = font_initial[i];
862 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
864 int font_bitmap_id = font_info[i].special_bitmap_id[j];
865 int graphic = font_info[i].special_graphic[j];
867 /* copy font relevant information from graphics information */
868 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
869 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
870 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
871 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
872 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
873 font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
874 font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
878 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
881 void InitElementGraphicInfo()
883 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
884 int num_property_mappings = getImageListPropertyMappingSize();
887 /* set values to -1 to identify later as "uninitialized" values */
888 for (i=0; i<MAX_NUM_ELEMENTS; i++)
890 for (act=0; act<NUM_ACTIONS; act++)
892 element_info[i].graphic[act] = -1;
894 for (dir=0; dir<NUM_DIRECTIONS; dir++)
895 element_info[i].direction_graphic[act][dir] = -1;
899 /* initialize normal element/graphic mapping from static configuration */
900 for (i=0; element_to_graphic[i].element > -1; i++)
902 int element = element_to_graphic[i].element;
903 int action = element_to_graphic[i].action;
904 int direction = element_to_graphic[i].direction;
905 int graphic = element_to_graphic[i].graphic;
908 action = ACTION_DEFAULT;
911 element_info[element].direction_graphic[action][direction] = graphic;
913 element_info[element].graphic[action] = graphic;
916 /* initialize normal element/graphic mapping from dynamic configuration */
917 for (i=0; i < num_property_mappings; i++)
919 int element = property_mapping[i].base_index;
920 int action = property_mapping[i].ext1_index;
921 int direction = property_mapping[i].ext2_index;
922 int special = property_mapping[i].ext3_index;
923 int graphic = property_mapping[i].artwork_index;
925 if (element >= MAX_NUM_ELEMENTS || special != -1)
929 action = ACTION_DEFAULT;
932 element_info[element].direction_graphic[action][direction] = graphic;
934 element_info[element].graphic[action] = graphic;
937 /* now set all '-1' values to element specific default values */
938 for (i=0; i<MAX_NUM_ELEMENTS; i++)
940 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
941 int default_action_direction_graphic[NUM_DIRECTIONS];
943 if (default_action_graphic == -1)
944 default_action_graphic = IMG_CHAR_QUESTION;
946 for (dir=0; dir<NUM_DIRECTIONS; dir++)
948 default_action_direction_graphic[dir] =
949 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
951 if (default_action_direction_graphic[dir] == -1)
952 default_action_direction_graphic[dir] = default_action_graphic;
955 for (act=0; act<NUM_ACTIONS; act++)
957 for (dir=0; dir<NUM_DIRECTIONS; dir++)
959 int default_direction_graphic = element_info[i].graphic[act];
961 /* no graphic for current action -- use default direction graphic */
962 if (default_direction_graphic == -1)
963 default_direction_graphic = default_action_direction_graphic[dir];
965 if (element_info[i].direction_graphic[act][dir] == -1)
966 element_info[i].direction_graphic[act][dir] =
967 default_direction_graphic;
970 /* no graphic for this specific action -- use default action graphic */
971 if (element_info[i].graphic[act] == -1)
972 element_info[i].graphic[act] = default_action_graphic;
980 for (i=0; i<MAX_NUM_ELEMENTS; i++)
981 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
982 i != EL_CHAR_QUESTION)
983 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
984 element_info[i].token_name, i);
990 void InitElementSpecialGraphicInfo()
992 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
993 int num_property_mappings = getImageListPropertyMappingSize();
996 /* always start with reliable default values */
997 for (i=0; i < MAX_NUM_ELEMENTS; i++)
998 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
999 element_info[i].special_graphic[j] =
1000 element_info[i].graphic[ACTION_DEFAULT];
1002 /* initialize special element/graphic mapping from static configuration */
1003 for (i=0; element_to_special_graphic[i].element > -1; i++)
1005 int element = element_to_special_graphic[i].element;
1006 int special = element_to_special_graphic[i].special;
1007 int graphic = element_to_special_graphic[i].graphic;
1008 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
1009 boolean special_redefined = getImageListEntry(graphic)->redefined;
1011 if (base_redefined && !special_redefined)
1014 element_info[element].special_graphic[special] = graphic;
1017 /* initialize special element/graphic mapping from dynamic configuration */
1018 for (i=0; i < num_property_mappings; i++)
1020 int element = property_mapping[i].base_index;
1021 int special = property_mapping[i].ext3_index;
1022 int graphic = property_mapping[i].artwork_index;
1024 if (element >= MAX_NUM_ELEMENTS)
1027 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
1028 element_info[element].special_graphic[special] = graphic;
1032 static void set_graphic_parameters(int graphic, char **parameter_raw)
1034 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
1035 int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
1036 int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
1037 int parameter[NUM_GFX_ARGS];
1040 /* get integer values from string parameters */
1041 for (i=0; i < NUM_GFX_ARGS; i++)
1043 get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
1044 image_config_suffix[i].type);
1046 graphic_info[graphic].bitmap = src_bitmap;
1048 /* start with reliable default values */
1049 graphic_info[graphic].src_x = 0;
1050 graphic_info[graphic].src_y = 0;
1051 graphic_info[graphic].width = TILEX;
1052 graphic_info[graphic].height = TILEY;
1053 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
1054 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
1056 /* optional x and y tile position of animation frame sequence */
1057 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
1058 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
1059 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
1060 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
1062 /* optional x and y pixel position of animation frame sequence */
1063 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
1064 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
1065 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
1066 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
1068 /* optional width and height of each animation frame */
1069 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
1070 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
1071 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
1072 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
1074 /* correct x or y offset dependant of vertical or horizontal frame order */
1075 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
1077 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1078 graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
1080 graphic_info[graphic].offset_y = graphic_info[graphic].height;
1082 else /* frames are ordered horizontally */
1084 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1085 graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
1087 graphic_info[graphic].offset_x = graphic_info[graphic].width;
1090 /* optionally, the x and y offset of frames can be specified directly */
1091 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
1092 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
1093 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
1094 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
1096 /* automatically determine correct number of frames, if not defined */
1097 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
1098 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
1099 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
1100 graphic_info[graphic].anim_frames = num_xtiles;
1101 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
1102 graphic_info[graphic].anim_frames = num_ytiles;
1104 graphic_info[graphic].anim_frames = 1;
1106 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
1107 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
1108 graphic_info[graphic].anim_delay = 1;
1110 if (parameter[GFX_ARG_ANIM_MODE] != ANIM_NONE)
1111 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
1112 else if (graphic_info[graphic].anim_frames > 1)
1113 graphic_info[graphic].anim_mode = ANIM_LOOP;
1115 /* automatically determine correct start frame, if not defined */
1116 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
1117 graphic_info[graphic].anim_start_frame = 0;
1118 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
1119 graphic_info[graphic].anim_start_frame =
1120 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
1122 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
1124 /* animation synchronized with global frame counter, not move position */
1125 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
1127 /* this is only used for toon animations */
1128 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
1129 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
1131 /* this is only used for drawing font characters */
1132 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
1133 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
1136 static void InitGraphicInfo()
1138 int fallback_graphic = IMG_CHAR_EXCLAM;
1139 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
1140 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
1141 int num_images = getImageListSize();
1144 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1145 static boolean clipmasks_initialized = FALSE;
1147 XGCValues clip_gc_values;
1148 unsigned long clip_gc_valuemask;
1149 GC copy_clipmask_gc = None;
1152 if (graphic_info != NULL)
1155 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
1157 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1158 if (clipmasks_initialized)
1160 for (i=0; i<num_images; i++)
1162 if (graphic_info[i].clip_mask)
1163 XFreePixmap(display, graphic_info[i].clip_mask);
1164 if (graphic_info[i].clip_gc)
1165 XFreeGC(display, graphic_info[i].clip_gc);
1167 graphic_info[i].clip_mask = None;
1168 graphic_info[i].clip_gc = None;
1173 for (i=0; i<num_images; i++)
1175 struct FileInfo *image = getImageListEntry(i);
1178 int first_frame, last_frame;
1180 set_graphic_parameters(i, image->parameter);
1182 /* now check if no animation frames are outside of the loaded image */
1184 if (graphic_info[i].bitmap == NULL)
1185 continue; /* skip check for optional images that are undefined */
1188 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1189 if (src_x < 0 || src_y < 0 ||
1190 src_x + TILEX > src_bitmap->width ||
1191 src_y + TILEY > src_bitmap->height)
1193 Error(ERR_RETURN_LINE, "-");
1194 Error(ERR_RETURN, "warning: error found in config file:");
1195 Error(ERR_RETURN, "- config file: '%s'",
1196 getImageConfigFilename());
1197 Error(ERR_RETURN, "- config token: '%s'",
1198 getTokenFromImageID(i));
1199 Error(ERR_RETURN, "- image file: '%s'",
1200 src_bitmap->source_filename);
1202 "error: first animation frame out of bounds (%d, %d)",
1204 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1206 if (i == fallback_graphic)
1207 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1209 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1210 Error(ERR_RETURN_LINE, "-");
1212 set_graphic_parameters(i, fallback_image->default_parameter);
1213 graphic_info[i].bitmap = fallback_bitmap;
1216 last_frame = graphic_info[i].anim_frames - 1;
1217 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1218 if (src_x < 0 || src_y < 0 ||
1219 src_x + TILEX > src_bitmap->width ||
1220 src_y + TILEY > src_bitmap->height)
1222 Error(ERR_RETURN_LINE, "-");
1223 Error(ERR_RETURN, "warning: error found in config file:");
1224 Error(ERR_RETURN, "- config file: '%s'",
1225 getImageConfigFilename());
1226 Error(ERR_RETURN, "- config token: '%s'",
1227 getTokenFromImageID(i));
1228 Error(ERR_RETURN, "- image file: '%s'",
1229 src_bitmap->source_filename);
1231 "error: last animation frame (%d) out of bounds (%d, %d)",
1232 last_frame, src_x, src_y);
1233 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1235 if (i == fallback_graphic)
1236 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1238 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1239 Error(ERR_RETURN_LINE, "-");
1241 set_graphic_parameters(i, fallback_image->default_parameter);
1242 graphic_info[i].bitmap = fallback_bitmap;
1245 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1246 /* currently we need only a tile clip mask from the first frame */
1247 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1249 if (copy_clipmask_gc == None)
1251 clip_gc_values.graphics_exposures = False;
1252 clip_gc_valuemask = GCGraphicsExposures;
1253 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1254 clip_gc_valuemask, &clip_gc_values);
1257 graphic_info[i].clip_mask =
1258 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1260 src_pixmap = src_bitmap->clip_mask;
1261 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1262 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1264 clip_gc_values.graphics_exposures = False;
1265 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1266 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1268 graphic_info[i].clip_gc =
1269 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1273 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1274 if (copy_clipmask_gc)
1275 XFreeGC(display, copy_clipmask_gc);
1277 clipmasks_initialized = TRUE;
1281 static void InitElementSoundInfo()
1283 /* !!! soon to come !!! */
1286 static void set_sound_parameters(int sound, char **parameter_raw)
1288 int parameter[NUM_SND_ARGS];
1291 /* get integer values from string parameters */
1292 for (i=0; i < NUM_SND_ARGS; i++)
1294 get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
1295 sound_config_suffix[i].type);
1297 /* explicit loop mode setting in configuration overrides default value */
1298 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1299 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1302 static void InitSoundInfo()
1304 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1305 int num_property_mappings = getSoundListPropertyMappingSize();
1306 int *sound_effect_properties;
1307 int num_sounds = getSoundListSize();
1310 if (sound_info != NULL)
1313 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1314 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1316 /* initialize sound effect for all elements to "no sound" */
1317 for (i=0; i<MAX_NUM_ELEMENTS; i++)
1318 for (j=0; j<NUM_ACTIONS; j++)
1319 element_info[i].sound[j] = SND_UNDEFINED;
1321 for (i=0; i<num_sounds; i++)
1323 struct FileInfo *sound = getSoundListEntry(i);
1324 int len_effect_text = strlen(sound->token);
1326 sound_effect_properties[i] = ACTION_OTHER;
1327 sound_info[i].loop = FALSE;
1329 /* determine all loop sounds and identify certain sound classes */
1331 for (j=0; element_action_info[j].suffix; j++)
1333 int len_action_text = strlen(element_action_info[j].suffix);
1335 if (len_action_text < len_effect_text &&
1336 strcmp(&sound->token[len_effect_text - len_action_text],
1337 element_action_info[j].suffix) == 0)
1339 sound_effect_properties[i] = element_action_info[j].value;
1341 if (element_action_info[j].is_loop_sound)
1342 sound_info[i].loop = TRUE;
1346 /* associate elements and some selected sound actions */
1348 for (j=0; j<MAX_NUM_ELEMENTS; j++)
1350 if (element_info[j].sound_class_name)
1352 int len_class_text = strlen(element_info[j].sound_class_name);
1354 if (len_class_text + 1 < len_effect_text &&
1355 strncmp(sound->token,
1356 element_info[j].sound_class_name, len_class_text) == 0 &&
1357 sound->token[len_class_text] == '.')
1359 int sound_action_value = sound_effect_properties[i];
1361 element_info[j].sound[sound_action_value] = i;
1366 set_sound_parameters(i, sound->parameter);
1369 free(sound_effect_properties);
1371 /* initialize element/sound mapping from dynamic configuration */
1372 for (i=0; i < num_property_mappings; i++)
1374 int element = property_mapping[i].base_index;
1375 int action = property_mapping[i].ext1_index;
1376 int sound = property_mapping[i].artwork_index;
1379 action = ACTION_DEFAULT;
1381 element_info[element].sound[action] = sound;
1387 int element = EL_CUSTOM_11;
1390 while (element_action_info[j].suffix)
1392 printf("element %d, sound action '%s' == %d\n",
1393 element, element_action_info[j].suffix,
1394 element_info[element].sound[j]);
1399 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1405 int element = EL_SAND;
1406 int sound_action = ACTION_DIGGING;
1409 while (element_action_info[j].suffix)
1411 if (element_action_info[j].value == sound_action)
1412 printf("element %d, sound action '%s' == %d\n",
1413 element, element_action_info[j].suffix,
1414 element_info[element].sound[sound_action]);
1421 void InitElementProperties()
1425 static int ep_amoebalive[] =
1432 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
1434 static int ep_amoeboid[] =
1442 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
1444 static int ep_schluessel[] =
1455 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
1457 static int ep_pforte[] =
1476 EL_SWITCHGATE_OPENING,
1477 EL_SWITCHGATE_CLOSED,
1478 EL_SWITCHGATE_CLOSING,
1480 EL_TIMEGATE_OPENING,
1482 EL_TIMEGATE_CLOSING,
1486 EL_TUBE_VERTICAL_LEFT,
1487 EL_TUBE_VERTICAL_RIGHT,
1488 EL_TUBE_HORIZONTAL_UP,
1489 EL_TUBE_HORIZONTAL_DOWN,
1495 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
1497 static int ep_solid[] =
1516 EL_QUICKSAND_FILLING,
1517 EL_QUICKSAND_EMPTYING,
1519 EL_MAGIC_WALL_ACTIVE,
1520 EL_MAGIC_WALL_EMPTYING,
1521 EL_MAGIC_WALL_FILLING,
1525 EL_BD_MAGIC_WALL_ACTIVE,
1526 EL_BD_MAGIC_WALL_EMPTYING,
1527 EL_BD_MAGIC_WALL_FULL,
1528 EL_BD_MAGIC_WALL_FILLING,
1529 EL_BD_MAGIC_WALL_DEAD,
1538 EL_SP_TERMINAL_ACTIVE,
1542 EL_INVISIBLE_WALL_ACTIVE,
1543 EL_SWITCHGATE_SWITCH_UP,
1544 EL_SWITCHGATE_SWITCH_DOWN,
1546 EL_TIMEGATE_SWITCH_ACTIVE,
1547 EL_EMC_WALL_PILLAR_UPPER,
1548 EL_EMC_WALL_PILLAR_MIDDLE,
1549 EL_EMC_WALL_PILLAR_LOWER,
1558 /* the following elements are a direct copy of "indestructible" elements,
1559 except "EL_ACID", which is "indestructible", but not "solid"! */
1564 EL_ACIDPOOL_TOPLEFT,
1565 EL_ACIDPOOL_TOPRIGHT,
1566 EL_ACIDPOOL_BOTTOMLEFT,
1568 EL_ACIDPOOL_BOTTOMRIGHT,
1580 EL_INVISIBLE_STEELWALL,
1581 EL_INVISIBLE_STEELWALL_ACTIVE,
1582 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1583 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1584 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1585 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1586 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1587 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1588 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1589 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1590 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1591 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1592 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1593 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1595 EL_LIGHT_SWITCH_ACTIVE,
1596 EL_SIGN_EXCLAMATION,
1597 EL_SIGN_RADIOACTIVITY,
1608 EL_STEELWALL_SLANTED,
1631 EL_SWITCHGATE_OPENING,
1632 EL_SWITCHGATE_CLOSED,
1633 EL_SWITCHGATE_CLOSING,
1635 EL_TIMEGATE_OPENING,
1637 EL_TIMEGATE_CLOSING,
1641 EL_TUBE_VERTICAL_LEFT,
1642 EL_TUBE_VERTICAL_RIGHT,
1643 EL_TUBE_HORIZONTAL_UP,
1644 EL_TUBE_HORIZONTAL_DOWN,
1650 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1652 static int ep_indestructible[] =
1656 EL_ACIDPOOL_TOPLEFT,
1657 EL_ACIDPOOL_TOPRIGHT,
1658 EL_ACIDPOOL_BOTTOMLEFT,
1660 EL_ACIDPOOL_BOTTOMRIGHT,
1672 EL_INVISIBLE_STEELWALL,
1673 EL_INVISIBLE_STEELWALL_ACTIVE,
1674 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1675 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1676 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1677 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1678 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1679 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1680 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1681 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1682 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1683 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1684 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1685 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1687 EL_LIGHT_SWITCH_ACTIVE,
1688 EL_SIGN_EXCLAMATION,
1689 EL_SIGN_RADIOACTIVITY,
1700 EL_STEELWALL_SLANTED,
1723 EL_SWITCHGATE_OPENING,
1724 EL_SWITCHGATE_CLOSED,
1725 EL_SWITCHGATE_CLOSING,
1727 EL_TIMEGATE_OPENING,
1729 EL_TIMEGATE_CLOSING,
1733 EL_TUBE_VERTICAL_LEFT,
1734 EL_TUBE_VERTICAL_RIGHT,
1735 EL_TUBE_HORIZONTAL_UP,
1736 EL_TUBE_HORIZONTAL_DOWN,
1742 static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible);
1744 static int ep_slippery[] =
1758 EL_ROBOT_WHEEL_ACTIVE,
1764 EL_ACIDPOOL_TOPLEFT,
1765 EL_ACIDPOOL_TOPRIGHT,
1775 EL_STEELWALL_SLANTED,
1779 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1781 static int ep_enemy[] =
1794 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1796 static int ep_mauer[] =
1824 EL_WALL_GROWING_ACTIVE,
1843 EL_SP_TERMINAL_ACTIVE,
1846 EL_INVISIBLE_STEELWALL,
1847 EL_INVISIBLE_STEELWALL_ACTIVE,
1849 EL_INVISIBLE_WALL_ACTIVE,
1850 EL_STEELWALL_SLANTED,
1855 EL_EMC_WALL_PILLAR_UPPER,
1856 EL_EMC_WALL_PILLAR_MIDDLE,
1857 EL_EMC_WALL_PILLAR_LOWER,
1864 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1866 static int ep_can_fall[] =
1881 EL_BD_MAGIC_WALL_FULL,
1892 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1894 static int ep_can_smash[] =
1917 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1919 static int ep_can_change[] =
1930 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1932 static int ep_can_move[] =
1952 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1954 static int ep_could_move[] =
1964 EL_BD_BUTTERFLY_RIGHT,
1966 EL_BD_BUTTERFLY_LEFT,
1967 EL_BD_BUTTERFLY_DOWN,
1968 EL_BD_FIREFLY_RIGHT,
1977 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1979 static int ep_dont_touch[] =
1986 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1988 static int ep_dont_go_to[] =
2002 EL_SP_BUGGY_BASE_ACTIVE,
2006 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
2008 static int ep_mampf2[] =
2033 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
2035 static int ep_bd_element[] =
2062 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
2064 static int ep_sb_element[] =
2069 EL_SOKOBAN_FIELD_EMPTY,
2070 EL_SOKOBAN_FIELD_FULL,
2072 EL_INVISIBLE_STEELWALL
2074 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
2076 static int ep_gem[] =
2085 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
2087 static int ep_inactive[] =
2124 EL_INVISIBLE_STEELWALL,
2132 EL_WALL_EMERALD_YELLOW,
2137 EL_SOKOBAN_FIELD_EMPTY,
2138 EL_SOKOBAN_FIELD_FULL,
2139 EL_WALL_EMERALD_RED,
2140 EL_WALL_EMERALD_PURPLE,
2141 EL_ACIDPOOL_TOPLEFT,
2142 EL_ACIDPOOL_TOPRIGHT,
2143 EL_ACIDPOOL_BOTTOMLEFT,
2145 EL_ACIDPOOL_BOTTOMRIGHT,
2149 EL_BD_MAGIC_WALL_DEAD,
2150 EL_AMOEBA_TO_DIAMOND,
2183 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2184 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2185 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2186 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2187 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2188 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2189 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2190 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2191 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2192 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2193 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2194 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2195 EL_SIGN_EXCLAMATION,
2196 EL_SIGN_RADIOACTIVITY,
2207 EL_STEELWALL_SLANTED,
2212 EL_EMC_WALL_PILLAR_UPPER,
2213 EL_EMC_WALL_PILLAR_MIDDLE,
2214 EL_EMC_WALL_PILLAR_LOWER,
2221 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
2223 static int ep_explosive[] =
2228 EL_DYNABOMB_PLAYER1_ACTIVE,
2229 EL_DYNABOMB_PLAYER2_ACTIVE,
2230 EL_DYNABOMB_PLAYER3_ACTIVE,
2231 EL_DYNABOMB_PLAYER4_ACTIVE,
2235 EL_SP_DISK_RED_ACTIVE,
2249 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
2251 static int ep_mampf3[] =
2262 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
2264 static int ep_pushable[] =
2271 EL_SOKOBAN_FIELD_FULL,
2281 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
2283 static int ep_player[] =
2290 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
2292 static int ep_has_content[] =
2300 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
2302 static int ep_eatable[] =
2307 EL_SP_BUGGY_BASE_ACTIVATING,
2310 EL_INVISIBLE_SAND_ACTIVE
2312 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
2314 static int ep_sp_element[] =
2357 /* additional elements that appeared in newer Supaplex levels */
2359 /* more than one murphy in a level results in an inactive clone */
2362 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
2364 static int ep_quick_gate[] =
2388 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
2390 static int ep_over_player[] =
2406 EL_TUBE_VERTICAL_LEFT,
2407 EL_TUBE_VERTICAL_RIGHT,
2408 EL_TUBE_HORIZONTAL_UP,
2409 EL_TUBE_HORIZONTAL_DOWN,
2415 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
2417 static int ep_active_bomb[] =
2420 EL_DYNABOMB_PLAYER1_ACTIVE,
2421 EL_DYNABOMB_PLAYER2_ACTIVE,
2422 EL_DYNABOMB_PLAYER3_ACTIVE,
2423 EL_DYNABOMB_PLAYER4_ACTIVE,
2424 EL_SP_DISK_RED_ACTIVE
2426 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
2428 static int ep_belt[] =
2430 EL_CONVEYOR_BELT1_LEFT,
2431 EL_CONVEYOR_BELT1_MIDDLE,
2432 EL_CONVEYOR_BELT1_RIGHT,
2433 EL_CONVEYOR_BELT2_LEFT,
2434 EL_CONVEYOR_BELT2_MIDDLE,
2435 EL_CONVEYOR_BELT2_RIGHT,
2436 EL_CONVEYOR_BELT3_LEFT,
2437 EL_CONVEYOR_BELT3_MIDDLE,
2438 EL_CONVEYOR_BELT3_RIGHT,
2439 EL_CONVEYOR_BELT4_LEFT,
2440 EL_CONVEYOR_BELT4_MIDDLE,
2441 EL_CONVEYOR_BELT4_RIGHT,
2443 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
2445 static int ep_belt_active[] =
2447 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
2448 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
2449 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
2450 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
2451 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
2452 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
2453 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
2454 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
2455 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
2456 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
2457 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
2458 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
2460 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
2462 static int ep_belt_switch[] =
2464 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2465 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2466 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2467 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2468 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2469 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2470 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2471 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2472 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2473 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2474 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2475 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2477 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
2479 static int ep_tube[] =
2484 EL_TUBE_VERTICAL_LEFT,
2485 EL_TUBE_VERTICAL_RIGHT,
2486 EL_TUBE_HORIZONTAL_UP,
2487 EL_TUBE_HORIZONTAL_DOWN,
2493 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
2495 static long ep1_bit[] =
2502 EP_BIT_INDESTRUCTIBLE,
2529 static long ep2_bit[] =
2536 static int *ep1_array[] =
2570 static int *ep2_array[] =
2577 static int *ep1_num[] =
2584 &ep_indestructible_num,
2604 &ep_has_content_num,
2608 &ep_over_player_num,
2611 static int *ep2_num[] =
2614 &ep_belt_active_num,
2615 &ep_belt_switch_num,
2618 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2619 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2621 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2627 for (i=0; i<num_properties1; i++)
2628 for (j=0; j<*(ep1_num[i]); j++)
2629 Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
2630 for (i=0; i<num_properties2; i++)
2631 for (j=0; j<*(ep2_num[i]); j++)
2632 Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
2634 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2635 Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2638 void Execute_Command(char *command)
2640 if (strcmp(command, "print graphicsinfo.conf") == 0)
2644 printf("# You can configure additional/alternative image files here.\n");
2645 printf("# (The images below are default and therefore commented out.)\n");
2647 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2649 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2652 for (i=0; image_config[i].token != NULL; i++)
2654 getFormattedSetupEntry(image_config[i].token,
2655 image_config[i].value));
2659 else if (strcmp(command, "print soundsinfo.conf") == 0)
2663 printf("# You can configure additional/alternative sound files here.\n");
2664 printf("# (The sounds below are default and therefore commented out.)\n");
2666 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2668 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2671 for (i=0; sound_config[i].token != NULL; i++)
2673 getFormattedSetupEntry(sound_config[i].token,
2674 sound_config[i].value));
2678 else if (strcmp(command, "print musicinfo.conf") == 0)
2680 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2682 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2684 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2688 else if (strncmp(command, "dump level ", 11) == 0)
2690 char *filename = &command[11];
2692 if (access(filename, F_OK) != 0)
2693 Error(ERR_EXIT, "cannot open file '%s'", filename);
2695 LoadLevelFromFilename(filename);
2700 else if (strncmp(command, "dump tape ", 10) == 0)
2702 char *filename = &command[10];
2704 if (access(filename, F_OK) != 0)
2705 Error(ERR_EXIT, "cannot open file '%s'", filename);
2707 LoadTapeFromFilename(filename);
2712 else if (strncmp(command, "autoplay ", 9) == 0)
2714 char *str_copy = getStringCopy(&command[9]);
2715 char *str_ptr = strchr(str_copy, ' ');
2717 global.autoplay_leveldir = str_copy;
2718 global.autoplay_level_nr = -1;
2720 if (str_ptr != NULL)
2722 *str_ptr++ = '\0'; /* terminate leveldir string */
2723 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2728 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2732 void CloseAllAndExit(int exit_value)
2737 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2740 FreeTileClipmasks();
2742 CloseVideoDisplay();
2743 ClosePlatformDependantStuff();