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 */
32 static char *image_filename[NUM_PICTURES] =
40 "RocksFontMedium.pcx",
53 "RocksFontMedium.pcx",
58 static Bitmap *bitmap_font_initial = NULL;
60 static void InitGlobal(void);
61 static void InitSetup(void);
62 static void InitPlayerInfo(void);
63 static void InitLevelInfo(void);
64 static void InitArtworkInfo(void);
65 static void InitLevelArtworkInfo(void);
66 static void InitNetworkServer(void);
67 static void InitImages(void);
68 static void InitMixer(void);
69 static void InitSound(void);
70 static void InitGfx(void);
71 static void InitGfxBackground(void);
72 static void InitGadgets(void);
73 static void InitElementProperties(void);
74 static void InitElementInfo(void);
75 static void InitGraphicInfo(void);
76 static void InitSoundInfo();
77 static void Execute_Command(char *);
81 InitGlobal(); /* initialize some global variables */
83 if (options.execute_command)
84 Execute_Command(options.execute_command);
86 if (options.serveronly)
88 #if defined(PLATFORM_UNIX)
89 NetworkServer(options.server_port, options.serveronly);
91 Error(ERR_WARN, "networking only supported in Unix version");
93 exit(0); /* never reached */
96 InitProgramInfo(UNIX_USERDATA_DIRECTORY,
97 PROGRAM_TITLE_STRING, getWindowTitleString(),
98 ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME,
99 MSDOS_POINTER_FILENAME,
100 COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
104 InitArtworkInfo(); /* needed before loading gfx, sound & music */
109 InitRND(NEW_RANDOMIZE);
112 InitVideoBuffer(&backbuffer, &window, WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH,
115 InitEventFilter(FilterMouseMotionEvents);
117 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
123 InitLevelArtworkInfo();
125 InitImages(); /* needs to know current level directory */
126 InitSound(); /* needs to know current level directory */
128 InitGadgets(); /* needs images + number of level series */
133 if (global.autoplay_leveldir)
146 global.autoplay_leveldir = NULL;
148 global.frames_per_second = 0;
149 global.fps_slowdown = FALSE;
150 global.fps_slowdown_factor = 1;
155 LoadSetup(); /* global setup info */
158 void InitPlayerInfo()
162 /* choose default local player */
163 local_player = &stored_player[0];
165 for (i=0; i<MAX_PLAYERS; i++)
166 stored_player[i].connected = FALSE;
168 local_player->connected = TRUE;
173 LoadLevelInfo(); /* global level info */
174 LoadLevelSetup_LastSeries(); /* last played series info */
175 LoadLevelSetup_SeriesInfo(); /* last played level info */
178 void InitArtworkInfo()
183 void InitLevelArtworkInfo()
185 LoadLevelArtworkInfo();
188 void InitNetworkServer()
190 #if defined(PLATFORM_UNIX)
194 if (!options.network)
197 #if defined(PLATFORM_UNIX)
198 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
200 if (!ConnectToServer(options.server_host, options.server_port))
201 Error(ERR_EXIT, "cannot connect to network game server");
203 SendToServer_PlayerName(setup.player_name);
204 SendToServer_ProtocolVersion();
207 SendToServer_NrWanted(nr_wanted);
211 static void ReinitializeGraphics()
213 ReloadCustomImages(); /* load custom image files */
215 InitGraphicInfo(); /* initialize graphic info from config file */
217 InitFontInfo(bitmap_font_initial,
218 new_graphic_info[IMG_MENU_FONT_BIG].bitmap,
219 new_graphic_info[IMG_MENU_FONT_MEDIUM].bitmap,
220 new_graphic_info[IMG_MENU_FONT_SMALL].bitmap,
221 new_graphic_info[IMG_MENU_FONT_EM].bitmap);
227 static void InitImages()
229 InitImageList(image_config, image_config_suffix, NUM_IMAGE_FILES);
231 ReinitializeGraphics();
234 static void InitMixer()
238 InitSoundList(sound_config, sound_config_suffix, NUM_SOUND_FILES);
243 static void InitSound()
245 /* load custom sounds and music */
246 InitReloadSounds(artwork.snd_current->identifier);
247 InitReloadMusic(artwork.mus_current->identifier);
252 static void InitTileClipmasks()
254 #if defined(TARGET_X11)
255 XGCValues clip_gc_values;
256 unsigned long clip_gc_valuemask;
258 #if defined(TARGET_X11_NATIVE)
268 tile_needs_clipping[] =
270 { GFX_SPIELER1_UP, 4 },
271 { GFX_SPIELER1_DOWN, 4 },
272 { GFX_SPIELER1_LEFT, 4 },
273 { GFX_SPIELER1_RIGHT, 4 },
274 { GFX_SPIELER1_PUSH_LEFT, 4 },
275 { GFX_SPIELER1_PUSH_RIGHT, 4 },
276 { GFX_SPIELER2_UP, 4 },
277 { GFX_SPIELER2_DOWN, 4 },
278 { GFX_SPIELER2_LEFT, 4 },
279 { GFX_SPIELER2_RIGHT, 4 },
280 { GFX_SPIELER2_PUSH_LEFT, 4 },
281 { GFX_SPIELER2_PUSH_RIGHT, 4 },
282 { GFX_SPIELER3_UP, 4 },
283 { GFX_SPIELER3_DOWN, 4 },
284 { GFX_SPIELER3_LEFT, 4 },
285 { GFX_SPIELER3_RIGHT, 4 },
286 { GFX_SPIELER3_PUSH_LEFT, 4 },
287 { GFX_SPIELER3_PUSH_RIGHT, 4 },
288 { GFX_SPIELER4_UP, 4 },
289 { GFX_SPIELER4_DOWN, 4 },
290 { GFX_SPIELER4_LEFT, 4 },
291 { GFX_SPIELER4_RIGHT, 4 },
292 { GFX_SPIELER4_PUSH_LEFT, 4 },
293 { GFX_SPIELER4_PUSH_RIGHT, 4 },
294 { GFX_SP_MURPHY, 1 },
295 { GFX_MURPHY_GO_LEFT, 3 },
296 { GFX_MURPHY_GO_RIGHT, 3 },
297 { GFX_MURPHY_SNAP_UP, 1 },
298 { GFX_MURPHY_SNAP_DOWN, 1 },
299 { GFX_MURPHY_SNAP_RIGHT, 1 },
300 { GFX_MURPHY_SNAP_LEFT, 1 },
301 { GFX_MURPHY_PUSH_RIGHT, 1 },
302 { GFX_MURPHY_PUSH_LEFT, 1 },
303 { GFX_GEBLUBBER, 4 },
306 { GFX_EXPLOSION, 8 },
307 { GFX_SOKOBAN_OBJEKT, 1 },
308 { GFX_FUNKELN_BLAU, 3 },
309 { GFX_FUNKELN_WEISS, 3 },
310 { GFX2_SHIELD_PASSIVE, 3 },
311 { GFX2_SHIELD_ACTIVE, 3 },
316 #endif /* TARGET_X11_NATIVE */
317 #endif /* TARGET_X11 */
321 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
322 for (i=0; i<NUM_TILES; i++)
323 tile_clipmask[i] = None;
325 #if defined(TARGET_X11)
326 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
327 often very slow when preparing a masked XCopyArea() for big Pixmaps.
328 To prevent this, create small (tile-sized) mask Pixmaps which will then
329 be set much faster with XSetClipOrigin() and speed things up a lot. */
331 clip_gc_values.graphics_exposures = False;
332 clip_gc_valuemask = GCGraphicsExposures;
333 tile_clip_gc = XCreateGC(display, window->drawable,
334 clip_gc_valuemask, &clip_gc_values);
337 for (i=0; i<NUM_BITMAPS; i++)
339 if (pix[i]->clip_mask)
341 clip_gc_values.graphics_exposures = False;
342 clip_gc_values.clip_mask = pix[i]->clip_mask;
343 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
344 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
345 clip_gc_valuemask, &clip_gc_values);
350 #if defined(TARGET_X11_NATIVE)
353 /* create graphic context structures needed for clipping */
354 clip_gc_values.graphics_exposures = False;
355 clip_gc_valuemask = GCGraphicsExposures;
356 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
357 clip_gc_valuemask, &clip_gc_values);
359 /* create only those clipping Pixmaps we really need */
360 for (i=0; tile_needs_clipping[i].start>=0; i++)
364 for (j=0; j<tile_needs_clipping[i].count; j++)
366 int tile = tile_needs_clipping[i].start + j;
372 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
373 src_pixmap = src_bitmap->clip_mask;
375 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
378 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
379 src_x, src_y, TILEX, TILEY, 0, 0);
383 XFreeGC(display, copy_clipmask_gc);
386 #endif /* TARGET_X11_NATIVE */
387 #endif /* TARGET_X11 */
390 void FreeTileClipmasks()
392 #if defined(TARGET_X11)
395 for (i=0; i<NUM_TILES; i++)
397 if (tile_clipmask[i] != None)
399 XFreePixmap(display, tile_clipmask[i]);
400 tile_clipmask[i] = None;
405 XFreeGC(display, tile_clip_gc);
409 for (i=0; i<NUM_BITMAPS; i++)
411 if (pix[i] != NULL && pix[i]->stored_clip_gc)
413 XFreeGC(display, pix[i]->stored_clip_gc);
414 pix[i]->stored_clip_gc = None;
419 #endif /* TARGET_X11 */
428 /* initialize screen properties */
429 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
430 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
431 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
432 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
433 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
435 /* create additional image buffers for double-buffering */
436 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
437 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
440 pix[PIX_FONT_SMALL] = LoadCustomImage(image_filename[PIX_FONT_SMALL]);
442 InitFontInfo(NULL, NULL, pix[PIX_FONT_SMALL], NULL);
444 bitmap_font_initial = LoadCustomImage(image_filename[PIX_FONT_SMALL]);
446 InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL);
449 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
450 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
452 DrawInitText("Loading graphics:", 120, FC_GREEN);
455 for (i=0; i<NUM_PICTURES; i++)
458 if (i != PIX_FONT_SMALL)
461 DrawInitText(image_filename[i], 150, FC_YELLOW);
463 pix[i] = LoadCustomImage(image_filename[i]);
469 InitFontInfo(pix[PIX_FONT_BIG], pix[PIX_FONT_MEDIUM], pix[PIX_FONT_SMALL],
476 void InitGfxBackground()
481 fieldbuffer = bitmap_db_field;
482 SetDrawtoField(DRAW_BACKBUFFER);
484 BlitBitmap(new_graphic_info[IMG_MENU_BACK].bitmap, backbuffer,
485 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
486 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
487 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
489 for (x=0; x<MAX_BUF_XSIZE; x++)
490 for (y=0; y<MAX_BUF_YSIZE; y++)
493 redraw_mask = REDRAW_ALL;
496 void ReloadCustomArtwork()
498 static char *leveldir_current_identifier = NULL;
499 static boolean last_override_level_graphics = FALSE;
500 static boolean last_override_level_sounds = FALSE;
501 static boolean last_override_level_music = FALSE;
502 /* identifier for new artwork; default: artwork configured in setup */
503 char *gfx_new_identifier = artwork.gfx_current->identifier;
504 char *snd_new_identifier = artwork.snd_current->identifier;
505 char *mus_new_identifier = artwork.mus_current->identifier;
506 boolean redraw_screen = FALSE;
508 if (leveldir_current_identifier == NULL)
509 leveldir_current_identifier = leveldir_current->identifier;
512 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
513 leveldir_current->graphics_set);
514 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
515 leveldir_current->identifier);
519 printf("graphics --> '%s' ('%s')\n",
520 artwork.gfx_current_identifier, artwork.gfx_current->filename);
521 printf("sounds --> '%s' ('%s')\n",
522 artwork.snd_current_identifier, artwork.snd_current->filename);
523 printf("music --> '%s' ('%s')\n",
524 artwork.mus_current_identifier, artwork.mus_current->filename);
527 /* leveldir_current may be invalid (level group, parent link) */
528 if (!validLevelSeries(leveldir_current))
532 printf("--> '%s'\n", artwork.gfx_current_identifier);
535 /* when a new level series was selected, check if there was a change
536 in custom artwork stored in level series directory */
537 if (leveldir_current_identifier != leveldir_current->identifier)
539 char *identifier_old = leveldir_current_identifier;
540 char *identifier_new = leveldir_current->identifier;
542 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
543 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
544 gfx_new_identifier = identifier_new;
545 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
546 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
547 snd_new_identifier = identifier_new;
548 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
549 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
550 mus_new_identifier = identifier_new;
552 leveldir_current_identifier = leveldir_current->identifier;
555 /* custom level artwork configured in level series configuration file
556 always overrides custom level artwork stored in level series directory
557 and (level independant) custom artwork configured in setup menue */
558 if (leveldir_current->graphics_set != NULL)
559 gfx_new_identifier = leveldir_current->graphics_set;
560 if (leveldir_current->sounds_set != NULL)
561 snd_new_identifier = leveldir_current->sounds_set;
562 if (leveldir_current->music_set != NULL)
563 mus_new_identifier = leveldir_current->music_set;
565 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
566 last_override_level_graphics != setup.override_level_graphics)
569 printf("CHANGED GFX: '%s' -> '%s'\n",
570 artwork.gfx_current_identifier, gfx_new_identifier);
577 setLevelArtworkDir(artwork.gfx_first);
579 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
582 for (i=0; i<NUM_PICTURES; i++)
584 DrawInitText(image_filename[i], 150, FC_YELLOW);
585 ReloadCustomImage(pix[i], image_filename[i]);
593 ReinitializeGraphics();
601 /* force redraw of (open or closed) door graphics */
602 SetDoorState(DOOR_OPEN_ALL);
603 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
607 artwork.gfx_current_identifier = gfx_new_identifier;
609 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
611 last_override_level_graphics = setup.override_level_graphics;
613 redraw_screen = TRUE;
616 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
617 last_override_level_sounds != setup.override_level_sounds)
619 /* set artwork path to send it to the sound server process */
620 setLevelArtworkDir(artwork.snd_first);
622 InitReloadSounds(snd_new_identifier);
624 artwork.snd_current_identifier = snd_new_identifier;
625 last_override_level_sounds = setup.override_level_sounds;
627 redraw_screen = TRUE;
630 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
631 last_override_level_music != setup.override_level_music)
633 /* set artwork path to send it to the sound server process */
634 setLevelArtworkDir(artwork.mus_first);
636 InitReloadMusic(mus_new_identifier);
638 artwork.mus_current_identifier = mus_new_identifier;
639 last_override_level_music = setup.override_level_music;
641 redraw_screen = TRUE;
648 /* force redraw of (open or closed) door graphics */
649 SetDoorState(DOOR_OPEN_ALL);
650 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
654 printf("<-- '%s'\n", artwork.gfx_current_identifier);
660 FreeLevelEditorGadgets();
669 static boolean gadgets_initialized = FALSE;
671 if (gadgets_initialized)
674 CreateLevelEditorGadgets();
678 CreateScreenGadgets();
680 gadgets_initialized = TRUE;
683 void InitElementInfo()
688 /* set values to -1 to identify later as "uninitialized" values */
689 for (i=0; i<MAX_ELEMENTS; i++)
691 for (act=0; act<NUM_GFX_ACTIONS_MAPPED; act++)
693 element_info[i].graphic[act] = -1;
695 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
696 element_info[i].direction_graphic[act][dir] = -1;
700 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
701 element_info[i].graphic[GFX_ACTION_DEFAULT] =
702 IMG_CHAR_START + (i - EL_CHAR_START);
704 for (i=EL_GENERIC_START; i<=EL_GENERIC_END; i++)
705 element_info[i].graphic[GFX_ACTION_DEFAULT] =
706 IMG_GENERIC_START + (i - EL_GENERIC_START);
709 while (element_to_graphic[i].element > -1)
711 int element = element_to_graphic[i].element;
712 int direction = element_to_graphic[i].direction;
713 int action = element_to_graphic[i].action;
714 int graphic = element_to_graphic[i].graphic;
717 action = graphics_action_mapping[action];
719 action = GFX_ACTION_DEFAULT;
723 direction = MV_DIR_BIT(direction);
725 element_info[element].direction_graphic[action][direction] = graphic;
728 element_info[element].graphic[action] = graphic;
733 /* now set all '-1' values to element specific default values */
734 for (i=0; i<MAX_ELEMENTS; i++)
736 int default_action_graphic = element_info[i].graphic[GFX_ACTION_DEFAULT];
737 int default_action_direction_graphic[NUM_MV_DIRECTIONS];
739 if (default_action_graphic == -1)
740 default_action_graphic = IMG_CHAR_QUESTION;
742 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
744 default_action_direction_graphic[dir] =
745 element_info[i].direction_graphic[GFX_ACTION_DEFAULT][dir];
747 if (default_action_direction_graphic[dir] == -1)
748 default_action_direction_graphic[dir] = default_action_graphic;
751 for (act=0; act<NUM_GFX_ACTIONS_MAPPED; act++)
753 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
755 int default_direction_graphic = element_info[i].graphic[act];
757 /* no graphic for current action -- use default direction graphic */
758 if (default_direction_graphic == -1)
759 default_direction_graphic = default_action_direction_graphic[dir];
761 if (element_info[i].direction_graphic[act][dir] == -1)
762 element_info[i].direction_graphic[act][dir] =
763 default_direction_graphic;
766 /* no graphic for this specific action -- use default action graphic */
767 if (element_info[i].graphic[act] == -1)
768 element_info[i].graphic[act] = default_action_graphic;
773 static void InitGraphicInfo()
775 static int gfx_action[NUM_IMAGE_FILES];
778 int first_frame, last_frame;
781 image_files = getCurrentImageList();
783 /* set temporary graphics action field to default value */
784 for (i=0; i<NUM_IMAGE_FILES; i++)
785 gfx_action[i] = GFX_ACTION_DEFAULT;
787 /* set temporary graphics action field from element_to_graphic list */
789 while (element_to_graphic[i].element > -1)
791 int action = element_to_graphic[i].action;
792 int graphic = element_to_graphic[i].graphic;
795 action = GFX_ACTION_DEFAULT;
797 gfx_action[graphic] = action;
802 for (i=0; i<NUM_IMAGE_FILES; i++)
804 int *parameter = image_files[i].parameter;
806 new_graphic_info[i].bitmap = getBitmapFromImageID(i);
808 new_graphic_info[i].src_x = parameter[GFX_ARG_XPOS] * TILEX;
809 new_graphic_info[i].src_y = parameter[GFX_ARG_YPOS] * TILEY;
810 new_graphic_info[i].offset_x = parameter[GFX_ARG_OFFSET];
811 new_graphic_info[i].offset_y = 0;
813 /* animation frames are ordered vertically instead of horizontally */
814 if (parameter[GFX_ARG_VERTICAL])
816 new_graphic_info[i].offset_x = 0;
817 new_graphic_info[i].offset_y = parameter[GFX_ARG_OFFSET];
820 /* optionally, the x and y offset of frames can be specified directly */
821 if (parameter[GFX_ARG_XOFFSET] != GFX_ARG_UNDEFINED_VALUE)
822 new_graphic_info[i].offset_x = parameter[GFX_ARG_XOFFSET];
823 if (parameter[GFX_ARG_YOFFSET] != GFX_ARG_UNDEFINED_VALUE)
824 new_graphic_info[i].offset_y = parameter[GFX_ARG_YOFFSET];
826 new_graphic_info[i].anim_frames = parameter[GFX_ARG_FRAMES];
828 new_graphic_info[i].anim_delay = parameter[GFX_ARG_DELAY];
829 if (new_graphic_info[i].anim_delay == 0) /* delay must be at least 1 */
830 new_graphic_info[i].anim_delay = 1;
832 /* set mode for animation frame order */
833 if (parameter[GFX_ARG_MODE_LOOP])
834 new_graphic_info[i].anim_mode = ANIM_LOOP;
835 else if (parameter[GFX_ARG_MODE_LINEAR])
836 new_graphic_info[i].anim_mode = ANIM_LINEAR;
837 else if (parameter[GFX_ARG_MODE_PINGPONG])
838 new_graphic_info[i].anim_mode = ANIM_PINGPONG;
839 else if (parameter[GFX_ARG_MODE_PINGPONG2])
840 new_graphic_info[i].anim_mode = ANIM_PINGPONG2;
841 else if (parameter[GFX_ARG_FRAMES] > 1)
842 new_graphic_info[i].anim_mode = ANIM_LOOP;
844 new_graphic_info[i].anim_mode = ANIM_NONE;
846 /* set additional flag to play animation frames in reverse order */
847 if (parameter[GFX_ARG_MODE_REVERSE])
848 new_graphic_info[i].anim_mode |= ANIM_REVERSE;
850 /* set first frame of animation after determining animation mode */
851 new_graphic_info[i].anim_start_frame = parameter[GFX_ARG_START_FRAME];
853 /* automatically determine correct start frame, if not defined */
854 if (parameter[GFX_ARG_START_FRAME] == GFX_ARG_UNDEFINED_VALUE)
855 new_graphic_info[i].anim_start_frame = 0;
856 else if (new_graphic_info[i].anim_mode & ANIM_REVERSE)
857 new_graphic_info[i].anim_start_frame =
858 new_graphic_info[i].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
860 /* animation synchronized with global frame counter, not move position */
861 new_graphic_info[i].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
863 /* set global_sync for all animations with undefined "animation action" */
864 if (parameter[GFX_ARG_GLOBAL_SYNC] == GFX_ARG_UNDEFINED_VALUE)
865 new_graphic_info[i].anim_global_sync =
866 (gfx_action[i] == GFX_ACTION_DEFAULT ? TRUE : FALSE);
868 /* "linear" animations are never globally synchronized */
869 if (parameter[GFX_ARG_MODE_LINEAR])
870 new_graphic_info[i].anim_global_sync = FALSE;
872 /* now check if no animation frames are outside of the loaded image */
875 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
876 if (src_x < 0 || src_y < 0 ||
877 src_x + TILEX > src_bitmap->width ||
878 src_y + TILEY > src_bitmap->height)
879 Error(ERR_EXIT, "InitGraphicInfo: first frame of graphic animation object %d outside of image bitmap file '%s'", i, src_bitmap->source_filename);
881 last_frame = new_graphic_info[i].anim_frames - 1;
882 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
883 if (src_x < 0 || src_y < 0 ||
884 src_x + TILEX > src_bitmap->width ||
885 src_y + TILEY > src_bitmap->height)
886 Error(ERR_EXIT, "InitGraphicInfo: last frame of graphic animation object %d outside of image bitmap file '%s'", i, src_bitmap->source_filename);
890 static void InitSoundInfo()
892 sound_files = getCurrentSoundList();
894 /* initialize sound effect lookup table for element actions */
898 void InitElementProperties()
902 static int ep_amoebalive[] =
909 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
911 static int ep_amoeboid[] =
919 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
921 static int ep_schluessel[] =
932 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
934 static int ep_pforte[] =
953 EL_SWITCHGATE_OPENING,
954 EL_SWITCHGATE_CLOSED,
955 EL_SWITCHGATE_CLOSING,
963 EL_TUBE_VERTICAL_LEFT,
964 EL_TUBE_VERTICAL_RIGHT,
965 EL_TUBE_HORIZONTAL_UP,
966 EL_TUBE_HORIZONTAL_DOWN,
972 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
974 static int ep_solid[] =
994 EL_QUICKSAND_FILLING,
995 EL_QUICKSAND_EMPTYING,
997 EL_MAGIC_WALL_ACTIVE,
998 EL_MAGIC_WALL_EMPTYING,
999 EL_MAGIC_WALL_FILLING,
1003 EL_BD_MAGIC_WALL_ACTIVE,
1004 EL_BD_MAGIC_WALL_EMPTYING,
1005 EL_BD_MAGIC_WALL_FULL,
1006 EL_BD_MAGIC_WALL_FILLING,
1007 EL_BD_MAGIC_WALL_DEAD,
1010 EL_ACIDPOOL_TOPLEFT,
1011 EL_ACIDPOOL_TOPRIGHT,
1012 EL_ACIDPOOL_BOTTOMLEFT,
1014 EL_ACIDPOOL_BOTTOMRIGHT,
1032 EL_SP_TERMINAL_ACTIVE,
1035 EL_INVISIBLE_STEELWALL,
1036 EL_INVISIBLE_STEELWALL_ACTIVE,
1038 EL_INVISIBLE_WALL_ACTIVE,
1039 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1040 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1041 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1042 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1043 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1044 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1045 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1046 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1047 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1048 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1049 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1050 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1051 EL_SWITCHGATE_SWITCH_UP,
1052 EL_SWITCHGATE_SWITCH_DOWN,
1054 EL_LIGHT_SWITCH_ACTIVE,
1056 EL_TIMEGATE_SWITCH_ACTIVE,
1057 EL_SIGN_EXCLAMATION,
1058 EL_SIGN_RADIOACTIVITY,
1069 EL_STEELWALL_SLANTED,
1074 EL_EMC_WALL_PILLAR_UPPER,
1075 EL_EMC_WALL_PILLAR_MIDDLE,
1076 EL_EMC_WALL_PILLAR_LOWER,
1102 EL_SWITCHGATE_OPENING,
1103 EL_SWITCHGATE_CLOSED,
1104 EL_SWITCHGATE_CLOSING,
1106 EL_TIMEGATE_OPENING,
1108 EL_TIMEGATE_CLOSING,
1112 EL_TUBE_VERTICAL_LEFT,
1113 EL_TUBE_VERTICAL_RIGHT,
1114 EL_TUBE_HORIZONTAL_UP,
1115 EL_TUBE_HORIZONTAL_DOWN,
1121 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1123 static int ep_massive[] =
1127 EL_ACIDPOOL_TOPLEFT,
1128 EL_ACIDPOOL_TOPRIGHT,
1129 EL_ACIDPOOL_BOTTOMLEFT,
1131 EL_ACIDPOOL_BOTTOMRIGHT,
1143 EL_INVISIBLE_STEELWALL,
1144 EL_INVISIBLE_STEELWALL_ACTIVE,
1145 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1146 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1147 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1148 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1149 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1150 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1151 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1152 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1153 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1154 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1155 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1156 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1158 EL_LIGHT_SWITCH_ACTIVE,
1159 EL_SIGN_EXCLAMATION,
1160 EL_SIGN_RADIOACTIVITY,
1171 EL_STEELWALL_SLANTED,
1194 EL_SWITCHGATE_OPENING,
1195 EL_SWITCHGATE_CLOSED,
1196 EL_SWITCHGATE_CLOSING,
1198 EL_TIMEGATE_OPENING,
1200 EL_TIMEGATE_CLOSING,
1204 EL_TUBE_VERTICAL_LEFT,
1205 EL_TUBE_VERTICAL_RIGHT,
1206 EL_TUBE_HORIZONTAL_UP,
1207 EL_TUBE_HORIZONTAL_DOWN,
1213 static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive);
1215 static int ep_slippery[] =
1229 EL_ROBOT_WHEEL_ACTIVE,
1235 EL_ACIDPOOL_TOPLEFT,
1236 EL_ACIDPOOL_TOPRIGHT,
1246 EL_STEELWALL_SLANTED,
1250 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1252 static int ep_enemy[] =
1265 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1267 static int ep_mauer[] =
1295 EL_WALL_GROWING_ACTIVE,
1314 EL_SP_TERMINAL_ACTIVE,
1317 EL_INVISIBLE_STEELWALL,
1318 EL_INVISIBLE_STEELWALL_ACTIVE,
1320 EL_INVISIBLE_WALL_ACTIVE,
1321 EL_STEELWALL_SLANTED,
1326 EL_EMC_WALL_PILLAR_UPPER,
1327 EL_EMC_WALL_PILLAR_MIDDLE,
1328 EL_EMC_WALL_PILLAR_LOWER,
1335 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1337 static int ep_can_fall[] =
1352 EL_BD_MAGIC_WALL_FULL,
1363 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1365 static int ep_can_smash[] =
1396 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1398 static int ep_can_change[] =
1409 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1411 static int ep_can_move[] =
1431 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1433 static int ep_could_move[] =
1443 EL_BD_BUTTERFLY_RIGHT,
1445 EL_BD_BUTTERFLY_LEFT,
1446 EL_BD_BUTTERFLY_DOWN,
1447 EL_BD_FIREFLY_RIGHT,
1456 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1458 static int ep_dont_touch[] =
1465 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1467 static int ep_dont_go_to[] =
1481 EL_SP_BUGGY_BASE_ACTIVE,
1485 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
1487 static int ep_mampf2[] =
1512 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1514 static int ep_bd_element[] =
1541 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1543 static int ep_sb_element[] =
1548 EL_SOKOBAN_FIELD_EMPTY,
1549 EL_SOKOBAN_FIELD_FULL,
1551 EL_INVISIBLE_STEELWALL
1553 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1555 static int ep_gem[] =
1564 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1566 static int ep_inactive[] =
1603 EL_INVISIBLE_STEELWALL,
1611 EL_WALL_EMERALD_YELLOW,
1616 EL_SOKOBAN_FIELD_EMPTY,
1617 EL_SOKOBAN_FIELD_FULL,
1618 EL_WALL_EMERALD_RED,
1619 EL_WALL_EMERALD_PURPLE,
1620 EL_ACIDPOOL_TOPLEFT,
1621 EL_ACIDPOOL_TOPRIGHT,
1622 EL_ACIDPOOL_BOTTOMLEFT,
1624 EL_ACIDPOOL_BOTTOMRIGHT,
1628 EL_BD_MAGIC_WALL_DEAD,
1629 EL_AMOEBA_TO_DIAMOND,
1662 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1663 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1664 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1665 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1666 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1667 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1668 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1669 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1670 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1671 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1672 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1673 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1674 EL_SIGN_EXCLAMATION,
1675 EL_SIGN_RADIOACTIVITY,
1686 EL_STEELWALL_SLANTED,
1691 EL_EMC_WALL_PILLAR_UPPER,
1692 EL_EMC_WALL_PILLAR_MIDDLE,
1693 EL_EMC_WALL_PILLAR_LOWER,
1700 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
1702 static int ep_explosive[] =
1707 EL_DYNABOMB_PLAYER1_ACTIVE,
1708 EL_DYNABOMB_PLAYER2_ACTIVE,
1709 EL_DYNABOMB_PLAYER3_ACTIVE,
1710 EL_DYNABOMB_PLAYER4_ACTIVE,
1727 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
1729 static int ep_mampf3[] =
1740 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
1742 static int ep_pushable[] =
1749 EL_SOKOBAN_FIELD_FULL,
1759 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
1761 static int ep_player[] =
1768 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
1770 static int ep_has_content[] =
1778 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
1780 static int ep_eatable[] =
1787 EL_INVISIBLE_SAND_ACTIVE
1789 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
1791 static int ep_sp_element[] =
1834 /* additional elements that appeared in newer Supaplex levels */
1836 /* more than one murphy in a level results in an inactive clone */
1839 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
1841 static int ep_quick_gate[] =
1865 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
1867 static int ep_over_player[] =
1883 EL_TUBE_VERTICAL_LEFT,
1884 EL_TUBE_VERTICAL_RIGHT,
1885 EL_TUBE_HORIZONTAL_UP,
1886 EL_TUBE_HORIZONTAL_DOWN,
1892 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
1894 static int ep_active_bomb[] =
1897 EL_DYNABOMB_PLAYER1_ACTIVE,
1898 EL_DYNABOMB_PLAYER2_ACTIVE,
1899 EL_DYNABOMB_PLAYER3_ACTIVE,
1900 EL_DYNABOMB_PLAYER4_ACTIVE
1902 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
1904 static int ep_belt[] =
1906 EL_CONVEYOR_BELT1_LEFT,
1907 EL_CONVEYOR_BELT1_MIDDLE,
1908 EL_CONVEYOR_BELT1_RIGHT,
1909 EL_CONVEYOR_BELT2_LEFT,
1910 EL_CONVEYOR_BELT2_MIDDLE,
1911 EL_CONVEYOR_BELT2_RIGHT,
1912 EL_CONVEYOR_BELT3_LEFT,
1913 EL_CONVEYOR_BELT3_MIDDLE,
1914 EL_CONVEYOR_BELT3_RIGHT,
1915 EL_CONVEYOR_BELT4_LEFT,
1916 EL_CONVEYOR_BELT4_MIDDLE,
1917 EL_CONVEYOR_BELT4_RIGHT,
1919 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
1921 static int ep_belt_active[] =
1923 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
1924 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
1925 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
1926 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
1927 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
1928 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
1929 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
1930 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
1931 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
1932 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
1933 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
1934 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
1936 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
1938 static int ep_belt_switch[] =
1940 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1941 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1942 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1943 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1944 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1945 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1946 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1947 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1948 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1949 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1950 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1951 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1953 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
1955 static int ep_tube[] =
1960 EL_TUBE_VERTICAL_LEFT,
1961 EL_TUBE_VERTICAL_RIGHT,
1962 EL_TUBE_HORIZONTAL_UP,
1963 EL_TUBE_HORIZONTAL_DOWN,
1969 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
1971 static long ep1_bit[] =
2005 static long ep2_bit[] =
2012 static int *ep1_array[] =
2046 static int *ep2_array[] =
2053 static int *ep1_num[] =
2080 &ep_has_content_num,
2084 &ep_over_player_num,
2087 static int *ep2_num[] =
2090 &ep_belt_active_num,
2091 &ep_belt_switch_num,
2094 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2095 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2097 for (i=0; i<MAX_ELEMENTS; i++)
2099 Elementeigenschaften1[i] = 0;
2100 Elementeigenschaften2[i] = 0;
2103 for (i=0; i<num_properties1; i++)
2104 for (j=0; j<*(ep1_num[i]); j++)
2105 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2106 for (i=0; i<num_properties2; i++)
2107 for (j=0; j<*(ep2_num[i]); j++)
2108 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2110 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2111 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2114 void Execute_Command(char *command)
2116 if (strcmp(command, "print graphicsinfo.conf") == 0)
2120 printf("# You can configure additional/alternative image files here.\n");
2121 printf("# (The images below are default and therefore commented out.)\n");
2123 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2125 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2128 for (i=0; image_config[i].token != NULL; i++)
2130 getFormattedSetupEntry(image_config[i].token,
2131 image_config[i].value));
2135 else if (strcmp(command, "print soundsinfo.conf") == 0)
2139 printf("# You can configure additional/alternative sound files here.\n");
2140 printf("# (The sounds below are default and therefore commented out.)\n");
2142 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2144 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2147 for (i=0; sound_config[i].token != NULL; i++)
2149 getFormattedSetupEntry(sound_config[i].token,
2150 sound_config[i].value));
2154 else if (strcmp(command, "print musicinfo.conf") == 0)
2156 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2158 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2160 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2164 else if (strncmp(command, "dump tape ", 10) == 0)
2166 char *filename = &command[10];
2168 if (access(filename, F_OK) != 0)
2169 Error(ERR_EXIT, "cannot open file '%s'", filename);
2171 LoadTapeFromFilename(filename);
2176 else if (strncmp(command, "autoplay ", 9) == 0)
2178 char *str_copy = getStringCopy(&command[9]);
2179 char *str_ptr = strchr(str_copy, ' ');
2181 global.autoplay_leveldir = str_copy;
2182 global.autoplay_level_nr = -1;
2184 if (str_ptr != NULL)
2186 *str_ptr++ = '\0'; /* terminate leveldir string */
2187 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2192 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2196 void CloseAllAndExit(int exit_value)
2201 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2204 FreeTileClipmasks();
2206 if (bitmap_font_initial)
2207 FreeBitmap(bitmap_font_initial);
2209 CloseVideoDisplay();
2210 ClosePlatformDependantStuff();