133202Sbostic /*
2*60815Sbostic * Copyright (c) 1980, 1993
3*60815Sbostic * The Regents of the University of California. All rights reserved.
433202Sbostic *
542583Sbostic * %sccs.include.redist.c%
633202Sbostic */
733202Sbostic
832477Sbostic #ifndef lint
9*60815Sbostic static char sccsid[] = "@(#)houses.c 8.1 (Berkeley) 05/31/93";
1033202Sbostic #endif /* not lint */
1132477Sbostic
1232477Sbostic # include "monop.ext"
1332477Sbostic
1432477Sbostic static char *names[N_MON+2],
1532477Sbostic cur_prop[80];
1632477Sbostic
1732477Sbostic static MON *monops[N_MON];
1832477Sbostic
1932477Sbostic /*
2032477Sbostic * These routines deal with buying and selling houses
2132477Sbostic */
buy_houses()2232477Sbostic buy_houses() {
2332477Sbostic
2432477Sbostic reg int num_mon;
2532477Sbostic reg MON *mp;
2632477Sbostic reg OWN *op;
2732477Sbostic bool good,got_morg;
2832477Sbostic int i,p;
2932477Sbostic
3032477Sbostic over:
3132477Sbostic num_mon = 0;
3232477Sbostic good = TRUE;
3332477Sbostic got_morg = FALSE;
3432477Sbostic for (op = cur_p->own_list; op && op->sqr->type != PRPTY; op = op->next)
3532477Sbostic continue;
3632477Sbostic while (op)
3732477Sbostic if (op->sqr->desc->monop) {
3832477Sbostic mp = op->sqr->desc->mon_desc;
3932477Sbostic names[num_mon] = (monops[num_mon]=mp)->name;
4032477Sbostic num_mon++;
4132477Sbostic got_morg = good = FALSE;
4232477Sbostic for (i = 0; i < mp->num_in; i++) {
4332477Sbostic if (op->sqr->desc->morg)
4432477Sbostic got_morg++;
4532477Sbostic if (op->sqr->desc->houses != 5)
4632477Sbostic good++;
4732477Sbostic op = op->next;
4832477Sbostic }
4932477Sbostic if (!good || got_morg)
5032477Sbostic --num_mon;
5132477Sbostic }
5232477Sbostic else
5332477Sbostic op = op->next;
5432477Sbostic if (num_mon == 0) {
5532477Sbostic if (got_morg)
5632477Sbostic printf("You can't build on mortgaged monopolies.\n");
5732477Sbostic else if (!good)
5832477Sbostic printf("You can't build any more.\n");
5932477Sbostic else
6032477Sbostic printf("But you don't have any monopolies!!\n");
6132477Sbostic return;
6232477Sbostic }
6332477Sbostic if (num_mon == 1)
6432477Sbostic buy_h(monops[0]);
6532477Sbostic else {
6632477Sbostic names[num_mon++] = "done";
6732477Sbostic names[num_mon--] = 0;
6832477Sbostic if ((p=getinp("Which property do you wish to buy houses for? ", names)) == num_mon)
6932477Sbostic return;
7032477Sbostic buy_h(monops[p]);
7132477Sbostic goto over;
7232477Sbostic }
7332477Sbostic }
7432477Sbostic
buy_h(mnp)7532477Sbostic buy_h(mnp)
7632477Sbostic MON *mnp; {
7732477Sbostic
7832477Sbostic reg int i;
7932477Sbostic reg MON *mp;
8032477Sbostic reg int price;
8132477Sbostic shrt input[3],temp[3];
8232477Sbostic int tot;
8332477Sbostic PROP *pp;
8432477Sbostic
8532477Sbostic mp = mnp;
8632477Sbostic price = mp->h_cost * 50;
8732477Sbostic blew_it:
8832477Sbostic list_cur(mp);
8932477Sbostic printf("Houses will cost $%d\n", price);
9032477Sbostic printf("How many houses do you wish to buy for\n");
9132477Sbostic for (i = 0; i < mp->num_in; i++) {
9232477Sbostic pp = mp->sq[i]->desc;
9332477Sbostic over:
9432477Sbostic if (pp->houses == 5) {
9532477Sbostic printf("%s (H):\n", mp->sq[i]->name);
9632477Sbostic input[i] = 0;
9732477Sbostic temp[i] = 5;
9832477Sbostic continue;
9932477Sbostic }
10032478Sbostic (void)sprintf(cur_prop, "%s (%d): ",
10132478Sbostic mp->sq[i]->name, pp->houses);
10232477Sbostic input[i] = get_int(cur_prop);
10332477Sbostic temp[i] = input[i] + pp->houses;
10432477Sbostic if (temp[i] > 5) {
10532477Sbostic printf("That's too many. The most you can buy is %d\n",
10632477Sbostic 5 - pp->houses);
10732477Sbostic goto over;
10832477Sbostic }
10932477Sbostic }
11032477Sbostic if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
11132477Sbostic abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
11232477Sbostic err: printf("That makes the spread too wide. Try again\n");
11332477Sbostic goto blew_it;
11432477Sbostic }
11532477Sbostic else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
11632477Sbostic goto err;
11732477Sbostic for (tot = i = 0; i < mp->num_in; i++)
11832477Sbostic tot += input[i];
11932477Sbostic if (tot) {
12032477Sbostic printf("You asked for %d houses for $%d\n", tot, tot * price);
12132477Sbostic if (getyn("Is that ok? ", yn) == 0) {
12232477Sbostic cur_p->money -= tot * price;
12332477Sbostic for (tot = i = 0; i < mp->num_in; i++)
12432477Sbostic mp->sq[i]->desc->houses = temp[i];
12532477Sbostic }
12632477Sbostic }
12732477Sbostic }
12832477Sbostic
12932477Sbostic /*
13032477Sbostic * This routine sells houses.
13132477Sbostic */
sell_houses()13232477Sbostic sell_houses() {
13332477Sbostic
13432477Sbostic reg int num_mon;
13532477Sbostic reg MON *mp;
13632477Sbostic reg OWN *op;
13732477Sbostic bool good;
13832477Sbostic int p;
13932477Sbostic
14032477Sbostic over:
14132477Sbostic num_mon = 0;
14232477Sbostic good = TRUE;
14332477Sbostic for (op = cur_p->own_list; op; op = op->next)
14432477Sbostic if (op->sqr->type == PRPTY && op->sqr->desc->monop) {
14532477Sbostic mp = op->sqr->desc->mon_desc;
14632477Sbostic names[num_mon] = (monops[num_mon]=mp)->name;
14732477Sbostic num_mon++;
14832477Sbostic good = 0;
14932477Sbostic do
15032477Sbostic if (!good && op->sqr->desc->houses != 0)
15132477Sbostic good++;
15232477Sbostic while (op->next && op->sqr->desc->mon_desc == mp
15332477Sbostic && (op=op->next));
15432477Sbostic if (!good)
15532477Sbostic --num_mon;
15632477Sbostic }
15732477Sbostic if (num_mon == 0) {
15832477Sbostic printf("You don't have any houses to sell!!\n");
15932477Sbostic return;
16032477Sbostic }
16132477Sbostic if (num_mon == 1)
16232477Sbostic sell_h(monops[0]);
16332477Sbostic else {
16432477Sbostic names[num_mon++] = "done";
16532477Sbostic names[num_mon--] = 0;
16632477Sbostic if ((p=getinp("Which property do you wish to sell houses from? ", names)) == num_mon)
16732477Sbostic return;
16832477Sbostic sell_h(monops[p]);
16932477Sbostic notify();
17032477Sbostic goto over;
17132477Sbostic }
17232477Sbostic }
17332477Sbostic
sell_h(mnp)17432477Sbostic sell_h(mnp)
17532477Sbostic MON *mnp; {
17632477Sbostic
17732477Sbostic reg int i;
17832477Sbostic reg MON *mp;
17932477Sbostic reg int price;
18032477Sbostic shrt input[3],temp[3];
18132477Sbostic int tot;
18232477Sbostic PROP *pp;
18332477Sbostic
18432477Sbostic mp = mnp;
18532477Sbostic price = mp->h_cost * 25;
18632477Sbostic blew_it:
18732477Sbostic printf("Houses will get you $%d apiece\n", price);
18832477Sbostic list_cur(mp);
18932477Sbostic printf("How many houses do you wish to sell from\n");
19032477Sbostic for (i = 0; i < mp->num_in; i++) {
19132477Sbostic pp = mp->sq[i]->desc;
19232477Sbostic over:
19332477Sbostic if (pp->houses == 0) {
19432477Sbostic printf("%s (0):\n", mp->sq[i]->name);
19532477Sbostic input[i] = temp[i] = 0;
19632477Sbostic continue;
19732477Sbostic }
19832477Sbostic if (pp->houses < 5)
19932478Sbostic (void)sprintf(cur_prop,"%s (%d): ",
20032478Sbostic mp->sq[i]->name,pp->houses);
20132477Sbostic else
20232478Sbostic (void)sprintf(cur_prop,"%s (H): ",mp->sq[i]->name);
20332477Sbostic input[i] = get_int(cur_prop);
20432477Sbostic temp[i] = pp->houses - input[i];
20532477Sbostic if (temp[i] < 0) {
20632477Sbostic printf("That's too many. The most you can sell is %d\n", pp->houses);
20732477Sbostic goto over;
20832477Sbostic }
20932477Sbostic }
21032477Sbostic if (mp->num_in == 3 && (abs(temp[0] - temp[1]) > 1 ||
21132477Sbostic abs(temp[0] - temp[2]) > 1 || abs(temp[1] - temp[2]) > 1)) {
21232477Sbostic err: printf("That makes the spread too wide. Try again\n");
21332477Sbostic goto blew_it;
21432477Sbostic }
21532477Sbostic else if (mp->num_in == 2 && abs(temp[0] - temp[1]) > 1)
21632477Sbostic goto err;
21732477Sbostic for (tot = i = 0; i < mp->num_in; i++)
21832477Sbostic tot += input[i];
21932477Sbostic if (tot) {
22032477Sbostic printf("You asked to sell %d houses for $%d\n",tot,tot * price);
22132477Sbostic if (getyn("Is that ok? ", yn) == 0) {
22232477Sbostic cur_p->money += tot * price;
22332477Sbostic for (tot = i = 0; i < mp->num_in; i++)
22432477Sbostic mp->sq[i]->desc->houses = temp[i];
22532477Sbostic }
22632477Sbostic }
22732477Sbostic }
22832477Sbostic
list_cur(mp)22932477Sbostic list_cur(mp)
23032477Sbostic reg MON *mp; {
23132477Sbostic
23232477Sbostic reg int i;
23332477Sbostic reg SQUARE *sqp;
23432477Sbostic
23532477Sbostic for (i = 0; i < mp->num_in; i++) {
23632477Sbostic sqp = mp->sq[i];
23732477Sbostic if (sqp->desc->houses == 5)
23832477Sbostic printf("%s (H) ", sqp->name);
23932477Sbostic else
24032477Sbostic printf("%s (%d) ", sqp->name, sqp->desc->houses);
24132477Sbostic }
24232477Sbostic putchar('\n');
24332477Sbostic }
244