4 * SPDX-FileCopyrightText: (C) 1977, 2005 by Will Crowther and Don Woods
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
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
26 * Reaching "game.closng" 25 25
27 * "Closed": Quit/Killed 10
31 * Came to Witt's End 1 1
32 * Round out the total 2 2
34 * Points can also be deducted for using hints or too many turns, or
35 * for saving intermediate positions. */
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. */
40 for (int i = 1; i <= NOBJECTS; i++) {
41 if (!objects[i].is_treasure) {
44 if (objects[i].inventory != 0) {
52 if (!PROP_IS_STASHED(i) && !PROP_IS_NOTFOUND(i)) {
55 if (game.objects[i].place == LOC_BUILDING &&
63 /* Now look at how he finished and how far he got. NDEATHS and
64 * game.numdie tell us how well he survived. game.dflag will tell us
65 * if he ever got suitably deep into the cave. game.closng still
66 * indicates whether he reached the endgame. And if he got as far as
67 * "cave closed" (indicated by "game.closed"), then bonus is zero for
68 * mundane exits or 133, 134, 135 if he blew it (so to speak). */
69 score += (NDEATHS - game.numdie) * 10;
70 mxscor += NDEATHS * 10;
71 if (mode == endgame) {
75 if (game.dflag != 0) {
84 if (game.bonus == none) {
87 if (game.bonus == splatter) {
90 if (game.bonus == defeat) {
93 if (game.bonus == victory) {
99 /* Did he come to Witt's End as he should? */
100 if (game.objects[MAGAZINE].place == LOC_WITTSEND) {
109 /* Deduct for hints/turns/saves. Hints < 4 are special; see database
111 for (int i = 0; i < NHINTS; i++) {
112 if (game.hints[i].used) {
113 score = score - hints[i].penalty;
122 score = score - game.trnluz - game.saved;
124 /* Return to score command if that's where we came from. */
125 if (mode == scoregame) {
126 rspeak(GARNERED_POINTS, score, mxscor, game.turns, game.turns);
132 void terminate(enum termination mode) {
133 /* End of game. Let's tell him all about it. */
134 int points = score(mode);
135 #if defined ADVENT_AUTOSAVE
139 if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0) {
142 if (points + game.saved + 1 >= mxscor && game.saved != 0) {
143 rspeak(WITHOUT_SUSPENDS);
145 rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
146 for (int i = 1; i <= (int)NCLASSES; i++) {
147 if (classes[i].threshold >= points) {
148 speak(classes[i].message);
149 if (i < (int)NCLASSES) {
150 int nxt = classes[i].threshold + 1 - points;
151 rspeak(NEXT_HIGHER, nxt, nxt);