2 * Actions for the dungeon-running code.
4 * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
5 * Copyright (c) 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 if ((foobar == WORD_EMPTY) && (id == FIE || id == FOE || id == FOO || id == FUM)) {
198 rspeak(NOTHING_HAPPENS);
202 if ((foobar == WORD_EMPTY && id == FEE) ||
203 (foobar == FEE && id == FIE) ||
204 (foobar == FIE && id == FOE) ||
205 (foobar == FOE && id == FOO) ||
206 (foobar == FOE && id == FUM)) {
208 if ((id != FOO) && (id != FUM)) {
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);
217 } else if (id == FUM) {
220 /* Bring back troll if we steal the eggs back from him before
222 if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
223 game.prop[TROLL] = TROLL_PAIDONCE;
225 pspeak(EGGS, look, true, EGGS_VANISHED);
226 else if (game.loc == objects[EGGS].plac)
227 pspeak(EGGS, look, true, EGGS_HERE);
229 pspeak(EGGS, look, true, EGGS_DONE);
230 move(EGGS, objects[EGGS].plac);
237 game.foobar = WORD_EMPTY;
242 static void blast(void)
243 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
245 if (game.prop[ROD2] == STATE_NOTFOUND ||
247 rspeak(REQUIRES_DYNAMITE);
250 game.bonus = splatter;
251 rspeak(SPLATTER_MESSAGE);
252 } else if (game.loc == LOC_NE) {
254 rspeak(DEFEAT_MESSAGE);
256 game.bonus = victory;
257 rspeak(VICTORY_MESSAGE);
263 static phase_codes_t vbreak(verb_t verb, obj_t obj)
264 /* Break. Only works for mirror in repository and, of course, the vase. */
269 state_change(MIRROR, MIRROR_BROKEN);
276 if (game.prop[VASE] == VASE_WHOLE) {
278 drop(VASE, game.loc);
279 state_change(VASE, VASE_BROKEN);
280 game.fixed[VASE] = IS_FIXED;
285 speak(actions[verb].message);
287 return (GO_CLEAROBJ);
290 static phase_codes_t brief(void)
291 /* Brief. Intransitive only. Suppress full descriptions after first time. */
295 rspeak(BRIEF_CONFIRM);
299 static phase_codes_t vcarry(verb_t verb, obj_t obj)
300 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
301 * take one without the other). Liquids also special, since they depend on
302 * status of bottle. Also various side effects, etc. */
304 if (obj == INTRANSITIVE) {
305 /* Carry, no object given yet. OK if only one object present. */
306 if (game.atloc[game.loc] == NO_OBJECT ||
307 game.link[game.atloc[game.loc]] != 0 ||
308 atdwrf(game.loc) > 0)
310 obj = game.atloc[game.loc];
314 speak(actions[verb].message);
319 rspeak(REMOVE_MESSAGE);
324 if (game.fixed[obj] != IS_FREE) {
327 /* Next guard tests whether plant is tiny or stashed */
328 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
331 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
334 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
337 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
343 rspeak(DOUGHNUT_HOLES);
349 rspeak(HAND_PASSTHROUGH);
361 if (!TOTING(BOTTLE)) {
362 rspeak(NO_CONTAINER);
365 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
366 return (fill(verb, BOTTLE));
374 if (game.holdng >= INVLIMIT) {
380 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
381 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
387 rspeak(CANNOT_CARRY);
394 game.prop[BIRD] = BIRD_CAGED;
398 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
399 /* expression maps BIRD to CAGE and CAGE to BIRD */
400 carry(BIRD + CAGE - obj, game.loc);
403 carry(obj, game.loc);
405 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
406 game.place[LIQUID()] = CARRIED;
408 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
409 game.prop[obj] = STATE_FOUND;
410 game.prop[CAVITY] = CAVITY_EMPTY;
416 static int chain(verb_t verb)
417 /* Do something to the bear's chain */
420 if (game.prop[BEAR] == UNTAMED_BEAR) {
424 if (game.prop[CHAIN] == CHAIN_HEAP) {
425 rspeak(ALREADY_UNLOCKED);
428 game.prop[CHAIN] = CHAIN_HEAP;
429 game.fixed[CHAIN] = IS_FREE;
430 if (game.prop[BEAR] != BEAR_DEAD)
431 game.prop[BEAR] = CONTENTED_BEAR;
433 switch (game.prop[BEAR]) {
436 /* Can't be reached until the bear can die in some way other
437 * than a bridge collapse. Leave in in case this changes, but
438 * exclude from coverage testing. */
439 game.fixed[BEAR] = IS_FIXED;
443 game.fixed[BEAR] = IS_FREE;
445 rspeak(CHAIN_UNLOCKED);
449 if (game.prop[CHAIN] != CHAIN_HEAP) {
450 rspeak(ALREADY_LOCKED);
453 if (game.loc != objects[CHAIN].plac) {
458 game.prop[CHAIN] = CHAIN_FIXED;
461 drop(CHAIN, game.loc);
462 game.fixed[CHAIN] = IS_FIXED;
464 rspeak(CHAIN_LOCKED);
468 static phase_codes_t discard(verb_t verb, obj_t obj)
469 /* Discard object. "Throw" also comes here for most objects. Special cases for
470 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
471 * Drop coins at vending machine for extra batteries. */
473 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
478 speak(actions[verb].message);
482 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
484 game.prop[obj] = STATE_IN_CAVITY;
485 game.prop[CAVITY] = CAVITY_FULL;
486 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
487 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
490 else if (TOTING(RUG))
494 if (!TOTING(RUG) || obj == RUBY) {
495 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
498 k = objects[SAPPH].plac;
499 move(RUG + NOBJECTS, k);
506 if (obj == COINS && HERE(VEND)) {
508 drop(BATTERY, game.loc);
509 pspeak(BATTERY, look, true, FRESH_BATTERIES);
515 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
516 game.place[LIQUID()] = LOC_NOWHERE;
519 if (obj == BEAR && AT(TROLL)) {
520 state_change(TROLL, TROLL_GONE);
521 move(TROLL, LOC_NOWHERE);
522 move(TROLL + NOBJECTS, IS_FREE);
523 move(TROLL2, objects[TROLL].plac);
524 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
531 if (game.loc != objects[PILLOW].plac) {
532 state_change(VASE, AT(PILLOW)
535 if (game.prop[VASE] != VASE_WHOLE)
536 game.fixed[VASE] = IS_FIXED;
542 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
543 drop(BIRD, game.loc);
547 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
553 rspeak(BIRD_ATTACKS);
557 /* Set game.prop for use by travel options */
558 game.prop[SNAKE] = SNAKE_CHASED;
562 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
572 static phase_codes_t drink(verb_t verb, obj_t obj)
573 /* Drink. If no object, assume water and look for it here. If water is in
574 * the bottle, drink that, else must be at a water loc, so drink stream. */
576 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
577 (LIQUID() != WATER || !HERE(BOTTLE))) {
583 state_change(DRAGON, DRAGON_BLOODLESS);
588 if (obj != INTRANSITIVE && obj != WATER) {
589 rspeak(RIDICULOUS_ATTEMPT);
592 if (LIQUID() == WATER && HERE(BOTTLE)) {
593 game.place[WATER] = LOC_NOWHERE;
594 state_change(BOTTLE, EMPTY_BOTTLE);
598 speak(actions[verb].message);
602 static phase_codes_t eat(verb_t verb, obj_t obj)
603 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
604 * ok, some things lose appetite, rest are ridiculous. */
613 rspeak(THANKS_DELICIOUS);
624 rspeak(LOST_APPETITE);
627 speak(actions[verb].message);
632 static phase_codes_t extinguish(verb_t verb, obj_t obj)
633 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
635 if (obj == INTRANSITIVE) {
636 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
638 if (HERE(URN) && game.prop[URN] == URN_LIT)
640 if (obj == INTRANSITIVE)
646 if (game.prop[URN] != URN_EMPTY) {
647 state_change(URN, URN_DARK);
649 pspeak(URN, change, true, URN_DARK);
653 state_change(LAMP, LAMP_DARK);
654 rspeak(DARK(game.loc) ?
660 rspeak(BEYOND_POWER);
663 speak(actions[verb].message);
668 static phase_codes_t feed(verb_t verb, obj_t obj)
669 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
670 * mad. Bear, special. */
677 if (game.prop[DRAGON] != DRAGON_BARS)
678 rspeak(RIDICULOUS_ATTEMPT);
680 rspeak(NOTHING_EDIBLE);
683 if (!game.closed && HERE(BIRD)) {
685 rspeak(BIRD_DEVOURED);
687 rspeak(NOTHING_EDIBLE);
697 speak(actions[verb].message);
700 if (game.prop[BEAR] == BEAR_DEAD) {
701 rspeak(RIDICULOUS_ATTEMPT);
704 if (game.prop[BEAR] == UNTAMED_BEAR) {
707 game.fixed[AXE] = IS_FREE;
708 game.prop[AXE] = AXE_HERE;
709 state_change(BEAR, SITTING_BEAR);
711 rspeak(NOTHING_EDIBLE);
714 speak(actions[verb].message);
720 speak(actions[verb].message);
728 phase_codes_t fill(verb_t verb, obj_t obj)
729 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
733 if (LIQLOC(game.loc) == NO_OBJECT) {
734 rspeak(FILL_INVALID);
738 rspeak(ARENT_CARRYING);
741 rspeak(SHATTER_VASE);
742 game.prop[VASE] = VASE_BROKEN;
743 game.fixed[VASE] = IS_FIXED;
744 drop(VASE, game.loc);
749 if (game.prop[URN] != URN_EMPTY) {
754 rspeak(FILL_INVALID);
760 game.prop[BOTTLE] = EMPTY_BOTTLE;
764 game.prop[URN] = URN_DARK;
765 game.prop[BOTTLE] = EMPTY_BOTTLE;
770 rspeak(FILL_INVALID);
773 game.place[k] = LOC_NOWHERE;
776 if (obj != INTRANSITIVE && obj != BOTTLE) {
777 speak(actions[verb].message);
780 if (obj == INTRANSITIVE && !HERE(BOTTLE))
783 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
787 if (LIQUID() != NO_OBJECT) {
791 if (LIQLOC(game.loc) == NO_OBJECT) {
796 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
800 game.place[LIQUID()] = CARRIED;
804 static phase_codes_t find(verb_t verb, obj_t obj)
805 /* Find. Might be carrying it, or it might be here. Else give caveat. */
808 rspeak(ALREADY_CARRYING);
813 rspeak(NEEDED_NEARBY);
818 (LIQUID() == obj && AT(BOTTLE)) ||
819 obj == LIQLOC(game.loc) ||
820 (obj == DWARF && atdwrf(game.loc) > 0)) {
826 speak(actions[verb].message);
830 static phase_codes_t fly(verb_t verb, obj_t obj)
831 /* Fly. Snide remarks unless hovering rug is here. */
833 if (obj == INTRANSITIVE) {
838 if (game.prop[RUG] != RUG_HOVER) {
839 rspeak(RUG_NOTHING2);
846 speak(actions[verb].message);
849 if (game.prop[RUG] != RUG_HOVER) {
850 rspeak(RUG_NOTHING1);
854 if (game.loc == LOC_CLIFF) {
855 game.oldlc2 = game.oldloc;
856 game.oldloc = game.loc;
857 game.newloc = LOC_LEDGE;
859 } else if (game.loc == LOC_LEDGE) {
860 game.oldlc2 = game.oldloc;
861 game.oldloc = game.loc;
862 game.newloc = LOC_CLIFF;
866 /* should never happen */
867 rspeak(NOTHING_HAPPENS);
873 static phase_codes_t inven(void)
874 /* Inventory. If object, treat same as find. Else report on current burden. */
877 for (obj_t i = 1; i <= NOBJECTS; i++) {
885 pspeak(i, touch, false, -1);
894 static phase_codes_t light(verb_t verb, obj_t obj)
895 /* Light. Applicable only to lamp and urn. */
897 if (obj == INTRANSITIVE) {
899 if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
903 if (HERE(URN) && game.prop[URN] == URN_DARK) {
913 state_change(URN, game.prop[URN] == URN_EMPTY ?
918 if (game.limit < 0) {
922 state_change(LAMP, LAMP_BRIGHT);
927 speak(actions[verb].message);
932 static phase_codes_t listen(void)
933 /* Listen. Intransitive only. Print stuff based on object sound properties. */
935 bool soundlatch = false;
936 vocab_t sound = locations[game.loc].sound;
937 if (sound != SILENT) {
939 if (!locations[game.loc].loud)
943 for (obj_t i = 1; i <= NOBJECTS; i++) {
945 objects[i].sounds[0] == NULL ||
948 int mi = game.prop[i];
949 /* (ESR) Some unpleasant magic on object states here. Ideally
950 * we'd have liked the bird to be a normal object that we can
951 * use state_change() on; can't do it, because there are
952 * actually two different series of per-state birdsounds
953 * depending on whether player has drunk dragon's blood. */
955 mi += 3 * game.blooded;
956 pspeak(i, hear, true, mi, game.zzword);
958 if (i == BIRD && mi == BIRD_ENDSTATE)
967 static phase_codes_t lock(verb_t verb, obj_t obj)
968 /* Lock, unlock, no object given. Assume various things if present. */
970 if (obj == INTRANSITIVE) {
981 if (obj == INTRANSITIVE) {
982 rspeak(NOTHING_LOCKED);
987 /* Lock, unlock object. Special stuff for opening clam/oyster
1000 rspeak(EXIT_CLOSED);
1002 game.clock2 = PANICTIME;
1005 state_change(GRATE, (verb == LOCK) ?
1015 else if (TOTING(CLAM))
1017 else if (!TOTING(TRIDENT))
1018 rspeak(CLAM_OPENER);
1021 drop(OYSTER, game.loc);
1022 drop(PEARL, LOC_CULDESAC);
1023 rspeak(PEARL_FALLS);
1029 else if (TOTING(OYSTER))
1030 rspeak(DROP_OYSTER);
1031 else if (!TOTING(TRIDENT))
1032 rspeak(OYSTER_OPENER);
1034 rspeak(OYSTER_OPENS);
1037 rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1043 rspeak(CANNOT_UNLOCK);
1046 speak(actions[verb].message);
1052 static phase_codes_t pour(verb_t verb, obj_t obj)
1053 /* Pour. If no object, or object is bottle, assume contents of bottle.
1054 * special tests for pouring water or oil on plant or rusty door. */
1056 if (obj == BOTTLE ||
1057 obj == INTRANSITIVE)
1059 if (obj == NO_OBJECT)
1062 speak(actions[verb].message);
1066 if (obj != OIL && obj != WATER) {
1070 if (HERE(URN) && game.prop[URN] == URN_EMPTY)
1071 return fill(verb, URN);
1072 game.prop[BOTTLE] = EMPTY_BOTTLE;
1073 game.place[obj] = LOC_NOWHERE;
1081 /* cycle through the three plant states */
1082 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1083 game.prop[PLANT2] = game.prop[PLANT];
1086 rspeak(SHAKING_LEAVES);
1090 state_change(DOOR, (obj == OIL) ?
1097 static phase_codes_t quit(void)
1098 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1100 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1101 terminate(quitgame);
1105 static phase_codes_t read(command_t command)
1106 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1108 if (command.obj == INTRANSITIVE) {
1109 command.obj = NO_OBJECT;
1110 for (int i = 1; i <= NOBJECTS; i++) {
1111 if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
1112 command.obj = command.obj * NOBJECTS + i;
1114 if (command.obj > NOBJECTS ||
1115 command.obj == NO_OBJECT ||
1120 if (DARK(game.loc)) {
1121 sspeak(NO_SEE, command.word[0].raw);
1122 } else if (command.obj == OYSTER) {
1123 if (!TOTING(OYSTER) || !game.closed) {
1124 rspeak(DONT_UNDERSTAND);
1125 } else if (!game.clshnt) {
1126 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1128 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1130 } else if (objects[command.obj].texts[0] == NULL ||
1131 game.prop[command.obj] == STATE_NOTFOUND) {
1132 speak(actions[command.verb].message);
1134 pspeak(command.obj, study, true, game.prop[command.obj]);
1138 static phase_codes_t reservoir(void)
1139 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1141 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1142 rspeak(NOTHING_HAPPENS);
1146 game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1150 game.oldlc2 = game.loc;
1151 game.newloc = LOC_NOWHERE;
1153 return GO_TERMINATE;
1158 static phase_codes_t rub(verb_t verb, obj_t obj)
1159 /* Rub. Yields various snide remarks except for lit urn. */
1161 if (obj == URN && game.prop[URN] == URN_LIT) {
1163 drop(AMBER, game.loc);
1164 game.prop[AMBER] = AMBER_IN_ROCK;
1166 drop(CAVITY, game.loc);
1168 } else if (obj != LAMP) {
1169 rspeak(PECULIAR_NOTHING);
1171 speak(actions[verb].message);
1176 static phase_codes_t say(command_t command)
1177 /* Say. Echo WD2. Magic words override. */
1179 if (command.word[1].type == MOTION &&
1180 (command.word[1].id == XYZZY ||
1181 command.word[1].id == PLUGH ||
1182 command.word[1].id == PLOVER)) {
1185 if (command.word[1].type == ACTION && command.word[1].id == PART)
1188 if (command.word[1].type == ACTION &&
1189 (command.word[1].id == FEE ||
1190 command.word[1].id == FIE ||
1191 command.word[1].id == FOE ||
1192 command.word[1].id == FOO ||
1193 command.word[1].id == FUM ||
1194 command.word[1].id == PART)) {
1195 return bigwords(command.word[1].id);
1197 sspeak(OKEY_DOKEY, command.word[1].raw);
1201 static phase_codes_t throw_support(vocab_t spk)
1204 drop(AXE, game.loc);
1208 static phase_codes_t throwit(command_t command)
1209 /* Throw. Same as discard unless axe. Then same as attack except
1210 * ignore bird, and if dwarf is present then one might be killed.
1211 * (Only way to do so!) Axe also special for dragon, bear, and
1212 * troll. Treasures special for troll. */
1214 if (!TOTING(command.obj)) {
1215 speak(actions[command.verb].message);
1218 if (objects[command.obj].is_treasure && AT(TROLL)) {
1219 /* Snarf a treasure for the troll. */
1220 drop(command.obj, LOC_NOWHERE);
1221 move(TROLL, LOC_NOWHERE);
1222 move(TROLL + NOBJECTS, IS_FREE);
1223 drop(TROLL2, objects[TROLL].plac);
1224 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1226 rspeak(TROLL_SATISFIED);
1229 if (command.obj == FOOD && HERE(BEAR)) {
1230 /* But throwing food is another story. */
1232 return (feed(command.verb, command.obj));
1234 if (command.obj != AXE)
1235 return (discard(command.verb, command.obj));
1237 if (atdwrf(game.loc) <= 0) {
1238 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS)
1239 return throw_support(DRAGON_SCALES);
1241 return throw_support(TROLL_RETURNS);
1243 return throw_support(OGRE_DODGE);
1244 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
1245 /* This'll teach him to throw the axe at the bear! */
1246 drop(AXE, game.loc);
1247 game.fixed[AXE] = IS_FIXED;
1249 state_change(AXE, AXE_LOST);
1252 command.obj = INTRANSITIVE;
1253 return (attack(command));
1256 if (randrange(NDWARVES + 1) < game.dflag) {
1257 return throw_support(DWARF_DODGES);
1259 int i = atdwrf(game.loc);
1260 game.dseen[i] = false;
1261 game.dloc[i] = LOC_NOWHERE;
1262 return throw_support((++game.dkill == 1) ?
1269 static phase_codes_t wake(verb_t verb, obj_t obj)
1270 /* Wake. Only use is to disturb the dwarves. */
1274 speak(actions[verb].message);
1278 return GO_DWARFWAKE;
1282 static phase_codes_t seed(verb_t verb, const char *arg)
1285 int32_t seed = strtol(arg, NULL, 10);
1286 speak(actions[verb].message, seed);
1292 static phase_codes_t waste(verb_t verb, turn_t turns)
1295 game.limit -= turns;
1296 speak(actions[verb].message, (int)game.limit);
1300 static phase_codes_t wave(verb_t verb, obj_t obj)
1301 /* Wave. No effect unless waving rod at fissure or at bird. */
1308 speak(((!TOTING(obj)) && (obj != ROD ||
1310 arbitrary_messages[ARENT_CARRYING] :
1311 actions[verb].message);
1315 if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1316 drop(JADE, game.loc);
1317 game.prop[JADE] = STATE_FOUND;
1319 rspeak(NECKLACE_FLY);
1323 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1326 return GO_DWARFWAKE;
1330 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1336 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1340 state_change(FISSURE,
1341 game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED);
1346 phase_codes_t action(command_t command)
1347 /* Analyse a verb. Remember what it was, go back for object if second word
1348 * unless verb is "say", which snarfs arbitrary second word.
1351 /* Previously, actions that result in a message, but don't do anything
1352 * further were called "specials". Now they're handled here as normal
1353 * actions. If noaction is true, then we spit out the message and return */
1354 if (actions[command.verb].noaction) {
1355 speak(actions[command.verb].message);
1359 if (command.part == unknown) {
1360 /* Analyse an object word. See if the thing is here, whether
1361 * we've got a verb yet, and so on. Object must be here
1362 * unless verb is "find" or "invent(ory)" (and no new verb
1363 * yet to be analysed). Water and oil are also funny, since
1364 * they are never actually dropped at any location, but might
1365 * be here inside the bottle or urn or as a feature of the
1367 if (HERE(command.obj))
1369 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1371 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1372 command.obj == LIQLOC(game.loc)))
1374 else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
1377 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) {
1378 command.obj = PLANT2;
1380 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1382 rspeak(KNIVES_VANISH);
1384 } else if (command.obj == ROD && HERE(ROD2)) {
1387 } else if ((command.verb == FIND ||
1388 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1391 sspeak(NO_SEE, command.word[0].raw);
1395 if (command.verb != 0)
1396 command.part = transitive;
1399 switch (command.part) {
1401 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1403 if (command.verb == SAY)
1404 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1405 * will do here. We're preventing interpretation as an intransitive
1406 * verb when the word is unknown. */
1407 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1408 if (command.obj == NO_OBJECT ||
1409 command.obj == INTRANSITIVE) {
1410 /* Analyse an intransitive verb (ie, no object given yet). */
1411 switch (command.verb) {
1413 return vcarry(command.verb, INTRANSITIVE);
1419 return lock(command.verb, INTRANSITIVE);
1422 return (GO_CLEAROBJ);
1425 return lock(command.verb, INTRANSITIVE);
1427 return light(command.verb, INTRANSITIVE);
1429 return extinguish(command.verb, INTRANSITIVE);
1435 speak(actions[command.verb].message);
1439 command.obj = INTRANSITIVE;
1440 return attack(command);
1442 return pour(command.verb, INTRANSITIVE);
1444 return eat(command.verb, INTRANSITIVE);
1446 return drink(command.verb, INTRANSITIVE);
1460 return fill(command.verb, INTRANSITIVE);
1472 return bigwords(command.word[0].id);
1476 command.obj = INTRANSITIVE;
1477 return read(command);
1487 return fly(command.verb, INTRANSITIVE);
1494 rspeak(NUMERIC_REQUIRED);
1496 default: // LCOV_EXCL_LINE
1497 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1502 /* Analyse a transitive verb. */
1503 switch (command.verb) {
1505 return vcarry(command.verb, command.obj);
1507 return discard(command.verb, command.obj);
1509 return say(command);
1511 return lock(command.verb, command.obj);
1514 return (GO_CLEAROBJ);
1517 return lock(command.verb, command.obj);
1519 return light(command.verb, command.obj);
1521 return extinguish(command.verb, command.obj);
1523 return wave(command.verb, command.obj);
1525 speak(actions[command.verb].message);
1529 speak(actions[command.verb].message);
1533 return attack(command);
1535 return pour(command.verb, command.obj);
1537 return eat(command.verb, command.obj);
1539 return drink(command.verb, command.obj);
1541 return rub(command.verb, command.obj);
1543 return throwit(command);
1545 speak(actions[command.verb].message);
1549 return find(command.verb, command.obj);
1551 return find(command.verb, command.obj);
1553 return feed(command.verb, command.obj);
1555 return fill(command.verb, command.obj);
1560 speak(actions[command.verb].message);
1568 speak(actions[command.verb].message);
1572 speak(actions[command.verb].message);
1576 return read(command);
1578 return vbreak(command.verb, command.obj);
1580 return wake(command.verb, command.obj);
1582 speak(actions[command.verb].message);
1586 speak(actions[command.verb].message);
1590 return fly(command.verb, command.obj);
1592 speak(actions[command.verb].message);
1596 // This case should never happen - here only as placeholder
1601 return seed(command.verb, command.word[1].raw);
1603 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1604 default: // LCOV_EXCL_LINE
1605 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1608 /* Unknown verb, couldn't deduce object - might need hint */
1609 sspeak(WHAT_DO, command.word[0].raw);
1610 return GO_CHECKHINT;
1611 default: // LCOV_EXCL_LINE
1612 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE