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)
880 Error(ERR_RETURN, "custom artwork configuration error:");
881 Error(ERR_RETURN, "- config file: '%s'",
882 getImageConfigFilename());
883 Error(ERR_RETURN, "- config token: '%s'",
884 getTokenFromImageID(i));
885 Error(ERR_RETURN, "- image file: '%s'",
886 src_bitmap->source_filename);
887 Error(ERR_EXIT, "error: first animation frame out of bounds (%d,%d)",
891 last_frame = new_graphic_info[i].anim_frames - 1;
892 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
893 if (src_x < 0 || src_y < 0 ||
894 src_x + TILEX > src_bitmap->width ||
895 src_y + TILEY > src_bitmap->height)
897 Error(ERR_RETURN, "custom artwork configuration error:");
898 Error(ERR_RETURN, "- config file: '%s'",
899 getImageConfigFilename());
900 Error(ERR_RETURN, "- config token: '%s'",
901 getTokenFromImageID(i));
902 Error(ERR_RETURN, "- image file: '%s'",
903 src_bitmap->source_filename);
904 Error(ERR_EXIT, "error: last animation frame out of bounds (%d,%d)",
910 static void InitSoundInfo()
912 sound_files = getCurrentSoundList();
914 /* initialize sound effect lookup table for element actions */
918 void InitElementProperties()
922 static int ep_amoebalive[] =
929 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
931 static int ep_amoeboid[] =
939 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
941 static int ep_schluessel[] =
952 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
954 static int ep_pforte[] =
973 EL_SWITCHGATE_OPENING,
974 EL_SWITCHGATE_CLOSED,
975 EL_SWITCHGATE_CLOSING,
983 EL_TUBE_VERTICAL_LEFT,
984 EL_TUBE_VERTICAL_RIGHT,
985 EL_TUBE_HORIZONTAL_UP,
986 EL_TUBE_HORIZONTAL_DOWN,
992 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
994 static int ep_solid[] =
1014 EL_QUICKSAND_FILLING,
1015 EL_QUICKSAND_EMPTYING,
1017 EL_MAGIC_WALL_ACTIVE,
1018 EL_MAGIC_WALL_EMPTYING,
1019 EL_MAGIC_WALL_FILLING,
1023 EL_BD_MAGIC_WALL_ACTIVE,
1024 EL_BD_MAGIC_WALL_EMPTYING,
1025 EL_BD_MAGIC_WALL_FULL,
1026 EL_BD_MAGIC_WALL_FILLING,
1027 EL_BD_MAGIC_WALL_DEAD,
1030 EL_ACIDPOOL_TOPLEFT,
1031 EL_ACIDPOOL_TOPRIGHT,
1032 EL_ACIDPOOL_BOTTOMLEFT,
1034 EL_ACIDPOOL_BOTTOMRIGHT,
1052 EL_SP_TERMINAL_ACTIVE,
1055 EL_INVISIBLE_STEELWALL,
1056 EL_INVISIBLE_STEELWALL_ACTIVE,
1058 EL_INVISIBLE_WALL_ACTIVE,
1059 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1060 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1061 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1062 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1063 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1064 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1065 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1066 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1067 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1068 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1069 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1070 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1071 EL_SWITCHGATE_SWITCH_UP,
1072 EL_SWITCHGATE_SWITCH_DOWN,
1074 EL_LIGHT_SWITCH_ACTIVE,
1076 EL_TIMEGATE_SWITCH_ACTIVE,
1077 EL_SIGN_EXCLAMATION,
1078 EL_SIGN_RADIOACTIVITY,
1089 EL_STEELWALL_SLANTED,
1094 EL_EMC_WALL_PILLAR_UPPER,
1095 EL_EMC_WALL_PILLAR_MIDDLE,
1096 EL_EMC_WALL_PILLAR_LOWER,
1122 EL_SWITCHGATE_OPENING,
1123 EL_SWITCHGATE_CLOSED,
1124 EL_SWITCHGATE_CLOSING,
1126 EL_TIMEGATE_OPENING,
1128 EL_TIMEGATE_CLOSING,
1132 EL_TUBE_VERTICAL_LEFT,
1133 EL_TUBE_VERTICAL_RIGHT,
1134 EL_TUBE_HORIZONTAL_UP,
1135 EL_TUBE_HORIZONTAL_DOWN,
1141 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1143 static int ep_massive[] =
1147 EL_ACIDPOOL_TOPLEFT,
1148 EL_ACIDPOOL_TOPRIGHT,
1149 EL_ACIDPOOL_BOTTOMLEFT,
1151 EL_ACIDPOOL_BOTTOMRIGHT,
1163 EL_INVISIBLE_STEELWALL,
1164 EL_INVISIBLE_STEELWALL_ACTIVE,
1165 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1166 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1167 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1168 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1169 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1170 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1171 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1172 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1173 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1174 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1175 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1176 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1178 EL_LIGHT_SWITCH_ACTIVE,
1179 EL_SIGN_EXCLAMATION,
1180 EL_SIGN_RADIOACTIVITY,
1191 EL_STEELWALL_SLANTED,
1214 EL_SWITCHGATE_OPENING,
1215 EL_SWITCHGATE_CLOSED,
1216 EL_SWITCHGATE_CLOSING,
1218 EL_TIMEGATE_OPENING,
1220 EL_TIMEGATE_CLOSING,
1224 EL_TUBE_VERTICAL_LEFT,
1225 EL_TUBE_VERTICAL_RIGHT,
1226 EL_TUBE_HORIZONTAL_UP,
1227 EL_TUBE_HORIZONTAL_DOWN,
1233 static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive);
1235 static int ep_slippery[] =
1249 EL_ROBOT_WHEEL_ACTIVE,
1255 EL_ACIDPOOL_TOPLEFT,
1256 EL_ACIDPOOL_TOPRIGHT,
1266 EL_STEELWALL_SLANTED,
1270 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1272 static int ep_enemy[] =
1285 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1287 static int ep_mauer[] =
1315 EL_WALL_GROWING_ACTIVE,
1334 EL_SP_TERMINAL_ACTIVE,
1337 EL_INVISIBLE_STEELWALL,
1338 EL_INVISIBLE_STEELWALL_ACTIVE,
1340 EL_INVISIBLE_WALL_ACTIVE,
1341 EL_STEELWALL_SLANTED,
1346 EL_EMC_WALL_PILLAR_UPPER,
1347 EL_EMC_WALL_PILLAR_MIDDLE,
1348 EL_EMC_WALL_PILLAR_LOWER,
1355 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1357 static int ep_can_fall[] =
1372 EL_BD_MAGIC_WALL_FULL,
1383 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1385 static int ep_can_smash[] =
1416 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1418 static int ep_can_change[] =
1429 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1431 static int ep_can_move[] =
1451 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1453 static int ep_could_move[] =
1463 EL_BD_BUTTERFLY_RIGHT,
1465 EL_BD_BUTTERFLY_LEFT,
1466 EL_BD_BUTTERFLY_DOWN,
1467 EL_BD_FIREFLY_RIGHT,
1476 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1478 static int ep_dont_touch[] =
1485 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1487 static int ep_dont_go_to[] =
1501 EL_SP_BUGGY_BASE_ACTIVE,
1505 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
1507 static int ep_mampf2[] =
1532 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1534 static int ep_bd_element[] =
1561 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1563 static int ep_sb_element[] =
1568 EL_SOKOBAN_FIELD_EMPTY,
1569 EL_SOKOBAN_FIELD_FULL,
1571 EL_INVISIBLE_STEELWALL
1573 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1575 static int ep_gem[] =
1584 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1586 static int ep_inactive[] =
1623 EL_INVISIBLE_STEELWALL,
1631 EL_WALL_EMERALD_YELLOW,
1636 EL_SOKOBAN_FIELD_EMPTY,
1637 EL_SOKOBAN_FIELD_FULL,
1638 EL_WALL_EMERALD_RED,
1639 EL_WALL_EMERALD_PURPLE,
1640 EL_ACIDPOOL_TOPLEFT,
1641 EL_ACIDPOOL_TOPRIGHT,
1642 EL_ACIDPOOL_BOTTOMLEFT,
1644 EL_ACIDPOOL_BOTTOMRIGHT,
1648 EL_BD_MAGIC_WALL_DEAD,
1649 EL_AMOEBA_TO_DIAMOND,
1682 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1683 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1684 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1685 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1686 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1687 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1688 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1689 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1690 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1691 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1692 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1693 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1694 EL_SIGN_EXCLAMATION,
1695 EL_SIGN_RADIOACTIVITY,
1706 EL_STEELWALL_SLANTED,
1711 EL_EMC_WALL_PILLAR_UPPER,
1712 EL_EMC_WALL_PILLAR_MIDDLE,
1713 EL_EMC_WALL_PILLAR_LOWER,
1720 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
1722 static int ep_explosive[] =
1727 EL_DYNABOMB_PLAYER1_ACTIVE,
1728 EL_DYNABOMB_PLAYER2_ACTIVE,
1729 EL_DYNABOMB_PLAYER3_ACTIVE,
1730 EL_DYNABOMB_PLAYER4_ACTIVE,
1747 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
1749 static int ep_mampf3[] =
1760 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
1762 static int ep_pushable[] =
1769 EL_SOKOBAN_FIELD_FULL,
1779 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
1781 static int ep_player[] =
1788 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
1790 static int ep_has_content[] =
1798 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
1800 static int ep_eatable[] =
1807 EL_INVISIBLE_SAND_ACTIVE
1809 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
1811 static int ep_sp_element[] =
1854 /* additional elements that appeared in newer Supaplex levels */
1856 /* more than one murphy in a level results in an inactive clone */
1859 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
1861 static int ep_quick_gate[] =
1885 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
1887 static int ep_over_player[] =
1903 EL_TUBE_VERTICAL_LEFT,
1904 EL_TUBE_VERTICAL_RIGHT,
1905 EL_TUBE_HORIZONTAL_UP,
1906 EL_TUBE_HORIZONTAL_DOWN,
1912 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
1914 static int ep_active_bomb[] =
1917 EL_DYNABOMB_PLAYER1_ACTIVE,
1918 EL_DYNABOMB_PLAYER2_ACTIVE,
1919 EL_DYNABOMB_PLAYER3_ACTIVE,
1920 EL_DYNABOMB_PLAYER4_ACTIVE
1922 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
1924 static int ep_belt[] =
1926 EL_CONVEYOR_BELT1_LEFT,
1927 EL_CONVEYOR_BELT1_MIDDLE,
1928 EL_CONVEYOR_BELT1_RIGHT,
1929 EL_CONVEYOR_BELT2_LEFT,
1930 EL_CONVEYOR_BELT2_MIDDLE,
1931 EL_CONVEYOR_BELT2_RIGHT,
1932 EL_CONVEYOR_BELT3_LEFT,
1933 EL_CONVEYOR_BELT3_MIDDLE,
1934 EL_CONVEYOR_BELT3_RIGHT,
1935 EL_CONVEYOR_BELT4_LEFT,
1936 EL_CONVEYOR_BELT4_MIDDLE,
1937 EL_CONVEYOR_BELT4_RIGHT,
1939 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
1941 static int ep_belt_active[] =
1943 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
1944 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
1945 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
1946 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
1947 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
1948 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
1949 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
1950 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
1951 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
1952 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
1953 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
1954 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
1956 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
1958 static int ep_belt_switch[] =
1960 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1961 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1962 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1963 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1964 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1965 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1966 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1967 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1968 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1969 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1970 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1971 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1973 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
1975 static int ep_tube[] =
1980 EL_TUBE_VERTICAL_LEFT,
1981 EL_TUBE_VERTICAL_RIGHT,
1982 EL_TUBE_HORIZONTAL_UP,
1983 EL_TUBE_HORIZONTAL_DOWN,
1989 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
1991 static long ep1_bit[] =
2025 static long ep2_bit[] =
2032 static int *ep1_array[] =
2066 static int *ep2_array[] =
2073 static int *ep1_num[] =
2100 &ep_has_content_num,
2104 &ep_over_player_num,
2107 static int *ep2_num[] =
2110 &ep_belt_active_num,
2111 &ep_belt_switch_num,
2114 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2115 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2117 for (i=0; i<MAX_ELEMENTS; i++)
2119 Elementeigenschaften1[i] = 0;
2120 Elementeigenschaften2[i] = 0;
2123 for (i=0; i<num_properties1; i++)
2124 for (j=0; j<*(ep1_num[i]); j++)
2125 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2126 for (i=0; i<num_properties2; i++)
2127 for (j=0; j<*(ep2_num[i]); j++)
2128 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2130 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2131 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2134 void Execute_Command(char *command)
2136 if (strcmp(command, "print graphicsinfo.conf") == 0)
2140 printf("# You can configure additional/alternative image files here.\n");
2141 printf("# (The images below are default and therefore commented out.)\n");
2143 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2145 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2148 for (i=0; image_config[i].token != NULL; i++)
2150 getFormattedSetupEntry(image_config[i].token,
2151 image_config[i].value));
2155 else if (strcmp(command, "print soundsinfo.conf") == 0)
2159 printf("# You can configure additional/alternative sound files here.\n");
2160 printf("# (The sounds below are default and therefore commented out.)\n");
2162 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2164 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2167 for (i=0; sound_config[i].token != NULL; i++)
2169 getFormattedSetupEntry(sound_config[i].token,
2170 sound_config[i].value));
2174 else if (strcmp(command, "print musicinfo.conf") == 0)
2176 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2178 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2180 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2184 else if (strncmp(command, "dump tape ", 10) == 0)
2186 char *filename = &command[10];
2188 if (access(filename, F_OK) != 0)
2189 Error(ERR_EXIT, "cannot open file '%s'", filename);
2191 LoadTapeFromFilename(filename);
2196 else if (strncmp(command, "autoplay ", 9) == 0)
2198 char *str_copy = getStringCopy(&command[9]);
2199 char *str_ptr = strchr(str_copy, ' ');
2201 global.autoplay_leveldir = str_copy;
2202 global.autoplay_level_nr = -1;
2204 if (str_ptr != NULL)
2206 *str_ptr++ = '\0'; /* terminate leveldir string */
2207 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2212 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2216 void CloseAllAndExit(int exit_value)
2221 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2224 FreeTileClipmasks();
2226 if (bitmap_font_initial)
2227 FreeBitmap(bitmap_font_initial);
2229 CloseVideoDisplay();
2230 ClosePlatformDependantStuff();