Test coverage - failure to fill
[open-adventure.git] / actions.c
index 4798d7d77150238647b95d8f2ebc4a68b459a299..2a223bc9a9e40b42626530ee93d8820937d1d0db 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -5,16 +5,11 @@
 #include "newdb.h"
 
 /* Limit visibility of ugly globals.  Eventually these should go away. */
-extern long WD1, WD1X, WD2, WD2X;
+extern token_t WD1, WD1X, WD2, WD2X;
 
-/*
- * Action handlers.  Eventually we'll do lookup through a method table
- * that calls these.
- */
-
-static int fill(token_t verb, token_t);
+static int fill(token_t, token_t);
 
-static int attack(FILE *input, long verb, token_t obj)
+static int attack(FILE *input, token_t verb, token_t obj)
 /*  Attack.  Assume target if unambiguous.  "Throw" also links here.
  *  Attackable objects fall into two categories: enemies (snake,
  *  dwarf, etc.)  and others (bird, clam, machine).  Ambiguous if 2
@@ -87,7 +82,7 @@ static int attack(FILE *input, long verb, token_t obj)
          *  too.  Then do a null motion to get new description. */
         RSPEAK(BARE_HANDS_QUERY);
         GETIN(input, &WD1, &WD1X, &WD2, &WD2X);
-        if (WD1 != MAKEWD(25) && WD1 != MAKEWD(250519))
+        if (WD1 != MAKEWD(WORD_YINIT) && WD1 != MAKEWD(WORD_YES))
             return GO_CHECKFOO;
         PSPEAK(DRAGON, 3);
         game.prop[DRAGON] = 1;
@@ -110,7 +105,7 @@ static int attack(FILE *input, long verb, token_t obj)
     return GO_CLEAROBJ;
 }
 
-static int bigwords(long foo)
+static int bigwords(token_t foo)
 /*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
  *  Look up WD1 in section 3 of vocab to determine which word we've got.  Last
  *  word zips the eggs back to the giant room (unless already there). */
@@ -134,7 +129,7 @@ static int bigwords(long foo)
         } else {
             /*  Bring back troll if we steal the eggs back from him before
              *  crossing. */
-            if (game.place[EGGS] == 0 && game.place[TROLL] == 0 && game.prop[TROLL] == 0)
+            if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == 0)
                 game.prop[TROLL] = 1;
             k = 2;
             if (HERE(EGGS))k = 1;
@@ -389,7 +384,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
     int k = LIQUID();
     if (k == obj)obj = BOTTLE;
     if (obj == BOTTLE && k != 0)
-        game.place[k] = NOWHERE;
+        game.place[k] = LOC_NOWHERE;
     if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD, game.loc);
     DROP(obj, game.loc);
     if (obj != BIRD) return GO_CLEAROBJ;
@@ -409,7 +404,7 @@ static int drink(token_t verb, token_t obj)
         if (obj != 0 && obj != WATER)spk = RIDICULOUS_ATTEMPT;
         if (spk != RIDICULOUS_ATTEMPT && LIQUID() == WATER && HERE(BOTTLE)) {
             game.prop[BOTTLE] = 1;
-            game.place[WATER] = NOWHERE;
+            game.place[WATER] = LOC_NOWHERE;
             spk = BOTTLE_EMPTY;
         }
     } else {
@@ -539,7 +534,7 @@ int fill(token_t verb, token_t obj)
             RSPEAK(spk);
             return GO_CLEAROBJ;
         }
-        game.place[k] = NOWHERE;
+        game.place[k] = LOC_NOWHERE;
         game.prop[BOTTLE] = 1;
         if (k == OIL)game.prop[URN] = 1;
         spk = WATER_URN + game.prop[URN];
@@ -578,7 +573,7 @@ static int find(token_t verb, token_t obj)
         obj == LIQLOC(game.loc) ||
         (obj == DWARF && ATDWRF(game.loc) > 0))
         spk = YOU_HAVEIT;
-    if (game.closed)spk = NEEDED_NEreplace;
+    if (game.closed)spk = NEEDED_NEARBY;
     if (TOTING(obj))spk = ALREADY_CARRYING;
     RSPEAK(spk);
     return GO_CLEAROBJ;
@@ -764,7 +759,7 @@ static int pour(token_t verb, token_t obj)
     if (HERE(URN) && game.prop[URN] == 0)
         return fill(verb, URN);
     game.prop[BOTTLE] = 1;
