1 /* $NetBSD: cards.c,v 1.27 2014/12/29 10:38:52 jnemeth 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.27 2014/12/29 10:38:52 jnemeth 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 owner 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.
212 dp
->cards
= calloc((size_t)dp
->num_cards
, sizeof(dp
->cards
[0]));
213 if (dp
->cards
== NULL
)
214 errx(1, "out of memory");
216 for (i
= 0; i
< dp
->num_cards
; i
++)
220 dp
->gojf_used
= FALSE
;
222 for (i
= 0; i
< dp
->num_cards
; i
++) {
225 r1
= roll(1, dp
->num_cards
) - 1;
226 r2
= roll(1, dp
->num_cards
) - 1;
227 temp
= dp
->cards
[r2
];
228 dp
->cards
[r2
] = dp
->cards
[r1
];
229 dp
->cards
[r1
] = temp
;
234 * This routine draws a card from the given deck
239 char type_maj
, type_min
;
241 int i
, per_h
, per_H
, num_h
, num_H
;
243 const struct cardinfo
*thiscard
;
246 thiscard
= &dp
->info
[dp
->top_card
];
247 type_maj
= thiscard
->actioncode
[0];
248 dp
->top_card
= (dp
->top_card
+ 1) % dp
->num_cards
;
249 } while (dp
->gojf_used
&& type_maj
== GOJF
);
250 type_min
= thiscard
->actioncode
[1];
251 num
= atoi(thiscard
->actioncode
+2);
253 printmes(thiscard
->text
);
255 case '+': /* get money */
256 if (type_min
== 'A') {
257 for (i
= 0; i
< num_play
; i
++)
259 play
[i
].money
-= num
;
260 num
= num
* (num_play
- 1);
264 case '-': /* lose money */
265 if (type_min
== 'A') {
266 for (i
= 0; i
< num_play
; i
++)
268 play
[i
].money
+= num
;
269 num
= num
* (num_play
- 1);
273 case 'M': /* move somewhere */
275 case 'F': /* move forward */
280 case 'J': /* move to jail */
283 case 'R': /* move to railroad */
285 num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
287 case 'U': /* move to utility */
289 if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
290 num
= 28 - cur_p
->loc
;
292 num
= 12 - cur_p
->loc
;
313 for (op
= cur_p
->own_list
; op
; op
= op
->next
)
314 if (op
->sqr
->type
== PRPTY
) {
315 if (op
->sqr
->desc
->houses
== 5)
318 num_h
+= op
->sqr
->desc
->houses
;
320 num
= per_h
* num_h
+ per_H
* num_H
;
322 "You had %d Houses and %d Hotels, so that cost you $%d\n",
329 case GOJF
: /* get-out-of-jail-free card */
331 dp
->gojf_used
= TRUE
;
338 * This routine prints out the message on the card
341 printmes(const char *text
)
347 for (i
= 0; text
[i
] != '\0'; i
++)
354 * This routine returns the players get-out-of-jail-free card
355 * to the bottom of a deck. XXX currently does not return to the correct
362 int gojfpos
, last_card
;
372 dp
->gojf_used
= FALSE
;
374 /* Put at bottom of deck (top_card - 1) and remove it from wherever else
377 last_card
= dp
->top_card
- 1;
379 last_card
+= dp
->num_cards
;
380 gojfpos
= dp
->top_card
;
382 gojfpos
= (gojfpos
+ 1) % dp
->num_cards
;
383 type_maj
= dp
->info
[gojfpos
].actioncode
[0];
384 } while (type_maj
!= GOJF
);
385 temp
= dp
->cards
[gojfpos
];
386 /* Only one of the next two loops does anything */
387 for (i
= gojfpos
- 1; i
> last_card
; i
--)
388 dp
->cards
[i
+ 1] = dp
->cards
[i
];
389 for (i
= gojfpos
; i
< last_card
; i
++)
390 dp
->cards
[i
] = dp
->cards
[i
+ 1];
391 if (gojfpos
> last_card
) {
392 dp
->cards
[dp
->top_card
] = temp
;
394 dp
->top_card
%= dp
->num_cards
;
396 dp
->cards
[last_card
] = temp
;