X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=actions.c;h=c05cfb0ffd3fd2710776dd6b9ea5b464caa516a5;hp=9ddbb56bde703c52e54c2a378b852c98775d785e;hb=16a175bbabffe66a68eeab1ca4ac0703553fdf56;hpb=eba8015059c1ad2d20e55be9ed69c22aec1871be diff --git a/actions.c b/actions.c index 9ddbb56..c05cfb0 100644 --- a/actions.c +++ b/actions.c @@ -1,5 +1,6 @@ #include #include +#include #include "advent.h" #include "dungeon.h" @@ -171,14 +172,15 @@ static int bigwords(token_t foo) * Look up foo in special section of vocab to determine which word we've got. * Last word zips the eggs back to the giant room (unless already there). */ { - char word[TOKLEN+1]; + char word[TOKLEN + 1]; 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; - rspeak(spk); + if (game.foobar != 0 && game.loc == LOC_GIANTROOM) { + rspeak( START_OVER); + } else { + rspeak(NOTHING_HAPPENS); + } return GO_CLEAROBJ; } else { game.foobar = k; @@ -189,7 +191,7 @@ static int bigwords(token_t foo) game.foobar = 0; if (game.place[EGGS] == objects[EGGS].plac || (TOTING(EGGS) && game.loc == objects[EGGS].plac)) { - rspeak(spk); + rspeak(NOTHING_HAPPENS); return GO_CLEAROBJ; } else { /* Bring back troll if we steal the eggs back from him before @@ -208,38 +210,6 @@ static int bigwords(token_t foo) } } -static int bivalve(token_t verb, token_t obj) -/* Clam/oyster actions */ -{ - bool is_oyster = (obj == OYSTER); - if (verb == LOCK) { - rspeak(HUH_MAN); - return GO_CLEAROBJ; - } - if (!TOTING(TRIDENT)) { - rspeak(is_oyster ? - OYSTER_OPENER : - CLAM_OPENER); - return GO_CLEAROBJ; - } - if (TOTING(obj)) { - rspeak( is_oyster ? - DROP_OYSTER : - DROP_CLAM); - return GO_CLEAROBJ; - } - - if (!is_oyster) { - DESTROY(CLAM); - drop(OYSTER, game.loc); - drop(PEARL, LOC_CULDESAC); - } - rspeak(is_oyster ? - OYSTER_OPENS : - PEARL_FALLS); - return GO_CLEAROBJ; -} - static void blast(void) /* Blast. No effect unless you've got dynamite, which is a neat trick! */ { @@ -393,39 +363,47 @@ static int vcarry(token_t verb, token_t obj) static int chain(token_t verb) /* Do something to the bear's chain */ { - int spk; if (verb != LOCK) { - spk = CHAIN_UNLOCKED; - if (game.prop[BEAR] == UNTAMED_BEAR) - spk = BEAR_BLOCKS; - if (game.prop[CHAIN] == CHAIN_HEAP) - spk = ALREADY_UNLOCKED; - if (spk != CHAIN_UNLOCKED) { - rspeak(spk); + if (game.prop[BEAR] == UNTAMED_BEAR) { + rspeak(BEAR_BLOCKS); + return GO_CLEAROBJ; + } + if (game.prop[CHAIN] == CHAIN_HEAP) { + rspeak(ALREADY_UNLOCKED); return GO_CLEAROBJ; } game.prop[CHAIN] = CHAIN_HEAP; game.fixed[CHAIN] = CHAIN_HEAP; 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] != CHAIN_HEAP) - spk = ALREADY_LOCKED; - if (game.loc != objects[CHAIN].plac) - spk = NO_LOCKSITE; - if (spk != CHAIN_LOCKED) { - rspeak(spk); - return GO_CLEAROBJ; + + switch (game.prop[BEAR]) { + case BEAR_DEAD: + game.fixed[BEAR] = -1; + break; + default: + game.fixed[BEAR] = 0; } - game.prop[CHAIN] = CHAIN_FIXED; - if (TOTING(CHAIN)) - drop(CHAIN, game.loc); - game.fixed[CHAIN] = -1; + rspeak(CHAIN_UNLOCKED); + return GO_CLEAROBJ; } - rspeak(spk); + + if (game.prop[CHAIN] != CHAIN_HEAP) { + rspeak(ALREADY_LOCKED); + return GO_CLEAROBJ; + } + if (game.loc != objects[CHAIN].plac) { + rspeak(NO_LOCKSITE); + return GO_CLEAROBJ; + } + + game.prop[CHAIN] = CHAIN_FIXED; + + if (TOTING(CHAIN)) + drop(CHAIN, game.loc); + game.fixed[CHAIN] = -1; + + rspeak(CHAIN_LOCKED); return GO_CLEAROBJ; } @@ -481,13 +459,12 @@ static int discard(token_t verb, token_t obj, bool just_do_it) DESTROY(BIRD); return GO_CLEAROBJ; } else if (obj == BEAR && AT(TROLL)) { - rspeak(TROLL_SCAMPERS); + state_change(TROLL, TROLL_GONE); move(TROLL, LOC_NOWHERE); move(TROLL + NOBJECTS, LOC_NOWHERE); move(TROLL2, objects[TROLL].plac); move(TROLL2 + NOBJECTS, objects[TROLL].fixd); juggle(CHASM); - game.prop[TROLL] = TROLL_GONE; } else if (obj != VASE || game.loc == objects[PILLOW].plac) { rspeak(OK_MAN); @@ -520,24 +497,30 @@ static int drink(token_t verb, token_t obj) /* Drink. If no object, assume water and look for it here. If water is in * the bottle, drink that, else must be at a water loc, so drink stream. */ { - if (obj == NO_OBJECT && LIQLOC(game.loc) != WATER && (LIQUID() != WATER || - !HERE(BOTTLE))) + if (obj == NO_OBJECT && LIQLOC(game.loc) != WATER && + (LIQUID() != WATER || !HERE(BOTTLE))) { return GO_UNKNOWN; - if (obj != BLOOD) { - if (obj != NO_OBJECT && obj != WATER) { - rspeak(RIDICULOUS_ATTEMPT); - } else if (LIQUID() == WATER && HERE(BOTTLE)) { - game.prop[BOTTLE] = EMPTY_BOTTLE; - game.place[WATER] = LOC_NOWHERE; - rspeak(BOTTLE_EMPTY); - } else { - rspeak(actions[verb].message); - } - } else { + } + + if (obj == BLOOD) { DESTROY(BLOOD); state_change(DRAGON, DRAGON_BLOODLESS); game.blooded = true; + return GO_CLEAROBJ; + } + + if (obj != NO_OBJECT && obj != WATER) { + rspeak(RIDICULOUS_ATTEMPT); + return GO_CLEAROBJ; } + if (LIQUID() == WATER && HERE(BOTTLE)) { + game.prop[BOTTLE] = EMPTY_BOTTLE; + game.place[WATER] = LOC_NOWHERE; + rspeak(BOTTLE_EMPTY); + return GO_CLEAROBJ; + } + + rspeak(actions[verb].message); return GO_CLEAROBJ; } @@ -581,9 +564,7 @@ static int extinguish(token_t verb, int obj) obj = LAMP; if (HERE(URN) && game.prop[URN] == URN_LIT) obj = URN; - if (obj == INTRANSITIVE || - (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT && - HERE(URN) && game.prop[URN] == URN_LIT)) + if (obj == INTRANSITIVE) return GO_UNKNOWN; } @@ -593,20 +574,24 @@ static int extinguish(token_t verb, int obj) } else { pspeak(URN, change, URN_DARK, true); } + return GO_CLEAROBJ; + } - } else if (obj == LAMP) { + if (obj == LAMP) { state_change(LAMP, LAMP_DARK); rspeak(DARK(game.loc) ? PITCH_DARK : NO_MESSAGE); + return GO_CLEAROBJ; + } - } else if (obj == DRAGON || - obj == VOLCANO) { + if (obj == DRAGON || + obj == VOLCANO) { rspeak(BEYOND_POWER); - - } else { - rspeak(actions[verb].message); + return GO_CLEAROBJ; } + + rspeak(actions[verb].message); return GO_CLEAROBJ; } @@ -661,80 +646,102 @@ int fill(token_t verb, token_t obj) /* Fill. Bottle or urn must be empty, and liquid available. (Vase * is nasty.) */ { - int k; - int spk = actions[verb].message; if (obj == VASE) { - spk = ARENT_CARRYING; - if (LIQLOC(game.loc) == 0) - spk = FILL_INVALID; - if (LIQLOC(game.loc) == 0 || - !TOTING(VASE)) { - rspeak(spk); + if (LIQLOC(game.loc) == NO_OBJECT) { + rspeak(FILL_INVALID); + return GO_CLEAROBJ; + } + if (!TOTING(VASE)) { + rspeak(ARENT_CARRYING); return GO_CLEAROBJ; } rspeak(SHATTER_VASE); game.prop[VASE] = VASE_BROKEN; game.fixed[VASE] = -1; return (discard(verb, obj, true)); - } else if (obj == URN) { - spk = FULL_URN; + } + + if (obj == URN) { if (game.prop[URN] != URN_EMPTY) { - rspeak(spk); + rspeak(FULL_URN); return GO_CLEAROBJ; } - spk = FILL_INVALID; - k = LIQUID(); - if (k == 0 || - !HERE(BOTTLE)) { - rspeak(spk); + if (!HERE(BOTTLE)) { + rspeak(FILL_INVALID); return GO_CLEAROBJ; } - game.place[k] = LOC_NOWHERE; - game.prop[BOTTLE] = EMPTY_BOTTLE; - if (k == OIL) + int k = LIQUID(); + switch (k) { + case WATER: + game.prop[BOTTLE] = EMPTY_BOTTLE; + rspeak(WATER_URN); + break; + case OIL: game.prop[URN] = URN_DARK; - spk = WATER_URN + game.prop[URN]; - rspeak(spk); + game.prop[BOTTLE] = EMPTY_BOTTLE; + rspeak(OIL_URN); + break; + case NO_OBJECT: + default: + rspeak(FILL_INVALID); + return GO_CLEAROBJ; + } + game.place[k] = LOC_NOWHERE; return GO_CLEAROBJ; - } else if (obj != NO_OBJECT && obj != BOTTLE) { - rspeak(spk); + } + if (obj != NO_OBJECT && obj != BOTTLE) { + rspeak(actions[verb].message); return GO_CLEAROBJ; - } else if (obj == NO_OBJECT && !HERE(BOTTLE)) + } + if (obj == NO_OBJECT && !HERE(BOTTLE)) return GO_UNKNOWN; - spk = BOTTLED_WATER; - if (LIQLOC(game.loc) == 0) - spk = NO_LIQUID; - if (HERE(URN) && game.prop[URN] != URN_EMPTY) - spk = URN_NOPOUR; - if (LIQUID() != 0) - spk = BOTTLE_FULL; - if (spk == BOTTLED_WATER) { - /* FIXME: Arithmetic on property values */ - game.prop[BOTTLE] = MOD(conditions[game.loc], 4) / 2 * 2; - k = LIQUID(); - if (TOTING(BOTTLE)) - game.place[k] = CARRIED; - if (k == OIL) - spk = BOTTLED_OIL; + + if (HERE(URN) && game.prop[URN] != URN_EMPTY) { + rspeak(URN_NOPOUR); + return GO_CLEAROBJ; } - rspeak(spk); + if (LIQUID() != NO_OBJECT) { + rspeak(BOTTLE_FULL); + return GO_CLEAROBJ; + } + if (LIQLOC(game.loc) == NO_OBJECT) { + rspeak(NO_LIQUID); + return GO_CLEAROBJ; + } + + game.prop[BOTTLE] = (LIQLOC(game.loc) == OIL) ? OIL_BOTTLE : WATER_BOTTLE; + if (TOTING(BOTTLE)) + game.place[LIQUID()] = CARRIED; + if (LIQUID() == OIL) + rspeak(BOTTLED_OIL); + else + rspeak(BOTTLED_WATER); return GO_CLEAROBJ; } static int find(token_t verb, token_t obj) /* Find. Might be carrying it, or it might be here. Else give caveat. */ { - int spk = actions[verb].message; + if (TOTING(obj)) { + rspeak(ALREADY_CARRYING); + return GO_CLEAROBJ; + } + + if (game.closed) { + rspeak(NEEDED_NEARBY); + return GO_CLEAROBJ; + } + if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) || obj == LIQLOC(game.loc) || - (obj == DWARF && atdwrf(game.loc) > 0)) - spk = YOU_HAVEIT; - if (game.closed) - spk = NEEDED_NEARBY; - if (TOTING(obj)) - spk = ALREADY_CARRYING; - rspeak(spk); + (obj == DWARF && atdwrf(game.loc) > 0)) { + rspeak(YOU_HAVEIT); + return GO_CLEAROBJ; + } + + + rspeak(actions[verb].message); return GO_CLEAROBJ; } @@ -777,19 +784,21 @@ static int fly(token_t verb, token_t obj) static int inven(void) /* Inventory. If object, treat same as find. Else report on current burden. */ { - int spk = NO_CARRY; + bool empty = true; for (int i = 1; i <= NOBJECTS; i++) { if (i == BEAR || !TOTING(i)) continue; - if (spk == NO_CARRY) + if (empty) { rspeak(NOW_HOLDING); + empty = false; + } pspeak(i, touch, -1, false); - spk = NO_MESSAGE; } if (TOTING(BEAR)) - spk = TAME_BEAR; - rspeak(spk); + rspeak(TAME_BEAR); + if (empty) + rspeak(NO_CARRY); return GO_CLEAROBJ; } @@ -873,8 +882,7 @@ static int lock(token_t verb, token_t obj) obj = GRATE; if (HERE(CHAIN)) obj = CHAIN; - if (obj == NO_OBJECT || - obj == INTRANSITIVE) { + if (obj == INTRANSITIVE) { rspeak(NOTHING_LOCKED); return GO_CLEAROBJ; } @@ -882,26 +890,17 @@ static int lock(token_t verb, token_t obj) /* Lock, unlock object. Special stuff for opening clam/oyster * and for chain. */ - int spk = actions[verb].message; - if (obj == CLAM || obj == OYSTER) - return bivalve(verb, obj); - if (obj == DOOR) - spk = (game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR; - if (obj == CAGE) - spk = NO_LOCK; - if (obj == KEYS) - spk = CANNOT_UNLOCK; if (obj == GRATE || obj == CHAIN) { - spk = NO_KEYS; if (HERE(KEYS)) { if (obj == CHAIN) return chain(verb); if (game.closng) { - spk = EXIT_CLOSED; + rspeak(EXIT_CLOSED); if (!game.panic) game.clock2 = PANICTIME; game.panic = true; + return GO_CLEAROBJ ; } else { state_change(GRATE, (verb == LOCK) ? GRATE_CLOSED : @@ -909,8 +908,43 @@ static int lock(token_t verb, token_t obj) return GO_CLEAROBJ; } } + rspeak(NO_KEYS); + return GO_CLEAROBJ; } - rspeak(spk); + + switch (obj) { + case CLAM: + if (verb == LOCK) + rspeak(HUH_MAN); + else if (!TOTING(TRIDENT)) + rspeak(OYSTER_OPENER); + else { + DESTROY(CLAM); + drop(OYSTER, game.loc); + drop(PEARL, LOC_CULDESAC); + rspeak(PEARL_FALLS); + } + return GO_CLEAROBJ; + case OYSTER: + if (verb == LOCK) + rspeak(HUH_MAN); + else + rspeak(OYSTER_OPENER); + + return GO_CLEAROBJ; + case DOOR: + rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR); + break; + case CAGE: + rspeak( NO_LOCK); + break; + case KEYS: + rspeak(CANNOT_UNLOCK); + break; + default: + rspeak(actions[verb].message); + } + return GO_CLEAROBJ; } @@ -942,15 +976,15 @@ static int pour(token_t verb, token_t obj) return GO_CLEAROBJ; } if (!AT(DOOR)) { - if (obj != WATER) { + if (obj == WATER) { + /* cycle through the three plant states */ + state_change(PLANT, MOD(game.prop[PLANT] + 1, 3)); + game.prop[PLANT2] = game.prop[PLANT]; + return GO_MOVE; + } else { rspeak(SHAKING_LEAVES); return GO_CLEAROBJ; - } - /* FIXME: Arithmetic on state numbers */ - pspeak(PLANT, look, game.prop[PLANT] + 3, true); - game.prop[PLANT] = MOD(game.prop[PLANT] + 1, 3); - game.prop[PLANT2] = game.prop[PLANT]; - return GO_MOVE; + } } else { state_change(DOOR, (obj == OIL) ? DOOR_UNRUSTED : @@ -983,7 +1017,7 @@ static int read(struct command_t command) } if (DARK(game.loc)) { - rspeak(NO_SEE, command.wd1, command.wd1x); + sspeak(NO_SEE, command.raw1); } else if (command.obj == OYSTER && !game.clshnt && game.closed) { game.clshnt = yes(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]); } else if (objects[command.obj].texts[0] == NULL || @@ -1002,9 +1036,8 @@ static int reservoir(void) rspeak(NOTHING_HAPPENS); return GO_CLEAROBJ; } else { - /* FIXME: Arithmetic on state numbers */ - pspeak(RESER, look, game.prop[RESER] + 1, true); - game.prop[RESER] = 1 - game.prop[RESER]; + state_change(RESER, + game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED); if (AT(RESER)) return GO_CLEAROBJ; else { @@ -1037,13 +1070,11 @@ static int rub(token_t verb, token_t obj) static int say(struct command_t *command) /* Say. Echo WD2 (or WD1 if no WD2 (SAY WHAT?, etc.).) Magic words override. */ { - long a = command->wd1, b = command->wd1x; if (command->wd2 > 0) { - a = command->wd2; - b = command->wd2x; command->wd1 = command->wd2; + strcpy(command->raw1, command->raw2); } - char word1[TOKLEN+1]; + char word1[TOKLEN + 1]; packed_to_token(command->wd1, word1); int wd = (int) get_vocab_id(word1); /* FIXME: magic numbers */ @@ -1056,7 +1087,7 @@ static int say(struct command_t *command) wordclear(&command->wd2); return GO_LOOKUP; } - rspeak(OKEY_DOKEY, a, b); + sspeak(OKEY_DOKEY, command->raw1); return GO_CLEAROBJ; } @@ -1183,9 +1214,8 @@ static int wave(token_t verb, token_t obj) CAGE_FLY : FREE_FLY); - /* FIXME: Arithemetic on property values */ - game.prop[FISSURE] = 1 - game.prop[FISSURE]; - pspeak(FISSURE, look, 2 - game.prop[FISSURE], true); + state_change(FISSURE, + game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED); return GO_CLEAROBJ; } } @@ -1240,7 +1270,7 @@ int action(struct command_t *command) command->verb == INVENTORY) && command->wd2 <= 0) /* FALL THROUGH */; else { - rspeak(NO_SEE, command->wd1, command->wd1x); + sspeak(NO_SEE, command->raw1); return GO_CLEAROBJ; } @@ -1437,7 +1467,7 @@ int action(struct command_t *command) } case unknown: /* Unknown verb, couldn't deduce object - might need hint */ - rspeak(WHAT_DO, command->wd1, command->wd1x); + sspeak(WHAT_DO, command->raw1); return GO_CHECKHINT; default: BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE