Abolish HNTMAX and HNTSIZ in favor of HINT_COUNT.
[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 static long mxscor;     /* ugh..the price for having score() not exit. */
11
12 long score(enum termination mode)
13 /* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died
14  * or won */
15 {
16     long score = 0;
17
18     /*  The present scoring algorithm is as follows:
19      *     Objective:          Points:        Present total possible:
20      *  Getting well into cave   25                    25
21      *  Each treasure < chest    12                    60
22      *  Treasure chest itself    14                    14
23      *  Each treasure > chest    16                   224
24      *  Surviving             (MAX-NUM)*10             30
25      *  Not quitting              4                     4
26      *  Reaching "game.closng"   25                    25
27      *  "Closed": Quit/Killed    10
28      *            Klutzed        25
29      *            Wrong way      30
30      *            Success        45                    45
31      *  Came to Witt's End        1                     1
32      *  Round out the total       2                     2
33      *                                       TOTAL:   430
34      *  Points can also be deducted for using hints or too many turns, or for
35      *  saving intermediate positions. */
36
37     /*  First tally up the treasures.  Must be in building and not broken.
38      *  Give the poor guy 2 points just for finding each treasure. */
39     mxscor = 0;
40     for (long i = MINTRS; i <= MAXTRS; i++) {
41         if (object_descriptions[i].inventory != 0) {
42             long k = 12;
43             if (i == CHEST)k = 14;
44             if (i > CHEST)k = 16;
45             if (game.prop[i] >= 0)
46                 score += 2;
47             if (game.place[i] == LOC_BUILDING && game.prop[i] == 0)
48                 score += k - 2;
49             mxscor += k;
50         }
51     }
52
53     /*  Now look at how he finished and how far he got.  maximum_deaths and
54      *  game.numdie tell us how well he survived.  game.dflag will tell us
55      *  if he ever got suitably deep into the cave.  game.closng still
56      *  indicates whether he reached the endgame.  And if he got as far as
57      *  "cave closed" (indicated by "game.closed"), then bonus is zero for
58      *  mundane exits or 133, 134, 135 if he blew it (so to speak). */
59     score += (maximum_deaths - game.numdie) * 10;
60     mxscor += maximum_deaths * 10;
61     if (mode == endgame)
62         score += 4;
63     mxscor += 4;
64     if (game.dflag != 0)score += 25;
65     mxscor += 25;
66     if (game.closng)score += 25;
67     mxscor += 25;
68     if (game.closed) {
69         if (game.bonus == 0)
70             score += 10;
71         if (game.bonus == SPLATTER_MESSAGE)
72             score += 25;
73         if (game.bonus == DEFEAT_MESSAGE)
74             score += 30;
75         if (game.bonus == VICTORY_MESSAGE)
76             score += 45;
77     }
78     mxscor += 45;
79
80     /* Did he come to Witt's End as he should? */
81     if (game.place[MAGAZINE] == LOC_WITTSEND)
82         score += 1;
83     mxscor += 1;
84
85     /* Round it off. */
86     score += 2;
87     mxscor += 2;
88
89     /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
90     for (long i = 1; i <= HINT_COUNT; i++) {
91         if (game.hinted[i])
92             score = score - hints[i-1].penalty;
93     }
94     if (game.novice)
95         score -= 5;
96     if (game.clshnt)
97         score -= 10;
98     score = score - game.trnluz - game.saved;
99
100     /* Return to score command if that's where we came from. */
101     if (mode == scoregame) {
102         rspeak(GARNERED_POINTS, score, mxscor, game.turns, game.turns);
103     }
104
105     return score;
106 }
107
108 void terminate(enum termination mode)
109 /* End of game.  Let's tell him all about it. */
110 {
111     long points = score(mode);
112
113     if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
114         rspeak(TOOK_LONG);
115     if (points + game.saved + 1 >= mxscor && game.saved != 0)
116         rspeak(WITHOUT_SUSPENDS);
117     rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
118     for (long i = 1; i <= (long)CLSSES; i++) {
119         if (classes[i].threshold >= points) {
120             speak(classes[i].message);
121             i = classes[i].threshold + 1 - points;
122             rspeak(NEXT_HIGHER, i, i);
123             exit(0);
124         }
125     }
126     rspeak(OFF_SCALE);
127     rspeak(NO_HIGHER);
128     exit(0);
129 }
130
131 /* end */