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