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[] =
182 static char *ignore_sound_tokens[] =
190 for (i=0; i<MAX_NUM_ELEMENTS; i++)
191 image_id_prefix[i] = element_info[i].token_name;
192 for (i=0; i<NUM_FONTS + 1; i++)
193 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
195 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
196 sound_id_prefix[i] = element_info[i].sound_class_name;
198 for (i=0; i<NUM_ACTIONS + 1; i++)
199 action_id_suffix[i] = element_action_info[i].suffix;
201 for (i=0; i<NUM_DIRECTIONS + 1; i++)
202 direction_id_suffix[i] = element_direction_info[i].suffix;
204 for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
205 special_id_suffix[i] = special_suffix_info[i].suffix;
207 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
208 image_id_prefix, action_id_suffix, direction_id_suffix,
209 special_id_suffix, ignore_image_tokens);
210 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
211 sound_id_prefix, action_id_suffix, dummy,
212 dummy, ignore_sound_tokens);
215 void InitLevelArtworkInfo()
217 LoadLevelArtworkInfo();
220 void InitNetworkServer()
222 #if defined(PLATFORM_UNIX)
226 if (!options.network)
229 #if defined(PLATFORM_UNIX)
230 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
232 if (!ConnectToServer(options.server_host, options.server_port))
233 Error(ERR_EXIT, "cannot connect to network game server");
235 SendToServer_PlayerName(setup.player_name);
236 SendToServer_ProtocolVersion();
239 SendToServer_NrWanted(nr_wanted);
243 static void InitMixer()
249 static void ReinitializeGraphics()
251 InitElementGraphicInfo(); /* element game graphic mapping */
252 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
253 InitGraphicInfo(); /* graphic properties mapping */
255 InitElementSmallImages(); /* create editor and preview images */
256 InitFontGraphicInfo(); /* initialize text drawing functions */
258 SetMainBackgroundImage(IMG_BACKGROUND);
259 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
265 static void ReinitializeSounds()
267 InitElementSoundInfo(); /* element game sound mapping */
268 InitSoundInfo(); /* sound properties mapping */
270 InitPlaySoundLevel(); /* internal game sound settings */
273 static void ReinitializeMusic()
275 /* currently nothing to do */
278 static void InitImages()
280 ReloadCustomImages();
282 LoadCustomElementDescriptions();
283 LoadSpecialMenuDesignSettings();
285 ReinitializeGraphics();
288 static void InitSound()
290 InitReloadCustomSounds(artwork.snd_current->identifier);
291 ReinitializeSounds();
294 static void InitMusic()
296 InitReloadCustomMusic(artwork.mus_current->identifier);
300 static void InitTileClipmasks()
303 #if defined(TARGET_X11)
304 XGCValues clip_gc_values;
305 unsigned long clip_gc_valuemask;
307 #if defined(TARGET_X11_NATIVE)
317 tile_needs_clipping[] =
319 { GFX_SPIELER1_UP, 4 },
320 { GFX_SPIELER1_DOWN, 4 },
321 { GFX_SPIELER1_LEFT, 4 },
322 { GFX_SPIELER1_RIGHT, 4 },
323 { GFX_SPIELER1_PUSH_LEFT, 4 },
324 { GFX_SPIELER1_PUSH_RIGHT, 4 },
325 { GFX_SPIELER2_UP, 4 },
326 { GFX_SPIELER2_DOWN, 4 },
327 { GFX_SPIELER2_LEFT, 4 },
328 { GFX_SPIELER2_RIGHT, 4 },
329 { GFX_SPIELER2_PUSH_LEFT, 4 },
330 { GFX_SPIELER2_PUSH_RIGHT, 4 },
331 { GFX_SPIELER3_UP, 4 },
332 { GFX_SPIELER3_DOWN, 4 },
333 { GFX_SPIELER3_LEFT, 4 },
334 { GFX_SPIELER3_RIGHT, 4 },
335 { GFX_SPIELER3_PUSH_LEFT, 4 },
336 { GFX_SPIELER3_PUSH_RIGHT, 4 },
337 { GFX_SPIELER4_UP, 4 },
338 { GFX_SPIELER4_DOWN, 4 },
339 { GFX_SPIELER4_LEFT, 4 },
340 { GFX_SPIELER4_RIGHT, 4 },
341 { GFX_SPIELER4_PUSH_LEFT, 4 },
342 { GFX_SPIELER4_PUSH_RIGHT, 4 },
343 { GFX_SP_MURPHY, 1 },
344 { GFX_MURPHY_GO_LEFT, 3 },
345 { GFX_MURPHY_GO_RIGHT, 3 },
346 { GFX_MURPHY_SNAP_UP, 1 },
347 { GFX_MURPHY_SNAP_DOWN, 1 },
348 { GFX_MURPHY_SNAP_RIGHT, 1 },
349 { GFX_MURPHY_SNAP_LEFT, 1 },
350 { GFX_MURPHY_PUSH_RIGHT, 1 },
351 { GFX_MURPHY_PUSH_LEFT, 1 },
352 { GFX_GEBLUBBER, 4 },
355 { GFX_EXPLOSION, 8 },
356 { GFX_SOKOBAN_OBJEKT, 1 },
357 { GFX_FUNKELN_BLAU, 3 },
358 { GFX_FUNKELN_WEISS, 3 },
359 { GFX2_SHIELD_PASSIVE, 3 },
360 { GFX2_SHIELD_ACTIVE, 3 },
365 #endif /* TARGET_X11_NATIVE */
366 #endif /* TARGET_X11 */
370 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
371 for (i=0; i<NUM_TILES; i++)
372 tile_clipmask[i] = None;
374 #if defined(TARGET_X11)
375 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
376 often very slow when preparing a masked XCopyArea() for big Pixmaps.
377 To prevent this, create small (tile-sized) mask Pixmaps which will then
378 be set much faster with XSetClipOrigin() and speed things up a lot. */
380 clip_gc_values.graphics_exposures = False;
381 clip_gc_valuemask = GCGraphicsExposures;
382 tile_clip_gc = XCreateGC(display, window->drawable,
383 clip_gc_valuemask, &clip_gc_values);
386 for (i=0; i<NUM_BITMAPS; i++)
388 if (pix[i]->clip_mask)
390 clip_gc_values.graphics_exposures = False;
391 clip_gc_values.clip_mask = pix[i]->clip_mask;
392 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
393 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
394 clip_gc_valuemask, &clip_gc_values);
399 #if defined(TARGET_X11_NATIVE)
402 /* create graphic context structures needed for clipping */
403 clip_gc_values.graphics_exposures = False;
404 clip_gc_valuemask = GCGraphicsExposures;
405 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
406 clip_gc_valuemask, &clip_gc_values);
408 /* create only those clipping Pixmaps we really need */
409 for (i=0; tile_needs_clipping[i].start>=0; i++)
413 for (j=0; j<tile_needs_clipping[i].count; j++)
415 int tile = tile_needs_clipping[i].start + j;
421 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
422 src_pixmap = src_bitmap->clip_mask;
424 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
427 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
428 src_x, src_y, TILEX, TILEY, 0, 0);
432 XFreeGC(display, copy_clipmask_gc);
435 #endif /* TARGET_X11_NATIVE */
436 #endif /* TARGET_X11 */
440 void FreeTileClipmasks()
443 #if defined(TARGET_X11)
446 for (i=0; i<NUM_TILES; i++)
448 if (tile_clipmask[i] != None)
450 XFreePixmap(display, tile_clipmask[i]);
451 tile_clipmask[i] = None;
456 XFreeGC(display, tile_clip_gc);
460 for (i=0; i<NUM_BITMAPS; i++)
462 if (pix[i] != NULL && pix[i]->stored_clip_gc)
464 XFreeGC(display, pix[i]->stored_clip_gc);
465 pix[i]->stored_clip_gc = None;
470 #endif /* TARGET_X11 */
476 char *filename_font_initial = NULL;
477 Bitmap *bitmap_font_initial = NULL;
480 /* determine settings for initial font (for displaying startup messages) */
481 for (i=0; image_config[i].token != NULL; i++)
483 for (j=0; j < NUM_INITIAL_FONTS; j++)
485 char font_token[128];
488 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
489 len_font_token = strlen(font_token);
491 if (strcmp(image_config[i].token, font_token) == 0)
492 filename_font_initial = image_config[i].value;
493 else if (strlen(image_config[i].token) > len_font_token &&
494 strncmp(image_config[i].token, font_token, len_font_token) == 0)
496 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
497 font_initial[j].src_x = atoi(image_config[i].value);
498 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
499 font_initial[j].src_y = atoi(image_config[i].value);
500 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
501 font_initial[j].width = atoi(image_config[i].value);
502 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
503 font_initial[j].height = atoi(image_config[i].value);
508 if (filename_font_initial == NULL) /* should not happen */
509 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
511 /* initialize screen properties */
512 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
513 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
514 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
515 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
516 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
518 /* create additional image buffers for double-buffering */
519 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
520 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
522 bitmap_font_initial = LoadCustomImage(filename_font_initial);
524 for (j=0; j < NUM_INITIAL_FONTS; j++)
525 font_initial[j].bitmap = bitmap_font_initial;
527 InitFontGraphicInfo();
529 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
530 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
532 DrawInitText("Loading graphics:", 120, FC_GREEN);
537 void InitGfxBackground()
542 fieldbuffer = bitmap_db_field;
543 SetDrawtoField(DRAW_BACKBUFFER);
545 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
546 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
547 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
548 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
550 for (x=0; x<MAX_BUF_XSIZE; x++)
551 for (y=0; y<MAX_BUF_YSIZE; y++)
554 redraw_mask = REDRAW_ALL;
557 void ReloadCustomArtwork()
559 static char *leveldir_current_identifier = NULL;
560 static boolean last_override_level_graphics = FALSE;
561 static boolean last_override_level_sounds = FALSE;
562 static boolean last_override_level_music = FALSE;
563 /* identifier for new artwork; default: artwork configured in setup */
564 char *gfx_new_identifier = artwork.gfx_current->identifier;
565 char *snd_new_identifier = artwork.snd_current->identifier;
566 char *mus_new_identifier = artwork.mus_current->identifier;
567 boolean redraw_screen = FALSE;
569 if (leveldir_current_identifier == NULL)
570 leveldir_current_identifier = leveldir_current->identifier;
573 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
574 leveldir_current->graphics_set);
575 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
576 leveldir_current->identifier);
580 printf("graphics --> '%s' ('%s')\n",
581 artwork.gfx_current_identifier, artwork.gfx_current->filename);
582 printf("sounds --> '%s' ('%s')\n",
583 artwork.snd_current_identifier, artwork.snd_current->filename);
584 printf("music --> '%s' ('%s')\n",
585 artwork.mus_current_identifier, artwork.mus_current->filename);
588 /* leveldir_current may be invalid (level group, parent link) */
589 if (!validLevelSeries(leveldir_current))
592 /* when a new level series was selected, check if there was a change
593 in custom artwork stored in level series directory */
594 if (leveldir_current_identifier != leveldir_current->identifier)
596 char *identifier_old = leveldir_current_identifier;
597 char *identifier_new = leveldir_current->identifier;
599 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
600 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
601 gfx_new_identifier = identifier_new;
602 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
603 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
604 snd_new_identifier = identifier_new;
605 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
606 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
607 mus_new_identifier = identifier_new;
609 leveldir_current_identifier = leveldir_current->identifier;
612 /* custom level artwork configured in level series configuration file
613 always overrides custom level artwork stored in level series directory
614 and (level independant) custom artwork configured in setup menue */
615 if (leveldir_current->graphics_set != NULL)
616 gfx_new_identifier = leveldir_current->graphics_set;
617 if (leveldir_current->sounds_set != NULL)
618 snd_new_identifier = leveldir_current->sounds_set;
619 if (leveldir_current->music_set != NULL)
620 mus_new_identifier = leveldir_current->music_set;
622 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
623 last_override_level_graphics != setup.override_level_graphics)
626 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
627 artwork.gfx_current_identifier,
628 artwork.gfx_current->identifier,
632 setLevelArtworkDir(artwork.gfx_first);
634 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
641 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
642 last_override_level_graphics = setup.override_level_graphics;
644 redraw_screen = TRUE;
647 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
648 last_override_level_sounds != setup.override_level_sounds)
651 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
652 artwork.snd_current_identifier,
653 artwork.snd_current->identifier,
657 /* set artwork path to send it to the sound server process */
658 setLevelArtworkDir(artwork.snd_first);
660 InitReloadCustomSounds(snd_new_identifier);
661 ReinitializeSounds();
663 artwork.snd_current_identifier = artwork.snd_current->identifier;
664 last_override_level_sounds = setup.override_level_sounds;
666 redraw_screen = TRUE;
669 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
670 last_override_level_music != setup.override_level_music)
672 /* set artwork path to send it to the sound server process */
673 setLevelArtworkDir(artwork.mus_first);
675 InitReloadCustomMusic(mus_new_identifier);
678 artwork.mus_current_identifier = artwork.mus_current->identifier;
679 last_override_level_music = setup.override_level_music;
681 redraw_screen = TRUE;
688 /* force redraw of (open or closed) door graphics */
689 SetDoorState(DOOR_OPEN_ALL);
690 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
696 FreeLevelEditorGadgets();
705 static boolean gadgets_initialized = FALSE;
707 if (gadgets_initialized)
710 CreateLevelEditorGadgets();
714 CreateScreenGadgets();
716 gadgets_initialized = TRUE;
719 void InitElementSmallImages()
721 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
722 int num_property_mappings = getImageListPropertyMappingSize();
725 /* initialize normal images from static configuration */
726 for (i=0; element_to_graphic[i].element > -1; i++)
727 CreateImageWithSmallImages(element_to_graphic[i].graphic);
729 /* initialize special images from static configuration */
730 for (i=0; element_to_special_graphic[i].element > -1; i++)
731 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
733 /* initialize images from dynamic configuration */
734 for (i=0; i < num_property_mappings; i++)
735 if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
736 CreateImageWithSmallImages(property_mapping[i].artwork_index);
739 static int getFontBitmapID(int font_nr)
743 if (game_status == MAINMENU || game_status == TYPENAME)
744 special = GFX_SPECIAL_ARG_MAIN;
745 else if (game_status == CHOOSELEVEL)
746 special = GFX_SPECIAL_ARG_LEVELS;
747 else if (game_status == HALLOFFAME)
748 special = GFX_SPECIAL_ARG_SCORES;
749 else if (game_status == LEVELED)
750 special = GFX_SPECIAL_ARG_EDITOR;
751 else if (game_status == HELPSCREEN)
752 special = GFX_SPECIAL_ARG_INFO;
753 else if (game_status == SETUP)
754 special = GFX_SPECIAL_ARG_SETUP;
755 else if (game_status == PSEUDO_PREVIEW)
756 special = GFX_SPECIAL_ARG_PREVIEW;
757 else if (game_status == PLAYING || game_status == PSEUDO_DOOR)
758 special = GFX_SPECIAL_ARG_DOOR;
761 return font_info[font_nr].special_bitmap_id[special];
766 void InitFontGraphicInfo()
768 static struct FontBitmapInfo *font_bitmap_info = NULL;
769 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
770 int num_property_mappings = getImageListPropertyMappingSize();
771 int num_font_bitmaps = NUM_FONTS;
774 if (graphic_info == NULL) /* still at startup phase */
776 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
781 /* ---------- initialize font graphic definitions ---------- */
783 /* always start with reliable default values (normal font graphics) */
784 for (i=0; i < NUM_FONTS; i++)
785 font_info[i].graphic = FONT_INITIAL_1;
787 /* initialize normal font/graphic mapping from static configuration */
788 for (i=0; font_to_graphic[i].font_nr > -1; i++)
790 int font_nr = font_to_graphic[i].font_nr;
791 int special = font_to_graphic[i].special;
792 int graphic = font_to_graphic[i].graphic;
797 font_info[font_nr].graphic = graphic;
800 /* always start with reliable default values (special font graphics) */
801 for (i=0; i < NUM_FONTS; i++)
803 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
805 font_info[i].special_graphic[j] = font_info[i].graphic;
806 font_info[i].special_bitmap_id[j] = i;
810 /* initialize special font/graphic mapping from static configuration */
811 for (i=0; font_to_graphic[i].font_nr > -1; i++)
813 int font_nr = font_to_graphic[i].font_nr;
814 int special = font_to_graphic[i].special;
815 int graphic = font_to_graphic[i].graphic;
817 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
819 font_info[font_nr].special_graphic[special] = graphic;
820 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
825 /* initialize special element/graphic mapping from dynamic configuration */
826 for (i=0; i < num_property_mappings; i++)
828 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
829 int special = property_mapping[i].ext3_index;
830 int graphic = property_mapping[i].artwork_index;
835 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
837 font_info[font_nr].special_graphic[special] = graphic;
838 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
843 /* ---------- initialize font bitmap array ---------- */
845 if (font_bitmap_info != NULL)
846 free(font_bitmap_info);
849 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
851 /* ---------- initialize font bitmap definitions ---------- */
853 for (i=0; i < NUM_FONTS; i++)
855 if (i < NUM_INITIAL_FONTS)
857 font_bitmap_info[i] = font_initial[i];
861 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
863 int font_bitmap_id = font_info[i].special_bitmap_id[j];
864 int graphic = font_info[i].special_graphic[j];
866 /* copy font relevant information from graphics information */
867 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
868 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
869 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
870 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
871 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
872 font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
873 font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
877 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
880 void InitElementGraphicInfo()
882 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
883 int num_property_mappings = getImageListPropertyMappingSize();
886 /* set values to -1 to identify later as "uninitialized" values */
887 for (i=0; i<MAX_NUM_ELEMENTS; i++)
889 for (act=0; act<NUM_ACTIONS; act++)
891 element_info[i].graphic[act] = -1;
893 for (dir=0; dir<NUM_DIRECTIONS; dir++)
894 element_info[i].direction_graphic[act][dir] = -1;
898 /* initialize normal element/graphic mapping from static configuration */
899 for (i=0; element_to_graphic[i].element > -1; i++)
901 int element = element_to_graphic[i].element;
902 int action = element_to_graphic[i].action;
903 int direction = element_to_graphic[i].direction;
904 int graphic = element_to_graphic[i].graphic;
907 action = ACTION_DEFAULT;
910 element_info[element].direction_graphic[action][direction] = graphic;
912 element_info[element].graphic[action] = graphic;
915 /* initialize normal element/graphic mapping from dynamic configuration */
916 for (i=0; i < num_property_mappings; i++)
918 int element = property_mapping[i].base_index;
919 int action = property_mapping[i].ext1_index;
920 int direction = property_mapping[i].ext2_index;
921 int special = property_mapping[i].ext3_index;
922 int graphic = property_mapping[i].artwork_index;
924 if (element >= MAX_NUM_ELEMENTS || special != -1)
928 action = ACTION_DEFAULT;
931 element_info[element].direction_graphic[action][direction] = graphic;
933 element_info[element].graphic[action] = graphic;
936 /* now set all '-1' values to element specific default values */
937 for (i=0; i<MAX_NUM_ELEMENTS; i++)
939 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
940 int default_action_direction_graphic[NUM_DIRECTIONS];
942 if (default_action_graphic == -1)
943 default_action_graphic = IMG_CHAR_QUESTION;
945 for (dir=0; dir<NUM_DIRECTIONS; dir++)
947 default_action_direction_graphic[dir] =
948 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
950 if (default_action_direction_graphic[dir] == -1)
951 default_action_direction_graphic[dir] = default_action_graphic;
954 for (act=0; act<NUM_ACTIONS; act++)
956 for (dir=0; dir<NUM_DIRECTIONS; dir++)
958 int default_direction_graphic = element_info[i].graphic[act];
960 /* no graphic for current action -- use default direction graphic */
961 if (default_direction_graphic == -1)
962 default_direction_graphic = default_action_direction_graphic[dir];
964 if (element_info[i].direction_graphic[act][dir] == -1)
965 element_info[i].direction_graphic[act][dir] =
966 default_direction_graphic;
969 /* no graphic for this specific action -- use default action graphic */
970 if (element_info[i].graphic[act] == -1)
971 element_info[i].graphic[act] = default_action_graphic;
979 for (i=0; i<MAX_NUM_ELEMENTS; i++)
980 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
981 i != EL_CHAR_QUESTION)
982 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
983 element_info[i].token_name, i);
989 void InitElementSpecialGraphicInfo()
991 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
992 int num_property_mappings = getImageListPropertyMappingSize();
995 /* always start with reliable default values */
996 for (i=0; i < MAX_NUM_ELEMENTS; i++)
997 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
998 element_info[i].special_graphic[j] =
999 element_info[i].graphic[ACTION_DEFAULT];
1001 /* initialize special element/graphic mapping from static configuration */
1002 for (i=0; element_to_special_graphic[i].element > -1; i++)
1004 int element = element_to_special_graphic[i].element;
1005 int special = element_to_special_graphic[i].special;
1006 int graphic = element_to_special_graphic[i].graphic;
1007 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
1008 boolean special_redefined = getImageListEntry(graphic)->redefined;
1010 if (base_redefined && !special_redefined)
1013 element_info[element].special_graphic[special] = graphic;
1016 /* initialize special element/graphic mapping from dynamic configuration */
1017 for (i=0; i < num_property_mappings; i++)
1019 int element = property_mapping[i].base_index;
1020 int special = property_mapping[i].ext3_index;
1021 int graphic = property_mapping[i].artwork_index;
1023 if (element >= MAX_NUM_ELEMENTS)
1026 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
1027 element_info[element].special_graphic[special] = graphic;
1031 static void set_graphic_parameters(int graphic, char **parameter_raw)
1033 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
1034 int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
1035 int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
1036 int parameter[NUM_GFX_ARGS];
1039 /* get integer values from string parameters */
1040 for (i=0; i < NUM_GFX_ARGS; i++)
1042 get_parameter_value(image_config_suffix[i].token, parameter_raw[i],
1043 image_config_suffix[i].type);
1045 graphic_info[graphic].bitmap = src_bitmap;
1047 /* start with reliable default values */
1048 graphic_info[graphic].src_x = 0;
1049 graphic_info[graphic].src_y = 0;
1050 graphic_info[graphic].width = TILEX;
1051 graphic_info[graphic].height = TILEY;
1052 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
1053 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
1055 /* optional x and y tile position of animation frame sequence */
1056 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
1057 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
1058 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
1059 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
1061 /* optional x and y pixel position of animation frame sequence */
1062 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
1063 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
1064 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
1065 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
1067 /* optional width and height of each animation frame */
1068 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
1069 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
1070 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
1071 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
1073 /* correct x or y offset dependant of vertical or horizontal frame order */
1074 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
1076 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1077 graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
1079 graphic_info[graphic].offset_y = graphic_info[graphic].height;
1081 else /* frames are ordered horizontally */
1083 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1084 graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
1086 graphic_info[graphic].offset_x = graphic_info[graphic].width;
1089 /* optionally, the x and y offset of frames can be specified directly */
1090 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
1091 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
1092 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
1093 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
1095 /* automatically determine correct number of frames, if not defined */
1096 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
1097 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
1098 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
1099 graphic_info[graphic].anim_frames = num_xtiles;
1100 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
1101 graphic_info[graphic].anim_frames = num_ytiles;
1103 graphic_info[graphic].anim_frames = 1;
1105 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
1106 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
1107 graphic_info[graphic].anim_delay = 1;
1109 if (parameter[GFX_ARG_ANIM_MODE] != ANIM_NONE)
1110 graphic_info[graphic].anim_mode = parameter[GFX_ARG_ANIM_MODE];
1111 else if (graphic_info[graphic].anim_frames > 1)
1112 graphic_info[graphic].anim_mode = ANIM_LOOP;
1114 /* automatically determine correct start frame, if not defined */
1115 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
1116 graphic_info[graphic].anim_start_frame = 0;
1117 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
1118 graphic_info[graphic].anim_start_frame =
1119 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
1121 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
1123 /* animation synchronized with global frame counter, not move position */
1124 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
1126 /* this is only used for toon animations */
1127 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
1128 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
1130 /* this is only used for drawing font characters */
1131 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
1132 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
1135 static void InitGraphicInfo()
1137 int fallback_graphic = IMG_CHAR_EXCLAM;
1138 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
1139 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
1140 int num_images = getImageListSize();
1143 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1144 static boolean clipmasks_initialized = FALSE;
1146 XGCValues clip_gc_values;
1147 unsigned long clip_gc_valuemask;
1148 GC copy_clipmask_gc = None;
1151 if (graphic_info != NULL)
1154 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
1156 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1157 if (clipmasks_initialized)
1159 for (i=0; i<num_images; i++)
1161 if (graphic_info[i].clip_mask)
1162 XFreePixmap(display, graphic_info[i].clip_mask);
1163 if (graphic_info[i].clip_gc)
1164 XFreeGC(display, graphic_info[i].clip_gc);
1166 graphic_info[i].clip_mask = None;
1167 graphic_info[i].clip_gc = None;
1172 for (i=0; i<num_images; i++)
1174 struct FileInfo *image = getImageListEntry(i);
1177 int first_frame, last_frame;
1179 set_graphic_parameters(i, image->parameter);
1181 /* now check if no animation frames are outside of the loaded image */
1183 if (graphic_info[i].bitmap == NULL)
1184 continue; /* skip check for optional images that are undefined */
1187 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1188 if (src_x < 0 || src_y < 0 ||
1189 src_x + TILEX > src_bitmap->width ||
1190 src_y + TILEY > src_bitmap->height)
1192 Error(ERR_RETURN_LINE, "-");
1193 Error(ERR_RETURN, "warning: error found in config file:");
1194 Error(ERR_RETURN, "- config file: '%s'",
1195 getImageConfigFilename());
1196 Error(ERR_RETURN, "- config token: '%s'",
1197 getTokenFromImageID(i));
1198 Error(ERR_RETURN, "- image file: '%s'",
1199 src_bitmap->source_filename);
1201 "error: first animation frame out of bounds (%d, %d)",
1203 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1205 if (i == fallback_graphic)
1206 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1208 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1209 Error(ERR_RETURN_LINE, "-");
1211 set_graphic_parameters(i, fallback_image->default_parameter);
1212 graphic_info[i].bitmap = fallback_bitmap;
1215 last_frame = graphic_info[i].anim_frames - 1;
1216 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1217 if (src_x < 0 || src_y < 0 ||
1218 src_x + TILEX > src_bitmap->width ||
1219 src_y + TILEY > src_bitmap->height)
1221 Error(ERR_RETURN_LINE, "-");
1222 Error(ERR_RETURN, "warning: error found in config file:");
1223 Error(ERR_RETURN, "- config file: '%s'",
1224 getImageConfigFilename());
1225 Error(ERR_RETURN, "- config token: '%s'",
1226 getTokenFromImageID(i));
1227 Error(ERR_RETURN, "- image file: '%s'",
1228 src_bitmap->source_filename);
1230 "error: last animation frame (%d) out of bounds (%d, %d)",
1231 last_frame, src_x, src_y);
1232 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1234 if (i == fallback_graphic)
1235 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1237 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1238 Error(ERR_RETURN_LINE, "-");
1240 set_graphic_parameters(i, fallback_image->default_parameter);
1241 graphic_info[i].bitmap = fallback_bitmap;
1244 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1245 /* currently we need only a tile clip mask from the first frame */
1246 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1248 if (copy_clipmask_gc == None)
1250 clip_gc_values.graphics_exposures = False;
1251 clip_gc_valuemask = GCGraphicsExposures;
1252 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1253 clip_gc_valuemask, &clip_gc_values);
1256 graphic_info[i].clip_mask =
1257 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1259 src_pixmap = src_bitmap->clip_mask;
1260 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1261 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1263 clip_gc_values.graphics_exposures = False;
1264 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1265 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1267 graphic_info[i].clip_gc =
1268 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1272 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1273 if (copy_clipmask_gc)
1274 XFreeGC(display, copy_clipmask_gc);
1276 clipmasks_initialized = TRUE;
1280 static void InitElementSoundInfo()
1282 /* !!! soon to come !!! */
1285 static void set_sound_parameters(int sound, char **parameter_raw)
1287 int parameter[NUM_SND_ARGS];
1290 /* get integer values from string parameters */
1291 for (i=0; i < NUM_SND_ARGS; i++)
1293 get_parameter_value(sound_config_suffix[i].token, parameter_raw[i],
1294 sound_config_suffix[i].type);
1296 /* explicit loop mode setting in configuration overrides default value */
1297 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1298 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1301 static void InitSoundInfo()
1303 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1304 int num_property_mappings = getSoundListPropertyMappingSize();
1305 int *sound_effect_properties;
1306 int num_sounds = getSoundListSize();
1309 if (sound_info != NULL)
1312 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1313 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1315 /* initialize sound effect for all elements to "no sound" */
1316 for (i=0; i<MAX_NUM_ELEMENTS; i++)
1317 for (j=0; j<NUM_ACTIONS; j++)
1318 element_info[i].sound[j] = SND_UNDEFINED;
1320 for (i=0; i<num_sounds; i++)
1322 struct FileInfo *sound = getSoundListEntry(i);
1323 int len_effect_text = strlen(sound->token);
1325 sound_effect_properties[i] = ACTION_OTHER;
1326 sound_info[i].loop = FALSE;
1328 /* determine all loop sounds and identify certain sound classes */
1330 for (j=0; element_action_info[j].suffix; j++)
1332 int len_action_text = strlen(element_action_info[j].suffix);
1334 if (len_action_text < len_effect_text &&
1335 strcmp(&sound->token[len_effect_text - len_action_text],
1336 element_action_info[j].suffix) == 0)
1338 sound_effect_properties[i] = element_action_info[j].value;
1340 if (element_action_info[j].is_loop_sound)
1341 sound_info[i].loop = TRUE;
1345 /* associate elements and some selected sound actions */
1347 for (j=0; j<MAX_NUM_ELEMENTS; j++)
1349 if (element_info[j].sound_class_name)
1351 int len_class_text = strlen(element_info[j].sound_class_name);
1353 if (len_class_text + 1 < len_effect_text &&
1354 strncmp(sound->token,
1355 element_info[j].sound_class_name, len_class_text) == 0 &&
1356 sound->token[len_class_text] == '.')
1358 int sound_action_value = sound_effect_properties[i];
1360 element_info[j].sound[sound_action_value] = i;
1365 set_sound_parameters(i, sound->parameter);
1368 free(sound_effect_properties);
1370 /* initialize element/sound mapping from dynamic configuration */
1371 for (i=0; i < num_property_mappings; i++)
1373 int element = property_mapping[i].base_index;
1374 int action = property_mapping[i].ext1_index;
1375 int sound = property_mapping[i].artwork_index;
1378 action = ACTION_DEFAULT;
1380 element_info[element].sound[action] = sound;
1386 int element = EL_CUSTOM_11;
1389 while (element_action_info[j].suffix)
1391 printf("element %d, sound action '%s' == %d\n",
1392 element, element_action_info[j].suffix,
1393 element_info[element].sound[j]);
1398 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1404 int element = EL_SAND;
1405 int sound_action = ACTION_DIGGING;
1408 while (element_action_info[j].suffix)
1410 if (element_action_info[j].value == sound_action)
1411 printf("element %d, sound action '%s' == %d\n",
1412 element, element_action_info[j].suffix,
1413 element_info[element].sound[sound_action]);
1420 void InitElementProperties()
1424 static int ep_amoebalive[] =
1431 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
1433 static int ep_amoeboid[] =
1441 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
1443 static int ep_schluessel[] =
1454 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
1456 static int ep_pforte[] =
1475 EL_SWITCHGATE_OPENING,
1476 EL_SWITCHGATE_CLOSED,
1477 EL_SWITCHGATE_CLOSING,
1479 EL_TIMEGATE_OPENING,
1481 EL_TIMEGATE_CLOSING,
1485 EL_TUBE_VERTICAL_LEFT,
1486 EL_TUBE_VERTICAL_RIGHT,
1487 EL_TUBE_HORIZONTAL_UP,
1488 EL_TUBE_HORIZONTAL_DOWN,
1494 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
1496 static int ep_solid[] =
1515 EL_QUICKSAND_FILLING,
1516 EL_QUICKSAND_EMPTYING,
1518 EL_MAGIC_WALL_ACTIVE,
1519 EL_MAGIC_WALL_EMPTYING,
1520 EL_MAGIC_WALL_FILLING,
1524 EL_BD_MAGIC_WALL_ACTIVE,
1525 EL_BD_MAGIC_WALL_EMPTYING,
1526 EL_BD_MAGIC_WALL_FULL,
1527 EL_BD_MAGIC_WALL_FILLING,
1528 EL_BD_MAGIC_WALL_DEAD,
1537 EL_SP_TERMINAL_ACTIVE,
1541 EL_INVISIBLE_WALL_ACTIVE,
1542 EL_SWITCHGATE_SWITCH_UP,
1543 EL_SWITCHGATE_SWITCH_DOWN,
1545 EL_TIMEGATE_SWITCH_ACTIVE,
1546 EL_EMC_WALL_PILLAR_UPPER,
1547 EL_EMC_WALL_PILLAR_MIDDLE,
1548 EL_EMC_WALL_PILLAR_LOWER,
1557 /* the following elements are a direct copy of "indestructible" elements,
1558 except "EL_ACID", which is "indestructible", but not "solid"! */
1563 EL_ACIDPOOL_TOPLEFT,
1564 EL_ACIDPOOL_TOPRIGHT,
1565 EL_ACIDPOOL_BOTTOMLEFT,
1567 EL_ACIDPOOL_BOTTOMRIGHT,
1579 EL_INVISIBLE_STEELWALL,
1580 EL_INVISIBLE_STEELWALL_ACTIVE,
1581 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1582 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1583 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1584 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1585 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1586 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1587 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1588 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1589 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1590 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1591 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1592 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1594 EL_LIGHT_SWITCH_ACTIVE,
1595 EL_SIGN_EXCLAMATION,
1596 EL_SIGN_RADIOACTIVITY,
1607 EL_STEELWALL_SLANTED,
1630 EL_SWITCHGATE_OPENING,
1631 EL_SWITCHGATE_CLOSED,
1632 EL_SWITCHGATE_CLOSING,
1634 EL_TIMEGATE_OPENING,
1636 EL_TIMEGATE_CLOSING,
1640 EL_TUBE_VERTICAL_LEFT,
1641 EL_TUBE_VERTICAL_RIGHT,
1642 EL_TUBE_HORIZONTAL_UP,
1643 EL_TUBE_HORIZONTAL_DOWN,
1649 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1651 static int ep_indestructible[] =
1655 EL_ACIDPOOL_TOPLEFT,
1656 EL_ACIDPOOL_TOPRIGHT,
1657 EL_ACIDPOOL_BOTTOMLEFT,
1659 EL_ACIDPOOL_BOTTOMRIGHT,
1671 EL_INVISIBLE_STEELWALL,
1672 EL_INVISIBLE_STEELWALL_ACTIVE,
1673 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1674 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1675 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1676 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1677 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1678 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1679 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1680 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1681 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1682 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1683 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1684 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1686 EL_LIGHT_SWITCH_ACTIVE,
1687 EL_SIGN_EXCLAMATION,
1688 EL_SIGN_RADIOACTIVITY,
1699 EL_STEELWALL_SLANTED,
1722 EL_SWITCHGATE_OPENING,
1723 EL_SWITCHGATE_CLOSED,
1724 EL_SWITCHGATE_CLOSING,
1726 EL_TIMEGATE_OPENING,
1728 EL_TIMEGATE_CLOSING,
1732 EL_TUBE_VERTICAL_LEFT,
1733 EL_TUBE_VERTICAL_RIGHT,
1734 EL_TUBE_HORIZONTAL_UP,
1735 EL_TUBE_HORIZONTAL_DOWN,
1741 static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible);
1743 static int ep_slippery[] =
1757 EL_ROBOT_WHEEL_ACTIVE,
1763 EL_ACIDPOOL_TOPLEFT,
1764 EL_ACIDPOOL_TOPRIGHT,
1774 EL_STEELWALL_SLANTED,
1778 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1780 static int ep_enemy[] =
1793 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1795 static int ep_mauer[] =
1823 EL_WALL_GROWING_ACTIVE,
1842 EL_SP_TERMINAL_ACTIVE,
1845 EL_INVISIBLE_STEELWALL,
1846 EL_INVISIBLE_STEELWALL_ACTIVE,
1848 EL_INVISIBLE_WALL_ACTIVE,
1849 EL_STEELWALL_SLANTED,
1854 EL_EMC_WALL_PILLAR_UPPER,
1855 EL_EMC_WALL_PILLAR_MIDDLE,
1856 EL_EMC_WALL_PILLAR_LOWER,
1863 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1865 static int ep_can_fall[] =
1880 EL_BD_MAGIC_WALL_FULL,
1891 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1893 static int ep_can_smash[] =
1916 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1918 static int ep_can_change[] =
1929 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1931 static int ep_can_move[] =
1951 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1953 static int ep_could_move[] =
1963 EL_BD_BUTTERFLY_RIGHT,
1965 EL_BD_BUTTERFLY_LEFT,
1966 EL_BD_BUTTERFLY_DOWN,
1967 EL_BD_FIREFLY_RIGHT,
1976 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1978 static int ep_dont_touch[] =
1985 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1987 static int ep_dont_go_to[] =
2001 EL_SP_BUGGY_BASE_ACTIVE,
2005 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
2007 static int ep_mampf2[] =
2032 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
2034 static int ep_bd_element[] =
2061 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
2063 static int ep_sb_element[] =
2068 EL_SOKOBAN_FIELD_EMPTY,
2069 EL_SOKOBAN_FIELD_FULL,
2071 EL_INVISIBLE_STEELWALL
2073 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
2075 static int ep_gem[] =
2084 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
2086 static int ep_inactive[] =
2123 EL_INVISIBLE_STEELWALL,
2131 EL_WALL_EMERALD_YELLOW,
2136 EL_SOKOBAN_FIELD_EMPTY,
2137 EL_SOKOBAN_FIELD_FULL,
2138 EL_WALL_EMERALD_RED,
2139 EL_WALL_EMERALD_PURPLE,
2140 EL_ACIDPOOL_TOPLEFT,
2141 EL_ACIDPOOL_TOPRIGHT,
2142 EL_ACIDPOOL_BOTTOMLEFT,
2144 EL_ACIDPOOL_BOTTOMRIGHT,
2148 EL_BD_MAGIC_WALL_DEAD,
2149 EL_AMOEBA_TO_DIAMOND,
2182 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2183 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2184 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2185 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2186 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2187 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2188 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2189 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2190 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2191 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2192 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2193 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2194 EL_SIGN_EXCLAMATION,
2195 EL_SIGN_RADIOACTIVITY,
2206 EL_STEELWALL_SLANTED,
2211 EL_EMC_WALL_PILLAR_UPPER,
2212 EL_EMC_WALL_PILLAR_MIDDLE,
2213 EL_EMC_WALL_PILLAR_LOWER,
2220 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
2222 static int ep_explosive[] =
2227 EL_DYNABOMB_PLAYER1_ACTIVE,
2228 EL_DYNABOMB_PLAYER2_ACTIVE,
2229 EL_DYNABOMB_PLAYER3_ACTIVE,
2230 EL_DYNABOMB_PLAYER4_ACTIVE,
2234 EL_SP_DISK_RED_ACTIVE,
2248 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
2250 static int ep_mampf3[] =
2261 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
2263 static int ep_pushable[] =
2270 EL_SOKOBAN_FIELD_FULL,
2280 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
2282 static int ep_player[] =
2289 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
2291 static int ep_has_content[] =
2299 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
2301 static int ep_eatable[] =
2306 EL_SP_BUGGY_BASE_ACTIVATING,
2309 EL_INVISIBLE_SAND_ACTIVE
2311 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
2313 static int ep_sp_element[] =
2356 /* additional elements that appeared in newer Supaplex levels */
2358 /* more than one murphy in a level results in an inactive clone */
2361 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
2363 static int ep_quick_gate[] =
2387 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
2389 static int ep_over_player[] =
2405 EL_TUBE_VERTICAL_LEFT,
2406 EL_TUBE_VERTICAL_RIGHT,
2407 EL_TUBE_HORIZONTAL_UP,
2408 EL_TUBE_HORIZONTAL_DOWN,
2414 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
2416 static int ep_active_bomb[] =
2419 EL_DYNABOMB_PLAYER1_ACTIVE,
2420 EL_DYNABOMB_PLAYER2_ACTIVE,
2421 EL_DYNABOMB_PLAYER3_ACTIVE,
2422 EL_DYNABOMB_PLAYER4_ACTIVE,
2423 EL_SP_DISK_RED_ACTIVE
2425 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
2427 static int ep_belt[] =
2429 EL_CONVEYOR_BELT1_LEFT,
2430 EL_CONVEYOR_BELT1_MIDDLE,
2431 EL_CONVEYOR_BELT1_RIGHT,
2432 EL_CONVEYOR_BELT2_LEFT,
2433 EL_CONVEYOR_BELT2_MIDDLE,
2434 EL_CONVEYOR_BELT2_RIGHT,
2435 EL_CONVEYOR_BELT3_LEFT,
2436 EL_CONVEYOR_BELT3_MIDDLE,
2437 EL_CONVEYOR_BELT3_RIGHT,
2438 EL_CONVEYOR_BELT4_LEFT,
2439 EL_CONVEYOR_BELT4_MIDDLE,
2440 EL_CONVEYOR_BELT4_RIGHT,
2442 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
2444 static int ep_belt_active[] =
2446 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
2447 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
2448 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
2449 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
2450 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
2451 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
2452 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
2453 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
2454 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
2455 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
2456 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
2457 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
2459 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
2461 static int ep_belt_switch[] =
2463 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2464 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2465 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2466 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2467 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2468 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2469 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2470 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2471 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2472 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2473 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2474 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2476 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
2478 static int ep_tube[] =
2483 EL_TUBE_VERTICAL_LEFT,
2484 EL_TUBE_VERTICAL_RIGHT,
2485 EL_TUBE_HORIZONTAL_UP,
2486 EL_TUBE_HORIZONTAL_DOWN,
2492 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
2494 static long ep1_bit[] =
2501 EP_BIT_INDESTRUCTIBLE,
2528 static long ep2_bit[] =
2535 static int *ep1_array[] =
2569 static int *ep2_array[] =
2576 static int *ep1_num[] =
2583 &ep_indestructible_num,
2603 &ep_has_content_num,
2607 &ep_over_player_num,
2610 static int *ep2_num[] =
2613 &ep_belt_active_num,
2614 &ep_belt_switch_num,
2617 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2618 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2620 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2626 for (i=0; i<num_properties1; i++)
2627 for (j=0; j<*(ep1_num[i]); j++)
2628 Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
2629 for (i=0; i<num_properties2; i++)
2630 for (j=0; j<*(ep2_num[i]); j++)
2631 Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
2633 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2634 Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2637 void Execute_Command(char *command)
2639 if (strcmp(command, "print graphicsinfo.conf") == 0)
2643 printf("# You can configure additional/alternative image files here.\n");
2644 printf("# (The images below are default and therefore commented out.)\n");
2646 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2648 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2651 for (i=0; image_config[i].token != NULL; i++)
2653 getFormattedSetupEntry(image_config[i].token,
2654 image_config[i].value));
2658 else if (strcmp(command, "print soundsinfo.conf") == 0)
2662 printf("# You can configure additional/alternative sound files here.\n");
2663 printf("# (The sounds below are default and therefore commented out.)\n");
2665 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2667 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2670 for (i=0; sound_config[i].token != NULL; i++)
2672 getFormattedSetupEntry(sound_config[i].token,
2673 sound_config[i].value));
2677 else if (strcmp(command, "print musicinfo.conf") == 0)
2679 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2681 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2683 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2687 else if (strncmp(command, "dump level ", 11) == 0)
2689 char *filename = &command[11];
2691 if (access(filename, F_OK) != 0)
2692 Error(ERR_EXIT, "cannot open file '%s'", filename);
2694 LoadLevelFromFilename(filename);
2699 else if (strncmp(command, "dump tape ", 10) == 0)
2701 char *filename = &command[10];
2703 if (access(filename, F_OK) != 0)
2704 Error(ERR_EXIT, "cannot open file '%s'", filename);
2706 LoadTapeFromFilename(filename);
2711 else if (strncmp(command, "autoplay ", 9) == 0)
2713 char *str_copy = getStringCopy(&command[9]);
2714 char *str_ptr = strchr(str_copy, ' ');
2716 global.autoplay_leveldir = str_copy;
2717 global.autoplay_level_nr = -1;
2719 if (str_ptr != NULL)
2721 *str_ptr++ = '\0'; /* terminate leveldir string */
2722 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2727 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2731 void CloseAllAndExit(int exit_value)
2736 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2739 FreeTileClipmasks();
2741 CloseVideoDisplay();
2742 ClosePlatformDependantStuff();