1*47851Sbostic /*- 2*47851Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*47851Sbostic * All rights reserved. 4*47851Sbostic * 5*47851Sbostic * The game adventure was original written Fortran by Will Crowther 6*47851Sbostic * and Don Woods. It was later translated to C and enhanced by 7*47851Sbostic * Jim Gillogly. 8*47851Sbostic * 9*47851Sbostic * %sccs.include.redist.c% 10*47851Sbostic */ 11*47851Sbostic 12*47851Sbostic #ifndef lint 13*47851Sbostic static char sccsid[] = "@(#)wizard.c 5.1 (Berkeley) 04/08/91"; 14*47851Sbostic #endif /* not lint */ 15*47851Sbostic 166742Srrh /* Re-coding of advent in C: privileged operations */ 176742Srrh 186742Srrh # include "hdr.h" 196742Srrh 206742Srrh datime(d,t) 216742Srrh int *d,*t; 226742Srrh { int tvec[2],*tptr; 236742Srrh int *localtime(); 246742Srrh time(tvec); 256742Srrh tptr=localtime(tvec); 266742Srrh *d=tptr[7]+365*(tptr[5]-77); /* day since 1977 (mod leap) */ 276742Srrh /* bug: this will overflow in the year 2066 AD */ 286742Srrh /* it will be attributed to Wm the C's millenial celebration */ 296742Srrh *t=tptr[2]*60+tptr[1]; /* and minutes since midnite */ 306742Srrh } /* pretty painless */ 316742Srrh 326742Srrh 336742Srrh char *magic; 346742Srrh 356742Srrh poof() 366742Srrh { magic="dwarf"; 376742Srrh latncy=45; 386742Srrh } 396742Srrh 406742Srrh start(n) 416742Srrh { int d,t,delay; 426742Srrh datime(&d,&t); 436742Srrh delay=(d-saved)*1440+(t-savet); /* good for about a month */ 446742Srrh if (delay>=latncy || setup >= 0) 456742Srrh { saved= -1; 466742Srrh return(FALSE); 476742Srrh } 486742Srrh printf("This adventure was suspended a mere %d minutes ago.",delay); 496742Srrh if (delay<=latncy/3) 506742Srrh { mspeak(2); 516742Srrh exit(0); 526742Srrh } 536742Srrh mspeak(8); 546742Srrh if (!wizard()) 556742Srrh { mspeak(9); 566742Srrh exit(0); 576742Srrh } 586742Srrh saved = -1; 596742Srrh return(FALSE); 606742Srrh } 616742Srrh 626742Srrh wizard() /* not as complex as advent/10 (for now) */ 636742Srrh { register int wiz; 646742Srrh char *word,*x; 656742Srrh if (!yesm(16,0,7)) return(FALSE); 666742Srrh mspeak(17); 676742Srrh getin(&word,&x); 686742Srrh if (!weq(word,magic)) 696742Srrh { mspeak(20); 706742Srrh return(FALSE); 716742Srrh } 726742Srrh mspeak(19); 736742Srrh return(TRUE); 746742Srrh } 756742Srrh 766742Srrh ciao(cmdfile) 776742Srrh char *cmdfile; 786742Srrh { register char *c; 796742Srrh register int outfd, size; 806742Srrh char fname[80], buf[512]; 816742Srrh extern unsigned filesize; 826742Srrh 836742Srrh lseek(datfd,(long)filesize,0); 846742Srrh for (;;) 856742Srrh { printf("What would you like to call the saved version?\n"); 866742Srrh for (c=fname;; c++) 876742Srrh if ((*c=getchar())=='\n') break; 886742Srrh *c=0; 896742Srrh if (save(cmdfile,fname)>=0) break; 906742Srrh printf("I can't use that one.\n"); 916742Srrh return; 926742Srrh } 936742Srrh outfd=open(fname,1); 946742Srrh lseek(outfd,0L,2); /* end of executable file */ 956742Srrh while ((size=read(datfd,buf,512))>0) 966742Srrh write(outfd,buf,size); /* copy the message data */ 976742Srrh printf(" ^\n"); 986742Srrh printf("That should do it. Gis revido.\n"); 996742Srrh exit(0); 1006742Srrh } 1016742Srrh 1026742Srrh 1036742Srrh ran(range) /* uses unix rng */ 1046742Srrh int range; /* can't div by 32768 because */ 1056742Srrh { 1066742Srrh long rand(), i; 1076742Srrh i = rand() % range; 1086742Srrh return(i); 1096742Srrh } 1106742Srrh 111