mirror of
https://salsa.debian.org/games-team/bsdgames
synced 2025-02-02 15:07:16 -05:00
522 lines
12 KiB
Diff
522 lines
12 KiB
Diff
Update wump directory to NetBSD CVS as of 2010-01-14
|
|
This fixes Debian bug #564891
|
|
--- a/wump/Makefile.bsd
|
|
+++ b/wump/Makefile.bsd
|
|
@@ -1,4 +1,4 @@
|
|
-# $NetBSD: Makefile,v 1.8 1999/02/13 02:54:22 lukem Exp $
|
|
+# $NetBSD: Makefile,v 1.10 2008/01/28 07:04:00 dholland Exp $
|
|
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
|
|
|
.include <bsd.own.mk>
|
|
--- a/wump/wump.6
|
|
+++ b/wump/wump.6
|
|
@@ -1,4 +1,4 @@
|
|
-.\" $NetBSD: wump.6,v 1.6 2003/08/07 09:37:57 agc Exp $
|
|
+.\" $NetBSD: wump.6,v 1.8 2006/01/22 21:22:30 wiz Exp $
|
|
.\"
|
|
.\" Copyright (c) 1989, 1993
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
@@ -32,7 +32,7 @@
|
|
.\"
|
|
.\" @(#)wump.6 8.1 (Berkeley) 5/31/93
|
|
.\"
|
|
-.Dd May 31, 1993
|
|
+.Dd January 19, 2006
|
|
.Dt WUMP 6
|
|
.Os
|
|
.Sh NAME
|
|
@@ -74,7 +74,7 @@
|
|
The default is three.
|
|
.It Fl r
|
|
Specifies the number of rooms in the cave.
|
|
-The default cave size is twenty-five rooms.
|
|
+The default cave size is twenty rooms.
|
|
.It Fl t
|
|
Specifies the number of tunnels connecting each room in the cave to
|
|
another room.
|
|
--- a/wump/wump.c
|
|
+++ b/wump/wump.c
|
|
@@ -1,4 +1,4 @@
|
|
-/* $NetBSD: wump.c,v 1.17 2005/02/15 12:56:20 jsm Exp $ */
|
|
+/* $NetBSD: wump.c,v 1.25 2009/08/27 00:19:52 dholland Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1989, 1993
|
|
@@ -35,15 +35,15 @@
|
|
|
|
#include <sys/cdefs.h>
|
|
#ifndef lint
|
|
-__COPYRIGHT("@(#) Copyright (c) 1989, 1993\n\
|
|
- The Regents of the University of California. All rights reserved.\n");
|
|
+__COPYRIGHT("@(#) Copyright (c) 1989, 1993\
|
|
+ The Regents of the University of California. All rights reserved.");
|
|
#endif /* not lint */
|
|
|
|
#ifndef lint
|
|
#if 0
|
|
static char sccsid[] = "@(#)wump.c 8.1 (Berkeley) 5/31/93";
|
|
#else
|
|
-__RCSID("$NetBSD: wump.c,v 1.17 2005/02/15 12:56:20 jsm Exp $");
|
|
+__RCSID("$NetBSD: wump.c,v 1.25 2009/08/27 00:19:52 dholland Exp $");
|
|
#endif
|
|
#endif /* not lint */
|
|
|
|
@@ -86,7 +86,7 @@
|
|
#define plural(n) (n == 1 ? "" : "s")
|
|
|
|
/* simple cave data structure; +1 so we can index from '1' not '0' */
|
|
-struct room_record {
|
|
+static struct room_record {
|
|
int tunnel[MAX_LINKS_IN_ROOM];
|
|
int has_a_pit, has_a_bat;
|
|
} cave[MAX_ROOMS_IN_CAVE+1];
|
|
@@ -95,57 +95,57 @@
|
|
* global variables so we can keep track of where the player is, how
|
|
* many arrows they still have, where el wumpo is, and so on...
|
|
*/
|
|
-int player_loc = -1; /* player location */
|
|
-int wumpus_loc = -1; /* The Bad Guy location */
|
|
-int level = EASY; /* level of play */
|
|
-int arrows_left; /* arrows unshot */
|
|
+static int player_loc = -1; /* player location */
|
|
+static int wumpus_loc = -1; /* The Bad Guy location */
|
|
+static int level = EASY; /* level of play */
|
|
+static int arrows_left; /* arrows unshot */
|
|
|
|
#ifdef DEBUG
|
|
-int debug = 0;
|
|
+static int debug = 0;
|
|
#endif
|
|
|
|
-int pit_num = PIT_COUNT; /* # pits in cave */
|
|
-int bat_num = BAT_COUNT; /* # bats */
|
|
-int room_num = ROOMS_IN_CAVE; /* # rooms in cave */
|
|
-int link_num = LINKS_IN_ROOM; /* links per room */
|
|
-int arrow_num = NUMBER_OF_ARROWS; /* arrow inventory */
|
|
-
|
|
-char answer[20]; /* user input */
|
|
-
|
|
-int bats_nearby(void);
|
|
-void cave_init(void);
|
|
-void clear_things_in_cave(void);
|
|
-void display_room_stats(void);
|
|
-int gcd(int, int);
|
|
-int getans(const char *);
|
|
-void initialize_things_in_cave(void);
|
|
-void instructions(void);
|
|
-int int_compare(const void *, const void *);
|
|
-void jump(int);
|
|
-void kill_wump(void);
|
|
+static int pit_num = PIT_COUNT; /* # pits in cave */
|
|
+static int bat_num = BAT_COUNT; /* # bats */
|
|
+static int room_num = ROOMS_IN_CAVE; /* # rooms in cave */
|
|
+static int link_num = LINKS_IN_ROOM; /* links per room */
|
|
+static int arrow_num = NUMBER_OF_ARROWS;/* arrow inventory */
|
|
+
|
|
+static char answer[20]; /* user input */
|
|
+
|
|
int main(int, char **);
|
|
-int move_to(const char *);
|
|
-void move_wump(void);
|
|
-void no_arrows(void);
|
|
-void pit_kill(void);
|
|
-int pit_nearby(void);
|
|
-void pit_survive(void);
|
|
-int shoot(char *);
|
|
-void shoot_self(void);
|
|
-int take_action(void);
|
|
-void usage(void) __attribute__((__noreturn__));
|
|
-void wump_kill(void);
|
|
-int wump_nearby(void);
|
|
+static int bats_nearby(void);
|
|
+static void cave_init(void);
|
|
+static void clear_things_in_cave(void);
|
|
+static void display_room_stats(void);
|
|
+static int gcd(int, int);
|
|
+static int getans(const char *);
|
|
+static void initialize_things_in_cave(void);
|
|
+static void instructions(void);
|
|
+static int int_compare(const void *, const void *);
|
|
+static void jump(int);
|
|
+static void kill_wump(void);
|
|
+static int move_to(const char *);
|
|
+static void move_wump(void);
|
|
+static void no_arrows(void);
|
|
+static void pit_kill(void);
|
|
+static int pit_nearby(void);
|
|
+static void pit_survive(void);
|
|
+static int shoot(char *);
|
|
+static void shoot_self(void);
|
|
+static int take_action(void);
|
|
+static void usage(void) __dead;
|
|
+static void wump_kill(void);
|
|
+static int wump_nearby(void);
|
|
|
|
int
|
|
main(argc, argv)
|
|
int argc;
|
|
char **argv;
|
|
{
|
|
- int c;
|
|
+ int c, e=0;
|
|
|
|
/* Revoke setgid privileges */
|
|
- setregid(getgid(), getgid());
|
|
+ setgid(getgid());
|
|
|
|
#ifdef DEBUG
|
|
while ((c = getopt(argc, argv, "a:b:hp:r:t:d")) != -1)
|
|
@@ -232,28 +232,29 @@
|
|
plural(pit_num), arrow_num);
|
|
|
|
for (;;) {
|
|
+ clear_things_in_cave();
|
|
initialize_things_in_cave();
|
|
arrows_left = arrow_num;
|
|
do {
|
|
display_room_stats();
|
|
(void)printf("Move or shoot? (m-s) ");
|
|
(void)fflush(stdout);
|
|
- if (!fgets(answer, sizeof(answer), stdin))
|
|
+ if (!fgets(answer, sizeof(answer), stdin)) {
|
|
+ e=2;
|
|
break;
|
|
- } while (!take_action());
|
|
+ }
|
|
+ } while (!(e = take_action()));
|
|
|
|
- if (!getans("\nCare to play another game? (y-n) "))
|
|
+ if (e == 2 || !getans("\nCare to play another game? (y-n) "))
|
|
exit(0);
|
|
- if (getans("In the same cave? (y-n) "))
|
|
- clear_things_in_cave();
|
|
- else
|
|
+ if (getans("In the same cave? (y-n) ") == 0)
|
|
cave_init();
|
|
}
|
|
/* NOTREACHED */
|
|
return (0);
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
display_room_stats()
|
|
{
|
|
int i;
|
|
@@ -283,7 +284,7 @@
|
|
(void)printf("and %d.\n", cave[player_loc].tunnel[link_num - 1]);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
take_action()
|
|
{
|
|
/*
|
|
@@ -312,7 +313,7 @@
|
|
return(0);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
move_to(room_number)
|
|
const char *room_number;
|
|
{
|
|
@@ -404,12 +405,12 @@
|
|
return(0);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
shoot(room_list)
|
|
char *room_list;
|
|
{
|
|
int chance, next, roomcnt;
|
|
- int j, arrow_location, link, ok;
|
|
+ int j, arrow_location, lnk, ok;
|
|
char *p;
|
|
|
|
/*
|
|
@@ -450,24 +451,24 @@
|
|
} else
|
|
arrow_location = next;
|
|
} else {
|
|
- link = (random() % link_num);
|
|
- if (link == player_loc)
|
|
+ lnk = (random() % link_num);
|
|
+ if (lnk == player_loc)
|
|
(void)printf(
|
|
"*thunk* The arrow can't find a way from %d to %d and flys back into\n\
|
|
your room!\n",
|
|
arrow_location, next);
|
|
- else if (cave[arrow_location].tunnel[link] > room_num)
|
|
+ else if (cave[arrow_location].tunnel[lnk] > room_num)
|
|
(void)printf(
|
|
"*thunk* The arrow flys randomly into a magic tunnel, thence into\n\
|
|
room %d!\n",
|
|
- cave[arrow_location].tunnel[link]);
|
|
+ cave[arrow_location].tunnel[lnk]);
|
|
else
|
|
(void)printf(
|
|
"*thunk* The arrow can't find a way from %d to %d and flys randomly\n\
|
|
into room %d!\n",
|
|
arrow_location, next,
|
|
- cave[arrow_location].tunnel[link]);
|
|
- arrow_location = cave[arrow_location].tunnel[link];
|
|
+ cave[arrow_location].tunnel[lnk]);
|
|
+ arrow_location = cave[arrow_location].tunnel[lnk];
|
|
break;
|
|
}
|
|
chance = random() % 10;
|
|
@@ -506,7 +507,7 @@
|
|
/* each time you shoot, it's more likely the wumpus moves */
|
|
static int lastchance = 2;
|
|
|
|
- if (random() % level == EASY ? 12 : 9 < (lastchance += 2)) {
|
|
+ if (random() % (level == EASY ? 12 : 9) < (lastchance += 2)) {
|
|
move_wump();
|
|
if (wumpus_loc == player_loc)
|
|
wump_kill();
|
|
@@ -517,7 +518,7 @@
|
|
return(0);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
gcd(a, b)
|
|
int a, b;
|
|
{
|
|
@@ -529,10 +530,10 @@
|
|
return (gcd(b, r));
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
cave_init()
|
|
{
|
|
- int i, j, k, link;
|
|
+ int i, j, k, lnk;
|
|
int delta;
|
|
|
|
/*
|
|
@@ -561,31 +562,31 @@
|
|
} while (gcd(room_num, delta + 1) != 1);
|
|
|
|
for (i = 1; i <= room_num; ++i) {
|
|
- link = ((i + delta) % room_num) + 1; /* connection */
|
|
- cave[i].tunnel[0] = link; /* forw link */
|
|
- cave[link].tunnel[1] = i; /* back link */
|
|
+ lnk = ((i + delta) % room_num) + 1; /* connection */
|
|
+ cave[i].tunnel[0] = lnk; /* forw link */
|
|
+ cave[lnk].tunnel[1] = i; /* back link */
|
|
}
|
|
/* now fill in the rest of the cave with random connections */
|
|
for (i = 1; i <= room_num; i++)
|
|
for (j = 2; j < link_num ; j++) {
|
|
if (cave[i].tunnel[j] != -1)
|
|
continue;
|
|
-try_again: link = (random() % room_num) + 1;
|
|
+try_again: lnk = (random() % room_num) + 1;
|
|
/* skip duplicates */
|
|
for (k = 0; k < j; k++)
|
|
- if (cave[i].tunnel[k] == link)
|
|
+ if (cave[i].tunnel[k] == lnk)
|
|
goto try_again;
|
|
- cave[i].tunnel[j] = link;
|
|
+ cave[i].tunnel[j] = lnk;
|
|
if (random() % 2 == 1)
|
|
continue;
|
|
for (k = 0; k < link_num; ++k) {
|
|
/* if duplicate, skip it */
|
|
- if (cave[link].tunnel[k] == i)
|
|
+ if (cave[lnk].tunnel[k] == i)
|
|
k = link_num;
|
|
|
|
/* if open link, use it, force exit */
|
|
- if (cave[link].tunnel[k] == -1) {
|
|
- cave[link].tunnel[k] = i;
|
|
+ if (cave[lnk].tunnel[k] == -1) {
|
|
+ cave[lnk].tunnel[k] = i;
|
|
k = link_num;
|
|
}
|
|
}
|
|
@@ -595,7 +596,7 @@
|
|
* make it easier on the intrepid adventurer.
|
|
*/
|
|
for (i = 1; i <= room_num; ++i)
|
|
- qsort(cave[i].tunnel, (u_int)link_num,
|
|
+ qsort(cave[i].tunnel, link_num,
|
|
sizeof(cave[i].tunnel[0]), int_compare);
|
|
|
|
#ifdef DEBUG
|
|
@@ -609,7 +610,7 @@
|
|
#endif
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
clear_things_in_cave()
|
|
{
|
|
int i;
|
|
@@ -622,7 +623,7 @@
|
|
cave[i].has_a_bat = cave[i].has_a_pit = 0;
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
initialize_things_in_cave()
|
|
{
|
|
int i, loc;
|
|
@@ -642,7 +643,7 @@
|
|
for (i = 0; i < pit_num; ++i) {
|
|
do {
|
|
loc = (random() % room_num) + 1;
|
|
- } while (cave[loc].has_a_pit && cave[loc].has_a_bat);
|
|
+ } while (cave[loc].has_a_pit || cave[loc].has_a_bat);
|
|
cave[loc].has_a_pit = 1;
|
|
#ifdef DEBUG
|
|
if (debug)
|
|
@@ -656,13 +657,17 @@
|
|
(void)printf("<wumpus in room %d>\n", loc);
|
|
#endif
|
|
|
|
+ i = 0;
|
|
do {
|
|
player_loc = (random() % room_num) + 1;
|
|
- } while (player_loc == wumpus_loc || (level == HARD ?
|
|
- (link_num / room_num < 0.4 ? wump_nearby() : 0) : 0));
|
|
+ i++;
|
|
+ } while (player_loc == wumpus_loc || cave[player_loc].has_a_pit ||
|
|
+ cave[player_loc].has_a_bat || (level == HARD ?
|
|
+ (link_num / room_num < 0.4 ? wump_nearby() : 0) : 0) ||
|
|
+ (i > 100 && player_loc != wumpus_loc));
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
getans(prompt)
|
|
const char *prompt;
|
|
{
|
|
@@ -688,7 +693,7 @@
|
|
/* NOTREACHED */
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
bats_nearby()
|
|
{
|
|
int i;
|
|
@@ -700,7 +705,7 @@
|
|
return(0);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
pit_nearby()
|
|
{
|
|
int i;
|
|
@@ -712,7 +717,7 @@
|
|
return(0);
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
wump_nearby()
|
|
{
|
|
int i, j;
|
|
@@ -729,20 +734,20 @@
|
|
return(0);
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
move_wump()
|
|
{
|
|
wumpus_loc = cave[wumpus_loc].tunnel[random() % link_num];
|
|
}
|
|
|
|
-int
|
|
+static int
|
|
int_compare(a, b)
|
|
const void *a, *b;
|
|
{
|
|
return(*(const int *)a < *(const int *)b ? -1 : 1);
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
instructions()
|
|
{
|
|
const char *pager;
|
|
@@ -786,7 +791,7 @@
|
|
}
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
usage()
|
|
{
|
|
(void)fprintf(stderr,
|
|
@@ -796,7 +801,7 @@
|
|
|
|
/* messages */
|
|
|
|
-void
|
|
+static void
|
|
wump_kill()
|
|
{
|
|
(void)printf(
|
|
@@ -808,7 +813,7 @@
|
|
passed out from the stench!\n");
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
kill_wump()
|
|
{
|
|
(void)printf(
|
|
@@ -820,7 +825,7 @@
|
|
mightiest adventurer at a single whiff!!\n");
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
no_arrows()
|
|
{
|
|
(void)printf(
|
|
@@ -830,7 +835,7 @@
|
|
you, and with a mighty *ROAR* eats you alive!\n");
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
shoot_self()
|
|
{
|
|
(void)printf(
|
|
@@ -841,7 +846,7 @@
|
|
(*CHOMP*)\n");
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
jump(where)
|
|
int where;
|
|
{
|
|
@@ -851,7 +856,7 @@
|
|
a very curious, warm sensation and find yourself in room %d!!\n", where);
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
pit_kill()
|
|
{
|
|
(void)printf(
|
|
@@ -863,7 +868,7 @@
|
|
you can at least find out if Jules Verne was right...\n");
|
|
}
|
|
|
|
-void
|
|
+static void
|
|
pit_survive()
|
|
{
|
|
(void)printf(
|