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