2 * Actions for the dungeon-running code.
4 * SPDX-FileCopyrightText: (C) 1977, 2005 Will Crowther and Don Woods
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. */
22 verb_t verb = command.verb;
23 obj_t obj = command.obj;
25 if (obj == INTRANSITIVE) {
27 if (atdwrf(game.loc) > 0) {
35 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) {
47 if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) {
51 /* check for low-priority targets */
52 if (obj == INTRANSITIVE) {
53 /* Can't attack bird or machine by throwing axe. */
54 if (HERE(BIRD) && verb != THROW) {
58 if (HERE(VEND) && verb != THROW) {
62 /* Clam and oyster both treated as clam for intransitive case;
64 if (HERE(CLAM) || HERE(OYSTER)) {
84 game.objects[VEND].prop == VEND_BLOCKS ? VEND_UNBLOCKS : VEND_BLOCKS);
90 switch (game.objects[BEAR].prop) {
95 rspeak(BEAR_CONFUSED);
98 rspeak(BEAR_CONFUSED);
101 rspeak(ALREADY_DEAD);
106 if (obj == DRAGON && game.objects[DRAGON].prop == DRAGON_BARS) {
107 /* Fun stuff for dragon. If he insists on attacking it, win!
108 * Set game.prop to dead, move dragon to central loc (still
109 * fixed), move rug there (not fixed), and move him there,
110 * too. Then do a null motion to get new description. */
111 rspeak(BARE_HANDS_QUERY);
112 if (!silent_yes_or_no()) {
113 speak(arbitrary_messages[NASTY_DRAGON]);
116 state_change(DRAGON, DRAGON_DEAD);
117 game.objects[RUG].prop = RUG_FLOOR;
118 /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly.
119 * The way it was computed before was worse; it depended on the
120 * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and
121 * LOC_SECRET5 being right between them.
123 move(DRAGON + NOBJECTS, IS_FIXED);
124 move(RUG + NOBJECTS, IS_FREE);
125 move(DRAGON, LOC_SECRET5);
126 move(RUG, LOC_SECRET5);
127 drop(BLOOD, LOC_SECRET5);
128 for (obj_t i = 1; i <= NOBJECTS; i++) {
129 if (game.objects[i].place == objects[DRAGON].plac ||
130 game.objects[i].place == objects[DRAGON].fixd)
131 move(i, LOC_SECRET5);
133 game.loc = LOC_SECRET5;
139 if (atdwrf(game.loc) == 0) {
142 rspeak(KNIFE_THROWN);
145 for (int i = 1; i < PIRATE; i++) {
146 if (game.dwarves[i].loc == game.loc) {
148 game.dwarves[i].loc = LOC_LONGWEST;
149 game.dwarves[i].seen = false;
152 rspeak((dwarves > 1) ?
164 rspeak(SHELL_IMPERVIOUS);
167 rspeak(SNAKE_WARNING);
173 rspeak(BARE_HANDS_QUERY);
176 rspeak(ALREADY_DEAD);
182 speak(actions[verb].message);
187 static phase_codes_t bigwords(vocab_t id) {
188 /* Only called on FEE FIE FOE FOO (AND FUM). Advance to next state if given
189 * in proper order. Look up foo in special section of vocab to determine which
190 * word we've got. Last word zips the eggs back to the giant room (unless
192 int foobar = abs(game.foobar);
194 /* Only FEE can start a magic-word sequence. */
195 if ((foobar == WORD_EMPTY) && (id == FIE || id == FOE || id == FOO || id == FUM)) {
196 rspeak(NOTHING_HAPPENS);
200 if ((foobar == WORD_EMPTY && id == FEE) ||
201 (foobar == FEE && id == FIE) ||
202 (foobar == FIE && id == FOE) ||
203 (foobar == FOE && id == FOO)) {
209 game.foobar = WORD_EMPTY;
210 if (game.objects[EGGS].place == objects[EGGS].plac ||
211 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
212 rspeak(NOTHING_HAPPENS);
215 /* Bring back troll if we steal the eggs back from him before
217 if (game.objects[EGGS].place == LOC_NOWHERE && game.objects[TROLL].place == LOC_NOWHERE
218 && game.objects[TROLL].prop == TROLL_UNPAID)
219 game.objects[TROLL].prop = TROLL_PAIDONCE;
221 pspeak(EGGS, look, true, EGGS_VANISHED);
222 } else if (game.loc == objects[EGGS].plac) {
223 pspeak(EGGS, look, true, EGGS_HERE);
225 pspeak(EGGS, look, true, EGGS_DONE);
227 move(EGGS, objects[EGGS].plac);
232 /* Magic-word sequence was started but is incorrect */
233 if (settings.oldstyle || game.seenbigwords) {
236 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! */
245 if (PROP_IS_NOTFOUND(ROD2) || !game.closed)
246 rspeak(REQUIRES_DYNAMITE);
249 game.bonus = splatter;
250 rspeak(SPLATTER_MESSAGE);
251 } else if (game.loc == LOC_NE) {
253 rspeak(DEFEAT_MESSAGE);
255 game.bonus = victory;
256 rspeak(VICTORY_MESSAGE);
262 static phase_codes_t vbreak(verb_t verb, obj_t obj) {
263 /* Break. Only works for mirror in repository and, of course, the vase. */
267 state_change(MIRROR, MIRROR_BROKEN);
274 if (game.objects[VASE].prop == VASE_WHOLE) {
276 drop(VASE, game.loc);
277 state_change(VASE, VASE_BROKEN);
278 game.objects[VASE].fixed = IS_FIXED;
283 speak(actions[verb].message);
285 return (GO_CLEAROBJ);
288 static phase_codes_t brief(void) {
289 /* Brief. Intransitive only. Suppress full descriptions after first time. */
292 rspeak(BRIEF_CONFIRM);
296 static phase_codes_t vcarry(verb_t verb, obj_t obj) {
297 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
298 * take one without the other). Liquids also special, since they depend on
299 * status of bottle. Also various side effects, etc. */
300 if (obj == INTRANSITIVE) {
301 /* Carry, no object given yet. OK if only one object present. */
302 if (game.locs[game.loc].atloc == NO_OBJECT ||
303 game.link[game.locs[game.loc].atloc] != 0 ||
304 atdwrf(game.loc) > 0) {
307 obj = game.locs[game.loc].atloc;
311 speak(actions[verb].message);
316 rspeak(REMOVE_MESSAGE);
321 if (game.objects[obj].fixed != IS_FREE) {
324 /* Next guard tests whether plant is tiny or stashed */
325 rspeak(game.objects[PLANT].prop <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
328 rspeak( game.objects[BEAR].prop == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
331 rspeak( game.objects[BEAR].prop != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
334 rspeak(game.objects[RUG].prop == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
340 rspeak(DOUGHNUT_HOLES);
346 rspeak(HAND_PASSTHROUGH);
354 if (obj == WATER || obj == OIL) {
355 if (!HERE(BOTTLE) || LIQUID() != obj) {
356 if (!TOTING(BOTTLE)) {
357 rspeak(NO_CONTAINER);
360 if (game.objects[BOTTLE].prop == EMPTY_BOTTLE) {
361 return (fill(verb, BOTTLE));
370 if (game.holdng >= INVLIMIT) {
376 if (obj == BIRD && game.objects[BIRD].prop != BIRD_CAGED && !PROP_IS_STASHED(BIRD)) {
377 if (game.objects[BIRD].prop == BIRD_FOREST_UNCAGED) {
383 rspeak(CANNOT_CARRY);
390 game.objects[BIRD].prop = BIRD_CAGED;
392 if ((obj == BIRD || obj == CAGE) &&
393 (game.objects[BIRD].prop == BIRD_CAGED || PROP_STASHED(BIRD) == BIRD_CAGED)) {
394 /* expression maps BIRD to CAGE and CAGE to BIRD */
395 carry(BIRD + CAGE - obj, game.loc);
398 carry(obj, game.loc);
400 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
401 game.objects[LIQUID()].place = CARRIED;
404 if (GSTONE(obj) && !PROP_IS_FOUND(obj)) {
406 game.objects[CAVITY].prop = CAVITY_EMPTY;
412 static int chain(verb_t verb) {
413 /* Do something to the bear's chain */
415 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
419 if (game.objects[CHAIN].prop == CHAIN_HEAP) {
420 rspeak(ALREADY_UNLOCKED);
423 game.objects[CHAIN].prop = CHAIN_HEAP;
424 game.objects[CHAIN].fixed = IS_FREE;
425 if (game.objects[BEAR].prop != BEAR_DEAD)
426 game.objects[BEAR].prop = CONTENTED_BEAR;
428 switch (game.objects[BEAR].prop) {
431 /* Can't be reached until the bear can die in some way other
432 * than a bridge collapse. Leave in in case this changes, but
433 * exclude from coverage testing. */
434 game.objects[BEAR].fixed = IS_FIXED;
438 game.objects[BEAR].fixed = IS_FREE;
440 rspeak(CHAIN_UNLOCKED);
444 if (game.objects[CHAIN].prop != CHAIN_HEAP) {
445 rspeak(ALREADY_LOCKED);
448 if (game.loc != objects[CHAIN].plac) {
453 game.objects[CHAIN].prop = CHAIN_FIXED;
456 drop(CHAIN, game.loc);
457 game.objects[CHAIN].fixed = IS_FIXED;
459 rspeak(CHAIN_LOCKED);
463 static phase_codes_t discard(verb_t verb, obj_t obj) {
464 /* Discard object. "Throw" also comes here for most objects. Special cases for
465 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
466 * Drop coins at vending machine for extra batteries. */
467 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
472 speak(actions[verb].message);
476 if (GSTONE(obj) && AT(CAVITY) && game.objects[CAVITY].prop != CAVITY_FULL) {
478 game.objects[obj].prop = STATE_IN_CAVITY;
479 game.objects[CAVITY].prop = CAVITY_FULL;
480 if (HERE(RUG) && ((obj == EMERALD && game.objects[RUG].prop != RUG_HOVER) ||
481 (obj == RUBY && game.objects[RUG].prop == RUG_HOVER))) {
484 } else if (TOTING(RUG)) {
489 if (!TOTING(RUG) || obj == RUBY) {
490 int k = (game.objects[RUG].prop == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
491 game.objects[RUG].prop = k;
492 if (k == RUG_HOVER) {
493 k = objects[SAPPH].plac;
495 move(RUG + NOBJECTS, k);
502 if (obj == COINS && HERE(VEND)) {
504 drop(BATTERY, game.loc);
505 pspeak(BATTERY, look, true, FRESH_BATTERIES);
509 if (LIQUID() == obj) {
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;
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);
556 /* Set game.prop for use by travel options */
557 game.objects[SNAKE].prop = SNAKE_CHASED;
562 game.objects[BIRD].prop = 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. */
575 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
576 (LIQUID() != WATER || !HERE(BOTTLE))) {
582 state_change(DRAGON, DRAGON_BLOODLESS);
587 if (obj != INTRANSITIVE && obj != WATER) {
588 rspeak(RIDICULOUS_ATTEMPT);
591 if (LIQUID() == WATER && HERE(BOTTLE)) {
592 game.objects[WATER].place = LOC_NOWHERE;
593 state_change(BOTTLE, EMPTY_BOTTLE);
597 speak(actions[verb].message);
601 static phase_codes_t eat(verb_t verb, obj_t obj) {
602 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
603 * 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). */
632 if (obj == INTRANSITIVE) {
633 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_BRIGHT) {
636 if (HERE(URN) && game.objects[URN].prop == URN_LIT) {
639 if (obj == INTRANSITIVE) {
646 if (game.objects[URN].prop != 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. */
676 if (game.objects[DRAGON].prop != DRAGON_BARS) {
677 rspeak(RIDICULOUS_ATTEMPT);
679 rspeak(NOTHING_EDIBLE);
683 if (!game.closed && HERE(BIRD)) {
685 rspeak(BIRD_DEVOURED);
687 rspeak(NOTHING_EDIBLE);
698 speak(actions[verb].message);
702 if (game.objects[BEAR].prop == BEAR_DEAD) {
703 rspeak(RIDICULOUS_ATTEMPT);
706 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
709 game.objects[AXE].fixed = IS_FREE;
710 game.objects[AXE].prop = AXE_HERE;
711 state_change(BEAR, SITTING_BEAR);
713 rspeak(NOTHING_EDIBLE);
717 speak(actions[verb].message);
723 speak(actions[verb].message);
732 phase_codes_t fill(verb_t verb, obj_t obj) {
733 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
736 if (LIQLOC(game.loc) == NO_OBJECT) {
737 rspeak(FILL_INVALID);
741 rspeak(ARENT_CARRYING);
744 rspeak(SHATTER_VASE);
745 game.objects[VASE].prop = VASE_BROKEN;
746 game.objects[VASE].fixed = IS_FIXED;
747 drop(VASE, game.loc);
752 if (game.objects[URN].prop != URN_EMPTY) {
757 rspeak(FILL_INVALID);
763 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
767 game.objects[URN].prop = URN_DARK;
768 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
773 rspeak(FILL_INVALID);
776 game.objects[k].place = LOC_NOWHERE;
779 if (obj != INTRANSITIVE && obj != BOTTLE) {
780 speak(actions[verb].message);
783 if (obj == INTRANSITIVE && !HERE(BOTTLE))
786 if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
790 if (LIQUID() != NO_OBJECT) {
794 if (LIQLOC(game.loc) == NO_OBJECT) {
799 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
802 if (TOTING(BOTTLE)) {
803 game.objects[LIQUID()].place = CARRIED;
808 static phase_codes_t find(verb_t verb, obj_t obj) {
809 /* Find. Might be carrying it, or it might be here. Else give caveat. */
811 rspeak(ALREADY_CARRYING);
816 rspeak(NEEDED_NEARBY);
820 if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
821 obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
827 speak(actions[verb].message);
831 static phase_codes_t fly(verb_t verb, obj_t obj) {
832 /* Fly. Snide remarks unless hovering rug is here. */
833 if (obj == INTRANSITIVE) {
838 if (game.objects[RUG].prop != RUG_HOVER) {
839 rspeak(RUG_NOTHING2);
846 speak(actions[verb].message);
849 if (game.objects[RUG].prop != 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. */
876 for (obj_t i = 1; i <= NOBJECTS; i++) {
877 if (i == BEAR || !TOTING(i))
883 pspeak(i, touch, false, -1);
892 static phase_codes_t light(verb_t verb, obj_t obj) {
893 /* Light. Applicable only to lamp and urn. */
894 if (obj == INTRANSITIVE) {
896 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_DARK && game.limit >= 0) {
900 if (HERE(URN) && game.objects[URN].prop == URN_DARK) {
910 state_change(URN, game.objects[URN].prop == URN_EMPTY ?
915 if (game.limit < 0) {
919 state_change(LAMP, LAMP_BRIGHT);
925 speak(actions[verb].message);
930 static phase_codes_t listen(void) {
931 /* Listen. Intransitive only. Print stuff based on object sound properties. */
932 bool soundlatch = false;
933 vocab_t sound = locations[game.loc].sound;
934 if (sound != SILENT) {
936 if (!locations[game.loc].loud) {
941 for (obj_t i = 1; i <= NOBJECTS; i++) {
942 if (!HERE(i) || objects[i].sounds[0] == NULL || PROP_IS_STASHED_OR_UNSEEN(i)) {
945 int mi = game.objects[i].prop;
946 /* (ESR) Some unpleasant magic on object states here. Ideally
947 * we'd have liked the bird to be a normal object that we can
948 * use state_change() on; can't do it, because there are
949 * actually two different series of per-state birdsounds
950 * depending on whether player has drunk dragon's blood. */
952 mi += 3 * game.blooded;
954 pspeak(i, hear, true, mi, game.zzword);
956 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. */
969 if (obj == INTRANSITIVE) {
985 if (obj == INTRANSITIVE) {
986 rspeak(NOTHING_LOCKED);
991 /* Lock, unlock object. Special stuff for opening clam/oyster
1005 rspeak(EXIT_CLOSED);
1007 game.clock2 = PANICTIME;
1011 state_change(GRATE, (verb == LOCK) ?
1022 } else if (TOTING(CLAM)) {
1024 } else if (!TOTING(TRIDENT)) {
1025 rspeak(CLAM_OPENER);
1028 drop(OYSTER, game.loc);
1029 drop(PEARL, LOC_CULDESAC);
1030 rspeak(PEARL_FALLS);
1036 } else if (TOTING(OYSTER)) {
1037 rspeak(DROP_OYSTER);
1038 } else if (!TOTING(TRIDENT)) {
1039 rspeak(OYSTER_OPENER);
1041 rspeak(OYSTER_OPENS);
1045 rspeak((game.objects[DOOR].prop == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1051 rspeak(CANNOT_UNLOCK);
1054 speak(actions[verb].message);
1060 static phase_codes_t pour(verb_t verb, obj_t obj) {
1061 /* Pour. If no object, or object is bottle, assume contents of bottle.
1062 * special tests for pouring water or oil on plant or rusty door. */
1063 if (obj == BOTTLE || obj == INTRANSITIVE) {
1066 if (obj == NO_OBJECT) {
1070 speak(actions[verb].message);
1074 if (obj != OIL && obj != WATER) {
1078 if (HERE(URN) && game.objects[URN].prop == URN_EMPTY) {
1079 return fill(verb, URN);
1081 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
1082 game.objects[obj].place = LOC_NOWHERE;
1083 if (!(AT(PLANT) || AT(DOOR))) {
1089 /* cycle through the three plant states */
1090 state_change(PLANT, MOD(game.objects[PLANT].prop + 1, 3));
1091 game.objects[PLANT2].prop = game.objects[PLANT].prop;
1094 rspeak(SHAKING_LEAVES);
1098 state_change(DOOR, (obj == OIL) ?
1105 static phase_codes_t quit(void) {
1106 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1107 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) {
1108 terminate(quitgame);
1113 static phase_codes_t read(command_t command)
1114 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1116 if (command.obj == INTRANSITIVE) {
1117 command.obj = NO_OBJECT;
1118 for (int i = 1; i <= NOBJECTS; i++) {
1119 if (HERE(i) && objects[i].texts[0] != NULL && !PROP_IS_STASHED(i)) {
1120 command.obj = command.obj * NOBJECTS + i;
1123 if (command.obj > NOBJECTS || command.obj == NO_OBJECT || DARK(game.loc)) {
1128 if (DARK(game.loc)) {
1129 sspeak(NO_SEE, command.word[0].raw);
1130 } else if (command.obj == OYSTER) {
1131 if (!TOTING(OYSTER) || !game.closed) {
1132 rspeak(DONT_UNDERSTAND);
1133 } else if (!game.clshnt) {
1134 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1136 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1138 } else if (objects[command.obj].texts[0] == NULL || PROP_IS_NOTFOUND(command.obj)) {
1139 speak(actions[command.verb].message);
1141 pspeak(command.obj, study, true, game.objects[command.obj].prop);
1146 static phase_codes_t reservoir(void) {
1147 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1148 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1149 rspeak(NOTHING_HAPPENS);
1153 game.objects[RESER].prop == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1157 game.oldlc2 = game.loc;
1158 game.newloc = LOC_NOWHERE;
1160 return GO_TERMINATE;
1165 static phase_codes_t rub(verb_t verb, obj_t obj) {
1166 /* Rub. Yields various snide remarks except for lit urn. */
1167 if (obj == URN && game.objects[URN].prop == URN_LIT) {
1169 drop(AMBER, game.loc);
1170 game.objects[AMBER].prop = AMBER_IN_ROCK;
1172 drop(CAVITY, game.loc);
1174 } else if (obj != LAMP) {
1175 rspeak(PECULIAR_NOTHING);
1177 speak(actions[verb].message);
1182 static phase_codes_t say(command_t command) {
1183 /* Say. Echo WD2. Magic words override. */
1184 if (command.word[1].type == MOTION &&
1185 (command.word[1].id == XYZZY ||
1186 command.word[1].id == PLUGH ||
1187 command.word[1].id == PLOVER)) {
1190 if (command.word[1].type == ACTION && command.word[1].id == PART) {
1194 if (command.word[1].type == ACTION &&
1195 (command.word[1].id == FEE ||
1196 command.word[1].id == FIE ||
1197 command.word[1].id == FOE ||
1198 command.word[1].id == FOO ||
1199 command.word[1].id == FUM ||
1200 command.word[1].id == PART)) {
1201 return bigwords(command.word[1].id);
1203 sspeak(OKEY_DOKEY, command.word[1].raw);
1207 static phase_codes_t throw_support(vocab_t spk)
1210 drop(AXE, game.loc);
1214 static phase_codes_t throwit(command_t command) {
1215 /* Throw. Same as discard unless axe. Then same as attack except
1216 * ignore bird, and if dwarf is present then one might be killed.
1217 * (Only way to do so!) Axe also special for dragon, bear, and
1218 * troll. Treasures special for troll. */
1219 if (!TOTING(command.obj)) {
1220 speak(actions[command.verb].message);
1223 if (objects[command.obj].is_treasure && AT(TROLL)) {
1224 /* Snarf a treasure for the troll. */
1225 drop(command.obj, LOC_NOWHERE);
1226 move(TROLL, LOC_NOWHERE);
1227 move(TROLL + NOBJECTS, IS_FREE);
1228 drop(TROLL2, objects[TROLL].plac);
1229 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1231 rspeak(TROLL_SATISFIED);
1234 if (command.obj == FOOD && HERE(BEAR)) {
1235 /* But throwing food is another story. */
1237 return (feed(command.verb, command.obj));
1239 if (command.obj != AXE) {
1240 return (discard(command.verb, command.obj));
1242 if (atdwrf(game.loc) <= 0) {
1243 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS)
1244 return throw_support(DRAGON_SCALES);
1246 return throw_support(TROLL_RETURNS);
1249 return throw_support(OGRE_DODGE);
1251 if (HERE(BEAR) && game.objects[BEAR].prop == UNTAMED_BEAR) {
1252 /* This'll teach him to throw the axe at the bear! */
1253 drop(AXE, game.loc);
1254 game.objects[AXE].fixed = IS_FIXED;
1256 state_change(AXE, AXE_LOST);
1259 command.obj = INTRANSITIVE;
1260 return (attack(command));
1263 if (randrange(NDWARVES + 1) < game.dflag) {
1264 return throw_support(DWARF_DODGES);
1266 int i = atdwrf(game.loc);
1267 game.dwarves[i].seen = false;
1268 game.dwarves[i].loc = LOC_NOWHERE;
1269 return throw_support((++game.dkill == 1) ?
1276 static phase_codes_t wake(verb_t verb, obj_t obj) {
1277 /* Wake. Only use is to disturb the dwarves. */
1278 if (obj != DWARF || !game.closed) {
1279 speak(actions[verb].message);
1283 return GO_DWARFWAKE;
1287 static phase_codes_t seed(verb_t verb, const char *arg) {
1289 int32_t seed = strtol(arg, NULL, 10);
1290 speak(actions[verb].message, seed);
1296 static phase_codes_t waste(verb_t verb, turn_t turns) {
1298 game.limit -= turns;
1299 speak(actions[verb].message, (int)game.limit);
1303 static phase_codes_t wave(verb_t verb, obj_t obj) {
1304 /* Wave. No effect unless waving rod at fissure or at bird. */
1305 if (obj != ROD || !TOTING(obj) || (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
1306 speak(((!TOTING(obj)) && (obj != ROD ||
1308 arbitrary_messages[ARENT_CARRYING] :
1309 actions[verb].message);
1313 if (game.objects[BIRD].prop == BIRD_UNCAGED && game.loc == game.objects[STEPS].place
1314 && PROP_IS_NOTFOUND(JADE)) {
1315 drop(JADE, game.loc);
1316 PROP_SET_FOUND(JADE);
1318 rspeak(NECKLACE_FLY);
1322 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1325 return GO_DWARFWAKE;
1327 if (game.closng || !AT(FISSURE)) {
1328 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1334 rspeak((game.objects[BIRD].prop == BIRD_CAGED) ?
1338 state_change(FISSURE,
1339 game.objects[FISSURE].prop == BRIDGED ? UNBRIDGED : BRIDGED);
1344 phase_codes_t action(command_t command) {
1345 /* Analyse a verb. Remember what it was, go back for object if second word
1346 * unless verb is "say", which snarfs arbitrary second word.
1348 /* Previously, actions that result in a message, but don't do anything
1349 * further were called "specials". Now they're handled here as normal
1350 * actions. If noaction is true, then we spit out the message and return */
1351 if (actions[command.verb].noaction) {
1352 speak(actions[command.verb].message);
1356 if (command.part == unknown) {
1357 /* Analyse an object word. See if the thing is here, whether
1358 * we've got a verb yet, and so on. Object must be here
1359 * unless verb is "find" or "invent(ory)" (and no new verb
1360 * yet to be analysed). Water and oil are also funny, since
1361 * they are never actually dropped at any location, but might
1362 * be here inside the bottle or urn or as a feature of the
1364 if (HERE(command.obj)) {
1366 } else if (command.obj == DWARF && atdwrf(game.loc) > 0) {
1368 } else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1369 command.obj == LIQLOC(game.loc))) {
1371 } else if (command.obj == OIL && HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
1374 } else if (command.obj == PLANT && AT(PLANT2) && game.objects[PLANT2].prop != PLANT_THIRSTY) {
1375 command.obj = PLANT2;
1377 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1379 rspeak(KNIVES_VANISH);
1381 } else if (command.obj == ROD && HERE(ROD2)) {
1384 } else if ((command.verb == FIND ||
1385 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND)) {
1388 sspeak(NO_SEE, command.word[0].raw);
1392 if (command.verb != 0) {
1393 command.part = transitive;
1397 switch (command.part) {
1399 if (command.word[1].raw[0] != '\0' && command.verb != SAY) {
1402 if (command.verb == SAY) {
1403 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1404 * will do here. We're preventing interpretation as an intransitive
1405 * verb when the word is unknown. */
1406 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1408 if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
1409 /* Analyse an intransitive verb (ie, no object given yet). */
1410 switch (command.verb) {
1412 return vcarry(command.verb, INTRANSITIVE);
1418 return lock(command.verb, INTRANSITIVE);
1421 return (GO_CLEAROBJ);
1424 return lock(command.verb, INTRANSITIVE);
1426 return light(command.verb, INTRANSITIVE);
1428 return extinguish(command.verb, INTRANSITIVE);
1434 speak(actions[command.verb].message);
1438 command.obj = INTRANSITIVE;
1439 return attack(command);
1441 return pour(command.verb, INTRANSITIVE);
1443 return eat(command.verb, INTRANSITIVE);
1445 return drink(command.verb, INTRANSITIVE);
1459 return fill(command.verb, INTRANSITIVE);
1471 return bigwords(command.word[0].id);
1475 command.obj = INTRANSITIVE;
1476 return read(command);
1486 return fly(command.verb, INTRANSITIVE);
1493 rspeak(NUMERIC_REQUIRED);
1495 default: // LCOV_EXCL_LINE
1496 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1501 /* Analyse a transitive verb. */
1502 switch (command.verb) {
1504 return vcarry(command.verb, command.obj);
1506 return discard(command.verb, command.obj);
1508 return say(command);
1510 return lock(command.verb, command.obj);
1513 return (GO_CLEAROBJ);
1516 return lock(command.verb, command.obj);
1518 return light(command.verb, command.obj);
1520 return extinguish(command.verb, command.obj);
1522 return wave(command.verb, command.obj);
1524 speak(actions[command.verb].message);
1528 speak(actions[command.verb].message);
1532 return attack(command);
1534 return pour(command.verb, command.obj);
1536 return eat(command.verb, command.obj);
1538 return drink(command.verb, command.obj);
1540 return rub(command.verb, command.obj);
1542 return throwit(command);
1544 speak(actions[command.verb].message);
1547 return find(command.verb, command.obj);
1549 return find(command.verb, command.obj);
1551 return feed(command.verb, command.obj);
1553 return fill(command.verb, command.obj);
1558 speak(actions[command.verb].message);
1565 speak(actions[command.verb].message);
1568 speak(actions[command.verb].message);
1571 return read(command);
1573 return vbreak(command.verb, command.obj);
1575 return wake(command.verb, command.obj);
1577 speak(actions[command.verb].message);
1580 speak(actions[command.verb].message);
1583 return fly(command.verb, command.obj);
1585 speak(actions[command.verb].message);
1588 // This case should never happen - here only as placeholder
1593 return seed(command.verb, command.word[1].raw);
1595 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1596 default: // LCOV_EXCL_LINE
1597 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1600 /* Unknown verb, couldn't deduce object - might need hint */
1601 sspeak(WHAT_DO, command.word[0].raw);
1602 return GO_CHECKHINT;
1603 default: // LCOV_EXCL_LINE
1604 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE