Apply loc_t type.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 371b3b67d7a1af9ae14e018f1d372f00927e7d2f..e3e6a96dc29f3e4ea87a5f0636972cf2887cddb7 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
- * Copyright (c) 2017 by Eric S. Raymond
- * SPDX-License-Identifier: BSD-2-clause
+ * SPDX-FileCopyrightText: 1977, 2005 by Will Crowther and Don Woods
+ * SPDX-FileCopyrightText: 2017 by Eric S. Raymond
+ * SPDX-License-Identifier: BSD-2-Clause
  */
 
 #include <stdlib.h>
@@ -24,7 +24,7 @@ void autosave(void)
 {
     if (autosave_fp != NULL) {
         rewind(autosave_fp);
-        savefile(autosave_fp, /* version (auto): */0);
+        savefile(autosave_fp);
         fflush(autosave_fp);
     }
 }
@@ -55,8 +55,13 @@ char *myreadline(const char *prompt)
      * logfiles for testing purposes.
      */
     /* Normal case - no script arguments */
-    if (settings.argc == 0)
-        return readline(prompt);
+    if (settings.argc == 0) {
+       char *ln = readline(prompt);
+       if (ln == NULL) {
+           fputs(prompt, stdout);
+       }
+        return ln;
+    }
 
     char *buf = malloc(LINESIZE + 1);
     for (;;) {
@@ -82,9 +87,9 @@ char *myreadline(const char *prompt)
         } else {
             char *ln = fgets(buf, LINESIZE, settings.scriptfp);
             if (ln != NULL) {
-                fputs(PROMPT, stdout);
+               fputs(prompt, stdout);
                 fputs(ln, stdout);
-                return ln;
+               return ln;
             }
         }
     }
@@ -194,8 +199,7 @@ static bool spotted_by_pirate(int i)
      *  that game.place[CHEST] = LOC_NOWHERE might mean that he's thrown
      *  it to the troll, but in that case he's seen the chest
      *  (game.prop[CHEST] == STATE_FOUND). */
-    if (game.loc == game.chloc ||
-        game.prop[CHEST] != STATE_NOTFOUND)
+    if (game.loc == game.chloc || game.prop[CHEST] != STATE_NOTFOUND)
         return true;
     int snarfed = 0;
     bool movechest = false, robplayer = false;
@@ -208,8 +212,7 @@ static bool spotted_by_pirate(int i)
                                     game.loc == objects[EMERALD].plac)) {
             continue;
         }
