* Copyright (c) 1980 Regents of the University of California.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
static char sccsid
[] = "@(#)cards.c 5.4 (Berkeley) 6/1/90";
* These routine deal with the card decks
# define GOJF 'F' /* char for get-out-of-jail-free cards */
static char *cardfile
= _PATH_CARDS
;
static char *cardfile
= "cards.pck";
* This routine initializes the decks from the data file,
if ((deckf
=fopen(cardfile
, "r")) == NULL
) {
if (fread(deck
, sizeof (DECK
), 2, deckf
) != 2)
* This routine sets up the offset pointers for the given deck.
dp
->offsets
= (long *) calloc(sizeof (long), dp
->num_cards
);
if (fread(dp
->offsets
, sizeof(long), dp
->num_cards
, deckf
) != dp
->num_cards
) {
for (i
= 0; i
< dp
->num_cards
; i
++) {
r1
= roll(1, dp
->num_cards
) - 1;
r2
= roll(1, dp
->num_cards
) - 1;
dp
->offsets
[r2
] = dp
->offsets
[r1
];
* This routine draws a card from the given deck
reg
char type_maj
, type_min
;
int i
, per_h
, per_H
, num_h
, num_H
;
fseek(deckf
, dp
->offsets
[dp
->last_card
], 0);
dp
->last_card
= ++(dp
->last_card
) % dp
->num_cards
;
} while (dp
->gojf_used
&& type_maj
== GOJF
);
case '+': /* get money */
for (i
= 0; i
< num_play
; i
++)
num
= num
* (num_play
- 1);
case '-': /* lose money */
for (i
= 0; i
< num_play
; i
++)
num
= num
* (num_play
- 1);
case 'M': /* move somewhere */
case 'F': /* move forward */
case 'J': /* move to jail */
case 'R': /* move to railroad */
num
= (int)((cur_p
->loc
+ 5)/10)*10 + 5 - cur_p
->loc
;
case 'U': /* move to utility */
if (cur_p
->loc
>= 12 && cur_p
->loc
< 28)
for (op
= cur_p
->own_list
; op
; op
= op
->next
)
if (op
->sqr
->type
== PRPTY
)
if (op
->sqr
->desc
->houses
== 5)
num_h
+= op
->sqr
->desc
->houses
;
num
= per_h
* num_h
+ per_H
* num_H
;
printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h
, num_H
, num
);
case GOJF
: /* get-out-of-jail-free card */
* This routine prints out the message on the card
while ((c
= getc(deckf
)) != '\0')