xref: /original-bsd/games/adventure/wizard.c (revision c471a344)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * The game adventure was original written Fortran by Will Crowther
6  * and Don Woods.  It was later translated to C and enhanced by
7  * Jim Gillogly.
8  *
9  * %sccs.include.redist.c%
10  */
11 
12 #ifndef lint
13 static char sccsid[] = "@(#)wizard.c	5.1 (Berkeley) 04/08/91";
14 #endif /* not lint */
15 
16 /*      Re-coding of advent in C: privileged operations                 */
17 
18 # include "hdr.h"
19 
20 datime(d,t)
21 int *d,*t;
22 {       int tvec[2],*tptr;
23 	int *localtime();
24 	time(tvec);
25 	tptr=localtime(tvec);
26 	*d=tptr[7]+365*(tptr[5]-77);    /* day since 1977  (mod leap)   */
27 	/* bug: this will overflow in the year 2066 AD                  */
28 	/* it will be attributed to Wm the C's millenial celebration    */
29 	*t=tptr[2]*60+tptr[1];          /* and minutes since midnite    */
30 }                                       /* pretty painless              */
31 
32 
33 char *magic;
34 
35 poof()
36 {       magic="dwarf";
37 	latncy=45;
38 }
39 
40 start(n)
41 {       int d,t,delay;
42 	datime(&d,&t);
43 	delay=(d-saved)*1440+(t-savet); /* good for about a month       */
44 	if (delay>=latncy || setup >= 0)
45 	{       saved= -1;
46 		return(FALSE);
47 	}
48 	printf("This adventure was suspended a mere %d minutes ago.",delay);
49 	if (delay<=latncy/3)
50 	{       mspeak(2);
51 		exit(0);
52 	}
53 	mspeak(8);
54 	if (!wizard())
55 	{       mspeak(9);
56 		exit(0);
57 	}
58 	saved = -1;
59 	return(FALSE);
60 }
61 
62 wizard()                /* not as complex as advent/10 (for now)        */
63 {       register int wiz;
64 	char *word,*x;
65 	if (!yesm(16,0,7)) return(FALSE);
66 	mspeak(17);
67 	getin(&word,&x);
68 	if (!weq(word,magic))
69 	{       mspeak(20);
70 		return(FALSE);
71 	}
72 	mspeak(19);
73 	return(TRUE);
74 }
75 
76 ciao(cmdfile)
77 char *cmdfile;
78 {       register char *c;
79 	register int outfd, size;
80 	char fname[80], buf[512];
81 	extern unsigned filesize;
82 
83 	lseek(datfd,(long)filesize,0);
84 	for (;;)
85 	{       printf("What would you like to call the saved version?\n");
86 		for (c=fname;; c++)
87 			if ((*c=getchar())=='\n') break;
88 		*c=0;
89 		if (save(cmdfile,fname)>=0) break;
90 		printf("I can't use that one.\n");
91 		return;
92 	}
93 	outfd=open(fname,1);
94 	lseek(outfd,0L,2);                /* end of executable file       */
95 	while ((size=read(datfd,buf,512))>0)
96 		write(outfd,buf,size);  /* copy the message data        */
97 	printf("                    ^\n");
98 	printf("That should do it.  Gis revido.\n");
99 	exit(0);
100 }
101 
102 
103 ran(range)                              /* uses unix rng                */
104 int range;                              /* can't div by 32768 because   */
105 {
106 	long rand(), i;
107 	i = rand() % range;
108 	return(i);
109 }
110 
111