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 ***********************************************************/
31 struct PictureFileInfo
33 char *picture_filename;
34 boolean picture_with_mask;
39 char *picture_filename;
40 char *picturemask_filename;
43 static int sound_process_id = 0;
45 static void InitLevelAndPlayerInfo(void);
46 static void InitNetworkServer(void);
47 static void InitDisplay(void);
48 static void InitSound(void);
49 static void InitSoundServer(void);
50 static void InitWindow(int, char **);
51 static void InitGfx(void);
52 static void LoadGfx(int, struct PictureFileInfo *);
53 static void InitGadgets(void);
54 static void InitElementProperties(void);
56 void OpenAll(int argc, char *argv[])
62 if (options.serveronly)
64 NetworkServer(options.server_port, options.serveronly);
74 InitRND(NEW_RANDOMIZE);
76 signal(SIGINT, CloseAllAndExit);
77 signal(SIGTERM, CloseAllAndExit);
80 InitWindow(argc, argv);
82 #ifndef USE_SDL_LIBRARY
83 XMapWindow(display, window);
88 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
90 InitLevelAndPlayerInfo();
92 InitGadgets(); /* needs to know number of level series */
99 void InitLevelAndPlayerInfo()
103 /* choose default local player */
104 local_player = &stored_player[0];
106 for (i=0; i<MAX_PLAYERS; i++)
108 stored_player[i].joystick_fd = -1; /* joystick device closed */
109 stored_player[i].connected = FALSE;
112 local_player->connected = TRUE;
114 LoadLevelInfo(); /* global level info */
115 LoadSetup(); /* global setup info */
116 LoadLevelSetup_LastSeries(); /* last played series info */
117 LoadLevelSetup_SeriesInfo(); /* last played level info */
120 void InitNetworkServer()
126 if (!options.network)
130 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
132 if (!ConnectToServer(options.server_host, options.server_port))
133 Error(ERR_EXIT, "cannot connect to network game server");
135 SendToServer_PlayerName(setup.player_name);
136 SendToServer_ProtocolVersion();
139 SendToServer_NrWanted(nr_wanted);
147 if (sound_status == SOUND_OFF)
151 if (access(sound_device_name, W_OK) != 0)
153 Error(ERR_WARN, "cannot access sound device - no sounds");
154 sound_status = SOUND_OFF;
158 if ((sound_device = open(sound_device_name,O_WRONLY))<0)
160 Error(ERR_WARN, "cannot open sound device - no sounds");
161 sound_status = SOUND_OFF;
166 sound_status = SOUND_AVAILABLE;
169 sound_loops_allowed = TRUE;
172 setup.sound_loops_on = TRUE;
177 sound_loops_allowed = TRUE;
180 setup.sound_loops_on = TRUE;
185 for(i=0; i<NUM_SOUNDS; i++)
188 sprintf(sound_name[i], "%d", i + 1);
191 Sound[i].name = sound_name[i];
192 if (!LoadSound(&Sound[i]))
194 sound_status = SOUND_OFF;
200 void InitSoundServer()
202 if (sound_status == SOUND_OFF)
207 if (pipe(sound_pipe)<0)
209 Error(ERR_WARN, "cannot create pipe - no sounds");
210 sound_status = SOUND_OFF;
214 if ((sound_process_id = fork()) < 0)
216 Error(ERR_WARN, "cannot create sound server process - no sounds");
217 sound_status = SOUND_OFF;
221 if (!sound_process_id) /* we are child */
228 else /* we are parent */
229 close(sound_pipe[0]); /* no reading from pipe needed */
242 if (global_joystick_status == JOYSTICK_OFF)
245 joystick_status = JOYSTICK_OFF;
248 for (i=0; i<MAX_PLAYERS; i++)
250 char *device_name = setup.input[i].joy.device_name;
252 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
253 if (stored_player[i].joystick_fd != -1)
255 close(stored_player[i].joystick_fd);
256 stored_player[i].joystick_fd = -1;
259 if (!setup.input[i].use_joystick)
262 if (access(device_name, R_OK) != 0)
264 Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
268 if ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
270 Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
274 joystick_status = JOYSTICK_AVAILABLE;
279 /* try to access two joysticks; if that fails, try to access just one */
280 if (install_joystick(JOY_TYPE_2PADS) == 0 ||
281 install_joystick(JOY_TYPE_AUTODETECT) == 0)
282 joystick_status = JOYSTICK_AVAILABLE;
285 load_joystick_data(JOYSTICK_FILENAME);
288 for (i=0; i<MAX_PLAYERS; i++)
290 char *device_name = setup.input[i].joy.device_name;
291 int joystick_nr = getJoystickNrFromDeviceName(device_name);
293 if (joystick_nr >= num_joysticks)
296 /* misuse joystick file descriptor variable to store joystick number */
297 stored_player[i].joystick_fd = joystick_nr;
304 #ifdef USE_SDL_LIBRARY
306 if (SDL_Init(SDL_INIT_VIDEO) < 0)
307 Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
309 /* automatically cleanup SDL stuff after exit() */
312 #else /* !USE_SDL_LIBRARY */
315 XVisualInfo vinfo_template, *vinfo;
320 /* connect to X server */
321 if (!(display = XOpenDisplay(options.display_name)))
322 Error(ERR_EXIT, "cannot connect to X server %s",
323 XDisplayName(options.display_name));
325 screen = DefaultScreen(display);
326 visual = DefaultVisual(display, screen);
327 depth = DefaultDepth(display, screen);
328 cmap = DefaultColormap(display, screen);
331 /* look for good enough visual */
332 vinfo_template.screen = screen;
333 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
334 vinfo_template.depth = depth;
335 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
336 VisualDepthMask, &vinfo_template, &num_visuals)))
338 visual = vinfo->visual;
339 XFree((void *)vinfo);
342 /* got appropriate visual? */
345 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
348 else if ((depth ==8 && visual->class != PseudoColor) ||
349 (depth > 8 && visual->class != TrueColor &&
350 visual->class != DirectColor))
352 printf("Sorry, cannot get appropriate visual.\n");
356 #endif /* !USE_SDL_LIBRARY */
359 void InitWindow(int argc, char *argv[])
361 #ifdef USE_SDL_LIBRARY
362 /* open SDL video output device (window or fullscreen mode) */
363 if ((sdl_window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
366 Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
368 /* set window and icon title */
369 SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
371 /* select event types: initially no mouse motion events */
372 SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
374 #else /* !USE_SDL_LIBRARY */
376 unsigned int border_width = 4;
378 unsigned long gc_valuemask;
380 XTextProperty windowName, iconName;
381 Pixmap icon_pixmap, iconmask_pixmap;
382 unsigned int icon_width, icon_height;
383 int icon_hot_x, icon_hot_y;
384 char icon_filename[256];
385 XSizeHints size_hints;
387 XClassHint class_hints;
388 char *window_name = WINDOW_TITLE_STRING;
389 char *icon_name = WINDOW_TITLE_STRING;
390 long window_event_mask;
391 Atom proto_atom = None, delete_atom = None;
393 int screen_width, screen_height;
394 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
395 unsigned long pen_fg = WhitePixel(display,screen);
396 unsigned long pen_bg = BlackPixel(display,screen);
397 const int width = WIN_XSIZE, height = WIN_YSIZE;
400 static struct IconFileInfo icon_pic =
407 screen_width = XDisplayWidth(display, screen);
408 screen_height = XDisplayHeight(display, screen);
410 win_xpos = (screen_width - width) / 2;
411 win_ypos = (screen_height - height) / 2;
413 window = XCreateSimpleWindow(display, RootWindow(display, screen),
414 win_xpos, win_ypos, width, height, border_width,
418 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
419 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
420 if ((proto_atom != None) && (delete_atom != None))
421 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
422 PropModePrepend, (unsigned char *) &delete_atom, 1);
424 sprintf(icon_filename, "%s/%s/%s",
425 options.ro_base_directory, GRAPHICS_DIRECTORY,
426 icon_pic.picture_filename);
427 XReadBitmapFile(display,window,icon_filename,
428 &icon_width,&icon_height,
429 &icon_pixmap,&icon_hot_x,&icon_hot_y);
431 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
433 sprintf(icon_filename, "%s/%s/%s",
434 options.ro_base_directory, GRAPHICS_DIRECTORY,
435 icon_pic.picturemask_filename);
436 XReadBitmapFile(display,window,icon_filename,
437 &icon_width,&icon_height,
438 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
439 if (!iconmask_pixmap)
440 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
442 size_hints.width = size_hints.min_width = size_hints.max_width = width;
443 size_hints.height = size_hints.min_height = size_hints.max_height = height;
444 size_hints.flags = PSize | PMinSize | PMaxSize;
446 if (win_xpos || win_ypos)
448 size_hints.x = win_xpos;
449 size_hints.y = win_ypos;
450 size_hints.flags |= PPosition;
453 if (!XStringListToTextProperty(&window_name, 1, &windowName))
454 Error(ERR_EXIT, "structure allocation for windowName failed");
456 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
457 Error(ERR_EXIT, "structure allocation for iconName failed");
459 wm_hints.initial_state = NormalState;
460 wm_hints.input = True;
461 wm_hints.icon_pixmap = icon_pixmap;
462 wm_hints.icon_mask = iconmask_pixmap;
463 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
465 class_hints.res_name = program_name;
466 class_hints.res_class = "Rocks'n'Diamonds";
468 XSetWMProperties(display, window, &windowName, &iconName,
469 argv, argc, &size_hints, &wm_hints,
472 XFree(windowName.value);
473 XFree(iconName.value);
475 /* Select event types wanted */
477 ExposureMask | StructureNotifyMask | FocusChangeMask |
478 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
479 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
481 XSelectInput(display, window, window_event_mask);
484 /* create GC for drawing with window depth */
485 gc_values.graphics_exposures = False;
486 gc_values.foreground = pen_bg;
487 gc_values.background = pen_bg;
488 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
489 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
490 #endif /* !USE_SDL_LIBRARY */
497 #ifdef USE_SDL_LIBRARY
498 SDL_Surface *sdl_image_tmp;
501 XGCValues clip_gc_values;
502 unsigned long clip_gc_valuemask;
506 static struct PictureFileInfo pic[NUM_PICTURES] =
520 static struct PictureFileInfo pic[NUM_PICTURES] =
522 { "RocksScreen", TRUE },
523 { "RocksDoor", TRUE },
524 { "RocksHeroes", TRUE },
525 { "RocksToons", TRUE },
528 { "RocksMore", TRUE },
529 { "RocksFont", FALSE },
530 { "RocksFont2", FALSE },
531 { "RocksFont3", FALSE }
537 static struct PictureFileInfo test_pic1 =
542 static struct PictureFileInfo test_pic2 =
555 tile_needs_clipping[] =
557 { GFX_SPIELER1_UP, 4 },
558 { GFX_SPIELER1_DOWN, 4 },
559 { GFX_SPIELER1_LEFT, 4 },
560 { GFX_SPIELER1_RIGHT, 4 },
561 { GFX_SPIELER1_PUSH_LEFT, 4 },
562 { GFX_SPIELER1_PUSH_RIGHT, 4 },
563 { GFX_SPIELER2_UP, 4 },
564 { GFX_SPIELER2_DOWN, 4 },
565 { GFX_SPIELER2_LEFT, 4 },
566 { GFX_SPIELER2_RIGHT, 4 },
567 { GFX_SPIELER2_PUSH_LEFT, 4 },
568 { GFX_SPIELER2_PUSH_RIGHT, 4 },
569 { GFX_SPIELER3_UP, 4 },
570 { GFX_SPIELER3_DOWN, 4 },
571 { GFX_SPIELER3_LEFT, 4 },
572 { GFX_SPIELER3_RIGHT, 4 },
573 { GFX_SPIELER3_PUSH_LEFT, 4 },
574 { GFX_SPIELER3_PUSH_RIGHT, 4 },
575 { GFX_SPIELER4_UP, 4 },
576 { GFX_SPIELER4_DOWN, 4 },
577 { GFX_SPIELER4_LEFT, 4 },
578 { GFX_SPIELER4_RIGHT, 4 },
579 { GFX_SPIELER4_PUSH_LEFT, 4 },
580 { GFX_SPIELER4_PUSH_RIGHT, 4 },
581 { GFX_SP_MURPHY, 1 },
582 { GFX_MURPHY_GO_LEFT, 3 },
583 { GFX_MURPHY_GO_RIGHT, 3 },
584 { GFX_MURPHY_SNAP_UP, 1 },
585 { GFX_MURPHY_SNAP_DOWN, 1 },
586 { GFX_MURPHY_SNAP_RIGHT, 1 },
587 { GFX_MURPHY_SNAP_LEFT, 1 },
588 { GFX_MURPHY_PUSH_RIGHT, 1 },
589 { GFX_MURPHY_PUSH_LEFT, 1 },
590 { GFX_GEBLUBBER, 4 },
593 { GFX_EXPLOSION, 8 },
594 { GFX_SOKOBAN_OBJEKT, 1 },
595 { GFX_FUNKELN_BLAU, 3 },
596 { GFX_FUNKELN_WEISS, 3 },
597 { GFX2_SHIELD_PASSIVE, 3 },
598 { GFX2_SHIELD_ACTIVE, 3 },
603 debug_print_timestamp(0, NULL); /* initialize timestamp function */
608 printf("Test: Loading RocksFont2.pcx ...\n");
609 LoadGfx(PIX_SMALLFONT,&test_pic1);
610 printf("Test: Done.\n");
611 printf("Test: Loading mouse.pcx ...\n");
612 LoadGfx(PIX_SMALLFONT,&test_pic2);
613 printf("Test: Done.\n");
617 LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
618 DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW);
619 DrawInitText(COPYRIGHT_STRING,50,FC_RED);
621 DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE);
624 DrawInitText("Loading graphics:",120,FC_GREEN);
626 for(i=0; i<NUM_PICTURES; i++)
627 if (i != PIX_SMALLFONT)
631 debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
634 #ifdef USE_SDL_LIBRARY
635 /* create some native image surfaces for double-buffer purposes */
637 /* create double-buffer surface for background image */
638 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
639 WIN_XSIZE, WIN_YSIZE,
640 WIN_SDL_DEPTH, 0, 0, 0, 0))
642 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
644 if ((sdl_pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
645 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
647 SDL_FreeSurface(sdl_image_tmp);
649 /* create double-buffer surface for door image */
650 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
651 3 * DXSIZE, DYSIZE + VYSIZE,
652 WIN_SDL_DEPTH, 0, 0, 0, 0))
654 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
656 if ((sdl_pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
657 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
659 SDL_FreeSurface(sdl_image_tmp);
661 /* create double-buffer surface for field image */
662 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
664 WIN_SDL_DEPTH, 0, 0, 0, 0))
666 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
668 if ((sdl_pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
669 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
671 SDL_FreeSurface(sdl_image_tmp);
673 /* initialize surface array to 'NULL' */
674 for(i=0; i<NUM_TILES; i++)
675 sdl_tile_masked[i] = NULL;
677 /* create only those masked surfaces we really need */
678 for(i=0; tile_needs_clipping[i].start>=0; i++)
680 for(j=0; j<tile_needs_clipping[i].count; j++)
682 int tile = tile_needs_clipping[i].start + j;
689 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
690 src_pixmap = clipmask[pixmap_nr];
692 tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
694 XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
695 src_x,src_y, TILEX,TILEY, 0,0);
700 sdl_drawto = sdl_backbuffer = sdl_pix[PIX_DB_BACK];
701 sdl_fieldbuffer = sdl_pix[PIX_DB_FIELD];
702 SetDrawtoField(DRAW_BACKBUFFER);
704 SDLCopyArea(sdl_pix[PIX_BACK], sdl_backbuffer,
705 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
706 SDLFillRectangle(sdl_pix[PIX_DB_BACK],
707 REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, 0x000000);
708 SDLFillRectangle(sdl_pix[PIX_DB_DOOR],
709 0,0, 3*DXSIZE,DYSIZE+VYSIZE, 0x000000);
711 #else /* !USE_SDL_LIBRARY */
713 pix[PIX_DB_BACK] = XCreatePixmap(display, window,
715 XDefaultDepth(display,screen));
716 pix[PIX_DB_DOOR] = XCreatePixmap(display, window,
717 3*DXSIZE,DYSIZE+VYSIZE,
718 XDefaultDepth(display,screen));
719 pix[PIX_DB_FIELD] = XCreatePixmap(display, window,
721 XDefaultDepth(display,screen));
723 clip_gc_values.graphics_exposures = False;
724 clip_gc_valuemask = GCGraphicsExposures;
726 XCreateGC(display,clipmask[PIX_BACK],clip_gc_valuemask,&clip_gc_values);
728 clip_gc_values.graphics_exposures = False;
729 clip_gc_valuemask = GCGraphicsExposures;
731 XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
733 /* initialize pixmap array to Pixmap 'None' */
734 for(i=0; i<NUM_TILES; i++)
735 tile_clipmask[i] = None;
737 /* create only those clipping Pixmaps we really need */
738 for(i=0; tile_needs_clipping[i].start>=0; i++)
740 for(j=0; j<tile_needs_clipping[i].count; j++)
742 int tile = tile_needs_clipping[i].start + j;
748 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
749 src_pixmap = clipmask[pixmap_nr];
751 tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
753 XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
754 src_x,src_y, TILEX,TILEY, 0,0);
758 if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
759 Error(ERR_EXIT, "cannot create additional pixmaps");
761 for(i=0; i<NUM_PIXMAPS; i++)
765 clip_gc_values.graphics_exposures = False;
766 clip_gc_values.clip_mask = clipmask[i];
767 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
768 clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
772 drawto = backbuffer = pix[PIX_DB_BACK];
773 fieldbuffer = pix[PIX_DB_FIELD];
774 SetDrawtoField(DRAW_BACKBUFFER);
776 XCopyArea(display, pix[PIX_BACK], backbuffer, gc,
777 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
778 XFillRectangle(display, pix[PIX_DB_BACK], gc,
779 REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
780 XFillRectangle(display, pix[PIX_DB_DOOR], gc,
781 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
782 #endif /* !USE_SDL_LIBRARY */
784 for(i=0; i<MAX_BUF_XSIZE; i++)
785 for(j=0; j<MAX_BUF_YSIZE; j++)
788 redraw_mask = REDRAW_ALL;
791 void LoadGfx(int pos, struct PictureFileInfo *pic)
793 char basefilename[256];
796 #ifdef USE_XPM_LIBRARY
797 int xpm_err, xbm_err;
798 unsigned int width,height;
801 char *picture_ext = ".xpm";
802 char *picturemask_ext = "Mask.xbm";
805 #ifdef USE_SDL_LIBRARY
806 SDL_Surface *sdl_image_tmp;
807 #else /* !USE_SDL_LIBRARY */
809 #endif /* !USE_SDL_LIBRARY */
810 char *picture_ext = ".pcx";
812 #endif /* !USE_XPM_LIBRARY */
815 if (pic->picture_filename)
817 sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext);
818 DrawInitText(basefilename, 150, FC_YELLOW);
819 sprintf(filename, "%s/%s/%s",
820 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
827 debug_print_timestamp(1, NULL); /* initialize timestamp function */
830 #ifdef USE_SDL_LIBRARY
831 /* load image to temporary surface */
832 if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
833 Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError());
835 /* create native non-transparent surface for current image */
836 if ((sdl_pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
837 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
839 /* create native transparent surface for current image */
840 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
841 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
842 if ((sdl_pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
843 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
845 /* free temporary surface */
846 SDL_FreeSurface(sdl_image_tmp);
848 #else /* !USE_SDL_LIBRARY */
850 #ifdef USE_XPM_LIBRARY
852 xpm_att[pos].valuemask = XpmCloseness;
853 xpm_att[pos].closeness = 20000;
854 xpm_err = XpmReadFileToPixmap(display,window,filename,
855 &pix[pos],&shapemask,&xpm_att[pos]);
859 Error(ERR_EXIT, "cannot open XPM file '%s'", filename);
861 Error(ERR_EXIT, "invalid XPM file '%s'", filename);
863 Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename);
865 Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename);
871 printf("LOADING XPM FILE %s:", filename);
872 debug_print_timestamp(1, "");
875 #else /* !USE_XPM_LIBRARY */
877 pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
878 &pix[pos], &clipmask[pos]);
884 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
886 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
887 case PCX_FileInvalid:
888 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
890 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
891 case PCX_ColorFailed:
892 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
898 printf("SUMMARY LOADING PCX FILE %s:", filename);
899 debug_print_timestamp(1, "");
902 #endif /* !USE_XPM_LIBRARY */
905 Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
906 #endif /* !USE_SDL_LIBRARY */
909 #ifndef USE_SDL_LIBRARY
910 /* zugehörige Maske laden (wenn vorhanden) */
911 if (pic->picture_with_mask)
913 #ifdef USE_XPM_LIBRARY
915 sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext);
916 DrawInitText(basefilename, 150, FC_YELLOW);
917 sprintf(filename, "%s/%s/%s",
918 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
921 debug_print_timestamp(1, NULL); /* initialize timestamp function */
924 xbm_err = XReadBitmapFile(display,window,filename,
925 &width,&height,&clipmask[pos],&hot_x,&hot_y);
930 case BitmapOpenFailed:
931 Error(ERR_EXIT, "cannot open XBM file '%s'", filename);
932 case BitmapFileInvalid:
933 Error(ERR_EXIT, "invalid XBM file '%s'", filename);
935 Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename);
942 printf("LOADING XBM FILE %s:", filename);
943 debug_print_timestamp(1, "");
946 #endif /* USE_XPM_LIBRARY */
949 Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
951 #endif /* !USE_SDL_LIBRARY */
956 CreateLevelEditorGadgets();
960 CreateScreenGadgets();
963 void InitElementProperties()
967 static int ep_amoebalive[] =
974 static int ep_amoebalive_num = sizeof(ep_amoebalive)/sizeof(int);
976 static int ep_amoeboid[] =
984 static int ep_amoeboid_num = sizeof(ep_amoeboid)/sizeof(int);
986 static int ep_schluessel[] =
997 static int ep_schluessel_num = sizeof(ep_schluessel)/sizeof(int);
999 static int ep_pforte[] =
1018 EL_SWITCHGATE_CLOSED,
1033 static int ep_pforte_num = sizeof(ep_pforte)/sizeof(int);
1035 static int ep_solid[] =
1056 EL_MAGIC_WALL_EMPTY,
1059 EL_MAGIC_WALL_BD_OFF,
1060 EL_MAGIC_WALL_BD_EMPTY,
1061 EL_MAGIC_WALL_BD_FULL,
1062 EL_MAGIC_WALL_BD_DEAD,
1089 EL_BELT1_SWITCH_LEFT,
1090 EL_BELT1_SWITCH_MIDDLE,
1091 EL_BELT1_SWITCH_RIGHT,
1092 EL_BELT2_SWITCH_LEFT,
1093 EL_BELT2_SWITCH_MIDDLE,
1094 EL_BELT2_SWITCH_RIGHT,
1095 EL_BELT3_SWITCH_LEFT,
1096 EL_BELT3_SWITCH_MIDDLE,
1097 EL_BELT3_SWITCH_RIGHT,
1098 EL_BELT4_SWITCH_LEFT,
1099 EL_BELT4_SWITCH_MIDDLE,
1100 EL_BELT4_SWITCH_RIGHT,
1101 EL_SWITCHGATE_SWITCH_1,
1102 EL_SWITCHGATE_SWITCH_2,
1103 EL_LIGHT_SWITCH_OFF,
1105 EL_TIMEGATE_SWITCH_OFF,
1106 EL_TIMEGATE_SWITCH_ON,
1107 EL_SIGN_EXCLAMATION,
1108 EL_SIGN_RADIOACTIVITY,
1120 EL_EMC_STEEL_WALL_1,
1121 EL_EMC_STEEL_WALL_2,
1122 EL_EMC_STEEL_WALL_3,
1123 EL_EMC_STEEL_WALL_4,
1147 static int ep_solid_num = sizeof(ep_solid)/sizeof(int);
1149 static int ep_massive[] =
1175 EL_SWITCHGATE_CLOSED,
1190 EL_BELT1_SWITCH_LEFT,
1191 EL_BELT1_SWITCH_MIDDLE,
1192 EL_BELT1_SWITCH_RIGHT,
1193 EL_BELT2_SWITCH_LEFT,
1194 EL_BELT2_SWITCH_MIDDLE,
1195 EL_BELT2_SWITCH_RIGHT,
1196 EL_BELT3_SWITCH_LEFT,
1197 EL_BELT3_SWITCH_MIDDLE,
1198 EL_BELT3_SWITCH_RIGHT,
1199 EL_BELT4_SWITCH_LEFT,
1200 EL_BELT4_SWITCH_MIDDLE,
1201 EL_BELT4_SWITCH_RIGHT,
1202 EL_LIGHT_SWITCH_OFF,
1204 EL_SIGN_EXCLAMATION,
1205 EL_SIGN_RADIOACTIVITY,
1217 EL_EMC_STEEL_WALL_1,
1218 EL_EMC_STEEL_WALL_2,
1219 EL_EMC_STEEL_WALL_3,
1220 EL_EMC_STEEL_WALL_4,
1234 static int ep_massive_num = sizeof(ep_massive)/sizeof(int);
1236 static int ep_slippery[] =
1271 static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
1273 static int ep_enemy[] =
1286 static int ep_enemy_num = sizeof(ep_enemy)/sizeof(int);
1288 static int ep_mauer[] =
1338 EL_EMC_STEEL_WALL_1,
1339 EL_EMC_STEEL_WALL_2,
1340 EL_EMC_STEEL_WALL_3,
1341 EL_EMC_STEEL_WALL_4,
1351 static int ep_mauer_num = sizeof(ep_mauer)/sizeof(int);
1353 static int ep_can_fall[] =
1368 EL_MAGIC_WALL_BD_FULL,
1379 static int ep_can_fall_num = sizeof(ep_can_fall)/sizeof(int);
1381 static int ep_can_smash[] =
1412 static int ep_can_smash_num = sizeof(ep_can_smash)/sizeof(int);
1414 static int ep_can_change[] =
1425 static int ep_can_change_num = sizeof(ep_can_change)/sizeof(int);
1427 static int ep_can_move[] =
1447 static int ep_can_move_num = sizeof(ep_can_move)/sizeof(int);
1449 static int ep_could_move[] =
1472 static int ep_could_move_num = sizeof(ep_could_move)/sizeof(int);
1474 static int ep_dont_touch[] =
1481 static int ep_dont_touch_num = sizeof(ep_dont_touch)/sizeof(int);
1483 static int ep_dont_go_to[] =
1501 static int ep_dont_go_to_num = sizeof(ep_dont_go_to)/sizeof(int);
1503 static int ep_mampf2[] =
1528 static int ep_mampf2_num = sizeof(ep_mampf2)/sizeof(int);
1530 static int ep_bd_element[] =
1539 EL_MAGIC_WALL_BD_OFF,
1557 static int ep_bd_element_num = sizeof(ep_bd_element)/sizeof(int);
1559 static int ep_sb_element[] =
1564 EL_SOKOBAN_FELD_LEER,
1565 EL_SOKOBAN_FELD_VOLL,
1569 static int ep_sb_element_num = sizeof(ep_sb_element)/sizeof(int);
1571 static int ep_gem[] =
1581 static int ep_gem_num = sizeof(ep_gem)/sizeof(int);
1583 static int ep_inactive[] =
1620 EL_DYNAMITE_INACTIVE,
1632 EL_SOKOBAN_FELD_LEER,
1633 EL_SOKOBAN_FELD_VOLL,
1643 EL_MAGIC_WALL_BD_OFF,
1644 EL_MAGIC_WALL_BD_DEAD,
1680 EL_BELT1_SWITCH_LEFT,
1681 EL_BELT1_SWITCH_MIDDLE,
1682 EL_BELT1_SWITCH_RIGHT,
1683 EL_BELT2_SWITCH_LEFT,
1684 EL_BELT2_SWITCH_MIDDLE,
1685 EL_BELT2_SWITCH_RIGHT,
1686 EL_BELT3_SWITCH_LEFT,
1687 EL_BELT3_SWITCH_MIDDLE,
1688 EL_BELT3_SWITCH_RIGHT,
1689 EL_BELT4_SWITCH_LEFT,
1690 EL_BELT4_SWITCH_MIDDLE,
1691 EL_BELT4_SWITCH_RIGHT,
1692 EL_SIGN_EXCLAMATION,
1693 EL_SIGN_RADIOACTIVITY,
1705 EL_EMC_STEEL_WALL_1,
1706 EL_EMC_STEEL_WALL_2,
1707 EL_EMC_STEEL_WALL_3,
1708 EL_EMC_STEEL_WALL_4,
1718 static int ep_inactive_num = sizeof(ep_inactive)/sizeof(int);
1720 static int ep_explosive[] =
1724 EL_DYNAMITE_INACTIVE,
1725 EL_DYNABOMB_ACTIVE_1,
1726 EL_DYNABOMB_ACTIVE_2,
1727 EL_DYNABOMB_ACTIVE_3,
1728 EL_DYNABOMB_ACTIVE_4,
1745 static int ep_explosive_num = sizeof(ep_explosive)/sizeof(int);
1747 static int ep_mampf3[] =
1758 static int ep_mampf3_num = sizeof(ep_mampf3)/sizeof(int);
1760 static int ep_pushable[] =
1767 EL_SOKOBAN_FELD_VOLL,
1777 static int ep_pushable_num = sizeof(ep_pushable)/sizeof(int);
1779 static int ep_player[] =
1787 static int ep_player_num = sizeof(ep_player)/sizeof(int);
1789 static int ep_has_content[] =
1797 static int ep_has_content_num = sizeof(ep_has_content)/sizeof(int);
1799 static int ep_eatable[] =
1807 static int ep_eatable_num = sizeof(ep_eatable)/sizeof(int);
1809 static int ep_sp_element[] =
1851 /* additional elements that appeared in newer Supaplex levels */
1853 /* more than one murphy in a level results in an inactive clone */
1856 static int ep_sp_element_num = sizeof(ep_sp_element)/sizeof(int);
1858 static int ep_quick_gate[] =
1882 static int ep_quick_gate_num = sizeof(ep_quick_gate)/sizeof(int);
1884 static int ep_over_player[] =
1909 static int ep_over_player_num = sizeof(ep_over_player)/sizeof(int);
1911 static int ep_active_bomb[] =
1914 EL_DYNABOMB_ACTIVE_1,
1915 EL_DYNABOMB_ACTIVE_2,
1916 EL_DYNABOMB_ACTIVE_3,
1917 EL_DYNABOMB_ACTIVE_4
1919 static int ep_active_bomb_num = sizeof(ep_active_bomb)/sizeof(int);
1921 static int ep_belt[] =
1936 static int ep_belt_num = sizeof(ep_belt)/sizeof(int);
1938 static int ep_belt_switch[] =
1940 EL_BELT1_SWITCH_LEFT,
1941 EL_BELT1_SWITCH_MIDDLE,
1942 EL_BELT1_SWITCH_RIGHT,
1943 EL_BELT2_SWITCH_LEFT,
1944 EL_BELT2_SWITCH_MIDDLE,
1945 EL_BELT2_SWITCH_RIGHT,
1946 EL_BELT3_SWITCH_LEFT,
1947 EL_BELT3_SWITCH_MIDDLE,
1948 EL_BELT3_SWITCH_RIGHT,
1949 EL_BELT4_SWITCH_LEFT,
1950 EL_BELT4_SWITCH_MIDDLE,
1951 EL_BELT4_SWITCH_RIGHT,
1953 static int ep_belt_switch_num = sizeof(ep_belt_switch)/sizeof(int);
1955 static int ep_tube[] =
1969 static int ep_tube_num = sizeof(ep_tube)/sizeof(int);
1971 static long ep1_bit[] =
2005 static long ep2_bit[] =
2011 static int *ep1_array[] =
2045 static int *ep2_array[] =
2051 static int *ep1_num[] =
2078 &ep_has_content_num,
2082 &ep_over_player_num,
2085 static int *ep2_num[] =
2088 &ep_belt_switch_num,
2091 static int num_properties1 = sizeof(ep1_num)/sizeof(int *);
2092 static int num_properties2 = sizeof(ep2_num)/sizeof(int *);
2094 for(i=0; i<MAX_ELEMENTS; i++)
2096 Elementeigenschaften1[i] = 0;
2097 Elementeigenschaften2[i] = 0;
2100 for(i=0; i<num_properties1; i++)
2101 for(j=0; j<*(ep1_num[i]); j++)
2102 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2103 for(i=0; i<num_properties2; i++)
2104 for(j=0; j<*(ep2_num[i]); j++)
2105 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2107 for(i=EL_CHAR_START; i<EL_CHAR_END; i++)
2108 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2111 void CloseAllAndExit(int exit_value)
2115 if (sound_process_id)
2118 kill(sound_process_id, SIGTERM);
2119 FreeSounds(NUM_SOUNDS);
2122 for(i=0; i<NUM_PIXMAPS; i++)
2126 #ifdef USE_XPM_LIBRARY
2127 if (i < NUM_PICTURES) /* XPM pictures */
2129 XFreeColors(display,DefaultColormap(display,screen),
2130 xpm_att[i].pixels,xpm_att[i].npixels,0);
2131 XpmFreeAttributes(&xpm_att[i]);
2134 XFreePixmap(display,pix[i]);
2137 XFreePixmap(display,clipmask[i]);
2139 XFreeGC(display, clip_gc[i]);
2143 XFreeGC(display, gc);
2147 XAutoRepeatOn(display);
2148 XCloseDisplay(display);