]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/trade.c
1 /* $NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd 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
38 static char sccsid
[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd Exp $";
46 struct trd_st
{ /* how much to give to other player */
47 int trader
; /* trader number */
48 int cash
; /* amount of cash */
49 int gojf
; /* # get-out-of-jail-free cards */
50 OWN
*prop_list
; /* property list */
53 typedef struct trd_st TRADE
;
55 static char *list
[MAX_PRP
+2];
57 static int used
[MAX_PRP
];
59 static TRADE trades
[2];
66 for (i
= 0; i
< 2; i
++) {
68 trades
[i
].gojf
= FALSE
;
69 trades
[i
].prop_list
= NULL
;
73 printf("There ain't no-one around to trade WITH!!\n");
77 tradee
= getinp("Which player do you wish to trade with? ",
79 if (tradee
== num_play
)
81 if (tradee
== player
) {
82 printf("You can't trade with yourself!\n");
90 if (getyn("Do you wish a summary? ") == 0)
92 if (getyn("Is the trade ok? ") == 0)
96 * This routine gets the list of things to be trader for the
97 * player, and puts in the structure given.
99 get_list(struct_no
, play_no
)
100 int struct_no
, play_no
; {
104 int numin
, prop
, num_prp
;
108 for (numin
= 0; numin
< MAX_PRP
; numin
++)
110 sn
= struct_no
, pn
= play_no
;
114 printf("player %s (%d):\n", pp
->name
, pn
+1);
116 numin
= set_list(pp
->own_list
);
117 for (num_prp
= numin
; num_prp
; ) {
118 prop
= getinp("Which property do you wish to trade? ",
123 printf("You've already allocated that.\n");
127 for (op
= pp
->own_list
; prop
--; op
= op
->next
)
129 add_list(pn
, &(tp
->prop_list
), sqnum(op
->sqr
));
134 printf("You have $%d. ", pp
->money
);
135 tp
->cash
= get_int("How much are you trading? ");
137 if (pp
->num_gojf
> 0) {
139 printf("You have %d get-out-of-jail-free cards. ",pp
->num_gojf
);
140 tp
->gojf
= get_int("How many are you trading? ");
141 if (tp
->gojf
> pp
->num_gojf
) {
142 printf("You don't have that many. Try again.\n");
148 * This routine sets up the list of tradable property.
157 for (op
= the_list
; op
; op
= op
->next
)
159 list
[i
++] = op
->sqr
->name
;
165 * This routine summates the trade.
174 for (i
= 0; i
< 2; i
++) {
177 printf("Player %s (%d) gives:\n", play
[tp
->trader
].name
,
180 printf("\t$%d\n", tp
->cash
), some
++;
182 printf("\t%d get-out-of-jail-free card(s)\n", tp
->gojf
),
185 for (op
= tp
->prop_list
; op
; op
= op
->next
)
186 putchar('\t'), printsq(sqnum(op
->sqr
), TRUE
);
190 printf("\t-- Nothing --\n");
194 * This routine actually executes the trade.
198 move_em(&trades
[0], &trades
[1]);
199 move_em(&trades
[1], &trades
[0]);
202 * This routine does a switch from one player to another
207 reg PLAY
*pl_fr
, *pl_to
;
210 pl_fr
= &play
[from
->trader
];
211 pl_to
= &play
[to
->trader
];
213 pl_fr
->money
-= from
->cash
;
214 pl_to
->money
+= from
->cash
;
215 pl_fr
->num_gojf
-= from
->gojf
;
216 pl_to
->num_gojf
+= from
->gojf
;
217 for (op
= from
->prop_list
; op
; op
= op
->next
) {
218 add_list(to
->trader
, &(pl_to
->own_list
), sqnum(op
->sqr
));
219 op
->sqr
->owner
= to
->trader
;
220 del_list(from
->trader
, &(pl_fr
->own_list
), sqnum(op
->sqr
));
222 set_ownlist(to
->trader
);
225 * This routine lets a player resign
233 if (cur_p
->money
<= 0) {
234 switch (board
[cur_p
->loc
].type
) {
238 new_own
= board
[cur_p
->loc
].owner
;
240 default: /* Chance, taxes, etc */
244 if (new_own
== num_play
)
245 printf("You would resign to the bank\n");
247 printf("You would resign to %s\n", name_list
[new_own
]);
249 else if (num_play
== 1) {
251 printf("You would resign to the bank\n");
254 name_list
[num_play
] = "bank";
256 new_own
= getinp("Who do you wish to resign to? ",
258 if (new_own
== player
)
259 printf("You can't resign to yourself!!\n");
260 } while (new_own
== player
);
261 name_list
[num_play
] = "done";
263 if (getyn("Do you really want to resign? ", yn
) != 0)
266 printf("Then NOBODY wins (not even YOU!)\n");
269 if (new_own
< num_play
) { /* resign to player */
270 printf("resigning to player\n");
271 trades
[0].trader
= new_own
;
272 trades
[0].cash
= trades
[0].gojf
= 0;
273 trades
[0].prop_list
= NULL
;
274 trades
[1].trader
= player
;
275 trades
[1].cash
= cur_p
->money
> 0 ? cur_p
->money
: 0;
276 trades
[1].gojf
= cur_p
->num_gojf
;
277 trades
[1].prop_list
= cur_p
->own_list
;
280 else { /* resign to bank */
281 printf("resigning to bank\n");
282 for (op
= cur_p
->own_list
; op
; op
= op
->next
) {
285 sqp
->desc
->morg
= FALSE
;
286 if (sqp
->type
== PRPTY
) {
287 isnot_monop(sqp
->desc
->mon_desc
);
288 sqp
->desc
->houses
= 0;
294 for (i
= player
; i
< num_play
; i
++) {
295 name_list
[i
] = name_list
[i
+1];
296 if (i
+ 1 < num_play
)
297 cpy_st(&play
[i
], &play
[i
+1], sizeof (PLAY
));
299 name_list
[num_play
--] = 0;
300 for (i
= 0; i
< N_SQRS
; i
++)
301 if (board
[i
].owner
> player
)
303 player
= --player
< 0 ? num_play
- 1 : player
;
306 printf("\nThen %s WINS!!!!!\n", play
[0].name
);
308 printf("That's a grand worth of $%d.\n",
309 play
[0].money
+prop_worth(&play
[0]));