Magic-number elimination.
[open-adventure.git] / actions.c
index 6cd73b562d218bf489abc5269d0e7bd54332ffea..7a401eb65faada635e3093218f47110181b64c7d 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -70,49 +70,47 @@ static int attack(FILE *input, long verb, token_t obj)
        RSPEAK(spk);
        RSPEAK(KNIFE_THROWN);
        DSTROY(OGRE);
-       int k=0;
+       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=spk+1+1/k;  /* FIXME: Arithmetic on message numbers */
-       RSPEAK(spk);
-       return GO_CLEAROBJ;
+       spk=spk+1+1/dwarves;    /* FIXME: Arithmetic on message numbers */
     }
-
-    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)
@@ -183,7 +181,7 @@ static int blast(void)
     if (HERE(ROD2))
        game.bonus=135;
     RSPEAK(game.bonus);
-    score(0);
+    score(endgame);
     return GO_CLEAROBJ;        /* pacify compiler - we never get here */
 }
 
@@ -285,7 +283,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;
@@ -386,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]=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,8 +403,8 @@ 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 {
@@ -537,8 +535,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 +559,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;
     }
@@ -614,7 +612,7 @@ static int fly(token_t verb, token_t obj)
     return GO_TERMINATE;
 }
 
-static int inven(token_t obj)
+static int inven(void)
 /* Inventory. If object, treat same as find.  Else report on current burden. */
 {
     int spk=NO_CARRY;
@@ -752,8 +750,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;}
@@ -777,7 +775,7 @@ static int quit(FILE *input)
 /*  Quit.  Intransitive only.  Verify intent and exit if that's what he wants. */
 {
     if (YES(input,REALLY_QUIT,OK_MAN,OK_MAN))
-       score(1);
+       score(quitgame);
     return GO_CLEAROBJ;
 }
 
@@ -949,7 +947,7 @@ static int throw(FILE *cmdin, long verb, token_t obj)
 static int vscore(void)
 /* Score.  Call scoring routine but tell it to return. */
 {
-    score(-1);
+    score(scoregame);
     return GO_CLEAROBJ;
 }
 
@@ -1087,7 +1085,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
                    case 16: /* TOSS  */ return GO_UNKNOWN; 
                    case 17: /* QUIT  */ return quit(input);   
                    case 18: /* FIND  */ return GO_UNKNOWN; 
-                   case 19: /* INVEN */ return inven(obj);   
+                   case 19: /* INVEN */ return inven();
                    case 20: /* FEED  */ return GO_UNKNOWN; 
                    case 21: /* FILL  */ return fill(verb, obj);   
                    case 22: /* BLAST */ return blast();