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