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