]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - adventure/done.c
Bah! Compare, don't assign!
[bsdgames-darwin.git] / adventure / done.c
1 /* $NetBSD: done.c,v 1.9 2005/07/01 00:03:36 jmc 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.9 2005/07/01 00:03:36 jmc 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
54 score(void)
55 { /* sort of like 20000 */
56 int scor, i;
57 mxscor = scor = 0;
58 for (i = 50; i <= maxtrs; i++) {
59 if (ptext[i].txtlen == 0)
60 continue;
61 k = 12;
62 if (i == chest)
63 k = 14;
64 if (i > chest)
65 k = 16;
66 if (prop[i] >= 0)
67 scor += 2;
68 if (place[i] == 3 && prop[i] == 0)
69 scor += k - 2;
70 mxscor += k;
71 }
72 scor += (maxdie - numdie) * 10;
73 mxscor += maxdie * 10;
74 if (!(scorng || gaveup))
75 scor += 4;
76 mxscor += 4;
77 if (dflag != 0)
78 scor += 25;
79 mxscor += 25;
80 if (closng)
81 scor += 25;
82 mxscor += 25;
83 if (closed) {
84 if (bonus == 0)
85 scor += 10;
86 if (bonus == 135)
87 scor += 25;
88 if (bonus == 134)
89 scor += 30;
90 if (bonus == 133)
91 scor += 45;
92 }
93 mxscor += 45;
94 if (place[magzin] == 108)
95 scor++;
96 mxscor++;
97 scor += 2;
98 mxscor += 2;
99 for (i = 1; i <= hntmax; i++)
100 if (hinted[i])
101 scor -= hints[i][2];
102 return (scor);
103 }
104
105 /* entry=1 means goto 13000 */ /* game is over */
106 /* entry=2 means goto 20000 */ /* 3=19000 */
107 void
108 done(int entry)
109 {
110 int i, sc;
111 if (entry == 1)
112 mspeak(1);
113 if (entry == 3)
114 rspeak(136);
115 printf("\n\n\nYou scored %d out of a ", (sc = score()));
116 printf("possible %d using %d turns.\n", mxscor, turns);
117 for (i = 1; i <= clsses; i++)
118 if (cval[i] >= sc) {
119 speak(&ctext[i]);
120 if (i == clsses - 1) {
121 printf("To achieve the next higher rating");
122 printf(" would be a neat trick!\n\n");
123 printf("Congratulations!!\n");
124 exit(0);
125 }
126 k = cval[i] + 1 - sc;
127 printf("To achieve the next higher rating, you need");
128 printf(" %d more point", k);
129 if (k == 1)
130 printf(".\n");
131 else
132 printf("s.\n");
133 exit(0);
134 }
135 printf("You just went off my scale!!!\n");
136 exit(0);
137 }
138
139 /* label 90 */
140 void
141 die(int entry)
142 {
143 int i;
144 if (entry != 99) {
145 rspeak(23);
146 oldlc2 = loc;
147 }
148 if (closng) { /* 99 */
149 rspeak(131);
150 numdie++;
151 done(2);
152 }
153 yea = yes(81 + numdie * 2, 82 + numdie * 2, 54);
154 numdie++;
155 if (numdie == maxdie || !yea)
156 done(2);
157 place[water] = 0;
158 place[oil] = 0;
159 if (toting(lamp))
160 prop[lamp] = 0;
161 for (i = 100; i >= 1; i--) {
162 if (!toting(i))
163 continue;
164 k = oldlc2;
165 if (i == lamp)
166 k = 1;
167 drop(i, k);
168 }
169 loc = 3;
170 oldloc = loc;
171 }