2001-01-16 05:41:17 +03:00
|
|
|
/* $NetBSD: misc.c,v 1.10 2001/01/16 02:41:17 cgd Exp $ */
|
1995-03-23 11:28:00 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1995-03-23 11:28:00 +03:00
|
|
|
* Copyright (c) 1980, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1997-10-12 21:45:06 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-23 11:28:00 +03:00
|
|
|
#if 0
|
|
|
|
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 5/31/93";
|
|
|
|
#else
|
2001-01-16 05:41:17 +03:00
|
|
|
__RCSID("$NetBSD: misc.c,v 1.10 2001/01/16 02:41:17 cgd Exp $");
|
1995-03-23 11:28:00 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
1999-08-21 14:40:03 +04:00
|
|
|
#include "monop.ext"
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <signal.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This routine executes a truncated set of commands until a
|
|
|
|
* "yes or "no" answer is gotten.
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
getyn(prompt)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *prompt;
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int com;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (;;)
|
|
|
|
if ((com=getinp(prompt, yn)) < 2)
|
|
|
|
return com;
|
|
|
|
else
|
|
|
|
(*func[com-2])();
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine tells the player if he's out of money.
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
|
|
|
notify()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
if (cur_p->money < 0)
|
|
|
|
printf("That leaves you $%d in debt\n", -cur_p->money);
|
|
|
|
else if (cur_p->money == 0)
|
|
|
|
printf("that leaves you broke\n");
|
|
|
|
else if (fixing && !told_em && cur_p->money > 0) {
|
|
|
|
printf("-- You are now Solvent ---\n");
|
|
|
|
told_em = TRUE;
|
|
|
|
}
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine switches to the next player
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
|
|
|
next_play()
|
|
|
|
{
|
2001-01-16 05:41:17 +03:00
|
|
|
player = (player + 1) % num_play;
|
1993-03-21 12:45:37 +03:00
|
|
|
cur_p = &play[player];
|
|
|
|
num_doub = 0;
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine gets an integer from the keyboard after the
|
|
|
|
* given prompt.
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
int
|
1993-03-21 12:45:37 +03:00
|
|
|
get_int(prompt)
|
Add use of `const' where appropriate to the games.
This merges in all such remaining changes from the Linux port of the
NetBSD games, except in hunt (where substantial changes from OpenBSD
need to be looked at).
Some such changes were previously covered in PRs bin/6041, bin/6146,
bin/6148, bin/6150, bin/6151, bin/6580, bin/6660, bin/7993, bin/7994,
bin/8039, bin/8057 and bin/8093.
1999-09-09 01:17:44 +04:00
|
|
|
const char *prompt;
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int num;
|
|
|
|
char *sp;
|
|
|
|
int c;
|
|
|
|
char buf[257];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
inter:
|
|
|
|
printf(prompt);
|
|
|
|
num = 0;
|
1997-03-29 23:42:16 +03:00
|
|
|
for (sp = buf; (c=getchar()) != '\n'; *sp++ = c)
|
|
|
|
if (c == -1) /* check for interrupted system call */
|
1993-03-21 12:45:37 +03:00
|
|
|
goto inter;
|
1997-03-29 23:42:16 +03:00
|
|
|
*sp = c;
|
1993-03-21 12:45:37 +03:00
|
|
|
if (sp == buf)
|
|
|
|
continue;
|
|
|
|
for (sp = buf; isspace(*sp); sp++)
|
|
|
|
continue;
|
|
|
|
for (; isdigit(*sp); sp++)
|
|
|
|
num = num * 10 + *sp - '0';
|
|
|
|
if (*sp == '\n')
|
|
|
|
return num;
|
|
|
|
else
|
|
|
|
printf("I can't understand that\n");
|
|
|
|
}
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine sets the monopoly flag from the list given.
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
set_ownlist(pl)
|
1999-08-21 14:40:03 +04:00
|
|
|
int pl;
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int num; /* general counter */
|
|
|
|
MON *orig; /* remember starting monop ptr */
|
|
|
|
OWN *op; /* current owned prop */
|
|
|
|
OWN *orig_op; /* origianl prop before loop */
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
op = play[pl].own_list;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("op [%d] = play[pl [%d] ].own_list;\n", op, pl);
|
|
|
|
#endif
|
|
|
|
while (op) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("op->sqr->type = %d\n", op->sqr->type);
|
|
|
|
#endif
|
|
|
|
switch (op->sqr->type) {
|
|
|
|
case UTIL:
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf(" case UTIL:\n");
|
|
|
|
#endif
|
1999-08-21 14:40:03 +04:00
|
|
|
for (num = 0; op && op->sqr->type == UTIL;
|
|
|
|
op = op->next)
|
1993-03-21 12:45:37 +03:00
|
|
|
num++;
|
|
|
|
play[pl].num_util = num;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("play[pl].num_util = num [%d];\n", num);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case RR:
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf(" case RR:\n");
|
|
|
|
#endif
|
1999-08-21 14:40:03 +04:00
|
|
|
for (num = 0; op && op->sqr->type == RR;
|
|
|
|
op = op->next) {
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
printf("iter: %d\n", num);
|
1999-08-21 14:40:03 +04:00
|
|
|
printf("op = %d, op->sqr = %d, "
|
|
|
|
"op->sqr->type = %d\n", op, op->sqr,
|
|
|
|
op->sqr->type);
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
play[pl].num_rr = num;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("play[pl].num_rr = num [%d];\n", num);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case PRPTY:
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf(" case PRPTY:\n");
|
|
|
|
#endif
|
|
|
|
orig = op->sqr->desc->mon_desc;
|
|
|
|
orig_op = op;
|
|
|
|
num = 0;
|
|
|
|
while (op && op->sqr->desc->mon_desc == orig) {
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("iter: %d\n", num);
|
|
|
|
#endif
|
|
|
|
num++;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("op = op->next ");
|
|
|
|
#endif
|
|
|
|
op = op->next;
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("[%d];\n", op);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("num = %d\n");
|
|
|
|
#endif
|
|
|
|
if (orig == 0) {
|
1999-08-21 14:40:03 +04:00
|
|
|
printf("panic: bad monopoly descriptor: "
|
|
|
|
"orig = %p\n", orig);
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("player # %d\n", pl+1);
|
|
|
|
printhold(pl);
|
1997-10-12 21:45:06 +04:00
|
|
|
printf("orig_op = %p\n", orig_op);
|
1999-08-21 14:40:03 +04:00
|
|
|
printf("orig_op->sqr->type = %d (PRPTY)\n",
|
|
|
|
op->sqr->type);
|
1997-10-12 21:45:06 +04:00
|
|
|
printf("orig_op->next = %p\n", op->next);
|
1999-08-21 14:40:03 +04:00
|
|
|
printf("orig_op->sqr->desc = %p\n",
|
|
|
|
op->sqr->desc);
|
1997-10-12 21:45:06 +04:00
|
|
|
printf("op = %p\n", op);
|
1999-08-21 14:40:03 +04:00
|
|
|
printf("op->sqr->type = %d (PRPTY)\n",
|
|
|
|
op->sqr->type);
|
1997-10-12 21:45:06 +04:00
|
|
|
printf("op->next = %p\n", op->next);
|
|
|
|
printf("op->sqr->desc = %p\n", op->sqr->desc);
|
1993-03-21 12:45:37 +03:00
|
|
|
printf("num = %d\n", num);
|
|
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("orig->num_in = %d\n", orig->num_in);
|
|
|
|
#endif
|
|
|
|
if (num == orig->num_in)
|
|
|
|
is_monop(orig, pl);
|
|
|
|
else
|
1999-09-30 22:01:31 +04:00
|
|
|
is_not_monop(orig);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine sets things up as if it is a new monopoly
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
is_monop(mp, pl)
|
1999-08-21 14:40:03 +04:00
|
|
|
MON *mp;
|
|
|
|
int pl;
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine sets things up as if it is no longer a monopoly
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
1999-09-30 22:01:31 +04:00
|
|
|
is_not_monop(mp)
|
1999-08-21 14:40:03 +04:00
|
|
|
MON *mp;
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int i;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
mp->owner = -1;
|
|
|
|
for (i = 0; i < mp->num_in; i++)
|
|
|
|
mp->sq[i]->desc->monop = FALSE;
|
|
|
|
mp->name = mp->not_m;
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine gives a list of the current player's routine
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
1999-08-21 14:40:03 +04:00
|
|
|
list()
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
printhold(player);
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine gives a list of a given players holdings
|
|
|
|
*/
|
1997-10-12 21:45:06 +04:00
|
|
|
void
|
1999-08-21 14:40:03 +04:00
|
|
|
list_all()
|
1997-10-12 21:45:06 +04:00
|
|
|
{
|
1999-08-21 14:40:03 +04:00
|
|
|
int pl;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1999-08-21 14:40:03 +04:00
|
|
|
while ((pl = getinp("Whose holdings do you want to see? ", name_list))
|
|
|
|
< num_play)
|
1993-03-21 12:45:37 +03:00
|
|
|
printhold(pl);
|
|
|
|
}
|
1999-08-21 14:40:03 +04:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
|
|
|
* This routine gives the players a chance before it exits.
|
|
|
|
*/
|
|
|
|
void
|
1997-10-12 21:45:06 +04:00
|
|
|
quit()
|
|
|
|
{
|
1993-03-21 12:45:37 +03:00
|
|
|
putchar('\n');
|
1997-10-12 21:45:06 +04:00
|
|
|
if (getyn("Do you all really want to quit? ") == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
exit(0);
|
|
|
|
}
|