Factor out handling of variables populated from the database.
[open-adventure.git] / score.c
1 #include <stdlib.h>
2 #include "misc.h"
3 #include "main.h"
4 #include "share.h"
5 #include "database.h"
6
7 /*
8  * scoring and wrap-up
9  */
10
11 void score(long MODE) {
12         /* <0 if scoring, >0 if quitting, =0 if died or won */
13
14 /*  The present scoring algorithm is as follows:
15  *     Objective:          Points:        Present total possible:
16  *  Getting well into cave   25                    25
17  *  Each treasure < chest    12                    60
18  *  Treasure chest itself    14                    14
19  *  Each treasure > chest    16                   224
20  *  Surviving             (MAX-NUM)*10             30
21  *  Not quitting              4                     4
22  *  Reaching "CLOSNG"        25                    25
23  *  "Closed": Quit/Killed    10
24  *            Klutzed        25
25  *            Wrong way      30
26  *            Success        45                    45
27  *  Came to Witt's End        1                     1
28  *  Round out the total       2                     2
29  *                                       TOTAL:   430
30  *  Points can also be deducted for using hints or too many turns, or for
31  *  saving intermediate positions. */
32
33         SCORE=0;
34         MXSCOR=0;
35
36 /*  First tally up the treasures.  Must be in building and not broken.
37  *  Give the poor guy 2 points just for finding each treasure. */
38
39         /* 20010 */ for (I=50; I<=MAXTRS; I++) {
40         if(PTEXT[I] == 0) goto L20010;
41         K=12;
42         if(I == CHEST)K=14;
43         if(I > CHEST)K=16;
44         if(PROP[I] >= 0)SCORE=SCORE+2;
45         if(PLACE[I] == 3 && PROP[I] == 0)SCORE=SCORE+K-2;
46         MXSCOR=MXSCOR+K;
47 L20010: /*etc*/ ;
48         } /* end loop */
49
50 /*  Now look at how he finished and how far he got.  MAXDIE and NUMDIE tell us
51  *  how well he survived.  DFLAG will
52  *  tell us if he ever got suitably deep into the cave.  CLOSNG still indicates
53  *  whether he reached the endgame.  And if he got as far as "cave closed"
54  *  (indicated by "CLOSED"), then bonus is zero for mundane exits or 133, 134,
55  *  135 if he blew it (so to speak). */
56
57         SCORE=SCORE+(MAXDIE-NUMDIE)*10;
58         MXSCOR=MXSCOR+MAXDIE*10;
59         if(MODE == 0)SCORE=SCORE+4;
60         MXSCOR=MXSCOR+4;
61         if(DFLAG != 0)SCORE=SCORE+25;
62         MXSCOR=MXSCOR+25;
63         if(CLOSNG)SCORE=SCORE+25;
64         MXSCOR=MXSCOR+25;
65         if(!CLOSED) goto L20020;
66         if(BONUS == 0)SCORE=SCORE+10;
67         if(BONUS == 135)SCORE=SCORE+25;
68         if(BONUS == 134)SCORE=SCORE+30;
69         if(BONUS == 133)SCORE=SCORE+45;
70 L20020: MXSCOR=MXSCOR+45;
71
72 /*  Did he come to Witt's End as he should? */
73
74         if(PLACE[MAGZIN] == 108)SCORE=SCORE+1;
75         MXSCOR=MXSCOR+1;
76
77 /*  Round it off. */
78
79         SCORE=SCORE+2;
80         MXSCOR=MXSCOR+2;
81
82 /*  Deduct for hints/turns/saves.  Hints < 4 are special; see database desc. */
83
84         for (I=1; I<=HNTMAX; I++) {
85         if(HINTED[I])SCORE=SCORE-HINTS[I][2];
86         } /* end loop */
87         if(NOVICE)SCORE=SCORE-5;
88         if(CLSHNT)SCORE=SCORE-10;
89         SCORE=SCORE-TRNLUZ-SAVED;
90
91 /*  Return to score command if that's where we came from. */
92
93         if(MODE < 0) return;
94
95 /*  that should be good enough.  Let's tell him all about it. */
96
97         if(SCORE+TRNLUZ+1 >= MXSCOR && TRNLUZ != 0)RSPEAK(242);
98         if(SCORE+SAVED+1 >= MXSCOR && SAVED != 0)RSPEAK(143);
99         SETPRM(1,SCORE,MXSCOR);
100         SETPRM(3,TURNS,TURNS);
101         RSPEAK(262);
102         for (I=1; I<=CLSSES; I++) {
103         if(CVAL[I] >= SCORE) goto L20210;
104         /*etc*/ ;
105         } /* end loop */
106         SPK=265;
107          goto L25000;
108
109 L20210: SPEAK(CTEXT[I]);
110         SPK=264;
111         if(I >= CLSSES) goto L25000;
112         I=CVAL[I]+1-SCORE;
113         SETPRM(1,I,I);
114         SPK=263;
115 L25000: RSPEAK(SPK);
116         exit(0);
117
118 }