X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=actions.c;h=2a223bc9a9e40b42626530ee93d8820937d1d0db;hp=1938d24be054ce6c904e8d0d7247013f23e39c70;hb=7ae0782b2507ebed265e9bd2bb8db6b1ac062411;hpb=704b86afbbf1f60af53a3edd27dafc795674d694 diff --git a/actions.c b/actions.c index 1938d24..2a223bc 100644 --- a/actions.c +++ b/actions.c @@ -5,16 +5,11 @@ #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 @@ -87,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; @@ -110,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). */ @@ -134,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; @@ -153,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); @@ -346,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; @@ -361,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); @@ -389,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; @@ -409,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 { @@ -462,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; @@ -539,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]; @@ -578,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; @@ -764,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); @@ -789,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)) + 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++) { @@ -816,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]); @@ -922,32 +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 wake(token_t verb, token_t obj) @@ -969,7 +967,7 @@ 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; } @@ -986,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. */ @@ -1056,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). */ @@ -1100,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 */ @@ -1113,22 +1112,22 @@ int action(FILE *input, enum speechpart part, long verb, token_t obj) blast(); return GO_CLEAROBJ; case 23: /* SCOR */ - score(scoregame); - return GO_CLEAROBJ; + 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 */ @@ -1136,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: @@ -1210,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 */ @@ -1232,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); } }