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 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 (game.prop[ROD2] == STATE_NOTFOUND || !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.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);
357 if (obj == WATER || obj == OIL) {
358 if (!HERE(BOTTLE) || LIQUID() != obj) {
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;
394 if ((obj == BIRD || obj == CAGE) &&
395 (game.prop[BIRD] == BIRD_CAGED || 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.place[LIQUID()] = CARRIED;
405 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
406 game.prop[obj] = STATE_FOUND;
407 game.prop[CAVITY] = CAVITY_EMPTY;
413 static int chain(verb_t verb)
414 /* Do something to the bear's chain */
417 if (game.prop[BEAR] == UNTAMED_BEAR) {
421 if (game.prop[CHAIN] == CHAIN_HEAP) {
422 rspeak(ALREADY_UNLOCKED);
425 game.prop[CHAIN] = CHAIN_HEAP;
426 game.fixed[CHAIN] = IS_FREE;
427 if (game.prop[BEAR] != BEAR_DEAD)
428 game.prop[BEAR] = CONTENTED_BEAR;
430 switch (game.prop[BEAR]) {
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.fixed[BEAR] = IS_FIXED;
440 game.fixed[BEAR] = IS_FREE;
442 rspeak(CHAIN_UNLOCKED);
446 if (game.prop[CHAIN] != CHAIN_HEAP) {
447 rspeak(ALREADY_LOCKED);
450 if (game.loc != objects[CHAIN].plac) {
455 game.prop[CHAIN] = CHAIN_FIXED;
458 drop(CHAIN, game.loc);
459 game.fixed[CHAIN] = 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.prop[CAVITY] != CAVITY_FULL) {
481 game.prop[obj] = STATE_IN_CAVITY;
482 game.prop[CAVITY] = CAVITY_FULL;
483 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
484 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
487 else if (TOTING(RUG))
491 if (!TOTING(RUG) || obj == RUBY) {
492 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
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.place[LIQUID()] = 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.prop[VASE] != VASE_WHOLE)
533 game.fixed[VASE] = IS_FIXED;
539 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
540 drop(BIRD, game.loc);
544 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
550 rspeak(BIRD_ATTACKS);
554 /* Set game.prop for use by travel options */
555 game.prop[SNAKE] = SNAKE_CHASED;
559 game.prop[BIRD] = 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.place[WATER] = 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.prop[LAMP] == LAMP_BRIGHT)
635 if (HERE(URN) && game.prop[URN] == URN_LIT)
637 if (obj == INTRANSITIVE)
643 if (game.prop[URN] != 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.prop[DRAGON] != 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.prop[BEAR] == BEAR_DEAD) {
698 rspeak(RIDICULOUS_ATTEMPT);
701 if (game.prop[BEAR] == UNTAMED_BEAR) {
704 game.fixed[AXE] = IS_FREE;
705 game.prop[AXE] = 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.prop[VASE] = VASE_BROKEN;
740 game.fixed[VASE] = IS_FIXED;
741 drop(VASE, game.loc);
746 if (game.prop[URN] != URN_EMPTY) {
751 rspeak(FILL_INVALID);
757 game.prop[BOTTLE] = EMPTY_BOTTLE;
761 game.prop[URN] = URN_DARK;
762 game.prop[BOTTLE] = EMPTY_BOTTLE;
767 rspeak(FILL_INVALID);
770 game.place[k] = LOC_NOWHERE;
773 if (obj != INTRANSITIVE && obj != BOTTLE) {
774 speak(actions[verb].message);
777 if (obj == INTRANSITIVE && !HERE(BOTTLE))
780 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
784 if (LIQUID() != NO_OBJECT) {
788 if (LIQLOC(game.loc) == NO_OBJECT) {
793 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
797 game.place[LIQUID()] = 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.prop[RUG] != RUG_HOVER) {
834 rspeak(RUG_NOTHING2);
841 speak(actions[verb].message);
844 if (game.prop[RUG] != 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.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
897 if (HERE(URN) && game.prop[URN] == URN_DARK) {
907 state_change(URN, game.prop[URN] == 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 || game.prop[i] < 0)
940 int mi = game.prop[i];
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.prop[DOOR] == 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.prop[URN] == URN_EMPTY)
1062 return fill(verb, URN);
1063 game.prop[BOTTLE] = EMPTY_BOTTLE;
1064 game.place[obj] = LOC_NOWHERE;
1065 if (!(AT(PLANT) || AT(DOOR))) {
1071 /* cycle through the three plant states */
1072 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1073 game.prop[PLANT2] = game.prop[PLANT];
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 && game.prop[i] >= 0)
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 ||
1119 game.prop[command.obj] == STATE_NOTFOUND) {
1120 speak(actions[command.verb].message);
1122 pspeak(command.obj, study, true, game.prop[command.obj]);
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.prop[RESER] == 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.prop[URN] == URN_LIT) {
1151 drop(AMBER, game.loc);
1152 game.prop[AMBER] = 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.prop[DRAGON] == 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.prop[BEAR] == UNTAMED_BEAR) {
1233 /* This'll teach him to throw the axe at the bear! */
1234 drop(AXE, game.loc);
1235 game.fixed[AXE] = 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.dseen[i] = false;
1249 game.dloc[i] = 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.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1299 drop(JADE, game.loc);
1300 game.prop[JADE] = STATE_FOUND;
1302 rspeak(NECKLACE_FLY);
1306 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1309 return GO_DWARFWAKE;
1311 if (game.closng || !AT(FISSURE)) {
1312 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1318 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1322 state_change(FISSURE,
1323 game.prop[FISSURE] == 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.prop[URN] != URN_EMPTY) {
1359 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != 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