]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/trade.c
move the ) to after the 3rd arg to open. weeeeee!
[bsdgames-darwin.git] / monop / trade.c
1 /* $NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd 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 #ifndef lint
37 #if 0
38 static char sccsid[] = "@(#)trade.c 8.1 (Berkeley) 5/31/93";
39 #else
40 static char rcsid[] = "$NetBSD: trade.c,v 1.3 1995/03/23 08:35:19 cgd Exp $";
41 #endif
42 #endif /* not lint */
43
44 # include "monop.ext"
45
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 */
51 };
52
53 typedef struct trd_st TRADE;
54
55 static char *list[MAX_PRP+2];
56
57 static int used[MAX_PRP];
58
59 static TRADE trades[2];
60
61 trade() {
62
63 reg int tradee, i;
64
65 trading = TRUE;
66 for (i = 0; i < 2; i++) {
67 trades[i].cash = 0;
68 trades[i].gojf = FALSE;
69 trades[i].prop_list = NULL;
70 }
71 over:
72 if (num_play == 1) {
73 printf("There ain't no-one around to trade WITH!!\n");
74 return;
75 }
76 if (num_play > 2) {
77 tradee = getinp("Which player do you wish to trade with? ",
78 name_list);
79 if (tradee == num_play)
80 return;
81 if (tradee == player) {
82 printf("You can't trade with yourself!\n");
83 goto over;
84 }
85 }
86 else
87 tradee = 1 - player;
88 get_list(0, player);
89 get_list(1, tradee);
90 if (getyn("Do you wish a summary? ") == 0)
91 summate();
92 if (getyn("Is the trade ok? ") == 0)
93 do_trade();
94 }
95 /*
96 * This routine gets the list of things to be trader for the
97 * player, and puts in the structure given.
98 */
99 get_list(struct_no, play_no)
100 int struct_no, play_no; {
101
102 reg int sn, pn;
103 reg PLAY *pp;
104 int numin, prop, num_prp;
105 OWN *op;
106 TRADE *tp;
107
108 for (numin = 0; numin < MAX_PRP; numin++)
109 used[numin] = FALSE;
110 sn = struct_no, pn = play_no;
111 pp = &play[pn];
112 tp = &trades[sn];
113 tp->trader = pn;
114 printf("player %s (%d):\n", pp->name, pn+1);
115 if (pp->own_list) {
116 numin = set_list(pp->own_list);
117 for (num_prp = numin; num_prp; ) {
118 prop = getinp("Which property do you wish to trade? ",
119 list);
120 if (prop == numin)
121 break;
122 else if (used[prop])
123 printf("You've already allocated that.\n");
124 else {
125 num_prp--;
126 used[prop] = TRUE;
127 for (op = pp->own_list; prop--; op = op->next)
128 continue;
129 add_list(pn, &(tp->prop_list), sqnum(op->sqr));
130 }
131 }
132 }
133 if (pp->money > 0) {
134 printf("You have $%d. ", pp->money);
135 tp->cash = get_int("How much are you trading? ");
136 }
137 if (pp->num_gojf > 0) {
138 once_more:
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");
143 goto once_more;
144 }
145 }
146 }
147 /*
148 * This routine sets up the list of tradable property.
149 */
150 set_list(the_list)
151 reg OWN *the_list; {
152
153 reg int i;
154 reg OWN *op;
155
156 i = 0;
157 for (op = the_list; op; op = op->next)
158 if (!used[i])
159 list[i++] = op->sqr->name;
160 list[i++] = "done";
161 list[i--] = 0;
162 return i;
163 }
164 /*
165 * This routine summates the trade.
166 */
167 summate() {
168
169 reg bool some;
170 reg int i;
171 reg TRADE *tp;
172 OWN *op;
173
174 for (i = 0; i < 2; i++) {
175 tp = &trades[i];
176 some = FALSE;
177 printf("Player %s (%d) gives:\n", play[tp->trader].name,
178 tp->trader+1);
179 if (tp->cash > 0)
180 printf("\t$%d\n", tp->cash), some++;
181 if (tp->gojf > 0)
182 printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf),
183 some++;
184 if (tp->prop_list) {
185 for (op = tp->prop_list; op; op = op->next)
186 putchar('\t'), printsq(sqnum(op->sqr), TRUE);
187 some++;
188 }
189 if (!some)
190 printf("\t-- Nothing --\n");
191 }
192 }
193 /*
194 * This routine actually executes the trade.
195 */
196 do_trade() {
197
198 move_em(&trades[0], &trades[1]);
199 move_em(&trades[1], &trades[0]);
200 }
201 /*
202 * This routine does a switch from one player to another
203 */
204 move_em(from, to)
205 TRADE *from, *to; {
206
207 reg PLAY *pl_fr, *pl_to;
208 reg OWN *op;
209
210 pl_fr = &play[from->trader];
211 pl_to = &play[to->trader];
212
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));
221 }
222 set_ownlist(to->trader);
223 }
224 /*
225 * This routine lets a player resign
226 */
227 resign() {
228
229 reg int i, new_own;
230 reg OWN *op;
231 SQUARE *sqp;
232
233 if (cur_p->money <= 0) {
234 switch (board[cur_p->loc].type) {
235 case UTIL:
236 case RR:
237 case PRPTY:
238 new_own = board[cur_p->loc].owner;
239 break;
240 default: /* Chance, taxes, etc */
241 new_own = num_play;
242 break;
243 }
244 if (new_own == num_play)
245 printf("You would resign to the bank\n");
246 else
247 printf("You would resign to %s\n", name_list[new_own]);
248 }
249 else if (num_play == 1) {
250 new_own = num_play;
251 printf("You would resign to the bank\n");
252 }
253 else {
254 name_list[num_play] = "bank";
255 do {
256 new_own = getinp("Who do you wish to resign to? ",
257 name_list);
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";
262 }
263 if (getyn("Do you really want to resign? ", yn) != 0)
264 return;
265 if (num_play == 1) {
266 printf("Then NOBODY wins (not even YOU!)\n");
267 exit(0);
268 }
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;
278 do_trade();
279 }
280 else { /* resign to bank */
281 printf("resigning to bank\n");
282 for (op = cur_p->own_list; op; op = op->next) {
283 sqp = op->sqr;
284 sqp->owner = -1;
285 sqp->desc->morg = FALSE;
286 if (sqp->type == PRPTY) {
287 isnot_monop(sqp->desc->mon_desc);
288 sqp->desc->houses = 0;
289 }
290 }
291 if (cur_p->num_gojf)
292 ret_card(cur_p);
293 }
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));
298 }
299 name_list[num_play--] = 0;
300 for (i = 0; i < N_SQRS; i++)
301 if (board[i].owner > player)
302 --board[i].owner;
303 player = --player < 0 ? num_play - 1 : player;
304 next_play();
305 if (num_play < 2) {
306 printf("\nThen %s WINS!!!!!\n", play[0].name);
307 printhold(0);
308 printf("That's a grand worth of $%d.\n",
309 play[0].money+prop_worth(&play[0]));
310 exit(0);
311 }
312 }