More action handlers. Use consistent VO order.
[open-adventure.git] / actions1.c
index 34ae784043c7b9116f4ad22bca93d97992408f7d..1f337155361f4bad3fc6b238634545959e83029b 100644 (file)
@@ -1,9 +1,68 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include "advent.h"
-#include "funcs.h"
 #include "database.h"
 
+/*
+ * Action handlers.  Eventually we'll do lookup through a method table
+ * that calls these.  Absolutely nothing like the original FORTRAN
+ */
+
+static int bivalve(token_t verb, token_t obj)
+/* Clam/oyster actions */
+{
+    int k=0;
+    if(obj == OYSTER)k=1;
+    SPK=124+k;
+    if(TOTING(obj))SPK=120+k;
+    if(!TOTING(TRIDNT))SPK=122+k;
+    if(verb == LOCK)SPK=61;
+    if(SPK != 124)
+       return(2011);
+    DSTROY(CLAM);
+    DROP(OYSTER,game.loc);
+    DROP(PEARL,105);
+    return(2011);
+}
+
+static int chain(token_t verb)
+/* Do something to the bear's chain */
+{
+    if(verb != LOCK) {
+       SPK=171;
+       if(game.prop[BEAR] == 0)SPK=41;
+       if(game.prop[CHAIN] == 0)SPK=37;
+       if(SPK != 171) return(2011);
+       game.prop[CHAIN]=0;
+       game.fixed[CHAIN]=0;
+       if(game.prop[BEAR] != 3)game.prop[BEAR]=2;
+       game.fixed[BEAR]=2-game.prop[BEAR];
+       return(2011);
+    } else {
+       SPK=172;
+       if(game.prop[CHAIN] != 0)SPK=34;
+       if(game.loc != PLAC[CHAIN])SPK=173;
+       if(SPK != 172) return(2011);
+       game.prop[CHAIN]=2;
+       if(TOTING(CHAIN))DROP(CHAIN,game.loc);
+       game.fixed[CHAIN]= -1;
+       return(2011);
+    }
+}
+
+static int find(token_t obj)
+/*  Find.  Might be carrying it, or it might be here.  Else give caveat. */
+{
+    if(AT(obj) ||
+       (LIQ(0) == obj && AT(BOTTLE)) ||
+       K == LIQLOC(game.loc) ||
+       (obj == DWARF && ATDWRF(game.loc) > 0))
+       SPK=94;
+    if(game.closed)SPK=138;
+    if(TOTING(obj))SPK=24;
+    return(2011);
+}
+
 /* This stuff was broken off as part of an effort to get the main program
  * to compile without running out of memory.  We're called with a number
  * that says what label the caller wanted to "goto", and we return a
 
 /*  Analyse a verb.  Remember what it was, go back for object if second word
  *  unless verb is "say", which snarfs arbitrary second word.
- *  FIXME: Takes K and VERB as additional inputs.
  */
 
