LCOV - code coverage report
Current view: top level - open-adventure - score.c (source / functions) Hit Total Coverage
Test: advent.info Lines: 70 70 100.0 %
Date: 2017-09-17 15:40:10 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include <stdlib.h>
       2             : #include "advent.h"
       3             : #include "dungeon.h"
       4             : 
       5             : /*
       6             :  * scoring and wrap-up
       7             :  */
       8             : 
       9             : static int mxscor;      /* ugh..the price for having score() not exit. */
      10             : 
      11          91 : long score(enum termination mode)
      12             : /* mode is 'scoregame' if scoring, 'quitgame' if quitting, 'endgame' if died
      13             :  * or won */
      14             : {
      15          91 :     int score = 0;
      16             : 
      17             :     /*  The present scoring algorithm is as follows:
      18             :      *     Objective:          Points:        Present total possible:
      19             :      *  Getting well into cave   25                    25
      20             :      *  Each treasure < chest    12                    60
      21             :      *  Treasure chest itself    14                    14
      22             :      *  Each treasure > chest    16                   224
      23             :      *  Surviving             (MAX-NUM)*10             30
      24             :      *  Not quitting              4                     4
      25             :      *  Reaching "game.closng"   25                    25
      26             :      *  "Closed": Quit/Killed    10
      27             :      *            Klutzed        25
      28             :      *            Wrong way      30
      29             :      *            Success        45                    45
      30             :      *  Came to Witt's End        1                     1
      31             :      *  Round out the total       2                     2
      32             :      *                                       TOTAL:   430
      33             :      *  Points can also be deducted for using hints or too many turns, or for
      34             :      *  saving intermediate positions. */
      35             : 
      36             :     /*  First tally up the treasures.  Must be in building and not broken.
      37             :      *  Give the poor guy 2 points just for finding each treasure. */
      38          91 :     mxscor = 0;
      39        6370 :     for (int i = 1; i <= NOBJECTS; i++) {
      40        6279 :         if (!objects[i].is_treasure)
      41        4459 :             continue;
      42        1820 :         if (objects[i].inventory != 0) {
      43        1820 :             int k = 12;
      44        1820 :             if (i == CHEST)
      45          91 :                 k = 14;
      46        1820 :             if (i > CHEST)
      47        1274 :                 k = 16;
      48        1820 :             if (game.prop[i] > STATE_NOTFOUND)
      49         735 :                 score += 2;
      50        1820 :             if (game.place[i] == LOC_BUILDING && game.prop[i] == STATE_FOUND)
      51         505 :                 score += k - 2;
      52        1820 :             mxscor += k;
      53             :         }
      54             :     }
      55             : 
      56             :     /*  Now look at how he finished and how far he got.  NDEATHS and
      57             :      *  game.numdie tell us how well he survived.  game.dflag will tell us
      58             :      *  if he ever got suitably deep into the cave.  game.closng still
      59             :      *  indicates whether he reached the endgame.  And if he got as far as
      60             :      *  "cave closed" (indicated by "game.closed"), then bonus is zero for
      61             :      *  mundane exits or 133, 134, 135 if he blew it (so to speak). */
      62          91 :     score += (NDEATHS - game.numdie) * 10;
      63          91 :     mxscor += NDEATHS * 10;
      64          91 :     if (mode == endgame)
      65          18 :         score += 4;
      66          91 :     mxscor += 4;
      67          91 :     if (game.dflag != 0)
      68          65 :         score += 25;
      69          91 :     mxscor += 25;
      70          91 :     if (game.closng)
      71          13 :         score += 25;
      72          91 :     mxscor += 25;
      73          91 :     if (game.closed) {
      74           9 :         if (game.bonus == none)
      75           5 :             score += 10;
      76           9 :         if (game.bonus == splatter)
      77           1 :             score += 25;
      78           9 :         if (game.bonus == defeat)
      79           1 :             score += 30;
      80           9 :         if (game.bonus == victory)
      81           2 :             score += 45;
      82             :     }
      83          91 :     mxscor += 45;
      84             : 
      85             :     /* Did he come to Witt's End as he should? */
      86          91 :     if (game.place[MAGAZINE] == LOC_WITTSEND)
      87          13 :         score += 1;
      88          91 :     mxscor += 1;
      89             : 
      90             :     /* Round it off. */
      91          91 :     score += 2;
      92          91 :     mxscor += 2;
      93             : 
      94             :     /* Deduct for hints/turns/saves. Hints < 4 are special; see database desc. */
      95        1001 :     for (int i = 0; i < NHINTS; i++) {
      96         910 :         if (game.hinted[i])
      97          10 :             score = score - hints[i].penalty;
      98             :     }
      99          91 :     if (game.novice)
     100           2 :         score -= 5;
     101          91 :     if (game.clshnt)
     102           1 :         score -= 10;
     103          91 :     score = score - game.trnluz - game.saved;
     104             : 
     105             :     /* Return to score command if that's where we came from. */
     106          91 :     if (mode == scoregame) {
     107           3 :         rspeak(GARNERED_POINTS, score, mxscor, game.turns, game.turns);
     108             :     }
     109             : 
     110          91 :     return score;
     111             : }
     112             : 
     113          88 : void terminate(enum termination mode)
     114             : /* End of game.  Let's tell him all about it. */
     115             : {
     116          88 :     long points = score(mode);
     117             : 
     118          88 :     if (points + game.trnluz + 1 >= mxscor && game.trnluz != 0)
     119           1 :         rspeak(TOOK_LONG);
     120          88 :     if (points + game.saved + 1 >= mxscor && game.saved != 0)
     121           2 :         rspeak(WITHOUT_SUSPENDS);
     122          88 :     rspeak(TOTAL_SCORE, points, mxscor, game.turns, game.turns);
     123         281 :     for (int i = 1; i <= (long)NCLASSES; i++) {
     124         280 :         if (classes[i].threshold >= points) {
     125          87 :             speak(classes[i].message);
     126          87 :             i = classes[i].threshold + 1 - points;
     127          87 :             rspeak(NEXT_HIGHER, i, i);
     128          87 :             exit(EXIT_SUCCESS);
     129             :         }
     130             :     }
     131           1 :     rspeak(OFF_SCALE);
     132           1 :     rspeak(NO_HIGHER);
     133           1 :     exit(EXIT_SUCCESS);
     134             : }
     135             : 
     136             : /* end */

Generated by: LCOV version 1.13