Use enums for object number mnemonics instead of VOCWRD() calls.
[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 #include "database.h"
8
9 /*
10  * Initialisation
11  */
12
13 void initialise(void)
14 {
15     if (oldstyle)
16         printf("Initialising...\n");
17
18     for (int i = 1; i <= NOBJECTS; i++) {
19         game.place[i] = LOC_NOWHERE;
20         game.prop[i] = 0;
21         game.link[i + NOBJECTS] = game.link[i] = 0;
22     }
23
24     for (int i = 1; i <= NLOCATIONS; i++) {
25         game.abbrev[i] = 0;
26         if (!(locations[i].description.big == 0 || TKEY[i] == 0)) {
27             int k = TKEY[i];
28             if (MOD(labs(TRAVEL[k]), 1000) == 1)
29                 conditions[i] |= (1 << COND_FORCED);
30         }
31         game.atloc[i] = 0;
32     }
33
34     /*  Set up the game.atloc and game.link arrays.
35      *  We'll use the DROP subroutine, which prefaces new objects on the
36      *  lists.  Since we want things in the other order, we'll run the
37      *  loop backwards.  If the object is in two locs, we drop it twice.
38      *  This also sets up "game.place" and "fixed" as copies of "PLAC" and
39      *  "FIXD".  Also, since two-placed objects are typically best
40      *  described last, we'll drop them first. */
41     for (int i = NOBJECTS; i >= 1; i--) {
42         if (objects[i].fixd > 0) {
43             drop(i + NOBJECTS, objects[i].fixd);
44             drop(i, objects[i].plac);
45         }
46     }
47
48     for (int i = 1; i <= NOBJECTS; i++) {
49         int k = NOBJECTS + 1 - i;
50         game.fixed[k] = objects[k].fixd;
51         if (objects[k].plac != 0 && objects[k].fixd <= 0)
52             drop(k, objects[k].plac);
53     }
54
55     /*  Treasure props are initially -1, and are set to 0 the first time
56      *  they are described.  game.tally keeps track of how many are
57      *  not yet found, so we know when to close the cave. */
58     game.tally = 0;
59     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
60         if (objects[treasure].is_treasure) {
61             if (objects[treasure].inventory != 0)
62                 game.prop[treasure] = -1;
63             game.tally = game.tally - game.prop[treasure];
64         }
65     }
66
67     /*  Clear the hint stuff.  game.hintlc[i] is how long he's been at LOC
68      *  with cond bit i.  game.hinted[i] is true iff hint i has been
69      *  used. */
70     for (int i = 0; i < NHINTS; i++) {
71         game.hinted[i] = false;
72         game.hintlc[i] = 0;
73     }
74
75     /* Define some handy mnemonics. */
76
77     /* These are motion-verb numbers. */
78     BACK = VOCWRD(WORD_BACK, 0);
79     CAVE = VOCWRD(WORD_CAVE, 0);
80     DPRSSN = VOCWRD(WORD_DPRSSN, 0);
81     ENTER = VOCWRD(WORD_ENTER, 0);
82     ENTRNC = VOCWRD(WORD_ENTRNC, 0);
83     LOOK = VOCWRD(WORD_LOOK, 0);
84     NUL = VOCWRD(WORD_NUL, 0);
85     STREAM = VOCWRD(WORD_STREAM, 0);
86
87     /* And some action verbs. */
88     FIND = VOCWRD(WORD_FIND, 2);
89     INVENT = VOCWRD(WORD_INVENT, 2);
90     LOCK = VOCWRD(WORD_LOCK, 2);
91     SAY = VOCWRD(WORD_SAY, 2);
92     THROW = VOCWRD(WORD_THROW, 2);
93
94     /*  Initialise the dwarves.  game.dloc is loc of dwarves,
95      *  hard-wired in.  game.odloc is prior loc of each dwarf,
96      *  initially garbage.  DALTLC is alternate initial loc for dwarf,
97      *  in case one of them starts out on top of the adventurer.  (No
98      *  2 of the 5 initial locs are adjacent.)  game.dseen is true if
99      *  dwarf has seen him.  game.dflag controls the level of
100      *  activation of all this:
101      *  0       No dwarf stuff yet (wait until reaches Hall Of Mists)
102      *  1       Reached Hall Of Mists, but hasn't met first dwarf
103      *  2       Met first dwarf, others start moving, no knives thrown yet
104      *  3       A knife has been thrown (first set always misses)
105      *  3+      Dwarves are mad (increases their accuracy)
106      *  Sixth dwarf is special (the pirate).  He always starts at his
107      *  chest's eventual location inside the maze.  This loc is saved
108      *  in game.chloc for ref.  the dead end in the other maze has its
109      *  loc stored in game.chloc2. */
110     game.chloc = LOC_DEADEND12;
111     game.chloc2 = LOC_DEADEND13;
112     for (int i = 1; i <= NDWARVES; i++) {
113         game.dseen[i] = false;
114     }
115     game.dflag = 0;
116     game.dloc[1] = LOC_KINGHALL;
117     game.dloc[2] = LOC_WESTBANK;
118     game.dloc[3] = LOC_Y2;
119     game.dloc[4] = LOC_ALIKE3;
120     game.dloc[5] = LOC_COMPLEX;
121     game.dloc[6] = game.chloc;
122
123     game.turns = 0;
124     game.trnluz = 0;
125     game.lmwarn = false;
126     game.iwest = 0;
127     game.knfloc = 0;
128     game.detail = 0;
129     game.abbnum = 5;
130     game.numdie = 0;
131     game.holdng = 0;
132     game.dkill = 0;
133     game.foobar = 0;
134     game.bonus = 0;
135     game.clock1 = WARNTIME;
136     game.clock2 = FLASHTIME;
137     game.conds = setbit(11);
138     game.saved = 0;
139     game.closng = false;
140     game.panic = false;
141     game.closed = false;
142     game.clshnt = false;
143     game.novice = false;
144     game.blklin = true;
145 }