147851Sbostic /*-
2*61056Sbostic * Copyright (c) 1991, 1993
3*61056Sbostic * The Regents of the University of California. All rights reserved.
447851Sbostic *
559968Sbostic * The game adventure was originally written in Fortran by Will Crowther
659968Sbostic * and Don Woods. It was later translated to C and enhanced by Jim
759968Sbostic * Gillogly. This code is derived from software contributed to Berkeley
859968Sbostic * by Jim Gillogly at The Rand Corporation.
947851Sbostic *
1047851Sbostic * %sccs.include.redist.c%
1147851Sbostic */
1247851Sbostic
1347851Sbostic #ifndef lint
14*61056Sbostic static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 06/02/93";
1547851Sbostic #endif /* not lint */
1647851Sbostic
176742Srrh /* Re-coding of advent in C: privileged operations */
186742Srrh
196742Srrh # include "hdr.h"
206742Srrh
datime(d,t)216742Srrh datime(d,t)
226742Srrh int *d,*t;
236742Srrh { int tvec[2],*tptr;
246742Srrh int *localtime();
2559968Sbostic
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
3559968Sbostic char magic[6];
366742Srrh
poof()376742Srrh poof()
3859968Sbostic {
3959968Sbostic strcpy(magic, DECR(d,w,a,r,f));
4059968Sbostic latncy = 45;
416742Srrh }
426742Srrh
Start(n)4361055Sbostic Start(n)
446742Srrh { int d,t,delay;
4559968Sbostic
466742Srrh datime(&d,&t);
4759968Sbostic delay=(d-saved)*1440+(t-savet); /* good for about a month */
4859968Sbostic
4959968Sbostic if (delay >= latncy)
5059968Sbostic { saved = -1;
516742Srrh return(FALSE);
526742Srrh }
5359968Sbostic printf("This adventure was suspended a mere %d minute%s ago.",
5459968Sbostic delay, delay == 1? "" : "s");
5559968Sbostic 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
wizard()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
ciao(cmdfile)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
8959968Sbostic printf("What would you like to call the saved version?\n");
9059968Sbostic for (c=fname;; c++)
9159968Sbostic if ((*c=getchar())=='\n') break;
9259968Sbostic *c=0;
9359968Sbostic if (save(fname) != 0) return; /* Save failed */
9459968Sbostic printf("To resume, say \"adventure %s\".\n", fname);
9559968Sbostic printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
966742Srrh exit(0);
976742Srrh }
986742Srrh
996742Srrh
ran(range)10059968Sbostic ran(range)
10159968Sbostic int range;
1026742Srrh {
1036742Srrh long rand(), i;
10459968Sbostic
1056742Srrh i = rand() % range;
1066742Srrh return(i);
1076742Srrh }
108