133204Sbostic /*
2*60815Sbostic * Copyright (c) 1980, 1993
3*60815Sbostic * The Regents of the University of California. All rights reserved.
433204Sbostic *
542583Sbostic * %sccs.include.redist.c%
633204Sbostic */
733204Sbostic
833204Sbostic #ifndef lint
9*60815Sbostic static char sccsid[] = "@(#)cards.c 8.1 (Berkeley) 05/31/93";
1033204Sbostic #endif /* not lint */
1133204Sbostic
1233204Sbostic # include "monop.ext"
1341775Sbostic # include "pathnames.h"
1433204Sbostic
1533204Sbostic /*
1633204Sbostic * These routine deal with the card decks
1733204Sbostic */
1833204Sbostic
1933204Sbostic # define GOJF 'F' /* char for get-out-of-jail-free cards */
2033204Sbostic
2133204Sbostic # ifndef DEV
2241775Sbostic static char *cardfile = _PATH_CARDS;
2333204Sbostic # else
2433204Sbostic static char *cardfile = "cards.pck";
2533204Sbostic # endif
2633204Sbostic
2733204Sbostic static FILE *deckf;
2833204Sbostic
2933204Sbostic /*
3033204Sbostic * This routine initializes the decks from the data file,
3133204Sbostic * which it opens.
3233204Sbostic */
init_decks()3333204Sbostic init_decks() {
3433204Sbostic
3533204Sbostic if ((deckf=fopen(cardfile, "r")) == NULL) {
3633204Sbostic file_err:
3733204Sbostic perror(cardfile);
3833204Sbostic exit(1);
3933204Sbostic }
4033204Sbostic if (fread(deck, sizeof (DECK), 2, deckf) != 2)
4133204Sbostic goto file_err;
4233204Sbostic set_up(&CC_D);
4333204Sbostic set_up(&CH_D);
4433204Sbostic }
4533204Sbostic /*
4633204Sbostic * This routine sets up the offset pointers for the given deck.
4733204Sbostic */
set_up(dp)4833204Sbostic set_up(dp)
4933204Sbostic DECK *dp; {
5033204Sbostic
5133204Sbostic reg int r1, r2;
5233204Sbostic int i;
5333204Sbostic
5433204Sbostic dp->offsets = (long *) calloc(sizeof (long), dp->num_cards);
5533204Sbostic if (fread(dp->offsets, sizeof(long), dp->num_cards, deckf) != dp->num_cards) {
5633204Sbostic perror(cardfile);
5733204Sbostic exit(1);
5833204Sbostic }
5933204Sbostic dp->last_card = 0;
6033204Sbostic dp->gojf_used = FALSE;
6133204Sbostic for (i = 0; i < dp->num_cards; i++) {
6233204Sbostic reg long temp;
6333204Sbostic
6433204Sbostic r1 = roll(1, dp->num_cards) - 1;
6533204Sbostic r2 = roll(1, dp->num_cards) - 1;
6633204Sbostic temp = dp->offsets[r2];
6733204Sbostic dp->offsets[r2] = dp->offsets[r1];
6833204Sbostic dp->offsets[r1] = temp;
6933204Sbostic }
7033204Sbostic }
7133204Sbostic /*
7233204Sbostic * This routine draws a card from the given deck
7333204Sbostic */
get_card(dp)7433204Sbostic get_card(dp)
7533204Sbostic DECK *dp; {
7633204Sbostic
7733204Sbostic reg char type_maj, type_min;
7833204Sbostic reg int num;
7933204Sbostic int i, per_h, per_H, num_h, num_H;
8033204Sbostic OWN *op;
8133204Sbostic
8233204Sbostic do {
8333204Sbostic fseek(deckf, dp->offsets[dp->last_card], 0);
8433204Sbostic dp->last_card = ++(dp->last_card) % dp->num_cards;
8533204Sbostic type_maj = getc(deckf);
8633204Sbostic } while (dp->gojf_used && type_maj == GOJF);
8733204Sbostic type_min = getc(deckf);
8833204Sbostic num = getw(deckf);
8933204Sbostic printmes();
9033204Sbostic switch (type_maj) {
9133204Sbostic case '+': /* get money */
9233204Sbostic if (type_min == 'A') {
9333204Sbostic for (i = 0; i < num_play; i++)
9433204Sbostic if (i != player)
9533204Sbostic play[i].money -= num;
9633204Sbostic num = num * (num_play - 1);
9733204Sbostic }
9833204Sbostic cur_p->money += num;
9933204Sbostic break;
10033204Sbostic case '-': /* lose money */
10133204Sbostic if (type_min == 'A') {
10233204Sbostic for (i = 0; i < num_play; i++)
10333204Sbostic if (i != player)
10433204Sbostic play[i].money += num;
10533204Sbostic num = num * (num_play - 1);
10633204Sbostic }
10733204Sbostic cur_p->money -= num;
10833204Sbostic break;
10933204Sbostic case 'M': /* move somewhere */
11033204Sbostic switch (type_min) {
11133204Sbostic case 'F': /* move forward */
11233204Sbostic num -= cur_p->loc;
11333204Sbostic if (num < 0)
11433204Sbostic num += 40;
11533204Sbostic break;
11633204Sbostic case 'J': /* move to jail */
11733204Sbostic goto_jail();
11833204Sbostic return;
11933204Sbostic case 'R': /* move to railroad */
12033204Sbostic spec = TRUE;
12133204Sbostic num = (int)((cur_p->loc + 5)/10)*10 + 5 - cur_p->loc;
12233204Sbostic break;
12333204Sbostic case 'U': /* move to utility */
12433204Sbostic spec = TRUE;
12533204Sbostic if (cur_p->loc >= 12 && cur_p->loc < 28)
12633204Sbostic num = 28 - cur_p->loc;
12733204Sbostic else {
12833204Sbostic num = 12 - cur_p->loc;
12933204Sbostic if (num < 0)
13033204Sbostic num += 40;
13133204Sbostic }
13233204Sbostic break;
13333204Sbostic case 'B':
13433204Sbostic num = -num;
13533204Sbostic break;
13633204Sbostic }
13733204Sbostic move(num);
13833204Sbostic break;
13933204Sbostic case 'T': /* tax */
14033204Sbostic if (dp == &CC_D) {
14133204Sbostic per_h = 40;
14233204Sbostic per_H = 115;
14333204Sbostic }
14433204Sbostic else {
14533204Sbostic per_h = 25;
14633204Sbostic per_H = 100;
14733204Sbostic }
14833204Sbostic num_h = num_H = 0;
14933204Sbostic for (op = cur_p->own_list; op; op = op->next)
15033204Sbostic if (op->sqr->type == PRPTY)
15133204Sbostic if (op->sqr->desc->houses == 5)
15233204Sbostic ++num_H;
15333204Sbostic else
15433204Sbostic num_h += op->sqr->desc->houses;
15533204Sbostic num = per_h * num_h + per_H * num_H;
15633204Sbostic printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h, num_H, num);
15733204Sbostic if (num == 0)
15833204Sbostic lucky("");
15933204Sbostic else
16033204Sbostic cur_p->money -= num;
16133204Sbostic break;
16233204Sbostic case GOJF: /* get-out-of-jail-free card */
16333204Sbostic cur_p->num_gojf++;
16433204Sbostic dp->gojf_used = TRUE;
16533204Sbostic break;
16633204Sbostic }
16733204Sbostic spec = FALSE;
16833204Sbostic }
16933204Sbostic /*
17033204Sbostic * This routine prints out the message on the card
17133204Sbostic */
printmes()17233204Sbostic printmes() {
17333204Sbostic
17433204Sbostic reg char c;
17533204Sbostic
17633204Sbostic printline();
17733204Sbostic fflush(stdout);
17833204Sbostic while ((c = getc(deckf)) != '\0')
17933204Sbostic putchar(c);
18033204Sbostic printline();
18133204Sbostic fflush(stdout);
18233204Sbostic }
183