xref: /netbsd/games/adventure/done.c (revision bf9ec67e)
1 /*	$NetBSD: done.c,v 1.7 2000/07/03 03:57:39 matt Exp $	*/
2 
3 /*-
4  * Copyright (c) 1991, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * The game adventure was originally written in Fortran by Will Crowther
8  * and Don Woods.  It was later translated to C and enhanced by Jim
9  * Gillogly.  This code is derived from software contributed to Berkeley
10  * by Jim Gillogly at The Rand Corporation.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *	This product includes software developed by the University of
23  *	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  */
40 
41 #include <sys/cdefs.h>
42 #ifndef lint
43 #if 0
44 static char sccsid[] = "@(#)done.c	8.1 (Berkeley) 5/31/93";
45 #else
46 __RCSID("$NetBSD: done.c,v 1.7 2000/07/03 03:57:39 matt Exp $");
47 #endif
48 #endif /* not lint */
49 
50 /*      Re-coding of advent in C: termination routines */
51 
52 #include <stdio.h>
53 #include <stdlib.h>
54 #include "hdr.h"
55 #include "extern.h"
56 
57 int
58 score()
59 {				/* sort of like 20000 */
60 	int     scor, i;
61 	mxscor = scor = 0;
62 	for (i = 50; i <= maxtrs; i++) {
63 		if (ptext[i].txtlen == 0)
64 			continue;
65 		k = 12;
66 		if (i == chest)
67 			k = 14;
68 		if (i > chest)
69 			k = 16;
70 		if (prop[i] >= 0)
71 			scor += 2;
72 		if (place[i] == 3 && prop[i] == 0)
73 			scor += k - 2;
74 		mxscor += k;
75 	}
76 	scor += (maxdie - numdie) * 10;
77 	mxscor += maxdie * 10;
78 	if (!(scorng || gaveup))
79 		scor += 4;
80 	mxscor += 4;
81 	if (dflag != 0)
82 		scor += 25;
83 	mxscor += 25;
84 	if (closng)
85 		scor += 25;
86 	mxscor += 25;
87 	if (closed) {
88 		if (bonus == 0)
89 			scor += 10;
90 		if (bonus == 135)
91 			scor += 25;
92 		if (bonus == 134)
93 			scor += 30;
94 		if (bonus == 133)
95 			scor += 45;
96 	}
97 	mxscor += 45;
98 	if (place[magzin] == 108)
99 		scor++;
100 	mxscor++;
101 	scor += 2;
102 	mxscor += 2;
103 	for (i = 1; i <= hntmax; i++)
104 		if (hinted[i])
105 			scor -= hints[i][2];
106 	return (scor);
107 }
108 
109 void
110 done(entry)		/* entry=1 means goto 13000 */	/* game is over */
111 	int     entry;	/* entry=2 means goto 20000 */	/* 3=19000 */
112 {
113 	int     i, sc;
114 	if (entry == 1)
115 		mspeak(1);
116 	if (entry == 3)
117 		rspeak(136);
118 	printf("\n\n\nYou scored %d out of a ", (sc = score()));
119 	printf("possible %d using %d turns.\n", mxscor, turns);
120 	for (i = 1; i <= clsses; i++)
121 		if (cval[i] >= sc) {
122 			speak(&ctext[i]);
123 			if (i == clsses - 1) {
124 				printf("To achieve the next higher rating");
125 				printf(" would be a neat trick!\n\n");
126 				printf("Congratulations!!\n");
127 				exit(0);
128 			}
129 			k = cval[i] + 1 - sc;
130 			printf("To achieve the next higher rating, you need");
131 			printf(" %d more point", k);
132 			if (k == 1)
133 				printf(".\n");
134 			else
135 				printf("s.\n");
136 			exit(0);
137 		}
138 	printf("You just went off my scale!!!\n");
139 	exit(0);
140 }
141 
142 
143 void
144 die(entry)			/* label 90 */
145 	int     entry;
146 {
147 	int     i;
148 	if (entry != 99) {
149 		rspeak(23);
150 		oldlc2 = loc;
151 	}
152 	if (closng) {		/* 99 */
153 		rspeak(131);
154 		numdie++;
155 		done(2);
156 	}
157 	yea = yes(81 + numdie * 2, 82 + numdie * 2, 54);
158 	numdie++;
159 	if (numdie == maxdie || !yea)
160 		done(2);
161 	place[water] = 0;
162 	place[oil] = 0;
163 	if (toting(lamp))
164 		prop[lamp] = 0;
165 	for (i = 100; i >= 1; i--) {
166 		if (!toting(i))
167 			continue;
168 		k = oldlc2;
169 		if (i == lamp)
170 			k = 1;
171 		drop(i, k);
172 	}
173 	loc = 3;
174 	oldloc = loc;
175 }
176