Home | History | Annotate | Line # | Download | only in adventure
done.c revision 1.3
      1 /*	$NetBSD: done.c,v 1.3 1997/08/11 14:06:12 christos 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.3 1997/08/11 14:06:12 christos 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()                                         /* sort of like 20000   */
     58 {       register int scor,i;
     59 	mxscor=scor=0;
     60 	for (i=50; i<=maxtrs; i++)
     61 	{	if (ptext[i].txtlen==0) continue;
     62 		k=12;
     63 		if (i==chest) k=14;
     64 		if (i>chest) k=16;
     65 		if (prop[i]>=0) scor += 2;
     66 		if (place[i]==3&&prop[i]==0) scor += k-2;
     67 		mxscor += k;
     68 	}
     69 	scor += (maxdie-numdie)*10;
     70 	mxscor += maxdie*10;
     71 	if (!(scorng||gaveup)) scor += 4;
     72 	mxscor += 4;
     73 	if (dflag!=0) scor += 25;
     74 	mxscor += 25;
     75 	if (closng) scor += 25;
     76 	mxscor += 25;
     77 	if (closed)
     78 	{       if (bonus==0) scor += 10;
     79 		if (bonus==135) scor += 25;
     80 		if (bonus==134) scor += 30;
     81 		if (bonus==133) scor += 45;
     82 	}
     83 	mxscor += 45;
     84 	if (place[magzin]==108) scor++;
     85 	mxscor++;
     86 	scor += 2;
     87 	mxscor += 2;
     88 	for (i=1; i<=hntmax; i++)
     89 		if (hinted[i]) scor -= hints[i][2];
     90 	return(scor);
     91 }
     92 
     93 void
     94 done(entry)     /* entry=1 means goto 13000 */  /* game is over         */
     95 int entry;      /* entry=2 means goto 20000 */ /* 3=19000 */
     96 {       register int i,sc;
     97 	if (entry==1) mspeak(1);
     98 	if (entry==3) rspeak(136);
     99 	printf("\n\n\nYou scored %d out of a ",(sc=score()));
    100 	printf("possible %d using %d turns.\n",mxscor,turns);
    101 	for (i=1; i<=clsses; i++)
    102 		if (cval[i]>=sc)
    103 		{       speak(&ctext[i]);
    104 			if (i==clsses-1)
    105 			{       printf("To achieve the next higher rating");
    106 				printf(" would be a neat trick!\n\n");
    107 				printf("Congratulations!!\n");
    108 				exit(0);
    109 			}
    110 			k=cval[i]+1-sc;
    111 			printf("To achieve the next higher rating, you need");
    112 			printf(" %d more point",k);
    113 			if (k==1) printf(".\n");
    114 			else printf("s.\n");
    115 			exit(0);
    116 		}
    117 	printf("You just went off my scale!!!\n");
    118 	exit(0);
    119 }
    120 
    121 
    122 int
    123 die(entry)                                      /* label 90             */
    124 int entry;
    125 {       register int i;
    126 	if (entry != 99)
    127 	{       rspeak(23);
    128 		oldlc2=loc;
    129 	}
    130 	if (closng)                             /* 99                   */
    131 	{       rspeak(131);
    132 		numdie++;
    133 		done(2);
    134 	}
    135 	yea=yes(81+numdie*2,82+numdie*2,54);
    136 	numdie++;
    137 	if (numdie==maxdie || !yea) done(2);
    138 	place[water]=0;
    139 	place[oil]=0;
    140 	if (toting(lamp)) prop[lamp]=0;
    141 	for (i=100; i>=1; i--)
    142 	{       if (!toting(i)) continue;
    143 		k=oldlc2;
    144 		if (i==lamp) k=1;
    145 		drop(i,k);
    146 	}
    147 	loc=3;
    148 	oldloc=loc;
    149 	return(2000);
    150 }
    151