0ad375bfe22c5c2f45701f15904eca1245a6f58b
[open-adventure.git] / main.c
1 /*
2  * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
3  * Copyright (c) 2017 by Eric S. Raymond
4  * SPDX-License-Identifier: BSD-2-clause
5  */
6
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <stdbool.h>
10 #include <getopt.h>
11 #include <signal.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include "advent.h"
15 #include "dungeon.h"
16
17 #define DIM(a) (sizeof(a)/sizeof(a[0]))
18
19 // LCOV_EXCL_START
20 // exclude from coverage analysis because it requires interactivity to test
21 static void sig_handler(int signo)
22 {
23     if (signo == SIGINT) {
24         if (settings.logfp != NULL)
25             fflush(settings.logfp);
26     }
27     exit(EXIT_FAILURE);
28 }
29 // LCOV_EXCL_STOP
30
31 /*
32  * MAIN PROGRAM
33  *
34  *  Adventure (rev 2: 20 treasures)
35  *  History: Original idea & 5-treasure version (adventures) by Willie Crowther
36  *           15-treasure version (adventure) by Don Woods, April-June 1977
37  *           20-treasure version (rev 2) by Don Woods, August 1978
38  *              Errata fixed: 78/12/25
39  *           Revived 2017 as Open Adventure.
40  */
41
42 static bool do_command(void);
43 static bool do_move(void);
44
45 int main(int argc, char *argv[])
46 {
47     int ch;
48
49     /*  Options. */
50
51 #ifndef ADVENT_NOSAVE
52     const char* opts = "l:or:";
53     const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename]\n";
54     FILE *rfp = NULL;
55 #else
56     const char* opts = "l:o";
57     const char* usage = "Usage: %s [-l logfilename] [-o]\n";
58 #endif
59     while ((ch = getopt(argc, argv, opts)) != EOF) {
60         switch (ch) {
61         case 'l':
62             settings.logfp = fopen(optarg, "w");
63             if (settings.logfp == NULL)
64                 fprintf(stderr,
65                         "advent: can't open logfile %s for write\n",
66                         optarg);
67             signal(SIGINT, sig_handler);
68             break;
69         case 'o':
70             settings.oldstyle = true;
71             settings.prompt = false;
72             break;
73 #ifndef ADVENT_NOSAVE
74         case 'r':
75             rfp = fopen(optarg, "r");
76             if (rfp == NULL)
77                 fprintf(stderr,
78                         "advent: can't open save file %s for read\n",
79                         optarg);
80             break;
81 #endif
82         default:
83             fprintf(stderr,
84                     usage, argv[0]);
85             fprintf(stderr,
86                     "        -l create a log file of your game named as specified'\n");
87             fprintf(stderr,
88                     "        -o 'oldstyle' (no prompt, no command editing, displays 'Initialising...')\n");
89 #ifndef ADVENT_NOSAVE
90             fprintf(stderr,
91                     "        -r restore from specified saved game file\n");
92 #endif
93             exit(EXIT_FAILURE);
94             break;
95         }
96     }
97
98     /*  Initialize game variables */
99     long seedval = initialise();
100
101 #ifndef ADVENT_NOSAVE
102     if (!rfp) {
103         game.novice = yes(arbitrary_messages[WELCOME_YOU], arbitrary_messages[CAVE_NEARBY], arbitrary_messages[NO_MESSAGE]);
104         if (game.novice)
105             game.limit = NOVICELIMIT;
106     } else {
107         restore(rfp);
108     }
109 #else
110     game.novice = yes(arbitrary_messages[WELCOME_YOU], arbitrary_messages[CAVE_NEARBY], arbitrary_messages[NO_MESSAGE]);
111     if (game.novice)
112         game.limit = NOVICELIMIT;
113 #endif
114
115     if (settings.logfp)
116         fprintf(settings.logfp, "seed %ld\n", seedval);
117
118     /* interpret commands until EOF or interrupt */
119     for (;;) {
120         // if we're supposed to move, move
121         if (!do_move())
122             continue;
123
124         // get command
125         if (!do_command())
126             break;
127     }
128     /* show score and exit */
129     terminate(quitgame);
130 }
131
132 /*  Check if this loc is eligible for any hints.  If been here long
133  *  enough, display.  Ignore "HINTS" < 4 (special stuff, see database
134  *  notes). */
135 static void checkhints(void)
136 {
137     if (conditions[game.loc] >= game.conds) {
138         for (int hint = 0; hint < NHINTS; hint++) {
139             if (game.hinted[hint])
140                 continue;
141             if (!CNDBIT(game.loc, hint + 1 + COND_HBASE))
142                 game.hintlc[hint] = -1;
143             ++game.hintlc[hint];
144             /*  Come here if he's been long enough at required loc(s) for some
145              *  unused hint. */
146             if (game.hintlc[hint] >= hints[hint].turns) {
147                 int i;
148
149                 switch (hint) {
150                 case 0:
151                     /* cave */
152                     if (game.prop[GRATE] == GRATE_CLOSED && !HERE(KEYS))
153                         break;
154                     game.hintlc[hint] = 0;
155                     return;
156                 case 1: /* bird */
157                     if (game.place[BIRD] == game.loc && TOTING(ROD) && game.oldobj == BIRD)
158                         break;
159                     return;
160                 case 2: /* snake */
161                     if (HERE(SNAKE) && !HERE(BIRD))
162                         break;
163                     game.hintlc[hint] = 0;
164                     return;
165                 case 3: /* maze */
166                     if (game.atloc[game.loc] == NO_OBJECT &&
167                         game.atloc[game.oldloc] == NO_OBJECT &&
168                         game.atloc[game.oldlc2] == NO_OBJECT &&
169                         game.holdng > 1)
170                         break;
171                     game.hintlc[hint] = 0;
172                     return;
173                 case 4: /* dark */
174                     if (game.prop[EMERALD] != STATE_NOTFOUND && game.prop[PYRAMID] == STATE_NOTFOUND)
175                         break;
176                     game.hintlc[hint] = 0;
177                     return;
178                 case 5: /* witt */
179                     break;
180                 case 6: /* urn */
181                     if (game.dflag == 0)
182                         break;
183                     game.hintlc[hint] = 0;
184                     return;
185                 case 7: /* woods */
186                     if (game.atloc[game.loc] == NO_OBJECT &&
187                         game.atloc[game.oldloc] == NO_OBJECT &&
188                         game.atloc[game.oldlc2] == NO_OBJECT)
189                         break;
190                     return;
191                 case 8: /* ogre */
192                     i = atdwrf(game.loc);
193                     if (i < 0) {
194                         game.hintlc[hint] = 0;
195                         return;
196                     }
197                     if (HERE(OGRE) && i == 0)
198                         break;
199                     return;
200                 case 9: /* jade */
201                     if (game.tally == 1 && game.prop[JADE] < 0)
202                         break;
203                     game.hintlc[hint] = 0;
204                     return;
205                 default: // LCOV_EXCL_LINE
206                     BUG(HINT_NUMBER_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
207                 }
208
209                 /* Fall through to hint display */
210                 game.hintlc[hint] = 0;
211                 if (!yes(hints[hint].question, arbitrary_messages[NO_MESSAGE], arbitrary_messages[OK_MAN]))
212                     return;
213                 rspeak(HINT_COST, hints[hint].penalty, hints[hint].penalty);
214                 game.hinted[hint] = yes(arbitrary_messages[WANT_HINT], hints[hint].hint, arbitrary_messages[OK_MAN]);
215                 if (game.hinted[hint] && game.limit > WARNTIME)
216                     game.limit += WARNTIME * hints[hint].penalty;
217             }
218         }
219     }
220
221
222 }
223
224 static bool spotted_by_pirate(int i)
225 {
226     if (i != PIRATE)
227         return false;
228
229     /*  The pirate's spotted him.  Pirate leaves him alone once we've
230      *  found chest.  K counts if a treasure is here.  If not, and
231      *  tally=1 for an unseen chest, let the pirate be spotted.  Note
232      *  that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown
233      *  it to the troll, but in that case he's seen the chest
234      *  (game.prop[CHEST] == STATE_FOUND). */
235     if (game.loc == game.chloc ||
236         game.prop[CHEST] != STATE_NOTFOUND)
237         return true;
238     int snarfed = 0;
239     bool movechest = false, robplayer = false;
240     for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
241         if (!objects[treasure].is_treasure)
242             continue;
243         /*  Pirate won't take pyramid from plover room or dark
244          *  room (too easy!). */
245         if (treasure == PYRAMID && (game.loc == objects[PYRAMID].plac ||
246                                     game.loc == objects[EMERALD].plac)) {
247             continue;
248         }
249         if (TOTING(treasure) ||
250             HERE(treasure))
251             ++snarfed;
252         if (TOTING(treasure)) {
253             movechest = true;
254             robplayer = true;
255         }
256     }
257     /* Force chest placement before player finds last treasure */
258     if (game.tally == 1 && snarfed == 0 && game.place[CHEST] == LOC_NOWHERE && HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT) {
259         rspeak(PIRATE_SPOTTED);
260         movechest = true;
261     }
262     /* Do things in this order (chest move before robbery) so chest is listed
263      * last at the maze location. */
264     if (movechest) {
265         move(CHEST, game.chloc);
266         move(MESSAG, game.chloc2);
267         game.dloc[PIRATE] = game.chloc;
268         game.odloc[PIRATE] = game.chloc;
269         game.dseen[PIRATE] = false;
270     } else {
271         /* You might get a hint of the pirate's presence even if the
272          * chest doesn't move... */
273         if (game.odloc[PIRATE] != game.dloc[PIRATE] && PCT(20))
274             rspeak(PIRATE_RUSTLES);
275     }
276     if (robplayer) {
277         rspeak(PIRATE_POUNCES);
278         for (int treasure = 1; treasure <= NOBJECTS; treasure++) {
279             if (!objects[treasure].is_treasure)
280                 continue;
281             if (!(treasure == PYRAMID && (game.loc == objects[PYRAMID].plac ||
282                                           game.loc == objects[EMERALD].plac))) {
283                 if (AT(treasure) && game.fixed[treasure] == IS_FREE)
284                     carry(treasure, game.loc);
285                 if (TOTING(treasure))
286                     drop(treasure, game.chloc);
287             }
288         }
289     }
290
291     return true;
292 }
293
294 static bool dwarfmove(void)
295 /* Dwarves move.  Return true if player survives, false if he dies. */
296 {
297     int kk, stick, attack;
298     loc_t tk[21];
299
300     /*  Dwarf stuff.  See earlier comments for description of
301      *  variables.  Remember sixth dwarf is pirate and is thus
302      *  very different except for motion rules. */
303
304     /*  First off, don't let the dwarves follow him into a pit or a
305      *  wall.  Activate the whole mess the first time he gets as far
306      *  as the Hall of Mists (what INDEEP() tests).  If game.newloc
307      *  is forbidden to pirate (in particular, if it's beyond the
308      *  troll bridge), bypass dwarf stuff.  That way pirate can't
309      *  steal return toll, and dwarves can't meet the bear.  Also
310      *  means dwarves won't follow him into dead end in maze, but
311      *  c'est la vie.  They'll wait for him outside the dead end. */
312     if (game.loc == LOC_NOWHERE ||
313         FORCED(game.loc) ||
314         CNDBIT(game.newloc, COND_NOARRR))
315         return true;
316
317     /* Dwarf activity level ratchets up */
318     if (game.dflag == 0) {
319         if (INDEEP(game.loc))
320             game.dflag = 1;
321         return true;
322     }
323
324     /*  When we encounter the first dwarf, we kill 0, 1, or 2 of
325      *  the 5 dwarves.  If any of the survivors is at game.loc,
326      *  replace him with the alternate. */
327     if (game.dflag == 1) {
328         if (!INDEEP(game.loc) ||
329             (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) ||
330                          PCT(85))))
331             return true;
332         game.dflag = 2;
333         for (int i = 1; i <= 2; i++) {
334             int j = 1 + randrange(NDWARVES - 1);
335             if (PCT(50))
336                 game.dloc[j] = 0;
337         }
338
339         /* Alternate initial loc for dwarf, in case one of them
340         *  starts out on top of the adventurer. */
341         for (int i = 1; i <= NDWARVES - 1; i++) {
342             if (game.dloc[i] == game.loc)
343                 game.dloc[i] = DALTLC; //
344             game.odloc[i] = game.dloc[i];
345         }
346         rspeak(DWARF_RAN);
347         drop(AXE, game.loc);
348         return true;
349     }
350
351     /*  Things are in full swing.  Move each dwarf at random,
352      *  except if he's seen us he sticks with us.  Dwarves stay
353      *  deep inside.  If wandering at random, they don't back up
354      *  unless there's no alternative.  If they don't have to
355      *  move, they attack.  And, of course, dead dwarves don't do
356      *  much of anything. */
357     game.dtotal = 0;
358     attack = 0;
359     stick = 0;
360     for (int i = 1; i <= NDWARVES; i++) {
361         if (game.dloc[i] == 0)
362             continue;
363         /*  Fill tk array with all the places this dwarf might go. */
364         unsigned int j = 1;
365         kk = tkey[game.dloc[i]];
366         if (kk != 0)
367             do {
368                 enum desttype_t desttype = travel[kk].desttype;
369                 game.newloc = travel[kk].destval;
370                 /* Have we avoided a dwarf encounter? */
371                 if (desttype != dest_goto)
372                     continue;
373                 else if (!INDEEP(game.newloc))
374                     continue;
375                 else if (game.newloc == game.odloc[i])
376                     continue;
377                 else if (j > 1 && game.newloc == tk[j - 1])
378                     continue;
379                 else if (j >= DIM(tk) - 1)
380                     /* This can't actually happen. */
381                     continue; // LCOV_EXCL_LINE
382                 else if (game.newloc == game.dloc[i])
383                     continue;
384                 else if (FORCED(game.newloc))
385                     continue;
386                 else if (i == PIRATE && CNDBIT(game.newloc, COND_NOARRR))
387                     continue;
388                 else if (travel[kk].nodwarves)
389                     continue;
390                 tk[j++] = game.newloc;
391             } while
392             (!travel[kk++].stop);
393         tk[j] = game.odloc[i];
394         if (j >= 2)
395             --j;
396         j = 1 + randrange(j);
397         game.odloc[i] = game.dloc[i];
398         game.dloc[i] = tk[j];
399         game.dseen[i] = (game.dseen[i] && INDEEP(game.loc)) ||
400                         (game.dloc[i] == game.loc ||
401                          game.odloc[i] == game.loc);
402         if (!game.dseen[i])
403             continue;
404         game.dloc[i] = game.loc;
405         if (spotted_by_pirate(i))
406             continue;
407         /* This threatening little dwarf is in the room with him! */
408         ++game.dtotal;
409         if (game.odloc[i] == game.dloc[i]) {
410             ++attack;
411             if (game.knfloc >= 0)
412                 game.knfloc = game.loc;
413             if (randrange(1000) < 95 * (game.dflag - 2))
414                 ++stick;
415         }
416     }
417
418     /*  Now we know what's happening.  Let's tell the poor sucker about it. */
419     if (game.dtotal == 0)
420         return true;
421     rspeak(game.dtotal == 1 ? DWARF_SINGLE : DWARF_PACK, game.dtotal);
422     if (attack == 0)
423         return true;
424     if (game.dflag == 2)
425         game.dflag = 3;
426     if (attack > 1) {
427         rspeak(THROWN_KNIVES, attack);
428         rspeak(stick > 1 ? MULTIPLE_HITS : (stick == 1 ? ONE_HIT : NONE_HIT), stick);
429     } else {
430         rspeak(KNIFE_THROWN);
431         rspeak(stick ? GETS_YOU : MISSES_YOU);
432     }
433     if (stick == 0)
434         return true;
435     game.oldlc2 = game.loc;
436     return false;
437 }
438
439 /*  "You're dead, Jim."
440  *
441  *  If the current loc is zero, it means the clown got himself killed.
442  *  We'll allow this maxdie times.  NDEATHS is automatically set based
443  *  on the number of snide messages available.  Each death results in
444  *  a message (obituaries[n]) which offers reincarnation; if accepted,
445  *  this results in message obituaries[0], obituaries[2], etc.  The
446  *  last time, if he wants another chance, he gets a snide remark as
447  *  we exit.  When reincarnated, all objects being carried get dropped
448  *  at game.oldlc2 (presumably the last place prior to being killed)
449  *  without change of props.  The loop runs backwards to assure that
450  *  the bird is dropped before the cage.  (This kluge could be changed
451  *  once we're sure all references to bird and cage are done by
452  *  keywords.)  The lamp is a special case (it wouldn't do to leave it
453  *  in the cave). It is turned off and left outside the building (only
454  *  if he was carrying it, of course).  He himself is left inside the
455  *  building (and heaven help him if he tries to xyzzy back into the
456  *  cave without the lamp!).  game.oldloc is zapped so he can't just
457  *  "retreat". */
458 static void croak(void)
459 /*  Okay, he's dead.  Let's get on with it. */
460 {
461     if (game.numdie < 0)
462         game.numdie = 0;  // LCOV_EXCL_LINE
463     const char* query = obituaries[game.numdie].query;
464     const char* yes_response = obituaries[game.numdie].yes_response;
465     ++game.numdie;
466     if (game.closng) {
467         /*  He died during closing time.  No resurrection.  Tally up a
468          *  death and exit. */
469         rspeak(DEATH_CLOSING);
470         terminate(endgame);
471     } else if ( !yes(query, yes_response, arbitrary_messages[OK_MAN])
472                 || game.numdie == NDEATHS)
473         terminate(endgame);
474     else {
475         game.place[WATER] = game.place[OIL] = LOC_NOWHERE;
476         if (TOTING(LAMP))
477             game.prop[LAMP] = LAMP_DARK;
478         for (int j = 1; j <= NOBJECTS; j++) {
479             int i = NOBJECTS + 1 - j;
480             if (TOTING(i)) {
481                 /* Always leave lamp where it's accessible aboveground */
482                 drop(i, (i == LAMP) ? LOC_START : game.oldlc2);
483             }
484         }
485         game.oldloc = game.loc = game.newloc = LOC_BUILDING;
486     }
487 }
488
489 static void describe_location(void) {
490     const char* msg = locations[game.loc].description.small;
491     if (MOD(game.abbrev[game.loc], game.abbnum) == 0 ||
492         msg == NO_MESSAGE)
493         msg = locations[game.loc].description.big;
494
495     if (!FORCED(game.loc) && DARK(game.loc)) {
496         msg = arbitrary_messages[PITCH_DARK];
497     }
498
499     if (TOTING(BEAR))
500         rspeak(TAME_BEAR);
501
502     speak(msg);
503     
504     if (game.loc == LOC_Y2 && PCT(25) && !game.closng) // FIXME: magic number
505         rspeak(SAYS_PLUGH);
506 }
507
508
509 static bool traveleq(int a, int b)
510 /* Are two travel entries equal for purposes of skip after failed condition? */
511 {
512     return (travel[a].condtype == travel[b].condtype)
513            && (travel[a].condarg1 == travel[b].condarg1)
514            && (travel[a].condarg2 == travel[b].condarg2)
515            && (travel[a].desttype == travel[b].desttype)
516            && (travel[a].destval == travel[b].destval);
517 }
518
519 /*  Given the current location in "game.loc", and a motion verb number in
520  *  "motion", put the new location in "game.newloc".  The current loc is saved
521  *  in "game.oldloc" in case he wants to retreat.  The current
522  *  game.oldloc is saved in game.oldlc2, in case he dies.  (if he
523  *  does, game.newloc will be limbo, and game.oldloc will be what killed
524  *  him, so we need game.oldlc2, which is the last place he was
525  *  safe.) */
526 static void playermove(int motion)
527 {
528     int scratchloc, travel_entry = tkey[game.loc];
529     game.newloc = game.loc;
530     if (travel_entry == 0)
531         BUG(LOCATION_HAS_NO_TRAVEL_ENTRIES); // LCOV_EXCL_LINE
532     if (motion == NUL)
533         return;
534     else if (motion == BACK) {
535         /*  Handle "go back".  Look for verb which goes from game.loc to
536          *  game.oldloc, or to game.oldlc2 If game.oldloc has forced-motion.
537          *  te_tmp saves entry -> forced loc -> previous loc. */
538         motion = game.oldloc;
539         if (FORCED(motion))
540             motion = game.oldlc2;
541         game.oldlc2 = game.oldloc;
542         game.oldloc = game.loc;
543         if (CNDBIT(game.loc, COND_NOBACK)) {
544             rspeak(TWIST_TURN);
545             return;
546         }
547         if (motion == game.loc) {
548             rspeak(FORGOT_PATH);
549             return;
550         }
551
552         int te_tmp = 0;
553         for (;;) {
554             enum desttype_t desttype = travel[travel_entry].desttype;
555             scratchloc = travel[travel_entry].destval;
556             if (desttype != dest_goto || scratchloc != motion) {
557                 if (desttype == dest_goto) {
558                     if (FORCED(scratchloc) && travel[tkey[scratchloc]].destval == motion)
559                         te_tmp = travel_entry;
560                 }
561                 if (!travel[travel_entry].stop) {
562                     ++travel_entry;     /* go to next travel entry for this location */
563                     continue;
564                 }
565                 /* we've reached the end of travel entries for game.loc */
566                 travel_entry = te_tmp;
567                 if (travel_entry == 0) {
568                     rspeak(NOT_CONNECTED);
569                     return;
570                 }
571             }
572
573             motion = travel[travel_entry].motion;
574             travel_entry = tkey[game.loc];
575             break; /* fall through to ordinary travel */
576         }
577     } else if (motion == LOOK) {
578         /*  Look.  Can't give more detail.  Pretend it wasn't dark
579          *  (though it may now be dark) so he won't fall into a
580          *  pit while staring into the gloom. */
581         if (game.detail < 3)
582             rspeak(NO_MORE_DETAIL);
583         ++game.detail;
584         game.wzdark = false;
585         game.abbrev[game.loc] = 0;
586         return;
587     } else if (motion == CAVE) {
588         /*  Cave.  Different messages depending on whether above ground. */
589         rspeak((OUTSID(game.loc) && game.loc != LOC_GRATE) ? FOLLOW_STREAM : NEED_DETAIL);
590         return;
591     } else {
592         /* none of the specials */
593         game.oldlc2 = game.oldloc;
594         game.oldloc = game.loc;
595     }
596
597     /* Look for a way to fulfil the motion verb passed in - travel_entry indexes
598      * the beginning of the motion entries for here (game.loc). */
599     for (;;) {
600         if (T_TERMINATE(travel[travel_entry]) ||
601             travel[travel_entry].motion == motion)
602             break;
603         if (travel[travel_entry].stop) {
604             /*  Couldn't find an entry matching the motion word passed
605              *  in.  Various messages depending on word given. */
606             switch (motion) {
607             case EAST:
608             case WEST:
609             case SOUTH:
610             case NORTH:
611             case NE:
612             case NW:
613             case SW:
614             case SE:
615             case UP:
616             case DOWN:
617                 rspeak(BAD_DIRECTION);
618                 break;
619             case FORWARD:
620             case LEFT:
621             case RIGHT:
622                 rspeak(UNSURE_FACING);
623                 break;
624             case OUTSIDE:
625             case INSIDE:
626                 rspeak(NO_INOUT_HERE);
627                 break;
628             case XYZZY:
629             case PLUGH:
630                 rspeak(NOTHING_HAPPENS);
631                 break;
632             case CRAWL:
633                 rspeak(WHICH_WAY);
634                 break;
635             default:
636                 rspeak(CANT_APPLY);
637             }
638             return;
639         }
640         ++travel_entry;
641     }
642
643     /* (ESR) We've found a destination that goes with the motion verb.
644      * Next we need to check any conditional(s) on this destination, and
645      * possibly on following entries. */
646     do {
647         for (;;) { /* L12 loop */
648             for (;;) {
649                 enum condtype_t condtype = travel[travel_entry].condtype;
650                 long condarg1 = travel[travel_entry].condarg1;
651                 long condarg2 = travel[travel_entry].condarg2;
652                 if (condtype < cond_not) {
653                     /* YAML N and [pct N] conditionals */
654                     if (condtype == cond_goto || condtype == cond_pct) {
655                         if (condarg1 == 0 ||
656                             PCT(condarg1))
657                             break;
658                         /* else fall through */
659                     }
660                     /* YAML [with OBJ] clause */
661                     else if (TOTING(condarg1) ||
662                              (condtype == cond_with && AT(condarg1)))
663                         break;
664                     /* else fall through to check [not OBJ STATE] */
665                 } else if (game.prop[condarg1] != condarg2)
666                     break;
667
668                 /* We arrive here on conditional failure.
669                  * Skip to next non-matching destination */
670                 int te_tmp = travel_entry;
671                 do {
672                     if (travel[te_tmp].stop)
673                         BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
674                     ++te_tmp;
675                 } while
676                 (traveleq(travel_entry, te_tmp));
677                 travel_entry = te_tmp;
678             }
679
680             /* Found an eligible rule, now execute it */
681             enum desttype_t desttype = travel[travel_entry].desttype;
682             game.newloc = travel[travel_entry].destval;
683             if (desttype == dest_goto)
684                 return;
685
686             if (desttype == dest_speak) {
687                 /* Execute a speak rule */
688                 rspeak(game.newloc);
689                 game.newloc = game.loc;
690                 return;
691             } else {
692                 switch (game.newloc) {
693                 case 1:
694                     /* Special travel 1.  Plover-alcove passage.  Can carry only
695                      * emerald.  Note: travel table must include "useless"
696                      * entries going through passage, which can never be used
697                      * for actual motion, but can be spotted by "go back". */
698                     game.newloc = (game.loc == LOC_PLOVER)
699                                   ? LOC_ALCOVE
700                                   : LOC_PLOVER;
701                     if (game.holdng > 1 ||
702                         (game.holdng == 1 && !TOTING(EMERALD))) {
703                         game.newloc = game.loc;
704                         rspeak(MUST_DROP);
705                     }
706                     return;
707                 case 2:
708                     /* Special travel 2.  Plover transport.  Drop the
709                      * emerald (only use special travel if toting
710                      * it), so he's forced to use the plover-passage
711                      * to get it out.  Having dropped it, go back and
712                      * pretend he wasn't carrying it after all. */
713                     drop(EMERALD, game.loc);
714                     {
715                         int te_tmp = travel_entry;
716                         do {
717                             if (travel[te_tmp].stop)
718                                 BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
719                             ++te_tmp;
720                         } while
721                         (traveleq(travel_entry, te_tmp));
722                         travel_entry = te_tmp;
723                     }
724                     continue; /* goto L12 */
725                 case 3:
726                     /* Special travel 3.  Troll bridge.  Must be done
727                      * only as special motion so that dwarves won't
728                      * wander across and encounter the bear.  (They
729                      * won't follow the player there because that
730                      * region is forbidden to the pirate.)  If
731                      * game.prop[TROLL]=TROLL_PAIDONCE, he's crossed
732                      * since paying, so step out and block him.
733                      * (standard travel entries check for
734                      * game.prop[TROLL]=TROLL_UNPAID.)  Special stuff
735                      * for bear. */
736                     if (game.prop[TROLL] == TROLL_PAIDONCE) {
737                         pspeak(TROLL, look, true, TROLL_PAIDONCE);
738                         game.prop[TROLL] = TROLL_UNPAID;
739                         move(TROLL2, LOC_NOWHERE);
740                         move(TROLL2 + NOBJECTS, IS_FREE);
741                         move(TROLL, objects[TROLL].plac);
742                         move(TROLL + NOBJECTS, objects[TROLL].fixd);
743                         juggle(CHASM);
744                         game.newloc = game.loc;
745                         return;
746                     } else {
747                         game.newloc = objects[TROLL].plac + objects[TROLL].fixd - game.loc;
748                         if (game.prop[TROLL] == TROLL_UNPAID)
749                             game.prop[TROLL] = TROLL_PAIDONCE;
750                         if (!TOTING(BEAR))
751                             return;
752                         state_change(CHASM, BRIDGE_WRECKED);
753                         game.prop[TROLL] = TROLL_GONE;
754                         drop(BEAR, game.newloc);
755                         game.fixed[BEAR] = IS_FIXED;
756                         game.prop[BEAR] = BEAR_DEAD;
757                         game.oldlc2 = game.newloc;
758                         croak();
759                         return;
760                     }
761                 default: // LCOV_EXCL_LINE
762                     BUG(SPECIAL_TRAVEL_500_GT_L_GT_300_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
763                 }
764             }
765             break; /* Leave L12 loop */
766         }
767     } while
768     (false);
769 }
770
771 static void lampcheck(void)
772 /* Check game limit and lamp timers */
773 {
774     if (game.prop[LAMP] == LAMP_BRIGHT)
775         --game.limit;
776
777     /*  Another way we can force an end to things is by having the
778      *  lamp give out.  When it gets close, we come here to warn him.
779      *  First following arm checks if the lamp and fresh batteries are
780      *  here, in which case we replace the batteries and continue.
781      *  Second is for other cases of lamp dying.  Even after it goes
782      *  out, he can explore outside for a while if desired. */
783     if (game.limit <= WARNTIME) {
784         if (HERE(BATTERY) && game.prop[BATTERY] == FRESH_BATTERIES && HERE(LAMP)) {
785             rspeak(REPLACE_BATTERIES);
786             game.prop[BATTERY] = DEAD_BATTERIES;
787 #ifdef __unused__
788             /* This code from the original game seems to have been faulty.
789              * No tests ever passed the guard, and with the guard removed
790              * the game hangs when the lamp limit is reached.
791              */
792             if (TOTING(BATTERY))
793                 drop(BATTERY, game.loc);
794 #endif
795             game.limit += BATTERYLIFE;
796             game.lmwarn = false;
797         } else if (!game.lmwarn && HERE(LAMP)) {
798             game.lmwarn = true;
799             if (game.prop[BATTERY] == DEAD_BATTERIES)
800                 rspeak(MISSING_BATTERIES);
801             else if (game.place[BATTERY] == LOC_NOWHERE)
802                 rspeak(LAMP_DIM);
803             else
804                 rspeak(GET_BATTERIES);
805         }
806     }
807     if (game.limit == 0) {
808         game.limit = -1;
809         game.prop[LAMP] = LAMP_DARK;
810         if (HERE(LAMP))
811             rspeak(LAMP_OUT);
812     }
813 }
814
815 static bool closecheck(void)
816 /*  Handle the closing of the cave.  The cave closes "clock1" turns
817  *  after the last treasure has been located (including the pirate's
818  *  chest, which may of course never show up).  Note that the
819  *  treasures need not have been taken yet, just located.  Hence
820  *  clock1 must be large enough to get out of the cave (it only ticks
821  *  while inside the cave).  When it hits zero, we branch to 10000 to
822  *  start closing the cave, and then sit back and wait for him to try
823  *  to get out.  If he doesn't within clock2 turns, we close the cave;
824  *  if he does try, we assume he panics, and give him a few additional
825  *  turns to get frantic before we close.  When clock2 hits zero, we
826  *  transport him into the final puzzle.  Note that the puzzle depends
827  *  upon all sorts of random things.  For instance, there must be no
828  *  water or oil, since there are beanstalks which we don't want to be
829  *  able to water, since the code can't handle it.  Also, we can have
830  *  no keys, since there is a grate (having moved the fixed object!)
831  *  there separating him from all the treasures.  Most of these
832  *  problems arise from the use of negative prop numbers to suppress
833  *  the object descriptions until he's actually moved the objects. */
834 {
835     /* If a turn threshold has been met, apply penalties and tell
836      * the player about it. */
837     for (int i = 0; i < NTHRESHOLDS; ++i) {
838         if (game.turns == turn_thresholds[i].threshold + 1) {
839             game.trnluz += turn_thresholds[i].point_loss;
840             speak(turn_thresholds[i].message);
841         }
842     }
843
844     /*  Don't tick game.clock1 unless well into cave (and not at Y2). */
845     if (game.tally == 0 && INDEEP(game.loc) && game.loc != LOC_Y2)
846         --game.clock1;
847
848     /*  When the first warning comes, we lock the grate, destroy
849      *  the bridge, kill all the dwarves (and the pirate), remove
850      *  the troll and bear (unless dead), and set "closng" to
851      *  true.  Leave the dragon; too much trouble to move it.
852      *  from now until clock2 runs out, he cannot unlock the
853      *  grate, move to any location outside the cave, or create
854      *  the bridge.  Nor can he be resurrected if he dies.  Note
855      *  that the snake is already gone, since he got to the
856      *  treasure accessible only via the hall of the mountain
857      *  king. Also, he's been in giant room (to get eggs), so we
858      *  can refer to it.  Also also, he's gotten the pearl, so we
859      *  know the bivalve is an oyster.  *And*, the dwarves must
860      *  have been activated, since we've found chest. */
861     if (game.clock1 == 0) {
862         game.prop[GRATE] = GRATE_CLOSED;
863         game.prop[FISSURE] = UNBRIDGED;
864         for (int i = 1; i <= NDWARVES; i++) {
865             game.dseen[i] = false;
866             game.dloc[i] = LOC_NOWHERE;
867         }
868         move(TROLL, LOC_NOWHERE);
869         move(TROLL + NOBJECTS, IS_FREE);
870         move(TROLL2, objects[TROLL].plac);
871         move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
872         juggle(CHASM);
873         if (game.prop[BEAR] != BEAR_DEAD)
874             DESTROY(BEAR);
875         game.prop[CHAIN] = CHAIN_HEAP;
876         game.fixed[CHAIN] = IS_FREE;
877         game.prop[AXE] = AXE_HERE;
878         game.fixed[AXE] = IS_FREE;
879         rspeak(CAVE_CLOSING);
880         game.clock1 = -1;
881         game.closng = true;
882         return game.closed;
883     } else if (game.clock1 < 0)
884         --game.clock2;
885     if (game.clock2 == 0) {
886         /*  Once he's panicked, and clock2 has run out, we come here
887          *  to set up the storage room.  The room has two locs,
888          *  hardwired as LOC_NE and LOC_SW.  At the ne end, we
889          *  place empty bottles, a nursery of plants, a bed of
890          *  oysters, a pile of lamps, rods with stars, sleeping
891          *  dwarves, and him.  At the sw end we place grate over
892          *  treasures, snake pit, covey of caged birds, more rods, and
893          *  pillows.  A mirror stretches across one wall.  Many of the
894          *  objects come from known locations and/or states (e.g. the
895          *  snake is known to have been destroyed and needn't be
896          *  carried away from its old "place"), making the various
897          *  objects be handled differently.  We also drop all other
898          *  objects he might be carrying (lest he have some which
899          *  could cause trouble, such as the keys).  We describe the
900          *  flash of light and trundle back. */
901         game.prop[BOTTLE] = put(BOTTLE, LOC_NE, EMPTY_BOTTLE);
902         game.prop[PLANT] = put(PLANT, LOC_NE, PLANT_THIRSTY);
903         game.prop[OYSTER] = put(OYSTER, LOC_NE, STATE_FOUND);
904         game.prop[LAMP] = put(LAMP, LOC_NE, LAMP_DARK);
905         game.prop[ROD] = put(ROD, LOC_NE, STATE_FOUND);
906         game.prop[DWARF] = put(DWARF, LOC_NE, 0);
907         game.loc = LOC_NE;
908         game.oldloc = LOC_NE;
909         game.newloc = LOC_NE;
910         /*  Leave the grate with normal (non-negative) property.
911          *  Reuse sign. */
912         put(GRATE, LOC_SW, 0);
913         put(SIGN, LOC_SW, 0);
914         game.prop[SIGN] = ENDGAME_SIGN;
915         game.prop[SNAKE] = put(SNAKE, LOC_SW, SNAKE_CHASED);
916         game.prop[BIRD] = put(BIRD, LOC_SW, BIRD_CAGED);
917         game.prop[CAGE] = put(CAGE, LOC_SW, STATE_FOUND);
918         game.prop[ROD2] = put(ROD2, LOC_SW, STATE_FOUND);
919         game.prop[PILLOW] = put(PILLOW, LOC_SW, STATE_FOUND);
920
921         game.prop[MIRROR] = put(MIRROR, LOC_NE, STATE_FOUND);
922         game.fixed[MIRROR] = LOC_SW;
923
924         for (int i = 1; i <= NOBJECTS; i++) {
925             if (TOTING(i))
926                 DESTROY(i);
927         }
928
929         rspeak(CAVE_CLOSED);
930         game.closed = true;
931         return game.closed;
932     }
933
934     lampcheck();
935     return false;
936 }
937
938 static void listobjects(void)
939 /*  Print out descriptions of objects at this location.  If
940  *  not closing and property value is negative, tally off
941  *  another treasure.  Rug is special case; once seen, its
942  *  game.prop is RUG_DRAGON (dragon on it) till dragon is killed.
943  *  Similarly for chain; game.prop is initially CHAINING_BEAR (locked to
944  *  bear).  These hacks are because game.prop=0 is needed to
945  *  get full score. */
946 {
947     if (!DARK(game.loc)) {
948         ++game.abbrev[game.loc];
949         for (int i = game.atloc[game.loc]; i != 0; i = game.link[i]) {
950             obj_t obj = i;
951             if (obj > NOBJECTS)
952                 obj = obj - NOBJECTS;
953             if (obj == STEPS && TOTING(NUGGET))
954                 continue;
955             if (game.prop[obj] < 0) {
956                 if (game.closed)
957                     continue;
958                 game.prop[obj] = STATE_FOUND;
959                 if (obj == RUG)
960                     game.prop[RUG] = RUG_DRAGON;
961                 if (obj == CHAIN)
962                     game.prop[CHAIN] = CHAINING_BEAR;
963                 --game.tally;
964                 /*  Note: There used to be a test here to see whether the
965                  *  player had blown it so badly that he could never ever see
966                  *  the remaining treasures, and if so the lamp was zapped to
967                  *  35 turns.  But the tests were too simple-minded; things
968                  *  like killing the bird before the snake was gone (can never
969                  *  see jewelry), and doing it "right" was hopeless.  E.G.,
970                  *  could cross troll bridge several times, using up all
971                  *  available treasures, breaking vase, using coins to buy
972                  *  batteries, etc., and eventually never be able to get
973                  *  across again.  If bottle were left on far side, could then
974                  *  never get eggs or trident, and the effects propagate.  So
975                  *  the whole thing was flushed.  anyone who makes such a
976                  *  gross blunder isn't likely to find everything else anyway
977                  *  (so goes the rationalisation). */
978             }
979             int kk = game.prop[obj];
980             if (obj == STEPS)
981                 kk = (game.loc == game.fixed[STEPS])
982                      ? STEPS_UP
983                      : STEPS_DOWN;
984             pspeak(obj, look, true, kk);
985         }
986     }
987 }
988
989 bool preprocess_command(command_t *command) 
990 /* Pre-processes a command input to see if we need to tease out a few specific cases:
991  * - "enter water" or "enter stream": 
992  *   wierd specific case that gets the user wet, and then kicks us back to get another command
993  * - <object> <verb>:
994  *   Irregular form of input, but should be allowed. We switch back to <verb> <object> form for 
995  *   furtherprocessing.
996  * - "grate":
997  *   If in location with grate, we move to that grate. If we're in a number of other places, 
998  *   we move to the entrance.
999  * - "water plant", "oil plant", "water door", "oil door":
1000  *   Change to "pour water" or "pour oil" based on context
1001  * - "cage bird":
1002  *   If bird is present, we change to "carry bird"
1003  *
1004  * Returns true if pre-processing is complete, and we're ready to move to the primary command 
1005  * processing, false otherwise. */
1006 {
1007     if (command->word[0].type == MOTION && command->word[0].id == ENTER
1008         && (command->word[1].id == STREAM || command->word[1].id == WATER)) {
1009         if (LIQLOC(game.loc) == WATER)
1010             rspeak(FEET_WET);
1011         else
1012             rspeak(WHERE_QUERY);
1013     } else {
1014         if (command->word[0].type == OBJECT) {
1015             /* From OV to VO form */
1016             if (command->word[1].type == ACTION) {
1017                 command_word_t stage = command->word[0];
1018                 command->word[0] = command->word[1];
1019                 command->word[1] = stage;
1020             }
1021
1022             if (command->word[0].id == GRATE) {
1023                 command->word[0].type = MOTION;
1024                 if (game.loc == LOC_START ||
1025                     game.loc == LOC_VALLEY ||
1026                     game.loc == LOC_SLIT) {
1027                     command->word[0].id = DEPRESSION;
1028                 }
1029                 if (game.loc == LOC_COBBLE ||
1030                     game.loc == LOC_DEBRIS ||
1031                     game.loc == LOC_AWKWARD ||
1032                     game.loc == LOC_BIRD ||
1033                     game.loc == LOC_PITTOP) {
1034                     command->word[0].id = ENTRANCE;
1035                 }
1036             }
1037             if ((command->word[0].id == WATER || command->word[0].id == OIL) && 
1038                 (command->word[1].id == PLANT || command->word[1].id == DOOR)) {
1039                 if (AT(command->word[1].id)) {
1040                     command->word[1] = command->word[0];
1041                     command->word[0].id = POUR;
1042                     command->word[0].type = ACTION;
1043                     strncpy(command->word[0].raw, "pour", LINESIZE - 1);
1044                 }
1045             }
1046             if (command->word[0].id == CAGE && command->word[1].id == BIRD && HERE(CAGE) && HERE(BIRD)) {
1047                 command->word[0].id = CARRY;
1048                 command->word[0].type = ACTION;
1049             }
1050         }
1051
1052         /* If no word type is given for the first word, we assume it's a motion. */
1053         if(command->word[0].type == NO_WORD_TYPE) 
1054             command->word[0].type = MOTION;
1055         
1056         command->state = PREPROCESSED;
1057         return true;
1058     }
1059     return false;
1060 }
1061
1062 static bool do_move(void) 
1063 /* Actually execute the move to the new location and dwarf movement */
1064 {
1065     /*  Can't leave cave once it's closing (except by main office). */
1066     if (OUTSID(game.newloc) && game.newloc != 0 && game.closng) {
1067         rspeak(EXIT_CLOSED);
1068         game.newloc = game.loc;
1069         if (!game.panic)
1070             game.clock2 = PANICTIME;
1071         game.panic = true;
1072     }
1073
1074     /*  See if a dwarf has seen him and has come from where he
1075      *  wants to go.  If so, the dwarf's blocking his way.  If
1076      *  coming from place forbidden to pirate (dwarves rooted in
1077      *  place) let him get out (and attacked). */
1078     if (game.newloc != game.loc && !FORCED(game.loc) && !CNDBIT(game.loc, COND_NOARRR)) {
1079         for (size_t i = 1; i <= NDWARVES - 1; i++) {
1080             if (game.odloc[i] == game.newloc && game.dseen[i]) {
1081                 game.newloc = game.loc;
1082                 rspeak(DWARF_BLOCK);
1083                 break;
1084             }
1085         }
1086     }
1087     game.loc = game.newloc;
1088
1089     if (!dwarfmove())
1090         croak();
1091
1092     if (game.loc == LOC_NOWHERE)
1093         croak();
1094
1095     /* The easiest way to get killed is to fall into a pit in
1096      * pitch darkness. */
1097     if (!FORCED(game.loc) && DARK(game.loc) && game.wzdark && PCT(35)) { // FIXME: magic number
1098         rspeak(PIT_FALL);
1099         game.oldlc2 = game.loc;
1100         croak();
1101         return false;
1102     }
1103
1104     return true;
1105 }
1106
1107 static bool do_command()
1108 /* Get and execute a command */
1109 {
1110     static command_t command;
1111     clear_command(&command);
1112
1113     /* Describe the current location and (maybe) get next command. */
1114     while (command.state != EXECUTED) {
1115         describe_location();
1116
1117         if (FORCED(game.loc)) {
1118             playermove(HERE);
1119             return true;
1120         }
1121
1122         listobjects();
1123
1124         /* Command not yet given; keep getting commands from user  
1125          * until valid command is both given and executed. */
1126         clear_command(&command);
1127         while (command.state <= GIVEN) {
1128
1129             if (game.closed) {
1130             /*  If closing time, check for any objects being toted with
1131              *  game.prop < 0 and stash them.  This way objects won't be
1132              *  described until they've been picked up and put down
1133              *  separate from their respective piles. */
1134                 if (game.prop[OYSTER] < 0 && TOTING(OYSTER))
1135                     pspeak(OYSTER, look, true, 1);
1136                 for (size_t i = 1; i <= NOBJECTS; i++) {
1137                     if (TOTING(i) && game.prop[i] < 0)
1138                         game.prop[i] = STASHED(i);
1139                 }
1140             }
1141
1142             /* Check to see if the room is dark. If the knife is here, 
1143              * and it's dark, the knife permanently disappears */
1144             game.wzdark = DARK(game.loc);
1145             if (game.knfloc != LOC_NOWHERE && game.knfloc != game.loc)
1146                 game.knfloc = LOC_NOWHERE;
1147
1148             /* Check some for hints, get input from user, increment
1149              * turn, and pre-process commands. Keep going until
1150              * pre-processing is done. */
1151             while ( command.state < PREPROCESSED ) {
1152                 checkhints();
1153
1154                 /* Get command input from user */
1155                 if (!get_command_input(&command))
1156                     return false;
1157
1158                 ++game.turns;
1159                 preprocess_command(&command);
1160             }
1161
1162             /* check if game is closed, and exit if it is */
1163             if (closecheck() ) 
1164                 return true;
1165
1166             /* loop until all words in command are procesed */
1167             while (command.state == PREPROCESSED ) {
1168                 command.state = PROCESSING;
1169
1170                 if (command.word[0].id == WORD_NOT_FOUND) {
1171                     /* Gee, I don't understand. */
1172                     sspeak(DONT_KNOW, command.word[0].raw);
1173                     clear_command(&command);
1174                     continue;
1175                 }
1176
1177                 /* Give user hints of shortcuts */
1178                 if (strncasecmp(command.word[0].raw, "west", sizeof("west")) == 0) {
1179                     if (++game.iwest == 10)
1180                         rspeak(W_IS_WEST);
1181                 }
1182                 if (strncasecmp(command.word[0].raw, "go", sizeof("go")) == 0 && command.word[1].id != WORD_EMPTY) {
1183                     if (++game.igo == 10)
1184                         rspeak(GO_UNNEEDED);
1185                 }
1186
1187                 switch (command.word[0].type) {
1188                 case MOTION:
1189                     playermove(command.word[0].id);
1190                     command.state = EXECUTED;
1191                     continue;
1192                 case OBJECT:
1193                     command.part = unknown;
1194                     command.obj = command.word[0].id;
1195                     break;
1196                 case ACTION:
1197                     if (command.word[1].type == NUMERIC)
1198                         command.part = transitive;
1199                     else
1200                         command.part = intransitive;
1201                     command.verb = command.word[0].id;
1202                     break;
1203                 case NUMERIC:
1204                     if (!settings.oldstyle) {
1205                         sspeak(DONT_KNOW, command.word[0].raw);
1206                         clear_command(&command);
1207                         continue;
1208                     }
1209                     break;
1210                 default: // LCOV_EXCL_LINE
1211                     BUG(VOCABULARY_TYPE_N_OVER_1000_NOT_BETWEEN_0_AND_3); // LCOV_EXCL_LINE
1212                 }
1213
1214                 switch (action(command)) {
1215                 case GO_TERMINATE:
1216                     command.state = EXECUTED;
1217                     break;
1218                 case GO_MOVE:
1219                     playermove(NUL);
1220                     command.state = EXECUTED;
1221                     break;
1222                 case GO_WORD2:
1223 #ifdef GDEBUG
1224                     printf("Word shift\n");
1225 #endif /* GDEBUG */
1226                     /* Get second word for analysis. */
1227                     command.word[0] = command.word[1];
1228                     command.word[1] = empty_command_word;
1229                     command.state = PREPROCESSED;
1230                     break;
1231                 case GO_UNKNOWN:
1232                     /*  Random intransitive verbs come here.  Clear obj just in case
1233                      *  (see attack()). */
1234                     command.word[0].raw[0] = toupper(command.word[0].raw[0]);
1235                     sspeak(DO_WHAT, command.word[0].raw);
1236                     command.obj = NO_OBJECT;
1237
1238                     /* object cleared; we need to go back to the preprocessing step */
1239                     command.state = GIVEN;
1240                     break;
1241                 case GO_CHECKHINT: // FIXME: re-name to be more contextual; this was previously a label
1242                     command.state = GIVEN;
1243                     break;
1244                 case GO_DWARFWAKE:
1245                     /*  Oh dear, he's disturbed the dwarves. */
1246                     rspeak(DWARVES_AWAKEN);
1247                     terminate(endgame);
1248                 case GO_CLEAROBJ: // FIXME: re-name to be more contextual; this was previously a label
1249                     clear_command(&command);
1250                     break;
1251                 case GO_TOP: // FIXME: re-name to be more contextual; this was previously a label
1252                     break;
1253                 default: // LCOV_EXCL_LINE
1254                     BUG(ACTION_RETURNED_PHASE_CODE_BEYOND_END_OF_SWITCH); // LCOV_EXCL_LINE
1255                 }
1256             } /* while command has nob been fully processed */
1257         } /* while command is not yet given */
1258     } /* while command is not executed */
1259
1260     /* command completely executed; we return true. */
1261     return true;
1262 }
1263
1264 /* end */