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
63 * case; no harm done. */
64 if (HERE(CLAM) || HERE(OYSTER)) {
83 state_change(VEND, game.objects[VEND].prop == 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
120 * ugly. The way it was computed before was worse; it depended
121 * on the two dragon locations being LOC_SECRET4 and LOC_SECRET6
122 * and 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) ? OGRE_PANIC1 : OGRE_PANIC2);
163 rspeak(SHELL_IMPERVIOUS);
166 rspeak(SNAKE_WARNING);
172 rspeak(BARE_HANDS_QUERY);
175 rspeak(ALREADY_DEAD);
181 speak(actions[verb].message);
186 static phase_codes_t bigwords(vocab_t id) {
187 /* Only called on FEE FIE FOE FOO (AND FUM). Advance to next state if
188 * given in proper order. Look up foo in special section of vocab to
189 * determine which word we've got. Last word zips the eggs back to the
190 * giant room (unless already there). */
191 int foobar = abs(game.foobar);
193 /* Only FEE can start a magic-word sequence. */
194 if ((foobar == WORD_EMPTY) &&
195 (id == FIE || id == FOE || id == FOO || id == FUM)) {
196 rspeak(NOTHING_HAPPENS);
200 if ((foobar == WORD_EMPTY && id == FEE) ||
201 (foobar == FEE && id == FIE) || (foobar == FIE && id == FOE) ||
202 (foobar == FOE && id == FOO)) {
208 game.foobar = WORD_EMPTY;
209 if (game.objects[EGGS].place == objects[EGGS].plac ||
210 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
211 rspeak(NOTHING_HAPPENS);
214 /* Bring back troll if we steal the eggs back from him
215 * before crossing. */
216 if (game.objects[EGGS].place == LOC_NOWHERE &&
217 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!
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
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
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,
301 * can't take one without the other). Liquids also special, since they
302 * depend on status of bottle. Also various side effects, etc. */
303 if (obj == INTRANSITIVE) {
304 /* 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) {
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
334 rspeak(game.objects[BEAR].prop == SITTING_BEAR
339 rspeak(game.objects[BEAR].prop != UNTAMED_BEAR
344 rspeak(game.objects[RUG].prop == RUG_HOVER
352 rspeak(DOUGHNUT_HOLES);
358 rspeak(HAND_PASSTHROUGH);
366 if (obj == WATER || obj == OIL) {
367 if (!HERE(BOTTLE) || LIQUID() != obj) {
368 if (!TOTING(BOTTLE)) {
369 rspeak(NO_CONTAINER);
372 if (game.objects[BOTTLE].prop == EMPTY_BOTTLE) {
373 return (fill(verb, BOTTLE));
382 if (game.holdng >= INVLIMIT) {
387 if (obj == BIRD && game.objects[BIRD].prop != BIRD_CAGED &&
388 !PROP_IS_STASHED(BIRD)) {
389 if (game.objects[BIRD].prop == BIRD_FOREST_UNCAGED) {
395 rspeak(CANNOT_CARRY);
402 game.objects[BIRD].prop = BIRD_CAGED;
404 if ((obj == BIRD || obj == CAGE) &&
405 (game.objects[BIRD].prop == BIRD_CAGED ||
406 PROP_STASHED(BIRD) == BIRD_CAGED)) {
407 /* expression maps BIRD to CAGE and CAGE to BIRD */
408 carry(BIRD + CAGE - obj, game.loc);
411 carry(obj, game.loc);
413 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
414 game.objects[LIQUID()].place = CARRIED;
417 if (GSTONE(obj) && !PROP_IS_FOUND(obj)) {
419 game.objects[CAVITY].prop = CAVITY_EMPTY;
425 static int chain(verb_t verb) {
426 /* Do something to the bear's chain */
428 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
432 if (game.objects[CHAIN].prop == CHAIN_HEAP) {
433 rspeak(ALREADY_UNLOCKED);
436 game.objects[CHAIN].prop = CHAIN_HEAP;
437 game.objects[CHAIN].fixed = IS_FREE;
438 if (game.objects[BEAR].prop != BEAR_DEAD)
439 game.objects[BEAR].prop = CONTENTED_BEAR;
441 switch (game.objects[BEAR].prop) {
444 /* Can't be reached until the bear can die in some way
445 * other than a bridge collapse. Leave in in case this
446 * changes, but exclude from coverage testing. */
447 game.objects[BEAR].fixed = IS_FIXED;
451 game.objects[BEAR].fixed = IS_FREE;
453 rspeak(CHAIN_UNLOCKED);
457 if (game.objects[CHAIN].prop != CHAIN_HEAP) {
458 rspeak(ALREADY_LOCKED);
461 if (game.loc != objects[CHAIN].plac) {
466 game.objects[CHAIN].prop = CHAIN_FIXED;
469 drop(CHAIN, game.loc);
470 game.objects[CHAIN].fixed = IS_FIXED;
472 rspeak(CHAIN_LOCKED);
476 static phase_codes_t discard(verb_t verb, obj_t obj) {
477 /* Discard object. "Throw" also comes here for most objects. Special
478 * cases for bird (might attack snake or dragon) and cage (might contain
479 * bird) and vase. Drop coins at vending machine for extra batteries. */
480 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
485 speak(actions[verb].message);
489 if (GSTONE(obj) && AT(CAVITY) &&
490 game.objects[CAVITY].prop != CAVITY_FULL) {
492 game.objects[obj].prop = STATE_IN_CAVITY;
493 game.objects[CAVITY].prop = CAVITY_FULL;
495 ((obj == EMERALD && game.objects[RUG].prop != RUG_HOVER) ||
496 (obj == RUBY && game.objects[RUG].prop == RUG_HOVER))) {
499 } else if (TOTING(RUG)) {
504 if (!TOTING(RUG) || obj == RUBY) {
505 int k = (game.objects[RUG].prop == RUG_HOVER)
508 game.objects[RUG].prop = k;
509 if (k == RUG_HOVER) {
510 k = objects[SAPPH].plac;
512 move(RUG + NOBJECTS, k);
519 if (obj == COINS && HERE(VEND)) {
521 drop(BATTERY, game.loc);
522 pspeak(BATTERY, look, true, FRESH_BATTERIES);
526 if (LIQUID() == obj) {
529 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
530 game.objects[LIQUID()].place = LOC_NOWHERE;
533 if (obj == BEAR && AT(TROLL)) {
534 state_change(TROLL, TROLL_GONE);
535 move(TROLL, LOC_NOWHERE);
536 move(TROLL + NOBJECTS, IS_FREE);
537 move(TROLL2, objects[TROLL].plac);
538 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
545 if (game.loc != objects[PILLOW].plac) {
547 AT(PILLOW) ? VASE_WHOLE : VASE_DROPPED);
548 if (game.objects[VASE].prop != VASE_WHOLE) {
549 game.objects[VASE].fixed = IS_FIXED;
556 if (obj == CAGE && game.objects[BIRD].prop == BIRD_CAGED) {
557 drop(BIRD, game.loc);
561 if (AT(DRAGON) && game.objects[DRAGON].prop == DRAGON_BARS) {
567 rspeak(BIRD_ATTACKS);
572 /* Set game.prop for use by travel options */
573 game.objects[SNAKE].prop = SNAKE_CHASED;
578 game.objects[BIRD].prop =
579 FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
589 static phase_codes_t drink(verb_t verb, obj_t obj) {
590 /* Drink. If no object, assume water and look for it here. If water
591 * is in the bottle, drink that, else must be at a water loc, so drink
593 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
594 (LIQUID() != WATER || !HERE(BOTTLE))) {
600 state_change(DRAGON, DRAGON_BLOODLESS);
605 if (obj != INTRANSITIVE && obj != WATER) {
606 rspeak(RIDICULOUS_ATTEMPT);
609 if (LIQUID() == WATER && HERE(BOTTLE)) {
610 game.objects[WATER].place = LOC_NOWHERE;
611 state_change(BOTTLE, EMPTY_BOTTLE);
615 speak(actions[verb].message);
619 static phase_codes_t eat(verb_t verb, obj_t obj) {
620 /* Eat. Intransitive: assume food if present, else ask what.
621 * Transitive: food ok, some things lose appetite, rest are ridiculous.
630 rspeak(THANKS_DELICIOUS);
641 rspeak(LOST_APPETITE);
644 speak(actions[verb].message);
649 static phase_codes_t extinguish(verb_t verb, obj_t obj) {
650 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
651 if (obj == INTRANSITIVE) {
652 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_BRIGHT) {
655 if (HERE(URN) && game.objects[URN].prop == URN_LIT) {
658 if (obj == INTRANSITIVE) {
665 if (game.objects[URN].prop != URN_EMPTY) {
666 state_change(URN, URN_DARK);
668 pspeak(URN, change, true, URN_DARK);
672 state_change(LAMP, LAMP_DARK);
673 rspeak(DARK(game.loc) ? PITCH_DARK : NO_MESSAGE);
677 rspeak(BEYOND_POWER);
680 speak(actions[verb].message);
685 static phase_codes_t feed(verb_t verb, obj_t obj) {
686 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf,
687 * make him mad. Bear, special. */
693 if (game.objects[DRAGON].prop != DRAGON_BARS) {
694 rspeak(RIDICULOUS_ATTEMPT);
696 rspeak(NOTHING_EDIBLE);
700 if (!game.closed && HERE(BIRD)) {
702 rspeak(BIRD_DEVOURED);
704 rspeak(NOTHING_EDIBLE);
715 speak(actions[verb].message);
719 if (game.objects[BEAR].prop == BEAR_DEAD) {
720 rspeak(RIDICULOUS_ATTEMPT);
723 if (game.objects[BEAR].prop == UNTAMED_BEAR) {
726 game.objects[AXE].fixed = IS_FREE;
727 game.objects[AXE].prop = AXE_HERE;
728 state_change(BEAR, SITTING_BEAR);
730 rspeak(NOTHING_EDIBLE);
734 speak(actions[verb].message);
740 speak(actions[verb].message);
749 phase_codes_t fill(verb_t verb, obj_t obj) {
750 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
753 if (LIQLOC(game.loc) == NO_OBJECT) {
754 rspeak(FILL_INVALID);
758 rspeak(ARENT_CARRYING);
761 rspeak(SHATTER_VASE);
762 game.objects[VASE].prop = VASE_BROKEN;
763 game.objects[VASE].fixed = IS_FIXED;
764 drop(VASE, game.loc);
769 if (game.objects[URN].prop != URN_EMPTY) {
774 rspeak(FILL_INVALID);
780 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
784 game.objects[URN].prop = URN_DARK;
785 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
790 rspeak(FILL_INVALID);
793 game.objects[k].place = LOC_NOWHERE;
796 if (obj != INTRANSITIVE && obj != BOTTLE) {
797 speak(actions[verb].message);
800 if (obj == INTRANSITIVE && !HERE(BOTTLE))
803 if (HERE(URN) && game.objects[URN].prop != URN_EMPTY) {
807 if (LIQUID() != NO_OBJECT) {
811 if (LIQLOC(game.loc) == NO_OBJECT) {
817 (LIQLOC(game.loc) == OIL) ? OIL_BOTTLE : WATER_BOTTLE);
818 if (TOTING(BOTTLE)) {
819 game.objects[LIQUID()].place = CARRIED;
824 static phase_codes_t find(verb_t verb, obj_t obj) {
825 /* Find. Might be carrying it, or it might be here. Else give caveat.
828 rspeak(ALREADY_CARRYING);
833 rspeak(NEEDED_NEARBY);
837 if (AT(obj) || (LIQUID() == obj && AT(BOTTLE)) ||
838 obj == LIQLOC(game.loc) || (obj == DWARF && atdwrf(game.loc) > 0)) {
843 speak(actions[verb].message);
847 static phase_codes_t fly(verb_t verb, obj_t obj) {
848 /* Fly. Snide remarks unless hovering rug is here. */
849 if (obj == INTRANSITIVE) {
854 if (game.objects[RUG].prop != RUG_HOVER) {
855 rspeak(RUG_NOTHING2);
862 speak(actions[verb].message);
865 if (game.objects[RUG].prop != RUG_HOVER) {
866 rspeak(RUG_NOTHING1);
870 if (game.loc == LOC_CLIFF) {
871 game.oldlc2 = game.oldloc;
872 game.oldloc = game.loc;
873 game.newloc = LOC_LEDGE;
875 } else if (game.loc == LOC_LEDGE) {
876 game.oldlc2 = game.oldloc;
877 game.oldloc = game.loc;
878 game.newloc = LOC_CLIFF;
882 /* should never happen */
883 rspeak(NOTHING_HAPPENS);
889 static phase_codes_t inven(void) {
890 /* Inventory. If object, treat same as find. Else report on current
893 for (obj_t i = 1; i <= NOBJECTS; i++) {
894 if (i == BEAR || !TOTING(i))
900 pspeak(i, touch, false, -1);
909 static phase_codes_t light(verb_t verb, obj_t obj) {
910 /* Light. Applicable only to lamp and urn. */
911 if (obj == INTRANSITIVE) {
913 if (HERE(LAMP) && game.objects[LAMP].prop == LAMP_DARK &&
918 if (HERE(URN) && game.objects[URN].prop == URN_DARK) {
928 state_change(URN, game.objects[URN].prop == URN_EMPTY
933 if (game.limit < 0) {
937 state_change(LAMP, LAMP_BRIGHT);
943 speak(actions[verb].message);
948 static phase_codes_t listen(void) {
949 /* Listen. Intransitive only. Print stuff based on object sound
951 bool soundlatch = false;
952 vocab_t sound = locations[game.loc].sound;
953 if (sound != SILENT) {
955 if (!locations[game.loc].loud) {
960 for (obj_t i = 1; i <= NOBJECTS; i++) {
961 if (!HERE(i) || objects[i].sounds[0] == NULL ||
962 PROP_IS_STASHED_OR_UNSEEN(i)) {
965 int mi = game.objects[i].prop;
966 /* (ESR) Some unpleasant magic on object states here. Ideally
967 * we'd have liked the bird to be a normal object that we can
968 * use state_change() on; can't do it, because there are
969 * actually two different series of per-state birdsounds
970 * depending on whether player has drunk dragon's blood. */
972 mi += 3 * game.blooded;
974 pspeak(i, hear, true, mi, game.zzword);
976 if (i == BIRD && mi == BIRD_ENDSTATE) {
987 static phase_codes_t lock(verb_t verb, obj_t obj) {
988 /* Lock, unlock, no object given. Assume various things if present. */
989 if (obj == INTRANSITIVE) {
1005 if (obj == INTRANSITIVE) {
1006 rspeak(NOTHING_LOCKED);
1011 /* Lock, unlock object. Special stuff for opening clam/oyster
1025 rspeak(EXIT_CLOSED);
1027 game.clock2 = PANICTIME;
1031 state_change(GRATE, (verb == LOCK)
1042 } else if (TOTING(CLAM)) {
1044 } else if (!TOTING(TRIDENT)) {
1045 rspeak(CLAM_OPENER);
1048 drop(OYSTER, game.loc);
1049 drop(PEARL, LOC_CULDESAC);
1050 rspeak(PEARL_FALLS);
1056 } else if (TOTING(OYSTER)) {
1057 rspeak(DROP_OYSTER);
1058 } else if (!TOTING(TRIDENT)) {
1059 rspeak(OYSTER_OPENER);
1061 rspeak(OYSTER_OPENS);
1065 rspeak((game.objects[DOOR].prop == DOOR_UNRUSTED) ? OK_MAN
1072 rspeak(CANNOT_UNLOCK);
1075 speak(actions[verb].message);
1081 static phase_codes_t pour(verb_t verb, obj_t obj) {
1082 /* Pour. If no object, or object is bottle, assume contents of bottle.
1083 * special tests for pouring water or oil on plant or rusty door. */
1084 if (obj == BOTTLE || obj == INTRANSITIVE) {
1087 if (obj == NO_OBJECT) {
1091 speak(actions[verb].message);
1095 if (obj != OIL && obj != WATER) {
1099 if (HERE(URN) && game.objects[URN].prop == URN_EMPTY) {
1100 return fill(verb, URN);
1102 game.objects[BOTTLE].prop = EMPTY_BOTTLE;
1103 game.objects[obj].place = LOC_NOWHERE;
1104 if (!(AT(PLANT) || AT(DOOR))) {
1110 /* cycle through the three plant states */
1112 MOD(game.objects[PLANT].prop + 1, 3));
1113 game.objects[PLANT2].prop = game.objects[PLANT].prop;
1116 rspeak(SHAKING_LEAVES);
1120 state_change(DOOR, (obj == OIL) ? DOOR_UNRUSTED : DOOR_RUSTED);
1125 static phase_codes_t quit(void) {
1126 /* Quit. Intransitive only. Verify intent and exit if that's what he
1128 if (yes_or_no(arbitrary_messages[REALLY_QUIT],
1129 arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN])) {
1130 terminate(quitgame);
1135 static phase_codes_t read(command_t command)
1136 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1138 if (command.obj == INTRANSITIVE) {
1139 command.obj = NO_OBJECT;
1140 for (int i = 1; i <= NOBJECTS; i++) {
1141 if (HERE(i) && objects[i].texts[0] != NULL &&
1142 !PROP_IS_STASHED(i)) {
1143 command.obj = command.obj * NOBJECTS + i;
1146 if (command.obj > NOBJECTS || command.obj == NO_OBJECT ||
1152 if (DARK(game.loc)) {
1153 sspeak(NO_SEE, command.word[0].raw);
1154 } else if (command.obj == OYSTER) {
1155 if (!TOTING(OYSTER) || !game.closed) {
1156 rspeak(DONT_UNDERSTAND);
1157 } else if (!game.clshnt) {
1158 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY],
1159 arbitrary_messages[WAYOUT_CLUE],
1160 arbitrary_messages[OK_MAN]);
1162 pspeak(OYSTER, hear, true,
1163 1); // Not really a sound, but oh well.
1165 } else if (objects[command.obj].texts[0] == NULL ||
1166 PROP_IS_NOTFOUND(command.obj)) {
1167 speak(actions[command.verb].message);
1169 pspeak(command.obj, study, true,
1170 game.objects[command.obj].prop);
1175 static phase_codes_t reservoir(void) {
1176 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1177 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1178 rspeak(NOTHING_HAPPENS);
1181 state_change(RESER, game.objects[RESER].prop == WATERS_PARTED
1187 game.oldlc2 = game.loc;
1188 game.newloc = LOC_NOWHERE;
1190 return GO_TERMINATE;
1195 static phase_codes_t rub(verb_t verb, obj_t obj) {
1196 /* Rub. Yields various snide remarks except for lit urn. */
1197 if (obj == URN && game.objects[URN].prop == URN_LIT) {
1199 drop(AMBER, game.loc);
1200 game.objects[AMBER].prop = AMBER_IN_ROCK;
1202 drop(CAVITY, game.loc);
1204 } else if (obj != LAMP) {
1205 rspeak(PECULIAR_NOTHING);
1207 speak(actions[verb].message);
1212 static phase_codes_t say(command_t command) {
1213 /* Say. Echo WD2. Magic words override. */
1214 if (command.word[1].type == MOTION &&
1215 (command.word[1].id == XYZZY || command.word[1].id == PLUGH ||
1216 command.word[1].id == PLOVER)) {
1219 if (command.word[1].type == ACTION && command.word[1].id == PART) {
1223 if (command.word[1].type == ACTION &&
1224 (command.word[1].id == FEE || command.word[1].id == FIE ||
1225 command.word[1].id == FOE || command.word[1].id == FOO ||
1226 command.word[1].id == FUM || command.word[1].id == PART)) {
1227 return bigwords(command.word[1].id);
1229 sspeak(OKEY_DOKEY, command.word[1].raw);
1233 static phase_codes_t throw_support(vocab_t spk) {
1235 drop(AXE, game.loc);
1239 static phase_codes_t throwit(command_t command) {
1240 /* Throw. Same as discard unless axe. Then same as attack except
1241 * ignore bird, and if dwarf is present then one might be killed.
1242 * (Only way to do so!) Axe also special for dragon, bear, and
1243 * troll. Treasures special for troll. */
1244 if (!TOTING(command.obj)) {
1245 speak(actions[command.verb].message);
1248 if (objects[command.obj].is_treasure && AT(TROLL)) {
1249 /* Snarf a treasure for the troll. */
1250 drop(command.obj, LOC_NOWHERE);
1251 move(TROLL, LOC_NOWHERE);
1252 move(TROLL + NOBJECTS, IS_FREE);
1253 drop(TROLL2, objects[TROLL].plac);
1254 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1256 rspeak(TROLL_SATISFIED);
1259 if (command.obj == FOOD && HERE(BEAR)) {
1260 /* But throwing food is another story. */
1262 return (feed(command.verb, command.obj));
1264 if (command.obj != AXE) {
1265 return (discard(command.verb, command.obj));
1267 if (atdwrf(game.loc) <= 0) {
1269 game.objects[DRAGON].prop == DRAGON_BARS)
1270 return throw_support(DRAGON_SCALES);
1272 return throw_support(TROLL_RETURNS);
1275 return throw_support(OGRE_DODGE);
1278 game.objects[BEAR].prop == UNTAMED_BEAR) {
1279 /* This'll teach him to throw the axe at the
1281 drop(AXE, game.loc);
1282 game.objects[AXE].fixed = IS_FIXED;
1284 state_change(AXE, AXE_LOST);
1287 command.obj = INTRANSITIVE;
1288 return (attack(command));
1291 if (randrange(NDWARVES + 1) < game.dflag) {
1292 return throw_support(DWARF_DODGES);
1294 int i = atdwrf(game.loc);
1295 game.dwarves[i].seen = false;
1296 game.dwarves[i].loc = LOC_NOWHERE;
1297 return throw_support(
1298 (++game.dkill == 1) ? DWARF_SMOKE : KILLED_DWARF);
1303 static phase_codes_t wake(verb_t verb, obj_t obj) {
1304 /* Wake. Only use is to disturb the dwarves. */
1305 if (obj != DWARF || !game.closed) {
1306 speak(actions[verb].message);
1310 return GO_DWARFWAKE;
1314 static phase_codes_t seed(verb_t verb, const char *arg) {
1316 int32_t seed = strtol(arg, NULL, 10);
1317 speak(actions[verb].message, seed);
1323 static phase_codes_t waste(verb_t verb, turn_t turns) {
1325 game.limit -= turns;
1326 speak(actions[verb].message, (int)game.limit);
1330 static phase_codes_t wave(verb_t verb, obj_t obj) {
1331 /* Wave. No effect unless waving rod at fissure or at bird. */
1332 if (obj != ROD || !TOTING(obj) ||
1333 (!HERE(BIRD) && (game.closng || !AT(FISSURE)))) {
1334 speak(((!TOTING(obj)) && (obj != ROD || !TOTING(ROD2)))
1335 ? arbitrary_messages[ARENT_CARRYING]
1336 : actions[verb].message);
1340 if (game.objects[BIRD].prop == BIRD_UNCAGED &&
1341 game.loc == game.objects[STEPS].place && PROP_IS_NOTFOUND(JADE)) {
1342 drop(JADE, game.loc);
1343 PROP_SET_FOUND(JADE);
1345 rspeak(NECKLACE_FLY);
1349 rspeak((game.objects[BIRD].prop == BIRD_CAGED)
1352 return GO_DWARFWAKE;
1354 if (game.closng || !AT(FISSURE)) {
1355 rspeak((game.objects[BIRD].prop == BIRD_CAGED)
1361 rspeak((game.objects[BIRD].prop == BIRD_CAGED)
1365 state_change(FISSURE, game.objects[FISSURE].prop == BRIDGED
1372 phase_codes_t action(command_t command) {
1373 /* Analyse a verb. Remember what it was, go back for object if second
1374 * word unless verb is "say", which snarfs arbitrary second word.
1376 /* Previously, actions that result in a message, but don't do anything
1377 * further were called "specials". Now they're handled here as normal
1378 * actions. If noaction is true, then we spit out the message and return
1380 if (actions[command.verb].noaction) {
1381 speak(actions[command.verb].message);
1385 if (command.part == unknown) {
1386 /* Analyse an object word. See if the thing is here, whether
1387 * we've got a verb yet, and so on. Object must be here
1388 * unless verb is "find" or "invent(ory)" (and no new verb
1389 * yet to be analysed). Water and oil are also funny, since
1390 * they are never actually dropped at any location, but might
1391 * be here inside the bottle or urn or as a feature of the
1393 if (HERE(command.obj)) {
1395 } else if (command.obj == DWARF && atdwrf(game.loc) > 0) {
1397 } else if (!game.closed &&
1398 ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1399 command.obj == LIQLOC(game.loc))) {
1401 } else if (command.obj == OIL && HERE(URN) &&
1402 game.objects[URN].prop != URN_EMPTY) {
1405 } else if (command.obj == PLANT && AT(PLANT2) &&
1406 game.objects[PLANT2].prop != PLANT_THIRSTY) {
1407 command.obj = PLANT2;
1409 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1411 rspeak(KNIVES_VANISH);
1413 } else if (command.obj == ROD && HERE(ROD2)) {
1416 } else if ((command.verb == FIND ||
1417 command.verb == INVENTORY) &&
1418 (command.word[1].id == WORD_EMPTY ||
1419 command.word[1].id == WORD_NOT_FOUND)) {
1422 sspeak(NO_SEE, command.word[0].raw);
1426 if (command.verb != 0) {
1427 command.part = transitive;
1431 switch (command.part) {
1433 if (command.word[1].raw[0] != '\0' && command.verb != SAY) {
1436 if (command.verb == SAY) {
1437 /* KEYS is not special, anything not NO_OBJECT or
1438 * INTRANSITIVE will do here. We're preventing
1439 * interpretation as an intransitive verb when the word
1442 command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1444 if (command.obj == NO_OBJECT || command.obj == INTRANSITIVE) {
1445 /* Analyse an intransitive verb (ie, no object given
1447 switch (command.verb) {
1449 return vcarry(command.verb, INTRANSITIVE);
1455 return lock(command.verb, INTRANSITIVE);
1458 return (GO_CLEAROBJ);
1461 return lock(command.verb, INTRANSITIVE);
1463 return light(command.verb, INTRANSITIVE);
1465 return extinguish(command.verb, INTRANSITIVE);
1471 speak(actions[command.verb].message);
1475 command.obj = INTRANSITIVE;
1476 return attack(command);
1478 return pour(command.verb, INTRANSITIVE);
1480 return eat(command.verb, INTRANSITIVE);
1482 return drink(command.verb, INTRANSITIVE);
1496 return fill(command.verb, INTRANSITIVE);
1508 return bigwords(command.word[0].id);
1512 command.obj = INTRANSITIVE;
1513 return read(command);
1523 return fly(command.verb, INTRANSITIVE);
1530 rspeak(NUMERIC_REQUIRED);
1532 default: // LCOV_EXCL_LINE
1533 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1538 /* Analyse a transitive verb. */
1539 switch (command.verb) {
1541 return vcarry(command.verb, command.obj);
1543 return discard(command.verb, command.obj);
1545 return say(command);
1547 return lock(command.verb, command.obj);
1550 return (GO_CLEAROBJ);
1553 return lock(command.verb, command.obj);
1555 return light(command.verb, command.obj);
1557 return extinguish(command.verb, command.obj);
1559 return wave(command.verb, command.obj);
1561 speak(actions[command.verb].message);
1565 speak(actions[command.verb].message);
1569 return attack(command);
1571 return pour(command.verb, command.obj);
1573 return eat(command.verb, command.obj);
1575 return drink(command.verb, command.obj);
1577 return rub(command.verb, command.obj);
1579 return throwit(command);
1581 speak(actions[command.verb].message);
1584 return find(command.verb, command.obj);
1586 return find(command.verb, command.obj);
1588 return feed(command.verb, command.obj);
1590 return fill(command.verb, command.obj);
1595 speak(actions[command.verb].message);
1602 speak(actions[command.verb].message);
1605 speak(actions[command.verb].message);
1608 return read(command);
1610 return vbreak(command.verb, command.obj);
1612 return wake(command.verb, command.obj);
1614 speak(actions[command.verb].message);
1617 speak(actions[command.verb].message);
1620 return fly(command.verb, command.obj);
1622 speak(actions[command.verb].message);
1625 // This case should never happen - here only as placeholder
1630 return seed(command.verb, command.word[1].raw);
1632 return waste(command.verb,
1633 (turn_t)atol(command.word[1].raw));
1634 default: // LCOV_EXCL_LINE
1635 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1638 /* Unknown verb, couldn't deduce object - might need hint */
1639 sspeak(WHAT_DO, command.word[0].raw);
1640 return GO_CHECKHINT;
1641 default: // LCOV_EXCL_LINE
1642 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE