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 static int sound_process_id = 0;
46 static void InitLevelAndPlayerInfo(void);
47 static void InitNetworkServer(void);
48 static void InitDisplay(void);
49 static void InitSound(void);
50 static void InitSoundServer(void);
51 static void InitWindow(int, char **);
52 static void InitGfx(void);
53 static void LoadGfx(int, struct PictureFileInfo *);
54 static void InitGadgets(void);
55 static void InitElementProperties(void);
57 void OpenAll(int argc, char *argv[])
63 if (options.serveronly)
65 NetworkServer(options.server_port, options.serveronly);
75 InitRND(NEW_RANDOMIZE);
77 signal(SIGINT, CloseAllAndExit);
78 signal(SIGTERM, CloseAllAndExit);
81 InitWindow(argc, argv);
83 #ifndef USE_SDL_LIBRARY
84 XMapWindow(display, window);
89 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
91 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)
150 #ifdef USE_SDL_LIBRARY
151 /* initialize SDL audio */
153 if (SDL_Init(SDL_INIT_AUDIO) < 0)
155 Error(ERR_WARN, "SDL_Init() failed: %s\n", SDL_GetError());
156 sound_status = SOUND_OFF;
160 if (Mix_OpenAudio(22050, AUDIO_S16, 2, 256) < 0)
162 Error(ERR_WARN, "Mix_OpenAudio() failed: %s\n", SDL_GetError());
163 sound_status = SOUND_OFF;
167 Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
168 Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
170 sound_status = SOUND_AVAILABLE;
171 sound_loops_allowed = TRUE;
173 #else /* !USE_SDL_LIBRARY */
176 if (access(sound_device_name, W_OK) != 0)
178 Error(ERR_WARN, "cannot access sound device - no sounds");
179 sound_status = SOUND_OFF;
183 if ((sound_device = open(sound_device_name,O_WRONLY))<0)
185 Error(ERR_WARN, "cannot open sound device - no sounds");
186 sound_status = SOUND_OFF;
191 sound_status = SOUND_AVAILABLE;
194 sound_loops_allowed = TRUE;
197 setup.sound_loops_on = TRUE;
202 sound_loops_allowed = TRUE;
205 setup.sound_loops_on = TRUE;
209 #endif /* !USE_SDL_LIBRARY */
211 for(i=0; i<NUM_SOUNDS; i++)
214 sprintf(sound_name[i], "%d", i + 1);
217 #ifdef USE_SDL_LIBRARY
219 char *str = getStringCopy(sound_name[i]);
220 sprintf(str, "%d", i + 1);
224 Sound[i].name = sound_name[i];
226 if (!LoadSound(&Sound[i]))
228 sound_status = SOUND_OFF;
234 sound_status = SOUND_OFF;
239 void InitSoundServer()
241 if (sound_status == SOUND_OFF)
244 #ifdef USE_SDL_LIBRARY
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 */
283 #ifdef USE_SDL_LIBRARY
284 static boolean sdl_joystick_subsystem_initialized = FALSE;
289 if (global_joystick_status == JOYSTICK_OFF)
292 joystick_status = JOYSTICK_OFF;
294 #ifdef USE_SDL_LIBRARY
296 if (!sdl_joystick_subsystem_initialized)
298 sdl_joystick_subsystem_initialized = TRUE;
300 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
302 Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
307 for (i=0; i<MAX_PLAYERS; i++)
309 char *device_name = setup.input[i].joy.device_name;
310 int joystick_nr = getJoystickNrFromDeviceName(device_name);
312 if (joystick_nr >= SDL_NumJoysticks())
315 /* misuse joystick file descriptor variable to store joystick number */
316 stored_player[i].joystick_fd = joystick_nr;
318 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
319 if (Check_SDL_JoystickOpened(joystick_nr))
320 Close_SDL_Joystick(joystick_nr);
322 if (!setup.input[i].use_joystick)
325 if (!Open_SDL_Joystick(joystick_nr))
327 Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
331 joystick_status = JOYSTICK_AVAILABLE;
334 #else /* !USE_SDL_LIBRARY */
337 for (i=0; i<MAX_PLAYERS; i++)
339 char *device_name = setup.input[i].joy.device_name;
341 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
342 if (stored_player[i].joystick_fd != -1)
344 close(stored_player[i].joystick_fd);
345 stored_player[i].joystick_fd = -1;
348 if (!setup.input[i].use_joystick)
351 if (access(device_name, R_OK) != 0)
353 Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
357 if ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
359 Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
363 joystick_status = JOYSTICK_AVAILABLE;
368 /* try to access two joysticks; if that fails, try to access just one */
369 if (install_joystick(JOY_TYPE_2PADS) == 0 ||
370 install_joystick(JOY_TYPE_AUTODETECT) == 0)
371 joystick_status = JOYSTICK_AVAILABLE;
374 load_joystick_data(JOYSTICK_FILENAME);
377 for (i=0; i<MAX_PLAYERS; i++)
379 char *device_name = setup.input[i].joy.device_name;
380 int joystick_nr = getJoystickNrFromDeviceName(device_name);
382 if (joystick_nr >= num_joysticks)
385 /* misuse joystick file descriptor variable to store joystick number */
386 stored_player[i].joystick_fd = joystick_nr;
390 #endif /* !USE_SDL_LIBRARY */
395 #ifdef USE_SDL_LIBRARY
396 /* initialize SDL video */
397 if (SDL_Init(SDL_INIT_VIDEO) < 0)
398 Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
400 /* automatically cleanup SDL stuff after exit() */
403 #else /* !USE_SDL_LIBRARY */
406 XVisualInfo vinfo_template, *vinfo;
411 /* connect to X server */
412 if (!(display = XOpenDisplay(options.display_name)))
413 Error(ERR_EXIT, "cannot connect to X server %s",
414 XDisplayName(options.display_name));
416 screen = DefaultScreen(display);
417 visual = DefaultVisual(display, screen);
418 depth = DefaultDepth(display, screen);
419 cmap = DefaultColormap(display, screen);
422 /* look for good enough visual */
423 vinfo_template.screen = screen;
424 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
425 vinfo_template.depth = depth;
426 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
427 VisualDepthMask, &vinfo_template, &num_visuals)))
429 visual = vinfo->visual;
430 XFree((void *)vinfo);
433 /* got appropriate visual? */
436 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
439 else if ((depth ==8 && visual->class != PseudoColor) ||
440 (depth > 8 && visual->class != TrueColor &&
441 visual->class != DirectColor))
443 printf("Sorry, cannot get appropriate visual.\n");
447 #endif /* !USE_SDL_LIBRARY */
450 void InitWindow(int argc, char *argv[])
452 #ifdef USE_SDL_LIBRARY
453 /* open SDL video output device (window or fullscreen mode) */
454 if ((window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
457 Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
459 /* set window and icon title */
460 SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
462 /* set event filter to filter out certain mouse motion events */
463 SDL_SetEventFilter(EventFilter);
465 #else /* !USE_SDL_LIBRARY */
467 unsigned int border_width = 4;
469 unsigned long gc_valuemask;
471 XTextProperty windowName, iconName;
472 Pixmap icon_pixmap, iconmask_pixmap;
473 unsigned int icon_width, icon_height;
474 int icon_hot_x, icon_hot_y;
475 char icon_filename[256];
476 XSizeHints size_hints;
478 XClassHint class_hints;
479 char *window_name = WINDOW_TITLE_STRING;
480 char *icon_name = WINDOW_TITLE_STRING;
481 long window_event_mask;
482 Atom proto_atom = None, delete_atom = None;
484 int screen_width, screen_height;
485 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
486 unsigned long pen_fg = WhitePixel(display,screen);
487 unsigned long pen_bg = BlackPixel(display,screen);
488 const int width = WIN_XSIZE, height = WIN_YSIZE;
491 static struct IconFileInfo icon_pic =
498 screen_width = XDisplayWidth(display, screen);
499 screen_height = XDisplayHeight(display, screen);
501 win_xpos = (screen_width - width) / 2;
502 win_ypos = (screen_height - height) / 2;
504 window = XCreateSimpleWindow(display, RootWindow(display, screen),
505 win_xpos, win_ypos, width, height, border_width,
509 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
510 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
511 if ((proto_atom != None) && (delete_atom != None))
512 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
513 PropModePrepend, (unsigned char *) &delete_atom, 1);
515 sprintf(icon_filename, "%s/%s/%s",
516 options.ro_base_directory, GRAPHICS_DIRECTORY,
517 icon_pic.picture_filename);
518 XReadBitmapFile(display,window,icon_filename,
519 &icon_width,&icon_height,
520 &icon_pixmap,&icon_hot_x,&icon_hot_y);
522 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
524 sprintf(icon_filename, "%s/%s/%s",
525 options.ro_base_directory, GRAPHICS_DIRECTORY,
526 icon_pic.picturemask_filename);
527 XReadBitmapFile(display,window,icon_filename,
528 &icon_width,&icon_height,
529 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
530 if (!iconmask_pixmap)
531 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
533 size_hints.width = size_hints.min_width = size_hints.max_width = width;
534 size_hints.height = size_hints.min_height = size_hints.max_height = height;
535 size_hints.flags = PSize | PMinSize | PMaxSize;
537 if (win_xpos || win_ypos)
539 size_hints.x = win_xpos;
540 size_hints.y = win_ypos;
541 size_hints.flags |= PPosition;
544 if (!XStringListToTextProperty(&window_name, 1, &windowName))
545 Error(ERR_EXIT, "structure allocation for windowName failed");
547 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
548 Error(ERR_EXIT, "structure allocation for iconName failed");
550 wm_hints.initial_state = NormalState;
551 wm_hints.input = True;
552 wm_hints.icon_pixmap = icon_pixmap;
553 wm_hints.icon_mask = iconmask_pixmap;
554 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
556 class_hints.res_name = program_name;
557 class_hints.res_class = "Rocks'n'Diamonds";
559 XSetWMProperties(display, window, &windowName, &iconName,
560 argv, argc, &size_hints, &wm_hints,
563 XFree(windowName.value);
564 XFree(iconName.value);
566 /* Select event types wanted */
568 ExposureMask | StructureNotifyMask | FocusChangeMask |
569 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
570 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
572 XSelectInput(display, window, window_event_mask);
575 /* create GC for drawing with window depth and background color (black) */
576 gc_values.graphics_exposures = False;
577 gc_values.foreground = pen_bg;
578 gc_values.background = pen_bg;
579 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
580 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
581 #endif /* !USE_SDL_LIBRARY */
588 #ifdef USE_SDL_LIBRARY
589 SDL_Surface *sdl_image_tmp;
592 XGCValues clip_gc_values;
593 unsigned long clip_gc_valuemask;
597 static struct PictureFileInfo pic[NUM_PICTURES] =
611 static struct PictureFileInfo pic[NUM_PICTURES] =
613 { "RocksScreen", TRUE },
614 { "RocksDoor", TRUE },
615 { "RocksHeroes", TRUE },
616 { "RocksToons", TRUE },
619 { "RocksMore", TRUE },
620 { "RocksFont", FALSE },
621 { "RocksFont2", FALSE },
622 { "RocksFont3", FALSE }
628 static struct PictureFileInfo test_pic1 =
633 static struct PictureFileInfo test_pic2 =
646 tile_needs_clipping[] =
648 { GFX_SPIELER1_UP, 4 },
649 { GFX_SPIELER1_DOWN, 4 },
650 { GFX_SPIELER1_LEFT, 4 },
651 { GFX_SPIELER1_RIGHT, 4 },
652 { GFX_SPIELER1_PUSH_LEFT, 4 },
653 { GFX_SPIELER1_PUSH_RIGHT, 4 },
654 { GFX_SPIELER2_UP, 4 },
655 { GFX_SPIELER2_DOWN, 4 },
656 { GFX_SPIELER2_LEFT, 4 },
657 { GFX_SPIELER2_RIGHT, 4 },
658 { GFX_SPIELER2_PUSH_LEFT, 4 },
659 { GFX_SPIELER2_PUSH_RIGHT, 4 },
660 { GFX_SPIELER3_UP, 4 },
661 { GFX_SPIELER3_DOWN, 4 },
662 { GFX_SPIELER3_LEFT, 4 },
663 { GFX_SPIELER3_RIGHT, 4 },
664 { GFX_SPIELER3_PUSH_LEFT, 4 },
665 { GFX_SPIELER3_PUSH_RIGHT, 4 },
666 { GFX_SPIELER4_UP, 4 },
667 { GFX_SPIELER4_DOWN, 4 },
668 { GFX_SPIELER4_LEFT, 4 },
669 { GFX_SPIELER4_RIGHT, 4 },
670 { GFX_SPIELER4_PUSH_LEFT, 4 },
671 { GFX_SPIELER4_PUSH_RIGHT, 4 },
672 { GFX_SP_MURPHY, 1 },
673 { GFX_MURPHY_GO_LEFT, 3 },
674 { GFX_MURPHY_GO_RIGHT, 3 },
675 { GFX_MURPHY_SNAP_UP, 1 },
676 { GFX_MURPHY_SNAP_DOWN, 1 },
677 { GFX_MURPHY_SNAP_RIGHT, 1 },
678 { GFX_MURPHY_SNAP_LEFT, 1 },
679 { GFX_MURPHY_PUSH_RIGHT, 1 },
680 { GFX_MURPHY_PUSH_LEFT, 1 },
681 { GFX_GEBLUBBER, 4 },
684 { GFX_EXPLOSION, 8 },
685 { GFX_SOKOBAN_OBJEKT, 1 },
686 { GFX_FUNKELN_BLAU, 3 },
687 { GFX_FUNKELN_WEISS, 3 },
688 { GFX2_SHIELD_PASSIVE, 3 },
689 { GFX2_SHIELD_ACTIVE, 3 },
694 debug_print_timestamp(0, NULL); /* initialize timestamp function */
699 printf("Test: Loading RocksFont2.pcx ...\n");
700 LoadGfx(PIX_SMALLFONT,&test_pic1);
701 printf("Test: Done.\n");
702 printf("Test: Loading mouse.pcx ...\n");
703 LoadGfx(PIX_SMALLFONT,&test_pic2);
704 printf("Test: Done.\n");
708 LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
709 DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW);
710 DrawInitText(COPYRIGHT_STRING,50,FC_RED);
712 DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE);
715 DrawInitText("Loading graphics:",120,FC_GREEN);
717 for(i=0; i<NUM_PICTURES; i++)
718 if (i != PIX_SMALLFONT)
722 debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
725 #ifdef USE_SDL_LIBRARY
726 /* create some native image surfaces for double-buffer purposes */
728 /* create double-buffer surface for background image */
729 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
730 WIN_XSIZE, WIN_YSIZE,
731 WIN_SDL_DEPTH, 0, 0, 0, 0))
733 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
735 if ((pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
736 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
738 SDL_FreeSurface(sdl_image_tmp);
740 /* create double-buffer surface for door image */
741 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
742 3 * DXSIZE, DYSIZE + VYSIZE,
743 WIN_SDL_DEPTH, 0, 0, 0, 0))
745 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
747 if ((pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
748 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
750 SDL_FreeSurface(sdl_image_tmp);
752 /* create double-buffer surface for field image */
753 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
755 WIN_SDL_DEPTH, 0, 0, 0, 0))
757 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
759 if ((pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
760 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
762 SDL_FreeSurface(sdl_image_tmp);
764 /* initialize surface array to 'NULL' */
765 for(i=0; i<NUM_TILES; i++)
766 tile_masked[i] = NULL;
768 /* create only those masked surfaces we really need */
769 for(i=0; tile_needs_clipping[i].start>=0; i++)
771 for(j=0; j<tile_needs_clipping[i].count; j++)
773 int tile = tile_needs_clipping[i].start + j;
779 getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y);
780 src_bitmap = pix_masked[bitmap_nr];
782 /* create surface for masked tile graphic */
783 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, TILEX, TILEY,
784 WIN_SDL_DEPTH, 0, 0, 0, 0))
786 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
788 /* create native transparent surface for current image */
789 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
790 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
791 if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
792 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
794 SDL_FreeSurface(sdl_image_tmp);
796 BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0);
800 #else /* !USE_SDL_LIBRARY */
802 pix[PIX_DB_BACK] = XCreatePixmap(display, window,
804 XDefaultDepth(display,screen));
805 pix[PIX_DB_DOOR] = XCreatePixmap(display, window,
806 3*DXSIZE,DYSIZE+VYSIZE,
807 XDefaultDepth(display,screen));
808 pix[PIX_DB_FIELD] = XCreatePixmap(display, window,
810 XDefaultDepth(display,screen));
812 clip_gc_values.graphics_exposures = False;
813 clip_gc_valuemask = GCGraphicsExposures;
815 XCreateGC(display,clipmask[PIX_BACK],clip_gc_valuemask,&clip_gc_values);
817 clip_gc_values.graphics_exposures = False;
818 clip_gc_valuemask = GCGraphicsExposures;
820 XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
822 /* initialize pixmap array to Pixmap 'None' */
823 for(i=0; i<NUM_TILES; i++)
824 tile_clipmask[i] = None;
826 /* create only those clipping Pixmaps we really need */
827 for(i=0; tile_needs_clipping[i].start>=0; i++)
829 for(j=0; j<tile_needs_clipping[i].count; j++)
831 int tile = tile_needs_clipping[i].start + j;
837 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
838 src_pixmap = clipmask[pixmap_nr];
840 tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
842 XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
843 src_x,src_y, TILEX,TILEY, 0,0);
847 if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
848 Error(ERR_EXIT, "cannot create additional pixmaps");
850 for(i=0; i<NUM_BITMAPS; i++)
854 clip_gc_values.graphics_exposures = False;
855 clip_gc_values.clip_mask = clipmask[i];
856 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
857 clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
861 #endif /* !USE_SDL_LIBRARY */
863 drawto = backbuffer = pix[PIX_DB_BACK];
864 fieldbuffer = pix[PIX_DB_FIELD];
865 SetDrawtoField(DRAW_BACKBUFFER);
867 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
868 ClearRectangle(pix[PIX_DB_BACK], REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
869 ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
871 for(i=0; i<MAX_BUF_XSIZE; i++)
872 for(j=0; j<MAX_BUF_YSIZE; j++)
875 redraw_mask = REDRAW_ALL;
878 void LoadGfx(int pos, struct PictureFileInfo *pic)
880 char basefilename[256];
883 #ifdef USE_XPM_LIBRARY
884 int xpm_err, xbm_err;
885 unsigned int width,height;
888 char *picture_ext = ".xpm";
889 char *picturemask_ext = "Mask.xbm";
892 #ifdef USE_SDL_LIBRARY
893 SDL_Surface *sdl_image_tmp;
894 #else /* !USE_SDL_LIBRARY */
896 #endif /* !USE_SDL_LIBRARY */
897 char *picture_ext = ".pcx";
899 #endif /* !USE_XPM_LIBRARY */
902 if (pic->picture_filename)
904 sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext);
905 DrawInitText(basefilename, 150, FC_YELLOW);
906 sprintf(filename, "%s/%s/%s",
907 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
914 debug_print_timestamp(1, NULL); /* initialize timestamp function */
917 #ifdef USE_SDL_LIBRARY
918 /* load image to temporary surface */
919 if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
920 Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError());
922 /* create native non-transparent surface for current image */
923 if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
924 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
926 /* create native transparent surface for current image */
927 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
928 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
929 if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
930 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
932 /* free temporary surface */
933 SDL_FreeSurface(sdl_image_tmp);
935 #else /* !USE_SDL_LIBRARY */
937 #ifdef USE_XPM_LIBRARY
939 xpm_att[pos].valuemask = XpmCloseness;
940 xpm_att[pos].closeness = 20000;
941 xpm_err = XpmReadFileToPixmap(display,window,filename,
942 &pix[pos],&shapemask,&xpm_att[pos]);
946 Error(ERR_EXIT, "cannot open XPM file '%s'", filename);
948 Error(ERR_EXIT, "invalid XPM file '%s'", filename);
950 Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename);
952 Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename);
958 printf("LOADING XPM FILE %s:", filename);
959 debug_print_timestamp(1, "");
962 #else /* !USE_XPM_LIBRARY */
964 pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
965 &pix[pos], &clipmask[pos]);
971 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
973 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
974 case PCX_FileInvalid:
975 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
977 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
978 case PCX_ColorFailed:
979 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
985 printf("SUMMARY LOADING PCX FILE %s:", filename);
986 debug_print_timestamp(1, "");
989 #endif /* !USE_XPM_LIBRARY */
992 Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
994 /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always
995 use pix_masked[], although they are the same when not using SDL */
996 pix_masked[pos] = pix[pos];
998 #endif /* !USE_SDL_LIBRARY */
1001 #ifndef USE_SDL_LIBRARY
1002 /* zugehörige Maske laden (wenn vorhanden) */
1003 if (pic->picture_with_mask)
1005 #ifdef USE_XPM_LIBRARY
1007 sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext);
1008 DrawInitText(basefilename, 150, FC_YELLOW);
1009 sprintf(filename, "%s/%s/%s",
1010 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
1013 debug_print_timestamp(1, NULL); /* initialize timestamp function */
1016 xbm_err = XReadBitmapFile(display,window,filename,
1017 &width,&height,&clipmask[pos],&hot_x,&hot_y);
1022 case BitmapOpenFailed:
1023 Error(ERR_EXIT, "cannot open XBM file '%s'", filename);
1024 case BitmapFileInvalid:
1025 Error(ERR_EXIT, "invalid XBM file '%s'", filename);
1026 case BitmapNoMemory:
1027 Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename);
1034 printf("LOADING XBM FILE %s:", filename);
1035 debug_print_timestamp(1, "");
1038 #endif /* USE_XPM_LIBRARY */
1041 Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
1043 #endif /* !USE_SDL_LIBRARY */
1048 CreateLevelEditorGadgets();
1049 CreateGameButtons();
1050 CreateTapeButtons();
1051 CreateToolButtons();
1052 CreateScreenGadgets();
1055 void InitElementProperties()
1059 static int ep_amoebalive[] =
1066 static int ep_amoebalive_num = sizeof(ep_amoebalive)/sizeof(int);
1068 static int ep_amoeboid[] =
1076 static int ep_amoeboid_num = sizeof(ep_amoeboid)/sizeof(int);
1078 static int ep_schluessel[] =
1089 static int ep_schluessel_num = sizeof(ep_schluessel)/sizeof(int);
1091 static int ep_pforte[] =
1110 EL_SWITCHGATE_CLOSED,
1125 static int ep_pforte_num = sizeof(ep_pforte)/sizeof(int);
1127 static int ep_solid[] =
1148 EL_MAGIC_WALL_EMPTY,
1151 EL_MAGIC_WALL_BD_OFF,
1152 EL_MAGIC_WALL_BD_EMPTY,
1153 EL_MAGIC_WALL_BD_FULL,
1154 EL_MAGIC_WALL_BD_DEAD,
1181 EL_BELT1_SWITCH_LEFT,
1182 EL_BELT1_SWITCH_MIDDLE,
1183 EL_BELT1_SWITCH_RIGHT,
1184 EL_BELT2_SWITCH_LEFT,
1185 EL_BELT2_SWITCH_MIDDLE,
1186 EL_BELT2_SWITCH_RIGHT,
1187 EL_BELT3_SWITCH_LEFT,
1188 EL_BELT3_SWITCH_MIDDLE,
1189 EL_BELT3_SWITCH_RIGHT,
1190 EL_BELT4_SWITCH_LEFT,
1191 EL_BELT4_SWITCH_MIDDLE,
1192 EL_BELT4_SWITCH_RIGHT,
1193 EL_SWITCHGATE_SWITCH_1,
1194 EL_SWITCHGATE_SWITCH_2,
1195 EL_LIGHT_SWITCH_OFF,
1197 EL_TIMEGATE_SWITCH_OFF,
1198 EL_TIMEGATE_SWITCH_ON,
1199 EL_SIGN_EXCLAMATION,
1200 EL_SIGN_RADIOACTIVITY,
1212 EL_EMC_STEEL_WALL_1,
1213 EL_EMC_STEEL_WALL_2,
1214 EL_EMC_STEEL_WALL_3,
1215 EL_EMC_STEEL_WALL_4,
1239 static int ep_solid_num = sizeof(ep_solid)/sizeof(int);
1241 static int ep_massive[] =
1267 EL_SWITCHGATE_CLOSED,
1282 EL_BELT1_SWITCH_LEFT,
1283 EL_BELT1_SWITCH_MIDDLE,
1284 EL_BELT1_SWITCH_RIGHT,
1285 EL_BELT2_SWITCH_LEFT,
1286 EL_BELT2_SWITCH_MIDDLE,
1287 EL_BELT2_SWITCH_RIGHT,
1288 EL_BELT3_SWITCH_LEFT,
1289 EL_BELT3_SWITCH_MIDDLE,
1290 EL_BELT3_SWITCH_RIGHT,
1291 EL_BELT4_SWITCH_LEFT,
1292 EL_BELT4_SWITCH_MIDDLE,
1293 EL_BELT4_SWITCH_RIGHT,
1294 EL_LIGHT_SWITCH_OFF,
1296 EL_SIGN_EXCLAMATION,
1297 EL_SIGN_RADIOACTIVITY,
1309 EL_EMC_STEEL_WALL_1,
1310 EL_EMC_STEEL_WALL_2,
1311 EL_EMC_STEEL_WALL_3,
1312 EL_EMC_STEEL_WALL_4,
1326 static int ep_massive_num = sizeof(ep_massive)/sizeof(int);
1328 static int ep_slippery[] =
1363 static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
1365 static int ep_enemy[] =
1378 static int ep_enemy_num = sizeof(ep_enemy)/sizeof(int);
1380 static int ep_mauer[] =
1430 EL_EMC_STEEL_WALL_1,
1431 EL_EMC_STEEL_WALL_2,
1432 EL_EMC_STEEL_WALL_3,
1433 EL_EMC_STEEL_WALL_4,
1443 static int ep_mauer_num = sizeof(ep_mauer)/sizeof(int);
1445 static int ep_can_fall[] =
1460 EL_MAGIC_WALL_BD_FULL,
1471 static int ep_can_fall_num = sizeof(ep_can_fall)/sizeof(int);
1473 static int ep_can_smash[] =
1504 static int ep_can_smash_num = sizeof(ep_can_smash)/sizeof(int);
1506 static int ep_can_change[] =
1517 static int ep_can_change_num = sizeof(ep_can_change)/sizeof(int);
1519 static int ep_can_move[] =
1539 static int ep_can_move_num = sizeof(ep_can_move)/sizeof(int);
1541 static int ep_could_move[] =
1564 static int ep_could_move_num = sizeof(ep_could_move)/sizeof(int);
1566 static int ep_dont_touch[] =
1573 static int ep_dont_touch_num = sizeof(ep_dont_touch)/sizeof(int);
1575 static int ep_dont_go_to[] =
1593 static int ep_dont_go_to_num = sizeof(ep_dont_go_to)/sizeof(int);
1595 static int ep_mampf2[] =
1620 static int ep_mampf2_num = sizeof(ep_mampf2)/sizeof(int);
1622 static int ep_bd_element[] =
1631 EL_MAGIC_WALL_BD_OFF,
1649 static int ep_bd_element_num = sizeof(ep_bd_element)/sizeof(int);
1651 static int ep_sb_element[] =
1656 EL_SOKOBAN_FELD_LEER,
1657 EL_SOKOBAN_FELD_VOLL,
1661 static int ep_sb_element_num = sizeof(ep_sb_element)/sizeof(int);
1663 static int ep_gem[] =
1673 static int ep_gem_num = sizeof(ep_gem)/sizeof(int);
1675 static int ep_inactive[] =
1712 EL_DYNAMITE_INACTIVE,
1724 EL_SOKOBAN_FELD_LEER,
1725 EL_SOKOBAN_FELD_VOLL,
1735 EL_MAGIC_WALL_BD_OFF,
1736 EL_MAGIC_WALL_BD_DEAD,
1772 EL_BELT1_SWITCH_LEFT,
1773 EL_BELT1_SWITCH_MIDDLE,
1774 EL_BELT1_SWITCH_RIGHT,
1775 EL_BELT2_SWITCH_LEFT,
1776 EL_BELT2_SWITCH_MIDDLE,
1777 EL_BELT2_SWITCH_RIGHT,
1778 EL_BELT3_SWITCH_LEFT,
1779 EL_BELT3_SWITCH_MIDDLE,
1780 EL_BELT3_SWITCH_RIGHT,
1781 EL_BELT4_SWITCH_LEFT,
1782 EL_BELT4_SWITCH_MIDDLE,
1783 EL_BELT4_SWITCH_RIGHT,
1784 EL_SIGN_EXCLAMATION,
1785 EL_SIGN_RADIOACTIVITY,
1797 EL_EMC_STEEL_WALL_1,
1798 EL_EMC_STEEL_WALL_2,
1799 EL_EMC_STEEL_WALL_3,
1800 EL_EMC_STEEL_WALL_4,
1810 static int ep_inactive_num = sizeof(ep_inactive)/sizeof(int);
1812 static int ep_explosive[] =
1816 EL_DYNAMITE_INACTIVE,
1817 EL_DYNABOMB_ACTIVE_1,
1818 EL_DYNABOMB_ACTIVE_2,
1819 EL_DYNABOMB_ACTIVE_3,
1820 EL_DYNABOMB_ACTIVE_4,
1837 static int ep_explosive_num = sizeof(ep_explosive)/sizeof(int);
1839 static int ep_mampf3[] =
1850 static int ep_mampf3_num = sizeof(ep_mampf3)/sizeof(int);
1852 static int ep_pushable[] =
1859 EL_SOKOBAN_FELD_VOLL,
1869 static int ep_pushable_num = sizeof(ep_pushable)/sizeof(int);
1871 static int ep_player[] =
1879 static int ep_player_num = sizeof(ep_player)/sizeof(int);
1881 static int ep_has_content[] =
1889 static int ep_has_content_num = sizeof(ep_has_content)/sizeof(int);
1891 static int ep_eatable[] =
1899 static int ep_eatable_num = sizeof(ep_eatable)/sizeof(int);
1901 static int ep_sp_element[] =
1943 /* additional elements that appeared in newer Supaplex levels */
1945 /* more than one murphy in a level results in an inactive clone */
1948 static int ep_sp_element_num = sizeof(ep_sp_element)/sizeof(int);
1950 static int ep_quick_gate[] =
1974 static int ep_quick_gate_num = sizeof(ep_quick_gate)/sizeof(int);
1976 static int ep_over_player[] =
2001 static int ep_over_player_num = sizeof(ep_over_player)/sizeof(int);
2003 static int ep_active_bomb[] =
2006 EL_DYNABOMB_ACTIVE_1,
2007 EL_DYNABOMB_ACTIVE_2,
2008 EL_DYNABOMB_ACTIVE_3,
2009 EL_DYNABOMB_ACTIVE_4
2011 static int ep_active_bomb_num = sizeof(ep_active_bomb)/sizeof(int);
2013 static int ep_belt[] =
2028 static int ep_belt_num = sizeof(ep_belt)/sizeof(int);
2030 static int ep_belt_switch[] =
2032 EL_BELT1_SWITCH_LEFT,
2033 EL_BELT1_SWITCH_MIDDLE,
2034 EL_BELT1_SWITCH_RIGHT,
2035 EL_BELT2_SWITCH_LEFT,
2036 EL_BELT2_SWITCH_MIDDLE,
2037 EL_BELT2_SWITCH_RIGHT,
2038 EL_BELT3_SWITCH_LEFT,
2039 EL_BELT3_SWITCH_MIDDLE,
2040 EL_BELT3_SWITCH_RIGHT,
2041 EL_BELT4_SWITCH_LEFT,
2042 EL_BELT4_SWITCH_MIDDLE,
2043 EL_BELT4_SWITCH_RIGHT,
2045 static int ep_belt_switch_num = sizeof(ep_belt_switch)/sizeof(int);
2047 static int ep_tube[] =
2061 static int ep_tube_num = sizeof(ep_tube)/sizeof(int);
2063 static long ep1_bit[] =
2097 static long ep2_bit[] =
2103 static int *ep1_array[] =
2137 static int *ep2_array[] =
2143 static int *ep1_num[] =
2170 &ep_has_content_num,
2174 &ep_over_player_num,
2177 static int *ep2_num[] =
2180 &ep_belt_switch_num,
2183 static int num_properties1 = sizeof(ep1_num)/sizeof(int *);
2184 static int num_properties2 = sizeof(ep2_num)/sizeof(int *);
2186 for(i=0; i<MAX_ELEMENTS; i++)
2188 Elementeigenschaften1[i] = 0;
2189 Elementeigenschaften2[i] = 0;
2192 for(i=0; i<num_properties1; i++)
2193 for(j=0; j<*(ep1_num[i]); j++)
2194 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2195 for(i=0; i<num_properties2; i++)
2196 for(j=0; j<*(ep2_num[i]); j++)
2197 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2199 for(i=EL_CHAR_START; i<EL_CHAR_END; i++)
2200 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2203 void CloseAllAndExit(int exit_value)
2207 if (sound_process_id)
2210 kill(sound_process_id, SIGTERM);
2211 FreeSounds(NUM_SOUNDS);
2214 for(i=0; i<NUM_BITMAPS; i++)
2218 #ifdef USE_XPM_LIBRARY
2219 if (i < NUM_PICTURES) /* XPM pictures */
2221 XFreeColors(display,DefaultColormap(display,screen),
2222 xpm_att[i].pixels,xpm_att[i].npixels,0);
2223 XpmFreeAttributes(&xpm_att[i]);
2227 #ifdef USE_SDL_LIBRARY
2228 SDL_FreeSurface(pix[i]);
2230 XFreePixmap(display,pix[i]);
2234 #ifdef USE_SDL_LIBRARY
2235 SDL_FreeSurface(pix_masked[i]);
2238 XFreePixmap(display,clipmask[i]);
2240 XFreeGC(display, clip_gc[i]);
2244 #ifdef USE_SDL_LIBRARY
2245 KeyboardAutoRepeatOn();
2248 XFreeGC(display, gc);
2252 KeyboardAutoRepeatOn();
2253 XCloseDisplay(display);