Spread documentation from init.c It was empty without anything to document. Reindente...
[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      *  Also, since two-placed objects are typically best described
34      *  last, we'll drop them first. */
35     for (int i = NOBJECTS; i >= 1; i--) {
36         if (objects[i].fixd > 0) {
37             drop(i + NOBJECTS, objects[i].fixd);
38             drop(i, objects[i].plac);
39         }
40     }
41
42     for (int i = 1; i <= NOBJECTS; i++) {
43         int k = NOBJECTS + 1 - i;
44         game.fixed[k] = objects[k].fixd;
45         if (objects[k].plac != 0 && objects[k].fixd <= 0)
46             drop(k, objects[k].plac);
47     }
48
49     /*  Treasure props are initially -1, and are set to 0 the first time
50      *  they are described.  game.tally keeps track of how many are
51      *  not yet found, so we know when to close the cave. */
52     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
53         if (objects[treasure].is_treasure) {
54             if (objects[treasure].inventory != 0)
55                 game.prop[treasure] = -1;
56             game.tally = game.tally - game.prop[treasure];
57         }
58     }
59     game.conds = setbit(11);
60 }