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