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