]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/cards.c
1 /* $NetBSD: cards.c,v 1.14 2004/01/27 20:30:30 jsm 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.14 2004/01/27 20:30:30 jsm Exp $");
41 #include <sys/types.h>
42 #include <sys/endian.h>
44 #include "pathnames.h"
47 * These routine deal with the card decks
50 #define GOJF 'F' /* char for get-out-of-jail-free cards */
53 static const char *cardfile
= _PATH_CARDS
;
55 static const char *cardfile
= "cards.pck";
60 static void set_up(DECK
*);
61 static void printmes(void);
64 * This routine initializes the decks from the data file,
72 if ((deckf
=fopen(cardfile
, "r")) == NULL
) {
78 /* read number of community chest cards... */
79 if (fread(&nc
, sizeof(nc
), 1, deckf
) != 1)
81 CC_D
.num_cards
= be32toh(nc
);
82 /* ... and number of community chest cards. */
83 if (fread(&nc
, sizeof(nc
), 1, deckf
) != 1)
85 CH_D
.num_cards
= be32toh(nc
);
91 * This routine sets up the offset pointers for the given deck.
100 dp
->offsets
= (off_t
*) calloc(dp
->num_cards
, sizeof (off_t
));
101 if (dp
->offsets
== NULL
)
102 errx(1, "out of memory");
103 if (fread(dp
->offsets
, sizeof(off_t
), dp
->num_cards
, deckf
) !=
108 /* convert offsets from big-endian byte order */
109 for (i
= 0; i
< dp
->num_cards
; i
++)
110 BE64TOH(dp
->offsets
[i
]);
112 dp
->gojf_used
= FALSE
;
113 for (i
= 0; i
< dp
->num_cards
; i
++) {
116 r1
= roll(1, dp
->num_cards
) - 1;
117 r2
= roll(1, dp
->num_cards
) - 1;
118 temp
= dp
->offsets
[r2
];
119 dp
->offsets
[r2
] = dp
->offsets
[r1
];
120 dp
->offsets
[r1
] = temp
;
125 * This routine draws a card from the given deck
131 char type_maj
, type_min
;
133 int i
, per_h
, per_H
, num_h
, num_H
;
137 fseek(deckf
, dp
->offsets
[dp
->last_card
], SEEK_SET
);
138 dp
->last_card
= ++(dp
->last_card
) % dp
->num_cards
;
139 type_maj
= getc(deckf
);
140 } while (dp
->gojf_used
&& type_maj
== GOJF
);
141 type_min
= getc(deckf
);
142 num
= ntohl(getw(deckf
));
145 case '+': /* get money */
146 if (type_min
== 'A') {
147 for (i
= 0; i
< num_play
; i
++)
149 play
[i
].money
-= num
;
150 num
= num
* (num_play
- 1);
154 case '-': /* lose money */
155 if (type_min
== 'A') {
156 for (i
= 0; i
< num_play
; i
++)
158 play
[i
].money
+= num
;
159 num
= num
* (num_play
- 1);
163 case 'M': /* move somewhere */
165 case 'F': /* move forward */
170 case 'J': /* move to jail */
173 case 'R': /* move to railroad */
175 num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
177 case 'U': /* move to utility */
179 if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
180 num
= 28 - cur_p
->loc
;
182 num
= 12 - cur_p
->loc
;
203 for (op
= cur_p
->own_list
; op
; op
= op
->next
)
204 if (op
->sqr
->type
== PRPTY
) {
205 if (op
->sqr
->desc
->houses
== 5)
208 num_h
+= op
->sqr
->desc
->houses
;
210 num
= per_h
* num_h
+ per_H
* num_H
;
212 "You had %d Houses and %d Hotels, so that cost you $%d\n",
219 case GOJF
: /* get-out-of-jail-free card */
221 dp
->gojf_used
= TRUE
;
228 * This routine prints out the message on the card
237 while ((c
= getc(deckf
)) != '\0')