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