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