]> git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/houses.c
Fix formatting bug apparently introduced when the page was mdoc'd. (Had
[bsdgames-darwin.git] / monop / houses.c
1 /* $NetBSD: houses.c,v 1.9 2006/03/19 00:19:31 christos 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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #ifndef lint
34 #if 0
35 static char sccsid[] = "@(#)houses.c 8.1 (Berkeley) 5/31/93";
36 #else
37 __RCSID("$NetBSD: houses.c,v 1.9 2006/03/19 00:19:31 christos Exp $");
38 #endif
39 #endif /* not lint */
40
41 #include "monop.ext"
42
43 static const char *names[N_MON+2];
44 static char cur_prop[80];
45
46 static MON *monops[N_MON];
47
48 static void buy_h(MON *);
49 static void sell_h(MON *);
50 static void list_cur(MON *);
51 /*
52 * These routines deal with buying and selling houses
53 */
54 void
55 buy_houses()
56 {
57 int num_mon;
58 MON *mp;
59 OWN *op;
60 bool good,got_morg;
61 int i,p;
62
63 over:
64 num_mon = 0;
65 good = TRUE;
66 got_morg = FALSE;
67 for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
68 continue;
69 while (op)
70 if (op->sqr->desc->monop) {
71 mp = op->sqr->desc->mon_desc;
72 names[num_mon] = (monops[num_mon]=mp)->name;
73 num_mon++;
74 got_morg = good = FALSE;
75 for (i = 0; i < mp->num_in; i++) {
76 if (op->sqr->desc->morg)
77 got_morg++;
78 if (op->sqr->desc->houses != 5)
79 good++;
80 op = op->next;
81 }
82 if (!good || got_morg)
83 --num_mon;
84 }
85 else
86 op = op->next;
87 if (num_mon == 0) {
88 if (got_morg)
89 printf("You can't build on mortgaged monopolies.\n");
90 else if (!good)
91 printf("You can't build any more.\n");
92 else
93 printf("But you don't have any monopolies!!\n");
94 return;
95 }
96 if (num_mon == 1)
97 buy_h(monops[0]);
98 else {
99 names[num_mon++] = "done";
100 names[num_mon--] = 0;
101 if ((p = getinp(
102 "Which property do you wish to buy houses for? ",
103 names)) == num_mon)
104 return;
105 buy_h(monops[p]);
106 goto over;
107 }
108 }
109
110 static void
111 buy_h(mnp)
112 MON *mnp;
113 {
114 int i;
115 MON *mp;
116 int price;
117 short input[3],temp[3];
118 int tot;
119 PROP *pp;
120
121 mp = mnp;
122 price = mp->h_cost * 50;
123 blew_it:
124 list_cur(mp);
125 printf("Houses will cost $%d\n", price);
126 printf("How many houses do you wish to buy for\n");
127 for (i = 0; i < mp->num_in; i++) {
128 pp = mp->sq[i]->desc;
129 over:
130 if (pp->houses == 5) {
131 printf("%s (H):\n", mp->sq[i]->name);
132 input[i] = 0;
133 temp[i] = 5;
134 continue;
135 }
136 (void)sprintf(cur_prop, "%s (%d): ",
137 mp->sq[i]->name, pp->houses);
138 input[i] = get_int(cur_prop);
139 temp[i] = input[i] + pp->houses;
140 if (temp[i] > 5) {
141 printf("That's too many. The most you can buy is %d\n",
142 5 - pp->houses);
143 goto over;
144 }
145 }
146 if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
147 abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
148 err: printf("That makes the spread too wide. Try again\n");
149 goto blew_it;
150 }
151 else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
152 goto err;
153 for (tot = i = 0; i < mp->num_in; i++)
154 tot += input[i];
155 if (tot) {
156 printf("You asked for %d houses for $%d\n", tot, tot * price);
157 if (getyn("Is that ok? ") == 0) {
158 cur_p->money -= tot * price;
159 for (tot = i = 0; i < mp->num_in; i++)
160 mp->sq[i]->desc->houses = temp[i];
161 }
162 }
163 }
164
165 /*
166 * This routine sells houses.
167 */
168 void
169 sell_houses()
170 {
171 int num_mon;
172 MON *mp;
173 OWN *op;
174 bool good;
175 int p;
176
177 over:
178 num_mon = 0;
179 good = TRUE;
180 for (op = cur_p->own_list; op;)
181 if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
182 mp = op->sqr->desc->mon_desc;
183 names[num_mon] = (monops[num_mon]=mp)->name;
184 num_mon++;
185 good = 0;
186 do
187 if (!good && op->sqr->desc->houses != 0)
188 good++;
189 while (op->next && op->sqr->desc->mon_desc == mp
190 && (op = op->next));
191 if (!good)
192 --num_mon;
193 } else
194 op = op->next;
195 if (num_mon == 0) {
196 printf("You don't have any houses to sell!!\n");
197 return;
198 }
199 if (num_mon == 1)
200 sell_h(monops[0]);
201 else {
202 names[num_mon++] = "done";
203 names[num_mon--] = 0;
204 if ((p = getinp(
205 "Which property do you wish to sell houses from? ",
206 names)) == num_mon)
207 return;
208 sell_h(monops[p]);
209 notify();
210 goto over;
211 }
212 }
213
214 static void
215 sell_h(mnp)
216 MON *mnp;
217 {
218 int i;
219 MON *mp;
220 int price;
221 short input[3],temp[3];
222 int tot;
223 PROP *pp;
224
225 mp = mnp;
226 price = mp->h_cost * 25;
227 blew_it:
228 printf("Houses will get you $%d apiece\n", price);
229 list_cur(mp);
230 printf("How many houses do you wish to sell from\n");
231 for (i = 0; i < mp->num_in; i++) {
232 pp = mp->sq[i]->desc;
233 over:
234 if (pp->houses == 0) {
235 printf("%s (0):\n", mp->sq[i]->name);
236 input[i] = temp[i] = 0;
237 continue;
238 }
239 if (pp->houses < 5)
240 (void)sprintf(cur_prop,"%s (%d): ",
241 mp->sq[i]->name,pp->houses);
242 else
243 (void)sprintf(cur_prop,"%s (H): ",mp->sq[i]->name);
244 input[i] = get_int(cur_prop);
245 temp[i] = pp->houses - input[i];
246 if (temp[i] < 0) {
247 printf(
248 "That's too many. The most you can sell is %d\n",
249 pp->houses);
250 goto over;
251 }
252 }
253 if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
254 abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
255 err: printf("That makes the spread too wide. Try again\n");
256 goto blew_it;
257 }
258 else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
259 goto err;
260 for (tot = i = 0; i < mp->num_in; i++)
261 tot += input[i];
262 if (tot) {
263 printf("You asked to sell %d houses for $%d\n",tot,tot * price);
264 if (getyn("Is that ok? ") == 0) {
265 cur_p->money += tot * price;
266 for (tot = i = 0; i < mp->num_in; i++)
267 mp->sq[i]->desc->houses = temp[i];
268 }
269 }
270 }
271
272 static void
273 list_cur(mp)
274 MON *mp;
275 {
276 int i;
277 SQUARE *sqp;
278
279 for (i = 0; i < mp->num_in; i++) {
280 sqp = mp->sq[i];
281 if (sqp->desc->houses == 5)
282 printf("%s (H) ", sqp->name);
283 else
284 printf("%s (%d) ", sqp->name, sqp->desc->houses);
285 }
286 putchar('\n');
287 }