Removed equivocation between ROD and ROD2 in throw()
[open-adventure.git] / actions.c
index 07c55e07e95d28867344ec0eac4fa369bf4b681c..abe9e5bb38ef2eac3a9b3e481bbbf1445c648874 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -7,6 +7,7 @@
 static int fill(token_t, token_t);
 
 static void state_change(long obj, long state)
+/* Object must have a change-message list for this to be useful; only some do */
 {
     game.prop[obj] = state;
     pspeak(obj, change, state, true);
@@ -281,7 +282,6 @@ static int vcarry(token_t verb, token_t obj)
  *  take one without the other).  Liquids also special, since they depend on
  *  status of bottle.  Also various side effects, etc. */
 {
-    int spk;
     if (obj == INTRANSITIVE) {
         /*  Carry, no object given yet.  OK if only one object present. */
         if (game.atloc[game.loc] == 0 ||
@@ -295,82 +295,99 @@ static int vcarry(token_t verb, token_t obj)
         rspeak(ALREADY_CARRYING);
         return GO_CLEAROBJ;
     }
-    spk = YOU_JOKING;
-    if (obj == PLANT && game.prop[PLANT] <= 0)
-        spk = DEEP_ROOTS;
-    if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR)
-        spk = BEAR_CHAINED;
-    if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR)
-        spk = STILL_LOCKED;
-    if (obj == URN)
-        spk = URN_NOBUDGE;
-    if (obj == CAVITY)
-        spk = DOUGHNUT_HOLES;
-    if (obj == BLOOD)
-        spk = FEW_DROPS;
-    if (obj == RUG && game.prop[RUG] == RUG_HOVER)
-        spk = RUG_HOVERS;
-    if (obj == SIGN)
-        spk = HAND_PASSTHROUGH;
+
     if (obj == MESSAG) {
         rspeak(REMOVE_MESSAGE);
         DESTROY(MESSAG);
         return GO_CLEAROBJ;
     }
+
     if (game.fixed[obj] != 0) {
-        rspeak(spk);
+        if (obj == PLANT && game.prop[PLANT] <= 0) {
+            rspeak(DEEP_ROOTS);
+            return GO_CLEAROBJ;
+        }
+        if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR) {
+            rspeak(BEAR_CHAINED);
+            return GO_CLEAROBJ;
+        }
+        if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR) {
+            rspeak(STILL_LOCKED);
+            return GO_CLEAROBJ;
+        }
+        if (obj == URN) {
+            rspeak(URN_NOBUDGE);
+            return GO_CLEAROBJ;
+        }
+        if (obj == CAVITY) {
+            rspeak(DOUGHNUT_HOLES);
+            return GO_CLEAROBJ;
+        }
+        if (obj == BLOOD) {
+            rspeak(FEW_DROPS);
+            return GO_CLEAROBJ;
+        }
+        if (obj == RUG && game.prop[RUG] == RUG_HOVER) {
+            rspeak(RUG_HOVERS);
+            return GO_CLEAROBJ;
+        }
+        if (obj == SIGN) {
+            rspeak(HAND_PASSTHROUGH);
+            return GO_CLEAROBJ;
+        }
+        rspeak(YOU_JOKING);
         return GO_CLEAROBJ;
     }
+
     if (obj == WATER ||
         obj == OIL) {
         if (!HERE(BOTTLE) ||
             LIQUID() != obj) {
-            if (TOTING(BOTTLE) && game.prop[BOTTLE] == EMPTY_BOTTLE)
-                return (fill(verb, BOTTLE));
-            else {
-                if (game.prop[BOTTLE] != EMPTY_BOTTLE)
-                    spk = BOTTLE_FULL;
-                if (!TOTING(BOTTLE))
-                    spk = NO_CONTAINER;
-                rspeak(spk);
+            if (TOTING(BOTTLE)) {
+                if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
+                    return (fill(verb, BOTTLE));
+                } else if (game.prop[BOTTLE] != EMPTY_BOTTLE)
+                    rspeak(BOTTLE_FULL);
                 return GO_CLEAROBJ;
             }
+            rspeak(NO_CONTAINER);
+            return GO_CLEAROBJ;
         }
         obj = BOTTLE;
     }
 
-    spk = CARRY_LIMIT;
     if (game.holdng >= INVLIMIT) {
-        rspeak(spk);
+        rspeak(CARRY_LIMIT);
         return GO_CLEAROBJ;
-    } else if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && -1 - game.prop[BIRD] != BIRD_CAGED) {
+
+    }
+
+    if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
         if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
             DESTROY(BIRD);
             rspeak(BIRD_CRAP);
             return GO_CLEAROBJ;
         }
