4 * SPDX-FileCopyrightText: (C) 1977, 2005 by Will Crowther and Don Woodsm
5 * SPDX-License-Identifier: BSD-2-Clause
17 struct settings_t settings = {.logfp = NULL, .oldstyle = false, .prompt = true};
19 struct game_t game = {
20 /* Last dwarf is special (the pirate). He always starts at his
21 * chest's eventual location inside the maze. This loc is saved
22 * in chloc for ref. The dead end in the other maze has its
23 * loc stored in chloc2. */
24 .chloc = LOC_MAZEEND12, .chloc2 = LOC_DEADEND13, .abbnum = 5,
25 .clock1 = WARNTIME, .clock2 = FLASHTIME, .newloc = LOC_START,
26 .loc = LOC_START, .limit = GAMELIMIT, .foobar = WORD_EMPTY,
29 int initialise(void) {
30 if (settings.oldstyle) {
31 printf("Initialising...\n");
35 int seedval = (int)rand();
38 for (int i = 1; i <= NDWARVES; i++) {
39 game.dwarves[i].loc = dwarflocs[i - 1];
42 for (int i = 1; i <= NOBJECTS; i++) {
43 game.objects[i].place = LOC_NOWHERE;
46 for (int i = 1; i <= NLOCATIONS; i++) {
47 if (!(locations[i].description.big == 0 || tkey[i] == 0)) {
49 if (travel[k].motion == HERE) {
50 conditions[i] |= (1 << COND_FORCED);
55 /* Set up the game.locs atloc and game.link arrays.
56 * We'll use the DROP subroutine, which prefaces new objects on the
57 * lists. Since we want things in the other order, we'll run the
58 * loop backwards. If the object is in two locs, we drop it twice.
59 * Also, since two-placed objects are typically best described
60 * last, we'll drop them first. */
61 for (int i = NOBJECTS; i >= 1; i--) {
62 if (objects[i].fixd > 0) {
63 drop(i + NOBJECTS, objects[i].fixd);
64 drop(i, objects[i].plac);
68 for (int i = 1; i <= NOBJECTS; i++) {
69 int k = NOBJECTS + 1 - i;
70 game.objects[k].fixed = objects[k].fixd;
71 if (objects[k].plac != 0 && objects[k].fixd <= 0) {
72 drop(k, objects[k].plac);
76 /* Treasure props are initially STATE_NOTFOUND, and are set to
77 * STATE_FOUND the first time they are described. game.tally
78 * keeps track of how many are not yet found, so we know when to
80 * (ESR) Non-trreasures are set to STATE_FOUND explicity so we
81 * don't rely on the value of uninitialized storage. This is to
82 * make translation to future languages easier. */
83 for (int object = 1; object <= NOBJECTS; object++) {
84 if (objects[object].is_treasure) {
86 if (objects[object].inventory != NULL) {
87 OBJECT_SET_NOT_FOUND(object);
90 OBJECT_SET_FOUND(object);
93 game.conds = setbit(COND_HBASE);