Documentation polishing.
[open-adventure.git] / actions.c
index 5000f1eb0f738cd0ff369cba0af05d1bdd119705..e88773e94245869e39f0dc3ce598c0f82127a647 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -21,9 +21,9 @@ static int attack(FILE *input, long verb, token_t obj)
  *  enemies, or no enemies but 2 others. */
 {
     int spk = ACTSPK[verb];
-    int i = ATDWRF(game.loc);
+    int d = ATDWRF(game.loc);
     if (obj == 0) {
-       if (i > 0)
+       if (d > 0)
            obj=DWARF;
        if (HERE(SNAKE))obj=obj*NOBJECTS+SNAKE;
        if (AT(DRAGON) && game.prop[DRAGON] == 0)obj=obj*NOBJECTS+DRAGON;
@@ -65,25 +65,31 @@ static int attack(FILE *input, long verb, token_t obj)
     if (obj == DWARF && game.closed) return GO_DWARFWAKE;
     if (obj == DRAGON)spk=ALREADY_DEAD;
     if (obj == TROLL)spk=ROCKY_TROLL;
-    if (obj == OGRE)spk=OGRE_DOFGE;
-    if (obj == OGRE && i > 0) {
+    if (obj == OGRE)spk=OGRE_DODGE;
+    if (obj == OGRE && d > 0) {
        RSPEAK(spk);
        RSPEAK(KNIFE_THROWN);
        DSTROY(OGRE);
        int k=0;
-       for (i=1; i < PIRATE; i++) {
+       for (int i=1; i < PIRATE; i++) {
            if (game.dloc[i] == game.loc) {
                ++k;
-               game.dloc[i]=61;
+               game.dloc[i] = LOC_LONGWEST;
                game.dseen[i]=false;
            }
        }
-       spk=spk+1+1/k;
+       spk=spk+1+1/k;  /* FIXME: Arithmetic on message numbers */
+       RSPEAK(spk);
+       return GO_CLEAROBJ;
+    }
+
+    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;
     }
-    if (obj == BEAR)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,
@@ -148,16 +154,16 @@ static int bigwords(long foo)
 static int bivalve(token_t verb, token_t obj)
 /* Clam/oyster actions */
 {
-    int spk, k=0;
-    if (obj == OYSTER)k=1;
-    spk=PEARL_FALLS+k;
-    if (TOTING(obj))spk=DROP_CLAM+k;
-    if (!TOTING(TRIDNT))spk=CLAM_OPENER+k;
+    int spk;
+    bool is_oyster = (obj == OYSTER);
+    spk= is_oyster ? OYSTER_OPENS : PEARL_FALLS;
+    if (TOTING(obj))spk= is_oyster ? DROP_OYSTER : DROP_CLAM;
+    if (!TOTING(TRIDNT))spk= is_oyster ? OYSTER_OPENER : CLAM_OPENER;
     if (verb == LOCK)spk=HUH_MAN;
-    if (spk == 124) {
+    if (spk == PEARL_FALLS) {
        DSTROY(CLAM);
        DROP(OYSTER,game.loc);
-       DROP(PEARL,105);
+       DROP(PEARL,LOC_CULDESAC);
     }
     RSPEAK(spk);
     return GO_CLEAROBJ;
@@ -172,12 +178,12 @@ static int blast(void)
        return GO_CLEAROBJ;
     }
     game.bonus=133;
-    if (game.loc == 115)
+    if (game.loc == LOC_NE)
        game.bonus=134;
     if (HERE(ROD2))
        game.bonus=135;
     RSPEAK(game.bonus);
-    score(0);
+    score(endgame);
     return GO_CLEAROBJ;        /* pacify compiler - we never get here */
 }
 
@@ -269,7 +275,7 @@ static int carry(token_t verb, token_t obj)
        }
        if (!TOTING(CAGE))spk=CANNOT_CARRY;
        if (TOTING(ROD))spk=BIRD_EVADES;
-       if (spk/2 == 13) {      /* FIXME: Arithmetic on message number */
+       if (spk == CANNOT_CARRY || spk == BIRD_EVADES) {
            RSPEAK(spk);
            return GO_CLEAROBJ;
        }
@@ -305,7 +311,10 @@ static int chain(token_t verb)
        spk=CHAIN_LOCKED;
        if (game.prop[CHAIN] != 0)spk=ALREADY_LOCKED;
        if (game.loc != PLAC[CHAIN])spk=NO_LOCKSITE;
-       if (spk != CHAIN_LOCKED) {RSPEAK(spk); return GO_CLEAROBJ;}
+       if (spk != CHAIN_LOCKED) {
+           RSPEAK(spk);
+           return GO_CLEAROBJ;
+       }
        game.prop[CHAIN]=2;
        if (TOTING(CHAIN))DROP(CHAIN,game.loc);
        game.fixed[CHAIN]= -1;
@@ -340,7 +349,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it)
                 if (TOTING(RUG))spk=RUG_WIGGLES;
                 if (obj == RUBY)spk=RUG_SETTLES;
                 RSPEAK(spk);
-                if (spk != 220) {
+                if (spk != RUG_WIGGLES) {
                     int k = 2-game.prop[RUG];
                     game.prop[RUG] = k;
                     if (k == 2) k = PLAC[SAPPH];
@@ -395,7 +404,7 @@ static int drink(token_t verb, token_t obj)
        return GO_UNKNOWN;
     if (obj != BLOOD) {
        if (obj != 0 && obj != WATER)spk=RIDICULOUS_ATTEMPT;
-       if (spk != 110 && LIQUID() == WATER && HERE(BOTTLE)) {
+       if (spk != RIDICULOUS_ATTEMPT && LIQUID() == WATER && HERE(BOTTLE)) {
            game.prop[BOTTLE]=1;
            game.place[WATER]=0;
            spk=BOTTLE_EMPTY;
@@ -518,7 +527,7 @@ int fill(token_t verb, token_t obj)
            return GO_CLEAROBJ;
        }
        RSPEAK(SHATTER_VASE);
-       game.prop[VASE]=2;
+       game.prop[VASE] = 2;
        game.fixed[VASE]= -1;
        return(discard(verb, obj, true));
     }
@@ -552,7 +561,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] = -1;
        if (k == OIL)
            spk=BOTTLED_OIL;
     }
@@ -582,7 +591,7 @@ static int fly(token_t verb, token_t obj)
     if (obj == INTRANSITIVE) {
        if (game.prop[RUG] != 2)spk=RUG_NOTHING2;
        if (!HERE(RUG))spk=FLAP_ARMS;
-       if (spk/2 == 112) {
+       if (spk == RUG_NOTHING2 || spk == FLAP_ARMS) {
            RSPEAK(spk);
            return GO_CLEAROBJ;
        }
@@ -599,20 +608,20 @@ static int fly(token_t verb, token_t obj)
     game.oldloc=game.loc;
     game.newloc=game.place[RUG]+game.fixed[RUG]-game.loc;
     spk=RUG_GOES;
-    if (game.prop[SAPPH] >= 0)spk=RUG_RETURNS;
+    if (game.prop[SAPPH] >= 0)
+       spk=RUG_RETURNS;
     RSPEAK(spk);
     return GO_TERMINATE;
 }
-    
+
 static int inven(token_t obj)
 /* Inventory. If object, treat same as find.  Else report on current burden. */
 {
-    int i;
     int spk=NO_CARRY;
-    for (i=1; i<=NOBJECTS; i++) {
+    for (int i=1; i<=NOBJECTS; i++) {
        if (i == BEAR || !TOTING(i))
            continue;
-       if (spk == 98)
+       if (spk == NO_CARRY)
            RSPEAK(NOW_HOLDING);
        game.blklin=false;
        PSPEAK(i,-1);
@@ -660,13 +669,13 @@ int light(token_t verb, token_t obj)
            return GO_TOP;
        else
            return GO_CLEAROBJ;
-    }   
+    }
 }
 
 static int listen(void)
 /*  Listen.  Intransitive only.  Print stuff based on objsnd/locsnd. */
 {
-    int i, k;
+    int k;
     int spk=ALL_SILENT;
     k=LOCSND[game.loc];
     if (k != 0) {
@@ -675,7 +684,7 @@ static int listen(void)
        spk=ARB_0;
     }
     SETPRM(1,game.zzword,0);
-    for (i=1; i<=NOBJECTS; i++) {
+    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]);
@@ -720,10 +729,10 @@ static int lock(token_t verb, token_t obj)
                if (!game.panic)game.clock2=15;
                game.panic=true;
            } else {
-               spk=ALREADY_LOCKED+game.prop[GRATE];    /* FIXME: Arithmetic on message number */
+               spk=game.prop[GRATE] ? GRATE_LOCKED : ALREADY_LOCKED;
                game.prop[GRATE]=1;
                if (verb == LOCK)game.prop[GRATE]=0;
-               spk=spk+2*game.prop[GRATE];
+               spk=game.prop[GRATE] ? GRATE_UNLOCKED : GRATE_LOCKED;
            }
        }
     }
@@ -768,7 +777,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;
 }
 
