* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 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
static char sccsid
[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90";
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 char *list
[MAX_PRP
+2];
static int used
[MAX_PRP
];
for (i
= 0; i
< 2; i
++) {
trades
[i
].prop_list
= NULL
;
printf("There ain't no-one around to trade WITH!!\n");
tradee
= getinp("Which player do you wish to trade with? ",
printf("You can't trade with yourself!\n");
if (getyn("Do you wish a summary? ") == 0)
if (getyn("Is the trade ok? ") == 0)
* This routine gets the list of things to be trader for the
* player, and puts in the structure given.
get_list(struct_no
, play_no
)
int struct_no
, play_no
; {
int numin
, prop
, num_prp
;
for (numin
= 0; numin
< MAX_PRP
; numin
++)
sn
= struct_no
, pn
= play_no
;
printf("player %s (%d):\n", pp
->name
, pn
+1);
numin
= set_list(pp
->own_list
);
for (num_prp
= numin
; num_prp
; ) {
prop
= getinp("Which property do you wish to trade? ",
printf("You've already allocated that.\n");
for (op
= pp
->own_list
; prop
--; op
= op
->next
)
add_list(pn
, &(tp
->prop_list
), sqnum(op
->sqr
));
printf("You have $%d. ", pp
->money
);
tp
->cash
= get_int("How much are you trading? ");
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");
* This routine sets up the list of tradable property.
for (op
= the_list
; op
; op
= op
->next
)
list
[i
++] = op
->sqr
->name
;
* This routine summates the trade.
for (i
= 0; i
< 2; i
++) {
printf("Player %s (%d) gives:\n", play
[tp
->trader
].name
,
printf("\t$%d\n", tp
->cash
), some
++;
printf("\t%d get-out-of-jail-free card(s)\n", tp
->gojf
),
for (op
= tp
->prop_list
; op
; op
= op
->next
)
putchar('\t'), printsq(sqnum(op
->sqr
), TRUE
);
printf("\t-- Nothing --\n");
* This routine actually executes the trade.
move_em(&trades
[0], &trades
[1]);
move_em(&trades
[1], &trades
[0]);
* This routine does a switch from one player to another
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
));
* This routine lets a player resign
switch (board
[cur_p
->loc
].type
) {
new_own
= board
[cur_p
->loc
].owner
;
default: /* Chance, taxes, etc */
printf("You would resign to the bank\n");
printf("You would resign to %s\n", name_list
[new_own
]);
else if (num_play
== 1) {
printf("You would resign to the bank\n");
name_list
[num_play
] = "bank";
new_own
= getinp("Who do you wish to resign to? ",
printf("You can't resign to yourself!!\n");
} while (new_own
== player
);
name_list
[num_play
] = "done";
if (getyn("Do you really want to resign? ", yn
) != 0)
printf("Then NOBODY wins (not even YOU!)\n");
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
;
else { /* resign to bank */
printf("resigning to bank\n");
for (op
= cur_p
->own_list
; op
; op
= op
->next
) {
if (sqp
->type
== PRPTY
) {
isnot_monop(sqp
->desc
->mon_desc
);
for (i
= player
; i
< num_play
; i
++) {
name_list
[i
] = name_list
[i
+1];
cpy_st(&play
[i
], &play
[i
+1], sizeof (PLAY
));
name_list
[num_play
--] = 0;
for (i
= 0; i
< N_SQRS
; i
++)
if (board
[i
].owner
> player
)
player
= --player
< 0 ? num_play
- 1 : player
;
printf("\nThen %s WINS!!!!!\n", play
[0].name
);
printf("That's a grand worth of $%d.\n",
play
[0].money
+prop_worth(&play
[0]));