Some progress on 'monop' game.

This commit is contained in:
Serge Vakulenko
2014-09-08 21:36:15 -07:00
parent e4e9ff1ef4
commit 2da083e9bd
28 changed files with 646 additions and 549 deletions

1
src/games/monop/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
monop

View File

@@ -3,85 +3,57 @@
# Program: Ken Arnold
# Makefile: K.S.
#
DESTDIR=
DATFILES=brd.dat mon.dat prop.dat
CFILES= 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 strcmp.c trade.c
OBJS= monop.o cards.o execute.o getinp.o houses.o jail.o misc.o morg.o \
print.o prop.o rent.o roll.o spec.o strcmp.o trade.o strings.o
HEADERS=monop.h deck.h
BINDIR= ${DESTDIR}/usr/games
LIBDIR= ${DESTDIR}/usr/games/lib
LIB=
CFLAGS= -O -w
SEPFLAG= -i
DAT= brd.dat monop.dat prop.dat
CC= cc
XSTR= xstr
ED= ed
AS= as
RM= rm -f
CTAGS= ctags
TOPSRC = $(shell cd ../../..; pwd)
#include $(TOPSRC)/target.mk
include $(TOPSRC)/cross.mk
CFLAGS = -DCROSS
#
# Be cool about compiling strings.
#
.c.o:
${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
${CC} -c ${CFLAGS} x.c
mv x.o $*.o
CFLAGS += -O -Werror -Wall
LIBS = -lc
it: monop cards.pck
OBJS = monop.o cards.o execute.o getinp.o houses.o jail.o misc.o \
morg.o print.o prop.o rent.o roll.o spec.o trade.o
MAN = monop.0
MANSRC = monop.6
monop: ${OBJS}
${CC} -o monop ${SEPFLAG} ${OBJS} ${LIB}
all: monop $(MAN) cards.pck
install: monop cards.pck
${RM} ${BINDIR}/monop ${LIBDIR}/cards.pck
install -s monop ${BINDIR}
mv cards.pck ${LIBDIR}
monop: $(OBJS)
$(CC) $(LDFLAGS) -o monop.elf $(OBJS) $(LIBS)
$(OBJDUMP) -S monop.elf > monop.dis
$(SIZE) monop.elf
$(ELF2AOUT) monop.elf $@ && rm monop.elf
new: clean ctags monop
initdeck: initdeck.c deck.h
$(CC) -o initdeck $(LDFLAGS) $(CFLAGS) initdeck.c
strings.o: strings
${XSTR}
${CC} -S xs.c
${ED} - < :rofix xs.s
${AS} -o strings.o xs.s
${RM} xs.s xs.c
cards.pck: initdeck cards.inp
./initdeck
monop.o: ${DATFILES} monop.def
${CC} -E ${CFLAGS} monop.c | ${XSTR} -c -
${CC} -c ${CFLAGS} x.c
mv x.o monop.o
cards.o: deck.h
${CC} -E ${CFLAGS} cards.c | ${XSTR} -c -
${CC} -c ${CFLAGS} x.c
mv x.o cards.o
newone:
${CC} ${SEPFLAG} -o monop ${CFLAGS} ${CFILES} ${LIB}
ctags:
${CTAGS} ${CFILES} monop.h deck.h monop.def initdeck.c
cards.pck: initdeck cards.inp
./initdeck
initdeck: initdeck.c deck.h
${CC} -o initdeck ${CFLAGS} initdeck.c ${LIB}
monop.tar:
tar crvf monop.tar ${CFILES} ${DATFILES} ${HEADERS} :rofix Makefile cards.inp initdeck.c monop.def monop.ext
$(MAN): $(MANSRC)
$(MANROFF) $< > $@
clean:
${RM} ${OBJS} monop core tags x.c x.o monop.tar initdeck cards.pck errs
cp /dev/null strings
rm -f *.o *.0 *.elf $(MAN) monop initdeck cards.pck *.elf *.dis tags *~
printall:
-/usr/bin/eecs/pr monop.h deck.h monop.def monop.ext ${CFILES} ${DATFILES} | /usr/bin/lpr
-/usr/bin/lpq
lint:
lint ${CFILES} > lint.out ;
install: all
install monop $(DESTDIR)/games/
cp $(MAN) $(DESTDIR)/share/man/cat6/
cp cards.pck $(DESTDIR)/games/lib/
###
cards.o: cards.c extern.h monop.h deck.h
execute.o: execute.c extern.h monop.h deck.h
getinp.o: getinp.c
houses.o: houses.c extern.h monop.h deck.h
initdeck.o: initdeck.c deck.h
jail.o: jail.c extern.h monop.h deck.h
misc.o: misc.c extern.h monop.h deck.h
monop.o: monop.c defines.h monop.h deck.h mon.dat.h prop.dat.h brd.dat.h
morg.o: morg.c extern.h monop.h deck.h
print.o: print.c extern.h monop.h deck.h
prop.o: prop.c extern.h monop.h deck.h
rent.o: rent.c extern.h monop.h deck.h
roll.o: roll.c
spec.o: spec.c extern.h monop.h deck.h
strcmp.o: strcmp.c
trade.o: trade.c extern.h monop.h deck.h

View File

@@ -1,3 +0,0 @@
g/^[ ]*\.data/s//.text/
w
q

View File

@@ -1,43 +0,0 @@
/* name (COLOR) owner type desc cost */
{"=== GO ===", -1, SAFE, 0 },
{"Mediterranean ave. (P)", -1, PRPTY, &prop[0], 60 },
{"Community Chest i", -1, CC, cc },
{"Baltic ave. (P)", -1, PRPTY, &prop[1], 60 },
{"Income Tax", -1, SPEC, inc_tax },
{"Reading RR", -1, RR, &rr[0], 200 },
{"Oriental ave. (L)", -1, PRPTY, &prop[2], 100 },
{"Chance i", -1, CHANCE, chance },
{"Vermont ave. (L)", -1, PRPTY, &prop[3], 100 },
{"Connecticut ave. (L)", -1, PRPTY, &prop[4], 120 },
{"Just Visiting", -1, SAFE, 0 },
{"St. Charles pl. (V)", -1, PRPTY, &prop[5], 140 },
{"Electric Co.", -1, UTIL, &util[0], 150 },
{"States ave. (V)", -1, PRPTY, &prop[6], 140 },
{"Virginia ave. (V)", -1, PRPTY, &prop[7], 160 },
{"Pennsylvania RR", -1, RR, &rr[1], 200 },
{"St. James pl. (O)", -1, PRPTY, &prop[8], 180 },
{"Community Chest ii", -1, CC, cc },
{"Tennessee ave. (O)", -1, PRPTY, &prop[9], 180 },
{"New York ave. (O)", -1, PRPTY, &prop[10], 200 },
{"Free Parking", -1, SAFE, 0 },
{"Kentucky ave. (R)", -1, PRPTY, &prop[11], 220 },
{"Chance ii", -1, CHANCE, chance },
{"Indiana ave. (R)", -1, PRPTY, &prop[12], 220 },
{"Illinois ave. (R)", -1, PRPTY, &prop[13], 240 },
{"B&O RR", -1, RR, &rr[2], 200 },
{"Atlantic ave. (Y)", -1, PRPTY, &prop[14], 260 },
{"Ventnor ave. (Y)", -1, PRPTY, &prop[15], 260 },
{"Water Works", -1, UTIL, &util[1], 150 },
{"Marvin Gardens (Y)", -1, PRPTY, &prop[16], 280 },
{"GO TO JAIL", -1, SPEC, goto_jail },
{"Pacific ave. (G)", -1, PRPTY, &prop[17], 300 },
{"N. Carolina ave. (G)", -1, PRPTY, &prop[18], 300 },
{"Community Chest iii", -1, CC, cc },
{"Pennsylvania ave. (G)", -1, PRPTY, &prop[19], 320 },
{"Short Line RR", -1, RR, &rr[3], 200 },
{"Chance iii", -1, CHANCE, chance },
{"Park place (D)", -1, PRPTY, &prop[20], 350 },
{"Luxury Tax", -1, SPEC, lux_tax },
{"Boardwalk (D)", -1, PRPTY, &prop[21], 400 },
{"JAIL", -1, SPEC }

43
src/games/monop/brd.dat.h Normal file
View File

@@ -0,0 +1,43 @@
/* name (COLOR) owner type desc cost */
{"=== GO ===", -1, SAFE, 0 },
{"Mediterranean ave. (P)", -1, PRPTY, (char*)&prop[0], 60 },
{"Community Chest i", -1, CC, (char*)cc },
{"Baltic ave. (P)", -1, PRPTY, (char*)&prop[1], 60 },
{"Income Tax", -1, SPEC, (char*)inc_tax },
{"Reading RR", -1, RR, (char*)&rr[0], 200 },
{"Oriental ave. (L)", -1, PRPTY, (char*)&prop[2], 100 },
{"Chance i", -1, CHANCE, (char*)chance },
{"Vermont ave. (L)", -1, PRPTY, (char*)&prop[3], 100 },
{"Connecticut ave. (L)", -1, PRPTY, (char*)&prop[4], 120 },
{"Just Visiting", -1, SAFE, 0 },
{"St. Charles pl. (V)", -1, PRPTY, (char*)&prop[5], 140 },
{"Electric Co.", -1, UTIL, (char*)&util[0], 150 },
{"States ave. (V)", -1, PRPTY, (char*)&prop[6], 140 },
{"Virginia ave. (V)", -1, PRPTY, (char*)&prop[7], 160 },
{"Pennsylvania RR", -1, RR, (char*)&rr[1], 200 },
{"St. James pl. (O)", -1, PRPTY, (char*)&prop[8], 180 },
{"Community Chest ii", -1, CC, (char*)cc },
{"Tennessee ave. (O)", -1, PRPTY, (char*)&prop[9], 180 },
{"New York ave. (O)", -1, PRPTY, (char*)&prop[10], 200 },
{"Free Parking", -1, SAFE, 0 },
{"Kentucky ave. (R)", -1, PRPTY, (char*)&prop[11], 220 },
{"Chance ii", -1, CHANCE, (char*)chance },
{"Indiana ave. (R)", -1, PRPTY, (char*)&prop[12], 220 },
{"Illinois ave. (R)", -1, PRPTY, (char*)&prop[13], 240 },
{"B&O RR", -1, RR, (char*)&rr[2], 200 },
{"Atlantic ave. (Y)", -1, PRPTY, (char*)&prop[14], 260 },
{"Ventnor ave. (Y)", -1, PRPTY, (char*)&prop[15], 260 },
{"Water Works", -1, UTIL, (char*)&util[1], 150 },
{"Marvin Gardens (Y)", -1, PRPTY, (char*)&prop[16], 280 },
{"GO TO JAIL", -1, SPEC, (char*)goto_jail },
{"Pacific ave. (G)", -1, PRPTY, (char*)&prop[17], 300 },
{"N. Carolina ave. (G)", -1, PRPTY, (char*)&prop[18], 300 },
{"Community Chest iii", -1, CC, (char*)cc },
{"Pennsylvania ave. (G)", -1, PRPTY, (char*)&prop[19], 320 },
{"Short Line RR", -1, RR, (char*)&rr[3], 200 },
{"Chance iii", -1, CHANCE, (char*)chance },
{"Park place (D)", -1, PRPTY, (char*)&prop[20], 350 },
{"Luxury Tax", -1, SPEC, (char*)lux_tax },
{"Boardwalk (D)", -1, PRPTY, (char*)&prop[21], 400 },
{"JAIL", -1, SPEC }

View File

@@ -1,38 +1,24 @@
# include "monop.ext"
#include "extern.h"
#include <stdlib.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
static char *cardfile = "/usr/games/lib/cards.pck";
# else
#ifdef CROSS
static char *cardfile = "cards.pck";
# endif
#else
static char *cardfile = "/games/lib/cards.pck";
#endif
static FILE *deckf;
/*
* This routine initializes the decks from the data file,
* which it opens.
*/
init_decks() {
if ((deckf=fopen(cardfile, "r")) == NULL) {
file_err:
perror(cardfile);
exit(1);
}
if (fread(deck, sizeof (DECK), 2, deckf) != 2)
goto file_err;
set_up(&CC_D);
set_up(&CH_D);
}
/*
* This routine sets up the offset pointers for the given deck.
*/
static void
set_up(dp)
DECK *dp; {
@@ -56,9 +42,45 @@ DECK *dp; {
dp->offsets[r1] = temp;
}
}
/*
* This routine initializes the decks from the data file,
* which it opens.
*/
void
init_decks() {
if ((deckf=fopen(cardfile, "r")) == NULL) {
file_err:
perror(cardfile);
exit(1);
}
if (fread(deck, sizeof (DECK), 2, deckf) != 2)
goto file_err;
set_up(&CC_D);
set_up(&CH_D);
}
/*
* This routine prints out the message on the card
*/
static void
printmes() {
reg char c;
printline();
fflush(stdout);
while ((c = getc(deckf)) != '\0')
putchar(c);
printline();
fflush(stdout);
}
/*
* This routine draws a card from the given deck
*/
void
get_card(dp)
DECK *dp; {
@@ -69,7 +91,8 @@ DECK *dp; {
do {
fseek(deckf, dp->offsets[dp->last_card], 0);
dp->last_card = ++(dp->last_card) % dp->num_cards;
dp->last_card++;
dp->last_card %= dp->num_cards;
type_maj = getc(deckf);
} while (dp->gojf_used && type_maj == GOJF);
type_min = getc(deckf);
@@ -135,11 +158,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->desc->houses == 5)
if (op->sqr->type == PRPTY) {
if (((PROP*)op->sqr->desc)->houses == 5)
++num_H;
else
num_h += op->sqr->desc->houses;
num_h += ((PROP*)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)
@@ -154,17 +178,3 @@ DECK *dp; {
}
spec = FALSE;
}
/*
* This routine prints out the message on the card
*/
printmes() {
reg char c;
printline();
fflush(stdout);
while ((c = getc(deckf)) != '\0')
putchar(c);
printline();
fflush(stdout);
}

View File

@@ -1,5 +1,5 @@
# include "monop.h"
# include "deck.h"
#include "monop.h"
#include "deck.h"
bool fixing, /* set if fixing up debt */
trading, /* set if in process of trading */
@@ -19,7 +19,7 @@ char *name_list[MAX_PL+2], /* list of players' names */
"roll", /* 16 */ "", /* 17 */
0
},
*yn[] = { /* list of commands for yes/no answers */
*yesno[] = { /* list of commands for yes/no answers */
"yes", /* 0 */ "no", /* 1 */
"quit", /* 2 */ "print", /* 3 */
"where", /* 4 */ "own holdings", /* 5 */
@@ -43,11 +43,11 @@ int player, /* current player number */
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(),
mortgage(), pay(), printboard(), quitgame(), resign(), restore(),
rub(), save(), sell_houses(), shell_out(), trade(),
unmortgage(), where(),
(*func[])() = { /* array of function calls for commands */
quit, /* quit game |* 0 *| */
quitgame, /* quit game |* 0 *| */
printboard, /* print board |* 1 *| */
where, /* where players are |* 2 *| */
list, /* own holdings |* 3 *| */
@@ -77,13 +77,13 @@ RR_S rr[N_RR]; /* raildroad descriptions */
UTIL_S util[2]; /* utility descriptions */
MON mon[N_MON] = { /* monopoly descriptions */
# include "mon.dat"
#include "mon.dat.h"
};
PROP prop[N_PROP] = { /* typical properties */
# include "prop.dat"
#include "prop.dat.h"
};
SQUARE board[N_SQRS+1] = { /* board itself (+1 for Jail) */
# include "brd.dat"
#include "brd.dat.h"
};

View File

@@ -1,24 +1,29 @@
# include "monop.ext"
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/time.h>
#include "extern.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <fcntl.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 */
extern char __data_start[], /* beginning of data 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 */
/*
* This routine executes the given command by index number
*/
void
execute(com_num)
reg int com_num; {
@@ -31,9 +36,11 @@ reg int com_num; {
else if (num_doub)
printf("%s rolled doubles. Goes again\n", cur_p->name);
}
/*
* This routine moves a piece around.
*/
void
do_move() {
reg int r1, r2;
@@ -62,30 +69,16 @@ do_move() {
ret:
return;
}
/*
* This routine moves a normal move
*/
move(rl)
reg int rl; {
reg int old_loc;
old_loc = cur_p->loc;
cur_p->loc = (cur_p->loc + rl) % N_SQRS;
if (cur_p->loc < old_loc && rl > 0) {
cur_p->money += 200;
printf("You pass %s and get $200\n", board[0].name);
}
show_move();
}
/*
* This routine shows the results of a move
*/
static void
show_move() {
reg SQUARE *sqp;
sqp = &board[cur_p->loc];
sqp = &board[(int)cur_p->loc];
printf("That puts you on %s\n", sqp->name);
switch (sqp->type) {
case SAFE:
@@ -106,7 +99,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");
@@ -114,18 +107,37 @@ show_move() {
rent(sqp);
}
}
/*
* This routine moves a normal move
*/
void
move(rl)
reg int rl; {
reg int old_loc;
old_loc = cur_p->loc;
cur_p->loc = (cur_p->loc + rl) % N_SQRS;
if (cur_p->loc < old_loc && rl > 0) {
cur_p->money += 200;
printf("You pass %s and get $200\n", board[0].name);
}
show_move();
}
/*
* This routine saves the current game for use at a later date
*/
void
save() {
reg char *sp;
reg int outf, num;
TIME tme, *tp;
int *dat_end, junk[18];
time_t tme;
struct stat junk;
unsgn start, end;
tp = &tme;
printf("Which file do you wish to save it in? ");
sp = buf;
while ((*sp++=getchar()) != '\n' && !feof(stdin))
@@ -137,9 +149,8 @@ save() {
/*
* check for existing files, and confirm overwrite if needed
*/
if (stat(buf, junk) > -1
&& getyn("File exists. Do you wish to overwrite? ", yn_only) > 0)
if (stat(buf, &junk) >= 0
&& getyn("File exists. Do you wish to overwrite? ") > 0)
return;
if ((outf=creat(buf, 0644)) < 0) {
@@ -147,28 +158,29 @@ save() {
return;
}
printf("\"%s\" ", buf);
time(tp); /* get current time */
strcpy(buf, ctime(tp));
time(&tme); /* get current time */
strcpy(buf, ctime(&tme));
for (sp = buf; *sp != '\n'; sp++)
continue;
*sp = '\0';
# if 0
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
# else
start = 0;
# endif
end = sbrk(0);
start = (unsigned) __data_start;
end = (unsigned) sbrk(0);
while (start < end) { /* write out entire data space */
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
write(outf, start, num);
if (write(outf, (void*)start, num) != num) {
perror(buf);
exit(-1);
}
start += num;
}
close(outf);
printf("[%s]\n", buf);
}
/*
* This routine restores an old game from a file
*/
void
restore() {
reg char *sp;
@@ -181,10 +193,12 @@ restore() {
clearerr(stdin);
rest_f(buf);
}
/*
* This does the actual restoring. It returns TRUE if the
* backup was successful, else false.
*/
int
rest_f(file)
reg char *file; {
@@ -203,19 +217,22 @@ reg char *file; {
perror(file);
exit(1);
}
# if 0
start = (((int) etext + (SEGSIZE-1)) / SEGSIZE ) * SEGSIZE;
# else
start = 0;
# endif
brk(end = start + sbuf.st_size);
start = (unsigned) __data_start;
end = start + sbuf.st_size;
if (brk((void*) end) < 0) {
perror("brk");
exit(-1);
}
while (start < end) { /* write out entire data space */
num = start + 16 * 1024 > end ? end - start : 16 * 1024;
read(inf, start, num);
if (read(inf, (void*) start, num) != num) {
perror(file);
exit(-1);
}
start += num;
}
close(inf);
strcpy(buf, ctime(sbuf.st_mtime));
strcpy(buf, ctime(&sbuf.st_mtime));
for (sp = buf; *sp != '\n'; sp++)
continue;
*sp = '\0';

View File

@@ -1,9 +1,9 @@
# include "monop.h"
# include "deck.h"
#include "monop.h"
#include "deck.h"
extern bool trading, spec, fixing, told_em;
extern char *yn[], *comlist[], *name_list[], *lucky_mes[];
extern char *yesno[], *comlist[], *name_list[], *lucky_mes[];
extern int num_play, player, num_doub, num_luck, (*func[])();

View File

@@ -1,23 +1,41 @@
# include <stdio.h>
# include <ctype.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
# define reg register
#define reg register
# define LINE 70
#define LINE 70
static char buf[257];
static int
comp(s1)
char *s1; {
reg char *sp, *tsp, c;
if (buf[0] != '\0')
for (sp = buf, tsp = s1; *sp; ) {
c = isupper(*tsp) ? tolower(*tsp) : *tsp;
tsp++;
if (c != *sp++)
return 0;
}
else if (*s1 != '\0')
return 0;
return 1;
}
int
getinp(prompt, list)
char *prompt, *list[]; {
reg int i, n_match, match;
reg int i, n_match, match = 0;
char *sp;
int plen;
for (;;) {
inter:
printf(prompt);
printf("%s", prompt);
for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); )
if (*sp == -1) /* check for interupted system call */
goto inter;
@@ -39,7 +57,7 @@ inter:
printf("<RETURN>");
}
else
printf(list[i]);
printf("%s", list[i]);
if (list[i+1])
printf(", ");
else
@@ -63,21 +81,3 @@ inter:
printf("Illegal response: \"%s\". Use '?' to get list of valid answers\n", buf);
}
}
static
comp(s1)
char *s1; {
reg char *sp, *tsp, c;
if (buf[0] != '\0')
for (sp = buf, tsp = s1; *sp; ) {
c = isupper(*tsp) ? tolower(*tsp) : *tsp;
tsp++;
if (c != *sp++)
return 0;
}
else if (*s1 != '\0')
return 0;
return 1;
}

View File

@@ -1,66 +1,29 @@
# include "monop.ext"
#include "extern.h"
#include <stdlib.h>
static char *names[N_MON+2],
cur_prop[80];
static MON *monops[N_MON];
/*
* These routines deal with buying and selling houses
*/
buy_houses() {
static void
list_cur(mp)
reg MON *mp; {
reg int num_mon;
reg MON *mp;
reg OWN *op;
bool good,got_morg;
int i,p;
reg int i;
reg SQUARE *sqp;
over:
num_mon = 0;
good = TRUE;
got_morg = FALSE;
for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
continue;
while (op)
if (op->sqr->desc->monop) {
mp = op->sqr->desc->mon_desc;
names[num_mon] = (monops[num_mon]=mp)->name;
num_mon++;
got_morg = good = FALSE;
for (i = 0; i < mp->num_in; i++) {
if (op->sqr->desc->morg)
got_morg++;
if (op->sqr->desc->houses != 5)
good++;
op = op->next;
}
if (!good || got_morg)
--num_mon;
}
for (i = 0; i < mp->num_in; i++) {
sqp = mp->sq[i];
if (((PROP*)sqp->desc)->houses == 5)
printf("%s (H) ", sqp->name);
else
op = op->next;
if (num_mon == 0) {
if (got_morg)
printf("You can't build on mortgaged monopolies.\n");
else if (!good)
printf("You can't build any more.\n");
else
printf("But you don't have any monopolies!!\n");
return;
}
if (num_mon == 1)
buy_h(monops[0]);
else {
names[num_mon++] = "done";
names[num_mon--] = 0;
if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
return;
buy_h(monops[p]);
goto over;
printf("%s (%d) ", sqp->name, ((PROP*)sqp->desc)->houses);
}
putchar('\n');
}
static void
buy_h(mnp)
MON *mnp; {
@@ -78,7 +41,7 @@ blew_it:
printf("Houses will cost $%d\n", price);
printf("How many houses do you wish to buy for\n");
for (i = 0; i < mp->num_in; i++) {
pp = mp->sq[i]->desc;
pp = (PROP*) mp->sq[i]->desc;
over:
if (pp->houses == 5) {
printf("%s (H):\n", mp->sq[i]->name);
@@ -106,10 +69,124 @@ 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];
((PROP*)mp->sq[i]->desc)->houses = temp[i];
}
}
}
/*
* These routines deal with buying and selling houses
*/
void
buy_houses() {
reg int num_mon;
reg MON *mp;
reg OWN *op;
bool good,got_morg;
int i,p;
over:
num_mon = 0;
good = TRUE;
got_morg = FALSE;
for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
continue;
while (op) {
PROP *prop = (PROP*) op->sqr->desc;
if (prop->monop) {
mp = prop->mon_desc;
names[num_mon] = (monops[num_mon]=mp)->name;
num_mon++;
got_morg = good = FALSE;
for (i = 0; i < mp->num_in; i++) {
if (prop->morg)
got_morg++;
if (prop->houses != 5)
good++;
op = op->next;
}
if (!good || got_morg)
--num_mon;
}
else
op = op->next;
}
if (num_mon == 0) {
if (got_morg)
printf("You can't build on mortgaged monopolies.\n");
else if (!good)
printf("You can't build any more.\n");
else
printf("But you don't have any monopolies!!\n");
return;
}
if (num_mon == 1)
buy_h(monops[0]);
else {
names[num_mon++] = "done";
names[num_mon--] = 0;
if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
return;
buy_h(monops[p]);
goto over;
}
}
static void
sell_h(mnp)
MON *mnp; {
reg int i;
reg MON *mp;
reg int price;
shrt input[3],temp[3];
int tot;
PROP *pp;
mp = mnp;
price = mp->h_cost * 25;
blew_it:
printf("Houses will get you $%d apiece\n", price);
list_cur(mp);
printf("How many houses do you wish to sell from\n");
for (i = 0; i < mp->num_in; i++) {
pp = (PROP*) mp->sq[i]->desc;
over:
if (pp->houses == 0) {
printf("%s (0):\n", mp->sq[i]->name);
input[i] = temp[i] = 0;
continue;
}
if (pp->houses < 5)
sprintf(cur_prop,"%s (%d): ", mp->sq[i]->name, pp->houses);
else
sprintf(cur_prop,"%s (H): ", mp->sq[i]->name);
input[i] = get_int(cur_prop);
temp[i] = pp->houses - input[i];
if (temp[i] < 0) {
printf("That's too many. The most you can sell is %d\n", pp->houses);
goto over;
}
}
if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
err: printf("That makes the spread too wide. Try again\n");
goto blew_it;
}
else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
goto err;
for (tot = i = 0; i < mp->num_in; i++)
tot += input[i];
if (tot) {
printf("You asked to sell %d houses for $%d\n",tot,tot * price);
if (getyn("Is that ok? ") == 0) {
cur_p->money += tot * price;
for (tot = i = 0; i < mp->num_in; i++)
((PROP*)mp->sq[i]->desc)->houses = temp[i];
}
}
}
@@ -117,6 +194,7 @@ err: printf("That makes the spread too wide. Try again\n");
/*
* This routine sells houses.
*/
void
sell_houses() {
reg int num_mon;
@@ -129,15 +207,15 @@ over:
num_mon = 0;
good = TRUE;
for (op = cur_p->own_list; op; op = op->next)
if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
mp = op->sqr->desc->mon_desc;
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->monop) {
mp = ((PROP*)op->sqr->desc)->mon_desc;
names[num_mon] = (monops[num_mon]=mp)->name;
num_mon++;
good = 0;
do
if (!good && op->sqr->desc->houses != 0)
if (!good && ((PROP*)op->sqr->desc)->houses != 0)
good++;
while (op->next && op->sqr->desc->mon_desc == mp
while (op->next && ((PROP*)op->sqr->desc)->mon_desc == mp
&& (op=op->next));
if (!good)
--num_mon;
@@ -158,73 +236,3 @@ over:
goto over;
}
}
sell_h(mnp)
MON *mnp; {
reg int i;
reg MON *mp;
reg int price;
shrt input[3],temp[3];
int tot;
PROP *pp;
mp = mnp;
price = mp->h_cost * 25;
blew_it:
printf("Houses will get you $%d apiece\n", price);
list_cur(mp);
printf("How many houses do you wish to sell from\n");
for (i = 0; i < mp->num_in; i++) {
pp = mp->sq[i]->desc;
over:
if (pp->houses == 0) {
printf("%s (0):\n", mp->sq[i]->name);
input[i] = temp[i] = 0;
continue;
}
if (pp->houses < 5)
sprintf(cur_prop,"%s (%d): ",mp->sq[i]->name,pp->houses);
else
sprintf(cur_prop,"%s (H): ",mp->sq[i]->name,pp->houses);
input[i] = get_int(cur_prop);
temp[i] = pp->houses - input[i];
if (temp[i] < 0) {
printf("That's too many. The most you can sell is %d\n", pp->houses);
goto over;
}
}
if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
err: printf("That makes the spread too wide. Try again\n");
goto blew_it;
}
else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
goto err;
for (tot = i = 0; i < mp->num_in; i++)
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) {
cur_p->money += tot * price;
for (tot = i = 0; i < mp->num_in; i++)
mp->sq[i]->desc->houses = temp[i];
}
}
}
list_cur(mp)
reg MON *mp; {
reg int i;
reg SQUARE *sqp;
for (i = 0; i < mp->num_in; i++) {
sqp = mp->sq[i];
if (sqp->desc->houses == 5)
printf("%s (H) ", sqp->name);
else
printf("%s (%d) ", sqp->name, sqp->desc->houses);
}
putchar('\n');
}

View File

@@ -1,5 +1,6 @@
# include <stdio.h>
# include "deck.h"
#include <stdio.h>
#include <stdlib.h>
#include "deck.h"
/*
* This program initializes the card files for monopoly.
@@ -12,11 +13,11 @@
* string to print, terminated with a null byte.
*/
# define TRUE 1
# define FALSE 0
#define TRUE 1
#define FALSE 0
# define bool char
# define reg register
#define bool char
#define reg register
char *infile = "cards.inp", /* input file */
*outfile = "cards.pck"; /* "packed" file */

View File

@@ -1,9 +1,10 @@
# include "monop.ext"
#include "extern.h"
/*
* This routine uses a get-out-of-jail-free card to get the
* player out of jail.
*/
void
card() {
if (cur_p->loc != JAIL) {
@@ -18,10 +19,12 @@ card() {
cur_p->loc = 10; /* just visiting */
cur_p->in_jail = 0;
}
/*
* This routine returns the players get-out-of-jail-free card
* to a deck.
*/
void
ret_card(plr)
reg PLAY *plr; {
@@ -31,9 +34,11 @@ reg PLAY *plr; {
else
CH_D.gojf_used = FALSE;
}
/*
* This routine deals with paying your way out of jail.
*/
void
pay() {
if (cur_p->loc != JAIL) {
@@ -45,9 +50,11 @@ pay() {
cur_p->in_jail = 0;
printf("That cost you $50\n");
}
/*
* This routine deals with a move in jail
*/
int
move_jail(r1, r2)
reg int r1, r2; {
@@ -70,6 +77,8 @@ moveit:
goto moveit;
}
}
void
printturn() {
if (cur_p->loc != JAIL)

View File

@@ -1,8 +1,13 @@
# include "monop.ext"
# include <ctype.h>
# include <signal.h>
#include "extern.h"
#include <ctype.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <pwd.h>
#include <sys/types.h>
#include <sys/wait.h>
# define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], 0)
#define execsh(sh) execl(sh, shell_name[roll(1, num_names)-1], NULL)
static char *shell_def = "/bin/csh",
*shell_name[] = {
@@ -21,26 +26,27 @@ static char *shell_def = "/bin/csh",
static int num_names = sizeof shell_name / sizeof (char *);;
char *shell_in();
/*
* 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;
for (;;)
if ((com=getinp(prompt, yn)) < 2)
if ((com=getinp(prompt, yesno)) < 2)
return com;
else
(*func[com-2])();
}
/*
* This routine tells the player if he's out of money.
*/
void
notify() {
if (cur_p->money < 0)
@@ -52,19 +58,24 @@ notify() {
told_em = TRUE;
}
}
/*
* This routine switches to the next player
*/
void
next_play() {
player = ++player % num_play;
player++;
player %= num_play;
cur_p = &play[player];
num_doub = 0;
}
/*
* This routine gets an integer from the keyboard after the
* given prompt.
*/
int
get_int(prompt)
reg char *prompt; {
@@ -74,7 +85,7 @@ reg char *prompt; {
for (;;) {
inter:
printf(prompt);
printf("%s", prompt);
num = 0;
for (sp = buf; (*sp=getchar()) != '\n' && !feof(stdin); sp++)
if (*sp == -1) /* check for interrupted system call */
@@ -95,9 +106,28 @@ inter:
printf("I can't understand that\n");
}
}
/*
* This routine sets things up as if it is a new monopoly
*/
static void
is_monop(mp, pl)
reg MON *mp;
int pl; {
reg int i;
mp->owner = pl;
mp->num_own = mp->num_in;
for (i = 0; i < mp->num_in; i++)
((PROP*)mp->sq[i]->desc)->monop = TRUE;
mp->name = mp->mon_n;
}
/*
* This routine sets the monopoly flag from the list given.
*/
void
set_ownlist(pl)
int pl; {
@@ -146,10 +176,10 @@ int pl; {
#ifdef DEBUG
printf(" case PRPTY:\n");
#endif
orig = op->sqr->desc->mon_desc;
orig = ((PROP*)op->sqr->desc)->mon_desc;
orig_op = op;
num = 0;
while (op && op->sqr->desc->mon_desc == orig) {
while (op && ((PROP*)op->sqr->desc)->mon_desc == orig) {
#ifdef DEBUG
printf("iter: %d\n", num);
#endif
@@ -166,17 +196,17 @@ int pl; {
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
@@ -190,66 +220,64 @@ int pl; {
}
}
}
/*
* This routine sets things up as if it is a new monopoly
*/
is_monop(mp, pl)
reg MON *mp;
int pl; {
reg char *sp;
reg int i;
mp->owner = pl;
mp->num_own = mp->num_in;
for (i = 0; i < mp->num_in; i++)
mp->sq[i]->desc->monop = TRUE;
mp->name = mp->mon_n;
}
/*
* 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;
mp->owner = -1;
for (i = 0; i < mp->num_in; i++)
mp->sq[i]->desc->monop = FALSE;
((PROP*)mp->sq[i]->desc)->monop = FALSE;
mp->name = mp->not_m;
}
/*
* This routine gives a list of the current player's routine
*/
void
list() {
printhold(player);
}
/*
* This routine gives a list of a given players holdings
*/
void
list_all() {
reg int pl;
while ((pl=getinp("Whose holdings do you want to see? ", name_list)) < num_play)
printhold(pl);
}
/*
* This routine gives the players a chance before it exits.
*/
quit() {
void
quit(int sig) {
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(2, quit);
}
int
quitgame()
{
quit(0);
return 0;
}
/*
* This routine copies one structure to another
*/
void
cpy_st(s1, s2, size)
reg int *s1, *s2, size; {
@@ -257,37 +285,11 @@ reg int *s1, *s2, size; {
while (size--)
*s1++ = *s2++;
}
/*
* This routine forks off a shell. It uses the users login shell
*/
shell_out() {
static char *shell = NULL;
printline();
if (shell == NULL)
shell = shell_in();
fflush();
if (!fork()) {
signal(SIGINT, SIG_DFL);
execsh(shell);
}
ignoresigs();
wait();
resetsigs();
putchar('\n');
printline();
}
/*
* This routine looks up the users login shell
*/
# include <pwd.h>
struct passwd *getpwuid();
char *getenv();
char *
static char *
shell_in() {
reg struct passwd *pp;
@@ -303,24 +305,49 @@ shell_in() {
}
return sp;
}
/*
* This routine sets things up to ignore all the signals.
*/
static void
ignoresigs() {
reg int i;
for (i = 0; i < NSIG; i++)
signal(i, SIG_IGN);
}
/*
* This routine sets up things as they were before.
*/
static void
resetsigs() {
reg int i;
for (i = 0; i < NSIG; i++)
signal(i, SIG_DFL);
signal(2, quit);
}
/*
* This routine forks off a shell. It uses the users login shell
*/
void
shell_out() {
static char *shell = NULL;
int status;
printline();
if (shell == NULL)
shell = shell_in();
fflush(stdout);
if (!fork()) {
signal(SIGINT, SIG_DFL);
execsh(shell);
}
ignoresigs();
wait(&status);
resetsigs();
putchar('\n');
printline();
}

View File

@@ -1,9 +0,0 @@
/* name owner num_in num_own h_cost not_m mon_n sq */
{0, -1, 2, 0, 1, "Purple", "PURPLE", {1,3}},
{0, -1, 3, 0, 1, "Lt. Blue", "LT. BLUE", {6,8,9}},
{0, -1, 3, 0, 2, "Violet", "VIOLET", {11,13,14}},
{0, -1, 3, 0, 2, "Orange", "ORANGE", {16,18,19}},
{0, -1, 3, 0, 3, "Red", "RED", {21,23,24}},
{0, -1, 3, 0, 3, "Yellow", "YELLOW", {26,27,29}},
{0, -1, 3, 0, 4, "Green", "GREEN", {31,32,34}},
{0, -1, 2, 0, 4, "Dk. Blue", "DK. BLUE", {37,39}}

View File

@@ -0,0 +1,9 @@
/* name owner num_in num_own h_cost not_m mon_n sq */
{0, -1, 2, 0, 1, "Purple", "PURPLE", {(SQUARE*)1,(SQUARE*)3}},
{0, -1, 3, 0, 1, "Lt. Blue", "LT. BLUE", {(SQUARE*)6,(SQUARE*)8,(SQUARE*)9}},
{0, -1, 3, 0, 2, "Violet", "VIOLET", {(SQUARE*)11,(SQUARE*)13,(SQUARE*)14}},
{0, -1, 3, 0, 2, "Orange", "ORANGE", {(SQUARE*)16,(SQUARE*)18,(SQUARE*)19}},
{0, -1, 3, 0, 3, "Red", "RED", {(SQUARE*)21,(SQUARE*)23,(SQUARE*)24}},
{0, -1, 3, 0, 3, "Yellow", "YELLOW", {(SQUARE*)26,(SQUARE*)27,(SQUARE*)29}},
{0, -1, 3, 0, 4, "Green", "GREEN", {(SQUARE*)31,(SQUARE*)32,(SQUARE*)34}},
{0, -1, 2, 0, 4, "Dk. Blue", "DK. BLUE", {(SQUARE*)37,(SQUARE*)39}}

View File

@@ -1,37 +1,13 @@
# include "monop.def"
#include "defines.h"
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <signal.h>
/*
* This program implements a monopoly game
*/
main(ac, av)
reg int ac;
reg char *av[]; {
srand(getpid());
if (ac > 1) {
if (!rest_f(av[1]))
restore();
}
else {
getplayers();
init_players();
init_monops();
}
num_luck = sizeof lucky_mes / sizeof (char *);
init_decks();
signal(2, quit);
for (;;) {
printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
cur_p->money, board[cur_p->loc].name);
printturn();
force_morg();
execute(getinp("-- Command: ", comlist));
}
}
/*
* This routine gets the names of the players
*/
void
getplayers() {
reg char *sp;
@@ -64,7 +40,7 @@ over:
name_list[i] = 0;
for (i = 0; i < num_play; i++)
for (j = i + 1; j < num_play; j++)
if (strcmp(name_list[i], name_list[j]) == 0) {
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");
else
@@ -75,14 +51,16 @@ over:
goto blew_it;
}
}
/*
* This routine figures out who goes first
*/
void
init_players() {
reg int i, rl, cur_max;
bool over;
int max_pl;
bool over = 0;
int max_pl = 0;
again:
putchar('\n');
@@ -105,9 +83,11 @@ again:
cur_p = &play[max_pl];
printf("%s (%d) goes first\n", cur_p->name, max_pl + 1);
}
/*
* This routine initalizes the monopoly structures.
*/
void
init_monops() {
reg MON *mp;
@@ -119,3 +99,34 @@ init_monops() {
mp->sq[i] = &board[(int)(mp->sq[i])];
}
}
/*
* This program implements a monopoly game
*/
int
main(ac, av)
reg int ac;
reg char *av[]; {
srand(getpid());
if (ac > 1) {
if (!rest_f(av[1]))
restore();
}
else {
getplayers();
init_players();
init_monops();
}
num_luck = sizeof lucky_mes / sizeof (char *);
init_decks();
signal(2, quit);
for (;;) {
printf("\n%s (%d) (cash $%d) on %s\n", cur_p->name, player + 1,
cur_p->money, board[(int)cur_p->loc].name);
printturn();
force_morg();
execute(getinp("-- Command: ", comlist));
}
}

View File

@@ -95,4 +95,29 @@ typedef struct prp_st PROP;
typedef struct rr_st RR_S;
typedef struct rr_st UTIL_S;
int cc(), chance(), lux_tax(), goto_jail(), inc_tax();
int rest_f(char *file);
int get_int(char *prompt);
int roll(int ndie, int nsides);
int getinp(char *prompt, char *list[]);
int move_jail(int r1, int r2);
int getyn(char *prompt);
void goto_jail(void);
void inc_tax(void);
void lux_tax(void);
void cc(void);
void chance(void);
void init_decks(void);
void quit(int sig);
void printturn(void);
void force_morg(void);
void execute(int com_num);
void move(int rl);
void notify(void);
void next_play(void);
void buy(int player, SQUARE *sqrp);
void bid(void);
void rent(SQUARE *sqp);
void ret_card(PLAY *plr);
void printhold(int pl);
void isnot_monop(MON *mp);

View File

@@ -1,4 +1,4 @@
# include "monop.ext"
#include "extern.h"
/*
* These routines deal with mortgaging.
@@ -34,6 +34,7 @@ static int num_good,got_houses;
* it gets the list of mortgageable property and asks which are to
* be mortgaged.
*/
void
mortgage() {
reg int prop;
@@ -59,17 +60,19 @@ mortgage() {
notify(cur_p);
}
}
/*
* This routine sets up the list of mortgageable property
*/
int
set_mlist() {
reg OWN *op;
num_good = 0;
for (op = cur_p->own_list; op; op = op->next)
if (!op->sqr->desc->morg)
if (op->sqr->type == PRPTY && op->sqr->desc->houses)
if (! ((PROP*)op->sqr->desc)->morg)
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->houses)
got_houses++;
else {
names[num_good] = op->sqr->name;
@@ -79,24 +82,28 @@ set_mlist() {
names[num_good--] = 0;
return num_good;
}
/*
* This routine actually mortgages the property.
*/
void
m(prop)
reg int prop; {
reg int price;
price = board[prop].cost/2;
board[prop].desc->morg = TRUE;
((PROP*)board[prop].desc)->morg = TRUE;
printf("That got you $%d\n",price);
cur_p->money += price;
}
/*
* This routine is the command level repsponse to the unmortgage
* command. It gets the list of mortgaged property and asks which are
* to be unmortgaged.
*/
void
unmortgage() {
reg int prop;
@@ -118,16 +125,18 @@ unmortgage() {
unm(square[prop]);
}
}
/*
* This routine sets up the list of mortgaged property
*/
int
set_umlist() {
reg OWN *op;
num_good = 0;
for (op = cur_p->own_list; op; op = op->next)
if (op->sqr->desc->morg) {
if (((PROP*)op->sqr->desc)->morg) {
names[num_good] = op->sqr->name;
square[num_good++] = sqnum(op->sqr);
}
@@ -135,25 +144,29 @@ set_umlist() {
names[num_good--] = 0;
return num_good;
}
/*
* This routine actually unmortgages the property
*/
void
unm(prop)
reg int prop; {
reg int price;
price = board[prop].cost/2;
board[prop].desc->morg = FALSE;
((PROP*)board[prop].desc)->morg = FALSE;
price += price/10;
printf("That cost you $%d\n",price);
cur_p->money -= price;
set_umlist();
}
/*
* This routine forces the indebted player to fix his
* financial woes.
*/
void
force_morg() {
told_em = fixing = TRUE;
@@ -161,9 +174,11 @@ force_morg() {
fix_ex(getinp("How are you going to fix it up? ",morg_coms));
fixing = FALSE;
}
/*
* This routine is a special execute for the force_morg routine
*/
void
fix_ex(com_num)
reg int com_num; {

View File

@@ -1,4 +1,4 @@
# include "monop.ext"
#include "extern.h"
static char buf[80], /* output buffer */
*header = "Name Own Price Mg # Rent";
@@ -6,6 +6,7 @@ static char buf[80], /* output buffer */
/*
* This routine prints out the current board
*/
void
printboard() {
reg int i;
@@ -17,9 +18,11 @@ printboard() {
printsq(i+N_SQRS/2, TRUE);
}
}
/*
* This routine lists where each player is.
*/
void
where() {
reg int i;
@@ -34,9 +37,11 @@ where() {
putchar('\n');
}
}
/*
* This routine prints out an individual square
*/
void
printsq(sqn, eoln)
int sqn;
reg bool eoln; {
@@ -60,7 +65,7 @@ spec:
printf(" ");
break;
case PRPTY:
pp = sqp->desc;
pp = (PROP*) sqp->desc;
if (sqp->owner < 0) {
printf(" - %-8.8s %3d", pp->mon_desc->name, sqp->cost);
if (!eoln)
@@ -113,20 +118,24 @@ spec:
if (eoln)
putchar('\n');
}
/*
* This routine prints out the mortgage flag.
*/
void
printmorg(sqp)
reg SQUARE *sqp; {
if (sqp->desc->morg)
if (((PROP*)sqp->desc)->morg)
printf(" * ");
else
printf(" ");
}
/*
* This routine lists the holdings of the player given
*/
void
printhold(pl)
reg int pl; {

View File

@@ -1,9 +1,11 @@
# include "monop.ext"
#include "extern.h"
#include <stdlib.h>
/*
* This routine deals with buying property, setting all the
* appropriate flags.
*/
void
buy(player, sqrp)
reg int player;
reg SQUARE *sqrp; {
@@ -12,9 +14,11 @@ reg SQUARE *sqrp; {
sqrp->owner = player;
add_list(player, &(play[player].own_list), cur_p->loc);
}
/*
* This routine adds an item to the list.
*/
void
add_list(plr, head, op_sqr)
int plr;
OWN **head;
@@ -44,9 +48,11 @@ int op_sqr; {
if (!trading)
set_ownlist(plr);
}
/*
* This routine deletes property from the list.
*/
void
del_list(plr, head, op_sqr)
int plr;
OWN **head;
@@ -57,7 +63,7 @@ shrt op_sqr; {
switch (board[op_sqr].type) {
case PRPTY:
board[op_sqr].desc->mon_desc->num_own--;
((PROP*)board[op_sqr].desc)->mon_desc->num_own--;
break;
case RR:
play[plr].num_rr--;
@@ -83,6 +89,7 @@ shrt op_sqr; {
* This routine calculates the value for sorting of the
* given square.
*/
int
value(sqp)
reg SQUARE *sqp; {
@@ -105,12 +112,13 @@ reg SQUARE *sqp; {
return 8 + (PROP *)(sqp->desc) - prop;
}
}
/*
* This routine accepts bids for the current peice
* of property.
*/
void
bid() {
static bool in[MAX_PL];
reg int i, num_in, cur_max;
char buf[80];
@@ -151,10 +159,12 @@ bid() {
else
printf("Nobody seems to want it, so we'll leave it for later\n");
}
/*
* This routine calculates the value of the property
* of given player.
*/
int
prop_worth(plp)
reg PLAY *plp; {
@@ -163,9 +173,9 @@ reg PLAY *plp; {
worth = 0;
for (op = plp->own_list; op; op = op->next) {
if (op->sqr->type == PRPTY && op->sqr->desc->monop)
worth += op->sqr->desc->mon_desc->h_cost * 50 *
op->sqr->desc->houses;
if (op->sqr->type == PRPTY && ((PROP*)op->sqr->desc)->monop)
worth += ((PROP*)op->sqr->desc)->mon_desc->h_cost * 50 *
((PROP*)op->sqr->desc)->houses;
worth += op->sqr->cost;
}
return worth;

View File

@@ -1,8 +1,9 @@
# include "monop.ext"
#include "extern.h"
/*
* This routine has the player pay rent
*/
void
rent(sqp)
reg SQUARE *sqp; {
@@ -12,13 +13,13 @@ reg SQUARE *sqp; {
plp = &play[sqp->owner];
printf("Owned by %s\n", plp->name);
if (sqp->desc->morg) {
if (((PROP*)sqp->desc)->morg) {
lucky("The thing is mortgaged. ");
return;
}
switch (sqp->type) {
case PRPTY:
pp = sqp->desc;
pp = (PROP*) sqp->desc;
if (pp->monop)
if (pp->houses == 0)
printf("rent is %d\n", rnt=pp->rent[0] * 2);

View File

@@ -2,36 +2,14 @@
* This routine rolls ndie nside-sided dice.
*/
# define reg register
# ifndef vax
# define MAXRAND 32767L
int
roll(ndie, nsides)
int ndie, nsides; {
reg long tot;
reg unsigned n, r;
int tot;
tot = 0;
n = ndie;
while (n--)
tot += rand();
return (int) ((tot * (long) nsides) / ((long) MAXRAND + 1)) + ndie;
}
# else
roll(ndie, nsides)
reg int ndie, nsides; {
reg int tot, r;
reg double num_sides;
num_sides = nsides;
tot = 0;
while (ndie--)
tot += (r = rand()) * (num_sides / 017777777777) + 1;
tot += rand() % nsides + 1;
return tot;
}
# endif

View File

@@ -1,9 +1,10 @@
# include "monop.ext"
#include "extern.h"
static char *perc[] = {
"10%", "ten percent", "%", "$200", "200", 0
};
void
inc_tax() { /* collect income tax */
reg int worth, com_num;
@@ -30,20 +31,24 @@ 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);
}

View File

@@ -1,9 +1,9 @@
# include <stdio.h>
# include <ctype.h>
#include <stdio.h>
#include <ctype.h>
# define reg register
#define reg register
# define makelower(c) (isupper(c) ? tolower(c) : c)
#define makelower(c) (isupper(c) ? tolower(c) : c)
/*
* Compare strings: s1>s2: >0 s1==s2: 0 s1<s2: <0

View File

@@ -1,6 +1,7 @@
# include "monop.ext"
#include "extern.h"
#include <stdlib.h>
static struct trd_st { /* how much to give to other player */
struct trd_st { /* how much to give to other player */
int trader; /* trader number */
int cash; /* amount of cash */
int gojf; /* # get-out-of-jail-free cards */
@@ -219,7 +220,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? ", yesno) != 0)
return;
if (num_play == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
@@ -241,10 +242,10 @@ resign() {
for (op = cur_p->own_list; op; op = op->next) {
sqp = op->sqr;
sqp->owner = -1;
sqp->desc->morg = FALSE;
if (op->type == PRPTY) {
isnot_monop(sqp->desc->mon_desc);
sqp->desc->houses = 0;
((PROP*)sqp->desc)->morg = FALSE;
if (op->sqr->type == PRPTY) {
isnot_monop(((PROP*)sqp->desc)->mon_desc);
((PROP*)sqp->desc)->houses = 0;
}
}
if (cur_p->num_gojf)