diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-09-20 23:36:57 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-09-20 23:36:57 +0000 |
commit | 258e8f6c8fefb0e8f3e410890a5003a86c897a41 (patch) | |
tree | 8f4987a0191afe0747e1b90d6c6c072684ebd9d2 | |
parent | 9103334d21fd70396d762c44151c3eeee652b1e6 (diff) |
rand -> random; handle EOF; don't overflow on user input; check for calloc()
success; OpenBSD tags; some reformatting and ridding of unused variables.
-rw-r--r-- | games/monop/Makefile | 4 | ||||
-rw-r--r-- | games/monop/brd.dat | 1 | ||||
-rw-r--r-- | games/monop/cards.c | 71 | ||||
-rw-r--r-- | games/monop/cards.inp | 2 | ||||
-rw-r--r-- | games/monop/deck.h | 11 | ||||
-rw-r--r-- | games/monop/execute.c | 186 | ||||
-rw-r--r-- | games/monop/getinp.c | 53 | ||||
-rw-r--r-- | games/monop/houses.c | 64 | ||||
-rw-r--r-- | games/monop/initdeck.c | 80 | ||||
-rw-r--r-- | games/monop/jail.c | 29 | ||||
-rw-r--r-- | games/monop/misc.c | 133 | ||||
-rw-r--r-- | games/monop/mon.dat | 1 | ||||
-rw-r--r-- | games/monop/monop.6 | 50 | ||||
-rw-r--r-- | games/monop/monop.c | 99 | ||||
-rw-r--r-- | games/monop/monop.def | 24 | ||||
-rw-r--r-- | games/monop/monop.ext | 15 | ||||
-rw-r--r-- | games/monop/monop.h | 153 | ||||
-rw-r--r-- | games/monop/morg.c | 85 | ||||
-rw-r--r-- | games/monop/pathnames.h | 1 | ||||
-rw-r--r-- | games/monop/print.c | 82 | ||||
-rw-r--r-- | games/monop/prop.c | 85 | ||||
-rw-r--r-- | games/monop/prop.dat | 1 | ||||
-rw-r--r-- | games/monop/rent.c | 32 | ||||
-rw-r--r-- | games/monop/roll.c | 35 | ||||
-rw-r--r-- | games/monop/spec.c | 28 | ||||
-rw-r--r-- | games/monop/trade.c | 88 |
26 files changed, 806 insertions, 607 deletions
diff --git a/games/monop/Makefile b/games/monop/Makefile index 4170924013d..e504790f026 100644 --- a/games/monop/Makefile +++ b/games/monop/Makefile @@ -1,11 +1,9 @@ -# $OpenBSD: Makefile,v 1.5 1997/09/21 11:36:21 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 1998/09/20 23:36:48 pjanzen Exp $ PROG= monop SRCS= monop.c cards.c execute.c getinp.c houses.c jail.c misc.c morg.c \ print.c prop.c rent.c roll.c spec.c trade.c MAN= monop.6 -DPADD+= ${LIBCOMPAT} -LDADD+= -lcompat HIDEGAME=hidegame CLEANFILES+=initdeck cards.pck diff --git a/games/monop/brd.dat b/games/monop/brd.dat index 987fa293727..a6db0c2efbe 100644 --- a/games/monop/brd.dat +++ b/games/monop/brd.dat @@ -1,3 +1,4 @@ +/* $OpenBSD: brd.dat,v 1.2 1998/09/20 23:36:49 pjanzen Exp $ */ /* $NetBSD: brd.dat,v 1.2 1995/03/23 08:34:34 cgd Exp $ */ /*- diff --git a/games/monop/cards.c b/games/monop/cards.c index e29b8001bcd..2de4a31bed5 100644 --- a/games/monop/cards.c +++ b/games/monop/cards.c @@ -1,3 +1,4 @@ +/* $OpenBSD: cards.c,v 1.3 1998/09/20 23:36:50 pjanzen Exp $ */ /* $NetBSD: cards.c,v 1.3 1995/03/23 08:34:35 cgd Exp $ */ /* @@ -37,38 +38,41 @@ #if 0 static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: cards.c,v 1.3 1995/03/23 08:34:35 cgd Exp $"; +static char rcsid[] = "$OpenBSD: cards.c,v 1.3 1998/09/20 23:36:50 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" -# include "pathnames.h" +#include <err.h> +#include "monop.ext" +#include "pathnames.h" /* * These routine deal with the card decks */ -# define GOJF 'F' /* char for get-out-of-jail-free cards */ +#define GOJF 'F' /* char for get-out-of-jail-free cards */ -# ifndef DEV +#ifndef DEV static char *cardfile = _PATH_CARDS; -# else +#else static char *cardfile = "cards.pck"; -# endif +#endif static FILE *deckf; +static void set_up __P((DECK *)); +static void printmes __P((void)); + /* * This routine initializes the decks from the data file, * which it opens. */ -init_decks() { - - if ((deckf=fopen(cardfile, "r")) == NULL) { +void +init_decks() +{ + if ((deckf = fopen(cardfile, "r")) == NULL) file_err: - perror(cardfile); - exit(1); - } + err(1, cardfile); if (fread(&deck[0].num_cards, sizeof(deck[0].num_cards), 1, deckf) != 1) goto file_err; if (fread(&deck[0].last_card, sizeof(deck[0].last_card), 1, deckf) != 1) @@ -93,24 +97,24 @@ file_err: /* * This routine sets up the offset pointers for the given deck. */ +static void set_up(dp) -DECK *dp; { - - reg int r1, r2; + DECK *dp; +{ + int r1, r2; int i; - dp->offsets = (int32_t *) calloc(sizeof (int32_t), dp->num_cards); + if ((dp->offsets = (int32_t *) calloc(sizeof (int32_t), dp->num_cards)) == NULL) + errx(1, "malloc"); for (i = 0 ; i < dp->num_cards ; i++) { - if (fread(&dp->offsets[i], sizeof(dp->offsets[i]), 1, deckf) != 1) { - perror(cardfile); - exit(1); - } + if (fread(&dp->offsets[i], sizeof(dp->offsets[i]), 1, deckf) != 1) + err(1, cardfile); dp->offsets[i] = ntohl(dp->offsets[i]); } dp->last_card = 0; dp->gojf_used = FALSE; for (i = 0; i < dp->num_cards; i++) { - reg long temp; + long temp; r1 = roll(1, dp->num_cards) - 1; r2 = roll(1, dp->num_cards) - 1; @@ -122,13 +126,14 @@ DECK *dp; { /* * This routine draws a card from the given deck */ +void get_card(dp) -DECK *dp; { - - reg char type_maj, type_min; - int16_t num; - int i, per_h, per_H, num_h, num_H; - OWN *op; + DECK *dp; +{ + char type_maj, type_min; + int16_t num; + int i, per_h, per_H, num_h, num_H; + OWN *op; do { fseek(deckf, dp->offsets[dp->last_card], 0); @@ -199,11 +204,12 @@ DECK *dp; { } num_h = num_H = 0; for (op = cur_p->own_list; op; op = op->next) - if (op->sqr->type == PRPTY) + if (op->sqr->type == PRPTY) { if (op->sqr->desc->houses == 5) ++num_H; else num_h += op->sqr->desc->houses; + } num = per_h * num_h + per_H * num_H; printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h, num_H, num); if (num == 0) @@ -221,9 +227,10 @@ DECK *dp; { /* * This routine prints out the message on the card */ -printmes() { - - reg char c; +static void +printmes() +{ + char c; printline(); fflush(stdout); diff --git a/games/monop/cards.inp b/games/monop/cards.inp index 1867e87bb08..4b6aa814f47 100644 --- a/games/monop/cards.inp +++ b/games/monop/cards.inp @@ -93,7 +93,7 @@ Take a Walk on the Board Walk. (Advance To Board Walk) %% MF24 -Advance to Illinos Ave. +Advance to Illinois Ave. %% MF0 Advance to Go diff --git a/games/monop/deck.h b/games/monop/deck.h index 47a3c6ff916..4e22f512db3 100644 --- a/games/monop/deck.h +++ b/games/monop/deck.h @@ -1,3 +1,4 @@ +/* $OpenBSD: deck.h,v 1.3 1998/09/20 23:36:50 pjanzen Exp $ */ /* $NetBSD: deck.h,v 1.3 1995/03/23 08:34:36 cgd Exp $ */ /* @@ -35,16 +36,18 @@ * @(#)deck.h 8.1 (Berkeley) 5/31/93 */ -# define bool int8_t +#include <sys/types.h> -# define CC_D deck[0] -# define CH_D deck[1] +#define bool int8_t + +#define CC_D deck[0] +#define CH_D deck[1] struct dk_st { /* deck description structure */ int16_t num_cards; /* number of cards in deck */ int16_t last_card; /* number of last card picked */ bool gojf_used; /* set if gojf card out of deck */ - int32_t *offsets; /* offests for start of cards */ + int32_t *offsets; /* offsets for start of cards */ }; typedef struct dk_st DECK; diff --git a/games/monop/execute.c b/games/monop/execute.c index f4f49ab4ad8..95b38f7db53 100644 --- a/games/monop/execute.c +++ b/games/monop/execute.c @@ -1,3 +1,4 @@ +/* $OpenBSD: execute.c,v 1.2 1998/09/20 23:36:50 pjanzen Exp $ */ /* $NetBSD: execute.c,v 1.3 1995/03/23 08:34:38 cgd Exp $ */ /* @@ -37,34 +38,59 @@ #if 0 static char sccsid[] = "@(#)execute.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: execute.c,v 1.3 1995/03/23 08:34:38 cgd Exp $"; +static char rcsid[] = "$OpenBSD: execute.c,v 1.2 1998/09/20 23:36:50 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" -# include <sys/types.h> -# include <sys/stat.h> -# include <sys/time.h> +#include "monop.ext" +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <err.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> -# define SEGSIZE 8192 +#define SEGSIZE 8192 typedef struct stat STAT; typedef struct tm TIME; -extern char etext[], /* end of text space */ - rub(); - -static char buf[257], - *yn_only[] = { "yes", "no"}; +static char buf[257]; static bool new_play; /* set if move on to new player */ +static void show_move __P((void)); + +/* + * This routine takes user input and puts it in buf + */ +void +getbuf() +{ + char *sp; + int tmpin, i; + + i = 0; + sp = buf; + while (((tmpin = getchar()) != '\n') && (i < sizeof(buf)) && + (tmpin != EOF)) { + *sp++ = tmpin; + i++; + } + if (tmpin == EOF) { + printf("user closed input stream, quitting...\n"); + exit(0); + } + *sp = '\0'; +} /* * This routine executes the given command by index number */ +void execute(com_num) -reg int com_num; { - + int com_num; +{ new_play = FALSE; /* new_play is true if fixing */ (*func[com_num])(); notify(); @@ -77,13 +103,14 @@ reg int com_num; { /* * This routine moves a piece around. */ -do_move() { - - reg int r1, r2; - reg bool was_jail; +void +do_move() +{ + int r1, r2; + bool was_jail; new_play = was_jail = FALSE; - printf("roll is %d, %d\n", r1=roll(1, 6), r2=roll(1, 6)); + printf("roll is %d, %d\n", r1 = roll(1, 6), r2 = roll(1, 6)); if (cur_p->loc == JAIL) { was_jail++; if (!move_jail(r1, r2)) { @@ -98,7 +125,7 @@ do_move() { new_play++; goto ret; } - move(r1+r2); + move(r1 + r2); } if (r1 != r2 || was_jail) new_play++; @@ -108,10 +135,11 @@ ret: /* * This routine moves a normal move */ +void move(rl) -reg int rl; { - - reg int old_loc; + int rl; +{ + int old_loc; old_loc = cur_p->loc; cur_p->loc = (cur_p->loc + rl) % N_SQRS; @@ -124,29 +152,35 @@ reg int rl; { /* * This routine shows the results of a move */ -show_move() { - - reg SQUARE *sqp; +static void +show_move() +{ + SQUARE *sqp; sqp = &board[cur_p->loc]; printf("That puts you on %s\n", sqp->name); switch (sqp->type) { - case SAFE: + case SAFE: printf("That is a safe place\n"); break; - case CC: - cc(); break; - case CHANCE: - chance(); break; - case INC_TAX: - inc_tax(); break; - case GOTO_J: - goto_jail(); break; - case LUX_TAX: - lux_tax(); break; - case PRPTY: - case RR: - case UTIL: + case CC: + cc(); + break; + case CHANCE: + chance(); + break; + case INC_TAX: + inc_tax(); + break; + case GOTO_J: + goto_jail(); + break; + case LUX_TAX: + lux_tax(); + break; + case PRPTY: + case RR: + case UTIL: if (sqp->owner < 0) { printf("That would cost $%d\n", sqp->cost); if (getyn("Do you want to buy? ") == 0) { @@ -154,7 +188,7 @@ show_move() { cur_p->money -= sqp->cost; } else if (num_play > 2) - bid(sqp); + bid(); } else if (sqp->owner == player) printf("You own it.\n"); @@ -165,31 +199,28 @@ show_move() { /* * This routine saves the current game for use at a later date */ -save() { - - reg char *sp; - reg int outf, num; +void +save() +{ + char *sp; + int outf, num; time_t t; - int *dat_end; struct stat sb; - unsgn start, end; + char *start, *end; printf("Which file do you wish to save it in? "); - sp = buf; - while ((*sp++=getchar()) != '\n') - continue; - *--sp = '\0'; + getbuf(); /* * check for existing files, and confirm overwrite if needed */ - if (stat(buf, &sb) > -1 - && getyn("File exists. Do you wish to overwrite? ", yn_only) > 0) + if (stat(buf, &sb) == 0 + && getyn("File exists. Do you wish to overwrite? ") > 0) return; if ((outf=creat(buf, 0644)) < 0) { - perror(buf); + warn(buf); return; } printf("\"%s\" ", buf); @@ -198,11 +229,11 @@ save() { for (sp = buf; *sp != '\n'; sp++) continue; *sp = '\0'; -# if 0 +#if 0 start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE; -# else +#else start = 0; -# endif +#endif end = sbrk(0); while (start < end) { /* write out entire data space */ num = start + 16 * 1024 > end ? end - start : 16 * 1024; @@ -215,43 +246,38 @@ save() { /* * This routine restores an old game from a file */ -restore() { - - reg char *sp; - +void +restore() +{ printf("Which file do you wish to restore from? "); - for (sp = buf; (*sp=getchar()) != '\n'; sp++) - continue; - *sp = '\0'; + getbuf(); rest_f(buf); } /* * This does the actual restoring. It returns TRUE if the - * backup was successful, else false. + * backup was successful, else FALSE. */ +int rest_f(file) -reg char *file; { - - reg char *sp; - reg int inf, num; - char buf[80]; - unsgn start, end; - STAT sbuf; + char *file; +{ + char *sp; + int inf, num; + char *start, *end; + STAT sbuf; - if ((inf=open(file, 0)) < 0) { - perror(file); + if ((inf = open(file, 0)) < 0) { + warn(file); return FALSE; } printf("\"%s\" ", file); - if (fstat(inf, &sbuf) < 0) { /* get file stats */ - perror(file); - exit(1); - } -# if 0 + if (fstat(inf, &sbuf) < 0) /* get file stats */ + err(1, file); +#if 0 start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE; -# else +#else start = 0; -# endif +#endif brk(end = start + sbuf.st_size); while (start < end) { /* write out entire data space */ num = start + 16 * 1024 > end ? end - start : 16 * 1024; diff --git a/games/monop/getinp.c b/games/monop/getinp.c index 709767ded70..531d9bf4d4d 100644 --- a/games/monop/getinp.c +++ b/games/monop/getinp.c @@ -1,3 +1,4 @@ +/* $OpenBSD: getinp.c,v 1.3 1998/09/20 23:36:50 pjanzen Exp $ */ /* $NetBSD: getinp.c,v 1.4 1995/04/24 12:24:20 cgd Exp $ */ /* @@ -37,44 +38,39 @@ #if 0 static char sccsid[] = "@(#)getinp.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: getinp.c,v 1.4 1995/04/24 12:24:20 cgd Exp $"; +static char rcsid[] = "$OpenBSD: getinp.c,v 1.3 1998/09/20 23:36:50 pjanzen Exp $"; #endif #endif /* not lint */ -# include <stdio.h> -# include <string.h> -# include <ctype.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include "monop.ext" -# define reg register - -# define LINE 70 +#define LINE 70 static char buf[257]; -getinp(prompt, list) -char *prompt, *list[]; { +static int comp __P((char *)); - reg int i, n_match, match; +int +getinp(prompt, list) + char *prompt, *list[]; +{ + int i, n_match, match; char *sp; - int c; - int plen; - static int comp(); for (;;) { -inter: printf(prompt); - for (sp = buf; (c=getchar()) != '\n'; ) { - *sp = c; - if (c == -1) /* check for interupted system call */ - goto inter; - else if (sp != buf || *sp != ' ') - sp++; + fgets(buf, sizeof(buf), stdin); + if ((feof(stdin))) { + printf("user closed input stream, quitting...\n"); + exit(0); } - *sp = c; if (buf[0] == '?' && buf[1] == '\n') { printf("Valid inputs are: "); for (i = 0, match = 18; list[i]; i++) { - if ((match+=(n_match=strlen(list[i]))) > LINE) { + if ((match += (n_match = strlen(list[i]))) > LINE) { printf("\n\t"); match = n_match + 8; } @@ -92,7 +88,9 @@ inter: } continue; } - *sp = '\0'; + sp = buf + strlen(buf) - 1; + if (*sp == '\n') + *sp = '\0'; for (sp = buf; *sp; sp++) if (isupper(*sp)) *sp = tolower(*sp); @@ -106,13 +104,14 @@ inter: else if (buf[0] != '\0') printf("Illegal response: \"%s\". Use '?' to get list of valid answers\n", buf); } + return 0; } -static +static int comp(s1) -char *s1; { - - reg char *sp, *tsp, c; + char *s1; +{ + char *sp, *tsp, c; if (buf[0] != '\0') for (sp = buf, tsp = s1; *sp; ) { diff --git a/games/monop/houses.c b/games/monop/houses.c index 1cb4b0a3ed2..eed8ae029ed 100644 --- a/games/monop/houses.c +++ b/games/monop/houses.c @@ -1,3 +1,4 @@ +/* $OpenBSD: houses.c,v 1.2 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: houses.c,v 1.3 1995/03/23 08:34:40 cgd Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)houses.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: houses.c,v 1.3 1995/03/23 08:34:40 cgd Exp $"; +static char rcsid[] = "$OpenBSD: houses.c,v 1.2 1998/09/20 23:36:51 pjanzen Exp $"; #endif #endif /* not lint */ @@ -48,14 +49,19 @@ static char *names[N_MON+2], static MON *monops[N_MON]; +static void buy_h __P((MON *)); +static void sell_h __P((MON *)); +static void list_cur __P((MON *)); + /* * These routines deal with buying and selling houses */ -buy_houses() { - - reg int num_mon; - reg MON *mp; - reg OWN *op; +void +buy_houses() +{ + int num_mon; + MON *mp; + OWN *op; bool good,got_morg; int i,p; @@ -104,12 +110,13 @@ over: } } +static void buy_h(mnp) -MON *mnp; { - - reg int i; - reg MON *mp; - reg int price; + MON *mnp; +{ + int i; + MON *mp; + int price; shrt input[3],temp[3]; int tot; PROP *pp; @@ -150,7 +157,7 @@ err: printf("That makes the spread too wide. Try again\n"); tot += input[i]; if (tot) { printf("You asked for %d houses for $%d\n", tot, tot * price); - if (getyn("Is that ok? ", yn) == 0) { + if (getyn("Is that ok? ") == 0) { cur_p->money -= tot * price; for (tot = i = 0; i < mp->num_in; i++) mp->sq[i]->desc->houses = temp[i]; @@ -161,11 +168,12 @@ err: printf("That makes the spread too wide. Try again\n"); /* * This routine sells houses. */ -sell_houses() { - - reg int num_mon; - reg MON *mp; - reg OWN *op; +void +sell_houses() +{ + int num_mon; + MON *mp; + OWN *op; bool good; int p; @@ -203,12 +211,13 @@ over: } } +static void sell_h(mnp) -MON *mnp; { - - reg int i; - reg MON *mp; - reg int price; + MON *mnp; +{ + int i; + MON *mp; + int price; shrt input[3],temp[3]; int tot; PROP *pp; @@ -250,7 +259,7 @@ err: printf("That makes the spread too wide. Try again\n"); tot += input[i]; if (tot) { printf("You asked to sell %d houses for $%d\n",tot,tot * price); - if (getyn("Is that ok? ", yn) == 0) { + if (getyn("Is that ok? ") == 0) { cur_p->money += tot * price; for (tot = i = 0; i < mp->num_in; i++) mp->sq[i]->desc->houses = temp[i]; @@ -258,11 +267,12 @@ err: printf("That makes the spread too wide. Try again\n"); } } +static void list_cur(mp) -reg MON *mp; { - - reg int i; - reg SQUARE *sqp; + MON *mp; +{ + int i; + SQUARE *sqp; for (i = 0; i < mp->num_in; i++) { sqp = mp->sq[i]; diff --git a/games/monop/initdeck.c b/games/monop/initdeck.c index 5cc371cb5c8..1f712d86f7d 100644 --- a/games/monop/initdeck.c +++ b/games/monop/initdeck.c @@ -1,3 +1,4 @@ +/* $OpenBSD: initdeck.c,v 1.6 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: initdeck.c,v 1.3 1995/03/23 08:34:43 cgd Exp $ */ /* @@ -43,12 +44,15 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)initdeck.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: initdeck.c,v 1.3 1995/03/23 08:34:43 cgd Exp $"; +static char rcsid[] = "$OpenBSD: initdeck.c,v 1.6 1998/09/20 23:36:51 pjanzen Exp $"; #endif #endif /* not lint */ -# include <stdio.h> -# include "deck.h" +#include <err.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include "deck.h" /* * This program initializes the card files for monopoly. @@ -61,25 +65,27 @@ static char rcsid[] = "$NetBSD: initdeck.c,v 1.3 1995/03/23 08:34:43 cgd Exp $"; * string to print, terminated with a null byte. */ -# define TRUE 1 -# define FALSE 0 +#define TRUE 1 +#define FALSE 0 -# define bool int8_t -# define reg register +#define bool int8_t char *infile = "cards.inp", /* input file */ *outfile = "cards.pck"; /* "packed" file */ -extern long ftell(); -extern char *calloc(); - DECK deck[2]; FILE *inf, *outf; +static void getargs __P((int, char *[])); +static void count __P((void)); +static void putem __P((void)); + +int main(ac, av) -int ac; -char *av[]; { + int ac; + char *av[]; +{ int n; /* revoke */ @@ -87,21 +93,20 @@ char *av[]; { setgid(getgid()); getargs(ac, av); - if ((inf = fopen(infile, "r")) == NULL) { - perror(infile); - exit(1); - } + if ((inf = fopen(infile, "r")) == NULL) + err(1, infile); count(); /* * allocate space for pointers. */ - CC_D.offsets = (int32_t *)calloc(CC_D.num_cards + 1, sizeof (int32_t)); - CH_D.offsets = (int32_t *)calloc(CH_D.num_cards + 1, sizeof (int32_t)); + if ((CC_D.offsets = (int32_t *)calloc(CC_D.num_cards + 1, + sizeof (int32_t))) == NULL || + (CH_D.offsets = (int32_t *)calloc(CH_D.num_cards + 1, + sizeof (int32_t))) == NULL) + errx(1, "malloc"); fseek(inf, 0L, 0); - if ((outf = fopen(outfile, "w")) == NULL) { - perror(outfile); - exit(0); - } + if ((outf = fopen(outfile, "w")) == NULL) + err(1, outfile); fwrite(&deck[0].num_cards, sizeof(deck[0].num_cards), 1, outf); fwrite(&deck[0].last_card, sizeof(deck[0].last_card), 1, outf); @@ -146,10 +151,11 @@ char *av[]; { exit(0); } +static void getargs(ac, av) -int ac; -char *av[]; { - + int ac; + char *av[]; +{ if (ac > 1) infile = av[1]; if (ac > 2) @@ -159,11 +165,12 @@ char *av[]; { /* * count the cards */ -count() { - - reg bool newline; - reg DECK *in_deck; - reg int c; +static void +count() +{ + bool newline; + DECK *in_deck; + int c; newline = TRUE; in_deck = &CC_D; @@ -181,12 +188,13 @@ count() { /* * put strings in the file */ -putem() { - - reg bool newline; - reg DECK *in_deck; - reg int c; - int16_t num; +static void +putem() +{ + bool newline; + DECK *in_deck; + int c; + int16_t num; in_deck = &CC_D; CC_D.num_cards = 1; diff --git a/games/monop/jail.c b/games/monop/jail.c index 060553150bd..665c4c20d7c 100644 --- a/games/monop/jail.c +++ b/games/monop/jail.c @@ -1,3 +1,4 @@ +/* $OpenBSD: jail.c,v 1.2 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: jail.c,v 1.3 1995/03/23 08:34:44 cgd Exp $ */ /* @@ -37,18 +38,19 @@ #if 0 static char sccsid[] = "@(#)jail.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: jail.c,v 1.3 1995/03/23 08:34:44 cgd Exp $"; +static char rcsid[] = "$OpenBSD: jail.c,v 1.2 1998/09/20 23:36:51 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include "monop.ext" /* * This routine uses a get-out-of-jail-free card to get the * player out of jail. */ -card() { - +void +card() +{ if (cur_p->loc != JAIL) { printf("But you're not IN Jail\n"); return; @@ -65,9 +67,10 @@ card() { * This routine returns the players get-out-of-jail-free card * to a deck. */ +void ret_card(plr) -reg PLAY *plr; { - + PLAY *plr; +{ plr->num_gojf--; if (CC_D.gojf_used) CC_D.gojf_used = FALSE; @@ -77,8 +80,9 @@ reg PLAY *plr; { /* * This routine deals with paying your way out of jail. */ -pay() { - +void +pay() +{ if (cur_p->loc != JAIL) { printf("But you're not IN Jail\n"); return; @@ -91,9 +95,10 @@ pay() { /* * This routine deals with a move in jail */ +int move_jail(r1, r2) -reg int r1, r2; { - + int r1, r2; +{ if (r1 != r2) { printf("Sorry, that doesn't get you out\n"); if (++(cur_p->in_jail) == 3) { @@ -113,8 +118,10 @@ moveit: goto moveit; } } -printturn() { +void +printturn() +{ if (cur_p->loc != JAIL) return; printf("(This is your "); diff --git a/games/monop/misc.c b/games/monop/misc.c index b2e89a4c31f..2ba193c67d3 100644 --- a/games/monop/misc.c +++ b/games/monop/misc.c @@ -1,3 +1,4 @@ +/* $OpenBSD: misc.c,v 1.3 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $ */ /* @@ -37,22 +38,23 @@ #if 0 static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: misc.c,v 1.4 1995/03/23 08:34:47 cgd Exp $"; +static char rcsid[] = "$OpenBSD: misc.c,v 1.3 1998/09/20 23:36:51 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" -# include <ctype.h> -# include <signal.h> +#include "monop.ext" +#include <ctype.h> +#include <signal.h> /* * This routine executes a truncated set of commands until a * "yes or "no" answer is gotten. */ +int getyn(prompt) -reg char *prompt; { - - reg int com; + char *prompt; +{ + int com; for (;;) if ((com=getinp(prompt, yn)) < 2) @@ -63,8 +65,9 @@ reg char *prompt; { /* * This routine tells the player if he's out of money. */ -notify() { - +void +notify() +{ if (cur_p->money < 0) printf("That leaves you $%d in debt\n", -cur_p->money); else if (cur_p->money == 0) @@ -77,8 +80,9 @@ notify() { /* * This routine switches to the next player */ -next_play() { - +void +next_play() +{ player = ++player % num_play; cur_p = &play[player]; num_doub = 0; @@ -87,21 +91,30 @@ next_play() { * This routine gets an integer from the keyboard after the * given prompt. */ +int get_int(prompt) -reg char *prompt; { - - reg int num; - reg char *sp; - int c; - char buf[257]; + char *prompt; +{ + int num; + char *sp; + int c, i; + char buf[257]; for (;;) { -inter: printf(prompt); num = 0; - for (sp = buf; (c = getchar()) != '\n'; *sp++ = c) - if (c == -1) /* check for interrupted system call */ - goto inter; + i = 0; + for (sp = buf; (c = getchar()) != '\n';) { + if (c == EOF) { + printf("user closed input stream, quitting...\n"); + exit(0); + } + *sp = c; + if (i < sizeof(buf)) { + i++; + sp++; + } + } *sp = c; if (sp == buf) continue; @@ -118,17 +131,18 @@ inter: /* * This routine sets the monopoly flag from the list given. */ +void set_ownlist(pl) -int pl; { - - reg int num; /* general counter */ - reg MON *orig; /* remember starting monop ptr */ - reg OWN *op; /* current owned prop */ + int pl; +{ + int num; /* general counter */ + MON *orig; /* remember starting monop ptr */ + OWN *op; /* current owned prop */ OWN *orig_op; /* origianl prop before loop */ op = play[pl].own_list; #ifdef DEBUG - printf("op [%d] = play[pl [%d] ].own_list;\n", op, pl); + printf("op [%p] = play[pl [%d] ].own_list;\n", op, pl); #endif while (op) { #ifdef DEBUG @@ -153,7 +167,7 @@ int pl; { for (num = 0; op && op->sqr->type == RR; op = op->next) { #ifdef DEBUG printf("iter: %d\n", num); - printf("op = %d, op->sqr = %d, op->sqr->type = %d\n", op, op->sqr, op->sqr->type); + printf("op = %p, op->sqr = %p, op->sqr->type = %d\n", op, op->sqr, op->sqr->type); #endif num++; } @@ -179,24 +193,24 @@ int pl; { #endif op = op->next; #ifdef DEBUG - printf("[%d];\n", op); + printf("[%p];\n", op); #endif } #ifdef DEBUG printf("num = %d\n"); #endif if (orig == 0) { - printf("panic: bad monopoly descriptor: orig = %d\n", orig); + printf("panic: bad monopoly descriptor: orig = %p\n", orig); printf("player # %d\n", pl+1); printhold(pl); - printf("orig_op = %d\n", orig_op); + printf("orig_op = %p\n", orig_op); printf("orig_op->sqr->type = %d (PRPTY)\n", op->sqr->type); - printf("orig_op->next = %d\n", op->next); - printf("orig_op->sqr->desc = %d\n", op->sqr->desc); - printf("op = %d\n", op); + printf("orig_op->next = %p\n", op->next); + printf("orig_op->sqr->desc = %p\n", op->sqr->desc); + printf("op = %p\n", op); printf("op->sqr->type = %d (PRPTY)\n", op->sqr->type); - printf("op->next = %d\n", op->next); - printf("op->sqr->desc = %d\n", op->sqr->desc); + printf("op->next = %p\n", op->next); + printf("op->sqr->desc = %p\n", op->sqr->desc); printf("num = %d\n", num); } #ifdef DEBUG @@ -213,12 +227,12 @@ int pl; { /* * This routine sets things up as if it is a new monopoly */ +void is_monop(mp, pl) -reg MON *mp; -int pl; { - - reg char *sp; - reg int i; + MON *mp; + int pl; +{ + int i; mp->owner = pl; mp->num_own = mp->num_in; @@ -229,11 +243,11 @@ int pl; { /* * This routine sets things up as if it is no longer a monopoly */ +void isnot_monop(mp) -reg MON *mp; { - - reg char *sp; - reg int i; + MON *mp; +{ + int i; mp->owner = -1; for (i = 0; i < mp->num_in; i++) @@ -243,16 +257,18 @@ reg MON *mp; { /* * This routine gives a list of the current player's routine */ -list() { - +void +list() +{ printhold(player); } /* * This routine gives a list of a given players holdings */ -list_all() { - - reg int pl; +void +list_all() +{ + int pl; while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play) printhold(pl); @@ -261,20 +277,9 @@ list_all() { * This routine gives the players a chance before it exits. */ void -quit() { - +quit() +{ putchar('\n'); - if (getyn("Do you all really want to quit? ", yn) == 0) + if (getyn("Do you all really want to quit? ") == 0) exit(0); - signal(SIGINT, quit); -} -/* - * This routine copies one structure to another - */ -cpy_st(s1, s2, size) -reg int *s1, *s2, size; { - - size /= 2; - while (size--) - *s1++ = *s2++; } diff --git a/games/monop/mon.dat b/games/monop/mon.dat index bfafa4c027b..87647e06464 100644 --- a/games/monop/mon.dat +++ b/games/monop/mon.dat @@ -1,3 +1,4 @@ +/* $OpenBSD: mon.dat,v 1.2 1998/09/20 23:36:51 pjanzen Exp $ */ /* $NetBSD: mon.dat,v 1.2 1995/03/23 08:34:49 cgd Exp $ */ /*- diff --git a/games/monop/monop.6 b/games/monop/monop.6 index 5412a616901..b841d6fe3d4 100644 --- a/games/monop/monop.6 +++ b/games/monop/monop.6 @@ -1,4 +1,4 @@ -.\" $NetBSD: monop.6,v 1.8 1995/03/23 08:34:50 cgd Exp $ +.\" $OpenBSD: monop.6,v 1.2 1998/09/20 23:36:52 pjanzen Exp $ .\" .\" Copyright (c) 1980 The Regents of the University of California. .\" All rights reserved. @@ -40,17 +40,17 @@ .Nm monop .Nd Monopoly game .Sh SYNOPSIS -.Nm /usr/games/monop +.Nm .Op Ar file .Sh DESCRIPTION -.Nm Monop +.Nm is reminiscent of the Parker Brother's game Monopoly, and monitors a game between 1 to 9 users. It is assumed that the rules of Monopoly are known. The game follows the standard rules, with the exception that, if a property goes up for auction and there are only two solvent players, no auction is held and the property remains unowned. -.Nm +.Pp The game, in effect, lends the player money, so it is possible to buy something which you cannot afford. However, as soon as a person goes into debt, @@ -73,9 +73,9 @@ It is not possible to input a negative number, nor is it ever necessary. .Em A Summary of Commands : .Bl -tag -width item .It Ic quit -quit game: This allows you to quit the game. It asks you if you're sure. +quit game. It asks you if you're sure. .It Ic print -print board: This prints out the current board. +print current board. The columns have the following meanings (column headings are the same for the .Ic where , .Ic own holdings , @@ -104,58 +104,55 @@ If the property is land, this is the number of houses on it. Current rent on the property. If it is not owned, there is no rent. .El .It Ic where -where players are: Tells you where all the players are. +tell where players are. A `*' indicates the current player. .It Ic own holdings -List your own holdings, +list your own holdings, .Em i.e. , money, get-out-of-jail-free cards, and property. .It Ic holdings -holdings list: Look at anyone's holdings. +show holdings list: look at anyone's holdings. It will ask you whose holdings you wish to look at. When you are finished, type .Sq Ic done . .It Ic mortgage mortgage property: -Sets up a list of mortgageable property, and asks which you wish to mortgage. +sets up a list of mortgageable property, and asks which you wish to mortgage. .It Ic unmortgage unmortgage property: -Unmortgage mortgaged property. +unmortgage mortgaged property. .It Ic buy buy houses: -Sets up a list of monopolies on which you can buy houses. +sets up a list of monopolies on which you can buy houses. If there is more than one, it asks you which you want to buy for. It then asks you how many for each piece of property, giving the current amount in parentheses after the property name. If you build in an unbalanced manner (a disparity of more than one house within the same monopoly), -it asks you to re-input things. +it asks you to re-input. .It Ic sell sell houses: -Sets up a list of monopolies from which you can sell houses. +sets up a list of monopolies from which you can sell houses. It operates in an analogous manner to .Ic buy. .It Ic card -card for jail: -Use a get-out-of-jail-free card to get out of jail. +use a get-out-of-jail-free card to get out of jail. If you're not in jail, or you don't have one, it tells you so. .It Ic pay -pay for jail: -Pay $50 to get out of jail, from whence you are put on Just Visiting. +pay $50 to get out of jail, from whence you are put on Just Visiting. Difficult to do if you're not there. .It Ic trade -This allows you to trade with another player. -It asks you whom you wish to trade with, +trade with another player. +It asks you with whom you wish to trade, and then asks you what each wishes to give up. You can get a summary at the end, and, in all cases, it asks for confirmation of the trade before doing it. .It Ic resign -Resign to another player or the bank. +resign to another player or the bank. If you resign to the bank, all property reverts to its virgin state, and get-out-of-jail free cards revert to the deck. .It Ic save -save game: -Save the current game in a file for later play. +save the current game in a file for later play. You can continue play after saving, either by adding the file in which you saved the game after the .Nm monop @@ -165,11 +162,10 @@ command (see below). It will ask you which file you wish to save it in, and, if the file exists, confirm that you wish to overwrite it. .It Ic restore -restore game: -Read in a previously saved game from a file. +read in a previously saved game from a file. It leaves the file intact. .It Ic roll -Roll the dice and move forward to your new location. +roll the dice and move forward to your new location. If you simply hit the <RETURN> key instead of a command, it is the same as typing .Ic roll . @@ -183,3 +179,5 @@ Chance and Community Chest cards .El .Sh BUGS No command can be given an argument instead of a response to a query. +.Pp +While saving a game works pretty well, restoring one does not. diff --git a/games/monop/monop.c b/games/monop/monop.c index 8e33522688c..316b6ab5388 100644 --- a/games/monop/monop.c +++ b/games/monop/monop.c @@ -1,3 +1,4 @@ +/* $OpenBSD: monop.c,v 1.2 1998/09/20 23:36:52 pjanzen Exp $ */ /* $NetBSD: monop.c,v 1.3 1995/03/23 08:34:52 cgd Exp $ */ /* @@ -43,21 +44,30 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)monop.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: monop.c,v 1.3 1995/03/23 08:34:52 cgd Exp $"; +static char rcsid[] = "$OpenBSD: monop.c,v 1.2 1998/09/20 23:36:52 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.def" +#include <err.h> +#include <signal.h> +#include <stdlib.h> +#include <unistd.h> +#include "monop.def" + +static void getplayers __P((void)); +static void init_players __P((void)); +static void init_monops __P((void)); +static void do_quit __P((int)); /* * This program implements a monopoly game */ +int main(ac, av) -reg int ac; -reg char *av[]; { - - - srand(getpid()); + int ac; + char *av[]; +{ + srandom(getpid()); if (ac > 1) { if (!rest_f(av[1])) restore(); @@ -69,7 +79,7 @@ reg char *av[]; { } num_luck = sizeof lucky_mes / sizeof (char *); init_decks(); - signal(2, quit); + signal(SIGQUIT, do_quit); for (;;) { printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1, cur_p->money, board[cur_p->loc].name); @@ -78,42 +88,57 @@ reg char *av[]; { execute(getinp("-- Command: ", comlist)); } } + +static void +do_quit(n) + int n; +{ + quit(); +} /* * This routine gets the names of the players */ -getplayers() { - - reg char *sp; - reg int i, j; - char buf[257]; +static void +getplayers() +{ + char *sp; + int i, j; + char buf[257]; blew_it: for (;;) { - if ((num_play=get_int("How many players? ")) <= 0 || + if ((num_play = get_int("How many players? ")) <= 1 || num_play > MAX_PL) - printf("Sorry. Number must range from 1 to 9\n"); + printf("Sorry. Number must range from 2 to 9\n"); else break; } - cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY)); + if ((cur_p = play = (PLAY *) calloc(num_play, sizeof (PLAY))) == NULL) + errx(1, "malloc"); for (i = 0; i < num_play; i++) { -over: - printf("Player %d's name: ", i + 1); - for (sp = buf; (*sp=getchar()) != '\n'; sp++) - continue; - if (sp == buf) - goto over; - *sp++ = '\0'; - strcpy(name_list[i]=play[i].name=(char *)calloc(1,sp-buf),buf); + do { + printf("Player %d's name: ", i + 1); + fgets(buf, sizeof(buf), stdin); + if ((feof(stdin))) { + printf("user closed input stream, quitting...\n"); + exit(0); + } + sp = buf + strlen(buf) - 1; + if (*sp == '\n') + *sp = '\0'; + } while (strlen(buf) == 0); + if ((name_list[i] = play[i].name = (char *)calloc(1, sizeof(buf))) == NULL) + errx(1, "malloc"); + strcpy(name_list[i], buf); play[i].money = 1500; } name_list[i++] = "done"; name_list[i] = 0; for (i = 0; i < num_play; i++) - for (j = i + 1; j < num_play; j++) + for (j = i + 1; j <= num_play; j++) if (strcasecmp(name_list[i], name_list[j]) == 0) { - if (i != num_play - 1) - printf("Hey!!! Some of those are IDENTICAL!! Let's try that again....\n"); + if (j != num_play) + printf("Hey!!! Some of those are IDENTICAL!! Let's try that again...\n"); else printf("\"done\" is a reserved word. Please try again\n"); for (i = 0; i < num_play; i++) @@ -125,11 +150,12 @@ over: /* * This routine figures out who goes first */ -init_players() { - - reg int i, rl, cur_max; - bool over; - int max_pl; +static void +init_players() +{ + int i, rl, cur_max; + bool over = 0; + int max_pl = 0; again: putchar('\n'); @@ -155,10 +181,11 @@ again: /* * This routine initalizes the monopoly structures. */ -init_monops() { - - reg MON *mp; - reg int i; +static void +init_monops() +{ + MON *mp; + int i; for (mp = mon; mp < &mon[N_MON]; mp++) { mp->name = mp->not_m; diff --git a/games/monop/monop.def b/games/monop/monop.def index 344c4f49b4c..3a187b2a27b 100644 --- a/games/monop/monop.def +++ b/games/monop/monop.def @@ -1,3 +1,4 @@ +/* $OpenBSD: monop.def,v 1.2 1998/09/20 23:36:52 pjanzen Exp $ */ /* $NetBSD: monop.def,v 1.3 1995/03/23 08:34:54 cgd Exp $ */ /*- @@ -35,8 +36,8 @@ * @(#)monop.def 5.5 (Berkeley) 5/31/93 */ -# include "monop.h" -# include "deck.h" +#include "deck.h" +#include "monop.h" bool fixing, /* set if fixing up debt */ trading, /* set if in process of trading */ @@ -77,13 +78,10 @@ int player, /* current player number */ num_play, /* current number of players */ num_doub, /* # of doubles current player rolled */ /* # of "got lucky" messages */ - num_luck = sizeof lucky_mes / sizeof (char *), - /* list of command functions */ - buy_houses(), card(), do_move(), do_move(), list(), list_all(), - mortgage(), pay(), printboard(), quit(), resign(), restore(), - rub(), save(), sell_houses(), trade(), - unmortgage(), where(), - (*func[])() = { /* array of function calls for commands */ + num_luck = sizeof lucky_mes / sizeof (char *); + +/* list of command functions */ +void (*func[]) __P((void)) = { /* array of function calls for commands */ quit, /* quit game |* 0 *| */ printboard, /* print board |* 1 *| */ where, /* where players are |* 2 *| */ @@ -108,18 +106,18 @@ DECK deck[2]; /* Chance and Community Chest */ PLAY *play, /* player structure array ("calloc"ed) */ *cur_p; /* pointer to current player's struct */ -RR_S rr[N_RR]; /* raildroad descriptions */ +RR_S rr[N_RR]; /* railroad descriptions */ UTIL_S util[2]; /* utility descriptions */ MON mon[N_MON] = { /* monopoly descriptions */ -# include "mon.dat" +#include "mon.dat" }; PROP prop[N_PROP] = { /* typical properties */ -# include "prop.dat" +#include "prop.dat" }; SQUARE board[N_SQRS+1] = { /* board itself (+1 for Jail) */ -# include "brd.dat" +#include "brd.dat" }; diff --git a/games/monop/monop.ext b/games/monop/monop.ext index ea955a88fc9..c46b073c8e6 100644 --- a/games/monop/monop.ext +++ b/games/monop/monop.ext @@ -1,3 +1,4 @@ +/* $OpenBSD: monop.ext,v 1.2 1998/09/20 23:36:54 pjanzen Exp $ */ /* $NetBSD: monop.ext,v 1.2 1995/03/23 08:34:58 cgd Exp $ */ /*- @@ -35,8 +36,8 @@ * @(#)monop.ext 5.4 (Berkeley) 5/31/93 */ -# include "monop.h" -# include "deck.h" +#include "deck.h" +#include "monop.h" extern bool trading, spec, fixing, told_em; @@ -46,14 +47,14 @@ extern int num_play, player, num_doub, num_luck, (*func[])(); extern DECK deck[2]; -extern MON mon[]; +extern MON mon[N_MON]; extern PLAY *play, *cur_p; -extern PROP prop[]; +extern PROP prop[N_PROP]; -extern RR_S rr[]; +extern RR_S rr[N_RR]; -extern SQUARE board[]; +extern SQUARE board[N_SQRS + 1]; -extern UTIL_S util[]; +extern UTIL_S util[2]; diff --git a/games/monop/monop.h b/games/monop/monop.h index fd9981ac8ce..75c8bdd5e06 100644 --- a/games/monop/monop.h +++ b/games/monop/monop.h @@ -1,3 +1,4 @@ +/* $OpenBSD: monop.h,v 1.4 1998/09/20 23:36:54 pjanzen Exp $ */ /* $NetBSD: monop.h,v 1.4 1995/04/24 12:24:23 cgd Exp $ */ /* @@ -35,52 +36,45 @@ * @(#)monop.h 8.1 (Berkeley) 5/31/93 */ -# include <stdio.h> -# include <stdlib.h> -# include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> -# define reg register #ifdef __CHAR_UNSIGNED__ -# define shrt short +#define shrt short #else -# define shrt char +#define shrt char #endif -# define bool int8_t -# define unsgn unsigned - -# define TRUE (1) -# define FALSE (0) - -# define N_MON 8 /* number of monopolies */ -# define N_PROP 22 /* number of normal property squares */ -# define N_RR 4 /* number of railroads */ -# define N_UTIL 2 /* number of utilities */ -# define N_SQRS 40 /* number of squares on board */ -# define MAX_PL 9 /* maximum number of players */ -# define MAX_PRP (N_PROP+N_RR+N_UTIL) /* max # ownable property */ - - /* square type numbers */ -# define PRPTY 0 /* normal property */ -# define RR 1 /* railroad */ -# define UTIL 2 /* water works - electric co */ -# define SAFE 3 /* safe spot */ -# define CC 4 /* community chest */ -# define CHANCE 5 /* chance (surprise!!!) */ -# define INC_TAX 6 /* Income tax */ -# define GOTO_J 7 /* Go To Jail! */ -# define LUX_TAX 8 /* Luxury tax */ -# define IN_JAIL 9 /* In jail */ - -# define JAIL 40 /* JAIL square number */ - -# define lucky(str) printf("%s%s\n",str,lucky_mes[roll(1,num_luck)-1]) -# define printline() printf("------------------------------\n") -# define sqnum(sqp) (sqp - board) -# define swap(A1,A2) if ((A1) != (A2)) { \ - (A1) ^= (A2); \ - (A2) ^= (A1); \ - (A1) ^= (A2); \ - } +#define bool int8_t + +#define TRUE (1) +#define FALSE (0) + +#define N_MON 8 /* number of monopolies */ +#define N_PROP 22 /* number of normal property squares */ +#define N_RR 4 /* number of railroads */ +#define N_UTIL 2 /* number of utilities */ +#define N_SQRS 40 /* number of squares on board */ +#define MAX_PL 9 /* maximum number of players */ +#define MAX_PRP (N_PROP+N_RR+N_UTIL) /* max # ownable property */ + + /* square type numbers */ +#define PRPTY 0 /* normal property */ +#define RR 1 /* railroad */ +#define UTIL 2 /* water works - electric co */ +#define SAFE 3 /* safe spot */ +#define CC 4 /* community chest */ +#define CHANCE 5 /* chance (surprise!!!) */ +#define INC_TAX 6 /* Income tax */ +#define GOTO_J 7 /* Go To Jail! */ +#define LUX_TAX 8 /* Luxury tax */ +#define IN_JAIL 9 /* In jail */ + +#define JAIL 40 /* JAIL square number */ + +#define lucky(str) printf("%s%s\n",str,lucky_mes[roll(1,num_luck)-1]) +#define printline() printf("------------------------------\n") +#define sqnum(sqp) (sqp - board) struct sqr_st { /* structure for square */ char *name; /* place name */ @@ -134,7 +128,7 @@ struct plr_st { /* player description structure */ shrt loc; /* location on board */ shrt in_jail; /* count of turns in jail */ int money; /* amount of money */ - OWN *own_list; /* start of propery list */ + OWN *own_list; /* start of property list */ }; typedef struct plr_st PLAY; @@ -142,4 +136,75 @@ typedef struct prp_st PROP; typedef struct prp_st RR_S; typedef struct prp_st UTIL_S; -int cc(), chance(), lux_tax(), goto_jail(), inc_tax(); +/* cards.c */ +void init_decks __P((void)); +void get_card __P((DECK *)); + +/* execute.c */ +void execute __P((int)); +void do_move __P((void)); +void move __P((int)); +void save __P((void)); +void restore __P((void)); +int rest_f __P((char *)); + +/* getinp.c */ +int getinp __P((char *, char *[])); + +/* houses.c */ +void buy_houses __P((void)); +void sell_houses __P((void)); + +/* jail.c */ +void card __P((void)); +void ret_card __P((PLAY *)); +void pay __P((void)); +int move_jail __P((int, int )); +void printturn __P((void)); + +/* misc.c */ +int getyn __P((char *)); +void notify __P((void)); +void next_play __P((void)); +int get_int __P((char *)); +void set_ownlist __P((int)); +void is_monop __P((MON *, int)); +void isnot_monop __P((MON *)); +void list __P((void)); +void list_all __P((void)); +void quit __P((void)); + +/* morg.c */ +void mortgage __P((void)); +void unmortgage __P((void)); +void force_morg __P((void)); + +/* print.c */ +void printboard __P((void)); +void where __P((void)); +void printsq __P((int, bool)); +void printhold __P((int)); + +/* prop.c */ +void buy __P((int, SQUARE *)); +void add_list __P((int, OWN **, int)); +void del_list __P((int, OWN **, shrt)); +void bid __P((void)); +int prop_worth __P((PLAY *)); + +/* rent.c */ +void rent __P((SQUARE *)); + +/* roll.c */ +int roll __P((int, int)); + +/* spec.c */ +void inc_tax __P((void)); +void goto_jail __P((void)); +void lux_tax __P((void)); +void cc __P((void)); +void chance __P((void)); + +/* trade.c */ +void trade __P((void)); +void resign __P((void)); diff --git a/games/monop/morg.c b/games/monop/morg.c index 957085644c1..46c027242ec 100644 --- a/games/monop/morg.c +++ b/games/monop/morg.c @@ -1,3 +1,4 @@ +/* $OpenBSD: morg.c,v 1.2 1998/09/20 23:36:54 pjanzen Exp $ */ /* $NetBSD: morg.c,v 1.4 1995/03/23 08:35:02 cgd Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)morg.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: morg.c,v 1.4 1995/03/23 08:35:02 cgd Exp $"; +static char rcsid[] = "$OpenBSD: morg.c,v 1.2 1998/09/20 23:36:54 pjanzen Exp $"; #endif #endif /* not lint */ @@ -71,14 +72,20 @@ static shrt square[MAX_PRP+2]; static int num_good,got_houses; +static int set_mlist __P((void)); +static void m __P((int)); +static int set_umlist __P((void)); +static void unm __P((int)); + /* * This routine is the command level response the mortgage command. * it gets the list of mortgageable property and asks which are to * be mortgaged. */ -mortgage() { - - reg int prop; +void +mortgage() +{ + int prop; for (;;) { if (set_mlist() == 0) { @@ -89,34 +96,36 @@ mortgage() { return; } if (num_good == 1) { - printf("Your only mortageable property is %s\n",names[0]); + printf("Your only mortageable property is %s\n", names[0]); if (getyn("Do you want to mortgage it? ") == 0) m(square[0]); return; } - prop = getinp("Which property do you want to mortgage? ",names); + prop = getinp("Which property do you want to mortgage? ", names); if (prop == num_good) return; m(square[prop]); - notify(cur_p); + notify(); } } /* * This routine sets up the list of mortgageable property */ -set_mlist() { - - reg OWN *op; +static int +set_mlist() +{ + OWN *op; num_good = 0; for (op = cur_p->own_list; op; op = op->next) - if (!op->sqr->desc->morg) + if (!op->sqr->desc->morg) { if (op->sqr->type == PRPTY && op->sqr->desc->houses) got_houses++; else { names[num_good] = op->sqr->name; square[num_good++] = sqnum(op->sqr); } + } names[num_good++] = "done"; names[num_good--] = 0; return num_good; @@ -124,10 +133,11 @@ set_mlist() { /* * This routine actually mortgages the property. */ +static void m(prop) -reg int prop; { - - reg int price; + int prop; +{ + int price; price = board[prop].cost/2; board[prop].desc->morg = TRUE; @@ -139,9 +149,10 @@ reg int prop; { * command. It gets the list of mortgaged property and asks which are * to be unmortgaged. */ -unmortgage() { - - reg int prop; +void +unmortgage() +{ + int prop; for (;;) { if (set_umlist() == 0) { @@ -149,12 +160,12 @@ unmortgage() { return; } if (num_good == 1) { - printf("Your only mortaged property is %s\n",names[0]); + printf("Your only mortaged property is %s\n", names[0]); if (getyn("Do you want to unmortgage it? ") == 0) unm(square[0]); return; } - prop = getinp("Which property do you want to unmortgage? ",names); + prop = getinp("Which property do you want to unmortgage? ", names); if (prop == num_good) return; unm(square[prop]); @@ -163,9 +174,10 @@ unmortgage() { /* * This routine sets up the list of mortgaged property */ -set_umlist() { - - reg OWN *op; +static int +set_umlist() +{ + OWN *op; num_good = 0; for (op = cur_p->own_list; op; op = op->next) @@ -180,10 +192,11 @@ set_umlist() { /* * This routine actually unmortgages the property */ +static void unm(prop) -reg int prop; { - - reg int price; + int prop; +{ + int price; price = board[prop].cost/2; board[prop].desc->morg = FALSE; @@ -196,20 +209,14 @@ reg int prop; { * This routine forces the indebted player to fix his * financial woes. */ -force_morg() { - +void +force_morg() +{ told_em = fixing = TRUE; - while (cur_p->money <= 0) - fix_ex(getinp("How are you going to fix it up? ",morg_coms)); + while (cur_p->money <= 0) { + told_em = FALSE; + (*func[(getinp("How are you going to fix it up? ",morg_coms))])(); + notify(); + } fixing = FALSE; } -/* - * This routine is a special execute for the force_morg routine - */ -fix_ex(com_num) -reg int com_num; { - - told_em = FALSE; - (*func[com_num])(); - notify(); -} diff --git a/games/monop/pathnames.h b/games/monop/pathnames.h index e0cc52f2d4a..8f23847388f 100644 --- a/games/monop/pathnames.h +++ b/games/monop/pathnames.h @@ -1,3 +1,4 @@ +/* $OpenBSD: pathnames.h,v 1.2 1998/09/20 23:36:55 pjanzen Exp $ */ /* $NetBSD: pathnames.h,v 1.3 1995/03/23 08:35:03 cgd Exp $ */ /*- diff --git a/games/monop/print.c b/games/monop/print.c index eb49d1fc0f5..69ab9e3e838 100644 --- a/games/monop/print.c +++ b/games/monop/print.c @@ -1,3 +1,4 @@ +/* $OpenBSD: print.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $ */ /* $NetBSD: print.c,v 1.3 1995/03/23 08:35:05 cgd Exp $ */ /* @@ -37,21 +38,23 @@ #if 0 static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: print.c,v 1.3 1995/03/23 08:35:05 cgd Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include "monop.ext" -static char buf[80], /* output buffer */ - *header = "Name Own Price Mg # Rent"; +static char *header = "Name Own Price Mg # Rent"; + +static void printmorg __P((SQUARE *)); /* * This routine prints out the current board */ -printboard() { - - reg int i; +void +printboard() +{ + int i; printf("%s\t%s\n", header, header); for (i = 0; i < N_SQRS/2; i++) { @@ -63,10 +66,10 @@ printboard() { /* * This routine lists where each player is. */ -where() { - - reg int i; - char *bsp; +void +where() +{ + int i; printf("%s Player\n", header); for (i = 0; i < num_play; i++) { @@ -80,30 +83,29 @@ where() { /* * This routine prints out an individual square */ +void printsq(sqn, eoln) -int sqn; -reg bool eoln; { - - reg int rnt; - reg PROP *pp; - reg SQUARE *sqp; - int i; + int sqn; + bool eoln; +{ + int rnt; + PROP *pp; + SQUARE *sqp; sqp = &board[sqn]; printf("%-10.10s", sqp->name); switch (sqp->type) { - case SAFE: - case CC: - case CHANCE: - case INC_TAX: - case GOTO_J: - case LUX_TAX: - case IN_JAIL: -spec: + case SAFE: + case CC: + case CHANCE: + case INC_TAX: + case GOTO_J: + case LUX_TAX: + case IN_JAIL: if (!eoln) printf(" "); break; - case PRPTY: + case PRPTY: pp = sqp->desc; if (sqp->owner < 0) { printf(" - %-8.8s %3d", pp->mon_desc->name, sqp->cost); @@ -115,19 +117,18 @@ spec: sqp->cost); printmorg(sqp); if (pp->monop) { - if (pp->houses < 5) + if (pp->houses < 5) { if (pp->houses > 0) printf("%d %4d", pp->houses, pp->rent[pp->houses]); else printf("0 %4d", pp->rent[0] * 2); - else + } else printf("H %4d", pp->rent[5]); - } - else + } else printf(" %4d", pp->rent[0]); break; - case UTIL: + case UTIL: if (sqp->owner < 0) { printf(" - 150"); if (!eoln) @@ -140,7 +141,7 @@ spec: if (!eoln) printf(" "); break; - case RR: + case RR: if (sqp->owner < 0) { printf(" - Railroad 200"); if (!eoln) @@ -160,9 +161,10 @@ spec: /* * This routine prints out the mortgage flag. */ +static void printmorg(sqp) -reg SQUARE *sqp; { - + SQUARE *sqp; +{ if (sqp->desc->morg) printf(" * "); else @@ -171,12 +173,12 @@ reg SQUARE *sqp; { /* * This routine lists the holdings of the player given */ +void printhold(pl) -reg int pl; { - - reg OWN *op; - reg PLAY *pp; - char *bsp; + int pl; +{ + OWN *op; + PLAY *pp; pp = &play[pl]; printf("%s's (%d) holdings (Total worth: $%d):\n", name_list[pl], pl+1, diff --git a/games/monop/prop.c b/games/monop/prop.c index 77b1f6f1b8e..825d3800654 100644 --- a/games/monop/prop.c +++ b/games/monop/prop.c @@ -1,3 +1,4 @@ +/* $OpenBSD: prop.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $ */ /* $NetBSD: prop.c,v 1.3 1995/03/23 08:35:06 cgd Exp $ */ /* @@ -37,22 +38,24 @@ #if 0 static char sccsid[] = "@(#)prop.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: prop.c,v 1.3 1995/03/23 08:35:06 cgd Exp $"; +static char rcsid[] = "$OpenBSD: prop.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include <err.h> +#include "monop.ext" -extern char *calloc(); +static int value __P((SQUARE *)); /* * This routine deals with buying property, setting all the * appropriate flags. */ +void buy(player, sqrp) -reg int player; -reg SQUARE *sqrp; { - + int player; + SQUARE *sqrp; +{ trading = FALSE; sqrp->owner = player; add_list(player, &(play[player].own_list), cur_p->loc); @@ -60,17 +63,18 @@ reg SQUARE *sqrp; { /* * This routine adds an item to the list. */ +void add_list(plr, head, op_sqr) -int plr; -OWN **head; -int op_sqr; { - - reg int val; - reg OWN *tp, *last_tp; - MON *mp; + int plr; + OWN **head; + int op_sqr; +{ + int val; + OWN *tp, *last_tp; OWN *op; - op = (OWN *)calloc(1, sizeof (OWN)); + if ((op = (OWN *)calloc(1, sizeof (OWN))) == NULL) + errx(1, "malloc"); op->sqr = &board[op_sqr]; val = value(op->sqr); last_tp = NULL; @@ -92,22 +96,22 @@ int op_sqr; { /* * This routine deletes property from the list. */ +void del_list(plr, head, op_sqr) -int plr; -OWN **head; -shrt op_sqr; { - - reg int i; - reg OWN *op, *last_op; + int plr; + OWN **head; + shrt op_sqr; +{ + OWN *op, *last_op; switch (board[op_sqr].type) { - case PRPTY: + case PRPTY: board[op_sqr].desc->mon_desc->num_own--; break; - case RR: + case RR: play[plr].num_rr--; break; - case UTIL: + case UTIL: play[plr].num_util--; break; } @@ -128,25 +132,26 @@ shrt op_sqr; { * This routine calculates the value for sorting of the * given square. */ +static int value(sqp) -reg SQUARE *sqp; { - - reg int sqr; + SQUARE *sqp; +{ + int sqr; sqr = sqnum(sqp); switch (sqp->type) { - case SAFE: + case SAFE: return 0; - default: /* Specials, etc */ + default: /* Specials, etc */ return 1; - case UTIL: + case UTIL: if (sqr == 12) return 2; else return 3; - case RR: + case RR: return 4 + sqr/10; - case PRPTY: + case PRPTY: return 8 + (sqp->desc) - prop; } } @@ -154,11 +159,12 @@ reg SQUARE *sqp; { * This routine accepts bids for the current peice * of property. */ -bid() { - +void +bid() +{ static bool in[MAX_PL]; - reg int i, num_in, cur_max; - char buf[80]; + int i, num_in, cur_max; + char buf[257]; int cur_bid; printf("\nSo it goes up for auction. Type your bid after your name\n"); @@ -200,11 +206,12 @@ bid() { * This routine calculates the value of the property * of given player. */ +int prop_worth(plp) -reg PLAY *plp; { - - reg OWN *op; - reg int worth; + PLAY *plp; +{ + OWN *op; + int worth; worth = 0; for (op = plp->own_list; op; op = op->next) { diff --git a/games/monop/prop.dat b/games/monop/prop.dat index 6e83098d2ff..9fd20a9b18f 100644 --- a/games/monop/prop.dat +++ b/games/monop/prop.dat @@ -1,3 +1,4 @@ +/* $OpenBSD: prop.dat,v 1.2 1998/09/20 23:36:55 pjanzen Exp $ */ /* $NetBSD: prop.dat,v 1.2 1995/03/23 08:35:09 cgd Exp $ */ /*- diff --git a/games/monop/rent.c b/games/monop/rent.c index ef915bb8ce8..6fc85de61cb 100644 --- a/games/monop/rent.c +++ b/games/monop/rent.c @@ -1,3 +1,4 @@ +/* $OpenBSD: rent.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $ */ /* $NetBSD: rent.c,v 1.3 1995/03/23 08:35:11 cgd Exp $ */ /* @@ -37,21 +38,22 @@ #if 0 static char sccsid[] = "@(#)rent.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: rent.c,v 1.3 1995/03/23 08:35:11 cgd Exp $"; +static char rcsid[] = "$OpenBSD: rent.c,v 1.2 1998/09/20 23:36:55 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include "monop.ext" /* * This routine has the player pay rent */ +void rent(sqp) -reg SQUARE *sqp; { - - reg int rnt; - reg PROP *pp; - PLAY *plp; + SQUARE *sqp; +{ + int rnt; + PROP *pp; + PLAY *plp; plp = &play[sqp->owner]; printf("Owned by %s\n", plp->name); @@ -60,28 +62,28 @@ reg SQUARE *sqp; { return; } switch (sqp->type) { - case PRPTY: + case PRPTY: pp = sqp->desc; - if (pp->monop) + if (pp->monop) { if (pp->houses == 0) - printf("rent is %d\n", rnt=pp->rent[0] * 2); + printf("rent is %d\n", rnt = pp->rent[0] * 2); else if (pp->houses < 5) printf("with %d houses, rent is %d\n", - pp->houses, rnt=pp->rent[pp->houses]); + pp->houses, rnt = pp->rent[pp->houses]); else printf("with a hotel, rent is %d\n", - rnt=pp->rent[pp->houses]); - else + rnt = pp->rent[pp->houses]); + } else printf("rent is %d\n", rnt = pp->rent[0]); break; - case RR: + case RR: rnt = 25; rnt <<= (plp->num_rr - 1); if (spec) rnt <<= 1; printf("rent is %d\n", rnt); break; - case UTIL: + case UTIL: rnt = roll(2, 6); if (plp->num_util == 2 || spec) { printf("rent is 10 * roll (%d) = %d\n", rnt, rnt * 10); diff --git a/games/monop/roll.c b/games/monop/roll.c index ddf38a2e790..476f1ed18aa 100644 --- a/games/monop/roll.c +++ b/games/monop/roll.c @@ -1,3 +1,4 @@ +/* $OpenBSD: roll.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $ */ /* $NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $ */ /* @@ -37,7 +38,7 @@ #if 0 static char sccsid[] = "@(#)roll.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $"; +static char rcsid[] = "$OpenBSD: roll.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $"; #endif #endif /* not lint */ @@ -47,36 +48,36 @@ static char rcsid[] = "$NetBSD: roll.c,v 1.5 1995/03/23 08:35:13 cgd Exp $"; * This routine rolls ndie nside-sided dice. */ -# define reg register - -# if defined(pdp11) -# define MAXRAND 32767L +#if defined(pdp11) +#define MAXRAND 32767L +int roll(ndie, nsides) -int ndie, nsides; { - - reg long tot; - reg unsigned n, r; + int ndie, nsides; +{ + long tot; + unsigned n, r; tot = 0; n = ndie; while (n--) - tot += rand(); + tot += random(); return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie; } -# else +#else +int roll(ndie, nsides) -reg int ndie, nsides; { - - reg int tot, r; - reg double num_sides; + int ndie, nsides; +{ + int tot, r; + double num_sides; num_sides = nsides; tot = 0; while (ndie--) - tot += (r = rand()) * (num_sides / RAND_MAX) + 1; + tot += (r = random()) * (num_sides / RAND_MAX) + 1; return tot; } -# endif +#endif diff --git a/games/monop/spec.c b/games/monop/spec.c index 5b8f32e1425..1df305197ae 100644 --- a/games/monop/spec.c +++ b/games/monop/spec.c @@ -1,3 +1,4 @@ +/* $OpenBSD: spec.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $ */ /* $NetBSD: spec.c,v 1.3 1995/03/23 08:35:16 cgd Exp $ */ /* @@ -37,19 +38,20 @@ #if 0 static char sccsid[] = "@(#)spec.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: spec.c,v 1.3 1995/03/23 08:35:16 cgd Exp $"; +static char rcsid[] = "$OpenBSD: spec.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include "monop.ext" static char *perc[] = { "10%", "ten percent", "%", "$200", "200", 0 }; -inc_tax() { /* collect income tax */ - - reg int worth, com_num; +void +inc_tax() /* collect income tax */ +{ + int worth, com_num; com_num = getinp("Do you wish to lose 10%% of your total worth or $200? ", perc); worth = cur_p->money + prop_worth(cur_p); @@ -73,20 +75,28 @@ inc_tax() { /* collect income tax */ if (worth == 200) lucky("\nIt makes no difference! "); } -goto_jail() { /* move player to jail */ +void +goto_jail() /* move player to jail */ +{ cur_p->loc = JAIL; } -lux_tax() { /* landing on luxury tax */ +void +lux_tax() /* landing on luxury tax */ +{ printf("You lose $75\n"); cur_p->money -= 75; } -cc() { /* draw community chest card */ +void +cc() /* draw community chest card */ +{ get_card(&CC_D); } -chance() { /* draw chance card */ +void +chance() /* draw chance card */ +{ get_card(&CH_D); } diff --git a/games/monop/trade.c b/games/monop/trade.c index e8207f996f5..c0ea9f38d24 100644 --- a/games/monop/trade.c +++ b/games/monop/trade.c @@ -1,3 +1,4 @@ +/* $OpenBSD: trade.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $ */ /* $NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd Exp $ */ /* @@ -37,11 +38,11 @@ #if 0 static char sccsid[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93"; #else -static char rcsid[] = "$NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd Exp $"; +static char rcsid[] = "$OpenBSD: trade.c,v 1.2 1998/09/20 23:36:56 pjanzen Exp $"; #endif #endif /* not lint */ -# include "monop.ext" +#include "monop.ext" struct trd_st { /* how much to give to other player */ int trader; /* trader number */ @@ -52,15 +53,22 @@ struct trd_st { /* how much to give to other player */ typedef struct trd_st TRADE; -static char *list[MAX_PRP+2]; +static char *plist[MAX_PRP+2]; static int used[MAX_PRP]; static TRADE trades[2]; -trade() { +static void get_list __P((int, int )); +static int set_list __P((OWN *)); +static void summate __P((void)); +static void do_trade __P((void)); +static void move_em __P((TRADE *, TRADE *)); - reg int tradee, i; +void +trade() +{ + int tradee, i; trading = TRUE; for (i = 0; i < 2; i++) { @@ -96,14 +104,15 @@ over: * This routine gets the list of things to be trader for the * player, and puts in the structure given. */ +static void get_list(struct_no, play_no) -int struct_no, play_no; { - - reg int sn, pn; - reg PLAY *pp; - int numin, prop, num_prp; - OWN *op; - TRADE *tp; + int struct_no, play_no; +{ + int sn, pn; + PLAY *pp; + int numin, prop, num_prp; + OWN *op; + TRADE *tp; for (numin = 0; numin < MAX_PRP; numin++) used[numin] = FALSE; @@ -116,7 +125,7 @@ int struct_no, play_no; { numin = set_list(pp->own_list); for (num_prp = numin; num_prp; ) { prop = getinp("Which property do you wish to trade? ", - list); + plist); if (prop == numin) break; else if (used[prop]) @@ -147,28 +156,30 @@ once_more: /* * This routine sets up the list of tradable property. */ +static int set_list(the_list) -reg OWN *the_list; { - - reg int i; - reg OWN *op; + OWN *the_list; +{ + int i; + OWN *op; i = 0; for (op = the_list; op; op = op->next) if (!used[i]) - list[i++] = op->sqr->name; - list[i++] = "done"; - list[i--] = 0; + plist[i++] = op->sqr->name; + plist[i++] = "done"; + plist[i--] = 0; return i; } /* * This routine summates the trade. */ -summate() { - - reg bool some; - reg int i; - reg TRADE *tp; +static void +summate() +{ + bool some; + int i; + TRADE *tp; OWN *op; for (i = 0; i < 2; i++) { @@ -193,19 +204,21 @@ summate() { /* * This routine actually executes the trade. */ -do_trade() { - +static void +do_trade() +{ move_em(&trades[0], &trades[1]); move_em(&trades[1], &trades[0]); } /* * This routine does a switch from one player to another */ +static void move_em(from, to) -TRADE *from, *to; { - - reg PLAY *pl_fr, *pl_to; - reg OWN *op; + TRADE *from, *to; +{ + PLAY *pl_fr, *pl_to; + OWN *op; pl_fr = &play[from->trader]; pl_to = &play[to->trader]; @@ -224,10 +237,11 @@ TRADE *from, *to; { /* * This routine lets a player resign */ -resign() { - - reg int i, new_own; - reg OWN *op; +void +resign() +{ + int i, new_own; + OWN *op; SQUARE *sqp; if (cur_p->money <= 0) { @@ -260,7 +274,7 @@ resign() { } while (new_own == player); name_list[num_play] = "done"; } - if (getyn("Do you really want to resign? ", yn) != 0) + if (getyn("Do you really want to resign? ") != 0) return; if (num_play == 1) { printf("Then NOBODY wins (not even YOU!)\n"); @@ -294,7 +308,7 @@ resign() { for (i = player; i < num_play; i++) { name_list[i] = name_list[i+1]; if (i + 1 < num_play) - cpy_st(&play[i], &play[i+1], sizeof (PLAY)); + play[i] = play[i+1]; } name_list[num_play--] = 0; for (i = 0; i < N_SQRS; i++) |