]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/cards.c
1 /* $NetBSD: cards.c,v 1.3 1995/03/23 08:34:35 cgd 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
38 static char sccsid
[] = "@(#)cards.c 8.1 (Berkeley) 5/31/93";
40 static char rcsid
[] = "$NetBSD: cards.c,v 1.3 1995/03/23 08:34:35 cgd Exp $";
45 # include "pathnames.h"
48 * These routine deal with the card decks
51 # define GOJF 'F' /* char for get-out-of-jail-free cards */
54 static char *cardfile
= _PATH_CARDS
;
56 static char *cardfile
= "cards.pck";
62 * This routine initializes the decks from the data file,
67 if ((deckf
=fopen(cardfile
, "r")) == NULL
) {
72 if (fread(deck
, sizeof (DECK
), 2, deckf
) != 2)
78 * This routine sets up the offset pointers for the given deck.
86 dp
->offsets
= (long *) calloc(sizeof (long), dp
->num_cards
);
87 if (fread(dp
->offsets
, sizeof(long), dp
->num_cards
, deckf
) != dp
->num_cards
) {
92 dp
->gojf_used
= FALSE
;
93 for (i
= 0; i
< dp
->num_cards
; i
++) {
96 r1
= roll(1, dp
->num_cards
) - 1;
97 r2
= roll(1, dp
->num_cards
) - 1;
98 temp
= dp
->offsets
[r2
];
99 dp
->offsets
[r2
] = dp
->offsets
[r1
];
100 dp
->offsets
[r1
] = temp
;
104 * This routine draws a card from the given deck
109 reg
char type_maj
, type_min
;
111 int i
, per_h
, per_H
, num_h
, num_H
;
115 fseek(deckf
, dp
->offsets
[dp
->last_card
], 0);
116 dp
->last_card
= ++(dp
->last_card
) % dp
->num_cards
;
117 type_maj
= getc(deckf
);
118 } while (dp
->gojf_used
&& type_maj
== GOJF
);
119 type_min
= getc(deckf
);
123 case '+': /* get money */
124 if (type_min
== 'A') {
125 for (i
= 0; i
< num_play
; i
++)
127 play
[i
].money
-= num
;
128 num
= num
* (num_play
- 1);
132 case '-': /* lose 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 'M': /* move somewhere */
143 case 'F': /* move forward */
148 case 'J': /* move to jail */
151 case 'R': /* move to railroad */
153 num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
155 case 'U': /* move to utility */
157 if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
158 num
= 28 - cur_p
->loc
;
160 num
= 12 - cur_p
->loc
;
181 for (op
= cur_p
->own_list
; op
; op
= op
->next
)
182 if (op
->sqr
->type
== PRPTY
)
183 if (op
->sqr
->desc
->houses
== 5)
186 num_h
+= op
->sqr
->desc
->houses
;
187 num
= per_h
* num_h
+ per_H
* num_H
;
188 printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h
, num_H
, num
);
194 case GOJF
: /* get-out-of-jail-free card */
196 dp
->gojf_used
= TRUE
;
202 * This routine prints out the message on the card
210 while ((c
= getc(deckf
)) != '\0')