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