2 * Actions for the dungeon-running code.
4 * SPDX-FileCopyrightText: Copyright 1977, 2005 by Will Crowther and Don Woods, Copyright 2017 by Eric S. Raymond
5 * SPDX-License-Identifier: BSD-2-Clause
15 static phase_codes_t fill(verb_t, obj_t);
17 static phase_codes_t attack(command_t command)
18 /* Attack. Assume target if unambiguous. "Throw" also links here.
19 * Attackable objects fall into two categories: enemies (snake,
20 * dwarf, etc.) and others (bird, clam, machine). Ambiguous if 2
21 * enemies, or no enemies but 2 others. */
23 verb_t verb = command.verb;
24 obj_t obj = command.obj;
26 if (obj == INTRANSITIVE) {
28 if (atdwrf(game.loc) > 0) {
36 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) {
48 if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) {
52 /* check for low-priority targets */
53 if (obj == INTRANSITIVE) {
54 /* Can't attack bird or machine by throwing axe. */
55 if (HERE(BIRD) && verb != THROW) {
59 if (HERE(VEND) && verb != THROW) {
63 /* Clam and oyster both treated as clam for intransitive case;
65 if (HERE(CLAM) || HERE(OYSTER)) {
85 game.objects[VEND].prop == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
91 switch (game.objects[BEAR].prop) {
96 rspeak(BEAR_CONFUSED);
99 rspeak(BEAR_CONFUSED);
102 rspeak(ALREADY_DEAD);
107 if (obj == DRAGON && game.objects[DRAGON].prop == DRAGON_BARS) {
108 /* Fun stuff for dragon. If he insists on attacking it, win!
109 * Set game.prop to dead, move dragon to central loc (still
110 * fixed), move rug there (not fixed), and move him there,
111 * too. Then do a null motion to get new description. */
112 rspeak(BARE_HANDS_QUERY);
113 if (!silent_yes_or_no()) {
114 speak(arbitrary_messages[NASTY_DRAGON]);
117 state_change(DRAGON, DRAGON_DEAD);
118 game.objects[RUG].prop = RUG_FLOOR;
119 /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly.
120 * The way it was computed before was worse; it depended on the
121 * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and
122 * LOC_SECRET5 being right between them.
124 move(DRAGON + NOBJECTS, IS_FIXED);
125 move(RUG + NOBJECTS, IS_FREE);
126 move(DRAGON, LOC_SECRET5);
127 move(RUG, LOC_SECRET5);
128 drop(BLOOD, LOC_SECRET5);
129 for (obj_t i = 1; i <= NOBJECTS; i++) {
130 if (game.objects[i].place == objects[DRAGON].plac ||
131 game.objects[i].place == objects[DRAGON].fixd)
132 move(i, LOC_SECRET5);
134 game.loc = LOC_SECRET5;
140 if (atdwrf(game.loc) == 0)
143 rspeak(KNIFE_THROWN);
146 for (int i = 1; i < PIRATE; i++) {
147 if (game.dwarves[i].loc == game.loc) {
149 game.dwarves[i].loc = LOC_LONGWEST;
150 game.dwarves[i].seen = false;
153 rspeak((dwarves > 1) ?
165 rspeak(SHELL_IMPERVIOUS);
168 rspeak(SNAKE_WARNING);
174 rspeak(BARE_HANDS_QUERY);
177 rspeak(ALREADY_DEAD);
183 speak(actions[verb].message);
188 static phase_codes_t bigwords(vocab_t id)
189 /* Only called on FEE FIE FOE FOO (AND FUM). Advance to next state if given
190 * in proper order. Look up foo in special section of vocab to determine which
191 * word we've got. Last word zips the eggs back to the giant room (unless
194 int foobar = abs(game.foobar);
196 /* Only FEE can start a magic-word sequence. */
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)) {
211 game.foobar = WORD_EMPTY;
212 if (game.objects[EGGS].place == objects[EGGS].plac ||
213 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
214 rspeak(NOTHING_HAPPENS);
217 /* Bring back troll if we steal the eggs back from him before
219 if (game.objects[EGGS].place == LOC_NOWHERE && game.objects[TROLL].place == LOC_NOWHERE
220 && game.objects[TROLL].prop == TROLL_UNPAID)
221 game.objects[TROLL].prop = 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 sequence was started but is incorrect */
234 if (settings.oldstyle || game.seenbigwords)
237 rspeak(WELL_POINTLESS);
238 game.foobar = WORD_EMPTY;
243 static void blast(void)
244 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
246 if (PROP_IS_NOTFOUND(ROD2) || !game.closed)
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.objects[VASE].prop == VASE_WHOLE) {
278 drop(VASE, game.loc);
279 state_change(VASE, VASE_BROKEN);
280 game.objects[VASE].fixed = 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.locs[game.loc].atloc == NO_OBJECT ||
307 game.link[game.locs[game.loc].atloc] != 0 ||
308 atdwrf(game.loc) > 0)
310 obj = game.locs[game.loc].atloc;
314 speak(actions[verb].message);
319 rspeak(REMOVE_MESSAGE);
324 if (game.objects[obj].fixed != IS_FREE) {
327 /* Next guard tests whether plant is tiny or stashed */
328 rspeak(game.objects[PLANT].prop <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
331 rspeak( game.objects[BEAR].prop == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
334 rspeak( game.objects[BEAR].prop != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
337 rspeak(game.objects[RUG].prop == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
343 rspeak(DOUGHNUT_HOLES);
349 rspeak(HAND_PASSTHROUGH);
357 if (obj == WATER || obj == OIL) {
358 if (!HERE(BOTTLE) || LIQUID() != obj) {
359 if (!TOTING(BOTTLE)) {
360 rspeak(NO_CONTAINER);
363 if (game.objects[BOTTLE].prop == EMPTY_BOTTLE) {
364 return (fill(verb, BOTTLE));
372 if (game.holdng >= INVLIMIT) {
378 if (obj == BIRD && game.objects[BIRD].prop != BIRD_CAGED && !PROP_IS_STASHED(BIRD)) {
379 if (game.objects[BIRD].prop == BIRD_FOREST_UNCAGED) {
385 rspeak(CANNOT_CARRY);
392 game.objects[BIRD].prop = BIRD_CAGED;
394 if ((obj == BIRD || obj == CAGE) &&
395 (game.objects[BIRD].prop == BIRD_CAGED || PROP_STASHED(BIRD) == BIRD_CAGED)) {
396 /* expression maps BIRD to CAGE and CAGE to BIRD */
397 carry(BIRD + CAGE - obj, game.loc);
400 carry(obj, game.loc);
402 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
403 game.objects[LIQUID()].place = CARRIED;
405 if (GSTONE(obj) && !PROP_IS_FOUND(obj)) {
407 game.objects[CAVITY].prop = CAVITY_EMPTY;
413 static int chain(verb_t verb)
414 /* Do something to the bear's chain */
417 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
421 if (game.objects[CHAIN].prop == CHAIN_HEAP) {
422 rspeak(ALREADY_UNLOCKED);
425 game.objects[CHAIN].prop = CHAIN_HEAP;
426 game.objects[CHAIN].fixed = IS_FREE;
427 if (game.objects[BEAR].prop != BEAR_DEAD)
428 game.objects[BEAR].prop = CONTENTED_BEAR;
430 switch (game.objects[BEAR].prop) {
433 /* Can't be reached until the bear can die in some way other
434 * than a bridge collapse. Leave in in case this changes, but
435 * exclude from coverage testing. */
436 game.objects[BEAR].fixed = IS_FIXED;
440 game.objects[BEAR].fixed = IS_FREE;
442 rspeak(CHAIN_UNLOCKED);
446 if (game.objects[CHAIN].prop != CHAIN_HEAP) {
447 rspeak(ALREADY_LOCKED);
450 if (game.loc != objects[CHAIN].plac) {
455 game.objects[CHAIN].prop = CHAIN_FIXED;
458 drop(CHAIN, game.loc);
459 game.objects[CHAIN].fixed = IS_FIXED;
461 rspeak(CHAIN_LOCKED);
465 static phase_codes_t discard(verb_t verb, obj_t obj)
466 /* Discard object. "Throw" also comes here for most objects. Special cases for
467 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
468 * Drop coins at vending machine for extra batteries. */
470 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
475 speak(actions[verb].message);
479 if (GSTONE(obj) && AT(CAVITY) && game.objects[CAVITY].prop != CAVITY_FULL) {
481 game.objects[obj].prop = STATE_IN_CAVITY;
482 game.objects[CAVITY].prop = CAVITY_FULL;
483 if (HERE(RUG) && ((obj == EMERALD && game.objects[RUG].prop != RUG_HOVER) ||
484 (obj == RUBY && game.objects[RUG].prop == RUG_HOVER))) {
487 else if (TOTING(RUG))
491 if (!TOTING(RUG) || obj == RUBY) {
492 int k = (game.objects[RUG].prop == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
493 game.objects[RUG].prop = k;
495 k = objects[SAPPH].plac;
496 move(RUG + NOBJECTS, k);
503 if (obj == COINS && HERE(VEND)) {
505 drop(BATTERY, game.loc);
506 pspeak(BATTERY, look, true, FRESH_BATTERIES);
512 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
513 game.objects[LIQUID()].place = LOC_NOWHERE;
516 if (obj == BEAR && AT(TROLL)) {
517 state_change(TROLL, TROLL_GONE);
518 move(TROLL, LOC_NOWHERE);
519 move(TROLL + NOBJECTS, IS_FREE);
520 move(TROLL2, objects[TROLL].plac);
521 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
528 if (game.loc != objects[PILLOW].plac) {
529 state_change(VASE, AT(PILLOW)
532 if (game.objects[VASE].prop != VASE_WHOLE)
533 game.objects[VASE].fixed = IS_FIXED;
539 if (obj == CAGE && game.objects[BIRD].prop == BIRD_CAGED) {
540 drop(BIRD, game.loc);
544 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) {
550 rspeak(BIRD_ATTACKS);
554 /* Set game.prop for use by travel options */
555 game.objects[SNAKE].prop = SNAKE_CHASED;
559 game.objects[BIRD].prop = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
569 static phase_codes_t drink(verb_t verb, obj_t obj)
570 /* Drink. If no object, assume water and look for it here. If water is in
571 * the bottle, drink that, else must be at a water loc, so drink stream. */
573 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
574 (LIQUID() != WATER || !HERE(BOTTLE))) {
580 state_change(DRAGON, DRAGON_BLOODLESS);
585 if (obj != INTRANSITIVE && obj != WATER) {
586 rspeak(RIDICULOUS_ATTEMPT);
589 if (LIQUID() == WATER && HERE(BOTTLE)) {
590 game.objects[WATER].place = LOC_NOWHERE;
591 state_change(BOTTLE, EMPTY_BOTTLE);
595 speak(actions[verb].message);
599 static phase_codes_t eat(verb_t verb, obj_t obj)
600 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
601 * ok, some things lose appetite, rest are ridiculous. */
610 rspeak(THANKS_DELICIOUS);
621 rspeak(LOST_APPETITE);
624 speak(actions[verb].message);
629 static phase_codes_t extinguish(verb_t verb, obj_t obj)
630 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
632 if (obj == INTRANSITIVE) {
633 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_BRIGHT)
635 if (HERE(URN) && game.objects[URN].prop == URN_LIT)
637 if (obj == INTRANSITIVE)
643 if (game.objects[URN].prop != URN_EMPTY) {
644 state_change(URN, URN_DARK);
646 pspeak(URN, change, true, URN_DARK);
650 state_change(LAMP, LAMP_DARK);
651 rspeak(DARK(game.loc) ?
657 rspeak(BEYOND_POWER);
660 speak(actions[verb].message);
665 static phase_codes_t feed(verb_t verb, obj_t obj)
666 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
667 * mad. Bear, special. */
674 if (game.objects[DRAGON].prop != DRAGON_BARS)
675 rspeak(RIDICULOUS_ATTEMPT);
677 rspeak(NOTHING_EDIBLE);
680 if (!game.closed && HERE(BIRD)) {
682 rspeak(BIRD_DEVOURED);
684 rspeak(NOTHING_EDIBLE);
694 speak(actions[verb].message);
697 if (game.objects[BEAR].prop == BEAR_DEAD) {
698 rspeak(RIDICULOUS_ATTEMPT);
701 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
704 game.objects[AXE].fixed = IS_FREE;
705 game.objects[AXE].prop = AXE_HERE;
706 state_change(BEAR, SITTING_BEAR);
708 rspeak(NOTHING_EDIBLE);
711 speak(actions[verb].message);
717 speak(actions[verb].message);
725 phase_codes_t fill(verb_t verb, obj_t obj)
726 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
730 if (LIQLOC(game.loc) == NO_OBJECT) {
731 rspeak(FILL_INVALID);
735 rspeak(ARENT_CARRYING);
738 rspeak(SHATTER_VASE);
739 game.objects[VASE].prop = VASE_BROKEN;
740 game.objects[VASE].fixed = IS_FIXED;
741 drop(VASE, game.loc);
746 if (game.objects[URN].prop != URN_EMPTY) {
751 rspeak(FILL_INVALID);
757 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
761 game.objects[URN].prop = URN_DARK;
762 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
767 rspeak(FILL_INVALID);
770 game.objects[k].place = LOC_NOWHERE;
773 if (obj != INTRANSITIVE && obj != BOTTLE) {
774 speak(actions[verb].message);
777 if (obj == INTRANSITIVE && !HERE(BOTTLE))
780 if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
784 if (LIQUID() != NO_OBJECT) {
788 if (LIQLOC(game.loc) == NO_OBJECT) {
793 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
797 game.objects[LIQUID()].place = CARRIED;
801 static phase_codes_t find(verb_t verb, obj_t obj)
802 /* Find. Might be carrying it, or it might be here. Else give caveat. */
805 rspeak(ALREADY_CARRYING);
810 rspeak(NEEDED_NEARBY);
814 if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
815 obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
821 speak(actions[verb].message);
825 static phase_codes_t fly(verb_t verb, obj_t obj)
826 /* Fly. Snide remarks unless hovering rug is here. */
828 if (obj == INTRANSITIVE) {
833 if (game.objects[RUG].prop != RUG_HOVER) {
834 rspeak(RUG_NOTHING2);
841 speak(actions[verb].message);
844 if (game.objects[RUG].prop != RUG_HOVER) {
845 rspeak(RUG_NOTHING1);
849 if (game.loc == LOC_CLIFF) {
850 game.oldlc2 = game.oldloc;
851 game.oldloc = game.loc;
852 game.newloc = LOC_LEDGE;
854 } else if (game.loc == LOC_LEDGE) {
855 game.oldlc2 = game.oldloc;
856 game.oldloc = game.loc;
857 game.newloc = LOC_CLIFF;
861 /* should never happen */
862 rspeak(NOTHING_HAPPENS);
868 static phase_codes_t inven(void)
869 /* Inventory. If object, treat same as find. Else report on current burden. */
872 for (obj_t i = 1; i <= NOBJECTS; i++) {
873 if (i == BEAR || !TOTING(i))
879 pspeak(i, touch, false, -1);
888 static phase_codes_t light(verb_t verb, obj_t obj)
889 /* Light. Applicable only to lamp and urn. */
891 if (obj == INTRANSITIVE) {
893 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_DARK && game.limit >= 0) {
897 if (HERE(URN) && game.objects[URN].prop == URN_DARK) {
907 state_change(URN, game.objects[URN].prop == URN_EMPTY ?
912 if (game.limit < 0) {
916 state_change(LAMP, LAMP_BRIGHT);
921 speak(actions[verb].message);
926 static phase_codes_t listen(void)
927 /* Listen. Intransitive only. Print stuff based on object sound properties. */
929 bool soundlatch = false;
930 vocab_t sound = locations[game.loc].sound;
931 if (sound != SILENT) {
933 if (!locations[game.loc].loud)
937 for (obj_t i = 1; i <= NOBJECTS; i++) {
938 if (!HERE(i) || objects[i].sounds[0] == NULL || PROP_IS_STASHED_OR_UNSEEN(i))
940 int mi = game.objects[i].prop;
941 /* (ESR) Some unpleasant magic on object states here. Ideally
942 * we'd have liked the bird to be a normal object that we can
943 * use state_change() on; can't do it, because there are
944 * actually two different series of per-state birdsounds
945 * depending on whether player has drunk dragon's blood. */
947 mi += 3 * game.blooded;
948 pspeak(i, hear, true, mi, game.zzword);
950 if (i == BIRD && mi == BIRD_ENDSTATE)
959 static phase_codes_t lock(verb_t verb, obj_t obj)
960 /* Lock, unlock, no object given. Assume various things if present. */
962 if (obj == INTRANSITIVE) {
973 if (obj == INTRANSITIVE) {
974 rspeak(NOTHING_LOCKED);
979 /* Lock, unlock object. Special stuff for opening clam/oyster
994 game.clock2 = PANICTIME;
997 state_change(GRATE, (verb == LOCK) ?
1007 else if (TOTING(CLAM))
1009 else if (!TOTING(TRIDENT))
1010 rspeak(CLAM_OPENER);
1013 drop(OYSTER, game.loc);
1014 drop(PEARL, LOC_CULDESAC);
1015 rspeak(PEARL_FALLS);
1021 else if (TOTING(OYSTER))
1022 rspeak(DROP_OYSTER);
1023 else if (!TOTING(TRIDENT))
1024 rspeak(OYSTER_OPENER);
1026 rspeak(OYSTER_OPENS);
1029 rspeak((game.objects[DOOR].prop == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1035 rspeak(CANNOT_UNLOCK);
1038 speak(actions[verb].message);
1044 static phase_codes_t pour(verb_t verb, obj_t obj)
1045 /* Pour. If no object, or object is bottle, assume contents of bottle.
1046 * special tests for pouring water or oil on plant or rusty door. */
1048 if (obj == BOTTLE || obj == INTRANSITIVE)
1050 if (obj == NO_OBJECT)
1053 speak(actions[verb].message);
1057 if (obj != OIL && obj != WATER) {
1061 if (HERE(URN) && game.objects[URN].prop == URN_EMPTY)
1062 return fill(verb, URN);
1063 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
1064 game.objects[obj].place = LOC_NOWHERE;
1065 if (!(AT(PLANT) || AT(DOOR))) {
1071 /* cycle through the three plant states */
1072 state_change(PLANT, MOD(game.objects[PLANT].prop + 1, 3));
1073 game.objects[PLANT2].prop = game.objects[PLANT].prop;
1076 rspeak(SHAKING_LEAVES);
1080 state_change(DOOR, (obj == OIL) ?
1087 static phase_codes_t quit(void)
1088 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1090 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1091 terminate(quitgame);
1095 static phase_codes_t read(command_t command)
1096 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1098 if (command.obj == INTRANSITIVE) {
1099 command.obj = NO_OBJECT;
1100 for (int i = 1; i <= NOBJECTS; i++) {
1101 if (HERE(i) && objects[i].texts[0] != NULL && !PROP_IS_STASHED(i))
1102 command.obj = command.obj * NOBJECTS + i;
1104 if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc))
1108 if (DARK(game.loc)) {
1109 sspeak(NO_SEE, command.word[0].raw);
1110 } else if (command.obj == OYSTER) {
1111 if (!TOTING(OYSTER) || !game.closed) {
1112 rspeak(DONT_UNDERSTAND);
1113 } else if (!game.clshnt) {
1114 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1116 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1118 } else if (objects[command.obj].texts[0] == NULL || PROP_IS_NOTFOUND(command.obj)) {
1119 speak(actions[command.verb].message);
1121 pspeak(command.obj, study, true, game.objects[command.obj].prop);
1125 static phase_codes_t reservoir(void)
1126 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1128 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1129 rspeak(NOTHING_HAPPENS);
1133 game.objects[RESER].prop == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1137 game.oldlc2 = game.loc;
1138 game.newloc = LOC_NOWHERE;
1140 return GO_TERMINATE;
1145 static phase_codes_t rub(verb_t verb, obj_t obj)
1146 /* Rub. Yields various snide remarks except for lit urn. */
1148 if (obj == URN && game.objects[URN].prop == URN_LIT) {
1150 drop(AMBER, game.loc);
1151 game.objects[AMBER].prop = AMBER_IN_ROCK;
1153 drop(CAVITY, game.loc);
1155 } else if (obj != LAMP) {
1156 rspeak(PECULIAR_NOTHING);
1158 speak(actions[verb].message);
1163 static phase_codes_t say(command_t command)
1164 /* Say. Echo WD2. Magic words override. */
1166 if (command.word[1].type == MOTION &&
1167 (command.word[1].id == XYZZY ||
1168 command.word[1].id == PLUGH ||
1169 command.word[1].id == PLOVER)) {
1172 if (command.word[1].type == ACTION && command.word[1].id == PART)
1175 if (command.word[1].type == ACTION &&
1176 (command.word[1].id == FEE ||
1177 command.word[1].id == FIE ||
1178 command.word[1].id == FOE ||
1179 command.word[1].id == FOO ||
1180 command.word[1].id == FUM ||
1181 command.word[1].id == PART)) {
1182 return bigwords(command.word[1].id);
1184 sspeak(OKEY_DOKEY, command.word[1].raw);
1188 static phase_codes_t throw_support(vocab_t spk)
1191 drop(AXE, game.loc);
1195 static phase_codes_t throwit(command_t command)
1196 /* Throw. Same as discard unless axe. Then same as attack except
1197 * ignore bird, and if dwarf is present then one might be killed.
1198 * (Only way to do so!) Axe also special for dragon, bear, and
1199 * troll. Treasures special for troll. */
1201 if (!TOTING(command.obj)) {
1202 speak(actions[command.verb].message);
1205 if (objects[command.obj].is_treasure && AT(TROLL)) {
1206 /* Snarf a treasure for the troll. */
1207 drop(command.obj, LOC_NOWHERE);
1208 move(TROLL, LOC_NOWHERE);
1209 move(TROLL + NOBJECTS, IS_FREE);
1210 drop(TROLL2, objects[TROLL].plac);
1211 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1213 rspeak(TROLL_SATISFIED);
1216 if (command.obj == FOOD && HERE(BEAR)) {
1217 /* But throwing food is another story. */
1219 return (feed(command.verb, command.obj));
1221 if (command.obj != AXE)
1222 return (discard(command.verb, command.obj));
1224 if (atdwrf(game.loc) <= 0) {
1225 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS)
1226 return throw_support(DRAGON_SCALES);
1228 return throw_support(TROLL_RETURNS);
1230 return throw_support(OGRE_DODGE);
1231 if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) {
1232 /* This'll teach him to throw the axe at the bear! */
1233 drop(AXE, game.loc);
1234 game.objects[AXE].fixed = IS_FIXED;
1236 state_change(AXE, AXE_LOST);
1239 command.obj = INTRANSITIVE;
1240 return (attack(command));
1243 if (randrange(NDWARVES + 1) < game.dflag) {
1244 return throw_support(DWARF_DODGES);
1246 int i = atdwrf(game.loc);
1247 game.dwarves[i].seen = false;
1248 game.dwarves[i].loc = LOC_NOWHERE;
1249 return throw_support((++game.dkill == 1) ?
1256 static phase_codes_t wake(verb_t verb, obj_t obj)
1257 /* Wake. Only use is to disturb the dwarves. */
1259 if (obj != DWARF || !game.closed) {
1260 speak(actions[verb].message);
1264 return GO_DWARFWAKE;
1268 static phase_codes_t seed(verb_t verb, const char *arg)
1271 int32_t seed = strtol(arg, NULL, 10);
1272 speak(actions[verb].message, seed);
1278 static phase_codes_t waste(verb_t verb, turn_t turns)
1281 game.limit -= turns;
1282 speak(actions[verb].message, (int)game.limit);
1286 static phase_codes_t wave(verb_t verb, obj_t obj)
1287 /* Wave. No effect unless waving rod at fissure or at bird. */
1289 if (obj != ROD || !TOTING(obj) || (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
1290 speak(((!TOTING(obj)) && (obj != ROD ||
1292 arbitrary_messages[ARENT_CARRYING] :
1293 actions[verb].message);
1297 if (game.objects[BIRD].prop == BIRD_UNCAGED && game.loc == game.objects[STEPS].place
1298 && PROP_IS_NOTFOUND(JADE)) {
1299 drop(JADE, game.loc);
1300 PROP_SET_FOUND(JADE);
1302 rspeak(NECKLACE_FLY);
1306 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1309 return GO_DWARFWAKE;
1311 if (game.closng || !AT(FISSURE)) {
1312 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1318 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1322 state_change(FISSURE,
1323 game.objects[FISSURE].prop == BRIDGED ? UNBRIDGED : BRIDGED);
1328 phase_codes_t action(command_t command)
1329 /* Analyse a verb. Remember what it was, go back for object if second word
1330 * unless verb is "say", which snarfs arbitrary second word.
1333 /* Previously, actions that result in a message, but don't do anything
1334 * further were called "specials". Now they're handled here as normal
1335 * actions. If noaction is true, then we spit out the message and return */
1336 if (actions[command.verb].noaction) {
1337 speak(actions[command.verb].message);
1341 if (command.part == unknown) {
1342 /* Analyse an object word. See if the thing is here, whether
1343 * we've got a verb yet, and so on. Object must be here
1344 * unless verb is "find" or "invent(ory)" (and no new verb
1345 * yet to be analysed). Water and oil are also funny, since
1346 * they are never actually dropped at any location, but might
1347 * be here inside the bottle or urn or as a feature of the
1349 if (HERE(command.obj))
1351 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1353 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1354 command.obj == LIQLOC(game.loc)))
1356 else if (command.obj == OIL && HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
1359 } else if (command.obj == PLANT && AT(PLANT2) && game.objects[PLANT2].prop != PLANT_THIRSTY) {
1360 command.obj = PLANT2;
1362 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1364 rspeak(KNIVES_VANISH);
1366 } else if (command.obj == ROD && HERE(ROD2)) {
1369 } else if ((command.verb == FIND ||
1370 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1373 sspeak(NO_SEE, command.word[0].raw);
1377 if (command.verb != 0)
1378 command.part = transitive;
1381 switch (command.part) {
1383 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1385 if (command.verb == SAY)
1386 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1387 * will do here. We're preventing interpretation as an intransitive
1388 * verb when the word is unknown. */
1389 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1390 if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
1391 /* Analyse an intransitive verb (ie, no object given yet). */
1392 switch (command.verb) {
1394 return vcarry(command.verb, INTRANSITIVE);
1400 return lock(command.verb, INTRANSITIVE);
1403 return (GO_CLEAROBJ);
1406 return lock(command.verb, INTRANSITIVE);
1408 return light(command.verb, INTRANSITIVE);
1410 return extinguish(command.verb, INTRANSITIVE);
1416 speak(actions[command.verb].message);
1420 command.obj = INTRANSITIVE;
1421 return attack(command);
1423 return pour(command.verb, INTRANSITIVE);
1425 return eat(command.verb, INTRANSITIVE);
1427 return drink(command.verb, INTRANSITIVE);
1441 return fill(command.verb, INTRANSITIVE);
1453 return bigwords(command.word[0].id);
1457 command.obj = INTRANSITIVE;
1458 return read(command);
1468 return fly(command.verb, INTRANSITIVE);
1475 rspeak(NUMERIC_REQUIRED);
1477 default: // LCOV_EXCL_LINE
1478 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1483 /* Analyse a transitive verb. */
1484 switch (command.verb) {
1486 return vcarry(command.verb, command.obj);
1488 return discard(command.verb, command.obj);
1490 return say(command);
1492 return lock(command.verb, command.obj);
1495 return (GO_CLEAROBJ);
1498 return lock(command.verb, command.obj);
1500 return light(command.verb, command.obj);
1502 return extinguish(command.verb, command.obj);
1504 return wave(command.verb, command.obj);
1506 speak(actions[command.verb].message);
1510 speak(actions[command.verb].message);
1514 return attack(command);
1516 return pour(command.verb, command.obj);
1518 return eat(command.verb, command.obj);
1520 return drink(command.verb, command.obj);
1522 return rub(command.verb, command.obj);
1524 return throwit(command);
1526 speak(actions[command.verb].message);
1530 return find(command.verb, command.obj);
1532 return find(command.verb, command.obj);
1534 return feed(command.verb, command.obj);
1536 return fill(command.verb, command.obj);
1541 speak(actions[command.verb].message);
1549 speak(actions[command.verb].message);
1553 speak(actions[command.verb].message);
1557 return read(command);
1559 return vbreak(command.verb, command.obj);
1561 return wake(command.verb, command.obj);
1563 speak(actions[command.verb].message);
1567 speak(actions[command.verb].message);
1571 return fly(command.verb, command.obj);
1573 speak(actions[command.verb].message);
1577 // This case should never happen - here only as placeholder
1582 return seed(command.verb, command.word[1].raw);
1584 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1585 default: // LCOV_EXCL_LINE
1586 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1589 /* Unknown verb, couldn't deduce object - might need hint */
1590 sspeak(WHAT_DO, command.word[0].raw);
1591 return GO_CHECKHINT;
1592 default: // LCOV_EXCL_LINE
1593 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE