1 /***********************************************************
2 * Rocks'n'Diamonds -- McDuffin Strikes Back! *
3 *----------------------------------------------------------*
4 * ©1995 Artsoft Development *
6 * 33659 Bielefeld-Senne *
7 * Telefon: (0521) 493245 *
8 * eMail: aeglos@valinor.owl.de *
9 * aeglos@uni-paderborn.de *
10 * q99492@pbhrzx.uni-paderborn.de *
11 *----------------------------------------------------------*
13 ***********************************************************/
22 static int sound_process_id = 0;
24 void OpenAll(int argc, char *argv[])
26 InitLevelAndPlayerInfo();
32 InitRND(NEW_RANDOMIZE);
34 signal(SIGINT, CloseAll);
35 signal(SIGTERM, CloseAll);
37 InitDisplay(argc, argv);
38 InitWindow(argc, argv);
40 InitElementProperties();
44 XMapWindow(display, window);
48 void InitLevelAndPlayerInfo()
50 if (!LoadLevelInfo()) /* global level info */
53 LoadPlayerInfo(PLAYER_SETUP); /* global setup info */
54 LoadPlayerInfo(PLAYER_LEVEL); /* level specific info */
61 if (sound_status==SOUND_OFF)
64 if (access(sound_device_name,W_OK)<0)
66 fprintf(stderr,"%s: cannot access sound device - no sounds\n",progname);
67 sound_status=SOUND_OFF;
71 if ((sound_device=open(sound_device_name,O_WRONLY))<0)
73 fprintf(stderr,"%s: cannot open sound device - no sounds\n",progname);
74 sound_status=SOUND_OFF;
79 sound_status=SOUND_AVAILABLE;
82 sound_loops_allowed = TRUE;
83 sound_loops_on = TRUE;
86 for(i=0;i<NUM_SOUNDS;i++)
88 Sound[i].name = sound_name[i];
89 if (!LoadSound(&Sound[i]))
91 sound_status=SOUND_OFF;
97 void InitSoundProcess()
99 if (sound_status==SOUND_OFF)
102 if (pipe(sound_pipe)<0)
104 fprintf(stderr,"%s: cannot create pipe - no sounds\n",progname);
105 sound_status=SOUND_OFF;
109 if ((sound_process_id=fork())<0)
111 fprintf(stderr,"%s: cannot create child process - no sounds\n",progname);
112 sound_status=SOUND_OFF;
116 if (!sound_process_id) /* we are child */
118 else /* we are parent */
119 close(sound_pipe[0]); /* no reading from pipe needed */
124 if (global_joystick_status==JOYSTICK_OFF)
127 if (access(joystick_device_name[joystick_nr],R_OK)<0)
129 fprintf(stderr,"%s: cannot access joystick device '%s'\n",
130 progname,joystick_device_name[joystick_nr]);
131 joystick_status = JOYSTICK_OFF;
135 if ((joystick_device=open(joystick_device_name[joystick_nr],O_RDONLY))<0)
137 fprintf(stderr,"%s: cannot open joystick device '%s'\n",
138 progname,joystick_device_name[joystick_nr]);
139 joystick_status = JOYSTICK_OFF;
143 joystick_status = JOYSTICK_AVAILABLE;
147 void InitDisplay(int argc, char *argv[])
149 char *display_name = NULL;
152 /* get X server to connect to, if given as an argument */
153 for (i=1;i<argc-1;i++)
155 char *dispstr="-display";
156 int len=MAX(strlen(dispstr),strlen(argv[i]));
160 else if (!strncmp(argv[i],dispstr,len))
162 display_name=argv[i+1];
167 /* connect to X server */
168 if (!(display=XOpenDisplay(display_name)))
170 fprintf(stderr,"%s: cannot connect to X server %s\n",
171 progname, XDisplayName(display_name));
175 screen = DefaultScreen(display);
176 cmap = DefaultColormap(display, screen);
177 pen_fg = WhitePixel(display,screen);
178 pen_bg = BlackPixel(display,screen);
181 void InitWindow(int argc, char *argv[])
183 unsigned int border_width = 4;
184 Pixmap icon_pixmap, iconmask_pixmap;
185 unsigned int icon_width,icon_height;
186 int icon_hot_x,icon_hot_y;
187 char icon_filename[256];
188 XSizeHints size_hints;
190 XClassHint class_hints;
191 XTextProperty windowName, iconName;
193 unsigned long gc_valuemask;
194 char *window_name = "Rocks'n'Diamonds";
195 char *icon_name = "Rocks'n'Diamonds";
196 long window_event_mask;
197 static struct PictureFile icon_pic =
206 window = XCreateSimpleWindow(display, RootWindow(display, screen),
207 WIN_XPOS, WIN_YPOS, width, height, border_width,
210 sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picture_filename);
211 XReadBitmapFile(display,window,icon_filename,
212 &icon_width,&icon_height,
213 &icon_pixmap,&icon_hot_x,&icon_hot_y);
216 fprintf(stderr, "%s: cannot read icon bitmap file '%s'.\n",
217 progname,icon_filename);
221 sprintf(icon_filename,"%s/%s",GFX_PATH,icon_pic.picturemask_filename);
222 XReadBitmapFile(display,window,icon_filename,
223 &icon_width,&icon_height,
224 &iconmask_pixmap,&icon_hot_x,&icon_hot_y);
225 if (!iconmask_pixmap)
227 fprintf(stderr, "%s: cannot read icon bitmap file '%s'.\n",
228 progname,icon_filename);
232 size_hints.flags = PSize | PMinSize | PMaxSize;
233 size_hints.width = size_hints.min_width = size_hints.max_width = width;
234 size_hints.height = size_hints.min_height = size_hints.max_height = height;
236 if (!XStringListToTextProperty(&window_name, 1, &windowName))
238 fprintf(stderr, "%s: structure allocation for windowName failed.\n",
243 if (!XStringListToTextProperty(&icon_name, 1, &iconName))
245 fprintf(stderr, "%s: structure allocation for iconName failed.\n",
250 wm_hints.initial_state = NormalState;
251 wm_hints.input = True;
252 wm_hints.icon_pixmap = icon_pixmap;
253 wm_hints.icon_mask = iconmask_pixmap;
254 wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint;
256 class_hints.res_name = progname;
257 class_hints.res_class = "Rocks'n'Diamonds";
259 XSetWMProperties(display, window, &windowName, &iconName,
260 argv, argc, &size_hints, &wm_hints,
263 XFree(windowName.value);
264 XFree(iconName.value);
266 /* Select event types wanted */
267 window_event_mask = ExposureMask | StructureNotifyMask | FocusChangeMask |
268 ButtonPressMask | ButtonReleaseMask | ButtonMotionMask |
269 KeyPressMask | KeyReleaseMask;
270 XSelectInput(display, window, window_event_mask);
272 /* create GC for drawing with window depth */
273 gc_values.graphics_exposures = False;
274 gc_values.foreground = pen_bg;
275 gc_values.background = pen_bg;
276 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
277 gc = XCreateGC(display, window, gc_valuemask, &gc_values);
283 int xpm_err, xbm_err;
284 unsigned int width,height;
287 unsigned long gc_valuemask;
288 XGCValues clip_gc_values;
289 unsigned long clip_gc_valuemask;
293 static struct PictureFile pic[NUM_PICTURES] =
295 "RocksScreen.xpm", "RocksScreenMaske.xbm",
296 "RocksDoor.xpm", "RocksDoorMaske.xbm",
297 "RocksToons.xpm", "RocksToonsMaske.xbm",
298 "RocksFont.xpm", NULL,
299 "RocksFont2.xpm", NULL
302 for(i=0;i<NUM_PICTURES;i++)
304 if (pic[i].picture_filename)
306 sprintf(filename,"%s/%s",GFX_PATH,pic[i].picture_filename);
308 xpm_att[i].valuemask = XpmCloseness;
309 xpm_att[i].closeness = 20000;
310 xpm_err = XpmReadFileToPixmap(display,window,filename,
311 &pix[i],&shapemask,&xpm_att[i]);
315 fprintf(stderr,"Xpm file open failed on '%s' !\n",filename);
319 fprintf(stderr,"Invalid Xpm file '%s'!\n",filename);
323 fprintf(stderr,"Not enough memory !\n");
327 fprintf(stderr,"Can`t get any colors...\n");
335 fprintf(stderr, "%s: cannot read Xpm file '%s'.\n",
342 if (pic[i].picturemask_filename)
344 sprintf(filename,"%s/%s",GFX_PATH,pic[i].picturemask_filename);
346 xbm_err = XReadBitmapFile(display,window,filename,
347 &width,&height,&clipmask[i],&hot_x,&hot_y);
352 case BitmapOpenFailed:
353 fprintf(stderr,"Bitmap file open failed on '%s' !\n",filename);
357 case BitmapFileInvalid:
358 fprintf(stderr,"Bitmap file invalid: '%s' !\n",filename);
363 fprintf(stderr,"No memory for file '%s' !\n",filename);
372 fprintf(stderr, "%s: cannot read X11 bitmap file '%s'.\n",
380 pix[PIX_DB_BACK] = XCreatePixmap(display, window,
382 XDefaultDepth(display,screen));
383 pix[PIX_DB_DOOR] = XCreatePixmap(display, window,
384 3*DXSIZE,DYSIZE+VYSIZE,
385 XDefaultDepth(display,screen));
387 clipmask[PIX_FADEMASK] = XCreatePixmap(display, window,
388 SXSIZE+TILEX,SYSIZE+TILEY,1);
390 if (!pix[PIX_DB_BACK] || !pix[PIX_DB_DOOR] || !clipmask[PIX_FADEMASK])
392 fprintf(stderr, "%s: cannot create additional Pixmaps!\n",progname);
397 /* create GC for drawing with bitplane depth */
398 gc_values.graphics_exposures = False;
399 gc_values.foreground = pen_bg;
400 gc_values.background = pen_bg;
401 gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
402 plane_gc = XCreateGC(display, clipmask[PIX_BACK], gc_valuemask, &gc_values);
404 for(y=0;y<=SCR_FIELDY;y++) for(x=0;x<=SCR_FIELDX;x++)
405 XCopyArea(display,clipmask[PIX_BACK],clipmask[PIX_FADEMASK],plane_gc,
406 SX+2*TILEX,SY+10*TILEY,TILEX,TILEY,x*TILEX,y*TILEY);
408 for(i=0;i<NUM_PIXMAPS;i++)
412 clip_gc_values.graphics_exposures = False;
413 clip_gc_values.foreground = pen_fg;
414 clip_gc_values.background = pen_bg;
415 clip_gc_values.clip_mask = clipmask[i];
417 GCGraphicsExposures | GCForeground | GCBackground | GCClipMask;
418 clip_gc[i] = XCreateGC(display,window,clip_gc_valuemask,&clip_gc_values);
422 drawto = drawto_field = backbuffer = pix[PIX_DB_BACK];
424 XCopyArea(display,pix[PIX_BACK],backbuffer,gc,
425 0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
426 XFillRectangle(display,backbuffer,gc,
427 REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
429 for(i=0;i<SCR_FIELDX;i++)
430 for(j=0;j<SCR_FIELDY;j++)
433 redraw_mask=REDRAW_ALL;
436 void InitElementProperties()
440 static int ep_amoebalive[] =
446 static int ep_amoebalive_num = sizeof(ep_amoebalive)/sizeof(int);
448 static int ep_amoeboid[] =
455 static int ep_amoeboid_num = sizeof(ep_amoeboid)/sizeof(int);
457 static int ep_badewannoid[] =
465 static int ep_badewannoid_num = sizeof(ep_badewannoid)/sizeof(int);
467 static int ep_schluessel[] =
474 static int ep_schluessel_num = sizeof(ep_schluessel)/sizeof(int);
476 static int ep_pforte[] =
487 static int ep_pforte_num = sizeof(ep_pforte)/sizeof(int);
489 static int ep_solid[] =
513 static int ep_solid_num = sizeof(ep_solid)/sizeof(int);
515 static int ep_massiv[] =
533 static int ep_massiv_num = sizeof(ep_massiv)/sizeof(int);
535 static int ep_slippery[] =
552 static int ep_slippery_num = sizeof(ep_slippery)/sizeof(int);
554 static int ep_enemy[] =
562 static int ep_enemy_num = sizeof(ep_enemy)/sizeof(int);
564 static int ep_can_fall[] =
577 static int ep_can_fall_num = sizeof(ep_can_fall)/sizeof(int);
579 static int ep_can_smash[] =
594 static int ep_can_smash_num = sizeof(ep_can_smash)/sizeof(int);
596 static int ep_can_change[] =
602 static int ep_can_change_num = sizeof(ep_can_change)/sizeof(int);
604 static int ep_can_move[] =
612 static int ep_can_move_num = sizeof(ep_can_move)/sizeof(int);
614 static int ep_could_move[] =
629 static int ep_could_move_num = sizeof(ep_could_move)/sizeof(int);
631 static int ep_dont_touch[] =
636 static int ep_dont_touch_num = sizeof(ep_dont_touch)/sizeof(int);
638 static int ep_dont_go_to[] =
648 static int ep_dont_go_to_num = sizeof(ep_dont_go_to)/sizeof(int);
650 static long ep_bit[] =
669 static int *ep_array[] =
688 static int *ep_num[] =
707 static int num_properties = sizeof(ep_num)/sizeof(int *);
709 for(i=0;i<MAX_ELEMENTS;i++)
710 Elementeigenschaften[i] = 0;
712 for(i=0;i<num_properties;i++)
713 for(j=0;j<*(ep_num[i]);j++)
714 Elementeigenschaften[(ep_array[i])[j]] |= ep_bit[i];
715 for(i=EL_CHAR_START;i<EL_CHAR_END;i++)
716 Elementeigenschaften[i] |= EP_BIT_CHAR;
723 if (sound_process_id)
726 kill(sound_process_id, SIGTERM);
727 FreeSounds(NUM_SOUNDS);
730 for(i=0;i<NUM_PIXMAPS;i++)
734 if (i<NUM_PICTURES) /* XPM pictures */
736 XFreeColors(display,DefaultColormap(display,screen),
737 xpm_att[i].pixels,xpm_att[i].npixels,0);
738 XpmFreeAttributes(&xpm_att[i]);
740 XFreePixmap(display,pix[i]);
743 XFreePixmap(display,clipmask[i]);
745 XFreeGC(display, clip_gc[i]);
749 XFreeGC(display, gc);
751 XFreeGC(display, plane_gc);
753 XCloseDisplay(display);