]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/trade.c
WARNSify
[bsdgames-darwin.git] / monop / trade.c
1 /* $NetBSD: trade.c,v 1.4 1997/10/12 17:45:27 christos Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
22 *
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
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: trade.c,v 1.4 1997/10/12 17:45:27 christos Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "monop.ext"
46
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 */
52 };
53
54 typedef struct trd_st TRADE;
55
56 static char *plist[MAX_PRP+2];
57
58 static int used[MAX_PRP];
59
60 static TRADE trades[2];
61
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 *));
67
68 void
69 trade()
70 {
71
72 int tradee, i;
73
74 trading = TRUE;
75 for (i = 0; i < 2; i++) {
76 trades[i].cash = 0;
77 trades[i].gojf = FALSE;
78 trades[i].prop_list = NULL;
79 }
80 over:
81 if (num_play == 1) {
82 printf("There ain't no-one around to trade WITH!!\n");
83 return;
84 }
85 if (num_play > 2) {
86 tradee = getinp("Which player do you wish to trade with? ",
87 name_list);
88 if (tradee == num_play)
89 return;
90 if (tradee == player) {
91 printf("You can't trade with yourself!\n");
92 goto over;
93 }
94 }
95 else
96 tradee = 1 - player;
97 get_list(0, player);
98 get_list(1, tradee);
99 if (getyn("Do you wish a summary? ") == 0)
100 summate();
101 if (getyn("Is the trade ok? ") == 0)
102 do_trade();
103 }
104 /*
105 * This routine gets the list of things to be trader for the
106 * player, and puts in the structure given.
107 */
108 static void
109 get_list(struct_no, play_no)
110 int struct_no, play_no;
111 {
112
113 int sn, pn;
114 PLAY *pp;
115 int numin, prop, num_prp;
116 OWN *op;
117 TRADE *tp;
118
119 for (numin = 0; numin < MAX_PRP; numin++)
120 used[numin] = FALSE;
121 sn = struct_no, pn = play_no;
122 pp = &play[pn];
123 tp = &trades[sn];
124 tp->trader = pn;
125 printf("player %s (%d):\n", pp->name, pn+1);
126 if (pp->own_list) {
127 numin = set_list(pp->own_list);
128 for (num_prp = numin; num_prp; ) {
129 prop = getinp("Which property do you wish to trade? ",
130 plist);
131 if (prop == numin)
132 break;
133 else if (used[prop])
134 printf("You've already allocated that.\n");
135 else {
136 num_prp--;
137 used[prop] = TRUE;
138 for (op = pp->own_list; prop--; op = op->next)
139 continue;
140 add_list(pn, &(tp->prop_list), sqnum(op->sqr));
141 }
142 }
143 }
144 if (pp->money > 0) {
145 printf("You have $%d. ", pp->money);
146 tp->cash = get_int("How much are you trading? ");
147 }
148 if (pp->num_gojf > 0) {
149 once_more:
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");
154 goto once_more;
155 }
156 }
157 }
158 /*
159 * This routine sets up the list of tradable property.
160 */
161 static int
162 set_list(the_list)
163 OWN *the_list;
164 {
165
166 int i;
167 OWN *op;
168
169 i = 0;
170 for (op = the_list; op; op = op->next)
171 if (!used[i])
172 plist[i++] = op->sqr->name;
173 plist[i++] = "done";
174 plist[i--] = 0;
175 return i;
176 }
177 /*
178 * This routine summates the trade.
179 */
180 static void
181 summate()
182 {
183
184 bool some;
185 int i;
186 TRADE *tp;
187 OWN *op;
188
189 for (i = 0; i < 2; i++) {
190 tp = &trades[i];
191 some = FALSE;
192 printf("Player %s (%d) gives:\n", play[tp->trader].name,
193 tp->trader+1);
194 if (tp->cash > 0)
195 printf("\t$%d\n", tp->cash), some++;
196 if (tp->gojf > 0)
197 printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf),
198 some++;
199 if (tp->prop_list) {
200 for (op = tp->prop_list; op; op = op->next)
201 putchar('\t'), printsq(sqnum(op->sqr), TRUE);
202 some++;
203 }
204 if (!some)
205 printf("\t-- Nothing --\n");
206 }
207 }
208 /*
209 * This routine actually executes the trade.
210 */
211 static void
212 do_trade()
213 {
214
215 move_em(&trades[0], &trades[1]);
216 move_em(&trades[1], &trades[0]);
217 }
218 /*
219 * This routine does a switch from one player to another
220 */
221 static void
222 move_em(from, to)
223 TRADE *from, *to;
224 {
225
226 PLAY *pl_fr, *pl_to;
227 OWN *op;
228
229 pl_fr = &play[from->trader];
230 pl_to = &play[to->trader];
231
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));
240 }
241 set_ownlist(to->trader);
242 }
243 /*
244 * This routine lets a player resign
245 */
246 void
247 resign()
248 {
249
250 int i, new_own;
251 OWN *op;
252 SQUARE *sqp;
253
254 if (cur_p->money <= 0) {
255 switch (board[cur_p->loc].type) {
256 case UTIL:
257 case RR:
258 case PRPTY:
259 new_own = board[cur_p->loc].owner;
260 break;
261 default: /* Chance, taxes, etc */
262 new_own = num_play;
263 break;
264 }
265 if (new_own == num_play)
266 printf("You would resign to the bank\n");
267 else
268 printf("You would resign to %s\n", name_list[new_own]);
269 }
270 else if (num_play == 1) {
271 new_own = num_play;
272 printf("You would resign to the bank\n");
273 }
274 else {
275 name_list[num_play] = "bank";
276 do {
277 new_own = getinp("Who do you wish to resign to? ",
278 name_list);
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";
283 }
284 if (getyn("Do you really want to resign? ") != 0)
285 return;
286 if (num_play == 1) {
287 printf("Then NOBODY wins (not even YOU!)\n");
288 exit(0);
289 }
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;
299 do_trade();
300 }
301 else { /* resign to bank */
302 printf("resigning to bank\n");
303 for (op = cur_p->own_list; op; op = op->next) {
304 sqp = op->sqr;
305 sqp->owner = -1;
306 sqp->desc->morg = FALSE;
307 if (sqp->type == PRPTY) {
308 isnot_monop(sqp->desc->mon_desc);
309 sqp->desc->houses = 0;
310 }
311 }
312 if (cur_p->num_gojf)
313 ret_card(cur_p);
314 }
315 for (i = player; i < num_play; i++) {
316 name_list[i] = name_list[i+1];
317 if (i + 1 < num_play)
318 play[i] = play[i+1];
319 }
320 name_list[num_play--] = 0;
321 for (i = 0; i < N_SQRS; i++)
322 if (board[i].owner > player)
323 --board[i].owner;
324 player = --player < 0 ? num_play - 1 : player;
325 next_play();
326 if (num_play < 2) {
327 printf("\nThen %s WINS!!!!!\n", play[0].name);
328 printhold(0);
329 printf("That's a grand worth of $%d.\n",
330 play[0].money+prop_worth(&play[0]));
331 exit(0);
332 }
333 }