Fix some screwy formatting of conditionals...
[open-adventure.git] / actions.c
index 09f7836b616fa9727ee7235c0338ff645e1bdc77..d8b1546b3a55ea61190a45674fa88702af2edf2a 100644 (file)
--- a/actions.c
+++ b/actions.c
@@ -1,9 +1,9 @@
 /*
- * Actions for the duneon-running code.
+ * Actions for the dungeon-running code.
  *
- * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
- * Copyright (c) 2017 by Eric S. Raymond
- * SPDX-License-Identifier: BSD-2-clause
+ * SPDX-FileCopyrightText: 1977, 2005 by Will Crowther and Don Woods
+ * SPDX-FileCopyrightText 2017 by Eric S. Raymond
+ * SPDX-License-Identifier: BSD-2-Clause
  */
 
 #include <stdlib.h>
@@ -111,7 +111,7 @@ static phase_codes_t attack(command_t command)
          *  fixed), move rug there (not fixed), and move him there,
          *  too.  Then do a null motion to get new description. */
         rspeak(BARE_HANDS_QUERY);
-        if (!silent_yes()) {
+        if (!silent_yes_or_no()) {
             speak(arbitrary_messages[NASTY_DRAGON]);
             return GO_MOVE;
         }
@@ -187,17 +187,25 @@ static phase_codes_t attack(command_t command)
 }
 
 static phase_codes_t bigwords(vocab_t id)