-int action(FILE *input, long STARTAT, long obj) {
+int action(FILE *input, long STARTAT, long verb, long obj) {
+       int kk;
        switch(STARTAT) {
           case 4000: goto L4000;
           case 4090: goto L4090;
@@ -23,15 +82,15 @@ int action(FILE *input, long STARTAT, long obj) {
           }
        BUG(99);
 
-L4000: VERB=K;
-       SPK=ACTSPK[VERB];
-       if(WD2 > 0 && VERB != SAY) return(2800);
-       if(VERB == SAY)obj=WD2;
+L4000: 
+       SPK=ACTSPK[verb];
+       if(WD2 > 0 && verb != SAY) return(2800);
+       if(verb == SAY)obj=WD2;
        if(obj > 0) goto L4090;
 
 /*  Analyse an intransitive verb (ie, no object given yet). */
 
-       switch (VERB-1) {
+       switch (verb-1) {
                case 0: goto L8010;     /* CARRY */
                case 1: return(8000);   /* DROP */
                case 2: return(8000);   /* SAY */
@@ -71,7 +130,7 @@ L4000:       VERB=K;
 
 /*  Analyse a transitive verb. */
 
-L4090: switch (VERB-1) {
+L4090: switch (verb-1) {
                case 0: goto L9010;     /* CARRY */
                case 1: goto L9020;     /* DROP */
                case 2: goto L9030;     /* SAY */
@@ -118,7 +177,7 @@ L4090:      switch (VERB-1) {
 L5000: obj=K;
        if(!HERE(K)) goto L5100;
 L5010: if(WD2 > 0) return(2800);
-       if(VERB != 0) goto L4090;
+       if(verb != 0) goto L4090;
        SETPRM(1,WD1,WD1X);
        RSPEAK(255);
         return(2600);
@@ -142,7 +201,7 @@ L5130:      if(obj != KNIFE || game.knfloc != game.loc) goto L5140;
 L5140: if(obj != ROD || !HERE(ROD2)) goto L5190;
        obj=ROD2;
         goto L5010;
-L5190: if((VERB == FIND || VERB == INVENT) && WD2 <= 0) goto L5010;
+L5190: if((verb == FIND || verb == INVENT) && WD2 <= 0) goto L5010;
        SETPRM(1,WD1,WD1X);
        RSPEAK(256);
         return(2012);
@@ -201,51 +260,23 @@ L9040:    if(obj == CLAM || obj == OYSTER) goto L9046;
        if(obj == GRATE || obj == CHAIN)SPK=31;
        if(SPK != 31 || !HERE(KEYS)) return(2011);
        if(obj == CHAIN) goto L9048;
-       if(!game.closng) goto L9043;
-       K=130;
-       if(!game.panic)game.clock2=15;
-       game.panic=true;
-        return(2010);
-
-L9043: K=34+game.prop[GRATE];
+       if (game.closng) {
+           K=130;
+           if(!game.panic)game.clock2=15;
+           game.panic=true;
+           return(2010);
+       }
+       K=34+game.prop[GRATE];
        game.prop[GRATE]=1;
-       if(VERB == LOCK)game.prop[GRATE]=0;
+       if(verb == LOCK)game.prop[GRATE]=0;
        K=K+2*game.prop[GRATE];
         return(2010);
 
 /*  Clam/Oyster. */
-L9046: K=0;
-       if(obj == OYSTER)K=1;
-       SPK=124+K;
-       if(TOTING(obj))SPK=120+K;
-       if(!TOTING(TRIDNT))SPK=122+K;
-       if(VERB == LOCK)SPK=61;
-       if(SPK != 124) return(2011);
-       DSTROY(CLAM);
-       DROP(OYSTER,game.loc);
-       DROP(PEARL,105);
-        return(2011);
+L9046: return bivalve(verb, obj);
 
 /*  Chain. */
-L9048: if(VERB == LOCK) goto L9049;
-       SPK=171;
-       if(game.prop[BEAR] == 0)SPK=41;
-       if(game.prop[CHAIN] == 0)SPK=37;
-       if(SPK != 171) return(2011);
-       game.prop[CHAIN]=0;
-       game.fixed[CHAIN]=0;
-       if(game.prop[BEAR] != 3)game.prop[BEAR]=2;
-       game.fixed[BEAR]=2-game.prop[BEAR];
-        return(2011);
-
-L9049: SPK=172;
-       if(game.prop[CHAIN] != 0)SPK=34;
-       if(game.loc != PLAC[CHAIN])SPK=173;
-       if(SPK != 172) return(2011);
-       game.prop[CHAIN]=2;
-       if(TOTING(CHAIN))DROP(CHAIN,game.loc);
-       game.fixed[CHAIN]= -1;
-        return(2011);
+L9048:  return chain(verb);
 
 /*  Light.  Applicable only to lamp and urn. */
 
@@ -310,7 +341,7 @@ L9094:      DROP(JADE,game.loc);
 
 /*  Attack also moved into separate module. */
 
-L9120: return(attack(input, obj, VERB));
+L9120: return(attack(input, verb, 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. */
@@ -386,24 +417,17 @@ L9160:    if(obj != LAMP)SPK=76;
        game.tally=game.tally-1;
        DROP(CAVITY,game.loc);
        SPK=216;
-        return(2011);
-
-/*  Throw moved into separate module. */
+       return(2011);
 
-L9170: return(throw(input, obj, VERB));
+L9170: return(throw(input, verb, obj));
 
 /*  Quit.  Intransitive only.  Verify intent and exit if that's what he wants. */
 
 L8180: if(YES(input,22,54,54)) score(1);
         return(2012);
 
-/*  Find.  Might be carrying it, or it might be here.  Else give caveat. */
 
-L9190: if(AT(obj) || (LIQ(0) == obj && AT(BOTTLE)) || K == LIQLOC(game.loc) || (obj ==
-               DWARF && ATDWRF(game.loc) > 0))SPK=94;
-       if(game.closed)SPK=138;
-       if(TOTING(obj))SPK=24;
-        return(2011);
+L9190: return find(obj);
 
 /*  Inventory.  If object, treat same as find.  Else report on current burden. */
 
@@ -437,10 +461,7 @@ L9230:     if(game.prop[ROD2] < 0 || !game.closed) return(2011);
 /*  Score.  Call scoring routine but tell it to return. */
 
 L8240: score(-1);
-       SETPRM(1,SCORE,MXSCOR);
-       SETPRM(3,game.turns,game.turns);
-       RSPEAK(259);
-        return(2012);
+       return(2012);
 
 /*  FEE FIE FOE FOO (AND FUM).  Advance to next state if given in proper order.
  *  Look up WD1 in section 3 of vocab to determine which word we've got.  Last
@@ -518,14 +539,14 @@ L8300:    SPK=201;
        RSPEAK(260);
        if(!YES(input,200,54,54)) return(2012);
        game.saved=game.saved+5;
-       KK= -1;
+       kk= -1;
 
 /*  This next part is shared with the "resume" code.  The two cases are
  *  distinguished by the value of kk (-1 for suspend, +1 for resume). */
 
 L8305: DATIME(&I,&K);
        K=I+650*K;
-       SAVWRD(KK,K);
+       SAVWRD(kk,K);
        K=VRSION;
        SAVWRD(0,K);
        if(K != VRSION) goto L8312;
@@ -540,7 +561,7 @@ L8305:      DATIME(&I,&K);
        SAVWDS(game.knfloc,game.limit,K,game.lmwarn,game.loc,game.newloc,game.numdie);
        SAVWDS(K,game.oldlc2,game.oldloc,game.oldobj,game.panic,game.saved,game.setup);
        SAVWDS(SPK,game.tally,game.thresh,game.trndex,game.trnluz,game.turns,OBJTXT[OYSTER]);
-       SAVWDS(VERB,WD1,WD1X,WD2,game.wzdark,game.zzword,OBJSND[BIRD]);
+       SAVWDS(K,WD1,WD1X,WD2,game.wzdark,game.zzword,OBJSND[BIRD]);
        SAVWDS(OBJTXT[SIGN],game.clshnt,game.novice,K,K,K,K);
        SAVARR(game.abbrev,LOCSIZ);
        SAVARR(game.atloc,LOCSIZ);
@@ -553,17 +574,17 @@ L8305:    DATIME(&I,&K);
        SAVARR(game.odloc,NDWARVES);
        SAVARR(game.place,NOBJECTS);
        SAVARR(game.prop,NOBJECTS);
-       SAVWRD(KK,K);
+       SAVWRD(kk,K);
        if(K != 0) goto L8318;
        K=NUL;
        game.zzword=RNDVOC(3,game.zzword);
-       if(KK > 0) return(8);
+       if(kk > 0) return(8);
        RSPEAK(266);
        exit(0);
 
 /*  Resume.  Read a suspended game back from a file. */
 
-L8310: KK=1;
+L8310: kk=1;
        if(game.loc == 1 && game.abbrev[1] == 1) goto L8305;
        RSPEAK(268);
        if(!YES(input,200,54,54)) return(2012);