]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/houses.c
Add use of `const' where appropriate to the games.
[bsdgames-darwin.git] / monop / houses.c
1 /* $NetBSD: houses.c,v 1.6 1999/09/08 21:17:51 jsm Exp $ */
2
3 /*
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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.
22 *
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
33 * SUCH DAMAGE.
34 */
35
36 #include <sys/cdefs.h>
37 #ifndef lint
38 #if 0
39 static char sccsid[] = "@(#)houses.c 8.1 (Berkeley) 5/31/93";
40 #else
41 __RCSID("$NetBSD: houses.c,v 1.6 1999/09/08 21:17:51 jsm Exp $");
42 #endif
43 #endif /* not lint */
44
45 #include "monop.ext"
46
47 static const char *names[N_MON+2];
48 static char cur_prop[80];
49
50 static MON *monops[N_MON];
51
52 static void buy_h __P((MON *));
53 static void sell_h __P((MON *));
54 static void list_cur __P((MON *));
55 /*
56 * These routines deal with buying and selling houses
57 */
58 void
59 buy_houses()
60 {
61 int num_mon;
62 MON *mp;
63 OWN *op;
64 bool good,got_morg;
65 int i,p;
66
67 over:
68 num_mon = 0;
69 good = TRUE;
70 got_morg = FALSE;
71 for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
72 continue;
73 while (op)
74 if (op->sqr->desc->monop) {
75 mp = op->sqr->desc->mon_desc;
76 names[num_mon] = (monops[num_mon]=mp)->name;
77 num_mon++;
78 got_morg = good = FALSE;
79 for (i = 0; i < mp->num_in; i++) {
80 if (op->sqr->desc->morg)
81 got_morg++;
82 if (op->sqr->desc->houses != 5)
83 good++;
84 op = op->next;
85 }
86 if (!good || got_morg)
87 --num_mon;
88 }
89 else
90 op = op->next;
91 if (num_mon == 0) {
92 if (got_morg)
93 printf("You can't build on mortgaged monopolies.\n");
94 else if (!good)
95 printf("You can't build any more.\n");
96 else
97 printf("But you don't have any monopolies!!\n");
98 return;
99 }
100 if (num_mon == 1)
101 buy_h(monops[0]);
102 else {
103 names[num_mon++] = "done";
104 names[num_mon--] = 0;
105 if ((p = getinp(
106 "Which property do you wish to buy houses for? ",
107 names)) == num_mon)
108 return;
109 buy_h(monops[p]);
110 goto over;
111 }
112 }
113
114 static void
115 buy_h(mnp)
116 MON *mnp;
117 {
118 int i;
119 MON *mp;
120 int price;
121 short input[3],temp[3];
122 int tot;
123 PROP *pp;
124
125 mp = mnp;
126 price = mp->h_cost * 50;
127 blew_it:
128 list_cur(mp);
129 printf("Houses will cost $%d\n", price);
130 printf("How many houses do you wish to buy for\n");
131 for (i = 0; i < mp->num_in; i++) {
132 pp = mp->sq[i]->desc;
133 over:
134 if (pp->houses == 5) {
135 printf("%s (H):\n", mp->sq[i]->name);
136 input[i] = 0;
137 temp[i] = 5;
138 continue;
139 }
140 (void)sprintf(cur_prop, "%s (%d): ",
141 mp->sq[i]->name, pp->houses);
142 input[i] = get_int(cur_prop);
143 temp[i] = input[i] + pp->houses;
144 if (temp[i] > 5) {
145 printf("That's too many. The most you can buy is %d\n",
146 5 - pp->houses);
147 goto over;
148 }
149 }
150 if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
151 abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
152 err: printf("That makes the spread too wide. Try again\n");
153 goto blew_it;
154 }
155 else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
156 goto err;
157 for (tot = i = 0; i < mp->num_in; i++)
158 tot += input[i];
159 if (tot) {
160 printf("You asked for %d houses for $%d\n", tot, tot * price);
161 if (getyn("Is that ok? ") == 0) {
162 cur_p->money -= tot * price;
163 for (tot = i = 0; i < mp->num_in; i++)
164 mp->sq[i]->desc->houses = temp[i];
165 }
166 }
167 }
168
169 /*
170 * This routine sells houses.
171 */
172 void
173 sell_houses()
174 {
175 int num_mon;
176 MON *mp;
177 OWN *op;
178 bool good;
179 int p;
180
181 over:
182 num_mon = 0;
183 good = TRUE;
184 for (op = cur_p->own_list; op; op = op->next)
185 if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
186 mp = op->sqr->desc->mon_desc;
187 names[num_mon] = (monops[num_mon]=mp)->name;
188 num_mon++;
189 good = 0;
190 do
191 if (!good && op->sqr->desc->houses != 0)
192 good++;
193 while (op->next && op->sqr->desc->mon_desc == mp
194 && (op=op->next));
195 if (!good)
196 --num_mon;
197 }
198 if (num_mon == 0) {
199 printf("You don't have any houses to sell!!\n");
200 return;
201 }
202 if (num_mon == 1)
203 sell_h(monops[0]);
204 else {
205 names[num_mon++] = "done";
206 names[num_mon--] = 0;
207 if ((p = getinp(
208 "Which property do you wish to sell houses from? ",
209 names)) == num_mon)
210 return;
211 sell_h(monops[p]);
212 notify();
213 goto over;
214 }
215 }
216
217 static void
218 sell_h(mnp)
219 MON *mnp;
220 {
221 int i;
222 MON *mp;
223 int price;
224 short input[3],temp[3];
225 int tot;
226 PROP *pp;
227
228 mp = mnp;
229 price = mp->h_cost * 25;
230 blew_it:
231 printf("Houses will get you $%d apiece\n", price);
232 list_cur(mp);
233 printf("How many houses do you wish to sell from\n");
234 for (i = 0; i < mp->num_in; i++) {
235 pp = mp->sq[i]->desc;
236 over:
237 if (pp->houses == 0) {
238 printf("%s (0):\n", mp->sq[i]->name);
239 input[i] = temp[i] = 0;
240 continue;
241 }
242 if (pp->houses < 5)
243 (void)sprintf(cur_prop,"%s (%d): ",
244 mp->sq[i]->name,pp->houses);
245 else
246 (void)sprintf(cur_prop,"%s (H): ",mp->sq[i]->name);
247 input[i] = get_int(cur_prop);
248 temp[i] = pp->houses - input[i];
249 if (temp[i] < 0) {
250 printf(
251 "That's too many. The most you can sell is %d\n",
252 pp->houses);
253 goto over;
254 }
255 }
256 if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
257 abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
258 err: printf("That makes the spread too wide. Try again\n");
259 goto blew_it;
260 }
261 else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
262 goto err;
263 for (tot = i = 0; i < mp->num_in; i++)
264 tot += input[i];
265 if (tot) {
266 printf("You asked to sell %d houses for $%d\n",tot,tot * price);
267 if (getyn("Is that ok? ") == 0) {
268 cur_p->money += tot * price;
269 for (tot = i = 0; i < mp->num_in; i++)
270 mp->sq[i]->desc->houses = temp[i];
271 }
272 }
273 }
274
275 static void
276 list_cur(mp)
277 MON *mp;
278 {
279 int i;
280 SQUARE *sqp;
281
282 for (i = 0; i < mp->num_in; i++) {
283 sqp = mp->sq[i];
284 if (sqp->desc->houses == 5)
285 printf("%s (H) ", sqp->name);
286 else
287 printf("%s (%d) ", sqp->name, sqp->desc->houses);
288 }
289 putchar('\n');
290 }