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

          Line data    Source code
       1             : #include <unistd.h>
       2             : #include <stdlib.h>
       3             : #include <stdio.h>
       4             : #include <stdbool.h>
       5             : #include <time.h>
       6             : 
       7             : #include "advent.h"
       8             : 
       9             : /*
      10             :  * Initialisation
      11             :  */
      12             : 
      13             : struct settings_t settings = {
      14             :     .logfp = NULL,
      15             :     .oldstyle = false,
      16             :     .prompt = true
      17             : };
      18             : 
      19             : struct game_t game = {
      20             :     .dloc[1] = LOC_KINGHALL,
      21             :     .dloc[2] = LOC_WESTBANK,
      22             :     .dloc[3] = LOC_Y2,
      23             :     .dloc[4] = LOC_ALIKE3,
      24             :     .dloc[5] = LOC_COMPLEX,
      25             : 
      26             :     /*  Sixth dwarf is special (the pirate).  He always starts at his
      27             :      *  chest's eventual location inside the maze. This loc is saved
      28             :      *  in chloc for ref. The dead end in the other maze has its
      29             :      *  loc stored in chloc2. */
      30             :     .dloc[6] = LOC_DEADEND12,
      31             :     .chloc   = LOC_DEADEND12,
      32             :     .chloc2  = LOC_DEADEND13,
      33             :     .abbnum  = 5,
      34             :     .clock1  = WARNTIME,
      35             :     .clock2  = FLASHTIME,
      36             :     .newloc  = LOC_START,
      37             :     .loc     = LOC_START,
      38             :     .limit   = GAMELIMIT,
      39             :     .foobar  = WORD_EMPTY,
      40             : };
      41             : 
      42         104 : long initialise(void)
      43             : {
      44         104 :     if (settings.oldstyle)
      45           1 :         printf("Initialising...\n");
      46             : 
      47         104 :     srand(time(NULL));
      48         104 :     long seedval = (long)rand();
      49         104 :     set_seed(seedval);
      50             : 
      51        7280 :     for (int i = 1; i <= NOBJECTS; i++) {
      52        7176 :         game.place[i] = LOC_NOWHERE;
      53             :     }
      54             : 
      55       19240 :     for (int i = 1; i <= NLOCATIONS; i++) {
      56       38272 :         if (!(locations[i].description.big == 0 ||
      57       19136 :               tkey[i] == 0)) {
      58       19136 :             int k = tkey[i];
      59       19136 :             if (T_TERMINATE(travel[k]))
      60        2288 :                 conditions[i] |= (1 << COND_FORCED);
      61             :         }
      62             :     }
      63             : 
      64             :     /*  Set up the game.atloc and game.link arrays.
      65             :      *  We'll use the DROP subroutine, which prefaces new objects on the
      66             :      *  lists.  Since we want things in the other order, we'll run the
      67             :      *  loop backwards.  If the object is in two locs, we drop it twice.
      68             :      *  Also, since two-placed objects are typically best described
      69             :      *  last, we'll drop them first. */
      70        7280 :     for (int i = NOBJECTS; i >= 1; i--) {
      71        7176 :         if (objects[i].fixd > 0) {
      72        1040 :             drop(i + NOBJECTS, objects[i].fixd);
      73        1040 :             drop(i, objects[i].plac);
      74             :         }
      75             :     }
      76             : 
      77        7280 :     for (int i = 1; i <= NOBJECTS; i++) {
      78        7176 :         int k = NOBJECTS + 1 - i;
      79        7176 :         game.fixed[k] = objects[k].fixd;
      80        7176 :         if (objects[k].plac != 0 && objects[k].fixd <= 0)
      81        4368 :             drop(k, objects[k].plac);
      82             :     }
      83             : 
      84             :     /*  Treasure props are initially -1, and are set to 0 the first time
      85             :      *  they are described.  game.tally keeps track of how many are
      86             :      *  not yet found, so we know when to close the cave. */
      87        7280 :     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
      88        7176 :         if (objects[treasure].is_treasure) {
      89        2080 :             if (objects[treasure].inventory != 0)
      90        2080 :                 game.prop[treasure] = STATE_NOTFOUND;
      91        2080 :             game.tally = game.tally - game.prop[treasure];
      92             :         }
      93             :     }
      94         104 :     game.conds = setbit(11);
      95             : 
      96         104 :     return seedval;
      97             : }

Generated by: LCOV version 1.13