NetBSD/games/monop/trade.c

330 lines
8.0 KiB
C
Raw Normal View History

2012-06-19 09:30:43 +04:00
/* $NetBSD: trade.c,v 1.16 2012/06/19 05:35:32 dholland Exp $ */
1993-03-21 12:45:37 +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. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* 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
#if 0
static char sccsid[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93";
#else
2012-06-19 09:30:43 +04:00
__RCSID("$NetBSD: trade.c,v 1.16 2012/06/19 05:35:32 dholland Exp $");
#endif
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#include "monop.h"
1993-03-21 12:45:37 +03:00
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 */
OWN *prop_list; /* property list */
};
typedef struct trd_st TRADE;
static const char *plist[MAX_PRP+2];
1993-03-21 12:45:37 +03:00
static int used[MAX_PRP];
static TRADE trades[2];
2004-01-27 23:30:28 +03:00
static void get_list(int, int );
static int set_list(OWN *);
static void summate(void);
static void do_trade(void);
static void move_em(TRADE *, TRADE *);
1993-03-21 12:45:37 +03:00
1997-10-12 21:45:06 +04:00
void
2012-06-19 09:30:43 +04:00
trade(void)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int tradee, i;
1993-03-21 12:45:37 +03:00
trading = TRUE;
for (i = 0; i < 2; i++) {
trades[i].cash = 0;
trades[i].gojf = FALSE;
trades[i].prop_list = NULL;
}
over:
if (num_play == 1) {
printf("There ain't no-one around to trade WITH!!\n");
return;
}
if (num_play > 2) {
tradee = getinp("Which player do you wish to trade with? ",
name_list);
if (tradee == num_play)
return;
if (tradee == player) {
printf("You can't trade with yourself!\n");
goto over;
}
}
else
tradee = 1 - player;
get_list(0, player);
get_list(1, tradee);
if (getyn("Do you wish a summary? ") == 0)
summate();
if (getyn("Is the trade ok? ") == 0)
do_trade();
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine gets the list of things to be trader for the
* player, and puts in the structure given.
*/
1997-10-12 21:45:06 +04:00
static void
2012-06-19 09:30:43 +04:00
get_list(int struct_no, int play_no)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int sn, pn;
PLAY *pp;
2008-01-28 09:16:13 +03:00
int numin, propnum, num_prp;
1999-08-21 14:40:03 +04:00
OWN *op;
TRADE *tp;
1993-03-21 12:45:37 +03:00
for (numin = 0; numin < MAX_PRP; numin++)
used[numin] = FALSE;
sn = struct_no, pn = play_no;
pp = &play[pn];
tp = &trades[sn];
tp->trader = pn;
printf("player %s (%d):\n", pp->name, pn+1);
if (pp->own_list) {
numin = set_list(pp->own_list);
for (num_prp = numin; num_prp; ) {
2008-01-28 09:16:13 +03:00
propnum=getinp("Which property do you wish to trade? ",
1997-10-12 21:45:06 +04:00
plist);
2008-01-28 09:16:13 +03:00
if (propnum == numin)
1993-03-21 12:45:37 +03:00
break;
2008-01-28 09:16:13 +03:00
else if (used[propnum])
1993-03-21 12:45:37 +03:00
printf("You've already allocated that.\n");
else {
num_prp--;
2008-01-28 09:16:13 +03:00
used[propnum] = TRUE;
for (op = pp->own_list; propnum--; op = op->next)
1993-03-21 12:45:37 +03:00
continue;
add_list(pn, &(tp->prop_list), sqnum(op->sqr));
}
}
}
if (pp->money > 0) {
printf("You have $%d. ", pp->money);
tp->cash = get_int("How much are you trading? ");
}
if (pp->num_gojf > 0) {
once_more:
printf("You have %d get-out-of-jail-free cards. ",pp->num_gojf);
tp->gojf = get_int("How many are you trading? ");
if (tp->gojf > pp->num_gojf) {
printf("You don't have that many. Try again.\n");
goto once_more;
}
}
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine sets up the list of tradable property.
*/
1997-10-12 21:45:06 +04:00
static int
2012-06-19 09:30:43 +04:00
set_list(OWN *the_list)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int i;
OWN *op;
1993-03-21 12:45:37 +03:00
i = 0;
for (op = the_list; op; op = op->next)
if (!used[i])
1997-10-12 21:45:06 +04:00
plist[i++] = op->sqr->name;
plist[i++] = "done";
plist[i--] = 0;
1993-03-21 12:45:37 +03:00
return i;
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine summates the trade.
*/
1997-10-12 21:45:06 +04:00
static void
2012-06-19 09:30:43 +04:00
summate(void)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
bool some;
int i;
TRADE *tp;
OWN *op;
1993-03-21 12:45:37 +03:00
for (i = 0; i < 2; i++) {
tp = &trades[i];
some = FALSE;
printf("Player %s (%d) gives:\n", play[tp->trader].name,
tp->trader+1);
if (tp->cash > 0)
printf("\t$%d\n", tp->cash), some++;
if (tp->gojf > 0)
printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf),
some++;
if (tp->prop_list) {
for (op = tp->prop_list; op; op = op->next)
putchar('\t'), printsq(sqnum(op->sqr), TRUE);
some++;
}
if (!some)
printf("\t-- Nothing --\n");
}
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine actually executes the trade.
*/
1997-10-12 21:45:06 +04:00
static void
2012-06-19 09:30:43 +04:00
do_trade(void)
1997-10-12 21:45:06 +04:00
{
1993-03-21 12:45:37 +03:00
move_em(&trades[0], &trades[1]);
move_em(&trades[1], &trades[0]);
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine does a switch from one player to another
*/
1997-10-12 21:45:06 +04:00
static void
2012-06-19 09:30:43 +04:00
move_em(TRADE *from, TRADE *to)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
PLAY *pl_fr, *pl_to;
OWN *op;
1993-03-21 12:45:37 +03:00
pl_fr = &play[from->trader];
pl_to = &play[to->trader];
pl_fr->money -= from->cash;
pl_to->money += from->cash;
pl_fr->num_gojf -= from->gojf;
pl_to->num_gojf += from->gojf;
for (op = from->prop_list; op; op = op->next) {
add_list(to->trader, &(pl_to->own_list), sqnum(op->sqr));
op->sqr->owner = to->trader;
del_list(from->trader, &(pl_fr->own_list), sqnum(op->sqr));
}
set_ownlist(to->trader);
}
1999-08-21 14:40:03 +04:00
1993-03-21 12:45:37 +03:00
/*
* This routine lets a player resign
*/
1997-10-12 21:45:06 +04:00
void
2012-06-19 09:30:43 +04:00
resign(void)
1997-10-12 21:45:06 +04:00
{
1999-08-21 14:40:03 +04:00
int i, new_own;
OWN *op;
SQUARE *sqp;
1993-03-21 12:45:37 +03:00
if (cur_p->money <= 0) {
switch (board[cur_p->loc].type) {
case UTIL:
case RR:
case PRPTY:
new_own = board[cur_p->loc].owner;
/* If you ran out of money by buying current location */
if (new_own == player)
new_own = num_play;
1993-03-21 12:45:37 +03:00
break;
default: /* Chance, taxes, etc */
new_own = num_play;
break;
}
if (new_own == num_play)
printf("You would resign to the bank\n");
else
printf("You would resign to %s\n", name_list[new_own]);
}
else if (num_play == 1) {
new_own = num_play;
printf("You would resign to the bank\n");
}
else {
name_list[num_play] = "bank";
do {
new_own = getinp("Who do you wish to resign to? ",
name_list);
if (new_own == player)
printf("You can't resign to yourself!!\n");
} while (new_own == player);
name_list[num_play] = "done";
}
1997-10-12 21:45:06 +04:00
if (getyn("Do you really want to resign? ") != 0)
1993-03-21 12:45:37 +03:00
return;
if (num_play == 1) {
printf("Then NOBODY wins (not even YOU!)\n");
exit(0);
}
if (new_own < num_play) { /* resign to player */
printf("resigning to player\n");
trades[0].trader = new_own;
trades[0].cash = trades[0].gojf = 0;
trades[0].prop_list = NULL;
trades[1].trader = player;
trades[1].cash = cur_p->money > 0 ? cur_p->money : 0;
trades[1].gojf = cur_p->num_gojf;
trades[1].prop_list = cur_p->own_list;
do_trade();
}
else { /* resign to bank */
printf("resigning to bank\n");
for (op = cur_p->own_list; op; op = op->next) {
sqp = op->sqr;
sqp->owner = -1;
sqp->desc->morg = FALSE;
if (sqp->type == PRPTY) {
is_not_monop(sqp->desc->mon_desc);
1993-03-21 12:45:37 +03:00
sqp->desc->houses = 0;
}
}
if (cur_p->num_gojf)
ret_card(cur_p);
}
2008-02-24 04:37:57 +03:00
free(play[player].name);
1993-03-21 12:45:37 +03:00
for (i = player; i < num_play; i++) {
name_list[i] = name_list[i+1];
if (i + 1 < num_play)
play[i] = play[i+1];
1993-03-21 12:45:37 +03:00
}
name_list[num_play--] = NULL;
1993-03-21 12:45:37 +03:00
for (i = 0; i < N_SQRS; i++)
if (board[i].owner > player)
--board[i].owner;
player = player == 0 ? num_play - 1 : player - 1;
1993-03-21 12:45:37 +03:00
next_play();
if (num_play < 2) {
printf("\nThen %s WINS!!!!!\n", play[0].name);
printhold(0);
printf("That's a grand worth of $%d.\n",
play[0].money+prop_worth(&play[0]));
exit(0);
}
}