4 * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
5 * Copyright (c) 2017 by Eric S. Raymond
6 * SPDX-License-Identifier: BSD-2-clause
12 static int mxscor; /* ugh..the price for having score() not exit. */
14 int score(enum termination mode)
15 /* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died
20 /* The present scoring algorithm is as follows:
21 * Objective: Points: Present total possible:
22 * Getting well into cave 25 25
23 * Each treasure < chest 12 60
24 * Treasure chest itself 14 14
25 * Each treasure > chest 16 224
26 * Surviving (MAX-NUM)*10 30
28 * Reaching "game.closng" 25 25
29 * "Closed": Quit/Killed 10
33 * Came to Witt's End 1 1
34 * Round out the total 2 2
36 * Points can also be deducted for using hints or too many turns, or for
37 * saving intermediate positions. */
39 /* First tally up the treasures. Must be in building and not broken.
40 * Give the poor guy 2 points just for finding each treasure. */
42 for (int i = 1; i <= NOBJECTS; i++) {
43 if (!objects[i].is_treasure)
45 if (objects[i].inventory != 0) {
51 if (game.prop[i] > STATE_NOTFOUND)
53 if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_FOUND)
59 /* Now look at how he finished and how far he got. NDEATHS and
60 * game.numdie tell us how well he survived. game.dflag will tell us
61 * if he ever got suitably deep into the cave. game.closng still
62 * indicates whether he reached the endgame. And if he got as far as
63 * "cave closed" (indicated by "game.closed"), then bonus is zero for
64 * mundane exits or 133, 134, 135 if he blew it (so to speak). */
65 score += (NDEATHS - game.numdie) * 10;
66 mxscor += NDEATHS * 10;
77 if (game.bonus == none)
79 if (game.bonus == splatter)
81 if (game.bonus == defeat)
83 if (game.bonus == victory)
88 /* Did he come to Witt's End as he should? */
89 if (game.place[MAGAZINE] == LOC_WITTSEND)
97 /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
98 for (int i = 0; i < NHINTS; i++) {
100 score = score - hints[i].penalty;
106 score = score - game.trnluz - game.saved;
108 /* Return to score command if that's where we came from. */
109 if (mode == scoregame) {
110 rspeak(GARNERED_POINTS, score, mxscor, game.turns, game.turns);
116 void terminate(enum termination mode)
117 /* End of game. Let's tell him all about it. */
119 int points = score(mode);
120 #if defined ADVENT_AUTOSAVE
124 if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
126 if (points + game.saved + 1 >= mxscor && game.saved != 0)
127 rspeak(WITHOUT_SUSPENDS);
128 rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
129 for (int i = 1; i <= (int)NCLASSES; i++) {
130 if (classes[i].threshold >= points) {
131 speak(classes[i].message);
132 if (i < (int)NCLASSES) {
133 int nxt = classes[i].threshold + 1 - points;
134 rspeak(NEXT_HIGHER, nxt, nxt);