Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)trade.c 5.5 (Berkeley) 6/1/90"; | |
36 | #endif /* not lint */ | |
37 | ||
38 | # include "monop.ext" | |
39 | ||
40 | struct trd_st { /* how much to give to other player */ | |
41 | int trader; /* trader number */ | |
42 | int cash; /* amount of cash */ | |
43 | int gojf; /* # get-out-of-jail-free cards */ | |
44 | OWN *prop_list; /* property list */ | |
45 | }; | |
46 | ||
47 | typedef struct trd_st TRADE; | |
48 | ||
49 | static char *list[MAX_PRP+2]; | |
50 | ||
51 | static int used[MAX_PRP]; | |
52 | ||
53 | static TRADE trades[2]; | |
54 | ||
55 | trade() { | |
56 | ||
57 | reg int tradee, i; | |
58 | ||
59 | trading = TRUE; | |
60 | for (i = 0; i < 2; i++) { | |
61 | trades[i].cash = 0; | |
62 | trades[i].gojf = FALSE; | |
63 | trades[i].prop_list = NULL; | |
64 | } | |
65 | over: | |
66 | if (num_play == 1) { | |
67 | printf("There ain't no-one around to trade WITH!!\n"); | |
68 | return; | |
69 | } | |
70 | if (num_play > 2) { | |
71 | tradee = getinp("Which player do you wish to trade with? ", | |
72 | name_list); | |
73 | if (tradee == num_play) | |
74 | return; | |
75 | if (tradee == player) { | |
76 | printf("You can't trade with yourself!\n"); | |
77 | goto over; | |
78 | } | |
79 | } | |
80 | else | |
81 | tradee = 1 - player; | |
82 | get_list(0, player); | |
83 | get_list(1, tradee); | |
84 | if (getyn("Do you wish a summary? ") == 0) | |
85 | summate(); | |
86 | if (getyn("Is the trade ok? ") == 0) | |
87 | do_trade(); | |
88 | } | |
89 | /* | |
90 | * This routine gets the list of things to be trader for the | |
91 | * player, and puts in the structure given. | |
92 | */ | |
93 | get_list(struct_no, play_no) | |
94 | int struct_no, play_no; { | |
95 | ||
96 | reg int sn, pn; | |
97 | reg PLAY *pp; | |
98 | int numin, prop, num_prp; | |
99 | OWN *op; | |
100 | TRADE *tp; | |
101 | ||
102 | for (numin = 0; numin < MAX_PRP; numin++) | |
103 | used[numin] = FALSE; | |
104 | sn = struct_no, pn = play_no; | |
105 | pp = &play[pn]; | |
106 | tp = &trades[sn]; | |
107 | tp->trader = pn; | |
108 | printf("player %s (%d):\n", pp->name, pn+1); | |
109 | if (pp->own_list) { | |
110 | numin = set_list(pp->own_list); | |
111 | for (num_prp = numin; num_prp; ) { | |
112 | prop = getinp("Which property do you wish to trade? ", | |
113 | list); | |
114 | if (prop == numin) | |
115 | break; | |
116 | else if (used[prop]) | |
117 | printf("You've already allocated that.\n"); | |
118 | else { | |
119 | num_prp--; | |
120 | used[prop] = TRUE; | |
121 | for (op = pp->own_list; prop--; op = op->next) | |
122 | continue; | |
123 | add_list(pn, &(tp->prop_list), sqnum(op->sqr)); | |
124 | } | |
125 | } | |
126 | } | |
127 | if (pp->money > 0) { | |
128 | printf("You have $%d. ", pp->money); | |
129 | tp->cash = get_int("How much are you trading? "); | |
130 | } | |
131 | if (pp->num_gojf > 0) { | |
132 | once_more: | |
133 | printf("You have %d get-out-of-jail-free cards. ",pp->num_gojf); | |
134 | tp->gojf = get_int("How many are you trading? "); | |
135 | if (tp->gojf > pp->num_gojf) { | |
136 | printf("You don't have that many. Try again.\n"); | |
137 | goto once_more; | |
138 | } | |
139 | } | |
140 | } | |
141 | /* | |
142 | * This routine sets up the list of tradable property. | |
143 | */ | |
144 | set_list(the_list) | |
145 | reg OWN *the_list; { | |
146 | ||
147 | reg int i; | |
148 | reg OWN *op; | |
149 | ||
150 | i = 0; | |
151 | for (op = the_list; op; op = op->next) | |
152 | if (!used[i]) | |
153 | list[i++] = op->sqr->name; | |
154 | list[i++] = "done"; | |
155 | list[i--] = 0; | |
156 | return i; | |
157 | } | |
158 | /* | |
159 | * This routine summates the trade. | |
160 | */ | |
161 | summate() { | |
162 | ||
163 | reg bool some; | |
164 | reg int i; | |
165 | reg TRADE *tp; | |
166 | OWN *op; | |
167 | ||
168 | for (i = 0; i < 2; i++) { | |
169 | tp = &trades[i]; | |
170 | some = FALSE; | |
171 | printf("Player %s (%d) gives:\n", play[tp->trader].name, | |
172 | tp->trader+1); | |
173 | if (tp->cash > 0) | |
174 | printf("\t$%d\n", tp->cash), some++; | |
175 | if (tp->gojf > 0) | |
176 | printf("\t%d get-out-of-jail-free card(s)\n", tp->gojf), | |
177 | some++; | |
178 | if (tp->prop_list) { | |
179 | for (op = tp->prop_list; op; op = op->next) | |
180 | putchar('\t'), printsq(sqnum(op->sqr), TRUE); | |
181 | some++; | |
182 | } | |
183 | if (!some) | |
184 | printf("\t-- Nothing --\n"); | |
185 | } | |
186 | } | |
187 | /* | |
188 | * This routine actually executes the trade. | |
189 | */ | |
190 | do_trade() { | |
191 | ||
192 | move_em(&trades[0], &trades[1]); | |
193 | move_em(&trades[1], &trades[0]); | |
194 | } | |
195 | /* | |
196 | * This routine does a switch from one player to another | |
197 | */ | |
198 | move_em(from, to) | |
199 | TRADE *from, *to; { | |
200 | ||
201 | reg PLAY *pl_fr, *pl_to; | |
202 | reg OWN *op; | |
203 | ||
204 | pl_fr = &play[from->trader]; | |
205 | pl_to = &play[to->trader]; | |
206 | ||
207 | pl_fr->money -= from->cash; | |
208 | pl_to->money += from->cash; | |
209 | pl_fr->num_gojf -= from->gojf; | |
210 | pl_to->num_gojf += from->gojf; | |
211 | for (op = from->prop_list; op; op = op->next) { | |
212 | add_list(to->trader, &(pl_to->own_list), sqnum(op->sqr)); | |
213 | op->sqr->owner = to->trader; | |
214 | del_list(from->trader, &(pl_fr->own_list), sqnum(op->sqr)); | |
215 | } | |
216 | set_ownlist(to->trader); | |
217 | } | |
218 | /* | |
219 | * This routine lets a player resign | |
220 | */ | |
221 | resign() { | |
222 | ||
223 | reg int i, new_own; | |
224 | reg OWN *op; | |
225 | SQUARE *sqp; | |
226 | ||
227 | if (cur_p->money <= 0) { | |
228 | switch (board[cur_p->loc].type) { | |
229 | case UTIL: | |
230 | case RR: | |
231 | case PRPTY: | |
232 | new_own = board[cur_p->loc].owner; | |
233 | break; | |
234 | default: /* Chance, taxes, etc */ | |
235 | new_own = num_play; | |
236 | break; | |
237 | } | |
238 | if (new_own == num_play) | |
239 | printf("You would resign to the bank\n"); | |
240 | else | |
241 | printf("You would resign to %s\n", name_list[new_own]); | |
242 | } | |
243 | else if (num_play == 1) { | |
244 | new_own = num_play; | |
245 | printf("You would resign to the bank\n"); | |
246 | } | |
247 | else { | |
248 | name_list[num_play] = "bank"; | |
249 | do { | |
250 | new_own = getinp("Who do you wish to resign to? ", | |
251 | name_list); | |
252 | if (new_own == player) | |
253 | printf("You can't resign to yourself!!\n"); | |
254 | } while (new_own == player); | |
255 | name_list[num_play] = "done"; | |
256 | } | |
257 | if (getyn("Do you really want to resign? ", yn) != 0) | |
258 | return; | |
259 | if (num_play == 1) { | |
260 | printf("Then NOBODY wins (not even YOU!)\n"); | |
261 | exit(0); | |
262 | } | |
263 | if (new_own < num_play) { /* resign to player */ | |
264 | printf("resigning to player\n"); | |
265 | trades[0].trader = new_own; | |
266 | trades[0].cash = trades[0].gojf = 0; | |
267 | trades[0].prop_list = NULL; | |
268 | trades[1].trader = player; | |
269 | trades[1].cash = cur_p->money > 0 ? cur_p->money : 0; | |
270 | trades[1].gojf = cur_p->num_gojf; | |
271 | trades[1].prop_list = cur_p->own_list; | |
272 | do_trade(); | |
273 | } | |
274 | else { /* resign to bank */ | |
275 | printf("resigning to bank\n"); | |
276 | for (op = cur_p->own_list; op; op = op->next) { | |
277 | sqp = op->sqr; | |
278 | sqp->owner = -1; | |
279 | sqp->desc->morg = FALSE; | |
280 | if (sqp->type == PRPTY) { | |
281 | isnot_monop(sqp->desc->mon_desc); | |
282 | sqp->desc->houses = 0; | |
283 | } | |
284 | } | |
285 | if (cur_p->num_gojf) | |
286 | ret_card(cur_p); | |
287 | } | |
288 | for (i = player; i < num_play; i++) { | |
289 | name_list[i] = name_list[i+1]; | |
290 | if (i + 1 < num_play) | |
291 | cpy_st(&play[i], &play[i+1], sizeof (PLAY)); | |
292 | } | |
293 | name_list[num_play--] = 0; | |
294 | for (i = 0; i < N_SQRS; i++) | |
295 | if (board[i].owner > player) | |
296 | --board[i].owner; | |
297 | player = --player < 0 ? num_play - 1 : player; | |
298 | next_play(); | |
299 | if (num_play < 2) { | |
300 | printf("\nThen %s WINS!!!!!\n", play[0].name); | |
301 | printhold(0); | |
302 | printf("That's a grand worth of $%d.\n", | |
303 | play[0].money+prop_worth(&play[0])); | |
304 | exit(0); | |
305 | } | |
306 | } |