1 /* $NetBSD: cards.c,v 1.22 2008/02/24 02:43:18 dholland 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: cards.c,v 1.22 2008/02/24 02:43:18 dholland Exp $");
41 #include <sys/types.h>
42 #include <sys/endian.h>
47 * These routine deal with the card decks
50 static void set_up(DECK
*);
51 static void printmes(const char *text
);
53 #define GOJF 'F' /* char for get-out-of-jail-free cards */
56 const char *actioncode
;
60 static const struct cardinfo cc_cards
[] = {
62 ">> GET OUT OF JAIL FREE <<\n"
63 "Keep this card until needed or sold\n"
66 "Receive for Services $25.\n"
69 "Bank Error in Your Favor.\n"
73 "Income Tax Refund.\n"
80 "Life Insurance Matures.\n"
84 "From sale of Stock You get $45.\n"
87 "You are Assessed for street repairs.\n"
92 "X-mas Fund Matures.\n"
96 "You have won Second Prize in a Beauty Contest\n"
107 "Pay School Tax of $150.\n"
110 "\t\t>> GO TO JAIL <<\n"
111 "Go Directly to Jail. Do not pass GO Do not collect $200.\n"
114 "\t\t>> GRAND OPERA OPENING <<\n"
115 "Collect $50 from each player for opening night seats.\n"
118 "Doctor's Fee: Pay $50.\n"
122 static const struct cardinfo ch_cards
[] = {
124 ">> GET OUT OF JAIL FREE <<\n"
125 "Keep this card until needed or sold\n"
128 "Advance to the nearest Railroad, and pay owner\n"
129 "Twice the rental to which he is otherwise entitled.\n"
130 "If Railroad is unowned you may buy it from the bank\n"
133 "Advance to the nearest Utility.\n"
134 "If unowned, you may buy it from the bank.\n"
135 "If owned, throw dice and pay oner a total of ten times\n"
136 "the amount thrown.\n"
142 "Advance to the nearest Railroad, and pay owner\n"
143 "Twice the rental to which he is otherwise entitled.\n"
144 "If Railroad is unowned you may buy it from the bank\n"
147 " >> GO DIRECTLY TO JAIL <<\n"
148 "Do not pass GO, Do not Collect $200.\n"
151 "Take a Ride on the Reading.\n"
152 "If you pass GO, collect $200.\n"
155 "Take a Walk on the Board Walk.\n"
156 " (Advance To Board Walk)\n"
159 "Advance to Illinois Ave.\n"
165 "Advance to St. Charles Place.\n"
166 "If you pass GO, collect $200.\n"
169 "Make general repairs on all of your Property.\n"
170 "For Each House pay $25.\n"
171 "For Each Hotel pay $100.\n"
174 "You have been elected Chairman of the Board.\n"
175 "Pay each player $50.\n"
178 "Pay Poor Tax of $15\n"
181 "Bank pays you Dividend of $50.\n"
184 "Your Building and Loan Matures.\n"
190 * This routine initializes the decks from the data above.
195 CC_D
.info
= cc_cards
;
196 CC_D
.num_cards
= sizeof(cc_cards
) / sizeof(cc_cards
[0]);
197 CH_D
.info
= ch_cards
;
198 CH_D
.num_cards
= sizeof(ch_cards
) / sizeof(ch_cards
[0]);
204 * This routine sets up the offset pointers for the given deck.
213 dp
->cards
= calloc((size_t)dp
->num_cards
, sizeof(dp
->cards
[0]));
214 if (dp
->cards
== NULL
)
215 errx(1, "out of memory");
217 for (i
= 0; i
< dp
->num_cards
; i
++)
221 dp
->gojf_used
= FALSE
;
223 for (i
= 0; i
< dp
->num_cards
; i
++) {
226 r1
= roll(1, dp
->num_cards
) - 1;
227 r2
= roll(1, dp
->num_cards
) - 1;
228 temp
= dp
->cards
[r2
];
229 dp
->cards
[r2
] = dp
->cards
[r1
];
230 dp
->cards
[r1
] = temp
;
235 * This routine draws a card from the given deck
241 char type_maj
, type_min
;
243 int i
, per_h
, per_H
, num_h
, num_H
;
245 const struct cardinfo
*thiscard
;
248 thiscard
= &dp
->info
[dp
->top_card
];
249 type_maj
= thiscard
->actioncode
[0];
250 dp
->top_card
= ++(dp
->top_card
) % dp
->num_cards
;
251 } while (dp
->gojf_used
&& type_maj
== GOJF
);
252 type_min
= thiscard
->actioncode
[1];
253 num
= atoi(thiscard
->actioncode
+2);
255 printmes(thiscard
->text
);
257 case '+': /* get money */
258 if (type_min
== 'A') {
259 for (i
= 0; i
< num_play
; i
++)
261 play
[i
].money
-= num
;
262 num
= num
* (num_play
- 1);
266 case '-': /* lose money */
267 if (type_min
== 'A') {
268 for (i
= 0; i
< num_play
; i
++)
270 play
[i
].money
+= num
;
271 num
= num
* (num_play
- 1);
275 case 'M': /* move somewhere */
277 case 'F': /* move forward */
282 case 'J': /* move to jail */
285 case 'R': /* move to railroad */
287 num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
289 case 'U': /* move to utility */
291 if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
292 num
= 28 - cur_p
->loc
;
294 num
= 12 - cur_p
->loc
;
315 for (op
= cur_p
->own_list
; op
; op
= op
->next
)
316 if (op
->sqr
->type
== PRPTY
) {
317 if (op
->sqr
->desc
->houses
== 5)
320 num_h
+= op
->sqr
->desc
->houses
;
322 num
= per_h
* num_h
+ per_H
* num_H
;
324 "You had %d Houses and %d Hotels, so that cost you $%d\n",
331 case GOJF
: /* get-out-of-jail-free card */
333 dp
->gojf_used
= TRUE
;
340 * This routine prints out the message on the card
343 printmes(const char *text
)
349 for (i
= 0; text
[i
] != '\0'; i
++)
356 * This routine returns the players get-out-of-jail-free card
357 * to the bottom of a deck. XXX currently does not return to the correct
365 int gojfpos
, last_card
;
375 dp
->gojf_used
= FALSE
;
377 /* Put at bottom of deck (top_card - 1) and remove it from wherever else
380 last_card
= dp
->top_card
- 1;
382 last_card
+= dp
->num_cards
;
383 gojfpos
= dp
->top_card
;
385 gojfpos
= (gojfpos
+ 1) % dp
->num_cards
;
386 type_maj
= dp
->info
[gojfpos
].actioncode
[0];
387 } while (type_maj
!= GOJF
);
388 temp
= dp
->cards
[gojfpos
];
389 /* Only one of the next two loops does anything */
390 for (i
= gojfpos
- 1; i
> last_card
; i
--)
391 dp
->cards
[i
+ 1] = dp
->cards
[i
];
392 for (i
= gojfpos
; i
< last_card
; i
++)
393 dp
->cards
[i
] = dp
->cards
[i
+ 1];
394 if (gojfpos
> last_card
) {
395 dp
->cards
[dp
->top_card
] = temp
;
397 dp
->top_card
%= dp
->num_cards
;
399 dp
->cards
[last_card
] = temp
;