Global-variable elimination.
[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 i, score = 0, 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 /*  First tally up the treasures.  Must be in building and not broken.
33  *  Give the poor guy 2 points just for finding each treasure. */
34
35         for (i=MINTRS; i<=MAXTRS; i++) {
36                 if(PTEXT[i] != 0) {
37                         K=12;
38                         if(i == CHEST)K=14;
39                         if(i > CHEST)K=16;
40                         if(game.prop[i] >= 0)
41                                 score=score+2;
42                         if(game.place[i] == 3 && game.prop[i] == 0)
43                                 score=score+K-2;
44                         mxscor=mxscor+K;
45                 }
46         } /* end loop */
47
48 /*  Now look at how he finished and how far he got.  MAXDIE and
49  *  game.numdie tell us how well he survived.  game.dflag will tell us
50  *  if he ever got suitably deep into the cave.  game.closng still
51  *  indicates whether he reached the endgame.  And if he got as far as
52  *  "cave closed" (indicated by "game.closed"), then bonus is zero for
53  *  mundane exits or 133, 134, 135 if he blew it (so to speak). */
54
55         score=score+(MAXDIE-game.numdie)*10;
56         mxscor=mxscor+MAXDIE*10;
57         if(mode == 0)score=score+4;
58         mxscor=mxscor+4;
59         if(game.dflag != 0)score=score+25;
60         mxscor=mxscor+25;
61         if(game.closng)score=score+25;
62         mxscor=mxscor+25;
63         if(game.closed) {
64                 if(game.bonus == 0)score=score+10;
65                 if(game.bonus == 135)score=score+25;
66                 if(game.bonus == 134)score=score+30;
67                 if(game.bonus == 133)score=score+45;
68         }
69         mxscor=mxscor+45;
70
71 /*  Did he come to Witt's End as he should? */
72
73         if(game.place[MAGZIN] == 108)
74                 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(game.hinted[i])score=score-HINTS[i][2];
86         } /* end loop */
87         if(game.novice)
88                 score=score-5;
89         if(game.clshnt)
90                 score=score-10;
91         score=score-game.trnluz-game.saved;
92
93 /*  Return to score command if that's where we came from. */
94
95         if(mode < 0) {
96                 SETPRM(1,score,mxscor);
97                 SETPRM(3,game.turns,game.turns);
98                 RSPEAK(259);
99                 return;
100         }
101
102 /*  that should be good enough.  Let's tell him all about it. */
103
104         if(score+game.trnluz+1 >= mxscor && game.trnluz != 0)RSPEAK(242);
105         if(score+game.saved+1 >= mxscor && game.saved != 0)RSPEAK(143);
106         SETPRM(1,score,mxscor);
107         SETPRM(3,game.turns,game.turns);
108         RSPEAK(262);
109         for (i=1; i<=CLSSES; i++) {
110                 if(CVAL[i] >= score) goto L20210;
111         } /* end loop */
112         SPK=265;
113         goto L25000;
114
115 L20210: SPEAK(CTEXT[i]);
116         SPK=264;
117         if(i >= CLSSES) goto L25000;
118         i=CVAL[i]+1-score;
119         SETPRM(1,i,i);
120         SPK=263;
121 L25000: RSPEAK(SPK);
122         exit(0);
123
124 }