-        if (!TOTING(CAGE))
-            spk = CANNOT_CARRY;
-        if (TOTING(ROD))
-            spk = BIRD_EVADES;
-        if (spk == CANNOT_CARRY ||
-            spk == BIRD_EVADES) {
-            rspeak(spk);
+        if (!TOTING(CAGE)) {
+            rspeak(CANNOT_CARRY);
+            return GO_CLEAROBJ;
+        }
+        if (TOTING(ROD)) {
+            rspeak(BIRD_EVADES);
             return GO_CLEAROBJ;
         }
         game.prop[BIRD] = BIRD_CAGED;
     }
-    /* FIXME: Arithmetic on state numbers */
     if ((obj == BIRD ||
          obj == CAGE) &&
-        (game.prop[BIRD] == BIRD_CAGED ||
-         -1 - game.prop[BIRD] == 1))
+        (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED))
+       /* expression maps BIRD to CAGE and CAGE to BIRD */
         carry(BIRD + CAGE - obj, game.loc);
     carry(obj, game.loc);
-    if (obj == BOTTLE && LIQUID() != 0)
+    if (obj == BOTTLE && LIQUID() != NO_OBJECT)
         game.place[LIQUID()] = CARRIED;
-    if (GSTONE(obj) && game.prop[obj] != 0) {
-        game.prop[obj] = STATE_GROUND;
+    if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
+        game.prop[obj] = STATE_FOUND;
         game.prop[CAVITY] = CAVITY_EMPTY;
     }
     rspeak(OK_MAN);
@@ -429,12 +446,11 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
  *  bird (might attack snake or dragon) and cage (might contain bird) and vase.
  *  Drop coins at vending machine for extra batteries. */
 {
-    int spk = actions[verb].message;
     if (!just_do_it) {
         if (TOTING(ROD2) && obj == ROD && !TOTING(ROD))
             obj = ROD2;
         if (!TOTING(obj)) {
-            rspeak(spk);
+            rspeak(actions[verb].message);
             return GO_CLEAROBJ;
         }
         if (obj == BIRD && HERE(SNAKE)) {
@@ -447,11 +463,11 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
 
         } else if ((GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL)) {
             rspeak(GEM_FITS);
-            game.prop[obj] = 1;
+            game.prop[obj] = STATE_IN_CAVITY;
             game.prop[CAVITY] = CAVITY_FULL;
             if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
                               (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
-                spk = RUG_RISES;
+                int spk = RUG_RISES;
                 if (TOTING(RUG))
                     spk = RUG_WIGGLES;
                 if (obj == RUBY)
@@ -497,7 +513,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)
+    if (obj == BOTTLE && k != NO_OBJECT)
         game.place[k] = LOC_NOWHERE;
     if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED)
         drop(BIRD, game.loc);
@@ -646,7 +662,7 @@ static int feed(token_t verb, token_t obj)
             DESTROY(FOOD);
             game.prop[BEAR] = SITTING_BEAR;
             game.fixed[AXE] = 0;
-            game.prop[AXE] = 0;
+            game.prop[AXE] = AXE_HERE;
             spk = BEAR_TAMED;
         }
     } else if (obj == OGRE) {
@@ -675,7 +691,7 @@ int fill(token_t verb, token_t obj)
         rspeak(SHATTER_VASE);
         game.prop[VASE] = VASE_BROKEN;
         game.fixed[VASE] = -1;
-        return (discard(verb, obj, true));
+        return (discard(verb, VASE, true));
     }
 
     if (obj == URN) {
@@ -1094,7 +1110,6 @@ static int say(struct command_t *command)
     char word1[TOKLEN + 1];
     packed_to_token(command->wd1, word1);
     int wd = (int) get_vocab_id(word1);
-    /* FIXME: magic numbers */
     if (wd == MOTION_WORD(XYZZY) ||
         wd == MOTION_WORD(PLUGH) ||
         wd == MOTION_WORD(PLOVER) ||
@@ -1121,8 +1136,6 @@ static int throw (struct command_t *command)
  *  (Only way to do so!)  Axe also special for dragon, bear, and
  *  troll.  Treasures special for troll. */
 {
-    if (TOTING(ROD2) && command->obj == ROD && !TOTING(ROD))
-        command->obj = ROD2;
     if (!TOTING(command->obj)) {
         rspeak(actions[command->verb].message);
         return GO_CLEAROBJ;
@@ -1208,7 +1221,7 @@ static int wave(token_t verb, token_t obj)
 
     if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] < 0) {
         drop(JADE, game.loc);
-        game.prop[JADE] = 0;
+        game.prop[JADE] = STATE_FOUND;
         --game.tally;
         rspeak(NECKLACE_FLY);
         return GO_CLEAROBJ;