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 */
127 InitGadgets(); /* needs images + number of level series */
132 if (global.autoplay_leveldir)
145 global.autoplay_leveldir = NULL;
147 global.frames_per_second = 0;
148 global.fps_slowdown = FALSE;
149 global.fps_slowdown_factor = 1;
154 LoadSetup(); /* global setup info */
157 void InitPlayerInfo()
161 /* choose default local player */
162 local_player = &stored_player[0];
164 for (i=0; i<MAX_PLAYERS; i++)
165 stored_player[i].connected = FALSE;
167 local_player->connected = TRUE;
172 LoadLevelInfo(); /* global level info */
173 LoadLevelSetup_LastSeries(); /* last played series info */
174 LoadLevelSetup_SeriesInfo(); /* last played level info */
177 void InitArtworkInfo()
182 void InitLevelArtworkInfo()
184 LoadLevelArtworkInfo();
187 void InitNetworkServer()
189 #if defined(PLATFORM_UNIX)
193 if (!options.network)
196 #if defined(PLATFORM_UNIX)
197 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
199 if (!ConnectToServer(options.server_host, options.server_port))
200 Error(ERR_EXIT, "cannot connect to network game server");
202 SendToServer_PlayerName(setup.player_name);
203 SendToServer_ProtocolVersion();
206 SendToServer_NrWanted(nr_wanted);
210 static void ReinitializeGraphics()
212 ReloadCustomImages(); /* load custom image files */
214 InitGraphicInfo(); /* initialize graphic info from config file */
216 InitFontInfo(bitmap_font_initial,
217 new_graphic_info[IMG_MENU_FONT_BIG].bitmap,
218 new_graphic_info[IMG_MENU_FONT_MEDIUM].bitmap,
219 new_graphic_info[IMG_MENU_FONT_SMALL].bitmap,
220 new_graphic_info[IMG_MENU_FONT_EM].bitmap);
223 static void InitImages()
225 InitImageList(image_config, image_config_suffix, NUM_IMAGE_FILES);
227 ReinitializeGraphics();
230 static void InitMixer()
234 InitSoundList(sound_config, sound_config_suffix, NUM_SOUND_FILES);
239 static void InitSound()
241 /* load custom sounds and music */
242 InitReloadSounds(artwork.snd_current->identifier);
243 InitReloadMusic(artwork.mus_current->identifier);
248 static void InitTileClipmasks()
250 #if defined(TARGET_X11)
251 XGCValues clip_gc_values;
252 unsigned long clip_gc_valuemask;
254 #if defined(TARGET_X11_NATIVE)
264 tile_needs_clipping[] =
266 { GFX_SPIELER1_UP, 4 },
267 { GFX_SPIELER1_DOWN, 4 },
268 { GFX_SPIELER1_LEFT, 4 },
269 { GFX_SPIELER1_RIGHT, 4 },
270 { GFX_SPIELER1_PUSH_LEFT, 4 },
271 { GFX_SPIELER1_PUSH_RIGHT, 4 },
272 { GFX_SPIELER2_UP, 4 },
273 { GFX_SPIELER2_DOWN, 4 },
274 { GFX_SPIELER2_LEFT, 4 },
275 { GFX_SPIELER2_RIGHT, 4 },
276 { GFX_SPIELER2_PUSH_LEFT, 4 },
277 { GFX_SPIELER2_PUSH_RIGHT, 4 },
278 { GFX_SPIELER3_UP, 4 },
279 { GFX_SPIELER3_DOWN, 4 },
280 { GFX_SPIELER3_LEFT, 4 },
281 { GFX_SPIELER3_RIGHT, 4 },
282 { GFX_SPIELER3_PUSH_LEFT, 4 },
283 { GFX_SPIELER3_PUSH_RIGHT, 4 },
284 { GFX_SPIELER4_UP, 4 },
285 { GFX_SPIELER4_DOWN, 4 },
286 { GFX_SPIELER4_LEFT, 4 },
287 { GFX_SPIELER4_RIGHT, 4 },
288 { GFX_SPIELER4_PUSH_LEFT, 4 },
289 { GFX_SPIELER4_PUSH_RIGHT, 4 },
290 { GFX_SP_MURPHY, 1 },
291 { GFX_MURPHY_GO_LEFT, 3 },
292 { GFX_MURPHY_GO_RIGHT, 3 },
293 { GFX_MURPHY_SNAP_UP, 1 },
294 { GFX_MURPHY_SNAP_DOWN, 1 },
295 { GFX_MURPHY_SNAP_RIGHT, 1 },
296 { GFX_MURPHY_SNAP_LEFT, 1 },
297 { GFX_MURPHY_PUSH_RIGHT, 1 },
298 { GFX_MURPHY_PUSH_LEFT, 1 },
299 { GFX_GEBLUBBER, 4 },
302 { GFX_EXPLOSION, 8 },
303 { GFX_SOKOBAN_OBJEKT, 1 },
304 { GFX_FUNKELN_BLAU, 3 },
305 { GFX_FUNKELN_WEISS, 3 },
306 { GFX2_SHIELD_PASSIVE, 3 },
307 { GFX2_SHIELD_ACTIVE, 3 },
312 #endif /* TARGET_X11_NATIVE */
313 #endif /* TARGET_X11 */
317 /* initialize pixmap array for special X11 tile clipping to Pixmap 'None' */
318 for (i=0; i<NUM_TILES; i++)
319 tile_clipmask[i] = None;
321 #if defined(TARGET_X11)
322 /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is
323 often very slow when preparing a masked XCopyArea() for big Pixmaps.
324 To prevent this, create small (tile-sized) mask Pixmaps which will then
325 be set much faster with XSetClipOrigin() and speed things up a lot. */
327 clip_gc_values.graphics_exposures = False;
328 clip_gc_valuemask = GCGraphicsExposures;
329 tile_clip_gc = XCreateGC(display, window->drawable,
330 clip_gc_valuemask, &clip_gc_values);
333 for (i=0; i<NUM_BITMAPS; i++)
335 if (pix[i]->clip_mask)
337 clip_gc_values.graphics_exposures = False;
338 clip_gc_values.clip_mask = pix[i]->clip_mask;
339 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
340 pix[i]->stored_clip_gc = XCreateGC(display, window->drawable,
341 clip_gc_valuemask, &clip_gc_values);
346 #if defined(TARGET_X11_NATIVE)
349 /* create graphic context structures needed for clipping */
350 clip_gc_values.graphics_exposures = False;
351 clip_gc_valuemask = GCGraphicsExposures;
352 copy_clipmask_gc = XCreateGC(display, pix[PIX_BACK]->clip_mask,
353 clip_gc_valuemask, &clip_gc_values);
355 /* create only those clipping Pixmaps we really need */
356 for (i=0; tile_needs_clipping[i].start>=0; i++)
360 for (j=0; j<tile_needs_clipping[i].count; j++)
362 int tile = tile_needs_clipping[i].start + j;
368 getGraphicSource(graphic, &src_bitmap, &src_x, &src_y);
369 src_pixmap = src_bitmap->clip_mask;
371 tile_clipmask[tile] = XCreatePixmap(display, window->drawable,
374 XCopyArea(display, src_pixmap, tile_clipmask[tile], copy_clipmask_gc,
375 src_x, src_y, TILEX, TILEY, 0, 0);
379 XFreeGC(display, copy_clipmask_gc);
382 #endif /* TARGET_X11_NATIVE */
383 #endif /* TARGET_X11 */
386 void FreeTileClipmasks()
388 #if defined(TARGET_X11)
391 for (i=0; i<NUM_TILES; i++)
393 if (tile_clipmask[i] != None)
395 XFreePixmap(display, tile_clipmask[i]);
396 tile_clipmask[i] = None;
401 XFreeGC(display, tile_clip_gc);
405 for (i=0; i<NUM_BITMAPS; i++)
407 if (pix[i] != NULL && pix[i]->stored_clip_gc)
409 XFreeGC(display, pix[i]->stored_clip_gc);
410 pix[i]->stored_clip_gc = None;
415 #endif /* TARGET_X11 */
424 /* initialize screen properties */
425 InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
426 REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
427 InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
428 InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
429 InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
431 /* create additional image buffers for double-buffering */
432 bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
433 bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
436 pix[PIX_FONT_SMALL] = LoadCustomImage(image_filename[PIX_FONT_SMALL]);
438 InitFontInfo(NULL, NULL, pix[PIX_FONT_SMALL], NULL);
440 bitmap_font_initial = LoadCustomImage(image_filename[PIX_FONT_SMALL]);
442 InitFontInfo(bitmap_font_initial, NULL, NULL, NULL, NULL);
445 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
446 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
448 DrawInitText("Loading graphics:", 120, FC_GREEN);
451 for (i=0; i<NUM_PICTURES; i++)
454 if (i != PIX_FONT_SMALL)
457 DrawInitText(image_filename[i], 150, FC_YELLOW);
459 pix[i] = LoadCustomImage(image_filename[i]);
465 InitFontInfo(pix[PIX_FONT_BIG], pix[PIX_FONT_MEDIUM], pix[PIX_FONT_SMALL],
472 void InitGfxBackground()
477 fieldbuffer = bitmap_db_field;
478 SetDrawtoField(DRAW_BACKBUFFER);
480 BlitBitmap(new_graphic_info[IMG_MENU_BACK].bitmap, backbuffer,
481 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
482 ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
483 ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
485 for (x=0; x<MAX_BUF_XSIZE; x++)
486 for (y=0; y<MAX_BUF_YSIZE; y++)
489 redraw_mask = REDRAW_ALL;
492 void ReloadCustomArtwork()
494 static char *leveldir_current_identifier = NULL;
495 static boolean last_override_level_graphics = FALSE;
496 static boolean last_override_level_sounds = FALSE;
497 static boolean last_override_level_music = FALSE;
498 /* identifier for new artwork; default: artwork configured in setup */
499 char *gfx_new_identifier = artwork.gfx_current->identifier;
500 char *snd_new_identifier = artwork.snd_current->identifier;
501 char *mus_new_identifier = artwork.mus_current->identifier;
502 boolean redraw_screen = FALSE;
504 if (leveldir_current_identifier == NULL)
505 leveldir_current_identifier = leveldir_current->identifier;
508 printf("CURRENT GFX: '%s' ['%s']\n", artwork.gfx_current->identifier,
509 leveldir_current->graphics_set);
510 printf("CURRENT LEV: '%s' / '%s'\n", leveldir_current_identifier,
511 leveldir_current->identifier);
515 printf("graphics --> '%s' ('%s')\n",
516 artwork.gfx_current_identifier, artwork.gfx_current->filename);
517 printf("sounds --> '%s' ('%s')\n",
518 artwork.snd_current_identifier, artwork.snd_current->filename);
519 printf("music --> '%s' ('%s')\n",
520 artwork.mus_current_identifier, artwork.mus_current->filename);
523 /* leveldir_current may be invalid (level group, parent link) */
524 if (!validLevelSeries(leveldir_current))
528 printf("--> '%s'\n", artwork.gfx_current_identifier);
531 /* when a new level series was selected, check if there was a change
532 in custom artwork stored in level series directory */
533 if (leveldir_current_identifier != leveldir_current->identifier)
535 char *identifier_old = leveldir_current_identifier;
536 char *identifier_new = leveldir_current->identifier;
538 if (getTreeInfoFromIdentifier(artwork.gfx_first, identifier_old) !=
539 getTreeInfoFromIdentifier(artwork.gfx_first, identifier_new))
540 gfx_new_identifier = identifier_new;
541 if (getTreeInfoFromIdentifier(artwork.snd_first, identifier_old) !=
542 getTreeInfoFromIdentifier(artwork.snd_first, identifier_new))
543 snd_new_identifier = identifier_new;
544 if (getTreeInfoFromIdentifier(artwork.mus_first, identifier_new) !=
545 getTreeInfoFromIdentifier(artwork.mus_first, identifier_new))
546 mus_new_identifier = identifier_new;
548 leveldir_current_identifier = leveldir_current->identifier;
551 /* custom level artwork configured in level series configuration file
552 always overrides custom level artwork stored in level series directory
553 and (level independant) custom artwork configured in setup menue */
554 if (leveldir_current->graphics_set != NULL)
555 gfx_new_identifier = leveldir_current->graphics_set;
556 if (leveldir_current->sounds_set != NULL)
557 snd_new_identifier = leveldir_current->sounds_set;
558 if (leveldir_current->music_set != NULL)
559 mus_new_identifier = leveldir_current->music_set;
561 if (strcmp(artwork.gfx_current_identifier, gfx_new_identifier) != 0 ||
562 last_override_level_graphics != setup.override_level_graphics)
565 printf("CHANGED GFX: '%s' -> '%s'\n",
566 artwork.gfx_current_identifier, gfx_new_identifier);
573 setLevelArtworkDir(artwork.gfx_first);
575 ClearRectangle(window, 0, 0, WIN_XSIZE, WIN_YSIZE);
578 for (i=0; i<NUM_PICTURES; i++)
580 DrawInitText(image_filename[i], 150, FC_YELLOW);
581 ReloadCustomImage(pix[i], image_filename[i]);
585 ReinitializeGraphics();
593 /* force redraw of (open or closed) door graphics */
594 SetDoorState(DOOR_OPEN_ALL);
595 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
599 artwork.gfx_current_identifier = gfx_new_identifier;
601 artwork.gfx_current_identifier = artwork.gfx_current->identifier;
603 last_override_level_graphics = setup.override_level_graphics;
605 redraw_screen = TRUE;
608 if (strcmp(artwork.snd_current_identifier, snd_new_identifier) != 0 ||
609 last_override_level_sounds != setup.override_level_sounds)
611 /* set artwork path to send it to the sound server process */
612 setLevelArtworkDir(artwork.snd_first);
614 InitReloadSounds(snd_new_identifier);
616 artwork.snd_current_identifier = snd_new_identifier;
617 last_override_level_sounds = setup.override_level_sounds;
619 redraw_screen = TRUE;
622 if (strcmp(artwork.mus_current_identifier, mus_new_identifier) != 0 ||
623 last_override_level_music != setup.override_level_music)
625 /* set artwork path to send it to the sound server process */
626 setLevelArtworkDir(artwork.mus_first);
628 InitReloadMusic(mus_new_identifier);
630 artwork.mus_current_identifier = mus_new_identifier;
631 last_override_level_music = setup.override_level_music;
633 redraw_screen = TRUE;
640 /* force redraw of (open or closed) door graphics */
641 SetDoorState(DOOR_OPEN_ALL);
642 CloseDoor(DOOR_CLOSE_ALL | DOOR_NO_DELAY);
646 printf("<-- '%s'\n", artwork.gfx_current_identifier);
652 CreateLevelEditorGadgets();
656 CreateScreenGadgets();
659 void InitElementInfo()
664 /* set values to -1 to identify later as "uninitialized" values */
665 for (i=0; i<MAX_ELEMENTS; i++)
667 for (act=0; act<NUM_GFX_ACTIONS_MAPPED; act++)
669 element_info[i].graphic[act] = -1;
671 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
672 element_info[i].direction_graphic[act][dir] = -1;
676 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
677 element_info[i].graphic[GFX_ACTION_DEFAULT] =
678 IMG_CHAR_START + (i - EL_CHAR_START);
680 for (i=EL_GENERIC_START; i<=EL_GENERIC_END; i++)
681 element_info[i].graphic[GFX_ACTION_DEFAULT] =
682 IMG_GENERIC_START + (i - EL_GENERIC_START);
685 while (element_to_graphic[i].element > -1)
687 int element = element_to_graphic[i].element;
688 int direction = element_to_graphic[i].direction;
689 int action = element_to_graphic[i].action;
690 int graphic = element_to_graphic[i].graphic;
693 action = graphics_action_mapping[action];
695 action = GFX_ACTION_DEFAULT;
699 direction = MV_DIR_BIT(direction);
701 element_info[element].direction_graphic[action][direction] = graphic;
704 element_info[element].graphic[action] = graphic;
709 /* now set all '-1' values to element specific default values */
710 for (i=0; i<MAX_ELEMENTS; i++)
712 int default_action_graphic = element_info[i].graphic[GFX_ACTION_DEFAULT];
713 int default_action_direction_graphic[NUM_MV_DIRECTIONS];
715 if (default_action_graphic == -1)
716 default_action_graphic = IMG_CHAR_QUESTION;
718 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
720 default_action_direction_graphic[dir] =
721 element_info[i].direction_graphic[GFX_ACTION_DEFAULT][dir];
723 if (default_action_direction_graphic[dir] == -1)
724 default_action_direction_graphic[dir] = default_action_graphic;
727 for (act=0; act<NUM_GFX_ACTIONS_MAPPED; act++)
729 for (dir=0; dir<NUM_MV_DIRECTIONS; dir++)
731 int default_direction_graphic = element_info[i].graphic[act];
733 /* no graphic for current action -- use default direction graphic */
734 if (default_direction_graphic == -1)
735 default_direction_graphic = default_action_direction_graphic[dir];
737 if (element_info[i].direction_graphic[act][dir] == -1)
738 element_info[i].direction_graphic[act][dir] =
739 default_direction_graphic;
742 /* no graphic for this specific action -- use default action graphic */
743 if (element_info[i].graphic[act] == -1)
744 element_info[i].graphic[act] = default_action_graphic;
749 static void InitGraphicInfo()
751 static int gfx_action[NUM_IMAGE_FILES];
754 int first_frame, last_frame;
757 image_files = getCurrentImageList();
759 /* set temporary graphics action field to default value */
760 for (i=0; i<NUM_IMAGE_FILES; i++)
761 gfx_action[i] = GFX_ACTION_DEFAULT;
763 /* set temporary graphics action field from element_to_graphic list */
765 while (element_to_graphic[i].element > -1)
767 int action = element_to_graphic[i].action;
768 int graphic = element_to_graphic[i].graphic;
771 action = GFX_ACTION_DEFAULT;
773 gfx_action[graphic] = action;
778 for (i=0; i<NUM_IMAGE_FILES; i++)
780 int *parameter = image_files[i].parameter;
782 new_graphic_info[i].bitmap = getBitmapFromImageID(i);
784 new_graphic_info[i].src_x = parameter[GFX_ARG_XPOS] * TILEX;
785 new_graphic_info[i].src_y = parameter[GFX_ARG_YPOS] * TILEY;
786 new_graphic_info[i].offset_x = parameter[GFX_ARG_OFFSET];
787 new_graphic_info[i].offset_y = 0;
789 /* animation frames are ordered vertically instead of horizontally */
790 if (parameter[GFX_ARG_VERTICAL])
792 new_graphic_info[i].offset_x = 0;
793 new_graphic_info[i].offset_y = parameter[GFX_ARG_OFFSET];
796 /* optionally, the x and y offset of frames can be specified directly */
797 if (parameter[GFX_ARG_XOFFSET] != GFX_ARG_UNDEFINED_VALUE)
798 new_graphic_info[i].offset_x = parameter[GFX_ARG_XOFFSET];
799 if (parameter[GFX_ARG_YOFFSET] != GFX_ARG_UNDEFINED_VALUE)
800 new_graphic_info[i].offset_y = parameter[GFX_ARG_YOFFSET];
802 new_graphic_info[i].anim_frames = parameter[GFX_ARG_FRAMES];
804 new_graphic_info[i].anim_delay = parameter[GFX_ARG_DELAY];
805 if (new_graphic_info[i].anim_delay == 0) /* delay must be at least 1 */
806 new_graphic_info[i].anim_delay = 1;
808 /* set mode for animation frame order */
809 if (parameter[GFX_ARG_MODE_LOOP])
810 new_graphic_info[i].anim_mode = ANIM_LOOP;
811 else if (parameter[GFX_ARG_MODE_LINEAR])
812 new_graphic_info[i].anim_mode = ANIM_LINEAR;
813 else if (parameter[GFX_ARG_MODE_PINGPONG])
814 new_graphic_info[i].anim_mode = ANIM_PINGPONG;
815 else if (parameter[GFX_ARG_MODE_PINGPONG2])
816 new_graphic_info[i].anim_mode = ANIM_PINGPONG2;
817 else if (parameter[GFX_ARG_FRAMES] > 1)
818 new_graphic_info[i].anim_mode = ANIM_LOOP;
820 new_graphic_info[i].anim_mode = ANIM_NONE;
822 /* set additional flag to play animation frames in reverse order */
823 if (parameter[GFX_ARG_MODE_REVERSE])
824 new_graphic_info[i].anim_mode |= ANIM_REVERSE;
826 /* set first frame of animation after determining animation mode */
827 new_graphic_info[i].anim_start_frame = parameter[GFX_ARG_START_FRAME];
829 /* automatically determine correct start frame, if not defined */
830 if (parameter[GFX_ARG_START_FRAME] == GFX_ARG_UNDEFINED_VALUE)
831 new_graphic_info[i].anim_start_frame = 0;
832 else if (new_graphic_info[i].anim_mode & ANIM_REVERSE)
833 new_graphic_info[i].anim_start_frame =
834 new_graphic_info[i].anim_frames - parameter[GFX_ARG_START_FRAME] - 1;
836 /* animation synchronized with global frame counter, not move position */
837 new_graphic_info[i].anim_global_sync = parameter[GFX_ARG_GLOBAL_SYNC];
839 /* set global_sync for all animations with undefined "animation action" */
840 if (parameter[GFX_ARG_GLOBAL_SYNC] == GFX_ARG_UNDEFINED_VALUE)
841 new_graphic_info[i].anim_global_sync =
842 (gfx_action[i] == GFX_ACTION_DEFAULT ? TRUE : FALSE);
844 /* "linear" animations are never globally synchronized */
845 if (parameter[GFX_ARG_MODE_LINEAR])
846 new_graphic_info[i].anim_global_sync = FALSE;
848 /* now check if no animation frames are outside of the loaded image */
851 getGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
852 if (src_x < 0 || src_y < 0 ||
853 src_x + TILEX > src_bitmap->width ||
854 src_y + TILEY > src_bitmap->height)
855 Error(ERR_EXIT, "InitGraphicInfo: first frame of graphic animation object %d outside of image bitmap file '%s'", i, src_bitmap->source_filename);
857 last_frame = new_graphic_info[i].anim_frames - 1;
858 getGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
859 if (src_x < 0 || src_y < 0 ||
860 src_x + TILEX > src_bitmap->width ||
861 src_y + TILEY > src_bitmap->height)
862 Error(ERR_EXIT, "InitGraphicInfo: last frame of graphic animation object %d outside of image bitmap file '%s'", i, src_bitmap->source_filename);
866 static void InitSoundInfo()
868 sound_files = getCurrentSoundList();
870 /* initialize sound effect lookup table for element actions */
874 void InitElementProperties()
878 static int ep_amoebalive[] =
885 static int ep_amoebalive_num = SIZEOF_ARRAY_INT(ep_amoebalive);
887 static int ep_amoeboid[] =
895 static int ep_amoeboid_num = SIZEOF_ARRAY_INT(ep_amoeboid);
897 static int ep_schluessel[] =
908 static int ep_schluessel_num = SIZEOF_ARRAY_INT(ep_schluessel);
910 static int ep_pforte[] =
929 EL_SWITCHGATE_OPENING,
930 EL_SWITCHGATE_CLOSED,
931 EL_SWITCHGATE_CLOSING,
939 EL_TUBE_VERTICAL_LEFT,
940 EL_TUBE_VERTICAL_RIGHT,
941 EL_TUBE_HORIZONTAL_UP,
942 EL_TUBE_HORIZONTAL_DOWN,
948 static int ep_pforte_num = SIZEOF_ARRAY_INT(ep_pforte);
950 static int ep_solid[] =
970 EL_QUICKSAND_FILLING,
971 EL_QUICKSAND_EMPTYING,
973 EL_MAGIC_WALL_ACTIVE,
974 EL_MAGIC_WALL_EMPTYING,
975 EL_MAGIC_WALL_FILLING,
979 EL_BD_MAGIC_WALL_ACTIVE,
980 EL_BD_MAGIC_WALL_EMPTYING,
981 EL_BD_MAGIC_WALL_FULL,
982 EL_BD_MAGIC_WALL_FILLING,
983 EL_BD_MAGIC_WALL_DEAD,
987 EL_ACIDPOOL_TOPRIGHT,
988 EL_ACIDPOOL_BOTTOMLEFT,
990 EL_ACIDPOOL_BOTTOMRIGHT,
1008 EL_SP_TERMINAL_ACTIVE,
1011 EL_INVISIBLE_STEELWALL,
1012 EL_INVISIBLE_STEELWALL_ACTIVE,
1014 EL_INVISIBLE_WALL_ACTIVE,
1015 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1016 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1017 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1018 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1019 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1020 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1021 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1022 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1023 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1024 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1025 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1026 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1027 EL_SWITCHGATE_SWITCH_UP,
1028 EL_SWITCHGATE_SWITCH_DOWN,
1030 EL_LIGHT_SWITCH_ACTIVE,
1032 EL_TIMEGATE_SWITCH_ACTIVE,
1033 EL_SIGN_EXCLAMATION,
1034 EL_SIGN_RADIOACTIVITY,
1045 EL_STEELWALL_SLANTED,
1050 EL_EMC_WALL_PILLAR_UPPER,
1051 EL_EMC_WALL_PILLAR_MIDDLE,
1052 EL_EMC_WALL_PILLAR_LOWER,
1078 EL_SWITCHGATE_OPENING,
1079 EL_SWITCHGATE_CLOSED,
1080 EL_SWITCHGATE_CLOSING,
1082 EL_TIMEGATE_OPENING,
1084 EL_TIMEGATE_CLOSING,
1088 EL_TUBE_VERTICAL_LEFT,
1089 EL_TUBE_VERTICAL_RIGHT,
1090 EL_TUBE_HORIZONTAL_UP,
1091 EL_TUBE_HORIZONTAL_DOWN,
1097 static int ep_solid_num = SIZEOF_ARRAY_INT(ep_solid);
1099 static int ep_massive[] =
1103 EL_ACIDPOOL_TOPLEFT,
1104 EL_ACIDPOOL_TOPRIGHT,
1105 EL_ACIDPOOL_BOTTOMLEFT,
1107 EL_ACIDPOOL_BOTTOMRIGHT,
1119 EL_INVISIBLE_STEELWALL,
1120 EL_INVISIBLE_STEELWALL_ACTIVE,
1121 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1122 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1123 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1124 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1125 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1126 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1127 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1128 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1129 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1130 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1131 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1132 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1134 EL_LIGHT_SWITCH_ACTIVE,
1135 EL_SIGN_EXCLAMATION,
1136 EL_SIGN_RADIOACTIVITY,
1147 EL_STEELWALL_SLANTED,
1170 EL_SWITCHGATE_OPENING,
1171 EL_SWITCHGATE_CLOSED,
1172 EL_SWITCHGATE_CLOSING,
1174 EL_TIMEGATE_OPENING,
1176 EL_TIMEGATE_CLOSING,
1180 EL_TUBE_VERTICAL_LEFT,
1181 EL_TUBE_VERTICAL_RIGHT,
1182 EL_TUBE_HORIZONTAL_UP,
1183 EL_TUBE_HORIZONTAL_DOWN,
1189 static int ep_massive_num = SIZEOF_ARRAY_INT(ep_massive);
1191 static int ep_slippery[] =
1205 EL_ROBOT_WHEEL_ACTIVE,
1211 EL_ACIDPOOL_TOPLEFT,
1212 EL_ACIDPOOL_TOPRIGHT,
1222 EL_STEELWALL_SLANTED,
1226 static int ep_slippery_num = SIZEOF_ARRAY_INT(ep_slippery);
1228 static int ep_enemy[] =
1241 static int ep_enemy_num = SIZEOF_ARRAY_INT(ep_enemy);
1243 static int ep_mauer[] =
1271 EL_WALL_GROWING_ACTIVE,
1290 EL_SP_TERMINAL_ACTIVE,
1293 EL_INVISIBLE_STEELWALL,
1294 EL_INVISIBLE_STEELWALL_ACTIVE,
1296 EL_INVISIBLE_WALL_ACTIVE,
1297 EL_STEELWALL_SLANTED,
1302 EL_EMC_WALL_PILLAR_UPPER,
1303 EL_EMC_WALL_PILLAR_MIDDLE,
1304 EL_EMC_WALL_PILLAR_LOWER,
1311 static int ep_mauer_num = SIZEOF_ARRAY_INT(ep_mauer);
1313 static int ep_can_fall[] =
1328 EL_BD_MAGIC_WALL_FULL,
1339 static int ep_can_fall_num = SIZEOF_ARRAY_INT(ep_can_fall);
1341 static int ep_can_smash[] =
1372 static int ep_can_smash_num = SIZEOF_ARRAY_INT(ep_can_smash);
1374 static int ep_can_change[] =
1385 static int ep_can_change_num = SIZEOF_ARRAY_INT(ep_can_change);
1387 static int ep_can_move[] =
1407 static int ep_can_move_num = SIZEOF_ARRAY_INT(ep_can_move);
1409 static int ep_could_move[] =
1419 EL_BD_BUTTERFLY_RIGHT,
1421 EL_BD_BUTTERFLY_LEFT,
1422 EL_BD_BUTTERFLY_DOWN,
1423 EL_BD_FIREFLY_RIGHT,
1432 static int ep_could_move_num = SIZEOF_ARRAY_INT(ep_could_move);
1434 static int ep_dont_touch[] =
1441 static int ep_dont_touch_num = SIZEOF_ARRAY_INT(ep_dont_touch);
1443 static int ep_dont_go_to[] =
1457 EL_SP_BUGGY_BASE_ACTIVE,
1461 static int ep_dont_go_to_num = SIZEOF_ARRAY_INT(ep_dont_go_to);
1463 static int ep_mampf2[] =
1488 static int ep_mampf2_num = SIZEOF_ARRAY_INT(ep_mampf2);
1490 static int ep_bd_element[] =
1517 static int ep_bd_element_num = SIZEOF_ARRAY_INT(ep_bd_element);
1519 static int ep_sb_element[] =
1524 EL_SOKOBAN_FIELD_EMPTY,
1525 EL_SOKOBAN_FIELD_FULL,
1527 EL_INVISIBLE_STEELWALL
1529 static int ep_sb_element_num = SIZEOF_ARRAY_INT(ep_sb_element);
1531 static int ep_gem[] =
1540 static int ep_gem_num = SIZEOF_ARRAY_INT(ep_gem);
1542 static int ep_inactive[] =
1579 EL_INVISIBLE_STEELWALL,
1587 EL_WALL_EMERALD_YELLOW,
1592 EL_SOKOBAN_FIELD_EMPTY,
1593 EL_SOKOBAN_FIELD_FULL,
1594 EL_WALL_EMERALD_RED,
1595 EL_WALL_EMERALD_PURPLE,
1596 EL_ACIDPOOL_TOPLEFT,
1597 EL_ACIDPOOL_TOPRIGHT,
1598 EL_ACIDPOOL_BOTTOMLEFT,
1600 EL_ACIDPOOL_BOTTOMRIGHT,
1604 EL_BD_MAGIC_WALL_DEAD,
1605 EL_AMOEBA_TO_DIAMOND,
1638 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1639 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1640 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1641 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1642 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1643 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1644 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1645 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1646 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1647 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1648 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1649 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1650 EL_SIGN_EXCLAMATION,
1651 EL_SIGN_RADIOACTIVITY,
1662 EL_STEELWALL_SLANTED,
1667 EL_EMC_WALL_PILLAR_UPPER,
1668 EL_EMC_WALL_PILLAR_MIDDLE,
1669 EL_EMC_WALL_PILLAR_LOWER,
1676 static int ep_inactive_num = SIZEOF_ARRAY_INT(ep_inactive);
1678 static int ep_explosive[] =
1683 EL_DYNABOMB_PLAYER1_ACTIVE,
1684 EL_DYNABOMB_PLAYER2_ACTIVE,
1685 EL_DYNABOMB_PLAYER3_ACTIVE,
1686 EL_DYNABOMB_PLAYER4_ACTIVE,
1703 static int ep_explosive_num = SIZEOF_ARRAY_INT(ep_explosive);
1705 static int ep_mampf3[] =
1716 static int ep_mampf3_num = SIZEOF_ARRAY_INT(ep_mampf3);
1718 static int ep_pushable[] =
1725 EL_SOKOBAN_FIELD_FULL,
1735 static int ep_pushable_num = SIZEOF_ARRAY_INT(ep_pushable);
1737 static int ep_player[] =
1744 static int ep_player_num = SIZEOF_ARRAY_INT(ep_player);
1746 static int ep_has_content[] =
1754 static int ep_has_content_num = SIZEOF_ARRAY_INT(ep_has_content);
1756 static int ep_eatable[] =
1763 EL_INVISIBLE_SAND_ACTIVE
1765 static int ep_eatable_num = SIZEOF_ARRAY_INT(ep_eatable);
1767 static int ep_sp_element[] =
1810 /* additional elements that appeared in newer Supaplex levels */
1812 /* more than one murphy in a level results in an inactive clone */
1815 static int ep_sp_element_num = SIZEOF_ARRAY_INT(ep_sp_element);
1817 static int ep_quick_gate[] =
1841 static int ep_quick_gate_num = SIZEOF_ARRAY_INT(ep_quick_gate);
1843 static int ep_over_player[] =
1859 EL_TUBE_VERTICAL_LEFT,
1860 EL_TUBE_VERTICAL_RIGHT,
1861 EL_TUBE_HORIZONTAL_UP,
1862 EL_TUBE_HORIZONTAL_DOWN,
1868 static int ep_over_player_num = SIZEOF_ARRAY_INT(ep_over_player);
1870 static int ep_active_bomb[] =
1873 EL_DYNABOMB_PLAYER1_ACTIVE,
1874 EL_DYNABOMB_PLAYER2_ACTIVE,
1875 EL_DYNABOMB_PLAYER3_ACTIVE,
1876 EL_DYNABOMB_PLAYER4_ACTIVE
1878 static int ep_active_bomb_num = SIZEOF_ARRAY_INT(ep_active_bomb);
1880 static int ep_belt[] =
1882 EL_CONVEYOR_BELT1_LEFT,
1883 EL_CONVEYOR_BELT1_MIDDLE,
1884 EL_CONVEYOR_BELT1_RIGHT,
1885 EL_CONVEYOR_BELT2_LEFT,
1886 EL_CONVEYOR_BELT2_MIDDLE,
1887 EL_CONVEYOR_BELT2_RIGHT,
1888 EL_CONVEYOR_BELT3_LEFT,
1889 EL_CONVEYOR_BELT3_MIDDLE,
1890 EL_CONVEYOR_BELT3_RIGHT,
1891 EL_CONVEYOR_BELT4_LEFT,
1892 EL_CONVEYOR_BELT4_MIDDLE,
1893 EL_CONVEYOR_BELT4_RIGHT,
1895 static int ep_belt_num = SIZEOF_ARRAY_INT(ep_belt);
1897 static int ep_belt_active[] =
1899 EL_CONVEYOR_BELT1_LEFT_ACTIVE,
1900 EL_CONVEYOR_BELT1_MIDDLE_ACTIVE,
1901 EL_CONVEYOR_BELT1_RIGHT_ACTIVE,
1902 EL_CONVEYOR_BELT2_LEFT_ACTIVE,
1903 EL_CONVEYOR_BELT2_MIDDLE_ACTIVE,
1904 EL_CONVEYOR_BELT2_RIGHT_ACTIVE,
1905 EL_CONVEYOR_BELT3_LEFT_ACTIVE,
1906 EL_CONVEYOR_BELT3_MIDDLE_ACTIVE,
1907 EL_CONVEYOR_BELT3_RIGHT_ACTIVE,
1908 EL_CONVEYOR_BELT4_LEFT_ACTIVE,
1909 EL_CONVEYOR_BELT4_MIDDLE_ACTIVE,
1910 EL_CONVEYOR_BELT4_RIGHT_ACTIVE,
1912 static int ep_belt_active_num = SIZEOF_ARRAY_INT(ep_belt_active);
1914 static int ep_belt_switch[] =
1916 EL_CONVEYOR_BELT1_SWITCH_LEFT,
1917 EL_CONVEYOR_BELT1_SWITCH_MIDDLE,
1918 EL_CONVEYOR_BELT1_SWITCH_RIGHT,
1919 EL_CONVEYOR_BELT2_SWITCH_LEFT,
1920 EL_CONVEYOR_BELT2_SWITCH_MIDDLE,
1921 EL_CONVEYOR_BELT2_SWITCH_RIGHT,
1922 EL_CONVEYOR_BELT3_SWITCH_LEFT,
1923 EL_CONVEYOR_BELT3_SWITCH_MIDDLE,
1924 EL_CONVEYOR_BELT3_SWITCH_RIGHT,
1925 EL_CONVEYOR_BELT4_SWITCH_LEFT,
1926 EL_CONVEYOR_BELT4_SWITCH_MIDDLE,
1927 EL_CONVEYOR_BELT4_SWITCH_RIGHT,
1929 static int ep_belt_switch_num = SIZEOF_ARRAY_INT(ep_belt_switch);
1931 static int ep_tube[] =
1936 EL_TUBE_VERTICAL_LEFT,
1937 EL_TUBE_VERTICAL_RIGHT,
1938 EL_TUBE_HORIZONTAL_UP,
1939 EL_TUBE_HORIZONTAL_DOWN,
1945 static int ep_tube_num = SIZEOF_ARRAY_INT(ep_tube);
1947 static long ep1_bit[] =
1981 static long ep2_bit[] =
1988 static int *ep1_array[] =
2022 static int *ep2_array[] =
2029 static int *ep1_num[] =
2056 &ep_has_content_num,
2060 &ep_over_player_num,
2063 static int *ep2_num[] =
2066 &ep_belt_active_num,
2067 &ep_belt_switch_num,
2070 static int num_properties1 = SIZEOF_ARRAY(ep1_num, int *);
2071 static int num_properties2 = SIZEOF_ARRAY(ep2_num, int *);
2073 for (i=0; i<MAX_ELEMENTS; i++)
2075 Elementeigenschaften1[i] = 0;
2076 Elementeigenschaften2[i] = 0;
2079 for (i=0; i<num_properties1; i++)
2080 for (j=0; j<*(ep1_num[i]); j++)
2081 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2082 for (i=0; i<num_properties2; i++)
2083 for (j=0; j<*(ep2_num[i]); j++)
2084 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2086 for (i=EL_CHAR_START; i<=EL_CHAR_END; i++)
2087 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2090 void Execute_Command(char *command)
2092 if (strcmp(command, "print graphicsinfo.conf") == 0)
2096 printf("# You can configure additional/alternative image files here.\n");
2097 printf("# (The images below are default and therefore commented out.)\n");
2099 printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
2101 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2104 for (i=0; image_config[i].token != NULL; i++)
2106 getFormattedSetupEntry(image_config[i].token,
2107 image_config[i].value));
2111 else if (strcmp(command, "print soundsinfo.conf") == 0)
2115 printf("# You can configure additional/alternative sound files here.\n");
2116 printf("# (The sounds below are default and therefore commented out.)\n");
2118 printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
2120 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2123 for (i=0; sound_config[i].token != NULL; i++)
2125 getFormattedSetupEntry(sound_config[i].token,
2126 sound_config[i].value));
2130 else if (strcmp(command, "print musicinfo.conf") == 0)
2132 printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
2134 printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
2136 printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
2140 else if (strncmp(command, "dump tape ", 10) == 0)
2142 char *filename = &command[10];
2144 if (access(filename, F_OK) != 0)
2145 Error(ERR_EXIT, "cannot open file '%s'", filename);
2147 LoadTapeFromFilename(filename);
2152 else if (strncmp(command, "autoplay ", 9) == 0)
2154 char *str_copy = getStringCopy(&command[9]);
2155 char *str_ptr = strchr(str_copy, ' ');
2157 global.autoplay_leveldir = str_copy;
2158 global.autoplay_level_nr = -1;
2160 if (str_ptr != NULL)
2162 *str_ptr++ = '\0'; /* terminate leveldir string */
2163 global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
2168 Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
2172 void CloseAllAndExit(int exit_value)
2177 CloseAudio(); /* called after freeing sounds (needed for SDL) */
2180 FreeTileClipmasks();
2182 if (bitmap_font_initial)
2183 FreeBitmap(bitmap_font_initial);
2185 CloseVideoDisplay();
2186 ClosePlatformDependantStuff();