#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
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;
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. */
/* 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. */
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. */
/* 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