1 /*-
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * The game adventure was originally written in Fortran by Will Crowther
6 * and Don Woods. It was later translated to C and enhanced by Jim
7 * Gillogly. This code is derived from software contributed to Berkeley
8 * by Jim Gillogly at The Rand Corporation.
9 *
10 * %sccs.include.redist.c%
11 */
12
13 #ifndef lint
14 static char sccsid[] = "@(#)wizard.c 8.1 (Berkeley) 06/02/93";
15 #endif /* not lint */
16
17 /* Re-coding of advent in C: privileged operations */
18
19 # include "hdr.h"
20
datime(d,t)21 datime(d,t)
22 int *d,*t;
23 { int tvec[2],*tptr;
24 int *localtime();
25
26 time(tvec);
27 tptr=localtime(tvec);
28 *d=tptr[7]+365*(tptr[5]-77); /* day since 1977 (mod leap) */
29 /* bug: this will overflow in the year 2066 AD */
30 /* it will be attributed to Wm the C's millenial celebration */
31 *t=tptr[2]*60+tptr[1]; /* and minutes since midnite */
32 } /* pretty painless */
33
34
35 char magic[6];
36
poof()37 poof()
38 {
39 strcpy(magic, DECR(d,w,a,r,f));
40 latncy = 45;
41 }
42
Start(n)43 Start(n)
44 { int d,t,delay;
45
46 datime(&d,&t);
47 delay=(d-saved)*1440+(t-savet); /* good for about a month */
48
49 if (delay >= latncy)
50 { saved = -1;
51 return(FALSE);
52 }
53 printf("This adventure was suspended a mere %d minute%s ago.",
54 delay, delay == 1? "" : "s");
55 if (delay <= latncy/3)
56 { mspeak(2);
57 exit(0);
58 }
59 mspeak(8);
60 if (!wizard())
61 { mspeak(9);
62 exit(0);
63 }
64 saved = -1;
65 return(FALSE);
66 }
67
wizard()68 wizard() /* not as complex as advent/10 (for now) */
69 { register int wiz;
70 char *word,*x;
71 if (!yesm(16,0,7)) return(FALSE);
72 mspeak(17);
73 getin(&word,&x);
74 if (!weq(word,magic))
75 { mspeak(20);
76 return(FALSE);
77 }
78 mspeak(19);
79 return(TRUE);
80 }
81
ciao(cmdfile)82 ciao(cmdfile)
83 char *cmdfile;
84 { register char *c;
85 register int outfd, size;
86 char fname[80], buf[512];
87 extern unsigned filesize;
88
89 printf("What would you like to call the saved version?\n");
90 for (c=fname;; c++)
91 if ((*c=getchar())=='\n') break;
92 *c=0;
93 if (save(fname) != 0) return; /* Save failed */
94 printf("To resume, say \"adventure %s\".\n", fname);
95 printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
96 exit(0);
97 }
98
99
ran(range)100 ran(range)
101 int range;
102 {
103 long rand(), i;
104
105 i = rand() % range;
106 return(i);
107 }
108