Working but unpolished refactor of bigwords().
authorJason S. Ninneman <jsn@mbar.us>
Wed, 5 Jul 2017 18:28:15 +0000 (11:28 -0700)
committerJason S. Ninneman <jsn@mbar.us>
Wed, 5 Jul 2017 21:02:52 +0000 (14:02 -0700)
actions.c
adventure.yaml
init.c
main.c

index 9c22f66cba2e654d7f829ef51cfc758a336fc61f..2b432f371470eb0645532951774149d7ce2d3925 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -178,46 +178,51 @@ static int attack(struct command_t *command)
     return GO_CLEAROBJ;
 }
 
-static int bigwords(token_t foo)
+static int bigwords(long id)
 /*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
  *  Look up foo in special section of vocab to determine which word we've got.
  *  Last word zips the eggs back to the giant room (unless already there). */
 {
-    char word[TOKLEN + 1];
-    packed_to_token(foo, word);
-    int k = (int) get_special_vocab_id(word);
-    if (game.foobar != 1 - k) {
-        if (game.foobar != 0 && game.loc == LOC_GIANTROOM) {
-            rspeak( START_OVER);
-        } else {
-            rspeak(NOTHING_HAPPENS);
-        }
-        return GO_CLEAROBJ;
-    } else {
-        game.foobar = k;
-        if (k != 4) {
-            rspeak(OK_MAN);
-            return GO_CLEAROBJ;
-        }
-        game.foobar = 0;
-        if (game.place[EGGS] == objects[EGGS].plac ||
-            (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
-            rspeak(NOTHING_HAPPENS);
-            return GO_CLEAROBJ;
-        } else {
-            /*  Bring back troll if we steal the eggs back from him before
-             *  crossing. */
-            if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
-                game.prop[TROLL] = TROLL_PAIDONCE;
-            k = EGGS_DONE;
-            if (HERE(EGGS))
-                k = EGGS_VANISHED;
-            if (game.loc == objects[EGGS].plac)
-                k = EGGS_HERE;
-            move(EGGS, objects[EGGS].plac);
-            pspeak(EGGS, look, k, true);
-            return GO_CLEAROBJ;
-        }
+  if ((game.foobar == WORD_EMPTY && id == ACTION_WORD(FEE)) ||
+      (game.foobar == ACTION_WORD(FEE) && id == ACTION_WORD(FIE)) ||
+      (game.foobar == ACTION_WORD(FIE) && id == ACTION_WORD(FOE)) ||
+      (game.foobar == ACTION_WORD(FOE) && id == ACTION_WORD(FOO)) ||
+      (game.foobar == ACTION_WORD(FOE) && id == ACTION_WORD(FUM)))
+    {
+      game.foobar = id;
+      if ((id != ACTION_WORD(FOO)) && (id != ACTION_WORD(FUM))) {
+       rspeak(OK_MAN);
+       return GO_CLEAROBJ;
+      }
+      game.foobar = WORD_EMPTY;
+      if (game.place[EGGS] == objects[EGGS].plac ||
+         (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
+       rspeak(NOTHING_HAPPENS);
+       return GO_CLEAROBJ;
+      } else {
+       /*  Bring back troll if we steal the eggs back from him before
+        *  crossing. */
+       if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
+         game.prop[TROLL] = TROLL_PAIDONCE;
+       int k = EGGS_DONE;
+       if (HERE(EGGS))
+         k = EGGS_VANISHED;
+       if (game.loc == objects[EGGS].plac)
+         k = EGGS_HERE;
+       move(EGGS, objects[EGGS].plac);
+       pspeak(EGGS, look, k, true);
+       return GO_CLEAROBJ;
+      }
+    }
+  else
+    {
+      if (game.loc == LOC_GIANTROOM) {
+       rspeak( START_OVER);
+      } else {
+       rspeak(NOTHING_HAPPENS);
+      }
+      game.foobar = WORD_EMPTY;
+      return GO_CLEAROBJ;
     }
 }
 
@@ -1115,7 +1120,11 @@ static int say(struct command_t *command)
     if (wd == MOTION_WORD(XYZZY) ||
         wd == MOTION_WORD(PLUGH) ||
         wd == MOTION_WORD(PLOVER) ||
-        wd == ACTION_WORD(GIANTWORDS) ||
+        wd == ACTION_WORD(FEE) ||
+       wd == ACTION_WORD(FIE) ||
+       wd == ACTION_WORD(FOE) ||
+       wd == ACTION_WORD(FOO) ||
+       wd == ACTION_WORD(FUM) ||
         wd == ACTION_WORD(PART)) {
         /* FIXME: scribbles on the interpreter's command block */
         wordclear(&command->wd2);
@@ -1376,8 +1385,12 @@ int action(struct command_t *command)
             case SCORE:
                 score(scoregame);
                 return GO_CLEAROBJ;
-            case GIANTWORDS:
-                return bigwords(command->wd1);
+           case FEE:
+           case FIE:
+           case FOE:
+           case FOO:
+            case FUM:
+                return bigwords(command->id1);
             case BRIEF:
                 return brief();
             case READ:
@@ -1464,7 +1477,11 @@ int action(struct command_t *command)
             rspeak(actions[command->verb].message);
             return GO_CLEAROBJ;
         }
-        case GIANTWORDS: {
+       case FEE:
+       case FIE:
+       case FOE:
+       case FOO:
+        case FUM: {
             rspeak(actions[command->verb].message);
             return GO_CLEAROBJ;
         }
index fe44ce879d62d82a7d55362cd0c0777597a9be8a..7f3d69be48f72e44281bcc5220baeec0e46d7fe7 100644 (file)
@@ -351,9 +351,21 @@ actions: !!omap
 - SCORE:
     message: HUH_MAN
     words: ['score']
-- GIANTWORDS:
+- FEE:
     message: NOT_KNOWHOW
-    words: ['fee', 'fie', 'foe', 'foo', 'fum']
+    words: ['fee']
+- FIE:
+    message: NOT_KNOWHOW
+    words: ['fie']
+- FOE:
+    message: NOT_KNOWHOW
+    words: ['foe']
+- FOO:
+    message: NOT_KNOWHOW
+    words: ['foo']
+- FUM:
+    message: NOT_KNOWHOW
+    words: ['fum']
 - BRIEF:
     message: ON_WHAT
     words: ['brief']
diff --git a/init.c b/init.c
index b3f984d049d2fe6867e6af49ba01546fa5d2cd09..be5c3fb271c0da846c96422c6c5e2f4ba6574894 100644 (file)
--- a/init.c
+++ b/init.c
@@ -36,6 +36,7 @@ struct game_t game = {
     .newloc  = LOC_START,
     .loc     = LOC_START,
     .limit   = GAMELIMIT,
+    .foobar  = WORD_EMPTY,
 
     /* Initialize our LCG PRNG with parameters tested against
      * Knuth vol. 2. by the original authors */
diff --git a/main.c b/main.c
index 59bb4e1fcf5126b76b0f2be2101843a8fd4f402a..a0c986a5251749fa31b498d475ca79df5552f3e5 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1065,11 +1065,7 @@ L2600:
         command.id1 = get_vocab_id(word1);
         command.id2 = get_vocab_id(word2);
 
-        /*  Every input, check "game.foobar" flag.  If zero, nothing's
-         *  going on.  If pos, make neg.  If neg, he skipped a word,
-         *  so make it zero. */
 L2607:
-        game.foobar = (game.foobar > 0 ? -game.foobar : 0);
         ++game.turns;
 
         /* If a turn threshold has been met, apply penalties and tell