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