Cut initialize in favor of implicit/default initialization where possible
[open-adventure.git] / init.c
1 #include <unistd.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <stdbool.h>
5
6 #include "advent.h"
7
8 /*
9  * Initialisation
10  */
11
12 void initialise(void)
13 {
14     if (oldstyle)
15         printf("Initialising...\n");
16
17     for (int i = 1; i <= NOBJECTS; i++) {
18         game.place[i] = LOC_NOWHERE;
19     }
20
21     for (int i = 1; i <= NLOCATIONS; i++) {
22         if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
23             int k = tkey[i];
24             if (T_TERMINATE(travel[k]))
25                 conditions[i] |= (1 << COND_FORCED);
26         }
27     }
28
29     /*  Set up the game.atloc and game.link arrays.
30      *  We'll use the DROP subroutine, which prefaces new objects on the
31      *  lists.  Since we want things in the other order, we'll run the
32      *  loop backwards.  If the object is in two locs, we drop it twice.
33      *  This also sets up "game.place" and "fixed" as copies of "PLAC" and
34      *  "FIXD".  Also, since two-placed objects are typically best
35      *  described last, we'll drop them first. */
36     for (int i = NOBJECTS; i >= 1; i--) {
37         if (objects[i].fixd > 0) {
38             drop(i + NOBJECTS, objects[i].fixd);
39             drop(i, objects[i].plac);
40         }
41     }
42
43     for (int i = 1; i <= NOBJECTS; i++) {
44         int k = NOBJECTS + 1 - i;
45         game.fixed[k] = objects[k].fixd;
46         if (objects[k].plac != 0 && objects[k].fixd <= 0)
47             drop(k, objects[k].plac);
48     }
49
50     /*  Treasure props are initially -1, and are set to 0 the first time
51      *  they are described.  game.tally keeps track of how many are
52      *  not yet found, so we know when to close the cave. */
53     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
54         if (objects[treasure].is_treasure) {
55             if (objects[treasure].inventory != 0)
56                 game.prop[treasure] = -1;
57             game.tally = game.tally - game.prop[treasure];
58         }
59     }
60
61     /*  Clear the hint stuff.  game.hintlc[i] is how long he's been at LOC
62      *  with cond bit i.  game.hinted[i] is true iff hint i has been
63      *  used. */
64     for (int i = 0; i < NHINTS; i++) {
65         game.hinted[i] = false;
66         game.hintlc[i] = 0;
67     }
68
69     /*  Initialise the dwarves.  game.dloc is loc of dwarves,
70      *  hard-wired in.  game.odloc is prior loc of each dwarf,
71      *  initially garbage.  DALTLC is alternate initial loc for dwarf,
72      *  in case one of them starts out on top of the adventurer.  (No
73      *  2 of the 5 initial locs are adjacent.)  game.dseen is true if
74      *  dwarf has seen him.  game.dflag controls the level of
75      *  activation of all this:
76      *  0       No dwarf stuff yet (wait until reaches Hall Of Mists)
77      *  1       Reached Hall Of Mists, but hasn't met first dwarf
78      *  2       Met first dwarf, others start moving, no knives thrown yet
79      *  3       A knife has been thrown (first set always misses)
80      *  3+      Dwarves are mad (increases their accuracy)
81      *  Sixth dwarf is special (the pirate).  He always starts at his
82      *  chest's eventual location inside the maze.  This loc is saved
83      *  in game.chloc for ref.  the dead end in the other maze has its
84      *  loc stored in game.chloc2. */
85
86     game.conds = setbit(11);
87 }