xref: /original-bsd/games/adventure/done.c (revision 25342562)
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  * %sccs.include.redist.c%
11  */
12 
13 #ifndef lint
14 static char sccsid[] = "@(#)done.c	8.1 (Berkeley) 05/31/93";
15 #endif /* not lint */
16 
17 /*      Re-coding of advent in C: termination routines                  */
18 
19 #include "hdr.h"
20 
21 score()                                         /* sort of like 20000   */
22 {       register int scor,i;
23 	mxscor=scor=0;
24 	for (i=50; i<=maxtrs; i++)
25 	{	if (ptext[i].txtlen==0) continue;
26 		k=12;
27 		if (i==chest) k=14;
28 		if (i>chest) k=16;
29 		if (prop[i]>=0) scor += 2;
30 		if (place[i]==3&&prop[i]==0) scor += k-2;
31 		mxscor += k;
32 	}
33 	scor += (maxdie-numdie)*10;
34 	mxscor += maxdie*10;
35 	if (!(scorng||gaveup)) scor += 4;
36 	mxscor += 4;
37 	if (dflag!=0) scor += 25;
38 	mxscor += 25;
39 	if (closng) scor += 25;
40 	mxscor += 25;
41 	if (closed)
42 	{       if (bonus==0) scor += 10;
43 		if (bonus==135) scor += 25;
44 		if (bonus==134) scor += 30;
45 		if (bonus==133) scor += 45;
46 	}
47 	mxscor += 45;
48 	if (place[magzin]==108) scor++;
49 	mxscor++;
50 	scor += 2;
51 	mxscor += 2;
52 	for (i=1; i<=hntmax; i++)
53 		if (hinted[i]) scor -= hints[i][2];
54 	return(scor);
55 }
56 
57 done(entry)     /* entry=1 means goto 13000 */  /* game is over         */
58 int entry;      /* entry=2 means goto 20000 */ /* 3=19000 */
59 {       register int i,sc;
60 	if (entry==1) mspeak(1);
61 	if (entry==3) rspeak(136);
62 	printf("\n\n\nYou scored %d out of a ",(sc=score()));
63 	printf("possible %d using %d turns.\n",mxscor,turns);
64 	for (i=1; i<=clsses; i++)
65 		if (cval[i]>=sc)
66 		{       speak(&ctext[i]);
67 			if (i==clsses-1)
68 			{       printf("To achieve the next higher rating");
69 				printf(" would be a neat trick!\n\n");
70 				printf("Congratulations!!\n");
71 				exit(0);
72 			}
73 			k=cval[i]+1-sc;
74 			printf("To achieve the next higher rating, you need");
75 			printf(" %d more point",k);
76 			if (k==1) printf(".\n");
77 			else printf("s.\n");
78 			exit(0);
79 		}
80 	printf("You just went off my scale!!!\n");
81 	exit(0);
82 }
83 
84 
85 die(entry)                                      /* label 90             */
86 int entry;
87 {       register int i;
88 	if (entry != 99)
89 	{       rspeak(23);
90 		oldlc2=loc;
91 	}
92 	if (closng)                             /* 99                   */
93 	{       rspeak(131);
94 		numdie++;
95 		done(2);
96 	}
97 	yea=yes(81+numdie*2,82+numdie*2,54);
98 	numdie++;
99 	if (numdie==maxdie || !yea) done(2);
100 	place[water]=0;
101 	place[oil]=0;
102 	if (toting(lamp)) prop[lamp]=0;
103 	for (i=100; i>=1; i--)
104 	{       if (!toting(i)) continue;
105 		k=oldlc2;
106 		if (i==lamp) k=1;
107 		drop(i,k);
108 	}
109 	loc=3;
110 	oldloc=loc;
111 	return(2000);
112 }
113