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