X-Git-Url: https://jxself.org/git/?p=open-adventure.git;a=blobdiff_plain;f=actions.c;h=fdd1c9341e1fb911ac000fbe6241699638115dc5;hp=c05cfb0ffd3fd2710776dd6b9ea5b464caa516a5;hb=92de4856a6b7f9889e72faa1fc30a78526a97758;hpb=16a175bbabffe66a68eeab1ca4ac0703553fdf56 diff --git a/actions.c b/actions.c index c05cfb0..fdd1c93 100644 --- a/actions.c +++ b/actions.c @@ -21,7 +21,6 @@ static int attack(struct command_t *command) vocab_t verb = command->verb; vocab_t obj = command->obj; - long spk = actions[verb].message; if (obj == NO_OBJECT || obj == INTRANSITIVE) { int changes = 0; @@ -69,69 +68,41 @@ static int attack(struct command_t *command) } if (changes >= 2) return GO_UNKNOWN; - } + if (obj == BIRD) { if (game.closed) { rspeak(UNHAPPY_BIRD); - return GO_CLEAROBJ; + } else { + DESTROY(BIRD); + rspeak(BIRD_DEAD); } - DESTROY(BIRD); - spk = BIRD_DEAD; - } else if (obj == VEND) { + return GO_CLEAROBJ; + } + if (obj == VEND) { state_change(VEND, game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS); return GO_CLEAROBJ; } - if (obj == NO_OBJECT) - spk = NO_TARGET; - if (obj == CLAM || - obj == OYSTER) - spk = SHELL_IMPERVIOUS; - if (obj == SNAKE) - spk = SNAKE_WARNING; - if (obj == DWARF) - spk = BARE_HANDS_QUERY; - if (obj == DWARF && game.closed) - return GO_DWARFWAKE; - if (obj == DRAGON) - spk = ALREADY_DEAD; - if (obj == TROLL) - spk = ROCKY_TROLL; - if (obj == OGRE) - spk = OGRE_DODGE; - if (obj == OGRE && atdwrf(game.loc) > 0) { - rspeak(spk); - rspeak(KNIFE_THROWN); - DESTROY(OGRE); - int dwarves = 0; - for (int i = 1; i < PIRATE; i++) { - if (game.dloc[i] == game.loc) { - ++dwarves; - game.dloc[i] = LOC_LONGWEST; - game.dseen[i] = false; - } - } - spk = (dwarves > 1) ? - OGRE_PANIC1 : - OGRE_PANIC2; - } else if (obj == BEAR) { + if (obj == BEAR) { switch (game.prop[BEAR]) { case UNTAMED_BEAR: - spk = BEAR_HANDS; + rspeak(BEAR_HANDS); break; case SITTING_BEAR: - spk = BEAR_CONFUSED; + rspeak(BEAR_CONFUSED); break; case CONTENTED_BEAR: - spk = BEAR_CONFUSED; + rspeak(BEAR_CONFUSED); break; case BEAR_DEAD: - spk = ALREADY_DEAD; + rspeak(ALREADY_DEAD); break; } - } else if (obj == DRAGON && game.prop[DRAGON] == DRAGON_BARS) { + return GO_CLEAROBJ; + } + if (obj == DRAGON && game.prop[DRAGON] == DRAGON_BARS) { /* Fun stuff for dragon. If he insists on attacking it, win! * Set game.prop to dead, move dragon to central loc (still * fixed), move rug there (not fixed), and move him there, @@ -163,7 +134,53 @@ static int attack(struct command_t *command) return GO_MOVE; } - rspeak(spk); + if (obj == OGRE) { + rspeak(OGRE_DODGE); + if (atdwrf(game.loc) == 0) + return GO_CLEAROBJ; + + rspeak(KNIFE_THROWN); + DESTROY(OGRE); + int dwarves = 0; + for (int i = 1; i < PIRATE; i++) { + if (game.dloc[i] == game.loc) { + ++dwarves; + game.dloc[i] = LOC_LONGWEST; + game.dseen[i] = false; + } + } + rspeak((dwarves > 1) ? + OGRE_PANIC1 : + OGRE_PANIC2); + return GO_CLEAROBJ; + } + + switch (obj) { + case NO_OBJECT: + rspeak(NO_TARGET); + break; + case CLAM: + case OYSTER: + rspeak(SHELL_IMPERVIOUS); + break; + case SNAKE: + rspeak(SNAKE_WARNING); + break; + case DWARF: + if (game.closed) { + return GO_DWARFWAKE; + } + rspeak(BARE_HANDS_QUERY); + break; + case DRAGON: + rspeak(ALREADY_DEAD); + break; + case TROLL: + rspeak(ROCKY_TROLL); + break; + default: + rspeak(actions[verb].message); + } return GO_CLEAROBJ; } @@ -264,7 +281,6 @@ static int vcarry(token_t verb, token_t obj) * take one without the other). Liquids also special, since they depend on * status of bottle. Also various side effects, etc. */ { - int spk; if (obj == INTRANSITIVE) { /* Carry, no object given yet. OK if only one object present. */ if (game.atloc[game.loc] == 0 || @@ -278,67 +294,85 @@ static int vcarry(token_t verb, token_t obj) rspeak(ALREADY_CARRYING); return GO_CLEAROBJ; } - spk = YOU_JOKING; - if (obj == PLANT && game.prop[PLANT] <= 0) - spk = DEEP_ROOTS; - 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; - if (obj == RUG && game.prop[RUG] == RUG_HOVER) - spk = RUG_HOVERS; - if (obj == SIGN) - spk = HAND_PASSTHROUGH; + if (obj == MESSAG) { rspeak(REMOVE_MESSAGE); DESTROY(MESSAG); return GO_CLEAROBJ; } + if (game.fixed[obj] != 0) { - rspeak(spk); + if (obj == PLANT && game.prop[PLANT] <= 0) { + rspeak(DEEP_ROOTS); + return GO_CLEAROBJ; + } + if (obj == BEAR && game.prop[BEAR] == SITTING_BEAR) { + rspeak(BEAR_CHAINED); + return GO_CLEAROBJ; + } + if (obj == CHAIN && game.prop[BEAR] != UNTAMED_BEAR) { + rspeak(STILL_LOCKED); + return GO_CLEAROBJ; + } + if (obj == URN) { + rspeak(URN_NOBUDGE); + return GO_CLEAROBJ; + } + if (obj == CAVITY) { + rspeak(DOUGHNUT_HOLES); + return GO_CLEAROBJ; + } + if (obj == BLOOD) { + rspeak(FEW_DROPS); + return GO_CLEAROBJ; + } + if (obj == RUG && game.prop[RUG] == RUG_HOVER) { + rspeak(RUG_HOVERS); + return GO_CLEAROBJ; + } + if (obj == SIGN) { + rspeak(HAND_PASSTHROUGH); + return GO_CLEAROBJ; + } + rspeak(YOU_JOKING); return GO_CLEAROBJ; } + if (obj == WATER || obj == OIL) { if (!HERE(BOTTLE) || LIQUID() != obj) { - if (TOTING(BOTTLE) && game.prop[BOTTLE] == EMPTY_BOTTLE) - return (fill(verb, BOTTLE)); - else { - if (game.prop[BOTTLE] != EMPTY_BOTTLE) - spk = BOTTLE_FULL; - if (!TOTING(BOTTLE)) - spk = NO_CONTAINER; - rspeak(spk); + if (TOTING(BOTTLE)) { + if (game.prop[BOTTLE] == EMPTY_BOTTLE) { + return (fill(verb, BOTTLE)); + } else if (game.prop[BOTTLE] != EMPTY_BOTTLE) + rspeak(BOTTLE_FULL); return GO_CLEAROBJ; } + rspeak(NO_CONTAINER); + return GO_CLEAROBJ; } obj = BOTTLE; } - spk = CARRY_LIMIT; if (game.holdng >= INVLIMIT) { - rspeak(spk); + rspeak(CARRY_LIMIT); return GO_CLEAROBJ; - } else if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && -1 - game.prop[BIRD] != BIRD_CAGED) { + + } + + if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && -1 - game.prop[BIRD] != BIRD_CAGED) { if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) { DESTROY(BIRD); rspeak(BIRD_CRAP); return GO_CLEAROBJ; } - if (!TOTING(CAGE)) - spk = CANNOT_CARRY; - if (TOTING(ROD)) - spk = BIRD_EVADES; - if (spk == CANNOT_CARRY || - spk == BIRD_EVADES) { - rspeak(spk); + if (!TOTING(CAGE)) { + rspeak(CANNOT_CARRY); + return GO_CLEAROBJ; + } + if (TOTING(ROD)) { + rspeak(BIRD_EVADES); return GO_CLEAROBJ; } game.prop[BIRD] = BIRD_CAGED; @@ -350,10 +384,11 @@ static int vcarry(token_t verb, token_t obj) -1 - game.prop[BIRD] == 1)) carry(BIRD + CAGE - obj, game.loc); carry(obj, game.loc); - if (obj == BOTTLE && LIQUID() != 0) + if (obj == BOTTLE && LIQUID() != NO_OBJECT) game.place[LIQUID()] = CARRIED; if (GSTONE(obj) && game.prop[obj] != 0) { - game.prop[obj] = STATE_GROUND; + game.prop[obj] + = STATE_GROUND; game.prop[CAVITY] = CAVITY_EMPTY; } rspeak(OK_MAN); @@ -412,12 +447,11 @@ static int discard(token_t verb, token_t obj, bool just_do_it) * bird (might attack snake or dragon) and cage (might contain bird) and vase. * Drop coins at vending machine for extra batteries. */ { - int spk = actions[verb].message; if (!just_do_it) { if (TOTING(ROD2) && obj == ROD && !TOTING(ROD)) obj = ROD2; if (!TOTING(obj)) { - rspeak(spk); + rspeak(actions[verb].message;); return GO_CLEAROBJ; } if (obj == BIRD && HERE(SNAKE)) { @@ -434,7 +468,7 @@ static int discard(token_t verb, token_t obj, bool just_do_it) game.prop[CAVITY] = CAVITY_FULL; if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) || (obj == RUBY && game.prop[RUG] == RUG_HOVER))) { - spk = RUG_RISES; + int spk = RUG_RISES; if (TOTING(RUG)) spk = RUG_WIGGLES; if (obj == RUBY) @@ -480,7 +514,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) + if (obj == BOTTLE && k != NO_OBJECT) game.place[k] = LOC_NOWHERE; if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) drop(BIRD, game.loc); @@ -977,14 +1011,14 @@ static int pour(token_t verb, token_t obj) } if (!AT(DOOR)) { 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; + /* 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; - } + } } else { state_change(DOOR, (obj == OIL) ? DOOR_UNRUSTED : @@ -1036,8 +1070,8 @@ static int reservoir(void) rspeak(NOTHING_HAPPENS); return GO_CLEAROBJ; } else { - state_change(RESER, - game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED); + state_change(RESER, + game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED); if (AT(RESER)) return GO_CLEAROBJ; else { @@ -1215,7 +1249,7 @@ static int wave(token_t verb, token_t obj) FREE_FLY); state_change(FISSURE, - game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED); + game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED); return GO_CLEAROBJ; } } @@ -1286,7 +1320,7 @@ int action(struct command_t *command) return GO_WORD2; if (command->verb == SAY) command->obj = command->wd2; - if (command->obj == 0 || + if (command->obj == NO_OBJECT || command->obj == INTRANSITIVE) { /* Analyse an intransitive verb (ie, no object given yet). */ switch (command->verb) {