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