@@ -811,11 +820,14 @@ static int reservoir(void)
     } else {
        PSPEAK(RESER,game.prop[RESER]+1);
        game.prop[RESER]=1-game.prop[RESER];
-       if (AT(RESER)) return GO_CLEAROBJ;
-       game.oldlc2=game.loc;
-       game.newloc=0;
-       RSPEAK(NOT_BRIGHT);
-       return GO_TERMINATE;
+       if (AT(RESER))
+           return GO_CLEAROBJ;
+       else {
+           game.oldlc2=game.loc;
+           game.newloc=0;
+           RSPEAK(NOT_BRIGHT);
+           return GO_TERMINATE;
+       }
     }
 }
 
@@ -847,6 +859,7 @@ static int say(void)
     if (WD2 > 0)
        WD1=WD2;
     int wd=VOCAB(WD1,-1);
+    /* FIXME: Magic numbers */
     if (wd == 62 || wd == 65 || wd == 71 || wd == 2025 || wd == 2034) {
        WD2=0;
        return GO_LOOKUP;
@@ -875,7 +888,7 @@ static int throw(FILE *cmdin, long verb, token_t obj)
        RSPEAK(spk);
        return GO_CLEAROBJ;
     }
-    if (obj >= 50 && obj <= MAXTRS && AT(TROLL)) {
+    if (obj >= MINTRS && obj <= MAXTRS && AT(TROLL)) {
         spk=TROLL_SATISFIED;
         /*  Snarf a treasure for the troll. */
         DROP(obj,0);
@@ -905,7 +918,7 @@ static int throw(FILE *cmdin, long verb, token_t obj)
             return throw_support(spk);
         }
         if (AT(OGRE)) {
-            spk=OGRE_DOFGE;
+            spk=OGRE_DODGE;
             return throw_support(spk);
         }
         if (HERE(BEAR) && game.prop[BEAR] == 0) {
@@ -936,7 +949,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;
 }
 
@@ -1003,9 +1016,10 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj)
        if (HERE(obj))
            /* FALL THROUGH */;
        else if (obj == GRATE) {
-           if (game.loc == 1 || game.loc == 4 || game.loc == 7)
+           if (game.loc == LOC_START || game.loc == LOC_VALLEY || game.loc == LOC_SLIT)
                obj=DPRSSN;
-           if (game.loc > 9 && game.loc < 15)
+           /* FIXME: Arithmetic on location numbers */
+           if (game.loc > LOC_BELOWGRATE && game.loc < LOC_MISTHALL)
                obj=ENTRNC;
            if (obj != GRATE)
                return GO_MOVE;