X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=actions.c;h=2a223bc9a9e40b42626530ee93d8820937d1d0db;hp=59f9942b6715acf1959362b8a1b9413d7ce1aea6;hb=7ae0782b2507ebed265e9bd2bb8db6b1ac062411;hpb=ff7db8b0c8d61c332cfde95530e8ebb2bb1a0c58 diff --git a/actions.c b/actions.c index 59f9942..2a223bc 100644 --- a/actions.c +++ b/actions.c @@ -5,25 +5,19 @@ #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; @@ -65,7 +59,7 @@ static int attack(FILE *input, long verb, token_t obj) 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); @@ -88,7 +82,7 @@ static int attack(FILE *input, long verb, token_t obj) * 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; @@ -111,7 +105,7 @@ static int attack(FILE *input, long verb, token_t obj) 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). */ @@ -135,7 +129,7 @@ static int bigwords(long foo) } 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; @@ -154,7 +148,7 @@ static int bivalve(token_t verb, token_t obj) 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); @@ -177,7 +171,7 @@ static void blast(void) if (HERE(ROD2)) game.bonus = SPLATTER_MESSAGE; RSPEAK(game.bonus); - score(endgame); + terminate(endgame); } } @@ -347,7 +341,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it) 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; @@ -362,8 +356,8 @@ static int discard(token_t verb, token_t obj, bool just_do_it) } } 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); @@ -390,7 +384,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it) 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; @@ -410,7 +404,7 @@ static int drink(token_t verb, token_t obj) 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 { @@ -463,7 +457,7 @@ static int extinguish(token_t verb, int obj) 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; @@ -540,7 +534,7 @@ int fill(token_t verb, token_t obj) 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]; @@ -558,7 +552,7 @@ int fill(token_t verb, token_t obj) spk = URN_NOPOUR; if (LIQUID() != 0) spk = BOTTLE_FULL; - if (spk == 107) { + if (spk == BOTTLED_WATER) { game.prop[BOTTLE] = MOD(COND[game.loc], 4) / 2 * 2; k = LIQUID(); if (TOTING(BOTTLE)) @@ -579,7 +573,7 @@ static int find(token_t verb, token_t obj) 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; @@ -711,7 +705,7 @@ static int lock(token_t verb, token_t obj) 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; } @@ -732,7 +726,7 @@ static int lock(token_t verb, token_t obj) 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; @@ -765,7 +759,7 @@ static int pour(token_t verb, token_t obj) 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); @@ -790,18 +784,17 @@ static int pour(token_t verb, token_t obj) } } -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++) { @@ -817,11 +810,11 @@ static int read(FILE *input, token_t verb, token_t obj) 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]); @@ -923,39 +916,36 @@ static int throw (FILE *cmdin, long verb, token_t 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) @@ -977,12 +967,12 @@ static int wave(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; } if (HERE(BIRD))spk = FREE_FLY + MOD(game.prop[BIRD], 2); - if (spk == 206 && game.loc == game.place[STEPS] && game.prop[JADE] < 0) { + if (spk == FREE_FLY && game.loc == game.place[STEPS] && game.prop[JADE] < 0) { DROP(JADE, game.loc); game.prop[JADE] = 0; --game.tally; @@ -994,18 +984,18 @@ static int wave(token_t verb, token_t obj) 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. */ @@ -1064,7 +1054,8 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) 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). */ @@ -1108,7 +1099,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) case 16: /* TOSS */ return GO_UNKNOWN; case 17: /* QUIT */ - return quit(input); + return quit(); case 18: /* FIND */ return GO_UNKNOWN; case 19: /* INVEN */ @@ -1121,21 +1112,22 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) 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 */ @@ -1143,7 +1135,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) case 33: /* ZZZZ */ return reservoir(); } - BUG(23); + BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); } /* FALLTHRU */ case transitive: @@ -1217,7 +1209,7 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) 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 */ @@ -1239,13 +1231,13 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) 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); } }