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 == FEE) ||
198 (foobar == FEE && id == FIE) ||
199 (foobar == FIE && id == FOE) ||
200 (foobar == FOE && id == FOO) ||
201 (foobar == FOE && id == FUM)) {
203 if ((id != FOO) && (id != FUM)) {
207 game.foobar = WORD_EMPTY;
208 if (game.place[EGGS] == objects[EGGS].plac ||
209 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
210 rspeak(NOTHING_HAPPENS);
212 } else if (id == FUM) {
215 /* Bring back troll if we steal the eggs back from him before
217 if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
218 game.prop[TROLL] = TROLL_PAIDONCE;
220 pspeak(EGGS, look, true, EGGS_VANISHED);
221 else if (game.loc == objects[EGGS].plac)
222 pspeak(EGGS, look, true, EGGS_HERE);
224 pspeak(EGGS, look, true, EGGS_DONE);
225 move(EGGS, objects[EGGS].plac);
231 if (game.loc == LOC_GIANTROOM || settings.oldstyle) {
234 /* This is new behavior in Open Adventure - sounds better when
235 * player isn't in the Giant Room. */
236 rspeak(NOTHING_HAPPENS);
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 ||
248 rspeak(REQUIRES_DYNAMITE);
251 game.bonus = splatter;
252 rspeak(SPLATTER_MESSAGE);
253 } else if (game.loc == LOC_NE) {
255 rspeak(DEFEAT_MESSAGE);
257 game.bonus = victory;
258 rspeak(VICTORY_MESSAGE);
264 static phase_codes_t vbreak(verb_t verb, obj_t obj)
265 /* Break. Only works for mirror in repository and, of course, the vase. */
270 state_change(MIRROR, MIRROR_BROKEN);
277 if (game.prop[VASE] == VASE_WHOLE) {
279 drop(VASE, game.loc);
280 state_change(VASE, VASE_BROKEN);
281 game.fixed[VASE] = IS_FIXED;
286 speak(actions[verb].message);
288 return (GO_CLEAROBJ);
291 static phase_codes_t brief(void)
292 /* Brief. Intransitive only. Suppress full descriptions after first time. */
296 rspeak(BRIEF_CONFIRM);
300 static phase_codes_t vcarry(verb_t verb, obj_t obj)
301 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
302 * take one without the other). Liquids also special, since they depend on
303 * status of bottle. Also various side effects, etc. */
305 if (obj == INTRANSITIVE) {
306 /* Carry, no object given yet. OK if only one object present. */
307 if (game.atloc[game.loc] == NO_OBJECT ||
308 game.link[game.atloc[game.loc]] != 0 ||
309 atdwrf(game.loc) > 0)
311 obj = game.atloc[game.loc];
315 speak(actions[verb].message);
320 rspeak(REMOVE_MESSAGE);
325 if (game.fixed[obj] != IS_FREE) {
328 /* Next guard tests whether plant is tiny or stashed */
329 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
332 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
335 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
338 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
344 rspeak(DOUGHNUT_HOLES);
350 rspeak(HAND_PASSTHROUGH);
362 if (!TOTING(BOTTLE)) {
363 rspeak(NO_CONTAINER);
366 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
367 return (fill(verb, BOTTLE));
375 if (game.holdng >= INVLIMIT) {
381 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
382 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
388 rspeak(CANNOT_CARRY);
395 game.prop[BIRD] = BIRD_CAGED;
399 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
400 /* expression maps BIRD to CAGE and CAGE to BIRD */
401 carry(BIRD + CAGE - obj, game.loc);
404 carry(obj, game.loc);
406 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
407 game.place[LIQUID()] = CARRIED;
409 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
410 game.prop[obj] = STATE_FOUND;
411 game.prop[CAVITY] = CAVITY_EMPTY;
417 static int chain(verb_t verb)
418 /* Do something to the bear's chain */
421 if (game.prop[BEAR] == UNTAMED_BEAR) {
425 if (game.prop[CHAIN] == CHAIN_HEAP) {
426 rspeak(ALREADY_UNLOCKED);
429 game.prop[CHAIN] = CHAIN_HEAP;
430 game.fixed[CHAIN] = IS_FREE;
431 if (game.prop[BEAR] != BEAR_DEAD)
432 game.prop[BEAR] = CONTENTED_BEAR;
434 switch (game.prop[BEAR]) {
437 /* Can't be reached until the bear can die in some way other
438 * than a bridge collapse. Leave in in case this changes, but
439 * exclude from coverage testing. */
440 game.fixed[BEAR] = IS_FIXED;
444 game.fixed[BEAR] = IS_FREE;
446 rspeak(CHAIN_UNLOCKED);
450 if (game.prop[CHAIN] != CHAIN_HEAP) {
451 rspeak(ALREADY_LOCKED);
454 if (game.loc != objects[CHAIN].plac) {
459 game.prop[CHAIN] = CHAIN_FIXED;
462 drop(CHAIN, game.loc);
463 game.fixed[CHAIN] = IS_FIXED;
465 rspeak(CHAIN_LOCKED);
469 static phase_codes_t discard(verb_t verb, obj_t obj)
470 /* Discard object. "Throw" also comes here for most objects. Special cases for
471 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
472 * Drop coins at vending machine for extra batteries. */
474 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
479 speak(actions[verb].message);
483 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
485 game.prop[obj] = STATE_IN_CAVITY;
486 game.prop[CAVITY] = CAVITY_FULL;
487 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
488 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
491 else if (TOTING(RUG))
495 if (!TOTING(RUG) || obj == RUBY) {
496 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
499 k = objects[SAPPH].plac;
500 move(RUG + NOBJECTS, k);
507 if (obj == COINS && HERE(VEND)) {
509 drop(BATTERY, game.loc);
510 pspeak(BATTERY, look, true, FRESH_BATTERIES);
516 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
517 game.place[LIQUID()] = LOC_NOWHERE;
520 if (obj == BEAR && AT(TROLL)) {
521 state_change(TROLL, TROLL_GONE);
522 move(TROLL, LOC_NOWHERE);
523 move(TROLL + NOBJECTS, IS_FREE);
524 move(TROLL2, objects[TROLL].plac);
525 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
532 if (game.loc != objects[PILLOW].plac) {
533 state_change(VASE, AT(PILLOW)
536 if (game.prop[VASE] != VASE_WHOLE)
537 game.fixed[VASE] = IS_FIXED;
543 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
544 drop(BIRD, game.loc);
548 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
554 rspeak(BIRD_ATTACKS);
558 /* Set game.prop for use by travel options */
559 game.prop[SNAKE] = SNAKE_CHASED;
563 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
573 static phase_codes_t drink(verb_t verb, obj_t obj)
574 /* Drink. If no object, assume water and look for it here. If water is in
575 * the bottle, drink that, else must be at a water loc, so drink stream. */
577 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
578 (LIQUID() != WATER || !HERE(BOTTLE))) {
584 state_change(DRAGON, DRAGON_BLOODLESS);
589 if (obj != INTRANSITIVE && obj != WATER) {
590 rspeak(RIDICULOUS_ATTEMPT);
593 if (LIQUID() == WATER && HERE(BOTTLE)) {
594 game.place[WATER] = LOC_NOWHERE;
595 state_change(BOTTLE, EMPTY_BOTTLE);
599 speak(actions[verb].message);
603 static phase_codes_t eat(verb_t verb, obj_t obj)
604 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
605 * ok, some things lose appetite, rest are ridiculous. */
614 rspeak(THANKS_DELICIOUS);
625 rspeak(LOST_APPETITE);
628 speak(actions[verb].message);
633 static phase_codes_t extinguish(verb_t verb, obj_t obj)
634 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
636 if (obj == INTRANSITIVE) {
637 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
639 if (HERE(URN) && game.prop[URN] == URN_LIT)
641 if (obj == INTRANSITIVE)
647 if (game.prop[URN] != URN_EMPTY) {
648 state_change(URN, URN_DARK);
650 pspeak(URN, change, true, URN_DARK);
654 state_change(LAMP, LAMP_DARK);
655 rspeak(DARK(game.loc) ?
661 rspeak(BEYOND_POWER);
664 speak(actions[verb].message);
669 static phase_codes_t feed(verb_t verb, obj_t obj)
670 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
671 * mad. Bear, special. */
678 if (game.prop[DRAGON] != DRAGON_BARS)
679 rspeak(RIDICULOUS_ATTEMPT);
681 rspeak(NOTHING_EDIBLE);
684 if (!game.closed && HERE(BIRD)) {
686 rspeak(BIRD_DEVOURED);
688 rspeak(NOTHING_EDIBLE);
698 speak(actions[verb].message);
701 if (game.prop[BEAR] == BEAR_DEAD) {
702 rspeak(RIDICULOUS_ATTEMPT);
705 if (game.prop[BEAR] == UNTAMED_BEAR) {
708 game.fixed[AXE] = IS_FREE;
709 game.prop[AXE] = AXE_HERE;
710 state_change(BEAR, SITTING_BEAR);
712 rspeak(NOTHING_EDIBLE);
715 speak(actions[verb].message);
721 speak(actions[verb].message);
729 phase_codes_t fill(verb_t verb, obj_t obj)
730 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
734 if (LIQLOC(game.loc) == NO_OBJECT) {
735 rspeak(FILL_INVALID);
739 rspeak(ARENT_CARRYING);
742 rspeak(SHATTER_VASE);
743 game.prop[VASE] = VASE_BROKEN;
744 game.fixed[VASE] = IS_FIXED;
745 drop(VASE, game.loc);
750 if (game.prop[URN] != URN_EMPTY) {
755 rspeak(FILL_INVALID);
761 game.prop[BOTTLE] = EMPTY_BOTTLE;
765 game.prop[URN] = URN_DARK;
766 game.prop[BOTTLE] = EMPTY_BOTTLE;
771 rspeak(FILL_INVALID);
774 game.place[k] = LOC_NOWHERE;
777 if (obj != INTRANSITIVE && obj != BOTTLE) {
778 speak(actions[verb].message);
781 if (obj == INTRANSITIVE && !HERE(BOTTLE))
784 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
788 if (LIQUID() != NO_OBJECT) {
792 if (LIQLOC(game.loc) == NO_OBJECT) {
797 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
801 game.place[LIQUID()] = CARRIED;
805 static phase_codes_t find(verb_t verb, obj_t obj)
806 /* Find. Might be carrying it, or it might be here. Else give caveat. */
809 rspeak(ALREADY_CARRYING);
814 rspeak(NEEDED_NEARBY);
819 (LIQUID() == obj && AT(BOTTLE)) ||
820 obj == LIQLOC(game.loc) ||
821 (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. */
834 if (obj == INTRANSITIVE) {
839 if (game.prop[RUG] != RUG_HOVER) {
840 rspeak(RUG_NOTHING2);
847 speak(actions[verb].message);
850 if (game.prop[RUG] != RUG_HOVER) {
851 rspeak(RUG_NOTHING1);
855 if (game.loc == LOC_CLIFF) {
856 game.oldlc2 = game.oldloc;
857 game.oldloc = game.loc;
858 game.newloc = LOC_LEDGE;
860 } else if (game.loc == LOC_LEDGE) {
861 game.oldlc2 = game.oldloc;
862 game.oldloc = game.loc;
863 game.newloc = LOC_CLIFF;
867 /* should never happen */
868 rspeak(NOTHING_HAPPENS);
874 static phase_codes_t inven(void)
875 /* Inventory. If object, treat same as find. Else report on current burden. */
878 for (obj_t i = 1; i <= NOBJECTS; i++) {
886 pspeak(i, touch, false, -1);
895 static phase_codes_t light(verb_t verb, obj_t obj)
896 /* Light. Applicable only to lamp and urn. */
898 if (obj == INTRANSITIVE) {
900 if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
904 if (HERE(URN) && game.prop[URN] == URN_DARK) {
914 state_change(URN, game.prop[URN] == URN_EMPTY ?
919 if (game.limit < 0) {
923 state_change(LAMP, LAMP_BRIGHT);
928 speak(actions[verb].message);
933 static phase_codes_t listen(void)
934 /* Listen. Intransitive only. Print stuff based on object sound properties. */
936 bool soundlatch = false;
937 vocab_t sound = locations[game.loc].sound;
938 if (sound != SILENT) {
940 if (!locations[game.loc].loud)
944 for (obj_t i = 1; i <= NOBJECTS; i++) {
946 objects[i].sounds[0] == NULL ||
949 int mi = game.prop[i];
950 /* (ESR) Some unpleasant magic on object states here. Ideally
951 * we'd have liked the bird to be a normal object that we can
952 * use state_change() on; can't do it, because there are
953 * actually two different series of per-state birdsounds
954 * depending on whether player has drunk dragon's blood. */
956 mi += 3 * game.blooded;
957 pspeak(i, hear, true, mi, game.zzword);
959 if (i == BIRD && mi == BIRD_ENDSTATE)
968 static phase_codes_t lock(verb_t verb, obj_t obj)
969 /* Lock, unlock, no object given. Assume various things if present. */
971 if (obj == INTRANSITIVE) {
982 if (obj == INTRANSITIVE) {
983 rspeak(NOTHING_LOCKED);
988 /* Lock, unlock object. Special stuff for opening clam/oyster
1001 rspeak(EXIT_CLOSED);
1003 game.clock2 = PANICTIME;
1006 state_change(GRATE, (verb == LOCK) ?
1016 else if (TOTING(CLAM))
1018 else if (!TOTING(TRIDENT))
1019 rspeak(CLAM_OPENER);
1022 drop(OYSTER, game.loc);
1023 drop(PEARL, LOC_CULDESAC);
1024 rspeak(PEARL_FALLS);
1030 else if (TOTING(OYSTER))
1031 rspeak(DROP_OYSTER);
1032 else if (!TOTING(TRIDENT))
1033 rspeak(OYSTER_OPENER);
1035 rspeak(OYSTER_OPENS);
1038 rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1044 rspeak(CANNOT_UNLOCK);
1047 speak(actions[verb].message);
1053 static phase_codes_t pour(verb_t verb, obj_t obj)
1054 /* Pour. If no object, or object is bottle, assume contents of bottle.
1055 * special tests for pouring water or oil on plant or rusty door. */
1057 if (obj == BOTTLE ||
1058 obj == INTRANSITIVE)
1060 if (obj == NO_OBJECT)
1063 speak(actions[verb].message);
1067 if (obj != OIL && obj != WATER) {
1071 if (HERE(URN) && game.prop[URN] == URN_EMPTY)
1072 return fill(verb, URN);
1073 game.prop[BOTTLE] = EMPTY_BOTTLE;
1074 game.place[obj] = LOC_NOWHERE;
1082 /* cycle through the three plant states */
1083 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1084 game.prop[PLANT2] = game.prop[PLANT];
1087 rspeak(SHAKING_LEAVES);
1091 state_change(DOOR, (obj == OIL) ?
1098 static phase_codes_t quit(void)
1099 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1101 if (yes_or_no(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1102 terminate(quitgame);
1106 static phase_codes_t read(command_t command)
1107 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1109 if (command.obj == INTRANSITIVE) {
1110 command.obj = NO_OBJECT;
1111 for (int i = 1; i <= NOBJECTS; i++) {
1112 if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
1113 command.obj = command.obj * NOBJECTS + i;
1115 if (command.obj > NOBJECTS ||
1116 command.obj == NO_OBJECT ||
1121 if (DARK(game.loc)) {
1122 sspeak(NO_SEE, command.word[0].raw);
1123 } else if (command.obj == OYSTER) {
1124 if (!TOTING(OYSTER) || !game.closed) {
1125 rspeak(DONT_UNDERSTAND);
1126 } else if (!game.clshnt) {
1127 game.clshnt = yes_or_no(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1129 pspeak(OYSTER, hear, true, 1); // Not really a sound, but oh well.
1131 } else if (objects[command.obj].texts[0] == NULL ||
1132 game.prop[command.obj] == STATE_NOTFOUND) {
1133 speak(actions[command.verb].message);
1135 pspeak(command.obj, study, true, game.prop[command.obj]);
1139 static phase_codes_t reservoir(void)
1140 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1142 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1143 rspeak(NOTHING_HAPPENS);
1147 game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1151 game.oldlc2 = game.loc;
1152 game.newloc = LOC_NOWHERE;
1154 return GO_TERMINATE;
1159 static phase_codes_t rub(verb_t verb, obj_t obj)
1160 /* Rub. Yields various snide remarks except for lit urn. */
1162 if (obj == URN && game.prop[URN] == URN_LIT) {
1164 drop(AMBER, game.loc);
1165 game.prop[AMBER] = AMBER_IN_ROCK;
1167 drop(CAVITY, game.loc);
1169 } else if (obj != LAMP) {
1170 rspeak(PECULIAR_NOTHING);
1172 speak(actions[verb].message);
1177 static phase_codes_t say(command_t command)
1178 /* Say. Echo WD2. Magic words override. */
1180 if (command.word[1].type == MOTION &&
1181 (command.word[1].id == XYZZY ||
1182 command.word[1].id == PLUGH ||
1183 command.word[1].id == PLOVER)) {
1186 if (command.word[1].type == ACTION && command.word[1].id == PART)
1189 if (command.word[1].type == ACTION &&
1190 (command.word[1].id == FEE ||
1191 command.word[1].id == FIE ||
1192 command.word[1].id == FOE ||
1193 command.word[1].id == FOO ||
1194 command.word[1].id == FUM ||
1195 command.word[1].id == PART)) {
1196 return bigwords(command.word[1].id);
1198 sspeak(OKEY_DOKEY, command.word[1].raw);
1202 static phase_codes_t throw_support(vocab_t spk)
1205 drop(AXE, game.loc);
1209 static phase_codes_t throwit(command_t command)
1210 /* Throw. Same as discard unless axe. Then same as attack except
1211 * ignore bird, and if dwarf is present then one might be killed.
1212 * (Only way to do so!) Axe also special for dragon, bear, and
1213 * troll. Treasures special for troll. */
1215 if (!TOTING(command.obj)) {
1216 speak(actions[command.verb].message);
1219 if (objects[command.obj].is_treasure && AT(TROLL)) {
1220 /* Snarf a treasure for the troll. */
1221 drop(command.obj, LOC_NOWHERE);
1222 move(TROLL, LOC_NOWHERE);
1223 move(TROLL + NOBJECTS, IS_FREE);
1224 drop(TROLL2, objects[TROLL].plac);
1225 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1227 rspeak(TROLL_SATISFIED);
1230 if (command.obj == FOOD && HERE(BEAR)) {
1231 /* But throwing food is another story. */
1233 return (feed(command.verb, command.obj));
1235 if (command.obj != AXE)
1236 return (discard(command.verb, command.obj));
1238 if (atdwrf(game.loc) <= 0) {
1239 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS)
1240 return throw_support(DRAGON_SCALES);
1242 return throw_support(TROLL_RETURNS);
1244 return throw_support(OGRE_DODGE);
1245 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
1246 /* This'll teach him to throw the axe at the bear! */
1247 drop(AXE, game.loc);
1248 game.fixed[AXE] = IS_FIXED;
1250 state_change(AXE, AXE_LOST);
1253 command.obj = INTRANSITIVE;
1254 return (attack(command));
1257 if (randrange(NDWARVES + 1) < game.dflag) {
1258 return throw_support(DWARF_DODGES);
1260 int i = atdwrf(game.loc);
1261 game.dseen[i] = false;
1262 game.dloc[i] = LOC_NOWHERE;
1263 return throw_support((++game.dkill == 1) ?
1270 static phase_codes_t wake(verb_t verb, obj_t obj)
1271 /* Wake. Only use is to disturb the dwarves. */
1275 speak(actions[verb].message);
1279 return GO_DWARFWAKE;
1283 static phase_codes_t seed(verb_t verb, const char *arg)
1286 int32_t seed = strtol(arg, NULL, 10);
1287 speak(actions[verb].message, seed);
1293 static phase_codes_t waste(verb_t verb, turn_t turns)
1296 game.limit -= turns;
1297 speak(actions[verb].message, (int)game.limit);
1301 static phase_codes_t wave(verb_t verb, obj_t obj)
1302 /* Wave. No effect unless waving rod at fissure or at bird. */
1309 speak(((!TOTING(obj)) && (obj != ROD ||
1311 arbitrary_messages[ARENT_CARRYING] :
1312 actions[verb].message);
1316 if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1317 drop(JADE, game.loc);
1318 game.prop[JADE] = STATE_FOUND;
1320 rspeak(NECKLACE_FLY);
1324 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1327 return GO_DWARFWAKE;
1331 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1337 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1341 state_change(FISSURE,
1342 game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED);
1347 phase_codes_t action(command_t command)
1348 /* Analyse a verb. Remember what it was, go back for object if second word
1349 * unless verb is "say", which snarfs arbitrary second word.
1352 /* Previously, actions that result in a message, but don't do anything
1353 * further were called "specials". Now they're handled here as normal
1354 * actions. If noaction is true, then we spit out the message and return */
1355 if (actions[command.verb].noaction) {
1356 speak(actions[command.verb].message);
1360 if (command.part == unknown) {
1361 /* Analyse an object word. See if the thing is here, whether
1362 * we've got a verb yet, and so on. Object must be here
1363 * unless verb is "find" or "invent(ory)" (and no new verb
1364 * yet to be analysed). Water and oil are also funny, since
1365 * they are never actually dropped at any location, but might
1366 * be here inside the bottle or urn or as a feature of the
1368 if (HERE(command.obj))
1370 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1372 else if (!game.closed && ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1373 command.obj == LIQLOC(game.loc)))
1375 else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
1378 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) {
1379 command.obj = PLANT2;
1381 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1383 rspeak(KNIVES_VANISH);
1385 } else if (command.obj == ROD && HERE(ROD2)) {
1388 } else if ((command.verb == FIND ||
1389 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1392 sspeak(NO_SEE, command.word[0].raw);
1396 if (command.verb != 0)
1397 command.part = transitive;
1400 switch (command.part) {
1402 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1404 if (command.verb == SAY)
1405 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1406 * will do here. We're preventing interpretation as an intransitive
1407 * verb when the word is unknown. */
1408 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1409 if (command.obj == NO_OBJECT ||
1410 command.obj == INTRANSITIVE) {
1411 /* Analyse an intransitive verb (ie, no object given yet). */
1412 switch (command.verb) {
1414 return vcarry(command.verb, INTRANSITIVE);
1420 return lock(command.verb, INTRANSITIVE);
1423 return (GO_CLEAROBJ);
1426 return lock(command.verb, INTRANSITIVE);
1428 return light(command.verb, INTRANSITIVE);
1430 return extinguish(command.verb, INTRANSITIVE);
1436 speak(actions[command.verb].message);
1440 command.obj = INTRANSITIVE;
1441 return attack(command);
1443 return pour(command.verb, INTRANSITIVE);
1445 return eat(command.verb, INTRANSITIVE);
1447 return drink(command.verb, INTRANSITIVE);
1461 return fill(command.verb, INTRANSITIVE);
1473 return bigwords(command.word[0].id);
1477 command.obj = INTRANSITIVE;
1478 return read(command);
1488 return fly(command.verb, INTRANSITIVE);
1495 rspeak(NUMERIC_REQUIRED);
1497 default: // LCOV_EXCL_LINE
1498 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1503 /* Analyse a transitive verb. */
1504 switch (command.verb) {
1506 return vcarry(command.verb, command.obj);
1508 return discard(command.verb, command.obj);
1510 return say(command);
1512 return lock(command.verb, command.obj);
1515 return (GO_CLEAROBJ);
1518 return lock(command.verb, command.obj);
1520 return light(command.verb, command.obj);
1522 return extinguish(command.verb, command.obj);
1524 return wave(command.verb, command.obj);
1526 speak(actions[command.verb].message);
1530 speak(actions[command.verb].message);
1534 return attack(command);
1536 return pour(command.verb, command.obj);
1538 return eat(command.verb, command.obj);
1540 return drink(command.verb, command.obj);
1542 return rub(command.verb, command.obj);
1544 return throwit(command);
1546 speak(actions[command.verb].message);
1550 return find(command.verb, command.obj);
1552 return find(command.verb, command.obj);
1554 return feed(command.verb, command.obj);
1556 return fill(command.verb, command.obj);
1561 speak(actions[command.verb].message);
1569 speak(actions[command.verb].message);
1573 speak(actions[command.verb].message);
1577 return read(command);
1579 return vbreak(command.verb, command.obj);
1581 return wake(command.verb, command.obj);
1583 speak(actions[command.verb].message);
1587 speak(actions[command.verb].message);
1591 return fly(command.verb, command.obj);
1593 speak(actions[command.verb].message);
1597 // This case should never happen - here only as placeholder
1602 return seed(command.verb, command.word[1].raw);
1604 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1605 default: // LCOV_EXCL_LINE
1606 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1609 /* Unknown verb, couldn't deduce object - might need hint */
1610 sspeak(WHAT_DO, command.word[0].raw);
1611 return GO_CHECKHINT;
1612 default: // LCOV_EXCL_LINE
1613 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE