Transition to YAML is done, adventure.text and travel.py can go away.
[open-adventure.git] / main.c
diff --git a/main.c b/main.c
index 2b264b915afa4f697f800d6f9019f26de0809ca6..7c6ba5f50fdcca67db74b8f7c9aeda43cb701696 100644 (file)
--- a/main.c
+++ b/main.c
@@ -22,9 +22,8 @@
 #include <time.h>
 #include <string.h>
 #include "advent.h"
-#include "database.h"
 #include "linenoise/linenoise.h"
-#include "newdb.h"
+#include "dungeon.h"
 
 #define DIM(a) (sizeof(a)/sizeof(a[0]))
 
@@ -54,7 +53,7 @@ static void sig_handler(int signo)
  * MAIN PROGRAM
  *
  *  Adventure (rev 2: 20 treasures)
- *
+Here's what we think. *
  *  History: Original idea & 5-treasure version (adventures) by Willie Crowther
  *           15-treasure version (adventure) by Don Woods, April-June 1977
  *           20-treasure version (rev 2) by Don Woods, August 1978
@@ -473,8 +472,8 @@ static bool dwarfmove(void)
  *  another chance, he gets a snide remark as we exit.  When
  *  reincarnated, all objects being carried get dropped at game.oldlc2
  *  (presumably the last place prior to being killed) without change
- *  of props.  the loop runs backwards to assure that the bird is
- *  dropped before the cage.  (this kluge could be changed once we're
+ *  of props.  The loop runs backwards to assure that the bird is
+ *  dropped before the cage.  (This kluge could be changed once we're
  *  sure all references to bird and cage are done by keywords.)  The
  *  lamp is a special case (it wouldn't do to leave it in the cave).
  *  It is turned off and left outside the building (only if he was
@@ -614,18 +613,10 @@ static bool playermove(token_t verb, int motion)
     /* (ESR) We've found a destination that goes with the motion verb.
      * Next we need to check any conditional(s) on this destination, and
      * possibly on following entries. */
-    scratchloc = T_HIGH(travel[kk]);
-
     do {
-        /*
-         * (ESR) This conditional-skip loop may have to be repeated if
-         * it includes the plover passage.  Same deal for any future
-         * cases where we need to block travel and then redo it once
-         * the blocking condition has been removed.
-         */
         for (;;) { /* L12 loop */
             for (;;) {
-                long cond = scratchloc / 1000;
+                long cond = T_CONDITION(travel[kk]);
                 long arg = MOD(cond, 100);
                 if (!SPECIAL(cond)) {
                    /* YAML N and [pct N] conditionals */
@@ -643,18 +634,18 @@ static bool playermove(token_t verb, int motion)
 
                /* We arrive here on conditional failure.
                 * Skip to next non-matching destination */
-               long nextup;
+               long k2 = kk;
                do {
-                    if (travel[kk].stop)
+                    if (travel[k2].stop)
                         BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
-                    ++kk;
-                    nextup = T_HIGH(travel[kk]);
+                    ++k2;
                 } while
-                   (nextup == scratchloc);
-                scratchloc = nextup;
+                   (T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
+               kk = k2;
             }
 
-            game.newloc = MOD(scratchloc, 1000);
+           /* Found an eligible rule, now execute it */
+            game.newloc = T_DESTINATION(travel[kk]);
             if (!SPECIAL(game.newloc))
                 return true;
 
@@ -685,14 +676,14 @@ static bool playermove(token_t verb, int motion)
                      * to get it out.  Having dropped it, go back and
                      * pretend he wasn't carrying it after all. */
                     drop(EMERALD, game.loc);
+                   k2 = kk;
                     do {
-                        if (travel[kk].stop)
+                        if (travel[k2].stop)
                             BUG(CONDITIONAL_TRAVEL_ENTRY_WITH_NO_ALTERATION); // LCOV_EXCL_LINE
-                        ++kk;
-                        game.newloc = T_HIGH(travel[kk]);
+                        ++k2;
                     } while
-                    (game.newloc == scratchloc);
-                    scratchloc = game.newloc;
+                       (T_HIGH(travel[kk]) == T_HIGH(travel[k2]));
+                    kk = k2;
                     continue; /* goto L12 */
                 case 3:
                     /* Travel 303.  Troll bridge.  Must be done only