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