2 * Actions for the dungeon-running code.
4 * Copyright (c) 1977, 2005 by Will Crowther and Don Woods
5 * Copyright (c) 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 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.place[EGGS] == 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.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
220 game.prop[TROLL] = TROLL_PAIDONCE;
222 pspeak(EGGS, look, true, EGGS_VANISHED);
223 else if (game.loc == objects[EGGS].plac)
224 pspeak(EGGS, look, true, EGGS_HERE);
226 pspeak(EGGS, look, true, EGGS_DONE);
227 move(EGGS, objects[EGGS].plac);
233 game.foobar = WORD_EMPTY;
238 static void blast(void)
239 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
241 if (game.prop[ROD2] == STATE_NOTFOUND ||
243 rspeak(REQUIRES_DYNAMITE);
246 game.bonus = splatter;
247 rspeak(SPLATTER_MESSAGE);
248 } else if (game.loc == LOC_NE) {
250 rspeak(DEFEAT_MESSAGE);
252 game.bonus = victory;
253 rspeak(VICTORY_MESSAGE);
259 static phase_codes_t vbreak(verb_t verb, obj_t obj)
260 /* Break. Only works for mirror in repository and, of course, the vase. */
265 state_change(MIRROR, MIRROR_BROKEN);
272 if (game.prop[VASE] == VASE_WHOLE) {
274 drop(VASE, game.loc);
275 state_change(VASE, VASE_BROKEN);
276 game.fixed[VASE] = IS_FIXED;
281 speak(actions[verb].message);
283 return (GO_CLEAROBJ);
286 static phase_codes_t brief(void)
287 /* Brief. Intransitive only. Suppress full descriptions after first time. */
291 rspeak(BRIEF_CONFIRM);
295 static phase_codes_t vcarry(verb_t verb, obj_t obj)
296 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
297 * take one without the other). Liquids also special, since they depend on
298 * 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.atloc[game.loc] == NO_OBJECT ||
303 game.link[game.atloc[game.loc]] != 0 ||
304 atdwrf(game.loc) > 0)
306 obj = game.atloc[game.loc];
310 speak(actions[verb].message);
315 rspeak(REMOVE_MESSAGE);
320 if (game.fixed[obj] != IS_FREE) {
323 /* Next guard tests whether plant is tiny or stashed */
324 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
327 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
330 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
333 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
339 rspeak(DOUGHNUT_HOLES);
345 rspeak(HAND_PASSTHROUGH);
357 if (!TOTING(BOTTLE)) {
358 rspeak(NO_CONTAINER);
361 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
362 return (fill(verb, BOTTLE));
370 if (game.holdng >= INVLIMIT) {
376 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
377 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
383 rspeak(CANNOT_CARRY);
390 game.prop[BIRD] = BIRD_CAGED;
394 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
395 /* expression maps BIRD to CAGE and CAGE to BIRD */
396 carry(BIRD + CAGE - obj, game.loc);
399 carry(obj, game.loc);
401 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
402 game.place[LIQUID()] = CARRIED;
404 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
405 game.prop[obj] = STATE_FOUND;
406 game.prop[CAVITY] = CAVITY_EMPTY;
412 static int chain(verb_t verb)
413 /* Do something to the bear's chain */
416 if (game.prop[BEAR] == UNTAMED_BEAR) {
420 if (game.prop[CHAIN] == CHAIN_HEAP) {
421 rspeak(ALREADY_UNLOCKED);
424 game.prop[CHAIN] = CHAIN_HEAP;
425 game.fixed[CHAIN] = IS_FREE;
426 if (game.prop[BEAR] != BEAR_DEAD)
427 game.prop[BEAR] = CONTENTED_BEAR;
429 switch (game.prop[BEAR]) {
432 /* Can't be reached until the bear can die in some way other
433 * than a bridge collapse. Leave in in case this changes, but
434 * exclude from coverage testing. */
435 game.fixed[BEAR] = IS_FIXED;
439 game.fixed[BEAR] = IS_FREE;
441 rspeak(CHAIN_UNLOCKED);
445 if (game.prop[CHAIN] != CHAIN_HEAP) {
446 rspeak(ALREADY_LOCKED);
449 if (game.loc != objects[CHAIN].plac) {
454 game.prop[CHAIN] = CHAIN_FIXED;
457 drop(CHAIN, game.loc);
458 game.fixed[CHAIN] = IS_FIXED;
460 rspeak(CHAIN_LOCKED);
464 static phase_codes_t discard(verb_t verb, obj_t obj)
465 /* Discard object. "Throw" also comes here for most objects. Special cases for
466 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
467 * Drop coins at vending machine for extra batteries. */
469 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
474 speak(actions[verb].message);
478 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
480 game.prop[obj] = STATE_IN_CAVITY;
481 game.prop[CAVITY] = CAVITY_FULL;
482 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
483 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
486 else if (TOTING(RUG))
490 if (!TOTING(RUG) || obj == RUBY) {
491 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
494 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);
511 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
512 game.place[LIQUID()] = LOC_NOWHERE;
515 if (obj == BEAR && AT(TROLL)) {
516 state_change(TROLL, TROLL_GONE);
517 move(TROLL, LOC_NOWHERE);
518 move(TROLL + NOBJECTS, IS_FREE);
519 move(TROLL2, objects[TROLL].plac);
520 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
527 if (game.loc != objects[PILLOW].plac) {
528 state_change(VASE, AT(PILLOW)
531 if (game.prop[VASE] != VASE_WHOLE)
532 game.fixed[VASE] = IS_FIXED;
538 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
539 drop(BIRD, game.loc);
543 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
549 rspeak(BIRD_ATTACKS);
553 /* Set game.prop for use by travel options */
554 game.prop[SNAKE] = SNAKE_CHASED;
558 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
568 static phase_codes_t drink(verb_t verb, obj_t obj)
569 /* Drink. If no object, assume water and look for it here. If water is in
570 * the bottle, drink that, else must be at a water loc, so drink stream. */
572 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
573 (LIQUID() != WATER || !HERE(BOTTLE))) {
579 state_change(DRAGON, DRAGON_BLOODLESS);
584 if (obj != INTRANSITIVE && obj != WATER) {
585 rspeak(RIDICULOUS_ATTEMPT);
588 if (LIQUID() == WATER && HERE(BOTTLE)) {
589 game.place[WATER] = LOC_NOWHERE;
590 state_change(BOTTLE, EMPTY_BOTTLE);
594 speak(actions[verb].message);
598 static phase_codes_t eat(verb_t verb, obj_t obj)
599 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
600 * ok, some things lose appetite, rest are ridiculous. */
609 rspeak(THANKS_DELICIOUS);
620 rspeak(LOST_APPETITE);
623 speak(actions[verb].message);
628 static phase_codes_t extinguish(verb_t verb, obj_t obj)
629 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
631 if (obj == INTRANSITIVE) {
632 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
634 if (HERE(URN) && game.prop[URN] == URN_LIT)
636 if (obj == INTRANSITIVE)
642 if (game.prop[URN] != URN_EMPTY) {
643 state_change(URN, URN_DARK);
645 pspeak(URN, change, true, URN_DARK);
649 state_change(LAMP, LAMP_DARK);
650 rspeak(DARK(game.loc) ?
656 rspeak(BEYOND_POWER);
659 speak(actions[verb].message);
664 static phase_codes_t feed(verb_t verb, obj_t obj)
665 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
666 * mad. Bear, special. */
673 if (game.prop[DRAGON] != DRAGON_BARS)
674 rspeak(RIDICULOUS_ATTEMPT);
676 rspeak(NOTHING_EDIBLE);
679 if (!game.closed && HERE(BIRD)) {
681 rspeak(BIRD_DEVOURED);
683 rspeak(NOTHING_EDIBLE);
693 speak(actions[verb].message);
696 if (game.prop[BEAR] == BEAR_DEAD) {
697 rspeak(RIDICULOUS_ATTEMPT);
700 if (game.prop[BEAR] == UNTAMED_BEAR) {
703 game.fixed[AXE] = IS_FREE;
704 game.prop[AXE] = AXE_HERE;
705 state_change(BEAR, SITTING_BEAR);
707 rspeak(NOTHING_EDIBLE);
710 speak(actions[verb].message);
716 speak(actions[verb].message);
724 phase_codes_t fill(verb_t verb, obj_t obj)
725 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
729 if (LIQLOC(game.loc) == NO_OBJECT) {
730 rspeak(FILL_INVALID);
734 rspeak(ARENT_CARRYING);
737 rspeak(SHATTER_VASE);
738 game.prop[VASE] = VASE_BROKEN;
739 game.fixed[VASE] = IS_FIXED;
740 drop(VASE, game.loc);
745 if (game.prop[URN] != URN_EMPTY) {
750 rspeak(FILL_INVALID);
756 game.prop[BOTTLE] = EMPTY_BOTTLE;
760 game.prop[URN] = URN_DARK;
761 game.prop[BOTTLE] = EMPTY_BOTTLE;
766 rspeak(FILL_INVALID);
769 game.place[k] = LOC_NOWHERE;
772 if (obj != INTRANSITIVE && obj != BOTTLE) {
773 speak(actions[verb].message);
776 if (obj == INTRANSITIVE && !HERE(BOTTLE))
779 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
783 if (LIQUID() != NO_OBJECT) {
787 if (LIQLOC(game.loc) == NO_OBJECT) {
792 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
796 game.place[LIQUID()] = CARRIED;
800 static phase_codes_t find(verb_t verb, obj_t obj)
801 /* Find. Might be carrying it, or it might be here. Else give caveat. */
804 rspeak(ALREADY_CARRYING);
809 rspeak(NEEDED_NEARBY);
814 (LIQUID() == obj && AT(BOTTLE)) ||
815 obj == LIQLOC(game.loc) ||
816 (obj == DWARF && atdwrf(game.loc) > 0)) {
822 speak(actions[verb].message);
826 static phase_codes_t fly(verb_t verb, obj_t obj)
827 /* Fly. Snide remarks unless hovering rug is here. */
829 if (obj == INTRANSITIVE) {
834 if (game.prop[RUG] != RUG_HOVER) {
835 rspeak(RUG_NOTHING2);
842 speak(actions[verb].message);
845 if (game.prop[RUG] != RUG_HOVER) {
846 rspeak(RUG_NOTHING1);
850 if (game.loc == LOC_CLIFF) {
851 game.oldlc2 = game.oldloc;
852 game.oldloc = game.loc;
853 game.newloc = LOC_LEDGE;
855 } else if (game.loc == LOC_LEDGE) {
856 game.oldlc2 = game.oldloc;
857 game.oldloc = game.loc;
858 game.newloc = LOC_CLIFF;
862 /* should never happen */
863 rspeak(NOTHING_HAPPENS);
869 static phase_codes_t inven(void)
870 /* Inventory. If object, treat same as find. Else report on current burden. */
873 for (obj_t i = 1; i <= NOBJECTS; i++) {
881 pspeak(i, touch, false, -1);
890 static phase_codes_t light(verb_t verb, obj_t obj)
891 /* Light. Applicable only to lamp and urn. */
893 if (obj == INTRANSITIVE) {
895 if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
899 if (HERE(URN) && game.prop[URN] == URN_DARK) {
909 state_change(URN, game.prop[URN] == URN_EMPTY ?
914 if (game.limit < 0) {
918 state_change(LAMP, LAMP_BRIGHT);
923 speak(actions[verb].message);
928 static phase_codes_t listen(void)
929 /* Listen. Intransitive only. Print stuff based on object sound properties. */
931 bool soundlatch = false;
932 vocab_t sound = locations[game.loc].sound;
933 if (sound != SILENT) {
935 if (!locations[game.loc].loud)
939 for (obj_t i = 1; i <= NOBJECTS; i++) {
941 objects[i].sounds[0] == NULL ||
944 int mi = game.prop[i];
945 /* (ESR) Some unpleasant magic on object states here. Ideally
946 * we'd have liked the bird to be a normal object that we can
947 * use state_change() on; can't do it, because there are
948 * actually two different series of per-state birdsounds
949 * depending on whether player has drunk dragon's blood. */
951 mi += 3 * game.blooded;
952 pspeak(i, hear, true, mi, game.zzword);
954 if (i == BIRD && mi == BIRD_ENDSTATE)
963 static phase_codes_t lock(verb_t verb, obj_t obj)
964 /* Lock, unlock, no object given. Assume various things if present. */
966 if (obj == INTRANSITIVE) {
977 if (obj == INTRANSITIVE) {
978 rspeak(NOTHING_LOCKED);
983 /* Lock, unlock object. Special stuff for opening clam/oyster
998 game.clock2 = PANICTIME;
1001 state_change(GRATE, (verb == LOCK) ?
1011 else if (TOTING(CLAM))
1013 else if (!TOTING(TRIDENT))
1014 rspeak(CLAM_OPENER);
1017 drop(OYSTER, game.loc);
1018 drop(PEARL, LOC_CULDESAC);
1019 rspeak(PEARL_FALLS);
1025 else if (TOTING(OYSTER))
1026 rspeak(DROP_OYSTER);
1027 else if (!TOTING(TRIDENT))
1028 rspeak(OYSTER_OPENER);
1030 rspeak(OYSTER_OPENS);
1033 rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1039 rspeak(CANNOT_UNLOCK);
1042 speak(actions[verb].message);
1048 static phase_codes_t pour(verb_t verb, obj_t obj)
1049 /* Pour. If no object, or object is bottle, assume contents of bottle.
1050 * special tests for pouring water or oil on plant or rusty door. */
1052 if (obj == BOTTLE ||
1053 obj == INTRANSITIVE)
1055 if (obj == NO_OBJECT)
1058 speak(actions[verb].message);
1062 if (obj != OIL && obj != WATER) {
1066 if (HERE(URN) && game.prop[URN] == URN_EMPTY)
1067 return fill(verb, URN);
1068 game.prop[BOTTLE] = EMPTY_BOTTLE;
1069 game.place[obj] = LOC_NOWHERE;
1077 /* cycle through the three plant states */
1078 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1079 game.prop[PLANT2] = game.prop[PLANT];
1082 rspeak(SHAKING_LEAVES);
1086 state_change(DOOR, (obj == OIL) ?
1093 static phase_codes_t quit(void)
1094 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1096 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1097 terminate(quitgame);
1101 static phase_codes_t read(command_t command)
1102 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1104 if (command.obj == INTRANSITIVE) {
1105 command.obj = NO_OBJECT;
1106 for (int i = 1; i <= NOBJECTS; i++) {
1107 if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
1108 command.obj = command.obj * NOBJECTS + i;
1110 if (command.obj > NOBJECTS ||
1111 command.obj == NO_OBJECT ||
1116 if (DARK(game.loc)) {
1117 sspeak(NO_SEE, command.word[0].raw);
1118 } else if (command.obj == OYSTER) {
1119 if (!TOTING(OYSTER) || !game.closed) {
1120 rspeak(DONT_UNDERSTAND);
1121 } else if (!game.clshnt) {
1122 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1124 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1126 } else if (objects[command.obj].texts[0] == NULL ||
1127 game.prop[command.obj] == STATE_NOTFOUND) {
1128 speak(actions[command.verb].message);
1130 pspeak(command.obj, study, true, game.prop[command.obj]);
1134 static phase_codes_t reservoir(void)
1135 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1137 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1138 rspeak(NOTHING_HAPPENS);
1142 game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1146 game.oldlc2 = game.loc;
1147 game.newloc = LOC_NOWHERE;
1149 return GO_TERMINATE;
1154 static phase_codes_t rub(verb_t verb, obj_t obj)
1155 /* Rub. Yields various snide remarks except for lit urn. */
1157 if (obj == URN && game.prop[URN] == URN_LIT) {
1159 drop(AMBER, game.loc);
1160 game.prop[AMBER] = AMBER_IN_ROCK;
1162 drop(CAVITY, game.loc);
1164 } else if (obj != LAMP) {
1165 rspeak(PECULIAR_NOTHING);
1167 speak(actions[verb].message);
1172 static phase_codes_t say(command_t command)
1173 /* Say. Echo WD2. Magic words override. */
1175 if (command.word[1].type == MOTION &&
1176 (command.word[1].id == XYZZY ||
1177 command.word[1].id == PLUGH ||
1178 command.word[1].id == PLOVER)) {
1181 if (command.word[1].type == ACTION && command.word[1].id == PART)
1184 if (command.word[1].type == ACTION &&
1185 (command.word[1].id == FEE ||
1186 command.word[1].id == FIE ||
1187 command.word[1].id == FOE ||
1188 command.word[1].id == FOO ||
1189 command.word[1].id == FUM ||
1190 command.word[1].id == PART)) {
1191 return bigwords(command.word[1].id);
1193 sspeak(OKEY_DOKEY, command.word[1].raw);
1197 static phase_codes_t throw_support(vocab_t spk)
1200 drop(AXE, game.loc);
1204 static phase_codes_t throwit(command_t command)
1205 /* Throw. Same as discard unless axe. Then same as attack except
1206 * ignore bird, and if dwarf is present then one might be killed.
1207 * (Only way to do so!) Axe also special for dragon, bear, and
1208 * troll. Treasures special for troll. */
1210 if (!TOTING(command.obj)) {
1211 speak(actions[command.verb].message);
1214 if (objects[command.obj].is_treasure && AT(TROLL)) {
1215 /* Snarf a treasure for the troll. */
1216 drop(command.obj, LOC_NOWHERE);
1217 move(TROLL, LOC_NOWHERE);
1218 move(TROLL + NOBJECTS, IS_FREE);
1219 drop(TROLL2, objects[TROLL].plac);
1220 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1222 rspeak(TROLL_SATISFIED);
1225 if (command.obj == FOOD && HERE(BEAR)) {
1226 /* But throwing food is another story. */
1228 return (feed(command.verb, command.obj));
1230 if (command.obj != AXE)
1231 return (discard(command.verb, command.obj));
1233 if (atdwrf(game.loc) <= 0) {
1234 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS)
1235 return throw_support(DRAGON_SCALES);
1237 return throw_support(TROLL_RETURNS);
1239 return throw_support(OGRE_DODGE);
1240 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
1241 /* This'll teach him to throw the axe at the bear! */
1242 drop(AXE, game.loc);
1243 game.fixed[AXE] = IS_FIXED;
1245 state_change(AXE, AXE_LOST);
1248 command.obj = INTRANSITIVE;
1249 return (attack(command));
1252 if (randrange(NDWARVES + 1) < game.dflag) {
1253 return throw_support(DWARF_DODGES);
1255 int i = atdwrf(game.loc);
1256 game.dseen[i] = false;
1257 game.dloc[i] = LOC_NOWHERE;
1258 return throw_support((++game.dkill == 1) ?
1265 static phase_codes_t wake(verb_t verb, obj_t obj)
1266 /* Wake. Only use is to disturb the dwarves. */
1270 speak(actions[verb].message);
1274 return GO_DWARFWAKE;
1278 static phase_codes_t seed(verb_t verb, const char *arg)
1281 int32_t seed = strtol(arg, NULL, 10);
1282 speak(actions[verb].message, seed);
1288 static phase_codes_t waste(verb_t verb, turn_t turns)
1291 game.limit -= turns;
1292 speak(actions[verb].message, (int)game.limit);
1296 static phase_codes_t wave(verb_t verb, obj_t obj)
1297 /* Wave. No effect unless waving rod at fissure or at bird. */
1304 speak(((!TOTING(obj)) && (obj != ROD ||
1306 arbitrary_messages[ARENT_CARRYING] :
1307 actions[verb].message);
1311 if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1312 drop(JADE, game.loc);
1313 game.prop[JADE] = STATE_FOUND;
1315 rspeak(NECKLACE_FLY);
1319 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1322 return GO_DWARFWAKE;
1326 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1332 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1336 state_change(FISSURE,
1337 game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED);
1342 phase_codes_t action(command_t command)
1343 /* Analyse a verb. Remember what it was, go back for object if second word
1344 * unless verb is "say", which snarfs arbitrary second word.
1347 /* Previously, actions that result in a message, but don't do anything
1348 * further were called "specials". Now they're handled here as normal
1349 * actions. If noaction is true, then we spit out the message and return */
1350 if (actions[command.verb].noaction) {
1351 speak(actions[command.verb].message);
1355 if (command.part == unknown) {
1356 /* Analyse an object word. See if the thing is here, whether
1357 * we've got a verb yet, and so on. Object must be here
1358 * unless verb is "find" or "invent(ory)" (and no new verb
1359 * yet to be analysed). Water and oil are also funny, since
1360 * they are never actually dropped at any location, but might
1361 * be here inside the bottle or urn or as a feature of the
1363 if (HERE(command.obj))
1365 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1367 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1368 command.obj == LIQLOC(game.loc)))
1370 else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
1373 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) {
1374 command.obj = PLANT2;
1376 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1378 rspeak(KNIVES_VANISH);
1380 } else if (command.obj == ROD && HERE(ROD2)) {
1383 } else if ((command.verb == FIND ||
1384 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1387 sspeak(NO_SEE, command.word[0].raw);
1391 if (command.verb != 0)
1392 command.part = transitive;
1395 switch (command.part) {
1397 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1399 if (command.verb == SAY)
1400 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1401 * will do here. We're preventing interpretation as an intransitive
1402 * verb when the word is unknown. */
1403 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1404 if (command.obj == NO_OBJECT ||
1405 command.obj == INTRANSITIVE) {
1406 /* Analyse an intransitive verb (ie, no object given yet). */
1407 switch (command.verb) {
1409 return vcarry(command.verb, INTRANSITIVE);
1415 return lock(command.verb, INTRANSITIVE);
1418 return (GO_CLEAROBJ);
1421 return lock(command.verb, INTRANSITIVE);
1423 return light(command.verb, INTRANSITIVE);
1425 return extinguish(command.verb, INTRANSITIVE);
1431 speak(actions[command.verb].message);
1435 command.obj = INTRANSITIVE;
1436 return attack(command);
1438 return pour(command.verb, INTRANSITIVE);
1440 return eat(command.verb, INTRANSITIVE);
1442 return drink(command.verb, INTRANSITIVE);
1456 return fill(command.verb, INTRANSITIVE);
1468 return bigwords(command.word[0].id);
1472 command.obj = INTRANSITIVE;
1473 return read(command);
1483 return fly(command.verb, INTRANSITIVE);
1490 rspeak(NUMERIC_REQUIRED);
1492 default: // LCOV_EXCL_LINE
1493 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1498 /* Analyse a transitive verb. */
1499 switch (command.verb) {
1501 return vcarry(command.verb, command.obj);
1503 return discard(command.verb, command.obj);
1505 return say(command);
1507 return lock(command.verb, command.obj);
1510 return (GO_CLEAROBJ);
1513 return lock(command.verb, command.obj);
1515 return light(command.verb, command.obj);
1517 return extinguish(command.verb, command.obj);
1519 return wave(command.verb, command.obj);
1521 speak(actions[command.verb].message);
1525 speak(actions[command.verb].message);
1529 return attack(command);
1531 return pour(command.verb, command.obj);
1533 return eat(command.verb, command.obj);
1535 return drink(command.verb, command.obj);
1537 return rub(command.verb, command.obj);
1539 return throwit(command);
1541 speak(actions[command.verb].message);
1545 return find(command.verb, command.obj);
1547 return find(command.verb, command.obj);
1549 return feed(command.verb, command.obj);
1551 return fill(command.verb, command.obj);
1556 speak(actions[command.verb].message);
1564 speak(actions[command.verb].message);
1568 speak(actions[command.verb].message);
1572 return read(command);
1574 return vbreak(command.verb, command.obj);
1576 return wake(command.verb, command.obj);
1578 speak(actions[command.verb].message);
1582 speak(actions[command.verb].message);
1586 return fly(command.verb, command.obj);
1588 speak(actions[command.verb].message);
1592 // This case should never happen - here only as placeholder
1597 return seed(command.verb, command.word[1].raw);
1599 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1600 default: // LCOV_EXCL_LINE
1601 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1604 /* Unknown verb, couldn't deduce object - might need hint */
1605 sspeak(WHAT_DO, command.word[0].raw);
1606 return GO_CHECKHINT;
1607 default: // LCOV_EXCL_LINE
1608 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE