xref: /minix/games/adventure/done.c (revision 0819c9f8)
1 /*	$NetBSD: done.c,v 1.10 2009/08/25 06:56:52 dholland 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. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36 
37 #include <sys/cdefs.h>
38 #ifndef lint
39 #if 0
40 static char sccsid[] = "@(#)done.c	8.1 (Berkeley) 5/31/93";
41 #else
42 __RCSID("$NetBSD: done.c,v 1.10 2009/08/25 06:56:52 dholland Exp $");
43 #endif
44 #endif /* not lint */
45 
46 /*      Re-coding of advent in C: termination routines */
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 #include "hdr.h"
51 #include "extern.h"
52 
53 int
score(void)54 score(void)
55 {				/* sort of like 20000 */
56 	int     myscore, i;
57 
58 	maxscore = myscore = 0;
59 	for (i = 50; i <= maxtrs; i++) {
60 		if (ptext[i].txtlen == 0)
61 			continue;
62 		k = 12;
63 		if (i == chest)
64 			k = 14;
65 		if (i > chest)
66 			k = 16;
67 		if (prop[i] >= 0)
68 			myscore += 2;
69 		if (place[i] == 3 && prop[i] == 0)
70 			myscore += k - 2;
71 		maxscore += k;
72 	}
73 	myscore += (maxdie - numdie) * 10;
74 	maxscore += maxdie * 10;
75 	if (!(scoring || gaveup))
76 		myscore += 4;
77 	maxscore += 4;
78 	if (dflag != 0)
79 		myscore += 25;
80 	maxscore += 25;
81 	if (isclosing)
82 		myscore += 25;
83 	maxscore += 25;
84 	if (closed) {
85 		if (bonus == 0)
86 			myscore += 10;
87 		if (bonus == 135)
88 			myscore += 25;
89 		if (bonus == 134)
90 			myscore += 30;
91 		if (bonus == 133)
92 			myscore += 45;
93 	}
94 	maxscore += 45;
95 	if (place[magazine] == 108)
96 		myscore++;
97 	maxscore++;
98 	myscore += 2;
99 	maxscore += 2;
100 	for (i = 1; i <= hintmax; i++)
101 		if (hinted[i])
102 			myscore -= hints[i][2];
103 	return myscore;
104 }
105 
106 /* entry=1 means goto 13000 */	/* game is over */
107 /* entry=2 means goto 20000 */	/* 3=19000 */
108 void
done(int entry)109 done(int entry)
110 {
111 	int     i, sc;
112 	if (entry == 1)
113 		mspeak(1);
114 	if (entry == 3)
115 		rspeak(136);
116 	printf("\n\n\nYou scored %d out of a ", (sc = score()));
117 	printf("possible %d using %d turns.\n", maxscore, turns);
118 	for (i = 1; i <= classes; i++)
119 		if (cval[i] >= sc) {
120 			speak(&ctext[i]);
121 			if (i == classes - 1) {
122 				printf("To achieve the next higher rating");
123 				printf(" would be a neat trick!\n\n");
124 				printf("Congratulations!!\n");
125 				exit(0);
126 			}
127 			k = cval[i] + 1 - sc;
128 			printf("To achieve the next higher rating, you need");
129 			printf(" %d more point", k);
130 			if (k == 1)
131 				printf(".\n");
132 			else
133 				printf("s.\n");
134 			exit(0);
135 		}
136 	printf("You just went off my scale!!!\n");
137 	exit(0);
138 }
139 
140 /* label 90 */
141 void
die(int entry)142 die(int entry)
143 {
144 	int     i;
145 	if (entry != 99) {
146 		rspeak(23);
147 		oldloc2 = loc;
148 	}
149 	if (isclosing) {		/* 99 */
150 		rspeak(131);
151 		numdie++;
152 		done(2);
153 	}
154 	yea = yes(81 + numdie * 2, 82 + numdie * 2, 54);
155 	numdie++;
156 	if (numdie == maxdie || !yea)
157 		done(2);
158 	place[water] = 0;
159 	place[oil] = 0;
160 	if (toting(lamp))
161 		prop[lamp] = 0;
162 	for (i = 100; i >= 1; i--) {
163 		if (!toting(i))
164 			continue;
165 		k = oldloc2;
166 		if (i == lamp)
167 			k = 1;
168 		drop(i, k);
169 	}
170 	loc = 3;
171 	oldloc = loc;
172 }
173