2 * Actions for the duneon-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);
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 /* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order.
191 * Look up foo in special section of vocab to determine which word we've got.
192 * Last word zips the eggs back to the giant room (unless already there). */
194 if ((game.foobar == WORD_EMPTY && id == FEE) ||
195 (game.foobar == FEE && id == FIE) ||
196 (game.foobar == FIE && id == FOE) ||
197 (game.foobar == FOE && id == FOO) ||
198 (game.foobar == FOE && id == FUM)) {
200 if ((id != FOO) && (id != FUM)) {
204 game.foobar = WORD_EMPTY;
205 if (game.place[EGGS] == objects[EGGS].plac ||
206 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
207 rspeak(NOTHING_HAPPENS);
209 } else if (id == FUM) {
212 /* Bring back troll if we steal the eggs back from him before
214 if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
215 game.prop[TROLL] = TROLL_PAIDONCE;
217 pspeak(EGGS, look, true, EGGS_VANISHED);
218 else if (game.loc == objects[EGGS].plac)
219 pspeak(EGGS, look, true, EGGS_HERE);
221 pspeak(EGGS, look, true, EGGS_DONE);
222 move(EGGS, objects[EGGS].plac);
228 if (game.loc == LOC_GIANTROOM) {
231 /* This is new begavior in Open Adventure - sounds better when
232 * player isn't in the Giant Room. */
233 rspeak(WELL_POINTLESS);
235 game.foobar = WORD_EMPTY;
240 static void blast(void)
241 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
243 if (game.prop[ROD2] == STATE_NOTFOUND ||
245 rspeak(REQUIRES_DYNAMITE);
248 game.bonus = splatter;
249 rspeak(SPLATTER_MESSAGE);
250 } else if (game.loc == LOC_NE) {
252 rspeak(DEFEAT_MESSAGE);
254 game.bonus = victory;
255 rspeak(VICTORY_MESSAGE);
261 static phase_codes_t vbreak(verb_t verb, obj_t obj)
262 /* Break. Only works for mirror in repository and, of course, the vase. */
267 state_change(MIRROR, MIRROR_BROKEN);
274 if (game.prop[VASE] == VASE_WHOLE) {
276 drop(VASE, game.loc);
277 state_change(VASE, VASE_BROKEN);
278 game.fixed[VASE] = 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. */
293 rspeak(BRIEF_CONFIRM);
297 static phase_codes_t vcarry(verb_t verb, obj_t obj)
298 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
299 * take one without the other). Liquids also special, since they depend on
300 * status of bottle. Also various side effects, etc. */
302 if (obj == INTRANSITIVE) {
303 /* Carry, no object given yet. OK if only one object present. */
304 if (game.atloc[game.loc] == NO_OBJECT ||
305 game.link[game.atloc[game.loc]] != 0 ||
306 atdwrf(game.loc) > 0)
308 obj = game.atloc[game.loc];
312 speak(actions[verb].message);
317 rspeak(REMOVE_MESSAGE);
322 if (game.fixed[obj] != IS_FREE) {
325 /* Next guard tests whether plant is tiny or stashed */
326 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
329 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
332 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
335 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
341 rspeak(DOUGHNUT_HOLES);
347 rspeak(HAND_PASSTHROUGH);
359 if (!TOTING(BOTTLE)) {
360 rspeak(NO_CONTAINER);
363 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
364 return (fill(verb, BOTTLE));
372 if (game.holdng >= INVLIMIT) {
378 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
379 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
385 rspeak(CANNOT_CARRY);
392 game.prop[BIRD] = BIRD_CAGED;
396 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
397 /* expression maps BIRD to CAGE and CAGE to BIRD */
398 carry(BIRD + CAGE - obj, game.loc);
401 carry(obj, game.loc);
403 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
404 game.place[LIQUID()] = CARRIED;
406 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
407 game.prop[obj] = STATE_FOUND;
408 game.prop[CAVITY] = CAVITY_EMPTY;
414 static int chain(verb_t verb)
415 /* Do something to the bear's chain */
418 if (game.prop[BEAR] == UNTAMED_BEAR) {
422 if (game.prop[CHAIN] == CHAIN_HEAP) {
423 rspeak(ALREADY_UNLOCKED);
426 game.prop[CHAIN] = CHAIN_HEAP;
427 game.fixed[CHAIN] = IS_FREE;
428 if (game.prop[BEAR] != BEAR_DEAD)
429 game.prop[BEAR] = CONTENTED_BEAR;
431 switch (game.prop[BEAR]) {
434 /* Can't be reached until the bear can die in some way other
435 * than a bridge collapse. Leave in in case this changes, but
436 * exclude from coverage testing. */
437 game.fixed[BEAR] = IS_FIXED;
441 game.fixed[BEAR] = IS_FREE;
443 rspeak(CHAIN_UNLOCKED);
447 if (game.prop[CHAIN] != CHAIN_HEAP) {
448 rspeak(ALREADY_LOCKED);
451 if (game.loc != objects[CHAIN].plac) {
456 game.prop[CHAIN] = CHAIN_FIXED;
459 drop(CHAIN, game.loc);
460 game.fixed[CHAIN] = IS_FIXED;
462 rspeak(CHAIN_LOCKED);
466 static phase_codes_t discard(verb_t verb, obj_t obj)
467 /* Discard object. "Throw" also comes here for most objects. Special cases for
468 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
469 * Drop coins at vending machine for extra batteries. */
471 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
476 speak(actions[verb].message);
480 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
482 game.prop[obj] = STATE_IN_CAVITY;
483 game.prop[CAVITY] = CAVITY_FULL;
484 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
485 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
488 else if (TOTING(RUG))
492 if (!TOTING(RUG) || obj == RUBY) {
493 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
496 k = objects[SAPPH].plac;
497 move(RUG + NOBJECTS, k);
504 if (obj == COINS && HERE(VEND)) {
506 drop(BATTERY, game.loc);
507 pspeak(BATTERY, look, true, FRESH_BATTERIES);
513 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
514 game.place[LIQUID()] = LOC_NOWHERE;
517 if (obj == BEAR && AT(TROLL)) {
518 state_change(TROLL, TROLL_GONE);
519 move(TROLL, LOC_NOWHERE);
520 move(TROLL + NOBJECTS, IS_FREE);
521 move(TROLL2, objects[TROLL].plac);
522 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
529 if (game.loc != objects[PILLOW].plac) {
530 state_change(VASE, AT(PILLOW)
533 if (game.prop[VASE] != VASE_WHOLE)
534 game.fixed[VASE] = IS_FIXED;
540 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
541 drop(BIRD, game.loc);
545 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
551 rspeak(BIRD_ATTACKS);
555 /* Set game.prop for use by travel options */
556 game.prop[SNAKE] = SNAKE_CHASED;
560 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
570 static phase_codes_t drink(verb_t verb, obj_t obj)
571 /* Drink. If no object, assume water and look for it here. If water is in
572 * the bottle, drink that, else must be at a water loc, so drink stream. */
574 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
575 (LIQUID() != WATER || !HERE(BOTTLE))) {
581 state_change(DRAGON, DRAGON_BLOODLESS);
586 if (obj != INTRANSITIVE && obj != WATER) {
587 rspeak(RIDICULOUS_ATTEMPT);
590 if (LIQUID() == WATER && HERE(BOTTLE)) {
591 game.place[WATER] = LOC_NOWHERE;
592 state_change(BOTTLE, EMPTY_BOTTLE);
596 speak(actions[verb].message);
600 static phase_codes_t eat(verb_t verb, obj_t obj)
601 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
602 * 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). */
633 if (obj == INTRANSITIVE) {
634 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
636 if (HERE(URN) && game.prop[URN] == URN_LIT)
638 if (obj == INTRANSITIVE)
644 if (game.prop[URN] != URN_EMPTY) {
645 state_change(URN, URN_DARK);
647 pspeak(URN, change, true, URN_DARK);
651 state_change(LAMP, LAMP_DARK);
652 rspeak(DARK(game.loc) ?
658 rspeak(BEYOND_POWER);
661 speak(actions[verb].message);
666 static phase_codes_t feed(verb_t verb, obj_t obj)
667 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
668 * mad. Bear, special. */
675 if (game.prop[DRAGON] != DRAGON_BARS)
676 rspeak(RIDICULOUS_ATTEMPT);
678 rspeak(NOTHING_EDIBLE);
681 if (!game.closed && HERE(BIRD)) {
683 rspeak(BIRD_DEVOURED);
685 rspeak(NOTHING_EDIBLE);
695 speak(actions[verb].message);
698 if (game.prop[BEAR] == BEAR_DEAD) {
699 rspeak(RIDICULOUS_ATTEMPT);
702 if (game.prop[BEAR] == UNTAMED_BEAR) {
705 game.fixed[AXE] = IS_FREE;
706 game.prop[AXE] = AXE_HERE;
707 state_change(BEAR, SITTING_BEAR);
709 rspeak(NOTHING_EDIBLE);
712 speak(actions[verb].message);
718 speak(actions[verb].message);
726 phase_codes_t fill(verb_t verb, obj_t obj)
727 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
731 if (LIQLOC(game.loc) == NO_OBJECT) {
732 rspeak(FILL_INVALID);
736 rspeak(ARENT_CARRYING);
739 rspeak(SHATTER_VASE);
740 game.prop[VASE] = VASE_BROKEN;
741 game.fixed[VASE] = IS_FIXED;
742 drop(VASE, game.loc);
747 if (game.prop[URN] != URN_EMPTY) {
752 rspeak(FILL_INVALID);
758 game.prop[BOTTLE] = EMPTY_BOTTLE;
762 game.prop[URN] = URN_DARK;
763 game.prop[BOTTLE] = EMPTY_BOTTLE;
768 rspeak(FILL_INVALID);
771 game.place[k] = LOC_NOWHERE;
774 if (obj != INTRANSITIVE && obj != BOTTLE) {
775 speak(actions[verb].message);
778 if (obj == INTRANSITIVE && !HERE(BOTTLE))
781 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
785 if (LIQUID() != NO_OBJECT) {
789 if (LIQLOC(game.loc) == NO_OBJECT) {
794 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
798 game.place[LIQUID()] = CARRIED;
802 static phase_codes_t find(verb_t verb, obj_t obj)
803 /* Find. Might be carrying it, or it might be here. Else give caveat. */
806 rspeak(ALREADY_CARRYING);
811 rspeak(NEEDED_NEARBY);
816 (LIQUID() == obj && AT(BOTTLE)) ||
817 obj == LIQLOC(game.loc) ||
818 (obj == DWARF && atdwrf(game.loc) > 0)) {
824 speak(actions[verb].message);
828 static phase_codes_t fly(verb_t verb, obj_t obj)
829 /* Fly. Snide remarks unless hovering rug is here. */
831 if (obj == INTRANSITIVE) {
836 if (game.prop[RUG] != RUG_HOVER) {
837 rspeak(RUG_NOTHING2);
844 speak(actions[verb].message);
847 if (game.prop[RUG] != RUG_HOVER) {
848 rspeak(RUG_NOTHING1);
852 if (game.loc == LOC_CLIFF) {
853 game.oldlc2 = game.oldloc;
854 game.oldloc = game.loc;
855 game.newloc = LOC_LEDGE;
857 } else if (game.loc == LOC_LEDGE) {
858 game.oldlc2 = game.oldloc;
859 game.oldloc = game.loc;
860 game.newloc = LOC_CLIFF;
863 /* should never happen */
864 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 proprties. */
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(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(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1123 } else if (game.clshnt) {
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 throw (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 throw (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