X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=actions.c;h=07644abf893ec6e8c888f64650bc68de6bd75919;hb=3f580acc0565587e4fab1f2181f4ff859e9c3aef;hp=16d303f10d60c216b128eca5a17af5ec2e9ee2a7;hpb=6521d49c0752da0bf65769a1d38b583d3a2a1854;p=open-adventure.git diff --git a/actions.c b/actions.c index 16d303f..07644ab 100644 --- a/actions.c +++ b/actions.c @@ -1,12 +1,17 @@ #include #include #include "advent.h" -#include "database.h" -#include "newdb.h" +#include "dungeon.h" static int fill(token_t, token_t); -static int attack(FILE *input, struct command_t *command) +static void state_change(long obj, long state) +{ + game.prop[obj] = state; + pspeak(obj, change, state); +} + +static int attack(struct command_t *command) /* 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 @@ -14,7 +19,7 @@ static int attack(FILE *input, struct command_t *command) { vocab_t verb = command->verb; vocab_t obj = command->obj; - int spk = actions[verb].message; + long spk = actions[verb].message; if (obj == 0 || obj == INTRANSITIVE) { if (atdwrf(game.loc) > 0) obj = DWARF; @@ -22,7 +27,8 @@ static int attack(FILE *input, struct command_t *command) if (AT(DRAGON) && game.prop[DRAGON] == 0)obj = obj * NOBJECTS + DRAGON; if (AT(TROLL))obj = obj * NOBJECTS + TROLL; if (AT(OGRE))obj = obj * NOBJECTS + OGRE; - if (HERE(BEAR) && game.prop[BEAR] == 0)obj = obj * NOBJECTS + BEAR; + if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) + obj = obj * NOBJECTS + BEAR; if (obj > NOBJECTS) return GO_UNKNOWN; if (obj == 0) { /* Can't attack bird or machine by throwing axe. */ @@ -44,9 +50,8 @@ static int attack(FILE *input, struct command_t *command) DESTROY(BIRD); spk = BIRD_DEAD; } else if (obj == VEND) { - bool blocking = (game.prop[VEND] == VEND_BLOCKS); - game.prop[VEND] = blocking ? VEND_UNBLOCKS : VEND_BLOCKS; - rspeak(blocking ? MACHINE_SWINGOUT : MACHINE_SWINGBACK); + state_change(VEND, + game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS); return GO_CLEAROBJ; } @@ -80,9 +85,14 @@ static int attack(FILE *input, struct command_t *command) * fixed), move rug there (not fixed), and move him there, * too. Then do a null motion to get new description. */ rspeak(BARE_HANDS_QUERY); - GETIN(input, &command->wd1, &command->wd1x, &command->wd2, &command->wd2x); - if (command->wd1 != MAKEWD(WORD_YINIT) && command->wd1 != MAKEWD(WORD_YES)) + if (silent_yes()) { + // FIXME: setting wd1 is a workaround for broken logic + command->wd1 = token_to_packed("Y"); + } else { + // FIXME: setting wd1 is a workaround for broken logic + command->wd1 = token_to_packed("N"); return GO_CHECKFOO; + } pspeak(DRAGON, look, 3); game.prop[DRAGON] = 1; game.prop[RUG] = 0; @@ -109,7 +119,10 @@ static int bigwords(token_t foo) * Look up foo 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). */ { - int k = vocab(foo, 3); + //int k = vocab(foo, 3); + char word[6]; + packed_to_token(foo, word); + int k = (int) get_special_vocab_id(word); int spk = NOTHING_HAPPENS; if (game.foobar != 1 - k) { if (game.foobar != 0 && game.loc == LOC_GIANTROOM)spk = START_OVER; @@ -224,8 +237,10 @@ static int vcarry(token_t verb, token_t obj) } spk = YOU_JOKING; if (obj == PLANT && game.prop[PLANT] <= 0)spk = DEEP_ROOTS; - if (obj == BEAR && game.prop[BEAR] == 1)spk = BEAR_CHAINED; - if (obj == CHAIN && game.prop[BEAR] != 0)spk = STILL_LOCKED; + if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR) + spk = BEAR_CHAINED; + if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR) + spk = STILL_LOCKED; if (obj == URN)spk = URN_NOBUDGE; if (obj == CAVITY)spk = DOUGHNUT_HOLES; if (obj == BLOOD)spk = FEW_DROPS; @@ -246,7 +261,7 @@ static int vcarry(token_t verb, token_t obj) return (fill(verb, BOTTLE)); else { if (game.prop[BOTTLE] != EMPTY_BOTTLE) - spk = BOTTLE_FULL; + spk = BOTTLE_FULL; if (!TOTING(BOTTLE))spk = NO_CONTAINER; rspeak(spk); return GO_CLEAROBJ; @@ -280,7 +295,7 @@ static int vcarry(token_t verb, token_t obj) game.place[LIQUID()] = CARRIED; if (GSTONE(obj) && game.prop[obj] != 0) { game.prop[obj] = 0; - game.prop[CAVITY] = 1; + game.prop[CAVITY] = CAVITY_EMPTY; } rspeak(OK_MAN); return GO_CLEAROBJ; @@ -292,26 +307,33 @@ static int chain(token_t verb) int spk; if (verb != LOCK) { spk = CHAIN_UNLOCKED; - if (game.prop[BEAR] == 0)spk = BEAR_BLOCKS; - if (game.prop[CHAIN] == 0)spk = ALREADY_UNLOCKED; + if (game.prop[BEAR] == UNTAMED_BEAR) + spk = BEAR_BLOCKS; + if (game.prop[CHAIN] == 0) + spk = ALREADY_UNLOCKED; if (spk != CHAIN_UNLOCKED) { rspeak(spk); return GO_CLEAROBJ; } game.prop[CHAIN] = 0; game.fixed[CHAIN] = 0; - if (game.prop[BEAR] != 3)game.prop[BEAR] = 2; + if (game.prop[BEAR] != BEAR_DEAD) + game.prop[BEAR] = CONTENTED_BEAR; + /* FIXME: Arithmetic on state numbers */ game.fixed[BEAR] = 2 - game.prop[BEAR]; } else { spk = CHAIN_LOCKED; - if (game.prop[CHAIN] != 0)spk = ALREADY_LOCKED; - if (game.loc != objects[CHAIN].plac)spk = NO_LOCKSITE; + if (game.prop[CHAIN] != 0) + spk = ALREADY_LOCKED; + if (game.loc != objects[CHAIN].plac) + spk = NO_LOCKSITE; if (spk != CHAIN_LOCKED) { rspeak(spk); return GO_CLEAROBJ; } game.prop[CHAIN] = 2; - if (TOTING(CHAIN))drop(CHAIN, game.loc); + if (TOTING(CHAIN)) + drop(CHAIN, game.loc); game.fixed[CHAIN] = -1; } rspeak(spk); @@ -335,12 +357,12 @@ static int discard(token_t verb, token_t obj, bool just_do_it) if (game.closed) return GO_DWARFWAKE; DESTROY(SNAKE); /* Set game.prop for use by travel options */ - game.prop[SNAKE] = 1; + game.prop[SNAKE] = SNAKE_CHASED; - } else if ((GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != 0)) { + } else if ((GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL)) { rspeak(GEM_FITS); game.prop[obj] = 1; - game.prop[CAVITY] = 0; + game.prop[CAVITY] = CAVITY_FULL; if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != 2) || (obj == RUBY && game.prop[RUG] == 2))) { spk = RUG_RISES; @@ -385,12 +407,12 @@ static int discard(token_t verb, token_t obj, bool just_do_it) if (obj == BOTTLE && k != 0) game.place[k] = LOC_NOWHERE; if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) - drop(BIRD, game.loc); + drop(BIRD, game.loc); drop(obj, game.loc); if (obj != BIRD) return GO_CLEAROBJ; game.prop[BIRD] = BIRD_UNCAGED; if (FOREST(game.loc)) - game.prop[BIRD] = BIRD_FOREST_UNCAGED; + game.prop[BIRD] = BIRD_FOREST_UNCAGED; return GO_CLEAROBJ; } @@ -447,7 +469,7 @@ static int extinguish(token_t verb, int obj) int spk = actions[verb].message; if (obj == INTRANSITIVE) { if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT) - obj = LAMP; + obj = LAMP; if (HERE(URN) && game.prop[URN] == 2)obj = obj * NOBJECTS + URN; if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN; } @@ -456,8 +478,7 @@ static int extinguish(token_t verb, int obj) game.prop[URN] = game.prop[URN] / 2; spk = URN_DARK; } else if (obj == LAMP) { - game.prop[LAMP] = LAMP_DARK; - rspeak(LAMP_OFF); + state_change(LAMP, LAMP_DARK); spk = DARK(game.loc) ? PITCH_DARK : NO_MESSAGE; } else if (obj == DRAGON || obj == VOLCANO) spk = BEYOND_POWER; @@ -487,11 +508,13 @@ static int feed(token_t verb, token_t obj) spk = REALLY_MAD; } } else if (obj == BEAR) { - if (game.prop[BEAR] == 0)spk = NOTHING_EDIBLE; - if (game.prop[BEAR] == 3)spk = RIDICULOUS_ATTEMPT; + if (game.prop[BEAR] == UNTAMED_BEAR) + spk = NOTHING_EDIBLE; + if (game.prop[BEAR] == BEAR_DEAD) + spk = RIDICULOUS_ATTEMPT; if (HERE(FOOD)) { DESTROY(FOOD); - game.prop[BEAR] = 1; + game.prop[BEAR] = SITTING_BEAR; game.fixed[AXE] = 0; game.prop[AXE] = 0; spk = BEAR_TAMED; @@ -554,7 +577,7 @@ int fill(token_t verb, token_t obj) if (LIQUID() != 0) spk = BOTTLE_FULL; if (spk == BOTTLED_WATER) { - /* FIXME: Arithmetic on property values */ + /* FIXME: Arithmetic on property values */ game.prop[BOTTLE] = MOD(conditions[game.loc], 4) / 2 * 2; k = LIQUID(); if (TOTING(BOTTLE)) @@ -640,7 +663,7 @@ static int light(token_t verb, token_t obj) int spk = actions[verb].message; if (obj == INTRANSITIVE) { if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) - obj = LAMP; + obj = LAMP; if (HERE(URN) && game.prop[URN] == 1)obj = obj * NOBJECTS + URN; if (obj == INTRANSITIVE || obj == 0 || obj > NOBJECTS) return GO_UNKNOWN; } @@ -663,8 +686,7 @@ static int light(token_t verb, token_t obj) rspeak(spk); return GO_CLEAROBJ; } - game.prop[LAMP] = LAMP_BRIGHT; - rspeak(LAMP_ON); + state_change(LAMP, LAMP_BRIGHT); if (game.wzdark) return GO_TOP; else @@ -681,20 +703,21 @@ static int listen(void) if (k != SILENT) { rspeak(k); if (locations[game.loc].loud) - return GO_CLEAROBJ; - else - spk = NO_MESSAGE; + return GO_CLEAROBJ; + else + spk = NO_MESSAGE; } for (int i = 1; i <= NOBJECTS; i++) { if (!HERE(i) || objects[i].sounds[0] == NULL || game.prop[i] < 0) continue; - int mi = game.prop[i]; - if (i == BIRD) - mi += 3 * game.blooded; - pspeak(i, hear, mi, game.zzword); + int mi = game.prop[i]; + if (i == BIRD) + mi += 3 * game.blooded; + long packed_zzword = token_to_packed(game.zzword); + pspeak(i, hear, mi, packed_zzword); spk = NO_MESSAGE; - /* FIXME: Magic number, sensitive to bird state logic */ - if (i == BIRD && game.prop[i] == 5) + /* FIXME: Magic number, sensitive to bird state logic */ + if (i == BIRD && game.prop[i] == 5) DESTROY(BIRD); } rspeak(spk); @@ -737,8 +760,8 @@ static int lock(token_t verb, token_t obj) if (!game.panic)game.clock2 = PANICTIME; game.panic = true; } else { - game.prop[GRATE] = (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN; - spk = game.prop[GRATE] ? GRATE_UNLOCKED : GRATE_LOCKED; + state_change(GRATE, (verb == LOCK) ? GRATE_CLOSED : GRATE_OPEN); + return GO_CLEAROBJ; } } } @@ -869,7 +892,10 @@ static int say(struct command_t *command) b = command->wd2x; command->wd1 = command->wd2; } - int wd = vocab(command->wd1, -1); + //int wd = vocab(command->wd1, -1); + char word1[6]; + packed_to_token(command->wd1, word1); + int wd = (int) get_vocab_id(word1); /* FIXME: Magic numbers */ if (wd == 62 || wd == 65 || wd == 71 || wd == 2025 || wd == 2034) { /* FIXME: scribbles on the interpreter's command block */ @@ -887,7 +913,7 @@ static int throw_support(long spk) return GO_MOVE; } -static int throw (FILE *cmdin, struct command_t *command) +static int throw (struct command_t *command) /* Throw. Same as discard unless axe. Then same as attack except * ignore bird, and if dwarf is present then one might be killed. * (Only way to do so!) Axe also special for dragon, bear, and @@ -927,7 +953,7 @@ static int throw (FILE *cmdin, struct command_t *command) return throw_support(TROLL_RETURNS); else if (AT(OGRE)) return throw_support(OGRE_DODGE); - else if (HERE(BEAR) && game.prop[BEAR] == 0) { + else if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) { /* This'll teach him to throw the axe at the bear! */ drop(AXE, game.loc); game.fixed[AXE] = -1; @@ -937,7 +963,7 @@ static int throw (FILE *cmdin, struct command_t *command) return GO_CLEAROBJ; } command->obj = 0; - return (attack(cmdin, command)); + return (attack(command)); } if (randrange(NDWARVES + 1) < game.dflag) { @@ -976,7 +1002,7 @@ static int wave(token_t verb, token_t obj) } /* FIXME: Arithemetic on proprty values */ if (HERE(BIRD)) - spk = FREE_FLY + MOD(game.prop[BIRD], 2); + spk = FREE_FLY + MOD(game.prop[BIRD], 2); if (spk == FREE_FLY && game.loc == game.place[STEPS] && game.prop[JADE] < 0) { drop(JADE, game.loc); game.prop[JADE] = 0; @@ -1000,7 +1026,7 @@ static int wave(token_t verb, token_t obj) } } -int action(FILE *input, struct command_t *command) +int action(struct command_t *command) /* Analyse a verb. Remember what it was, go back for object if second word * unless verb is "say", which snarfs arbitrary second word. */ @@ -1057,7 +1083,7 @@ int action(FILE *input, struct command_t *command) switch (command->part) { case intransitive: if (command->wd2 > 0 && command->verb != SAY) - return GO_WORD2; + return GO_WORD2; if (command->verb == SAY)command->obj = command->wd2; if (command->obj == 0 || command->obj == INTRANSITIVE) { /* Analyse an intransitive verb (ie, no object given yet). */ @@ -1089,7 +1115,7 @@ int action(FILE *input, struct command_t *command) return GO_CLEAROBJ; } case ATTACK: - return attack(input, command); + return attack(command); case POUR: return pour(command->verb, command->obj); case EAT: @@ -1121,7 +1147,7 @@ int action(FILE *input, struct command_t *command) case BRIEF: return brief(); case READ: - command->obj = INTRANSITIVE; + command->obj = INTRANSITIVE; return read(*command); case BREAK: return GO_UNKNOWN; @@ -1137,8 +1163,8 @@ int action(FILE *input, struct command_t *command) return listen(); case PART: return reservoir(); - default: - BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE + default: + BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE } } /* FALLTHRU */ @@ -1169,12 +1195,12 @@ int action(FILE *input, struct command_t *command) rspeak(spk); return GO_CLEAROBJ; } - case GO: { + case GO: { rspeak(spk); return GO_CLEAROBJ; } case ATTACK: - return attack(input, command); + return attack(command); case POUR: return pour(command->verb, command->obj); case EAT: @@ -1184,7 +1210,7 @@ int action(FILE *input, struct command_t *command) case RUB: return rub(command->verb, command->obj); case THROW: - return throw(input, command); + return throw (command); case QUIT: { rspeak(spk); return GO_CLEAROBJ; @@ -1232,11 +1258,11 @@ int action(FILE *input, struct command_t *command) rspeak(spk); return GO_CLEAROBJ; } - case PART: + case PART: return reservoir(); - default: - BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE - } + default: + BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE + } case unknown: /* Unknown verb, couldn't deduce object - might need hint */ rspeak(WHAT_DO, command->wd1, command->wd1x);