]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/trade.c
1 /* $NetBSD: trade.c,v 1.4 1997/10/12 17:45:27 christos Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: trade.c,v 1.4 1997/10/12 17:45:27 christos Exp $");
47 struct trd_st
{ /* how much to give to other player */
48 int trader
; /* trader number */
49 int cash
; /* amount of cash */
50 int gojf
; /* # get-out-of-jail-free cards */
51 OWN
*prop_list
; /* property list */
54 typedef struct trd_st TRADE
;
56 static char *plist
[MAX_PRP
+2];
58 static int used
[MAX_PRP
];
60 static TRADE trades
[2];
62 static void get_list
__P((int, int ));
63 static int set_list
__P((OWN
*));
64 static void summate
__P((void));
65 static void do_trade
__P((void));
66 static void move_em
__P((TRADE
*, TRADE
*));
75 for (i
= 0; i
< 2; i
++) {
77 trades
[i
].gojf
= FALSE
;
78 trades
[i
].prop_list
= NULL
;
82 printf("There ain't no-one around to trade WITH!!\n");
86 tradee
= getinp("Which player do you wish to trade with? ",
88 if (tradee
== num_play
)
90 if (tradee
== player
) {
91 printf("You can't trade with yourself!\n");
99 if (getyn("Do you wish a summary? ") == 0)
101 if (getyn("Is the trade ok? ") == 0)
105 * This routine gets the list of things to be trader for the
106 * player, and puts in the structure given.
109 get_list(struct_no
, play_no
)
110 int struct_no
, play_no
;
115 int numin
, prop
, num_prp
;
119 for (numin
= 0; numin
< MAX_PRP
; numin
++)
121 sn
= struct_no
, pn
= play_no
;
125 printf("player %s (%d):\n", pp
->name
, pn
+1);
127 numin
= set_list(pp
->own_list
);
128 for (num_prp
= numin
; num_prp
; ) {
129 prop
= getinp("Which property do you wish to trade? ",
134 printf("You've already allocated that.\n");
138 for (op
= pp
->own_list
; prop
--; op
= op
->next
)
140 add_list(pn
, &(tp
->prop_list
), sqnum(op
->sqr
));
145 printf("You have $%d. ", pp
->money
);
146 tp
->cash
= get_int("How much are you trading? ");
148 if (pp
->num_gojf
> 0) {
150 printf("You have %d get-out-of-jail-free cards. ",pp
->num_gojf
);
151 tp
->gojf
= get_int("How many are you trading? ");
152 if (tp
->gojf
> pp
->num_gojf
) {
153 printf("You don't have that many. Try again.\n");
159 * This routine sets up the list of tradable property.
170 for (op
= the_list
; op
; op
= op
->next
)
172 plist
[i
++] = op
->sqr
->name
;
178 * This routine summates the trade.
189 for (i
= 0; i
< 2; i
++) {
192 printf("Player %s (%d) gives:\n", play
[tp
->trader
].name
,
195 printf("\t$%d\n", tp
->cash
), some
++;
197 printf("\t%d get-out-of-jail-free card(s)\n", tp
->gojf
),
200 for (op
= tp
->prop_list
; op
; op
= op
->next
)
201 putchar('\t'), printsq(sqnum(op
->sqr
), TRUE
);
205 printf("\t-- Nothing --\n");
209 * This routine actually executes the trade.
215 move_em(&trades
[0], &trades
[1]);
216 move_em(&trades
[1], &trades
[0]);
219 * This routine does a switch from one player to another
229 pl_fr
= &play
[from
->trader
];
230 pl_to
= &play
[to
->trader
];
232 pl_fr
->money
-= from
->cash
;
233 pl_to
->money
+= from
->cash
;
234 pl_fr
->num_gojf
-= from
->gojf
;
235 pl_to
->num_gojf
+= from
->gojf
;
236 for (op
= from
->prop_list
; op
; op
= op
->next
) {
237 add_list(to
->trader
, &(pl_to
->own_list
), sqnum(op
->sqr
));
238 op
->sqr
->owner
= to
->trader
;
239 del_list(from
->trader
, &(pl_fr
->own_list
), sqnum(op
->sqr
));
241 set_ownlist(to
->trader
);
244 * This routine lets a player resign
254 if (cur_p
->money
<= 0) {
255 switch (board
[cur_p
->loc
].type
) {
259 new_own
= board
[cur_p
->loc
].owner
;
261 default: /* Chance, taxes, etc */
265 if (new_own
== num_play
)
266 printf("You would resign to the bank\n");
268 printf("You would resign to %s\n", name_list
[new_own
]);
270 else if (num_play
== 1) {
272 printf("You would resign to the bank\n");
275 name_list
[num_play
] = "bank";
277 new_own
= getinp("Who do you wish to resign to? ",
279 if (new_own
== player
)
280 printf("You can't resign to yourself!!\n");
281 } while (new_own
== player
);
282 name_list
[num_play
] = "done";
284 if (getyn("Do you really want to resign? ") != 0)
287 printf("Then NOBODY wins (not even YOU!)\n");
290 if (new_own
< num_play
) { /* resign to player */
291 printf("resigning to player\n");
292 trades
[0].trader
= new_own
;
293 trades
[0].cash
= trades
[0].gojf
= 0;
294 trades
[0].prop_list
= NULL
;
295 trades
[1].trader
= player
;
296 trades
[1].cash
= cur_p
->money
> 0 ? cur_p
->money
: 0;
297 trades
[1].gojf
= cur_p
->num_gojf
;
298 trades
[1].prop_list
= cur_p
->own_list
;
301 else { /* resign to bank */
302 printf("resigning to bank\n");
303 for (op
= cur_p
->own_list
; op
; op
= op
->next
) {
306 sqp
->desc
->morg
= FALSE
;
307 if (sqp
->type
== PRPTY
) {
308 isnot_monop(sqp
->desc
->mon_desc
);
309 sqp
->desc
->houses
= 0;
315 for (i
= player
; i
< num_play
; i
++) {
316 name_list
[i
] = name_list
[i
+1];
317 if (i
+ 1 < num_play
)
320 name_list
[num_play
--] = 0;
321 for (i
= 0; i
< N_SQRS
; i
++)
322 if (board
[i
].owner
> player
)
324 player
= --player
< 0 ? num_play
- 1 : player
;
327 printf("\nThen %s WINS!!!!!\n", play
[0].name
);
329 printf("That's a grand worth of $%d.\n",
330 play
[0].money
+prop_worth(&play
[0]));