YAMLify section 11 (hints).
[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 <= HNTMAX; 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         SETPRM(1, score, mxscor);
103         SETPRM(3, game.turns, game.turns);
104         RSPEAK(GARNERED_POINTS);
105     }
106
107     return score;
108 }
109
110 void terminate(enum termination mode)
111 /* End of game.  Let's tell him all about it. */
112 {
113     long points = score(mode);
114
115     if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
116         RSPEAK(TOOK_LONG);
117     if (points + game.saved + 1 >= mxscor && game.saved != 0)
118         RSPEAK(WITHOUT_SUSPENDS);
119     SETPRM(1, points, mxscor);
120     SETPRM(3, game.turns, game.turns);
121     RSPEAK(TOTAL_SCORE);
122     for (long i = 1; i <= (long)CLSSES; i++) {
123         if (classes[i].threshold >= points) {
124             speak(classes[i].message);
125             i = classes[i].threshold + 1 - points;
126             SETPRM(1, i, i);
127             RSPEAK(NEXT_HIGHER);
128             exit(0);
129         }
130     }
131     RSPEAK(OFF_SCALE);
132     RSPEAK(NO_HIGHER);
133     exit(0);
134 }
135
136 /* end */