1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-2002 Artsoft Entertainment *
6 * Detmolder Strasse 189 *
9 * e-mail: info@artsoft.org *
10 *----------------------------------------------------------*
12 ***********************************************************/
14 #include "libgame/libgame.h"
29 #include "conf_e2g.c" /* include auto-generated data structure definitions */
30 #include "conf_esg.c" /* include auto-generated data structure definitions */
33 static Bitmap *bitmap_font_initial = NULL;
35 static void InitGlobal();
36 static void InitSetup();
37 static void InitPlayerInfo();
38 static void InitLevelInfo();
39 static void InitArtworkInfo();
40 static void InitLevelArtworkInfo();
41 static void InitNetworkServer();
42 static void InitArtworkConfig();
43 static void InitImages();
44 static void InitMixer();
45 static void InitSound();
46 static void InitMusic();
47 static void InitGfx();
48 static void InitGfxBackground();
49 static void InitGadgets();
50 static void InitElementSmallImages();
51 static void InitElementGraphicInfo();
52 static void InitElementSpecialGraphicInfo();
53 static void InitElementSoundInfo();
54 static void InitElementProperties();
55 static void InitGraphicInfo();
56 static void InitSoundInfo();
57 static void Execute_Command(char *);
61 InitGlobal(); /* initialize some global variables */
63 if (options.execute_command)
64 Execute_Command(options.execute_command);
66 if (options.serveronly)
68 #if defined(PLATFORM_UNIX)
69 NetworkServer(options.server_port, options.serveronly);
71 Error(ERR_WARN, "networking only supported in Unix version");
73 exit(0); /* never reached */
76 InitProgramInfo(UNIX_USERDATA_DIRECTORY,
77 PROGRAM_TITLE_STRING, getWindowTitleString(),
78 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
79 MSDOS_POINTER_FILENAME,
80 COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
84 InitArtworkInfo(); /* needed before loading gfx, sound & music */
85 InitArtworkConfig(); /* needed before forking sound child process */
91 InitRND(NEW_RANDOMIZE);
94 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
97 InitEventFilter(FilterMouseMotionEvents);
99 InitElementProperties();
104 InitLevelArtworkInfo();
106 InitImages(); /* needs to know current level directory */
107 InitSound(); /* needs to know current level directory */
108 InitMusic(); /* needs to know current level directory */
112 if (global.autoplay_leveldir)
123 static void InitGlobal()
125 global.autoplay_leveldir = NULL;
127 global.frames_per_second = 0;
128 global.fps_slowdown = FALSE;
129 global.fps_slowdown_factor = 1;
132 static void InitSetup()
134 LoadSetup(); /* global setup info */
137 static void InitPlayerInfo()
141 /* choose default local player */
142 local_player = &stored_player[0];
144 for (i=0; i<MAX_PLAYERS; i++)
145 stored_player[i].connected = FALSE;
147 local_player->connected = TRUE;
150 static void InitLevelInfo()
152 LoadLevelInfo(); /* global level info */
153 LoadLevelSetup_LastSeries(); /* last played series info */
154 LoadLevelSetup_SeriesInfo(); /* last played level info */
157 static void InitArtworkInfo()
162 static void InitArtworkConfig()
164 static char *element_prefix[MAX_NUM_ELEMENTS + 1];
165 static char *sound_class_prefix[MAX_NUM_ELEMENTS + 1];
166 static char *action_suffix[NUM_ACTIONS + 1];
167 static char *direction_suffix[NUM_DIRECTIONS + 1];
168 static char *special_suffix[NUM_SPECIAL_GFX_ARGS + 1];
169 static char *dummy[1] = { NULL };
172 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
173 element_prefix[i] = element_info[i].token_name;
174 for (i=0; i<MAX_NUM_ELEMENTS + 1; i++)
175 sound_class_prefix[i] = element_info[i].sound_class_name;
176 for (i=0; i<NUM_ACTIONS + 1; i++)
177 action_suffix[i] = element_action_info[i].suffix;
178 for (i=0; i<NUM_DIRECTIONS + 1; i++)
179 direction_suffix[i] = element_direction_info[i].suffix;
180 for (i=0; i<NUM_SPECIAL_GFX_ARGS + 1; i++)
181 special_suffix[i] = special_suffix_info[i].suffix;
183 InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
184 element_prefix, action_suffix,direction_suffix,special_suffix);
185 InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
186 sound_class_prefix, action_suffix, dummy, dummy);
189 void InitLevelArtworkInfo()
191 LoadLevelArtworkInfo();
194 void InitNetworkServer()
196 #if defined(PLATFORM_UNIX)
200 if (!options.network)
203 #if defined(PLATFORM_UNIX)
204 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
206 if (!ConnectToServer(options.server_host, options.server_port))
207 Error(ERR_EXIT, "cannot connect to network game server");
209 SendToServer_PlayerName(setup.player_name);
210 SendToServer_ProtocolVersion();
213 SendToServer_NrWanted(nr_wanted);
217 static void InitMixer()
223 static void ReinitializeGraphics()
225 InitElementGraphicInfo(); /* element game graphic mapping */
226 InitElementSpecialGraphicInfo(); /* element special graphic mapping */
227 InitGraphicInfo(); /* graphic properties mapping */
229 InitElementSmallImages(); /* create editor and preview images */
231 InitFontInfo(bitmap_font_initial,
232 graphic_info[IMG_FONT_BIG].bitmap,
233 graphic_info[IMG_FONT_MEDIUM].bitmap,
234 graphic_info[IMG_FONT_SMALL].bitmap,
235 graphic_info[IMG_FONT_EM].bitmap);
237 SetMainBackgroundImage(IMG_BACKGROUND_DEFAULT);
238 SetDoorBackgroundImage(IMG_BACKGROUND_DOOR);
244 static void ReinitializeSounds()
246 InitElementSoundInfo(); /* element game sound mapping */
247 InitSoundInfo(); /* sound properties mapping */
249 InitPlaySoundLevel(); /* internal game sound settings */
252 static void ReinitializeMusic()
254 /* currently nothing to do */
257 static void InitImages()
259 ReloadCustomImages();
260 ReinitializeGraphics();
262 LoadCustomElementDescriptions();
263 LoadSpecialMenuDesignSettings();
266 static void InitSound()
268 InitReloadCustomSounds(artwork.snd_current->identifier);
269 ReinitializeSounds();
272 static void InitMusic()
274 InitReloadCustomMusic(artwork.mus_current->identifier);
278 static void InitTileClipmasks()
281 #if defined(TARGET_X11)
282 XGCValues clip_gc_values;
283 unsigned long clip_gc_valuemask;
285 #if defined(TARGET_X11_NATIVE)
295 tile_needs_clipping[] =
297 { GFX_SPIELER1_UP, 4 },
298 { GFX_SPIELER1_DOWN, 4 },
299 { GFX_SPIELER1_LEFT, 4 },
300 { GFX_SPIELER1_RIGHT, 4 },
301 { GFX_SPIELER1_PUSH_LEFT, 4 },
302 { GFX_SPIELER1_PUSH_RIGHT, 4 },
303 { GFX_SPIELER2_UP, 4 },
304 { GFX_SPIELER2_DOWN, 4 },
305 { GFX_SPIELER2_LEFT, 4 },
306 { GFX_SPIELER2_RIGHT, 4 },
307 { GFX_SPIELER2_PUSH_LEFT, 4 },
308 { GFX_SPIELER2_PUSH_RIGHT, 4 },
309 { GFX_SPIELER3_UP, 4 },
310 { GFX_SPIELER3_DOWN, 4 },
311 { GFX_SPIELER3_LEFT, 4 },
312 { GFX_SPIELER3_RIGHT, 4 },
313 { GFX_SPIELER3_PUSH_LEFT, 4 },
314 { GFX_SPIELER3_PUSH_RIGHT, 4 },
315 { GFX_SPIELER4_UP, 4 },
316 { GFX_SPIELER4_DOWN, 4 },
317 { GFX_SPIELER4_LEFT, 4 },
318 { GFX_SPIELER4_RIGHT, 4 },
319 { GFX_SPIELER4_PUSH_LEFT, 4 },
320 { GFX_SPIELER4_PUSH_RIGHT, 4 },
321 { GFX_SP_MURPHY, 1 },
322 { GFX_MURPHY_GO_LEFT, 3 },
323 { GFX_MURPHY_GO_RIGHT, 3 },
324 { GFX_MURPHY_SNAP_UP, 1 },
325 { GFX_MURPHY_SNAP_DOWN, 1 },
326 { GFX_MURPHY_SNAP_RIGHT, 1 },
327 { GFX_MURPHY_SNAP_LEFT, 1 },
328 { GFX_MURPHY_PUSH_RIGHT, 1 },
329 { GFX_MURPHY_PUSH_LEFT, 1 },
330 { GFX_GEBLUBBER, 4 },
333 { GFX_EXPLOSION, 8 },
334 { GFX_SOKOBAN_OBJEKT, 1 },
335 { GFX_FUNKELN_BLAU, 3 },
336 { GFX_FUNKELN_WEISS, 3 },
337 { GFX2_SHIELD_PASSIVE, 3 },
338 { GFX2_SHIELD_ACTIVE, 3 },
343 #endif /* TARGET_X11_NATIVE */
344 #endif /* TARGET_X11 */
348 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
349 for (i=0; i<NUM_TILES; i++)
350 tile_clipmask[i] = None;
352 #if defined(TARGET_X11)
353 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
354 often very slow when preparing a masked XCopyArea() for big Pixmaps.
355 To prevent this, create small (tile-sized) mask Pixmaps which will then
356 be set much faster with XSetClipOrigin() and speed things up a lot. */
358 clip_gc_values.graphics_exposures = False;
359 clip_gc_valuemask = GCGraphicsExposures;
360 tile_clip_gc = XCreateGC(display, window->drawable,
361 clip_gc_valuemask, &clip_gc_values);
364 for (i=0; i<NUM_BITMAPS; i++)
366 if (pix[i]->clip_mask)
368 clip_gc_values.graphics_exposures = False;
369 clip_gc_values.clip_mask = pix[i]->clip_mask;
370 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
371 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
372 clip_gc_valuemask, &clip_gc_values);
377 #if defined(TARGET_X11_NATIVE)
380 /* create graphic context structures needed for clipping */
381 clip_gc_values.graphics_exposures = False;
382 clip_gc_valuemask = GCGraphicsExposures;
383 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
384 clip_gc_valuemask, &clip_gc_values);
386 /* create only those clipping Pixmaps we really need */
387 for (i=0; tile_needs_clipping[i].start>=0; i++)
391 for (j=0; j<tile_needs_clipping[i].count; j++)
393 int tile = tile_needs_clipping[i].start + j;
399 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
400 src_pixmap = src_bitmap->clip_mask;
402 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
405 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
406 src_x, src_y, TILEX, TILEY, 0, 0);
410 XFreeGC(display, copy_clipmask_gc);
413 #endif /* TARGET_X11_NATIVE */
414 #endif /* TARGET_X11 */
418 void FreeTileClipmasks()
421 #if defined(TARGET_X11)
424 for (i=0; i<NUM_TILES; i++)
426 if (tile_clipmask[i] != None)
428 XFreePixmap(display, tile_clipmask[i]);
429 tile_clipmask[i] = None;
434 XFreeGC(display, tile_clip_gc);
438 for (i=0; i<NUM_BITMAPS; i++)
440 if (pix[i] != NULL && pix[i]->stored_clip_gc)
442 XFreeGC(display, pix[i]->stored_clip_gc);
443 pix[i]->stored_clip_gc = None;
448 #endif /* TARGET_X11 */
454 char *config_token_font_initial = "font.small";
455 char *filename_font_initial = NULL;
458 /* determine filename for initial font (for displaying startup messages) */
459 for (i=0; image_config[i].token != NULL; i++)
460 if (strcmp(image_config[i].token, config_token_font_initial) == 0)
461 filename_font_initial = image_config[i].value;
463 if (filename_font_initial == NULL) /* should not happen */
464 Error(ERR_EXIT, "cannot get filename for '%s'", config_token_font_initial);
466 /* initialize screen properties */
467 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
468 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
469 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
470 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
471 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
473 /* create additional image buffers for double-buffering */
474 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
475 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
477 bitmap_font_initial = LoadCustomImage(filename_font_initial);
479 InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL);
481 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
482 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
484 DrawInitText("Loading graphics:", 120, FC_GREEN);
489 void InitGfxBackground()
494 fieldbuffer = bitmap_db_field;
495 SetDrawtoField(DRAW_BACKBUFFER);
497 BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
498 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
499 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
500 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
502 for (x=0; x<MAX_BUF_XSIZE; x++)
503 for (y=0; y<MAX_BUF_YSIZE; y++)
506 redraw_mask = REDRAW_ALL;
509 void ReloadCustomArtwork()
511 static char *leveldir_current_identifier = NULL;
512 static boolean last_override_level_graphics = FALSE;
513 static boolean last_override_level_sounds = FALSE;
514 static boolean last_override_level_music = FALSE;
515 /* identifier for new artwork; default: artwork configured in setup */
516 char *gfx_new_identifier = artwork.gfx_current->identifier;
517 char *snd_new_identifier = artwork.snd_current->identifier;
518 char *mus_new_identifier = artwork.mus_current->identifier;
519 boolean redraw_screen = FALSE;
521 if (leveldir_current_identifier == NULL)
522 leveldir_current_identifier = leveldir_current->identifier;
525 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
526 leveldir_current->graphics_set);
527 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
528 leveldir_current->identifier);
532 printf("graphics --> '%s' ('%s')\n",
533 artwork.gfx_current_identifier, artwork.gfx_current->filename);
534 printf("sounds --> '%s' ('%s')\n",
535 artwork.snd_current_identifier, artwork.snd_current->filename);
536 printf("music --> '%s' ('%s')\n",
537 artwork.mus_current_identifier, artwork.mus_current->filename);
540 /* leveldir_current may be invalid (level group, parent link) */
541 if (!validLevelSeries(leveldir_current))
544 /* when a new level series was selected, check if there was a change
545 in custom artwork stored in level series directory */
546 if (leveldir_current_identifier != leveldir_current->identifier)
548 char *identifier_old = leveldir_current_identifier;
549 char *identifier_new = leveldir_current->identifier;
551 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
552 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
553 gfx_new_identifier = identifier_new;
554 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
555 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
556 snd_new_identifier = identifier_new;
557 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
558 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
559 mus_new_identifier = identifier_new;
561 leveldir_current_identifier = leveldir_current->identifier;
564 /* custom level artwork configured in level series configuration file
565 always overrides custom level artwork stored in level series directory
566 and (level independant) custom artwork configured in setup menue */
567 if (leveldir_current->graphics_set != NULL)
568 gfx_new_identifier = leveldir_current->graphics_set;
569 if (leveldir_current->sounds_set != NULL)
570 snd_new_identifier = leveldir_current->sounds_set;
571 if (leveldir_current->music_set != NULL)
572 mus_new_identifier = leveldir_current->music_set;
574 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
575 last_override_level_graphics != setup.override_level_graphics)
578 printf("RELOADING GRAPHICS '%s' -> '%s' ('%s')\n",
579 artwork.gfx_current_identifier,
580 artwork.gfx_current->identifier,
584 setLevelArtworkDir(artwork.gfx_first);
586 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
588 ReloadCustomImages();
589 ReinitializeGraphics();
591 LoadCustomElementDescriptions();
592 LoadSpecialMenuDesignSettings();
597 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
598 last_override_level_graphics = setup.override_level_graphics;
600 redraw_screen = TRUE;
603 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
604 last_override_level_sounds != setup.override_level_sounds)
607 printf("RELOADING SOUNDS '%s' -> '%s' ('%s')\n",
608 artwork.snd_current_identifier,
609 artwork.snd_current->identifier,
613 /* set artwork path to send it to the sound server process */
614 setLevelArtworkDir(artwork.snd_first);
616 InitReloadCustomSounds(snd_new_identifier);
617 ReinitializeSounds();
619 artwork.snd_current_identifier = artwork.snd_current->identifier;
620 last_override_level_sounds = setup.override_level_sounds;
622 redraw_screen = TRUE;
625 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
626 last_override_level_music != setup.override_level_music)
628 /* set artwork path to send it to the sound server process */
629 setLevelArtworkDir(artwork.mus_first);
631 InitReloadCustomMusic(mus_new_identifier);
634 artwork.mus_current_identifier = artwork.mus_current->identifier;
635 last_override_level_music = setup.override_level_music;
637 redraw_screen = TRUE;
644 /* force redraw of (open or closed) door graphics */
645 SetDoorState(DOOR_OPEN_ALL);
646 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
652 FreeLevelEditorGadgets();
661 static boolean gadgets_initialized = FALSE;
663 if (gadgets_initialized)
666 CreateLevelEditorGadgets();
670 CreateScreenGadgets();
672 gadgets_initialized = TRUE;
675 void InitElementSmallImages()
677 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
678 int num_property_mappings = getImageListPropertyMappingSize();
681 /* initialize normal images from static configuration */
682 for (i=0; element_to_graphic[i].element > -1; i++)
683 CreateImageWithSmallImages(element_to_graphic[i].graphic);
685 /* initialize special images from static configuration */
686 for (i=0; element_to_special_graphic[i].element > -1; i++)
687 CreateImageWithSmallImages(element_to_special_graphic[i].graphic);
689 /* initialize images from dynamic configuration */
690 for (i=0; i < num_property_mappings; i++)
691 CreateImageWithSmallImages(property_mapping[i].artwork_index);
694 void InitElementGraphicInfo()
696 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
697 int num_property_mappings = getImageListPropertyMappingSize();
700 /* set values to -1 to identify later as "uninitialized" values */
701 for (i=0; i<MAX_NUM_ELEMENTS; i++)
703 for (act=0; act<NUM_ACTIONS; act++)
705 element_info[i].graphic[act] = -1;
707 for (dir=0; dir<NUM_DIRECTIONS; dir++)
708 element_info[i].direction_graphic[act][dir] = -1;
713 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
714 element_info[i].graphic[ACTION_DEFAULT] =
715 IMG_CHAR_START + (i - EL_CHAR_START);
717 for (i=EL_CUSTOM_START; i<=EL_CUSTOM_END; i++)
718 element_info[i].graphic[ACTION_DEFAULT] =
719 IMG_CUSTOM_START + (i - EL_CUSTOM_START);
722 /* initialize normal element/graphic mapping from static configuration */
723 for (i=0; element_to_graphic[i].element > -1; i++)
725 int element = element_to_graphic[i].element;
726 int action = element_to_graphic[i].action;
727 int direction = element_to_graphic[i].direction;
728 int graphic = element_to_graphic[i].graphic;
731 action = ACTION_DEFAULT;
734 element_info[element].direction_graphic[action][direction] = graphic;
736 element_info[element].graphic[action] = graphic;
739 /* initialize normal element/graphic mapping from dynamic configuration */
740 for (i=0; i < num_property_mappings; i++)
742 int element = property_mapping[i].base_index;
743 int action = property_mapping[i].ext1_index;
744 int direction = property_mapping[i].ext2_index;
745 int special = property_mapping[i].ext3_index;
746 int graphic = property_mapping[i].artwork_index;
752 action = ACTION_DEFAULT;
755 element_info[element].direction_graphic[action][direction] = graphic;
757 element_info[element].graphic[action] = graphic;
760 /* now set all '-1' values to element specific default values */
761 for (i=0; i<MAX_NUM_ELEMENTS; i++)
763 int default_action_graphic = element_info[i].graphic[ACTION_DEFAULT];
764 int default_action_direction_graphic[NUM_DIRECTIONS];
766 if (default_action_graphic == -1)
767 default_action_graphic = IMG_CHAR_QUESTION;
769 for (dir=0; dir<NUM_DIRECTIONS; dir++)
771 default_action_direction_graphic[dir] =
772 element_info[i].direction_graphic[ACTION_DEFAULT][dir];
774 if (default_action_direction_graphic[dir] == -1)
775 default_action_direction_graphic[dir] = default_action_graphic;
778 for (act=0; act<NUM_ACTIONS; act++)
780 for (dir=0; dir<NUM_DIRECTIONS; dir++)
782 int default_direction_graphic = element_info[i].graphic[act];
784 /* no graphic for current action -- use default direction graphic */
785 if (default_direction_graphic == -1)
786 default_direction_graphic = default_action_direction_graphic[dir];
788 if (element_info[i].direction_graphic[act][dir] == -1)
789 element_info[i].direction_graphic[act][dir] =
790 default_direction_graphic;
793 /* no graphic for this specific action -- use default action graphic */
794 if (element_info[i].graphic[act] == -1)
795 element_info[i].graphic[act] = default_action_graphic;
803 for (i=0; i<MAX_NUM_ELEMENTS; i++)
804 if (element_info[i].graphic[ACTION_DEFAULT] == IMG_CHAR_QUESTION &&
805 i != EL_CHAR_QUESTION)
806 Error(ERR_RETURN, "warning: no graphic for element '%s' (%d)",
807 element_info[i].token_name, i);
813 void InitElementSpecialGraphicInfo()
815 struct PropertyMapping *property_mapping = getImageListPropertyMapping();
816 int num_property_mappings = getImageListPropertyMappingSize();
819 /* always start with reliable default values */
820 for (i=0; i<MAX_NUM_ELEMENTS; i++)
822 element_info[i].editor_graphic = element_info[i].graphic[ACTION_DEFAULT];
823 element_info[i].preview_graphic = element_info[i].graphic[ACTION_DEFAULT];
826 /* initialize special element/graphic mapping from static configuration */
827 for (i=0; element_to_special_graphic[i].element > -1; i++)
829 int element = element_to_special_graphic[i].element;
830 int special = element_to_special_graphic[i].special;
831 int graphic = element_to_special_graphic[i].graphic;
832 boolean base_redefined = getImageListEntry(el2img(element))->redefined;
833 boolean special_redefined = getImageListEntry(graphic)->redefined;
835 if (base_redefined && !special_redefined)
838 if (special == GFX_SPECIAL_ARG_EDITOR)
839 element_info[element].editor_graphic = graphic;
840 else if (special == GFX_SPECIAL_ARG_PREVIEW)
841 element_info[element].preview_graphic = graphic;
844 /* initialize special element/graphic mapping from dynamic configuration */
845 for (i=0; i < num_property_mappings; i++)
847 int element = property_mapping[i].base_index;
848 int special = property_mapping[i].ext3_index;
849 int graphic = property_mapping[i].artwork_index;
851 if (special == GFX_SPECIAL_ARG_EDITOR)
852 element_info[element].editor_graphic = graphic;
853 else if (special == GFX_SPECIAL_ARG_PREVIEW)
854 element_info[element].preview_graphic = graphic;
858 static void InitElementSoundInfo()
860 /* !!! soon to come !!! */
863 static void set_graphic_parameters(int graphic, char **parameter_raw)
865 Bitmap *src_bitmap = getBitmapFromImageID(graphic);
866 int num_xtiles = (src_bitmap ? src_bitmap->width : TILEX) / TILEX;
867 int num_ytiles = (src_bitmap ? src_bitmap->height * 2 / 3 : TILEY) / TILEY;
868 int parameter[NUM_GFX_ARGS];
871 /* get integer values from string parameters */
872 for (i=0; i < NUM_GFX_ARGS; i++)
874 get_parameter_value(image_config_suffix[i].type, parameter_raw[i]);
876 graphic_info[graphic].bitmap = src_bitmap;
878 /* start with reliable default values */
879 graphic_info[graphic].src_x = 0;
880 graphic_info[graphic].src_y = 0;
881 graphic_info[graphic].width = TILEX;
882 graphic_info[graphic].height = TILEY;
883 graphic_info[graphic].offset_x = 0; /* one or both of these values ... */
884 graphic_info[graphic].offset_y = 0; /* ... will be corrected later */
886 /* optional x and y tile position of animation frame sequence */
887 if (parameter[GFX_ARG_XPOS] != ARG_UNDEFINED_VALUE)
888 graphic_info[graphic].src_x = parameter[GFX_ARG_XPOS] * TILEX;
889 if (parameter[GFX_ARG_YPOS] != ARG_UNDEFINED_VALUE)
890 graphic_info[graphic].src_y = parameter[GFX_ARG_YPOS] * TILEY;
892 /* optional x and y pixel position of animation frame sequence */
893 if (parameter[GFX_ARG_X] != ARG_UNDEFINED_VALUE)
894 graphic_info[graphic].src_x = parameter[GFX_ARG_X];
895 if (parameter[GFX_ARG_Y] != ARG_UNDEFINED_VALUE)
896 graphic_info[graphic].src_y = parameter[GFX_ARG_Y];
898 /* optional width and height of each animation frame */
899 if (parameter[GFX_ARG_WIDTH] != ARG_UNDEFINED_VALUE)
900 graphic_info[graphic].width = parameter[GFX_ARG_WIDTH];
901 if (parameter[GFX_ARG_HEIGHT] != ARG_UNDEFINED_VALUE)
902 graphic_info[graphic].height = parameter[GFX_ARG_HEIGHT];
904 /* correct x or y offset dependant of vertical or horizontal frame order */
905 if (parameter[GFX_ARG_VERTICAL]) /* frames are ordered vertically */
907 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
908 graphic_info[graphic].offset_y = parameter[GFX_ARG_OFFSET];
910 graphic_info[graphic].offset_y = graphic_info[graphic].height;
912 else /* frames are ordered horizontally */
914 if (parameter[GFX_ARG_OFFSET] != ARG_UNDEFINED_VALUE)
915 graphic_info[graphic].offset_x = parameter[GFX_ARG_OFFSET];
917 graphic_info[graphic].offset_x = graphic_info[graphic].width;
920 /* optionally, the x and y offset of frames can be specified directly */
921 if (parameter[GFX_ARG_XOFFSET] != ARG_UNDEFINED_VALUE)
922 graphic_info[graphic].offset_x = parameter[GFX_ARG_XOFFSET];
923 if (parameter[GFX_ARG_YOFFSET] != ARG_UNDEFINED_VALUE)
924 graphic_info[graphic].offset_y = parameter[GFX_ARG_YOFFSET];
926 /* automatically determine correct number of frames, if not defined */
927 if (parameter[GFX_ARG_FRAMES] != ARG_UNDEFINED_VALUE)
928 graphic_info[graphic].anim_frames = parameter[GFX_ARG_FRAMES];
929 else if (parameter[GFX_ARG_XPOS] == 0 && !parameter[GFX_ARG_VERTICAL])
930 graphic_info[graphic].anim_frames = num_xtiles;
931 else if (parameter[GFX_ARG_YPOS] == 0 && parameter[GFX_ARG_VERTICAL])
932 graphic_info[graphic].anim_frames = num_ytiles;
934 graphic_info[graphic].anim_frames = 1;
936 graphic_info[graphic].anim_delay = parameter[GFX_ARG_DELAY];
937 if (graphic_info[graphic].anim_delay == 0) /* delay must be at least 1 */
938 graphic_info[graphic].anim_delay = 1;
940 /* set mode for animation frame order */
941 if (parameter[GFX_ARG_MODE_LOOP])
942 graphic_info[graphic].anim_mode = ANIM_LOOP;
943 else if (parameter[GFX_ARG_MODE_LINEAR])
944 graphic_info[graphic].anim_mode = ANIM_LINEAR;
945 else if (parameter[GFX_ARG_MODE_PINGPONG])
946 graphic_info[graphic].anim_mode = ANIM_PINGPONG;
947 else if (parameter[GFX_ARG_MODE_PINGPONG2])
948 graphic_info[graphic].anim_mode = ANIM_PINGPONG2;
949 else if (parameter[GFX_ARG_MODE_RANDOM])
950 graphic_info[graphic].anim_mode = ANIM_RANDOM;
951 else if (graphic_info[graphic].anim_frames > 1)
952 graphic_info[graphic].anim_mode = ANIM_LOOP;
954 graphic_info[graphic].anim_mode = ANIM_NONE;
956 /* set additional flag to play animation frames in reverse order */
957 if (parameter[GFX_ARG_MODE_REVERSE])
958 graphic_info[graphic].anim_mode |= ANIM_REVERSE;
960 /* automatically determine correct start frame, if not defined */
961 if (parameter[GFX_ARG_START_FRAME] == ARG_UNDEFINED_VALUE)
962 graphic_info[graphic].anim_start_frame = 0;
963 else if (graphic_info[graphic].anim_mode & ANIM_REVERSE)
964 graphic_info[graphic].anim_start_frame =
965 graphic_info[graphic].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
967 graphic_info[graphic].anim_start_frame = parameter[GFX_ARG_START_FRAME];
969 /* animation synchronized with global frame counter, not move position */
970 graphic_info[graphic].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
972 /* this is only used for toon animations */
973 graphic_info[graphic].step_offset = parameter[GFX_ARG_STEP_OFFSET];
974 graphic_info[graphic].step_delay = parameter[GFX_ARG_STEP_DELAY];
977 static void InitGraphicInfo()
979 static boolean clipmasks_initialized = FALSE;
980 int fallback_graphic = IMG_CHAR_EXCLAM;
981 struct FileInfo *fallback_image = getImageListEntry(fallback_graphic);
982 Bitmap *fallback_bitmap = getBitmapFromImageID(fallback_graphic);
983 int num_images = getImageListSize();
985 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
987 XGCValues clip_gc_values;
988 unsigned long clip_gc_valuemask;
989 GC copy_clipmask_gc = None;
992 if (graphic_info != NULL)
995 graphic_info = checked_calloc(num_images * sizeof(struct GraphicInfo));
997 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
998 if (clipmasks_initialized)
1000 for (i=0; i<num_images; i++)
1002 if (graphic_info[i].clip_mask)
1003 XFreePixmap(display, graphic_info[i].clip_mask);
1004 if (graphic_info[i].clip_gc)
1005 XFreeGC(display, graphic_info[i].clip_gc);
1007 graphic_info[i].clip_mask = None;
1008 graphic_info[i].clip_gc = None;
1013 for (i=0; i<num_images; i++)
1015 struct FileInfo *image = getImageListEntry(i);
1018 int first_frame, last_frame;
1020 set_graphic_parameters(i, image->parameter);
1022 /* now check if no animation frames are outside of the loaded image */
1024 if (graphic_info[i].bitmap == NULL)
1025 continue; /* skip check for optional images that are undefined */
1028 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1029 if (src_x < 0 || src_y < 0 ||
1030 src_x + TILEX > src_bitmap->width ||
1031 src_y + TILEY > src_bitmap->height)
1033 Error(ERR_RETURN_LINE, "-");
1034 Error(ERR_RETURN, "warning: error found in config file:");
1035 Error(ERR_RETURN, "- config file: '%s'",
1036 getImageConfigFilename());
1037 Error(ERR_RETURN, "- config token: '%s'",
1038 getTokenFromImageID(i));
1039 Error(ERR_RETURN, "- image file: '%s'",
1040 src_bitmap->source_filename);
1042 "error: first animation frame out of bounds (%d, %d)",
1044 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1046 if (i == fallback_graphic)
1047 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1049 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1050 Error(ERR_RETURN_LINE, "-");
1052 set_graphic_parameters(i, fallback_image->default_parameter);
1053 graphic_info[i].bitmap = fallback_bitmap;
1056 last_frame = graphic_info[i].anim_frames - 1;
1057 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
1058 if (src_x < 0 || src_y < 0 ||
1059 src_x + TILEX > src_bitmap->width ||
1060 src_y + TILEY > src_bitmap->height)
1062 Error(ERR_RETURN_LINE, "-");
1063 Error(ERR_RETURN, "warning: error found in config file:");
1064 Error(ERR_RETURN, "- config file: '%s'",
1065 getImageConfigFilename());
1066 Error(ERR_RETURN, "- config token: '%s'",
1067 getTokenFromImageID(i));
1068 Error(ERR_RETURN, "- image file: '%s'",
1069 src_bitmap->source_filename);
1071 "error: last animation frame (%d) out of bounds (%d, %d)",
1072 last_frame, src_x, src_y);
1073 Error(ERR_RETURN, "custom graphic rejected for this element/action");
1075 if (i == fallback_graphic)
1076 Error(ERR_EXIT, "fatal error: no fallback graphic available");
1078 Error(ERR_RETURN, "fallback done to 'char_exclam' for this graphic");
1079 Error(ERR_RETURN_LINE, "-");
1081 set_graphic_parameters(i, fallback_image->default_parameter);
1082 graphic_info[i].bitmap = fallback_bitmap;
1085 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1086 /* currently we need only a tile clip mask from the first frame */
1087 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
1089 if (copy_clipmask_gc == None)
1091 clip_gc_values.graphics_exposures = False;
1092 clip_gc_valuemask = GCGraphicsExposures;
1093 copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask,
1094 clip_gc_valuemask, &clip_gc_values);
1097 graphic_info[i].clip_mask =
1098 XCreatePixmap(display, window->drawable, TILEX, TILEY, 1);
1100 src_pixmap = src_bitmap->clip_mask;
1101 XCopyArea(display, src_pixmap, graphic_info[i].clip_mask,
1102 copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0);
1104 clip_gc_values.graphics_exposures = False;
1105 clip_gc_values.clip_mask = graphic_info[i].clip_mask;
1106 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
1107 graphic_info[i].clip_gc =
1108 XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values);
1112 #if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND)
1113 if (copy_clipmask_gc)
1114 XFreeGC(display, copy_clipmask_gc);
1117 clipmasks_initialized = TRUE;
1120 static void set_sound_parameters(int sound, char **parameter_raw)
1122 int parameter[NUM_SND_ARGS];
1125 /* get integer values from string parameters */
1126 for (i=0; i < NUM_SND_ARGS; i++)
1128 get_parameter_value(sound_config_suffix[i].type, parameter_raw[i]);
1130 /* explicit loop mode setting in configuration overrides default value */
1131 if (parameter[SND_ARG_MODE_LOOP] != ARG_UNDEFINED_VALUE)
1132 sound_info[sound].loop = parameter[SND_ARG_MODE_LOOP];
1135 static void InitSoundInfo()
1137 int *sound_effect_properties;
1138 int num_sounds = getSoundListSize();
1141 if (sound_info != NULL)
1144 sound_effect_properties = checked_calloc(num_sounds * sizeof(int));
1145 sound_info = checked_calloc(num_sounds * sizeof(struct SoundInfo));
1147 /* initialize sound effect for all elements to "no sound" */
1148 for (i=0; i<MAX_NUM_ELEMENTS; i++)
1149 for (j=0; j<NUM_ACTIONS; j++)
1150 element_info[i].sound[j] = SND_UNDEFINED;
1152 for (i=0; i<num_sounds; i++)
1154 struct FileInfo *sound = getSoundListEntry(i);
1155 int len_effect_text = strlen(sound->token);
1157 sound_effect_properties[i] = ACTION_OTHER;
1158 sound_info[i].loop = FALSE;
1160 /* determine all loop sounds and identify certain sound classes */
1162 for (j=0; element_action_info[j].suffix; j++)
1164 int len_action_text = strlen(element_action_info[j].suffix);
1166 if (len_action_text < len_effect_text &&
1167 strcmp(&sound->token[len_effect_text - len_action_text],
1168 element_action_info[j].suffix) == 0)
1170 sound_effect_properties[i] = element_action_info[j].value;
1172 if (element_action_info[j].is_loop_sound)
1173 sound_info[i].loop = TRUE;
1177 /* associate elements and some selected sound actions */
1179 for (j=0; j<MAX_NUM_ELEMENTS; j++)
1181 if (element_info[j].sound_class_name)
1183 int len_class_text = strlen(element_info[j].sound_class_name);
1185 if (len_class_text + 1 < len_effect_text &&
1186 strncmp(sound->token,
1187 element_info[j].sound_class_name, len_class_text) == 0 &&
1188 sound->token[len_class_text] == '.')
1190 int sound_action_value = sound_effect_properties[i];
1192 element_info[j].sound[sound_action_value] = i;
1197 set_sound_parameters(i, sound->parameter);
1200 free(sound_effect_properties);
1205 int element = EL_SAND;
1206 int sound_action = ACTION_DIGGING;
1209 while (element_action_info[j].suffix)
1211 if (element_action_info[j].value == sound_action)
1212 printf("element %d, sound action '%s' == %d\n",
1213 element, element_action_info[j].suffix,
1214 element_info_[element].sound[sound_action]);
1221 void InitElementProperties()
1225 static int ep_amoebalive[] =
1232 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
1234 static int ep_amoeboid[] =
1242 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
1244 static int ep_schluessel[] =
1255 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
1257 static int ep_pforte[] =
1276 EL_SWITCHGATE_OPENING,
1277 EL_SWITCHGATE_CLOSED,
1278 EL_SWITCHGATE_CLOSING,
1280 EL_TIMEGATE_OPENING,
1282 EL_TIMEGATE_CLOSING,
1286 EL_TUBE_VERTICAL_LEFT,
1287 EL_TUBE_VERTICAL_RIGHT,
1288 EL_TUBE_HORIZONTAL_UP,
1289 EL_TUBE_HORIZONTAL_DOWN,
1295 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
1297 static int ep_solid[] =
1317 EL_QUICKSAND_FILLING,
1318 EL_QUICKSAND_EMPTYING,
1320 EL_MAGIC_WALL_ACTIVE,
1321 EL_MAGIC_WALL_EMPTYING,
1322 EL_MAGIC_WALL_FILLING,
1326 EL_BD_MAGIC_WALL_ACTIVE,
1327 EL_BD_MAGIC_WALL_EMPTYING,
1328 EL_BD_MAGIC_WALL_FULL,
1329 EL_BD_MAGIC_WALL_FILLING,
1330 EL_BD_MAGIC_WALL_DEAD,
1333 EL_ACIDPOOL_TOPLEFT,
1334 EL_ACIDPOOL_TOPRIGHT,
1335 EL_ACIDPOOL_BOTTOMLEFT,
1337 EL_ACIDPOOL_BOTTOMRIGHT,
1355 EL_SP_TERMINAL_ACTIVE,
1358 EL_INVISIBLE_STEELWALL,
1359 EL_INVISIBLE_STEELWALL_ACTIVE,
1361 EL_INVISIBLE_WALL_ACTIVE,
1362 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1363 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1364 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1365 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1366 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1367 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1368 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1369 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1370 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1371 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1372 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1373 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1374 EL_SWITCHGATE_SWITCH_UP,
1375 EL_SWITCHGATE_SWITCH_DOWN,
1377 EL_LIGHT_SWITCH_ACTIVE,
1379 EL_TIMEGATE_SWITCH_ACTIVE,
1380 EL_SIGN_EXCLAMATION,
1381 EL_SIGN_RADIOACTIVITY,
1392 EL_STEELWALL_SLANTED,
1397 EL_EMC_WALL_PILLAR_UPPER,
1398 EL_EMC_WALL_PILLAR_MIDDLE,
1399 EL_EMC_WALL_PILLAR_LOWER,
1425 EL_SWITCHGATE_OPENING,
1426 EL_SWITCHGATE_CLOSED,
1427 EL_SWITCHGATE_CLOSING,
1429 EL_TIMEGATE_OPENING,
1431 EL_TIMEGATE_CLOSING,
1435 EL_TUBE_VERTICAL_LEFT,
1436 EL_TUBE_VERTICAL_RIGHT,
1437 EL_TUBE_HORIZONTAL_UP,
1438 EL_TUBE_HORIZONTAL_DOWN,
1444 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1446 static int ep_massive[] =
1450 EL_ACIDPOOL_TOPLEFT,
1451 EL_ACIDPOOL_TOPRIGHT,
1452 EL_ACIDPOOL_BOTTOMLEFT,
1454 EL_ACIDPOOL_BOTTOMRIGHT,
1466 EL_INVISIBLE_STEELWALL,
1467 EL_INVISIBLE_STEELWALL_ACTIVE,
1468 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1469 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1470 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1471 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1472 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1473 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1474 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1475 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1476 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1477 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1478 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1479 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1481 EL_LIGHT_SWITCH_ACTIVE,
1482 EL_SIGN_EXCLAMATION,
1483 EL_SIGN_RADIOACTIVITY,
1494 EL_STEELWALL_SLANTED,
1517 EL_SWITCHGATE_OPENING,
1518 EL_SWITCHGATE_CLOSED,
1519 EL_SWITCHGATE_CLOSING,
1521 EL_TIMEGATE_OPENING,
1523 EL_TIMEGATE_CLOSING,
1527 EL_TUBE_VERTICAL_LEFT,
1528 EL_TUBE_VERTICAL_RIGHT,
1529 EL_TUBE_HORIZONTAL_UP,
1530 EL_TUBE_HORIZONTAL_DOWN,
1536 static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive);
1538 static int ep_slippery[] =
1552 EL_ROBOT_WHEEL_ACTIVE,
1558 EL_ACIDPOOL_TOPLEFT,
1559 EL_ACIDPOOL_TOPRIGHT,
1569 EL_STEELWALL_SLANTED,
1573 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1575 static int ep_enemy[] =
1588 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1590 static int ep_mauer[] =
1618 EL_WALL_GROWING_ACTIVE,
1637 EL_SP_TERMINAL_ACTIVE,
1640 EL_INVISIBLE_STEELWALL,
1641 EL_INVISIBLE_STEELWALL_ACTIVE,
1643 EL_INVISIBLE_WALL_ACTIVE,
1644 EL_STEELWALL_SLANTED,
1649 EL_EMC_WALL_PILLAR_UPPER,
1650 EL_EMC_WALL_PILLAR_MIDDLE,
1651 EL_EMC_WALL_PILLAR_LOWER,
1658 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1660 static int ep_can_fall[] =
1675 EL_BD_MAGIC_WALL_FULL,
1686 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1688 static int ep_can_smash[] =
1711 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1713 static int ep_can_change[] =
1724 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1726 static int ep_can_move[] =
1746 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1748 static int ep_could_move[] =
1758 EL_BD_BUTTERFLY_RIGHT,
1760 EL_BD_BUTTERFLY_LEFT,
1761 EL_BD_BUTTERFLY_DOWN,
1762 EL_BD_FIREFLY_RIGHT,
1771 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1773 static int ep_dont_touch[] =
1780 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1782 static int ep_dont_go_to[] =
1796 EL_SP_BUGGY_BASE_ACTIVE,
1800 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
1802 static int ep_mampf2[] =
1827 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1829 static int ep_bd_element[] =
1856 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1858 static int ep_sb_element[] =
1863 EL_SOKOBAN_FIELD_EMPTY,
1864 EL_SOKOBAN_FIELD_FULL,
1866 EL_INVISIBLE_STEELWALL
1868 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1870 static int ep_gem[] =
1879 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1881 static int ep_inactive[] =
1918 EL_INVISIBLE_STEELWALL,
1926 EL_WALL_EMERALD_YELLOW,
1931 EL_SOKOBAN_FIELD_EMPTY,
1932 EL_SOKOBAN_FIELD_FULL,
1933 EL_WALL_EMERALD_RED,
1934 EL_WALL_EMERALD_PURPLE,
1935 EL_ACIDPOOL_TOPLEFT,
1936 EL_ACIDPOOL_TOPRIGHT,
1937 EL_ACIDPOOL_BOTTOMLEFT,
1939 EL_ACIDPOOL_BOTTOMRIGHT,
1943 EL_BD_MAGIC_WALL_DEAD,
1944 EL_AMOEBA_TO_DIAMOND,
1977 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1978 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1979 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1980 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1981 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1982 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1983 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1984 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1985 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1986 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1987 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1988 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1989 EL_SIGN_EXCLAMATION,
1990 EL_SIGN_RADIOACTIVITY,
2001 EL_STEELWALL_SLANTED,
2006 EL_EMC_WALL_PILLAR_UPPER,
2007 EL_EMC_WALL_PILLAR_MIDDLE,
2008 EL_EMC_WALL_PILLAR_LOWER,
2015 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
2017 static int ep_explosive[] =
2022 EL_DYNABOMB_PLAYER1_ACTIVE,
2023 EL_DYNABOMB_PLAYER2_ACTIVE,
2024 EL_DYNABOMB_PLAYER3_ACTIVE,
2025 EL_DYNABOMB_PLAYER4_ACTIVE,
2042 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
2044 static int ep_mampf3[] =
2055 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
2057 static int ep_pushable[] =
2064 EL_SOKOBAN_FIELD_FULL,
2074 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
2076 static int ep_player[] =
2083 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
2085 static int ep_has_content[] =
2093 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
2095 static int ep_eatable[] =
2100 EL_SP_BUGGY_BASE_ACTIVATING,
2103 EL_INVISIBLE_SAND_ACTIVE
2105 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
2107 static int ep_sp_element[] =
2150 /* additional elements that appeared in newer Supaplex levels */
2152 /* more than one murphy in a level results in an inactive clone */
2155 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
2157 static int ep_quick_gate[] =
2181 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
2183 static int ep_over_player[] =
2199 EL_TUBE_VERTICAL_LEFT,
2200 EL_TUBE_VERTICAL_RIGHT,
2201 EL_TUBE_HORIZONTAL_UP,
2202 EL_TUBE_HORIZONTAL_DOWN,
2208 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
2210 static int ep_active_bomb[] =
2213 EL_DYNABOMB_PLAYER1_ACTIVE,
2214 EL_DYNABOMB_PLAYER2_ACTIVE,
2215 EL_DYNABOMB_PLAYER3_ACTIVE,
2216 EL_DYNABOMB_PLAYER4_ACTIVE
2218 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
2220 static int ep_belt[] =
2222 EL_CONVEYOR_BELT1_LEFT,
2223 EL_CONVEYOR_BELT1_MIDDLE,
2224 EL_CONVEYOR_BELT1_RIGHT,
2225 EL_CONVEYOR_BELT2_LEFT,
2226 EL_CONVEYOR_BELT2_MIDDLE,
2227 EL_CONVEYOR_BELT2_RIGHT,
2228 EL_CONVEYOR_BELT3_LEFT,
2229 EL_CONVEYOR_BELT3_MIDDLE,
2230 EL_CONVEYOR_BELT3_RIGHT,
2231 EL_CONVEYOR_BELT4_LEFT,
2232 EL_CONVEYOR_BELT4_MIDDLE,
2233 EL_CONVEYOR_BELT4_RIGHT,
2235 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
2237 static int ep_belt_active[] =
2239 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
2240 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
2241 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
2242 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
2243 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
2244 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
2245 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
2246 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
2247 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
2248 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
2249 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
2250 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
2252 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
2254 static int ep_belt_switch[] =
2256 EL_CONVEYOR_BELT1_SWITCH_LEFT,
2257 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
2258 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
2259 EL_CONVEYOR_BELT2_SWITCH_LEFT,
2260 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
2261 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
2262 EL_CONVEYOR_BELT3_SWITCH_LEFT,
2263 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
2264 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
2265 EL_CONVEYOR_BELT4_SWITCH_LEFT,
2266 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
2267 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
2269 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
2271 static int ep_tube[] =
2276 EL_TUBE_VERTICAL_LEFT,
2277 EL_TUBE_VERTICAL_RIGHT,
2278 EL_TUBE_HORIZONTAL_UP,
2279 EL_TUBE_HORIZONTAL_DOWN,
2285 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
2287 static long ep1_bit[] =
2321 static long ep2_bit[] =
2328 static int *ep1_array[] =
2362 static int *ep2_array[] =
2369 static int *ep1_num[] =
2396 &ep_has_content_num,
2400 &ep_over_player_num,
2403 static int *ep2_num[] =
2406 &ep_belt_active_num,
2407 &ep_belt_switch_num,
2410 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2411 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2413 for (i=0; i<MAX_NUM_ELEMENTS; i++)
2419 for (i=0; i<num_properties1; i++)
2420 for (j=0; j<*(ep1_num[i]); j++)
2421 Properties1[(ep1_array[i])[j]] |= ep1_bit[i];
2422 for (i=0; i<num_properties2; i++)
2423 for (j=0; j<*(ep2_num[i]); j++)
2424 Properties2[(ep2_array[i])[j]] |= ep2_bit[i];
2426 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2427 Properties1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2430 void Execute_Command(char *command)
2432 if (strcmp(command, "print graphicsinfo.conf") == 0)
2436 printf("# You can configure additional/alternative image files here.\n");
2437 printf("# (The images below are default and therefore commented out.)\n");
2439 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2441 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2444 for (i=0; image_config[i].token != NULL; i++)
2446 getFormattedSetupEntry(image_config[i].token,
2447 image_config[i].value));
2451 else if (strcmp(command, "print soundsinfo.conf") == 0)
2455 printf("# You can configure additional/alternative sound files here.\n");
2456 printf("# (The sounds below are default and therefore commented out.)\n");
2458 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2460 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2463 for (i=0; sound_config[i].token != NULL; i++)
2465 getFormattedSetupEntry(sound_config[i].token,
2466 sound_config[i].value));
2470 else if (strcmp(command, "print musicinfo.conf") == 0)
2472 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2474 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2476 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2480 else if (strncmp(command, "dump level ", 11) == 0)
2482 char *filename = &command[11];
2484 if (access(filename, F_OK) != 0)
2485 Error(ERR_EXIT, "cannot open file '%s'", filename);
2487 LoadLevelFromFilename(filename);
2492 else if (strncmp(command, "dump tape ", 10) == 0)
2494 char *filename = &command[10];
2496 if (access(filename, F_OK) != 0)
2497 Error(ERR_EXIT, "cannot open file '%s'", filename);
2499 LoadTapeFromFilename(filename);
2504 else if (strncmp(command, "autoplay ", 9) == 0)
2506 char *str_copy = getStringCopy(&command[9]);
2507 char *str_ptr = strchr(str_copy, ' ');
2509 global.autoplay_leveldir = str_copy;
2510 global.autoplay_level_nr = -1;
2512 if (str_ptr != NULL)
2514 *str_ptr++ = '\0'; /* terminate leveldir string */
2515 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2520 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2524 void CloseAllAndExit(int exit_value)
2529 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2532 FreeTileClipmasks();
2534 if (bitmap_font_initial)
2535 FreeBitmap(bitmap_font_initial);
2537 CloseVideoDisplay();
2538 ClosePlatformDependantStuff();