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