#include "newdb.h"
/* Limit visibility of ugly globals. Eventually these should go away. */
-extern long WD1, WD1X, WD2, WD2X;
+extern token_t WD1, WD1X, WD2, WD2X;
-/*
- * Action handlers. Eventually we'll do lookup through a method table
- * that calls these.
- */
-
-static int fill(token_t verb, token_t);
+static int fill(token_t, token_t);
-static int attack(FILE *input, long verb, token_t obj)
+static int attack(FILE *input, token_t verb, token_t obj)
/* Attack. Assume target if unambiguous. "Throw" also links here.
* Attackable objects fall into two categories: enemies (snake,
* dwarf, etc.) and others (bird, clam, machine). Ambiguous if 2
* enemies, or no enemies but 2 others. */
{
int spk = ACTSPK[verb];
- int d = ATDWRF(game.loc);
- if (obj == 0) {
- if (d > 0)
+ if (obj == 0 || obj == INTRANSITIVE) {
+ if (ATDWRF(game.loc) > 0)
obj = DWARF;
if (HERE(SNAKE))obj = obj * NOBJECTS + SNAKE;
if (AT(DRAGON) && game.prop[DRAGON] == 0)obj = obj * NOBJECTS + DRAGON;
if (obj == DRAGON)spk = ALREADY_DEAD;
if (obj == TROLL)spk = ROCKY_TROLL;
if (obj == OGRE)spk = OGRE_DODGE;
- if (obj == OGRE && d > 0) {
+ if (obj == OGRE && ATDWRF(game.loc) > 0) {
RSPEAK(spk);
RSPEAK(KNIFE_THROWN);
DESTROY(OGRE);
* too. Then do a null motion to get new description. */
RSPEAK(BARE_HANDS_QUERY);
GETIN(input, &WD1, &WD1X, &WD2, &WD2X);
- if (WD1 != MAKEWD(25) && WD1 != MAKEWD(250519))
+ if (WD1 != MAKEWD(WORD_YINIT) && WD1 != MAKEWD(WORD_YES))
return GO_CHECKFOO;
PSPEAK(DRAGON, 3);
game.prop[DRAGON] = 1;
return GO_CLEAROBJ;
}
-static int bigwords(long foo)
+static int bigwords(token_t foo)
/* 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
* word zips the eggs back to the giant room (unless already there). */
} else {
/* Bring back troll if we steal the eggs back from him before
* crossing. */
- if (game.place[EGGS] == 0 && game.place[TROLL] == 0 && game.prop[TROLL] == 0)
+ if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == 0)
game.prop[TROLL] = 1;
k = 2;
if (HERE(EGGS))k = 1;
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 (!TOTING(TRIDENT))spk = is_oyster ? OYSTER_OPENER : CLAM_OPENER;
if (verb == LOCK)spk = HUH_MAN;
if (spk == PEARL_FALLS) {
DESTROY(CLAM);
if (HERE(ROD2))
game.bonus = SPLATTER_MESSAGE;
RSPEAK(game.bonus);
- score(endgame);
+ terminate(endgame);
}
}
RSPEAK(GEM_FITS);
game.prop[obj] = 1;
game.prop[CAVITY] = 0;
- if (HERE(RUG) && ((obj == EMRALD && game.prop[RUG] != 2) || (obj == RUBY &&
+ if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != 2) || (obj == RUBY &&
game.prop[RUG] == 2))) {
spk = RUG_RISES;
if (TOTING(RUG))spk = RUG_WIGGLES;
}
} else if (obj == COINS && HERE(VEND)) {
DESTROY(COINS);
- DROP(BATTER, game.loc);
- PSPEAK(BATTER, 0);
+ DROP(BATTERY, game.loc);
+ PSPEAK(BATTERY, 0);
return GO_CLEAROBJ;
} else if (obj == BIRD && AT(DRAGON) && game.prop[DRAGON] == 0) {
RSPEAK(BIRD_BURNT);
int k = LIQUID();
if (k == obj)obj = BOTTLE;
if (obj == BOTTLE && k != 0)
- game.place[k] = NOWHERE;
+ game.place[k] = LOC_NOWHERE;
if (obj == CAGE && game.prop[BIRD] == 1)DROP(BIRD, game.loc);
DROP(obj, game.loc);
if (obj != BIRD) return GO_CLEAROBJ;
if (obj != 0 && obj != WATER)spk = RIDICULOUS_ATTEMPT;
if (spk != RIDICULOUS_ATTEMPT && LIQUID() == WATER && HERE(BOTTLE)) {
game.prop[BOTTLE] = 1;
- game.place[WATER] = NOWHERE;
+ game.place[WATER] = LOC_NOWHERE;
spk = BOTTLE_EMPTY;
}
} else {
game.prop[LAMP] = 0;
RSPEAK(LAMP_OFF);
spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE;
- } else if (obj == DRAGON || obj == VOLCAN)
+ } else if (obj == DRAGON || obj == VOLCANO)
spk = BEYOND_POWER;
RSPEAK(spk);
return GO_CLEAROBJ;
RSPEAK(spk);
return GO_CLEAROBJ;
}
- game.place[k] = NOWHERE;
+ game.place[k] = LOC_NOWHERE;
game.prop[BOTTLE] = 1;
if (k == OIL)game.prop[URN] = 1;
spk = WATER_URN + game.prop[URN];
obj == LIQLOC(game.loc) ||
(obj == DWARF && ATDWRF(game.loc) > 0))
spk = YOU_HAVEIT;
- if (game.closed)spk = NEEDED_NEreplace;
+ if (game.closed)spk = NEEDED_NEARBY;
if (TOTING(obj))spk = ALREADY_CARRYING;
RSPEAK(spk);
return GO_CLEAROBJ;
if (AT(GRATE))obj = GRATE;
if (obj != 0 && HERE(CHAIN)) return GO_UNKNOWN;
if (HERE(CHAIN))obj = CHAIN;
- if (obj == 0) {
+ if (obj == 0 || obj == INTRANSITIVE) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
return chain(verb);
if (game.closng) {
spk = EXIT_CLOSED;
- if (!game.panic)game.clock2 = 15;
+ if (!game.panic)game.clock2 = PANICTIME;
game.panic = true;
} else {
spk = game.prop[GRATE] ? GRATE_LOCKED : ALREADY_LOCKED;
if (HERE(URN) && game.prop[URN] == 0)
return fill(verb, URN);
game.prop[BOTTLE] = 1;
- game.place[obj] = NOWHERE;
+ game.place[obj] = LOC_NOWHERE;
spk = GROUND_WET;
if (!(AT(PLANT) || AT(DOOR))) {
RSPEAK(spk);
}
}
-static int quit(FILE *input)
+static int quit(void)
/* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
{
- if (YES(input, REALLY_QUIT, OK_MAN, OK_MAN))
- score(quitgame);
+ if (YES(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
+ terminate(quitgame);
return GO_CLEAROBJ;
}
-static int read(FILE *input, token_t verb, token_t obj)
+static int read(token_t verb, token_t obj)
/* Read. Print stuff based on objtxt. Oyster (?) is special case. */
{
- int spk = ACTSPK[verb];
if (obj == INTRANSITIVE) {
obj = 0;
for (int i = 1; i <= NOBJECTS; i++) {
return GO_CLEAROBJ;
}
if (OBJTXT[obj] == 0 || game.prop[obj] < 0) {
- RSPEAK(spk);
+ RSPEAK(ACTSPK[verb]);
return GO_CLEAROBJ;
}
if (obj == OYSTER && !game.clshnt) {
- game.clshnt = YES(input, CLUE_QUERY, WAYOUT_CLUE, OK_MAN);
+ game.clshnt = YES(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
return GO_CLEAROBJ;
}
PSPEAK(obj, OBJTXT[obj] + game.prop[obj]);
}
if (obj != AXE)
return (discard(verb, obj, false));
- int i = ATDWRF(game.loc);
- if (i <= 0) {
- if (AT(DRAGON) && game.prop[DRAGON] == 0)
- return throw_support(DRAGON_SCALES);
- if (AT(TROLL))
- return throw_support(TROLL_RETURNS);
- else if (AT(OGRE))
- return throw_support(OGRE_DODGE);
- else if (HERE(BEAR) && game.prop[BEAR] == 0) {
- /* This'll teach him to throw the axe at the bear! */
- DROP(AXE, game.loc);
- game.fixed[AXE] = -1;
- game.prop[AXE] = 1;
- JUGGLE(BEAR);
- RSPEAK(AXE_LOST);
- return GO_CLEAROBJ;
+ else {
+ int i = ATDWRF(game.loc);
+ if (i <= 0) {
+ if (AT(DRAGON) && game.prop[DRAGON] == 0)
+ return throw_support(DRAGON_SCALES);
+ if (AT(TROLL))
+ return throw_support(TROLL_RETURNS);
+ else if (AT(OGRE))
+ return throw_support(OGRE_DODGE);
+ else if (HERE(BEAR) && game.prop[BEAR] == 0) {
+ /* This'll teach him to throw the axe at the bear! */
+ DROP(AXE, game.loc);
+ game.fixed[AXE] = -1;
+ game.prop[AXE] = 1;
+ JUGGLE(BEAR);
+ RSPEAK(AXE_LOST);
+ return GO_CLEAROBJ;
+ }
+ return (attack(cmdin, verb, 0));
}
- return (attack(cmdin, verb, 0));
- }
- if (randrange(NDWARVES + 1) < game.dflag) {
- return throw_support(DWARF_DODGES);
+ if (randrange(NDWARVES + 1) < game.dflag) {
+ return throw_support(DWARF_DODGES);
+ } else {
+ game.dseen[i] = false;
+ game.dloc[i] = 0;
+ return throw_support((++game.dkill == 1)
+ ? DWARF_SMOKE : KILLED_DWARF);
+ }
}
- game.dseen[i] = false;
- game.dloc[i] = 0;
- return throw_support((++game.dkill == 1) ? DWARF_SMOKE : KILLED_DWARF);
-}
-
-static int vscore(void)
-/* Score. Call scoring routine but tell it to return. */
-{
- score(scoregame);
- return GO_CLEAROBJ;
}
static int wake(token_t verb, token_t obj)
if ((!TOTING(obj)) && (obj != ROD || !TOTING(ROD2)))spk = ARENT_CARRYING;
if (obj != ROD ||
!TOTING(obj) ||
- (!HERE(BIRD) && (game.closng || !AT(FISSUR)))) {
+ (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
RSPEAK(spk);
return GO_DWARFWAKE;
}
- if (game.closng || !AT(FISSUR)) {
+ if (game.closng || !AT(FISSURE)) {
RSPEAK(spk);
return GO_CLEAROBJ;
}
if (HERE(BIRD))RSPEAK(spk);
- game.prop[FISSUR] = 1 - game.prop[FISSUR];
- PSPEAK(FISSUR, 2 - game.prop[FISSUR]);
+ game.prop[FISSURE] = 1 - game.prop[FISSURE];
+ PSPEAK(FISSURE, 2 - game.prop[FISSURE]);
return GO_CLEAROBJ;
}
}
-int action(FILE *input, enum speechpart part, long verb, token_t obj)
+int action(FILE *input, enum speechpart part, token_t verb, token_t obj)
/* Analyse a verb. Remember what it was, go back for object if second word
* unless verb is "say", which snarfs arbitrary second word.
*/
switch (part) {
case intransitive:
- if (WD2 > 0 && verb != SAY) return (2800);
+ if (WD2 > 0 && verb != SAY)
+ return GO_WORD2;
if (verb == SAY)obj = WD2;
if (obj == 0 || obj == INTRANSITIVE) {
/* Analyse an intransitive verb (ie, no object given yet). */
case 16: /* TOSS */
return GO_UNKNOWN;
case 17: /* QUIT */
- return quit(input);
+ return quit();
case 18: /* FIND */
return GO_UNKNOWN;
case 19: /* INVEN */
blast();
return GO_CLEAROBJ;
case 23: /* SCOR */
- return vscore();
+ score(scoregame);
+ return GO_CLEAROBJ;
case 24: /* FOO */
return bigwords(WD1);
case 25: /* BRIEF */
return brief();
case 26: /* READ */
- return read(input, verb, INTRANSITIVE);
+ return read(verb, INTRANSITIVE);
case 27: /* BREAK */
return GO_UNKNOWN;
case 28: /* WAKE */
return GO_UNKNOWN;
case 29: /* SUSP */
- return suspend(input);
+ return suspend();
case 30: /* RESU */
- return resume(input);
+ return resume();
case 31: /* FLY */
return fly(verb, INTRANSITIVE);
case 32: /* LISTE */
case 33: /* ZZZZ */
return reservoir();
}
- BUG(23);
+ BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
}
/* FALLTHRU */
case transitive:
return GO_CLEAROBJ;
}
case 26: /* READ */
- return read(input, verb, obj);
+ return read(verb, obj);
case 27: /* BREAK */
return vbreak(verb, obj);
case 28: /* WAKE */
case 33: /* ZZZZ */
return reservoir();
}
- BUG(24);
+ BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST);
case unknown:
/* Unknown verb, couldn't deduce object - might need hint */
SETPRM(1, WD1, WD1X);
RSPEAK(WHAT_DO);
return GO_CHECKHINT;
default:
- BUG(99);
+ BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN);
}
}