1
2 /*
3 xskat - a card game for 1 to 3 players.
4 Copyright (C) 2004 Gunter Gerhardt
5
6 This program is free software; you can redistribute it freely.
7 Use it at your own risk; there is NO WARRANTY.
8
9 Redistribution of modified versions is permitted
10 provided that the following conditions are met:
11 1. All copyright & permission notices are preserved.
12 2.a) Only changes required for packaging or porting are made.
13 or
14 2.b) It is clearly stated who last changed the program.
15 The program is renamed or
16 the version number is of the form x.y.z,
17 where x.y is the version of the original program
18 and z is an arbitrary suffix.
19 */
20
21 #define XIO_C
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <signal.h>
27 #include <unistd.h>
28 #include <ctype.h>
29 #include <pwd.h>
30 #include <sys/time.h>
31 #include <sys/types.h>
32 #ifdef __EMX__ /* XFree OS/2 */
33 #include <sys/select.h>
34 #endif
35 #include <sys/utsname.h>
36 #include <X11/Xlib.h>
37 #include <X11/X.h>
38 #include <X11/Xutil.h>
39 #include <X11/cursorfont.h>
40 #include <X11/Xatom.h>
41 #include "defs.h"
42 #include "skat.h"
43 #include "bitmaps.h"
44 #include "xio.h"
45 #include "irc.h"
46 #include "text.h"
47
change_gc(sn,fg,gcp)48 VOID change_gc(sn,fg,gcp)
49 int sn;
50 unsigned long fg;
51 GC *gcp;
52 {
53 XGCValues gcv;
54
55 gcv.foreground=fg;
56 XChangeGC(dpy[sn],gcp[sn],GCForeground,&gcv);
57 }
58
change_gcbg(sn,bg,gcp)59 VOID change_gcbg(sn,bg,gcp)
60 int sn;
61 unsigned long bg;
62 GC *gcp;
63 {
64 XGCValues gcv;
65
66 gcv.background=bg;
67 XChangeGC(dpy[sn],gcp[sn],GCBackground,&gcv);
68 }
69
change_gcxor(sn,fg)70 VOID change_gcxor(sn,fg)
71 int sn;
72 unsigned long fg;
73 {
74 change_gc(sn,fg^bgpix[sn],gcxor);
75 }
76
istrue(s)77 int istrue(s)
78 char *s;
79 {
80 char h[5];
81 int i;
82
83 for (i=0;i<4 && *s;i++,s++) {
84 h[i]=tolower(*s);
85 }
86 h[i]=0;
87 return h[0]=='0'?0:h[0]=='1'?1:!strcmp(h,"true");
88 }
89
v_gtextnc(sn,n,c,x,y,w,t)90 VOID v_gtextnc(sn,n,c,x,y,w,t)
91 int sn,n,c,x,y,w;
92 char *t;
93 {
94 int l;
95
96 l=strlen(t);
97 if (n) x+=(w-XTextWidth(dfont[sn],t,l))/2;
98 y+=(charh[sn]+dfont[sn]->ascent-dfont[sn]->descent)/2+1-gfx3d[sn];
99 if (c) {
100 change_gcbg(sn,btpix[sn],gc);
101 }
102 XDrawImageString(dpy[sn],win[sn],gc[sn],x,y,t,l);
103 XDrawImageString(dpy[sn],bck[sn],gc[sn],x,y,t,l);
104 if (c) {
105 change_gcbg(sn,bgpix[sn],gc);
106 }
107 }
108
v_gtextc(sn,c,x,y,w,t)109 VOID v_gtextc(sn,c,x,y,w,t)
110 int sn,c,x,y,w;
111 char *t;
112 {
113 v_gtextnc(sn,1,c,x,y,w,t);
114 }
115
v_gtext(sn,x,y,w,t)116 VOID v_gtext(sn,x,y,w,t)
117 int sn,x,y,w;
118 char *t;
119 {
120 v_gtextc(sn,0,x,y,w,t);
121 }
122
clr_text(sn,x,y)123 VOID clr_text(sn,x,y)
124 int sn,x,y;
125 {
126 x+=4;
127 y++;
128 change_gc(sn,btpix[sn],gc);
129 XFillRectangle(dpy[sn],win[sn],gc[sn],x,y,
130 64*desk[sn].f/desk[sn].q-8,charh[sn]-2);
131 XFillRectangle(dpy[sn],bck[sn],gc[sn],x,y,
132 64*desk[sn].f/desk[sn].q-8,charh[sn]-2);
133 change_gc(sn,fgpix[sn],gc);
134 }
135
b_text(s,str)136 VOID b_text(s,str)
137 int s;
138 tx_typ *str;
139 {
140 int sn,x;
141
142 for (sn=0;sn<numsp;sn++) {
143 if (sn!=s) {
144 x=s==left(sn)?desk[sn].cbox1x:desk[sn].cbox2x;
145 clr_text(sn,x,desk[sn].cboxy);
146 v_gtextc(sn,1,x,desk[sn].cboxy,desk[sn].cardw,str->t[lang[sn]]);
147 }
148 }
149 }
150
do_msaho(sn,str)151 VOID do_msaho(sn,str)
152 int sn;
153 char *str;
154 {
155 clr_text(sn,desk[sn].pboxx,desk[sn].pboxy);
156 v_gtextc(sn,1,desk[sn].pboxx,desk[sn].pboxy,desk[sn].cardw,str);
157 clr_text(sn,desk[sn].pboxx+desk[sn].cardw,desk[sn].pboxy);
158 v_gtextc(sn,1,desk[sn].pboxx+desk[sn].cardw,desk[sn].pboxy,desk[sn].cardw,
159 textarr[TX_PASSE].t[lang[sn]]);
160 }
161
draw_skat(sn)162 VOID draw_skat(sn)
163 int sn;
164 {
165 putcard(sn,cards[30],desk[sn].skatx,desk[sn].skaty);
166 putcard(sn,cards[31],desk[sn].skatx+desk[sn].cardw,
167 desk[sn].skaty);
168 skatopen=1;
169 }
170
home_skat()171 VOID home_skat()
172 {
173 int sn=spieler;
174
175 homecard(sn,0,0);
176 homecard(sn,0,1);
177 umdrueck=skatopen=0;
178 backopen[0]=backopen[1]=backopen[2]=1;
179 spitzeopen=1;
180 }
181
nimm_stich()182 VOID nimm_stich()
183 {
184 int sn=ausspl,i;
185
186 for (i=0;i<3;i++) {
187 homecard(sn,1,i);
188 }
189 stichopen=0;
190 }
191
drop_card(i,s)192 VOID drop_card(i,s)
193 int i,s;
194 {
195 int sn,sna[3],x1[3],y1[3],x2[3],y2[3];
196 static int l2r[3];
197
198 if (stich==10) backopen[s]=0;
199 for (sn=0;sn<numsp;sn++) {
200 sna[sn]=sn;
201 if (s==left(sn)) {
202 x1[sn]=desk[sn].com1x;
203 y1[sn]=desk[sn].com1y;
204 }
205 else {
206 x1[sn]=desk[sn].com2x;
207 y1[sn]=desk[sn].com2y;
208 }
209 if (sn==s || (ouveang && s==spieler)) {
210 x1[sn]=desk[sn].playx+(i%10)*desk[sn].cardx;
211 if (sn==s) y1[sn]=desk[sn].playy;
212 putdesk(sn,x1[sn],y1[sn]);
213 }
214 else if (stich==10) {
215 putdesk(sn,x1[sn],y1[sn]);
216 if (s==spieler) spitzeopen=0;
217 }
218 else if (spitzeang && cards[i]==(trumpf==4?BUBE:SIEBEN|trumpf<<3)) {
219 putback(sn,x1[sn],y1[sn]);
220 spitzeopen=0;
221 sptzmrk=1;
222 putamark(sn,spieler);
223 }
224 if (!vmh) l2r[sn]=trickl2r[sn];
225 x2[sn]=desk[sn].stichx+
226 (l2r[sn]?vmh:s==left(sn)?0:s==sn?1:2)*desk[sn].cardw;
227 y2[sn]=desk[sn].stichy;
228 }
229 movecard(numsp,sna,x1,y1,x2,y2);
230 for (sn=0;sn<numsp;sn++) {
231 putcard(sn,cards[i],x2[sn],desk[sn].stichy);
232 }
233 stcd[vmh]=cards[i];
234 stichopen=vmh+1;
235 gespcd[cards[i]]=2;
236 if ((cards[i]&7)!=BUBE) gespfb[cards[i]>>3]++;
237 cards[i]=-1;
238 stdwait();
239 }
240
query_err(d,e)241 int query_err(d,e)
242 Display *d;
243 XErrorEvent *e;
244 {
245 colerr=1;
246 return 0;
247 }
248
closest_col(sn,xcol)249 int closest_col(sn,xcol)
250 int sn;
251 XColor *xcol;
252 {
253 static int f[3];
254 static XColor xcm[3][256];
255 int i,j,k,pl;
256 long r,g,b;
257 int ps[9],sp;
258
259 if (XAllocColor(dpy[sn],cmap[sn],xcol)) return 1;
260 pl=desk[sn].plan;
261 if (pl<2 || pl>8 || wpix[sn]>=1<<pl || bpix[sn]>=1<<pl) return 0;
262 if (!f[sn]) {
263 for (i=0;i<256;i++) xcm[sn][i].pixel=i;
264 colerr=0;
265 XSetErrorHandler(query_err);
266 XQueryColors(dpy[sn],cmap[sn],xcm[sn],1<<pl);
267 XSync(dpy[sn],0);
268 XSetErrorHandler(NULL);
269 if (colerr) return 0;
270 f[sn]=1;
271 }
272 r=xcol->red;
273 g=xcol->green;
274 b=xcol->blue;
275 for (sp=0;sp<(1<<pl)/32+1;sp++) {
276 j=0;
277 for (k=0;k<sp;k++) {
278 if (ps[k]==j) {
279 j++;
280 k=-1;
281 }
282 }
283 for (i=j+1;i<1<<pl;i++) {
284 if (abs(xcm[sn][i].red-r)+
285 abs(xcm[sn][i].green-g)+
286 abs(xcm[sn][i].blue-b)<
287 abs(xcm[sn][j].red-r)+
288 abs(xcm[sn][j].green-g)+
289 abs(xcm[sn][j].blue-b)) {
290 for (k=0;k<sp && ps[k]!=i;k++);
291 if (k==sp) j=i;
292 }
293 }
294 xcol->red=xcm[sn][j].red;
295 xcol->green=xcm[sn][j].green;
296 xcol->blue=xcm[sn][j].blue;
297 if (XAllocColor(dpy[sn],cmap[sn],xcol)) return 1;
298 ps[sp]=j;
299 }
300 return 0;
301 }
302
get_col(sn,ucol,prog,col,defcol,defpix,xcol)303 unsigned long get_col(sn,ucol,prog,col,defcol,defpix,xcol)
304 int sn;
305 char *ucol,*prog,*col,*defcol;
306 unsigned long defpix;
307 XColor *xcol;
308 {
309 char *spec;
310
311 spec=XGetDefault(dpy[sn],prog,col);
312 if ((ucol && XParseColor(dpy[sn],cmap[sn],ucol,xcol) &&
313 closest_col(sn,xcol)) ||
314 (spec && XParseColor(dpy[sn],cmap[sn],spec,xcol) &&
315 closest_col(sn,xcol)) ||
316 (defcol && XParseColor(dpy[sn],cmap[sn],defcol,xcol) &&
317 closest_col(sn,xcol))) {
318 if (desk[sn].col>2) {
319 color[sn][desk[sn].col++]=*xcol;
320 }
321 return xcol->pixel;
322 }
323 xcol->pixel=defpix;
324 XQueryColor(dpy[sn],cmap[sn],xcol);
325 return defpix;
326 }
327
calc_desk(sn)328 VOID calc_desk(sn)
329 int sn;
330 {
331 desk[sn].x=0;
332 desk[sn].y=0;
333 desk[sn].cardw=desk[sn].large?96:64;
334 desk[sn].cardh=desk[sn].large?141:94;
335 desk[sn].f=desk[sn].large?3:1;
336 desk[sn].q=desk[sn].large?2:1;
337 desk[sn].w=10*desk[sn].cardw;
338 desk[sn].h=desk[sn].large?600:400;
339 desk[sn].com1x=desk[sn].x+desk[sn].cardw;
340 desk[sn].com2x=desk[sn].x+desk[sn].w-2*desk[sn].cardw;
341 desk[sn].com1y=desk[sn].com2y=desk[sn].y+3;
342 if (ouveang && sn!=spieler) {
343 if (spieler==left(sn)) {
344 desk[sn].com2y+=desk[sn].cardh+11*desk[sn].f/desk[sn].q;
345 }
346 else {
347 desk[sn].com1y+=desk[sn].cardh+11*desk[sn].f/desk[sn].q;
348 }
349 }
350 desk[sn].cardx=(desk[sn].w-desk[sn].cardw)/9;
351 desk[sn].playx=desk[sn].x+(desk[sn].w-desk[sn].cardw-9*desk[sn].cardx)/2;
352 desk[sn].playy=desk[sn].y+desk[sn].h-desk[sn].cardh-2;
353 desk[sn].skatx=desk[sn].x+(desk[sn].w-2*desk[sn].cardw)/2;
354 desk[sn].skaty=desk[sn].y+desk[sn].cardh+51*desk[sn].f/desk[sn].q;
355 desk[sn].stichx=desk[sn].x+(desk[sn].w-3*desk[sn].cardw)/2;
356 desk[sn].stichy=desk[sn].skaty;
357 desk[sn].cbox1x=desk[sn].com1x;
358 desk[sn].cbox2x=desk[sn].com2x;
359 desk[sn].cboxy=desk[sn].com1y+desk[sn].cardh+11*desk[sn].f/desk[sn].q;
360 desk[sn].pboxx=desk[sn].skatx;
361 desk[sn].pboxy=desk[sn].skaty+desk[sn].cardh+13*desk[sn].f/desk[sn].q;
362 }
363
364
extractnam(sn,str)365 VOID extractnam(sn,str)
366 int sn;
367 char *str;
368 {
369 int ln;
370
371 for (ln=0;ln<NUM_LANG;ln++) {
372 extractnamln(sn,str,ln);
373 }
374 }
375
extractnamln(sn,str,ln)376 VOID extractnamln(sn,str,ln)
377 int sn;
378 char *str;
379 int ln;
380 {
381 char *eos;
382 int z,s;
383
384 spnames[sn][0][ln][0]=0;
385 spnames[sn][1][ln][0]=0;
386 if (!str) str="";
387 if (!(eos=strchr(str,'@')) && !(eos=strchr(str,':'))) eos=str+strlen(str);
388 for (z=0;z<2 && str!=eos;z++) {
389 while (*str==' ' || *str=='~') str++;
390 for (s=0;s<9 && str!=eos && *str!=' ' && *str!='~';s++,str++) {
391 spnames[sn][z][ln][s]=*str;
392 }
393 spnames[sn][z][ln][s]=0;
394 }
395 }
396
usage()397 VOID usage()
398 {
399 fprintf(stderr,"\
400 xskat [-display|-d display] [-geometry|-g geometry] [-font|-fn font]\n\
401 [-iconic|-i] [-title|-T string] [-name prog] [-fg color] [-bg color]\n\
402 [-bt color] [-3d] [-2d] [-3dtop color] [-3dbot color] [-mark color]\n\
403 [-mb button] [-keyboard 0..2] [-tdelay sec] [-fastdeal] [-slowdeal]\n\
404 [-help|-h] [-frenchcards] [-french4cards] [-germancards] [-german4cards]\n\
405 [-color] [-mono] [-color1 color] .. [-color4 color] [-large] [-small]\n\
406 [-up] [-down] [-alt] [-seq] [-list|-l filename] [-alist] [-nlist] [-tlist]\n\
407 [-log filename] [-dolog] [-nolog] [-fmt] [-unfmt] [-game filename]\n\
408 [-briefmsg] [-verbosemsg] [-trickl2r] [-notrickl2r]\n\
409 [-lang language] [-start player#] [-s1 -4..4] [-s2 -4..4] [-s3 -4..4]\n\
410 [-ramsch] [-noramsch] [-ramschonly] [-sramsch] [-nosramsch]\n\
411 [-skattolast] [-skattoloser]\n\
412 [-kontra] [-nokontra] [-kontra18] [-bock] [-nobock] [-bockramsch]\n\
413 [-bockevents 1..255] [-resumebock] [-noresumebock]\n\
414 [-spitze] [-spitze2] [-nospitze] [-revolution] [-norevolution]\n\
415 [-klopfen] [-noklopfen] [-schenken] [-noschenken] [-hint] [-nohint]\n\
416 [-newrules] [-oldrules] [-shortcut] [-noshortcut] [-askshortcut]\n\
417 [-irc] [-noirc] [-irctelnet program] [-ircserver host]\n\
418 [-ircport number] [-ircchannel name] [-ircnick name] [-ircuser name]\n\
419 [-ircrealname name] [-ircpos number]\n\
420 [-irclog file] [-irclogappend] [-irclogoverwrite]\n\
421 [-auto #ofgames] [-opt filename] [-pk] [player@display...]\n\
422 After starting the game a mouse click or ESC/F1 will bring up a menu.\n\
423 ");
424 }
425
invopt(opt)426 VOID invopt(opt)
427 char *opt;
428 {
429 fprintf(stderr,"Invalid option %s\n",opt);
430 usage();
431 exitus(1);
432 }
433
nomem()434 VOID nomem()
435 {
436 fprintf(stderr,"Out of memory\n");
437 exitus(1);
438 }
439
finish(sn,ex)440 VOID finish(sn,ex)
441 int sn,ex;
442 {
443 int s;
444
445 quit=1;
446 for (s=0;s<numsp;s++) {
447 di_term(s,sn);
448 }
449 for (s=numsp;s<3;s++) {
450 lost[s]=1;
451 }
452 while (!lost[0] || !lost[1] || !lost[2]) {
453 hndl_events();
454 }
455 if (ex) exitus(1);
456 }
457
ioerr(d)458 int ioerr(d)
459 Display *d;
460 {
461 int sn,es=0;
462
463 for (sn=0;sn<numsp;sn++) {
464 if (dpy[sn]==d) lost[es=sn]=1;
465 }
466 if (irc_play) exitus(0);
467 finish(es,1);
468 return 0;
469 }
470
exitus(n)471 VOID exitus(n)
472 int n;
473 {
474 if (irc_telnetpid) {
475 kill(irc_telnetpid,SIGHUP);
476 }
477 exit(n);
478 }
479
startirc(f)480 VOID startirc(f)
481 int f;
482 {
483 char *argv[100];
484 int i,j;
485
486 j=0;
487 if (f) {
488 argv[j++]="xterm";
489 argv[j++]="-e";
490 }
491 for (i=j;i<90 && i-j<theargc;i++) {
492 argv[i]=theargv[i-j];
493 }
494 if (f) {
495 argv[i++]="-irc";
496 }
497 else {
498 if (irc_telnetpid) {
499 kill(irc_telnetpid,SIGHUP);
500 }
501 }
502 argv[i]=0;
503 execvp(argv[0],argv);
504 fprintf(stderr,"%s not found\n",argv[0]);
505 exitus(0);
506 }
507
getdeffn(prog_name,pfn,res,suf)508 int getdeffn(prog_name,pfn,res,suf)
509 char *prog_name,**pfn,*res,*suf;
510 {
511 char *home,*fn,*rfn;
512 int r;
513
514 home=getenv("HOME");
515 fn=XGetDefault(dpy[0],prog_name,res);
516 if (fn && !strncmp(fn,"~/",2)) {
517 if (home && (rfn=malloc(strlen(home)+strlen(fn)))) {
518 strcpy(rfn,home);
519 strcat(rfn,fn+1);
520 fn=rfn;
521 }
522 }
523 r=1;
524 if (!fn) {
525 r=0;
526 if (home && (fn=malloc(strlen(home)+3+strlen(suf)))) {
527 strcpy(fn,home);
528 strcat(fn,"/.");
529 strcat(fn,suf);
530 }
531 else {
532 fn=suf;
533 }
534 }
535 *pfn=fn;
536 return r;
537 }
538
logit()539 VOID logit()
540 {
541 #ifdef LOGDIR
542 FILE *f;
543 char logf[1000];
544 struct passwd *pwd;
545 struct utsname uts;
546
547 sprintf(logf,"%s/%lu",LOGDIR,(unsigned long)getuid());
548 f=fopen(logf,"w");
549 if (f) {
550 if (pwd=getpwuid(getuid())) {
551 if (pwd->pw_name) fputs(pwd->pw_name,f);
552 if (pwd->pw_gecos) fprintf(f,"(%s)",pwd->pw_gecos);
553 }
554 if (!uname(&uts)) {
555 fprintf(f,"@%s",uts.nodename);
556 #ifndef __hpux
557 fprintf(f,".%s",uts.domainname);
558 #endif
559 fprintf(f,"(%s",uts.sysname);
560 fprintf(f,",%s)",uts.machine);
561 }
562 fputc('\n',f);
563 fclose(f);
564 }
565 #endif
566 }
567
getcode(bpos,csiz,msk,thegif)568 int getcode(bpos,csiz,msk,thegif)
569 int *bpos,csiz,msk;
570 unsigned char *thegif;
571 {
572 int pos;
573 long c;
574
575 pos=*bpos>>3;
576 c=thegif[pos]+(thegif[pos+1]<<8);
577 if (csiz>=8) c+=(long)thegif[pos+2]<<16;
578 c>>=*bpos&7;
579 *bpos+=csiz;
580 return c&msk;
581 }
582
decompgif(thedata,thepic,themap,cmapsize)583 VOID decompgif(thedata,thepic,themap,cmapsize)
584 unsigned char *thedata,*thepic,**themap;
585 int *cmapsize;
586 {
587 unsigned char b,*p;
588 int i,bpos,cnt,csiz,isiz,cd,mc,cc,ec;
589 int ac,pc,ic,ff,fc,lc,bmsk,msk;
590 static int a[4096],e[4096],c[4097];
591 static unsigned char thegif[138*88];
592
593 bpos=cnt=pc=lc=0;
594 thedata+=10;
595 *cmapsize=1<<((*thedata++&7)+1);
596 bmsk=*cmapsize-1;
597 thedata+=2;
598 *themap=thedata;
599 thedata+=*cmapsize*3+10;
600 ec=(cc=1<<(csiz=*thedata++))+1;
601 fc=ff=cc+2;
602 isiz=++csiz;
603 msk=(mc=1<<csiz)-1;
604 p=thegif;
605 while ((b=*thedata++)) while (b--) *p++=*thedata++;
606 cd=getcode(&bpos,csiz,msk,thegif);
607 while (cd!=ec) {
608 if (cd==cc) {
609 msk=(mc=1<<(csiz=isiz))-1;
610 fc=ff;
611 ac=pc=cd=getcode(&bpos,csiz,msk,thegif);
612 *thepic++=lc=ac&bmsk;
613 }
614 else {
615 ac=ic=cd;
616 if (ac>=fc) {
617 ac=pc;
618 c[cnt++]=lc;
619 }
620 while (ac>bmsk) {
621 c[cnt++]=e[ac];
622 ac=a[ac];
623 }
624 c[cnt]=lc=ac&bmsk;
625 for (i=cnt;i>=0;i--) *thepic++=c[i];
626 cnt=0;
627 a[fc]=pc;
628 e[fc++]=lc;
629 pc=ic;
630 if (fc>=mc && csiz<12) {
631 msk=(1<<++csiz)-1;
632 mc<<=1;
633 }
634 }
635 cd=getcode(&bpos,csiz,msk,thegif);
636 }
637 }
638
drawimg(sn,c,f,w,x,y)639 VOID drawimg(sn,c,f,w,x,y)
640 int sn,c,f,w,x,y;
641 {
642 long i,j,k;
643 int l,p,r,g,b,m,s,gr,tc,idx,ld,pd,an;
644 static unsigned char thepic[138][88];
645 static int fsdbuf[2][138][3];
646 static int smlbuf[138][3];
647 static int smcbuf[138][3];
648 static XPoint xp[256][32];
649 unsigned long pm[256];
650 static int pc[16][16][16];
651 unsigned char (*themap)[256][3];
652 int xn[256];
653 XColor xc,*xcp;
654 int cmapsize;
655
656 decompgif(f<0?backsd_gif[0]:blatt[sn]>=2?de_gif[f][w]:fr_gif[f][w],
657 (unsigned char *)thepic,(unsigned char **)&themap,&cmapsize);
658 tc=desk[sn].plan>=12 && desk[sn].col>2 && desk[sn].large;
659 xcp=&color[sn][0];
660 if (!tc) {
661 for (i=0;i<=0xffff;i+=0x1111) {
662 for (j=0;j<=0xffff;j+=0x1111) {
663 for (k=0;k<=0xffff;k+=0x1111) {
664 l=0;
665 ld=abs(xcp[l].red-i)+abs(xcp[l].green-j)+abs(xcp[l].blue-k);
666 for (p=1;p<desk[sn].col;p++) {
667 pd=abs(xcp[p].red-i)+abs(xcp[p].green-j)+abs(xcp[p].blue-k);
668 if (pd<ld) {
669 l=p;
670 ld=pd;
671 }
672 }
673 pc[i/0x1111][j/0x1111][k/0x1111]=l;
674 }
675 }
676 }
677 }
678 xcp[desk[sn].col].pixel=wpix[sn];
679 for (i=0;i<256;i++) {
680 xn[i]=0;
681 }
682 if (tc) {
683 for (i=0;i<cmapsize;i++) {
684 xc.red=(*themap)[i][0];
685 xc.green=(*themap)[i][1];
686 xc.blue=(*themap)[i][2];
687 if (blatt[sn]==3 && f==3 && xc.red>220 && xc.green<100 && xc.blue<100) {
688 if (xc.blue<50) xc.blue=50;
689 xc.green+=xc.blue+50;
690 xc.blue=0;
691 }
692 if (xc.red==255 && xc.green==255 && xc.blue==255) {
693 pm[i]=wpix[sn];
694 }
695 else {
696 xc.red<<=8;
697 xc.green<<=8;
698 xc.blue<<=8;
699 pm[i]=closest_col(sn,&xc)?xc.pixel:bpix[sn];
700 }
701 }
702 }
703 if (f<0 || blatt[sn]<2) {
704 gr=f<0;
705 m=0;
706 }
707 else {
708 if (ggcards) {
709 gr=ggde_flg[f][w]>>1;
710 m=ggde_flg[f][w]&1;
711 }
712 else {
713 gr=de_flg[f][w]>>1;
714 m=de_flg[f][w]&1;
715 }
716 }
717 idx=0;
718 for (j=0;j<138;j++) {
719 fsdbuf[idx][j][0]=fsdbuf[idx][j][1]=fsdbuf[idx][j][2]=0;
720 smlbuf[j][0]=-1;
721 smcbuf[j][0]=-1;
722 }
723 idx=1-idx;
724 for (i=(desk[sn].large?87:86+(f<0));i>=0;i--) {
725 s=f<0 && i>43?1:2;
726 k=!i && m?desk[sn].large?88:58:0;
727 if (!desk[sn].large && !((i+s)%3)) {
728 for (j=(gr?137:68);j>=0;j--) {
729 p=thepic[j][i];
730 smlbuf[j][0]=(*themap)[p][0];
731 smlbuf[j][1]=(*themap)[p][1];
732 smlbuf[j][2]=(*themap)[p][2];
733 }
734 continue;
735 }
736 for (j=0;j<138;j++) {
737 fsdbuf[idx][j][0]=fsdbuf[idx][j][1]=fsdbuf[idx][j][2]=0;
738 }
739 idx=1-idx;
740 for (j=(gr?137:68);j>=0;j--) {
741 p=thepic[j][i];
742 if (!desk[sn].large && !((j+2)%3)) {
743 if (j) {
744 smcbuf[j-1][0]=(*themap)[p][0];
745 smcbuf[j-1][1]=(*themap)[p][1];
746 smcbuf[j-1][2]=(*themap)[p][2];
747 fsdbuf[idx][j-1][0]+=fsdbuf[idx][j][0];
748 fsdbuf[idx][j-1][1]+=fsdbuf[idx][j][1];
749 fsdbuf[idx][j-1][2]+=fsdbuf[idx][j][2];
750 }
751 continue;
752 }
753 if (!tc) {
754 r=(*themap)[p][0];
755 g=(*themap)[p][1];
756 b=(*themap)[p][2];
757 an=1;
758 if (smlbuf[j][0]>=0) {
759 r+=smlbuf[j][0];
760 g+=smlbuf[j][1];
761 b+=smlbuf[j][2];
762 smlbuf[j][0]=-1;
763 an++;
764 }
765 if (smcbuf[j][0]>=0) {
766 r+=smcbuf[j][0];
767 g+=smcbuf[j][1];
768 b+=smcbuf[j][2];
769 smcbuf[j][0]=-1;
770 an++;
771 }
772 if (an>1) {
773 r/=an;
774 g/=an;
775 b/=an;
776 }
777 if (blatt[sn]==3 && f==3 && r>220 && g<100 && b<100) {
778 if (b<50) b=50;
779 g+=b+50;
780 b=0;
781 }
782 if (r==255 && g==255 && b==255) {
783 p=desk[sn].col;
784 r=g=b=0;
785 }
786 else {
787 if (desk[sn].col<=2) {
788 if (r>=127) r=r*19/16;
789 if (g>=127) g=g*19/16;
790 if (b>=127) b=b*19/16;
791 }
792 r+=fsdbuf[idx][j][0];
793 if (r<0) r=0;
794 else if (r>255) r=255;
795 g+=fsdbuf[idx][j][1];
796 if (g<0) g=0;
797 else if (g>255) g=255;
798 b+=fsdbuf[idx][j][2];
799 if (b<0) b=0;
800 else if (b>255) b=255;
801 if (desk[sn].col<=2) {
802 if (r<127) r=r*11/16;
803 if (g<127) g=g*11/16;
804 if (b<127) b=b*11/16;
805 }
806 p=pc[r/0x11][g/0x11][b/0x11];
807 r-=xcp[p].red>>8;
808 g-=xcp[p].green>>8;
809 b-=xcp[p].blue>>8;
810 }
811 }
812 else {
813 r=g=b=0;
814 }
815 if (desk[sn].large) {
816 xp[p][xn[p]].x=x+i+1;
817 xp[p][xn[p]].y=y+j+1;
818 xn[p]++;
819 if (!gr) {
820 xp[p][xn[p]].x=x+88-i+m-k;
821 xp[p][xn[p]].y=y+138-j;
822 xn[p]++;
823 }
824 }
825 else {
826 xp[p][xn[p]].x=x+(i+s)*2/3-m+k;
827 xp[p][xn[p]].y=y+(j+2)*2/3;
828 xn[p]++;
829 if (!gr) {
830 xp[p][xn[p]].x=x+59-(i+s)*2/3+m-k;
831 xp[p][xn[p]].y=y+93-(j+2)*2/3;
832 xn[p]++;
833 }
834 }
835 if (j) {
836 fsdbuf[idx][j-1][0]+=r*10/27;
837 fsdbuf[idx][j-1][1]+=g*10/27;
838 fsdbuf[idx][j-1][2]+=b*10/27;
839 fsdbuf[1-idx][j-1][0]+=r-r*20/27;
840 fsdbuf[1-idx][j-1][1]+=g-g*20/27;
841 fsdbuf[1-idx][j-1][2]+=b-b*20/27;
842 }
843 fsdbuf[1-idx][j][0]+=r*10/27;
844 fsdbuf[1-idx][j][1]+=g*10/27;
845 fsdbuf[1-idx][j][2]+=b*10/27;
846 if (xn[p]==32) {
847 change_gc(sn,tc?pm[p]:xcp[p].pixel,gc);
848 XDrawPoints(dpy[sn],cardpx[sn][c+1],gc[sn],xp[p],32,CoordModeOrigin);
849 xn[p]=0;
850 }
851 }
852 }
853 for (p=0;p<256;p++) {
854 if (xn[p]) {
855 change_gc(sn,tc?pm[p]:xcp[p].pixel,gc);
856 XDrawPoints(dpy[sn],cardpx[sn][c+1],gc[sn],xp[p],xn[p],CoordModeOrigin);
857 }
858 }
859 }
860
create_card(sn,c)861 VOID create_card(sn,c)
862 int sn,c;
863 {
864 int i,j,p,x,y,x1,y1,x2,y2,x3,y3,f,pf,upf,w,ww,hh;
865
866 x=2;
867 y=0;
868 f=c>>3;
869 pf=blatt[sn]==1?f==0?4:f==2?5:f:f;
870 upf=desk[sn].col>pf && desk[sn].col>2;
871 w=c&7;
872 XFillRectangle(dpy[sn],cardpx[sn][c+1],gcbck[sn],0,0,
873 desk[sn].cardw,desk[sn].cardh);
874 if (((KOENIG<=w && w<=BUBE) || c<0 || blatt[sn]>=2)) {
875 drawimg(sn,c,c<0?c:f,w-(blatt[sn]>=2?0:KOENIG),x,y);
876 }
877 else {
878 change_gc(sn,wpix[sn],gc);
879 XFillRectangle(dpy[sn],cardpx[sn][c+1],gc[sn],x+1,y+1,
880 60*desk[sn].f/desk[sn].q-2,92*desk[sn].f/desk[sn].q);
881 }
882 change_gc(sn,bpix[sn],gc);
883 if (desk[sn].large) {
884 ww=89;
885 hh=139;
886 }
887 else {
888 ww=59;
889 hh=93;
890 }
891 for (i=(desk[sn].large?8:5);i<(desk[sn].large?82:55);i++) {
892 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+i, y);
893 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+i, y+hh);
894 }
895 for (j=(desk[sn].large?8:5);j<(desk[sn].large?132:89);j++) {
896 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x, y+j);
897 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+ww, y+j);
898 }
899 for (i=0;i<(desk[sn].large?9:5);i++) {
900 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn],
901 x+frm[desk[sn].large][i][0], y+frm[desk[sn].large][i][1]);
902 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn],
903 x+ww-frm[desk[sn].large][i][0], y+hh-frm[desk[sn].large][i][1]);
904 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn],
905 x+frm[desk[sn].large][i][0], y+hh-frm[desk[sn].large][i][1]);
906 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn],
907 x+ww-frm[desk[sn].large][i][0], y+frm[desk[sn].large][i][1]);
908 }
909 change_gc(sn,bgpix[sn],gc);
910 for (i=1;i<(desk[sn].large?5:3);i++) {
911 for (j=1;j<(desk[sn].large?6:4)-i;j++) {
912 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+i, y+j);
913 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+ww-i, y+hh-j);
914 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+i, y+hh-j);
915 XDrawPoint(dpy[sn],cardpx[sn][c+1], gc[sn], x+ww-i, y+j);
916 }
917 }
918 change_gc(sn,fgpix[sn],gc);
919 if (c>=0) {
920 if (blatt[sn]<2) {
921 change_gcxor(sn,(upf?color[sn][pf].pixel:bpix[sn])^
922 wpix[sn]^bgpix[sn]);
923 p=cnts[w];
924 do {
925 x1=f*16*desk[sn].f/desk[sn].q;
926 y1=0;
927 if (bigs[p+1]>70) x1+=64*desk[sn].f/desk[sn].q;
928 x2=x1+16*desk[sn].f/desk[sn].q;
929 y2=y1+16*desk[sn].f/desk[sn].q;
930 x3=bigs[p++];
931 y3=bigs[p++];
932 if (!desk[sn].large) {
933 x3=x3*2/3+(KOENIG<=w && w<=BUBE && p-2!=cnts[w]?1:0);
934 y3=y3*2/3+(KOENIG<=w && w<=BUBE && p-2!=cnts[w]?1:0);
935 }
936 if (upf) {
937 XCopyPlane(dpy[sn],symbs[sn],cardpx[sn][c+1],gcxor[sn],
938 x1+2*desk[sn].cardw,y1,x2-x1,y2-y1,x+x3,y+y3,1);
939 }
940 else {
941 XCopyPlane(dpy[sn],symbs[sn],cardpx[sn][c+1],gcxor[sn],
942 x1,y1,x2-x1,y2-y1,x+x3,y+y3,1);
943 }
944 } while (p!=cnts[w+1]);
945 }
946 else {
947 change_gcxor(sn,bpix[sn]^wpix[sn]^bgpix[sn]);
948 }
949 for (p=0;p<8;p+=2) {
950 if (blatt[sn]<2) {
951 x1=f*8*desk[sn].f/desk[sn].q;
952 y1=16*desk[sn].f/desk[sn].q;
953 if (smls[p+1]>50) x1+=32*desk[sn].f/desk[sn].q;
954 x2=x1+8*desk[sn].f/desk[sn].q;
955 y2=y1+8*desk[sn].f/desk[sn].q;
956 if (KOENIG<=w && w<=BUBE) {
957 x3=smls[p];
958 y3=smls[p+1];
959 }
960 else {
961 x3=smlz[p];
962 y3=smlz[p+1]+(!desk[sn].large && p>3?1:0);
963 }
964 if (!desk[sn].large) {
965 x3=x3*2/3+(p&2?1:0);
966 y3=y3*2/3+(p>3?1:0);
967 }
968 if (upf) {
969 XCopyPlane(dpy[sn],symbs[sn],cardpx[sn][c+1],gcxor[sn],
970 x1+2*desk[sn].cardw,y1,x2-x1,y2-y1,x+x3,y+y3,1);
971 }
972 else {
973 XCopyPlane(dpy[sn],symbs[sn],cardpx[sn][c+1],gcxor[sn],
974 x1,y1,x2-x1,y2-y1,x+x3,y+y3,1);
975 }
976 }
977 if (blatt[sn]<2) {
978 x1=256+(w==AS?lang[sn]*20:w==ZEHN?p>3?23:0:w<=BUBE?
979 (w-KOENIG+1)*5+lang[sn]*20:(p>3?31:8)+(w-NEUN)*5);
980 }
981 else {
982 x1=256+(w==ZEHN?p>3?23:0:w<=BUBE?(w-KOENIG+1)*5+35:
983 (p>3?31:8)+(w-NEUN)*5);
984 }
985 x1=x1*desk[sn].f/desk[sn].q;
986 y1=(w!=ZEHN && w<=BUBE?p>3?7:0:14)+1;
987 y1=y1*desk[sn].f/desk[sn].q;
988 x2=x1+(w==ZEHN?8:5)*desk[sn].f/desk[sn].q;
989 y2=y1+7*desk[sn].f/desk[sn].q;
990 x3=smlc[p]-(w==ZEHN?p&2?4:2:0);
991 y3=smlc[p+1];
992 if (!desk[sn].large) {
993 x3=x3*2/3+(w==ZEHN?p&2?0:2:0);
994 y3=y3*2/3+(p>3?1:0);
995 }
996 if (blatt[sn]<2 || w!=AS) {
997 XCopyPlane(dpy[sn],symbs[sn],cardpx[sn][c+1],gcxor[sn],
998 x1,y1,x2-x1,y2-y1,x+x3,y+y3,1);
999 }
1000 }
1001 }
1002 change_gcxor(sn,fgpix[sn]);
1003 }
1004
xinitwin(sn,argc,argv)1005 VOID xinitwin(sn,argc,argv)
1006 int sn,argc;
1007 char **argv;
1008 {
1009 Pixmap icon,iconmask;
1010 XClassHint classhint;
1011 XGCValues gcv;
1012 int i,gcvf;
1013 GC igc[3];
1014
1015 win[sn]=XCreateSimpleWindow(dpy[sn],DefaultRootWindow(dpy[sn]),
1016 desk[sn].x,desk[sn].y,desk[sn].w,desk[sn].h,
1017 0,fgpix[sn],bgpix[sn]);
1018 cursor[sn][0]=XCreateFontCursor(dpy[sn],XC_hand2);
1019 cursor[sn][1]=XCreateFontCursor(dpy[sn],XC_watch);
1020 XDefineCursor(dpy[sn],win[sn],cursor[sn][1]);
1021 gcvf=GCGraphicsExposures|GCForeground|GCBackground;
1022 gcv.graphics_exposures=False;
1023 gcv.font=dfont[sn]->fid;
1024 gcv.foreground=fgpix[sn];
1025 gcv.background=bgpix[sn];
1026 gc[sn]=XCreateGC(dpy[sn],win[sn],gcvf|GCFont,&gcv);
1027 gcv.foreground=bgpix[sn];
1028 gcv.background=fgpix[sn];
1029 gcbck[sn]=XCreateGC(dpy[sn],win[sn],gcvf,&gcv);
1030 gcv.foreground=fgpix[sn]^bgpix[sn];
1031 gcv.background=0;
1032 gcv.function=GXxor;
1033 gcxor[sn]=XCreateGC(dpy[sn],win[sn],gcvf|GCFunction,&gcv);
1034 symbs[sn]=XCreateBitmapFromData(dpy[sn],win[sn],(char *)symbs_bits,
1035 symbs_width,symbs_height);
1036 if (symbs[sn]==None) nomem();
1037 if (desk[sn].col>3) {
1038 icon=XCreatePixmap(dpy[sn],win[sn],icon_width,icon_height,desk[sn].plan);
1039 iconmask=XCreatePixmap(dpy[sn],win[sn],icon_width,icon_height,1);
1040 if (icon==None || iconmask==None) nomem();
1041 gcv.foreground=0;
1042 gcv.background=0;
1043 igc[sn]=XCreateGC(dpy[sn],iconmask,gcvf,&gcv);
1044 XFillRectangle(dpy[sn],iconmask,igc[sn],0,0,icon_width,icon_height);
1045 change_gc(sn,1,igc);
1046 XCopyPlane(dpy[sn],symbs[sn],iconmask,igc[sn],128,0,16,16,1,1,1);
1047 XCopyPlane(dpy[sn],symbs[sn],iconmask,igc[sn],128+16,0,16,16,16,16,1);
1048 XCopyPlane(dpy[sn],symbs[sn],iconmask,igc[sn],128+32,0,16,16,16,1,1);
1049 XCopyPlane(dpy[sn],symbs[sn],iconmask,igc[sn],128+48,0,16,16,1,16,1);
1050 XFreeGC(dpy[sn],igc[sn]);
1051 wmhints.flags|=IconMaskHint;
1052 wmhints.icon_mask=iconmask;
1053 change_gc(sn,wpix[sn],gc);
1054 XFillRectangle(dpy[sn],icon,gc[sn],0,0,icon_width,icon_height);
1055 change_gcxor(sn,color[sn][0].pixel^wpix[sn]^bgpix[sn]);
1056 XCopyPlane(dpy[sn],symbs[sn],icon,gcxor[sn],128,0,16,16,1,1,1);
1057 change_gcxor(sn,color[sn][1].pixel^wpix[sn]^bgpix[sn]);
1058 XCopyPlane(dpy[sn],symbs[sn],icon,gcxor[sn],128+16,0,16,16,16,16,1);
1059 change_gcxor(sn,color[sn][2].pixel^wpix[sn]^bgpix[sn]);
1060 XCopyPlane(dpy[sn],symbs[sn],icon,gcxor[sn],128+32,0,16,16,16,1,1);
1061 change_gcxor(sn,color[sn][3].pixel^wpix[sn]^bgpix[sn]);
1062 XCopyPlane(dpy[sn],symbs[sn],icon,gcxor[sn],128+48,0,16,16,1,16,1);
1063 change_gcxor(sn,fgpix[sn]);
1064 change_gc(sn,fgpix[sn],gc);
1065 }
1066 else {
1067 icon=XCreateBitmapFromData(dpy[sn],DefaultRootWindow(dpy[sn]),
1068 (char *)icon_bits,
1069 icon_width,icon_height);
1070 if (icon==None) nomem();
1071 }
1072 classhint.res_name=prog_name;
1073 classhint.res_class=prog_name;
1074 XSetClassHint(dpy[sn],win[sn],&classhint);
1075 XSetStandardProperties(dpy[sn],win[sn],title[sn],title[sn],icon,
1076 argv,argc,&szhints[sn]);
1077 #ifdef PWinGravity
1078 szhints[sn].win_gravity=
1079 (geom_f[sn]&XNegative?
1080 (geom_f[sn]&YNegative?
1081 SouthEastGravity:NorthEastGravity):
1082 (geom_f[sn]&YNegative?
1083 SouthWestGravity:NorthWestGravity));
1084 szhints[sn].flags|=PWinGravity;
1085 XSetWMNormalHints(dpy[sn],win[sn],&szhints[sn]);
1086 #endif
1087 if (szhints[sn].flags&USPosition) {
1088 XMoveWindow(dpy[sn],win[sn],szhints[sn].x,szhints[sn].y);
1089 }
1090 wmhints.flags|=IconPixmapHint;
1091 wmhints.icon_pixmap=icon;
1092 XSetWMHints(dpy[sn],win[sn],&wmhints);
1093 if (desk[sn].large) {
1094 XFreePixmap(dpy[sn],symbs[sn]);
1095 symbs[sn]=XCreateBitmapFromData(dpy[sn],win[sn],(char *)symbl_bits,
1096 symbl_width,symbl_height);
1097 if (symbs[sn]==None) nomem();
1098 }
1099 bck[sn]=XCreatePixmap(dpy[sn],win[sn],desk[sn].w,desk[sn].h,desk[sn].plan);
1100 if (bck[sn]==None) nomem();
1101 for (i=0;i<33;i++) {
1102 cardpx[sn][i]=XCreatePixmap(dpy[sn],win[sn],
1103 desk[sn].cardw,desk[sn].cardh,
1104 desk[sn].plan);
1105 if (cardpx[sn][i]==None) nomem();
1106 create_card(sn,i-1);
1107 }
1108 XFillRectangle(dpy[sn],win[sn],gcbck[sn],0,0,desk[sn].w,desk[sn].h);
1109 XFillRectangle(dpy[sn],bck[sn],gcbck[sn],0,0,desk[sn].w,desk[sn].h);
1110 if (!irc_play || irc_pos==sn) {
1111 XSelectInput(dpy[sn],win[sn],ButtonPressMask|ExposureMask|
1112 KeyPressMask|KeyReleaseMask);
1113 XMapWindow(dpy[sn],win[sn]);
1114 }
1115 }
1116
xinitplayers()1117 VOID xinitplayers()
1118 {
1119 int sn;
1120
1121 for (sn=1;sn<3;sn++) {
1122 disp_name[sn]=disp_name[0];
1123 dpy[sn]=dpy[0];
1124 cmap[sn]=cmap[0];
1125 desk[sn]=desk[0];
1126 bpix[sn]=bpix[0];
1127 wpix[sn]=wpix[0];
1128 bgpix[sn]=bgpix[0];
1129 fgpix[sn]=fgpix[0];
1130 btpix[sn]=btpix[0];
1131 mkpix[sn]=mkpix[0];
1132 w3dpix[sn]=w3dpix[0];
1133 b3dpix[sn]=b3dpix[0];
1134 gfx3d[sn]=gfx3d[0];
1135 memcpy((VOID *)color[sn],(VOID *)color[0],sizeof(color[0]));
1136 title[sn]=title[0];
1137 dfont[sn]=dfont[0];
1138 charw[sn]=charw[0];
1139 charh[sn]=charh[0];
1140 useoptfile[sn]=useoptfile[0];
1141 mbutton[sn]=mbutton[0];
1142 keyboard[sn]=keyboard[0];
1143 abkuerz[sn]=abkuerz[0];
1144 nimmstich[sn][0]=nimmstich[0][0];
1145 sort1[sn]=sort1[0];
1146 alternate[sn]=alternate[0];
1147 alist[sn]=alist[0];
1148 hints[sn]=hints[0];
1149 blatt[sn]=blatt[0];
1150 lang[sn]=lang[0];
1151 briefmsg[sn]=briefmsg[0];
1152 trickl2r[sn]=trickl2r[0];
1153 geom_f[sn]=geom_f[0];
1154 geom_x[sn]=geom_x[0];
1155 geom_y[sn]=geom_y[0];
1156 szhints[sn]=szhints[0];
1157 }
1158 }
1159
closecol(x,r)1160 int closecol(x,r)
1161 int x,*r;
1162 {
1163 int i;
1164
1165 for (i=1;x>r[i];i++);
1166 return i-(r[i]-x>x-r[i-1]);
1167 }
1168
find_cardcol(bm,r,col)1169 VOID find_cardcol(bm,r,col)
1170 unsigned char *bm;
1171 int *r,col[6][6][6];
1172 {
1173 int i,s;
1174
1175 bm+=10;
1176 s=1<<((*bm++&7)+1);
1177 bm+=2;
1178 for (i=0;i<s;i++) {
1179 col[closecol(bm[0],r)][closecol(bm[1],r)][closecol(bm[2],r)]=1;
1180 bm+=3;
1181 }
1182 }
1183
card_colors(sn)1184 VOID card_colors(sn)
1185 int sn;
1186 {
1187 int c,i,j,k,ncol;
1188 int col[6][6][6];
1189 unsigned long p;
1190 XColor xc;
1191
1192 if (desk[sn].col<=2) {
1193 return;
1194 }
1195 else if (desk[sn].plan>=8) {
1196 c=0;
1197 }
1198 else if (desk[sn].plan>=7) {
1199 c=1;
1200 }
1201 else if (desk[sn].plan>=6) {
1202 c=2;
1203 }
1204 else {
1205 c=3;
1206 }
1207 for (;c<4;c++) {
1208 for (i=0;i<6-c;i++) {
1209 for (j=0;j<6-c;j++) {
1210 for (k=0;k<6-c;k++) {
1211 col[i][j][k]=0;
1212 }
1213 }
1214 }
1215 for (i=0;i<4;i++) {
1216 for (j=0;j<3;j++) {
1217 find_cardcol(fr_gif[i][j],ramp[c],col);
1218 }
1219 for (j=0;j<8;j++) {
1220 find_cardcol(de_gif[i][j],ramp[c],col);
1221 }
1222 }
1223 find_cardcol(backsd_gif[0],ramp[c],col);
1224 ncol=0;
1225 for (i=0;i<6-c;i++) {
1226 for (j=0;j<6-c;j++) {
1227 for (k=0;k<6-c;k++) {
1228 if (col[i][j][k]) {
1229 xc.red=ramp[c][i]<<8;
1230 xc.green=ramp[c][j]<<8;
1231 xc.blue=ramp[c][k]<<8;
1232 if (closest_col(sn,&xc)) {
1233 color[sn][desk[sn].col+ncol++]=xc;
1234 }
1235 else {
1236 i=j=k=7;
1237 }
1238 }
1239 }
1240 }
1241 }
1242 if (i<7) {
1243 desk[sn].col+=ncol;
1244 return;
1245 }
1246 for (i=0;i<ncol;i++) {
1247 p=color[sn][desk[sn].col+i].pixel;
1248 for (j=0;j<desk[sn].col && color[sn][j].pixel!=p;j++);
1249 if (j==desk[sn].col) {
1250 for (j=i+1;j<ncol && color[sn][desk[sn].col+j].pixel!=p;j++);
1251 if (j==ncol) XFreeColors(dpy[sn],cmap[sn],&p,1,0);
1252 }
1253 }
1254 }
1255 }
1256
xinitres(sn)1257 VOID xinitres(sn)
1258 int sn;
1259 {
1260 static char stgs[]="s1";
1261 char cbuf[8];
1262 char *res;
1263 int logdef;
1264 int scr;
1265 XColor fgcol,nocol;
1266 unsigned long borw;
1267 int i,len,cw,nw,ln;
1268 unsigned int w,h;
1269 struct passwd *pwd;
1270
1271 if (sn) {
1272 font_name=fg_col=bg_col=bt_col=0;
1273 w3d_col=b3d_col=mk_col=0;
1274 bwcol=gfx3d[sn]=desk[sn].large=-1;
1275 extractnam(sn,disp_name[sn]);
1276 if (strchr(disp_name[sn],'@')) {
1277 disp_name[sn]=strchr(disp_name[sn],'@')+1;
1278 }
1279 }
1280 else {
1281 extractnam(sn,getenv("LOGNAME"));
1282 strcpy(usrname[0],spnames[0][0][0]);
1283 strcpy(usrname[1],spnames[0][1][0]);
1284 memcpy((VOID *)color[1],(VOID *)color[0],sizeof(color[0]));
1285 memcpy((VOID *)color[2],(VOID *)color[0],sizeof(color[0]));
1286 }
1287 if (!(dpy[sn]=XOpenDisplay(disp_name[sn]))) {
1288 fprintf(stderr,"Can't open display %s\n",XDisplayName(disp_name[sn]));
1289 exitus(1);
1290 }
1291 XSetIOErrorHandler(ioerr);
1292 scr=DefaultScreen(dpy[sn]);
1293 cmap[sn]=DefaultColormap(dpy[sn],scr);
1294 desk[sn].plan=DefaultDepth(dpy[sn],scr);
1295 bpix[sn]=BlackPixel(dpy[sn],scr);
1296 wpix[sn]=WhitePixel(dpy[sn],scr);
1297 for (i=0;i<4;i++) {
1298 if (sn || !ccol[i] ||
1299 !XParseColor(dpy[sn],cmap[sn],ccol[i],&color[sn][i])) {
1300 sprintf(cbuf,"color%d",i+1);
1301 res=XGetDefault(dpy[sn],prog_name,cbuf);
1302 if (res) {
1303 XParseColor(dpy[sn],cmap[sn],res,&color[sn][i]);
1304 }
1305 }
1306 }
1307 if (bwcol<0) {
1308 res=XGetDefault(dpy[sn],prog_name,"color");
1309 bwcol=!res || istrue(res);
1310 }
1311 if (bwcol && desk[sn].plan>1) {
1312 for (i=0;i<6 && closest_col(sn,&color[sn][i]);i++);
1313 if (i!=6) {
1314 if (i==4) color[sn][i++]=color[sn][0];
1315 if (i==5) color[sn][i++]=color[sn][2];
1316 else i=0;
1317 }
1318 }
1319 else i=0;
1320 color[sn][i].pixel=wpix[sn];
1321 color[sn][i].red=color[sn][i].green=color[sn][i].blue=0xffff;
1322 i++;
1323 color[sn][i].pixel=bpix[sn];
1324 color[sn][i].red=color[sn][i].green=color[sn][i].blue=0;
1325 i++;
1326 desk[sn].col=i;
1327 fgpix[sn]=get_col(sn,fg_col,prog_name,"foreground",NULL,bpix[sn],&fgcol);
1328 borw=(long)fgcol.red+fgcol.green+fgcol.blue<0x1E000L?wpix[sn]:bpix[sn];
1329 if (gfx3d[sn]<0) {
1330 res=XGetDefault(dpy[sn],prog_name,"3d");
1331 gfx3d[sn]=(!res && desk[sn].plan>1) || (res && istrue(res));
1332 }
1333 if (gfx3d[sn]) {
1334 bgpix[sn]=get_col(sn,bg_col,prog_name,"3dbackground",
1335 desk[sn].plan>1?"#cccccccccccc":
1336 borw==wpix[sn]?"white":"black",
1337 borw,&nocol);
1338 btpix[sn]=get_col(sn,bt_col,prog_name,"3dbutton",
1339 desk[sn].plan>1?"#dddddddddddd":
1340 borw==wpix[sn]?"white":"black",
1341 borw,&nocol);
1342 w3dpix[sn]=get_col(sn,w3d_col,prog_name,"3dtop",NULL,wpix[sn],&nocol);
1343 b3dpix[sn]=get_col(sn,b3d_col,prog_name,"3dbot",NULL,bpix[sn],&nocol);
1344 }
1345 else {
1346 bgpix[sn]=get_col(sn,bg_col,prog_name,"background",NULL,borw,&nocol);
1347 btpix[sn]=get_col(sn,bt_col,prog_name,"button",NULL,borw,&nocol);
1348 }
1349 mkpix[sn]=get_col(sn,mk_col,prog_name,"mark",
1350 desk[sn].plan>1?"#ffff00000000":"black",
1351 bpix[sn],&nocol);
1352 card_colors(sn);
1353 if (desk[sn].large<0) {
1354 res=XGetDefault(dpy[sn],prog_name,"large");
1355 if (res) desk[sn].large=istrue(res);
1356 if (desk[sn].large<0) {
1357 desk[sn].large=XDisplayWidth(dpy[sn],scr)>960 &&
1358 XDisplayHeight(dpy[sn],scr)>600;
1359 }
1360 }
1361 calc_desk(sn);
1362 if (!title[sn] &&
1363 !(title[sn]=XGetDefault(dpy[sn],prog_name,"title"))) title[sn]=prog_name;
1364 if (!geom_f[sn] &&
1365 (res=XGetDefault(dpy[sn],prog_name,"geometry"))) {
1366 geom_f[sn]=XParseGeometry(res,&geom_x[sn],&geom_y[sn],&w,&h);
1367 }
1368 if (!font_name &&
1369 !(font_name=XGetDefault(dpy[sn],prog_name,"font"))) {
1370 font_name=desk[sn].large?"10x20":"9x15";
1371 }
1372 if (!(dfont[sn]=XLoadQueryFont(dpy[sn],font_name))) {
1373 fprintf(stderr,"Font %s not found\n",font_name);
1374 exitus(1);
1375 }
1376 charw[sn]=dfont[sn]->max_bounds.width;
1377 charh[sn]=dfont[sn]->max_bounds.ascent+dfont[sn]->max_bounds.descent+1;
1378 if (desk[sn].large && charh[sn]<21) charh[sn]=21;
1379 else if (charh[sn]<16) charh[sn]=16;
1380 charh[sn]+=gfx3d[sn]+(charh[sn]&1);
1381 if (sn) {
1382 res=XGetDefault(dpy[sn],prog_name,"useoptfile");
1383 useoptfile[sn]=res && istrue(res);
1384 }
1385 else {
1386 useoptfile[sn]=1;
1387 }
1388 if (!mbuttonset[sn] &&
1389 (res=XGetDefault(dpy[sn],prog_name,"menubutton"))) {
1390 mbutton[sn]=atoi(res);
1391 }
1392 if (mbutton[sn]<0 || mbutton[sn]>5) mbutton[sn]=0;
1393 if (!keyboardset[sn] &&
1394 (res=XGetDefault(dpy[sn],prog_name,"keyboard"))) {
1395 keyboard[sn]=atoi(res);
1396 }
1397 if (keyboard[sn]<0 || keyboard[sn]>2) keyboard[sn]=1;
1398 if (!abkuerzset[sn] &&
1399 (res=XGetDefault(dpy[sn],prog_name,"shortcut"))) {
1400 abkuerz[sn]=atoi(res);
1401 if (abkuerz[sn]<0 || abkuerz[sn]>2) abkuerz[sn]=1;
1402 }
1403 if (!tdelayset[sn] &&
1404 (res=XGetDefault(dpy[sn],prog_name,"tdelay"))) {
1405 nimmstich[sn][0]=(int)(atof(res)*10+.5);
1406 }
1407 if (nimmstich[sn][0]<0) nimmstich[sn][0]=7;
1408 else if (nimmstich[sn][0]>101) nimmstich[sn][0]=101;
1409 if (!downupset[sn]) {
1410 res=XGetDefault(dpy[sn],prog_name,"down");
1411 downup=!res || istrue(res);
1412 }
1413 sort1[sn]=!downup;
1414 if (!altseqset[sn]) {
1415 res=XGetDefault(dpy[sn],prog_name,"alt");
1416 if (!res && sn) altseq=alternate[0];
1417 else altseq=res && istrue(res);
1418 }
1419 alternate[sn]=!!altseq;
1420 if (!alistset[sn]) {
1421 res=XGetDefault(dpy[sn],prog_name,"alist");
1422 if (res) {
1423 alist[sn]=istrue(res);
1424 }
1425 else {
1426 res=XGetDefault(dpy[sn],prog_name,"tlist");
1427 if (!res && sn) alist[sn]=alist[0];
1428 else alist[sn]=res && istrue(res)?2:0;
1429 }
1430 }
1431 if ((res=XGetDefault(dpy[sn],prog_name,"alias"))) {
1432 extractnam(sn,res);
1433 if (!sn) {
1434 strcpy(usrname[0],spnames[0][0][0]);
1435 strcpy(usrname[1],spnames[0][1][0]);
1436 }
1437 }
1438 if (!hintsset[sn]) {
1439 res=XGetDefault(dpy[sn],prog_name,"hint");
1440 if (!res && sn) hints[sn]=hints[0];
1441 else hints[sn]=res && istrue(res);
1442 }
1443 if (!blattset[sn]) {
1444 res=XGetDefault(dpy[sn],prog_name,"cards");
1445 if (res) {
1446 blatt[sn]=atoi(res);
1447 if (blatt[sn]<0 || blatt[sn]>3) blatt[sn]=1;
1448 }
1449 else if (sn) {
1450 blatt[sn]=blatt[0];
1451 }
1452 }
1453 if (!langset[sn]) {
1454 res=XGetDefault(dpy[sn],prog_name,"language");
1455 if (!res && sn) lang[sn]=lang[0];
1456 else lang[sn]=langidx(res);
1457 }
1458 if (!briefmsgset[sn]) {
1459 res=XGetDefault(dpy[sn],prog_name,"briefmsg");
1460 if (!res && sn) briefmsg[sn]=briefmsg[0];
1461 else briefmsg[sn]=res && istrue(res);
1462 }
1463 if (!trickl2rset[sn]) {
1464 res=XGetDefault(dpy[sn],prog_name,"trickl2r");
1465 if (!res && sn) trickl2r[sn]=trickl2r[0];
1466 else trickl2r[sn]=res && istrue(res);
1467 }
1468 if (!sn) {
1469 if (!game_file) {
1470 if (!getdeffn(prog_name,&game_file,"game","")) {
1471 game_file=0;
1472 }
1473 }
1474 logdef=!prot_file && getdeffn(prog_name,&prot_file,"log","xskat.log");
1475 if (logging<0) {
1476 res=XGetDefault(dpy[sn],prog_name,"dolog");
1477 logging=(res && istrue(res)) || (!res && logdef);
1478 }
1479 if (unformatted<0) {
1480 res=XGetDefault(dpy[sn],prog_name,"formatted");
1481 unformatted=!(res && istrue(res));
1482 }
1483 if (!opt_file) {
1484 getdeffn(prog_name,&opt_file,"opt","xskat.opt");
1485 }
1486 if (!ramschset && (res=XGetDefault(dpy[sn],prog_name,"ramsch"))) {
1487 playramsch=atoi(res);
1488 if (playramsch<0) playramsch=0;
1489 else if (playramsch>2) playramsch=2;
1490 }
1491 if (!sramschset && (res=XGetDefault(dpy[sn],prog_name,"sramsch"))) {
1492 playsramsch=istrue(res);
1493 }
1494 if (!rskatloserset && (res=XGetDefault(dpy[sn],prog_name,"skattoloser"))) {
1495 rskatloser=istrue(res);
1496 }
1497 if (!kontraset && (res=XGetDefault(dpy[sn],prog_name,"kontra"))) {
1498 playkontra=atoi(res);
1499 if (playkontra<0) playkontra=0;
1500 else if (playkontra>2) playkontra=2;
1501 }
1502 if (!bockset && (res=XGetDefault(dpy[sn],prog_name,"bock"))) {
1503 playbock=atoi(res);
1504 if (playbock<0) playbock=0;
1505 else if (playbock>2) playbock=2;
1506 }
1507 if (!bockeventsset &&
1508 (res=XGetDefault(dpy[sn],prog_name,"bockevents"))) {
1509 bockevents=atoi(res);
1510 }
1511 if (!resumebockset &&
1512 (res=XGetDefault(dpy[sn],prog_name,"resumebock"))) {
1513 resumebock=istrue(res);
1514 }
1515 if (!spitzezaehltset &&
1516 (res=XGetDefault(dpy[sn],prog_name,"spitze"))) {
1517 spitzezaehlt=atoi(res);
1518 if (spitzezaehlt<0) spitzezaehlt=0;
1519 else if (spitzezaehlt>2) spitzezaehlt=2;
1520 }
1521 if (!revolutionset &&
1522 (res=XGetDefault(dpy[sn],prog_name,"revolution"))) {
1523 revolution=istrue(res);
1524 }
1525 if (!klopfenset &&
1526 (res=XGetDefault(dpy[sn],prog_name,"klopfen"))) {
1527 klopfen=istrue(res);
1528 }
1529 if (!schenkenset &&
1530 (res=XGetDefault(dpy[sn],prog_name,"schenken"))) {
1531 schenken=istrue(res);
1532 }
1533 if (!oldrulesset &&
1534 (res=XGetDefault(dpy[sn],prog_name,"oldrules"))) {
1535 oldrules=istrue(res);
1536 }
1537 if (irc_play<0) {
1538 res=XGetDefault(dpy[sn],prog_name,"irc");
1539 irc_play=res && istrue(res);
1540 }
1541 if (irc_logappend<0) {
1542 res=XGetDefault(dpy[sn],prog_name,"irclogappend");
1543 irc_logappend=res && istrue(res);
1544 }
1545 if (!list_file) {
1546 getdeffn(prog_name,&list_file,
1547 irc_play?"irclist":"list",
1548 irc_play?"xskat.irc":"xskat.lst");
1549 }
1550 if (!cards_file) {
1551 getdeffn(prog_name,&cards_file,"cardsfile","xskat.cards");
1552 }
1553 if (!irc_host &&
1554 !(irc_host=XGetDefault(dpy[sn],prog_name,"ircserver")) &&
1555 !(irc_host=getenv("IRCSERVER"))) {
1556 irc_host=irc_defaulthost;
1557 }
1558 strncpy(irc_hostname,irc_host,35);
1559 irc_hostname[35]=0;
1560 if (irc_play) {
1561 game_file=0;
1562 if (irc_pos<0 &&
1563 (res=XGetDefault(dpy[sn],prog_name,"ircpos"))) {
1564 irc_pos=atoi(res);
1565 }
1566 irc_pos--;
1567 if (irc_pos<0 || irc_pos>2) irc_pos=-1;
1568 if (!irc_telnet &&
1569 !(irc_telnet=XGetDefault(dpy[sn],prog_name,"irctelnet"))) {
1570 irc_telnet="telnet";
1571 }
1572 if (irc_port<0 &&
1573 ((res=XGetDefault(dpy[sn],prog_name,"ircport")) ||
1574 (res=getenv("IRCPORT")))) {
1575 irc_port=atoi(res);
1576 }
1577 if (irc_port<0) irc_port=6667;
1578 if (!irc_channel &&
1579 !(irc_channel=XGetDefault(dpy[sn],prog_name,"ircchannel"))) {
1580 irc_channel="#xskat";
1581 }
1582 if (!irc_nick &&
1583 !(irc_nick=XGetDefault(dpy[sn],prog_name,"ircnick")) &&
1584 !(irc_nick=getenv("IRCNICK")) &&
1585 !(irc_nick=getenv("IRCUSER")) &&
1586 !(irc_nick=getenv("LOGNAME"))) {
1587 irc_changenick(0);
1588 }
1589 if (!irc_user &&
1590 !(irc_user=XGetDefault(dpy[sn],prog_name,"ircuser")) &&
1591 !(irc_user=getenv("IRCUSER")) &&
1592 !(irc_user=getenv("LOGNAME"))) {
1593 irc_user="XSkat";
1594 }
1595 if (!irc_realname &&
1596 !(irc_realname=XGetDefault(dpy[sn],prog_name,"ircrealname")) &&
1597 !(irc_realname=getenv("IRCNAME"))) {
1598 if ((pwd=getpwuid(getuid())) && pwd->pw_gecos) {
1599 irc_realname=pwd->pw_gecos;
1600 if ((res=strchr(irc_realname,','))) *res=0;
1601 }
1602 if (!irc_realname || !*irc_realname) {
1603 irc_realname="XSkat player";
1604 }
1605 }
1606 if (!irc_logfile) {
1607 getdeffn(prog_name,&irc_logfile,"irclog","xskat.ilg");
1608 }
1609 }
1610 if (geber<0) {
1611 if ((res=XGetDefault(dpy[sn],prog_name,"start"))) {
1612 geber=atoi(res);
1613 }
1614 if (geber<1 || geber>3) geber=0;
1615 else geber=left(geber);
1616 }
1617 for (i=0;i<2;i++) {
1618 if (!stgset[i]) {
1619 stgs[1]=i+'1';
1620 if ((res=XGetDefault(dpy[sn],prog_name,stgs))) {
1621 strateg[i]=atoi(res);
1622 }
1623 }
1624 if (strateg[i]<-4) strateg[i]=-4;
1625 else if (strateg[i]>0) strateg[i]=0;
1626 }
1627 if (prot_file && !*prot_file) prot_file=0;
1628 if (opt_file && !*opt_file) opt_file=0;
1629 if (game_file && !*game_file) game_file=0;
1630 if (list_file && !*list_file) list_file=0;
1631 if (irc_logfile && !*irc_logfile) irc_logfile=0;
1632 if (cards_file && !*cards_file) cards_file=0;
1633 }
1634 if ((geom_f[sn]&(XValue|YValue))==(XValue|YValue)) {
1635 szhints[sn].x=geom_f[sn]&XNegative?
1636 XDisplayWidth(dpy[sn],scr)+geom_x[sn]-desk[sn].w:geom_x[sn];
1637 szhints[sn].y=geom_f[sn]&YNegative?
1638 XDisplayHeight(dpy[sn],scr)+geom_y[sn]-desk[sn].h:geom_y[sn];
1639 szhints[sn].flags|=USPosition;
1640 }
1641 szhints[sn].flags|=PMinSize|PMaxSize;
1642 szhints[sn].min_width=szhints[sn].max_width=desk[sn].w;
1643 szhints[sn].min_height=szhints[sn].max_height=desk[sn].h;
1644 cw=1;
1645 for (ln=0;ln<NUM_LANG;ln++) {
1646 for (i=0;i<TX_NUM_TX;i++) {
1647 if ((len=strlen(textarr[i].t[ln]))>3 &&
1648 (nw=(XTextWidth(dfont[sn],textarr[i].t[ln],len)+len-1)/len)>cw) {
1649 cw=nw;
1650 }
1651 }
1652 }
1653 if (cw<charw[sn]) charw[sn]=cw;
1654 if (charw[sn]<7) charw[sn]=7;
1655 for (ln=0;ln<NUM_LANG;ln++) {
1656 if (!spnames[sn][0][ln][0]) {
1657 sprintf(spnames[sn][0][ln],textarr[TX_SPIELER_N].t[ln],sn+1);
1658 }
1659 }
1660 }
1661
xstoreres()1662 VOID xstoreres()
1663 {
1664 char buf[256];
1665 XColor xcol;
1666
1667 if (!XGetDefault(dpy[0],prog_name,"font") && font_name) {
1668 sprintf(buf,"%.99s.%s:%.99s\n",prog_name,"font",font_name);
1669 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1670 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1671 buf,strlen(buf));
1672 }
1673 if (!XGetDefault(dpy[0],prog_name,"title") && title[0]) {
1674 sprintf(buf,"%.99s.%s:%.99s\n",prog_name,"title",title[0]);
1675 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1676 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1677 buf,strlen(buf));
1678 }
1679 if (!XGetDefault(dpy[0],prog_name,"foreground")) {
1680 xcol.pixel=fgpix[0];
1681 XQueryColor(dpy[0],cmap[0],&xcol);
1682 sprintf(buf,"%.99s.%s:#%04x%04x%04x\n",prog_name,"foreground",
1683 xcol.red,xcol.green,xcol.blue);
1684 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1685 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1686 buf,strlen(buf));
1687 }
1688 if (!XGetDefault(dpy[0],prog_name,"background")) {
1689 xcol.pixel=bgpix[0];
1690 XQueryColor(dpy[0],cmap[0],&xcol);
1691 sprintf(buf,"%.99s.%s:#%04x%04x%04x\n",prog_name,"background",
1692 xcol.red,xcol.green,xcol.blue);
1693 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1694 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1695 buf,strlen(buf));
1696 }
1697 if (!XGetDefault(dpy[0],prog_name,"mark")) {
1698 xcol.pixel=mkpix[0];
1699 XQueryColor(dpy[0],cmap[0],&xcol);
1700 sprintf(buf,"%.99s.%s:#%04x%04x%04x\n",prog_name,"mark",
1701 xcol.red,xcol.green,xcol.blue);
1702 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1703 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1704 buf,strlen(buf));
1705 }
1706 if (!XGetDefault(dpy[0],prog_name,"menubutton")) {
1707 sprintf(buf,"%.99s.%s:%d\n",prog_name,"menubutton",mbutton[0]);
1708 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1709 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1710 buf,strlen(buf));
1711 }
1712 if (!XGetDefault(dpy[0],prog_name,"keyboard")) {
1713 sprintf(buf,"%.99s.%s:%d\n",prog_name,"keyboard",keyboard[0]);
1714 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1715 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1716 buf,strlen(buf));
1717 }
1718 if (!XGetDefault(dpy[0],prog_name,"tdelay")) {
1719 sprintf(buf,"%.99s.%s:%f\n",prog_name,"tdelay",nimmstich[0][0]/10.0);
1720 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1721 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1722 buf,strlen(buf));
1723 }
1724 if (!XGetDefault(dpy[0],prog_name,"cards")) {
1725 sprintf(buf,"%.99s.%s:%d\n",prog_name,"cards",blatt[0]);
1726 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1727 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1728 buf,strlen(buf));
1729 }
1730 if (!XGetDefault(dpy[0],prog_name,"large")) {
1731 sprintf(buf,"%.99s.%s:%d\n",prog_name,"large",desk[0].large);
1732 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1733 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1734 buf,strlen(buf));
1735 }
1736 if (!XGetDefault(dpy[0],prog_name,"down")) {
1737 sprintf(buf,"%.99s.%s:%d\n",prog_name,"down",!sort1[0]);
1738 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1739 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1740 buf,strlen(buf));
1741 }
1742 if (!XGetDefault(dpy[0],prog_name,"alt")) {
1743 sprintf(buf,"%.99s.%s:%d\n",prog_name,"alt",alternate[0]);
1744 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1745 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1746 buf,strlen(buf));
1747 }
1748 if (!XGetDefault(dpy[0],prog_name,"briefmsg")) {
1749 sprintf(buf,"%.99s.%s:%d\n",prog_name,"briefmsg",briefmsg[0]);
1750 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1751 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1752 buf,strlen(buf));
1753 }
1754 if (!XGetDefault(dpy[0],prog_name,"trickl2r")) {
1755 sprintf(buf,"%.99s.%s:%d\n",prog_name,"trickl2r",trickl2r[0]);
1756 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1757 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1758 buf,strlen(buf));
1759 }
1760 if (!XGetDefault(dpy[0],prog_name,"language")) {
1761 sprintf(buf,"%.99s.%s:%.99s\n",prog_name,"language",idxlang(lang[0]));
1762 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1763 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1764 buf,strlen(buf));
1765 }
1766 if (!XGetDefault(dpy[0],prog_name,"hint")) {
1767 sprintf(buf,"%.99s.%s:%d\n",prog_name,"hint",hints[0]);
1768 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1769 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1770 buf,strlen(buf));
1771 }
1772 if (!XGetDefault(dpy[0],prog_name,"shortcut")) {
1773 sprintf(buf,"%.99s.%s:%d\n",prog_name,"shortcut",abkuerz[0]);
1774 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1775 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1776 buf,strlen(buf));
1777 }
1778 if (!XGetDefault(dpy[0],prog_name,"alias")) {
1779 sprintf(buf,"%.99s.%s:%.9s %.9s\n",prog_name,"alias",
1780 spnames[0][0][0],spnames[0][1][0]);
1781 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1782 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1783 buf,strlen(buf));
1784 }
1785 if (!XGetDefault(dpy[0],prog_name,"ready")) {
1786 sprintf(buf,"%.99s.%s:%d\n",prog_name,"ready",1);
1787 XChangeProperty(dpy[0],DefaultRootWindow(dpy[0]),
1788 XA_RESOURCE_MANAGER,XA_STRING,8,PropModeAppend,
1789 buf,strlen(buf));
1790 }
1791 XCloseDisplay(dpy[0]);
1792 strcpy(buf,"+");
1793 strcat(buf,lanip[0]);
1794 if (strchr(buf,':')) *strchr(buf,':')=0;
1795 execlp("xhost","xhost",buf,NULL);
1796 fprintf(stderr,"xhost not found\n");
1797 }
1798
read_cards()1799 VOID read_cards()
1800 {
1801 FILE *f;
1802 int b,cd,cdst,bufidx,buflen=200000;
1803 char *buf,line[20];
1804
1805 if (!cards_file) return;
1806 f=fopen(cards_file,"r");
1807 if (!f) return;
1808 buf=malloc(buflen);
1809 if (!buf) nomem();
1810 bufidx=0;
1811 for (cd=0;cd<sizeof(map_gif)/sizeof(map_gif[0]);cd++) {
1812 while (fscanf(f,"unsigned char %4s",line)!=1) {
1813 if (feof(f)) {
1814 fclose(f);
1815 fprintf(stderr,"Error reading cards from %s\n",cards_file);
1816 return;
1817 }
1818 fscanf(f,"%*s ");
1819 }
1820 if (strncmp(map_gif[cd].name,line,strlen(map_gif[cd].name))) {
1821 cd--;
1822 continue;
1823 }
1824 cdst=bufidx;
1825 do {
1826 if (bufidx<buflen && fscanf(f,"%i",&b)==1) {
1827 buf[bufidx++]=b;
1828 }
1829 } while (fgetc(f)!='}' && !feof(f));
1830 if (bufidx>=buflen || feof(f) ||
1831 strcmp(buf+cdst,"GIF87aX") ||
1832 (buf[cdst+8]!=(char)0x45 && buf[cdst+8]!=(char)0x8a)) {
1833 cd--;
1834 bufidx=cdst;
1835 continue;
1836 }
1837 *(map_gif[cd].pos)=buf+cdst;
1838 ggcards=0;
1839 }
1840 fclose(f);
1841 }
1842
set_conames()1843 VOID set_conames()
1844 {
1845 int ln,sn;
1846 char buf[40];
1847
1848 if (!usrname[0][0]) strcpy(usrname[0],"~");
1849 if (!usrname[1][0]) strcpy(usrname[1],"~");
1850 for (ln=0;ln<NUM_LANG;ln++) {
1851 if (!strcmp(conames[0][0],textarr[TX_COMPUTER].t[ln]) &&
1852 !strcmp(conames[0][1],textarr[TX_LINKS].t[ln])) {
1853 strcpy(conames[0][0],"~");
1854 strcpy(conames[0][1],"~");
1855 }
1856 if (!strcmp(conames[1][0],textarr[TX_COMPUTER].t[ln]) &&
1857 !strcmp(conames[1][1],textarr[TX_RECHTS].t[ln])) {
1858 strcpy(conames[1][0],"~");
1859 strcpy(conames[1][1],"~");
1860 }
1861 }
1862 for (sn=0;sn<2;sn++) {
1863 if (!conames[sn][0][0]) strcpy(conames[sn][0],"~");
1864 if (!conames[sn][1][0]) strcpy(conames[sn][1],"~");
1865 }
1866 for (ln=0;ln<NUM_LANG;ln++) {
1867 switch (numsp) {
1868 case 0:
1869 for (sn=0;sn<3;sn++) {
1870 if (!spnames[sn][0][ln][0]) {
1871 sprintf(spnames[sn][0][ln],"%s%d",textarr[TX_COMPUTER].t[ln],sn+1);
1872 }
1873 }
1874 break;
1875 case 1:
1876 sprintf(buf,"%s %s",usrname[0],usrname[1]);
1877 extractnamln(0,buf,ln);
1878 sprintf(buf,"%s %s",conames[0][0],conames[0][1]);
1879 extractnamln(1,buf,ln);
1880 if (!spnames[1][0][ln][0]) {
1881 strcpy(spnames[1][0][ln],textarr[TX_COMPUTER].t[ln]);
1882 strcpy(spnames[1][1][ln],textarr[TX_LINKS].t[ln]);
1883 }
1884 sprintf(buf,"%s %s",conames[1][0],conames[1][1]);
1885 extractnamln(2,buf,ln);
1886 if (!spnames[2][0][ln][0]) {
1887 strcpy(spnames[2][0][ln],textarr[TX_COMPUTER].t[ln]);
1888 strcpy(spnames[2][1][ln],textarr[TX_RECHTS].t[ln]);
1889 }
1890 break;
1891 case 2:
1892 if (!irc_play) {
1893 sprintf(buf,"%s %s",usrname[0],usrname[1]);
1894 extractnamln(0,buf,ln);
1895 }
1896 sprintf(buf,"%s %s",conames[1][0],conames[1][1]);
1897 extractnamln(2,buf,ln);
1898 if (!spnames[2][0][ln][0]) {
1899 strcpy(spnames[2][0][ln],textarr[TX_COMPUTER].t[ln]);
1900 }
1901 break;
1902 case 3:
1903 if (!irc_play) {
1904 sprintf(buf,"%s %s",usrname[0],usrname[1]);
1905 extractnamln(0,buf,ln);
1906 }
1907 break;
1908 }
1909 }
1910 }
1911
xinit(argc,argv)1912 VOID xinit(argc,argv)
1913 int argc;
1914 char *argv[];
1915 {
1916 int ln,sn,i;
1917 unsigned int w,h;
1918
1919 logit();
1920 signal(SIGPIPE,SIG_IGN);
1921 signal(SIGHUP,exitus);
1922 signal(SIGINT,exitus);
1923 signal(SIGTERM,exitus);
1924 numsp=1;
1925 disp_name[0]=font_name=fg_col=bg_col=bt_col=0;
1926 w3d_col=b3d_col=mk_col=0;
1927 for (i=0;i<4;i++) ccol[i]=0;
1928 geber=logging=unformatted=bwcol=gfx3d[0]=desk[0].large=-1;
1929 irc_play=irc_pos=irc_port=irc_logappend=-1;
1930 irc_telnet=irc_host=irc_channel=irc_nick=0;
1931 irc_user=irc_realname=irc_logfile=0;
1932 nimmstich[0][0]=nimmstich[1][0]=nimmstich[2][0]=7;
1933 keyboard[0]=keyboard[1]=keyboard[2]=1;
1934 abkuerz[0]=abkuerz[1]=abkuerz[2]=1;
1935 trickl2r[0]=trickl2r[1]=trickl2r[2]=1;
1936 blatt[0]=blatt[1]=blatt[2]=1;
1937 prog_name=strrchr(argv[0],'/');
1938 if (prog_name) prog_name++;
1939 else prog_name=argv[0];
1940 #ifdef __EMX__ /* XFree OS/2 */
1941 _remext(prog_name);
1942 #endif
1943 while (argc>1) {
1944 if (!strcmp(argv[1],"-help") || !strcmp(argv[1],"-h")) {
1945 usage();
1946 exitus(0);
1947 }
1948 else if (!strcmp(argv[1],"-nopre")) {
1949 nopre=1;
1950 }
1951 else if (!strcmp(argv[1],"-color")) {
1952 bwcol=1;
1953 }
1954 else if (!strcmp(argv[1],"-mono")) {
1955 bwcol=0;
1956 }
1957 else if (!strcmp(argv[1],"-3d")) {
1958 gfx3d[0]=1;
1959 }
1960 else if (!strcmp(argv[1],"-2d")) {
1961 gfx3d[0]=0;
1962 }
1963 else if (!strcmp(argv[1],"-frenchcards")) {
1964 blatt[0]=0;
1965 blattset[0]=1;
1966 }
1967 else if (!strcmp(argv[1],"-french4cards")) {
1968 blatt[0]=1;
1969 blattset[0]=1;
1970 }
1971 else if (!strcmp(argv[1],"-germancards")) {
1972 blatt[0]=2;
1973 blattset[0]=1;
1974 }
1975 else if (!strcmp(argv[1],"-german4cards")) {
1976 blatt[0]=3;
1977 blattset[0]=1;
1978 }
1979 else if (!strcmp(argv[1],"-noshortcut")) {
1980 abkuerz[0]=0;
1981 abkuerzset[0]=1;
1982 }
1983 else if (!strcmp(argv[1],"-askshortcut")) {
1984 abkuerz[0]=1;
1985 abkuerzset[0]=1;
1986 }
1987 else if (!strcmp(argv[1],"-shortcut")) {
1988 abkuerz[0]=2;
1989 abkuerzset[0]=1;
1990 }
1991 else if (!strcmp(argv[1],"-iconic") || !strcmp(argv[1],"-i")) {
1992 wmhints.flags|=StateHint;
1993 wmhints.initial_state=IconicState;
1994 }
1995 else if (!strcmp(argv[1],"-down")) {
1996 downup=1;
1997 downupset[0]=1;
1998 }
1999 else if (!strcmp(argv[1],"-up")) {
2000 downup=0;
2001 downupset[0]=1;
2002 }
2003 else if (!strcmp(argv[1],"-alt")) {
2004 altseq=1;
2005 altseqset[0]=1;
2006 }
2007 else if (!strcmp(argv[1],"-seq")) {
2008 altseq=0;
2009 altseqset[0]=1;
2010 }
2011 else if (!strcmp(argv[1],"-dolog")) {
2012 logging=1;
2013 }
2014 else if (!strcmp(argv[1],"-nolog")) {
2015 logging=0;
2016 }
2017 else if (!strcmp(argv[1],"-fmt")) {
2018 unformatted=0;
2019 }
2020 else if (!strcmp(argv[1],"-unfmt")) {
2021 unformatted=1;
2022 }
2023 else if (!strcmp(argv[1],"-large")) {
2024 desk[0].large=1;
2025 }
2026 else if (!strcmp(argv[1],"-small")) {
2027 desk[0].large=0;
2028 }
2029 else if (!strcmp(argv[1],"-alist")) {
2030 alist[0]=1;
2031 alistset[0]=1;
2032 }
2033 else if (!strcmp(argv[1],"-nlist")) {
2034 alist[0]=0;
2035 alistset[0]=1;
2036 }
2037 else if (!strcmp(argv[1],"-tlist")) {
2038 alist[0]=2;
2039 alistset[0]=1;
2040 }
2041 else if (!strcmp(argv[1],"-noramsch")) {
2042 playramsch=0;
2043 ramschset=1;
2044 }
2045 else if (!strcmp(argv[1],"-ramsch")) {
2046 playramsch=1;
2047 ramschset=1;
2048 }
2049 else if (!strcmp(argv[1],"-ramschonly")) {
2050 playramsch=2;
2051 ramschset=1;
2052 }
2053 else if (!strcmp(argv[1],"-sramsch")) {
2054 playsramsch=1;
2055 sramschset=1;
2056 }
2057 else if (!strcmp(argv[1],"-nosramsch")) {
2058 playsramsch=0;
2059 sramschset=1;
2060 }
2061 else if (!strcmp(argv[1],"-skattolast")) {
2062 rskatloser=0;
2063 rskatloserset=1;
2064 }
2065 else if (!strcmp(argv[1],"-skattoloser")) {
2066 rskatloser=1;
2067 rskatloserset=1;
2068 }
2069 else if (!strcmp(argv[1],"-nokontra")) {
2070 playkontra=0;
2071 kontraset=1;
2072 }
2073 else if (!strcmp(argv[1],"-kontra")) {
2074 playkontra=1;
2075 kontraset=1;
2076 }
2077 else if (!strcmp(argv[1],"-kontra18")) {
2078 playkontra=2;
2079 kontraset=1;
2080 }
2081 else if (!strcmp(argv[1],"-nobock")) {
2082 playbock=0;
2083 bockset=1;
2084 }
2085 else if (!strcmp(argv[1],"-bock")) {
2086 playbock=1;
2087 bockset=1;
2088 }
2089 else if (!strcmp(argv[1],"-bockramsch")) {
2090 playbock=2;
2091 bockset=1;
2092 }
2093 else if (!strcmp(argv[1],"-resumebock")) {
2094 resumebock=1;
2095 resumebockset=1;
2096 }
2097 else if (!strcmp(argv[1],"-noresumebock")) {
2098 resumebock=0;
2099 resumebockset=1;
2100 }
2101 else if (!strcmp(argv[1],"-spitze")) {
2102 spitzezaehlt=1;
2103 spitzezaehltset=1;
2104 }
2105 else if (!strcmp(argv[1],"-spitze2")) {
2106 spitzezaehlt=2;
2107 spitzezaehltset=1;
2108 }
2109 else if (!strcmp(argv[1],"-nospitze")) {
2110 spitzezaehlt=0;
2111 spitzezaehltset=1;
2112 }
2113 else if (!strcmp(argv[1],"-revolution")) {
2114 revolution=1;
2115 revolutionset=1;
2116 }
2117 else if (!strcmp(argv[1],"-norevolution")) {
2118 revolution=0;
2119 revolutionset=1;
2120 }
2121 else if (!strcmp(argv[1],"-klopfen")) {
2122 klopfen=1;
2123 klopfenset=1;
2124 }
2125 else if (!strcmp(argv[1],"-noklopfen")) {
2126 klopfen=0;
2127 klopfenset=1;
2128 }
2129 else if (!strcmp(argv[1],"-schenken")) {
2130 schenken=1;
2131 schenkenset=1;
2132 }
2133 else if (!strcmp(argv[1],"-noschenken")) {
2134 schenken=0;
2135 schenkenset=1;
2136 }
2137 else if (!strcmp(argv[1],"-newrules")) {
2138 oldrules=0;
2139 oldrulesset=1;
2140 }
2141 else if (!strcmp(argv[1],"-oldrules")) {
2142 oldrules=1;
2143 oldrulesset=1;
2144 }
2145 else if (!strcmp(argv[1],"-fastdeal")) {
2146 fastdeal=1;
2147 fastdealset=1;
2148 }
2149 else if (!strcmp(argv[1],"-slowdeal")) {
2150 fastdeal=0;
2151 fastdealset=1;
2152 }
2153 else if (!strcmp(argv[1],"-hint")) {
2154 hints[0]=1;
2155 hintsset[0]=1;
2156 }
2157 else if (!strcmp(argv[1],"-nohint")) {
2158 hints[0]=0;
2159 hintsset[0]=1;
2160 }
2161 else if (!strcmp(argv[1],"-briefmsg")) {
2162 briefmsg[0]=1;
2163 briefmsgset[0]=1;
2164 }
2165 else if (!strcmp(argv[1],"-verbosemsg")) {
2166 briefmsg[0]=0;
2167 briefmsgset[0]=1;
2168 }
2169 else if (!strcmp(argv[1],"-trickl2r")) {
2170 trickl2r[0]=1;
2171 trickl2rset[0]=1;
2172 }
2173 else if (!strcmp(argv[1],"-notrickl2r")) {
2174 trickl2r[0]=0;
2175 trickl2rset[0]=1;
2176 }
2177 else if (!strcmp(argv[1],"-irc")) {
2178 irc_play=1;
2179 }
2180 else if (!strcmp(argv[1],"-noirc")) {
2181 irc_play=0;
2182 }
2183 else if (!strcmp(argv[1],"-irclogappend")) {
2184 irc_logappend=1;
2185 irc_play=1;
2186 }
2187 else if (!strcmp(argv[1],"-irclogoverwrite")) {
2188 irc_logappend=0;
2189 irc_play=1;
2190 }
2191 else if (!strcmp(argv[1],"-pk")) {
2192 pkoption=1;
2193 }
2194 else if ((argv[1][0]!='-') && numsp<3) {
2195 disp_name[numsp++]=argv[1];
2196 }
2197 else if (argc>2) {
2198 if (!strcmp(argv[1],"-display") || !strcmp(argv[1],"-d")) {
2199 disp_name[0]=argv[2];
2200 }
2201 else if (!strcmp(argv[1],"-geometry") || !strcmp(argv[1],"-g")) {
2202 geom_f[0]=XParseGeometry(argv[2],&geom_x[0],&geom_y[0],&w,&h);
2203 }
2204 else if (!strcmp(argv[1],"-name") || !strcmp(argv[1],"-n")) {
2205 prog_name=argv[2];
2206 }
2207 else if (!strcmp(argv[1],"-title") || !strcmp(argv[1],"-T")) {
2208 title[0]=argv[2];
2209 }
2210 else if (!strcmp(argv[1],"-fg")) {
2211 fg_col=argv[2];
2212 }
2213 else if (!strcmp(argv[1],"-bg")) {
2214 bg_col=argv[2];
2215 }
2216 else if (!strcmp(argv[1],"-bt")) {
2217 bt_col=argv[2];
2218 }
2219 else if (!strcmp(argv[1],"-3dtop")) {
2220 w3d_col=argv[2];
2221 }
2222 else if (!strcmp(argv[1],"-3dbot")) {
2223 b3d_col=argv[2];
2224 }
2225 else if (!strcmp(argv[1],"-mark")) {
2226 mk_col=argv[2];
2227 }
2228 else if (!strncmp(argv[1],"-color",6) &&
2229 (i=atoi(argv[1]+6))>=1 && i<=20) {
2230 if (i<=4) ccol[i-1]=argv[2];
2231 }
2232 else if (!strcmp(argv[1],"-mb")) {
2233 mbutton[0]=atoi(argv[2]);
2234 mbuttonset[0]=1;
2235 }
2236 else if (!strcmp(argv[1],"-keyboard")) {
2237 keyboard[0]=atoi(argv[2]);
2238 keyboardset[0]=1;
2239 }
2240 else if (!strcmp(argv[1],"-tdelay")) {
2241 nimmstich[0][0]=(int)(atof(argv[2])*10+.5);
2242 tdelayset[0]=1;
2243 }
2244 else if (!strcmp(argv[1],"-font") || !strcmp(argv[1],"-fn")) {
2245 font_name=argv[2];
2246 }
2247 else if (!strcmp(argv[1],"-list") || !strcmp(argv[1],"-l")) {
2248 list_file=argv[2];
2249 }
2250 else if (!strcmp(argv[1],"-bockevents")) {
2251 bockevents=atoi(argv[2]);
2252 bockeventsset=1;
2253 }
2254 else if (!strcmp(argv[1],"-opt")) {
2255 opt_file=argv[2];
2256 }
2257 else if (!strcmp(argv[1],"-log")) {
2258 prot_file=argv[2];
2259 logging=1;
2260 }
2261 else if (!strcmp(argv[1],"-game")) {
2262 game_file=argv[2];
2263 }
2264 else if (!strcmp(argv[1],"-lang")) {
2265 lang[0]=langidx(argv[2]);
2266 langset[0]=1;
2267 }
2268 else if (!strcmp(argv[1],"-start")) {
2269 geber=atoi(argv[2]);
2270 if (geber<1 || geber>3) geber=0;
2271 else geber=left(geber);
2272 }
2273 else if (!strcmp(argv[1],"-auto")) {
2274 numgames=atoi(argv[2]);
2275 if (numgames<1) numgames=1;
2276 }
2277 else if (!strcmp(argv[1],"-s1")) {
2278 strateg[0]=atoi(argv[2]);
2279 stgset[0]=1;
2280 }
2281 else if (!strcmp(argv[1],"-s2")) {
2282 strateg[1]=atoi(argv[2]);
2283 stgset[1]=1;
2284 }
2285 else if (!strcmp(argv[1],"-s3")) {
2286 strateg[2]=atoi(argv[2]);
2287 stgset[2]=1;
2288 }
2289 else if (!strcmp(argv[1],"-irctelnet")) {
2290 irc_telnet=argv[2];
2291 irc_play=1;
2292 }
2293 else if (!strcmp(argv[1],"-ircserver")) {
2294 irc_host=argv[2];
2295 irc_play=1;
2296 irc_hostset=1;
2297 }
2298 else if (!strcmp(argv[1],"-ircport")) {
2299 irc_port=atoi(argv[2]);
2300 irc_play=1;
2301 }
2302 else if (!strcmp(argv[1],"-ircchannel")) {
2303 irc_channel=argv[2];
2304 irc_play=1;
2305 }
2306 else if (!strcmp(argv[1],"-ircnick")) {
2307 irc_nick=argv[2];
2308 irc_play=1;
2309 }
2310 else if (!strcmp(argv[1],"-ircuser")) {
2311 irc_user=argv[2];
2312 irc_play=1;
2313 }
2314 else if (!strcmp(argv[1],"-ircrealname")) {
2315 irc_realname=argv[2];
2316 irc_play=1;
2317 }
2318 else if (!strcmp(argv[1],"-ircpos")) {
2319 irc_pos=atoi(argv[2]);
2320 irc_play=1;
2321 }
2322 else if (!strcmp(argv[1],"-irclog")) {
2323 irc_logfile=argv[2];
2324 irc_play=1;
2325 }
2326 else {
2327 invopt(argv[1]);
2328 }
2329 argc--;argv++;
2330 }
2331 else {
2332 invopt(argv[1]);
2333 }
2334 argc--;argv++;
2335 }
2336 init_text();
2337 if (numgames) {
2338 numsp=irc_play=0;
2339 if (!langset[0]) lang[0]=langidx((char *)0);
2340 lang[2]=lang[1]=lang[0];
2341 if (geber<0) geber=0;
2342 if (logging<0) logging=0;
2343 if (unformatted<0) unformatted=1;
2344 for (i=0;i<3;i++) {
2345 if (strateg[i]<-4) strateg[i]=-4;
2346 else if (strateg[i]>0) strateg[i]=0;
2347 }
2348 }
2349 else {
2350 xinitres(0);
2351 }
2352 read_list();
2353 if (irc_play) {
2354 setsum(0);
2355 read_opt();
2356 set_conames();
2357 irc_init();
2358 }
2359 else {
2360 read_opt();
2361 for (sn=1;sn<numsp;sn++) {
2362 xinitres(sn);
2363 }
2364 read_opt();
2365 }
2366 for (sn=0;sn<3;sn++) {
2367 if (!lanip[sn][0]) {
2368 strcpy(lanip[sn],"127.0.0.1");
2369 }
2370 }
2371 if (de_gif[3][0][8]==0x45) {
2372 ggcards=1;
2373 }
2374 read_cards();
2375 for (sn=0;sn<numsp;sn++) {
2376 selpos[sn].act=-1;
2377 xinitwin(sn,sn?0:theargc,sn?(char **)0:theargv);
2378 }
2379 init_dials();
2380 for (ln=0;ln<NUM_LANG;ln++) {
2381 for (sn=0;sn<3;sn++) {
2382 tspnames[sn][0].t[ln]=spnames[sn][0][ln];
2383 tspnames[sn][1].t[ln]=spnames[sn][1][ln];
2384 }
2385 }
2386 set_conames();
2387 if (!irc_play) save_opt();
2388 }
2389
waitt(t,f)2390 VOID waitt(t,f)
2391 int t,f;
2392 {
2393 struct timeval timeout;
2394 int sn;
2395
2396 if (numgames) return;
2397 ticker+=t;
2398 if (!irc_play || irc_state==IRC_PLAYING) {
2399 for (sn=0;sn<numsp;sn++) {
2400 if (!lost[sn]) {
2401 if (!f) {
2402 XFlush(dpy[sn]);
2403 }
2404 else {
2405 XSync(dpy[sn],0);
2406 }
2407 }
2408 }
2409 }
2410 timeout.tv_sec=t/1000;
2411 timeout.tv_usec=(t%1000)*1000L;
2412 select(0,NULL,NULL,NULL,&timeout);
2413 if (f>1) refresh();
2414 }
2415
stdwait()2416 VOID stdwait()
2417 {
2418 waitt(700,2);
2419 }
2420
backgr(sn,x,y,w,h)2421 VOID backgr(sn,x,y,w,h)
2422 int sn,x,y,w,h;
2423 {
2424 XFillRectangle(dpy[sn],bck[sn],gcbck[sn],x,y,w,h);
2425 XFillRectangle(dpy[sn],win[sn],gcbck[sn],x,y,w,h);
2426 }
2427
putdesk(sn,x,y)2428 VOID putdesk(sn,x,y)
2429 int sn,x,y;
2430 {
2431 backgr(sn,x,y,desk[sn].cardw,desk[sn].cardh);
2432 }
2433
drawcard(sn,c,x,y)2434 VOID drawcard(sn,c,x,y)
2435 int sn,c,x,y;
2436 {
2437 XCopyArea(dpy[sn],cardpx[sn][c+1],win[sn],gc[sn],0,0,
2438 desk[sn].cardw,desk[sn].cardh,x,y);
2439 XCopyArea(dpy[sn],cardpx[sn][c+1],bck[sn],gc[sn],0,0,
2440 desk[sn].cardw,desk[sn].cardh,x,y);
2441 }
2442
2443
putcard(sn,i,x,y)2444 VOID putcard(sn,i,x,y)
2445 int sn,i,x,y;
2446 {
2447 if (i<0) putdesk(sn,x,y);
2448 else drawcard(sn,i,x,y);
2449 }
2450
putback(sn,x,y)2451 VOID putback(sn,x,y)
2452 int sn,x,y;
2453 {
2454 drawcard(sn,-1,x,y);
2455 }
2456
hint_line(sn,c,gcp)2457 VOID hint_line(sn,c,gcp)
2458 int sn,c;
2459 GC *gcp;
2460 {
2461 int xyarr[4];
2462
2463 xyarr[0]=(c<30?desk[sn].playx:desk[sn].skatx)+
2464 (c%10)*desk[sn].cardx+7*desk[sn].f/desk[sn].q;
2465 xyarr[1]=(c<30?desk[sn].playy:desk[sn].skaty)
2466 -5*desk[sn].f/desk[sn].q;
2467 xyarr[2]=xyarr[0]+desk[sn].cardx-16*desk[sn].f/desk[sn].q+1;
2468 xyarr[3]=xyarr[1];
2469 XDrawLine(dpy[sn],win[sn],gcp[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2470 XDrawLine(dpy[sn],bck[sn],gcp[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2471 }
2472
show_hint(sn,c,d)2473 VOID show_hint(sn,c,d)
2474 int sn,c,d;
2475 {
2476 static int lm[3][2];
2477
2478 if (lm[sn][c]) {
2479 hint_line(sn,lm[sn][c]-1,gcbck);
2480 }
2481 if (d) {
2482 change_gc(sn,mkpix[sn],gc);
2483 hint_line(sn,hintcard[c],gc);
2484 change_gc(sn,fgpix[sn],gc);
2485 lm[sn][c]=hintcard[c]+1;
2486 }
2487 else {
2488 lm[sn][c]=0;
2489 }
2490 }
2491
putamark(sn,s)2492 VOID putamark(sn,s)
2493 int sn,s;
2494 {
2495 int a,b,xp1,xp2,yp,xyarr[4];
2496
2497 if (sn==s || ouveang || (spitzeang && !sptzmrk)) return;
2498 a=48*desk[sn].f/desk[sn].q-4;
2499 b=48*desk[sn].f/desk[sn].q-2;
2500 change_gc(sn,mkpix[sn],gc);
2501 xp1=desk[sn].com1x+32*desk[sn].f/desk[sn].q;
2502 xp2=desk[sn].com2x+32*desk[sn].f/desk[sn].q;
2503 yp=desk[sn].com1y+2*desk[sn].f/desk[sn].q;
2504 xyarr[0]=(s==left(sn)?xp1:xp2)-a/2;
2505 xyarr[1]=yp;
2506 xyarr[2]=xyarr[0]+a-4*desk[sn].f/desk[sn].q+3;
2507 xyarr[3]=xyarr[1];
2508 XDrawLine(dpy[sn],win[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2509 XDrawLine(dpy[sn],bck[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2510 xyarr[1]=yp+89*desk[sn].f/desk[sn].q;
2511 xyarr[3]=xyarr[1];
2512 XDrawLine(dpy[sn],win[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2513 XDrawLine(dpy[sn],bck[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2514 xyarr[0]=(s==left(sn)?xp1:xp2)-b/2;
2515 xyarr[1]=yp+1;
2516 xyarr[2]=xyarr[0]+b-4*desk[sn].f/desk[sn].q+3;
2517 xyarr[3]=xyarr[1];
2518 XDrawLine(dpy[sn],win[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2519 XDrawLine(dpy[sn],bck[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2520 xyarr[1]=yp+88*desk[sn].f/desk[sn].q;
2521 xyarr[3]=xyarr[1];
2522 XDrawLine(dpy[sn],win[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2523 XDrawLine(dpy[sn],bck[sn],gc[sn],xyarr[0],xyarr[1],xyarr[2],xyarr[3]);
2524 change_gc(sn,fgpix[sn],gc);
2525 }
2526
putmark(s)2527 VOID putmark(s)
2528 int s;
2529 {
2530 int sn;
2531
2532 for (sn=0;sn<numsp;sn++) {
2533 putamark(sn,s);
2534 }
2535 }
2536
remmark(f)2537 VOID remmark(f)
2538 int f;
2539 {
2540 int sn;
2541
2542 for (sn=0;sn<numsp;sn++) {
2543 putback(sn,desk[sn].com1x,desk[sn].com1y);
2544 putback(sn,desk[sn].com2x,desk[sn].com2y);
2545 if (f) putamark(sn,spieler);
2546 }
2547 }
2548
movecard(nn,sn,x1,y1,x2,y2)2549 VOID movecard(nn,sn,x1,y1,x2,y2)
2550 int nn,sn[],x1[],y1[],x2[],y2[];
2551 {
2552 int dx[3],dy[3],i,j,n=8;
2553
2554 for (i=0;i<nn;i++) {
2555 dx[i]=x2[i]-x1[i];
2556 dy[i]=y2[i]-y1[i];
2557 }
2558 for (i=0;i<n;i++) {
2559 for (j=0;j<nn;j++) {
2560 XDrawRectangle(dpy[sn[j]],win[sn[j]],gcxor[sn[j]],
2561 x1[j]+i*dx[j]/n,y1[j]+i*dy[j]/n,
2562 desk[sn[j]].cardw,desk[sn[j]].cardh);
2563 }
2564 waitt(9,0);
2565 for (j=0;j<nn;j++) {
2566 XDrawRectangle(dpy[sn[j]],win[sn[j]],gcxor[sn[j]],
2567 x1[j]+i*dx[j]/n,y1[j]+i*dy[j]/n,
2568 desk[sn[j]].cardw,desk[sn[j]].cardh);
2569 }
2570 }
2571 refresh();
2572 }
2573
homecard(s,n,m)2574 VOID homecard(s,n,m)
2575 int s,n,m;
2576 {
2577 int sn,sna[3],x1[3],y1[3],x2[3],y2[3];
2578
2579 for (sn=0;sn<numsp;sn++) {
2580 sna[sn]=sn;
2581 x2[sn]=desk[sn].x+desk[sn].w;
2582 if (s!=sn) {
2583 y2[sn]=desk[sn].com1y;
2584 if (s==left(sn)) x2[sn]=desk[sn].x-desk[sn].cardw;
2585 }
2586 else y2[sn]=desk[sn].playy;
2587 x1[sn]=(n?desk[sn].stichx:desk[sn].skatx)+m*desk[sn].cardw;
2588 y1[sn]=n?desk[sn].stichy:desk[sn].skaty;
2589 putdesk(sn,x1[sn],y1[sn]);
2590 }
2591 if (!umdrueck) movecard(numsp,sna,x1,y1,x2,y2);
2592 }
2593
givecard(s,n)2594 VOID givecard(s,n)
2595 int s,n;
2596 {
2597 int sn,sna[3],x1[3],y1[3],x2[3],y2[3];
2598
2599 sptzmrk=0;
2600 for (sn=0;sn<numsp;sn++) {
2601 sna[sn]=sn;
2602 if (s<0) {
2603 x1[sn]=desk[sn].skatx;
2604 y1[sn]=desk[sn].skaty;
2605 }
2606 else if (s!=sn) {
2607 if (s==left(sn)) x1[sn]=desk[sn].com1x;
2608 else x1[sn]=desk[sn].com2x;
2609 y1[sn]=desk[sn].com1y;
2610 }
2611 else {
2612 if (!n) x1[sn]=desk[sn].playx;
2613 else if (n==1) x1[sn]=desk[sn].playx+3*desk[sn].cardx;
2614 else x1[sn]=desk[sn].playx+7*desk[sn].cardx;
2615 y1[sn]=desk[sn].playy;
2616 }
2617 x2[sn]=desk[sn].x+desk[sn].w;
2618 if (geber!=sn) {
2619 y2[sn]=desk[sn].com1y;
2620 if (geber==left(sn)) x2[sn]=desk[sn].x-desk[sn].cardw;
2621 }
2622 else y2[sn]=desk[sn].playy;
2623 }
2624 if (!fastdeal) movecard(numsp,sna,x2,y2,x1,y1);
2625 for (sn=0;sn<numsp;sn++) {
2626 putback(sn,x1[sn],y1[sn]);
2627 if (s==hoerer) putamark(sn,s);
2628 if (s==sn) {
2629 putback(sn,x1[sn]+desk[sn].cardx,y1[sn]);
2630 putback(sn,x1[sn]+2*desk[sn].cardx,y1[sn]);
2631 if (n==1) putback(sn,x1[sn]+3*desk[sn].cardx,y1[sn]);
2632 }
2633 else if (s<0) {
2634 putback(sn,x1[sn]+desk[sn].cardw,y1[sn]);
2635 }
2636 }
2637 if (!fastdeal) waitt(300,2);
2638 }
2639
initscr(sn,sor)2640 VOID initscr(sn,sor)
2641 int sn,sor;
2642 {
2643 int i,x,y,c0,c1;
2644
2645 if (phase==WEITER || phase==REVOLUTION) return;
2646 if (sor) {
2647 c0=-1;
2648 c1=-1;
2649 if (hintcard[0]!=-1) {
2650 if (phase==SPIELEN) {
2651 c0=cards[hintcard[0]];
2652 }
2653 else if (phase==DRUECKEN) {
2654 if (hintcard[0]<30) c0=cards[hintcard[0]];
2655 if (hintcard[1]<30) c1=cards[hintcard[1]];
2656 }
2657 }
2658 if (sor!=2) sort(sn);
2659 else {
2660 if (skatopen) draw_skat(spieler);
2661 if (phase==SPIELEN || phase==NIMMSTICH) {
2662 for (i=0;i<stichopen;i++) {
2663 putcard(sn,stcd[i],desk[sn].stichx+i*desk[sn].cardw,desk[sn].stichy);
2664 }
2665 }
2666 }
2667 for (i=0;i<10;i++) {
2668 if (c0>=0 && c0==cards[sn*10+i]) hintcard[0]=sn*10+i;
2669 if (c1>=0 && c1==cards[sn*10+i]) hintcard[1]=sn*10+i;
2670 if (hintcard[0]!=-1 && !iscomp(sn) && hints[sn]) {
2671 if (phase==SPIELEN && sn==(ausspl+vmh)%3) {
2672 show_hint(sn,0,1);
2673 }
2674 else if (phase==DRUECKEN && sn==spieler) {
2675 show_hint(sn,0,1);
2676 show_hint(sn,1,1);
2677 }
2678 }
2679 putcard(sn,cards[sn*10+i],
2680 desk[sn].playx+i*desk[sn].cardx,desk[sn].playy);
2681 }
2682 }
2683 if (phase!=ANSAGEN) {
2684 di_info(sn,-1);
2685 if (predef && (!ouveang || sn==spieler) && (sn || !nopre)) {
2686 x=desk[sn].w/2;
2687 y=desk[sn].y+2*charh[sn];
2688 v_gtext(sn,x,y,0,textarr[TX_VORDEFINIERTES_SPIEL].t[lang[sn]]);
2689 }
2690 }
2691 if (phase!=ANSAGEN && ouveang) {
2692 if (sn==spieler) {
2693 for (sn=0;sn<numsp;sn++) {
2694 if (sn!=spieler) initscr(sn,0);
2695 }
2696 }
2697 else {
2698 y=spieler==left(sn)?desk[sn].com1y:desk[sn].com2y;
2699 for (i=0;i<10;i++) {
2700 putcard(sn,cards[spieler*10+i],desk[sn].playx+i*desk[sn].cardx,y);
2701 }
2702 x=spieler==left(sn)?desk[sn].com2x:desk[sn].com1x;
2703 y=spieler==left(sn)?desk[sn].com2y:desk[sn].com1y;
2704 if (backopen[spieler==left(sn)?left(spieler):left(sn)]) putback(sn,x,y);
2705 }
2706 }
2707 else if (spitzeang && sn!=spieler && spitzeopen) {
2708 x=spieler==left(sn)?desk[sn].com1x:desk[sn].com2x;
2709 y=spieler==left(sn)?desk[sn].com1y:desk[sn].com2y;
2710 putcard(sn,trumpf==4?BUBE:SIEBEN|trumpf<<3,x,y);
2711 }
2712 }
2713
spielendscr()2714 VOID spielendscr()
2715 {
2716 int sn,s,i,d,x,y1,y2,sav[3];
2717
2718 clr_desk(0);
2719 for (sn=0;sn<numsp;sn++) {
2720 di_info(sn,-2);
2721 for (s=0;s<3;s++) {
2722 sav[0]=alternate[s];
2723 sav[1]=sort1[s];
2724 sav[2]=sort2[s];
2725 alternate[s]=0;
2726 sort1[s]=sort1[sn];
2727 sort2[s]=sort2[sn];
2728 sort(s);
2729 alternate[s]=sav[0];
2730 sort1[s]=sav[1];
2731 sort2[s]=sav[2];
2732 }
2733 y1=desk[sn].com1y;
2734 y2=desk[sn].skaty;
2735 if (left(sn)!=spieler) swap(&y1,&y2);
2736 d=sort1[sn]?stich-1:0;
2737 for (i=0;i<11-stich;i++) {
2738 x=desk[sn].playx+(stich-1+2*i)*desk[sn].cardx/2;
2739 putcard(sn,cards[sn*10+i+d],x,desk[sn].playy);
2740 s=left(sn);
2741 putcard(sn,cards[s*10+i+d],x,y1);
2742 s=left(s);
2743 putcard(sn,cards[s*10+i+d],x,y2);
2744 }
2745 if (sn!=spieler || abkuerz[sn]==2) {
2746 x=desk[sn].skatx+desk[sn].cardx;
2747 y1=(desk[sn].skaty+desk[sn].com1y+desk[sn].cardh-charh[sn])/2;
2748 v_gtext(sn,x,y1,0,textarr[trumpf==-1?TX_NULL_DICHT:TX_REST_BEI_MIR].
2749 t[lang[sn]]);
2750 }
2751 }
2752 phase=WEITER;
2753 di_weiter(1);
2754 }
2755
revolutionsort(sp)2756 VOID revolutionsort(sp)
2757 int sp;
2758 {
2759 int sn,s,i,x,y1,y2,sav[3];
2760
2761 for (s=0;s<3;s++) {
2762 sav[0]=alternate[s];
2763 sav[1]=sort1[s];
2764 sav[2]=sort2[s];
2765 alternate[s]=0;
2766 sort1[s]=revolsort;
2767 sort2[s]=1;
2768 sort(s);
2769 alternate[s]=sav[0];
2770 sort1[s]=sav[1];
2771 sort2[s]=sav[2];
2772 }
2773 for (sn=0;sn<numsp;sn++) {
2774 if (sn==spieler) continue;
2775 y1=desk[sn].com1y;
2776 y2=desk[sn].skaty;
2777 if (left(sn)!=spieler) swap(&y1,&y2);
2778 for (i=0;i<10;i++) {
2779 x=desk[sn].playx+i*desk[sn].cardx;
2780 putcard(sn,cards[sn*10+i],x,desk[sn].playy);
2781 s=left(sn);
2782 if (sp || s!=spieler) putcard(sn,cards[s*10+i],x,y1);
2783 s=left(s);
2784 if (sp || s!=spieler) putcard(sn,cards[s*10+i],x,y2);
2785 }
2786 }
2787 }
2788
revolutionscr()2789 VOID revolutionscr()
2790 {
2791 int sn,mi,x,y,f;
2792
2793 tauschcard=-1;
2794 tauschdone=0;
2795 revolsort=iscomp(spieler)?sort1[0]:sort1[spieler];
2796 clr_desk(1);
2797 f=1;
2798 for (sn=0;sn<numsp;sn++) {
2799 if (sn==spieler) continue;
2800 di_info(sn,-2);
2801 x=desk[sn].skatx+desk[sn].cardx;
2802 y=(desk[sn].skaty+desk[sn].com1y+desk[sn].cardh-charh[sn])/2;
2803 v_gtext(sn,x,y,0,textarr[TX_KARTEN_AUSTAUSCHEN].t[lang[sn]]);
2804 mi=left(sn)==spieler?left(spieler):left(sn);
2805 x=desk[sn].playx+10*desk[sn].f/desk[sn].q;
2806 v_gtextnc(sn,0,0,x,desk[sn].com1y+desk[sn].cardh+1,
2807 0,textarr[spieler==ausspl?TX_VORHAND:
2808 spieler==left(ausspl)?TX_MITTELHAND:
2809 TX_HINTERHAND].t[lang[sn]]);
2810 v_gtextnc(sn,0,0,x,desk[sn].skaty-charh[sn]-1,
2811 0,textarr[mi==ausspl?TX_VORHAND:
2812 mi==left(ausspl)?TX_MITTELHAND:
2813 TX_HINTERHAND].t[lang[sn]]);
2814 if (f) {
2815 tauschply=sn;
2816 put_fbox(sn,TX_FERTIG);
2817 f=0;
2818 }
2819 }
2820 revolutionsort(1);
2821 phase=REVOLUTION;
2822 }
2823
clr_desk(nsp)2824 VOID clr_desk(nsp)
2825 int nsp;
2826 {
2827 int sn;
2828
2829 for (sn=0;sn<numsp;sn++) {
2830 if (!nsp || sn!=spieler) {
2831 backgr(sn,desk[sn].x,desk[sn].y,desk[sn].w,desk[sn].h);
2832 di_info(sn,3);
2833 }
2834 }
2835 if (!nsp && ouveang) {
2836 for (sn=0;sn<numsp;sn++) {
2837 if (sn!=spieler) di_info(sn,-2);
2838 }
2839 ouveang=0;
2840 for (sn=0;sn<numsp;sn++) {
2841 calc_desk(sn);
2842 if (sn!=spieler) di_info(sn,3);
2843 }
2844 ouveang=1;
2845 }
2846 }
2847
draw_box(sn,x,y,w)2848 VOID draw_box(sn,x,y,w)
2849 int sn,x,y,w;
2850 {
2851 int xy[4];
2852
2853 xy[0]=x+2;xy[1]=y-1;
2854 xy[2]=x+w-3;xy[3]=y+charh[sn]-gfx3d[sn]+1;
2855 if (gfx3d[sn]) {
2856 draw_3d(win[sn],bck[sn],sn,xy[0],xy[1],xy[2],xy[3],0);
2857 }
2858 else {
2859 XDrawRectangle(dpy[sn],win[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2860 XDrawRectangle(dpy[sn],bck[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2861 }
2862 xy[0]++;xy[1]++;
2863 xy[2]--;xy[3]--;
2864 if (gfx3d[sn]) {
2865 draw_3d(win[sn],bck[sn],sn,xy[0],xy[1],xy[2],xy[3],0);
2866 }
2867 else {
2868 XDrawRectangle(dpy[sn],win[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2869 XDrawRectangle(dpy[sn],bck[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2870 }
2871 xy[0]++;xy[1]++;
2872 change_gc(sn,btpix[sn],gc);
2873 XFillRectangle(dpy[sn],win[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2874 XFillRectangle(dpy[sn],bck[sn],gc[sn],xy[0],xy[1],xy[2]-xy[0],xy[3]-xy[1]);
2875 change_gc(sn,fgpix[sn],gc);
2876 }
2877
put_box(s)2878 VOID put_box(s)
2879 int s;
2880 {
2881 int sn;
2882
2883 for (sn=0;sn<numsp;sn++) {
2884 if (s!=sn) {
2885 if (s==left(sn)) draw_box(sn,desk[sn].cbox1x,desk[sn].cboxy,
2886 desk[sn].cardw);
2887 else draw_box(sn,desk[sn].cbox2x,desk[sn].cboxy,desk[sn].cardw);
2888 }
2889 else {
2890 draw_box(sn,desk[sn].pboxx,desk[sn].pboxy,desk[sn].cardw);
2891 draw_box(sn,desk[sn].pboxx+desk[sn].cardw,desk[sn].pboxy,desk[sn].cardw);
2892 }
2893 }
2894 }
2895
rem_box(s)2896 VOID rem_box(s)
2897 int s;
2898 {
2899 int sn;
2900
2901 for (sn=0;sn<numsp;sn++) {
2902 if (s!=sn) {
2903 if (s==left(sn)) backgr(sn,desk[sn].cbox1x,desk[sn].cboxy-5,
2904 66*desk[sn].f/desk[sn].q,
2905 28*desk[sn].f/desk[sn].q);
2906 else backgr(sn,desk[sn].cbox2x,desk[sn].cboxy-5,
2907 desk[sn].cardw,28*desk[sn].f/desk[sn].q);
2908 }
2909 else {
2910 backgr(sn,desk[sn].pboxx,desk[sn].pboxy-5,
2911 desk[sn].cardw,28*desk[sn].f/desk[sn].q);
2912 backgr(sn,desk[sn].pboxx+desk[sn].cardw,desk[sn].pboxy-5,
2913 desk[sn].cardw,28*desk[sn].f/desk[sn].q);
2914 }
2915 }
2916 }
2917
inv_box(s,c,rev)2918 VOID inv_box(s,c,rev)
2919 int s,c,rev;
2920 {
2921 int sn,x,y,w,h;
2922
2923 for (sn=0;sn<numsp;sn++) {
2924 x=(s!=sn
2925 ?s==left(sn)
2926 ?desk[sn].cbox1x
2927 :desk[sn].cbox2x
2928 :desk[sn].pboxx+(c?desk[sn].cardw:0))+4;
2929 y=(s!=sn?desk[sn].cboxy:desk[sn].pboxy)+1;
2930 w=64*desk[sn].f/desk[sn].q-8;
2931 h=charh[sn]-gfx3d[sn]-1;
2932 if (gfx3d[sn]) {
2933 draw_3d(win[sn],bck[sn],sn,x-1,y-1,x+w,y+h,rev);
2934 draw_3d(win[sn],bck[sn],sn,x-2,y-2,x+w+1,y+h+1,rev);
2935 }
2936 else {
2937 change_gcxor(sn,btpix[sn]^fgpix[sn]^bgpix[sn]);
2938 XFillRectangle(dpy[sn],win[sn],gcxor[sn],x,y,w,h);
2939 XFillRectangle(dpy[sn],bck[sn],gcxor[sn],x,y,w,h);
2940 change_gcxor(sn,fgpix[sn]);
2941 }
2942 }
2943 }
2944
put_fbox(sn,t)2945 VOID put_fbox(sn,t)
2946 int sn,t;
2947 {
2948 draw_box(sn,desk[sn].pboxx+24*desk[sn].f/desk[sn].q,desk[sn].pboxy,
2949 80*desk[sn].f/desk[sn].q);
2950 v_gtextc(sn,1,desk[sn].pboxx+24*desk[sn].f/desk[sn].q,desk[sn].pboxy,
2951 80*desk[sn].f/desk[sn].q,
2952 textarr[t].t[lang[sn]]);
2953 }
2954
rem_fbox(sn)2955 VOID rem_fbox(sn)
2956 int sn;
2957 {
2958 backgr(sn,desk[sn].pboxx+24*desk[sn].f/desk[sn].q,desk[sn].pboxy-5,
2959 80*desk[sn].f/desk[sn].q,28*desk[sn].f/desk[sn].q);
2960 }
2961
inv_fbox(sn,rev)2962 VOID inv_fbox(sn,rev)
2963 int sn,rev;
2964 {
2965 int x,y,w,h;
2966
2967 x=desk[sn].pboxx+24*desk[sn].f/desk[sn].q+4;
2968 y=desk[sn].pboxy+1;
2969 w=80*desk[sn].f/desk[sn].q-8;
2970 h=charh[sn]-gfx3d[sn]-1;
2971 if (gfx3d[sn]) {
2972 draw_3d(win[sn],bck[sn],sn,x-1,y-1,x+w,y+h,rev);
2973 draw_3d(win[sn],bck[sn],sn,x-2,y-2,x+w+1,y+h+1,rev);
2974 }
2975 else {
2976 change_gcxor(sn,btpix[sn]^fgpix[sn]^bgpix[sn]);
2977 XFillRectangle(dpy[sn],win[sn],gcxor[sn],x,y,w,h);
2978 XFillRectangle(dpy[sn],bck[sn],gcxor[sn],x,y,w,h);
2979 change_gcxor(sn,fgpix[sn]);
2980 }
2981 }
2982
card_at(sn,x,y,zw)2983 int card_at(sn,x,y,zw)
2984 int sn,x,y,zw;
2985 {
2986 int c,s;
2987
2988 zw=(zw && y>=desk[sn].skaty && y<desk[sn].skaty+desk[sn].cardh);
2989 if (y>=desk[sn].playy || zw) {
2990 x-=desk[sn].playx;
2991 if (x<0) return 0;
2992 c=x/desk[sn].cardx;
2993 if (c>9) c=9;
2994 s=zw?left(sn)==spieler?left(spieler):left(sn):sn;
2995 if (cards[10*s+c]>=0) return c+1+(zw?10:0);
2996 }
2997 return 0;
2998 }
2999
hndl_reizen(sn,x,y)3000 int hndl_reizen(sn,x,y)
3001 int sn,x,y;
3002 {
3003 int b;
3004
3005 if (x<=desk[sn].pboxx+60*desk[sn].f/desk[sn].q) b=0;
3006 else b=desk[sn].cardw;
3007 if (x>=desk[sn].pboxx+3*desk[sn].f/desk[sn].q+b &&
3008 x<=desk[sn].pboxx+60*desk[sn].f/desk[sn].q+b &&
3009 y>=desk[sn].pboxy+1 &&
3010 y<=desk[sn].pboxy+16*desk[sn].f/desk[sn].q) {
3011 di_delres(sn);
3012 if (b) maxrw[sn]=0;
3013 else {
3014 maxrw[sn]=999-1;
3015 }
3016 do_entsch();
3017 return 1;
3018 }
3019 return 0;
3020 }
3021
hndl_druecken(sn,x,y)3022 int hndl_druecken(sn,x,y)
3023 int sn,x,y;
3024 {
3025 int c,sna[1],x1[1],y1[1],x2[1],y2[1];
3026
3027 c=card_at(sn,x,y,0);
3028 if (c) {
3029 c--;
3030 swap(&cards[10*sn+c],&cards[drkcd+30]);
3031 if (hintcard[0]==10*sn+c) {
3032 hintcard[0]=drkcd+30;
3033 if (hints[sn]) show_hint(sn,0,0);
3034 }
3035 else if (hintcard[0]==drkcd+30) hintcard[0]=10*sn+c;
3036 if (hintcard[1]==10*sn+c) {
3037 hintcard[1]=drkcd+30;
3038 if (hints[sn]) show_hint(sn,1,0);
3039 }
3040 else if (hintcard[1]==drkcd+30) hintcard[1]=10*sn+c;
3041 sna[0]=sn;
3042 x1[0]=desk[sn].playx+c*desk[sn].cardx;
3043 y1[0]=desk[sn].playy;
3044 x2[0]=desk[sn].skatx+drkcd*desk[sn].cardw;
3045 y2[0]=desk[sn].skaty;
3046 movecard(1,sna,x1,y1,x2,y2);
3047 putcard(sn,cards[drkcd+30],x2[0],y2[0]);
3048 initscr(sn,1);
3049 drkcd=1-drkcd;
3050 return 1;
3051 }
3052 if (x>=desk[sn].pboxx+27*desk[sn].f/desk[sn].q &&
3053 x<=desk[sn].pboxx+100*desk[sn].f/desk[sn].q &&
3054 y>=desk[sn].pboxy+1 &&
3055 y<=desk[sn].pboxy+16*desk[sn].f/desk[sn].q) inv_fbox(spieler,1);
3056 else return 0;
3057 if (hints[sn] && hintcard[0]!=-1) {
3058 show_hint(sn,0,0);
3059 show_hint(sn,1,0);
3060 }
3061 stdwait();
3062 inv_fbox(spieler,0);
3063 if (trumpf==5 && (((cards[30]&7)==BUBE) || ((cards[31]&7)==BUBE))) {
3064 di_buben();
3065 return 1;
3066 }
3067 rem_fbox(spieler);
3068 drbut=0;
3069 if (trumpf==5) {
3070 putback(sn,desk[sn].skatx,desk[sn].skaty);
3071 putback(sn,desk[sn].skatx+desk[sn].cardw,desk[sn].skaty);
3072 if (ramschspiele && klopfen) {
3073 di_klopfen(spieler);
3074 }
3075 else {
3076 vmh=left(vmh);
3077 if (vmh) di_schieben();
3078 else start_ramsch();
3079 }
3080 return 1;
3081 }
3082 home_skat();
3083 save_skat(1);
3084 for (c=0;c<2;c++) {
3085 stsum+=cardw[cards[c+30]&7];
3086 gespcd[cards[c+30]]=1;
3087 cards[c+30]=-1;
3088 }
3089 gedr=2;
3090 do_ansagen();
3091 return 1;
3092 }
3093
hndl_tauschen(sn,x,y)3094 int hndl_tauschen(sn,x,y)
3095 int sn,x,y;
3096 {
3097 int c,c1,zw,mi,d[2],sna[2],x1[2],y1[2],x2[2],y2[2];
3098
3099 mi=left(sn)==spieler?left(spieler):left(sn);
3100 c=card_at(sn,x,y,1);
3101 if (c) {
3102 zw=c>10;
3103 c=(c-1)%10;
3104 c1=tauschcard!=-1?tauschcard%10:0;
3105 x1[0]=desk[sn].playx+c*desk[sn].cardx;
3106 y1[0]=zw?desk[sn].skaty:desk[sn].playy;
3107 x2[0]=desk[sn].playx+c1*desk[sn].cardx;
3108 y2[0]=zw?desk[sn].playy:desk[sn].skaty;
3109 d[0]=(zw?4:-4)*desk[sn].f/desk[sn].q;
3110 if (!iscomp(mi)) {
3111 x1[1]=desk[mi].playx+c*desk[mi].cardx;
3112 y1[1]=zw?desk[mi].playy:desk[mi].skaty;
3113 x2[1]=desk[mi].playx+c1*desk[mi].cardx;
3114 y2[1]=zw?desk[mi].skaty:desk[mi].playy;
3115 d[1]=(zw?4:-4)*desk[mi].f/desk[mi].q;
3116 }
3117 if (tauschcard!=-1) {
3118 if ((zw?mi:sn)==tauschcard/10) {
3119 if (c==c1) return 1;
3120 putdesk(sn,x2[0],y1[0]+d[0]);
3121 putcard(sn,cards[tauschcard],x2[0],y1[0]);
3122 if (!iscomp(mi)) {
3123 putdesk(mi,x2[1],y1[1]-d[1]);
3124 putcard(mi,cards[tauschcard],x2[1],y1[1]);
3125 }
3126 }
3127 else {
3128 swap(&cards[tauschcard],&cards[10*(zw?mi:sn)+c]);
3129 sna[0]=sn;
3130 if (!iscomp(mi)) sna[1]=mi;
3131 movecard(iscomp(mi)?1:2,sna,x1,y1,x2,y2);
3132 putdesk(sn,x2[0],y2[0]-d[0]);
3133 if (!iscomp(mi)) putdesk(mi,x2[1],y2[1]+d[1]);
3134 revolutionsort(0);
3135 tauschcard=-1;
3136 if (tauschdone) {
3137 tauschdone=0;
3138 }
3139 return 1;
3140 }
3141 }
3142 tauschcard=10*(zw?mi:sn)+c;
3143 putdesk(sn,x1[0],y1[0]);
3144 putcard(sn,cards[tauschcard],x1[0],y1[0]+d[0]);
3145 if (!iscomp(mi)) {
3146 putdesk(mi,x1[1],y1[1]);
3147 putcard(mi,cards[tauschcard],x1[1],y1[1]-d[1]);
3148 }
3149 return 1;
3150 }
3151 if (x>=desk[sn].pboxx+27*desk[sn].f/desk[sn].q &&
3152 x<=desk[sn].pboxx+100*desk[sn].f/desk[sn].q &&
3153 y>=desk[sn].pboxy+1 &&
3154 y<=desk[sn].pboxy+16*desk[sn].f/desk[sn].q) inv_fbox(sn,1);
3155 else return 0;
3156 stdwait();
3157 inv_fbox(sn,0);
3158 rem_fbox(sn);
3159 tauschdone|=left(sn)==spieler?1:2;
3160 if (iscomp(mi) || tauschdone==3) {
3161 clr_desk(1);
3162 spielphase();
3163 }
3164 else {
3165 tauschply=mi;
3166 put_fbox(mi,TX_FERTIG);
3167 }
3168 return 1;
3169 }
3170
hndl_spielen(sn,x,y)3171 int hndl_spielen(sn,x,y)
3172 int sn,x,y;
3173 {
3174 int i,c;
3175
3176 c=card_at(sn,x,y,0);
3177 if (c) {
3178 di_delres(sn);
3179 c--;
3180 calc_poss(sn);
3181 for (i=0;i<possc;i++) {
3182 if (10*sn+c==possi[i]) {
3183 if (hints[sn]) show_hint(sn,0,0);
3184 drop_card(10*sn+c,sn);
3185 do_next();
3186 break;
3187 }
3188 }
3189 return 1;
3190 }
3191 return 0;
3192 }
3193
hndl_nimmstich(sn)3194 int hndl_nimmstich(sn)
3195 int sn;
3196 {
3197 nimmstich[sn][1]=0;
3198 phase=SPIELEN;
3199 for (sn=0;sn<numsp;sn++) {
3200 if (nimmstich[sn][1]) {
3201 phase=NIMMSTICH;
3202 }
3203 }
3204 if (phase==SPIELEN) {
3205 next_stich();
3206 }
3207 return 1;
3208 }
3209
hndl_button(sn,x,y,opt,send)3210 int hndl_button(sn,x,y,opt,send)
3211 int sn,x,y,opt,send;
3212 {
3213 int ok=0;
3214 static int errcnt[3];
3215
3216 if (opt==2) {
3217 di_options(sn);
3218 errcnt[sn]=0;
3219 return 0;
3220 }
3221 if (phase==REIZEN) {
3222 if ((saho && sn==sager) || (!saho && sn==hoerer)) ok=hndl_reizen(sn,x,y);
3223 }
3224 else if (phase==DRUECKEN) {
3225 if (sn==spieler) ok=hndl_druecken(sn,x,y);
3226 }
3227 else if (phase==SPIELEN) {
3228 if (sn==(ausspl+vmh)%3) ok=hndl_spielen(sn,x,y);
3229 }
3230 else if (phase==NIMMSTICH) {
3231 if (nimmstich[sn][1]) ok=hndl_nimmstich(sn);
3232 }
3233 else if (phase==REVOLUTION) {
3234 if (sn==tauschply) ok=hndl_tauschen(sn,x,y);
3235 }
3236 if (!ok) {
3237 if (irc_play && sn!=irc_pos) return ok;
3238 if (opt==1) {
3239 di_options(sn);
3240 errcnt[sn]=0;
3241 }
3242 else {
3243 errcnt[sn]++;
3244 if (errcnt[sn]>=3) {
3245 di_eingabe(sn);
3246 errcnt[sn]=0;
3247 }
3248 }
3249 }
3250 else {
3251 errcnt[sn]=0;
3252 if (send && irc_play) irc_sendxyev(sn,x,y,opt);
3253 }
3254 return ok;
3255 }
3256
setcurs(f)3257 VOID setcurs(f)
3258 int f;
3259 {
3260 int x,y,w,sn,snn,newsn=-1;
3261 char clr[100];
3262 static int actsn=-1,wsn=-1,wtime;
3263 static int ur[3];
3264
3265 for (sn=0;sn<numsp;sn++) {
3266 switch (phase) {
3267 case REIZEN:
3268 if ((saho && sn==sager) || (!saho && sn==hoerer)) newsn=sn;
3269 break;
3270 case HANDSPIEL:
3271 case DRUECKEN:
3272 case ANSAGEN:
3273 case RESULT:
3274 if (phase==ANSAGEN && ktrply>=0) newsn=ktrply;
3275 else if (sn==spieler) newsn=sn;
3276 if (numsp==1) newsn=0;
3277 break;
3278 case SPIELEN:
3279 if (stich==1 && trumpf==5 && !ur[sn]) {
3280 di_info(sn,-1);
3281 ur[sn]=1;
3282 }
3283 if (stich==2) ur[sn]=0;
3284 if (sn==(ausspl+vmh)%3) newsn=sn;
3285 break;
3286 case SCHENKEN:
3287 newsn=schenkply;
3288 break;
3289 case NIMMSTICH:
3290 for (snn=0;snn<numsp;snn++) {
3291 if (nimmstich[snn][1]) newsn=snn;
3292 }
3293 break;
3294 case SPIELDICHT:
3295 newsn=spieler;
3296 break;
3297 case WEITER:
3298 newsn=-1;
3299 if (numsp==1) newsn=0;
3300 break;
3301 case REVOLUTION:
3302 newsn=tauschply;
3303 break;
3304 }
3305 }
3306 if (newsn!=actsn) {
3307 wtime=0;
3308 if (actsn>=0) XDefineCursor(dpy[actsn],win[actsn],cursor[actsn][1]);
3309 actsn=newsn;
3310 if (actsn>=0) {
3311 for (sn=0;sn<numsp;sn++) {
3312 if (phase!=WEITER && phase!=REVOLUTION) di_info(sn,actsn);
3313 }
3314 XDefineCursor(dpy[actsn],win[actsn],cursor[actsn][0]);
3315 }
3316 }
3317 if (f && actsn>=0) {
3318 if (phase!=WEITER && phase!=REVOLUTION) di_info(f-1,actsn);
3319 }
3320 if (actsn==-1) wtime=0;
3321 if (phase==REIZEN && bockspiele && !ramschspiele) wtime=15*1000;
3322 if (!wtime || wtime>=15*1000) {
3323 if (wsn!=-1 && (actsn!=wsn ||
3324 wtime==16*1000 ||
3325 (phase!=REIZEN && phase!=SPIELEN && phase!=NIMMSTICH))) {
3326 x=desk[wsn].w/2;
3327 y=(desk[wsn].pboxy+desk[wsn].playy)/2;
3328 w=5*desk[wsn].cardw/XTextWidth(dfont[wsn]," ",1)+1;
3329 if (w>99) w=99;
3330 clr[w]=0;
3331 while (w) clr[--w]=' ';
3332 v_gtext(wsn,x,y,0,clr);
3333 wsn=-1;
3334 if (wtime==16*1000) wtime-=1500;
3335 if (phase!=REIZEN && phase!=SPIELEN && phase!=NIMMSTICH) wtime=0;
3336 }
3337 if (wtime==15*1000 &&
3338 (phase==REIZEN || phase==SPIELEN || phase==NIMMSTICH)) {
3339 wsn=actsn;
3340 x=desk[wsn].w/2;
3341 y=(desk[wsn].pboxy+desk[wsn].playy)/2;
3342 if (phase==REIZEN) {
3343 if (bockspiele && !ramschspiele) {
3344 v_gtext(wsn,x,y,0,textarr[TX_BOCK_SPIEL].t[lang[wsn]]);
3345 }
3346 }
3347 else if (numsp!=1) {
3348 v_gtext(wsn,x,y,0,textarr[TX_DU_BIST_DRAN].t[lang[wsn]]);
3349 }
3350 }
3351 }
3352 wtime+=50;
3353 }
3354