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.objects[DRAGON].prop == DRAGON_BARS) {
49 if (HERE(BEAR) && game.objects[BEAR].prop == 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.objects[VEND].prop == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
92 switch (game.objects[BEAR].prop) {
97 rspeak(BEAR_CONFUSED);
100 rspeak(BEAR_CONFUSED);
103 rspeak(ALREADY_DEAD);
108 if (obj == DRAGON && game.objects[DRAGON].prop == 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.objects[RUG].prop = 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.objects[i].place == objects[DRAGON].plac ||
132 game.objects[i].place == 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.dwarves[i].loc == game.loc) {
150 game.dwarves[i].loc = LOC_LONGWEST;
151 game.dwarves[i].seen = 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.objects[EGGS].place == 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.objects[EGGS].place == LOC_NOWHERE && game.objects[TROLL].place == LOC_NOWHERE
221 && game.objects[TROLL].prop == TROLL_UNPAID)
222 game.objects[TROLL].prop = TROLL_PAIDONCE;
224 pspeak(EGGS, look, true, EGGS_VANISHED);
225 else if (game.loc == objects[EGGS].plac)
226 pspeak(EGGS, look, true, EGGS_HERE);
228 pspeak(EGGS, look, true, EGGS_DONE);
229 move(EGGS, objects[EGGS].plac);
234 /* Magic-word sequence was started but is incorrect */
235 if (settings.oldstyle || game.seenbigwords)
238 rspeak(WELL_POINTLESS);
239 game.foobar = WORD_EMPTY;
244 static void blast(void)
245 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
247 if (PROP_IS_NOTFOUND(ROD2) || !game.closed)
248 rspeak(REQUIRES_DYNAMITE);
251 game.bonus = splatter;
252 rspeak(SPLATTER_MESSAGE);
253 } else if (game.loc == LOC_NE) {
255 rspeak(DEFEAT_MESSAGE);
257 game.bonus = victory;
258 rspeak(VICTORY_MESSAGE);
264 static phase_codes_t vbreak(verb_t verb, obj_t obj)
265 /* Break. Only works for mirror in repository and, of course, the vase. */
270 state_change(MIRROR, MIRROR_BROKEN);
277 if (game.objects[VASE].prop == VASE_WHOLE) {
279 drop(VASE, game.loc);
280 state_change(VASE, VASE_BROKEN);
281 game.objects[VASE].fixed = IS_FIXED;
286 speak(actions[verb].message);
288 return (GO_CLEAROBJ);
291 static phase_codes_t brief(void)
292 /* Brief. Intransitive only. Suppress full descriptions after first time. */
296 rspeak(BRIEF_CONFIRM);
300 static phase_codes_t vcarry(verb_t verb, obj_t obj)
301 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
302 * take one without the other). Liquids also special, since they depend on
303 * status of bottle. Also various side effects, etc. */
305 if (obj == INTRANSITIVE) {
306 /* Carry, no object given yet. OK if only one object present. */
307 if (game.locs[game.loc].atloc == NO_OBJECT ||
308 game.link[game.locs[game.loc].atloc] != 0 ||
309 atdwrf(game.loc) > 0)
311 obj = game.locs[game.loc].atloc;
315 speak(actions[verb].message);
320 rspeak(REMOVE_MESSAGE);
325 if (game.objects[obj].fixed != IS_FREE) {
328 /* Next guard tests whether plant is tiny or stashed */
329 rspeak(game.objects[PLANT].prop <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
332 rspeak( game.objects[BEAR].prop == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
335 rspeak( game.objects[BEAR].prop != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
338 rspeak(game.objects[RUG].prop == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
344 rspeak(DOUGHNUT_HOLES);
350 rspeak(HAND_PASSTHROUGH);
358 if (obj == WATER || obj == OIL) {
359 if (!HERE(BOTTLE) || LIQUID() != obj) {
360 if (!TOTING(BOTTLE)) {
361 rspeak(NO_CONTAINER);
364 if (game.objects[BOTTLE].prop == EMPTY_BOTTLE) {
365 return (fill(verb, BOTTLE));
373 if (game.holdng >= INVLIMIT) {
379 if (obj == BIRD && game.objects[BIRD].prop != BIRD_CAGED && !PROP_IS_STASHED(BIRD)) {
380 if (game.objects[BIRD].prop == BIRD_FOREST_UNCAGED) {
386 rspeak(CANNOT_CARRY);
393 game.objects[BIRD].prop = BIRD_CAGED;
395 if ((obj == BIRD || obj == CAGE) &&
396 (game.objects[BIRD].prop == BIRD_CAGED || PROP_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.objects[LIQUID()].place = CARRIED;
406 if (GSTONE(obj) && !PROP_IS_FOUND(obj)) {
408 game.objects[CAVITY].prop = CAVITY_EMPTY;
414 static int chain(verb_t verb)
415 /* Do something to the bear's chain */
418 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
422 if (game.objects[CHAIN].prop == CHAIN_HEAP) {
423 rspeak(ALREADY_UNLOCKED);
426 game.objects[CHAIN].prop = CHAIN_HEAP;
427 game.objects[CHAIN].fixed = IS_FREE;
428 if (game.objects[BEAR].prop != BEAR_DEAD)
429 game.objects[BEAR].prop = CONTENTED_BEAR;
431 switch (game.objects[BEAR].prop) {
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.objects[BEAR].fixed = IS_FIXED;
441 game.objects[BEAR].fixed = IS_FREE;
443 rspeak(CHAIN_UNLOCKED);
447 if (game.objects[CHAIN].prop != CHAIN_HEAP) {
448 rspeak(ALREADY_LOCKED);
451 if (game.loc != objects[CHAIN].plac) {
456 game.objects[CHAIN].prop = CHAIN_FIXED;
459 drop(CHAIN, game.loc);
460 game.objects[CHAIN].fixed = 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.objects[CAVITY].prop != CAVITY_FULL) {
482 game.objects[obj].prop = STATE_IN_CAVITY;
483 game.objects[CAVITY].prop = CAVITY_FULL;
484 if (HERE(RUG) && ((obj == EMERALD && game.objects[RUG].prop != RUG_HOVER) ||
485 (obj == RUBY && game.objects[RUG].prop == RUG_HOVER))) {
488 else if (TOTING(RUG))
492 if (!TOTING(RUG) || obj == RUBY) {
493 int k = (game.objects[RUG].prop == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
494 game.objects[RUG].prop = k;
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.objects[LIQUID()].place = 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.objects[VASE].prop != VASE_WHOLE)
534 game.objects[VASE].fixed = IS_FIXED;
540 if (obj == CAGE && game.objects[BIRD].prop == BIRD_CAGED) {
541 drop(BIRD, game.loc);
545 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) {
551 rspeak(BIRD_ATTACKS);
555 /* Set game.prop for use by travel options */
556 game.objects[SNAKE].prop = SNAKE_CHASED;
560 game.objects[BIRD].prop = 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.objects[WATER].place = 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.objects[LAMP].prop == LAMP_BRIGHT)
636 if (HERE(URN) && game.objects[URN].prop == URN_LIT)
638 if (obj == INTRANSITIVE)
644 if (game.objects[URN].prop != 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.objects[DRAGON].prop != 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.objects[BEAR].prop == BEAR_DEAD) {
699 rspeak(RIDICULOUS_ATTEMPT);
702 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
705 game.objects[AXE].fixed = IS_FREE;
706 game.objects[AXE].prop = 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.objects[VASE].prop = VASE_BROKEN;
741 game.objects[VASE].fixed = IS_FIXED;
742 drop(VASE, game.loc);
747 if (game.objects[URN].prop != URN_EMPTY) {
752 rspeak(FILL_INVALID);
758 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
762 game.objects[URN].prop = URN_DARK;
763 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
768 rspeak(FILL_INVALID);
771 game.objects[k].place = LOC_NOWHERE;
774 if (obj != INTRANSITIVE && obj != BOTTLE) {
775 speak(actions[verb].message);
778 if (obj == INTRANSITIVE && !HERE(BOTTLE))
781 if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
785 if (LIQUID() != NO_OBJECT) {
789 if (LIQLOC(game.loc) == NO_OBJECT) {
794 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
798 game.objects[LIQUID()].place = 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);
815 if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
816 obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
822 speak(actions[verb].message);
826 static phase_codes_t fly(verb_t verb, obj_t obj)
827 /* Fly. Snide remarks unless hovering rug is here. */
829 if (obj == INTRANSITIVE) {
834 if (game.objects[RUG].prop != RUG_HOVER) {
835 rspeak(RUG_NOTHING2);
842 speak(actions[verb].message);
845 if (game.objects[RUG].prop != RUG_HOVER) {
846 rspeak(RUG_NOTHING1);
850 if (game.loc == LOC_CLIFF) {
851 game.oldlc2 = game.oldloc;
852 game.oldloc = game.loc;
853 game.newloc = LOC_LEDGE;
855 } else if (game.loc == LOC_LEDGE) {
856 game.oldlc2 = game.oldloc;
857 game.oldloc = game.loc;
858 game.newloc = LOC_CLIFF;
862 /* should never happen */
863 rspeak(NOTHING_HAPPENS);
869 static phase_codes_t inven(void)
870 /* Inventory. If object, treat same as find. Else report on current burden. */
873 for (obj_t i = 1; i <= NOBJECTS; i++) {
874 if (i == BEAR || !TOTING(i))
880 pspeak(i, touch, false, -1);
889 static phase_codes_t light(verb_t verb, obj_t obj)
890 /* Light. Applicable only to lamp and urn. */
892 if (obj == INTRANSITIVE) {
894 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_DARK && game.limit >= 0) {
898 if (HERE(URN) && game.objects[URN].prop == URN_DARK) {
908 state_change(URN, game.objects[URN].prop == URN_EMPTY ?
913 if (game.limit < 0) {
917 state_change(LAMP, LAMP_BRIGHT);
922 speak(actions[verb].message);
927 static phase_codes_t listen(void)
928 /* Listen. Intransitive only. Print stuff based on object sound properties. */
930 bool soundlatch = false;
931 vocab_t sound = locations[game.loc].sound;
932 if (sound != SILENT) {
934 if (!locations[game.loc].loud)
938 for (obj_t i = 1; i <= NOBJECTS; i++) {
939 if (!HERE(i) || objects[i].sounds[0] == NULL || PROP_IS_STASHED_OR_UNSEEN(i))
941 int mi = game.objects[i].prop;
942 /* (ESR) Some unpleasant magic on object states here. Ideally
943 * we'd have liked the bird to be a normal object that we can
944 * use state_change() on; can't do it, because there are
945 * actually two different series of per-state birdsounds
946 * depending on whether player has drunk dragon's blood. */
948 mi += 3 * game.blooded;
949 pspeak(i, hear, true, mi, game.zzword);
951 if (i == BIRD && mi == BIRD_ENDSTATE)
960 static phase_codes_t lock(verb_t verb, obj_t obj)
961 /* Lock, unlock, no object given. Assume various things if present. */
963 if (obj == INTRANSITIVE) {
974 if (obj == INTRANSITIVE) {
975 rspeak(NOTHING_LOCKED);
980 /* Lock, unlock object. Special stuff for opening clam/oyster
995 game.clock2 = PANICTIME;
998 state_change(GRATE, (verb == LOCK) ?
1008 else if (TOTING(CLAM))
1010 else if (!TOTING(TRIDENT))
1011 rspeak(CLAM_OPENER);
1014 drop(OYSTER, game.loc);
1015 drop(PEARL, LOC_CULDESAC);
1016 rspeak(PEARL_FALLS);
1022 else if (TOTING(OYSTER))
1023 rspeak(DROP_OYSTER);
1024 else if (!TOTING(TRIDENT))
1025 rspeak(OYSTER_OPENER);
1027 rspeak(OYSTER_OPENS);
1030 rspeak((game.objects[DOOR].prop == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1036 rspeak(CANNOT_UNLOCK);
1039 speak(actions[verb].message);
1045 static phase_codes_t pour(verb_t verb, obj_t obj)
1046 /* Pour. If no object, or object is bottle, assume contents of bottle.
1047 * special tests for pouring water or oil on plant or rusty door. */
1049 if (obj == BOTTLE || obj == INTRANSITIVE)
1051 if (obj == NO_OBJECT)
1054 speak(actions[verb].message);
1058 if (obj != OIL && obj != WATER) {
1062 if (HERE(URN) && game.objects[URN].prop == URN_EMPTY)
1063 return fill(verb, URN);
1064 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
1065 game.objects[obj].place = LOC_NOWHERE;
1066 if (!(AT(PLANT) || AT(DOOR))) {
1072 /* cycle through the three plant states */
1073 state_change(PLANT, MOD(game.objects[PLANT].prop + 1, 3));
1074 game.objects[PLANT2].prop = game.objects[PLANT].prop;
1077 rspeak(SHAKING_LEAVES);
1081 state_change(DOOR, (obj == OIL) ?
1088 static phase_codes_t quit(void)
1089 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1091 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1092 terminate(quitgame);
1096 static phase_codes_t read(command_t command)
1097 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1099 if (command.obj == INTRANSITIVE) {
1100 command.obj = NO_OBJECT;
1101 for (int i = 1; i <= NOBJECTS; i++) {
1102 if (HERE(i) && objects[i].texts[0] != NULL && game.objects[i].prop >= 0)
1103 command.obj = command.obj * NOBJECTS + i;
1105 if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc))
1109 if (DARK(game.loc)) {
1110 sspeak(NO_SEE, command.word[0].raw);
1111 } else if (command.obj == OYSTER) {
1112 if (!TOTING(OYSTER) || !game.closed) {
1113 rspeak(DONT_UNDERSTAND);
1114 } else if (!game.clshnt) {
1115 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1117 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1119 } else if (objects[command.obj].texts[0] == NULL || PROP_IS_NOTFOUND(command.obj)) {
1120 speak(actions[command.verb].message);
1122 pspeak(command.obj, study, true, game.objects[command.obj].prop);
1126 static phase_codes_t reservoir(void)
1127 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1129 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1130 rspeak(NOTHING_HAPPENS);
1134 game.objects[RESER].prop == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1138 game.oldlc2 = game.loc;
1139 game.newloc = LOC_NOWHERE;
1141 return GO_TERMINATE;
1146 static phase_codes_t rub(verb_t verb, obj_t obj)
1147 /* Rub. Yields various snide remarks except for lit urn. */
1149 if (obj == URN && game.objects[URN].prop == URN_LIT) {
1151 drop(AMBER, game.loc);
1152 game.objects[AMBER].prop = AMBER_IN_ROCK;
1154 drop(CAVITY, game.loc);
1156 } else if (obj != LAMP) {
1157 rspeak(PECULIAR_NOTHING);
1159 speak(actions[verb].message);
1164 static phase_codes_t say(command_t command)
1165 /* Say. Echo WD2. Magic words override. */
1167 if (command.word[1].type == MOTION &&
1168 (command.word[1].id == XYZZY ||
1169 command.word[1].id == PLUGH ||
1170 command.word[1].id == PLOVER)) {
1173 if (command.word[1].type == ACTION && command.word[1].id == PART)
1176 if (command.word[1].type == ACTION &&
1177 (command.word[1].id == FEE ||
1178 command.word[1].id == FIE ||
1179 command.word[1].id == FOE ||
1180 command.word[1].id == FOO ||
1181 command.word[1].id == FUM ||
1182 command.word[1].id == PART)) {
1183 return bigwords(command.word[1].id);
1185 sspeak(OKEY_DOKEY, command.word[1].raw);
1189 static phase_codes_t throw_support(vocab_t spk)
1192 drop(AXE, game.loc);
1196 static phase_codes_t throwit(command_t command)
1197 /* Throw. Same as discard unless axe. Then same as attack except
1198 * ignore bird, and if dwarf is present then one might be killed.
1199 * (Only way to do so!) Axe also special for dragon, bear, and
1200 * troll. Treasures special for troll. */
1202 if (!TOTING(command.obj)) {
1203 speak(actions[command.verb].message);
1206 if (objects[command.obj].is_treasure && AT(TROLL)) {
1207 /* Snarf a treasure for the troll. */
1208 drop(command.obj, LOC_NOWHERE);
1209 move(TROLL, LOC_NOWHERE);
1210 move(TROLL + NOBJECTS, IS_FREE);
1211 drop(TROLL2, objects[TROLL].plac);
1212 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1214 rspeak(TROLL_SATISFIED);
1217 if (command.obj == FOOD && HERE(BEAR)) {
1218 /* But throwing food is another story. */
1220 return (feed(command.verb, command.obj));
1222 if (command.obj != AXE)
1223 return (discard(command.verb, command.obj));
1225 if (atdwrf(game.loc) <= 0) {
1226 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS)
1227 return throw_support(DRAGON_SCALES);
1229 return throw_support(TROLL_RETURNS);
1231 return throw_support(OGRE_DODGE);
1232 if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) {
1233 /* This'll teach him to throw the axe at the bear! */
1234 drop(AXE, game.loc);
1235 game.objects[AXE].fixed = IS_FIXED;
1237 state_change(AXE, AXE_LOST);
1240 command.obj = INTRANSITIVE;
1241 return (attack(command));
1244 if (randrange(NDWARVES + 1) < game.dflag) {
1245 return throw_support(DWARF_DODGES);
1247 int i = atdwrf(game.loc);
1248 game.dwarves[i].seen = false;
1249 game.dwarves[i].loc = LOC_NOWHERE;
1250 return throw_support((++game.dkill == 1) ?
1257 static phase_codes_t wake(verb_t verb, obj_t obj)
1258 /* Wake. Only use is to disturb the dwarves. */
1260 if (obj != DWARF || !game.closed) {
1261 speak(actions[verb].message);
1265 return GO_DWARFWAKE;
1269 static phase_codes_t seed(verb_t verb, const char *arg)
1272 int32_t seed = strtol(arg, NULL, 10);
1273 speak(actions[verb].message, seed);
1279 static phase_codes_t waste(verb_t verb, turn_t turns)
1282 game.limit -= turns;
1283 speak(actions[verb].message, (int)game.limit);
1287 static phase_codes_t wave(verb_t verb, obj_t obj)
1288 /* Wave. No effect unless waving rod at fissure or at bird. */
1290 if (obj != ROD || !TOTING(obj) || (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
1291 speak(((!TOTING(obj)) && (obj != ROD ||
1293 arbitrary_messages[ARENT_CARRYING] :
1294 actions[verb].message);
1298 if (game.objects[BIRD].prop == BIRD_UNCAGED && game.loc == game.objects[STEPS].place
1299 && PROP_IS_NOTFOUND(JADE)) {
1300 drop(JADE, game.loc);
1301 PROP_SET_FOUND(JADE);
1303 rspeak(NECKLACE_FLY);
1307 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1310 return GO_DWARFWAKE;
1312 if (game.closng || !AT(FISSURE)) {
1313 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1319 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1323 state_change(FISSURE,
1324 game.objects[FISSURE].prop == BRIDGED ? UNBRIDGED : BRIDGED);
1329 phase_codes_t action(command_t command)
1330 /* Analyse a verb. Remember what it was, go back for object if second word
1331 * unless verb is "say", which snarfs arbitrary second word.
1334 /* Previously, actions that result in a message, but don't do anything
1335 * further were called "specials". Now they're handled here as normal
1336 * actions. If noaction is true, then we spit out the message and return */
1337 if (actions[command.verb].noaction) {
1338 speak(actions[command.verb].message);
1342 if (command.part == unknown) {
1343 /* Analyse an object word. See if the thing is here, whether
1344 * we've got a verb yet, and so on. Object must be here
1345 * unless verb is "find" or "invent(ory)" (and no new verb
1346 * yet to be analysed). Water and oil are also funny, since
1347 * they are never actually dropped at any location, but might
1348 * be here inside the bottle or urn or as a feature of the
1350 if (HERE(command.obj))
1352 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1354 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1355 command.obj == LIQLOC(game.loc)))
1357 else if (command.obj == OIL && HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
1360 } else if (command.obj == PLANT && AT(PLANT2) && game.objects[PLANT2].prop != PLANT_THIRSTY) {
1361 command.obj = PLANT2;
1363 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1365 rspeak(KNIVES_VANISH);
1367 } else if (command.obj == ROD && HERE(ROD2)) {
1370 } else if ((command.verb == FIND ||
1371 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1374 sspeak(NO_SEE, command.word[0].raw);
1378 if (command.verb != 0)
1379 command.part = transitive;
1382 switch (command.part) {
1384 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1386 if (command.verb == SAY)
1387 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1388 * will do here. We're preventing interpretation as an intransitive
1389 * verb when the word is unknown. */
1390 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1391 if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
1392 /* Analyse an intransitive verb (ie, no object given yet). */
1393 switch (command.verb) {
1395 return vcarry(command.verb, INTRANSITIVE);
1401 return lock(command.verb, INTRANSITIVE);
1404 return (GO_CLEAROBJ);
1407 return lock(command.verb, INTRANSITIVE);
1409 return light(command.verb, INTRANSITIVE);
1411 return extinguish(command.verb, INTRANSITIVE);
1417 speak(actions[command.verb].message);
1421 command.obj = INTRANSITIVE;
1422 return attack(command);
1424 return pour(command.verb, INTRANSITIVE);
1426 return eat(command.verb, INTRANSITIVE);
1428 return drink(command.verb, INTRANSITIVE);
1442 return fill(command.verb, INTRANSITIVE);
1454 return bigwords(command.word[0].id);
1458 command.obj = INTRANSITIVE;
1459 return read(command);
1469 return fly(command.verb, INTRANSITIVE);
1476 rspeak(NUMERIC_REQUIRED);
1478 default: // LCOV_EXCL_LINE
1479 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1484 /* Analyse a transitive verb. */
1485 switch (command.verb) {
1487 return vcarry(command.verb, command.obj);
1489 return discard(command.verb, command.obj);
1491 return say(command);
1493 return lock(command.verb, command.obj);
1496 return (GO_CLEAROBJ);
1499 return lock(command.verb, command.obj);
1501 return light(command.verb, command.obj);
1503 return extinguish(command.verb, command.obj);
1505 return wave(command.verb, command.obj);
1507 speak(actions[command.verb].message);
1511 speak(actions[command.verb].message);
1515 return attack(command);
1517 return pour(command.verb, command.obj);
1519 return eat(command.verb, command.obj);
1521 return drink(command.verb, command.obj);
1523 return rub(command.verb, command.obj);
1525 return throwit(command);
1527 speak(actions[command.verb].message);
1531 return find(command.verb, command.obj);
1533 return find(command.verb, command.obj);
1535 return feed(command.verb, command.obj);
1537 return fill(command.verb, command.obj);
1542 speak(actions[command.verb].message);
1550 speak(actions[command.verb].message);
1554 speak(actions[command.verb].message);
1558 return read(command);
1560 return vbreak(command.verb, command.obj);
1562 return wake(command.verb, command.obj);
1564 speak(actions[command.verb].message);
1568 speak(actions[command.verb].message);
1572 return fly(command.verb, command.obj);
1574 speak(actions[command.verb].message);
1578 // This case should never happen - here only as placeholder
1583 return seed(command.verb, command.word[1].raw);
1585 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1586 default: // LCOV_EXCL_LINE
1587 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1590 /* Unknown verb, couldn't deduce object - might need hint */
1591 sspeak(WHAT_DO, command.word[0].raw);
1592 return GO_CHECKHINT;
1593 default: // LCOV_EXCL_LINE
1594 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE