xref: /netbsd/games/adventure/wizard.c (revision c4816c32)
1*c4816c32Scgd /*	$NetBSD: wizard.c,v 1.3 1995/04/24 12:21:41 cgd Exp $	*/
243b95251Scgd 
3107c0a28Sjtc /*-
4107c0a28Sjtc  * Copyright (c) 1991, 1993
5107c0a28Sjtc  *	The Regents of the University of California.  All rights reserved.
6107c0a28Sjtc  *
7107c0a28Sjtc  * The game adventure was originally written in Fortran by Will Crowther
8107c0a28Sjtc  * and Don Woods.  It was later translated to C and enhanced by Jim
9107c0a28Sjtc  * Gillogly.  This code is derived from software contributed to Berkeley
10107c0a28Sjtc  * by Jim Gillogly at The Rand Corporation.
11107c0a28Sjtc  *
12107c0a28Sjtc  * Redistribution and use in source and binary forms, with or without
13107c0a28Sjtc  * modification, are permitted provided that the following conditions
14107c0a28Sjtc  * are met:
15107c0a28Sjtc  * 1. Redistributions of source code must retain the above copyright
16107c0a28Sjtc  *    notice, this list of conditions and the following disclaimer.
17107c0a28Sjtc  * 2. Redistributions in binary form must reproduce the above copyright
18107c0a28Sjtc  *    notice, this list of conditions and the following disclaimer in the
19107c0a28Sjtc  *    documentation and/or other materials provided with the distribution.
20107c0a28Sjtc  * 3. All advertising materials mentioning features or use of this software
21107c0a28Sjtc  *    must display the following acknowledgement:
22107c0a28Sjtc  *	This product includes software developed by the University of
23107c0a28Sjtc  *	California, Berkeley and its contributors.
24107c0a28Sjtc  * 4. Neither the name of the University nor the names of its contributors
25107c0a28Sjtc  *    may be used to endorse or promote products derived from this software
26107c0a28Sjtc  *    without specific prior written permission.
27107c0a28Sjtc  *
28107c0a28Sjtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29107c0a28Sjtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30107c0a28Sjtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31107c0a28Sjtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32107c0a28Sjtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33107c0a28Sjtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34107c0a28Sjtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35107c0a28Sjtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36107c0a28Sjtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37107c0a28Sjtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38107c0a28Sjtc  * SUCH DAMAGE.
39107c0a28Sjtc  */
40107c0a28Sjtc 
41107c0a28Sjtc #ifndef lint
4243b95251Scgd #if 0
43107c0a28Sjtc static char sccsid[] = "@(#)wizard.c	8.1 (Berkeley) 6/2/93";
4443b95251Scgd #else
45*c4816c32Scgd static char rcsid[] = "$NetBSD: wizard.c,v 1.3 1995/04/24 12:21:41 cgd Exp $";
4643b95251Scgd #endif
47107c0a28Sjtc #endif /* not lint */
48107c0a28Sjtc 
49107c0a28Sjtc /*      Re-coding of advent in C: privileged operations                 */
50107c0a28Sjtc 
51107c0a28Sjtc # include "hdr.h"
52*c4816c32Scgd #include <string.h>
53107c0a28Sjtc 
54107c0a28Sjtc datime(d,t)
55107c0a28Sjtc int *d,*t;
56107c0a28Sjtc {       int tvec[2],*tptr;
57107c0a28Sjtc 	int *localtime();
58107c0a28Sjtc 
59107c0a28Sjtc 	time(tvec);
60107c0a28Sjtc 	tptr=localtime(tvec);
61107c0a28Sjtc 	*d=tptr[7]+365*(tptr[5]-77);    /* day since 1977  (mod leap)   */
62107c0a28Sjtc 	/* bug: this will overflow in the year 2066 AD                  */
63107c0a28Sjtc 	/* it will be attributed to Wm the C's millenial celebration    */
64107c0a28Sjtc 	*t=tptr[2]*60+tptr[1];          /* and minutes since midnite    */
65107c0a28Sjtc }                                       /* pretty painless              */
66107c0a28Sjtc 
67107c0a28Sjtc 
68107c0a28Sjtc char magic[6];
69107c0a28Sjtc 
70107c0a28Sjtc poof()
71107c0a28Sjtc {
72107c0a28Sjtc 	strcpy(magic, DECR(d,w,a,r,f));
73107c0a28Sjtc 	latncy = 45;
74107c0a28Sjtc }
75107c0a28Sjtc 
76107c0a28Sjtc Start(n)
77107c0a28Sjtc {       int d,t,delay;
78107c0a28Sjtc 
79107c0a28Sjtc 	datime(&d,&t);
80107c0a28Sjtc 	delay=(d-saved)*1440+(t-savet); /* good for about a month     */
81107c0a28Sjtc 
82107c0a28Sjtc 	if (delay >= latncy)
83107c0a28Sjtc 	{       saved = -1;
84107c0a28Sjtc 		return(FALSE);
85107c0a28Sjtc 	}
86107c0a28Sjtc 	printf("This adventure was suspended a mere %d minute%s ago.",
87107c0a28Sjtc 		delay, delay == 1? "" : "s");
88107c0a28Sjtc 	if (delay <= latncy/3)
89107c0a28Sjtc 	{       mspeak(2);
90107c0a28Sjtc 		exit(0);
91107c0a28Sjtc 	}
92107c0a28Sjtc 	mspeak(8);
93107c0a28Sjtc 	if (!wizard())
94107c0a28Sjtc 	{       mspeak(9);
95107c0a28Sjtc 		exit(0);
96107c0a28Sjtc 	}
97107c0a28Sjtc 	saved = -1;
98107c0a28Sjtc 	return(FALSE);
99107c0a28Sjtc }
100107c0a28Sjtc 
101107c0a28Sjtc wizard()                /* not as complex as advent/10 (for now)        */
102107c0a28Sjtc {       register int wiz;
103107c0a28Sjtc 	char *word,*x;
104107c0a28Sjtc 	if (!yesm(16,0,7)) return(FALSE);
105107c0a28Sjtc 	mspeak(17);
106107c0a28Sjtc 	getin(&word,&x);
107107c0a28Sjtc 	if (!weq(word,magic))
108107c0a28Sjtc 	{       mspeak(20);
109107c0a28Sjtc 		return(FALSE);
110107c0a28Sjtc 	}
111107c0a28Sjtc 	mspeak(19);
112107c0a28Sjtc 	return(TRUE);
113107c0a28Sjtc }
114107c0a28Sjtc 
115107c0a28Sjtc ciao(cmdfile)
116107c0a28Sjtc char *cmdfile;
117107c0a28Sjtc {       register char *c;
118107c0a28Sjtc 	register int outfd, size;
119107c0a28Sjtc 	char fname[80], buf[512];
120107c0a28Sjtc 	extern unsigned filesize;
121107c0a28Sjtc 
122107c0a28Sjtc 	printf("What would you like to call the saved version?\n");
123107c0a28Sjtc 	for (c=fname;; c++)
124107c0a28Sjtc 		if ((*c=getchar())=='\n') break;
125107c0a28Sjtc 	*c=0;
126107c0a28Sjtc 	if (save(fname) != 0) return;           /* Save failed */
127107c0a28Sjtc 	printf("To resume, say \"adventure %s\".\n", fname);
128107c0a28Sjtc 	printf("\"With these rooms I might now have been familiarly acquainted.\"\n");
129107c0a28Sjtc 	exit(0);
130107c0a28Sjtc }
131107c0a28Sjtc 
132107c0a28Sjtc 
133107c0a28Sjtc ran(range)
134107c0a28Sjtc int range;
135107c0a28Sjtc {
136107c0a28Sjtc 	long rand(), i;
137107c0a28Sjtc 
138107c0a28Sjtc 	i = rand() % range;
139107c0a28Sjtc 	return(i);
140107c0a28Sjtc }
141