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 int fill(verb_t, obj_t);
18 static int 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);
91 switch (game.prop[BEAR]) {
96 rspeak(BEAR_CONFUSED);
99 rspeak(BEAR_CONFUSED);
102 rspeak(ALREADY_DEAD);
107 if (obj == DRAGON && game.prop[DRAGON] == 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);
114 speak(arbitrary_messages[NASTY_DRAGON]);
117 state_change(DRAGON, DRAGON_DEAD);
118 game.prop[RUG] = RUG_FLOOR;
119 /* Hardcoding LOC_SECRET5 as the dragon's death location is ugly.
120 * The way it was computed before was worse; it depended on the
121 * two dragon locations being LOC_SECRET4 and LOC_SECRET6 and
122 * 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.place[i] == objects[DRAGON].plac ||
131 game.place[i] == 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.dloc[i] == game.loc) {
149 game.dloc[i] = LOC_LONGWEST;
150 game.dseen[i] = false;
153 rspeak((dwarves > 1) ?
165 rspeak(SHELL_IMPERVIOUS);
168 rspeak(SNAKE_WARNING);
174 rspeak(BARE_HANDS_QUERY);
177 rspeak(ALREADY_DEAD);
183 speak(actions[verb].message);
188 static int bigwords(vocab_t id)
189 /* FEE FIE FOE FOO (AND FUM). Advance to next state if given in proper order.
190 * Look up foo in special section of vocab to determine which word we've got.
191 * Last word zips the eggs back to the giant room (unless already there). */
193 if ((game.foobar == WORD_EMPTY && id == FEE) ||
194 (game.foobar == FEE && id == FIE) ||
195 (game.foobar == FIE && id == FOE) ||
196 (game.foobar == FOE && id == FOO) ||
197 (game.foobar == FOE && id == FUM)) {
199 if ((id != FOO) && (id != FUM)) {
203 game.foobar = WORD_EMPTY;
204 if (game.place[EGGS] == objects[EGGS].plac ||
205 (TOTING(EGGS) && game.loc == objects[EGGS].plac)) {
206 rspeak(NOTHING_HAPPENS);
209 /* Bring back troll if we steal the eggs back from him before
211 if (game.place[EGGS] == LOC_NOWHERE && game.place[TROLL] == LOC_NOWHERE && game.prop[TROLL] == TROLL_UNPAID)
212 game.prop[TROLL] = TROLL_PAIDONCE;
214 pspeak(EGGS, look, EGGS_VANISHED, true);
215 else if (game.loc == objects[EGGS].plac)
216 pspeak(EGGS, look, EGGS_HERE, true);
218 pspeak(EGGS, look, EGGS_DONE, true);
219 move(EGGS, objects[EGGS].plac);
224 if (game.loc == LOC_GIANTROOM) {
227 /* This is new begavior in Open Adventure - sounds better when
228 * player isn't in the Giant Room. */
229 rspeak(WELL_POINTLESS);
231 game.foobar = WORD_EMPTY;
236 static void blast(void)
237 /* Blast. No effect unless you've got dynamite, which is a neat trick! */
239 if (game.prop[ROD2] == STATE_NOTFOUND ||
241 rspeak(REQUIRES_DYNAMITE);
244 game.bonus = splatter;
245 rspeak(SPLATTER_MESSAGE);
246 } else if (game.loc == LOC_NE) {
248 rspeak(DEFEAT_MESSAGE);
250 game.bonus = victory;
251 rspeak(VICTORY_MESSAGE);
257 static int vbreak(verb_t verb, obj_t obj)
258 /* Break. Only works for mirror in repository and, of course, the vase. */
263 state_change(MIRROR, MIRROR_BROKEN);
270 if (game.prop[VASE] == VASE_WHOLE) {
272 drop(VASE, game.loc);
273 state_change(VASE, VASE_BROKEN);
274 game.fixed[VASE] = IS_FIXED;
279 speak(actions[verb].message);
281 return (GO_CLEAROBJ);
284 static int brief(void)
285 /* Brief. Intransitive only. Suppress full descriptions after first time. */
289 rspeak(BRIEF_CONFIRM);
293 static int vcarry(verb_t verb, obj_t obj)
294 /* Carry an object. Special cases for bird and cage (if bird in cage, can't
295 * take one without the other). Liquids also special, since they depend on
296 * status of bottle. Also various side effects, etc. */
298 if (obj == INTRANSITIVE) {
299 /* Carry, no object given yet. OK if only one object present. */
300 if (game.atloc[game.loc] == NO_OBJECT ||
301 game.link[game.atloc[game.loc]] != 0 ||
302 atdwrf(game.loc) > 0)
304 obj = game.atloc[game.loc];
308 speak(actions[verb].message);
313 rspeak(REMOVE_MESSAGE);
318 if (game.fixed[obj] != IS_FREE) {
321 /* Next guard tests whether plant is tiny or stashed */
322 rspeak(game.prop[PLANT] <= PLANT_THIRSTY ? DEEP_ROOTS : YOU_JOKING);
325 rspeak( game.prop[BEAR] == SITTING_BEAR ? BEAR_CHAINED : YOU_JOKING);
328 rspeak( game.prop[BEAR] != UNTAMED_BEAR ? STILL_LOCKED : YOU_JOKING);
331 rspeak(game.prop[RUG] == RUG_HOVER ? RUG_HOVERS : YOU_JOKING);
337 rspeak(DOUGHNUT_HOLES);
343 rspeak(HAND_PASSTHROUGH);
355 if (!TOTING(BOTTLE)) {
356 rspeak(NO_CONTAINER);
359 if (game.prop[BOTTLE] == EMPTY_BOTTLE) {
360 return (fill(verb, BOTTLE));
368 if (game.holdng >= INVLIMIT) {
374 if (obj == BIRD && game.prop[BIRD] != BIRD_CAGED && STASHED(BIRD) != BIRD_CAGED) {
375 if (game.prop[BIRD] == BIRD_FOREST_UNCAGED) {
381 rspeak(CANNOT_CARRY);
388 game.prop[BIRD] = BIRD_CAGED;
392 (game.prop[BIRD] == BIRD_CAGED || STASHED(BIRD) == BIRD_CAGED)) {
393 /* expression maps BIRD to CAGE and CAGE to BIRD */
394 carry(BIRD + CAGE - obj, game.loc);
397 carry(obj, game.loc);
399 if (obj == BOTTLE && LIQUID() != NO_OBJECT)
400 game.place[LIQUID()] = CARRIED;
402 if (GSTONE(obj) && game.prop[obj] != STATE_FOUND) {
403 game.prop[obj] = STATE_FOUND;
404 game.prop[CAVITY] = CAVITY_EMPTY;
410 static int chain(verb_t verb)
411 /* Do something to the bear's chain */
414 if (game.prop[BEAR] == UNTAMED_BEAR) {
418 if (game.prop[CHAIN] == CHAIN_HEAP) {
419 rspeak(ALREADY_UNLOCKED);
422 game.prop[CHAIN] = CHAIN_HEAP;
423 game.fixed[CHAIN] = IS_FREE;
424 if (game.prop[BEAR] != BEAR_DEAD)
425 game.prop[BEAR] = CONTENTED_BEAR;
427 switch (game.prop[BEAR]) {
430 /* Can't be reached until the bear can die in some way other
431 * than a bridge collapse. Leave in in case this changes, but
432 * exclude from coverage testing. */
433 game.fixed[BEAR] = IS_FIXED;
437 game.fixed[BEAR] = IS_FREE;
439 rspeak(CHAIN_UNLOCKED);
443 if (game.prop[CHAIN] != CHAIN_HEAP) {
444 rspeak(ALREADY_LOCKED);
447 if (game.loc != objects[CHAIN].plac) {
452 game.prop[CHAIN] = CHAIN_FIXED;
455 drop(CHAIN, game.loc);
456 game.fixed[CHAIN] = IS_FIXED;
458 rspeak(CHAIN_LOCKED);
462 static int discard(verb_t verb, obj_t obj)
463 /* Discard object. "Throw" also comes here for most objects. Special cases for
464 * bird (might attack snake or dragon) and cage (might contain bird) and vase.
465 * Drop coins at vending machine for extra batteries. */
467 if (obj == ROD && !TOTING(ROD) && TOTING(ROD2)) {
472 speak(actions[verb].message);
476 if (GSTONE(obj) && AT(CAVITY) && game.prop[CAVITY] != CAVITY_FULL) {
478 game.prop[obj] = STATE_IN_CAVITY;
479 game.prop[CAVITY] = CAVITY_FULL;
480 if (HERE(RUG) && ((obj == EMERALD && game.prop[RUG] != RUG_HOVER) ||
481 (obj == RUBY && game.prop[RUG] == RUG_HOVER))) {
484 else if (TOTING(RUG))
488 if (!TOTING(RUG) || obj == RUBY) {
489 int k = (game.prop[RUG] == RUG_HOVER) ? RUG_FLOOR : RUG_HOVER;
492 k = objects[SAPPH].plac;
493 move(RUG + NOBJECTS, k);
500 if (obj == COINS && HERE(VEND)) {
502 drop(BATTERY, game.loc);
503 pspeak(BATTERY, look, FRESH_BATTERIES, true);
509 if (obj == BOTTLE && LIQUID() != NO_OBJECT) {
510 game.place[LIQUID()] = LOC_NOWHERE;
513 if (obj == BEAR && AT(TROLL)) {
514 state_change(TROLL, TROLL_GONE);
515 move(TROLL, LOC_NOWHERE);
516 move(TROLL + NOBJECTS, IS_FREE);
517 move(TROLL2, objects[TROLL].plac);
518 move(TROLL2 + NOBJECTS, objects[TROLL].fixd);
525 if (game.loc != objects[PILLOW].plac) {
526 state_change(VASE, AT(PILLOW)
529 if (game.prop[VASE] != VASE_WHOLE)
530 game.fixed[VASE] = IS_FIXED;
536 if (obj == CAGE && game.prop[BIRD] == BIRD_CAGED) {
537 drop(BIRD, game.loc);
541 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS) {
547 rspeak(BIRD_ATTACKS);
551 /* Set game.prop for use by travel options */
552 game.prop[SNAKE] = SNAKE_CHASED;
556 game.prop[BIRD] = FOREST(game.loc) ? BIRD_FOREST_UNCAGED : BIRD_UNCAGED;
566 static int drink(verb_t verb, obj_t obj)
567 /* Drink. If no object, assume water and look for it here. If water is in
568 * the bottle, drink that, else must be at a water loc, so drink stream. */
570 if (obj == INTRANSITIVE && LIQLOC(game.loc) != WATER &&
571 (LIQUID() != WATER || !HERE(BOTTLE))) {
577 state_change(DRAGON, DRAGON_BLOODLESS);
582 if (obj != INTRANSITIVE && obj != WATER) {
583 rspeak(RIDICULOUS_ATTEMPT);
586 if (LIQUID() == WATER && HERE(BOTTLE)) {
587 game.place[WATER] = LOC_NOWHERE;
588 state_change(BOTTLE, EMPTY_BOTTLE);
592 speak(actions[verb].message);
596 static int eat(verb_t verb, obj_t obj)
597 /* Eat. Intransitive: assume food if present, else ask what. Transitive: food
598 * ok, some things lose appetite, rest are ridiculous. */
607 rspeak(THANKS_DELICIOUS);
618 rspeak(LOST_APPETITE);
621 speak(actions[verb].message);
626 static int extinguish(verb_t verb, obj_t obj)
627 /* Extinguish. Lamp, urn, dragon/volcano (nice try). */
629 if (obj == INTRANSITIVE) {
630 if (HERE(LAMP) && game.prop[LAMP] == LAMP_BRIGHT)
632 if (HERE(URN) && game.prop[URN] == URN_LIT)
634 if (obj == INTRANSITIVE)
640 if (game.prop[URN] != URN_EMPTY) {
641 state_change(URN, URN_DARK);
643 pspeak(URN, change, URN_DARK, true);
647 state_change(LAMP, LAMP_DARK);
648 rspeak(DARK(game.loc) ?
654 rspeak(BEYOND_POWER);
657 speak(actions[verb].message);
662 static int feed(verb_t verb, obj_t obj)
663 /* Feed. If bird, no seed. Snake, dragon, troll: quip. If dwarf, make him
664 * mad. Bear, special. */
671 if (game.prop[DRAGON] != DRAGON_BARS)
672 rspeak(RIDICULOUS_ATTEMPT);
674 rspeak(NOTHING_EDIBLE);
677 if (!game.closed && HERE(BIRD)) {
679 rspeak(BIRD_DEVOURED);
681 rspeak(NOTHING_EDIBLE);
691 speak(actions[verb].message);
694 if (game.prop[BEAR] == BEAR_DEAD) {
695 rspeak(RIDICULOUS_ATTEMPT);
698 if (game.prop[BEAR] == UNTAMED_BEAR) {
701 game.fixed[AXE] = IS_FREE;
702 game.prop[AXE] = AXE_HERE;
703 state_change(BEAR, SITTING_BEAR);
705 rspeak(NOTHING_EDIBLE);
708 speak(actions[verb].message);
714 speak(actions[verb].message);
722 int fill(verb_t verb, obj_t obj)
723 /* Fill. Bottle or urn must be empty, and liquid available. (Vase
727 if (LIQLOC(game.loc) == NO_OBJECT) {
728 rspeak(FILL_INVALID);
732 rspeak(ARENT_CARRYING);
735 rspeak(SHATTER_VASE);
736 game.prop[VASE] = VASE_BROKEN;
737 game.fixed[VASE] = IS_FIXED;
738 drop(VASE, game.loc);
743 if (game.prop[URN] != URN_EMPTY) {
748 rspeak(FILL_INVALID);
754 game.prop[BOTTLE] = EMPTY_BOTTLE;
758 game.prop[URN] = URN_DARK;
759 game.prop[BOTTLE] = EMPTY_BOTTLE;
764 rspeak(FILL_INVALID);
767 game.place[k] = LOC_NOWHERE;
770 if (obj != INTRANSITIVE && obj != BOTTLE) {
771 speak(actions[verb].message);
774 if (obj == INTRANSITIVE && !HERE(BOTTLE))
777 if (HERE(URN) && game.prop[URN] != URN_EMPTY) {
781 if (LIQUID() != NO_OBJECT) {
785 if (LIQLOC(game.loc) == NO_OBJECT) {
790 state_change(BOTTLE, (LIQLOC(game.loc) == OIL)
794 game.place[LIQUID()] = CARRIED;
798 static int find(verb_t verb, obj_t obj)
799 /* Find. Might be carrying it, or it might be here. Else give caveat. */
802 rspeak(ALREADY_CARRYING);
807 rspeak(NEEDED_NEARBY);
812 (LIQUID() == obj && AT(BOTTLE)) ||
813 obj == LIQLOC(game.loc) ||
814 (obj == DWARF && atdwrf(game.loc) > 0)) {
820 speak(actions[verb].message);
824 static int fly(verb_t verb, obj_t obj)
825 /* Fly. Snide remarks unless hovering rug is here. */
827 if (obj == INTRANSITIVE) {
832 if (game.prop[RUG] != RUG_HOVER) {
833 rspeak(RUG_NOTHING2);
840 speak(actions[verb].message);
843 if (game.prop[RUG] != RUG_HOVER) {
844 rspeak(RUG_NOTHING1);
847 game.oldlc2 = game.oldloc;
848 game.oldloc = game.loc;
850 if (game.prop[SAPPH] == STATE_NOTFOUND) {
851 game.newloc = game.place[SAPPH];
854 game.newloc = LOC_CLIFF;
860 static int inven(void)
861 /* Inventory. If object, treat same as find. Else report on current burden. */
864 for (obj_t i = 1; i <= NOBJECTS; i++) {
872 pspeak(i, touch, -1, false);
881 static int light(verb_t verb, obj_t obj)
882 /* Light. Applicable only to lamp and urn. */
884 if (obj == INTRANSITIVE) {
886 if (HERE(LAMP) && game.prop[LAMP] == LAMP_DARK && game.limit >= 0) {
890 if (HERE(URN) && game.prop[URN] == URN_DARK) {
900 state_change(URN, game.prop[URN] == URN_EMPTY ?
905 if (game.limit < 0) {
909 state_change(LAMP, LAMP_BRIGHT);
914 speak(actions[verb].message);
919 static int listen(void)
920 /* Listen. Intransitive only. Print stuff based on object sound proprties. */
922 vocab_t sound = locations[game.loc].sound;
923 if (sound != SILENT) {
925 if (!locations[game.loc].loud)
929 for (obj_t i = 1; i <= NOBJECTS; i++) {
931 objects[i].sounds[0] == NULL ||
934 int mi = game.prop[i];
935 /* (ESR) Some unpleasant magic on object states here. Ideally
936 * we'd have liked the bird to be a normal object that we can
937 * use state_change() on; can't do it, because there are
938 * actually two different series of per-state birdsounds
939 * depending on whether player has drunk dragon's blood. */
941 mi += 3 * game.blooded;
942 pspeak(i, hear, mi, true, game.zzword);
944 if (i == BIRD && mi == BIRD_ENDSTATE)
952 static int lock(verb_t verb, obj_t obj)
953 /* Lock, unlock, no object given. Assume various things if present. */
955 if (obj == INTRANSITIVE) {
966 if (obj == INTRANSITIVE) {
967 rspeak(NOTHING_LOCKED);
972 /* Lock, unlock object. Special stuff for opening clam/oyster
987 game.clock2 = PANICTIME;
990 state_change(GRATE, (verb == LOCK) ?
1000 else if (!TOTING(TRIDENT))
1001 rspeak(CLAM_OPENER);
1004 drop(OYSTER, game.loc);
1005 drop(PEARL, LOC_CULDESAC);
1006 rspeak(PEARL_FALLS);
1012 else if (TOTING(OYSTER))
1013 rspeak(DROP_OYSTER);
1014 else if (!TOTING(TRIDENT))
1015 rspeak(OYSTER_OPENER);
1017 rspeak(OYSTER_OPENS);
1020 rspeak((game.prop[DOOR] == DOOR_UNRUSTED) ? OK_MAN : RUSTY_DOOR);
1026 rspeak(CANNOT_UNLOCK);
1029 speak(actions[verb].message);
1035 static int pour(verb_t verb, obj_t obj)
1036 /* Pour. If no object, or object is bottle, assume contents of bottle.
1037 * special tests for pouring water or oil on plant or rusty door. */
1039 if (obj == BOTTLE ||
1040 obj == INTRANSITIVE)
1042 if (obj == NO_OBJECT)
1045 speak(actions[verb].message);
1049 if (obj != OIL && obj != WATER) {
1053 if (HERE(URN) && game.prop[URN] == URN_EMPTY)
1054 return fill(verb, URN);
1055 game.prop[BOTTLE] = EMPTY_BOTTLE;
1056 game.place[obj] = LOC_NOWHERE;
1064 /* cycle through the three plant states */
1065 state_change(PLANT, MOD(game.prop[PLANT] + 1, 3));
1066 game.prop[PLANT2] = game.prop[PLANT];
1069 rspeak(SHAKING_LEAVES);
1073 state_change(DOOR, (obj == OIL) ?
1080 static int quit(void)
1081 /* Quit. Intransitive only. Verify intent and exit if that's what he wants. */
1083 if (yes(arbitrary_messages[REALLY_QUIT], arbitrary_messages[OK_MAN], arbitrary_messages[OK_MAN]))
1084 terminate(quitgame);
1088 static int read(command_t command)
1089 /* Read. Print stuff based on objtxt. Oyster (?) is special case. */
1091 if (command.obj == INTRANSITIVE) {
1092 command.obj = NO_OBJECT;
1093 for (int i = 1; i <= NOBJECTS; i++) {
1094 if (HERE(i) && objects[i].texts[0] != NULL && game.prop[i] >= 0)
1095 command.obj = command.obj * NOBJECTS + i;
1097 if (command.obj > NOBJECTS ||
1098 command.obj == NO_OBJECT ||
1103 if (DARK(game.loc)) {
1104 sspeak(NO_SEE, command.word[0].raw);
1105 } else if (command.obj == OYSTER && !game.clshnt && game.closed) {
1106 game.clshnt = yes(arbitrary_messages[CLUE_QUERY], arbitrary_messages[WAYOUT_CLUE], arbitrary_messages[OK_MAN]);
1107 } else if (objects[command.obj].texts[0] == NULL ||
1108 game.prop[command.obj] == STATE_NOTFOUND) {
1109 speak(actions[command.verb].message);
1111 pspeak(command.obj, study, game.prop[command.obj], true);
1115 static int reservoir(void)
1116 /* Z'ZZZ (word gets recomputed at startup; different each game). */
1118 if (!AT(RESER) && game.loc != LOC_RESBOTTOM) {
1119 rspeak(NOTHING_HAPPENS);
1123 game.prop[RESER] == WATERS_PARTED ? WATERS_UNPARTED : WATERS_PARTED);
1127 game.oldlc2 = game.loc;
1128 game.newloc = LOC_NOWHERE;
1130 return GO_TERMINATE;
1135 static int rub(verb_t verb, obj_t obj)
1136 /* Rub. Yields various snide remarks except for lit urn. */
1138 if (obj == URN && game.prop[URN] == URN_LIT) {
1140 drop(AMBER, game.loc);
1141 game.prop[AMBER] = AMBER_IN_ROCK;
1143 drop(CAVITY, game.loc);
1145 } else if (obj != LAMP) {
1146 rspeak(PECULIAR_NOTHING);
1148 speak(actions[verb].message);
1153 static int say(command_t command)
1154 /* Say. Echo WD2. Magic words override. */
1156 if (command.word[1].type == MOTION &&
1157 (command.word[1].id == XYZZY ||
1158 command.word[1].id == PLUGH ||
1159 command.word[1].id == PLOVER)) {
1162 if (command.word[1].type == ACTION && command.word[1].id == PART)
1165 if (command.word[1].type == ACTION &&
1166 (command.word[1].id == FEE ||
1167 command.word[1].id == FIE ||
1168 command.word[1].id == FOE ||
1169 command.word[1].id == FOO ||
1170 command.word[1].id == FUM ||
1171 command.word[1].id == PART)) {
1172 return bigwords(command.word[1].id);
1174 sspeak(OKEY_DOKEY, command.word[1].raw);
1178 static int throw_support(vocab_t spk)
1181 drop(AXE, game.loc);
1185 static int throw (command_t command)
1186 /* Throw. Same as discard unless axe. Then same as attack except
1187 * ignore bird, and if dwarf is present then one might be killed.
1188 * (Only way to do so!) Axe also special for dragon, bear, and
1189 * troll. Treasures special for troll. */
1191 if (!TOTING(command.obj)) {
1192 speak(actions[command.verb].message);
1195 if (objects[command.obj].is_treasure && AT(TROLL)) {
1196 /* Snarf a treasure for the troll. */
1197 drop(command.obj, LOC_NOWHERE);
1198 move(TROLL, LOC_NOWHERE);
1199 move(TROLL + NOBJECTS, IS_FREE);
1200 drop(TROLL2, objects[TROLL].plac);
1201 drop(TROLL2 + NOBJECTS, objects[TROLL].fixd);
1203 rspeak(TROLL_SATISFIED);
1206 if (command.obj == FOOD && HERE(BEAR)) {
1207 /* But throwing food is another story. */
1209 return (feed(command.verb, command.obj));
1211 if (command.obj != AXE)
1212 return (discard(command.verb, command.obj));
1214 if (atdwrf(game.loc) <= 0) {
1215 if (AT(DRAGON) && game.prop[DRAGON] == DRAGON_BARS)
1216 return throw_support(DRAGON_SCALES);
1218 return throw_support(TROLL_RETURNS);
1220 return throw_support(OGRE_DODGE);
1221 if (HERE(BEAR) && game.prop[BEAR] == UNTAMED_BEAR) {
1222 /* This'll teach him to throw the axe at the bear! */
1223 drop(AXE, game.loc);
1224 game.fixed[AXE] = IS_FIXED;
1226 state_change(AXE, AXE_LOST);
1229 command.obj = INTRANSITIVE;
1230 return (attack(command));
1233 if (randrange(NDWARVES + 1) < game.dflag) {
1234 return throw_support(DWARF_DODGES);
1236 int i = atdwrf(game.loc);
1237 game.dseen[i] = false;
1238 game.dloc[i] = LOC_NOWHERE;
1239 return throw_support((++game.dkill == 1) ?
1246 static int wake(verb_t verb, obj_t obj)
1247 /* Wake. Only use is to disturb the dwarves. */
1251 speak(actions[verb].message);
1255 return GO_DWARFWAKE;
1259 static int seed(verb_t verb, const char *arg)
1262 int32_t seed = strtol(arg, NULL, 10);
1263 speak(actions[verb].message, seed);
1269 static int waste(verb_t verb, turn_t turns)
1272 game.limit -= turns;
1273 speak(actions[verb].message, (int)game.limit);
1277 static int wave(verb_t verb, obj_t obj)
1278 /* Wave. No effect unless waving rod at fissure or at bird. */
1285 speak(((!TOTING(obj)) && (obj != ROD ||
1287 arbitrary_messages[ARENT_CARRYING] :
1288 actions[verb].message);
1292 if (game.prop[BIRD] == BIRD_UNCAGED && game.loc == game.place[STEPS] && game.prop[JADE] == STATE_NOTFOUND) {
1293 drop(JADE, game.loc);
1294 game.prop[JADE] = STATE_FOUND;
1296 rspeak(NECKLACE_FLY);
1300 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1303 return GO_DWARFWAKE;
1307 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1313 rspeak((game.prop[BIRD] == BIRD_CAGED) ?
1317 state_change(FISSURE,
1318 game.prop[FISSURE] == BRIDGED ? UNBRIDGED : BRIDGED);
1323 int action(command_t command)
1324 /* Analyse a verb. Remember what it was, go back for object if second word
1325 * unless verb is "say", which snarfs arbitrary second word.
1328 /* Previously, actions that result in a message, but don't do anything
1329 * further were called "specials". Now they're handled here as normal
1330 * actions. If noaction is true, then we spit out the message and return */
1331 if (actions[command.verb].noaction) {
1332 speak(actions[command.verb].message);
1336 if (command.part == unknown) {
1337 /* Analyse an object word. See if the thing is here, whether
1338 * we've got a verb yet, and so on. Object must be here
1339 * unless verb is "find" or "invent(ory)" (and no new verb
1340 * yet to be analysed). Water and oil are also funny, since
1341 * they are never actually dropped at any location, but might
1342 * be here inside the bottle or urn or as a feature of the
1344 if (HERE(command.obj))
1346 else if (command.obj == DWARF && atdwrf(game.loc) > 0)
1348 else if ((LIQUID() == command.obj && HERE(BOTTLE)) ||
1349 command.obj == LIQLOC(game.loc))
1351 else if (command.obj == OIL && HERE(URN) && game.prop[URN] != URN_EMPTY) {
1354 } else if (command.obj == PLANT && AT(PLANT2) && game.prop[PLANT2] != PLANT_THIRSTY) {
1355 command.obj = PLANT2;
1357 } else if (command.obj == KNIFE && game.knfloc == game.loc) {
1359 rspeak(KNIVES_VANISH);
1361 } else if (command.obj == ROD && HERE(ROD2)) {
1364 } else if ((command.verb == FIND ||
1365 command.verb == INVENTORY) && (command.word[1].id == WORD_EMPTY || command.word[1].id == WORD_NOT_FOUND))
1368 sspeak(NO_SEE, command.word[0].raw);
1372 if (command.verb != 0)
1373 command.part = transitive;
1376 switch (command.part) {
1378 if (command.word[1].raw[0] != '\0' && command.verb != SAY)
1380 if (command.verb == SAY)
1381 /* KEYS is not special, anything not NO_OBJECT or INTRANSITIVE
1382 * will do here. We're preventing interpretation as an intransitive
1383 * verb when the word is unknown. */
1384 command.obj = command.word[1].raw[0] != '\0' ? KEYS : NO_OBJECT;
1385 if (command.obj == NO_OBJECT ||
1386 command.obj == INTRANSITIVE) {
1387 /* Analyse an intransitive verb (ie, no object given yet). */
1388 switch (command.verb) {
1390 return vcarry(command.verb, INTRANSITIVE);
1396 return lock(command.verb, INTRANSITIVE);
1399 return (GO_CLEAROBJ);
1402 return lock(command.verb, INTRANSITIVE);
1404 return light(command.verb, INTRANSITIVE);
1406 return extinguish(command.verb, INTRANSITIVE);
1412 speak(actions[command.verb].message);
1416 command.obj = INTRANSITIVE;
1417 return attack(command);
1419 return pour(command.verb, INTRANSITIVE);
1421 return eat(command.verb, INTRANSITIVE);
1423 return drink(command.verb, INTRANSITIVE);
1437 return fill(command.verb, INTRANSITIVE);
1449 return bigwords(command.word[0].id);
1453 command.obj = INTRANSITIVE;
1454 return read(command);
1464 return fly(command.verb, INTRANSITIVE);
1471 rspeak(NUMERIC_REQUIRED);
1473 default: // LCOV_EXCL_LINE
1474 BUG(INTRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1479 /* Analyse a transitive verb. */
1480 switch (command.verb) {
1482 return vcarry(command.verb, command.obj);
1484 return discard(command.verb, command.obj);
1486 return say(command);
1488 return lock(command.verb, command.obj);
1491 return (GO_CLEAROBJ);
1494 return lock(command.verb, command.obj);
1496 return light(command.verb, command.obj);
1498 return extinguish(command.verb, command.obj);
1500 return wave(command.verb, command.obj);
1502 speak(actions[command.verb].message);
1506 speak(actions[command.verb].message);
1510 return attack(command);
1512 return pour(command.verb, command.obj);
1514 return eat(command.verb, command.obj);
1516 return drink(command.verb, command.obj);
1518 return rub(command.verb, command.obj);
1520 return throw (command);
1522 speak(actions[command.verb].message);
1526 return find(command.verb, command.obj);
1528 return find(command.verb, command.obj);
1530 return feed(command.verb, command.obj);
1532 return fill(command.verb, command.obj);
1537 speak(actions[command.verb].message);
1545 speak(actions[command.verb].message);
1549 speak(actions[command.verb].message);
1553 return read(command);
1555 return vbreak(command.verb, command.obj);
1557 return wake(command.verb, command.obj);
1559 speak(actions[command.verb].message);
1563 speak(actions[command.verb].message);
1567 return fly(command.verb, command.obj);
1569 speak(actions[command.verb].message);
1573 // This case should never happen - here only as placeholder
1578 return seed(command.verb, command.word[1].raw);
1580 return waste(command.verb, (turn_t)atol(command.word[1].raw));
1581 default: // LCOV_EXCL_LINE
1582 BUG(TRANSITIVE_ACTION_VERB_EXCEEDS_GOTO_LIST); // LCOV_EXCL_LINE
1585 /* Unknown verb, couldn't deduce object - might need hint */
1586 sspeak(WHAT_DO, command.word[0].raw);
1587 return GO_CHECKHINT;
1588 default: // LCOV_EXCL_LINE
1589 BUG(SPEECHPART_NOT_TRANSITIVE_OR_INTRANSITIVE_OR_UNKNOWN); // LCOV_EXCL_LINE