-    game.place[obj] = NOWHERE;
+    game.place[obj] = LOC_NOWHERE;
     spk = GROUND_WET;
     if (!(AT(PLANT) || AT(DOOR))) {
         RSPEAK(spk);
@@ -800,7 +795,6 @@ static int quit(void)
 static int read(token_t verb, token_t obj)
 /*  Read.  Print stuff based on objtxt.  Oyster (?) is special case. */
 {
-    int spk = ACTSPK[verb];
     if (obj == INTRANSITIVE) {
         obj = 0;
         for (int i = 1; i <= NOBJECTS; i++) {
@@ -816,7 +810,7 @@ static int read(token_t verb, token_t obj)
         return GO_CLEAROBJ;
     }
     if (OBJTXT[obj] == 0 || game.prop[obj] < 0) {
-        RSPEAK(spk);
+        RSPEAK(ACTSPK[verb]);
         return GO_CLEAROBJ;
     }
     if (obj == OYSTER && !game.clshnt) {
@@ -922,32 +916,36 @@ static int throw (FILE *cmdin, long verb, token_t obj)
     }
     if (obj != AXE)
         return (discard(verb, obj, false));
-    int i = ATDWRF(game.loc);
-    if (i <= 0) {
-        if (AT(DRAGON) && game.prop[DRAGON] == 0)
-            return throw_support(DRAGON_SCALES);
-        if (AT(TROLL))
-            return throw_support(TROLL_RETURNS);
-        else if (AT(OGRE))
-            return throw_support(OGRE_DODGE);
-        else if (HERE(BEAR) && game.prop[BEAR] == 0) {
-            /* This'll teach him to throw the axe at the bear! */
-            DROP(AXE, game.loc);
-            game.fixed[AXE] = -1;
-            game.prop[AXE] = 1;
-            JUGGLE(BEAR);
-            RSPEAK(AXE_LOST);
-            return GO_CLEAROBJ;
+    else {
+        int i = ATDWRF(game.loc);
+        if (i <= 0) {
+            if (AT(DRAGON) && game.prop[DRAGON] == 0)
+                return throw_support(DRAGON_SCALES);
+            if (AT(TROLL))
+                return throw_support(TROLL_RETURNS);
+            else if (AT(OGRE))
+                return throw_support(OGRE_DODGE);
+            else if (HERE(BEAR) && game.prop[BEAR] == 0) {
+                /* This'll teach him to throw the axe at the bear! */
+                DROP(AXE, game.loc);
+                game.fixed[AXE] = -1;
+                game.prop[AXE] = 1;
+                JUGGLE(BEAR);
+                RSPEAK(AXE_LOST);
+                return GO_CLEAROBJ;
+            }
+            return (attack(cmdin, verb, 0));
         }
-        return (attack(cmdin, verb, 0));
-    }
 
-    if (randrange(NDWARVES + 1) < game.dflag) {
-        return throw_support(DWARF_DODGES);
+        if (randrange(NDWARVES + 1) < game.dflag) {
+            return throw_support(DWARF_DODGES);
+        } else {
+            game.dseen[i] = false;
+            game.dloc[i] = 0;
+            return throw_support((++game.dkill == 1)
+                                 ? DWARF_SMOKE : KILLED_DWARF);
+        }
     }
-    game.dseen[i] = false;
-    game.dloc[i] = 0;
-    return throw_support((++game.dkill == 1) ? DWARF_SMOKE : KILLED_DWARF);
 }
 
 static int wake(token_t verb, token_t obj)
@@ -997,7 +995,7 @@ static int wave(token_t verb, token_t obj)
     }
 }
 
-int action(FILE *input, enum speechpart part, long verb, token_t obj)
+int action(FILE *input, enum speechpart part, token_t verb, token_t obj)
 /*  Analyse a verb.  Remember what it was, go back for object if second word
  *  unless verb is "say", which snarfs arbitrary second word.
  */
@@ -1056,7 +1054,8 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
 
     switch (part) {
     case intransitive:
-        if (WD2 > 0 && verb != SAY) return (2800);
+        if (WD2 > 0 && verb != SAY)
+           return GO_WORD2;
         if (verb == SAY)obj = WD2;
         if (obj == 0 || obj == INTRANSITIVE) {
             /*  Analyse an intransitive verb (ie, no object given yet). */