X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/91e8bf7c25f16721a2b11e84fe0d77ba69e81c84..13b270759f1529f9db9779c393c17985ff565bdf:/wump/wump.c?ds=sidebyside diff --git a/wump/wump.c b/wump/wump.c index 18e8401c..5d6066b3 100644 --- a/wump/wump.c +++ b/wump/wump.c @@ -1,4 +1,4 @@ -/* $NetBSD: wump.c,v 1.3 1995/04/22 08:19:51 cgd Exp $ */ +/* $NetBSD: wump.c,v 1.9 1999/07/14 22:49:27 hubertf Exp $ */ /* * Copyright (c) 1989, 1993 @@ -37,17 +37,17 @@ * SUCH DAMAGE. */ +#include #ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1989, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint #if 0 static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: wump.c,v 1.3 1995/04/22 08:19:51 cgd Exp $"; +__RCSID("$NetBSD: wump.c,v 1.9 1999/07/14 22:49:27 hubertf Exp $"); #endif #endif /* not lint */ @@ -57,9 +57,14 @@ static char rcsid[] = "$NetBSD: wump.c,v 1.3 1995/04/22 08:19:51 cgd Exp $"; * would care to remember. */ +#include #include #include +#include #include +#include +#include +#include #include "pathnames.h" /* some defines to spec out what our wumpus cave should look like */ @@ -110,17 +115,41 @@ int arrow_num = NUMBER_OF_ARROWS; /* arrow inventory */ char answer[20]; /* user input */ +int bats_nearby __P((void)); +void cave_init __P((void)); +void clear_things_in_cave __P((void)); +void display_room_stats __P((void)); +int getans __P((const char *)); +void initialize_things_in_cave __P((void)); +void instructions __P((void)); +int int_compare __P((const void *, const void *)); +void jump __P((int)); +void kill_wump __P((void)); +int main __P((int, char **)); +int move_to __P((const char *)); +void move_wump __P((void)); +void no_arrows __P((void)); +void pit_kill __P((void)); +int pit_nearby __P((void)); +void pit_survive __P((void)); +int shoot __P((char *)); +void shoot_self __P((void)); +int take_action __P((void)); +void usage __P((void)) __attribute__((__noreturn__)); +void wump_kill __P((void)); +int wump_nearby __P((void)); + +int main(argc, argv) int argc; char **argv; { - extern char *optarg; int c; #ifdef DEBUG - while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != EOF) + while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != -1) #else - while ((c = getopt(argc, argv, "a:b:hp:r:t:")) != EOF) + while ((c = getopt(argc, argv, "a:b:hp:r:t:")) != -1) #endif switch (c) { case 'a': @@ -220,11 +249,13 @@ quiver holds %d custom super anti-evil Wumpus arrows. Good luck.\n", cave_init(); } /* NOTREACHED */ + return (0); } +void display_room_stats() { - register int i; + int i; /* * Routine will explain what's going on with the current room, as well @@ -251,6 +282,7 @@ display_room_stats() (void)printf("and %d.\n", cave[player_loc].tunnel[link_num - 1]); } +int take_action() { /* @@ -279,8 +311,9 @@ take_action() return(0); } +int move_to(room_number) - char *room_number; + const char *room_number; { int i, just_moved_by_bats, next_room, tunnel_available; @@ -346,7 +379,7 @@ move_to(room_number) wump_kill(); return(1); } - if (cave[next_room].has_a_pit) + if (cave[next_room].has_a_pit) { if (random() % 12 < 2) { pit_survive(); return(0); @@ -354,6 +387,7 @@ move_to(room_number) pit_kill(); return(1); } + } if (cave[next_room].has_a_bat) { (void)printf( @@ -369,12 +403,13 @@ move_to(room_number) return(0); } +int shoot(room_list) char *room_list; { int chance, next, roomcnt; int j, arrow_location, link, ok; - char *p, *strtok(); + char *p; /* * Implement shooting arrows. Arrows are shot by the player indicating @@ -388,13 +423,14 @@ shoot(room_list) */ arrow_location = player_loc; for (roomcnt = 1;; ++roomcnt, room_list = NULL) { - if (!(p = strtok(room_list, " \t\n"))) + if (!(p = strtok(room_list, " \t\n"))) { if (roomcnt == 1) { (void)printf( "The arrow falls to the ground at your feet!\n"); return(0); } else break; + } if (roomcnt > 5) { (void)printf( "The arrow wavers in its flight and and can go no further!\n"); @@ -480,11 +516,11 @@ The arrow is weakly shot and can go no further!\n"); return(0); } +void cave_init() { - register int i, j, k, link; - int delta, int_compare(); - time_t time(); + int i, j, k, link; + int delta; /* * This does most of the interesting work in this program actually! @@ -554,9 +590,10 @@ try_again: link = (random() % room_num) + 1; #endif } +void clear_things_in_cave() { - register int i; + int i; /* * remove bats and pits from the current cave in preparation for us @@ -566,9 +603,10 @@ clear_things_in_cave() cave[i].has_a_bat = cave[i].has_a_pit = 0; } +void initialize_things_in_cave() { - register int i, loc; + int i, loc; /* place some bats, pits, the wumpus, and the player. */ for (i = 0; i < bat_num; ++i) { @@ -605,8 +643,9 @@ initialize_things_in_cave() (link_num / room_num < 0.4 ? wump_nearby() : 0) : 0)); } +int getans(prompt) - char *prompt; + const char *prompt; { char buf[20]; @@ -630,9 +669,10 @@ getans(prompt) /* NOTREACHED */ } +int bats_nearby() { - register int i; + int i; /* check for bats in the immediate vicinity */ for (i = 0; i < link_num; ++i) @@ -641,9 +681,10 @@ bats_nearby() return(0); } +int pit_nearby() { - register int i; + int i; /* check for pits in the immediate vicinity */ for (i = 0; i < link_num; ++i) @@ -652,9 +693,10 @@ pit_nearby() return(0); } +int wump_nearby() { - register int i, j; + int i, j; /* check for a wumpus within TWO caves of where we are */ for (i = 0; i < link_num; ++i) { @@ -668,20 +710,26 @@ wump_nearby() return(0); } +void move_wump() { wumpus_loc = cave[wumpus_loc].tunnel[random() % link_num]; } +int int_compare(a, b) - int *a, *b; + const void *a, *b; { - return(*a < *b ? -1 : 1); + return(*(const int *)a < *(const int *)b ? -1 : 1); } +void instructions() { - char buf[120], *p, *getenv(); + const char *pager; + pid_t pid; + int status; + int fd; /* * read the instructions file, if needed, and show the user how to @@ -697,14 +745,29 @@ puff of greasy black smoke! (poof)\n"); return; } - if (!(p = getenv("PAGER")) || - strlen(p) > sizeof(buf) + strlen(_PATH_WUMPINFO) + 5) - p = _PATH_PAGER; - - (void)sprintf(buf, "%s %s", p, _PATH_WUMPINFO); - (void)system(buf); + if (!isatty(1)) + pager = "cat"; + else { + if (!(pager = getenv("PAGER")) || (*pager == 0)) + pager = _PATH_PAGER; + } + switch (pid = fork()) { + case 0: /* child */ + if ((fd = open(_PATH_WUMPINFO, O_RDONLY)) == -1) + err(1, "open %s", _PATH_WUMPINFO); + if (dup2(fd, 0) == -1) + err(1, "dup2"); + (void)execl("/bin/sh", "sh", "-c", pager, NULL); + err(1, "exec sh -c %s", pager); + case -1: + err(1, "fork"); + default: + (void)waitpid(pid, &status, 0); + break; + } } +void usage() { (void)fprintf(stderr, @@ -714,6 +777,7 @@ usage() /* messages */ +void wump_kill() { (void)printf( @@ -725,6 +789,7 @@ so long since the evil Wumpus cleaned his teeth that you immediately\n\ passed out from the stench!\n"); } +void kill_wump() { (void)printf( @@ -736,6 +801,7 @@ dead Wumpus is also quite well known, a stench plenty enough to slay the\n\ mightiest adventurer at a single whiff!!\n"); } +void no_arrows() { (void)printf( @@ -745,6 +811,7 @@ with its psychic powers, the evil Wumpus rampagees through the cave, finds\n\ you, and with a mighty *ROAR* eats you alive!\n"); } +void shoot_self() { (void)printf( @@ -755,6 +822,7 @@ and immediately rushes to your side, not to help, alas, but to EAT YOU!\n\ (*CHOMP*)\n"); } +void jump(where) int where; { @@ -764,6 +832,7 @@ notice that the walls are shimmering and glowing. Suddenly you feel\n\ a very curious, warm sensation and find yourself in room %d!!\n", where); } +void pit_kill() { (void)printf( @@ -775,6 +844,7 @@ you fall many miles to the core of the earth. Look on the bright side;\n\ you can at least find out if Jules Verne was right...\n"); } +void pit_survive() { (void)printf(