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