147851Sbostic /*- 2*59968Sbostic * Copyright (c) 1991, 1993 The Regents of the University of California. 347851Sbostic * All rights reserved. 447851Sbostic * 5*59968Sbostic * The game adventure was originally written in Fortran by Will Crowther 6*59968Sbostic * and Don Woods. It was later translated to C and enhanced by Jim 7*59968Sbostic * Gillogly. This code is derived from software contributed to Berkeley 8*59968Sbostic * by Jim Gillogly at The Rand Corporation. 947851Sbostic * 1047851Sbostic * %sccs.include.redist.c% 1147851Sbostic */ 1247851Sbostic 1347851Sbostic #ifndef lint 14*59968Sbostic static char sccsid[] = "@(#)wizard.c 5.2 (Berkeley) 05/12/93"; 1547851Sbostic #endif /* not lint */ 1647851Sbostic 176742Srrh /* Re-coding of advent in C: privileged operations */ 186742Srrh 196742Srrh # include "hdr.h" 206742Srrh 216742Srrh datime(d,t) 226742Srrh int *d,*t; 236742Srrh { int tvec[2],*tptr; 246742Srrh int *localtime(); 25*59968Sbostic 266742Srrh time(tvec); 276742Srrh tptr=localtime(tvec); 286742Srrh *d=tptr[7]+365*(tptr[5]-77); /* day since 1977 (mod leap) */ 296742Srrh /* bug: this will overflow in the year 2066 AD */ 306742Srrh /* it will be attributed to Wm the C's millenial celebration */ 316742Srrh *t=tptr[2]*60+tptr[1]; /* and minutes since midnite */ 326742Srrh } /* pretty painless */ 336742Srrh 346742Srrh 35*59968Sbostic char magic[6]; 366742Srrh 376742Srrh poof() 38*59968Sbostic { 39*59968Sbostic strcpy(magic, DECR(d,w,a,r,f)); 40*59968Sbostic latncy = 45; 416742Srrh } 426742Srrh 436742Srrh start(n) 446742Srrh { int d,t,delay; 45*59968Sbostic 466742Srrh datime(&d,&t); 47*59968Sbostic delay=(d-saved)*1440+(t-savet); /* good for about a month */ 48*59968Sbostic 49*59968Sbostic if (delay >= latncy) 50*59968Sbostic { saved = -1; 516742Srrh return(FALSE); 526742Srrh } 53*59968Sbostic printf("This adventure was suspended a mere %d minute%s ago.", 54*59968Sbostic delay, delay == 1? "" : "s"); 55*59968Sbostic if (delay <= latncy/3) 566742Srrh { mspeak(2); 576742Srrh exit(0); 586742Srrh } 596742Srrh mspeak(8); 606742Srrh if (!wizard()) 616742Srrh { mspeak(9); 626742Srrh exit(0); 636742Srrh } 646742Srrh saved = -1; 656742Srrh return(FALSE); 666742Srrh } 676742Srrh 686742Srrh wizard() /* not as complex as advent/10 (for now) */ 696742Srrh { register int wiz; 706742Srrh char *word,*x; 716742Srrh if (!yesm(16,0,7)) return(FALSE); 726742Srrh mspeak(17); 736742Srrh getin(&word,&x); 746742Srrh if (!weq(word,magic)) 756742Srrh { mspeak(20); 766742Srrh return(FALSE); 776742Srrh } 786742Srrh mspeak(19); 796742Srrh return(TRUE); 806742Srrh } 816742Srrh 826742Srrh ciao(cmdfile) 836742Srrh char *cmdfile; 846742Srrh { register char *c; 856742Srrh register int outfd, size; 866742Srrh char fname[80], buf[512]; 876742Srrh extern unsigned filesize; 886742Srrh 89*59968Sbostic printf("What would you like to call the saved version?\n"); 90*59968Sbostic for (c=fname;; c++) 91*59968Sbostic if ((*c=getchar())=='\n') break; 92*59968Sbostic *c=0; 93*59968Sbostic if (save(fname) != 0) return; /* Save failed */ 94*59968Sbostic printf("To resume, say \"adventure %s\".\n", fname); 95*59968Sbostic printf("\"With these rooms I might now have been familiarly acquainted.\"\n"); 966742Srrh exit(0); 976742Srrh } 986742Srrh 996742Srrh 100*59968Sbostic ran(range) 101*59968Sbostic int range; 1026742Srrh { 1036742Srrh long rand(), i; 104*59968Sbostic 1056742Srrh i = rand() % range; 1066742Srrh return(i); 1076742Srrh } 108