1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * (c) 1995-98 Artsoft Entertainment *
8 * phone: ++49 +521 290471 *
9 * email: aeglos@valinor.owl.de *
10 *----------------------------------------------------------*
12 ***********************************************************/
32 struct PictureFileInfo
34 char *picture_filename;
35 boolean picture_with_mask;
40 char *picture_filename;
41 char *picturemask_filename;
44 #ifndef USE_SDL_LIBRARY
45 static int sound_process_id = 0;
48 static void InitPlayerInfo(void);
49 static void InitLevelInfo(void);
50 static void InitNetworkServer(void);
51 static void InitDisplay(void);
52 static void InitSound(void);
53 static void InitSoundServer(void);
54 static void InitWindow(int, char **);
55 static void InitGfx(void);
56 static void LoadGfx(int, struct PictureFileInfo *);
57 static void InitGadgets(void);
58 static void InitElementProperties(void);
60 void OpenAll(int argc, char *argv[])
62 #if defined(MSDOS) || defined(WIN32)
66 if (options.serveronly)
69 Error(ERR_WARN, "networking not supported in Windows version");
71 NetworkServer(options.server_port, options.serveronly);
84 InitRND(NEW_RANDOMIZE);
86 signal(SIGINT, CloseAllAndExit);
87 signal(SIGTERM, CloseAllAndExit);
90 InitWindow(argc, argv);
92 #ifndef USE_SDL_LIBRARY
93 XMapWindow(display, window);
98 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
101 InitGadgets(); /* needs to know number of level series */
108 void InitPlayerInfo()
112 /* choose default local player */
113 local_player = &stored_player[0];
115 for (i=0; i<MAX_PLAYERS; i++)
117 stored_player[i].joystick_fd = -1; /* joystick device closed */
118 stored_player[i].connected = FALSE;
121 local_player->connected = TRUE;
123 LoadSetup(); /* global setup info */
128 LoadLevelInfo(); /* global level info */
129 LoadLevelSetup_LastSeries(); /* last played series info */
130 LoadLevelSetup_SeriesInfo(); /* last played level info */
133 void InitNetworkServer()
135 #if !defined(MSDOS) && !defined(WIN32)
139 if (!options.network)
142 #if !defined(MSDOS) && !defined(WIN32)
143 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
145 if (!ConnectToServer(options.server_host, options.server_port))
146 Error(ERR_EXIT, "cannot connect to network game server");
148 SendToServer_PlayerName(setup.player_name);
149 SendToServer_ProtocolVersion();
152 SendToServer_NrWanted(nr_wanted);
160 if (sound_status == SOUND_OFF)
163 #ifdef USE_SDL_LIBRARY
164 /* initialize SDL audio */
166 if (SDL_Init(SDL_INIT_AUDIO) < 0)
168 Error(ERR_WARN, "SDL_Init() failed: %s", SDL_GetError());
169 sound_status = SOUND_OFF;
173 if (Mix_OpenAudio(22050, AUDIO_S16, 2, 512) < 0)
175 Error(ERR_WARN, "Mix_OpenAudio() failed: %s", SDL_GetError());
176 sound_status = SOUND_OFF;
180 Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
181 Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
183 sound_status = SOUND_AVAILABLE;
184 sound_loops_allowed = TRUE;
186 #else /* !USE_SDL_LIBRARY */
188 #if !defined(MSDOS) && !defined(WIN32)
189 if (access(sound_device_name, W_OK) != 0)
191 Error(ERR_WARN, "cannot access sound device - no sounds");
192 sound_status = SOUND_OFF;
196 if ((sound_device = open(sound_device_name,O_WRONLY))<0)
198 Error(ERR_WARN, "cannot open sound device - no sounds");
199 sound_status = SOUND_OFF;
204 sound_status = SOUND_AVAILABLE;
207 sound_loops_allowed = TRUE;
210 setup.sound_loops_on = TRUE;
214 #else /* MSDOS || WIN32 */
215 sound_loops_allowed = TRUE;
218 setup.sound_loops_on = TRUE;
221 #endif /* MSDOS || WIN32 */
222 #endif /* !USE_SDL_LIBRARY */
224 for(i=0; i<NUM_SOUNDS; i++)
226 Sound[i].name = sound_name[i];
228 if (!LoadSound(&Sound[i]))
230 sound_status = SOUND_OFF;
236 sound_status = SOUND_OFF;
241 void InitSoundServer()
243 if (sound_status == SOUND_OFF)
246 #ifndef USE_SDL_LIBRARY
248 #if !defined(MSDOS) && !defined(WIN32)
250 if (pipe(sound_pipe)<0)
252 Error(ERR_WARN, "cannot create pipe - no sounds");
253 sound_status = SOUND_OFF;
257 if ((sound_process_id = fork()) < 0)
259 Error(ERR_WARN, "cannot create sound server process - no sounds");
260 sound_status = SOUND_OFF;
264 if (!sound_process_id) /* we are child */
271 else /* we are parent */
272 close(sound_pipe[0]); /* no reading from pipe needed */
274 #else /* MSDOS || WIN32 */
280 #endif /* !USE_SDL_LIBRARY */
285 #ifdef USE_SDL_JOYSTICK
286 static boolean sdl_joystick_subsystem_initialized = FALSE;
291 if (global_joystick_status == JOYSTICK_OFF)
294 joystick_status = JOYSTICK_OFF;
296 #ifdef USE_SDL_JOYSTICK
298 if (!sdl_joystick_subsystem_initialized)
300 sdl_joystick_subsystem_initialized = TRUE;
302 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
304 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
309 for (i=0; i<MAX_PLAYERS; i++)
311 char *device_name = setup.input[i].joy.device_name;
312 int joystick_nr = getJoystickNrFromDeviceName(device_name);
314 if (joystick_nr >= SDL_NumJoysticks())
317 /* misuse joystick file descriptor variable to store joystick number */
318 stored_player[i].joystick_fd = joystick_nr;
320 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
321 if (Check_SDL_JoystickOpened(joystick_nr))
322 Close_SDL_Joystick(joystick_nr);
324 if (!setup.input[i].use_joystick)
327 if (!Open_SDL_Joystick(joystick_nr))
329 Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
333 joystick_status = JOYSTICK_AVAILABLE;
336 #else /* !USE_SDL_JOYSTICK */
339 for (i=0; i<MAX_PLAYERS; i++)
341 char *device_name = setup.input[i].joy.device_name;
343 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
344 if (stored_player[i].joystick_fd != -1)
346 close(stored_player[i].joystick_fd);
347 stored_player[i].joystick_fd = -1;
350 if (!setup.input[i].use_joystick)
353 if (access(device_name, R_OK) != 0)
355 Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
359 if ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
361 Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
365 joystick_status = JOYSTICK_AVAILABLE;
370 /* try to access two joysticks; if that fails, try to access just one */
371 if (install_joystick(JOY_TYPE_2PADS) == 0 ||
372 install_joystick(JOY_TYPE_AUTODETECT) == 0)
373 joystick_status = JOYSTICK_AVAILABLE;
376 load_joystick_data(JOYSTICK_FILENAME);
379 for (i=0; i<MAX_PLAYERS; i++)
381 char *device_name = setup.input[i].joy.device_name;
382 int joystick_nr = getJoystickNrFromDeviceName(device_name);
384 if (joystick_nr >= num_joysticks)
387 /* misuse joystick file descriptor variable to store joystick number */
388 stored_player[i].joystick_fd = joystick_nr;
392 #endif /* !USE_SDL_LIBRARY */
397 #ifdef USE_SDL_LIBRARY
398 /* initialize SDL video */
399 if (SDL_Init(SDL_INIT_VIDEO) < 0)
400 Error(ERR_EXIT, "SDL_Init() failed: %s", SDL_GetError());
402 /* automatically cleanup SDL stuff after exit() */
405 #else /* !USE_SDL_LIBRARY */
408 XVisualInfo vinfo_template, *vinfo;
413 /* connect to X server */
414 if (!(display = XOpenDisplay(options.display_name)))
415 Error(ERR_EXIT, "cannot connect to X server %s",
416 XDisplayName(options.display_name));
418 screen = DefaultScreen(display);
419 visual = DefaultVisual(display, screen);
420 depth = DefaultDepth(display, screen);
421 cmap = DefaultColormap(display, screen);
424 /* look for good enough visual */
425 vinfo_template.screen = screen;
426 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
427 vinfo_template.depth = depth;
428 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
429 VisualDepthMask, &vinfo_template, &num_visuals)))
431 visual = vinfo->visual;
432 XFree((void *)vinfo);
435 /* got appropriate visual? */
438 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
441 else if ((depth ==8 && visual->class != PseudoColor) ||
442 (depth > 8 && visual->class != TrueColor &&
443 visual->class != DirectColor))
445 printf("Sorry, cannot get appropriate visual.\n");
449 #endif /* !USE_SDL_LIBRARY */
452 void InitWindow(int argc, char *argv[])
454 #ifdef USE_SDL_LIBRARY
455 /* open SDL video output device (window or fullscreen mode) */
457 if ((window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
460 Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s", SDL_GetError());
463 Error(ERR_EXIT, "setting video mode failed");
466 /* set window and icon title */
467 SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
469 /* set event filter to filter out certain mouse motion events */
470 SDL_SetEventFilter(EventFilter);
472 #else /* !USE_SDL_LIBRARY */
474 unsigned int border_width = 4;
476 unsigned long gc_valuemask;
478 XTextProperty windowName, iconName;
479 Pixmap icon_pixmap, iconmask_pixmap;
480 unsigned int icon_width, icon_height;
481 int icon_hot_x, icon_hot_y;
482 char icon_filename[256];
483 XSizeHints size_hints;
485 XClassHint class_hints;
486 char *window_name = WINDOW_TITLE_STRING;
487 char *icon_name = WINDOW_TITLE_STRING;
488 long window_event_mask;
489 Atom proto_atom = None, delete_atom = None;
491 int screen_width, screen_height;
492 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
493 unsigned long pen_fg = WhitePixel(display,screen);
494 unsigned long pen_bg = BlackPixel(display,screen);
495 const int width = WIN_XSIZE, height = WIN_YSIZE;
498 static struct IconFileInfo icon_pic =
505 screen_width = XDisplayWidth(display, screen);
506 screen_height = XDisplayHeight(display, screen);
508 win_xpos = (screen_width - width) / 2;
509 win_ypos = (screen_height - height) / 2;
511 window = XCreateSimpleWindow(display, RootWindow(display, screen),
512 win_xpos, win_ypos, width, height, border_width,
516 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
517 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
518 if ((proto_atom != None) && (delete_atom != None))
519 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
520 PropModePrepend, (unsigned char *) &delete_atom, 1);
522 sprintf(icon_filename, "%s/%s/%s",
523 options.ro_base_directory, GRAPHICS_DIRECTORY,
524 icon_pic.picture_filename);
525 XReadBitmapFile(display,window,icon_filename,
526 &icon_width,&icon_height,
527 &icon_pixmap,&icon_hot_x,&icon_hot_y);
529 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
531 sprintf(icon_filename, "%s/%s/%s",
532 options.ro_base_directory, GRAPHICS_DIRECTORY,
533 icon_pic.picturemask_filename);
534 XReadBitmapFile(display,window,icon_filename,
535 &icon_width,&icon_height,
536 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
537 if (!iconmask_pixmap)
538 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
540 size_hints.width = size_hints.min_width = size_hints.max_width = width;
541 size_hints.height = size_hints.min_height = size_hints.max_height = height;
542 size_hints.flags = PSize | PMinSize | PMaxSize;
544 if (win_xpos || win_ypos)
546 size_hints.x = win_xpos;
547 size_hints.y = win_ypos;
548 size_hints.flags |= PPosition;
551 if (!XStringListToTextProperty(&window_name, 1, &windowName))
552 Error(ERR_EXIT, "structure allocation for windowName failed");
554 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
555 Error(ERR_EXIT, "structure allocation for iconName failed");
557 wm_hints.initial_state = NormalState;
558 wm_hints.input = True;
559 wm_hints.icon_pixmap = icon_pixmap;
560 wm_hints.icon_mask = iconmask_pixmap;
561 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
563 class_hints.res_name = program_name;
564 class_hints.res_class = "Rocks'n'Diamonds";
566 XSetWMProperties(display, window, &windowName, &iconName,
567 argv, argc, &size_hints, &wm_hints,
570 XFree(windowName.value);
571 XFree(iconName.value);
573 /* Select event types wanted */
575 ExposureMask | StructureNotifyMask | FocusChangeMask |
576 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
577 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
579 XSelectInput(display, window, window_event_mask);
582 /* create GC for drawing with window depth and background color (black) */
583 gc_values.graphics_exposures = False;
584 gc_values.foreground = pen_bg;
585 gc_values.background = pen_bg;
586 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
587 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
588 #endif /* !USE_SDL_LIBRARY */
595 #ifdef USE_SDL_LIBRARY
596 SDL_Surface *sdl_image_tmp;
599 XGCValues clip_gc_values;
600 unsigned long clip_gc_valuemask;
604 static struct PictureFileInfo pic[NUM_PICTURES] =
618 static struct PictureFileInfo pic[NUM_PICTURES] =
620 { "RocksScreen", TRUE },
621 { "RocksDoor", TRUE },
622 { "RocksHeroes", TRUE },
623 { "RocksToons", TRUE },
626 { "RocksMore", TRUE },
627 { "RocksFont", FALSE },
628 { "RocksFont2", FALSE },
629 { "RocksFont3", FALSE }
635 static struct PictureFileInfo test_pic1 =
640 static struct PictureFileInfo test_pic2 =
653 tile_needs_clipping[] =
655 { GFX_SPIELER1_UP, 4 },
656 { GFX_SPIELER1_DOWN, 4 },
657 { GFX_SPIELER1_LEFT, 4 },
658 { GFX_SPIELER1_RIGHT, 4 },
659 { GFX_SPIELER1_PUSH_LEFT, 4 },
660 { GFX_SPIELER1_PUSH_RIGHT, 4 },
661 { GFX_SPIELER2_UP, 4 },
662 { GFX_SPIELER2_DOWN, 4 },
663 { GFX_SPIELER2_LEFT, 4 },
664 { GFX_SPIELER2_RIGHT, 4 },
665 { GFX_SPIELER2_PUSH_LEFT, 4 },
666 { GFX_SPIELER2_PUSH_RIGHT, 4 },
667 { GFX_SPIELER3_UP, 4 },
668 { GFX_SPIELER3_DOWN, 4 },
669 { GFX_SPIELER3_LEFT, 4 },
670 { GFX_SPIELER3_RIGHT, 4 },
671 { GFX_SPIELER3_PUSH_LEFT, 4 },
672 { GFX_SPIELER3_PUSH_RIGHT, 4 },
673 { GFX_SPIELER4_UP, 4 },
674 { GFX_SPIELER4_DOWN, 4 },
675 { GFX_SPIELER4_LEFT, 4 },
676 { GFX_SPIELER4_RIGHT, 4 },
677 { GFX_SPIELER4_PUSH_LEFT, 4 },
678 { GFX_SPIELER4_PUSH_RIGHT, 4 },
679 { GFX_SP_MURPHY, 1 },
680 { GFX_MURPHY_GO_LEFT, 3 },
681 { GFX_MURPHY_GO_RIGHT, 3 },
682 { GFX_MURPHY_SNAP_UP, 1 },
683 { GFX_MURPHY_SNAP_DOWN, 1 },
684 { GFX_MURPHY_SNAP_RIGHT, 1 },
685 { GFX_MURPHY_SNAP_LEFT, 1 },
686 { GFX_MURPHY_PUSH_RIGHT, 1 },
687 { GFX_MURPHY_PUSH_LEFT, 1 },
688 { GFX_GEBLUBBER, 4 },
691 { GFX_EXPLOSION, 8 },
692 { GFX_SOKOBAN_OBJEKT, 1 },
693 { GFX_FUNKELN_BLAU, 3 },
694 { GFX_FUNKELN_WEISS, 3 },
695 { GFX2_SHIELD_PASSIVE, 3 },
696 { GFX2_SHIELD_ACTIVE, 3 },
701 debug_print_timestamp(0, NULL); /* initialize timestamp function */
706 printf("Test: Loading RocksFont2.pcx ...\n");
707 LoadGfx(PIX_SMALLFONT,&test_pic1);
708 printf("Test: Done.\n");
709 printf("Test: Loading mouse.pcx ...\n");
710 LoadGfx(PIX_SMALLFONT,&test_pic2);
711 printf("Test: Done.\n");
715 LoadGfx(PIX_SMALLFONT, &pic[PIX_SMALLFONT]);
716 DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
717 DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
719 DrawInitText(PROGRAM_DOS_PORT_STRING, 210, FC_BLUE);
722 DrawInitText("Loading graphics:",120,FC_GREEN);
724 for(i=0; i<NUM_PICTURES; i++)
725 if (i != PIX_SMALLFONT)
729 debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
732 #ifdef USE_SDL_LIBRARY
733 /* create some native image surfaces for double-buffer purposes */
735 /* create double-buffer surface for background image */
736 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
737 WIN_XSIZE, WIN_YSIZE,
738 WIN_SDL_DEPTH, 0, 0, 0, 0))
740 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
742 if ((pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
743 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
745 SDL_FreeSurface(sdl_image_tmp);
747 /* create double-buffer surface for door image */
748 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
749 3 * DXSIZE, DYSIZE + VYSIZE,
750 WIN_SDL_DEPTH, 0, 0, 0, 0))
752 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
754 if ((pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
755 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
757 SDL_FreeSurface(sdl_image_tmp);
759 /* create double-buffer surface for field image */
760 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
762 WIN_SDL_DEPTH, 0, 0, 0, 0))
764 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
766 if ((pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
767 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
769 SDL_FreeSurface(sdl_image_tmp);
771 /* initialize surface array to 'NULL' */
772 for(i=0; i<NUM_TILES; i++)
773 tile_masked[i] = NULL;
775 /* create only those masked surfaces we really need */
776 for(i=0; tile_needs_clipping[i].start>=0; i++)
778 for(j=0; j<tile_needs_clipping[i].count; j++)
780 int tile = tile_needs_clipping[i].start + j;
786 getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y);
787 src_bitmap = pix_masked[bitmap_nr];
789 /* create surface for masked tile graphic */
790 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, TILEX, TILEY,
791 WIN_SDL_DEPTH, 0, 0, 0, 0))
793 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s", SDL_GetError());
795 /* create native transparent surface for current image */
796 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
797 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
798 if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
799 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
801 SDL_FreeSurface(sdl_image_tmp);
803 BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0);
807 #else /* !USE_SDL_LIBRARY */
809 pix[PIX_DB_BACK] = XCreatePixmap(display, window,
811 XDefaultDepth(display,screen));
812 pix[PIX_DB_DOOR] = XCreatePixmap(display, window,
813 3*DXSIZE,DYSIZE+VYSIZE,
814 XDefaultDepth(display,screen));
815 pix[PIX_DB_FIELD] = XCreatePixmap(display, window,
817 XDefaultDepth(display,screen));
819 clip_gc_values.graphics_exposures = False;
820 clip_gc_valuemask = GCGraphicsExposures;
822 XCreateGC(display,clipmask[PIX_BACK],clip_gc_valuemask,&clip_gc_values);
824 clip_gc_values.graphics_exposures = False;
825 clip_gc_valuemask = GCGraphicsExposures;
827 XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
829 /* initialize pixmap array to Pixmap 'None' */
830 for(i=0; i<NUM_TILES; i++)
831 tile_clipmask[i] = None;
833 /* create only those clipping Pixmaps we really need */
834 for(i=0; tile_needs_clipping[i].start>=0; i++)
836 for(j=0; j<tile_needs_clipping[i].count; j++)
838 int tile = tile_needs_clipping[i].start + j;
844 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
845 src_pixmap = clipmask[pixmap_nr];
847 tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
849 XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
850 src_x,src_y, TILEX,TILEY, 0,0);
854 if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
855 Error(ERR_EXIT, "cannot create additional pixmaps");
857 for(i=0; i<NUM_BITMAPS; i++)
861 clip_gc_values.graphics_exposures = False;
862 clip_gc_values.clip_mask = clipmask[i];
863 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
864 clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
868 #endif /* !USE_SDL_LIBRARY */
870 drawto = backbuffer = pix[PIX_DB_BACK];
871 fieldbuffer = pix[PIX_DB_FIELD];
872 SetDrawtoField(DRAW_BACKBUFFER);
874 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
875 ClearRectangle(pix[PIX_DB_BACK], REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
876 ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
878 for(i=0; i<MAX_BUF_XSIZE; i++)
879 for(j=0; j<MAX_BUF_YSIZE; j++)
882 redraw_mask = REDRAW_ALL;
885 void LoadGfx(int pos, struct PictureFileInfo *pic)
887 char basefilename[256];
890 #ifdef USE_XPM_LIBRARY
891 int xpm_err, xbm_err;
892 unsigned int width,height;
895 char *picture_ext = ".xpm";
896 char *picturemask_ext = "Mask.xbm";
899 #ifdef USE_SDL_LIBRARY
900 SDL_Surface *sdl_image_tmp;
901 #else /* !USE_SDL_LIBRARY */
903 #endif /* !USE_SDL_LIBRARY */
904 char *picture_ext = ".pcx";
906 #endif /* !USE_XPM_LIBRARY */
909 if (pic->picture_filename)
911 sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext);
912 DrawInitText(basefilename, 150, FC_YELLOW);
913 sprintf(filename, "%s/%s/%s",
914 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
921 debug_print_timestamp(1, NULL); /* initialize timestamp function */
924 #ifdef USE_SDL_LIBRARY
925 /* load image to temporary surface */
926 if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
927 Error(ERR_EXIT, "IMG_Load() failed: %s", SDL_GetError());
929 /* create native non-transparent surface for current image */
930 if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
931 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
933 /* create native transparent surface for current image */
934 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
935 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
936 if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
937 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s", SDL_GetError());
939 /* free temporary surface */
940 SDL_FreeSurface(sdl_image_tmp);
942 #else /* !USE_SDL_LIBRARY */
944 #ifdef USE_XPM_LIBRARY
946 xpm_att[pos].valuemask = XpmCloseness;
947 xpm_att[pos].closeness = 20000;
948 xpm_err = XpmReadFileToPixmap(display,window,filename,
949 &pix[pos],&shapemask,&xpm_att[pos]);
953 Error(ERR_EXIT, "cannot open XPM file '%s'", filename);
955 Error(ERR_EXIT, "invalid XPM file '%s'", filename);
957 Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename);
959 Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename);
965 printf("LOADING XPM FILE %s:", filename);
966 debug_print_timestamp(1, "");
969 #else /* !USE_XPM_LIBRARY */
971 pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
972 &pix[pos], &clipmask[pos]);
978 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
980 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
981 case PCX_FileInvalid:
982 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
984 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
985 case PCX_ColorFailed:
986 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
992 printf("SUMMARY LOADING PCX FILE %s:", filename);
993 debug_print_timestamp(1, "");
996 #endif /* !USE_XPM_LIBRARY */
999 Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
1001 /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always
1002 use pix_masked[], although they are the same when not using SDL */
1003 pix_masked[pos] = pix[pos];
1005 #endif /* !USE_SDL_LIBRARY */
1008 #ifndef USE_SDL_LIBRARY
1009 /* zugehörige Maske laden (wenn vorhanden) */
1010 if (pic->picture_with_mask)
1012 #ifdef USE_XPM_LIBRARY
1014 sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext);
1015 DrawInitText(basefilename, 150, FC_YELLOW);
1016 sprintf(filename, "%s/%s/%s",
1017 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
1020 debug_print_timestamp(1, NULL); /* initialize timestamp function */
1023 xbm_err = XReadBitmapFile(display,window,filename,
1024 &width,&height,&clipmask[pos],&hot_x,&hot_y);
1029 case BitmapOpenFailed:
1030 Error(ERR_EXIT, "cannot open XBM file '%s'", filename);
1031 case BitmapFileInvalid:
1032 Error(ERR_EXIT, "invalid XBM file '%s'", filename);
1033 case BitmapNoMemory:
1034 Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename);
1041 printf("LOADING XBM FILE %s:", filename);
1042 debug_print_timestamp(1, "");
1045 #endif /* USE_XPM_LIBRARY */
1048 Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
1050 #endif /* !USE_SDL_LIBRARY */
1055 CreateLevelEditorGadgets();
1056 CreateGameButtons();
1057 CreateTapeButtons();
1058 CreateToolButtons();
1059 CreateScreenGadgets();
1062 void InitElementProperties()
1066 static int ep_amoebalive[] =
1073 static int ep_amoebalive_num = sizeof(ep_amoebalive)/sizeof(int);
1075 static int ep_amoeboid[] =
1083 static int ep_amoeboid_num = sizeof(ep_amoeboid)/sizeof(int);
1085 static int ep_schluessel[] =
1096 static int ep_schluessel_num = sizeof(ep_schluessel)/sizeof(int);
1098 static int ep_pforte[] =
1117 EL_SWITCHGATE_CLOSED,
1132 static int ep_pforte_num = sizeof(ep_pforte)/sizeof(int);
1134 static int ep_solid[] =
1155 EL_MAGIC_WALL_EMPTY,
1158 EL_MAGIC_WALL_BD_OFF,
1159 EL_MAGIC_WALL_BD_EMPTY,
1160 EL_MAGIC_WALL_BD_FULL,
1161 EL_MAGIC_WALL_BD_DEAD,
1188 EL_BELT1_SWITCH_LEFT,
1189 EL_BELT1_SWITCH_MIDDLE,
1190 EL_BELT1_SWITCH_RIGHT,
1191 EL_BELT2_SWITCH_LEFT,
1192 EL_BELT2_SWITCH_MIDDLE,
1193 EL_BELT2_SWITCH_RIGHT,
1194 EL_BELT3_SWITCH_LEFT,
1195 EL_BELT3_SWITCH_MIDDLE,
1196 EL_BELT3_SWITCH_RIGHT,
1197 EL_BELT4_SWITCH_LEFT,
1198 EL_BELT4_SWITCH_MIDDLE,
1199 EL_BELT4_SWITCH_RIGHT,
1200 EL_SWITCHGATE_SWITCH_1,
1201 EL_SWITCHGATE_SWITCH_2,
1202 EL_LIGHT_SWITCH_OFF,
1204 EL_TIMEGATE_SWITCH_OFF,
1205 EL_TIMEGATE_SWITCH_ON,
1206 EL_SIGN_EXCLAMATION,
1207 EL_SIGN_RADIOACTIVITY,
1219 EL_EMC_STEEL_WALL_1,
1220 EL_EMC_STEEL_WALL_2,
1221 EL_EMC_STEEL_WALL_3,
1222 EL_EMC_STEEL_WALL_4,
1246 static int ep_solid_num = sizeof(ep_solid)/sizeof(int);
1248 static int ep_massive[] =
1274 EL_SWITCHGATE_CLOSED,
1289 EL_BELT1_SWITCH_LEFT,
1290 EL_BELT1_SWITCH_MIDDLE,
1291 EL_BELT1_SWITCH_RIGHT,
1292 EL_BELT2_SWITCH_LEFT,
1293 EL_BELT2_SWITCH_MIDDLE,
1294 EL_BELT2_SWITCH_RIGHT,
1295 EL_BELT3_SWITCH_LEFT,
1296 EL_BELT3_SWITCH_MIDDLE,
1297 EL_BELT3_SWITCH_RIGHT,
1298 EL_BELT4_SWITCH_LEFT,
1299 EL_BELT4_SWITCH_MIDDLE,
1300 EL_BELT4_SWITCH_RIGHT,
1301 EL_LIGHT_SWITCH_OFF,
1303 EL_SIGN_EXCLAMATION,
1304 EL_SIGN_RADIOACTIVITY,
1316 EL_EMC_STEEL_WALL_1,
1317 EL_EMC_STEEL_WALL_2,
1318 EL_EMC_STEEL_WALL_3,
1319 EL_EMC_STEEL_WALL_4,
1333 static int ep_massive_num = sizeof(ep_massive)/sizeof(int);
1335 static int ep_slippery[] =
1370 static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
1372 static int ep_enemy[] =
1385 static int ep_enemy_num = sizeof(ep_enemy)/sizeof(int);
1387 static int ep_mauer[] =
1437 EL_EMC_STEEL_WALL_1,
1438 EL_EMC_STEEL_WALL_2,
1439 EL_EMC_STEEL_WALL_3,
1440 EL_EMC_STEEL_WALL_4,
1450 static int ep_mauer_num = sizeof(ep_mauer)/sizeof(int);
1452 static int ep_can_fall[] =
1467 EL_MAGIC_WALL_BD_FULL,
1478 static int ep_can_fall_num = sizeof(ep_can_fall)/sizeof(int);
1480 static int ep_can_smash[] =
1511 static int ep_can_smash_num = sizeof(ep_can_smash)/sizeof(int);
1513 static int ep_can_change[] =
1524 static int ep_can_change_num = sizeof(ep_can_change)/sizeof(int);
1526 static int ep_can_move[] =
1546 static int ep_can_move_num = sizeof(ep_can_move)/sizeof(int);
1548 static int ep_could_move[] =
1571 static int ep_could_move_num = sizeof(ep_could_move)/sizeof(int);
1573 static int ep_dont_touch[] =
1580 static int ep_dont_touch_num = sizeof(ep_dont_touch)/sizeof(int);
1582 static int ep_dont_go_to[] =
1600 static int ep_dont_go_to_num = sizeof(ep_dont_go_to)/sizeof(int);
1602 static int ep_mampf2[] =
1627 static int ep_mampf2_num = sizeof(ep_mampf2)/sizeof(int);
1629 static int ep_bd_element[] =
1638 EL_MAGIC_WALL_BD_OFF,
1656 static int ep_bd_element_num = sizeof(ep_bd_element)/sizeof(int);
1658 static int ep_sb_element[] =
1663 EL_SOKOBAN_FELD_LEER,
1664 EL_SOKOBAN_FELD_VOLL,
1668 static int ep_sb_element_num = sizeof(ep_sb_element)/sizeof(int);
1670 static int ep_gem[] =
1680 static int ep_gem_num = sizeof(ep_gem)/sizeof(int);
1682 static int ep_inactive[] =
1719 EL_DYNAMITE_INACTIVE,
1731 EL_SOKOBAN_FELD_LEER,
1732 EL_SOKOBAN_FELD_VOLL,
1742 EL_MAGIC_WALL_BD_OFF,
1743 EL_MAGIC_WALL_BD_DEAD,
1779 EL_BELT1_SWITCH_LEFT,
1780 EL_BELT1_SWITCH_MIDDLE,
1781 EL_BELT1_SWITCH_RIGHT,
1782 EL_BELT2_SWITCH_LEFT,
1783 EL_BELT2_SWITCH_MIDDLE,
1784 EL_BELT2_SWITCH_RIGHT,
1785 EL_BELT3_SWITCH_LEFT,
1786 EL_BELT3_SWITCH_MIDDLE,
1787 EL_BELT3_SWITCH_RIGHT,
1788 EL_BELT4_SWITCH_LEFT,
1789 EL_BELT4_SWITCH_MIDDLE,
1790 EL_BELT4_SWITCH_RIGHT,
1791 EL_SIGN_EXCLAMATION,
1792 EL_SIGN_RADIOACTIVITY,
1804 EL_EMC_STEEL_WALL_1,
1805 EL_EMC_STEEL_WALL_2,
1806 EL_EMC_STEEL_WALL_3,
1807 EL_EMC_STEEL_WALL_4,
1817 static int ep_inactive_num = sizeof(ep_inactive)/sizeof(int);
1819 static int ep_explosive[] =
1823 EL_DYNAMITE_INACTIVE,
1824 EL_DYNABOMB_ACTIVE_1,
1825 EL_DYNABOMB_ACTIVE_2,
1826 EL_DYNABOMB_ACTIVE_3,
1827 EL_DYNABOMB_ACTIVE_4,
1844 static int ep_explosive_num = sizeof(ep_explosive)/sizeof(int);
1846 static int ep_mampf3[] =
1857 static int ep_mampf3_num = sizeof(ep_mampf3)/sizeof(int);
1859 static int ep_pushable[] =
1866 EL_SOKOBAN_FELD_VOLL,
1876 static int ep_pushable_num = sizeof(ep_pushable)/sizeof(int);
1878 static int ep_player[] =
1886 static int ep_player_num = sizeof(ep_player)/sizeof(int);
1888 static int ep_has_content[] =
1896 static int ep_has_content_num = sizeof(ep_has_content)/sizeof(int);
1898 static int ep_eatable[] =
1906 static int ep_eatable_num = sizeof(ep_eatable)/sizeof(int);
1908 static int ep_sp_element[] =
1950 /* additional elements that appeared in newer Supaplex levels */
1952 /* more than one murphy in a level results in an inactive clone */
1955 static int ep_sp_element_num = sizeof(ep_sp_element)/sizeof(int);
1957 static int ep_quick_gate[] =
1981 static int ep_quick_gate_num = sizeof(ep_quick_gate)/sizeof(int);
1983 static int ep_over_player[] =
2008 static int ep_over_player_num = sizeof(ep_over_player)/sizeof(int);
2010 static int ep_active_bomb[] =
2013 EL_DYNABOMB_ACTIVE_1,
2014 EL_DYNABOMB_ACTIVE_2,
2015 EL_DYNABOMB_ACTIVE_3,
2016 EL_DYNABOMB_ACTIVE_4
2018 static int ep_active_bomb_num = sizeof(ep_active_bomb)/sizeof(int);
2020 static int ep_belt[] =
2035 static int ep_belt_num = sizeof(ep_belt)/sizeof(int);
2037 static int ep_belt_switch[] =
2039 EL_BELT1_SWITCH_LEFT,
2040 EL_BELT1_SWITCH_MIDDLE,
2041 EL_BELT1_SWITCH_RIGHT,
2042 EL_BELT2_SWITCH_LEFT,
2043 EL_BELT2_SWITCH_MIDDLE,
2044 EL_BELT2_SWITCH_RIGHT,
2045 EL_BELT3_SWITCH_LEFT,
2046 EL_BELT3_SWITCH_MIDDLE,
2047 EL_BELT3_SWITCH_RIGHT,
2048 EL_BELT4_SWITCH_LEFT,
2049 EL_BELT4_SWITCH_MIDDLE,
2050 EL_BELT4_SWITCH_RIGHT,
2052 static int ep_belt_switch_num = sizeof(ep_belt_switch)/sizeof(int);
2054 static int ep_tube[] =
2068 static int ep_tube_num = sizeof(ep_tube)/sizeof(int);
2070 static long ep1_bit[] =
2104 static long ep2_bit[] =
2110 static int *ep1_array[] =
2144 static int *ep2_array[] =
2150 static int *ep1_num[] =
2177 &ep_has_content_num,
2181 &ep_over_player_num,
2184 static int *ep2_num[] =
2187 &ep_belt_switch_num,
2190 static int num_properties1 = sizeof(ep1_num)/sizeof(int *);
2191 static int num_properties2 = sizeof(ep2_num)/sizeof(int *);
2193 for(i=0; i<MAX_ELEMENTS; i++)
2195 Elementeigenschaften1[i] = 0;
2196 Elementeigenschaften2[i] = 0;
2199 for(i=0; i<num_properties1; i++)
2200 for(j=0; j<*(ep1_num[i]); j++)
2201 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2202 for(i=0; i<num_properties2; i++)
2203 for(j=0; j<*(ep2_num[i]); j++)
2204 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2206 for(i=EL_CHAR_START; i<EL_CHAR_END; i++)
2207 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2210 void CloseAllAndExit(int exit_value)
2214 #ifdef USE_SDL_LIBRARY
2216 FreeSounds(NUM_SOUNDS);
2218 if (sound_process_id)
2221 kill(sound_process_id, SIGTERM);
2222 FreeSounds(NUM_SOUNDS);
2226 for(i=0; i<NUM_BITMAPS; i++)
2230 #ifdef USE_XPM_LIBRARY
2231 if (i < NUM_PICTURES) /* XPM pictures */
2233 XFreeColors(display,DefaultColormap(display,screen),
2234 xpm_att[i].pixels,xpm_att[i].npixels,0);
2235 XpmFreeAttributes(&xpm_att[i]);
2239 #ifdef USE_SDL_LIBRARY
2240 SDL_FreeSurface(pix[i]);
2242 XFreePixmap(display,pix[i]);
2246 #ifdef USE_SDL_LIBRARY
2247 SDL_FreeSurface(pix_masked[i]);
2250 XFreePixmap(display,clipmask[i]);
2252 XFreeGC(display, clip_gc[i]);
2256 #ifdef USE_SDL_LIBRARY
2257 KeyboardAutoRepeatOn();
2260 XFreeGC(display, gc);
2264 KeyboardAutoRepeatOn();
2265 XCloseDisplay(display);
2269 #if defined(MSDOS) || defined(WIN32)