Move a few prototypes and static'ed a few functions
[open-adventure.git] / actions.c
index 8b4f938aa694f2afe91e9c1c1ccb3b66838a4514..aa63f6c83bfe09eafe2c61704fcfb151fd999e45 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -38,7 +38,8 @@ static int attack(FILE *input, long verb, token_t obj)
            /* Clam and oyster both treated as clam for intransitive case;
             * no harm done. */
            if (HERE(CLAM) || HERE(OYSTER))obj=NOBJECTS*obj+CLAM;
-           if (obj > NOBJECTS) return GO_UNKNOWN;
+           if (obj > NOBJECTS)
+               return GO_UNKNOWN;
        }
     }
     if (obj == BIRD) {
@@ -48,11 +49,11 @@ static int attack(FILE *input, long verb, token_t obj)
            RSPEAK(spk);
            return GO_CLEAROBJ;
        }
-       DSTROY(BIRD);
+       DESTROY(BIRD);
        game.prop[BIRD]=0;
        spk=BIRD_DEAD;
     }
-    if (obj == VEND) {
+    else if (obj == VEND) {
        PSPEAK(VEND,game.prop[VEND]+2);
        game.prop[VEND]=3-game.prop[VEND];
        return GO_CLEAROBJ;
@@ -69,50 +70,48 @@ static int attack(FILE *input, long verb, token_t obj)
     if (obj == OGRE && d > 0) {
        RSPEAK(spk);
        RSPEAK(KNIFE_THROWN);
-       DSTROY(OGRE);
-       int k=0;
+       DESTROY(OGRE);
+       int dwarves=0;
        for (int i=1; i < PIRATE; i++) {
            if (game.dloc[i] == game.loc) {
-               ++k;
+               ++dwarves;
                game.dloc[i] = LOC_LONGWEST;
                game.dseen[i]=false;
            }
        }
-       spk=k == 2 ? OGRE_PANIC1 : OGRE_PANIC2;
-       RSPEAK(spk);
-       return GO_CLEAROBJ;
+       spk = (dwarves > 1) ? OGRE_PANIC1 : OGRE_PANIC2;
     }
-
-    if (obj == BEAR)
+    else if (obj == BEAR)
        /* FIXME: Arithmetic on message numbers */
        spk = BEAR_HANDS+(game.prop[BEAR]+1)/2;
-    if (obj != DRAGON || game.prop[DRAGON] != 0) {
-       RSPEAK(spk);
-       return GO_CLEAROBJ;
-    }
-    /*  Fun stuff for dragon.  If he insists on attacking it, win!
-     *  Set game.prop to dead, move dragon to central loc (still
-     *  fixed), move rug there (not fixed), and move him there,
-     *  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))
-       return GO_CHECKFOO;
-    PSPEAK(DRAGON,3);
-    game.prop[DRAGON]=1;
-    game.prop[RUG]=0;
-    int k=(PLAC[DRAGON]+FIXD[DRAGON])/2;
-    MOVE(DRAGON+NOBJECTS,-1);
-    MOVE(RUG+NOBJECTS,0);
-    MOVE(DRAGON,k);
-    MOVE(RUG,k);
-    DROP(BLOOD,k);
-    for (obj=1; obj<=NOBJECTS; obj++) {
-       if (game.place[obj] == PLAC[DRAGON] || game.place[obj] == FIXD[DRAGON])
-           MOVE(obj,k);
+    else if (obj == DRAGON && game.prop[DRAGON] == 0) {
+       /*  Fun stuff for dragon.  If he insists on attacking it, win!
+        *  Set game.prop to dead, move dragon to central loc (still
+        *  fixed), move rug there (not fixed), and move him there,
+        *  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))
+           return GO_CHECKFOO;
+       PSPEAK(DRAGON,3);
+       game.prop[DRAGON]=1;
+       game.prop[RUG]=0;
+       int k=(PLAC[DRAGON]+FIXD[DRAGON])/2;
+       MOVE(DRAGON+NOBJECTS,-1);
+       MOVE(RUG+NOBJECTS,0);
+       MOVE(DRAGON,k);
+       MOVE(RUG,k);
+       DROP(BLOOD,k);
+       for (obj=1; obj<=NOBJECTS; obj++) {
+           if (game.place[obj] == PLAC[DRAGON] || game.place[obj] == FIXD[DRAGON])
+               MOVE(obj,k);
+       }
+       game.loc=k;
+       return GO_MOVE;
     }
-    game.loc=k;
-    return GO_MOVE;
+
+    RSPEAK(spk);
+    return GO_CLEAROBJ;
 }
 
 static int bigwords(long foo)
@@ -161,7 +160,7 @@ static int bivalve(token_t verb, token_t obj)
     if (!TOTING(TRIDNT))spk= is_oyster ? OYSTER_OPENER : CLAM_OPENER;
     if (verb == LOCK)spk=HUH_MAN;
     if (spk == PEARL_FALLS) {
-       DSTROY(CLAM);
+       DESTROY(CLAM);
        DROP(OYSTER,game.loc);
        DROP(PEARL,LOC_CULDESAC);
     }
@@ -169,22 +168,20 @@ static int bivalve(token_t verb, token_t obj)
     return GO_CLEAROBJ;
 }
 
-static int blast(void)
+static void blast(void)
 /*  Blast.  No effect unless you've got dynamite, which is a neat trick! */
 {
     if (game.prop[ROD2] < 0 || !game.closed)
-    {
        RSPEAK(REQUIRES_DYNAMITE);
-       return GO_CLEAROBJ;
+    else {
+       game.bonus=133;
+       if (game.loc == LOC_NE)
+           game.bonus=134;
+       if (HERE(ROD2))
+           game.bonus=135;
+       RSPEAK(game.bonus);
+       score(endgame);
     }
-    game.bonus=133;
-    if (game.loc == LOC_NE)
-       game.bonus=134;
-    if (HERE(ROD2))
-       game.bonus=135;
-    RSPEAK(game.bonus);
-    score(endgame);
-    return GO_CLEAROBJ;        /* pacify compiler - we never get here */
 }
 
 static int vbreak(token_t verb, token_t obj)
@@ -243,7 +240,7 @@ static int carry(token_t verb, token_t obj)
     if (obj == SIGN)spk=HAND_PASSTHROUGH;
     if (obj == MESSAG) {
        RSPEAK(REMOVE_MESSAGE);
-       DSTROY(MESSAG);
+       DESTROY(MESSAG);
        return GO_CLEAROBJ;
     }
     if (game.fixed[obj] != 0) {
@@ -254,10 +251,12 @@ static int carry(token_t verb, token_t obj)
        if (!HERE(BOTTLE) || LIQUID() != obj) {
            if (TOTING(BOTTLE) && game.prop[BOTTLE] == 1)
                return(fill(verb, BOTTLE));
-           if (game.prop[BOTTLE] != 1)spk=BOTTLE_FULL;
-           if (!TOTING(BOTTLE))spk=NO_CONTAINER;
-           RSPEAK(spk);
-           return GO_CLEAROBJ;
+           else {
+               if (game.prop[BOTTLE] != 1)spk=BOTTLE_FULL;
+               if (!TOTING(BOTTLE))spk=NO_CONTAINER;
+               RSPEAK(spk);
+               return GO_CLEAROBJ;
+           }
        }
        obj = BOTTLE;
     }
@@ -269,7 +268,7 @@ static int carry(token_t verb, token_t obj)
     }
     else if (obj == BIRD && game.prop[BIRD] != 1 && -1-game.prop[BIRD] != 1) {
        if (game.prop[BIRD] == 2) {
-           DSTROY(BIRD);
+           DESTROY(BIRD);
            RSPEAK(BIRD_CRAP);
            return GO_CLEAROBJ;
        }
@@ -285,7 +284,7 @@ static int carry(token_t verb, token_t obj)
        CARRY(BIRD+CAGE-obj,game.loc);
     CARRY(obj,game.loc);
     if (obj == BOTTLE && LIQUID() != 0)
-       game.place[LIQUID()] = -1;
+       game.place[LIQUID()] = CARRIED;
     if (GSTONE(obj) && game.prop[obj] != 0) {
        game.prop[obj]=0;
        game.prop[CAVITY]=1;
@@ -335,7 +334,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
         if (obj == BIRD && HERE(SNAKE)) {
             RSPEAK(BIRD_ATTACKS);
             if (game.closed) return GO_DWARFWAKE;
-            DSTROY(SNAKE);
+            DESTROY(SNAKE);
             /* Set game.prop for use by travel options */
             game.prop[SNAKE]=1;
 
@@ -357,13 +356,13 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
                 }
             }
         } else if (obj == COINS && HERE(VEND)) {
-            DSTROY(COINS);
+            DESTROY(COINS);
             DROP(BATTER,game.loc);
             PSPEAK(BATTER,0);
             return GO_CLEAROBJ;
         } else if (obj == BIRD && AT(DRAGON) && game.prop[DRAGON] == 0) {
             RSPEAK(BIRD_BURNT);
-            DSTROY(BIRD);
+            DESTROY(BIRD);
             game.prop[BIRD]=0;
             return GO_CLEAROBJ;
         } else if (obj == BEAR && AT(TROLL)) {
@@ -386,7 +385,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]=0;
+       game.place[k] = NOWHERE;
     if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD,game.loc);
     DROP(obj,game.loc);
     if (obj != BIRD) return GO_CLEAROBJ;
@@ -405,12 +404,12 @@ static int drink(token_t verb, token_t obj)
     if (obj != BLOOD) {
        if (obj != 0 && obj != WATER)spk=RIDICULOUS_ATTEMPT;
        if (spk != RIDICULOUS_ATTEMPT && LIQUID() == WATER && HERE(BOTTLE)) {
-           game.prop[BOTTLE]=1;
-           game.place[WATER]=0;
+           game.prop[BOTTLE] = 1;
+           game.place[WATER] = NOWHERE;
            spk=BOTTLE_EMPTY;
        }
     } else {
-       DSTROY(BLOOD);
+       DESTROY(BLOOD);
        game.prop[DRAGON]=2;
        OBJSND[BIRD]=OBJSND[BIRD]+3;
        spk=HEAD_BUZZES;
@@ -427,11 +426,11 @@ static int eat(token_t verb, token_t obj)
     if (obj == INTRANSITIVE) {
        if (!HERE(FOOD))
            return GO_UNKNOWN;
-       DSTROY(FOOD);
+       DESTROY(FOOD);
        spk=THANKS_DELICIOUS;
     } else {
        if (obj == FOOD) {
-           DSTROY(FOOD);
+           DESTROY(FOOD);
            spk=THANKS_DELICIOUS;
        }
        if (obj == BIRD || obj == SNAKE || obj == CLAM || obj == OYSTER || obj ==
@@ -459,7 +458,7 @@ static int extinguish(token_t verb, int obj)
     else if (obj == LAMP) {
        game.prop[LAMP]=0;
        RSPEAK(LAMP_OFF);
-       spk = DARK(game.loc) ? PITCH_DARK : ARB_0;
+       spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
     }
     else if (obj == DRAGON || obj == VOLCAN)
        spk=BEYOND_POWER;
@@ -481,7 +480,7 @@ static int feed(token_t verb, token_t obj)
        if (obj == DRAGON && game.prop[DRAGON] != 0)spk=RIDICULOUS_ATTEMPT;
        if (obj == TROLL)spk=TROLL_VICES;
        if (obj == SNAKE && !game.closed && HERE(BIRD)) {
-           DSTROY(BIRD);
+           DESTROY(BIRD);
            game.prop[BIRD]=0;
            spk = BIRD_DEVOURED;
        }
@@ -496,7 +495,7 @@ static int feed(token_t verb, token_t obj)
        if (game.prop[BEAR] == 0)spk=NOTHING_EDIBLE;
        if (game.prop[BEAR] == 3)spk=RIDICULOUS_ATTEMPT;
        if (HERE(FOOD)) {
-           DSTROY(FOOD);
+           DESTROY(FOOD);
            game.prop[BEAR]=1;
            game.fixed[AXE]=0;
            game.prop[AXE]=0;
@@ -537,8 +536,8 @@ int fill(token_t verb, token_t obj)
        spk=FILL_INVALID;
        k=LIQUID();
        if (k == 0 || !HERE(BOTTLE)) {RSPEAK(spk); return GO_CLEAROBJ;}
-       game.place[k]=0;
-       game.prop[BOTTLE]=1;
+       game.place[k] = NOWHERE;
+       game.prop[BOTTLE] = 1;
        if (k == OIL)game.prop[URN]=1;
        spk=WATER_URN+game.prop[URN];
        RSPEAK(spk);
@@ -561,7 +560,7 @@ int fill(token_t verb, token_t obj)
        game.prop[BOTTLE]=MOD(COND[game.loc],4)/2*2;
        k=LIQUID();
        if (TOTING(BOTTLE))
-           game.place[k] = -1;
+           game.place[k] = CARRIED;
        if (k == OIL)
            spk=BOTTLED_OIL;
     }
@@ -626,7 +625,7 @@ static int inven(void)
        game.blklin=false;
        PSPEAK(i,-1);
        game.blklin=true;
-       spk=ARB_0;
+       spk=NO_MESSAGE;
     }
     if (TOTING(BEAR))
        spk=TAME_BEAR;
@@ -634,7 +633,7 @@ static int inven(void)
     return GO_CLEAROBJ;
 }
 
-int light(token_t verb, token_t obj)
+static int light(token_t verb, token_t obj)
 /*  Light.  Applicable only to lamp and urn. */
 {
     int spk = ACTSPK[verb];
@@ -645,12 +644,12 @@ int light(token_t verb, token_t obj)
     }
 
     if (obj == URN) {
-       spk=URN_EMPTY;
-       if (game.prop[URN] == 0)
-           {RSPEAK(spk); return GO_CLEAROBJ;}
-       spk=URN_LIT;
-       game.prop[URN]=2;
-       RSPEAK(spk);
+       if (game.prop[URN] == 0) {
+           RSPEAK(URN_EMPTY);
+       } else {
+           game.prop[URN] = 2;
+           RSPEAK(URN_LIT);
+       }
        return GO_CLEAROBJ;
     } else {
        if (obj != LAMP)
@@ -681,16 +680,16 @@ static int listen(void)
     if (k != 0) {
        RSPEAK(labs(k));
        if (k < 0) return GO_CLEAROBJ;
-       spk=ARB_0;
+       spk=NO_MESSAGE;
     }
     SETPRM(1,game.zzword,0);
     for (int i=1; i<=NOBJECTS; i++) {
        if (!HERE(i) || OBJSND[i] == 0 || game.prop[i] < 0)
            continue;
        PSPEAK(i,OBJSND[i]+game.prop[i]);
-       spk=ARB_0;
+       spk=NO_MESSAGE;
        if (i == BIRD && OBJSND[i]+game.prop[i] == 8)
-           DSTROY(BIRD);
+           DESTROY(BIRD);
     }
     RSPEAK(spk);
     return GO_CLEAROBJ;
@@ -752,8 +751,8 @@ static int pour(token_t verb, token_t obj)
     if (obj != OIL && obj != WATER) {RSPEAK(spk); return GO_CLEAROBJ;}
     if (HERE(URN) && game.prop[URN] == 0)
        return fill(verb, URN);
-    game.prop[BOTTLE]=1;
-    game.place[obj]=0;
+    game.prop[BOTTLE] = 1;
+    game.place[obj] = NOWHERE;
     spk=GROUND_WET;
     if (!(AT(PLANT) || AT(DOOR)))
        {RSPEAK(spk); return GO_CLEAROBJ;}
@@ -815,7 +814,7 @@ static int reservoir(void)
 /*  Z'ZZZ (word gets recomputed at startup; different each game). */
 {
     if (!AT(RESER) && game.loc != game.fixed[RESER]-1) {
-       RSPEAK(RUB_NOGO);
+       RSPEAK(NOTHING_HAPPENS);
        return GO_CLEAROBJ;
     } else {
        PSPEAK(RESER,game.prop[RESER]+1);
@@ -838,7 +837,7 @@ static int rub(token_t verb, token_t obj)
     if (obj != LAMP)
        spk=PECULIAR_NOTHING;
     if (obj == URN && game.prop[URN] == 2) {
-       DSTROY(URN);
+       DESTROY(URN);
        DROP(AMBER,game.loc);
        game.prop[AMBER]=1;
        --game.tally;
@@ -866,7 +865,6 @@ static int say(void)
     }
     RSPEAK(OKEY_DOKEY);
     return GO_CLEAROBJ;
-
 }
 
 static int throw_support(long spk)
@@ -923,27 +921,22 @@ static int throw(FILE *cmdin, long verb, token_t obj)
         }
         if (HERE(BEAR) && game.prop[BEAR] == 0) {
             /* This'll teach him to throw the axe at the bear! */
-            spk=AXE_LOST;
             DROP(AXE,game.loc);
-            game.fixed[AXE]= -1;
-            game.prop[AXE]=1;
+            game.fixed[AXE] = -1;
+            game.prop[AXE] = 1;
             JUGGLE(BEAR);
-            {RSPEAK(spk); return GO_CLEAROBJ;}
+            RSPEAK(AXE_LOST);
+           return GO_CLEAROBJ;
         }
         return(attack(cmdin, verb, 0));
     }
 
     if (randrange(NDWARVES+1) < game.dflag) {
-        spk=DWARF_DODGES;
-        return throw_support(spk);
+        return throw_support(DWARF_DODGES);
     }
     game.dseen[i]=false;
     game.dloc[i]=0;
-    spk=KILLED_DWARF;
-    ++game.dkill;
-    if (game.dkill == 1)spk=DWARF_SMOKE;
-
-    return throw_support(spk);
+    return throw_support((++game.dkill == 1) ? DWARF_SMOKE : KILLED_DWARF);
 }
 
 static int vscore(void)
@@ -956,13 +949,13 @@ static int vscore(void)
 static int wake(token_t verb, token_t obj)
 /* Wake.  Only use is to disturb the dwarves. */
 {
-    if (obj != DWARF || !game.closed)
-    {
+    if (obj != DWARF || !game.closed) {
        RSPEAK(ACTSPK[verb]);
        return GO_CLEAROBJ;
+    } else {
+       RSPEAK(PROD_DWARF);
+       return GO_DWARFWAKE;
     }
-    RSPEAK(PROD_DWARF);
-    return GO_DWARFWAKE;
 }
 
 static int wave(token_t verb, token_t obj)
@@ -1090,15 +1083,15 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
                    case 19: /* INVEN */ return inven();
                    case 20: /* FEED  */ return GO_UNKNOWN; 
                    case 21: /* FILL  */ return fill(verb, obj);   
-                   case 22: /* BLAST */ return blast();   
+                   case 22: /* BLAST */ blast(); return GO_CLEAROBJ;
                    case 23: /* SCOR  */ return vscore();   
                    case 24: /* FOO   */ return bigwords(WD1);   
                    case 25: /* BRIEF */ return brief();   
                    case 26: /* READ  */ return read(input, verb, INTRANSITIVE);
                    case 27: /* BREAK */ return GO_UNKNOWN; 
                    case 28: /* WAKE  */ return GO_UNKNOWN; 
-                   case 29: /* SUSP  */ return saveresume(input, false);   
-                   case 30: /* RESU  */ return saveresume(input, true);   
+                   case 29: /* SUSP  */ return suspend(input);
+                   case 30: /* RESU  */ return resume(input);
                    case 31: /* FLY   */ return fly(verb, INTRANSITIVE);   
                    case 32: /* LISTE */ return listen();   
                    case 33: /* ZZZZ  */ return reservoir();   
@@ -1131,7 +1124,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
                case 19: /* INVEN */ return find(verb, obj);   
                case 20: /* FEED  */ return feed(verb, obj);   
                case 21: /* FILL  */ return fill(verb, obj);   
-               case 22: /* BLAST */ return blast();   
+               case 22: /* BLAST */ blast(); return GO_CLEAROBJ;
                case 23: /* SCOR  */ {RSPEAK(spk); return GO_CLEAROBJ;} 
                case 24: /* FOO   */ {RSPEAK(spk); return GO_CLEAROBJ;} 
                case 25: /* BRIEF */ {RSPEAK(spk); return GO_CLEAROBJ;}