]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - monop/houses.c
1 /* $NetBSD: houses.c,v 1.9 2006/03/19 00:19:31 christos Exp $ */
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
32 #include <sys/cdefs.h>
35 static char sccsid
[] = "@(#)houses.c 8.1 (Berkeley) 5/31/93";
37 __RCSID("$NetBSD: houses.c,v 1.9 2006/03/19 00:19:31 christos Exp $");
43 static const char *names
[N_MON
+2];
44 static char cur_prop
[80];
46 static MON
*monops
[N_MON
];
48 static void buy_h(MON
*);
49 static void sell_h(MON
*);
50 static void list_cur(MON
*);
52 * These routines deal with buying and selling houses
67 for (op
= cur_p
->own_list
; op
&& op
->sqr
->type
!= PRPTY
; op
= op
->next
)
70 if (op
->sqr
->desc
->monop
) {
71 mp
= op
->sqr
->desc
->mon_desc
;
72 names
[num_mon
] = (monops
[num_mon
]=mp
)->name
;
74 got_morg
= good
= FALSE
;
75 for (i
= 0; i
< mp
->num_in
; i
++) {
76 if (op
->sqr
->desc
->morg
)
78 if (op
->sqr
->desc
->houses
!= 5)
82 if (!good
|| got_morg
)
89 printf("You can't build on mortgaged monopolies.\n");
91 printf("You can't build any more.\n");
93 printf("But you don't have any monopolies!!\n");
99 names
[num_mon
++] = "done";
100 names
[num_mon
--] = 0;
102 "Which property do you wish to buy houses for? ",
117 short input
[3],temp
[3];
122 price
= mp
->h_cost
* 50;
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
;
130 if (pp
->houses
== 5) {
131 printf("%s (H):\n", mp
->sq
[i
]->name
);
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
;
141 printf("That's too many. The most you can buy is %d\n",
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");
151 else if (mp
->num_in
== 2 && abs(temp
[0] - temp
[1]) > 1)
153 for (tot
= i
= 0; i
< mp
->num_in
; i
++)
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
];
166 * This routine sells houses.
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
;
187 if (!good
&& op
->sqr
->desc
->houses
!= 0)
189 while (op
->next
&& op
->sqr
->desc
->mon_desc
== mp
196 printf("You don't have any houses to sell!!\n");
202 names
[num_mon
++] = "done";
203 names
[num_mon
--] = 0;
205 "Which property do you wish to sell houses from? ",
221 short input
[3],temp
[3];
226 price
= mp
->h_cost
* 25;
228 printf("Houses will get you $%d apiece\n", price
);
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
;
234 if (pp
->houses
== 0) {
235 printf("%s (0):\n", mp
->sq
[i
]->name
);
236 input
[i
] = temp
[i
] = 0;
240 (void)sprintf(cur_prop
,"%s (%d): ",
241 mp
->sq
[i
]->name
,pp
->houses
);
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
];
248 "That's too many. The most you can sell is %d\n",
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");
258 else if (mp
->num_in
== 2 && abs(temp
[0] - temp
[1]) > 1)
260 for (tot
= i
= 0; i
< mp
->num_in
; i
++)
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
];
279 for (i
= 0; i
< mp
->num_in
; i
++) {
281 if (sqp
->desc
->houses
== 5)
282 printf("%s (H) ", sqp
->name
);
284 printf("%s (%d) ", sqp
->name
, sqp
->desc
->houses
);