]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/cards.c
1 /* $NetBSD: cards.c,v 1.4 1997/10/12 17:45:07 christos 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. 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.
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
36 #include <sys/cdefs.h>
39 static char sccsid
[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
41 __RCSID("$NetBSD: cards.c,v 1.4 1997/10/12 17:45:07 christos Exp $");
46 # include "pathnames.h"
49 * These routine deal with the card decks
52 # define GOJF 'F' /* char for get-out-of-jail-free cards */
55 static char *cardfile
= _PATH_CARDS
;
57 static char *cardfile
= "cards.pck";
62 static void set_up
__P((DECK
*));
63 static void printmes
__P((void));
66 * This routine initializes the decks from the data file,
73 if ((deckf
=fopen(cardfile
, "r")) == NULL
) {
78 if (fread(deck
, sizeof (DECK
), 2, deckf
) != 2)
84 * This routine sets up the offset pointers for the given deck.
93 dp
->offsets
= (long *) calloc(sizeof (long), dp
->num_cards
);
94 if (fread(dp
->offsets
, sizeof(long), dp
->num_cards
, deckf
) != dp
->num_cards
) {
99 dp
->gojf_used
= FALSE
;
100 for (i
= 0; i
< dp
->num_cards
; i
++) {
103 r1
= roll(1, dp
->num_cards
) - 1;
104 r2
= roll(1, dp
->num_cards
) - 1;
105 temp
= dp
->offsets
[r2
];
106 dp
->offsets
[r2
] = dp
->offsets
[r1
];
107 dp
->offsets
[r1
] = temp
;
111 * This routine draws a card from the given deck
118 char type_maj
, type_min
;
120 int i
, per_h
, per_H
, num_h
, num_H
;
124 fseek(deckf
, dp
->offsets
[dp
->last_card
], 0);
125 dp
->last_card
= ++(dp
->last_card
) % dp
->num_cards
;
126 type_maj
= getc(deckf
);
127 } while (dp
->gojf_used
&& type_maj
== GOJF
);
128 type_min
= getc(deckf
);
132 case '+': /* get money */
133 if (type_min
== 'A') {
134 for (i
= 0; i
< num_play
; i
++)
136 play
[i
].money
-= num
;
137 num
= num
* (num_play
- 1);
141 case '-': /* lose money */
142 if (type_min
== 'A') {
143 for (i
= 0; i
< num_play
; i
++)
145 play
[i
].money
+= num
;
146 num
= num
* (num_play
- 1);
150 case 'M': /* move somewhere */
152 case 'F': /* move forward */
157 case 'J': /* move to jail */
160 case 'R': /* move to railroad */
162 num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
164 case 'U': /* move to utility */
166 if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
167 num
= 28 - cur_p
->loc
;
169 num
= 12 - cur_p
->loc
;
190 for (op
= cur_p
->own_list
; op
; op
= op
->next
)
191 if (op
->sqr
->type
== PRPTY
)
192 if (op
->sqr
->desc
->houses
== 5)
195 num_h
+= op
->sqr
->desc
->houses
;
196 num
= per_h
* num_h
+ per_H
* num_H
;
197 printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h
, num_H
, num
);
203 case GOJF
: /* get-out-of-jail-free card */
205 dp
->gojf_used
= TRUE
;
212 * This routine prints out the message on the card
221 while ((c
= getc(deckf
)) != '\0')