-        if (TOTING(treasure) ||
-            HERE(treasure))
+        if (TOTING(treasure) || HERE(treasure))
             ++snarfed;
         if (TOTING(treasure)) {
             movechest = true;
@@ -271,9 +274,7 @@ static bool dwarfmove(void)
      *  steal return toll, and dwarves can't meet the bear.  Also
      *  means dwarves won't follow him into dead end in maze, but
      *  c'est la vie.  They'll wait for him outside the dead end. */
-    if (game.loc == LOC_NOWHERE ||
-        FORCED(game.loc) ||
-        CNDBIT(game.newloc, COND_NOARRR))
+    if (game.loc == LOC_NOWHERE || FORCED(game.loc) || CNDBIT(game.newloc, COND_NOARRR))
         return true;
 
     /* Dwarf activity level ratchets up */
@@ -288,8 +289,7 @@ static bool dwarfmove(void)
      *  replace him with the alternate. */
     if (game.dflag == 1) {
         if (!INDEEP(game.loc) ||
-            (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) ||
-                         PCT(85))))
+            (PCT(95) && (!CNDBIT(game.loc, COND_NOBACK) || PCT(85))))
             return true;
         game.dflag = 2;
         for (int i = 1; i <= 2; i++) {
@@ -370,7 +370,7 @@ static bool dwarfmove(void)
         ++game.dtotal;
         if (game.odloc[i] == game.dloc[i]) {
             ++attack;
-            if (game.knfloc >= 0)
+            if (game.knfloc >= LOC_NOWHERE)
                 game.knfloc = game.loc;
             if (randrange(1000) < 95 * (game.dflag - 2))
                 ++stick;
@@ -458,8 +458,7 @@ static void describe_location(void)
 {
     const char* msg = locations[game.loc].description.small;
 
-    if (MOD(game.abbrev[game.loc], game.abbnum) == 0 ||
-        msg == NO_MESSAGE)
+    if (MOD(game.abbrev[game.loc], game.abbnum) == 0 || msg == NO_MESSAGE)
         msg = locations[game.loc].description.big;
 
     if (!FORCED(game.loc) && DARK(game.loc)) {
@@ -567,8 +566,7 @@ static void playermove(int motion)
     /* Look for a way to fulfil the motion verb passed in - travel_entry indexes
      * the beginning of the motion entries for here (game.loc). */
     for (;;) {
-        if ((travel[travel_entry].motion == HERE) ||
-            travel[travel_entry].motion == motion)
+        if ((travel[travel_entry].motion == HERE) || travel[travel_entry].motion == motion)
             break;
         if (travel[travel_entry].stop) {
             /*  Couldn't find an entry matching the motion word passed
@@ -622,14 +620,12 @@ static void playermove(int motion)
                 if (condtype < cond_not) {
                     /* YAML N and [pct N] conditionals */
                     if (condtype == cond_goto || condtype == cond_pct) {
-                        if (condarg1 == 0 ||
-                            PCT(condarg1))
+                        if (condarg1 == 0 || PCT(condarg1))
                             break;
                         /* else fall through */
                     }
                     /* YAML [with OBJ] clause */
-                    else if (TOTING(condarg1) ||
-                             (condtype == cond_with && AT(condarg1)))
+                    else if (TOTING(condarg1) || (condtype == cond_with && AT(condarg1)))
                         break;
                     /* else fall through to check [not OBJ STATE] */
                 } else if (game.prop[condarg1] != condarg2)
@@ -668,8 +664,7 @@ static void playermove(int motion)
                     game.newloc = (game.loc == LOC_PLOVER)
                                   ? LOC_ALCOVE
                                   : LOC_PLOVER;
-                    if (game.holdng > 1 ||
-                        (game.holdng == 1 && !TOTING(EMERALD))) {
+                    if (game.holdng > 1 || (game.holdng == 1 && !TOTING(EMERALD))) {
                         game.newloc = game.loc;
                         rspeak(MUST_DROP);
                     }
@@ -930,6 +925,8 @@ static void listobjects(void)
                     game.prop[RUG] = RUG_DRAGON;
                 if (obj == CHAIN)
                     game.prop[CHAIN] = CHAINING_BEAR;
+               if (obj == EGGS)
+                   game.seenbigwords = true;
                 --game.tally;
                 /*  Note: There used to be a test here to see whether the
                  *  player had blown it so badly that he could never ever see
@@ -1064,7 +1061,7 @@ static bool do_move(void)
 
     /* The easiest way to get killed is to fall into a pit in
      * pitch darkness. */
-    if (!FORCED(game.loc) && DARK(game.loc) && game.wzdark && PCT(35)) { // FIXME: magic number
+    if (!FORCED(game.loc) && DARK(game.loc) && game.wzdark && PCT(PIT_KILL_PROB)) {
         rspeak(PIT_FALL);
         game.oldlc2 = game.loc;
         croak();
@@ -1074,7 +1071,7 @@ static bool do_move(void)
     return true;
 }
 
-static bool do_command()
+static bool do_command(void)
 /* Get and execute a command */
 {
     static command_t command;
@@ -1256,20 +1253,23 @@ int main(int argc, char *argv[])
     /*  Options. */
 
 #if defined ADVENT_AUTOSAVE
-    const char* opts = "l:oa:";
+    const char* opts = "dl:oa:";
     const char* usage = "Usage: %s [-l logfilename] [-o] [-a filename] [script...]\n";
     FILE *rfp = NULL;
     const char* autosave_filename = NULL;
 #elif !defined ADVENT_NOSAVE
-    const char* opts = "l:or:";
+    const char* opts = "dl:or:";
     const char* usage = "Usage: %s [-l logfilename] [-o] [-r restorefilename] [script...]\n";
     FILE *rfp = NULL;
 #else
-    const char* opts = "l:o";
+    const char* opts = "dl:o";
     const char* usage = "Usage: %s [-l logfilename] [-o] [script...]\n";
 #endif
     while ((ch = getopt(argc, argv, opts)) != EOF) {
         switch (ch) {
+       case 'd': // LCOV_EXCL_LINE
+           settings.debug +=1; // LCOV_EXCL_LINE
+           break; // LCOV_EXCL_LINE
         case 'l':
             settings.logfp = fopen(optarg, "w");
             if (settings.logfp == NULL)