Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Copyright (c) 1980 Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
20 | * | |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | */ | |
33 | ||
34 | #ifndef lint | |
35 | static char sccsid[] = "@(#)cards.c 5.4 (Berkeley) 6/1/90"; | |
36 | #endif /* not lint */ | |
37 | ||
38 | # include "monop.ext" | |
39 | # include "pathnames.h" | |
40 | ||
41 | /* | |
42 | * These routine deal with the card decks | |
43 | */ | |
44 | ||
45 | # define GOJF 'F' /* char for get-out-of-jail-free cards */ | |
46 | ||
47 | # ifndef DEV | |
48 | static char *cardfile = _PATH_CARDS; | |
49 | # else | |
50 | static char *cardfile = "cards.pck"; | |
51 | # endif | |
52 | ||
53 | static FILE *deckf; | |
54 | ||
55 | /* | |
56 | * This routine initializes the decks from the data file, | |
57 | * which it opens. | |
58 | */ | |
59 | init_decks() { | |
60 | ||
61 | if ((deckf=fopen(cardfile, "r")) == NULL) { | |
62 | file_err: | |
63 | perror(cardfile); | |
64 | exit(1); | |
65 | } | |
66 | if (fread(deck, sizeof (DECK), 2, deckf) != 2) | |
67 | goto file_err; | |
68 | set_up(&CC_D); | |
69 | set_up(&CH_D); | |
70 | } | |
71 | /* | |
72 | * This routine sets up the offset pointers for the given deck. | |
73 | */ | |
74 | set_up(dp) | |
75 | DECK *dp; { | |
76 | ||
77 | reg int r1, r2; | |
78 | int i; | |
79 | ||
80 | dp->offsets = (long *) calloc(sizeof (long), dp->num_cards); | |
81 | if (fread(dp->offsets, sizeof(long), dp->num_cards, deckf) != dp->num_cards) { | |
82 | perror(cardfile); | |
83 | exit(1); | |
84 | } | |
85 | dp->last_card = 0; | |
86 | dp->gojf_used = FALSE; | |
87 | for (i = 0; i < dp->num_cards; i++) { | |
88 | reg long temp; | |
89 | ||
90 | r1 = roll(1, dp->num_cards) - 1; | |
91 | r2 = roll(1, dp->num_cards) - 1; | |
92 | temp = dp->offsets[r2]; | |
93 | dp->offsets[r2] = dp->offsets[r1]; | |
94 | dp->offsets[r1] = temp; | |
95 | } | |
96 | } | |
97 | /* | |
98 | * This routine draws a card from the given deck | |
99 | */ | |
100 | get_card(dp) | |
101 | DECK *dp; { | |
102 | ||
103 | reg char type_maj, type_min; | |
104 | reg int num; | |
105 | int i, per_h, per_H, num_h, num_H; | |
106 | OWN *op; | |
107 | ||
108 | do { | |
109 | fseek(deckf, dp->offsets[dp->last_card], 0); | |
110 | dp->last_card = ++(dp->last_card) % dp->num_cards; | |
111 | type_maj = getc(deckf); | |
112 | } while (dp->gojf_used && type_maj == GOJF); | |
113 | type_min = getc(deckf); | |
114 | num = getw(deckf); | |
115 | printmes(); | |
116 | switch (type_maj) { | |
117 | case '+': /* get money */ | |
118 | if (type_min == 'A') { | |
119 | for (i = 0; i < num_play; i++) | |
120 | if (i != player) | |
121 | play[i].money -= num; | |
122 | num = num * (num_play - 1); | |
123 | } | |
124 | cur_p->money += num; | |
125 | break; | |
126 | case '-': /* lose money */ | |
127 | if (type_min == 'A') { | |
128 | for (i = 0; i < num_play; i++) | |
129 | if (i != player) | |
130 | play[i].money += num; | |
131 | num = num * (num_play - 1); | |
132 | } | |
133 | cur_p->money -= num; | |
134 | break; | |
135 | case 'M': /* move somewhere */ | |
136 | switch (type_min) { | |
137 | case 'F': /* move forward */ | |
138 | num -= cur_p->loc; | |
139 | if (num < 0) | |
140 | num += 40; | |
141 | break; | |
142 | case 'J': /* move to jail */ | |
143 | goto_jail(); | |
144 | return; | |
145 | case 'R': /* move to railroad */ | |
146 | spec = TRUE; | |
147 | num = (int)((cur_p->loc + 5)/10)*10 + 5 - cur_p->loc; | |
148 | break; | |
149 | case 'U': /* move to utility */ | |
150 | spec = TRUE; | |
151 | if (cur_p->loc >= 12 && cur_p->loc < 28) | |
152 | num = 28 - cur_p->loc; | |
153 | else { | |
154 | num = 12 - cur_p->loc; | |
155 | if (num < 0) | |
156 | num += 40; | |
157 | } | |
158 | break; | |
159 | case 'B': | |
160 | num = -num; | |
161 | break; | |
162 | } | |
163 | move(num); | |
164 | break; | |
165 | case 'T': /* tax */ | |
166 | if (dp == &CC_D) { | |
167 | per_h = 40; | |
168 | per_H = 115; | |
169 | } | |
170 | else { | |
171 | per_h = 25; | |
172 | per_H = 100; | |
173 | } | |
174 | num_h = num_H = 0; | |
175 | for (op = cur_p->own_list; op; op = op->next) | |
176 | if (op->sqr->type == PRPTY) | |
177 | if (op->sqr->desc->houses == 5) | |
178 | ++num_H; | |
179 | else | |
180 | num_h += op->sqr->desc->houses; | |
181 | num = per_h * num_h + per_H * num_H; | |
182 | printf("You had %d Houses and %d Hotels, so that cost you $%d\n", num_h, num_H, num); | |
183 | if (num == 0) | |
184 | lucky(""); | |
185 | else | |
186 | cur_p->money -= num; | |
187 | break; | |
188 | case GOJF: /* get-out-of-jail-free card */ | |
189 | cur_p->num_gojf++; | |
190 | dp->gojf_used = TRUE; | |
191 | break; | |
192 | } | |
193 | spec = FALSE; | |
194 | } | |
195 | /* | |
196 | * This routine prints out the message on the card | |
197 | */ | |
198 | printmes() { | |
199 | ||
200 | reg char c; | |
201 | ||
202 | printline(); | |
203 | fflush(stdout); | |
204 | while ((c = getc(deckf)) != '\0') | |
205 | putchar(c); | |
206 | printline(); | |
207 | fflush(stdout); | |
208 | } |