2 * Actions for the dungeon-running code.
4 * SPDX-FileCopyrightText: 1977, 2005 by Will Crowther and Don Woods
5 * SPDX-FileCopyrightText 2017 by Eric S. Raymond
6 * SPDX-License-Identifier: BSD-2-Clause
16 static phase_codes_t fill(verb_t, obj_t);
18 static phase_codes_t attack(command_t command)
19 /* Attack. Assume target if unambiguous. "Throw" also links here.
20 * Attackable objects fall into two categories: enemies (snake,
21 * dwarf, etc.) and others (bird, clam, machine). Ambiguous if 2
22 * enemies, or no enemies but 2 others. */
24 verb_t verb = command.verb;
25 obj_t obj = command.obj;
27 if (obj == INTRANSITIVE) {
29 if (atdwrf(game.loc) > 0) {
37 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
49 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
53 /* check for low-priority targets */
54 if (obj == INTRANSITIVE) {
55 /* Can't attack bird or machine by throwing axe. */
56 if (HERE(BIRD) && verb != THROW) {
60 if (HERE(VEND) && verb != THROW) {
64 /* Clam and oyster both treated as clam for intransitive case;
66 if (HERE(CLAM) || HERE(OYSTER)) {
86 game.prop[VEND] == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
92 switch (game.prop[BEAR]) {
97 rspeak(BEAR_CONFUSED);
100 rspeak(BEAR_CONFUSED);
103 rspeak(ALREADY_DEAD);
108 if (obj == DRAGON && game.prop[DRAGON] == DRAGON_BARS) {
109 /* Fun stuff for dragon. If he insists on attacking it, win!
110 * Set game.prop to dead, move dragon to central loc (still
111 * fixed), move rug there (not fixed), and move him there,
112 * too. Then do a null motion to get new description. */
113 rspeak(BARE_HANDS_QUERY);
114 if (!silent_yes_or_no()) {
115 speak(arbitrary_messages[NASTY_DRAGON]);
118 state_change(DRAGON, DRAGON_DEAD);
119 game.prop[RUG] = RUG_FLOOR;
120 /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly.
121 * The way it was computed before was worse; it depended on the
122 * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and
123 * LOC_SECRET5 being right between them.
125 move(DRAGON + NOBJECTS, IS_FIXED);
126 move(RUG + NOBJECTS, IS_FREE);
127 move(DRAGON, LOC_SECRET5);
128 move(RUG, LOC_SECRET5);
129 drop(BLOOD, LOC_SECRET5);
130 for (obj_t i = 1; i <= NOBJECTS; i++) {
131 if (game.place[i] == objects[DRAGON].plac ||
132 game.place[i] == objects[DRAGON].fixd)
133 move(i, LOC_SECRET5);
135 game.loc = LOC_SECRET5;
141 if (atdwrf(game.loc) == 0)
144 rspeak(KNIFE_THROWN);
147 for (int i = 1; i < PIRATE; i++) {
148 if (game.dloc[i] == game.loc) {
150 game.dloc[i] = LOC_LONGWEST;
151 game.dseen[i] = false;
154 rspeak((dwarves > 1) ?
166 rspeak(SHELL_IMPERVIOUS);
169 rspeak(SNAKE_WARNING);
175 rspeak(BARE_HANDS_QUERY);
178 rspeak(ALREADY_DEAD);
184 speak(actions[verb].message);
189 static phase_codes_t bigwords(vocab_t id)
190 /* Only called on FEE FIE FOE FOO (AND FUM). Advance to next state if given
191 * in proper order. Look up foo in special section of vocab to determine which
192 * word we've got. Last word zips the eggs back to the giant room (unless
195 int foobar = abs(game.foobar);
197 /* Only FEE can start a magic-word sequence. */
198 if ((foobar == WORD_EMPTY) && (id == FIE || id == FOE || id == FOO || id == FUM)) {
199 rspeak(NOTHING_HAPPENS);
203 if ((foobar == WORD_EMPTY && id == FEE) ||
204 (foobar == FEE && id == FIE) ||
205 (foobar == FIE && id == FOE) ||
206 (foobar == FOE && id == FOO)) {
212 game.foobar = WORD_EMPTY;
213 if (game.place[EGGS] == objects[EGGS].plac ||
214 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
215 rspeak(NOTHING_HAPPENS);
218 /* Bring back troll if we steal the eggs back from him before
220 if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
221 game.prop[TROLL] = TROLL_PAIDONCE;
223 pspeak(EGGS, look, true, EGGS_VANISHED);
224 else if (game.loc == objects[EGGS].plac)
225 pspeak(EGGS, look, true, EGGS_HERE);
227 pspeak(EGGS, look, true, EGGS_DONE);
228 move(EGGS, objects[EGGS].plac);
233 /* Magic-word sequebce was started but is incorrect */
235 game.foobar = WORD_EMPTY;
240 static void blast(void)
241 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
243 if (game.prop[ROD2] == STATE_NOTFOUND ||
245 rspeak(REQUIRES_DYNAMITE);
248 game.bonus = splatter;
249 rspeak(SPLATTER_MESSAGE);
250 } else if (game.loc == LOC_NE) {
252 rspeak(DEFEAT_MESSAGE);
254 game.bonus = victory;
255 rspeak(VICTORY_MESSAGE);
261 static phase_codes_t vbreak(verb_t verb, obj_t obj)
262 /* Break. Only works for mirror in repository and, of course, the vase. */
267 state_change(MIRROR, MIRROR_BROKEN);
274 if (game.prop[VASE] == VASE_WHOLE) {
276 drop(VASE, game.loc);
277 state_change(VASE, VASE_BROKEN);
278 game.fixed[VASE] = IS_FIXED;
283 speak(actions[verb].message);
285 return (GO_CLEAROBJ);
288 static phase_codes_t brief(void)
289 /* Brief. Intransitive only. Suppress full descriptions after first time. */
293 rspeak(BRIEF_CONFIRM);
297 static phase_codes_t vcarry(verb_t verb, obj_t obj)
298 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
299 * take one without the other). Liquids also special, since they depend on
300 * status of bottle. Also various side effects, etc. */
302 if (obj == INTRANSITIVE) {
303 /* Carry, no object given yet. OK if only one object present. */
304 if (game.atloc[game.loc] == NO_OBJECT ||
305 game.link[game.atloc[game.loc]] != 0 ||
306 atdwrf(game.loc) > 0)
308 obj = game.atloc[game.loc];
312 speak(actions[verb].message);
317 rspeak(REMOVE_MESSAGE);
322 if (game.fixed[obj] != IS_FREE) {
325 /* Next guard tests whether plant is tiny or stashed */
326 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
329 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
332 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
335 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
341 rspeak(DOUGHNUT_HOLES);
347 rspeak(HAND_PASSTHROUGH);
359 if (!TOTING(BOTTLE)) {
360 rspeak(NO_CONTAINER);
363 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
364 return (fill(verb, BOTTLE));
372 if (game.holdng >= INVLIMIT) {
378 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
379 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
385 rspeak(CANNOT_CARRY);
392 game.prop[BIRD] = BIRD_CAGED;
396 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
397 /* expression maps BIRD to CAGE and CAGE to BIRD */
398 carry(BIRD + CAGE - obj, game.loc);
401 carry(obj, game.loc);
403 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
404 game.place[LIQUID()] = CARRIED;
406 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
407 game.prop[obj] = STATE_FOUND;
408 game.prop[CAVITY] = CAVITY_EMPTY;
414 static int chain(verb_t verb)
415 /* Do something to the bear's chain */
418 if (game.prop[BEAR] == UNTAMED_BEAR) {
422 if (game.prop[CHAIN] == CHAIN_HEAP) {
423 rspeak(ALREADY_UNLOCKED);
426 game.prop[CHAIN] = CHAIN_HEAP;
427 game.fixed[CHAIN] = IS_FREE;
428 if (game.prop[BEAR] != BEAR_DEAD)
429 game.prop[BEAR] = CONTENTED_BEAR;
431 switch (game.prop[BEAR]) {
434 /* Can't be reached until the bear can die in some way other
435 * than a bridge collapse. Leave in in case this changes, but
436 * exclude from coverage testing. */
437 game.fixed[BEAR] = IS_FIXED;
441 game.fixed[BEAR] = IS_FREE;
443 rspeak(CHAIN_UNLOCKED);
447 if (game.prop[CHAIN] != CHAIN_HEAP) {
448 rspeak(ALREADY_LOCKED);
451 if (game.loc != objects[CHAIN].plac) {
456 game.prop[CHAIN] = CHAIN_FIXED;
459 drop(CHAIN, game.loc);
460 game.fixed[CHAIN] = IS_FIXED;
462 rspeak(CHAIN_LOCKED);
466 static phase_codes_t discard(verb_t verb, obj_t obj)
467 /* Discard object. "Throw" also comes here for most objects. Special cases for
468 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
469 * Drop coins at vending machine for extra batteries. */
471 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
476 speak(actions[verb].message);
480 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
482 game.prop[obj] = STATE_IN_CAVITY;
483 game.prop[CAVITY] = CAVITY_FULL;
484 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
485 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
488 else if (TOTING(RUG))
492 if (!TOTING(RUG) || obj == RUBY) {
493 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
496 k = objects[SAPPH].plac;
497 move(RUG + NOBJECTS, k);
504 if (obj == COINS && HERE(VEND)) {
506 drop(BATTERY, game.loc);
507 pspeak(BATTERY, look, true, FRESH_BATTERIES);
513 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
514 game.place[LIQUID()] = LOC_NOWHERE;
517 if (obj == BEAR && AT(TROLL)) {
518 state_change(TROLL, TROLL_GONE);
519 move(TROLL, LOC_NOWHERE);
520 move(TROLL + NOBJECTS, IS_FREE);
521 move(TROLL2, objects[TROLL].plac);
522 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
529 if (game.loc != objects[PILLOW].plac) {
530 state_change(VASE, AT(PILLOW)
533 if (game.prop[VASE] != VASE_WHOLE)
534 game.fixed[VASE] = IS_FIXED;
540 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
541 drop(BIRD, game.loc);
545 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
551 rspeak(BIRD_ATTACKS);
555 /* Set game.prop for use by travel options */
556 game.prop[SNAKE] = SNAKE_CHASED;
560 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
570 static phase_codes_t drink(verb_t verb, obj_t obj)
571 /* Drink. If no object, assume water and look for it here. If water is in
572 * the bottle, drink that, else must be at a water loc, so drink stream. */
574 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
575 (LIQUID() != WATER || !HERE(BOTTLE))) {
581 state_change(DRAGON, DRAGON_BLOODLESS);
586 if (obj != INTRANSITIVE && obj != WATER) {
587 rspeak(RIDICULOUS_ATTEMPT);
590 if (LIQUID() == WATER && HERE(BOTTLE)) {
591 game.place[WATER] = LOC_NOWHERE;
592 state_change(BOTTLE, EMPTY_BOTTLE);
596 speak(actions[verb].message);
600 static phase_codes_t eat(verb_t verb, obj_t obj)
601 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
602 * ok, some things lose appetite, rest are ridiculous. */
611 rspeak(THANKS_DELICIOUS);
622 rspeak(LOST_APPETITE);
625 speak(actions[verb].message);
630 static phase_codes_t extinguish(verb_t verb, obj_t obj)
631 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
633 if (obj == INTRANSITIVE) {
634 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
636 if (HERE(URN) && game.prop[URN] == URN_LIT)
638 if (obj == INTRANSITIVE)
644 if (game.prop[URN] != URN_EMPTY) {
645 state_change(URN, URN_DARK);
647 pspeak(URN, change, true, URN_DARK);
651 state_change(LAMP, LAMP_DARK);
652 rspeak(DARK(game.loc) ?
658 rspeak(BEYOND_POWER);
661 speak(actions[verb].message);
666 static phase_codes_t feed(verb_t verb, obj_t obj)
667 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
668 * mad. Bear, special. */
675 if (game.prop[DRAGON] != DRAGON_BARS)
676 rspeak(RIDICULOUS_ATTEMPT);
678 rspeak(NOTHING_EDIBLE);
681 if (!game.closed && HERE(BIRD)) {
683 rspeak(BIRD_DEVOURED);
685 rspeak(NOTHING_EDIBLE);
695 speak(actions[verb].message);
698 if (game.prop[BEAR] == BEAR_DEAD) {
699 rspeak(RIDICULOUS_ATTEMPT);
702 if (game.prop[BEAR] == UNTAMED_BEAR) {
705 game.fixed[AXE] = IS_FREE;
706 game.prop[AXE] = AXE_HERE;
707 state_change(BEAR, SITTING_BEAR);
709 rspeak(NOTHING_EDIBLE);
712 speak(actions[verb].message);
718 speak(actions[verb].message);
726 phase_codes_t fill(verb_t verb, obj_t obj)
727 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
731 if (LIQLOC(game.loc) == NO_OBJECT) {
732 rspeak(FILL_INVALID);
736 rspeak(ARENT_CARRYING);
739 rspeak(SHATTER_VASE);
740 game.prop[VASE] = VASE_BROKEN;
741 game.fixed[VASE] = IS_FIXED;
742 drop(VASE, game.loc);
747 if (game.prop[URN] != URN_EMPTY) {
752 rspeak(FILL_INVALID);
758 game.prop[BOTTLE] = EMPTY_BOTTLE;
762 game.prop[URN] = URN_DARK;
763 game.prop[BOTTLE] = EMPTY_BOTTLE;
768 rspeak(FILL_INVALID);
771 game.place[k] = LOC_NOWHERE;
774 if (obj != INTRANSITIVE && obj != BOTTLE) {
775 speak(actions[verb].message);
778 if (obj == INTRANSITIVE && !HERE(BOTTLE))
781 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
785 if (LIQUID() != NO_OBJECT) {
789 if (LIQLOC(game.loc) == NO_OBJECT) {
794 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
798 game.place[LIQUID()] = CARRIED;
802 static phase_codes_t find(verb_t verb, obj_t obj)
803 /* Find. Might be carrying it, or it might be here. Else give caveat. */
806 rspeak(ALREADY_CARRYING);
811 rspeak(NEEDED_NEARBY);
816 (LIQUID() == obj && AT(BOTTLE)) ||
817 obj == LIQLOC(game.loc) ||
818 (obj == DWARF && atdwrf(game.loc) > 0)) {
824 speak(actions[verb].message);
828 static phase_codes_t fly(verb_t verb, obj_t obj)
829 /* Fly. Snide remarks unless hovering rug is here. */
831 if (obj == INTRANSITIVE) {
836 if (game.prop[RUG] != RUG_HOVER) {
837 rspeak(RUG_NOTHING2);
844 speak(actions[verb].message);
847 if (game.prop[RUG] != RUG_HOVER) {
848 rspeak(RUG_NOTHING1);
852 if (game.loc == LOC_CLIFF) {
853 game.oldlc2 = game.oldloc;
854 game.oldloc = game.loc;
855 game.newloc = LOC_LEDGE;
857 } else if (game.loc == LOC_LEDGE) {
858 game.oldlc2 = game.oldloc;
859 game.oldloc = game.loc;
860 game.newloc = LOC_CLIFF;
864 /* should never happen */
865 rspeak(NOTHING_HAPPENS);
871 static phase_codes_t inven(void)
872 /* Inventory. If object, treat same as find. Else report on current burden. */
875 for (obj_t i = 1; i <= NOBJECTS; i++) {
883 pspeak(i, touch, false, -1);
892 static phase_codes_t light(verb_t verb, obj_t obj)
893 /* Light. Applicable only to lamp and urn. */
895 if (obj == INTRANSITIVE) {
897 if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
901 if (HERE(URN) && game.prop[URN] == URN_DARK) {
911 state_change(URN, game.prop[URN] == URN_EMPTY ?
916 if (game.limit < 0) {
920 state_change(LAMP, LAMP_BRIGHT);
925 speak(actions[verb].message);
930 static phase_codes_t listen(void)
931 /* Listen. Intransitive only. Print stuff based on object sound properties. */
933 bool soundlatch = false;
934 vocab_t sound = locations[game.loc].sound;
935 if (sound != SILENT) {
937 if (!locations[game.loc].loud)
941 for (obj_t i = 1; i <= NOBJECTS; i++) {
943 objects[i].sounds[0] == NULL ||
946 int mi = game.prop[i];
947 /* (ESR) Some unpleasant magic on object states here. Ideally
948 * we'd have liked the bird to be a normal object that we can
949 * use state_change() on; can't do it, because there are
950 * actually two different series of per-state birdsounds
951 * depending on whether player has drunk dragon's blood. */
953 mi += 3 * game.blooded;
954 pspeak(i, hear, true, mi, game.zzword);
956 if (i == BIRD && mi == BIRD_ENDSTATE)
965 static phase_codes_t lock(verb_t verb, obj_t obj)
966 /* Lock, unlock, no object given. Assume various things if present. */
968 if (obj == INTRANSITIVE) {
979 if (obj == INTRANSITIVE) {
980 rspeak(NOTHING_LOCKED);
985 /* Lock, unlock object. Special stuff for opening clam/oyster
1000 game.clock2 = PANICTIME;
1003 state_change(GRATE, (verb == LOCK) ?
1013 else if (TOTING(CLAM))
1015 else if (!TOTING(TRIDENT))
1016 rspeak(CLAM_OPENER);
1019 drop(OYSTER, game.loc);
1020 drop(PEARL, LOC_CULDESAC);
1021 rspeak(PEARL_FALLS);
1027 else if (TOTING(OYSTER))
1028 rspeak(DROP_OYSTER);
1029 else if (!TOTING(TRIDENT))
1030 rspeak(OYSTER_OPENER);
1032 rspeak(OYSTER_OPENS);
1035 rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1041 rspeak(CANNOT_UNLOCK);
1044 speak(actions[verb].message);
1050 static phase_codes_t pour(verb_t verb, obj_t obj)
1051 /* Pour. If no object, or object is bottle, assume contents of bottle.
1052 * special tests for pouring water or oil on plant or rusty door. */
1054 if (obj == BOTTLE ||
1055 obj == INTRANSITIVE)
1057 if (obj == NO_OBJECT)
1060 speak(actions[verb].message);
1064 if (obj != OIL && obj != WATER) {
1068 if (HERE(URN) && game.prop[URN] == URN_EMPTY)
1069 return fill(verb, URN);
1070 game.prop[BOTTLE] = EMPTY_BOTTLE;
1071 game.place[obj] = LOC_NOWHERE;
1079 /* cycle through the three plant states */
1080 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1081 game.prop[PLANT2] = game.prop[PLANT];
1084 rspeak(SHAKING_LEAVES);
1088 state_change(DOOR, (obj == OIL) ?
1095 static phase_codes_t quit(void)
1096 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1098 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1099 terminate(quitgame);
1103 static phase_codes_t read(command_t command)
1104 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1106 if (command.obj == INTRANSITIVE) {
1107 command.obj = NO_OBJECT;
1108 for (int i = 1; i <= NOBJECTS; i++) {
1109 if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
1110 command.obj = command.obj * NOBJECTS + i;
1112 if (command.obj > NOBJECTS ||
1113 command.obj == NO_OBJECT ||
1118 if (DARK(game.loc)) {
1119 sspeak(NO_SEE, command.word[0].raw);
1120 } else if (command.obj == OYSTER) {
1121 if (!TOTING(OYSTER) || !game.closed) {
1122 rspeak(DONT_UNDERSTAND);
1123 } else if (!game.clshnt) {
1124 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1126 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1128 } else if (objects[command.obj].texts[0] == NULL ||
1129 game.prop[command.obj] == STATE_NOTFOUND) {
1130 speak(actions[command.verb].message);
1132 pspeak(command.obj, study, true, game.prop[command.obj]);
1136 static phase_codes_t reservoir(void)
1137 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1139 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1140 rspeak(NOTHING_HAPPENS);
1144 game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1148 game.oldlc2 = game.loc;
1149 game.newloc = LOC_NOWHERE;
1151 return GO_TERMINATE;
1156 static phase_codes_t rub(verb_t verb, obj_t obj)
1157 /* Rub. Yields various snide remarks except for lit urn. */
1159 if (obj == URN && game.prop[URN] == URN_LIT) {
1161 drop(AMBER, game.loc);
1162 game.prop[AMBER] = AMBER_IN_ROCK;
1164 drop(CAVITY, game.loc);
1166 } else if (obj != LAMP) {
1167 rspeak(PECULIAR_NOTHING);
1169 speak(actions[verb].message);
1174 static phase_codes_t say(command_t command)
1175 /* Say. Echo WD2. Magic words override. */
1177 if (command.word[1].type == MOTION &&
1178 (command.word[1].id == XYZZY ||
1179 command.word[1].id == PLUGH ||
1180 command.word[1].id == PLOVER)) {
1183 if (command.word[1].type == ACTION && command.word[1].id == PART)
1186 if (command.word[1].type == ACTION &&
1187 (command.word[1].id == FEE ||
1188 command.word[1].id == FIE ||
1189 command.word[1].id == FOE ||
1190 command.word[1].id == FOO ||
1191 command.word[1].id == FUM ||
1192 command.word[1].id == PART)) {
1193 return bigwords(command.word[1].id);
1195 sspeak(OKEY_DOKEY, command.word[1].raw);
1199 static phase_codes_t throw_support(vocab_t spk)
1202 drop(AXE, game.loc);
1206 static phase_codes_t throwit(command_t command)
1207 /* Throw. Same as discard unless axe. Then same as attack except
1208 * ignore bird, and if dwarf is present then one might be killed.
1209 * (Only way to do so!) Axe also special for dragon, bear, and
1210 * troll. Treasures special for troll. */
1212 if (!TOTING(command.obj)) {
1213 speak(actions[command.verb].message);
1216 if (objects[command.obj].is_treasure && AT(TROLL)) {
1217 /* Snarf a treasure for the troll. */
1218 drop(command.obj, LOC_NOWHERE);
1219 move(TROLL, LOC_NOWHERE);
1220 move(TROLL + NOBJECTS, IS_FREE);
1221 drop(TROLL2, objects[TROLL].plac);
1222 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1224 rspeak(TROLL_SATISFIED);
1227 if (command.obj == FOOD && HERE(BEAR)) {
1228 /* But throwing food is another story. */
1230 return (feed(command.verb, command.obj));
1232 if (command.obj != AXE)
1233 return (discard(command.verb, command.obj));
1235 if (atdwrf(game.loc) <= 0) {
1236 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS)
1237 return throw_support(DRAGON_SCALES);
1239 return throw_support(TROLL_RETURNS);
1241 return throw_support(OGRE_DODGE);
1242 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
1243 /* This'll teach him to throw the axe at the bear! */
1244 drop(AXE, game.loc);
1245 game.fixed[AXE] = IS_FIXED;
1247 state_change(AXE, AXE_LOST);
1250 command.obj = INTRANSITIVE;
1251 return (attack(command));
1254 if (randrange(NDWARVES + 1) < game.dflag) {
1255 return throw_support(DWARF_DODGES);
1257 int i = atdwrf(game.loc);
1258 game.dseen[i] = false;
1259 game.dloc[i] = LOC_NOWHERE;
1260 return throw_support((++game.dkill == 1) ?
1267 static phase_codes_t wake(verb_t verb, obj_t obj)
1268 /* Wake. Only use is to disturb the dwarves. */
1272 speak(actions[verb].message);
1276 return GO_DWARFWAKE;
1280 static phase_codes_t seed(verb_t verb, const char *arg)
1283 int32_t seed = strtol(arg, NULL, 10);
1284 speak(actions[verb].message, seed);
1290 static phase_codes_t waste(verb_t verb, turn_t turns)
1293 game.limit -= turns;
1294 speak(actions[verb].message, (int)game.limit);
1298 static phase_codes_t wave(verb_t verb, obj_t obj)
1299 /* Wave. No effect unless waving rod at fissure or at bird. */
1306 speak(((!TOTING(obj)) && (obj != ROD ||
1308 arbitrary_messages[ARENT_CARRYING] :
1309 actions[verb].message);
1313 if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1314 drop(JADE, game.loc);
1315 game.prop[JADE] = STATE_FOUND;
1317 rspeak(NECKLACE_FLY);
1321 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1324 return GO_DWARFWAKE;
1328 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1334 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1338 state_change(FISSURE,
1339 game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED);
1344 phase_codes_t action(command_t command)
1345 /* Analyse a verb. Remember what it was, go back for object if second word
1346 * unless verb is "say", which snarfs arbitrary second word.
1349 /* Previously, actions that result in a message, but don't do anything
1350 * further were called "specials". Now they're handled here as normal
1351 * actions. If noaction is true, then we spit out the message and return */
1352 if (actions[command.verb].noaction) {
1353 speak(actions[command.verb].message);
1357 if (command.part == unknown) {
1358 /* Analyse an object word. See if the thing is here, whether
1359 * we've got a verb yet, and so on. Object must be here
1360 * unless verb is "find" or "invent(ory)" (and no new verb
1361 * yet to be analysed). Water and oil are also funny, since
1362 * they are never actually dropped at any location, but might
1363 * be here inside the bottle or urn or as a feature of the
1365 if (HERE(command.obj))
1367 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1369 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1370 command.obj == LIQLOC(game.loc)))
1372 else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
1375 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) {
1376 command.obj = PLANT2;
1378 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1380 rspeak(KNIVES_VANISH);
1382 } else if (command.obj == ROD && HERE(ROD2)) {
1385 } else if ((command.verb == FIND ||
1386 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1389 sspeak(NO_SEE, command.word[0].raw);
1393 if (command.verb != 0)
1394 command.part = transitive;
1397 switch (command.part) {
1399 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1401 if (command.verb == SAY)
1402 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1403 * will do here. We're preventing interpretation as an intransitive
1404 * verb when the word is unknown. */
1405 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1406 if (command.obj == NO_OBJECT ||
1407 command.obj == INTRANSITIVE) {
1408 /* Analyse an intransitive verb (ie, no object given yet). */
1409 switch (command.verb) {
1411 return vcarry(command.verb, INTRANSITIVE);
1417 return lock(command.verb, INTRANSITIVE);
1420 return (GO_CLEAROBJ);
1423 return lock(command.verb, INTRANSITIVE);
1425 return light(command.verb, INTRANSITIVE);
1427 return extinguish(command.verb, INTRANSITIVE);
1433 speak(actions[command.verb].message);
1437 command.obj = INTRANSITIVE;
1438 return attack(command);
1440 return pour(command.verb, INTRANSITIVE);
1442 return eat(command.verb, INTRANSITIVE);
1444 return drink(command.verb, INTRANSITIVE);
1458 return fill(command.verb, INTRANSITIVE);
1470 return bigwords(command.word[0].id);
1474 command.obj = INTRANSITIVE;
1475 return read(command);
1485 return fly(command.verb, INTRANSITIVE);
1492 rspeak(NUMERIC_REQUIRED);
1494 default: // LCOV_EXCL_LINE
1495 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1500 /* Analyse a transitive verb. */
1501 switch (command.verb) {
1503 return vcarry(command.verb, command.obj);
1505 return discard(command.verb, command.obj);
1507 return say(command);
1509 return lock(command.verb, command.obj);
1512 return (GO_CLEAROBJ);
1515 return lock(command.verb, command.obj);
1517 return light(command.verb, command.obj);
1519 return extinguish(command.verb, command.obj);
1521 return wave(command.verb, command.obj);
1523 speak(actions[command.verb].message);
1527 speak(actions[command.verb].message);
1531 return attack(command);
1533 return pour(command.verb, command.obj);
1535 return eat(command.verb, command.obj);
1537 return drink(command.verb, command.obj);
1539 return rub(command.verb, command.obj);
1541 return throwit(command);
1543 speak(actions[command.verb].message);
1547 return find(command.verb, command.obj);
1549 return find(command.verb, command.obj);
1551 return feed(command.verb, command.obj);
1553 return fill(command.verb, command.obj);
1558 speak(actions[command.verb].message);
1566 speak(actions[command.verb].message);
1570 speak(actions[command.verb].message);
1574 return read(command);
1576 return vbreak(command.verb, command.obj);
1578 return wake(command.verb, command.obj);
1580 speak(actions[command.verb].message);
1584 speak(actions[command.verb].message);
1588 return fly(command.verb, command.obj);
1590 speak(actions[command.verb].message);
1594 // This case should never happen - here only as placeholder
1599 return seed(command.verb, command.word[1].raw);
1601 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1602 default: // LCOV_EXCL_LINE
1603 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1606 /* Unknown verb, couldn't deduce object - might need hint */
1607 sspeak(WHAT_DO, command.word[0].raw);
1608 return GO_CHECKHINT;
1609 default: // LCOV_EXCL_LINE
1610 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE