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 InitLevelAndPlayerInfo(void);
49 static void InitNetworkServer(void);
50 static void InitDisplay(void);
51 static void InitSound(void);
52 static void InitSoundServer(void);
53 static void InitWindow(int, char **);
54 static void InitGfx(void);
55 static void LoadGfx(int, struct PictureFileInfo *);
56 static void InitGadgets(void);
57 static void InitElementProperties(void);
59 void OpenAll(int argc, char *argv[])
61 #if defined(MSDOS) || defined(WIN32)
65 if (options.serveronly)
68 Error(ERR_WARN, "networking not supported in Windows version");
70 NetworkServer(options.server_port, options.serveronly);
81 InitRND(NEW_RANDOMIZE);
83 signal(SIGINT, CloseAllAndExit);
84 signal(SIGTERM, CloseAllAndExit);
87 InitWindow(argc, argv);
89 #ifndef USE_SDL_LIBRARY
90 XMapWindow(display, window);
95 InitElementProperties(); /* initializes IS_CHAR() for el2gfx() */
97 InitLevelAndPlayerInfo();
98 InitGadgets(); /* needs to know number of level series */
105 void InitLevelAndPlayerInfo()
109 /* choose default local player */
110 local_player = &stored_player[0];
112 for (i=0; i<MAX_PLAYERS; i++)
114 stored_player[i].joystick_fd = -1; /* joystick device closed */
115 stored_player[i].connected = FALSE;
118 local_player->connected = TRUE;
120 LoadLevelInfo(); /* global level info */
121 LoadSetup(); /* global setup info */
122 LoadLevelSetup_LastSeries(); /* last played series info */
123 LoadLevelSetup_SeriesInfo(); /* last played level info */
126 void InitNetworkServer()
128 #if !defined(MSDOS) && !defined(WIN32)
132 if (!options.network)
135 #if !defined(MSDOS) && !defined(WIN32)
136 nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
138 if (!ConnectToServer(options.server_host, options.server_port))
139 Error(ERR_EXIT, "cannot connect to network game server");
141 SendToServer_PlayerName(setup.player_name);
142 SendToServer_ProtocolVersion();
145 SendToServer_NrWanted(nr_wanted);
153 if (sound_status == SOUND_OFF)
156 #ifdef USE_SDL_LIBRARY
157 /* initialize SDL audio */
159 if (SDL_Init(SDL_INIT_AUDIO) < 0)
161 Error(ERR_WARN, "SDL_Init() failed: %s\n", SDL_GetError());
162 sound_status = SOUND_OFF;
166 if (Mix_OpenAudio(22050, AUDIO_S16, 2, 256) < 0)
168 Error(ERR_WARN, "Mix_OpenAudio() failed: %s\n", SDL_GetError());
169 sound_status = SOUND_OFF;
173 Mix_Volume(-1, SDL_MIX_MAXVOLUME / 4);
174 Mix_VolumeMusic(SDL_MIX_MAXVOLUME / 4);
176 sound_status = SOUND_AVAILABLE;
177 sound_loops_allowed = TRUE;
179 #else /* !USE_SDL_LIBRARY */
181 #if !defined(MSDOS) && !defined(WIN32)
182 if (access(sound_device_name, W_OK) != 0)
184 Error(ERR_WARN, "cannot access sound device - no sounds");
185 sound_status = SOUND_OFF;
189 if ((sound_device = open(sound_device_name,O_WRONLY))<0)
191 Error(ERR_WARN, "cannot open sound device - no sounds");
192 sound_status = SOUND_OFF;
197 sound_status = SOUND_AVAILABLE;
200 sound_loops_allowed = TRUE;
203 setup.sound_loops_on = TRUE;
207 #else /* MSDOS || WIN32 */
208 sound_loops_allowed = TRUE;
211 setup.sound_loops_on = TRUE;
214 #endif /* MSDOS || WIN32 */
215 #endif /* !USE_SDL_LIBRARY */
217 for(i=0; i<NUM_SOUNDS; i++)
219 Sound[i].name = sound_name[i];
221 if (!LoadSound(&Sound[i]))
223 sound_status = SOUND_OFF;
229 sound_status = SOUND_OFF;
234 void InitSoundServer()
236 if (sound_status == SOUND_OFF)
239 #ifndef USE_SDL_LIBRARY
241 #if !defined(MSDOS) && !defined(WIN32)
243 if (pipe(sound_pipe)<0)
245 Error(ERR_WARN, "cannot create pipe - no sounds");
246 sound_status = SOUND_OFF;
250 if ((sound_process_id = fork()) < 0)
252 Error(ERR_WARN, "cannot create sound server process - no sounds");
253 sound_status = SOUND_OFF;
257 if (!sound_process_id) /* we are child */
264 else /* we are parent */
265 close(sound_pipe[0]); /* no reading from pipe needed */
267 #else /* MSDOS || WIN32 */
273 #endif /* !USE_SDL_LIBRARY */
278 #ifdef USE_SDL_LIBRARY
279 static boolean sdl_joystick_subsystem_initialized = FALSE;
284 if (global_joystick_status == JOYSTICK_OFF)
287 joystick_status = JOYSTICK_OFF;
289 #ifdef USE_SDL_LIBRARY
291 if (!sdl_joystick_subsystem_initialized)
293 sdl_joystick_subsystem_initialized = TRUE;
295 if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
297 Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
302 for (i=0; i<MAX_PLAYERS; i++)
304 char *device_name = setup.input[i].joy.device_name;
305 int joystick_nr = getJoystickNrFromDeviceName(device_name);
307 if (joystick_nr >= SDL_NumJoysticks())
310 /* misuse joystick file descriptor variable to store joystick number */
311 stored_player[i].joystick_fd = joystick_nr;
313 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
314 if (Check_SDL_JoystickOpened(joystick_nr))
315 Close_SDL_Joystick(joystick_nr);
317 if (!setup.input[i].use_joystick)
320 if (!Open_SDL_Joystick(joystick_nr))
322 Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
326 joystick_status = JOYSTICK_AVAILABLE;
329 #else /* !USE_SDL_LIBRARY */
332 for (i=0; i<MAX_PLAYERS; i++)
334 char *device_name = setup.input[i].joy.device_name;
336 /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
337 if (stored_player[i].joystick_fd != -1)
339 close(stored_player[i].joystick_fd);
340 stored_player[i].joystick_fd = -1;
343 if (!setup.input[i].use_joystick)
346 if (access(device_name, R_OK) != 0)
348 Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
352 if ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
354 Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
358 joystick_status = JOYSTICK_AVAILABLE;
363 /* try to access two joysticks; if that fails, try to access just one */
364 if (install_joystick(JOY_TYPE_2PADS) == 0 ||
365 install_joystick(JOY_TYPE_AUTODETECT) == 0)
366 joystick_status = JOYSTICK_AVAILABLE;
369 load_joystick_data(JOYSTICK_FILENAME);
372 for (i=0; i<MAX_PLAYERS; i++)
374 char *device_name = setup.input[i].joy.device_name;
375 int joystick_nr = getJoystickNrFromDeviceName(device_name);
377 if (joystick_nr >= num_joysticks)
380 /* misuse joystick file descriptor variable to store joystick number */
381 stored_player[i].joystick_fd = joystick_nr;
385 #endif /* !USE_SDL_LIBRARY */
390 #ifdef USE_SDL_LIBRARY
391 /* initialize SDL video */
392 if (SDL_Init(SDL_INIT_VIDEO) < 0)
393 Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
395 /* automatically cleanup SDL stuff after exit() */
398 #else /* !USE_SDL_LIBRARY */
401 XVisualInfo vinfo_template, *vinfo;
406 /* connect to X server */
407 if (!(display = XOpenDisplay(options.display_name)))
408 Error(ERR_EXIT, "cannot connect to X server %s",
409 XDisplayName(options.display_name));
411 screen = DefaultScreen(display);
412 visual = DefaultVisual(display, screen);
413 depth = DefaultDepth(display, screen);
414 cmap = DefaultColormap(display, screen);
417 /* look for good enough visual */
418 vinfo_template.screen = screen;
419 vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor);
420 vinfo_template.depth = depth;
421 if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask |
422 VisualDepthMask, &vinfo_template, &num_visuals)))
424 visual = vinfo->visual;
425 XFree((void *)vinfo);
428 /* got appropriate visual? */
431 printf("Sorry, displays with less than 8 bits per pixel not supported.\n");
434 else if ((depth ==8 && visual->class != PseudoColor) ||
435 (depth > 8 && visual->class != TrueColor &&
436 visual->class != DirectColor))
438 printf("Sorry, cannot get appropriate visual.\n");
442 #endif /* !USE_SDL_LIBRARY */
445 void InitWindow(int argc, char *argv[])
447 #ifdef USE_SDL_LIBRARY
448 /* open SDL video output device (window or fullscreen mode) */
449 if ((window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
452 Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
454 /* set window and icon title */
455 SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
457 /* set event filter to filter out certain mouse motion events */
458 SDL_SetEventFilter(EventFilter);
460 #else /* !USE_SDL_LIBRARY */
462 unsigned int border_width = 4;
464 unsigned long gc_valuemask;
466 XTextProperty windowName, iconName;
467 Pixmap icon_pixmap, iconmask_pixmap;
468 unsigned int icon_width, icon_height;
469 int icon_hot_x, icon_hot_y;
470 char icon_filename[256];
471 XSizeHints size_hints;
473 XClassHint class_hints;
474 char *window_name = WINDOW_TITLE_STRING;
475 char *icon_name = WINDOW_TITLE_STRING;
476 long window_event_mask;
477 Atom proto_atom = None, delete_atom = None;
479 int screen_width, screen_height;
480 int win_xpos = WIN_XPOS, win_ypos = WIN_YPOS;
481 unsigned long pen_fg = WhitePixel(display,screen);
482 unsigned long pen_bg = BlackPixel(display,screen);
483 const int width = WIN_XSIZE, height = WIN_YSIZE;
486 static struct IconFileInfo icon_pic =
493 screen_width = XDisplayWidth(display, screen);
494 screen_height = XDisplayHeight(display, screen);
496 win_xpos = (screen_width - width) / 2;
497 win_ypos = (screen_height - height) / 2;
499 window = XCreateSimpleWindow(display, RootWindow(display, screen),
500 win_xpos, win_ypos, width, height, border_width,
504 proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE);
505 delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE);
506 if ((proto_atom != None) && (delete_atom != None))
507 XChangeProperty(display, window, proto_atom, XA_ATOM, 32,
508 PropModePrepend, (unsigned char *) &delete_atom, 1);
510 sprintf(icon_filename, "%s/%s/%s",
511 options.ro_base_directory, GRAPHICS_DIRECTORY,
512 icon_pic.picture_filename);
513 XReadBitmapFile(display,window,icon_filename,
514 &icon_width,&icon_height,
515 &icon_pixmap,&icon_hot_x,&icon_hot_y);
517 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
519 sprintf(icon_filename, "%s/%s/%s",
520 options.ro_base_directory, GRAPHICS_DIRECTORY,
521 icon_pic.picturemask_filename);
522 XReadBitmapFile(display,window,icon_filename,
523 &icon_width,&icon_height,
524 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
525 if (!iconmask_pixmap)
526 Error(ERR_EXIT, "cannot read icon bitmap file '%s'", icon_filename);
528 size_hints.width = size_hints.min_width = size_hints.max_width = width;
529 size_hints.height = size_hints.min_height = size_hints.max_height = height;
530 size_hints.flags = PSize | PMinSize | PMaxSize;
532 if (win_xpos || win_ypos)
534 size_hints.x = win_xpos;
535 size_hints.y = win_ypos;
536 size_hints.flags |= PPosition;
539 if (!XStringListToTextProperty(&window_name, 1, &windowName))
540 Error(ERR_EXIT, "structure allocation for windowName failed");
542 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
543 Error(ERR_EXIT, "structure allocation for iconName failed");
545 wm_hints.initial_state = NormalState;
546 wm_hints.input = True;
547 wm_hints.icon_pixmap = icon_pixmap;
548 wm_hints.icon_mask = iconmask_pixmap;
549 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
551 class_hints.res_name = program_name;
552 class_hints.res_class = "Rocks'n'Diamonds";
554 XSetWMProperties(display, window, &windowName, &iconName,
555 argv, argc, &size_hints, &wm_hints,
558 XFree(windowName.value);
559 XFree(iconName.value);
561 /* Select event types wanted */
563 ExposureMask | StructureNotifyMask | FocusChangeMask |
564 ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
565 PointerMotionHintMask | KeyPressMask | KeyReleaseMask;
567 XSelectInput(display, window, window_event_mask);
570 /* create GC for drawing with window depth and background color (black) */
571 gc_values.graphics_exposures = False;
572 gc_values.foreground = pen_bg;
573 gc_values.background = pen_bg;
574 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
575 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
576 #endif /* !USE_SDL_LIBRARY */
583 #ifdef USE_SDL_LIBRARY
584 SDL_Surface *sdl_image_tmp;
587 XGCValues clip_gc_values;
588 unsigned long clip_gc_valuemask;
592 static struct PictureFileInfo pic[NUM_PICTURES] =
606 static struct PictureFileInfo pic[NUM_PICTURES] =
608 { "RocksScreen", TRUE },
609 { "RocksDoor", TRUE },
610 { "RocksHeroes", TRUE },
611 { "RocksToons", TRUE },
614 { "RocksMore", TRUE },
615 { "RocksFont", FALSE },
616 { "RocksFont2", FALSE },
617 { "RocksFont3", FALSE }
623 static struct PictureFileInfo test_pic1 =
628 static struct PictureFileInfo test_pic2 =
641 tile_needs_clipping[] =
643 { GFX_SPIELER1_UP, 4 },
644 { GFX_SPIELER1_DOWN, 4 },
645 { GFX_SPIELER1_LEFT, 4 },
646 { GFX_SPIELER1_RIGHT, 4 },
647 { GFX_SPIELER1_PUSH_LEFT, 4 },
648 { GFX_SPIELER1_PUSH_RIGHT, 4 },
649 { GFX_SPIELER2_UP, 4 },
650 { GFX_SPIELER2_DOWN, 4 },
651 { GFX_SPIELER2_LEFT, 4 },
652 { GFX_SPIELER2_RIGHT, 4 },
653 { GFX_SPIELER2_PUSH_LEFT, 4 },
654 { GFX_SPIELER2_PUSH_RIGHT, 4 },
655 { GFX_SPIELER3_UP, 4 },
656 { GFX_SPIELER3_DOWN, 4 },
657 { GFX_SPIELER3_LEFT, 4 },
658 { GFX_SPIELER3_RIGHT, 4 },
659 { GFX_SPIELER3_PUSH_LEFT, 4 },
660 { GFX_SPIELER3_PUSH_RIGHT, 4 },
661 { GFX_SPIELER4_UP, 4 },
662 { GFX_SPIELER4_DOWN, 4 },
663 { GFX_SPIELER4_LEFT, 4 },
664 { GFX_SPIELER4_RIGHT, 4 },
665 { GFX_SPIELER4_PUSH_LEFT, 4 },
666 { GFX_SPIELER4_PUSH_RIGHT, 4 },
667 { GFX_SP_MURPHY, 1 },
668 { GFX_MURPHY_GO_LEFT, 3 },
669 { GFX_MURPHY_GO_RIGHT, 3 },
670 { GFX_MURPHY_SNAP_UP, 1 },
671 { GFX_MURPHY_SNAP_DOWN, 1 },
672 { GFX_MURPHY_SNAP_RIGHT, 1 },
673 { GFX_MURPHY_SNAP_LEFT, 1 },
674 { GFX_MURPHY_PUSH_RIGHT, 1 },
675 { GFX_MURPHY_PUSH_LEFT, 1 },
676 { GFX_GEBLUBBER, 4 },
679 { GFX_EXPLOSION, 8 },
680 { GFX_SOKOBAN_OBJEKT, 1 },
681 { GFX_FUNKELN_BLAU, 3 },
682 { GFX_FUNKELN_WEISS, 3 },
683 { GFX2_SHIELD_PASSIVE, 3 },
684 { GFX2_SHIELD_ACTIVE, 3 },
689 debug_print_timestamp(0, NULL); /* initialize timestamp function */
694 printf("Test: Loading RocksFont2.pcx ...\n");
695 LoadGfx(PIX_SMALLFONT,&test_pic1);
696 printf("Test: Done.\n");
697 printf("Test: Loading mouse.pcx ...\n");
698 LoadGfx(PIX_SMALLFONT,&test_pic2);
699 printf("Test: Done.\n");
703 LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
704 DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW);
705 DrawInitText(COPYRIGHT_STRING,50,FC_RED);
707 DrawInitText("MSDOS version done by Guido Schulz",210,FC_BLUE);
710 DrawInitText("Loading graphics:",120,FC_GREEN);
712 for(i=0; i<NUM_PICTURES; i++)
713 if (i != PIX_SMALLFONT)
717 debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
720 #ifdef USE_SDL_LIBRARY
721 /* create some native image surfaces for double-buffer purposes */
723 /* create double-buffer surface for background image */
724 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
725 WIN_XSIZE, WIN_YSIZE,
726 WIN_SDL_DEPTH, 0, 0, 0, 0))
728 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
730 if ((pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
731 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
733 SDL_FreeSurface(sdl_image_tmp);
735 /* create double-buffer surface for door image */
736 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
737 3 * DXSIZE, DYSIZE + VYSIZE,
738 WIN_SDL_DEPTH, 0, 0, 0, 0))
740 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
742 if ((pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
743 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
745 SDL_FreeSurface(sdl_image_tmp);
747 /* create double-buffer surface for field image */
748 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
750 WIN_SDL_DEPTH, 0, 0, 0, 0))
752 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
754 if ((pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
755 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
757 SDL_FreeSurface(sdl_image_tmp);
759 /* initialize surface array to 'NULL' */
760 for(i=0; i<NUM_TILES; i++)
761 tile_masked[i] = NULL;
763 /* create only those masked surfaces we really need */
764 for(i=0; tile_needs_clipping[i].start>=0; i++)
766 for(j=0; j<tile_needs_clipping[i].count; j++)
768 int tile = tile_needs_clipping[i].start + j;
774 getGraphicSource(graphic, &bitmap_nr, &src_x, &src_y);
775 src_bitmap = pix_masked[bitmap_nr];
777 /* create surface for masked tile graphic */
778 if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE, TILEX, TILEY,
779 WIN_SDL_DEPTH, 0, 0, 0, 0))
781 Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
783 /* create native transparent surface for current image */
784 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
785 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
786 if ((tile_masked[tile] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
787 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
789 SDL_FreeSurface(sdl_image_tmp);
791 BlitBitmap(src_bitmap, tile_masked[tile], src_x,src_y, TILEX,TILEY, 0,0);
795 #else /* !USE_SDL_LIBRARY */
797 pix[PIX_DB_BACK] = XCreatePixmap(display, window,
799 XDefaultDepth(display,screen));
800 pix[PIX_DB_DOOR] = XCreatePixmap(display, window,
801 3*DXSIZE,DYSIZE+VYSIZE,
802 XDefaultDepth(display,screen));
803 pix[PIX_DB_FIELD] = XCreatePixmap(display, window,
805 XDefaultDepth(display,screen));
807 clip_gc_values.graphics_exposures = False;
808 clip_gc_valuemask = GCGraphicsExposures;
810 XCreateGC(display,clipmask[PIX_BACK],clip_gc_valuemask,&clip_gc_values);
812 clip_gc_values.graphics_exposures = False;
813 clip_gc_valuemask = GCGraphicsExposures;
815 XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
817 /* initialize pixmap array to Pixmap 'None' */
818 for(i=0; i<NUM_TILES; i++)
819 tile_clipmask[i] = None;
821 /* create only those clipping Pixmaps we really need */
822 for(i=0; tile_needs_clipping[i].start>=0; i++)
824 for(j=0; j<tile_needs_clipping[i].count; j++)
826 int tile = tile_needs_clipping[i].start + j;
832 getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
833 src_pixmap = clipmask[pixmap_nr];
835 tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
837 XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
838 src_x,src_y, TILEX,TILEY, 0,0);
842 if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR])
843 Error(ERR_EXIT, "cannot create additional pixmaps");
845 for(i=0; i<NUM_BITMAPS; i++)
849 clip_gc_values.graphics_exposures = False;
850 clip_gc_values.clip_mask = clipmask[i];
851 clip_gc_valuemask = GCGraphicsExposures | GCClipMask;
852 clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
856 #endif /* !USE_SDL_LIBRARY */
858 drawto = backbuffer = pix[PIX_DB_BACK];
859 fieldbuffer = pix[PIX_DB_FIELD];
860 SetDrawtoField(DRAW_BACKBUFFER);
862 BlitBitmap(pix[PIX_BACK], backbuffer, 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
863 ClearRectangle(pix[PIX_DB_BACK], REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
864 ClearRectangle(pix[PIX_DB_DOOR], 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
866 for(i=0; i<MAX_BUF_XSIZE; i++)
867 for(j=0; j<MAX_BUF_YSIZE; j++)
870 redraw_mask = REDRAW_ALL;
873 void LoadGfx(int pos, struct PictureFileInfo *pic)
875 char basefilename[256];
878 #ifdef USE_XPM_LIBRARY
879 int xpm_err, xbm_err;
880 unsigned int width,height;
883 char *picture_ext = ".xpm";
884 char *picturemask_ext = "Mask.xbm";
887 #ifdef USE_SDL_LIBRARY
888 SDL_Surface *sdl_image_tmp;
889 #else /* !USE_SDL_LIBRARY */
891 #endif /* !USE_SDL_LIBRARY */
892 char *picture_ext = ".pcx";
894 #endif /* !USE_XPM_LIBRARY */
897 if (pic->picture_filename)
899 sprintf(basefilename, "%s%s", pic->picture_filename, picture_ext);
900 DrawInitText(basefilename, 150, FC_YELLOW);
901 sprintf(filename, "%s/%s/%s",
902 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
909 debug_print_timestamp(1, NULL); /* initialize timestamp function */
912 #ifdef USE_SDL_LIBRARY
913 /* load image to temporary surface */
914 if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
915 Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError());
917 /* create native non-transparent surface for current image */
918 if ((pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
919 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
921 /* create native transparent surface for current image */
922 SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
923 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
924 if ((pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
925 Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
927 /* free temporary surface */
928 SDL_FreeSurface(sdl_image_tmp);
930 #else /* !USE_SDL_LIBRARY */
932 #ifdef USE_XPM_LIBRARY
934 xpm_att[pos].valuemask = XpmCloseness;
935 xpm_att[pos].closeness = 20000;
936 xpm_err = XpmReadFileToPixmap(display,window,filename,
937 &pix[pos],&shapemask,&xpm_att[pos]);
941 Error(ERR_EXIT, "cannot open XPM file '%s'", filename);
943 Error(ERR_EXIT, "invalid XPM file '%s'", filename);
945 Error(ERR_EXIT, "not enough memory for XPM file '%s'", filename);
947 Error(ERR_EXIT, "cannot get colors for XPM file '%s'", filename);
953 printf("LOADING XPM FILE %s:", filename);
954 debug_print_timestamp(1, "");
957 #else /* !USE_XPM_LIBRARY */
959 pcx_err = Read_PCX_to_Pixmap(display, window, gc, filename,
960 &pix[pos], &clipmask[pos]);
966 Error(ERR_EXIT, "cannot open PCX file '%s'", filename);
968 Error(ERR_EXIT, "cannot read PCX file '%s'", filename);
969 case PCX_FileInvalid:
970 Error(ERR_EXIT, "invalid PCX file '%s'", filename);
972 Error(ERR_EXIT, "not enough memory for PCX file '%s'", filename);
973 case PCX_ColorFailed:
974 Error(ERR_EXIT, "cannot get colors for PCX file '%s'", filename);
980 printf("SUMMARY LOADING PCX FILE %s:", filename);
981 debug_print_timestamp(1, "");
984 #endif /* !USE_XPM_LIBRARY */
987 Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
989 /* setting pix_masked[] to pix[] allows BlitBitmapMasked() to always
990 use pix_masked[], although they are the same when not using SDL */
991 pix_masked[pos] = pix[pos];
993 #endif /* !USE_SDL_LIBRARY */
996 #ifndef USE_SDL_LIBRARY
997 /* zugehörige Maske laden (wenn vorhanden) */
998 if (pic->picture_with_mask)
1000 #ifdef USE_XPM_LIBRARY
1002 sprintf(basefilename, "%s%s", pic->picture_filename, picturemask_ext);
1003 DrawInitText(basefilename, 150, FC_YELLOW);
1004 sprintf(filename, "%s/%s/%s",
1005 options.ro_base_directory, GRAPHICS_DIRECTORY, basefilename);
1008 debug_print_timestamp(1, NULL); /* initialize timestamp function */
1011 xbm_err = XReadBitmapFile(display,window,filename,
1012 &width,&height,&clipmask[pos],&hot_x,&hot_y);
1017 case BitmapOpenFailed:
1018 Error(ERR_EXIT, "cannot open XBM file '%s'", filename);
1019 case BitmapFileInvalid:
1020 Error(ERR_EXIT, "invalid XBM file '%s'", filename);
1021 case BitmapNoMemory:
1022 Error(ERR_EXIT, "not enough memory for XBM file '%s'", filename);
1029 printf("LOADING XBM FILE %s:", filename);
1030 debug_print_timestamp(1, "");
1033 #endif /* USE_XPM_LIBRARY */
1036 Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
1038 #endif /* !USE_SDL_LIBRARY */
1043 CreateLevelEditorGadgets();
1044 CreateGameButtons();
1045 CreateTapeButtons();
1046 CreateToolButtons();
1047 CreateScreenGadgets();
1050 void InitElementProperties()
1054 static int ep_amoebalive[] =
1061 static int ep_amoebalive_num = sizeof(ep_amoebalive)/sizeof(int);
1063 static int ep_amoeboid[] =
1071 static int ep_amoeboid_num = sizeof(ep_amoeboid)/sizeof(int);
1073 static int ep_schluessel[] =
1084 static int ep_schluessel_num = sizeof(ep_schluessel)/sizeof(int);
1086 static int ep_pforte[] =
1105 EL_SWITCHGATE_CLOSED,
1120 static int ep_pforte_num = sizeof(ep_pforte)/sizeof(int);
1122 static int ep_solid[] =
1143 EL_MAGIC_WALL_EMPTY,
1146 EL_MAGIC_WALL_BD_OFF,
1147 EL_MAGIC_WALL_BD_EMPTY,
1148 EL_MAGIC_WALL_BD_FULL,
1149 EL_MAGIC_WALL_BD_DEAD,
1176 EL_BELT1_SWITCH_LEFT,
1177 EL_BELT1_SWITCH_MIDDLE,
1178 EL_BELT1_SWITCH_RIGHT,
1179 EL_BELT2_SWITCH_LEFT,
1180 EL_BELT2_SWITCH_MIDDLE,
1181 EL_BELT2_SWITCH_RIGHT,
1182 EL_BELT3_SWITCH_LEFT,
1183 EL_BELT3_SWITCH_MIDDLE,
1184 EL_BELT3_SWITCH_RIGHT,
1185 EL_BELT4_SWITCH_LEFT,
1186 EL_BELT4_SWITCH_MIDDLE,
1187 EL_BELT4_SWITCH_RIGHT,
1188 EL_SWITCHGATE_SWITCH_1,
1189 EL_SWITCHGATE_SWITCH_2,
1190 EL_LIGHT_SWITCH_OFF,
1192 EL_TIMEGATE_SWITCH_OFF,
1193 EL_TIMEGATE_SWITCH_ON,
1194 EL_SIGN_EXCLAMATION,
1195 EL_SIGN_RADIOACTIVITY,
1207 EL_EMC_STEEL_WALL_1,
1208 EL_EMC_STEEL_WALL_2,
1209 EL_EMC_STEEL_WALL_3,
1210 EL_EMC_STEEL_WALL_4,
1234 static int ep_solid_num = sizeof(ep_solid)/sizeof(int);
1236 static int ep_massive[] =
1262 EL_SWITCHGATE_CLOSED,
1277 EL_BELT1_SWITCH_LEFT,
1278 EL_BELT1_SWITCH_MIDDLE,
1279 EL_BELT1_SWITCH_RIGHT,
1280 EL_BELT2_SWITCH_LEFT,
1281 EL_BELT2_SWITCH_MIDDLE,
1282 EL_BELT2_SWITCH_RIGHT,
1283 EL_BELT3_SWITCH_LEFT,
1284 EL_BELT3_SWITCH_MIDDLE,
1285 EL_BELT3_SWITCH_RIGHT,
1286 EL_BELT4_SWITCH_LEFT,
1287 EL_BELT4_SWITCH_MIDDLE,
1288 EL_BELT4_SWITCH_RIGHT,
1289 EL_LIGHT_SWITCH_OFF,
1291 EL_SIGN_EXCLAMATION,
1292 EL_SIGN_RADIOACTIVITY,
1304 EL_EMC_STEEL_WALL_1,
1305 EL_EMC_STEEL_WALL_2,
1306 EL_EMC_STEEL_WALL_3,
1307 EL_EMC_STEEL_WALL_4,
1321 static int ep_massive_num = sizeof(ep_massive)/sizeof(int);
1323 static int ep_slippery[] =
1358 static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
1360 static int ep_enemy[] =
1373 static int ep_enemy_num = sizeof(ep_enemy)/sizeof(int);
1375 static int ep_mauer[] =
1425 EL_EMC_STEEL_WALL_1,
1426 EL_EMC_STEEL_WALL_2,
1427 EL_EMC_STEEL_WALL_3,
1428 EL_EMC_STEEL_WALL_4,
1438 static int ep_mauer_num = sizeof(ep_mauer)/sizeof(int);
1440 static int ep_can_fall[] =
1455 EL_MAGIC_WALL_BD_FULL,
1466 static int ep_can_fall_num = sizeof(ep_can_fall)/sizeof(int);
1468 static int ep_can_smash[] =
1499 static int ep_can_smash_num = sizeof(ep_can_smash)/sizeof(int);
1501 static int ep_can_change[] =
1512 static int ep_can_change_num = sizeof(ep_can_change)/sizeof(int);
1514 static int ep_can_move[] =
1534 static int ep_can_move_num = sizeof(ep_can_move)/sizeof(int);
1536 static int ep_could_move[] =
1559 static int ep_could_move_num = sizeof(ep_could_move)/sizeof(int);
1561 static int ep_dont_touch[] =
1568 static int ep_dont_touch_num = sizeof(ep_dont_touch)/sizeof(int);
1570 static int ep_dont_go_to[] =
1588 static int ep_dont_go_to_num = sizeof(ep_dont_go_to)/sizeof(int);
1590 static int ep_mampf2[] =
1615 static int ep_mampf2_num = sizeof(ep_mampf2)/sizeof(int);
1617 static int ep_bd_element[] =
1626 EL_MAGIC_WALL_BD_OFF,
1644 static int ep_bd_element_num = sizeof(ep_bd_element)/sizeof(int);
1646 static int ep_sb_element[] =
1651 EL_SOKOBAN_FELD_LEER,
1652 EL_SOKOBAN_FELD_VOLL,
1656 static int ep_sb_element_num = sizeof(ep_sb_element)/sizeof(int);
1658 static int ep_gem[] =
1668 static int ep_gem_num = sizeof(ep_gem)/sizeof(int);
1670 static int ep_inactive[] =
1707 EL_DYNAMITE_INACTIVE,
1719 EL_SOKOBAN_FELD_LEER,
1720 EL_SOKOBAN_FELD_VOLL,
1730 EL_MAGIC_WALL_BD_OFF,
1731 EL_MAGIC_WALL_BD_DEAD,
1767 EL_BELT1_SWITCH_LEFT,
1768 EL_BELT1_SWITCH_MIDDLE,
1769 EL_BELT1_SWITCH_RIGHT,
1770 EL_BELT2_SWITCH_LEFT,
1771 EL_BELT2_SWITCH_MIDDLE,
1772 EL_BELT2_SWITCH_RIGHT,
1773 EL_BELT3_SWITCH_LEFT,
1774 EL_BELT3_SWITCH_MIDDLE,
1775 EL_BELT3_SWITCH_RIGHT,
1776 EL_BELT4_SWITCH_LEFT,
1777 EL_BELT4_SWITCH_MIDDLE,
1778 EL_BELT4_SWITCH_RIGHT,
1779 EL_SIGN_EXCLAMATION,
1780 EL_SIGN_RADIOACTIVITY,
1792 EL_EMC_STEEL_WALL_1,
1793 EL_EMC_STEEL_WALL_2,
1794 EL_EMC_STEEL_WALL_3,
1795 EL_EMC_STEEL_WALL_4,
1805 static int ep_inactive_num = sizeof(ep_inactive)/sizeof(int);
1807 static int ep_explosive[] =
1811 EL_DYNAMITE_INACTIVE,
1812 EL_DYNABOMB_ACTIVE_1,
1813 EL_DYNABOMB_ACTIVE_2,
1814 EL_DYNABOMB_ACTIVE_3,
1815 EL_DYNABOMB_ACTIVE_4,
1832 static int ep_explosive_num = sizeof(ep_explosive)/sizeof(int);
1834 static int ep_mampf3[] =
1845 static int ep_mampf3_num = sizeof(ep_mampf3)/sizeof(int);
1847 static int ep_pushable[] =
1854 EL_SOKOBAN_FELD_VOLL,
1864 static int ep_pushable_num = sizeof(ep_pushable)/sizeof(int);
1866 static int ep_player[] =
1874 static int ep_player_num = sizeof(ep_player)/sizeof(int);
1876 static int ep_has_content[] =
1884 static int ep_has_content_num = sizeof(ep_has_content)/sizeof(int);
1886 static int ep_eatable[] =
1894 static int ep_eatable_num = sizeof(ep_eatable)/sizeof(int);
1896 static int ep_sp_element[] =
1938 /* additional elements that appeared in newer Supaplex levels */
1940 /* more than one murphy in a level results in an inactive clone */
1943 static int ep_sp_element_num = sizeof(ep_sp_element)/sizeof(int);
1945 static int ep_quick_gate[] =
1969 static int ep_quick_gate_num = sizeof(ep_quick_gate)/sizeof(int);
1971 static int ep_over_player[] =
1996 static int ep_over_player_num = sizeof(ep_over_player)/sizeof(int);
1998 static int ep_active_bomb[] =
2001 EL_DYNABOMB_ACTIVE_1,
2002 EL_DYNABOMB_ACTIVE_2,
2003 EL_DYNABOMB_ACTIVE_3,
2004 EL_DYNABOMB_ACTIVE_4
2006 static int ep_active_bomb_num = sizeof(ep_active_bomb)/sizeof(int);
2008 static int ep_belt[] =
2023 static int ep_belt_num = sizeof(ep_belt)/sizeof(int);
2025 static int ep_belt_switch[] =
2027 EL_BELT1_SWITCH_LEFT,
2028 EL_BELT1_SWITCH_MIDDLE,
2029 EL_BELT1_SWITCH_RIGHT,
2030 EL_BELT2_SWITCH_LEFT,
2031 EL_BELT2_SWITCH_MIDDLE,
2032 EL_BELT2_SWITCH_RIGHT,
2033 EL_BELT3_SWITCH_LEFT,
2034 EL_BELT3_SWITCH_MIDDLE,
2035 EL_BELT3_SWITCH_RIGHT,
2036 EL_BELT4_SWITCH_LEFT,
2037 EL_BELT4_SWITCH_MIDDLE,
2038 EL_BELT4_SWITCH_RIGHT,
2040 static int ep_belt_switch_num = sizeof(ep_belt_switch)/sizeof(int);
2042 static int ep_tube[] =
2056 static int ep_tube_num = sizeof(ep_tube)/sizeof(int);
2058 static long ep1_bit[] =
2092 static long ep2_bit[] =
2098 static int *ep1_array[] =
2132 static int *ep2_array[] =
2138 static int *ep1_num[] =
2165 &ep_has_content_num,
2169 &ep_over_player_num,
2172 static int *ep2_num[] =
2175 &ep_belt_switch_num,
2178 static int num_properties1 = sizeof(ep1_num)/sizeof(int *);
2179 static int num_properties2 = sizeof(ep2_num)/sizeof(int *);
2181 for(i=0; i<MAX_ELEMENTS; i++)
2183 Elementeigenschaften1[i] = 0;
2184 Elementeigenschaften2[i] = 0;
2187 for(i=0; i<num_properties1; i++)
2188 for(j=0; j<*(ep1_num[i]); j++)
2189 Elementeigenschaften1[(ep1_array[i])[j]] |= ep1_bit[i];
2190 for(i=0; i<num_properties2; i++)
2191 for(j=0; j<*(ep2_num[i]); j++)
2192 Elementeigenschaften2[(ep2_array[i])[j]] |= ep2_bit[i];
2194 for(i=EL_CHAR_START; i<EL_CHAR_END; i++)
2195 Elementeigenschaften1[i] |= (EP_BIT_CHAR | EP_BIT_INACTIVE);
2198 void CloseAllAndExit(int exit_value)
2202 #ifdef USE_SDL_LIBRARY
2204 FreeSounds(NUM_SOUNDS);
2206 if (sound_process_id)
2209 kill(sound_process_id, SIGTERM);
2210 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);