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