Jettison MAKEWD(), GETTXT(), vocab(), GETIN(), and the old db compiler.
[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         game.prop[i] = 0;
20         game.link[i + NOBJECTS] = game.link[i] = 0;
21     }
22
23     for (int i = 1; i <= NLOCATIONS; i++) {
24         game.abbrev[i] = 0;
25         if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
26             int k = tkey[i];
27             if (T_TERMINATE(travel[k]))
28                 conditions[i] |= (1 << COND_FORCED);
29         }
30         game.atloc[i] = 0;
31     }
32
33     /*  Set up the game.atloc and game.link arrays.
34      *  We'll use the DROP subroutine, which prefaces new objects on the
35      *  lists.  Since we want things in the other order, we'll run the
36      *  loop backwards.  If the object is in two locs, we drop it twice.
37      *  This also sets up "game.place" and "fixed" as copies of "PLAC" and
38      *  "FIXD".  Also, since two-placed objects are typically best
39      *  described last, we'll drop them first. */
40     for (int i = NOBJECTS; i >= 1; i--) {
41         if (objects[i].fixd > 0) {
42             drop(i + NOBJECTS, objects[i].fixd);
43             drop(i, objects[i].plac);
44         }
45     }
46
47     for (int i = 1; i <= NOBJECTS; i++) {
48         int k = NOBJECTS + 1 - i;
49         game.fixed[k] = objects[k].fixd;
50         if (objects[k].plac != 0 && objects[k].fixd <= 0)
51             drop(k, objects[k].plac);
52     }
53
54     /*  Treasure props are initially -1, and are set to 0 the first time
55      *  they are described.  game.tally keeps track of how many are
56      *  not yet found, so we know when to close the cave. */
57     game.tally = 0;
58     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
59         if (objects[treasure].is_treasure) {
60             if (objects[treasure].inventory != 0)
61                 game.prop[treasure] = -1;
62             game.tally = game.tally - game.prop[treasure];
63         }
64     }
65
66     /*  Clear the hint stuff.  game.hintlc[i] is how long he's been at LOC
67      *  with cond bit i.  game.hinted[i] is true iff hint i has been
68      *  used. */
69     for (int i = 0; i < NHINTS; i++) {
70         game.hinted[i] = false;
71         game.hintlc[i] = 0;
72     }
73
74     /*  Initialise the dwarves.  game.dloc is loc of dwarves,
75      *  hard-wired in.  game.odloc is prior loc of each dwarf,
76      *  initially garbage.  DALTLC is alternate initial loc for dwarf,
77      *  in case one of them starts out on top of the adventurer.  (No
78      *  2 of the 5 initial locs are adjacent.)  game.dseen is true if
79      *  dwarf has seen him.  game.dflag controls the level of
80      *  activation of all this:
81      *  0       No dwarf stuff yet (wait until reaches Hall Of Mists)
82      *  1       Reached Hall Of Mists, but hasn't met first dwarf
83      *  2       Met first dwarf, others start moving, no knives thrown yet
84      *  3       A knife has been thrown (first set always misses)
85      *  3+      Dwarves are mad (increases their accuracy)
86      *  Sixth dwarf is special (the pirate).  He always starts at his
87      *  chest's eventual location inside the maze.  This loc is saved
88      *  in game.chloc for ref.  the dead end in the other maze has its
89      *  loc stored in game.chloc2. */
90     game.chloc = LOC_DEADEND12;
91     game.chloc2 = LOC_DEADEND13;
92     for (int i = 1; i <= NDWARVES; i++) {
93         game.dseen[i] = false;
94     }
95     game.dflag = 0;
96     game.dloc[1] = LOC_KINGHALL;
97     game.dloc[2] = LOC_WESTBANK;
98     game.dloc[3] = LOC_Y2;
99     game.dloc[4] = LOC_ALIKE3;
100     game.dloc[5] = LOC_COMPLEX;
101     game.dloc[6] = game.chloc;
102
103     game.turns = 0;
104     game.trnluz = 0;
105     game.lmwarn = false;
106     game.iwest = 0;
107     game.knfloc = 0;
108     game.detail = 0;
109     game.abbnum = 5;
110     game.numdie = 0;
111     game.holdng = 0;
112     game.dkill = 0;
113     game.foobar = 0;
114     game.bonus = 0;
115     game.clock1 = WARNTIME;
116     game.clock2 = FLASHTIME;
117     game.conds = setbit(11);
118     game.saved = 0;
119     game.closng = false;
120     game.panic = false;
121     game.closed = false;
122     game.clshnt = false;
123     game.novice = false;
124     game.blklin = true;
125 }