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)
126 static void InitGlobal()
128 global.autoplay_leveldir = NULL;
130 global.frames_per_second = 0;
131 global.fps_slowdown = FALSE;
132 global.fps_slowdown_factor = 1;
135 static void InitSetup()
137 LoadSetup(); /* global setup info */
140 static void InitPlayerInfo()
144 /* choose default local player */
145 local_player = &stored_player[0];
147 for (i=0; i<MAX_PLAYERS; i++)
148 stored_player[i].connected = FALSE;
150 local_player->connected = TRUE;
153 static void InitLevelInfo()
155 LoadLevelInfo(); /* global level info */
156 LoadLevelSetup_LastSeries(); /* last played series info */
157 LoadLevelSetup_SeriesInfo(); /* last played level info */
160 static void InitArtworkInfo()
165 static void InitArtworkConfig()
167 static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
168 static char *sound_id_prefix[MAX_NUM_ELEMENTS + 1];
169 static char *action_id_suffix[NUM_ACTIONS + 1];
170 static char *direction_id_suffix[NUM_DIRECTIONS + 1];
171 static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
172 static char *dummy[1] = { NULL };
173 static char *ignore_image_tokens[] =
177 "menu.main.hide_static_text",
181 static char *ignore_sound_tokens[] =
189 for (i=0; i<MAX_NUM_ELEMENTS; i++)
190 image_id_prefix[i] = element_info[i].token_name;
191 for (i=0; i<NUM_FONTS + 1; i++)
192 image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
194 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
195 sound_id_prefix[i] = element_info[i].sound_class_name;
197 for (i=0; i<NUM_ACTIONS + 1; i++)
198 action_id_suffix[i] = element_action_info[i].suffix;
200 for (i=0; i<NUM_DIRECTIONS + 1; i++)
201 direction_id_suffix[i] = element_direction_info[i].suffix;
203 for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
204 special_id_suffix[i] = special_suffix_info[i].suffix;
206 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
207 image_id_prefix, action_id_suffix, direction_id_suffix,
208 special_id_suffix, ignore_image_tokens);
209 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
210 sound_id_prefix, action_id_suffix, dummy,
211 dummy, ignore_sound_tokens);
214 void InitLevelArtworkInfo()
216 LoadLevelArtworkInfo();
219 void InitNetworkServer()
221 #if defined(PLATFORM_UNIX)
225 if (!options.network)
228 #if defined(PLATFORM_UNIX)
229 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
231 if (!ConnectToServer(options.server_host, options.server_port))
232 Error(ERR_EXIT, "cannot connect to network game server");
234 SendToServer_PlayerName(setup.player_name);
235 SendToServer_ProtocolVersion();
238 SendToServer_NrWanted(nr_wanted);
242 static void InitMixer()
248 static void ReinitializeGraphics()
250 InitElementGraphicInfo(); /* element game graphic mapping */
251 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
252 InitGraphicInfo(); /* graphic properties mapping */
254 InitElementSmallImages(); /* create editor and preview images */
255 InitFontGraphicInfo(); /* initialize text drawing functions */
257 SetMainBackgroundImage(IMG_BACKGROUND);
258 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
264 static void ReinitializeSounds()
266 InitElementSoundInfo(); /* element game sound mapping */
267 InitSoundInfo(); /* sound properties mapping */
269 InitPlaySoundLevel(); /* internal game sound settings */
272 static void ReinitializeMusic()
274 /* currently nothing to do */
277 static void InitImages()
279 ReloadCustomImages();
281 LoadCustomElementDescriptions();
282 LoadSpecialMenuDesignSettings();
284 ReinitializeGraphics();
287 static void InitSound()
289 InitReloadCustomSounds(artwork.snd_current->identifier);
290 ReinitializeSounds();
293 static void InitMusic()
295 InitReloadCustomMusic(artwork.mus_current->identifier);
299 static void InitTileClipmasks()
302 #if defined(TARGET_X11)
303 XGCValues clip_gc_values;
304 unsigned long clip_gc_valuemask;
306 #if defined(TARGET_X11_NATIVE)
316 tile_needs_clipping[] =
318 { GFX_SPIELER1_UP, 4 },
319 { GFX_SPIELER1_DOWN, 4 },
320 { GFX_SPIELER1_LEFT, 4 },
321 { GFX_SPIELER1_RIGHT, 4 },
322 { GFX_SPIELER1_PUSH_LEFT, 4 },
323 { GFX_SPIELER1_PUSH_RIGHT, 4 },
324 { GFX_SPIELER2_UP, 4 },
325 { GFX_SPIELER2_DOWN, 4 },
326 { GFX_SPIELER2_LEFT, 4 },
327 { GFX_SPIELER2_RIGHT, 4 },
328 { GFX_SPIELER2_PUSH_LEFT, 4 },
329 { GFX_SPIELER2_PUSH_RIGHT, 4 },
330 { GFX_SPIELER3_UP, 4 },
331 { GFX_SPIELER3_DOWN, 4 },
332 { GFX_SPIELER3_LEFT, 4 },
333 { GFX_SPIELER3_RIGHT, 4 },
334 { GFX_SPIELER3_PUSH_LEFT, 4 },
335 { GFX_SPIELER3_PUSH_RIGHT, 4 },
336 { GFX_SPIELER4_UP, 4 },
337 { GFX_SPIELER4_DOWN, 4 },
338 { GFX_SPIELER4_LEFT, 4 },
339 { GFX_SPIELER4_RIGHT, 4 },
340 { GFX_SPIELER4_PUSH_LEFT, 4 },
341 { GFX_SPIELER4_PUSH_RIGHT, 4 },
342 { GFX_SP_MURPHY, 1 },
343 { GFX_MURPHY_GO_LEFT, 3 },
344 { GFX_MURPHY_GO_RIGHT, 3 },
345 { GFX_MURPHY_SNAP_UP, 1 },
346 { GFX_MURPHY_SNAP_DOWN, 1 },
347 { GFX_MURPHY_SNAP_RIGHT, 1 },
348 { GFX_MURPHY_SNAP_LEFT, 1 },
349 { GFX_MURPHY_PUSH_RIGHT, 1 },
350 { GFX_MURPHY_PUSH_LEFT, 1 },
351 { GFX_GEBLUBBER, 4 },
354 { GFX_EXPLOSION, 8 },
355 { GFX_SOKOBAN_OBJEKT, 1 },
356 { GFX_FUNKELN_BLAU, 3 },
357 { GFX_FUNKELN_WEISS, 3 },
358 { GFX2_SHIELD_PASSIVE, 3 },
359 { GFX2_SHIELD_ACTIVE, 3 },
364 #endif /* TARGET_X11_NATIVE */
365 #endif /* TARGET_X11 */
369 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
370 for (i=0; i<NUM_TILES; i++)
371 tile_clipmask[i] = None;
373 #if defined(TARGET_X11)
374 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
375 often very slow when preparing a masked XCopyArea() for big Pixmaps.
376 To prevent this, create small (tile-sized) mask Pixmaps which will then
377 be set much faster with XSetClipOrigin() and speed things up a lot. */
379 clip_gc_values.graphics_exposures = False;
380 clip_gc_valuemask = GCGraphicsExposures;
381 tile_clip_gc = XCreateGC(display, window->drawable,
382 clip_gc_valuemask, &clip_gc_values);
385 for (i=0; i<NUM_BITMAPS; i++)
387 if (pix[i]->clip_mask)
389 clip_gc_values.graphics_exposures = False;
390 clip_gc_values.clip_mask = pix[i]->clip_mask;
391 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
392 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
393 clip_gc_valuemask, &clip_gc_values);
398 #if defined(TARGET_X11_NATIVE)
401 /* create graphic context structures needed for clipping */
402 clip_gc_values.graphics_exposures = False;
403 clip_gc_valuemask = GCGraphicsExposures;
404 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
405 clip_gc_valuemask, &clip_gc_values);
407 /* create only those clipping Pixmaps we really need */
408 for (i=0; tile_needs_clipping[i].start>=0; i++)
412 for (j=0; j<tile_needs_clipping[i].count; j++)
414 int tile = tile_needs_clipping[i].start + j;
420 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
421 src_pixmap = src_bitmap->clip_mask;
423 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
426 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
427 src_x, src_y, TILEX, TILEY, 0, 0);
431 XFreeGC(display, copy_clipmask_gc);
434 #endif /* TARGET_X11_NATIVE */
435 #endif /* TARGET_X11 */
439 void FreeTileClipmasks()
442 #if defined(TARGET_X11)
445 for (i=0; i<NUM_TILES; i++)
447 if (tile_clipmask[i] != None)
449 XFreePixmap(display, tile_clipmask[i]);
450 tile_clipmask[i] = None;
455 XFreeGC(display, tile_clip_gc);
459 for (i=0; i<NUM_BITMAPS; i++)
461 if (pix[i] != NULL && pix[i]->stored_clip_gc)
463 XFreeGC(display, pix[i]->stored_clip_gc);
464 pix[i]->stored_clip_gc = None;
469 #endif /* TARGET_X11 */
475 char *filename_font_initial = NULL;
476 Bitmap *bitmap_font_initial = NULL;
479 /* determine settings for initial font (for displaying startup messages) */
480 for (i=0; image_config[i].token != NULL; i++)
482 for (j=0; j < NUM_INITIAL_FONTS; j++)
484 char font_token[128];
487 sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
488 len_font_token = strlen(font_token);
490 if (strcmp(image_config[i].token, font_token) == 0)
491 filename_font_initial = image_config[i].value;
492 else if (strlen(image_config[i].token) > len_font_token &&
493 strncmp(image_config[i].token, font_token, len_font_token) == 0)
495 if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
496 font_initial[j].src_x = atoi(image_config[i].value);
497 else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
498 font_initial[j].src_y = atoi(image_config[i].value);
499 else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
500 font_initial[j].width = atoi(image_config[i].value);
501 else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
502 font_initial[j].height = atoi(image_config[i].value);
507 if (filename_font_initial == NULL) /* should not happen */
508 Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
510 /* initialize screen properties */
511 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
512 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
513 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
514 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
515 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
517 /* create additional image buffers for double-buffering */
518 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
519 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
521 bitmap_font_initial = LoadCustomImage(filename_font_initial);
523 for (j=0; j < NUM_INITIAL_FONTS; j++)
524 font_initial[j].bitmap = bitmap_font_initial;
526 InitFontGraphicInfo();
528 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
529 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
531 DrawInitText("Loading graphics:", 120, FC_GREEN);
536 void InitGfxBackground()
541 fieldbuffer = bitmap_db_field;
542 SetDrawtoField(DRAW_BACKBUFFER);
544 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
545 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
546 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
547 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
549 for (x=0; x<MAX_BUF_XSIZE; x++)
550 for (y=0; y<MAX_BUF_YSIZE; y++)
553 redraw_mask = REDRAW_ALL;
556 void ReloadCustomArtwork()
558 static char *leveldir_current_identifier = NULL;
559 static boolean last_override_level_graphics = FALSE;
560 static boolean last_override_level_sounds = FALSE;
561 static boolean last_override_level_music = FALSE;
562 /* identifier for new artwork; default: artwork configured in setup */
563 char *gfx_new_identifier = artwork.gfx_current->identifier;
564 char *snd_new_identifier = artwork.snd_current->identifier;
565 char *mus_new_identifier = artwork.mus_current->identifier;
566 boolean redraw_screen = FALSE;
568 if (leveldir_current_identifier == NULL)
569 leveldir_current_identifier = leveldir_current->identifier;
572 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
573 leveldir_current->graphics_set);
574 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
575 leveldir_current->identifier);
579 printf("graphics --> '%s' ('%s')\n",
580 artwork.gfx_current_identifier, artwork.gfx_current->filename);
581 printf("sounds --> '%s' ('%s')\n",
582 artwork.snd_current_identifier, artwork.snd_current->filename);
583 printf("music --> '%s' ('%s')\n",
584 artwork.mus_current_identifier, artwork.mus_current->filename);
587 /* leveldir_current may be invalid (level group, parent link) */
588 if (!validLevelSeries(leveldir_current))
591 /* when a new level series was selected, check if there was a change
592 in custom artwork stored in level series directory */
593 if (leveldir_current_identifier != leveldir_current->identifier)
595 char *identifier_old = leveldir_current_identifier;
596 char *identifier_new = leveldir_current->identifier;
598 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
599 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
600 gfx_new_identifier = identifier_new;
601 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
602 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
603 snd_new_identifier = identifier_new;
604 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
605 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
606 mus_new_identifier = identifier_new;
608 leveldir_current_identifier = leveldir_current->identifier;
611 /* custom level artwork configured in level series configuration file
612 always overrides custom level artwork stored in level series directory
613 and (level independant) custom artwork configured in setup menue */
614 if (leveldir_current->graphics_set != NULL)
615 gfx_new_identifier = leveldir_current->graphics_set;
616 if (leveldir_current->sounds_set != NULL)
617 snd_new_identifier = leveldir_current->sounds_set;
618 if (leveldir_current->music_set != NULL)
619 mus_new_identifier = leveldir_current->music_set;
621 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
622 last_override_level_graphics != setup.override_level_graphics)
625 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
626 artwork.gfx_current_identifier,
627 artwork.gfx_current->identifier,
631 setLevelArtworkDir(artwork.gfx_first);
633 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
640 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
641 last_override_level_graphics = setup.override_level_graphics;
643 redraw_screen = TRUE;
646 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
647 last_override_level_sounds != setup.override_level_sounds)
650 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
651 artwork.snd_current_identifier,
652 artwork.snd_current->identifier,
656 /* set artwork path to send it to the sound server process */
657 setLevelArtworkDir(artwork.snd_first);
659 InitReloadCustomSounds(snd_new_identifier);
660 ReinitializeSounds();
662 artwork.snd_current_identifier = artwork.snd_current->identifier;
663 last_override_level_sounds = setup.override_level_sounds;
665 redraw_screen = TRUE;
668 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
669 last_override_level_music != setup.override_level_music)
671 /* set artwork path to send it to the sound server process */
672 setLevelArtworkDir(artwork.mus_first);
674 InitReloadCustomMusic(mus_new_identifier);
677 artwork.mus_current_identifier = artwork.mus_current->identifier;
678 last_override_level_music = setup.override_level_music;
680 redraw_screen = TRUE;
687 /* force redraw of (open or closed) door graphics */
688 SetDoorState(DOOR_OPEN_ALL);
689 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
695 FreeLevelEditorGadgets();
704 static boolean gadgets_initialized = FALSE;
706 if (gadgets_initialized)
709 CreateLevelEditorGadgets();
713 CreateScreenGadgets();
715 gadgets_initialized = TRUE;
718 void InitElementSmallImages()
720 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
721 int num_property_mappings = getImageListPropertyMappingSize();
724 /* initialize normal images from static configuration */
725 for (i=0; element_to_graphic[i].element > -1; i++)
726 CreateImageWithSmallImages(element_to_graphic[i].graphic);
728 /* initialize special images from static configuration */
729 for (i=0; element_to_special_graphic[i].element > -1; i++)
730 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
732 /* initialize images from dynamic configuration */
733 for (i=0; i < num_property_mappings; i++)
734 if (property_mapping[i].artwork_index < MAX_NUM_ELEMENTS)
735 CreateImageWithSmallImages(property_mapping[i].artwork_index);
738 static int getFontBitmapID(int font_nr)
740 if (game_status == LEVELED)
741 return font_info[font_nr].special_bitmap_id[GFX_SPECIAL_ARG_EDITOR];
746 void InitFontGraphicInfo()
748 static struct FontBitmapInfo *font_bitmap_info = NULL;
749 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
750 int num_property_mappings = getImageListPropertyMappingSize();
751 int num_font_bitmaps = NUM_FONTS;
754 if (graphic_info == NULL) /* still at startup phase */
756 InitFontInfo(font_initial, NUM_INITIAL_FONTS, getFontBitmapID);
761 /* ---------- initialize font graphic definitions ---------- */
763 /* always start with reliable default values (normal font graphics) */
764 for (i=0; i < NUM_FONTS; i++)
765 font_info[i].graphic = FONT_INITIAL_1;
767 /* initialize normal font/graphic mapping from static configuration */
768 for (i=0; font_to_graphic[i].font_nr > -1; i++)
770 int font_nr = font_to_graphic[i].font_nr;
771 int special = font_to_graphic[i].special;
772 int graphic = font_to_graphic[i].graphic;
777 font_info[font_nr].graphic = graphic;
780 /* always start with reliable default values (special font graphics) */
781 for (i=0; i < NUM_FONTS; i++)
783 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
785 font_info[i].special_graphic[j] = font_info[i].graphic;
786 font_info[i].special_bitmap_id[j] = i;
790 /* initialize special font/graphic mapping from static configuration */
791 for (i=0; font_to_graphic[i].font_nr > -1; i++)
793 int font_nr = font_to_graphic[i].font_nr;
794 int special = font_to_graphic[i].special;
795 int graphic = font_to_graphic[i].graphic;
797 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
799 font_info[font_nr].special_graphic[special] = graphic;
800 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
805 /* initialize special element/graphic mapping from dynamic configuration */
806 for (i=0; i < num_property_mappings; i++)
808 int font_nr = property_mapping[i].base_index - MAX_NUM_ELEMENTS;
809 int special = property_mapping[i].ext3_index;
810 int graphic = property_mapping[i].artwork_index;
815 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
817 font_info[font_nr].special_graphic[special] = graphic;
818 font_info[font_nr].special_bitmap_id[special] = num_font_bitmaps;
823 /* ---------- initialize font bitmap array ---------- */
825 if (font_bitmap_info != NULL)
826 free(font_bitmap_info);
829 checked_calloc(num_font_bitmaps * sizeof(struct FontBitmapInfo));
831 /* ---------- initialize font bitmap definitions ---------- */
833 for (i=0; i < NUM_FONTS; i++)
835 if (i < NUM_INITIAL_FONTS)
837 font_bitmap_info[i] = font_initial[i];
841 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
843 int font_bitmap_id = font_info[i].special_bitmap_id[j];
844 int graphic = font_info[i].special_graphic[j];
846 /* copy font relevant information from graphics information */
847 font_bitmap_info[font_bitmap_id].bitmap = graphic_info[graphic].bitmap;
848 font_bitmap_info[font_bitmap_id].src_x = graphic_info[graphic].src_x;
849 font_bitmap_info[font_bitmap_id].src_y = graphic_info[graphic].src_y;
850 font_bitmap_info[font_bitmap_id].width = graphic_info[graphic].width;
851 font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
852 font_bitmap_info[font_bitmap_id].draw_x = graphic_info[graphic].draw_x;
853 font_bitmap_info[font_bitmap_id].draw_y = graphic_info[graphic].draw_y;
857 InitFontInfo(font_bitmap_info, num_font_bitmaps, getFontBitmapID);
860 void InitElementGraphicInfo()
862 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
863 int num_property_mappings = getImageListPropertyMappingSize();
866 /* set values to -1 to identify later as "uninitialized" values */
867 for (i=0; i<MAX_NUM_ELEMENTS; i++)
869 for (act=0; act<NUM_ACTIONS; act++)
871 element_info[i].graphic[act] = -1;
873 for (dir=0; dir<NUM_DIRECTIONS; dir++)
874 element_info[i].direction_graphic[act][dir] = -1;
878 /* initialize normal element/graphic mapping from static configuration */
879 for (i=0; element_to_graphic[i].element > -1; i++)
881 int element = element_to_graphic[i].element;
882 int action = element_to_graphic[i].action;
883 int direction = element_to_graphic[i].direction;
884 int graphic = element_to_graphic[i].graphic;
887 action = ACTION_DEFAULT;
890 element_info[element].direction_graphic[action][direction] = graphic;
892 element_info[element].graphic[action] = graphic;
895 /* initialize normal element/graphic mapping from dynamic configuration */
896 for (i=0; i < num_property_mappings; i++)
898 int element = property_mapping[i].base_index;
899 int action = property_mapping[i].ext1_index;
900 int direction = property_mapping[i].ext2_index;
901 int special = property_mapping[i].ext3_index;
902 int graphic = property_mapping[i].artwork_index;
904 if (element >= MAX_NUM_ELEMENTS || special != -1)
908 action = ACTION_DEFAULT;
911 element_info[element].direction_graphic[action][direction] = graphic;
913 element_info[element].graphic[action] = graphic;
916 /* now set all '-1' values to element specific default values */
917 for (i=0; i<MAX_NUM_ELEMENTS; i++)
919 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
920 int default_action_direction_graphic[NUM_DIRECTIONS];
922 if (default_action_graphic == -1)
923 default_action_graphic = IMG_CHAR_QUESTION;
925 for (dir=0; dir<NUM_DIRECTIONS; dir++)
927 default_action_direction_graphic[dir] =
928 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
930 if (default_action_direction_graphic[dir] == -1)
931 default_action_direction_graphic[dir] = default_action_graphic;
934 for (act=0; act<NUM_ACTIONS; act++)
936 for (dir=0; dir<NUM_DIRECTIONS; dir++)
938 int default_direction_graphic = element_info[i].graphic[act];
940 /* no graphic for current action -- use default direction graphic */
941 if (default_direction_graphic == -1)
942 default_direction_graphic = default_action_direction_graphic[dir];
944 if (element_info[i].direction_graphic[act][dir] == -1)
945 element_info[i].direction_graphic[act][dir] =
946 default_direction_graphic;
949 /* no graphic for this specific action -- use default action graphic */
950 if (element_info[i].graphic[act] == -1)
951 element_info[i].graphic[act] = default_action_graphic;
959 for (i=0; i<MAX_NUM_ELEMENTS; i++)
960 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
961 i != EL_CHAR_QUESTION)
962 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
963 element_info[i].token_name, i);
969 void InitElementSpecialGraphicInfo()
971 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
972 int num_property_mappings = getImageListPropertyMappingSize();
975 /* always start with reliable default values */
976 for (i=0; i < MAX_NUM_ELEMENTS; i++)
977 for (j=0; j < NUM_SPECIAL_GFX_ARGS; j++)
978 element_info[i].special_graphic[j] =
979 element_info[i].graphic[ACTION_DEFAULT];
981 /* initialize special element/graphic mapping from static configuration */
982 for (i=0; element_to_special_graphic[i].element > -1; i++)
984 int element = element_to_special_graphic[i].element;
985 int special = element_to_special_graphic[i].special;
986 int graphic = element_to_special_graphic[i].graphic;
987 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
988 boolean special_redefined = getImageListEntry(graphic)->redefined;
990 if (base_redefined && !special_redefined)
993 element_info[element].special_graphic[special] = graphic;
996 /* initialize special element/graphic mapping from dynamic configuration */
997 for (i=0; i < num_property_mappings; i++)
999 int element = property_mapping[i].base_index;
1000 int special = property_mapping[i].ext3_index;
1001 int graphic = property_mapping[i].artwork_index;
1003 if (element >= MAX_NUM_ELEMENTS)
1006 if (special >= 0 && special < NUM_SPECIAL_GFX_ARGS)
1007 element_info[element].special_graphic[special] = graphic;
1011 static void set_graphic_parameters(int graphic, char **parameter_raw)
1013 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
1014 int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
1015 int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
1016 int parameter[NUM_GFX_ARGS];
1019 /* get integer values from string parameters */
1020 for (i=0; i < NUM_GFX_ARGS; i++)
1022 get_parameter_value(image_config_suffix[i].type, parameter_raw[i]);
1024 graphic_info[graphic].bitmap = src_bitmap;
1026 /* start with reliable default values */
1027 graphic_info[graphic].src_x = 0;
1028 graphic_info[graphic].src_y = 0;
1029 graphic_info[graphic].width = TILEX;
1030 graphic_info[graphic].height = TILEY;
1031 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
1032 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
1034 /* optional x and y tile position of animation frame sequence */
1035 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
1036 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
1037 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
1038 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
1040 /* optional x and y pixel position of animation frame sequence */
1041 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
1042 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
1043 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
1044 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
1046 /* optional width and height of each animation frame */
1047 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
1048 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
1049 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
1050 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
1052 /* correct x or y offset dependant of vertical or horizontal frame order */
1053 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
1055 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1056 graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
1058 graphic_info[graphic].offset_y = graphic_info[graphic].height;
1060 else /* frames are ordered horizontally */
1062 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
1063 graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
1065 graphic_info[graphic].offset_x = graphic_info[graphic].width;
1068 /* optionally, the x and y offset of frames can be specified directly */
1069 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
1070 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
1071 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
1072 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
1074 /* automatically determine correct number of frames, if not defined */
1075 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
1076 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
1077 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
1078 graphic_info[graphic].anim_frames = num_xtiles;
1079 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
1080 graphic_info[graphic].anim_frames = num_ytiles;
1082 graphic_info[graphic].anim_frames = 1;
1084 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
1085 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
1086 graphic_info[graphic].anim_delay = 1;
1088 /* set mode for animation frame order */
1089 if (parameter[GFX_ARG_MODE_LOOP])
1090 graphic_info[graphic].anim_mode = ANIM_LOOP;
1091 else if (parameter[GFX_ARG_MODE_LINEAR])
1092 graphic_info[graphic].anim_mode = ANIM_LINEAR;
1093 else if (parameter[GFX_ARG_MODE_PINGPONG])
1094 graphic_info[graphic].anim_mode = ANIM_PINGPONG;
1095 else if (parameter[GFX_ARG_MODE_PINGPONG2])
1096 graphic_info[graphic].anim_mode = ANIM_PINGPONG2;
1097 else if (parameter[GFX_ARG_MODE_RANDOM])
1098 graphic_info[graphic].anim_mode = ANIM_RANDOM;
1099 else if (graphic_info[graphic].anim_frames > 1)
1100 graphic_info[graphic].anim_mode = ANIM_LOOP;
1102 graphic_info[graphic].anim_mode = ANIM_NONE;
1104 /* set additional flag to play animation frames in reverse order */
1105 if (parameter[GFX_ARG_MODE_REVERSE])
1106 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
1108 /* automatically determine correct start frame, if not defined */
1109 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
1110 graphic_info[graphic].anim_start_frame = 0;
1111 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
1112 graphic_info[graphic].anim_start_frame =
1113 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
1115 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
1117 /* animation synchronized with global frame counter, not move position */
1118 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
1120 /* this is only used for toon animations */
1121 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
1122 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
1124 /* this is only used for drawing font characters */
1125 graphic_info[graphic].draw_x = parameter[GFX_ARG_DRAW_XOFFSET];
1126 graphic_info[graphic].draw_y = parameter[GFX_ARG_DRAW_YOFFSET];
1129 static void InitGraphicInfo()
1131 int fallback_graphic = IMG_CHAR_EXCLAM;
1132 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
1133 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
1134 int num_images = getImageListSize();
1137 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1138 static boolean clipmasks_initialized = FALSE;
1140 XGCValues clip_gc_values;
1141 unsigned long clip_gc_valuemask;
1142 GC copy_clipmask_gc = None;
1145 if (graphic_info != NULL)
1148 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
1150 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1151 if (clipmasks_initialized)
1153 for (i=0; i<num_images; i++)
1155 if (graphic_info[i].clip_mask)
1156 XFreePixmap(display, graphic_info[i].clip_mask);
1157 if (graphic_info[i].clip_gc)
1158 XFreeGC(display, graphic_info[i].clip_gc);
1160 graphic_info[i].clip_mask = None;
1161 graphic_info[i].clip_gc = None;
1166 for (i=0; i<num_images; i++)
1168 struct FileInfo *image = getImageListEntry(i);
1171 int first_frame, last_frame;
1173 set_graphic_parameters(i, image->parameter);
1175 /* now check if no animation frames are outside of the loaded image */
1177 if (graphic_info[i].bitmap == NULL)
1178 continue; /* skip check for optional images that are undefined */
1181 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1182 if (src_x < 0 || src_y < 0 ||
1183 src_x + TILEX > src_bitmap->width ||
1184 src_y + TILEY > src_bitmap->height)
1186 Error(ERR_RETURN_LINE, "-");
1187 Error(ERR_RETURN, "warning: error found in config file:");
1188 Error(ERR_RETURN, "- config file: '%s'",
1189 getImageConfigFilename());
1190 Error(ERR_RETURN, "- config token: '%s'",
1191 getTokenFromImageID(i));
1192 Error(ERR_RETURN, "- image file: '%s'",
1193 src_bitmap->source_filename);
1195 "error: first animation frame out of bounds (%d, %d)",
1197 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1199 if (i == fallback_graphic)
1200 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1202 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1203 Error(ERR_RETURN_LINE, "-");
1205 set_graphic_parameters(i, fallback_image->default_parameter);
1206 graphic_info[i].bitmap = fallback_bitmap;
1209 last_frame = graphic_info[i].anim_frames - 1;
1210 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1211 if (src_x < 0 || src_y < 0 ||
1212 src_x + TILEX > src_bitmap->width ||
1213 src_y + TILEY > src_bitmap->height)
1215 Error(ERR_RETURN_LINE, "-");
1216 Error(ERR_RETURN, "warning: error found in config file:");
1217 Error(ERR_RETURN, "- config file: '%s'",
1218 getImageConfigFilename());
1219 Error(ERR_RETURN, "- config token: '%s'",
1220 getTokenFromImageID(i));
1221 Error(ERR_RETURN, "- image file: '%s'",
1222 src_bitmap->source_filename);
1224 "error: last animation frame (%d) out of bounds (%d, %d)",
1225 last_frame, src_x, src_y);
1226 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1228 if (i == fallback_graphic)
1229 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1231 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1232 Error(ERR_RETURN_LINE, "-");
1234 set_graphic_parameters(i, fallback_image->default_parameter);
1235 graphic_info[i].bitmap = fallback_bitmap;
1238 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1239 /* currently we need only a tile clip mask from the first frame */
1240 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1242 if (copy_clipmask_gc == None)
1244 clip_gc_values.graphics_exposures = False;
1245 clip_gc_valuemask = GCGraphicsExposures;
1246 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1247 clip_gc_valuemask, &clip_gc_values);
1250 graphic_info[i].clip_mask =
1251 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1253 src_pixmap = src_bitmap->clip_mask;
1254 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1255 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1257 clip_gc_values.graphics_exposures = False;
1258 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1259 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1261 graphic_info[i].clip_gc =
1262 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1266 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1267 if (copy_clipmask_gc)
1268 XFreeGC(display, copy_clipmask_gc);
1270 clipmasks_initialized = TRUE;
1274 static void InitElementSoundInfo()
1276 /* !!! soon to come !!! */
1279 static void set_sound_parameters(int sound, char **parameter_raw)
1281 int parameter[NUM_SND_ARGS];
1284 /* get integer values from string parameters */
1285 for (i=0; i < NUM_SND_ARGS; i++)
1287 get_parameter_value(sound_config_suffix[i].type, parameter_raw[i]);
1289 /* explicit loop mode setting in configuration overrides default value */
1290 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1291 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1294 static void InitSoundInfo()
1296 struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
1297 int num_property_mappings = getSoundListPropertyMappingSize();
1298 int *sound_effect_properties;
1299 int num_sounds = getSoundListSize();
1302 if (sound_info != NULL)
1305 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1306 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1308 /* initialize sound effect for all elements to "no sound" */
1309 for (i=0; i<MAX_NUM_ELEMENTS; i++)
1310 for (j=0; j<NUM_ACTIONS; j++)
1311 element_info[i].sound[j] = SND_UNDEFINED;
1313 for (i=0; i<num_sounds; i++)
1315 struct FileInfo *sound = getSoundListEntry(i);
1316 int len_effect_text = strlen(sound->token);
1318 sound_effect_properties[i] = ACTION_OTHER;
1319 sound_info[i].loop = FALSE;
1321 /* determine all loop sounds and identify certain sound classes */
1323 for (j=0; element_action_info[j].suffix; j++)
1325 int len_action_text = strlen(element_action_info[j].suffix);
1327 if (len_action_text < len_effect_text &&
1328 strcmp(&sound->token[len_effect_text - len_action_text],
1329 element_action_info[j].suffix) == 0)
1331 sound_effect_properties[i] = element_action_info[j].value;
1333 if (element_action_info[j].is_loop_sound)
1334 sound_info[i].loop = TRUE;
1338 /* associate elements and some selected sound actions */
1340 for (j=0; j<MAX_NUM_ELEMENTS; j++)
1342 if (element_info[j].sound_class_name)
1344 int len_class_text = strlen(element_info[j].sound_class_name);
1346 if (len_class_text + 1 < len_effect_text &&
1347 strncmp(sound->token,
1348 element_info[j].sound_class_name, len_class_text) == 0 &&
1349 sound->token[len_class_text] == '.')
1351 int sound_action_value = sound_effect_properties[i];
1353 element_info[j].sound[sound_action_value] = i;
1358 set_sound_parameters(i, sound->parameter);
1361 free(sound_effect_properties);
1363 /* initialize element/sound mapping from dynamic configuration */
1364 for (i=0; i < num_property_mappings; i++)
1366 int element = property_mapping[i].base_index;
1367 int action = property_mapping[i].ext1_index;
1368 int sound = property_mapping[i].artwork_index;
1371 action = ACTION_DEFAULT;
1373 element_info[element].sound[action] = sound;
1379 int element = EL_CUSTOM_11;
1382 while (element_action_info[j].suffix)
1384 printf("element %d, sound action '%s' == %d\n",
1385 element, element_action_info[j].suffix,
1386 element_info[element].sound[j]);
1391 PlaySoundLevelElementAction(0,0, EL_CUSTOM_11, ACTION_PUSHING);
1397 int element = EL_SAND;
1398 int sound_action = ACTION_DIGGING;
1401 while (element_action_info[j].suffix)
1403 if (element_action_info[j].value == sound_action)
1404 printf("element %d, sound action '%s' == %d\n",
1405 element, element_action_info[j].suffix,
1406 element_info[element].sound[sound_action]);
1413 void InitElementProperties()
1417 static int ep_amoebalive[] =
1424 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
1426 static int ep_amoeboid[] =
1434 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
1436 static int ep_schluessel[] =
1447 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
1449 static int ep_pforte[] =
1468 EL_SWITCHGATE_OPENING,
1469 EL_SWITCHGATE_CLOSED,
1470 EL_SWITCHGATE_CLOSING,
1472 EL_TIMEGATE_OPENING,
1474 EL_TIMEGATE_CLOSING,
1478 EL_TUBE_VERTICAL_LEFT,
1479 EL_TUBE_VERTICAL_RIGHT,
1480 EL_TUBE_HORIZONTAL_UP,
1481 EL_TUBE_HORIZONTAL_DOWN,
1487 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
1489 static int ep_solid[] =
1508 EL_QUICKSAND_FILLING,
1509 EL_QUICKSAND_EMPTYING,
1511 EL_MAGIC_WALL_ACTIVE,
1512 EL_MAGIC_WALL_EMPTYING,
1513 EL_MAGIC_WALL_FILLING,
1517 EL_BD_MAGIC_WALL_ACTIVE,
1518 EL_BD_MAGIC_WALL_EMPTYING,
1519 EL_BD_MAGIC_WALL_FULL,
1520 EL_BD_MAGIC_WALL_FILLING,
1521 EL_BD_MAGIC_WALL_DEAD,
1530 EL_SP_TERMINAL_ACTIVE,
1534 EL_INVISIBLE_WALL_ACTIVE,
1535 EL_SWITCHGATE_SWITCH_UP,
1536 EL_SWITCHGATE_SWITCH_DOWN,
1538 EL_TIMEGATE_SWITCH_ACTIVE,
1539 EL_EMC_WALL_PILLAR_UPPER,
1540 EL_EMC_WALL_PILLAR_MIDDLE,
1541 EL_EMC_WALL_PILLAR_LOWER,
1550 /* the following elements are a direct copy of "indestructible" elements,
1551 except "EL_ACID", which is "indestructible", but not "solid"! */
1556 EL_ACIDPOOL_TOPLEFT,
1557 EL_ACIDPOOL_TOPRIGHT,
1558 EL_ACIDPOOL_BOTTOMLEFT,
1560 EL_ACIDPOOL_BOTTOMRIGHT,
1572 EL_INVISIBLE_STEELWALL,
1573 EL_INVISIBLE_STEELWALL_ACTIVE,
1574 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1575 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1576 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1577 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1578 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1579 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1580 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1581 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1582 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1583 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1584 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1585 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1587 EL_LIGHT_SWITCH_ACTIVE,
1588 EL_SIGN_EXCLAMATION,
1589 EL_SIGN_RADIOACTIVITY,
1600 EL_STEELWALL_SLANTED,
1623 EL_SWITCHGATE_OPENING,
1624 EL_SWITCHGATE_CLOSED,
1625 EL_SWITCHGATE_CLOSING,
1627 EL_TIMEGATE_OPENING,
1629 EL_TIMEGATE_CLOSING,
1633 EL_TUBE_VERTICAL_LEFT,
1634 EL_TUBE_VERTICAL_RIGHT,
1635 EL_TUBE_HORIZONTAL_UP,
1636 EL_TUBE_HORIZONTAL_DOWN,
1642 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1644 static int ep_indestructible[] =
1648 EL_ACIDPOOL_TOPLEFT,
1649 EL_ACIDPOOL_TOPRIGHT,
1650 EL_ACIDPOOL_BOTTOMLEFT,
1652 EL_ACIDPOOL_BOTTOMRIGHT,
1664 EL_INVISIBLE_STEELWALL,
1665 EL_INVISIBLE_STEELWALL_ACTIVE,
1666 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1667 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1668 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1669 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1670 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1671 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1672 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1673 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1674 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1675 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1676 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1677 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1679 EL_LIGHT_SWITCH_ACTIVE,
1680 EL_SIGN_EXCLAMATION,
1681 EL_SIGN_RADIOACTIVITY,
1692 EL_STEELWALL_SLANTED,
1715 EL_SWITCHGATE_OPENING,
1716 EL_SWITCHGATE_CLOSED,
1717 EL_SWITCHGATE_CLOSING,
1719 EL_TIMEGATE_OPENING,
1721 EL_TIMEGATE_CLOSING,
1725 EL_TUBE_VERTICAL_LEFT,
1726 EL_TUBE_VERTICAL_RIGHT,
1727 EL_TUBE_HORIZONTAL_UP,
1728 EL_TUBE_HORIZONTAL_DOWN,
1734 static int ep_indestructible_num = SIZEOF_ARRAY_INT(ep_indestructible);
1736 static int ep_slippery[] =
1750 EL_ROBOT_WHEEL_ACTIVE,
1756 EL_ACIDPOOL_TOPLEFT,
1757 EL_ACIDPOOL_TOPRIGHT,
1767 EL_STEELWALL_SLANTED,
1771 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1773 static int ep_enemy[] =
1786 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1788 static int ep_mauer[] =
1816 EL_WALL_GROWING_ACTIVE,
1835 EL_SP_TERMINAL_ACTIVE,
1838 EL_INVISIBLE_STEELWALL,
1839 EL_INVISIBLE_STEELWALL_ACTIVE,
1841 EL_INVISIBLE_WALL_ACTIVE,
1842 EL_STEELWALL_SLANTED,
1847 EL_EMC_WALL_PILLAR_UPPER,
1848 EL_EMC_WALL_PILLAR_MIDDLE,
1849 EL_EMC_WALL_PILLAR_LOWER,
1856 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1858 static int ep_can_fall[] =
1873 EL_BD_MAGIC_WALL_FULL,
1884 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1886 static int ep_can_smash[] =
1909 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1911 static int ep_can_change[] =
1922 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1924 static int ep_can_move[] =
1944 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1946 static int ep_could_move[] =
1956 EL_BD_BUTTERFLY_RIGHT,
1958 EL_BD_BUTTERFLY_LEFT,
1959 EL_BD_BUTTERFLY_DOWN,
1960 EL_BD_FIREFLY_RIGHT,
1969 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1971 static int ep_dont_touch[] =
1978 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1980 static int ep_dont_go_to[] =
1994 EL_SP_BUGGY_BASE_ACTIVE,
1998 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
2000 static int ep_mampf2[] =
2025 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
2027 static int ep_bd_element[] =
2054 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
2056 static int ep_sb_element[] =
2061 EL_SOKOBAN_FIELD_EMPTY,
2062 EL_SOKOBAN_FIELD_FULL,
2064 EL_INVISIBLE_STEELWALL
2066 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
2068 static int ep_gem[] =
2077 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
2079 static int ep_inactive[] =
2116 EL_INVISIBLE_STEELWALL,
2124 EL_WALL_EMERALD_YELLOW,
2129 EL_SOKOBAN_FIELD_EMPTY,
2130 EL_SOKOBAN_FIELD_FULL,
2131 EL_WALL_EMERALD_RED,
2132 EL_WALL_EMERALD_PURPLE,
2133 EL_ACIDPOOL_TOPLEFT,
2134 EL_ACIDPOOL_TOPRIGHT,
2135 EL_ACIDPOOL_BOTTOMLEFT,
2137 EL_ACIDPOOL_BOTTOMRIGHT,
2141 EL_BD_MAGIC_WALL_DEAD,
2142 EL_AMOEBA_TO_DIAMOND,
2175 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2176 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2177 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2178 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2179 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2180 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2181 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2182 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2183 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2184 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2185 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2186 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2187 EL_SIGN_EXCLAMATION,
2188 EL_SIGN_RADIOACTIVITY,
2199 EL_STEELWALL_SLANTED,
2204 EL_EMC_WALL_PILLAR_UPPER,
2205 EL_EMC_WALL_PILLAR_MIDDLE,
2206 EL_EMC_WALL_PILLAR_LOWER,
2213 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
2215 static int ep_explosive[] =
2220 EL_DYNABOMB_PLAYER1_ACTIVE,
2221 EL_DYNABOMB_PLAYER2_ACTIVE,
2222 EL_DYNABOMB_PLAYER3_ACTIVE,
2223 EL_DYNABOMB_PLAYER4_ACTIVE,
2240 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
2242 static int ep_mampf3[] =
2253 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
2255 static int ep_pushable[] =
2262 EL_SOKOBAN_FIELD_FULL,
2272 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
2274 static int ep_player[] =
2281 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
2283 static int ep_has_content[] =
2291 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
2293 static int ep_eatable[] =
2298 EL_SP_BUGGY_BASE_ACTIVATING,
2301 EL_INVISIBLE_SAND_ACTIVE
2303 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
2305 static int ep_sp_element[] =
2348 /* additional elements that appeared in newer Supaplex levels */
2350 /* more than one murphy in a level results in an inactive clone */
2353 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
2355 static int ep_quick_gate[] =
2379 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
2381 static int ep_over_player[] =
2397 EL_TUBE_VERTICAL_LEFT,
2398 EL_TUBE_VERTICAL_RIGHT,
2399 EL_TUBE_HORIZONTAL_UP,
2400 EL_TUBE_HORIZONTAL_DOWN,
2406 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
2408 static int ep_active_bomb[] =
2411 EL_DYNABOMB_PLAYER1_ACTIVE,
2412 EL_DYNABOMB_PLAYER2_ACTIVE,
2413 EL_DYNABOMB_PLAYER3_ACTIVE,
2414 EL_DYNABOMB_PLAYER4_ACTIVE
2416 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
2418 static int ep_belt[] =
2420 EL_CONVEYOR_BELT1_LEFT,
2421 EL_CONVEYOR_BELT1_MIDDLE,
2422 EL_CONVEYOR_BELT1_RIGHT,
2423 EL_CONVEYOR_BELT2_LEFT,
2424 EL_CONVEYOR_BELT2_MIDDLE,
2425 EL_CONVEYOR_BELT2_RIGHT,
2426 EL_CONVEYOR_BELT3_LEFT,
2427 EL_CONVEYOR_BELT3_MIDDLE,
2428 EL_CONVEYOR_BELT3_RIGHT,
2429 EL_CONVEYOR_BELT4_LEFT,
2430 EL_CONVEYOR_BELT4_MIDDLE,
2431 EL_CONVEYOR_BELT4_RIGHT,
2433 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
2435 static int ep_belt_active[] =
2437 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
2438 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
2439 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
2440 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
2441 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
2442 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
2443 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
2444 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
2445 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
2446 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
2447 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
2448 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
2450 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
2452 static int ep_belt_switch[] =
2454 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2455 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2456 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2457 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2458 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2459 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2460 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2461 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2462 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2463 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2464 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2465 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2467 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
2469 static int ep_tube[] =
2474 EL_TUBE_VERTICAL_LEFT,
2475 EL_TUBE_VERTICAL_RIGHT,
2476 EL_TUBE_HORIZONTAL_UP,
2477 EL_TUBE_HORIZONTAL_DOWN,
2483 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
2485 static long ep1_bit[] =
2492 EP_BIT_INDESTRUCTIBLE,
2519 static long ep2_bit[] =
2526 static int *ep1_array[] =
2560 static int *ep2_array[] =
2567 static int *ep1_num[] =
2574 &ep_indestructible_num,
2594 &ep_has_content_num,
2598 &ep_over_player_num,
2601 static int *ep2_num[] =
2604 &ep_belt_active_num,
2605 &ep_belt_switch_num,
2608 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2609 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2611 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2617 for (i=0; i<num_properties1; i++)
2618 for (j=0; j<*(ep1_num[i]); j++)
2619 Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
2620 for (i=0; i<num_properties2; i++)
2621 for (j=0; j<*(ep2_num[i]); j++)
2622 Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
2624 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2625 Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2628 void Execute_Command(char *command)
2630 if (strcmp(command, "print graphicsinfo.conf") == 0)
2634 printf("# You can configure additional/alternative image files here.\n");
2635 printf("# (The images below are default and therefore commented out.)\n");
2637 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2639 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2642 for (i=0; image_config[i].token != NULL; i++)
2644 getFormattedSetupEntry(image_config[i].token,
2645 image_config[i].value));
2649 else if (strcmp(command, "print soundsinfo.conf") == 0)
2653 printf("# You can configure additional/alternative sound files here.\n");
2654 printf("# (The sounds below are default and therefore commented out.)\n");
2656 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2658 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2661 for (i=0; sound_config[i].token != NULL; i++)
2663 getFormattedSetupEntry(sound_config[i].token,
2664 sound_config[i].value));
2668 else if (strcmp(command, "print musicinfo.conf") == 0)
2670 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2672 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2674 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2678 else if (strncmp(command, "dump level ", 11) == 0)
2680 char *filename = &command[11];
2682 if (access(filename, F_OK) != 0)
2683 Error(ERR_EXIT, "cannot open file '%s'", filename);
2685 LoadLevelFromFilename(filename);
2690 else if (strncmp(command, "dump tape ", 10) == 0)
2692 char *filename = &command[10];
2694 if (access(filename, F_OK) != 0)
2695 Error(ERR_EXIT, "cannot open file '%s'", filename);
2697 LoadTapeFromFilename(filename);
2702 else if (strncmp(command, "autoplay ", 9) == 0)
2704 char *str_copy = getStringCopy(&command[9]);
2705 char *str_ptr = strchr(str_copy, ' ');
2707 global.autoplay_leveldir = str_copy;
2708 global.autoplay_level_nr = -1;
2710 if (str_ptr != NULL)
2712 *str_ptr++ = '\0'; /* terminate leveldir string */
2713 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2718 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2722 void CloseAllAndExit(int exit_value)
2727 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2730 FreeTileClipmasks();
2732 CloseVideoDisplay();
2733 ClosePlatformDependantStuff();