-/*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
- *  Look up foo in special section of vocab to determine which word we've got.
- *  Last word zips the eggs back to the giant room (unless already there). */
+/* Only called on FEE FIE FOE FOO (AND FUM).  Advance to next state if given
+ * in proper order. Look up foo in special section of vocab to determine which
+ * word we've got. Last word zips the eggs back to the giant room (unless
+ * already there). */
 {
-    if ((game.foobar == WORD_EMPTY && id == FEE) ||
-        (game.foobar == FEE && id == FIE) ||
-        (game.foobar == FIE && id == FOE) ||
-        (game.foobar == FOE && id == FOO) ||
-        (game.foobar == FOE && id == FUM)) {
+    int foobar = abs(game.foobar);
+
+    /* Only FEE can start a magic-word sequence. */
+    if ((foobar == WORD_EMPTY) && (id == FIE || id == FOE || id == FOO || id == FUM)) {
+       rspeak(NOTHING_HAPPENS);
+       return GO_CLEAROBJ;
+    }
+    
+    if ((foobar == WORD_EMPTY && id == FEE) ||
+        (foobar == FEE && id == FIE) ||
+        (foobar == FIE && id == FOE) ||
+        (foobar == FOE && id == FOO)) {
         game.foobar = id;
-        if ((id != FOO) && (id != FUM)) {
+        if (id != FOO) {
             rspeak(OK_MAN);
             return GO_CLEAROBJ;
         }
@@ -222,13 +230,11 @@ static phase_codes_t bigwords(vocab_t id)
             return GO_CLEAROBJ;
         }
     } else {
-        if (game.loc == LOC_GIANTROOM) {
-            rspeak(START_OVER);
-        } else {
-            /* This is new begavior in Open Adventure - sounds better when
-             * player isn't in the Giant Room. */
-            rspeak(WELL_POINTLESS);
-        }
+       /* Magic-word sequence was started but is incorrect */
+       if (settings.oldstyle || game.seenbigwords)
+           rspeak(START_OVER);
+       else
+           rspeak(WELL_POINTLESS);
         game.foobar = WORD_EMPTY;
         return GO_CLEAROBJ;
     }
@@ -237,8 +243,7 @@ static phase_codes_t bigwords(vocab_t id)
 static void blast(void)
 /*  Blast.  No effect unless you've got dynamite, which is a neat trick! */
 {
-    if (game.prop[ROD2] == STATE_NOTFOUND ||
-        !game.closed)
+    if (game.prop[ROD2] == STATE_NOTFOUND || !game.closed)
         rspeak(REQUIRES_DYNAMITE);
     else {
         if (HERE(ROD2)) {
@@ -349,10 +354,8 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
         return GO_CLEAROBJ;
     }
 
-    if (obj == WATER ||
-        obj == OIL) {
-        if (!HERE(BOTTLE) ||
-            LIQUID() != obj) {
+    if (obj == WATER || obj == OIL) {
+        if (!HERE(BOTTLE) || LIQUID() != obj) {
             if (!TOTING(BOTTLE)) {
                 rspeak(NO_CONTAINER);
                 return GO_CLEAROBJ;
@@ -388,8 +391,7 @@ static phase_codes_t vcarry(verb_t verb, obj_t obj)
         }
         game.prop[BIRD] = BIRD_CAGED;
     }
-    if ((obj == BIRD ||
-         obj == CAGE) &&
+    if ((obj == BIRD || obj == CAGE) &&
         (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
         /* expression maps BIRD to CAGE and CAGE to BIRD */
         carry(BIRD + CAGE - obj, game.loc);
@@ -809,10 +811,8 @@ static phase_codes_t find(verb_t verb, obj_t obj)
         return GO_CLEAROBJ;
     }
 
-    if (AT(obj) ||
-        (LIQUID() == obj && AT(BOTTLE)) ||
-        obj == LIQLOC(game.loc) ||
-        (obj == DWARF && atdwrf(game.loc) > 0)) {
+    if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
+        obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
         rspeak(YOU_HAVEIT);
         return GO_CLEAROBJ;
     }
@@ -847,18 +847,20 @@ static phase_codes_t fly(verb_t verb, obj_t obj)
     }
 
     if (game.loc == LOC_CLIFF) {
-       game.oldlc2 = game.oldloc;
-       game.oldloc = game.loc;
+        game.oldlc2 = game.oldloc;
+        game.oldloc = game.loc;
         game.newloc = LOC_LEDGE;
         rspeak(RUG_GOES);
     } else if (game.loc == LOC_LEDGE) {
-       game.oldlc2 = game.oldloc;
-       game.oldloc = game.loc;
+        game.oldlc2 = game.oldloc;
+        game.oldloc = game.loc;
         game.newloc = LOC_CLIFF;
         rspeak(RUG_RETURNS);
     } else {
-       /* should never happen */
-       rspeak(NOTHING_HAPPENS);
+// LCOV_EXCL_START
+        /* should never happen */
+        rspeak(NOTHING_HAPPENS);
+// LCOV_EXCL_STOP
     }
     return GO_TERMINATE;
 }
@@ -868,8 +870,7 @@ static phase_codes_t inven(void)
 {
     bool empty = true;
     for (obj_t i = 1; i <= NOBJECTS; i++) {
-        if (i == BEAR ||
-            !TOTING(i))
+        if (i == BEAR || !TOTING(i))
             continue;
         if (empty) {
             rspeak(NOW_HOLDING);
@@ -923,7 +924,7 @@ static phase_codes_t light(verb_t verb, obj_t obj)
 }
 
 static phase_codes_t listen(void)
-/*  Listen.  Intransitive only.  Print stuff based on object sound proprties. */
+/*  Listen.  Intransitive only.  Print stuff based on object sound properties. */
 {
     bool soundlatch = false;
     vocab_t sound = locations[game.loc].sound;
@@ -934,9 +935,7 @@ static phase_codes_t listen(void)
         soundlatch = true;
     }
     for (obj_t i = 1; i <= NOBJECTS; i++) {
-        if (!HERE(i) ||
-            objects[i].sounds[0] == NULL ||
-            game.prop[i] < 0)
+        if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0)
             continue;
         int mi =  game.prop[i];
         /* (ESR) Some unpleasant magic on object states here. Ideally
@@ -953,7 +952,7 @@ static phase_codes_t listen(void)
         soundlatch = true;
     }
     if (!soundlatch)
-       rspeak(ALL_SILENT);
+        rspeak(ALL_SILENT);
     return GO_CLEAROBJ;
 }
 
@@ -1006,7 +1005,7 @@ static phase_codes_t lock(verb_t verb, obj_t obj)
         if (verb == LOCK)
             rspeak(HUH_MAN);
         else if (TOTING(CLAM))
-           rspeak(DROP_CLAM);
+            rspeak(DROP_CLAM);
         else if (!TOTING(TRIDENT))
             rspeak(CLAM_OPENER);
         else {
@@ -1046,9 +1045,8 @@ static phase_codes_t pour(verb_t verb, obj_t obj)
 /*  Pour.  If no object, or object is bottle, assume contents of bottle.
  *  special tests for pouring water or oil on plant or rusty door. */
 {
-    if (obj == BOTTLE ||
-        obj == INTRANSITIVE)
-        obj = LIQUID();
+    if (obj == BOTTLE || obj == INTRANSITIVE)
+       obj = LIQUID();
     if (obj == NO_OBJECT)
         return GO_UNKNOWN;
     if (!TOTING(obj)) {
@@ -1064,8 +1062,7 @@ static phase_codes_t pour(verb_t verb, obj_t obj)
         return fill(verb, URN);
     game.prop[BOTTLE] = EMPTY_BOTTLE;
     game.place[obj] = LOC_NOWHERE;
-    if (!(AT(PLANT) ||
-          AT(DOOR))) {
+    if (!(AT(PLANT) || AT(DOOR))) {
         rspeak(GROUND_WET);
         return GO_CLEAROBJ;
     }
@@ -1090,7 +1087,7 @@ static phase_codes_t pour(verb_t verb, obj_t obj)
 static phase_codes_t quit(void)
 /*  Quit.  Intransitive only.  Verify intent and exit if that's what he wants. */
 {
-    if (yes(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+    if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
         terminate(quitgame);
     return GO_CLEAROBJ;
 }
@@ -1104,22 +1101,20 @@ static phase_codes_t read(command_t command)
             if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
                 command.obj = command.obj * NOBJECTS + i;
         }
-        if (command.obj > NOBJECTS ||
-            command.obj == NO_OBJECT ||
-            DARK(game.loc))
+        if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc))
             return GO_UNKNOWN;
     }
 
     if (DARK(game.loc)) {
         sspeak(NO_SEE, command.word[0].raw);
     } else if (command.obj == OYSTER) {
-       if (!TOTING(OYSTER) || !game.closed) {
-           rspeak(DONT_UNDERSTAND);
-       } else if (!game.clshnt) {
-           game.clshnt = yes(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
-       } else if (game.clshnt) {
-           pspeak(OYSTER, hear, true, 1);      // Not really a sound, but oh well.
-       }
+        if (!TOTING(OYSTER) || !game.closed) {
+            rspeak(DONT_UNDERSTAND);
+        } else if (!game.clshnt) {
+            game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
+        } else {
+            pspeak(OYSTER, hear, true, 1);     // Not really a sound, but oh well.
+        }
     } else if (objects[command.obj].texts[0] == NULL ||
                game.prop[command.obj] == STATE_NOTFOUND) {
         speak(actions[command.verb].message);
@@ -1198,7 +1193,7 @@ static phase_codes_t throw_support(vocab_t spk)
     return GO_MOVE;
 }
 
-static phase_codes_t throw (command_t command)
+static phase_codes_t throwit(command_t command)
 /*  Throw.  Same as discard unless axe.  Then same as attack except
  *  ignore bird, and if dwarf is present then one might be killed.
  *  (Only way to do so!)  Axe also special for dragon, bear, and
@@ -1262,8 +1257,7 @@ static phase_codes_t throw (command_t command)
 static phase_codes_t wake(verb_t verb, obj_t obj)
 /* Wake.  Only use is to disturb the dwarves. */
 {
-    if (obj != DWARF ||
-        !game.closed) {
+    if (obj != DWARF || !game.closed) {
         speak(actions[verb].message);
         return GO_CLEAROBJ;
     } else {
@@ -1293,11 +1287,7 @@ static phase_codes_t waste(verb_t verb, turn_t turns)
 static phase_codes_t wave(verb_t verb, obj_t obj)
 /* Wave.  No effect unless waving rod at fissure or at bird. */
 {
-    if (obj != ROD ||
-        !TOTING(obj) ||
-        (!HERE(BIRD) &&
-         (game.closng ||
-          !AT(FISSURE)))) {
+    if (obj != ROD || !TOTING(obj) || (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
         speak(((!TOTING(obj)) && (obj != ROD ||
                                   !TOTING(ROD2))) ?
               arbitrary_messages[ARENT_CARRYING] :
@@ -1318,8 +1308,7 @@ static phase_codes_t wave(verb_t verb, obj_t obj)
                    FREE_FLY);
             return GO_DWARFWAKE;
         }
-        if (game.closng ||
-            !AT(FISSURE)) {
+        if (game.closng || !AT(FISSURE)) {
             rspeak((game.prop[BIRD] == BIRD_CAGED) ?
                    CAGE_FLY :
                    FREE_FLY);
@@ -1362,7 +1351,7 @@ phase_codes_t action(command_t command)
         else if (command.obj == DWARF && atdwrf(game.loc) > 0)
             /* FALL THROUGH */;
         else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
-                                command.obj == LIQLOC(game.loc)))
+                                  command.obj == LIQLOC(game.loc)))
             /* FALL THROUGH */;
         else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
             command.obj = URN;
@@ -1398,8 +1387,7 @@ phase_codes_t action(command_t command)
              * will do here. We're preventing interpretation as an intransitive
              * verb when the word is unknown. */
             command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
-        if (command.obj == NO_OBJECT ||
-            command.obj == INTRANSITIVE) {
+        if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
             /*  Analyse an intransitive verb (ie, no object given yet). */
             switch (command.verb) {
             case CARRY:
@@ -1533,7 +1521,7 @@ phase_codes_t action(command_t command)
         case RUB:
             return rub(command.verb, command.obj);
         case THROW:
-            return throw (command);
+            return throwit(command);
         case QUIT: {
             speak(actions[command.verb].message);
             return GO_CLEAROBJ;