xref: /dragonfly/games/adventure/done.c (revision 1de703da)
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.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  * @(#)done.c	8.1 (Berkeley) 5/31/93
39  * $FreeBSD: src/games/adventure/done.c,v 1.7 1999/12/19 00:21:50 billf Exp $
40  * $DragonFly: src/games/adventure/done.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
41  */
42 
43 /*      Re-coding of advent in C: termination routines                  */
44 
45 #include <stdio.h>
46 #include "hdr.h"
47 
48 int
49 score()                                         /* sort of like 20000   */
50 {       int scor,i;
51 	mxscor=scor=0;
52 	for (i=50; i<=maxtrs; i++)
53 	{	if (ptext[i].txtlen==0) continue;
54 		k=12;
55 		if (i==chest) k=14;
56 		if (i>chest) k=16;
57 		if (prop[i]>=0) scor += 2;
58 		if (place[i]==3&&prop[i]==0) scor += k-2;
59 		mxscor += k;
60 	}
61 	scor += (maxdie-numdie)*10;
62 	mxscor += maxdie*10;
63 	if (!(scorng||gaveup)) scor += 4;
64 	mxscor += 4;
65 	if (dflag!=0) scor += 25;
66 	mxscor += 25;
67 	if (closng) scor += 25;
68 	mxscor += 25;
69 	if (closed)
70 	{       if (bonus==0) scor += 10;
71 		if (bonus==135) scor += 25;
72 		if (bonus==134) scor += 30;
73 		if (bonus==133) scor += 45;
74 	}
75 	mxscor += 45;
76 	if (place[magzin]==108) scor++;
77 	mxscor++;
78 	scor += 2;
79 	mxscor += 2;
80 	for (i=1; i<=hntmax; i++)
81 		if (hinted[i]) scor -= hints[i][2];
82 	return(scor);
83 }
84 
85 void
86 done(entry)     /* entry=1 means goto 13000 */  /* game is over         */
87 int entry;      /* entry=2 means goto 20000 */ /* 3=19000 */
88 {       int i,sc;
89 	if (entry==1) mspeak(1);
90 	if (entry==3) rspeak(136);
91 	printf("\n\n\nYou scored %d out of a ",(sc=score()));
92 	printf("possible %d using %d turns.\n",mxscor,turns);
93 	for (i=1; i<=clsses; i++)
94 		if (cval[i]>=sc)
95 		{       speak(&ctext[i]);
96 			if (i==clsses-1)
97 			{       printf("To achieve the next higher rating");
98 				printf(" would be a neat trick!\n\n");
99 				printf("Congratulations!!\n");
100 				exit(0);
101 			}
102 			k=cval[i]+1-sc;
103 			printf("To achieve the next higher rating, you need");
104 			printf(" %d more point",k);
105 			if (k==1) printf(".\n");
106 			else printf("s.\n");
107 			exit(0);
108 		}
109 	printf("You just went off my scale!!!\n");
110 	exit(0);
111 }
112 
113 
114 void
115 die(entry)                                      /* label 90             */
116 int entry;
117 {       int i;
118 	if (entry != 99)
119 	{       rspeak(23);
120 		oldlc2=loc;
121 	}
122 	if (closng)                             /* 99                   */
123 	{       rspeak(131);
124 		numdie++;
125 		done(2);
126 	}
127 	yea=yes(81+numdie*2,82+numdie*2,54);
128 	numdie++;
129 	if (numdie==maxdie || !yea) done(2);
130 	place[water]=0;
131 	place[oil]=0;
132 	if (toting(lamp)) prop[lamp]=0;
133 	for (i=100; i>=1; i--)
134 	{       if (!toting(i)) continue;
135 		k=oldlc2;
136 		if (i==lamp) k=1;
137 		drop(i,k);
138 	}
139 	loc=3;
140 	oldloc=loc;
141 }
142