xref: /openbsd/games/wump/wump.c (revision df930be7)
1 /*	$NetBSD: wump.c,v 1.4 1995/04/24 12:26:22 cgd Exp $	*/
2 
3 /*
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  * All rights reserved.
7  *
8  * This code is derived from software contributed to Berkeley by
9  * Dave Taylor, of Intuitive Systems.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the University of
22  *	California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  */
39 
40 #ifndef lint
41 static char copyright[] =
42 "@(#) Copyright (c) 1989, 1993\n\
43 	The Regents of the University of California.  All rights reserved.\n";
44 #endif /* not lint */
45 
46 #ifndef lint
47 #if 0
48 static char sccsid[] = "@(#)wump.c	8.1 (Berkeley) 5/31/93";
49 #else
50 static char rcsid[] = "$NetBSD: wump.c,v 1.4 1995/04/24 12:26:22 cgd Exp $";
51 #endif
52 #endif /* not lint */
53 
54 /*
55  * A very new version of the age old favorite Hunt-The-Wumpus game that has
56  * been a part of the BSD distribution of Unix for longer than us old folk
57  * would care to remember.
58  */
59 
60 #include <sys/types.h>
61 #include <sys/file.h>
62 #include <stdio.h>
63 #include <string.h>
64 #include "pathnames.h"
65 
66 /* some defines to spec out what our wumpus cave should look like */
67 
68 #define	MAX_ARROW_SHOT_DISTANCE	6		/* +1 for '0' stopper */
69 #define	MAX_LINKS_IN_ROOM	25		/* a complex cave */
70 
71 #define	MAX_ROOMS_IN_CAVE	250
72 #define	ROOMS_IN_CAVE		20
73 #define	MIN_ROOMS_IN_CAVE	10
74 
75 #define	LINKS_IN_ROOM		3
76 #define	NUMBER_OF_ARROWS	5
77 #define	PIT_COUNT		3
78 #define	BAT_COUNT		3
79 
80 #define	EASY			1		/* levels of play */
81 #define	HARD			2
82 
83 /* some macro definitions for cleaner output */
84 
85 #define	plural(n)	(n == 1 ? "" : "s")
86 
87 /* simple cave data structure; +1 so we can index from '1' not '0' */
88 struct room_record {
89 	int tunnel[MAX_LINKS_IN_ROOM];
90 	int has_a_pit, has_a_bat;
91 } cave[MAX_ROOMS_IN_CAVE+1];
92 
93 /*
94  * global variables so we can keep track of where the player is, how
95  * many arrows they still have, where el wumpo is, and so on...
96  */
97 int player_loc = -1;			/* player location */
98 int wumpus_loc = -1;			/* The Bad Guy location */
99 int level = EASY;			/* level of play */
100 int arrows_left;			/* arrows unshot */
101 
102 #ifdef DEBUG
103 int debug = 0;
104 #endif
105 
106 int pit_num = PIT_COUNT;		/* # pits in cave */
107 int bat_num = BAT_COUNT;		/* # bats */
108 int room_num = ROOMS_IN_CAVE;		/* # rooms in cave */
109 int link_num = LINKS_IN_ROOM;		/* links per room  */
110 int arrow_num = NUMBER_OF_ARROWS;	/* arrow inventory */
111 
112 char answer[20];			/* user input */
113 
114 main(argc, argv)
115 	int argc;
116 	char **argv;
117 {
118 	extern char *optarg;
119 	int c;
120 
121 #ifdef DEBUG
122 	while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != EOF)
123 #else
124 	while ((c = getopt(argc, argv, "a:b:hp:r:t:")) != EOF)
125 #endif
126 		switch (c) {
127 		case 'a':
128 			arrow_num = atoi(optarg);
129 			break;
130 		case 'b':
131 			bat_num = atoi(optarg);
132 			break;
133 #ifdef DEBUG
134 		case 'd':
135 			debug = 1;
136 			break;
137 #endif
138 		case 'h':
139 			level = HARD;
140 			break;
141 		case 'p':
142 			pit_num = atoi(optarg);
143 			break;
144 		case 'r':
145 			room_num = atoi(optarg);
146 			if (room_num < MIN_ROOMS_IN_CAVE) {
147 				(void)fprintf(stderr,
148 	"No self-respecting wumpus would live in such a small cave!\n");
149 				exit(1);
150 			}
151 			if (room_num > MAX_ROOMS_IN_CAVE) {
152 				(void)fprintf(stderr,
153 	"Even wumpii can't furnish caves that large!\n");
154 				exit(1);
155 			}
156 			break;
157 		case 't':
158 			link_num = atoi(optarg);
159 			if (link_num < 2) {
160 				(void)fprintf(stderr,
161 	"Wumpii like extra doors in their caves!\n");
162 				exit(1);
163 			}
164 			break;
165 		case '?':
166 		default:
167 			usage();
168 	}
169 
170 	if (link_num > MAX_LINKS_IN_ROOM ||
171 	    link_num > room_num - (room_num / 4)) {
172 		(void)fprintf(stderr,
173 "Too many tunnels!  The cave collapsed!\n(Fortunately, the wumpus escaped!)\n");
174 		exit(1);
175 	}
176 
177 	if (level == HARD) {
178 		bat_num += ((random() % (room_num / 2)) + 1);
179 		pit_num += ((random() % (room_num / 2)) + 1);
180 	}
181 
182 	if (bat_num > room_num / 2) {
183 		(void)fprintf(stderr,
184 "The wumpus refused to enter the cave, claiming it was too crowded!\n");
185 		exit(1);
186 	}
187 
188 	if (pit_num > room_num / 2) {
189 		(void)fprintf(stderr,
190 "The wumpus refused to enter the cave, claiming it was too dangerous!\n");
191 		exit(1);
192 	}
193 
194 	instructions();
195 	cave_init();
196 
197 	/* and we're OFF!  da dum, da dum, da dum, da dum... */
198 	(void)printf(
199 "\nYou're in a cave with %d rooms and %d tunnels leading from each room.\n\
200 There are %d bat%s and %d pit%s scattered throughout the cave, and your\n\
201 quiver holds %d custom super anti-evil Wumpus arrows.  Good luck.\n",
202 	    room_num, link_num, bat_num, plural(bat_num), pit_num,
203 	    plural(pit_num), arrow_num);
204 
205 	for (;;) {
206 		initialize_things_in_cave();
207 		arrows_left = arrow_num;
208 		do {
209 			display_room_stats();
210 			(void)printf("Move or shoot? (m-s) ");
211 			(void)fflush(stdout);
212 			if (!fgets(answer, sizeof(answer), stdin))
213 				break;
214 		} while (!take_action());
215 
216 		if (!getans("\nCare to play another game? (y-n) "))
217 			exit(0);
218 		if (getans("In the same cave? (y-n) "))
219 			clear_things_in_cave();
220 		else
221 			cave_init();
222 	}
223 	/* NOTREACHED */
224 }
225 
226 display_room_stats()
227 {
228 	register int i;
229 
230 	/*
231 	 * Routine will explain what's going on with the current room, as well
232 	 * as describe whether there are pits, bats, & wumpii nearby.  It's
233 	 * all pretty mindless, really.
234 	 */
235 	(void)printf(
236 "\nYou are in room %d of the cave, and have %d arrow%s left.\n",
237 	    player_loc, arrows_left, plural(arrows_left));
238 
239 	if (bats_nearby())
240 		(void)printf("*rustle* *rustle* (must be bats nearby)\n");
241 	if (pit_nearby())
242 		(void)printf("*whoosh* (I feel a draft from some pits).\n");
243 	if (wump_nearby())
244 		(void)printf("*sniff* (I can smell the evil Wumpus nearby!)\n");
245 
246 	(void)printf("There are tunnels to rooms %d, ",
247 	   cave[player_loc].tunnel[0]);
248 
249 	for (i = 1; i < link_num - 1; i++)
250 		if (cave[player_loc].tunnel[i] <= room_num)
251 			(void)printf("%d, ", cave[player_loc].tunnel[i]);
252 	(void)printf("and %d.\n", cave[player_loc].tunnel[link_num - 1]);
253 }
254 
255 take_action()
256 {
257 	/*
258 	 * Do the action specified by the player, either 'm'ove, 's'hoot
259 	 * or something exceptionally bizarre and strange!  Returns 1
260 	 * iff the player died during this turn, otherwise returns 0.
261 	 */
262 	switch (*answer) {
263 		case 'M':
264 		case 'm':			/* move */
265 			return(move_to(answer + 1));
266 		case 'S':
267 		case 's':			/* shoot */
268 			return(shoot(answer + 1));
269 		case 'Q':
270 		case 'q':
271 		case 'x':
272 			exit(0);
273 		case '\n':
274 			return(0);
275 		}
276 	if (random() % 15 == 1)
277 		(void)printf("Que pasa?\n");
278 	else
279 		(void)printf("I don't understand!\n");
280 	return(0);
281 }
282 
283 move_to(room_number)
284 	char *room_number;
285 {
286 	int i, just_moved_by_bats, next_room, tunnel_available;
287 
288 	/*
289 	 * This is responsible for moving the player into another room in the
290 	 * cave as per their directions.  If room_number is a null string,
291 	 * then we'll prompt the user for the next room to go into.   Once
292 	 * we've moved into the room, we'll check for things like bats, pits,
293 	 * and so on.  This routine returns 1 if something occurs that kills
294 	 * the player and 0 otherwise...
295 	 */
296 	tunnel_available = just_moved_by_bats = 0;
297 	next_room = atoi(room_number);
298 
299 	/* crap for magic tunnels */
300 	if (next_room == room_num + 1 &&
301 	    cave[player_loc].tunnel[link_num-1] != next_room)
302 		++next_room;
303 
304 	while (next_room < 1 || next_room > room_num + 1) {
305 		if (next_room < 0 && next_room != -1)
306 (void)printf("Sorry, but we're constrained to a semi-Euclidean cave!\n");
307 		if (next_room > room_num + 1)
308 (void)printf("What?  The cave surely isn't quite that big!\n");
309 		if (next_room == room_num + 1 &&
310 		    cave[player_loc].tunnel[link_num-1] != next_room) {
311 			(void)printf("What?  The cave isn't that big!\n");
312 			++next_room;
313 		}
314 		(void)printf("To which room do you wish to move? ");
315 		(void)fflush(stdout);
316 		if (!fgets(answer, sizeof(answer), stdin))
317 			return(1);
318 		next_room = atoi(answer);
319 	}
320 
321 	/* now let's see if we can move to that room or not */
322 	tunnel_available = 0;
323 	for (i = 0; i < link_num; i++)
324 		if (cave[player_loc].tunnel[i] == next_room)
325 			tunnel_available = 1;
326 
327 	if (!tunnel_available) {
328 		(void)printf("*Oof!*  (You hit the wall)\n");
329 		if (random() % 6 == 1) {
330 (void)printf("Your colorful comments awaken the wumpus!\n");
331 			move_wump();
332 			if (wumpus_loc == player_loc) {
333 				wump_kill();
334 				return(1);
335 			}
336 		}
337 		return(0);
338 	}
339 
340 	/* now let's move into that room and check it out for dangers */
341 	if (next_room == room_num + 1)
342 		jump(next_room = (random() % room_num) + 1);
343 
344 	player_loc = next_room;
345 	for (;;) {
346 		if (next_room == wumpus_loc) {		/* uh oh... */
347 			wump_kill();
348 			return(1);
349 		}
350 		if (cave[next_room].has_a_pit)
351 			if (random() % 12 < 2) {
352 				pit_survive();
353 				return(0);
354 			} else {
355 				pit_kill();
356 				return(1);
357 			}
358 
359 		if (cave[next_room].has_a_bat) {
360 			(void)printf(
361 "*flap*  *flap*  *flap*  (humongous bats pick you up and move you%s!)\n",
362 			    just_moved_by_bats ? " again": "");
363 			next_room = player_loc = (random() % room_num) + 1;
364 			just_moved_by_bats = 1;
365 		}
366 
367 		else
368 			break;
369 	}
370 	return(0);
371 }
372 
373 shoot(room_list)
374 	char *room_list;
375 {
376 	int chance, next, roomcnt;
377 	int j, arrow_location, link, ok;
378 	char *p, *strtok();
379 
380 	/*
381 	 * Implement shooting arrows.  Arrows are shot by the player indicating
382 	 * a space-separated list of rooms that the arrow should pass through;
383 	 * if any of the rooms they specify are not accessible via tunnel from
384 	 * the room the arrow is in, it will instead fly randomly into another
385 	 * room.  If the player hits the wumpus, this routine will indicate
386 	 * such.  If it misses, this routine will *move* the wumpus one room.
387 	 * If it's the last arrow, the player then dies...  Returns 1 if the
388 	 * player has won or died, 0 if nothing has happened.
389 	 */
390 	arrow_location = player_loc;
391 	for (roomcnt = 1;; ++roomcnt, room_list = NULL) {
392 		if (!(p = strtok(room_list, " \t\n")))
393 			if (roomcnt == 1) {
394 				(void)printf(
395 			"The arrow falls to the ground at your feet!\n");
396 				return(0);
397 			} else
398 				break;
399 		if (roomcnt > 5) {
400 			(void)printf(
401 "The arrow wavers in its flight and and can go no further!\n");
402 			break;
403 		}
404 		next = atoi(p);
405 		for (j = 0, ok = 0; j < link_num; j++)
406 			if (cave[arrow_location].tunnel[j] == next)
407 				ok = 1;
408 
409 		if (ok) {
410 			if (next > room_num) {
411 				(void)printf(
412 "A faint gleam tells you the arrow has gone through a magic tunnel!\n");
413 				arrow_location = (random() % room_num) + 1;
414 			} else
415 				arrow_location = next;
416 		} else {
417 			link = (random() % link_num);
418 			if (link == player_loc)
419 				(void)printf(
420 "*thunk*  The arrow can't find a way from %d to %d and flys back into\n\
421 your room!\n",
422 				    arrow_location, next);
423 			else if (cave[arrow_location].tunnel[link] > room_num)
424 				(void)printf(
425 "*thunk*  The arrow flys randomly into a magic tunnel, thence into\n\
426 room %d!\n",
427 				    cave[arrow_location].tunnel[link]);
428 			else
429 				(void)printf(
430 "*thunk*  The arrow can't find a way from %d to %d and flys randomly\n\
431 into room %d!\n",
432 				    arrow_location, next,
433 				    cave[arrow_location].tunnel[link]);
434 			arrow_location = cave[arrow_location].tunnel[link];
435 			break;
436 		}
437 		chance = random() % 10;
438 		if (roomcnt == 3 && chance < 2) {
439 			(void)printf(
440 "Your bowstring breaks!  *twaaaaaang*\n\
441 The arrow is weakly shot and can go no further!\n");
442 			break;
443 		} else if (roomcnt == 4 && chance < 6) {
444 			(void)printf(
445 "The arrow wavers in its flight and and can go no further!\n");
446 			break;
447 		}
448 	}
449 
450 	/*
451 	 * now we've gotten into the new room let us see if El Wumpo is
452 	 * in the same room ... if so we've a HIT and the player WON!
453 	 */
454 	if (arrow_location == wumpus_loc) {
455 		kill_wump();
456 		return(1);
457 	}
458 
459 	if (arrow_location == player_loc) {
460 		shoot_self();
461 		return(1);
462 	}
463 
464 	if (!--arrows_left) {
465 		no_arrows();
466 		return(1);
467 	}
468 
469 	{
470 		/* each time you shoot, it's more likely the wumpus moves */
471 		static int lastchance = 2;
472 
473 		if (random() % level == EASY ? 12 : 9 < (lastchance += 2)) {
474 			move_wump();
475 			if (wumpus_loc == player_loc)
476 				wump_kill();
477 			lastchance = random() % 3;
478 
479 		}
480 	}
481 	return(0);
482 }
483 
484 cave_init()
485 {
486 	register int i, j, k, link;
487 	int delta, int_compare();
488 	time_t time();
489 
490 	/*
491 	 * This does most of the interesting work in this program actually!
492 	 * In this routine we'll initialize the Wumpus cave to have all rooms
493 	 * linking to all others by stepping through our data structure once,
494 	 * recording all forward links and backwards links too.  The parallel
495 	 * "linkcount" data structure ensures that no room ends up with more
496 	 * than three links, regardless of the quality of the random number
497 	 * generator that we're using.
498 	 */
499 	srandom((int)time((time_t *)0));
500 
501 	/* initialize the cave first off. */
502 	for (i = 1; i <= room_num; ++i)
503 		for (j = 0; j < link_num ; ++j)
504 			cave[i].tunnel[j] = -1;
505 
506 	/* choose a random 'hop' delta for our guaranteed link */
507 	while (!(delta = random() % room_num));
508 
509 	for (i = 1; i <= room_num; ++i) {
510 		link = ((i + delta) % room_num) + 1;	/* connection */
511 		cave[i].tunnel[0] = link;		/* forw link */
512 		cave[link].tunnel[1] = i;		/* back link */
513 	}
514 	/* now fill in the rest of the cave with random connections */
515 	for (i = 1; i <= room_num; i++)
516 		for (j = 2; j < link_num ; j++) {
517 			if (cave[i].tunnel[j] != -1)
518 				continue;
519 try_again:		link = (random() % room_num) + 1;
520 			/* skip duplicates */
521 			for (k = 0; k < j; k++)
522 				if (cave[i].tunnel[k] == link)
523 					goto try_again;
524 			cave[i].tunnel[j] = link;
525 			if (random() % 2 == 1)
526 				continue;
527 			for (k = 0; k < link_num; ++k) {
528 				/* if duplicate, skip it */
529 				if (cave[link].tunnel[k] == i)
530 					k = link_num;
531 
532 				/* if open link, use it, force exit */
533 				if (cave[link].tunnel[k] == -1) {
534 					cave[link].tunnel[k] = i;
535 					k = link_num;
536 				}
537 			}
538 		}
539 	/*
540 	 * now that we're done, sort the tunnels in each of the rooms to
541 	 * make it easier on the intrepid adventurer.
542 	 */
543 	for (i = 1; i <= room_num; ++i)
544 		qsort(cave[i].tunnel, (u_int)link_num,
545 		    sizeof(cave[i].tunnel[0]), int_compare);
546 
547 #ifdef DEBUG
548 	if (debug)
549 		for (i = 1; i <= room_num; ++i) {
550 			(void)printf("<room %d  has tunnels to ", i);
551 			for (j = 0; j < link_num; ++j)
552 				(void)printf("%d ", cave[i].tunnel[j]);
553 			(void)printf(">\n");
554 		}
555 #endif
556 }
557 
558 clear_things_in_cave()
559 {
560 	register int i;
561 
562 	/*
563 	 * remove bats and pits from the current cave in preparation for us
564 	 * adding new ones via the initialize_things_in_cave() routines.
565 	 */
566 	for (i = 1; i <= room_num; ++i)
567 		cave[i].has_a_bat = cave[i].has_a_pit = 0;
568 }
569 
570 initialize_things_in_cave()
571 {
572 	register int i, loc;
573 
574 	/* place some bats, pits, the wumpus, and the player. */
575 	for (i = 0; i < bat_num; ++i) {
576 		do {
577 			loc = (random() % room_num) + 1;
578 		} while (cave[loc].has_a_bat);
579 		cave[loc].has_a_bat = 1;
580 #ifdef DEBUG
581 		if (debug)
582 			(void)printf("<bat in room %d>\n", loc);
583 #endif
584 	}
585 
586 	for (i = 0; i < pit_num; ++i) {
587 		do {
588 			loc = (random() % room_num) + 1;
589 		} while (cave[loc].has_a_pit && cave[loc].has_a_bat);
590 		cave[loc].has_a_pit = 1;
591 #ifdef DEBUG
592 		if (debug)
593 			(void)printf("<pit in room %d>\n", loc);
594 #endif
595 	}
596 
597 	wumpus_loc = (random() % room_num) + 1;
598 #ifdef DEBUG
599 	if (debug)
600 		(void)printf("<wumpus in room %d>\n", loc);
601 #endif
602 
603 	do {
604 		player_loc = (random() % room_num) + 1;
605 	} while (player_loc == wumpus_loc || (level == HARD ?
606 	    (link_num / room_num < 0.4 ? wump_nearby() : 0) : 0));
607 }
608 
609 getans(prompt)
610 	char *prompt;
611 {
612 	char buf[20];
613 
614 	/*
615 	 * simple routine to ask the yes/no question specified until the user
616 	 * answers yes or no, then return 1 if they said 'yes' and 0 if they
617 	 * answered 'no'.
618 	 */
619 	for (;;) {
620 		(void)printf("%s", prompt);
621 		(void)fflush(stdout);
622 		if (!fgets(buf, sizeof(buf), stdin))
623 			return(0);
624 		if (*buf == 'N' || *buf == 'n')
625 			return(0);
626 		if (*buf == 'Y' || *buf == 'y')
627 			return(1);
628 		(void)printf(
629 "I don't understand your answer; please enter 'y' or 'n'!\n");
630 	}
631 	/* NOTREACHED */
632 }
633 
634 bats_nearby()
635 {
636 	register int i;
637 
638 	/* check for bats in the immediate vicinity */
639 	for (i = 0; i < link_num; ++i)
640 		if (cave[cave[player_loc].tunnel[i]].has_a_bat)
641 			return(1);
642 	return(0);
643 }
644 
645 pit_nearby()
646 {
647 	register int i;
648 
649 	/* check for pits in the immediate vicinity */
650 	for (i = 0; i < link_num; ++i)
651 		if (cave[cave[player_loc].tunnel[i]].has_a_pit)
652 			return(1);
653 	return(0);
654 }
655 
656 wump_nearby()
657 {
658 	register int i, j;
659 
660 	/* check for a wumpus within TWO caves of where we are */
661 	for (i = 0; i < link_num; ++i) {
662 		if (cave[player_loc].tunnel[i] == wumpus_loc)
663 			return(1);
664 		for (j = 0; j < link_num; ++j)
665 			if (cave[cave[player_loc].tunnel[i]].tunnel[j] ==
666 			    wumpus_loc)
667 				return(1);
668 	}
669 	return(0);
670 }
671 
672 move_wump()
673 {
674 	wumpus_loc = cave[wumpus_loc].tunnel[random() % link_num];
675 }
676 
677 int_compare(a, b)
678 	int *a, *b;
679 {
680 	return(*a < *b ? -1 : 1);
681 }
682 
683 instructions()
684 {
685 	char buf[120], *p, *getenv();
686 
687 	/*
688 	 * read the instructions file, if needed, and show the user how to
689 	 * play this game!
690 	 */
691 	if (!getans("Instructions? (y-n) "))
692 		return;
693 
694 	if (access(_PATH_WUMPINFO, R_OK)) {
695 		(void)printf(
696 "Sorry, but the instruction file seems to have disappeared in a\n\
697 puff of greasy black smoke! (poof)\n");
698 		return;
699 	}
700 
701 	if (!(p = getenv("PAGER")) ||
702 	    strlen(p) > sizeof(buf) + strlen(_PATH_WUMPINFO) + 5)
703 		p = _PATH_PAGER;
704 
705 	(void)sprintf(buf, "%s %s", p, _PATH_WUMPINFO);
706 	(void)system(buf);
707 }
708 
709 usage()
710 {
711 	(void)fprintf(stderr,
712 "usage: wump [-h] [-a arrows] [-b bats] [-p pits] [-r rooms] [-t tunnels]\n");
713 	exit(1);
714 }
715 
716 /* messages */
717 
718 wump_kill()
719 {
720 	(void)printf(
721 "*ROAR* *chomp* *snurfle* *chomp*!\n\
722 Much to the delight of the Wumpus, you walked right into his mouth,\n\
723 making you one of the easiest dinners he's ever had!  For you, however,\n\
724 it's a rather unpleasant death.  The only good thing is that it's been\n\
725 so long since the evil Wumpus cleaned his teeth that you immediately\n\
726 passed out from the stench!\n");
727 }
728 
729 kill_wump()
730 {
731 	(void)printf(
732 "*thwock!* *groan* *crash*\n\n\
733 A horrible roar fills the cave, and you realize, with a smile, that you\n\
734 have slain the evil Wumpus and won the game!  You don't want to tarry for\n\
735 long, however, because not only is the Wumpus famous, but the stench of\n\
736 dead Wumpus is also quite well known, a stench plenty enough to slay the\n\
737 mightiest adventurer at a single whiff!!\n");
738 }
739 
740 no_arrows()
741 {
742 	(void)printf(
743 "\nYou turn and look at your quiver, and realize with a sinking feeling\n\
744 that you've just shot your last arrow (figuratively, too).  Sensing this\n\
745 with its psychic powers, the evil Wumpus rampagees through the cave, finds\n\
746 you, and with a mighty *ROAR* eats you alive!\n");
747 }
748 
749 shoot_self()
750 {
751 	(void)printf(
752 "\n*Thwack!*  A sudden piercing feeling informs you that the ricochet\n\
753 of your wild arrow has resulted in it wedging in your side, causing\n\
754 extreme agony.  The evil Wumpus, with its psychic powers, realizes this\n\
755 and immediately rushes to your side, not to help, alas, but to EAT YOU!\n\
756 (*CHOMP*)\n");
757 }
758 
759 jump(where)
760 	int where;
761 {
762 	(void)printf(
763 "\nWith a jaunty step you enter the magic tunnel.  As you do, you\n\
764 notice that the walls are shimmering and glowing.  Suddenly you feel\n\
765 a very curious, warm sensation and find yourself in room %d!!\n", where);
766 }
767 
768 pit_kill()
769 {
770 	(void)printf(
771 "*AAAUUUUGGGGGHHHHHhhhhhhhhhh...*\n\
772 The whistling sound and updraft as you walked into this room of the\n\
773 cave apparently wasn't enough to clue you in to the presence of the\n\
774 bottomless pit.  You have a lot of time to reflect on this error as\n\
775 you fall many miles to the core of the earth.  Look on the bright side;\n\
776 you can at least find out if Jules Verne was right...\n");
777 }
778 
779 pit_survive()
780 {
781 	(void)printf(
782 "Without conscious thought you grab for the side of the cave and manage\n\
783 to grasp onto a rocky outcrop.  Beneath your feet stretches the limitless\n\
784 depths of a bottomless pit!  Rock crumbles beneath your feet!\n");
785 }
786